feat(tools): TaskCreate family + Monitor (background tasks)#135
Merged
Conversation
Implements §0.1's "TaskCreate 全系" — async background tasks that run a
sub-agent concurrently with the main turn (cron covers *recurring*; this covers
*background*). Previously entirely missing.
core (tasks/manager.ts): TaskManager — runner-agnostic. create() starts a task
without blocking, pipes streamed output into the task buffer (onChunk) and flips
status on settle; get/list/output/update/stop/wait. Each task is
{id,description,status,output,createdAt,finishedAt}.
tools (tools/task-manage.ts): TaskCreate / TaskList / TaskGet / TaskOutput /
TaskUpdate / TaskStop / Monitor, driving ctx.tasks. Monitor awaits completion.
All no-op gracefully when ctx.tasks is absent.
agent loop: at depth 0 (top-level only), wires ctx.tasks = TaskManager whose
runner backs each task with runSubAgent + a per-task AbortController (so TaskStop
cancels just that task). runSubAgent gained an optional `signal`. The 7 tools are
in SUBAGENT_TOOL_DENYLIST (a sub-agent can't spawn tasks) and MCP_SERVE_EXCLUDE.
Registered in BUILTIN_TOOLS (now 26).
Tests: +10 — TaskManager (create/wait/fail/stop/streaming/list/update) and the
tools (create+Monitor round-trip, list/output, stop, no-manager guard, unknown
ids). Core 618 green.
Note: v1 surfaces final output on completion; per-chunk streaming from a live
sub-agent is a follow-up (the manager already supports onChunk).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements §0.1's "TaskCreate 全系" — async background tasks that run a sub-agent concurrently with the main turn (cron covers recurring jobs; this covers background ones). Previously entirely missing (the audit's biggest P0 gap).
Design
tasks/manager.ts—TaskManager(runner-agnostic):create()starts a task without blocking the caller, pipes streamed output into the task buffer (onChunk), and flips status on settle;get/list/output/update/stop/wait. A task is{ id, description, status, output, createdAt, finishedAt }.tools/task-manage.ts—TaskCreate/TaskList/TaskGet/TaskOutput/TaskUpdate/TaskStop/Monitor, drivingctx.tasks.Monitorblocks until the task completes/fails/stops. All no-op gracefully whenctx.tasksis absent.ctx.tasks = TaskManagerwhose runner backs each task withrunSubAgent+ a per-taskAbortController(soTaskStopcancels just that task).runSubAgentgained an optionalsignal. The 7 tools are inSUBAGENT_TOOL_DENYLIST(a sub-agent can't spawn tasks) andMCP_SERVE_EXCLUDE. Registered inBUILTIN_TOOLS(now 26).Tests
+10:
TaskManager(create→wait→completed, failed runner, stop+abort+no-op-second-stop, streamingonChunkkept over final text, list/get/update/unknown-id) and the tools (TaskCreate+Monitor round-trip, TaskList/TaskOutput, TaskStop, no-manager guard, unknown ids). Core suite 618 green; full repo green via pre-commit.Note
v1 surfaces the task's final output on completion; per-chunk streaming from a live sub-agent is a follow-up (the manager already supports
onChunk, so it's additive —runSubAgentjust needs to forward events).🤖 Generated with Claude Code