AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-266
  5. plan
  6. context.json
context.json(2.6 KB)· Apr 3, 2026
{
  "meta": {
    "agent": "planner",
    "task_id": "266",
    "title": "Guard against main repo on target branch before worktree creation",
    "created_at": "2026-04-03T12:00:00Z"
  },
  "inputs": [
    {
      "name": "issue-266",
      "type": "context",
      "ref": "https://github.com/AgentSDE/agent-core/issues/266",
      "notes": "Worktree creation fails when main repo is on target feature branch"
    },
    {
      "name": "worktree.service.ts",
      "type": "file",
      "ref": "src/worktree/worktree.service.ts",
      "notes": "createWorktree() method — lines 24-143"
    },
    {
      "name": "worktree.service.spec.ts",
      "type": "file",
      "ref": "src/worktree/worktree.service.spec.ts",
      "notes": "Existing unit tests using jest mocks for child_process and fs"
    }
  ],
  "outputs": [
    {
      "name": "plan",
      "type": "plan",
      "format": "md",
      "content": "plan.md"
    }
  ],
  "files": [
    {
      "path": "src/worktree/worktree.service.ts",
      "action": "modify",
      "reason": "Add branch guard with auto-switch to master before stale-branch cleanup"
    },
    {
      "path": "src/worktree/worktree.service.spec.ts",
      "action": "modify",
      "reason": "Add unit tests for guard logic: auto-switch, checkout failure, detached HEAD"
    }
  ],
  "steps": [
    {
      "id": "S1",
      "summary": "Add branch guard in createWorktree() — detect current branch, auto-switch to master if on target branch, throw on checkout failure",
      "acceptance": [
        "Before stale-branch cleanup, git rev-parse --abbrev-ref HEAD is called to check current branch",
        "If current branch matches target, git checkout master is executed",
        "If git checkout master fails, a descriptive error is thrown (not swallowed)",
        "Detached HEAD state is treated as not on target branch — no checkout attempted"
      ],
      "depends_on": []
    },
    {
      "id": "S2",
      "summary": "Add unit tests for branch guard scenarios",
      "acceptance": [
        "Test: main repo on target branch → auto-switch to master → worktree creation succeeds",
        "Test: main repo on target branch → git checkout master fails → typed error thrown",
        "Test: git branch -D failure is handled gracefully (existing behavior preserved)",
        "All existing tests continue to pass",
        "npm run lint passes with zero warnings"
      ],
      "depends_on": [
        "S1"
      ]
    }
  ],
  "risks": [
    {
      "risk": "git checkout master may fail if repoPath has uncommitted changes",
      "mitigation": "By design — throw a clear error; do not attempt stash (per issue scope)"
    }
  ],
  "assumptions": [
    "The main repo always has a master branch available to switch to",
    "Detached HEAD is safe to proceed — it means no named branch conflict"
  ],
  "open_questions": []
}
Plan