{
"meta": {
"agent": "planner",
"task_id": "232",
"title": "feat: /agent replan directive to reset task and restart from refinement",
"created_at": "2026-04-01T12:00:00Z"
},
"inputs": [
{
"name": "issue-232",
"type": "context",
"ref": "https://github.com/AgentSDE/agent-core/issues/232",
"notes": "Full issue with acceptance criteria and edge cases"
},
{
"name": "AGENTS.md",
"type": "context",
"ref": "AGENTS.md",
"notes": "Directive system knowledge: ALLOWED_DIRECTIVES is source of truth, wire in both DirectiveService and PhaseRouterService"
}
],
"outputs": [
{
"name": "plan.md",
"type": "plan",
"format": "md",
"content": "Implementation plan for /agent replan directive"
}
],
"files": [
{
"path": "src/directive/dto/directive.dto.ts",
"action": "modify",
"reason": "Add 'replan' to ALLOWED_DIRECTIVES"
},
{
"path": "src/directive/directive.service.ts",
"action": "modify",
"reason": "Add replan handler with state validation, PR cleanup, reset, event recording"
},
{
"path": "src/phase-router/phase-router.service.ts",
"action": "modify",
"reason": "Add replan to resolvePhase and directive handling block"
},
{
"path": "src/github/github.service.ts",
"action": "modify",
"reason": "Add closePR() and deleteBranch() methods"
},
{
"path": "src/hooks/phase-hooks.service.ts",
"action": "modify",
"reason": "Add cleanupLabelsForReplan() helper"
},
{
"path": "src/directive/directive.service.spec.ts",
"action": "modify",
"reason": "Unit tests for replan directive"
},
{
"path": "src/phase-router/phase-router.service.spec.ts",
"action": "modify",
"reason": "Unit test for replan resolvePhase"
},
{
"path": "src/github/github.service.spec.ts",
"action": "modify",
"reason": "Unit tests for closePR and deleteBranch"
}
],
"steps": [
{
"id": "S1",
"summary": "Add 'replan' to ALLOWED_DIRECTIVES and add closePR/deleteBranch to GitHubService",
"acceptance": [
"DirectiveValue type includes 'replan'",
"GitHubService.closePR() calls PATCH /pulls/:number with state:'closed'",
"GitHubService.deleteBranch() calls DELETE /git/refs/heads/:branch",
"Both methods handle 404/422 as success (already closed/deleted)",
"Unit tests for closePR and deleteBranch pass"
],
"depends_on": []
},
{
"id": "S2",
"summary": "Add cleanupLabelsForReplan to PhaseHooksService and replan handler to DirectiveService",
"acceptance": [
"cleanupLabelsForReplan removes 'refined', 'in-review', 'agent-blocked' and adds 'in-refinement'",
"Replan on completed/archived task is rejected with explanatory comment",
"Replan on task already in active refine is a no-op with explanatory comment",
"Normal replan: closes PR, deletes branch, resets all phases, clears PR metadata, records replan_triggered event, enqueues refine",
"PR/branch close failure (non-404) logs warning but replan proceeds",
"Confirmation comment posted with details",
"Unit tests cover normal replan, already-in-refine guard, completed-task guard"
],
"depends_on": [
"S1"
]
},
{
"id": "S3",
"summary": "Wire replan into PhaseRouterService and verify full pipeline",
"acceptance": [
"'replan' added to VALID_DIRECTIVES array",
"resolvePhase returns 'refine' for replan directive",
"Directive handling block processes replan (reset + enqueue, no active-process rejection)",
"npm run lint passes with zero warnings",
"npm run test passes all tests",
"npm run build compiles without errors"
],
"depends_on": [
"S2"
]
}
],
"risks": [
{
"risk": "In-flight Claude run not tracked by PID — cannot force-kill",
"mitigation": "Phase-router 'already active' guard prevents double-execution; old process times out naturally. Document limitation."
},
{
"risk": "PR close/branch delete race with concurrent merge",
"mitigation": "Treat 404/422 responses as success"
}
],
"assumptions": [
"resetForRestart() is suitable for replan reset (all phases pending, currentPhase='refine')",
"The existing directive allowlist/membership enforcement applies automatically since replan flows through the same webhook path",
"E2E test will be added separately (out of scope per issue — unit tests are in scope)"
],
"open_questions": []
}