feat: add lightweight task tracking for multi-step execution#28
feat: add lightweight task tracking for multi-step execution#28Davidwadesmith wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds session-scoped task tracking to MiniCode so the agent can create/update/complete/list a lightweight task list, surface it in the TUI (header badge + transcript entries), and persist/restore it via session JSONL snapshots.
Changes:
- Introduces
TaskState/snapshot utilities and a newtask_trackertool for managing tasks. - Persists task snapshots into session JSONL and restores task state on resume; adds
/taskscommand and TUI rendering/badge. - Extends agent loop callback plumbing to pass
toolInputintoonToolResultfor richer UI side effects.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/task-tracker.test.ts | Adds unit tests for task state transitions, snapshot round-trip, and formatting. |
| src/task-state.ts | Implements TaskState CRUD, allowed transitions, snapshot serialization, and task list formatting. |
| src/tools/task-tracker.ts | Adds the task_tracker tool (create/update_status/complete/list) with Zod validation + JSON schema. |
| src/tools/index.ts | Wires task_tracker into the default tool registry when a TaskState is provided. |
| src/session.ts | Adds task_snapshot session event, append + load helpers, and transcript representation on replay. |
| src/tty-app.ts | Threads TaskState through TTY app, adds /tasks, renders task updates, and persists snapshots after tool use. |
| src/tui/types.ts | Adds task_update transcript entry kind. |
| src/tui/transcript.ts | Renders task_update entries with icons/colors. |
| src/tui/chrome.ts | Adds [tasks] N/M header badge support. |
| src/cli-commands.ts | Adds /tasks slash command metadata. |
| src/prompt.ts | Updates system prompt with task tracking instructions for the agent. |
| src/agent-loop.ts | Passes toolInput into onToolResult callback (backward compatible). |
| src/index.ts | Creates initial TaskState and passes it into tool registry + TTY app. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| createContextCollapseState() | ||
| const loadedTaskState = await loadTaskState(args.cwd, sessionId) | ||
| if (loadedTaskState) { | ||
| args.taskState = loadedTaskState |
| args.sessionId = crypto.randomUUID().slice(0, 8) | ||
| args.alreadySavedCount = 0 | ||
| args.contextCollapseState = createContextCollapseState() | ||
| args.taskState = createTaskState() |
| state.transcriptScrollOffset = 0 | ||
| void appendTaskSnapshot(args.cwd, args.sessionId, toSnapshot(args.taskState)) | ||
| } |
| : entry.action === 'completed' ? '✓' | ||
| : '→' | ||
| const color = entry.action === 'completed' ? GREEN : YELLOW | ||
| return `${DIM}task${RESET} ${color}${icon}${RESET} ${entry.taskSummary}` |
| import path from 'node:path' | ||
| import { MINI_CODE_PROJECTS_DIR } from './config.js' | ||
| import { | ||
| createTaskState, |
|
Looks good overall. The design feels appropriately lightweight and fits the existing MiniCode session/TUI patterns. Before merging, I’d like to confirm a few edge cases around state consistency:
If these are already covered, it would be helpful to mention them in the PR description. Otherwise I’d suggest adding targeted tests for latest-snapshot restore, invalid task id handling, completed-task behavior, and non-TTY task tracker usage. |
|
Thanks for the thorough review. Answers inline: 1. loadTaskState robustness — Yes. It scans backwards to find the last 2. Task ID stability — Yes. 3. Invalid transitions —
Failed calls skip both transcript entry and snapshot persistence ( 4. Transcript/snapshot ordering — Transcript entry is pushed synchronously first, then 5. Non-TTY mode — 6. Prompt instructions — Added a guard in the follow-up commit: Follow-up commit: |
Add a task_tracker tool that lets the model self-manage a task list during long multi-step work. Tasks persist with the session and are visible via a header banner badge, transcript entries, and /tasks. - New task-state.ts: TaskStatus/Task/TaskState types, CRUD + snapshot - New task-tracker.ts tool: create/update_status/complete/list actions - Session persistence: task_snapshot JSONL events, resume/fork support - TUI: [tasks] N/M banner badge, task_update transcript entries - /tasks slash command for full task list view - System prompt instructions guiding model usage - agent-loop: pass toolInput to onToolResult callback ROADMAP P1 LiuMengxuan04#7. 167/167 tests pass, tsc --noEmit clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Add .catch() to appendTaskSnapshot fire-and-forget to prevent unhandled promise rejection - Add prompt guard: skip task_tracker for simple single-step requests (only use when work involves 3+ distinct steps) Note: non-TTY headless mode has no session persistence at all (no sessionId, no saveSession), so task snapshot persistence is a TTY-only concern. This matches the existing architecture where session management is part of the TTY app lifecycle. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6726a06 to
d930c51
Compare
Summary
Adds a
task_trackertool that lets the model self-manage a lightweight task list during long multi-step work. Addresses ROADMAP P1 #7.What changed:
src/task-state.ts(new):TaskStatus/Task/TaskStatetypes, state CRUD, snapshot serialization,formatTaskListsrc/tools/task-tracker.ts(new): single tool with 4 actions —create,update_status,complete,list. Zod validation + JSON Schema for APItest/task-tracker.test.ts(new): 15 unit tests covering state transitions, snapshot round-trip, formattingsrc/session.ts:task_snapshotJSONL event type,appendTaskSnapshot,loadTaskState(followsloadContextCollapseStatepattern)src/tty-app.ts:TaskStateinTtyAppArgs,/taskshandler, post-task_trackerside effects (transcript entry + snapshot persist), resume/fork/new integrationsrc/tui/types.ts+src/tui/transcript.ts:task_updatetranscript entry kind with created/updated/completed iconssrc/tui/chrome.ts:[tasks] N/Mbadge in header bannersrc/cli-commands.ts:/tasksslash commandsrc/prompt.ts: task tracking instructions in system promptsrc/agent-loop.ts: passtoolInputtoonToolResultcallback (backward-compatible)src/tools/index.ts+src/index.ts: wireTaskStatethrough tool registry and TTY appWhy it stays lightweight:
ContextCollapseStateHow it aligns with Claude Code:
TodoWritetool conceptVerification
npm run checkpasses (tsc --noEmit)/tasksdisplays list, session resume restores tasks🤖 Generated with Claude Code