@agimon-ai/doompi-task 0.0.1-alpha.13 → 0.0.1-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -12
- package/dist/commands/task/promptGuidelines.cjs +1 -1
- package/dist/commands/task/promptGuidelines.cjs.map +1 -1
- package/dist/commands/task/promptGuidelines.mjs +1 -1
- package/dist/commands/task/promptGuidelines.mjs.map +1 -1
- package/dist/commands/task/responseEnvelope.cjs +6 -5
- package/dist/commands/task/responseEnvelope.cjs.map +1 -1
- package/dist/commands/task/responseEnvelope.d.cts +14 -2
- package/dist/commands/task/responseEnvelope.d.cts.map +1 -1
- package/dist/commands/task/responseEnvelope.d.mts +14 -2
- package/dist/commands/task/responseEnvelope.d.mts.map +1 -1
- package/dist/commands/task/responseEnvelope.mjs +6 -5
- package/dist/commands/task/responseEnvelope.mjs.map +1 -1
- package/dist/commands/task/taskTool.cjs +2 -2
- package/dist/commands/task/taskTool.cjs.map +1 -1
- package/dist/commands/task/taskTool.d.cts.map +1 -1
- package/dist/commands/task/taskTool.d.mts.map +1 -1
- package/dist/commands/task/taskTool.mjs +2 -2
- package/dist/commands/task/taskTool.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/schemas/task.cjs +1 -1
- package/dist/schemas/task.cjs.map +1 -1
- package/dist/schemas/task.d.cts +28 -11
- package/dist/schemas/task.d.cts.map +1 -1
- package/dist/schemas/task.d.mts +28 -11
- package/dist/schemas/task.d.mts.map +1 -1
- package/dist/schemas/task.mjs +1 -1
- package/dist/schemas/task.mjs.map +1 -1
- package/dist/services/store/types.cjs.map +1 -1
- package/dist/services/store/types.d.cts +22 -10
- package/dist/services/store/types.d.cts.map +1 -1
- package/dist/services/store/types.d.mts +22 -10
- package/dist/services/store/types.d.mts.map +1 -1
- package/dist/services/store/types.mjs.map +1 -1
- package/dist/store/types.d.cts +2 -2
- package/dist/store/types.d.mts +2 -2
- package/dist/tool/responseEnvelope.cjs +1 -1
- package/dist/tool/responseEnvelope.d.cts +2 -2
- package/dist/tool/responseEnvelope.d.mts +2 -2
- package/dist/tool/responseEnvelope.mjs +1 -1
- package/dist/tool/schema.cjs +1 -1
- package/dist/tool/schema.d.cts +2 -2
- package/dist/tool/schema.d.mts +2 -2
- package/dist/tool/schema.mjs +1 -1
- package/dist/tui/format.cjs +3 -3
- package/dist/tui/format.cjs.map +1 -1
- package/dist/tui/format.d.cts.map +1 -1
- package/dist/tui/format.d.mts.map +1 -1
- package/dist/tui/format.mjs +3 -3
- package/dist/tui/format.mjs.map +1 -1
- package/dist/tui/selectors.cjs +1 -1
- package/dist/tui/selectors.cjs.map +1 -1
- package/dist/tui/selectors.d.cts +7 -0
- package/dist/tui/selectors.d.cts.map +1 -1
- package/dist/tui/selectors.d.mts +7 -0
- package/dist/tui/selectors.d.mts.map +1 -1
- package/dist/tui/selectors.mjs +1 -1
- package/dist/tui/selectors.mjs.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# @agimon-ai/doompi-task
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**A task list that survives the conversation.**
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
This is a file-backed task graph, not a checklist copied into chat. Tasks have statuses and
|
|
6
|
+
dependencies, can be handed to subagents, and remain authoritative after compaction rewrites
|
|
7
|
+
the transcript. The agent can forget the prose; it does not get to forget the work.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
This is part of [Doompi](https://www.npmjs.com/package/@agimon-ai/doompi). Most users get
|
|
10
|
+
it with the distribution; install it directly when embedding the task graph in another Pi
|
|
11
|
+
setup.
|
|
11
12
|
|
|
12
13
|
## Install
|
|
13
14
|
|
|
@@ -17,18 +18,26 @@ npm install @agimon-ai/doompi-task
|
|
|
17
18
|
|
|
18
19
|
## How it loads
|
|
19
20
|
|
|
20
|
-
Doompi loads
|
|
21
|
-
|
|
21
|
+
Doompi loads tasks as core. It is not a layer and does not appear in `.doom/modes.yaml`.
|
|
22
|
+
The bare package name follows its Pi manifest and selects the Doom adapter. That adapter
|
|
23
|
+
connects the graph to the Doom TUI and team runtime.
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
## What it does
|
|
26
|
+
|
|
27
|
+
- Stores tasks on disk instead of relying on transcript memory.
|
|
28
|
+
- Enforces dependency and lifecycle transitions.
|
|
29
|
+
- Shares one board with Doompi subagents.
|
|
30
|
+
- Keeps delegation visible to the parent session.
|
|
31
|
+
- Gives compaction an authoritative task snapshot to carry forward.
|
|
24
32
|
|
|
25
33
|
## Leader
|
|
26
34
|
|
|
27
|
-
`SPC t t` opens
|
|
35
|
+
`SPC t t` opens the task board.
|
|
28
36
|
|
|
29
|
-
##
|
|
37
|
+
## Public API
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
The package exports its task model, storage, tools, TUI, and Pi/Doom adapters through
|
|
40
|
+
supported subpaths. See `package.json` for the complete list.
|
|
32
41
|
|
|
33
42
|
## License
|
|
34
43
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=["Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.",`Capture a whole plan in one call: {"action":"upsert","tasks":[{"subject":"Research existing tool"},{"subject":"Write the reducer"},{"subject":"Add tests"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.`,`Do not batch progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.`,`Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status "failed" or keep it in_progress and add a new task for the blocker in the same upsert.`,`When every non-deleted task is completed, review the full task list once more and call task {"action":"clear"} to close it. Do not leave an all-completed list open.`,`Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.`,`One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {"action":"upsert","tasks":[{"id":3,"status":"completed"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.`,`Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a "ref" and list the ref string in place of an id: [{"ref":"api","subject":"Design the API"},{"subject":"Implement the API","blockedBy":["api"]}]. A ref must be declared before it is used. Cycles are rejected.`,`upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.`,`Before assigning work, call subagent with {"action":"agents"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.`,`Assign every unblocked pending task
|
|
1
|
+
const e=["Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.",`Capture a whole plan in one call: {"action":"upsert","tasks":[{"subject":"Research existing tool"},{"subject":"Write the reducer"},{"subject":"Add tests"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.`,`Do not batch parent progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: upsert batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Native assignments[] fan-out is separate from progress reporting. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.`,`Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status "failed" or keep it in_progress and add a new task for the blocker in the same upsert.`,`When every non-deleted task is completed, review the full task list once more and call task {"action":"clear"} to close it. Do not leave an all-completed list open.`,`Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.`,`One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {"action":"upsert","tasks":[{"id":3,"status":"completed"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.`,`Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a "ref" and list the ref string in place of an id: [{"ref":"api","subject":"Design the API"},{"subject":"Implement the API","blockedBy":["api"]}]. A ref must be declared before it is used. Cycles are rejected.`,`upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.`,`Before assigning work, call subagent with {"action":"agents"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.`,`Assign every unblocked pending task, including implementation tasks. Use assignments[] for every assign call, including one task: {"action":"assign","assignments":[{"id":1,"agent":"researcher"}]}. Put all assign-time fields — including model, inlineAgent, instructions, relevantFiles, priorFindings, and context — inside each assignments[] entry; assign has no top-level single-task form. For two or more independent ready tasks, use one native batch instead of repeated calls. Do not wrap repeated task assign calls in multi_tool; assignments[] reduces tool overhead and returns one indexed result. Do not use a direct subagent run for work already represented in the shared task list, so ownership and terminal results stay visible.`,`A batched assign applies each entry independently. Successful entries are already running if another entry fails; retry only failed entries after correcting them, and never resend successful entries.`,`Hand over what you already know when you assign. Pass relevantFiles with the paths you have actually read or located for that task, and priorFindings with the facts you established: symbol names, call sites, the approach you picked, what you ruled out. A fresh-context child starts with none of your context and will otherwise spend most of its run re-reading the repo. It treats this verified pack as satisfying initial context exploration, reads known paths directly, and widens discovery only for a concrete missing dependency. Send at most a dozen files and only ones you really opened — a guessed path costs the child more than an omitted one — and keep priorFindings to a few lines of facts, not directives.`,`After assigning work, continue non-overlapping parent work or end your turn. Do not poll or duplicate delegated scope.`,`When a delegated task completes and unblocks another task, repeat agent discovery if needed and assign that newly eligible task promptly. Do not poll in a loop. Completion notifications wake the parent session.`,`If a child asks for a decision through intercom, or an assignment fails to start for another concrete issue, respond, rescope, or retry explicitly. Do not silently leave the task pending.`,`assign refuses tasks that are blocked, already delegated, or completed. Resolve blockers first. Use {"action":"cancel","id":3} to stop a running delegation; the task returns to pending.`,`Doom Task records delegated lifecycle and results on the shared task. The child does not update task status directly. Read the completion or failure result before deciding what to do next.`,`The task list is scoped to this session tree: delegated subagents share it, while unrelated sessions start empty. It persists for later inspection until retention cleanup.`,`Subject must be short and imperative (e.g. 'Research existing tool'); description is long-form detail written when you plan the task, and the delegated brief is that description plus the assign-time instructions, relevantFiles and priorFindings. Put durable scope in description and what you learned while exploring in the assign-time pack — do not repeat one in the other.`];exports.DEFAULT_PROMPT_GUIDELINES=e;
|
|
2
2
|
//# sourceMappingURL=promptGuidelines.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptGuidelines.cjs","names":[],"sources":["../../../src/commands/task/promptGuidelines.ts"],"sourcesContent":["export const DEFAULT_PROMPT_GUIDELINES: string[] = [\n 'Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.',\n 'Capture a whole plan in one call: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research existing tool\"},{\"subject\":\"Write the reducer\"},{\"subject\":\"Add tests\"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.',\n 'Do not batch progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.',\n 'Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status \"failed\" or keep it in_progress and add a new task for the blocker in the same upsert.',\n 'When every non-deleted task is completed, review the full task list once more and call task {\"action\":\"clear\"} to close it. Do not leave an all-completed list open.',\n \"Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.\",\n 'One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {\"action\":\"upsert\",\"tasks\":[{\"id\":3,\"status\":\"completed\"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.',\n 'Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a \"ref\" and list the ref string in place of an id: [{\"ref\":\"api\",\"subject\":\"Design the API\"},{\"subject\":\"Implement the API\",\"blockedBy\":[\"api\"]}]. A ref must be declared before it is used. Cycles are rejected.',\n 'upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.',\n 'Before assigning work, call subagent with {\"action\":\"agents\"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.',\n 'Assign every unblocked pending task
|
|
1
|
+
{"version":3,"file":"promptGuidelines.cjs","names":[],"sources":["../../../src/commands/task/promptGuidelines.ts"],"sourcesContent":["export const DEFAULT_PROMPT_GUIDELINES: string[] = [\n 'Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.',\n 'Capture a whole plan in one call: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research existing tool\"},{\"subject\":\"Write the reducer\"},{\"subject\":\"Add tests\"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.',\n 'Do not batch parent progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: upsert batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Native assignments[] fan-out is separate from progress reporting. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.',\n 'Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status \"failed\" or keep it in_progress and add a new task for the blocker in the same upsert.',\n 'When every non-deleted task is completed, review the full task list once more and call task {\"action\":\"clear\"} to close it. Do not leave an all-completed list open.',\n \"Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.\",\n 'One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {\"action\":\"upsert\",\"tasks\":[{\"id\":3,\"status\":\"completed\"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.',\n 'Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a \"ref\" and list the ref string in place of an id: [{\"ref\":\"api\",\"subject\":\"Design the API\"},{\"subject\":\"Implement the API\",\"blockedBy\":[\"api\"]}]. A ref must be declared before it is used. Cycles are rejected.',\n 'upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.',\n 'Before assigning work, call subagent with {\"action\":\"agents\"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.',\n 'Assign every unblocked pending task, including implementation tasks. Use assignments[] for every assign call, including one task: {\"action\":\"assign\",\"assignments\":[{\"id\":1,\"agent\":\"researcher\"}]}. Put all assign-time fields — including model, inlineAgent, instructions, relevantFiles, priorFindings, and context — inside each assignments[] entry; assign has no top-level single-task form. For two or more independent ready tasks, use one native batch instead of repeated calls. Do not wrap repeated task assign calls in multi_tool; assignments[] reduces tool overhead and returns one indexed result. Do not use a direct subagent run for work already represented in the shared task list, so ownership and terminal results stay visible.',\n 'A batched assign applies each entry independently. Successful entries are already running if another entry fails; retry only failed entries after correcting them, and never resend successful entries.',\n 'Hand over what you already know when you assign. Pass relevantFiles with the paths you have actually read or located for that task, and priorFindings with the facts you established: symbol names, call sites, the approach you picked, what you ruled out. A fresh-context child starts with none of your context and will otherwise spend most of its run re-reading the repo. It treats this verified pack as satisfying initial context exploration, reads known paths directly, and widens discovery only for a concrete missing dependency. Send at most a dozen files and only ones you really opened — a guessed path costs the child more than an omitted one — and keep priorFindings to a few lines of facts, not directives.',\n 'After assigning work, continue non-overlapping parent work or end your turn. Do not poll or duplicate delegated scope.',\n 'When a delegated task completes and unblocks another task, repeat agent discovery if needed and assign that newly eligible task promptly. Do not poll in a loop. Completion notifications wake the parent session.',\n 'If a child asks for a decision through intercom, or an assignment fails to start for another concrete issue, respond, rescope, or retry explicitly. Do not silently leave the task pending.',\n 'assign refuses tasks that are blocked, already delegated, or completed. Resolve blockers first. Use {\"action\":\"cancel\",\"id\":3} to stop a running delegation; the task returns to pending.',\n 'Doom Task records delegated lifecycle and results on the shared task. The child does not update task status directly. Read the completion or failure result before deciding what to do next.',\n 'The task list is scoped to this session tree: delegated subagents share it, while unrelated sessions start empty. It persists for later inspection until retention cleanup.',\n \"Subject must be short and imperative (e.g. 'Research existing tool'); description is long-form detail written when you plan the task, and the delegated brief is that description plus the assign-time instructions, relevantFiles and priorFindings. Put durable scope in description and what you learned while exploring in the assign-time pack — do not repeat one in the other.\",\n];\n"],"mappings":"AAAA,MAAa,EAAsC,CACjD,4NACA,6XACA,ukBACA,mNACA,uKACA,kPACA,qXACA,0fACA,qTACA,sRACA,iuBACA,0MACA,4sBACA,yHACA,qNACA,8LACA,4LACA,+LACA,8KACA,uXACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=["Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.",`Capture a whole plan in one call: {"action":"upsert","tasks":[{"subject":"Research existing tool"},{"subject":"Write the reducer"},{"subject":"Add tests"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.`,`Do not batch progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.`,`Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status "failed" or keep it in_progress and add a new task for the blocker in the same upsert.`,`When every non-deleted task is completed, review the full task list once more and call task {"action":"clear"} to close it. Do not leave an all-completed list open.`,`Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.`,`One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {"action":"upsert","tasks":[{"id":3,"status":"completed"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.`,`Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a "ref" and list the ref string in place of an id: [{"ref":"api","subject":"Design the API"},{"subject":"Implement the API","blockedBy":["api"]}]. A ref must be declared before it is used. Cycles are rejected.`,`upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.`,`Before assigning work, call subagent with {"action":"agents"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.`,`Assign every unblocked pending task
|
|
1
|
+
const e=["Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.",`Capture a whole plan in one call: {"action":"upsert","tasks":[{"subject":"Research existing tool"},{"subject":"Write the reducer"},{"subject":"Add tests"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.`,`Do not batch parent progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: upsert batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Native assignments[] fan-out is separate from progress reporting. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.`,`Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status "failed" or keep it in_progress and add a new task for the blocker in the same upsert.`,`When every non-deleted task is completed, review the full task list once more and call task {"action":"clear"} to close it. Do not leave an all-completed list open.`,`Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.`,`One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {"action":"upsert","tasks":[{"id":3,"status":"completed"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.`,`Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a "ref" and list the ref string in place of an id: [{"ref":"api","subject":"Design the API"},{"subject":"Implement the API","blockedBy":["api"]}]. A ref must be declared before it is used. Cycles are rejected.`,`upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.`,`Before assigning work, call subagent with {"action":"agents"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.`,`Assign every unblocked pending task, including implementation tasks. Use assignments[] for every assign call, including one task: {"action":"assign","assignments":[{"id":1,"agent":"researcher"}]}. Put all assign-time fields — including model, inlineAgent, instructions, relevantFiles, priorFindings, and context — inside each assignments[] entry; assign has no top-level single-task form. For two or more independent ready tasks, use one native batch instead of repeated calls. Do not wrap repeated task assign calls in multi_tool; assignments[] reduces tool overhead and returns one indexed result. Do not use a direct subagent run for work already represented in the shared task list, so ownership and terminal results stay visible.`,`A batched assign applies each entry independently. Successful entries are already running if another entry fails; retry only failed entries after correcting them, and never resend successful entries.`,`Hand over what you already know when you assign. Pass relevantFiles with the paths you have actually read or located for that task, and priorFindings with the facts you established: symbol names, call sites, the approach you picked, what you ruled out. A fresh-context child starts with none of your context and will otherwise spend most of its run re-reading the repo. It treats this verified pack as satisfying initial context exploration, reads known paths directly, and widens discovery only for a concrete missing dependency. Send at most a dozen files and only ones you really opened — a guessed path costs the child more than an omitted one — and keep priorFindings to a few lines of facts, not directives.`,`After assigning work, continue non-overlapping parent work or end your turn. Do not poll or duplicate delegated scope.`,`When a delegated task completes and unblocks another task, repeat agent discovery if needed and assign that newly eligible task promptly. Do not poll in a loop. Completion notifications wake the parent session.`,`If a child asks for a decision through intercom, or an assignment fails to start for another concrete issue, respond, rescope, or retry explicitly. Do not silently leave the task pending.`,`assign refuses tasks that are blocked, already delegated, or completed. Resolve blockers first. Use {"action":"cancel","id":3} to stop a running delegation; the task returns to pending.`,`Doom Task records delegated lifecycle and results on the shared task. The child does not update task status directly. Read the completion or failure result before deciding what to do next.`,`The task list is scoped to this session tree: delegated subagents share it, while unrelated sessions start empty. It persists for later inspection until retention cleanup.`,`Subject must be short and imperative (e.g. 'Research existing tool'); description is long-form detail written when you plan the task, and the delegated brief is that description plus the assign-time instructions, relevantFiles and priorFindings. Put durable scope in description and what you learned while exploring in the assign-time pack — do not repeat one in the other.`];export{e as DEFAULT_PROMPT_GUIDELINES};
|
|
2
2
|
//# sourceMappingURL=promptGuidelines.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptGuidelines.mjs","names":[],"sources":["../../../src/commands/task/promptGuidelines.ts"],"sourcesContent":["export const DEFAULT_PROMPT_GUIDELINES: string[] = [\n 'Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.',\n 'Capture a whole plan in one call: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research existing tool\"},{\"subject\":\"Write the reducer\"},{\"subject\":\"Add tests\"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.',\n 'Do not batch progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.',\n 'Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status \"failed\" or keep it in_progress and add a new task for the blocker in the same upsert.',\n 'When every non-deleted task is completed, review the full task list once more and call task {\"action\":\"clear\"} to close it. Do not leave an all-completed list open.',\n \"Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.\",\n 'One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {\"action\":\"upsert\",\"tasks\":[{\"id\":3,\"status\":\"completed\"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.',\n 'Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a \"ref\" and list the ref string in place of an id: [{\"ref\":\"api\",\"subject\":\"Design the API\"},{\"subject\":\"Implement the API\",\"blockedBy\":[\"api\"]}]. A ref must be declared before it is used. Cycles are rejected.',\n 'upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.',\n 'Before assigning work, call subagent with {\"action\":\"agents\"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.',\n 'Assign every unblocked pending task
|
|
1
|
+
{"version":3,"file":"promptGuidelines.mjs","names":[],"sources":["../../../src/commands/task/promptGuidelines.ts"],"sourcesContent":["export const DEFAULT_PROMPT_GUIDELINES: string[] = [\n 'Use `task` for work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.',\n 'Capture a whole plan in one call: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research existing tool\"},{\"subject\":\"Write the reducer\"},{\"subject\":\"Add tests\"}]}. Batch whenever you are writing the plan down — the initial list, a revised plan, or wiring dependencies across several tasks — because one call keeps ids and blockers consistent and shows the user the whole plan at once.',\n 'Do not batch parent progress. Mark a task in_progress with its own call BEFORE beginning work, and completed with its own call IMMEDIATELY when it is done. upsert accepts many tasks, but a batch of completions sent at the end of a turn is still wrong: upsert batching is for writing a plan down, single calls are for reporting progress, and the user watches the task list to see where you are. Native assignments[] fan-out is separate from progress reporting. Exactly one task should be in_progress for your own work; delegated tasks run in parallel and do not count against that.',\n 'Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors, use status \"failed\" or keep it in_progress and add a new task for the blocker in the same upsert.',\n 'When every non-deleted task is completed, review the full task list once more and call task {\"action\":\"clear\"} to close it. Do not leave an all-completed list open.',\n \"Status is a state machine: pending → in_progress → completed, plus failed (recoverable, can go back to pending or in_progress) and deleted as a tombstone. Pass activeForm (present-continuous, e.g. 'writing tests') when marking in_progress.\",\n 'One call does both: an entry with an id changes that task, an entry without an id creates one. To change status, upsert the task by id, e.g. {\"action\":\"upsert\",\"tasks\":[{\"id\":3,\"status\":\"completed\"}]}. Never omit the id when you meant to change an existing task — an entry with no id creates a new one instead. An entry that carries an id and no other field is rejected.',\n 'Use blockedBy for dependencies (A is blocked by B). On an entry with no id pass blockedBy as the initial set; on an entry with an id use addBlockedBy / removeBlockedBy (additive merge, do not resend the full array). To depend on a task created earlier in the SAME call, give that earlier entry a \"ref\" and list the ref string in place of an id: [{\"ref\":\"api\",\"subject\":\"Design the API\"},{\"subject\":\"Implement the API\",\"blockedBy\":[\"api\"]}]. A ref must be declared before it is used. Cycles are rejected.',\n 'upsert applies each entry independently: the entries that pass are committed and the failures are reported with their array index. A failed entry changed nothing, so resend only the corrected failures — never resend the whole call, because an already-applied entry with no id would create a duplicate task.',\n 'Before assigning work, call subagent with {\"action\":\"agents\"} and match each task to an exact discovered agent name. Prefer a discovered general-purpose write-capable agent such as delegate or worker when no specialist fits. Use a focused inlineAgent only for read-only work.',\n 'Assign every unblocked pending task, including implementation tasks. Use assignments[] for every assign call, including one task: {\"action\":\"assign\",\"assignments\":[{\"id\":1,\"agent\":\"researcher\"}]}. Put all assign-time fields — including model, inlineAgent, instructions, relevantFiles, priorFindings, and context — inside each assignments[] entry; assign has no top-level single-task form. For two or more independent ready tasks, use one native batch instead of repeated calls. Do not wrap repeated task assign calls in multi_tool; assignments[] reduces tool overhead and returns one indexed result. Do not use a direct subagent run for work already represented in the shared task list, so ownership and terminal results stay visible.',\n 'A batched assign applies each entry independently. Successful entries are already running if another entry fails; retry only failed entries after correcting them, and never resend successful entries.',\n 'Hand over what you already know when you assign. Pass relevantFiles with the paths you have actually read or located for that task, and priorFindings with the facts you established: symbol names, call sites, the approach you picked, what you ruled out. A fresh-context child starts with none of your context and will otherwise spend most of its run re-reading the repo. It treats this verified pack as satisfying initial context exploration, reads known paths directly, and widens discovery only for a concrete missing dependency. Send at most a dozen files and only ones you really opened — a guessed path costs the child more than an omitted one — and keep priorFindings to a few lines of facts, not directives.',\n 'After assigning work, continue non-overlapping parent work or end your turn. Do not poll or duplicate delegated scope.',\n 'When a delegated task completes and unblocks another task, repeat agent discovery if needed and assign that newly eligible task promptly. Do not poll in a loop. Completion notifications wake the parent session.',\n 'If a child asks for a decision through intercom, or an assignment fails to start for another concrete issue, respond, rescope, or retry explicitly. Do not silently leave the task pending.',\n 'assign refuses tasks that are blocked, already delegated, or completed. Resolve blockers first. Use {\"action\":\"cancel\",\"id\":3} to stop a running delegation; the task returns to pending.',\n 'Doom Task records delegated lifecycle and results on the shared task. The child does not update task status directly. Read the completion or failure result before deciding what to do next.',\n 'The task list is scoped to this session tree: delegated subagents share it, while unrelated sessions start empty. It persists for later inspection until retention cleanup.',\n \"Subject must be short and imperative (e.g. 'Research existing tool'); description is long-form detail written when you plan the task, and the delegated brief is that description plus the assign-time instructions, relevantFiles and priorFindings. Put durable scope in description and what you learned while exploring in the assign-time pack — do not repeat one in the other.\",\n];\n"],"mappings":"AAAA,MAAa,EAAsC,CACjD,4NACA,6XACA,ukBACA,mNACA,uKACA,kPACA,qXACA,0fACA,qTACA,sRACA,iuBACA,0MACA,4sBACA,yHACA,qNACA,8LACA,4LACA,+LACA,8KACA,uXACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const e=require("../../services/store/taskGraph.cjs"),t=`All tasks are completed. Review the full task list once more, then close it with task {"action":"clear"}.`,n=`The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.`,r=`No task changed, so the whole call can be resent once corrected.`;function
|
|
2
|
-
`)}function
|
|
3
|
-
`)}function l(
|
|
4
|
-
`)}case`
|
|
5
|
-
`)}case`
|
|
1
|
+
const e=require("../../services/store/taskGraph.cjs"),t=`All tasks are completed. Review the full task list once more, then close it with task {"action":"clear"}.`,n=`The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.`,r=`No task changed, so the whole call can be resent once corrected.`,i=`Successful assignments are already running. Retry only the failed entries after correcting their task state or arguments; do not resend successful entries.`;function a(e){if(e.length===1)return e[0].message;let t=e.filter(e=>e.ok).length,n=e.length-t,r=[`Assigned ${t}/${e.length} tasks${n>0?`; ${n} failed`:``}.`,...e.map(e=>e.ok?`- [${e.index}] Delegated #${e.id} to ${e.agent}`:`- [${e.index}] Failed #${e.id} → ${e.agent}: ${e.message}`)];return n>0&&t>0&&r.push(``,i),n===0&&r.push(``,`All assignments are running independently in the background. Continue non-overlapping work, or end your turn.`),r.join(`
|
|
2
|
+
`)}function o(e){let t=e.blockedBy?.length?` ⛓ ${e.blockedBy.map(e=>`#${e}`).join(`,`)}`:``,n=e.status===`in_progress`&&e.activeForm?` (${e.activeForm})`:``,r=e.delegation&&e.delegation.state!==`cancelled`?` [${e.delegation.agent}]`:``;return`[${e.status}] #${e.id} ${e.subject}${n}${r}${t}`}function s(e){let t=e.delegation;if(!t)return[];let n=[` delegated to: ${t.agent} (${t.state})`];return t.model&&n.push(` model: ${t.model}`),t.result?.error&&n.push(` error: ${t.result.error}`),t.result?.outputPath&&n.push(` output file: ${t.result.outputPath}`),t.result?.output&&n.push(` output: ${t.result.output}`),n}function c(t,n){let r=e.deriveBlocks(n.tasks).get(t.id)??[],i=[`#${t.id} [${t.status}] ${t.subject}`];return t.description&&i.push(` description: ${t.description}`),t.activeForm&&i.push(` activeForm: ${t.activeForm}`),t.blockedBy?.length&&i.push(` blockedBy: ${t.blockedBy.map(e=>`#${e}`).join(`, `)}`),r.length&&i.push(` blocks: ${r.map(e=>`#${e}`).join(`, `)}`),t.owner&&i.push(` owner: ${t.owner}`),i.push(...s(t)),i.join(`
|
|
3
|
+
`)}function l(e){switch(e.kind){case`created`:{let t=e.ref?` (ref "${e.ref}")`:``,n=e.blockedBy?.length?` — blocked by ${e.blockedBy.map(e=>`#${e}`).join(`, `)}`:``;return`Created #${e.id}${t}: ${e.subject} (${e.status})${n}`}case`updated`:{let t=e.fromStatus===e.toStatus?``:` (${e.fromStatus} -> ${e.toStatus})`;return`Updated #${e.id}${t}`}case`unchanged`:return`No change: #${e.id} already matches the requested values (status: ${e.status})`;case`failed`:return`Failed${e.id===void 0?``:` #${e.id}`}: ${e.message}`}}function u(e){return e.items.length===1?e.items[0].kind===`failed`?e.items[0].message:`no entry was applied`:[`no entry was applied.`,...e.items.map(e=>`- [${e.index}] ${l(e)}`),r].join(`
|
|
4
|
+
`)}function d(r,i){switch(r.kind){case`upsert`:{let a=r.items.length===1?[l(r.items[0])]:[`Upsert applied ${r.applied}/${r.items.length} entries${r.failed>0?`; ${r.failed} failed`:``}.`,...r.items.map(e=>`- [${e.index}] ${l(e)}`),...r.failed>0?[``,n]:[]];return r.applied>0&&e.isTaskListComplete(i.tasks)&&a.push(t),a.join(`
|
|
5
|
+
`)}case`delete`:return`Deleted #${r.id}: ${r.subject}`;case`clear`:return`Closed task list (cleared ${r.count} tasks)`;case`list`:{let e=i.tasks;return r.includeDeleted||(e=e.filter(e=>e.status!==`deleted`)),r.statusFilter&&(e=e.filter(e=>e.status===r.statusFilter)),e.length===0?`No tasks`:e.map(o).join(`
|
|
6
|
+
`)}case`get`:return c(r.task,i);case`error`:return`Error: ${r.message}`}}function f(e,t,n,r){return{content:[{type:`text`,text:d(r,n)}],details:{action:e,params:t,tasks:n.tasks,nextId:n.nextId,rev:n.rev,...r.kind===`error`?{error:r.message}:{},...r.kind===`upsert`?{upsert:{applied:r.items.flatMap(e=>e.kind===`failed`?[]:[e.id]),failed:r.failed}}:{}}}}function p(e,t,n,r){return{content:[{type:`text`,text:n}],details:{action:`assign`,params:e,tasks:t.tasks,nextId:t.nextId,rev:t.rev,assignment:r}}}function m(e,t,n,r,i){return{content:[{type:`text`,text:i?`Error: ${i}`:r}],details:{action:e,params:t,tasks:n.tasks,nextId:n.nextId,rev:n.rev,...i?{error:i}:{}}}}exports.MSG_ALL_COMPLETE_CLEAR=t,exports.MSG_ASSIGN_PARTIAL=i,exports.MSG_UPSERT_NONE_APPLIED=r,exports.MSG_UPSERT_PARTIAL=n,exports.buildAssignmentResult=p,exports.buildTextResult=m,exports.buildToolResult=f,exports.formatAssignmentResults=a,exports.formatContent=d,exports.formatUpsertFailureText=u;
|
|
6
7
|
//# sourceMappingURL=responseEnvelope.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseEnvelope.cjs","names":["deriveBlocks","isTaskListComplete"],"sources":["../../../src/commands/task/responseEnvelope.ts"],"sourcesContent":["import type { Op } from '../../services/store/reducer.ts';\nimport { deriveBlocks, isTaskListComplete } from '../../services/store/taskGraph.ts';\nimport type {\n Task,\n TaskAction,\n TaskDetails,\n TaskDocument,\n TaskMutationParams,\n UpsertItemOutcome,\n} from '../../services/store/types.ts';\n\nexport const MSG_ALL_COMPLETE_CLEAR =\n 'All tasks are completed. Review the full task list once more, then close it with task {\"action\":\"clear\"}.';\n\n/**\n * Steering for a mixed batch. Unlike a batch of spawned subagents, a failed\n * entry here had no side effect at all, so retrying the failures is the safe\n * move and the model must be told so or it will do nothing. The hazard is the\n * other half: resending an applied create would make a second task.\n */\nexport const MSG_UPSERT_PARTIAL =\n 'The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.';\n\nexport const MSG_UPSERT_NONE_APPLIED = 'No task changed, so the whole call can be resent once corrected.';\n\n/** `[status] #id subject (activeForm) [agent] ⛓ #dep` — the `list` line format. */\nfunction formatListLine(task: Task): string {\n const block = task.blockedBy?.length ? ` ⛓ ${task.blockedBy.map((id) => `#${id}`).join(',')}` : '';\n const form = task.status === 'in_progress' && task.activeForm ? ` (${task.activeForm})` : '';\n const delegated = task.delegation && task.delegation.state !== 'cancelled' ? ` [${task.delegation.agent}]` : '';\n return `[${task.status}] #${task.id} ${task.subject}${form}${delegated}${block}`;\n}\n\nfunction formatDelegationLines(task: Task): string[] {\n const delegation = task.delegation;\n if (!delegation) return [];\n\n const lines = [` delegated to: ${delegation.agent} (${delegation.state})`];\n if (delegation.model) lines.push(` model: ${delegation.model}`);\n if (delegation.result?.error) lines.push(` error: ${delegation.result.error}`);\n if (delegation.result?.outputPath) lines.push(` output file: ${delegation.result.outputPath}`);\n if (delegation.result?.output) lines.push(` output: ${delegation.result.output}`);\n return lines;\n}\n\nfunction formatGetLines(task: Task, document: TaskDocument): string {\n const blocks = deriveBlocks(document.tasks).get(task.id) ?? [];\n const lines = [`#${task.id} [${task.status}] ${task.subject}`];\n if (task.description) lines.push(` description: ${task.description}`);\n if (task.activeForm) lines.push(` activeForm: ${task.activeForm}`);\n if (task.blockedBy?.length) lines.push(` blockedBy: ${task.blockedBy.map((id) => `#${id}`).join(', ')}`);\n if (blocks.length) lines.push(` blocks: ${blocks.map((id) => `#${id}`).join(', ')}`);\n if (task.owner) lines.push(` owner: ${task.owner}`);\n lines.push(...formatDelegationLines(task));\n return lines.join('\\n');\n}\n\n/** One entry's outcome. Batch lines prefix this with `- [n] `. */\nfunction formatUpsertItem(item: UpsertItemOutcome): string {\n switch (item.kind) {\n case 'created': {\n const ref = item.ref ? ` (ref \"${item.ref}\")` : '';\n const deps = item.blockedBy?.length ? ` — blocked by ${item.blockedBy.map((id) => `#${id}`).join(', ')}` : '';\n return `Created #${item.id}${ref}: ${item.subject} (${item.status})${deps}`;\n }\n case 'updated': {\n const transition = item.fromStatus === item.toStatus ? '' : ` (${item.fromStatus} -> ${item.toStatus})`;\n return `Updated #${item.id}${transition}`;\n }\n case 'unchanged':\n return `No change: #${item.id} already matches the requested values (status: ${item.status})`;\n case 'failed':\n return `Failed${item.id === undefined ? '' : ` #${item.id}`}: ${item.message}`;\n }\n}\n\n/**\n * The thrown message when an upsert applied nothing. Kept separate from\n * `formatContent` because the caller wraps it in the actionable Options block\n * rather than returning it as a successful result.\n */\nexport function formatUpsertFailureText(op: Extract<Op, { kind: 'upsert' }>): string {\n if (op.items.length === 1) return op.items[0].kind === 'failed' ? op.items[0].message : 'no entry was applied';\n return [\n 'no entry was applied.',\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n MSG_UPSERT_NONE_APPLIED,\n ].join('\\n');\n}\n\n/**\n * Pure formatter: `(op, document) -> string`. The switch is closed over `Op`,\n * so a new reducer variant fails to compile until it is handled here.\n */\nexport function formatContent(op: Op, document: TaskDocument): string {\n switch (op.kind) {\n case 'upsert': {\n // A batch of one is the common case and must not read like a bulk\n // report, so it keeps the exact single-line shape it has always had.\n const lines =\n op.items.length === 1\n ? [formatUpsertItem(op.items[0])]\n : [\n `Upsert applied ${op.applied}/${op.items.length} entries${op.failed > 0 ? `; ${op.failed} failed` : ''}.`,\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n ...(op.failed > 0 ? ['', MSG_UPSERT_PARTIAL] : []),\n ];\n // Once, last, and only when something landed: emitting it per entry\n // would repeat it for every completion in a batch.\n if (op.applied > 0 && isTaskListComplete(document.tasks)) lines.push(MSG_ALL_COMPLETE_CLEAR);\n return lines.join('\\n');\n }\n case 'delete':\n return `Deleted #${op.id}: ${op.subject}`;\n case 'clear':\n return `Closed task list (cleared ${op.count} tasks)`;\n case 'list': {\n let view = document.tasks;\n if (!op.includeDeleted) view = view.filter((task) => task.status !== 'deleted');\n if (op.statusFilter) view = view.filter((task) => task.status === op.statusFilter);\n return view.length === 0 ? 'No tasks' : view.map(formatListLine).join('\\n');\n }\n case 'get':\n return formatGetLines(op.task, document);\n case 'error':\n return `Error: ${op.message}`;\n }\n}\n\nexport interface ToolResult {\n content: Array<{ type: 'text'; text: string }>;\n details: TaskDetails;\n}\n\n/** Build the LLM-facing envelope. `details` carries the post-mutation snapshot. */\nexport function buildToolResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n op: Op,\n): ToolResult {\n return {\n content: [{ type: 'text', text: formatContent(op, document) }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(op.kind === 'error' ? { error: op.message } : {}),\n // Deliberately no `error` on a partial success: renderResult treats\n // `details.error` as total failure and would hide the rows for the\n // entries that did land.\n ...(op.kind === 'upsert'\n ? {\n upsert: {\n applied: op.items.flatMap((item) => (item.kind === 'failed' ? [] : [item.id])),\n failed: op.failed,\n },\n }\n : {}),\n },\n };\n}\n\n/** Envelope for delegation actions, which do not flow through the reducer. */\nexport function buildTextResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n text: string,\n error?: string,\n): ToolResult {\n return {\n content: [{ type: 'text', text: error ? `Error: ${error}` : text }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(error ? { error } : {}),\n },\n };\n}\n"],"mappings":"sDAWa,EACX,4GAQW,EACX,0OAEW,EAA0B,mEAGvC,SAAS,EAAe,EAAoB,CAC1C,IA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gB,EACd,EACA,EACA,EACA,EACA,EACY,CACZ,MAAO,CACL,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,EAAQ,UAAU,IAAU,CAAK,CAAC,EAClE,QAAS,CACP,SACQ,SACR,MAAO,EAAS,MAChB,OAAQ,EAAS,OACjB,IAAK,EAAS,IACd,GAAI,EAAQ,CAAE,OAAM,EAAI,CAAC,CAC3B,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"responseEnvelope.cjs","names":["deriveBlocks","isTaskListComplete"],"sources":["../../../src/commands/task/responseEnvelope.ts"],"sourcesContent":["import type { Op } from '../../services/store/reducer.ts';\nimport { deriveBlocks, isTaskListComplete } from '../../services/store/taskGraph.ts';\nimport type {\n AssignmentSummary,\n Task,\n TaskAction,\n TaskDetails,\n TaskDocument,\n TaskMutationParams,\n UpsertItemOutcome,\n} from '../../services/store/types.ts';\n\nexport const MSG_ALL_COMPLETE_CLEAR =\n 'All tasks are completed. Review the full task list once more, then close it with task {\"action\":\"clear\"}.';\n\n/**\n * Steering for a mixed batch. Unlike a batch of spawned subagents, a failed\n * entry here had no side effect at all, so retrying the failures is the safe\n * move and the model must be told so or it will do nothing. The hazard is the\n * other half: resending an applied create would make a second task.\n */\nexport const MSG_UPSERT_PARTIAL =\n 'The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.';\n\nexport const MSG_UPSERT_NONE_APPLIED = 'No task changed, so the whole call can be resent once corrected.';\n\nexport const MSG_ASSIGN_PARTIAL =\n 'Successful assignments are already running. Retry only the failed entries after correcting their task state or arguments; do not resend successful entries.';\n\nexport interface AssignmentItemResult {\n index: number;\n id: number;\n agent: string;\n ok: boolean;\n message: string;\n}\n\n/** LLM-facing report for a native assignment batch. */\nexport function formatAssignmentResults(items: readonly AssignmentItemResult[]): string {\n if (items.length === 1) return items[0].message;\n\n const succeeded = items.filter((item) => item.ok).length;\n const failed = items.length - succeeded;\n const lines = [\n `Assigned ${succeeded}/${items.length} tasks${failed > 0 ? `; ${failed} failed` : ''}.`,\n ...items.map((item) =>\n item.ok\n ? `- [${item.index}] Delegated #${item.id} to ${item.agent}`\n : `- [${item.index}] Failed #${item.id} → ${item.agent}: ${item.message}`,\n ),\n ];\n\n if (failed > 0 && succeeded > 0) lines.push('', MSG_ASSIGN_PARTIAL);\n if (failed === 0) {\n lines.push(\n '',\n 'All assignments are running independently in the background. Continue non-overlapping work, or end your turn.',\n );\n }\n return lines.join('\\n');\n}\n\n/** `[status] #id subject (activeForm) [agent] ⛓ #dep` — the `list` line format. */\nfunction formatListLine(task: Task): string {\n const block = task.blockedBy?.length ? ` ⛓ ${task.blockedBy.map((id) => `#${id}`).join(',')}` : '';\n const form = task.status === 'in_progress' && task.activeForm ? ` (${task.activeForm})` : '';\n const delegated = task.delegation && task.delegation.state !== 'cancelled' ? ` [${task.delegation.agent}]` : '';\n return `[${task.status}] #${task.id} ${task.subject}${form}${delegated}${block}`;\n}\n\nfunction formatDelegationLines(task: Task): string[] {\n const delegation = task.delegation;\n if (!delegation) return [];\n\n const lines = [` delegated to: ${delegation.agent} (${delegation.state})`];\n if (delegation.model) lines.push(` model: ${delegation.model}`);\n if (delegation.result?.error) lines.push(` error: ${delegation.result.error}`);\n if (delegation.result?.outputPath) lines.push(` output file: ${delegation.result.outputPath}`);\n if (delegation.result?.output) lines.push(` output: ${delegation.result.output}`);\n return lines;\n}\n\nfunction formatGetLines(task: Task, document: TaskDocument): string {\n const blocks = deriveBlocks(document.tasks).get(task.id) ?? [];\n const lines = [`#${task.id} [${task.status}] ${task.subject}`];\n if (task.description) lines.push(` description: ${task.description}`);\n if (task.activeForm) lines.push(` activeForm: ${task.activeForm}`);\n if (task.blockedBy?.length) lines.push(` blockedBy: ${task.blockedBy.map((id) => `#${id}`).join(', ')}`);\n if (blocks.length) lines.push(` blocks: ${blocks.map((id) => `#${id}`).join(', ')}`);\n if (task.owner) lines.push(` owner: ${task.owner}`);\n lines.push(...formatDelegationLines(task));\n return lines.join('\\n');\n}\n\n/** One entry's outcome. Batch lines prefix this with `- [n] `. */\nfunction formatUpsertItem(item: UpsertItemOutcome): string {\n switch (item.kind) {\n case 'created': {\n const ref = item.ref ? ` (ref \"${item.ref}\")` : '';\n const deps = item.blockedBy?.length ? ` — blocked by ${item.blockedBy.map((id) => `#${id}`).join(', ')}` : '';\n return `Created #${item.id}${ref}: ${item.subject} (${item.status})${deps}`;\n }\n case 'updated': {\n const transition = item.fromStatus === item.toStatus ? '' : ` (${item.fromStatus} -> ${item.toStatus})`;\n return `Updated #${item.id}${transition}`;\n }\n case 'unchanged':\n return `No change: #${item.id} already matches the requested values (status: ${item.status})`;\n case 'failed':\n return `Failed${item.id === undefined ? '' : ` #${item.id}`}: ${item.message}`;\n }\n}\n\n/**\n * The thrown message when an upsert applied nothing. Kept separate from\n * `formatContent` because the caller wraps it in the actionable Options block\n * rather than returning it as a successful result.\n */\nexport function formatUpsertFailureText(op: Extract<Op, { kind: 'upsert' }>): string {\n if (op.items.length === 1) return op.items[0].kind === 'failed' ? op.items[0].message : 'no entry was applied';\n return [\n 'no entry was applied.',\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n MSG_UPSERT_NONE_APPLIED,\n ].join('\\n');\n}\n\n/**\n * Pure formatter: `(op, document) -> string`. The switch is closed over `Op`,\n * so a new reducer variant fails to compile until it is handled here.\n */\nexport function formatContent(op: Op, document: TaskDocument): string {\n switch (op.kind) {\n case 'upsert': {\n // A batch of one is the common case and must not read like a bulk\n // report, so it keeps the exact single-line shape it has always had.\n const lines =\n op.items.length === 1\n ? [formatUpsertItem(op.items[0])]\n : [\n `Upsert applied ${op.applied}/${op.items.length} entries${op.failed > 0 ? `; ${op.failed} failed` : ''}.`,\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n ...(op.failed > 0 ? ['', MSG_UPSERT_PARTIAL] : []),\n ];\n // Once, last, and only when something landed: emitting it per entry\n // would repeat it for every completion in a batch.\n if (op.applied > 0 && isTaskListComplete(document.tasks)) lines.push(MSG_ALL_COMPLETE_CLEAR);\n return lines.join('\\n');\n }\n case 'delete':\n return `Deleted #${op.id}: ${op.subject}`;\n case 'clear':\n return `Closed task list (cleared ${op.count} tasks)`;\n case 'list': {\n let view = document.tasks;\n if (!op.includeDeleted) view = view.filter((task) => task.status !== 'deleted');\n if (op.statusFilter) view = view.filter((task) => task.status === op.statusFilter);\n return view.length === 0 ? 'No tasks' : view.map(formatListLine).join('\\n');\n }\n case 'get':\n return formatGetLines(op.task, document);\n case 'error':\n return `Error: ${op.message}`;\n }\n}\n\nexport interface ToolResult {\n content: Array<{ type: 'text'; text: string }>;\n details: TaskDetails;\n}\n\n/** Build the LLM-facing envelope. `details` carries the post-mutation snapshot. */\nexport function buildToolResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n op: Op,\n): ToolResult {\n return {\n content: [{ type: 'text', text: formatContent(op, document) }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(op.kind === 'error' ? { error: op.message } : {}),\n // Deliberately no `error` on a partial success: renderResult treats\n // `details.error` as total failure and would hide the rows for the\n // entries that did land.\n ...(op.kind === 'upsert'\n ? {\n upsert: {\n applied: op.items.flatMap((item) => (item.kind === 'failed' ? [] : [item.id])),\n failed: op.failed,\n },\n }\n : {}),\n },\n };\n}\n\n/** Envelope for a native assignment batch, including ids used by the consolidated TUI result. */\nexport function buildAssignmentResult(\n params: TaskMutationParams,\n document: TaskDocument,\n text: string,\n assignment: AssignmentSummary,\n): ToolResult {\n return {\n content: [{ type: 'text', text }],\n details: {\n action: 'assign',\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n assignment,\n },\n };\n}\n\n/** Envelope for delegation actions, which do not flow through the reducer. */\nexport function buildTextResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n text: string,\n error?: string,\n): ToolResult {\n return {\n content: [{ type: 'text', text: error ? `Error: ${error}` : text }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(error ? { error } : {}),\n },\n };\n}\n"],"mappings":"sDAYa,EACX,4GAQW,EACX,0OAEW,EAA0B,mEAE1B,EACX,8JAWF,SAAgB,EAAwB,EAAgD,CACtF,GAAI,EAAM,SAAW,EAAG,OAAO,EAAM,EAAE,CAAC,QAExC,IAAM,EAAY,EAAM,OAAQ,GAAS,EAAK,EAAE,CAAC,CAAC,OAC5C,EAAS,EAAM,OAAS,EACxB,EAAQ,CACZ,YAAY,EAAU,GAAG,EAAM,OAAO,QAAQ,EAAS,EAAI,KAAK,EAAO,SAAW,GAAG,GACrF,GAAG,EAAM,IAAK,GACZ,EAAK,GACD,MAAM,EAAK,MAAM,eAAe,EAAK,GAAG,MAAM,EAAK,QACnD,MAAM,EAAK,MAAM,YAAY,EAAK,GAAG,KAAK,EAAK,MAAM,IAAI,EAAK,SACpE,CACF,EASA,OAPI,EAAS,GAAK,EAAY,GAAG,EAAM,KAAK,GAAI,CAAkB,EAC9D,IAAW,GACb,EAAM,KACJ,GACA,+GACF,EAEK,EAAM,KAAK;CAAI,CACxB,CAGA,SAAS,EAAe,EAAoB,CAC1C,IAAM,EAAQ,EAAK,WAAW,OAAS,MAAM,EAAK,UAAU,IAAK,GAAO,IAAI,GAAI,CAAC,CAAC,KAAK,GAAG,IAAM,GAC1F,EAAO,EAAK,SAAW,eAAiB,EAAK,WAAa,KAAK,EAAK,WAAW,GAAK,GACpF,EAAY,EAAK,YAAc,EAAK,WAAW,QAAU,YAAc,KAAK,EAAK,WAAW,MAAM,GAAK,GAC7G,MAAO,IAAI,EAAK,OAAO,KAAK,EAAK,GAAG,GAAG,EAAK,UAAU,IAAO,IAAY,GAC3E,CAEA,SAAS,EAAsB,EAAsB,CACnD,IAAM,EAAa,EAAK,WACxB,GAAI,CAAC,EAAY,MAAO,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AE,OAAM,EAAI,CAAC,CAC3B,CACF,CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TaskAction, TaskDetails, TaskDocument, TaskMutationParams } from "../../services/store/types.cjs";
|
|
1
|
+
import { AssignmentSummary, TaskAction, TaskDetails, TaskDocument, TaskMutationParams } from "../../services/store/types.cjs";
|
|
2
2
|
import { Op } from "../../services/store/reducer.cjs";
|
|
3
3
|
//#region src/commands/task/responseEnvelope.d.ts
|
|
4
4
|
declare const MSG_ALL_COMPLETE_CLEAR = "All tasks are completed. Review the full task list once more, then close it with task {\"action\":\"clear\"}.";
|
|
@@ -10,6 +10,16 @@ declare const MSG_ALL_COMPLETE_CLEAR = "All tasks are completed. Review the full
|
|
|
10
10
|
*/
|
|
11
11
|
declare const MSG_UPSERT_PARTIAL = "The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.";
|
|
12
12
|
declare const MSG_UPSERT_NONE_APPLIED = "No task changed, so the whole call can be resent once corrected.";
|
|
13
|
+
declare const MSG_ASSIGN_PARTIAL = "Successful assignments are already running. Retry only the failed entries after correcting their task state or arguments; do not resend successful entries.";
|
|
14
|
+
interface AssignmentItemResult {
|
|
15
|
+
index: number;
|
|
16
|
+
id: number;
|
|
17
|
+
agent: string;
|
|
18
|
+
ok: boolean;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
/** LLM-facing report for a native assignment batch. */
|
|
22
|
+
declare function formatAssignmentResults(items: readonly AssignmentItemResult[]): string;
|
|
13
23
|
/**
|
|
14
24
|
* The thrown message when an upsert applied nothing. Kept separate from
|
|
15
25
|
* `formatContent` because the caller wraps it in the actionable Options block
|
|
@@ -32,8 +42,10 @@ interface ToolResult {
|
|
|
32
42
|
}
|
|
33
43
|
/** Build the LLM-facing envelope. `details` carries the post-mutation snapshot. */
|
|
34
44
|
declare function buildToolResult(action: TaskAction, params: TaskMutationParams, document: TaskDocument, op: Op): ToolResult;
|
|
45
|
+
/** Envelope for a native assignment batch, including ids used by the consolidated TUI result. */
|
|
46
|
+
declare function buildAssignmentResult(params: TaskMutationParams, document: TaskDocument, text: string, assignment: AssignmentSummary): ToolResult;
|
|
35
47
|
/** Envelope for delegation actions, which do not flow through the reducer. */
|
|
36
48
|
declare function buildTextResult(action: TaskAction, params: TaskMutationParams, document: TaskDocument, text: string, error?: string): ToolResult;
|
|
37
49
|
//#endregion
|
|
38
|
-
export { MSG_ALL_COMPLETE_CLEAR, MSG_UPSERT_NONE_APPLIED, MSG_UPSERT_PARTIAL, ToolResult, buildTextResult, buildToolResult, formatContent, formatUpsertFailureText };
|
|
50
|
+
export { AssignmentItemResult, MSG_ALL_COMPLETE_CLEAR, MSG_ASSIGN_PARTIAL, MSG_UPSERT_NONE_APPLIED, MSG_UPSERT_PARTIAL, ToolResult, buildAssignmentResult, buildTextResult, buildToolResult, formatAssignmentResults, formatContent, formatUpsertFailureText };
|
|
39
51
|
//# sourceMappingURL=responseEnvelope.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseEnvelope.d.cts","names":[],"sources":["../../../src/commands/task/responseEnvelope.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"responseEnvelope.d.cts","names":[],"sources":["../../../src/commands/task/responseEnvelope.ts"],"mappings":";;;cAYa;;;;;;;cASA;cAGA;cAEA;UAGI;EACf;EACA;EACA;EACA;EACA;;;iBAIc,wBAAwB,gBAAgB;;;;;;iBAgFxC,wBAAwB,IAAI,QAAQ;EAAM;;;;;;iBAa1C,cAAc,IAAI,IAAI,UAAU;UAmC/B;EACf,SAAS;IAAQ;IAAc;;EAC/B,SAAS;;;iBAIK,gBACd,QAAQ,YACR,QAAQ,oBACR,UAAU,cACV,IAAI,KACH;;iBA0Ba,sBACd,QAAQ,oBACR,UAAU,cACV,cACA,YAAY,oBACX;;iBAea,gBACd,QAAQ,YACR,QAAQ,oBACR,UAAU,cACV,cACA,iBACC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TaskAction, TaskDetails, TaskDocument, TaskMutationParams } from "../../services/store/types.mjs";
|
|
1
|
+
import { AssignmentSummary, TaskAction, TaskDetails, TaskDocument, TaskMutationParams } from "../../services/store/types.mjs";
|
|
2
2
|
import { Op } from "../../services/store/reducer.mjs";
|
|
3
3
|
//#region src/commands/task/responseEnvelope.d.ts
|
|
4
4
|
declare const MSG_ALL_COMPLETE_CLEAR = "All tasks are completed. Review the full task list once more, then close it with task {\"action\":\"clear\"}.";
|
|
@@ -10,6 +10,16 @@ declare const MSG_ALL_COMPLETE_CLEAR = "All tasks are completed. Review the full
|
|
|
10
10
|
*/
|
|
11
11
|
declare const MSG_UPSERT_PARTIAL = "The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.";
|
|
12
12
|
declare const MSG_UPSERT_NONE_APPLIED = "No task changed, so the whole call can be resent once corrected.";
|
|
13
|
+
declare const MSG_ASSIGN_PARTIAL = "Successful assignments are already running. Retry only the failed entries after correcting their task state or arguments; do not resend successful entries.";
|
|
14
|
+
interface AssignmentItemResult {
|
|
15
|
+
index: number;
|
|
16
|
+
id: number;
|
|
17
|
+
agent: string;
|
|
18
|
+
ok: boolean;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
/** LLM-facing report for a native assignment batch. */
|
|
22
|
+
declare function formatAssignmentResults(items: readonly AssignmentItemResult[]): string;
|
|
13
23
|
/**
|
|
14
24
|
* The thrown message when an upsert applied nothing. Kept separate from
|
|
15
25
|
* `formatContent` because the caller wraps it in the actionable Options block
|
|
@@ -32,8 +42,10 @@ interface ToolResult {
|
|
|
32
42
|
}
|
|
33
43
|
/** Build the LLM-facing envelope. `details` carries the post-mutation snapshot. */
|
|
34
44
|
declare function buildToolResult(action: TaskAction, params: TaskMutationParams, document: TaskDocument, op: Op): ToolResult;
|
|
45
|
+
/** Envelope for a native assignment batch, including ids used by the consolidated TUI result. */
|
|
46
|
+
declare function buildAssignmentResult(params: TaskMutationParams, document: TaskDocument, text: string, assignment: AssignmentSummary): ToolResult;
|
|
35
47
|
/** Envelope for delegation actions, which do not flow through the reducer. */
|
|
36
48
|
declare function buildTextResult(action: TaskAction, params: TaskMutationParams, document: TaskDocument, text: string, error?: string): ToolResult;
|
|
37
49
|
//#endregion
|
|
38
|
-
export { MSG_ALL_COMPLETE_CLEAR, MSG_UPSERT_NONE_APPLIED, MSG_UPSERT_PARTIAL, ToolResult, buildTextResult, buildToolResult, formatContent, formatUpsertFailureText };
|
|
50
|
+
export { AssignmentItemResult, MSG_ALL_COMPLETE_CLEAR, MSG_ASSIGN_PARTIAL, MSG_UPSERT_NONE_APPLIED, MSG_UPSERT_PARTIAL, ToolResult, buildAssignmentResult, buildTextResult, buildToolResult, formatAssignmentResults, formatContent, formatUpsertFailureText };
|
|
39
51
|
//# sourceMappingURL=responseEnvelope.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseEnvelope.d.mts","names":[],"sources":["../../../src/commands/task/responseEnvelope.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"responseEnvelope.d.mts","names":[],"sources":["../../../src/commands/task/responseEnvelope.ts"],"mappings":";;;cAYa;;;;;;;cASA;cAGA;cAEA;UAGI;EACf;EACA;EACA;EACA;EACA;;;iBAIc,wBAAwB,gBAAgB;;;;;;iBAgFxC,wBAAwB,IAAI,QAAQ;EAAM;;;;;;iBAa1C,cAAc,IAAI,IAAI,UAAU;UAmC/B;EACf,SAAS;IAAQ;IAAc;;EAC/B,SAAS;;;iBAIK,gBACd,QAAQ,YACR,QAAQ,oBACR,UAAU,cACV,IAAI,KACH;;iBA0Ba,sBACd,QAAQ,oBACR,UAAU,cACV,cACA,YAAY,oBACX;;iBAea,gBACd,QAAQ,YACR,QAAQ,oBACR,UAAU,cACV,cACA,iBACC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import{deriveBlocks as e,isTaskListComplete as t}from"../../services/store/taskGraph.mjs";const n=`All tasks are completed. Review the full task list once more, then close it with task {"action":"clear"}.`,r=`The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.`,i=`No task changed, so the whole call can be resent once corrected.`;function
|
|
2
|
-
`)}function
|
|
3
|
-
`)}function u(e
|
|
4
|
-
`)}case`
|
|
5
|
-
`)}case`
|
|
1
|
+
import{deriveBlocks as e,isTaskListComplete as t}from"../../services/store/taskGraph.mjs";const n=`All tasks are completed. Review the full task list once more, then close it with task {"action":"clear"}.`,r=`The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.`,i=`No task changed, so the whole call can be resent once corrected.`,a=`Successful assignments are already running. Retry only the failed entries after correcting their task state or arguments; do not resend successful entries.`;function o(e){if(e.length===1)return e[0].message;let t=e.filter(e=>e.ok).length,n=e.length-t,r=[`Assigned ${t}/${e.length} tasks${n>0?`; ${n} failed`:``}.`,...e.map(e=>e.ok?`- [${e.index}] Delegated #${e.id} to ${e.agent}`:`- [${e.index}] Failed #${e.id} → ${e.agent}: ${e.message}`)];return n>0&&t>0&&r.push(``,a),n===0&&r.push(``,`All assignments are running independently in the background. Continue non-overlapping work, or end your turn.`),r.join(`
|
|
2
|
+
`)}function s(e){let t=e.blockedBy?.length?` ⛓ ${e.blockedBy.map(e=>`#${e}`).join(`,`)}`:``,n=e.status===`in_progress`&&e.activeForm?` (${e.activeForm})`:``,r=e.delegation&&e.delegation.state!==`cancelled`?` [${e.delegation.agent}]`:``;return`[${e.status}] #${e.id} ${e.subject}${n}${r}${t}`}function c(e){let t=e.delegation;if(!t)return[];let n=[` delegated to: ${t.agent} (${t.state})`];return t.model&&n.push(` model: ${t.model}`),t.result?.error&&n.push(` error: ${t.result.error}`),t.result?.outputPath&&n.push(` output file: ${t.result.outputPath}`),t.result?.output&&n.push(` output: ${t.result.output}`),n}function l(t,n){let r=e(n.tasks).get(t.id)??[],i=[`#${t.id} [${t.status}] ${t.subject}`];return t.description&&i.push(` description: ${t.description}`),t.activeForm&&i.push(` activeForm: ${t.activeForm}`),t.blockedBy?.length&&i.push(` blockedBy: ${t.blockedBy.map(e=>`#${e}`).join(`, `)}`),r.length&&i.push(` blocks: ${r.map(e=>`#${e}`).join(`, `)}`),t.owner&&i.push(` owner: ${t.owner}`),i.push(...c(t)),i.join(`
|
|
3
|
+
`)}function u(e){switch(e.kind){case`created`:{let t=e.ref?` (ref "${e.ref}")`:``,n=e.blockedBy?.length?` — blocked by ${e.blockedBy.map(e=>`#${e}`).join(`, `)}`:``;return`Created #${e.id}${t}: ${e.subject} (${e.status})${n}`}case`updated`:{let t=e.fromStatus===e.toStatus?``:` (${e.fromStatus} -> ${e.toStatus})`;return`Updated #${e.id}${t}`}case`unchanged`:return`No change: #${e.id} already matches the requested values (status: ${e.status})`;case`failed`:return`Failed${e.id===void 0?``:` #${e.id}`}: ${e.message}`}}function d(e){return e.items.length===1?e.items[0].kind===`failed`?e.items[0].message:`no entry was applied`:[`no entry was applied.`,...e.items.map(e=>`- [${e.index}] ${u(e)}`),i].join(`
|
|
4
|
+
`)}function f(e,i){switch(e.kind){case`upsert`:{let a=e.items.length===1?[u(e.items[0])]:[`Upsert applied ${e.applied}/${e.items.length} entries${e.failed>0?`; ${e.failed} failed`:``}.`,...e.items.map(e=>`- [${e.index}] ${u(e)}`),...e.failed>0?[``,r]:[]];return e.applied>0&&t(i.tasks)&&a.push(n),a.join(`
|
|
5
|
+
`)}case`delete`:return`Deleted #${e.id}: ${e.subject}`;case`clear`:return`Closed task list (cleared ${e.count} tasks)`;case`list`:{let t=i.tasks;return e.includeDeleted||(t=t.filter(e=>e.status!==`deleted`)),e.statusFilter&&(t=t.filter(t=>t.status===e.statusFilter)),t.length===0?`No tasks`:t.map(s).join(`
|
|
6
|
+
`)}case`get`:return l(e.task,i);case`error`:return`Error: ${e.message}`}}function p(e,t,n,r){return{content:[{type:`text`,text:f(r,n)}],details:{action:e,params:t,tasks:n.tasks,nextId:n.nextId,rev:n.rev,...r.kind===`error`?{error:r.message}:{},...r.kind===`upsert`?{upsert:{applied:r.items.flatMap(e=>e.kind===`failed`?[]:[e.id]),failed:r.failed}}:{}}}}function m(e,t,n,r){return{content:[{type:`text`,text:n}],details:{action:`assign`,params:e,tasks:t.tasks,nextId:t.nextId,rev:t.rev,assignment:r}}}function h(e,t,n,r,i){return{content:[{type:`text`,text:i?`Error: ${i}`:r}],details:{action:e,params:t,tasks:n.tasks,nextId:n.nextId,rev:n.rev,...i?{error:i}:{}}}}export{n as MSG_ALL_COMPLETE_CLEAR,a as MSG_ASSIGN_PARTIAL,i as MSG_UPSERT_NONE_APPLIED,r as MSG_UPSERT_PARTIAL,m as buildAssignmentResult,h as buildTextResult,p as buildToolResult,o as formatAssignmentResults,f as formatContent,d as formatUpsertFailureText};
|
|
6
7
|
//# sourceMappingURL=responseEnvelope.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseEnvelope.mjs","names":[],"sources":["../../../src/commands/task/responseEnvelope.ts"],"sourcesContent":["import type { Op } from '../../services/store/reducer.ts';\nimport { deriveBlocks, isTaskListComplete } from '../../services/store/taskGraph.ts';\nimport type {\n Task,\n TaskAction,\n TaskDetails,\n TaskDocument,\n TaskMutationParams,\n UpsertItemOutcome,\n} from '../../services/store/types.ts';\n\nexport const MSG_ALL_COMPLETE_CLEAR =\n 'All tasks are completed. Review the full task list once more, then close it with task {\"action\":\"clear\"}.';\n\n/**\n * Steering for a mixed batch. Unlike a batch of spawned subagents, a failed\n * entry here had no side effect at all, so retrying the failures is the safe\n * move and the model must be told so or it will do nothing. The hazard is the\n * other half: resending an applied create would make a second task.\n */\nexport const MSG_UPSERT_PARTIAL =\n 'The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.';\n\nexport const MSG_UPSERT_NONE_APPLIED = 'No task changed, so the whole call can be resent once corrected.';\n\n/** `[status] #id subject (activeForm) [agent] ⛓ #dep` — the `list` line format. */\nfunction formatListLine(task: Task): string {\n const block = task.blockedBy?.length ? ` ⛓ ${task.blockedBy.map((id) => `#${id}`).join(',')}` : '';\n const form = task.status === 'in_progress' && task.activeForm ? ` (${task.activeForm})` : '';\n const delegated = task.delegation && task.delegation.state !== 'cancelled' ? ` [${task.delegation.agent}]` : '';\n return `[${task.status}] #${task.id} ${task.subject}${form}${delegated}${block}`;\n}\n\nfunction formatDelegationLines(task: Task): string[] {\n const delegation = task.delegation;\n if (!delegation) return [];\n\n const lines = [` delegated to: ${delegation.agent} (${delegation.state})`];\n if (delegation.model) lines.push(` model: ${delegation.model}`);\n if (delegation.result?.error) lines.push(` error: ${delegation.result.error}`);\n if (delegation.result?.outputPath) lines.push(` output file: ${delegation.result.outputPath}`);\n if (delegation.result?.output) lines.push(` output: ${delegation.result.output}`);\n return lines;\n}\n\nfunction formatGetLines(task: Task, document: TaskDocument): string {\n const blocks = deriveBlocks(document.tasks).get(task.id) ?? [];\n const lines = [`#${task.id} [${task.status}] ${task.subject}`];\n if (task.description) lines.push(` description: ${task.description}`);\n if (task.activeForm) lines.push(` activeForm: ${task.activeForm}`);\n if (task.blockedBy?.length) lines.push(` blockedBy: ${task.blockedBy.map((id) => `#${id}`).join(', ')}`);\n if (blocks.length) lines.push(` blocks: ${blocks.map((id) => `#${id}`).join(', ')}`);\n if (task.owner) lines.push(` owner: ${task.owner}`);\n lines.push(...formatDelegationLines(task));\n return lines.join('\\n');\n}\n\n/** One entry's outcome. Batch lines prefix this with `- [n] `. */\nfunction formatUpsertItem(item: UpsertItemOutcome): string {\n switch (item.kind) {\n case 'created': {\n const ref = item.ref ? ` (ref \"${item.ref}\")` : '';\n const deps = item.blockedBy?.length ? ` — blocked by ${item.blockedBy.map((id) => `#${id}`).join(', ')}` : '';\n return `Created #${item.id}${ref}: ${item.subject} (${item.status})${deps}`;\n }\n case 'updated': {\n const transition = item.fromStatus === item.toStatus ? '' : ` (${item.fromStatus} -> ${item.toStatus})`;\n return `Updated #${item.id}${transition}`;\n }\n case 'unchanged':\n return `No change: #${item.id} already matches the requested values (status: ${item.status})`;\n case 'failed':\n return `Failed${item.id === undefined ? '' : ` #${item.id}`}: ${item.message}`;\n }\n}\n\n/**\n * The thrown message when an upsert applied nothing. Kept separate from\n * `formatContent` because the caller wraps it in the actionable Options block\n * rather than returning it as a successful result.\n */\nexport function formatUpsertFailureText(op: Extract<Op, { kind: 'upsert' }>): string {\n if (op.items.length === 1) return op.items[0].kind === 'failed' ? op.items[0].message : 'no entry was applied';\n return [\n 'no entry was applied.',\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n MSG_UPSERT_NONE_APPLIED,\n ].join('\\n');\n}\n\n/**\n * Pure formatter: `(op, document) -> string`. The switch is closed over `Op`,\n * so a new reducer variant fails to compile until it is handled here.\n */\nexport function formatContent(op: Op, document: TaskDocument): string {\n switch (op.kind) {\n case 'upsert': {\n // A batch of one is the common case and must not read like a bulk\n // report, so it keeps the exact single-line shape it has always had.\n const lines =\n op.items.length === 1\n ? [formatUpsertItem(op.items[0])]\n : [\n `Upsert applied ${op.applied}/${op.items.length} entries${op.failed > 0 ? `; ${op.failed} failed` : ''}.`,\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n ...(op.failed > 0 ? ['', MSG_UPSERT_PARTIAL] : []),\n ];\n // Once, last, and only when something landed: emitting it per entry\n // would repeat it for every completion in a batch.\n if (op.applied > 0 && isTaskListComplete(document.tasks)) lines.push(MSG_ALL_COMPLETE_CLEAR);\n return lines.join('\\n');\n }\n case 'delete':\n return `Deleted #${op.id}: ${op.subject}`;\n case 'clear':\n return `Closed task list (cleared ${op.count} tasks)`;\n case 'list': {\n let view = document.tasks;\n if (!op.includeDeleted) view = view.filter((task) => task.status !== 'deleted');\n if (op.statusFilter) view = view.filter((task) => task.status === op.statusFilter);\n return view.length === 0 ? 'No tasks' : view.map(formatListLine).join('\\n');\n }\n case 'get':\n return formatGetLines(op.task, document);\n case 'error':\n return `Error: ${op.message}`;\n }\n}\n\nexport interface ToolResult {\n content: Array<{ type: 'text'; text: string }>;\n details: TaskDetails;\n}\n\n/** Build the LLM-facing envelope. `details` carries the post-mutation snapshot. */\nexport function buildToolResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n op: Op,\n): ToolResult {\n return {\n content: [{ type: 'text', text: formatContent(op, document) }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(op.kind === 'error' ? { error: op.message } : {}),\n // Deliberately no `error` on a partial success: renderResult treats\n // `details.error` as total failure and would hide the rows for the\n // entries that did land.\n ...(op.kind === 'upsert'\n ? {\n upsert: {\n applied: op.items.flatMap((item) => (item.kind === 'failed' ? [] : [item.id])),\n failed: op.failed,\n },\n }\n : {}),\n },\n };\n}\n\n/** Envelope for delegation actions, which do not flow through the reducer. */\nexport function buildTextResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n text: string,\n error?: string,\n): ToolResult {\n return {\n content: [{ type: 'text', text: error ? `Error: ${error}` : text }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(error ? { error } : {}),\n },\n };\n}\n"],"mappings":"0FAWA,MAAa,EACX,4GAQW,EACX,0OAEW,EAA0B,mEAGvC,SAAS,EAAe,EAAoB,CAC1C,IAAM,EAAQ,EAAK,WAAW,OAAS,MAAM,EAAK,UAAU,IAAK,GAAO,IAAI,GAAI,CAAC,CAAC,KAAK,GAAG,IAAM,GAC1F,EAAO,EAAK,SAAW,eAAiB,EAAK,WAAa,KAAK,EAAK,WAAW,GAAK,GACpF,EAAY,EAAK,YAAc,EAAK,WAAW,QAAU,YAAc,KAAK,EAAK,WAAW,MAAM,GAA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
|
+
{"version":3,"file":"responseEnvelope.mjs","names":[],"sources":["../../../src/commands/task/responseEnvelope.ts"],"sourcesContent":["import type { Op } from '../../services/store/reducer.ts';\nimport { deriveBlocks, isTaskListComplete } from '../../services/store/taskGraph.ts';\nimport type {\n AssignmentSummary,\n Task,\n TaskAction,\n TaskDetails,\n TaskDocument,\n TaskMutationParams,\n UpsertItemOutcome,\n} from '../../services/store/types.ts';\n\nexport const MSG_ALL_COMPLETE_CLEAR =\n 'All tasks are completed. Review the full task list once more, then close it with task {\"action\":\"clear\"}.';\n\n/**\n * Steering for a mixed batch. Unlike a batch of spawned subagents, a failed\n * entry here had no side effect at all, so retrying the failures is the safe\n * move and the model must be told so or it will do nothing. The hazard is the\n * other half: resending an applied create would make a second task.\n */\nexport const MSG_UPSERT_PARTIAL =\n 'The applied entries are committed. Resend only the failed entries, corrected — a failed entry changed nothing, so a corrected retry is safe. Do not resend an entry that already applied: an entry without an id creates a second task.';\n\nexport const MSG_UPSERT_NONE_APPLIED = 'No task changed, so the whole call can be resent once corrected.';\n\nexport const MSG_ASSIGN_PARTIAL =\n 'Successful assignments are already running. Retry only the failed entries after correcting their task state or arguments; do not resend successful entries.';\n\nexport interface AssignmentItemResult {\n index: number;\n id: number;\n agent: string;\n ok: boolean;\n message: string;\n}\n\n/** LLM-facing report for a native assignment batch. */\nexport function formatAssignmentResults(items: readonly AssignmentItemResult[]): string {\n if (items.length === 1) return items[0].message;\n\n const succeeded = items.filter((item) => item.ok).length;\n const failed = items.length - succeeded;\n const lines = [\n `Assigned ${succeeded}/${items.length} tasks${failed > 0 ? `; ${failed} failed` : ''}.`,\n ...items.map((item) =>\n item.ok\n ? `- [${item.index}] Delegated #${item.id} to ${item.agent}`\n : `- [${item.index}] Failed #${item.id} → ${item.agent}: ${item.message}`,\n ),\n ];\n\n if (failed > 0 && succeeded > 0) lines.push('', MSG_ASSIGN_PARTIAL);\n if (failed === 0) {\n lines.push(\n '',\n 'All assignments are running independently in the background. Continue non-overlapping work, or end your turn.',\n );\n }\n return lines.join('\\n');\n}\n\n/** `[status] #id subject (activeForm) [agent] ⛓ #dep` — the `list` line format. */\nfunction formatListLine(task: Task): string {\n const block = task.blockedBy?.length ? ` ⛓ ${task.blockedBy.map((id) => `#${id}`).join(',')}` : '';\n const form = task.status === 'in_progress' && task.activeForm ? ` (${task.activeForm})` : '';\n const delegated = task.delegation && task.delegation.state !== 'cancelled' ? ` [${task.delegation.agent}]` : '';\n return `[${task.status}] #${task.id} ${task.subject}${form}${delegated}${block}`;\n}\n\nfunction formatDelegationLines(task: Task): string[] {\n const delegation = task.delegation;\n if (!delegation) return [];\n\n const lines = [` delegated to: ${delegation.agent} (${delegation.state})`];\n if (delegation.model) lines.push(` model: ${delegation.model}`);\n if (delegation.result?.error) lines.push(` error: ${delegation.result.error}`);\n if (delegation.result?.outputPath) lines.push(` output file: ${delegation.result.outputPath}`);\n if (delegation.result?.output) lines.push(` output: ${delegation.result.output}`);\n return lines;\n}\n\nfunction formatGetLines(task: Task, document: TaskDocument): string {\n const blocks = deriveBlocks(document.tasks).get(task.id) ?? [];\n const lines = [`#${task.id} [${task.status}] ${task.subject}`];\n if (task.description) lines.push(` description: ${task.description}`);\n if (task.activeForm) lines.push(` activeForm: ${task.activeForm}`);\n if (task.blockedBy?.length) lines.push(` blockedBy: ${task.blockedBy.map((id) => `#${id}`).join(', ')}`);\n if (blocks.length) lines.push(` blocks: ${blocks.map((id) => `#${id}`).join(', ')}`);\n if (task.owner) lines.push(` owner: ${task.owner}`);\n lines.push(...formatDelegationLines(task));\n return lines.join('\\n');\n}\n\n/** One entry's outcome. Batch lines prefix this with `- [n] `. */\nfunction formatUpsertItem(item: UpsertItemOutcome): string {\n switch (item.kind) {\n case 'created': {\n const ref = item.ref ? ` (ref \"${item.ref}\")` : '';\n const deps = item.blockedBy?.length ? ` — blocked by ${item.blockedBy.map((id) => `#${id}`).join(', ')}` : '';\n return `Created #${item.id}${ref}: ${item.subject} (${item.status})${deps}`;\n }\n case 'updated': {\n const transition = item.fromStatus === item.toStatus ? '' : ` (${item.fromStatus} -> ${item.toStatus})`;\n return `Updated #${item.id}${transition}`;\n }\n case 'unchanged':\n return `No change: #${item.id} already matches the requested values (status: ${item.status})`;\n case 'failed':\n return `Failed${item.id === undefined ? '' : ` #${item.id}`}: ${item.message}`;\n }\n}\n\n/**\n * The thrown message when an upsert applied nothing. Kept separate from\n * `formatContent` because the caller wraps it in the actionable Options block\n * rather than returning it as a successful result.\n */\nexport function formatUpsertFailureText(op: Extract<Op, { kind: 'upsert' }>): string {\n if (op.items.length === 1) return op.items[0].kind === 'failed' ? op.items[0].message : 'no entry was applied';\n return [\n 'no entry was applied.',\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n MSG_UPSERT_NONE_APPLIED,\n ].join('\\n');\n}\n\n/**\n * Pure formatter: `(op, document) -> string`. The switch is closed over `Op`,\n * so a new reducer variant fails to compile until it is handled here.\n */\nexport function formatContent(op: Op, document: TaskDocument): string {\n switch (op.kind) {\n case 'upsert': {\n // A batch of one is the common case and must not read like a bulk\n // report, so it keeps the exact single-line shape it has always had.\n const lines =\n op.items.length === 1\n ? [formatUpsertItem(op.items[0])]\n : [\n `Upsert applied ${op.applied}/${op.items.length} entries${op.failed > 0 ? `; ${op.failed} failed` : ''}.`,\n ...op.items.map((item) => `- [${item.index}] ${formatUpsertItem(item)}`),\n ...(op.failed > 0 ? ['', MSG_UPSERT_PARTIAL] : []),\n ];\n // Once, last, and only when something landed: emitting it per entry\n // would repeat it for every completion in a batch.\n if (op.applied > 0 && isTaskListComplete(document.tasks)) lines.push(MSG_ALL_COMPLETE_CLEAR);\n return lines.join('\\n');\n }\n case 'delete':\n return `Deleted #${op.id}: ${op.subject}`;\n case 'clear':\n return `Closed task list (cleared ${op.count} tasks)`;\n case 'list': {\n let view = document.tasks;\n if (!op.includeDeleted) view = view.filter((task) => task.status !== 'deleted');\n if (op.statusFilter) view = view.filter((task) => task.status === op.statusFilter);\n return view.length === 0 ? 'No tasks' : view.map(formatListLine).join('\\n');\n }\n case 'get':\n return formatGetLines(op.task, document);\n case 'error':\n return `Error: ${op.message}`;\n }\n}\n\nexport interface ToolResult {\n content: Array<{ type: 'text'; text: string }>;\n details: TaskDetails;\n}\n\n/** Build the LLM-facing envelope. `details` carries the post-mutation snapshot. */\nexport function buildToolResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n op: Op,\n): ToolResult {\n return {\n content: [{ type: 'text', text: formatContent(op, document) }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(op.kind === 'error' ? { error: op.message } : {}),\n // Deliberately no `error` on a partial success: renderResult treats\n // `details.error` as total failure and would hide the rows for the\n // entries that did land.\n ...(op.kind === 'upsert'\n ? {\n upsert: {\n applied: op.items.flatMap((item) => (item.kind === 'failed' ? [] : [item.id])),\n failed: op.failed,\n },\n }\n : {}),\n },\n };\n}\n\n/** Envelope for a native assignment batch, including ids used by the consolidated TUI result. */\nexport function buildAssignmentResult(\n params: TaskMutationParams,\n document: TaskDocument,\n text: string,\n assignment: AssignmentSummary,\n): ToolResult {\n return {\n content: [{ type: 'text', text }],\n details: {\n action: 'assign',\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n assignment,\n },\n };\n}\n\n/** Envelope for delegation actions, which do not flow through the reducer. */\nexport function buildTextResult(\n action: TaskAction,\n params: TaskMutationParams,\n document: TaskDocument,\n text: string,\n error?: string,\n): ToolResult {\n return {\n content: [{ type: 'text', text: error ? `Error: ${error}` : text }],\n details: {\n action,\n params: params as Record<string, unknown>,\n tasks: document.tasks,\n nextId: document.nextId,\n rev: document.rev,\n ...(error ? { error } : {}),\n },\n };\n}\n"],"mappings":"0FAYA,MAAa,EACX,4GAQW,EACX,0OAEW,EAA0B,mEAE1B,EACX,8JAWF,SAAgB,EAAwB,EAAgD,CACtF,GAAI,EAAM,SAAW,EAAG,O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,KAAM,CAAQ,EACzC,IAAK,QACH,MAAO,UAAU,EAAG,SACxB,CACF,CAQA,SAAgB,EACd,EACA,EACA,EACA,EACY,CACZ,MAAO,CACL,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,EAAc,EAAI,CAAQ,CAAE,CAAC,EAC7D,QAAS,CACP,SACQ,SACR,MAAO,EAAS,MAChB,OAAQ,EAAS,OACjB,IAAK,EAAS,IACd,GAAI,EAAG,OAAS,QAAU,CAAE,MAAO,EAAG,OAAQ,EAAI,CAAC,EAInD,GAAI,EAAG,OAAS,SACZ,CACE,OAAQ,CACN,QAAS,EAAG,MAAM,QAAS,GAAU,EAAK,OAAS,SAAW,CAAC,EAAI,CAAC,EAAK,EAAE,CAAE,EAC7E,OAAQ,EAAG,MACb,CACF,EACA,CAAC,CACP,CACF,CACF,CAGA,SAAgB,EACd,EACA,EACA,EACA,EACY,CACZ,MAAO,CACL,QAAS,CAAC,CAAE,KAAM,OAAQ,MAAK,CAAC,EAChC,QAAS,CACP,OAAQ,SACA,SACR,MAAO,EAAS,MAChB,OAAQ,EAAS,OACjB,IAAK,EAAS,IACd,YACF,CACF,CACF,CAGA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACY,CACZ,MAAO,CACL,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,EAAQ,UAAU,IAAU,CAAK,CAAC,EAClE,QAAS,CACP,SACQ,SACR,MAAO,EAAS,MAChB,OAAQ,EAAS,OACjB,IAAK,EAAS,IACd,GAAI,EAAQ,CAAE,OAAM,EAAI,CAAC,CAC3B,CACF,CACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const e=require("../../adapters/telemetry/logSinkTelemetry.cjs"),t=require("../../schemas/task.cjs"),n=require("../../services/store/reducer.cjs"),r=require("../../tui/format.cjs"),i=require("./promptGuidelines.cjs"),a=require("./responseEnvelope.cjs"),o=`Manage a shared task list to track multi-step progress, and delegate tasks to subagents`,s=new Set([`upsert`,`list`,`get`,`delete`,`clear`]);var
|
|
2
|
-
`))}function
|
|
1
|
+
const e=require("../../adapters/telemetry/logSinkTelemetry.cjs"),t=require("../../schemas/task.cjs"),n=require("../../services/store/reducer.cjs"),r=require("../../tui/format.cjs"),i=require("./promptGuidelines.cjs"),a=require("./responseEnvelope.cjs"),o=`Manage a shared task list to track multi-step progress, and delegate tasks to subagents`,s=`tool.action`,c=`task.id`,l=new Set([`upsert`,`list`,`get`,`delete`,`clear`]);var u=class extends Error{};function d(e,t){return new u([`Task ${e} failed: ${t}`,``,`Options:`,`- List the task board and inspect the current ids, states, and blockers.`,`- Correct the arguments or state conflict, then retry once.`,`- Ask the user before cancelling work or changing dependencies to recover.`].join(`
|
|
2
|
+
`))}function f(e,n){let r=Object.keys(n).filter(r=>n[r]!==void 0&&!t.taskActionAcceptsField(e,r));if(r.length===0)return;let i=e===`upsert`?` ${t.MSG_UPSERT_FIELD_MISPLACED}`:``;throw d(e,`${e} does not accept ${r.join(`, `)}.${i}`)}function p(e){let t=e.assignments;if(!t||t.length===0)throw d(`assign`,`assign requires a non-empty assignments[] array`);return t}function m(e,t){return{agent:e.agent,inlineAgent:e.inlineAgent,instructions:e.instructions,relevantFiles:e.relevantFiles,priorFindings:e.priorFindings,model:e.model,context:e.context,signal:t}}async function h(t,n,r,i){let a=[];for(let[o,l]of n.entries()){let n;try{n=await t.assign(l.id,m(l,r))}catch(t){i?.error(e.TASK_EVENT.toolFailed,t,{[s]:`assign`,[c]:l.id}),n={ok:!1,message:t instanceof Error?t.message:String(t)}}a.push({index:o,id:l.id,agent:l.agent,...n})}return a}async function g(e,t,r){let{document:i,value:o}=await e.mutate(e=>{let i=n.applyTaskMutation(e,t,r);return{...n.isCommittingOp(i.op)?{document:i.document}:{},value:i}});if(o.op.kind===`error`)throw d(t,o.op.message);if(o.op.kind===`upsert`&&o.op.applied===0)throw d(t,a.formatUpsertFailureText(o.op));return a.buildToolResult(t,r,i,o.op)}function _(n,m){let{store:_,delegation:v}=m;n.registerTool({name:t.TOOL_NAME,label:t.TOOL_LABEL,description:`Manage a shared task list for tracking multi-step progress, and delegate tasks to subagents. Actions: upsert (write tasks — a tasks[] array where an entry with an id changes that task and an entry without an id creates one, so one call can capture a whole plan), list, get, delete (tombstone), clear (close/reset the list), assign (hand one or more tasks through assignments[] to named subagents that work in the background), cancel (stop a delegated run). upsert and assign apply entries independently: successes remain committed or delegated and failures are reported by array index. Batch a plan and independent assignments, but report progress one task at a time. Status: pending → in_progress → completed, plus failed and a deleted tombstone. The list is shared within the current session tree, including delegated subagents, while unrelated sessions start empty. Session stores persist until retention cleanup.`,promptSnippet:o,promptGuidelines:i.DEFAULT_PROMPT_GUIDELINES,parameters:t.TaskParamsSchema,renderShell:`self`,async execute(t,n,r,i,o){let y=n.action,b=n;try{if(f(y,b),l.has(y)){let e=await g(_,y,b);return m.onChange?.(),e}if(y===`assign`){let e=p(b),t=e[0],n=e.length===1&&t?`Delegating task #${t.id}...`:`Delegating ${e.length} tasks...`;i?.(a.buildTextResult(y,b,_.snapshot,n));let o=await h(v,e,r,m.report);m.onChange?.();let s=a.formatAssignmentResults(o),c=o.flatMap(e=>e.ok?[e.id]:[]);if(c.length===0)throw d(y,s);return a.buildAssignmentResult(b,_.snapshot,s,{assigned:c,failed:o.length-c.length})}i?.(a.buildTextResult(y,b,_.snapshot,`Requesting cancellation for task #${b.id??`unknown`}...`));let e=await v.cancel(b.id??NaN);if(m.onChange?.(),!e.ok)throw d(y,e.message);return a.buildTextResult(y,b,_.snapshot,e.message,void 0)}catch(t){throw m.report?.error(e.TASK_EVENT.toolFailed,t,{[s]:y,...b.id===void 0?{}:{[c]:b.id}}),t instanceof u?t:d(y,t instanceof Error?t.message:String(t))}},renderCall(e,t,n){return r.renderTaskCall(e,t,_.snapshot.tasks)},renderResult(e,t,n,i){return r.renderTaskResult(e,t,n)}})}exports.DEFAULT_PROMPT_GUIDELINES=i.DEFAULT_PROMPT_GUIDELINES,exports.DEFAULT_PROMPT_SNIPPET=o,exports.registerTaskTool=_;
|
|
3
3
|
//# sourceMappingURL=taskTool.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskTool.cjs","names":["taskActionAcceptsField","MSG_UPSERT_FIELD_MISPLACED","applyTaskMutation","isCommittingOp","formatUpsertFailureText","buildToolResult","TOOL_NAME","TOOL_LABEL","DEFAULT_PROMPT_GUIDELINES","TaskParamsSchema","buildTextResult","TASK_EVENT","renderTaskCall","renderTaskResult"],"sources":["../../../src/commands/task/taskTool.ts"],"sourcesContent":["import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';\nimport { TASK_EVENT, type TaskFailureReporter } from '../../adapters/telemetry/logSinkTelemetry.ts';\nimport {\n MSG_UPSERT_FIELD_MISPLACED,\n TaskParamsSchema,\n TOOL_LABEL,\n TOOL_NAME,\n taskActionAcceptsField,\n} from '../../schemas/task.ts';\nimport type { DelegationManager, DelegationOutcome } from '../../services/delegation/manager.ts';\nimport { applyTaskMutation, isCommittingOp, type ReducerAction } from '../../services/store/reducer.ts';\nimport type { TaskStore } from '../../services/store/taskStore.ts';\nimport type { TaskAction, TaskMutationParams } from '../../services/store/types.ts';\nimport { renderTaskCall, renderTaskResult } from '../../tui/format.ts';\nimport { DEFAULT_PROMPT_GUIDELINES } from './promptGuidelines.ts';\nimport { buildTextResult, buildToolResult, formatUpsertFailureText, type ToolResult } from './responseEnvelope.ts';\n\nexport { DEFAULT_PROMPT_GUIDELINES } from './promptGuidelines.ts';\n\nexport const DEFAULT_PROMPT_SNIPPET =\n 'Manage a shared task list to track multi-step progress, and delegate tasks to subagents';\n\nexport interface TaskToolDependencies {\n store: TaskStore;\n delegation: DelegationManager;\n onChange?: () => void;\n report?: TaskFailureReporter;\n}\n\nconst ACTION_ATTRIBUTE = 'tool.action';\nconst TASK_ID_ATTRIBUTE = 'task.id';\n\nconst REDUCER_ACTIONS = new Set<TaskAction>(['upsert', 'list', 'get', 'delete', 'clear']);\n\nclass TaskToolExecutionError extends Error {}\n\nfunction actionableTaskError(action: TaskAction, message: string): TaskToolExecutionError {\n return new TaskToolExecutionError(\n [\n `Task ${action} failed: ${message}`,\n '',\n 'Options:',\n '- List the task board and inspect the current ids, states, and blockers.',\n '- Correct the arguments or state conflict, then retry once.',\n '- Ask the user before cancelling work or changing dependencies to recover.',\n ].join('\\n'),\n );\n}\n\n/**\n * Reject a field that belongs to a different action.\n *\n * The params schema is flat and shared across every action, so this is the only\n * place `{\"action\":\"upsert\",\"id\":3}` can be caught — and it must be, because\n * the entry it carries has no id and would silently create a duplicate task.\n */\nfunction rejectStrayFields(action: TaskAction, params: TaskMutationParams): void {\n const stray = Object.keys(params).filter((key) => params[key] !== undefined && !taskActionAcceptsField(action, key));\n if (stray.length === 0) return;\n const hint = action === 'upsert' ? ` ${MSG_UPSERT_FIELD_MISPLACED}` : '';\n throw actionableTaskError(action, `${action} does not accept ${stray.join(', ')}.${hint}`);\n}\n\n/** Run an action through the reducer, persisting only when it produced a change. */\nasync function executeReducerAction(\n store: TaskStore,\n action: ReducerAction,\n params: TaskMutationParams,\n): Promise<ToolResult> {\n const { document, value } = await store.mutate((current) => {\n const result = applyTaskMutation(current, action, params);\n return {\n ...(isCommittingOp(result.op) ? { document: result.document } : {}),\n value: result,\n };\n });\n if (value.op.kind === 'error') throw actionableTaskError(action, value.op.message);\n // An upsert that applied nothing is a failed call: it wrote nothing and left\n // `rev` alone, so it must not read to the model as a success. A batch where\n // some entries landed returns normally — that is what partial apply means.\n if (value.op.kind === 'upsert' && value.op.applied === 0) {\n throw actionableTaskError(action, formatUpsertFailureText(value.op));\n }\n // `document` is the committed document, so `details.rev` matches what landed\n // on disk; `value.document` is the pre-write copy and lags by one.\n return buildToolResult(action, params, document, value.op);\n}\n\nexport function registerTaskTool(pi: ExtensionAPI, dependencies: TaskToolDependencies): void {\n const { store, delegation } = dependencies;\n\n pi.registerTool({\n name: TOOL_NAME,\n label: TOOL_LABEL,\n description:\n 'Manage a shared task list for tracking multi-step progress, and delegate tasks to subagents. Actions: upsert (write tasks — a tasks[] array where an entry with an id changes that task and an entry without an id creates one, so one call can capture a whole plan), list, get, delete (tombstone), clear (close/reset the list), assign (hand the task to a named subagent that works it in the background), cancel (stop a delegated run). upsert applies each entry independently: successes are committed and failures are reported by array index, and an entry can depend on a task created by an earlier entry in the same call via a ref. Batch when writing a plan down; report progress one task at a time. Status: pending → in_progress → completed, plus failed and a deleted tombstone. The list is shared within the current session tree, including delegated subagents, while unrelated sessions start empty. Session stores persist until retention cleanup.',\n promptSnippet: DEFAULT_PROMPT_SNIPPET,\n promptGuidelines: DEFAULT_PROMPT_GUIDELINES,\n parameters: TaskParamsSchema,\n // Task rows carry their own status colors. Owning the shell prevents Pi's\n // pending/success/error background fill from obscuring those row states.\n renderShell: 'self',\n\n async execute(_toolCallId, params, signal, onUpdate, _ctx) {\n const action = params.action as TaskAction;\n const mutationParams = params as TaskMutationParams;\n\n try {\n rejectStrayFields(action, mutationParams);\n if (REDUCER_ACTIONS.has(action)) {\n const result = await executeReducerAction(store, action as ReducerAction, mutationParams);\n dependencies.onChange?.();\n return result;\n }\n\n let outcome: DelegationOutcome;\n if (action === 'assign') {\n onUpdate?.(\n buildTextResult(\n action,\n mutationParams,\n store.snapshot,\n `Delegating task #${mutationParams.id ?? 'unknown'}...`,\n ),\n );\n outcome = await delegation.assign(mutationParams.id ?? Number.NaN, {\n agent: mutationParams.agent,\n inlineAgent: mutationParams.inlineAgent,\n instructions: mutationParams.instructions,\n relevantFiles: mutationParams.relevantFiles,\n priorFindings: mutationParams.priorFindings,\n model: mutationParams.model,\n context: mutationParams.context,\n signal,\n });\n } else {\n onUpdate?.(\n buildTextResult(\n action,\n mutationParams,\n store.snapshot,\n `Requesting cancellation for task #${mutationParams.id ?? 'unknown'}...`,\n ),\n );\n outcome = await delegation.cancel(mutationParams.id ?? Number.NaN);\n }\n\n dependencies.onChange?.();\n if (!outcome.ok) throw actionableTaskError(action, outcome.message);\n return buildTextResult(action, mutationParams, store.snapshot, outcome.message, undefined);\n } catch (error) {\n // Rethrown so pi still renders the failure to the model; recorded\n // because this is where a store fault becomes visible to the user.\n dependencies.report?.error(TASK_EVENT.toolFailed, error, {\n [ACTION_ATTRIBUTE]: action,\n ...(mutationParams.id === undefined ? {} : { [TASK_ID_ATTRIBUTE]: mutationParams.id }),\n });\n if (error instanceof TaskToolExecutionError) throw error;\n throw actionableTaskError(action, error instanceof Error ? error.message : String(error));\n }\n },\n\n // Render hooks receive no session identity, so they read the store snapshot\n // that the executing session last loaded. That is the foreground session's\n // own view, which is exactly what its transcript should show.\n renderCall(args, theme, _context) {\n return renderTaskCall(args as never, theme, store.snapshot.tasks);\n },\n\n renderResult(result, options, theme, _context) {\n return renderTaskResult(result, options, theme);\n },\n });\n}\n"],"mappings":"6PAmBa,EACX,0FAYI,EAAkB,IAAI,IAAgB,CAAC,SAAU,OAAQ,MAAO,SAAU,OAAO,CAAC,EAExF,IAAM,EAAN,cAAqC,KAAM,CAAC,EAE5C,SAAS,EAAoB,EAAoB,EAAyC,CACxF,OAAO,IAAI,EACT,CACE,QAAQ,EAAO,WAAW,IAC1B,GACA,WACA,2EACA,8DACA,4EACF,CAAC,CAAC,KAAK;CAAI,CACb,CACF,CASA,SAAS,EAAkB,EAAoB,EAAkC,CAC/E,IAAM,EAAQ,OAAO,KAAK,CAAM,CAAC,CAAC,OAAQ,GAAQ,EAAO,KAAS,IAAA,IAAa,CAACA,EAAAA,uBAAuB,EAAQ,CAAG,CAAC,EACnH,GAAI,EAAM,SAAW,EAAG,OACxB,IAAM,EAAO,IAAW,SAAW,IAAIC,EAAAA,6BAA+B,GACtE,MAAM,EAAoB,EAAQ,GAAG,EAAO,mBAAmB,EAAM,KAAK,IAAI,EAAE,GAAG,GAAM,CAC3F,CAGA,eAAe,EACb,EACA,EACA,EACqB,CACrB,GAAM,CAAE,WAAU,SAAU,MAAM,EAAM,OAAQ,GAAY,CAC1D,IAAM,EAASC,EAAAA,kBAAkB,EAAS,EAAQ,CAAM,EACxD,MAAO,CACL,GA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O,EAAe,IAAM,GAAU,GAGnE,EAAa,WAAW,EACpB,CAAC,EAAQ,GAAI,MAAM,EAAoB,EAAQ,EAAQ,OAAO,EAClE,OAAOA,EAAAA,gBAAgB,EAAQ,EAAgB,EAAM,SAAU,EAAQ,QAAS,IAAA,EAAS,CAC3F,OAAS,EAAO,CAQd,MALA,EAAa,QAAQ,MAAMC,EAAAA,WAAW,WAAY,EAAO,CACtD,cAAmB,EACpB,GAAI,EAAe,KAAO,IAAA,GAAY,CAAC,EAAI,CAAG,UAAoB,EAAe,EAAG,CACtF,CAAC,EACG,aAAiB,EAA8B,EAC7C,EAAoB,EAAQ,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,CAAC,CAC1F,CACF,EAKA,WAAW,EAAM,EAAO,EAAU,CAChC,OAAOC,EAAAA,eAAe,EAAe,EAAO,EAAM,SAAS,KAAK,CAClE,EAEA,aAAa,EAAQ,EAAS,EAAO,EAAU,CAC7C,OAAOC,EAAAA,iBAAiB,EAAQ,EAAS,CAAK,CAChD,CACF,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"taskTool.cjs","names":["taskActionAcceptsField","MSG_UPSERT_FIELD_MISPLACED","TASK_EVENT","applyTaskMutation","isCommittingOp","formatUpsertFailureText","buildToolResult","TOOL_NAME","TOOL_LABEL","DEFAULT_PROMPT_GUIDELINES","TaskParamsSchema","buildTextResult","formatAssignmentResults","buildAssignmentResult","renderTaskCall","renderTaskResult"],"sources":["../../../src/commands/task/taskTool.ts"],"sourcesContent":["import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';\nimport { TASK_EVENT, type TaskFailureReporter } from '../../adapters/telemetry/logSinkTelemetry.ts';\nimport {\n MSG_UPSERT_FIELD_MISPLACED,\n TaskParamsSchema,\n TOOL_LABEL,\n TOOL_NAME,\n taskActionAcceptsField,\n} from '../../schemas/task.ts';\nimport type { AssignOptions, DelegationManager, DelegationOutcome } from '../../services/delegation/manager.ts';\nimport { applyTaskMutation, isCommittingOp, type ReducerAction } from '../../services/store/reducer.ts';\nimport type { TaskStore } from '../../services/store/taskStore.ts';\nimport type { TaskAction, TaskAssignment, TaskMutationParams } from '../../services/store/types.ts';\nimport { renderTaskCall, renderTaskResult } from '../../tui/format.ts';\nimport { DEFAULT_PROMPT_GUIDELINES } from './promptGuidelines.ts';\nimport {\n buildAssignmentResult,\n buildTextResult,\n buildToolResult,\n formatAssignmentResults,\n formatUpsertFailureText,\n type AssignmentItemResult,\n type ToolResult,\n} from './responseEnvelope.ts';\n\nexport { DEFAULT_PROMPT_GUIDELINES } from './promptGuidelines.ts';\n\nexport const DEFAULT_PROMPT_SNIPPET =\n 'Manage a shared task list to track multi-step progress, and delegate tasks to subagents';\n\nexport interface TaskToolDependencies {\n store: TaskStore;\n delegation: DelegationManager;\n onChange?: () => void;\n report?: TaskFailureReporter;\n}\n\nconst ACTION_ATTRIBUTE = 'tool.action';\nconst TASK_ID_ATTRIBUTE = 'task.id';\nconst REDUCER_ACTIONS = new Set<TaskAction>(['upsert', 'list', 'get', 'delete', 'clear']);\n\nclass TaskToolExecutionError extends Error {}\n\nfunction actionableTaskError(action: TaskAction, message: string): TaskToolExecutionError {\n return new TaskToolExecutionError(\n [\n `Task ${action} failed: ${message}`,\n '',\n 'Options:',\n '- List the task board and inspect the current ids, states, and blockers.',\n '- Correct the arguments or state conflict, then retry once.',\n '- Ask the user before cancelling work or changing dependencies to recover.',\n ].join('\\n'),\n );\n}\n\n/**\n * Reject a field that belongs to a different action.\n *\n * The params schema is flat and shared across every action, so this is the only\n * place `{\"action\":\"upsert\",\"id\":3}` can be caught — and it must be, because\n * the entry it carries has no id and would silently create a duplicate task.\n */\nfunction rejectStrayFields(action: TaskAction, params: TaskMutationParams): void {\n const stray = Object.keys(params).filter((key) => params[key] !== undefined && !taskActionAcceptsField(action, key));\n if (stray.length === 0) return;\n const hint = action === 'upsert' ? ` ${MSG_UPSERT_FIELD_MISPLACED}` : '';\n throw actionableTaskError(action, `${action} does not accept ${stray.join(', ')}.${hint}`);\n}\n\n/** assignments[] is the only assign contract, even when it contains one task. */\nfunction resolveAssignments(params: TaskMutationParams): TaskAssignment[] {\n const assignments = params.assignments;\n if (!assignments || assignments.length === 0) {\n throw actionableTaskError('assign', 'assign requires a non-empty assignments[] array');\n }\n return assignments;\n}\n\nfunction assignOptions(request: TaskAssignment, signal: AbortSignal | undefined): AssignOptions {\n return {\n agent: request.agent,\n inlineAgent: request.inlineAgent,\n instructions: request.instructions,\n relevantFiles: request.relevantFiles,\n priorFindings: request.priorFindings,\n model: request.model,\n context: request.context,\n signal,\n };\n}\n\nasync function executeAssignmentBatch(\n delegation: DelegationManager,\n assignments: readonly TaskAssignment[],\n signal: AbortSignal | undefined,\n report: TaskFailureReporter | undefined,\n): Promise<AssignmentItemResult[]> {\n const results: AssignmentItemResult[] = [];\n for (const [index, assignment] of assignments.entries()) {\n let outcome: DelegationOutcome;\n try {\n outcome = await delegation.assign(assignment.id, assignOptions(assignment, signal));\n } catch (error) {\n report?.error(TASK_EVENT.toolFailed, error, {\n [ACTION_ATTRIBUTE]: 'assign',\n [TASK_ID_ATTRIBUTE]: assignment.id,\n });\n outcome = { ok: false, message: error instanceof Error ? error.message : String(error) };\n }\n results.push({ index, id: assignment.id, agent: assignment.agent, ...outcome });\n }\n return results;\n}\n\n/** Run an action through the reducer, persisting only when it produced a change. */\nasync function executeReducerAction(\n store: TaskStore,\n action: ReducerAction,\n params: TaskMutationParams,\n): Promise<ToolResult> {\n const { document, value } = await store.mutate((current) => {\n const result = applyTaskMutation(current, action, params);\n return {\n ...(isCommittingOp(result.op) ? { document: result.document } : {}),\n value: result,\n };\n });\n if (value.op.kind === 'error') throw actionableTaskError(action, value.op.message);\n // An upsert that applied nothing is a failed call: it wrote nothing and left\n // `rev` alone, so it must not read to the model as a success. A batch where\n // some entries landed returns normally — that is what partial apply means.\n if (value.op.kind === 'upsert' && value.op.applied === 0) {\n throw actionableTaskError(action, formatUpsertFailureText(value.op));\n }\n // `document` is the committed document, so `details.rev` matches what landed\n // on disk; `value.document` is the pre-write copy and lags by one.\n return buildToolResult(action, params, document, value.op);\n}\n\nexport function registerTaskTool(pi: ExtensionAPI, dependencies: TaskToolDependencies): void {\n const { store, delegation } = dependencies;\n\n pi.registerTool({\n name: TOOL_NAME,\n label: TOOL_LABEL,\n description:\n 'Manage a shared task list for tracking multi-step progress, and delegate tasks to subagents. Actions: upsert (write tasks — a tasks[] array where an entry with an id changes that task and an entry without an id creates one, so one call can capture a whole plan), list, get, delete (tombstone), clear (close/reset the list), assign (hand one or more tasks through assignments[] to named subagents that work in the background), cancel (stop a delegated run). upsert and assign apply entries independently: successes remain committed or delegated and failures are reported by array index. Batch a plan and independent assignments, but report progress one task at a time. Status: pending → in_progress → completed, plus failed and a deleted tombstone. The list is shared within the current session tree, including delegated subagents, while unrelated sessions start empty. Session stores persist until retention cleanup.',\n promptSnippet: DEFAULT_PROMPT_SNIPPET,\n promptGuidelines: DEFAULT_PROMPT_GUIDELINES,\n parameters: TaskParamsSchema,\n // Task rows carry their own status colors. Owning the shell prevents Pi's\n // pending/success/error background fill from obscuring those row states.\n renderShell: 'self',\n\n async execute(_toolCallId, params, signal, onUpdate, _ctx) {\n const action = params.action as TaskAction;\n const mutationParams = params as TaskMutationParams;\n\n try {\n rejectStrayFields(action, mutationParams);\n if (REDUCER_ACTIONS.has(action)) {\n const result = await executeReducerAction(store, action as ReducerAction, mutationParams);\n dependencies.onChange?.();\n return result;\n }\n\n if (action === 'assign') {\n const assignments = resolveAssignments(mutationParams);\n const first = assignments[0];\n const progress =\n assignments.length === 1 && first\n ? `Delegating task #${first.id}...`\n : `Delegating ${assignments.length} tasks...`;\n onUpdate?.(buildTextResult(action, mutationParams, store.snapshot, progress));\n const results = await executeAssignmentBatch(delegation, assignments, signal, dependencies.report);\n dependencies.onChange?.();\n const text = formatAssignmentResults(results);\n const assigned = results.flatMap((item) => (item.ok ? [item.id] : []));\n if (assigned.length === 0) throw actionableTaskError(action, text);\n return buildAssignmentResult(mutationParams, store.snapshot, text, {\n assigned,\n failed: results.length - assigned.length,\n });\n }\n\n onUpdate?.(\n buildTextResult(\n action,\n mutationParams,\n store.snapshot,\n `Requesting cancellation for task #${mutationParams.id ?? 'unknown'}...`,\n ),\n );\n const outcome = await delegation.cancel(mutationParams.id ?? Number.NaN);\n dependencies.onChange?.();\n if (!outcome.ok) throw actionableTaskError(action, outcome.message);\n return buildTextResult(action, mutationParams, store.snapshot, outcome.message, undefined);\n } catch (error) {\n // Rethrown so pi still renders the failure to the model; recorded\n // because this is where a store fault becomes visible to the user.\n dependencies.report?.error(TASK_EVENT.toolFailed, error, {\n [ACTION_ATTRIBUTE]: action,\n ...(mutationParams.id === undefined ? {} : { [TASK_ID_ATTRIBUTE]: mutationParams.id }),\n });\n if (error instanceof TaskToolExecutionError) throw error;\n throw actionableTaskError(action, error instanceof Error ? error.message : String(error));\n }\n },\n\n // Render hooks receive no session identity, so they read the store snapshot\n // that the executing session last loaded. That is the foreground session's\n // own view, which is exactly what its transcript should show.\n renderCall(args, theme, _context) {\n return renderTaskCall(args as never, theme, store.snapshot.tasks);\n },\n\n renderResult(result, options, theme, _context) {\n return renderTaskResult(result, options, theme);\n },\n });\n}\n"],"mappings":"6PA2Ba,EACX,0FASI,EAAmB,cACnB,EAAoB,UACpB,EAAkB,IAAI,IAAgB,CAAC,SAAU,OAAQ,MAAO,SAAU,OAAO,CAAC,EAExF,IAAM,EAAN,cAAqC,KAAM,CAAC,EAE5C,SAAS,EAAoB,EAAoB,EAAyC,CACxF,OAAO,IAAI,EACT,CACE,QAAQ,EAAO,WAAW,IAC1B,GACA,WACA,2EACA,8DACA,4EACF,CAAC,CAAC,KAAK;CAAI,CACb,CACF,CASA,SAAS,EAAkB,EAAoB,EAAkC,CAC/E,IAAM,EAAQ,OAAO,KAAK,CAAM,CAAC,CAAC,OAAQ,GAAQ,EAAO,KAAS,IAAA,IAAa,CAACA,EAAAA,uBAAuB,EAAQ,CAAG,CAAC,EACnH,GAAI,EAAM,S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