Add ability to resume interrupted subagent executions using Task tool's resume parameter. Tracks agent IDs during execution and enables seamless continuation after session timeout, rate limits, or crashes. - New /gsd:resume-task command for resuming interrupted agents - Agent ID tracking in execute-phase workflow - Dual storage: current-agent-id.txt (fast) + agent-history.json (audit) - Auto-detection of interrupted agents in resume-project workflow - File conflict warnings before resume Closes #37 Co-Authored-By: davesienkowski <davesienkowski@users.noreply.github.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
5.6 KiB
Enables seamless continuation of autonomous work that was interrupted by session timeout, user exit, or crash.
Parse the optional agent_id argument:# Check if argument provided
if [ -n "$ARGUMENTS" ]; then
AGENT_ID="$ARGUMENTS"
echo "Using provided agent ID: $AGENT_ID"
else
# Read from current-agent-id.txt
if [ -f .planning/current-agent-id.txt ] && [ -s .planning/current-agent-id.txt ]; then
AGENT_ID=$(cat .planning/current-agent-id.txt | tr -d '\n')
echo "Using current agent ID: $AGENT_ID"
else
echo "ERROR: No agent to resume"
exit 1
fi
fi
If no agent ID found: Present error:
No active agent to resume.
There's no interrupted agent recorded. This could mean:
- No subagent was spawned in the current plan
- The last agent completed successfully
- .planning/current-agent-id.txt was cleared
Use /gsd:progress to check project status.
If agent ID found: Continue to validate_agent step.
Validate the agent exists and is resumable:# Check if agent-history.json exists
if [ ! -f .planning/agent-history.json ]; then
echo "ERROR: No agent history found"
exit 1
fi
# Read history and find the agent
cat .planning/agent-history.json
Parse agent-history.json and find entry matching AGENT_ID:
Check the entry status:
- If status = "completed": Error - agent already completed
- If status = "spawned" or "interrupted": Valid for resume
- If not found: Error - agent ID not in history
If agent already completed:
Agent already completed.
Agent ID: [id]
Completed: [completion_timestamp]
Task: [task_description]
This agent finished successfully. No resume needed.
If agent not found:
Agent ID not found in history.
ID: [provided_id]
Available agents:
- [list most recent 5 agents with status]
Did you mean one of these?
If valid for resume: Continue to check_conflicts step.
Check for file modifications since the agent was spawned.Read the agent entry to get context:
- phase, plan, segment information
- timestamp of spawn
Check for git changes since spawn:
# Get files modified since agent spawn
# Note: This is a best-effort check - relies on git status
git status --short
If modifications detected:
Use AskUserQuestion to warn user:
Files modified since agent was interrupted:
- [list files]
These changes may conflict with the agent's work.
Options:
1. Continue anyway - Agent will resume with current files
2. Abort - Review changes first
Select option:
Wait for user response.
If user selects "Abort":
Resume aborted. Review your changes and run /gsd:resume-task when ready.
End workflow.
If user selects "Continue anyway" or no conflicts found: Continue to update_status step.
Update the agent status to "interrupted" if it was "spawned" (marking the interruption point):# Read current history
HISTORY=$(cat .planning/agent-history.json)
Update the entry in agent-history.json:
- If status was "spawned", change to "interrupted"
- Add note about resume attempt
This provides audit trail of the interruption before resume.
Resume the agent using Task tool's resume parameter:Resuming agent: [agent_id]
Task: [task_description from history]
Phase: [phase]-[plan]
The agent will continue from where it left off...
Use Task tool with resume parameter:
Task(
description: "Resume interrupted agent",
prompt: "Continue your previous work. You were executing [task_description].",
subagent_type: "general-purpose",
resume: "[AGENT_ID]"
)
Wait for agent completion.
On agent completion:
- Capture any results returned
- Continue to completion_update step
1. Update agent-history.json:
Add new entry marking the resume completion:
{
"agent_id": "[AGENT_ID]",
"task_description": "[original task] (resumed)",
"phase": "[phase]",
"plan": "[plan]",
"segment": [segment or null],
"timestamp": "[now]",
"status": "completed",
"completion_timestamp": "[now]"
}
2. Clear current-agent-id.txt:
# Clear the current agent file
> .planning/current-agent-id.txt
3. Present completion message:
Agent resumed and completed successfully.
Agent ID: [id]
Task: [task_description]
Original spawn: [original_timestamp]
Completed: [now]
The agent's work has been incorporated. Check git status for changes.
If Task tool returns error on resume:
Failed to resume agent.
Agent ID: [id]
Error: [error message]
Possible causes:
- Agent context may have expired
- Agent may have been invalidated
Options:
1. Start fresh - Execute plan from beginning
2. Check status - Review what was completed
Run /gsd:execute-plan to start fresh if needed.
Do NOT clear current-agent-id.txt on error - allow retry.
<success_criteria> Resume is complete when:
- Agent resumed successfully via Task tool resume parameter
- Agent-history.json updated with completion status
- Current-agent-id.txt cleared
- User informed of completion </success_criteria>