@astralyn/pi 1.4.5 → 1.4.6
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/CHANGELOG.md +20 -0
- package/dist/bundle/chunks/{chunk-I5S7H7GA.js → chunk-EYKC6ESU.js} +1 -1
- package/dist/bundle/chunks/chunk-KDO6L76C.js +230 -0
- package/dist/bundle/chunks/chunk-RBTJBQWX.js +1500 -0
- package/dist/bundle/chunks/{execute-GMFGC27P.js → execute-5ZQUS52M.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-6FUV7ZDV.js → virtual-modules-KCQU7LOC.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/isolated-session.d.ts +23 -0
- package/dist/core/isolated-session.d.ts.map +1 -0
- package/dist/core/isolated-session.js +55 -0
- package/dist/core/isolated-session.js.map +1 -0
- package/dist/core/tasks/codec.d.ts +12 -0
- package/dist/core/tasks/codec.d.ts.map +1 -0
- package/dist/core/tasks/codec.js +139 -0
- package/dist/core/tasks/codec.js.map +1 -0
- package/dist/core/tasks/execution.d.ts +64 -0
- package/dist/core/tasks/execution.d.ts.map +1 -0
- package/dist/core/tasks/execution.js +272 -0
- package/dist/core/tasks/execution.js.map +1 -0
- package/dist/core/tasks/output.d.ts +12 -6
- package/dist/core/tasks/output.d.ts.map +1 -1
- package/dist/core/tasks/output.js +38 -38
- package/dist/core/tasks/output.js.map +1 -1
- package/dist/core/tasks/presentation.d.ts +14 -5
- package/dist/core/tasks/presentation.d.ts.map +1 -1
- package/dist/core/tasks/presentation.js +56 -185
- package/dist/core/tasks/presentation.js.map +1 -1
- package/dist/core/tasks/runtime.d.ts +9 -9
- package/dist/core/tasks/runtime.d.ts.map +1 -1
- package/dist/core/tasks/runtime.js +63 -254
- package/dist/core/tasks/runtime.js.map +1 -1
- package/dist/core/tasks/scheduler.d.ts +16 -0
- package/dist/core/tasks/scheduler.d.ts.map +1 -0
- package/dist/core/tasks/scheduler.js +42 -0
- package/dist/core/tasks/scheduler.js.map +1 -0
- package/dist/core/tasks/session.d.ts +1 -0
- package/dist/core/tasks/session.d.ts.map +1 -1
- package/dist/core/tasks/session.js +15 -27
- package/dist/core/tasks/session.js.map +1 -1
- package/dist/core/tasks/store.js +4 -4
- package/dist/core/tasks/store.js.map +1 -1
- package/dist/core/tasks/types.d.ts +63 -53
- package/dist/core/tasks/types.d.ts.map +1 -1
- package/dist/core/tasks/types.js +3 -9
- package/dist/core/tasks/types.js.map +1 -1
- package/dist/core/tools/shell-execution.js +4 -4
- package/dist/core/tools/shell-execution.js.map +1 -1
- package/dist/core/tools/shell-tool.d.ts.map +1 -1
- package/dist/core/tools/shell-tool.js +23 -30
- package/dist/core/tools/shell-tool.js.map +1 -1
- package/dist/core/usage-totals.d.ts +1 -3
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +17 -8
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/agent/activity.d.ts +4 -4
- package/dist/extensions/agent/activity.d.ts.map +1 -1
- package/dist/extensions/agent/activity.js +15 -24
- package/dist/extensions/agent/activity.js.map +1 -1
- package/dist/extensions/agent/index.d.ts +2 -11
- package/dist/extensions/agent/index.d.ts.map +1 -1
- package/dist/extensions/agent/index.js +3 -88
- package/dist/extensions/agent/index.js.map +1 -1
- package/dist/extensions/agent/progress.d.ts +31 -0
- package/dist/extensions/agent/progress.d.ts.map +1 -0
- package/dist/extensions/agent/progress.js +145 -0
- package/dist/extensions/agent/progress.js.map +1 -0
- package/dist/extensions/agent/render.d.ts.map +1 -1
- package/dist/extensions/agent/render.js +8 -17
- package/dist/extensions/agent/render.js.map +1 -1
- package/dist/extensions/agent/report.d.ts +9 -0
- package/dist/extensions/agent/report.d.ts.map +1 -0
- package/dist/extensions/agent/report.js +40 -0
- package/dist/extensions/agent/report.js.map +1 -0
- package/dist/extensions/agent/settings-panel.d.ts +43 -0
- package/dist/extensions/agent/settings-panel.d.ts.map +1 -0
- package/dist/extensions/agent/settings-panel.js +125 -0
- package/dist/extensions/agent/settings-panel.js.map +1 -0
- package/dist/extensions/agent/settings.d.ts +1 -1
- package/dist/extensions/agent/settings.d.ts.map +1 -1
- package/dist/extensions/agent/settings.js +101 -83
- package/dist/extensions/agent/settings.js.map +1 -1
- package/dist/extensions/agent/tool.d.ts +13 -0
- package/dist/extensions/agent/tool.d.ts.map +1 -0
- package/dist/extensions/agent/tool.js +84 -0
- package/dist/extensions/agent/tool.js.map +1 -0
- package/dist/extensions/agent/types.d.ts +19 -21
- package/dist/extensions/agent/types.d.ts.map +1 -1
- package/dist/extensions/agent/types.js +2 -10
- package/dist/extensions/agent/types.js.map +1 -1
- package/dist/extensions/agent/worker.d.ts +16 -0
- package/dist/extensions/agent/worker.d.ts.map +1 -0
- package/dist/extensions/agent/worker.js +68 -0
- package/dist/extensions/agent/worker.js.map +1 -0
- package/dist/extensions/tasks/tool/actions.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/actions.js +1 -9
- package/dist/extensions/tasks/tool/actions.js.map +1 -1
- package/dist/extensions/tasks/tool/schema.js +1 -1
- package/dist/extensions/tasks/tool/schema.js.map +1 -1
- package/dist/extensions/tasks/tool/types.d.ts +2 -8
- package/dist/extensions/tasks/tool/types.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/types.js +0 -2
- package/dist/extensions/tasks/tool/types.js.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.js +27 -26
- package/dist/extensions/tasks/ui/completion-render.js.map +1 -1
- package/dist/extensions/tasks/ui/inspector.d.ts +5 -3
- package/dist/extensions/tasks/ui/inspector.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/inspector.js +18 -6
- package/dist/extensions/tasks/ui/inspector.js.map +1 -1
- package/dist/extensions/tasks/ui/layout.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/layout.js +111 -75
- package/dist/extensions/tasks/ui/layout.js.map +1 -1
- package/dist/extensions/tasks/ui/list.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/list.js +43 -28
- package/dist/extensions/tasks/ui/list.js.map +1 -1
- package/dist/extensions/tasks/ui/manager.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/manager.js +8 -2
- package/dist/extensions/tasks/ui/manager.js.map +1 -1
- package/dist/extensions/tasks/ui/model.d.ts +4 -0
- package/dist/extensions/tasks/ui/model.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/model.js +12 -1
- package/dist/extensions/tasks/ui/model.js.map +1 -1
- package/dist/extensions/tasks/ui/render.js +3 -4
- package/dist/extensions/tasks/ui/render.js.map +1 -1
- package/dist/extensions/tasks/ui/task-view.d.ts +0 -5
- package/dist/extensions/tasks/ui/task-view.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/task-view.js +0 -7
- package/dist/extensions/tasks/ui/task-view.js.map +1 -1
- package/dist/extensions/tasks/ui/tree.js +1 -1
- package/dist/extensions/tasks/ui/tree.js.map +1 -1
- package/dist/extensions/tasks/ui/views.d.ts +10 -5
- package/dist/extensions/tasks/ui/views.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/views.js +61 -36
- package/dist/extensions/tasks/ui/views.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +2 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +7 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +10 -3
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/docs/bundled/extensions/agent.md +12 -10
- package/docs/bundled/extensions/statusline.md +1 -1
- package/docs/bundled/tasks.md +15 -14
- package/docs/extensions.md +22 -6
- package/docs/sdk.md +2 -2
- package/docs/session-format.md +27 -23
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/bundle/chunks/chunk-FSJ45CRP.js +0 -229
- package/dist/bundle/chunks/chunk-W3FIUMGM.js +0 -1501
- package/dist/core/tasks/history.d.ts +0 -4
- package/dist/core/tasks/history.d.ts.map +0 -1
- package/dist/core/tasks/history.js +0 -131
- package/dist/core/tasks/history.js.map +0 -1
- package/dist/extensions/agent/runner.d.ts +0 -24
- package/dist/extensions/agent/runner.d.ts.map +0 -1
- package/dist/extensions/agent/runner.js +0 -274
- package/dist/extensions/agent/runner.js.map +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { defineTool } from "../../core/extensions/types.js";
|
|
3
|
+
import { clipText } from "./activity.js";
|
|
4
|
+
import { agentRenderers } from "./render.js";
|
|
5
|
+
import { resolveAgentConfiguration } from "./settings.js";
|
|
6
|
+
import { AGENT_CONCURRENCY, AGENT_PROMPT_BYTES } from "./types.js";
|
|
7
|
+
import { runWorker } from "./worker.js";
|
|
8
|
+
const agentSchema = Type.Object({
|
|
9
|
+
prompt: Type.String({
|
|
10
|
+
minLength: 1,
|
|
11
|
+
description: "Complete, self-contained task briefing; the Agent cannot see this conversation",
|
|
12
|
+
}),
|
|
13
|
+
description: Type.Optional(Type.String({ description: "Short task label for the transcript and Tasks panel" })),
|
|
14
|
+
background: Type.Optional(Type.Boolean({ description: "Return a task ID and deliver the final report asynchronously" })),
|
|
15
|
+
}, { additionalProperties: false });
|
|
16
|
+
/** The model-facing handoff: who moved the Agent, whether it waits for a slot, and how to follow it. */
|
|
17
|
+
function handoffResult(task, byUser) {
|
|
18
|
+
const moved = byUser
|
|
19
|
+
? `The user moved this Agent to the background while it was running: ${task.id}. It continues unchanged.`
|
|
20
|
+
: `Agent running in background: ${task.id}.`;
|
|
21
|
+
const queued = task.status === "queued" ? " It is queued until an Agent slot frees." : "";
|
|
22
|
+
return {
|
|
23
|
+
content: [
|
|
24
|
+
{
|
|
25
|
+
type: "text",
|
|
26
|
+
text: `${moved}${queued} The report will be delivered automatically. Use tasks read/wait/kill to inspect, wait or stop.`,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
details: { version: 2, state: "background", taskId: task.id, byUser },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function createAgentTool(options = {}) {
|
|
33
|
+
const limit = options.concurrency ?? AGENT_CONCURRENCY;
|
|
34
|
+
return defineTool({
|
|
35
|
+
name: "Agent",
|
|
36
|
+
label: "Agent",
|
|
37
|
+
description: "Delegate independent work to a temporary isolated Agent when separate context or parallel execution offers a clear benefit. Use sparingly; handle known-path reads and small edits directly. The Agent cannot see the parent conversation, so include all necessary context and desired verification in prompt. Foreground returns the final report; background returns a task ID and delivers it automatically.",
|
|
38
|
+
promptSnippet: "Delegate an independent task",
|
|
39
|
+
promptGuidelines: [
|
|
40
|
+
"Give Agent a complete, self-contained briefing with relevant paths, constraints and expected verification; use parallel calls only for independent, non-overlapping work.",
|
|
41
|
+
],
|
|
42
|
+
parameters: agentSchema,
|
|
43
|
+
constrainedSampling: { type: "json_schema", strict: "prefer" },
|
|
44
|
+
executionMode: "parallel",
|
|
45
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
46
|
+
if (!params.prompt.trim() || Buffer.byteLength(params.prompt) > AGENT_PROMPT_BYTES)
|
|
47
|
+
throw new Error("Agent prompt must contain text and fit within 16 KiB.");
|
|
48
|
+
const { model, thinking } = resolveAgentConfiguration(ctx);
|
|
49
|
+
const auth = await ctx.modelRuntime.getAuth(model, { signal });
|
|
50
|
+
if (!auth)
|
|
51
|
+
throw new Error(`No authentication for Agent model ${model.provider}/${model.id}`);
|
|
52
|
+
const outcome = await ctx.tasks.execute({
|
|
53
|
+
kind: "agent",
|
|
54
|
+
label: "Agent",
|
|
55
|
+
title: clipText((params.description?.trim() || params.prompt).replace(/\s+/gu, " ").trim(), 160),
|
|
56
|
+
output: "report",
|
|
57
|
+
input: { label: "Prompt", text: params.prompt, truncated: false },
|
|
58
|
+
facts: [
|
|
59
|
+
["Model", `${model.provider}/${model.id}`],
|
|
60
|
+
["Thinking", thinking],
|
|
61
|
+
["Directory", ctx.cwd],
|
|
62
|
+
],
|
|
63
|
+
concurrency: { key: "agent", limit },
|
|
64
|
+
toolCallId,
|
|
65
|
+
background: params.background,
|
|
66
|
+
signal,
|
|
67
|
+
onUpdate,
|
|
68
|
+
run: (control) => runWorker(control, {
|
|
69
|
+
prompt: params.prompt,
|
|
70
|
+
cwd: ctx.cwd,
|
|
71
|
+
model,
|
|
72
|
+
thinking,
|
|
73
|
+
modelRuntime: ctx.modelRuntime,
|
|
74
|
+
projectTrusted: ctx.isProjectTrusted(),
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
if (outcome.kind === "result")
|
|
78
|
+
return outcome.result;
|
|
79
|
+
return handoffResult(outcome.task, params.background !== true);
|
|
80
|
+
},
|
|
81
|
+
...agentRenderers,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/agent/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,i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EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE;gBACjE,KAAK,EAAE;oBACN,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;oBAC1C,CAAC,UAAU,EAAE,QAAQ,CAAC;oBACtB,CAAC,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC;iBACtB;gBACD,WAAW,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;gBACpC,UAAU;gBACV,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,MAAM;gBACN,QAAQ;gBACR,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAChB,SAAS,CAAC,OAAO,EAAE;oBAClB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,GAAG,EAAE,GAAG,CAAC,GAAG;oBACZ,KAAK;oBACL,QAAQ;oBACR,YAAY,EAAE,GAAG,CAAC,YAAY;oBAC9B,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE;iBACtC,CAAC;aACH,CAAC,CAAC;YACH,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO,OAAO,CAAC,MAAM,CAAC;YACrD,OAAO,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,CAAC;QAChE,CAAC;QACD,GAAG,cAAc;KACjB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport type { AgentToolResult, ToolDefinition } from \"../../core/extensions/types.ts\";\nimport { defineTool } from \"../../core/extensions/types.ts\";\nimport type { TaskSnapshot } from \"../../core/tasks/types.ts\";\nimport { clipText } from \"./activity.ts\";\nimport { agentRenderers } from \"./render.ts\";\nimport { resolveAgentConfiguration } from \"./settings.ts\";\nimport { AGENT_CONCURRENCY, AGENT_PROMPT_BYTES, type AgentToolDetails } from \"./types.ts\";\nimport { runWorker } from \"./worker.ts\";\n\nconst agentSchema = Type.Object(\n\t{\n\t\tprompt: Type.String({\n\t\t\tminLength: 1,\n\t\t\tdescription: \"Complete, self-contained task briefing; the Agent cannot see this conversation\",\n\t\t}),\n\t\tdescription: Type.Optional(Type.String({ description: \"Short task label for the transcript and Tasks panel\" })),\n\t\tbackground: Type.Optional(\n\t\t\tType.Boolean({ description: \"Return a task ID and deliver the final report asynchronously\" }),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\n/** The model-facing handoff: who moved the Agent, whether it waits for a slot, and how to follow it. */\nfunction handoffResult(task: TaskSnapshot, byUser: boolean): AgentToolResult<AgentToolDetails> {\n\tconst moved = byUser\n\t\t? `The user moved this Agent to the background while it was running: ${task.id}. It continues unchanged.`\n\t\t: `Agent running in background: ${task.id}.`;\n\tconst queued = task.status === \"queued\" ? \" It is queued until an Agent slot frees.\" : \"\";\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `${moved}${queued} The report will be delivered automatically. Use tasks read/wait/kill to inspect, wait or stop.`,\n\t\t\t},\n\t\t],\n\t\tdetails: { version: 2, state: \"background\", taskId: task.id, byUser },\n\t};\n}\n\nexport function createAgentTool(\n\toptions: { concurrency?: number } = {},\n): ToolDefinition<typeof agentSchema, AgentToolDetails> {\n\tconst limit = options.concurrency ?? AGENT_CONCURRENCY;\n\treturn defineTool({\n\t\tname: \"Agent\",\n\t\tlabel: \"Agent\",\n\t\tdescription:\n\t\t\t\"Delegate independent work to a temporary isolated Agent when separate context or parallel execution offers a clear benefit. Use sparingly; handle known-path reads and small edits directly. The Agent cannot see the parent conversation, so include all necessary context and desired verification in prompt. Foreground returns the final report; background returns a task ID and delivers it automatically.\",\n\t\tpromptSnippet: \"Delegate an independent task\",\n\t\tpromptGuidelines: [\n\t\t\t\"Give Agent a complete, self-contained briefing with relevant paths, constraints and expected verification; use parallel calls only for independent, non-overlapping work.\",\n\t\t],\n\t\tparameters: agentSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\texecutionMode: \"parallel\",\n\t\tasync execute(toolCallId, params, signal, onUpdate, ctx) {\n\t\t\tif (!params.prompt.trim() || Buffer.byteLength(params.prompt) > AGENT_PROMPT_BYTES)\n\t\t\t\tthrow new Error(\"Agent prompt must contain text and fit within 16 KiB.\");\n\t\t\tconst { model, thinking } = resolveAgentConfiguration(ctx);\n\t\t\tconst auth = await ctx.modelRuntime.getAuth(model, { signal });\n\t\t\tif (!auth) throw new Error(`No authentication for Agent model ${model.provider}/${model.id}`);\n\t\t\tconst outcome = await ctx.tasks.execute<AgentToolDetails>({\n\t\t\t\tkind: \"agent\",\n\t\t\t\tlabel: \"Agent\",\n\t\t\t\ttitle: clipText((params.description?.trim() || params.prompt).replace(/\\s+/gu, \" \").trim(), 160),\n\t\t\t\toutput: \"report\",\n\t\t\t\tinput: { label: \"Prompt\", text: params.prompt, truncated: false },\n\t\t\t\tfacts: [\n\t\t\t\t\t[\"Model\", `${model.provider}/${model.id}`],\n\t\t\t\t\t[\"Thinking\", thinking],\n\t\t\t\t\t[\"Directory\", ctx.cwd],\n\t\t\t\t],\n\t\t\t\tconcurrency: { key: \"agent\", limit },\n\t\t\t\ttoolCallId,\n\t\t\t\tbackground: params.background,\n\t\t\t\tsignal,\n\t\t\t\tonUpdate,\n\t\t\t\trun: (control) =>\n\t\t\t\t\trunWorker(control, {\n\t\t\t\t\t\tprompt: params.prompt,\n\t\t\t\t\t\tcwd: ctx.cwd,\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tthinking,\n\t\t\t\t\t\tmodelRuntime: ctx.modelRuntime,\n\t\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\t}),\n\t\t\t});\n\t\t\tif (outcome.kind === \"result\") return outcome.result;\n\t\t\treturn handoffResult(outcome.task, params.background !== true);\n\t\t},\n\t\t...agentRenderers,\n\t});\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { TaskTerminalStatus } from "../../core/tasks/types.ts";
|
|
3
3
|
export declare const AGENT_SETTINGS_NAMESPACE = "agent";
|
|
4
|
+
export declare const AGENT_PROMPT_BYTES: number;
|
|
4
5
|
export declare const AGENT_REPORT_BYTES: number;
|
|
5
6
|
export declare const AGENT_MAX_ACTIVITIES = 50;
|
|
7
|
+
export declare const AGENT_CONCURRENCY = 4;
|
|
6
8
|
export interface AgentSettings {
|
|
7
9
|
model?: string;
|
|
8
10
|
thinking?: ThinkingLevel;
|
|
@@ -18,28 +20,24 @@ export interface AgentActivity {
|
|
|
18
20
|
durationMs?: number;
|
|
19
21
|
error?: string;
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Agent tool-result details. Only progress updates carry activities; the persisted result
|
|
25
|
+
* keeps the transcript row's facts, and the full history lives in the task's Output.
|
|
26
|
+
*/
|
|
27
|
+
export type AgentToolDetails = {
|
|
28
|
+
version: 2;
|
|
29
|
+
state: "running";
|
|
23
30
|
taskId: string;
|
|
24
|
-
status: "running" | "background" | TaskTerminalStatus;
|
|
25
|
-
model: string;
|
|
26
|
-
thinking: ThinkingLevel;
|
|
27
|
-
/** Short terminal diagnostic; the complete report and error remain in Tasks Output. */
|
|
28
|
-
error?: string;
|
|
29
31
|
activities: AgentActivity[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
cacheRead: number;
|
|
41
|
-
cacheWrite: number;
|
|
42
|
-
total: number;
|
|
43
|
-
};
|
|
32
|
+
} | {
|
|
33
|
+
version: 2;
|
|
34
|
+
state: "background";
|
|
35
|
+
taskId: string;
|
|
36
|
+
byUser: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
version: 2;
|
|
39
|
+
state: TaskTerminalStatus;
|
|
40
|
+
taskId: string;
|
|
41
|
+
error?: string;
|
|
44
42
|
};
|
|
45
43
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/extensions/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAChD,eAAO,MAAM,kBAAkB,QAAY,CAAC;AAC5C,eAAO,MAAM,oBAAoB,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/extensions/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAChD,eAAO,MAAM,kBAAkB,QAAY,CAAC;AAC5C,eAAO,MAAM,kBAAkB,QAAY,CAAC;AAC5C,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,MAAM,WAAW,aAAa;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,WAAW,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,mGAAmG;IACnG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACzB;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,aAAa,EAAE,CAAA;CAAE,GAC7E;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACpE;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
export const AGENT_SETTINGS_NAMESPACE = "agent";
|
|
2
|
+
export const AGENT_PROMPT_BYTES = 16 * 1024;
|
|
2
3
|
export const AGENT_REPORT_BYTES = 24 * 1024;
|
|
3
4
|
export const AGENT_MAX_ACTIVITIES = 50;
|
|
4
|
-
export
|
|
5
|
-
return {
|
|
6
|
-
input: 0,
|
|
7
|
-
output: 0,
|
|
8
|
-
cacheRead: 0,
|
|
9
|
-
cacheWrite: 0,
|
|
10
|
-
totalTokens: 0,
|
|
11
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
12
|
-
};
|
|
13
|
-
}
|
|
5
|
+
export const AGENT_CONCURRENCY = 4;
|
|
14
6
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extensions/agent/types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extensions/agent/types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { TaskTerminalStatus } from \"../../core/tasks/types.ts\";\n\nexport const AGENT_SETTINGS_NAMESPACE = \"agent\";\nexport const AGENT_PROMPT_BYTES = 16 * 1024;\nexport const AGENT_REPORT_BYTES = 24 * 1024;\nexport const AGENT_MAX_ACTIVITIES = 50;\nexport const AGENT_CONCURRENCY = 4;\n\nexport interface AgentSettings {\n\tmodel?: string;\n\tthinking?: ThinkingLevel;\n}\n\nexport type AgentActivityStatus = \"running\" | \"ok\" | \"error\" | \"cancelled\";\n\nexport interface AgentActivity {\n\tid: string;\n\tname: string;\n\targs: string;\n\t/** Short display label derived from the original arguments; args remains the full bounded form. */\n\ttarget?: string;\n\tstatus: AgentActivityStatus;\n\tdurationMs?: number;\n\terror?: string;\n}\n\n/**\n * Agent tool-result details. Only progress updates carry activities; the persisted result\n * keeps the transcript row's facts, and the full history lives in the task's Output.\n */\nexport type AgentToolDetails =\n\t| { version: 2; state: \"running\"; taskId: string; activities: AgentActivity[] }\n\t| { version: 2; state: \"background\"; taskId: string; byUser: boolean }\n\t| { version: 2; state: TaskTerminalStatus; taskId: string; error?: string };\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { Model } from "@earendil-works/pi-ai/compat";
|
|
3
|
+
import type { ModelRuntime } from "../../core/model-runtime.ts";
|
|
4
|
+
import type { TaskCompletion, TaskControl } from "../../core/tasks/types.ts";
|
|
5
|
+
import type { AgentToolDetails } from "./types.ts";
|
|
6
|
+
export interface AgentRequest {
|
|
7
|
+
prompt: string;
|
|
8
|
+
cwd: string;
|
|
9
|
+
model: Model<any>;
|
|
10
|
+
thinking: ThinkingLevel;
|
|
11
|
+
modelRuntime: ModelRuntime;
|
|
12
|
+
projectTrusted: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Run one delegated task in an isolated session and settle it with a self-contained report. */
|
|
15
|
+
export declare function runWorker(control: TaskControl<AgentToolDetails>, request: AgentRequest): Promise<TaskCompletion<AgentToolDetails>>;
|
|
16
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/extensions/agent/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAG1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAI7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAInD,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,QAAQ,EAAE,aAAa,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,EAAE,OAAO,CAAC;CACxB;AAeD,gGAAgG;AAChG,wBAAsB,SAAS,CAC9B,OAAO,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACtC,OAAO,EAAE,YAAY,GACnB,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CA6C3C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createIsolatedSession } from "../../core/isolated-session.js";
|
|
2
|
+
import { clipText } from "./activity.js";
|
|
3
|
+
import { AgentProgress, finalAssistantText } from "./progress.js";
|
|
4
|
+
import { finalReport } from "./report.js";
|
|
5
|
+
const WORKER_TOOLS = ["read", "bash", "edit", "write"];
|
|
6
|
+
function workerPrompt(base) {
|
|
7
|
+
return [
|
|
8
|
+
base,
|
|
9
|
+
"You are an Agent working independently on one delegated task.",
|
|
10
|
+
"You cannot see the parent conversation. Treat the parent Agent as your caller, rely on the task briefing and available workspace context, and do not ask the end user questions. If anything is unclear, explain the ambiguity in your final report.",
|
|
11
|
+
"Work in the assigned directory and stay within the requested scope. Use read for known-path file reads and bash for file discovery, search, and shell commands.",
|
|
12
|
+
"Do not delegate or start background work. Run required commands in the foreground and wait for them.",
|
|
13
|
+
"Only your final report returns to the caller. Make it self-contained: include essential findings or changes, verification when applicable, blockers, and unresolved risks; omit process narration.",
|
|
14
|
+
]
|
|
15
|
+
.filter((part) => Boolean(part?.trim()))
|
|
16
|
+
.join("\n\n");
|
|
17
|
+
}
|
|
18
|
+
/** Run one delegated task in an isolated session and settle it with a self-contained report. */
|
|
19
|
+
export async function runWorker(control, request) {
|
|
20
|
+
const { signal } = control;
|
|
21
|
+
const progress = new AgentProgress(control);
|
|
22
|
+
let session;
|
|
23
|
+
let unsubscribe;
|
|
24
|
+
const abort = () => {
|
|
25
|
+
void session?.abort().catch(() => { });
|
|
26
|
+
};
|
|
27
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
28
|
+
try {
|
|
29
|
+
session = await createIsolatedSession({
|
|
30
|
+
cwd: request.cwd,
|
|
31
|
+
model: request.model,
|
|
32
|
+
thinkingLevel: request.thinking,
|
|
33
|
+
modelRuntime: request.modelRuntime,
|
|
34
|
+
projectTrusted: request.projectTrusted,
|
|
35
|
+
systemPrompt: workerPrompt,
|
|
36
|
+
tools: WORKER_TOOLS,
|
|
37
|
+
signal,
|
|
38
|
+
});
|
|
39
|
+
const worker = session;
|
|
40
|
+
unsubscribe = worker.subscribe((event) => {
|
|
41
|
+
// Cancellation during prompt preflight can precede the run's own abort controller.
|
|
42
|
+
if (event.type === "agent_start" && signal.aborted)
|
|
43
|
+
abort();
|
|
44
|
+
else
|
|
45
|
+
progress.handle(event);
|
|
46
|
+
});
|
|
47
|
+
progress.publish();
|
|
48
|
+
control.accept();
|
|
49
|
+
signal.throwIfAborted();
|
|
50
|
+
await worker.prompt(request.prompt, { expandPromptTemplates: false });
|
|
51
|
+
const { status, error } = progress.outcome();
|
|
52
|
+
return progress.complete(status, error, await finalReport(control, finalAssistantText(worker.messages), error));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const status = signal.aborted ? "cancelled" : "failed";
|
|
56
|
+
const reason = status === "cancelled"
|
|
57
|
+
? "Agent cancelled."
|
|
58
|
+
: clipText(error instanceof Error ? error.message : String(error), 4096);
|
|
59
|
+
const report = session ? finalAssistantText(session.messages) : "";
|
|
60
|
+
return progress.complete(status, reason, await finalReport(control, report, reason));
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
signal.removeEventListener("abort", abort);
|
|
64
|
+
unsubscribe?.();
|
|
65
|
+
session?.dispose();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/extensions/agent/worker.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAGvE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAA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C,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtF,CAAC;YAAS,CAAC;QACV,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC3C,WAAW,EAAE,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,CAAC;IACpB,CAAC;AACF,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Model } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport { createIsolatedSession } from \"../../core/isolated-session.ts\";\nimport type { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport type { TaskCompletion, TaskControl } from \"../../core/tasks/types.ts\";\nimport { clipText } from \"./activity.ts\";\nimport { AgentProgress, finalAssistantText } from \"./progress.ts\";\nimport { finalReport } from \"./report.ts\";\nimport type { AgentToolDetails } from \"./types.ts\";\n\nconst WORKER_TOOLS = [\"read\", \"bash\", \"edit\", \"write\"];\n\nexport interface AgentRequest {\n\tprompt: string;\n\tcwd: string;\n\tmodel: Model<any>;\n\tthinking: ThinkingLevel;\n\tmodelRuntime: ModelRuntime;\n\tprojectTrusted: boolean;\n}\n\nfunction workerPrompt(base: string | undefined): string {\n\treturn [\n\t\tbase,\n\t\t\"You are an Agent working independently on one delegated task.\",\n\t\t\"You cannot see the parent conversation. Treat the parent Agent as your caller, rely on the task briefing and available workspace context, and do not ask the end user questions. If anything is unclear, explain the ambiguity in your final report.\",\n\t\t\"Work in the assigned directory and stay within the requested scope. Use read for known-path file reads and bash for file discovery, search, and shell commands.\",\n\t\t\"Do not delegate or start background work. Run required commands in the foreground and wait for them.\",\n\t\t\"Only your final report returns to the caller. Make it self-contained: include essential findings or changes, verification when applicable, blockers, and unresolved risks; omit process narration.\",\n\t]\n\t\t.filter((part): part is string => Boolean(part?.trim()))\n\t\t.join(\"\\n\\n\");\n}\n\n/** Run one delegated task in an isolated session and settle it with a self-contained report. */\nexport async function runWorker(\n\tcontrol: TaskControl<AgentToolDetails>,\n\trequest: AgentRequest,\n): Promise<TaskCompletion<AgentToolDetails>> {\n\tconst { signal } = control;\n\tconst progress = new AgentProgress(control);\n\tlet session: AgentSession | undefined;\n\tlet unsubscribe: (() => void) | undefined;\n\tconst abort = () => {\n\t\tvoid session?.abort().catch(() => {});\n\t};\n\tsignal.addEventListener(\"abort\", abort, { once: true });\n\ttry {\n\t\tsession = await createIsolatedSession({\n\t\t\tcwd: request.cwd,\n\t\t\tmodel: request.model,\n\t\t\tthinkingLevel: request.thinking,\n\t\t\tmodelRuntime: request.modelRuntime,\n\t\t\tprojectTrusted: request.projectTrusted,\n\t\t\tsystemPrompt: workerPrompt,\n\t\t\ttools: WORKER_TOOLS,\n\t\t\tsignal,\n\t\t});\n\t\tconst worker = session;\n\t\tunsubscribe = worker.subscribe((event) => {\n\t\t\t// Cancellation during prompt preflight can precede the run's own abort controller.\n\t\t\tif (event.type === \"agent_start\" && signal.aborted) abort();\n\t\t\telse progress.handle(event);\n\t\t});\n\t\tprogress.publish();\n\t\tcontrol.accept();\n\t\tsignal.throwIfAborted();\n\t\tawait worker.prompt(request.prompt, { expandPromptTemplates: false });\n\t\tconst { status, error } = progress.outcome();\n\t\treturn progress.complete(status, error, await finalReport(control, finalAssistantText(worker.messages), error));\n\t} catch (error) {\n\t\tconst status = signal.aborted ? \"cancelled\" : \"failed\";\n\t\tconst reason =\n\t\t\tstatus === \"cancelled\"\n\t\t\t\t? \"Agent cancelled.\"\n\t\t\t\t: clipText(error instanceof Error ? error.message : String(error), 4096);\n\t\tconst report = session ? finalAssistantText(session.messages) : \"\";\n\t\treturn progress.complete(status, reason, await finalReport(control, report, reason));\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", abort);\n\t\tunsubscribe?.();\n\t\tsession?.dispose();\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../src/extensions/tasks/t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CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAkBrH;AAqFD,wBAAsB,OAAO,CAC5B,UAAU,EAAE,YAAY,EACxB,KAAK,EAAE,UAAU,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EAClC,eAAe,CAAC,EAAE,WAAW,GAC3B,OAAO,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,CA+D5C;AACD,wBAAgB,OAAO,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAoBtG;AACD,wBAAgB,OAAO,CAAC,UAAU,EAAE,YAAY,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAmBnF"}
|
|
@@ -123,8 +123,6 @@ function emptyWaitDetails(outcome, waitedMs, running) {
|
|
|
123
123
|
return {
|
|
124
124
|
action: "wait",
|
|
125
125
|
outcome,
|
|
126
|
-
timedOut: outcome === "timed_out",
|
|
127
|
-
exitCode: undefined,
|
|
128
126
|
waitedMs,
|
|
129
127
|
deltaBytes: 0,
|
|
130
128
|
totalBytes: 0,
|
|
@@ -165,8 +163,6 @@ async function runWaitAny(background, input, signal, onReady, interruptSignal) {
|
|
|
165
163
|
taskId: task.id,
|
|
166
164
|
status: task.status,
|
|
167
165
|
kind: task.kind,
|
|
168
|
-
timedOut: false,
|
|
169
|
-
exitCode: task.exitCode,
|
|
170
166
|
waitedMs: Date.now() - start,
|
|
171
167
|
deltaBytes: Buffer.byteLength(slice.text),
|
|
172
168
|
totalBytes: slice.totalBytes,
|
|
@@ -204,8 +200,6 @@ export async function runWait(background, input, signal, onReady, interruptSigna
|
|
|
204
200
|
taskId: task.id,
|
|
205
201
|
status: task.status,
|
|
206
202
|
kind: task.kind,
|
|
207
|
-
timedOut: false,
|
|
208
|
-
exitCode: task.exitCode,
|
|
209
203
|
waitedMs,
|
|
210
204
|
deltaBytes: 0,
|
|
211
205
|
totalBytes: 0,
|
|
@@ -231,8 +225,6 @@ export async function runWait(background, input, signal, onReady, interruptSigna
|
|
|
231
225
|
taskId: task.id,
|
|
232
226
|
status: task.status,
|
|
233
227
|
kind: task.kind,
|
|
234
|
-
timedOut,
|
|
235
|
-
exitCode: task.exitCode,
|
|
236
228
|
waitedMs,
|
|
237
229
|
deltaBytes: Buffer.byteLength(slice.text),
|
|
238
230
|
totalBytes: slice.totalBytes,
|
|
@@ -258,7 +250,7 @@ export function runKill(background, input) {
|
|
|
258
250
|
: `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`, {
|
|
259
251
|
action: "kill",
|
|
260
252
|
taskId: task.id,
|
|
261
|
-
|
|
253
|
+
title: task.title,
|
|
262
254
|
requested,
|
|
263
255
|
status: background.get(task.id).status,
|
|
264
256
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/actions.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAGlF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EACN,cAAc,EACd,eAAe,GAIf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAG3G,MAAM,UAAU,WAAW,CAAC,IAAY;IACvC,OAAO,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,OAA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AC,CAAC,EAAE,CAAC;KACvD,CACD,CAAC;AACH,CAAC","sourcesContent":["/** Management only: execution and delivery belong to the session task runtime. */\n\nimport type { AgentToolResult } from \"../../../core/extensions/types.ts\";\nimport { runtimeLabel } from \"../../../core/tasks/format.ts\";\nimport { boundText } from \"../../../core/tasks/output.ts\";\nimport {\n\tisTaskTerminal,\n\tTaskLookupError,\n\ttype TaskRead,\n\ttype TaskSnapshot,\n\ttype TasksContext,\n} from \"../../../core/tasks/types.ts\";\nimport { truncateHead } from \"../../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../../utils/shell.ts\";\nimport { TASKS_LIST_FINISHED_SHOWN, TASKS_WAIT_DELTA_BYTES } from \"./constants.ts\";\nimport { clampReadBytes, clampSinceBytes, clampWaitMs, requireTaskId, type TasksInput } from \"./schema.ts\";\nimport type { TasksDetails, TasksKillDetails, TasksListDetails, TasksReadDetails, TasksWaitDetails } from \"./types.ts\";\n\nexport function boundedText(text: string): string {\n\treturn truncateHead(sanitizeBinaryOutput(text), { maxBytes: 50 * 1024, maxLines: 2000 }).content;\n}\nfunction result<T extends TasksDetails>(text: string, details: T): AgentToolResult<T> {\n\treturn { content: [{ type: \"text\", text: boundedText(text) }], details };\n}\nexport function describeTaskLine(task: TaskSnapshot, now = Date.now()): string {\n\treturn `${task.id} ${task.kind} ${task.status} (${task.mode}) ${runtimeLabel(task, now)} ${task.title.slice(0, 200)}`;\n}\n\nconst LOOKUP_LIST_LIMIT = 10;\n\n/**\n * Finished rows sort most-recent first. list() is creation-ordered, so an\n * unsorted slice would surface the oldest completions rather than the recent\n * finishes a caller is most likely looking for.\n */\nfunction recentFinishedFirst(tasks: TaskSnapshot[]): TaskSnapshot[] {\n\treturn tasks.sort((left, right) => (right.endedAt ?? 0) - (left.endedAt ?? 0));\n}\n\n/**\n * Listings cover backgrounded work only; foreground executions deliver inline\n * in the transcript, so they are counted rather than shown. Every listing\n * (tasks list output and lookup-failure messages) shares this scope.\n */\nfunction listedTasks(background: TasksContext): { tasks: TaskSnapshot[]; foregroundOmitted: number } {\n\tconst all = background.list();\n\tconst tasks = all.filter((task) => task.mode === \"background\");\n\treturn { tasks, foregroundOmitted: all.length - tasks.length };\n}\n\nfunction foregroundOmissionNote(omitted: number): string {\n\treturn omitted > 0\n\t\t? `\\n${omitted} foreground ${omitted === 1 ? \"execution\" : \"executions\"} omitted — foreground work is delivered inline in the transcript.`\n\t\t: \"\";\n}\n\n/**\n * Rewrite the service's bare lookup failure into an actionable one: an\n * unknown id gets the session's current tasks (active first, then recent\n * finishes) so the next call can use a real id without a separate list call,\n * and an ambiguous prefix gets exactly the tasks it matched — including\n * records outside the current branch, which listings hide but the prefix\n * still collides with.\n */\nfunction lookupFailure(background: TasksContext, id: string, error: unknown): Error {\n\tif (!(error instanceof TaskLookupError)) return error instanceof Error ? error : new Error(String(error));\n\tif (error.kind === \"ambiguous\") {\n\t\tconst lines = error.matches.map((task) => describeTaskLine(task)).join(\"\\n\");\n\t\treturn new Error(`Ambiguous task ID \"${id}\" matches ${error.matches.length} tasks:\\n${lines}`);\n\t}\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isTaskTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isTaskTerminal(task.status)));\n\tconst shown = [...active, ...finished].slice(0, LOOKUP_LIST_LIMIT);\n\tif (shown.length === 0) {\n\t\treturn new Error(`No task \"${id}\" in this session. No background tasks in this session.`);\n\t}\n\tconst lines = shown.map((task) => describeTaskLine(task)).join(\"\\n\");\n\treturn new Error(\n\t\t`No task \"${id}\" in this session. IDs from other sessions are not valid here.\\nCurrent background tasks:\\n${lines}${foregroundOmissionNote(foregroundOmitted)}`,\n\t);\n}\n\n/**\n * Where this slice sits in the output, so the next wait can continue from it.\n * A wait whose new output exceeds its budget returns the newest bytes and says what it skipped.\n */\nfunction rangeText(slice: TaskRead, sinceBytes?: number): string {\n\tconst from = slice.fromByte ?? 0;\n\tconst to = from + Buffer.byteLength(slice.text);\n\tconst floor = sinceBytes === undefined || sinceBytes > slice.totalBytes ? 0 : sinceBytes;\n\treturn [\n\t\t`bytes ${from}–${to} of ${slice.totalBytes}`,\n\t\tsinceBytes !== undefined && from > floor ? `skipped ${from - floor} bytes after sinceBytes ${floor}` : \"\",\n\t\t`next sinceBytes ${to}`,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\" · \");\n}\n\n/** Reserve space for each independent diagnostic before allowing raw output to fill the budget. */\nfunction readText(header: string, slice: TaskRead): string {\n\tconst boundedField = (text: string, maxBytes: number) =>\n\t\ttruncateHead(boundText(sanitizeBinaryOutput(text), maxBytes), { maxBytes, maxLines: 100 }).content;\n\treturn [\n\t\tboundedField(header, 4096),\n\t\tslice.task.error ? `Task error: ${boundedField(slice.task.error, 4096)}` : \"\",\n\t\tslice.readError ? `Output read error: ${boundedField(slice.readError, 4096)}` : \"\",\n\t\tboundedField(slice.task.outputPath ?? \"\", 8192),\n\t\tslice.text || \"(no output yet)\",\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\"\\n\");\n}\nexport async function runRead(background: TasksContext, input: TasksInput): Promise<AgentToolResult<TasksReadDetails>> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst mode = input.mode ?? \"tail\";\n\t\tconst slice = await background.read(id, { mode, bytes: clampReadBytes(input.bytes) });\n\t\treturn result(readText(`[${describeTaskLine(slice.task)} · ${rangeText(slice)}]`, slice), {\n\t\t\taction: \"read\",\n\t\t\ttaskId: slice.task.id,\n\t\t\tmode,\n\t\t\tsliceBytes: Buffer.byteLength(slice.text),\n\t\t\ttotalBytes: slice.totalBytes,\n\t\t\toutputPath: slice.task.outputPath ?? \"\",\n\t\t\tkind: slice.task.kind,\n\t\t\tstatus: slice.task.status,\n\t\t});\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nfunction activeBackgroundTasks(background: TasksContext): TaskSnapshot[] {\n\treturn background.list().filter((task) => task.mode === \"background\" && !isTaskTerminal(task.status));\n}\n\nfunction stillRunningText(tasks: TaskSnapshot[]): string {\n\treturn tasks.length > 0 ? `\\n\\n[still_running]\\n${tasks.map((task) => describeTaskLine(task)).join(\"\\n\")}` : \"\";\n}\n\nfunction emptyWaitDetails(\n\toutcome: \"interrupted\" | \"timed_out\" | \"no_tasks\",\n\twaitedMs: number,\n\trunning: number,\n): TasksWaitDetails {\n\treturn {\n\t\taction: \"wait\",\n\t\toutcome,\n\t\ttimedOut: outcome === \"timed_out\",\n\t\texitCode: undefined,\n\t\twaitedMs,\n\t\tdeltaBytes: 0,\n\t\ttotalBytes: 0,\n\t\tdeltaTruncated: false,\n\t\toutputPath: \"\",\n\t\trunning,\n\t};\n}\n\nasync function runWaitAny(\n\tbackground: TasksContext,\n\tinput: TasksInput,\n\tsignal?: AbortSignal,\n\tonReady?: (taskId: string) => void,\n\tinterruptSignal?: AbortSignal,\n): Promise<AgentToolResult<TasksWaitDetails>> {\n\tconst candidates = activeBackgroundTasks(background);\n\tif (candidates.length === 0) {\n\t\treturn result(\n\t\t\t\"No background tasks are running, so there is nothing to wait for. Finished tasks report back via automatic notification.\",\n\t\t\temptyWaitDetails(\"no_tasks\", 0, 0),\n\t\t);\n\t}\n\t// Holds cover the whole initial cohort until the winning result is ready for\n\t// persistence. Other completed tasks resume ordinary notification delivery on release.\n\tconst releases = candidates.map((task) => background.holdDelivery(task.id));\n\tconst start = Date.now();\n\ttry {\n\t\tconst task = await background.waitAny(clampWaitMs(input.waitMs), signal, interruptSignal);\n\t\tconst ids = new Set(candidates.map((candidate) => candidate.id));\n\t\tconst running = activeBackgroundTasks(background).filter((candidate) => ids.has(candidate.id));\n\t\tif (!task) {\n\t\t\tconst interrupted = !background.closed && interruptSignal?.aborted === true;\n\t\t\tconst outcome = interrupted ? \"interrupted\" : \"timed_out\";\n\t\t\tconst note = background.closed\n\t\t\t\t? \"The host closed; execution state is unconfirmed.\"\n\t\t\t\t: interrupted\n\t\t\t\t\t? \"New steering input ended this wait early. Read the new input before deciding what to do next; no task was stopped.\"\n\t\t\t\t\t: \"The wait window expired; running tasks continue. Prefer other work over waiting again.\";\n\t\t\treturn result(\n\t\t\t\t`${note}${stillRunningText(running)}`,\n\t\t\t\temptyWaitDetails(outcome, Date.now() - start, running.length),\n\t\t\t);\n\t\t}\n\t\tconst slice = await background.read(task.id, { bytes: TASKS_WAIT_DELTA_BYTES });\n\t\tsignal?.throwIfAborted();\n\t\tonReady?.(task.id);\n\t\treturn result(\n\t\t\t`${readText(`[${describeTaskLine(task)} · waitAny settled · ${rangeText(slice)}]`, slice)}${stillRunningText(running)}`,\n\t\t\t{\n\t\t\t\taction: \"wait\",\n\t\t\t\toutcome: \"settled\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\tstatus: task.status,\n\t\t\t\tkind: task.kind,\n\t\t\t\ttimedOut: false,\n\t\t\t\texitCode: task.exitCode,\n\t\t\t\twaitedMs: Date.now() - start,\n\t\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tdeltaTruncated: slice.truncated,\n\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t\trunning: running.length,\n\t\t\t},\n\t\t);\n\t} finally {\n\t\tfor (const release of releases) release();\n\t}\n}\n\nexport async function runWait(\n\tbackground: TasksContext,\n\tinput: TasksInput,\n\tsignal?: AbortSignal,\n\tonReady?: (taskId: string) => void,\n\tinterruptSignal?: AbortSignal,\n): Promise<AgentToolResult<TasksWaitDetails>> {\n\tif (!input.taskId?.trim()) {\n\t\tif (input.sinceBytes !== undefined)\n\t\t\tthrow new Error(\"action 'wait' without 'taskId' does not accept 'sinceBytes'; offsets belong to one task.\");\n\t\treturn runWaitAny(background, input, signal, onReady, interruptSignal);\n\t}\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst release = background.holdDelivery(id);\n\t\ttry {\n\t\t\tconst start = Date.now();\n\t\t\tconst task = await background.wait(id, clampWaitMs(input.waitMs), signal, interruptSignal);\n\t\t\tconst settled = isTaskTerminal(task.status);\n\t\t\tconst interrupted = !settled && !background.closed && interruptSignal?.aborted === true;\n\t\t\tconst timedOut = !settled && !interrupted;\n\t\t\tconst outcome = settled ? \"settled\" : interrupted ? \"interrupted\" : \"timed_out\";\n\t\t\tconst waitedMs = Date.now() - start;\n\t\t\tif (interrupted) {\n\t\t\t\treturn result(\n\t\t\t\t\t`[${describeTaskLine(task)} · interrupted by steering; execution continues]\\nRead the new input before deciding whether to wait again; the task was not stopped.`,\n\t\t\t\t\t{\n\t\t\t\t\t\taction: \"wait\",\n\t\t\t\t\t\toutcome,\n\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\tstatus: task.status,\n\t\t\t\t\t\tkind: task.kind,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\texitCode: task.exitCode,\n\t\t\t\t\t\twaitedMs,\n\t\t\t\t\t\tdeltaBytes: 0,\n\t\t\t\t\t\ttotalBytes: 0,\n\t\t\t\t\t\tdeltaTruncated: false,\n\t\t\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\t// A closed host resolves waits early without settling anything; do not claim\n\t\t\t// the execution merely outlived the wait window.\n\t\t\tconst windowNote = background.closed\n\t\t\t\t? \" · host closed; execution state unconfirmed\"\n\t\t\t\t: timedOut\n\t\t\t\t\t? \" · wait window expired; execution continues\"\n\t\t\t\t\t: \"\";\n\t\t\tconst sinceBytes = clampSinceBytes(input.sinceBytes);\n\t\t\tconst slice = await background.read(id, { bytes: TASKS_WAIT_DELTA_BYTES, sinceBytes });\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (settled) onReady?.(task.id);\n\t\t\treturn result(readText(`[${describeTaskLine(task)}${windowNote} · ${rangeText(slice, sinceBytes)}]`, slice), {\n\t\t\t\taction: \"wait\",\n\t\t\t\toutcome,\n\t\t\t\ttaskId: task.id,\n\t\t\t\tstatus: task.status,\n\t\t\t\tkind: task.kind,\n\t\t\t\ttimedOut,\n\t\t\t\texitCode: task.exitCode,\n\t\t\t\twaitedMs,\n\t\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tdeltaTruncated: slice.truncated,\n\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t});\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runKill(background: TasksContext, input: TasksInput): AgentToolResult<TasksKillDetails> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst task = background.get(id);\n\t\tconst requested = background.kill(task.id);\n\t\treturn result(\n\t\t\trequested\n\t\t\t\t? `Cancellation requested for ${task.id}. The task or whole group is stopping; cleanup may still be in progress.`\n\t\t\t\t: `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`,\n\t\t\t{\n\t\t\t\taction: \"kill\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\tcommand: task.command ?? task.title,\n\t\t\t\trequested,\n\t\t\t\tstatus: background.get(task.id).status,\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runList(background: TasksContext): AgentToolResult<TasksListDetails> {\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isTaskTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isTaskTerminal(task.status)));\n\tconst shown = [...active, ...finished.slice(0, TASKS_LIST_FINISHED_SHOWN)].slice(0, 100);\n\tconst hidden = tasks.length - shown.length;\n\treturn result(\n\t\tshown.length\n\t\t\t? `${shown.map((task) => describeTaskLine(task)).join(\"\\n\")}${hidden > 0 ? `\\n${hidden} more records not shown.` : \"\"}${foregroundOmissionNote(foregroundOmitted)}`\n\t\t\t: `No background tasks. Start work through its owning tool with background: true.${foregroundOmissionNote(foregroundOmitted)}`,\n\t\t{\n\t\t\taction: \"list\",\n\t\t\trunning: active.length,\n\t\t\tfinished: finished.length,\n\t\t\tshown: shown.length,\n\t\t\thidden,\n\t\t\t...(foregroundOmitted > 0 ? { foregroundOmitted } : {}),\n\t\t},\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/actions.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAGlF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EACN,cAAc,EACd,eAAe,GAIf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAG3G,MAAM,UAAU,WAAW,CAAC,IAAY;IACvC,OAAO,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC;AAClG,CAAC;AACD,SAAS,MAAM,CAAyB,IAAY,EAAE,OAAU;IAC/D,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;AAC1E,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,IAAkB,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IACpE,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,K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,KAAK,CAAC,MAAM;QACX,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,0BAA0B,CAAC,CAAC,CAAC,EAAE,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,EAAE;QACnK,CAAC,CAAC,iFAAiF,sBAAsB,CAAC,iBAAiB,CAAC,EAAE,EAC/H;QACC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,QAAQ,EAAE,QAAQ,CAAC,MAAM;QACzB,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,MAAM;QACN,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CACD,CAAC;AACH,CAAC","sourcesContent":["/** Management only: execution and delivery belong to the session task runtime. */\n\nimport type { AgentToolResult } from \"../../../core/extensions/types.ts\";\nimport { runtimeLabel } from \"../../../core/tasks/format.ts\";\nimport { boundText } from \"../../../core/tasks/output.ts\";\nimport {\n\tisTaskTerminal,\n\tTaskLookupError,\n\ttype TaskRead,\n\ttype TaskSnapshot,\n\ttype TasksContext,\n} from \"../../../core/tasks/types.ts\";\nimport { truncateHead } from \"../../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../../utils/shell.ts\";\nimport { TASKS_LIST_FINISHED_SHOWN, TASKS_WAIT_DELTA_BYTES } from \"./constants.ts\";\nimport { clampReadBytes, clampSinceBytes, clampWaitMs, requireTaskId, type TasksInput } from \"./schema.ts\";\nimport type { TasksDetails, TasksKillDetails, TasksListDetails, TasksReadDetails, TasksWaitDetails } from \"./types.ts\";\n\nexport function boundedText(text: string): string {\n\treturn truncateHead(sanitizeBinaryOutput(text), { maxBytes: 50 * 1024, maxLines: 2000 }).content;\n}\nfunction result<T extends TasksDetails>(text: string, details: T): AgentToolResult<T> {\n\treturn { content: [{ type: \"text\", text: boundedText(text) }], details };\n}\nexport function describeTaskLine(task: TaskSnapshot, now = Date.now()): string {\n\treturn `${task.id} ${task.kind} ${task.status} (${task.mode}) ${runtimeLabel(task, now)} ${task.title.slice(0, 200)}`;\n}\n\nconst LOOKUP_LIST_LIMIT = 10;\n\n/**\n * Finished rows sort most-recent first. list() is creation-ordered, so an\n * unsorted slice would surface the oldest completions rather than the recent\n * finishes a caller is most likely looking for.\n */\nfunction recentFinishedFirst(tasks: TaskSnapshot[]): TaskSnapshot[] {\n\treturn tasks.sort((left, right) => (right.endedAt ?? 0) - (left.endedAt ?? 0));\n}\n\n/**\n * Listings cover backgrounded work only; foreground executions deliver inline\n * in the transcript, so they are counted rather than shown. Every listing\n * (tasks list output and lookup-failure messages) shares this scope.\n */\nfunction listedTasks(background: TasksContext): { tasks: TaskSnapshot[]; foregroundOmitted: number } {\n\tconst all = background.list();\n\tconst tasks = all.filter((task) => task.mode === \"background\");\n\treturn { tasks, foregroundOmitted: all.length - tasks.length };\n}\n\nfunction foregroundOmissionNote(omitted: number): string {\n\treturn omitted > 0\n\t\t? `\\n${omitted} foreground ${omitted === 1 ? \"execution\" : \"executions\"} omitted — foreground work is delivered inline in the transcript.`\n\t\t: \"\";\n}\n\n/**\n * Rewrite the service's bare lookup failure into an actionable one: an\n * unknown id gets the session's current tasks (active first, then recent\n * finishes) so the next call can use a real id without a separate list call,\n * and an ambiguous prefix gets exactly the tasks it matched — including\n * records outside the current branch, which listings hide but the prefix\n * still collides with.\n */\nfunction lookupFailure(background: TasksContext, id: string, error: unknown): Error {\n\tif (!(error instanceof TaskLookupError)) return error instanceof Error ? error : new Error(String(error));\n\tif (error.kind === \"ambiguous\") {\n\t\tconst lines = error.matches.map((task) => describeTaskLine(task)).join(\"\\n\");\n\t\treturn new Error(`Ambiguous task ID \"${id}\" matches ${error.matches.length} tasks:\\n${lines}`);\n\t}\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isTaskTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isTaskTerminal(task.status)));\n\tconst shown = [...active, ...finished].slice(0, LOOKUP_LIST_LIMIT);\n\tif (shown.length === 0) {\n\t\treturn new Error(`No task \"${id}\" in this session. No background tasks in this session.`);\n\t}\n\tconst lines = shown.map((task) => describeTaskLine(task)).join(\"\\n\");\n\treturn new Error(\n\t\t`No task \"${id}\" in this session. IDs from other sessions are not valid here.\\nCurrent background tasks:\\n${lines}${foregroundOmissionNote(foregroundOmitted)}`,\n\t);\n}\n\n/**\n * Where this slice sits in the output, so the next wait can continue from it.\n * A wait whose new output exceeds its budget returns the newest bytes and says what it skipped.\n */\nfunction rangeText(slice: TaskRead, sinceBytes?: number): string {\n\tconst from = slice.fromByte ?? 0;\n\tconst to = from + Buffer.byteLength(slice.text);\n\tconst floor = sinceBytes === undefined || sinceBytes > slice.totalBytes ? 0 : sinceBytes;\n\treturn [\n\t\t`bytes ${from}–${to} of ${slice.totalBytes}`,\n\t\tsinceBytes !== undefined && from > floor ? `skipped ${from - floor} bytes after sinceBytes ${floor}` : \"\",\n\t\t`next sinceBytes ${to}`,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\" · \");\n}\n\n/** Reserve space for each independent diagnostic before allowing raw output to fill the budget. */\nfunction readText(header: string, slice: TaskRead): string {\n\tconst boundedField = (text: string, maxBytes: number) =>\n\t\ttruncateHead(boundText(sanitizeBinaryOutput(text), maxBytes), { maxBytes, maxLines: 100 }).content;\n\treturn [\n\t\tboundedField(header, 4096),\n\t\tslice.task.error ? `Task error: ${boundedField(slice.task.error, 4096)}` : \"\",\n\t\tslice.readError ? `Output read error: ${boundedField(slice.readError, 4096)}` : \"\",\n\t\tboundedField(slice.task.outputPath ?? \"\", 8192),\n\t\tslice.text || \"(no output yet)\",\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\"\\n\");\n}\nexport async function runRead(background: TasksContext, input: TasksInput): Promise<AgentToolResult<TasksReadDetails>> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst mode = input.mode ?? \"tail\";\n\t\tconst slice = await background.read(id, { mode, bytes: clampReadBytes(input.bytes) });\n\t\treturn result(readText(`[${describeTaskLine(slice.task)} · ${rangeText(slice)}]`, slice), {\n\t\t\taction: \"read\",\n\t\t\ttaskId: slice.task.id,\n\t\t\tmode,\n\t\t\tsliceBytes: Buffer.byteLength(slice.text),\n\t\t\ttotalBytes: slice.totalBytes,\n\t\t\toutputPath: slice.task.outputPath ?? \"\",\n\t\t\tkind: slice.task.kind,\n\t\t\tstatus: slice.task.status,\n\t\t});\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nfunction activeBackgroundTasks(background: TasksContext): TaskSnapshot[] {\n\treturn background.list().filter((task) => task.mode === \"background\" && !isTaskTerminal(task.status));\n}\n\nfunction stillRunningText(tasks: TaskSnapshot[]): string {\n\treturn tasks.length > 0 ? `\\n\\n[still_running]\\n${tasks.map((task) => describeTaskLine(task)).join(\"\\n\")}` : \"\";\n}\n\nfunction emptyWaitDetails(\n\toutcome: \"interrupted\" | \"timed_out\" | \"no_tasks\",\n\twaitedMs: number,\n\trunning: number,\n): TasksWaitDetails {\n\treturn {\n\t\taction: \"wait\",\n\t\toutcome,\n\t\twaitedMs,\n\t\tdeltaBytes: 0,\n\t\ttotalBytes: 0,\n\t\tdeltaTruncated: false,\n\t\toutputPath: \"\",\n\t\trunning,\n\t};\n}\n\nasync function runWaitAny(\n\tbackground: TasksContext,\n\tinput: TasksInput,\n\tsignal?: AbortSignal,\n\tonReady?: (taskId: string) => void,\n\tinterruptSignal?: AbortSignal,\n): Promise<AgentToolResult<TasksWaitDetails>> {\n\tconst candidates = activeBackgroundTasks(background);\n\tif (candidates.length === 0) {\n\t\treturn result(\n\t\t\t\"No background tasks are running, so there is nothing to wait for. Finished tasks report back via automatic notification.\",\n\t\t\temptyWaitDetails(\"no_tasks\", 0, 0),\n\t\t);\n\t}\n\t// Holds cover the whole initial cohort until the winning result is ready for\n\t// persistence. Other completed tasks resume ordinary notification delivery on release.\n\tconst releases = candidates.map((task) => background.holdDelivery(task.id));\n\tconst start = Date.now();\n\ttry {\n\t\tconst task = await background.waitAny(clampWaitMs(input.waitMs), signal, interruptSignal);\n\t\tconst ids = new Set(candidates.map((candidate) => candidate.id));\n\t\tconst running = activeBackgroundTasks(background).filter((candidate) => ids.has(candidate.id));\n\t\tif (!task) {\n\t\t\tconst interrupted = !background.closed && interruptSignal?.aborted === true;\n\t\t\tconst outcome = interrupted ? \"interrupted\" : \"timed_out\";\n\t\t\tconst note = background.closed\n\t\t\t\t? \"The host closed; execution state is unconfirmed.\"\n\t\t\t\t: interrupted\n\t\t\t\t\t? \"New steering input ended this wait early. Read the new input before deciding what to do next; no task was stopped.\"\n\t\t\t\t\t: \"The wait window expired; running tasks continue. Prefer other work over waiting again.\";\n\t\t\treturn result(\n\t\t\t\t`${note}${stillRunningText(running)}`,\n\t\t\t\temptyWaitDetails(outcome, Date.now() - start, running.length),\n\t\t\t);\n\t\t}\n\t\tconst slice = await background.read(task.id, { bytes: TASKS_WAIT_DELTA_BYTES });\n\t\tsignal?.throwIfAborted();\n\t\tonReady?.(task.id);\n\t\treturn result(\n\t\t\t`${readText(`[${describeTaskLine(task)} · waitAny settled · ${rangeText(slice)}]`, slice)}${stillRunningText(running)}`,\n\t\t\t{\n\t\t\t\taction: \"wait\",\n\t\t\t\toutcome: \"settled\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\tstatus: task.status,\n\t\t\t\tkind: task.kind,\n\t\t\t\twaitedMs: Date.now() - start,\n\t\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tdeltaTruncated: slice.truncated,\n\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t\trunning: running.length,\n\t\t\t},\n\t\t);\n\t} finally {\n\t\tfor (const release of releases) release();\n\t}\n}\n\nexport async function runWait(\n\tbackground: TasksContext,\n\tinput: TasksInput,\n\tsignal?: AbortSignal,\n\tonReady?: (taskId: string) => void,\n\tinterruptSignal?: AbortSignal,\n): Promise<AgentToolResult<TasksWaitDetails>> {\n\tif (!input.taskId?.trim()) {\n\t\tif (input.sinceBytes !== undefined)\n\t\t\tthrow new Error(\"action 'wait' without 'taskId' does not accept 'sinceBytes'; offsets belong to one task.\");\n\t\treturn runWaitAny(background, input, signal, onReady, interruptSignal);\n\t}\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst release = background.holdDelivery(id);\n\t\ttry {\n\t\t\tconst start = Date.now();\n\t\t\tconst task = await background.wait(id, clampWaitMs(input.waitMs), signal, interruptSignal);\n\t\t\tconst settled = isTaskTerminal(task.status);\n\t\t\tconst interrupted = !settled && !background.closed && interruptSignal?.aborted === true;\n\t\t\tconst timedOut = !settled && !interrupted;\n\t\t\tconst outcome = settled ? \"settled\" : interrupted ? \"interrupted\" : \"timed_out\";\n\t\t\tconst waitedMs = Date.now() - start;\n\t\t\tif (interrupted) {\n\t\t\t\treturn result(\n\t\t\t\t\t`[${describeTaskLine(task)} · interrupted by steering; execution continues]\\nRead the new input before deciding whether to wait again; the task was not stopped.`,\n\t\t\t\t\t{\n\t\t\t\t\t\taction: \"wait\",\n\t\t\t\t\t\toutcome,\n\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\tstatus: task.status,\n\t\t\t\t\t\tkind: task.kind,\n\t\t\t\t\t\twaitedMs,\n\t\t\t\t\t\tdeltaBytes: 0,\n\t\t\t\t\t\ttotalBytes: 0,\n\t\t\t\t\t\tdeltaTruncated: false,\n\t\t\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\t// A closed host resolves waits early without settling anything; do not claim\n\t\t\t// the execution merely outlived the wait window.\n\t\t\tconst windowNote = background.closed\n\t\t\t\t? \" · host closed; execution state unconfirmed\"\n\t\t\t\t: timedOut\n\t\t\t\t\t? \" · wait window expired; execution continues\"\n\t\t\t\t\t: \"\";\n\t\t\tconst sinceBytes = clampSinceBytes(input.sinceBytes);\n\t\t\tconst slice = await background.read(id, { bytes: TASKS_WAIT_DELTA_BYTES, sinceBytes });\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (settled) onReady?.(task.id);\n\t\t\treturn result(readText(`[${describeTaskLine(task)}${windowNote} · ${rangeText(slice, sinceBytes)}]`, slice), {\n\t\t\t\taction: \"wait\",\n\t\t\t\toutcome,\n\t\t\t\ttaskId: task.id,\n\t\t\t\tstatus: task.status,\n\t\t\t\tkind: task.kind,\n\t\t\t\twaitedMs,\n\t\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tdeltaTruncated: slice.truncated,\n\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t});\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runKill(background: TasksContext, input: TasksInput): AgentToolResult<TasksKillDetails> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst task = background.get(id);\n\t\tconst requested = background.kill(task.id);\n\t\treturn result(\n\t\t\trequested\n\t\t\t\t? `Cancellation requested for ${task.id}. The task or whole group is stopping; cleanup may still be in progress.`\n\t\t\t\t: `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`,\n\t\t\t{\n\t\t\t\taction: \"kill\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\ttitle: task.title,\n\t\t\t\trequested,\n\t\t\t\tstatus: background.get(task.id).status,\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runList(background: TasksContext): AgentToolResult<TasksListDetails> {\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isTaskTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isTaskTerminal(task.status)));\n\tconst shown = [...active, ...finished.slice(0, TASKS_LIST_FINISHED_SHOWN)].slice(0, 100);\n\tconst hidden = tasks.length - shown.length;\n\treturn result(\n\t\tshown.length\n\t\t\t? `${shown.map((task) => describeTaskLine(task)).join(\"\\n\")}${hidden > 0 ? `\\n${hidden} more records not shown.` : \"\"}${foregroundOmissionNote(foregroundOmitted)}`\n\t\t\t: `No background tasks. Start work through its owning tool with background: true.${foregroundOmissionNote(foregroundOmitted)}`,\n\t\t{\n\t\t\taction: \"list\",\n\t\t\trunning: active.length,\n\t\t\tfinished: finished.length,\n\t\t\tshown: shown.length,\n\t\t\thidden,\n\t\t\t...(foregroundOmitted > 0 ? { foregroundOmitted } : {}),\n\t\t},\n\t);\n}\n"]}
|
|
@@ -61,7 +61,7 @@ export function clampSinceBytes(sinceBytes) {
|
|
|
61
61
|
export const TASKS_TOOL_DESCRIPTION = "Inspect and control background tasks started by native tools or extensions. " +
|
|
62
62
|
"Completion is delivered to you automatically as a notification — never poll. " +
|
|
63
63
|
"list: bounded activity/history listing; find task IDs here. " +
|
|
64
|
-
"read: bounded output or report slice (head/tail). " +
|
|
64
|
+
"read: bounded model-readable output or report slice (head/tail); tool-call activity stays in /tasks. " +
|
|
65
65
|
"wait: observe one task, or any task running at call time, for up to waitMs; no running tasks returns immediately. New steering input ends only the wait with outcome interrupted; it never stops the task. " +
|
|
66
66
|
"kill: request cancellation of a whole task. " +
|
|
67
67
|
"tasks cannot start work; submit background work through its owning tool. A wait ends as settled, interrupted, timed_out, or no_tasks. Timeout or cancellation ends only the wait, never execution. Reads and settled waits report byte ranges; use next sinceBytes only with that task's ID. Output is capped at 50KB per response.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAA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,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC;IAC/F,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpF,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,UAA8B;IAC7D,OAAO,UAAU,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AACnH,CAAC;AAED,MAAM,CAAC,MAAM,sBAAsB,GAClC,8EAA8E;IAC9E,+EAA+E;IAC/E,8DAA8D;IAC9D,uGAAuG;IACvG,6MAA6M;IAC7M,8CAA8C;IAC9C,qUAAqU,CAAC;AACvU,MAAM,CAAC,MAAM,oBAAoB,GAAG,uEAAuE,CAAC;AAC5G,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACtC,+GAA+G;IAC/G,qPAAqP;IACrP,gKAAgK;CAChK,CAAC","sourcesContent":["/**\n * The `tasks` tool's wire contract: one flat schema whose `action`\n * selects which of the remaining fields apply, plus the model-facing copy.\n *\n * The schema stays flat deliberately: a single tool keeps the model's tool list\n * short. Execution creation belongs to the native tools. Narrowing happens\n * inside actions.ts, not here.\n */\n\nimport { StringEnum } from \"@earendil-works/pi-ai\";\nimport { type Static, Type } from \"typebox\";\nimport { formatDuration } from \"../../../core/tasks/format.ts\";\nimport { TASK_RESULT_BYTES } from \"../../../core/tasks/output.ts\";\nimport { formatSize } from \"../../../core/tools/truncate.ts\";\nimport {\n\tTASKS_LOGS_DEFAULT_BYTES,\n\tTASKS_LOGS_MIN_BYTES,\n\tTASKS_WAIT_DEFAULT_MS,\n\tTASKS_WAIT_MAX_MS,\n\tTASKS_WAIT_MIN_MS,\n} from \"./constants.ts\";\n\nexport const tasksSchema = Type.Object({\n\taction: StringEnum([\"read\", \"wait\", \"kill\", \"list\"] as const, {\n\t\tdescription: \"Which task operation to perform\",\n\t}),\n\t// — read / wait / kill —\n\ttaskId: Type.Optional(\n\t\tType.String({\n\t\t\tdescription: \"Task execution id (read/wait/kill). Omit for wait to wait for any task running at call time.\",\n\t\t}),\n\t),\n\t// — read —\n\tmode: Type.Optional(\n\t\tStringEnum([\"tail\", \"head\"] as const, {\n\t\t\tdescription: \"Read from the end (default) or the start of the output (read)\",\n\t\t}),\n\t),\n\tbytes: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Max bytes to return (read, default ${formatSize(TASKS_LOGS_DEFAULT_BYTES)}, max ${formatSize(TASK_RESULT_BYTES)})`,\n\t\t}),\n\t),\n\t// — wait —\n\twaitMs: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Maximum wait window in ms (default ${formatDuration(TASKS_WAIT_DEFAULT_MS)}, max ${formatDuration(TASKS_WAIT_MAX_MS)}). Only the wait ends on timeout; execution continues.`,\n\t\t}),\n\t),\n\tsinceBytes: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription:\n\t\t\t\t\"Only return output written after this byte offset — use the 'next sinceBytes' value from a previous read or wait (wait with taskId only)\",\n\t\t}),\n\t),\n});\n\n/** Raw tool arguments. Every per-action field is optional here; actions.ts narrows. */\nexport type TasksInput = Static<typeof tasksSchema>;\n\n// ── reading the contract ──────────────────────────────────────────────────\n// One place per field: required fields throw a message that names the next\n// step, optional ones clamp to their documented range. Callers get plain\n// values, so no action handler needs a cast.\n\nexport function requireTaskId(input: TasksInput): string {\n\tconst taskId = input.taskId;\n\tif (!taskId || taskId.trim().length === 0) {\n\t\tthrow new Error(`action '${input.action}' requires 'taskId' — use action list to find the execution id.`);\n\t}\n\treturn taskId;\n}\n\nexport function clampReadBytes(bytes: number | undefined): number {\n\tconst value = bytes !== undefined && Number.isFinite(bytes) ? bytes : TASKS_LOGS_DEFAULT_BYTES;\n\treturn Math.min(TASK_RESULT_BYTES, Math.max(TASKS_LOGS_MIN_BYTES, Math.floor(value)));\n}\n\n/** Shared with the pending-call renderer so the window it shows is the one that runs. */\nexport function clampWaitMs(waitMs: number | undefined): number {\n\tconst value = waitMs !== undefined && Number.isFinite(waitMs) ? waitMs : TASKS_WAIT_DEFAULT_MS;\n\treturn Math.min(TASKS_WAIT_MAX_MS, Math.max(TASKS_WAIT_MIN_MS, Math.floor(value)));\n}\n\nexport function clampSinceBytes(sinceBytes: number | undefined): number | undefined {\n\treturn sinceBytes === undefined || !Number.isFinite(sinceBytes) ? undefined : Math.max(0, Math.floor(sinceBytes));\n}\n\nexport const TASKS_TOOL_DESCRIPTION =\n\t\"Inspect and control background tasks started by native tools or extensions. \" +\n\t\"Completion is delivered to you automatically as a notification — never poll. \" +\n\t\"list: bounded activity/history listing; find task IDs here. \" +\n\t\"read: bounded model-readable output or report slice (head/tail); tool-call activity stays in /tasks. \" +\n\t\"wait: observe one task, or any task running at call time, for up to waitMs; no running tasks returns immediately. New steering input ends only the wait with outcome interrupted; it never stops the task. \" +\n\t\"kill: request cancellation of a whole task. \" +\n\t\"tasks cannot start work; submit background work through its owning tool. A wait ends as settled, interrupted, timed_out, or no_tasks. Timeout or cancellation ends only the wait, never execution. Reads and settled waits report byte ranges; use next sinceBytes only with that task's ID. Output is capped at 50KB per response.\";\nexport const TASKS_PROMPT_SNIPPET = \"Manage background tasks; wait for a specific task or any running task\";\nexport const TASKS_PROMPT_GUIDELINES = [\n\t\"Start background work through its owning tool with background: true; continue independent work while it runs.\",\n\t\"A finished background task delivers its result automatically as a notification. Use tasks wait only when your next step is blocked: provide taskId for one task or omit it for any task running at call time; never sleep-poll with repeated reads.\",\n\t\"A new steering message interrupts only an active tasks wait so you can read the new input; it does not cancel execution. A wait timeout is not a task failure.\",\n];\n"]}
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* by the renderers on `/reload`, `/tree`, and session resume. Adding an optional
|
|
6
6
|
* field is free; renaming or repurposing an existing one degrades historical
|
|
7
7
|
* transcripts.
|
|
8
|
-
*
|
|
9
|
-
* `exitCode` is three-state: `null` for signal-reaped tasks.
|
|
10
8
|
*/
|
|
11
9
|
import type { TaskKind, TaskStatus } from "../../../core/tasks/types.ts";
|
|
12
10
|
export interface TasksReadDetails {
|
|
@@ -23,14 +21,10 @@ export type TasksWaitOutcome = "settled" | "interrupted" | "timed_out" | "no_tas
|
|
|
23
21
|
export interface TasksWaitDetails {
|
|
24
22
|
kind?: TaskKind;
|
|
25
23
|
action: "wait";
|
|
26
|
-
|
|
27
|
-
outcome?: TasksWaitOutcome;
|
|
24
|
+
outcome: TasksWaitOutcome;
|
|
28
25
|
/** Undefined for waitAny with no selected task, or when no tasks were running. */
|
|
29
26
|
taskId?: string;
|
|
30
|
-
/** Retained for compatibility with historical details; true only for a wait-window expiry. */
|
|
31
|
-
timedOut: boolean;
|
|
32
27
|
status?: TaskStatus;
|
|
33
|
-
exitCode: number | null | undefined;
|
|
34
28
|
waitedMs: number;
|
|
35
29
|
deltaBytes: number;
|
|
36
30
|
totalBytes: number;
|
|
@@ -44,7 +38,7 @@ export interface TasksKillDetails {
|
|
|
44
38
|
status?: TaskStatus;
|
|
45
39
|
action: "kill";
|
|
46
40
|
taskId: string;
|
|
47
|
-
|
|
41
|
+
title: string;
|
|
48
42
|
}
|
|
49
43
|
export interface TasksListDetails {
|
|
50
44
|
action: "list";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAEzE,MAAM,WA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AAG,gBAAgB,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,gBAAgB,CAAC"}
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* by the renderers on `/reload`, `/tree`, and session resume. Adding an optional
|
|
6
6
|
* field is free; renaming or repurposing an existing one degrades historical
|
|
7
7
|
* transcripts.
|
|
8
|
-
*
|
|
9
|
-
* `exitCode` is three-state: `null` for signal-reaped tasks.
|
|
10
8
|
*/
|
|
11
9
|
export {};
|
|
12
10
|
//# sourceMappingURL=types.js.map
|