@narumitw/pi-subagents 2.0.6 → 2.1.0
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 +152 -50
- package/dist/chunks/{auto-transport-SY2VHUFH.ts → auto-transport-FUUKFDIG.ts} +6 -6
- package/dist/chunks/{capability-grant-CGEWOEKE.ts → capability-grant-PR72SWWS.ts} +4 -4
- package/dist/chunks/{chunk-DPPVEQAM.ts → chunk-4AQSF7AS.ts} +1 -1
- package/dist/chunks/chunk-4AQSF7AS.ts.map +7 -0
- package/dist/chunks/chunk-6H6TBBED.ts +108 -0
- package/dist/chunks/chunk-6H6TBBED.ts.map +7 -0
- package/dist/chunks/{chunk-DSOOH73Y.ts → chunk-7AAJEUSL.ts} +3 -3
- package/dist/chunks/{chunk-DSOOH73Y.ts.map → chunk-7AAJEUSL.ts.map} +2 -2
- package/dist/chunks/{chunk-7QPPBBXZ.ts → chunk-D4CR7T73.ts} +21 -3
- package/dist/chunks/chunk-D4CR7T73.ts.map +7 -0
- package/dist/chunks/{chunk-434NII74.ts → chunk-DIHBUR2E.ts} +54 -8
- package/dist/chunks/chunk-DIHBUR2E.ts.map +7 -0
- package/dist/chunks/{chunk-NIF42QMF.ts → chunk-FEVPWRMU.ts} +7 -4
- package/dist/chunks/chunk-FEVPWRMU.ts.map +7 -0
- package/dist/chunks/{chunk-YBUWBRF7.ts → chunk-FXI45N3J.ts} +5 -5
- package/dist/chunks/{chunk-S2IWVK3J.ts → chunk-ILEQ27AL.ts} +3 -2
- package/dist/chunks/chunk-ILEQ27AL.ts.map +7 -0
- package/dist/chunks/{chunk-DQMN4OYM.ts → chunk-ITVWPNU4.ts} +12 -106
- package/dist/chunks/chunk-ITVWPNU4.ts.map +7 -0
- package/dist/chunks/{chunk-QDVGH2X7.ts → chunk-IWC32VPY.ts} +2 -1
- package/dist/chunks/{chunk-QDVGH2X7.ts.map → chunk-IWC32VPY.ts.map} +2 -2
- package/dist/chunks/{chunk-I2FAK44T.ts → chunk-JSZIP73U.ts} +48 -10
- package/dist/chunks/chunk-JSZIP73U.ts.map +7 -0
- package/dist/chunks/{chunk-ZHTNCZIA.ts → chunk-JU6LUNLP.ts} +2 -2
- package/dist/chunks/{chunk-PSK43Y6A.ts → chunk-LASD73CM.ts} +2 -2
- package/dist/chunks/{chunk-C4L6P266.ts → chunk-LEOYDZI3.ts} +1 -1
- package/dist/chunks/{chunk-C4L6P266.ts.map → chunk-LEOYDZI3.ts.map} +2 -2
- package/dist/chunks/{chunk-H3BFJ7HJ.ts → chunk-LL4LP2T7.ts} +5 -5
- package/dist/chunks/chunk-N2T5IN4X.ts +18 -0
- package/dist/chunks/chunk-N2T5IN4X.ts.map +7 -0
- package/dist/chunks/{chunk-G3RSMSXJ.ts → chunk-NTRPLF46.ts} +1 -1
- package/dist/chunks/chunk-NTRPLF46.ts.map +7 -0
- package/dist/chunks/{chunk-CBP76ARQ.ts → chunk-PABJJYP6.ts} +174 -47
- package/dist/chunks/chunk-PABJJYP6.ts.map +7 -0
- package/dist/chunks/{chunk-EFBPISNT.ts → chunk-PBZMBTNJ.ts} +104 -103
- package/dist/chunks/chunk-PBZMBTNJ.ts.map +7 -0
- package/dist/chunks/{chunk-SCZ33MYW.ts → chunk-PGLSFLYW.ts} +2 -2
- package/dist/chunks/{chunk-O4VO6JUJ.ts → chunk-TM2R67J3.ts} +3 -3
- package/dist/chunks/{chunk-QBORTI4W.ts → chunk-TMZRHIIK.ts} +32 -3
- package/dist/chunks/chunk-TMZRHIIK.ts.map +7 -0
- package/dist/chunks/chunk-TZ34IQ3M.ts +59 -0
- package/dist/chunks/chunk-TZ34IQ3M.ts.map +7 -0
- package/dist/chunks/chunk-VBDGNNLM.ts +214 -0
- package/dist/chunks/chunk-VBDGNNLM.ts.map +7 -0
- package/dist/chunks/{chunk-7OBINKFM.ts → chunk-VDG7LTYE.ts} +11 -11
- package/dist/chunks/chunk-VDG7LTYE.ts.map +7 -0
- package/dist/chunks/{chunk-AEUYS7JC.ts → chunk-X4NMONPE.ts} +1 -1
- package/dist/chunks/chunk-X4NMONPE.ts.map +7 -0
- package/dist/chunks/{chunk-HKC4ES4B.ts → chunk-YPJEN6NU.ts} +2 -2
- package/dist/chunks/{completion-delivery-YPOWSSV3.ts → completion-delivery-JVLNQRWX.ts} +5 -4
- package/dist/chunks/{config-status-J4GPWP46.ts → config-status-FKGDECZ3.ts} +7 -6
- package/dist/chunks/{config-ui-2YUCUEBM.ts → config-ui-DDKERQHI.ts} +297 -231
- package/dist/chunks/config-ui-DDKERQHI.ts.map +7 -0
- package/dist/chunks/{consult-IV7UBNQQ.ts → consult-PQ6PRAKC.ts} +14 -13
- package/dist/chunks/consult-PQ6PRAKC.ts.map +7 -0
- package/dist/chunks/{create-stateful-transport-ZP3IXNV3.ts → create-stateful-transport-JWC2EFYL.ts} +6 -6
- package/dist/chunks/{delegation-contract-WJPT4FVS.ts → delegation-contract-LA56I5DT.ts} +2 -2
- package/dist/chunks/{discovery-K25T3SH4.ts → discovery-MIFB2U4Y.ts} +3 -3
- package/dist/chunks/{execution-LA7HN5YF.ts → execution-Q2JZLKJA.ts} +19 -16
- package/dist/chunks/execution-Q2JZLKJA.ts.map +7 -0
- package/dist/chunks/{in-process-transport-4RF3J6XK.ts → in-process-transport-HJ6TZXC3.ts} +9 -9
- package/dist/chunks/{inspect-XV2QALMR.ts → inspect-UH2TKH6E.ts} +25 -10
- package/dist/chunks/inspect-UH2TKH6E.ts.map +7 -0
- package/dist/chunks/{persistence-VSGXAW4P.ts → persistence-XHPJBZL7.ts} +11 -7
- package/dist/chunks/persistence-XHPJBZL7.ts.map +7 -0
- package/dist/chunks/{registry-E6XPJB7L.ts → registry-XDXPECWF.ts} +136 -15
- package/dist/chunks/registry-XDXPECWF.ts.map +7 -0
- package/dist/chunks/{retained-semantic-state-7WXSGRJU.ts → retained-semantic-state-GM75FZGE.ts} +3 -3
- package/dist/chunks/{rpc-transport-NEHBHWX4.ts → rpc-transport-7R7DVCEB.ts} +12 -16
- package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +7 -0
- package/dist/chunks/{spawn-idempotency-QGHO2WKC.ts → spawn-idempotency-BNHOSMZW.ts} +2 -2
- package/dist/chunks/{subprocess-transport-NSHOGDC4.ts → subprocess-transport-VHZJRBTW.ts} +15 -14
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +7 -0
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +164 -0
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +7 -0
- package/dist/index.ts +427 -30
- package/dist/index.ts.map +3 -3
- package/docs/async-runtime-protocol.md +69 -0
- package/docs/implementation-notes/pi-subagents-capability-matrix.md +62 -0
- package/docs/implementation-notes/pi-subagents-current-direction.md +99 -0
- package/docs/implementation-notes/pi-subagents-rpc-v1.md +153 -0
- package/docs/pi-subagents-diagrams.md +183 -0
- package/package.json +9 -8
- package/src/agents/types.ts +2 -0
- package/src/async-subagent-benchmark.ts +532 -0
- package/src/completion-delivery.ts +71 -4
- package/src/completion-render.ts +1 -0
- package/src/completion-requirement.ts +308 -0
- package/src/config-registration.ts +5 -5
- package/src/config-status.ts +66 -70
- package/src/config-ui.ts +244 -150
- package/src/consult-resources.ts +1 -1
- package/src/consult.ts +3 -8
- package/src/delegation-contract.ts +55 -9
- package/src/execution-plan.ts +1 -1
- package/src/execution-ui.ts +40 -29
- package/src/execution.ts +2 -3
- package/src/inspect.ts +24 -1
- package/src/orchestration-metrics.ts +1 -1
- package/src/panel-execution.ts +2 -3
- package/src/panel-failure.ts +1 -1
- package/src/panel-render.ts +1 -1
- package/src/parallel-limit-ui.ts +6 -5
- package/src/params.ts +2 -1
- package/src/persistence.ts +9 -0
- package/src/process-control.ts +43 -0
- package/src/registry-types.ts +5 -0
- package/src/registry.ts +162 -18
- package/src/render.ts +2 -1
- package/src/rpc-transport.ts +1 -1
- package/src/runner-outcome.ts +1 -1
- package/src/runner-result.ts +1 -1
- package/src/runner-types.ts +102 -0
- package/src/runner.ts +11 -192
- package/src/settings/inspection.ts +27 -0
- package/src/settings/schema.ts +9 -0
- package/src/settings-reader.ts +7 -0
- package/src/settings.ts +20 -0
- package/src/spawn-idempotency.ts +5 -0
- package/src/stateful-agent-view.ts +15 -19
- package/src/stateful-guidance.ts +14 -4
- package/src/stateful-limit-ui.ts +23 -20
- package/src/stateful-limits.ts +10 -10
- package/src/stateful-registration.ts +126 -9
- package/src/stateful-render.ts +27 -2
- package/src/subagent-details.ts +43 -0
- package/src/subagents-extension.ts +66 -8
- package/src/subagents.ts +2 -0
- package/src/subprocess-transport.ts +2 -1
- package/src/supervision.ts +2 -1
- package/src/timeout-finalization.ts +1 -1
- package/src/tool-schema-compatibility.ts +73 -0
- package/src/transport-types.ts +6 -0
- package/src/transport-ui.ts +18 -46
- package/src/usage-recording-config.ts +13 -0
- package/src/usage-recording-store.ts +183 -0
- package/src/usage-recording.ts +478 -0
- package/src/verification-harness.ts +1 -1
- package/src/workflow-ui.ts +17 -9
- package/dist/chunks/chunk-434NII74.ts.map +0 -7
- package/dist/chunks/chunk-7OBINKFM.ts.map +0 -7
- package/dist/chunks/chunk-7QPPBBXZ.ts.map +0 -7
- package/dist/chunks/chunk-AEUYS7JC.ts.map +0 -7
- package/dist/chunks/chunk-CBP76ARQ.ts.map +0 -7
- package/dist/chunks/chunk-DPPVEQAM.ts.map +0 -7
- package/dist/chunks/chunk-DQMN4OYM.ts.map +0 -7
- package/dist/chunks/chunk-EFBPISNT.ts.map +0 -7
- package/dist/chunks/chunk-G3RSMSXJ.ts.map +0 -7
- package/dist/chunks/chunk-I2FAK44T.ts.map +0 -7
- package/dist/chunks/chunk-NIF42QMF.ts.map +0 -7
- package/dist/chunks/chunk-QBORTI4W.ts.map +0 -7
- package/dist/chunks/chunk-S2IWVK3J.ts.map +0 -7
- package/dist/chunks/config-ui-2YUCUEBM.ts.map +0 -7
- package/dist/chunks/consult-IV7UBNQQ.ts.map +0 -7
- package/dist/chunks/execution-LA7HN5YF.ts.map +0 -7
- package/dist/chunks/inspect-XV2QALMR.ts.map +0 -7
- package/dist/chunks/persistence-VSGXAW4P.ts.map +0 -7
- package/dist/chunks/registry-E6XPJB7L.ts.map +0 -7
- package/dist/chunks/rpc-transport-NEHBHWX4.ts.map +0 -7
- package/dist/chunks/subprocess-transport-NSHOGDC4.ts.map +0 -7
- /package/dist/chunks/{auto-transport-SY2VHUFH.ts.map → auto-transport-FUUKFDIG.ts.map} +0 -0
- /package/dist/chunks/{capability-grant-CGEWOEKE.ts.map → capability-grant-PR72SWWS.ts.map} +0 -0
- /package/dist/chunks/{chunk-YBUWBRF7.ts.map → chunk-FXI45N3J.ts.map} +0 -0
- /package/dist/chunks/{chunk-ZHTNCZIA.ts.map → chunk-JU6LUNLP.ts.map} +0 -0
- /package/dist/chunks/{chunk-PSK43Y6A.ts.map → chunk-LASD73CM.ts.map} +0 -0
- /package/dist/chunks/{chunk-H3BFJ7HJ.ts.map → chunk-LL4LP2T7.ts.map} +0 -0
- /package/dist/chunks/{chunk-SCZ33MYW.ts.map → chunk-PGLSFLYW.ts.map} +0 -0
- /package/dist/chunks/{chunk-O4VO6JUJ.ts.map → chunk-TM2R67J3.ts.map} +0 -0
- /package/dist/chunks/{chunk-HKC4ES4B.ts.map → chunk-YPJEN6NU.ts.map} +0 -0
- /package/dist/chunks/{completion-delivery-YPOWSSV3.ts.map → completion-delivery-JVLNQRWX.ts.map} +0 -0
- /package/dist/chunks/{config-status-J4GPWP46.ts.map → config-status-FKGDECZ3.ts.map} +0 -0
- /package/dist/chunks/{create-stateful-transport-ZP3IXNV3.ts.map → create-stateful-transport-JWC2EFYL.ts.map} +0 -0
- /package/dist/chunks/{delegation-contract-WJPT4FVS.ts.map → delegation-contract-LA56I5DT.ts.map} +0 -0
- /package/dist/chunks/{discovery-K25T3SH4.ts.map → discovery-MIFB2U4Y.ts.map} +0 -0
- /package/dist/chunks/{in-process-transport-4RF3J6XK.ts.map → in-process-transport-HJ6TZXC3.ts.map} +0 -0
- /package/dist/chunks/{retained-semantic-state-7WXSGRJU.ts.map → retained-semantic-state-GM75FZGE.ts.map} +0 -0
- /package/dist/chunks/{spawn-idempotency-QGHO2WKC.ts.map → spawn-idempotency-BNHOSMZW.ts.map} +0 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
grammarSafeToolObject
|
|
5
|
+
} from "./chunk-TZ34IQ3M.ts";
|
|
3
6
|
import {
|
|
4
7
|
MAX_SPAWN_IDEMPOTENCY_KEY_LENGTH,
|
|
5
8
|
assertSpawnIdempotencyKey
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ILEQ27AL.ts";
|
|
7
10
|
import {
|
|
8
11
|
assertCurrentSpawn,
|
|
9
12
|
waitForOwnedSpawn
|
|
@@ -17,21 +20,21 @@ import {
|
|
|
17
20
|
} from "./chunk-ONDTY4EL.ts";
|
|
18
21
|
import {
|
|
19
22
|
confirmProjectAgent
|
|
20
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-TM2R67J3.ts";
|
|
21
24
|
import {
|
|
22
25
|
SUBAGENT_RESULT_FORMATS
|
|
23
26
|
} from "./chunk-RSUXZD6S.ts";
|
|
24
27
|
import {
|
|
25
28
|
DEFAULT_DELEGATION_CWD_POLICY,
|
|
26
29
|
readSubagentSettings
|
|
27
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-TMZRHIIK.ts";
|
|
28
31
|
import {
|
|
29
32
|
resolveStatefulLimits
|
|
30
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-VDG7LTYE.ts";
|
|
31
34
|
import {
|
|
32
35
|
THINKING_LEVELS,
|
|
33
36
|
isThinkingLevel
|
|
34
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-4AQSF7AS.ts";
|
|
35
38
|
import {
|
|
36
39
|
COLLAPSED_LIST_LIMIT,
|
|
37
40
|
expansionHint,
|
|
@@ -45,9 +48,14 @@ import {
|
|
|
45
48
|
textResult,
|
|
46
49
|
toolHeader
|
|
47
50
|
} from "./chunk-BFK2Z4ZF.ts";
|
|
51
|
+
import {
|
|
52
|
+
CompletionRequirementModeSchema,
|
|
53
|
+
completionRequirementsFromBranch,
|
|
54
|
+
reconcileRequiredCompletionContext
|
|
55
|
+
} from "./chunk-VBDGNNLM.ts";
|
|
48
56
|
import {
|
|
49
57
|
DelegationContractSchema
|
|
50
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-JSZIP73U.ts";
|
|
51
59
|
import {
|
|
52
60
|
DEFAULT_MAX_CONTEXT_BYTES,
|
|
53
61
|
MAX_SUBAGENT_TIMEOUT_MS,
|
|
@@ -58,23 +66,10 @@ import {
|
|
|
58
66
|
// src/stateful-agent-view.ts
|
|
59
67
|
function formatStatefulAgentLine(agent, now = Date.now()) {
|
|
60
68
|
const elapsedSeconds = Math.max(0, Math.floor((now - agent.updatedAt) / 1e3));
|
|
61
|
-
const actions = agent.state === "running" || agent.state === "starting" ? "interrupt, close" : agent.state === "closed" ? "inspect" : "send, close";
|
|
62
69
|
const task = agent.currentTask ? ` \u2014 ${sanitizeStatusLine(agent.currentTask, 80)}` : "";
|
|
63
70
|
const unread = agent.mailbox.filter((message) => !message.readAt).length;
|
|
64
71
|
const indent = " ".repeat(agent.depth);
|
|
65
|
-
|
|
66
|
-
const timeout = agent.currentTimeoutMs ?? agent.timeoutMs;
|
|
67
|
-
const timeoutText = timeout ? ` timeout:${timeout}ms` : "";
|
|
68
|
-
const idleTimeout = agent.currentIdleTimeoutMs ?? agent.idleTimeoutMs;
|
|
69
|
-
const idleText = idleTimeout ? ` idle:${idleTimeout}ms` : "";
|
|
70
|
-
const maxTurns = agent.currentMaxTurns ?? agent.maxTurns;
|
|
71
|
-
const turnsText = maxTurns ? ` turns:${maxTurns}` : "";
|
|
72
|
-
const maxToolCalls = agent.currentMaxToolCalls ?? agent.maxToolCalls;
|
|
73
|
-
const toolsText = maxToolCalls ? ` tools:${maxToolCalls}` : "";
|
|
74
|
-
const transport = agent.telemetry?.transport ? ` transport:${agent.telemetry.transport}` : "";
|
|
75
|
-
const phase = agent.telemetry?.phase ? ` phase:${agent.telemetry.phase}` : "";
|
|
76
|
-
const queued = agent.telemetry?.queuePosition ? ` queue:${agent.telemetry.queuePosition}` : "";
|
|
77
|
-
return `${indent}${sanitizeStatusLine(agent.taskPath ?? agent.id, 256)} (${sanitizeStatusLine(agent.id, 128)}) ${sanitizeStatusLine(agent.agent, 128)} ${agent.state} ${elapsedSeconds}s${thinking}${timeoutText}${idleText}${turnsText}${toolsText}${transport}${phase}${queued} unread:${unread} [${actions}]${task}`;
|
|
72
|
+
return `${indent}${sanitizeStatusLine(agent.taskPath ?? agent.id, 256)} \xB7 ${sanitizeStatusLine(agent.agent, 128)} \xB7 ${agentStateLabel(agent.state)} \xB7 updated ${elapsedSeconds}s ago \xB7 ${unread} unread${task}`;
|
|
78
73
|
}
|
|
79
74
|
function summarizeStatefulAgent(agent) {
|
|
80
75
|
return {
|
|
@@ -110,6 +105,9 @@ function summarizeStatefulAgent(agent) {
|
|
|
110
105
|
truncated: agent.contextTruncated === true
|
|
111
106
|
},
|
|
112
107
|
resultFormat: agent.resultFormat ?? "text",
|
|
108
|
+
completionRequirements: (agent.completionRequirements ?? []).map((record) => ({
|
|
109
|
+
...record
|
|
110
|
+
})),
|
|
113
111
|
structuredResult: agent.structuredResult,
|
|
114
112
|
termination: agent.termination,
|
|
115
113
|
outcome: agent.outcome,
|
|
@@ -123,6 +121,16 @@ function summarizeStatefulAgent(agent) {
|
|
|
123
121
|
policy: agent.policy
|
|
124
122
|
};
|
|
125
123
|
}
|
|
124
|
+
function agentStateLabel(state) {
|
|
125
|
+
switch (state) {
|
|
126
|
+
case "running":
|
|
127
|
+
return "working";
|
|
128
|
+
case "completed":
|
|
129
|
+
return "finished";
|
|
130
|
+
default:
|
|
131
|
+
return state;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
126
134
|
function sanitizeStatusLine(value, maxLength) {
|
|
127
135
|
return value.slice(0, maxLength).replace(/[\u0000-\u001f\u007f-\u009f]/gu, " ").replace(/\s+/gu, " ").trim();
|
|
128
136
|
}
|
|
@@ -143,23 +151,31 @@ import { Type as Type2 } from "typebox";
|
|
|
143
151
|
|
|
144
152
|
// src/stateful-guidance.ts
|
|
145
153
|
function createSpawnPromptGuidelines(completionDelivery, blockingEnabled = true) {
|
|
146
|
-
const deliveryGuidance = completionDelivery === "auto-resume" ? blockingEnabled ? "With subagent_spawn completion delivery set to auto-resume, prefer one subagent_spawn for broad asynchronous research or consequential independent review that covers related branches even when the final answer depends on its result; do not choose blocking parallel fan-out merely to keep delegation in the same turn." : "With subagent_spawn completion delivery set to auto-resume, prefer one subagent_spawn for broad asynchronous research or consequential independent review that covers related branches even when the final answer depends on its result." : blockingEnabled ? "With subagent_spawn completion delivery set to next-turn (the default), prefer one subagent_spawn for broad asynchronous research or consequential independent review only when the current response does not depend on its result; use
|
|
154
|
+
const deliveryGuidance = completionDelivery === "auto-resume" ? blockingEnabled ? "With subagent_spawn completion delivery set to auto-resume, prefer one subagent_spawn for broad asynchronous research or consequential independent review that covers related branches even when the final answer depends on its result; do not choose blocking parallel fan-out merely to keep delegation in the same turn." : "With subagent_spawn completion delivery set to auto-resume, prefer one subagent_spawn for broad asynchronous research or consequential independent review that covers related branches even when the final answer depends on its result." : blockingEnabled ? "With subagent_spawn completion delivery set to next-turn (the default), prefer one subagent_spawn for broad asynchronous research or consequential independent review only when the current response does not depend on its result; when it does, use subagent_spawn only with useful overlap and call subagent_await after that overlap is complete. Do not migrate new work to the deprecated subagent tool." : "With subagent_spawn completion delivery set to next-turn (the default), use subagent_spawn only when the current response does not depend on its result; complete final-answer-dependent work directly because an idle root is not awakened.";
|
|
147
155
|
return [
|
|
148
156
|
"Do not use subagent_spawn for simple or critical-path work that the main agent can perform directly. The main agent retains overall planning, immediate critical-path work, integration, final verification, and the final answer.",
|
|
149
157
|
"Before one ordinary subagent_spawn, identify concrete useful non-overlapping main-agent work you can start immediately and a supported completion integration path. If none exists, perform the task directly instead of calling subagent_spawn.",
|
|
150
158
|
"Give subagent_spawn a concise unique taskName using lowercase letters, digits, and underscores so the retained agent has a stable canonical task path.",
|
|
151
159
|
"Set subagent_spawn thinkingLevel to the lowest sufficient thinking level for the delegated task: use off or minimal for extraction, formatting, or mechanical work; low for straightforward bounded work; medium for ordinary multi-step research or implementation; high for complex debugging, design, review, or cross-file analysis; xhigh for highly ambiguous, cross-system, or high-risk analysis; and max only for the hardest tasks when quality clearly outweighs latency and cost. Omit subagent_spawn thinkingLevel only to preserve the agent or child default.",
|
|
152
|
-
"Set subagent_spawn timeoutMs to the shortest realistic work deadline for the task difficulty; use idleTimeoutMs for stalled work and maxTurns or maxToolCalls to stop repeated work without progress.
|
|
160
|
+
"Set subagent_spawn timeoutMs to the shortest realistic work deadline for the task difficulty; use idleTimeoutMs for stalled work and maxTurns or maxToolCalls to stop repeated work without progress. Scope the task to the smallest named files or questions. When setting subagent_spawn maxTurns or maxToolCalls, leave sufficient headroom for discovery, evidence reads, and final synthesis; otherwise omit them instead of guessing speculative tight values. Split oversized tasks instead of extending budgets merely to compensate for broad scope.",
|
|
161
|
+
"For an ordinary subagent_spawn, omit contract; use a delegation contract only when explicit acceptance, authority, evidence, or admission semantics are required.",
|
|
162
|
+
"Do not set subagent_spawn contract enforcement to enforce with requestedAuthority readPaths, writePaths, network, or secrets; those guarantees are unsupported and reject before child launch, while capabilities and tools remain enforceable.",
|
|
163
|
+
"If subagent_spawn rejects an unsupported guarantee, retry once with those fields removed or enforcement set to audit only when they were advisory; when any field is a required security boundary, stop instead of weakening it.",
|
|
153
164
|
deliveryGuidance,
|
|
165
|
+
...completionDelivery === "auto-resume" ? [
|
|
166
|
+
'Track every final-answer-dependent subagent_spawn by setting completionRequirement to "required" and retaining its returned agentId or taskPath; treat interim output as progress, and synthesize only after every corresponding completion message is visible or terminal.'
|
|
167
|
+
] : [],
|
|
154
168
|
"Keep ordinary review in the main agent with a review skill and deterministic checks; use subagent_spawn for detached review only when consequential independent verification has concrete parallel value.",
|
|
155
169
|
"Use a single subagent_spawn for a bounded implementation slice with clear ownership only when it can run beside the identified main-agent work.",
|
|
156
170
|
"Use a single subagent_spawn without concurrent main-agent work only for an explicit user-requested specialist model, tool profile, or isolation boundary.",
|
|
157
171
|
...blockingEnabled ? [
|
|
158
|
-
"
|
|
159
|
-
"
|
|
172
|
+
"The subagent tool is deprecated; do not select it merely because synchronous output is required. Prefer subagent_spawn with supported completion delivery, and use subagent_await only after useful overlapping main-agent work is complete and an intentional join is required.",
|
|
173
|
+
"Use deprecated subagent instead of subagent_spawn only for an existing caller or an explicit user request whose blocking chain, fan-in, panel, or workflow semantics do not yet have a detached replacement; queued steering cannot be processed until it returns."
|
|
160
174
|
] : [],
|
|
161
175
|
"Add another subagent_spawn only for truly independent work with safe workspace concurrency and disjoint write ownership; shared workspaces permit concurrent writes by default, so use workspaceMode worktree when repository isolation is required. The main agent still owns integration.",
|
|
162
176
|
"After subagent_spawn returns, immediately continue the identified local task; do not merely announce the spawn, wait, poll, or end the response while useful local work remains.",
|
|
177
|
+
"When completionRequirement required subagent_spawn work remains active after local work is exhausted, emit at most one brief progress sentence and end the turn; do not repeat waiting updates or use the requested final format, verdict, or conclusion until every required completion is visible or terminal. Current Pi versions do not enforce a hard pre-display barrier.",
|
|
178
|
+
"Do not duplicate assigned work from subagent_spawn while its retained agent is running; use a bounded parent fallback only after its completion reports failure or insufficient evidence.",
|
|
163
179
|
'Consume and synthesize available subagent_spawn completion messages; use subagent_manage with action "interrupt" or "close" for agents that are no longer needed.',
|
|
164
180
|
'Completion from subagent_spawn is delivered automatically. Do not poll with subagent_inspect or subagent_mailbox action "read", repeatedly check progress, or duplicate the delegated work.'
|
|
165
181
|
];
|
|
@@ -213,6 +229,11 @@ function renderStatefulCall(tool, args, theme) {
|
|
|
213
229
|
0
|
|
214
230
|
);
|
|
215
231
|
}
|
|
232
|
+
if (tool === "await") {
|
|
233
|
+
const metadata2 = ["blocking"];
|
|
234
|
+
if (typeof args.timeoutMs === "number") metadata2.push(`timeout:${args.timeoutMs}ms`);
|
|
235
|
+
return new Text(toolHeader(theme, "subagent_await", args.agentId, metadata2), 0, 0);
|
|
236
|
+
}
|
|
216
237
|
if (tool === "manage") {
|
|
217
238
|
const metadata2 = [];
|
|
218
239
|
if (typeof args.agentId === "string") metadata2.push(`id:${safeLine(args.agentId, "", 256)}`);
|
|
@@ -233,9 +254,12 @@ function renderStatefulResult(tool, result2, options, theme, context) {
|
|
|
233
254
|
const details = recordValue(result2.details);
|
|
234
255
|
const args = recordValue(context.args) ?? {};
|
|
235
256
|
if (!details) return renderFallbackResult(result2, options, theme, context.isError);
|
|
236
|
-
if (tool === "spawn" || tool === "send") {
|
|
257
|
+
if (tool === "spawn" || tool === "send" || tool === "await") {
|
|
237
258
|
const agent = recordValue(details.agent);
|
|
238
259
|
if (!agent) return renderFallbackResult(result2, options, theme, context.isError);
|
|
260
|
+
if (tool === "await" && details.timedOut === true) {
|
|
261
|
+
return new Text(renderAwaitTimeout(agent, result2, options.expanded, theme), 0, 0);
|
|
262
|
+
}
|
|
239
263
|
return new Text(renderAgentResult(agent, result2, options.expanded, theme), 0, 0);
|
|
240
264
|
}
|
|
241
265
|
if (tool === "manage") {
|
|
@@ -279,6 +303,16 @@ function renderAgentResult(agent, result2, expanded, theme) {
|
|
|
279
303
|
} else lines.push(expansionHint());
|
|
280
304
|
return lines.join("\n");
|
|
281
305
|
}
|
|
306
|
+
function renderAwaitTimeout(agent, result2, expanded, theme) {
|
|
307
|
+
const lines = [
|
|
308
|
+
`${statusBadge(theme, "running")} \xB7 ${theme.fg("accent", safeLine(agent.id, "agent", 256))} \xB7 ${theme.fg("warning", "wait timed out")} \xB7 ${theme.fg("muted", safeLine(agent.state, "unknown", 128))}`
|
|
309
|
+
];
|
|
310
|
+
if (expanded) {
|
|
311
|
+
const content = safeBlock(textResult(result2), "", 8 * 1024).trim();
|
|
312
|
+
if (content) lines.push(theme.fg("toolOutput", content));
|
|
313
|
+
} else lines.push(expansionHint());
|
|
314
|
+
return lines.join("\n");
|
|
315
|
+
}
|
|
282
316
|
function renderManageResult(args, details, result2, expanded, theme) {
|
|
283
317
|
const action = safeLine(args.action, "action", 128);
|
|
284
318
|
const agents = recordList(details.agents);
|
|
@@ -364,6 +398,7 @@ function lifecycleStatus(state) {
|
|
|
364
398
|
return "running";
|
|
365
399
|
case "idle":
|
|
366
400
|
return "idle";
|
|
401
|
+
case "partial":
|
|
367
402
|
case "blocked":
|
|
368
403
|
case "needs-input":
|
|
369
404
|
case "abstained":
|
|
@@ -544,13 +579,13 @@ var statefulSpawnModules;
|
|
|
544
579
|
var workspaceModule;
|
|
545
580
|
function loadStatefulSessionModules() {
|
|
546
581
|
statefulSessionModules ??= Promise.all([
|
|
547
|
-
import("./completion-delivery-
|
|
582
|
+
import("./completion-delivery-JVLNQRWX.ts"),
|
|
548
583
|
import("./peer-communication-KL36Z6CO.ts"),
|
|
549
584
|
import("./context-QDKLVQXE.ts"),
|
|
550
|
-
import("./create-stateful-transport-
|
|
585
|
+
import("./create-stateful-transport-JWC2EFYL.ts"),
|
|
551
586
|
import("./cwd-policy-NB6XZ5GF.ts"),
|
|
552
|
-
import("./persistence-
|
|
553
|
-
import("./registry-
|
|
587
|
+
import("./persistence-XHPJBZL7.ts"),
|
|
588
|
+
import("./registry-XDXPECWF.ts"),
|
|
554
589
|
import("./stateful-lifecycle-JAR6K55H.ts")
|
|
555
590
|
]).then(
|
|
556
591
|
([
|
|
@@ -580,15 +615,15 @@ function loadStatefulSessionModules() {
|
|
|
580
615
|
}
|
|
581
616
|
function loadStatefulSpawnModules() {
|
|
582
617
|
statefulSpawnModules ??= Promise.all([
|
|
583
|
-
import("./discovery-
|
|
584
|
-
import("./capability-grant-
|
|
618
|
+
import("./discovery-MIFB2U4Y.ts"),
|
|
619
|
+
import("./capability-grant-PR72SWWS.ts"),
|
|
585
620
|
import("./context-QDKLVQXE.ts"),
|
|
586
621
|
import("./cwd-policy-NB6XZ5GF.ts"),
|
|
587
|
-
import("./delegation-contract-
|
|
622
|
+
import("./delegation-contract-LA56I5DT.ts"),
|
|
588
623
|
import("./runtime-policy-5YELCOVC.ts"),
|
|
589
|
-
import("./retained-semantic-state-
|
|
624
|
+
import("./retained-semantic-state-GM75FZGE.ts"),
|
|
590
625
|
import("./semantic-snapshot-WPJ3UAFW.ts"),
|
|
591
|
-
import("./spawn-idempotency-
|
|
626
|
+
import("./spawn-idempotency-BNHOSMZW.ts")
|
|
592
627
|
]).then(
|
|
593
628
|
([
|
|
594
629
|
agents,
|
|
@@ -640,6 +675,20 @@ var StatefulTimeoutSchema = Type2.Integer({
|
|
|
640
675
|
maximum: MAX_SUBAGENT_TIMEOUT_MS,
|
|
641
676
|
description: "Work deadline in milliseconds selected for the task difficulty. On expiry, Pi aborts the work and makes one separately bounded summary attempt. Retained as the agent default."
|
|
642
677
|
});
|
|
678
|
+
var DEFAULT_SUBAGENT_AWAIT_TIMEOUT_MS = 3e4;
|
|
679
|
+
var SubagentAwaitParams = Type2.Object({
|
|
680
|
+
agentId: Type2.String({
|
|
681
|
+
minLength: 1,
|
|
682
|
+
description: "Retained agent ID or canonical task path."
|
|
683
|
+
}),
|
|
684
|
+
timeoutMs: Type2.Optional(
|
|
685
|
+
Type2.Integer({
|
|
686
|
+
minimum: 1,
|
|
687
|
+
maximum: MAX_SUBAGENT_TIMEOUT_MS,
|
|
688
|
+
description: "Maximum time to wait in milliseconds. A wait timeout stops only this tool call and does not interrupt or close the subagent. Defaults to 30000."
|
|
689
|
+
})
|
|
690
|
+
)
|
|
691
|
+
});
|
|
643
692
|
var StatefulTurnLimitFields = {
|
|
644
693
|
idleTimeoutMs: Type2.Optional(
|
|
645
694
|
Type2.Integer({
|
|
@@ -652,14 +701,14 @@ var StatefulTurnLimitFields = {
|
|
|
652
701
|
Type2.Integer({
|
|
653
702
|
minimum: 1,
|
|
654
703
|
maximum: MAX_SUBAGENT_TURNS,
|
|
655
|
-
description: "Maximum unfinished assistant turns; retained as the agent default."
|
|
704
|
+
description: "Maximum unfinished assistant turns; retained as the agent default. Omit rather than guessing a tight bound."
|
|
656
705
|
})
|
|
657
706
|
),
|
|
658
707
|
maxToolCalls: Type2.Optional(
|
|
659
708
|
Type2.Integer({
|
|
660
709
|
minimum: 1,
|
|
661
710
|
maximum: MAX_SUBAGENT_TOOL_CALLS,
|
|
662
|
-
description: "Maximum tool calls; retained as the agent default."
|
|
711
|
+
description: "Maximum tool calls; retained as the agent default. Omit rather than guessing a tight bound."
|
|
663
712
|
})
|
|
664
713
|
)
|
|
665
714
|
};
|
|
@@ -755,7 +804,7 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
755
804
|
if (!registry) throw new Error("Stateful subagents are not initialized for this session");
|
|
756
805
|
return registry;
|
|
757
806
|
};
|
|
758
|
-
pi.on("session_start", async (
|
|
807
|
+
pi.on("session_start", async (event, ctx) => {
|
|
759
808
|
const generation = ++runtimeGeneration;
|
|
760
809
|
completionBroker?.close();
|
|
761
810
|
completionBroker = void 0;
|
|
@@ -805,9 +854,16 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
805
854
|
const reason = error instanceof Error ? error.message : String(error);
|
|
806
855
|
ctx.ui.notify(`Subagent completion delivery failed: ${reason}`, "warning");
|
|
807
856
|
},
|
|
857
|
+
onDeliveryAttempt: (completions, input) => {
|
|
858
|
+
if (generation !== runtimeGeneration) return;
|
|
859
|
+
for (const completion of completions) {
|
|
860
|
+
dependencies.usageRecording?.recordCompletionDeliveryAttempt(completion, input);
|
|
861
|
+
}
|
|
862
|
+
},
|
|
808
863
|
onAcknowledged: (completions, deliveredAt) => {
|
|
809
864
|
if (generation !== runtimeGeneration) return;
|
|
810
865
|
for (const completion of completions) {
|
|
866
|
+
dependencies.usageRecording?.recordCompletionVisible(completion);
|
|
811
867
|
void nextRegistry.markCompletionDelivered(completion.completionId, deliveredAt).catch((error) => {
|
|
812
868
|
if (!ctx.hasUI || generation !== runtimeGeneration) return;
|
|
813
869
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -867,6 +923,7 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
867
923
|
if (generation !== runtimeGeneration) return;
|
|
868
924
|
await sessionPersistence.save(agents);
|
|
869
925
|
if (generation !== runtimeGeneration) return;
|
|
926
|
+
dependencies.usageRecording?.observeAgents(agents);
|
|
870
927
|
for (const agent of agents) {
|
|
871
928
|
for (const message of agent.mailbox) {
|
|
872
929
|
if (seenMessageIds.has(message.id)) continue;
|
|
@@ -890,9 +947,9 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
890
947
|
}
|
|
891
948
|
},
|
|
892
949
|
onTurnComplete: (completion) => {
|
|
893
|
-
if (generation
|
|
894
|
-
|
|
895
|
-
|
|
950
|
+
if (generation !== runtimeGeneration) return;
|
|
951
|
+
dependencies.usageRecording?.recordChildCompletion(completion);
|
|
952
|
+
if (completion.recipientId === "root") sessionBroker.enqueue(completion);
|
|
896
953
|
}
|
|
897
954
|
});
|
|
898
955
|
const persisted = sessionPersistence.load();
|
|
@@ -929,6 +986,25 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
929
986
|
for (const message of agent.mailbox) seenMessageIds.add(message.id);
|
|
930
987
|
}
|
|
931
988
|
nextRegistry.restore(restored);
|
|
989
|
+
const branchRequirements = completionRequirementsFromBranch(ctx.sessionManager.getBranch());
|
|
990
|
+
const branchOwnsRequirementState = branchRequirements.observedState || event.reason === "fork" || event.reason === "new";
|
|
991
|
+
nextRegistry.reconcileCompletionRequirements(
|
|
992
|
+
branchRequirements.records,
|
|
993
|
+
branchOwnsRequirementState
|
|
994
|
+
);
|
|
995
|
+
if (branchOwnsRequirementState) {
|
|
996
|
+
try {
|
|
997
|
+
await sessionPersistence.save(nextRegistry.list(true));
|
|
998
|
+
} catch (error) {
|
|
999
|
+
if (generation === runtimeGeneration && ctx.hasUI) {
|
|
1000
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1001
|
+
ctx.ui.notify(
|
|
1002
|
+
`Subagent requirement reconciliation could not be persisted yet: ${reason}`,
|
|
1003
|
+
"warning"
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
932
1008
|
if (generation !== runtimeGeneration) {
|
|
933
1009
|
sessionBroker.close();
|
|
934
1010
|
await sessionPeerBroker.close();
|
|
@@ -966,6 +1042,9 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
966
1042
|
});
|
|
967
1043
|
pi.on("context", (event) => {
|
|
968
1044
|
completionBroker?.onParentContext(event.messages);
|
|
1045
|
+
const agents = registry?.list() ?? [];
|
|
1046
|
+
const messages = reconcileRequiredCompletionContext(event.messages, agents);
|
|
1047
|
+
if (messages !== event.messages) return { messages };
|
|
969
1048
|
});
|
|
970
1049
|
pi.on("agent_settled", () => {
|
|
971
1050
|
completionBroker?.onParentSettled();
|
|
@@ -1010,7 +1089,7 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
1010
1089
|
description: appendAgentCatalog(baseSpawnDescription(), agentCatalog),
|
|
1011
1090
|
promptSnippet: "Start a reusable detached subagent; completion is delivered asynchronously",
|
|
1012
1091
|
promptGuidelines: createSpawnPromptGuidelines(completionDelivery, blockingEnabled),
|
|
1013
|
-
parameters:
|
|
1092
|
+
parameters: grammarSafeToolObject({
|
|
1014
1093
|
agent: Type2.String({ minLength: 1 }),
|
|
1015
1094
|
taskName: Type2.Optional(
|
|
1016
1095
|
Type2.String({
|
|
@@ -1056,7 +1135,8 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
1056
1135
|
StringEnum2(SUBAGENT_RESULT_FORMATS, {
|
|
1057
1136
|
description: "Use text (default), structured-v1, or the evidence-preserving structured-v2 completion contract."
|
|
1058
1137
|
})
|
|
1059
|
-
)
|
|
1138
|
+
),
|
|
1139
|
+
completionRequirement: Type2.Optional(CompletionRequirementModeSchema)
|
|
1060
1140
|
}),
|
|
1061
1141
|
...createStatefulToolRenderer("spawn"),
|
|
1062
1142
|
async execute(_id, params, signal, _update, ctx) {
|
|
@@ -1146,7 +1226,8 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
1146
1226
|
workspaceMode: params.workspaceMode ?? "shared",
|
|
1147
1227
|
allowConcurrentWrites: params.allowConcurrentWrites ?? false,
|
|
1148
1228
|
contract,
|
|
1149
|
-
resultFormat
|
|
1229
|
+
resultFormat,
|
|
1230
|
+
completionRequirement: params.completionRequirement ?? "background"
|
|
1150
1231
|
});
|
|
1151
1232
|
if (!capturedRegistry) {
|
|
1152
1233
|
throw new Error("Stateful subagents are not initialized for this session");
|
|
@@ -1230,6 +1311,7 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
1230
1311
|
spawnRequestHash: params.idempotencyKey ? requestHash : void 0,
|
|
1231
1312
|
contract,
|
|
1232
1313
|
resultFormat: resultFormat === "text" ? void 0 : resultFormat,
|
|
1314
|
+
completionRequirement: params.completionRequirement ?? "background",
|
|
1233
1315
|
executionPlan,
|
|
1234
1316
|
capabilityGrant,
|
|
1235
1317
|
semanticSnapshot,
|
|
@@ -1247,10 +1329,11 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
1247
1329
|
else if (workspace) await currentWorkspaceManager.cleanup(workspaceOwner);
|
|
1248
1330
|
assertCurrentSpawn(signal, generation, runtimeGeneration);
|
|
1249
1331
|
resolvePending?.(agent);
|
|
1250
|
-
const deliveryNote = completionDelivery === "auto-resume" ? "Auto-resume
|
|
1332
|
+
const deliveryNote = completionDelivery === "auto-resume" ? "Auto-resume steers completions into active parent work or requests synthesis when idle. Treat this response as progress, not final synthesis, until every final-answer-required completion message is visible. If local work is exhausted while required children remain active, emit at most one brief progress sentence and end the turn; do not repeat waiting updates or use the requested final format, verdict, or conclusion. Do not redo a running child's assigned work." : "The current response must not depend on the result because next-turn delivery will not wake an idle root.";
|
|
1333
|
+
const requirementNote = params.completionRequirement === "required" ? "This exact run is runtime-tracked as required until its completion becomes visible or reaches an explicit terminal state. Current Pi versions still cannot prevent already-streamed premature output." : "This run is background work and does not block the parent final answer.";
|
|
1251
1334
|
return result(
|
|
1252
1335
|
agent,
|
|
1253
|
-
`Spawned ${agent.agent} as ${agent.taskPath ?? agent.id} (${agent.id}). Continue the identified non-overlapping local work immediately; do not merely announce the spawn or end while useful local work remains. Only an explicit user-requested specialist model, tool-profile, or isolation exception may lack concurrent local work. ${deliveryNote} Do not poll for progress.`
|
|
1336
|
+
`Spawned ${agent.agent} as ${agent.taskPath ?? agent.id} (${agent.id}). ${requirementNote} Continue the identified non-overlapping local work immediately; do not merely announce the spawn or end while useful local work remains. Only an explicit user-requested specialist model, tool-profile, or isolation exception may lack concurrent local work. ${deliveryNote} Do not poll for progress.`
|
|
1254
1337
|
);
|
|
1255
1338
|
} catch (error) {
|
|
1256
1339
|
rejectPending?.(error);
|
|
@@ -1284,6 +1367,7 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
1284
1367
|
})
|
|
1285
1368
|
),
|
|
1286
1369
|
...StatefulTurnLimitFields,
|
|
1370
|
+
completionRequirement: Type2.Optional(CompletionRequirementModeSchema),
|
|
1287
1371
|
revalidate: Type2.Optional(
|
|
1288
1372
|
Type2.Boolean({
|
|
1289
1373
|
description: "Accept the current semantic resource snapshot after a reported mismatch before starting this follow-up."
|
|
@@ -1381,12 +1465,34 @@ function registerStatefulSubagents(pi, dependencies = {}) {
|
|
|
1381
1465
|
timeoutMs: params.timeoutMs,
|
|
1382
1466
|
idleTimeoutMs: params.idleTimeoutMs,
|
|
1383
1467
|
maxTurns: params.maxTurns,
|
|
1384
|
-
maxToolCalls: params.maxToolCalls
|
|
1468
|
+
maxToolCalls: params.maxToolCalls,
|
|
1469
|
+
completionRequirement: params.completionRequirement ?? "background"
|
|
1385
1470
|
});
|
|
1386
1471
|
assertCurrentSpawn(signal, generation, runtimeGeneration);
|
|
1387
1472
|
return result(agent, `Started follow-up for ${agent.id}.`);
|
|
1388
1473
|
}
|
|
1389
1474
|
});
|
|
1475
|
+
if (blockingEnabled) {
|
|
1476
|
+
pi.registerTool({
|
|
1477
|
+
name: "subagent_await",
|
|
1478
|
+
label: "Await Subagent",
|
|
1479
|
+
description: "Wait for one retained subagent's current turn to settle and return its latest bounded output. This blocks Pi from processing queued steering until the wait finishes. A wait timeout or caller cancellation stops only the wait and never interrupts or closes the subagent; use subagent_manage for lifecycle changes. Automatic completion delivery remains active and may later repeat the same at-least-once completion.",
|
|
1480
|
+
promptSnippet: "Intentionally block until one retained subagent settles or the wait times out",
|
|
1481
|
+
promptGuidelines: [
|
|
1482
|
+
"Use subagent_await only when the retained result is required before the next action, useful overlapping main-agent work is complete, and blocking Pi is intentional.",
|
|
1483
|
+
"Do not repeatedly call subagent_await after a timeout; the subagent keeps running and completion delivery remains active. Use subagent_manage only when the user wants to interrupt or close it."
|
|
1484
|
+
],
|
|
1485
|
+
parameters: SubagentAwaitParams,
|
|
1486
|
+
...createStatefulToolRenderer("await"),
|
|
1487
|
+
async execute(_id, params, signal) {
|
|
1488
|
+
const generation = runtimeGeneration;
|
|
1489
|
+
const timeoutMs = params.timeoutMs ?? DEFAULT_SUBAGENT_AWAIT_TIMEOUT_MS;
|
|
1490
|
+
const waited = await requireRegistry().wait(params.agentId, timeoutMs, signal);
|
|
1491
|
+
assertCurrentSpawn(signal, generation, runtimeGeneration);
|
|
1492
|
+
return awaitResult(waited.agent, waited.timedOut, timeoutMs);
|
|
1493
|
+
}
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1390
1496
|
pi.registerTool({
|
|
1391
1497
|
name: "subagent_manage",
|
|
1392
1498
|
label: "Manage Subagents",
|
|
@@ -1532,6 +1638,27 @@ function result(agent, text) {
|
|
|
1532
1638
|
details: { agent: summarizeStatefulAgent(agent) }
|
|
1533
1639
|
};
|
|
1534
1640
|
}
|
|
1641
|
+
function awaitResult(agent, timedOut, timeoutMs) {
|
|
1642
|
+
const latestTurn = agent.history.at(-1);
|
|
1643
|
+
const output = timedOut ? "" : truncateUtf8(latestTurn?.output ?? "", DEFAULT_MAX_CONTEXT_BYTES).text;
|
|
1644
|
+
const error = timedOut ? "" : truncateUtf8(agent.error ?? "", MAX_TOOL_MESSAGE_BYTES).text;
|
|
1645
|
+
const text = timedOut ? `Stopped waiting for ${agent.taskPath ?? agent.id} after ${timeoutMs}ms; it remains ${agent.state}. The wait did not interrupt or close the subagent.` : [`Subagent ${agent.taskPath ?? agent.id} settled as ${agent.state}.`, output || error].filter(Boolean).join("\n\n");
|
|
1646
|
+
return {
|
|
1647
|
+
content: [
|
|
1648
|
+
{
|
|
1649
|
+
type: "text",
|
|
1650
|
+
text: truncateUtf8(text, DEFAULT_MAX_CONTEXT_BYTES).text
|
|
1651
|
+
}
|
|
1652
|
+
],
|
|
1653
|
+
details: {
|
|
1654
|
+
agent: summarizeStatefulAgent(agent),
|
|
1655
|
+
timedOut,
|
|
1656
|
+
timeoutMs,
|
|
1657
|
+
...output ? { output } : {},
|
|
1658
|
+
...error ? { error } : {}
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1535
1662
|
function normalizeRuntimeThinkingLevel(value) {
|
|
1536
1663
|
return isThinkingLevel(value) ? value : "off";
|
|
1537
1664
|
}
|
|
@@ -1540,4 +1667,4 @@ export {
|
|
|
1540
1667
|
formatStatefulAgentLine,
|
|
1541
1668
|
registerStatefulSubagents
|
|
1542
1669
|
};
|
|
1543
|
-
//# sourceMappingURL=chunk-
|
|
1670
|
+
//# sourceMappingURL=chunk-PABJJYP6.ts.map
|