@xingular/harness 1.2.0 → 1.3.1-unstable.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/CHANGELOG.md +35 -0
- package/README.md +10 -5
- package/dist/cli.js +5560 -5056
- package/dist/sdk/agents/builtin.js +3 -3
- package/dist/sdk/agents/planResearch.d.ts +23 -1
- package/dist/sdk/agents/planResearch.js +71 -8
- package/dist/sdk/agents/profiles.d.ts +4 -1
- package/dist/sdk/agents/profiles.js +17 -6
- package/dist/sdk/capabilities/runSnapshot.js +10 -4
- package/dist/sdk/commands/registry.d.ts +11 -3
- package/dist/sdk/commands/registry.js +3 -2
- package/dist/sdk/core/shell.d.ts +20 -0
- package/dist/sdk/core/shell.js +73 -0
- package/dist/sdk/core/workspaceBashTool.d.ts +17 -1
- package/dist/sdk/core/workspaceBashTool.js +16 -2
- package/dist/sdk/core/workspaceSandbox.d.ts +10 -0
- package/dist/sdk/core/workspaceSandbox.js +52 -12
- package/dist/sdk/core/workspaceWriteOperations.d.ts +11 -0
- package/dist/sdk/core/workspaceWriteOperations.js +26 -8
- package/dist/sdk/doctor/checks.js +71 -12
- package/dist/sdk/hub/hub.js +5 -3
- package/dist/sdk/index.d.ts +2 -2
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/plugins/builtin.js +3 -3
- package/dist/sdk/plugins/install.d.ts +6 -2
- package/dist/sdk/plugins/install.js +29 -5
- package/dist/sdk/plugins/inventory.js +2 -2
- package/dist/sdk/prompt/compile.d.ts +2 -2
- package/dist/sdk/prompt/compile.js +14 -16
- package/dist/sdk/server/methods.js +4 -2
- package/dist/sdk/sessions/compactionCheckpoint.d.ts +3 -3
- package/dist/sdk/sessions/compactionCheckpoint.js +12 -12
- package/dist/sdk/sessions/continuation.d.ts +4 -2
- package/dist/sdk/sessions/continuation.js +7 -6
- package/dist/sdk/sessions/contracts.d.ts +22 -4
- package/dist/sdk/sessions/contracts.js +12 -7
- package/dist/sdk/sessions/planMode.js +2 -2
- package/dist/sdk/sessions/runStore.js +3 -1
- package/dist/sdk/sessions/runner.js +2 -2
- package/dist/sdk/sessions/sessions.js +29 -11
- package/dist/sdk/sessions/subagentService.d.ts +15 -0
- package/dist/sdk/sessions/subagentService.js +194 -54
- package/dist/sdk/sessions/subagents.d.ts +10 -1
- package/dist/sdk/sessions/subagents.js +4 -0
- package/dist/sdk/sessions/workSlice.d.ts +8 -5
- package/dist/sdk/sessions/workSlice.js +77 -45
- package/dist/sdk/terminal/controller.d.ts +20 -0
- package/dist/sdk/terminal/controller.js +43 -18
- package/dist/sdk/terminal/opentui/ansi.d.ts +25 -0
- package/dist/sdk/terminal/opentui/ansi.js +192 -0
- package/dist/sdk/terminal/opentui/model.d.ts +163 -0
- package/dist/sdk/terminal/opentui/model.js +482 -0
- package/dist/sdk/terminal/opentui/subagentsWidget.d.ts +3 -3
- package/dist/sdk/terminal/opentui/subagentsWidget.js +7 -5
- package/dist/sdk/terminal/opentui/theme.js +1 -0
- package/dist/sdk/terminal/piExtension.js +28 -14
- package/dist/sdk/terminal/subagentMonitor.d.ts +17 -4
- package/dist/sdk/terminal/subagentMonitor.js +29 -8
- package/dist/sdk/terminal/terminals.d.ts +7 -0
- package/dist/sdk/terminal/terminals.js +86 -14
- package/dist/sdk/terminal/trajectory.d.ts +6 -1
- package/dist/sdk/terminal/trajectory.js +8 -0
- package/dist/sdk/terminal/tui/chrome.d.ts +4 -0
- package/dist/sdk/terminal/tui/chrome.js +13 -0
- package/dist/sdk/terminal/tui/commandPages.js +14 -4
- package/dist/sdk/terminal/tui/commands.d.ts +4 -0
- package/dist/sdk/terminal/tui/commands.js +8 -0
- package/dist/sdk/terminal/tui/pageOverlay.js +13 -6
- package/dist/sdk/terminal/tui/pages/browserPage.js +5 -4
- package/dist/sdk/terminal/tui/pages/hubPage.d.ts +14 -1
- package/dist/sdk/terminal/tui/pages/hubPage.js +192 -28
- package/dist/sdk/terminal/tui/pages/pluginsPage.d.ts +8 -1
- package/dist/sdk/terminal/tui/pages/pluginsPage.js +197 -25
- package/dist/sdk/terminal/tui/pages/subagentsPage.js +8 -5
- package/dist/sdk/tools/sessionName.d.ts +2 -0
- package/dist/sdk/tools/sessionName.js +5 -3
- package/dist/sdk/tools/spawnSubagent.js +9 -7
- package/dist/sdk/tools/todo.d.ts +15 -0
- package/dist/sdk/tools/todo.js +64 -0
- package/dist/terminal-opentui.js +1416 -348
- package/dist/terminal-pi.js +315 -126
- package/docs/architecture/00-overview.md +1 -1
- package/docs/architecture/01-extension-points.md +1 -1
- package/docs/architecture/02-sessions-and-runs.md +65 -34
- package/docs/architecture/04-prompt.md +8 -6
- package/docs/architecture/06-plugins-and-capabilities.md +10 -6
- package/docs/architecture/07-tools-and-gate.md +31 -5
- package/docs/architecture/09-accounts-and-connectors.md +8 -2
- package/docs/architecture/10-server-protocol.md +16 -9
- package/docs/architecture/11-terminal.md +51 -26
- package/docs/architecture/14-surfaces-and-parity.md +4 -1
- package/docs/architecture/README.md +18 -17
- package/docs/architecture/proposals/PROP-0006-run-checklist.md +2 -0
- package/docs/architecture/proposals/PROP-0041-bounded-work-slices.md +32 -21
- package/docs/architecture/proposals/PROP-0044-work-slice-defaults.md +93 -0
- package/docs/architecture/proposals/PROP-0045-rename-checklist-to-todo.md +132 -0
- package/docs/architecture/proposals/PROP-0046-progress-aware-stall-guards.md +82 -0
- package/docs/architecture/proposals/PROP-0047-plugins-hub-separation.md +122 -0
- package/docs/architecture/proposals/README.md +10 -6
- package/docs/decisions/ADR-0039-progress-aware-stall-guards.md +39 -0
- package/docs/decisions/ADR-0040-architecture-change-workflow.md +31 -0
- package/docs/decisions/ADR-0041-plugins-hub-separation.md +41 -0
- package/docs/decisions/ADR-0042-windows-shell-without-sandbox.md +40 -0
- package/docs/decisions/ADR-0043-parents-continue-stopped-subagents.md +49 -0
- package/docs/doctor.md +14 -1
- package/docs/parity.md +9 -9
- package/docs/releases/1.3.0.md +21 -0
- package/docs/releases/README.md +2 -2
- package/docs/terminal-tui.md +85 -46
- package/package.json +1 -1
- package/dist/sdk/tools/checklist.d.ts +0 -9
- package/dist/sdk/tools/checklist.js +0 -55
|
@@ -6,10 +6,11 @@ import { now } from "../core/fs.js";
|
|
|
6
6
|
import { takeChars } from "../core/text.js";
|
|
7
7
|
import { isActiveStatus } from "./contracts.js";
|
|
8
8
|
import { narrowForProfile } from "../agents/narrow.js";
|
|
9
|
-
import {
|
|
9
|
+
import { planResearchEligibility } from "../agents/planResearch.js";
|
|
10
10
|
import { resolveProfile } from "../agents/profiles.js";
|
|
11
|
+
import { continuationOf } from "./continuation.js";
|
|
11
12
|
import { findRun, loadRun, readEvents, recordedSubagents, recordSubagent, saveRun } from "./runStore.js";
|
|
12
|
-
import { SPAWN_SUBAGENT, SUBAGENT_RELATION, SUBAGENT_OWNER, SUBAGENT_RECEIPT, SUBAGENT_RESULTS, briefTitle, subagentHistory, subagentTitle } from "./subagents.js";
|
|
13
|
+
import { SPAWN_SUBAGENT, SUBAGENT_RELATION, SUBAGENT_OWNER, SUBAGENT_RECEIPT, SUBAGENT_RESULTS, briefTitle, continueHint, subagentHistory, subagentTitle } from "./subagents.js";
|
|
13
14
|
function until(promise, signal) {
|
|
14
15
|
if (signal.aborted) {
|
|
15
16
|
void promise.catch(() => { });
|
|
@@ -95,39 +96,53 @@ export class Subagents {
|
|
|
95
96
|
throw new HarnessError('run_not_active', 'The parent run is not accepting subagents.');
|
|
96
97
|
return parent;
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
-
planSpawnRefusal(parentRunId, args) {
|
|
99
|
+
planSpawnCheck(parentRunId, args) {
|
|
100
100
|
const parent = this.parents.get(parentRunId);
|
|
101
101
|
if (!parent || !this.runs.active(parentRunId))
|
|
102
|
-
return 'The parent run is not accepting subagents.';
|
|
102
|
+
return { refusal: 'The parent run is not accepting subagents.' };
|
|
103
103
|
if (!parent.input.plan)
|
|
104
|
-
return 'Read-only research delegation is available only during plan mode.';
|
|
104
|
+
return { refusal: 'Read-only research delegation is available only during plan mode.' };
|
|
105
105
|
if (!parent.capabilities.tools.includes(SPAWN_SUBAGENT))
|
|
106
|
-
return 'Subagents are not enabled for this run.';
|
|
106
|
+
return { refusal: 'Subagents are not enabled for this run.' };
|
|
107
107
|
if (!args || typeof args !== 'object' || Array.isArray(args))
|
|
108
|
-
return 'Plan-mode delegation requires a named, eligible read-only research profile.';
|
|
109
|
-
|
|
108
|
+
return { refusal: 'Plan-mode delegation requires a named, eligible read-only research profile.' };
|
|
109
|
+
let request = args;
|
|
110
|
+
if (request.continue !== undefined) {
|
|
111
|
+
// A continued child keeps its own profile; judge that profile.
|
|
112
|
+
const id = typeof request.continue === 'string' ? request.continue.trim() : '';
|
|
113
|
+
const record = id && this.owned(parentRunId, parent).has(id) ? findRun(this.env.root, id) : null;
|
|
114
|
+
if (!record?.profile)
|
|
115
|
+
return { refusal: 'Plan mode can continue only a stopped research subagent of this conversation that has a named profile.' };
|
|
116
|
+
if (request.agent !== undefined || request.tools !== undefined)
|
|
117
|
+
return { refusal: 'A continued subagent keeps its profile and tools; omit agent and tools.' };
|
|
118
|
+
request = { agent: record.profile };
|
|
119
|
+
}
|
|
110
120
|
if (typeof request.agent !== 'string' || !request.agent.trim())
|
|
111
|
-
return 'Plan-mode delegation requires a named, eligible read-only research profile.';
|
|
121
|
+
return { refusal: 'Plan-mode delegation requires a named, eligible read-only research profile.' };
|
|
122
|
+
if (request.tools !== undefined && (!Array.isArray(request.tools) || request.tools.some(name => typeof name !== 'string'))) {
|
|
123
|
+
return { refusal: 'The optional tools field must be an array of tool names. Omit it to inherit the selected profile’s safe research intersection.' };
|
|
124
|
+
}
|
|
112
125
|
const profile = resolveProfile(this.env.root, parent.input.cwd, request.agent.trim(), parent.input.variant && 'dir' in parent.input.variant ? parent.input.variant.dir : null);
|
|
113
126
|
if (!profile)
|
|
114
|
-
return `There is no agent profile named ${request.agent.trim()}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
127
|
+
return { refusal: `There is no agent profile named ${request.agent.trim()}.` };
|
|
128
|
+
const eligibility = planResearchEligibility(profile, {
|
|
129
|
+
frozenTools: parent.capabilities.tools,
|
|
130
|
+
contributions: parent.capabilities.contributions,
|
|
131
|
+
descriptors: this.options.descriptors?.() ?? []
|
|
132
|
+
}, request.tools);
|
|
133
|
+
return { refusal: eligibility.refusal, profile, eligibility };
|
|
134
|
+
}
|
|
135
|
+
/** The plan-mode per-call gate and spawn implementation share this eligibility check. */
|
|
136
|
+
planSpawnRefusal(parentRunId, args) {
|
|
137
|
+
return this.planSpawnCheck(parentRunId, args).refusal;
|
|
125
138
|
}
|
|
126
139
|
async spawn(request) {
|
|
127
140
|
const parent = this.parent(request.parentRunId);
|
|
128
141
|
const { input, accountId, capabilities } = parent;
|
|
129
142
|
if (!capabilities.tools.includes(SPAWN_SUBAGENT))
|
|
130
143
|
throw invalid('Subagents are not enabled for this run.');
|
|
144
|
+
if (request.continue !== undefined)
|
|
145
|
+
return this.continueChild(parent, request);
|
|
131
146
|
const brief = typeof request.brief === 'string' ? request.brief.trim() : '';
|
|
132
147
|
if (!brief)
|
|
133
148
|
throw invalid('Give the subagent a brief.');
|
|
@@ -138,27 +153,33 @@ export class Subagents {
|
|
|
138
153
|
throw invalid('wait must be a boolean.');
|
|
139
154
|
if (request.tools !== undefined && (!Array.isArray(request.tools) || request.tools.some((name) => typeof name !== 'string')))
|
|
140
155
|
throw invalid('Tools must be an array of tool names.');
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
throw invalid(`A subagent cannot have tools you do not have: ${outside.join(', ')}.`);
|
|
156
|
+
let profile = null;
|
|
157
|
+
let planEligibility = null;
|
|
144
158
|
if (input.plan) {
|
|
145
|
-
const
|
|
146
|
-
if (refusal)
|
|
147
|
-
throw invalid(refusal);
|
|
159
|
+
const check = this.planSpawnCheck(request.parentRunId, request);
|
|
160
|
+
if (check.refusal || !check.profile || !check.eligibility)
|
|
161
|
+
throw invalid(check.refusal ?? 'The selected profile has no eligible research tools in this run.');
|
|
162
|
+
profile = check.profile;
|
|
163
|
+
planEligibility = check.eligibility;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const outside = request.tools?.filter((name) => !capabilities.tools.includes(name)) ?? [];
|
|
167
|
+
if (outside.length)
|
|
168
|
+
throw invalid(`A subagent cannot have tools you do not have: ${outside.join(', ')}.`);
|
|
169
|
+
if (request.agent !== undefined) {
|
|
170
|
+
if (typeof request.agent !== 'string' || !request.agent.trim())
|
|
171
|
+
throw invalid('agent must be the name of an agent profile.');
|
|
172
|
+
profile = resolveProfile(this.env.root, input.cwd, request.agent.trim(), input.variant && 'dir' in input.variant ? input.variant.dir : null);
|
|
173
|
+
if (!profile)
|
|
174
|
+
throw invalid(`There is no agent profile named ${request.agent.trim()}.`);
|
|
175
|
+
}
|
|
148
176
|
}
|
|
149
177
|
await until(parent.ready, parent.stopped.signal);
|
|
150
178
|
let variant = input.variant ?? null;
|
|
151
179
|
let launch = input.launch;
|
|
152
180
|
let model = input.model;
|
|
153
181
|
let effort = input.effort;
|
|
154
|
-
|
|
155
|
-
if (request.agent !== undefined) {
|
|
156
|
-
if (typeof request.agent !== 'string' || !request.agent.trim())
|
|
157
|
-
throw invalid('agent must be the name of an agent profile.');
|
|
158
|
-
const dir = variant && 'dir' in variant ? variant.dir : null;
|
|
159
|
-
profile = resolveProfile(this.env.root, input.cwd, request.agent.trim(), dir);
|
|
160
|
-
if (!profile)
|
|
161
|
-
throw invalid(`There is no agent profile named ${request.agent.trim()}.`);
|
|
182
|
+
if (profile) {
|
|
162
183
|
// A variant's own subagent works from its definition alone; a profile keeps the parent's
|
|
163
184
|
// variant unless it names another one, or none.
|
|
164
185
|
if (profile.source === 'variant' || profile.variant === 'none')
|
|
@@ -171,20 +192,13 @@ export class Subagents {
|
|
|
171
192
|
effort = profile.effort;
|
|
172
193
|
launch = { ...(input.launch ?? {}), sections: [...(input.launch?.sections ?? []).filter((section) => section.id !== 'subagent'), { id: 'subagent', title: `Your role: ${profile.name}`, body: profile.instructions || profile.description, budget: 16_000, order: 22 }] };
|
|
173
194
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
const narrowed = narrowForProfile(capabilities, profile, request.tools, this.options.descriptors?.() ?? []);
|
|
180
|
-
const childCapabilities = input.plan
|
|
181
|
-
? { ...narrowed.capabilities, tools: narrowed.capabilities.tools.filter(name => PLAN_RESEARCH_TOOLS.has(name)), connectors: [] }
|
|
182
|
-
: narrowed.capabilities;
|
|
195
|
+
const narrowed = input.plan
|
|
196
|
+
? { capabilities: planEligibility.capabilities, unavailable: planEligibility.unavailableTools }
|
|
197
|
+
: narrowForProfile(capabilities, profile, request.tools, this.options.descriptors?.() ?? []);
|
|
198
|
+
const childCapabilities = narrowed.capabilities;
|
|
183
199
|
const tools = childCapabilities.tools;
|
|
184
200
|
const runId = randomUUID();
|
|
185
201
|
const sessionId = randomUUID();
|
|
186
|
-
this.rememberRuntimeSettings(runId, { model: model ?? null, effort: effort ?? null });
|
|
187
|
-
recordSubagent(this.env.root, request.parentRunId, runId);
|
|
188
202
|
const child = {
|
|
189
203
|
...input,
|
|
190
204
|
run: { ...input.run, ...(input.plan ? { worktreeId: null } : {}), id: runId, sessionId, parentRunId: request.parentRunId, relation: SUBAGENT_RELATION, goal: takeChars(brief, 4000), title, attachmentCount: 0, resumedFromRunId: null, handoffId: null, profile: profile?.name ?? null },
|
|
@@ -196,10 +210,18 @@ export class Subagents {
|
|
|
196
210
|
variant, launch, model, effort,
|
|
197
211
|
...(input.plan ? { connections: false, subagents: null } : {})
|
|
198
212
|
};
|
|
213
|
+
const result = await this.launchChild(parent, request, child);
|
|
214
|
+
return { ...result, ...(profile ? { agent: profile.name } : {}), ...(narrowed.unavailable.length ? { unavailableTools: narrowed.unavailable } : {}) };
|
|
215
|
+
}
|
|
216
|
+
/** Records ownership, starts the child, and writes a failed record when it never opened. */
|
|
217
|
+
async launchChild(parent, request, child) {
|
|
218
|
+
const runId = child.run.id;
|
|
219
|
+
this.rememberRuntimeSettings(runId, { model: child.model ?? null, effort: child.effort ?? null });
|
|
220
|
+
recordSubagent(this.env.root, request.parentRunId, runId);
|
|
199
221
|
const started = this.launch(child).catch((error) => {
|
|
200
222
|
if (!findRun(this.env.root, runId)) {
|
|
201
223
|
const source = loadRun(this.env.root, request.parentRunId);
|
|
202
|
-
saveRun(this.env.root, { ...source, id: runId, sessionId, parentRunId: request.parentRunId, relation: SUBAGENT_RELATION, nativeSessionId: null, resumedFromRunId: null, handoffId: null, exitCode: null, goal:
|
|
224
|
+
saveRun(this.env.root, { ...source, id: runId, sessionId: child.run.sessionId, parentRunId: request.parentRunId, relation: SUBAGENT_RELATION, nativeSessionId: null, resumedFromRunId: child.run.resumedFromRunId ?? null, handoffId: null, exitCode: null, goal: child.run.goal ?? null, title: child.run.title ?? null, attachmentCount: 0, status: 'failed', startedAt: now(), endedAt: now(), terminalReason: error instanceof HarnessError ? error.message : 'Subagent startup failed before its session opened.', profile: child.run.profile ?? null, model: child.model ?? null, effort: child.effort ?? null });
|
|
203
225
|
}
|
|
204
226
|
return { runId, nativeSessionId: null };
|
|
205
227
|
});
|
|
@@ -208,10 +230,113 @@ export class Subagents {
|
|
|
208
230
|
const result = await until(started, parent.stopped.signal);
|
|
209
231
|
if (request.wait)
|
|
210
232
|
await this.wait({ parentRunId: request.parentRunId, runIds: [runId] });
|
|
211
|
-
return
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
/** The children this parent may read or continue: its own, and those recovered from its history. */
|
|
236
|
+
owned(parentRunId, parent) {
|
|
237
|
+
return new Set([...recordedSubagents(this.env.root, parentRunId), ...(parent?.recovered ?? [])]);
|
|
238
|
+
}
|
|
239
|
+
/** The newest run in a continued child's chain, among the runs this parent owns. */
|
|
240
|
+
latestLink(start, owned) {
|
|
241
|
+
const records = [...owned].flatMap((id) => findRun(this.env.root, id) ?? []);
|
|
242
|
+
let latest = start;
|
|
243
|
+
const seen = new Set([start.id]);
|
|
244
|
+
for (;;) {
|
|
245
|
+
const next = records.filter((record) => record.resumedFromRunId === latest.id && !seen.has(record.id)).sort((left, right) => left.startedAt.localeCompare(right.startedAt)).at(-1);
|
|
246
|
+
if (!next)
|
|
247
|
+
return latest;
|
|
248
|
+
seen.add(next.id);
|
|
249
|
+
latest = next;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** The first run of a chain: its folder holds the child's history for every later link. */
|
|
253
|
+
firstLink(record) {
|
|
254
|
+
let first = record;
|
|
255
|
+
const seen = new Set([record.id]);
|
|
256
|
+
while (first.resumedFromRunId && !seen.has(first.resumedFromRunId)) {
|
|
257
|
+
const previous = findRun(this.env.root, first.resumedFromRunId);
|
|
258
|
+
if (!previous || previous.relation !== SUBAGENT_RELATION)
|
|
259
|
+
break;
|
|
260
|
+
seen.add(previous.id);
|
|
261
|
+
first = previous;
|
|
262
|
+
}
|
|
263
|
+
return first;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Continues a stopped child as a new child run with `continueFrom`: the same history, profile,
|
|
267
|
+
* account, variant version and capability set, which must still lie within the parent's.
|
|
268
|
+
*/
|
|
269
|
+
async continueChild(parent, request) {
|
|
270
|
+
const { root } = this.env;
|
|
271
|
+
const { input, accountId, capabilities } = parent;
|
|
272
|
+
const requested = typeof request.continue === 'string' ? request.continue.trim() : '';
|
|
273
|
+
if (!requested)
|
|
274
|
+
throw invalid('continue must be the run ID of a subagent that stopped.');
|
|
275
|
+
if (request.agent !== undefined || request.tools !== undefined)
|
|
276
|
+
throw invalid('A continued subagent keeps its profile and tools; omit agent and tools.');
|
|
277
|
+
if (request.brief !== undefined && typeof request.brief !== 'string')
|
|
278
|
+
throw invalid('brief must be text.');
|
|
279
|
+
if (request.wait !== undefined && typeof request.wait !== 'boolean')
|
|
280
|
+
throw invalid('wait must be a boolean.');
|
|
281
|
+
await until(parent.ready, parent.stopped.signal);
|
|
282
|
+
const owned = this.owned(request.parentRunId, parent);
|
|
283
|
+
const named = owned.has(requested) ? findRun(root, requested) : null;
|
|
284
|
+
if (!named || named.relation !== SUBAGENT_RELATION)
|
|
285
|
+
throw invalid('Continue only a subagent that this conversation started.');
|
|
286
|
+
const latest = this.latestLink(named, owned);
|
|
287
|
+
if (isActiveStatus(latest.status))
|
|
288
|
+
throw invalid(`Subagent ${latest.id} is still running; wait for it with wait_subagents.`);
|
|
289
|
+
if (latest.status === 'completed')
|
|
290
|
+
throw invalid(`Subagent ${latest.id} already finished and its result was delivered. Start a new subagent for more work.`);
|
|
291
|
+
const sessionDir = join(input.sessionDir, 'subagents', this.firstLink(latest).id);
|
|
292
|
+
const continuation = continuationOf(root, latest.id, sessionDir);
|
|
293
|
+
if (!continuation.resumable || !continuation.resume)
|
|
294
|
+
throw invalid(`Subagent ${latest.id} cannot be continued: ${continuation.reason === 'no_history' ? 'it stopped before its conversation started' : 'its saved conversation is missing'}. Start a new subagent instead.`);
|
|
295
|
+
if (continuation.accountId !== accountId)
|
|
296
|
+
throw invalid(`Subagent ${latest.id} ran on another account; start a new subagent instead.`);
|
|
297
|
+
const pinned = continuation.capabilities;
|
|
298
|
+
if (!pinned)
|
|
299
|
+
throw invalid(`Subagent ${latest.id} has no recorded capabilities; start a new subagent instead.`);
|
|
300
|
+
const missing = [
|
|
301
|
+
...pinned.tools.filter((name) => !capabilities.tools.includes(name)),
|
|
302
|
+
...pinned.connectors.filter((id) => !capabilities.connectors.includes(id)),
|
|
303
|
+
...pinned.contributions.filter((id) => !capabilities.contributions.includes(id))
|
|
304
|
+
];
|
|
305
|
+
if (missing.length)
|
|
306
|
+
throw invalid(`Subagent ${latest.id} needs capabilities you do not have in this run: ${missing.join(', ')}. Start a new subagent instead.`);
|
|
307
|
+
let profile = null;
|
|
308
|
+
if (latest.profile)
|
|
309
|
+
profile = resolveProfile(root, input.cwd, latest.profile, input.variant && 'dir' in input.variant ? input.variant.dir : null);
|
|
310
|
+
if (input.plan) {
|
|
311
|
+
// A plan run continues only a research child whose pinned tools still qualify.
|
|
312
|
+
const check = latest.profile ? this.planSpawnCheck(request.parentRunId, { agent: latest.profile }) : { refusal: 'Plan mode can continue only a stopped research subagent that has a named profile.' };
|
|
313
|
+
if (check.refusal || !check.eligibility)
|
|
314
|
+
throw invalid(check.refusal ?? 'This subagent is not eligible for plan-mode research.');
|
|
315
|
+
const outside = pinned.tools.filter((name) => !check.eligibility.capabilities.tools.includes(name));
|
|
316
|
+
if (outside.length)
|
|
317
|
+
throw invalid(`Subagent ${latest.id} has tools plan mode does not allow: ${outside.join(', ')}.`);
|
|
318
|
+
}
|
|
319
|
+
const launch = profile
|
|
320
|
+
? { ...(input.launch ?? {}), sections: [...(input.launch?.sections ?? []).filter((section) => section.id !== 'subagent'), { id: 'subagent', title: `Your role: ${profile.name}`, body: profile.instructions || profile.description, budget: 16_000, order: 22 }] }
|
|
321
|
+
: input.launch;
|
|
322
|
+
const runId = randomUUID();
|
|
323
|
+
const child = {
|
|
324
|
+
...input,
|
|
325
|
+
run: { ...input.run, ...(input.plan ? { worktreeId: null } : {}), id: runId, sessionId: latest.sessionId, parentRunId: request.parentRunId, relation: SUBAGENT_RELATION, goal: latest.goal, title: latest.title ?? briefTitle(latest.goal), attachmentCount: 0, resumedFromRunId: latest.id, handoffId: null, profile: latest.profile ?? null },
|
|
326
|
+
accountId, poolId: null, sessionDir, resume: null, continueFrom: latest.id,
|
|
327
|
+
text: typeof request.brief === 'string' ? request.brief.trim() : '', images: undefined, requiresImageInput: false, preamble: null,
|
|
328
|
+
caller: { ...input.caller, runId: undefined, sessionId: latest.sessionId },
|
|
329
|
+
tools: { allow: pinned.tools, gated: (input.tools.gated ?? []).filter((name) => pinned.tools.includes(name)) },
|
|
330
|
+
capabilities: pinned, depth: (input.depth ?? 0) + 1,
|
|
331
|
+
variant: null, launch,
|
|
332
|
+
model: latest.model ?? input.model, effort: latest.effort ?? input.effort,
|
|
333
|
+
...(input.plan ? { connections: false, subagents: null } : {})
|
|
334
|
+
};
|
|
335
|
+
const result = await this.launchChild(parent, request, child);
|
|
336
|
+
return { ...result, continued: latest.id, ...(latest.profile ? { agent: latest.profile } : {}) };
|
|
212
337
|
}
|
|
213
338
|
selected(selection, parent) {
|
|
214
|
-
const owned =
|
|
339
|
+
const owned = this.owned(selection.parentRunId, parent);
|
|
215
340
|
if (selection.runIds !== undefined && (!Array.isArray(selection.runIds) || selection.runIds.some((id) => typeof id !== 'string')))
|
|
216
341
|
throw invalid('runIds must be an array of child run IDs.');
|
|
217
342
|
const ids = [...new Set(selection.runIds ?? [...owned])];
|
|
@@ -251,7 +376,9 @@ export class Subagents {
|
|
|
251
376
|
if (owner === parentRunId)
|
|
252
377
|
continue;
|
|
253
378
|
const old = findRun(this.env.root, owner);
|
|
254
|
-
|
|
379
|
+
// The owner marker on this native branch is the lineage; a host may give each launch of the
|
|
380
|
+
// same conversation a new session id (INV-RUN-4).
|
|
381
|
+
if (!old || old.accountId !== current.accountId || old.agentId !== current.agentId || old.projectId !== current.projectId || old.workingDirectory !== current.workingDirectory || !old.nativeSessionId || old.nativeSessionId !== current.nativeSessionId)
|
|
255
382
|
continue;
|
|
256
383
|
for (const id of recordedSubagents(this.env.root, owner)) {
|
|
257
384
|
let child = findRun(this.env.root, id);
|
|
@@ -277,12 +404,19 @@ export class Subagents {
|
|
|
277
404
|
}
|
|
278
405
|
}
|
|
279
406
|
const delivered = new Set(history.receipts.flatMap((receipt) => receipt.delivered ?? []));
|
|
280
|
-
const
|
|
407
|
+
const all = this.results({ parentRunId });
|
|
408
|
+
const records = new Map(all.map((result) => [result.runId, findRun(this.env.root, result.runId)]));
|
|
409
|
+
// A stopped child that was continued is reported through its continuation instead.
|
|
410
|
+
const superseded = new Set([...records.values()].flatMap((record) => record?.resumedFromRunId ? [record.resumedFromRunId] : []));
|
|
411
|
+
const pending = all.filter((result) => !isActiveStatus(result.status) && !delivered.has(result.runId) && !superseded.has(result.runId));
|
|
281
412
|
const chunks = [];
|
|
282
413
|
const ids = [];
|
|
283
414
|
let size = 0;
|
|
284
415
|
for (const result of pending) {
|
|
285
|
-
const
|
|
416
|
+
const record = records.get(result.runId);
|
|
417
|
+
const label = [record?.profile, record?.title].filter(Boolean).join(' · ');
|
|
418
|
+
const stopped = (result.status === 'interrupted' || result.status === 'failed') && continuationOf(this.env.root, result.runId).resumable;
|
|
419
|
+
const text = `Subagent run ${result.runId} · ${result.status}${label ? ` (${label})` : ''}\n${result.text || result.terminalReason || 'No written reply.'}${stopped ? `\nIt stopped before finishing. ${continueHint(result.runId)}` : ''}`;
|
|
286
420
|
if (size + text.length > 32_000 && ids.length)
|
|
287
421
|
break;
|
|
288
422
|
chunks.push(text);
|
|
@@ -301,12 +435,18 @@ export class Subagents {
|
|
|
301
435
|
}
|
|
302
436
|
extension(runId) {
|
|
303
437
|
return { name: 'native-subagents', factory: (pi) => {
|
|
304
|
-
pi.on('before_agent_start', (_event, ctx) => {
|
|
438
|
+
pi.on('before_agent_start', async (_event, ctx) => {
|
|
305
439
|
if (!this.parents.has(runId))
|
|
306
440
|
return;
|
|
307
|
-
|
|
441
|
+
const history = subagentHistory(ctx.sessionManager.getBranch());
|
|
442
|
+
this.restore(runId, history);
|
|
308
443
|
pi.appendEntry(SUBAGENT_OWNER, { runId });
|
|
309
444
|
this.parent(runId).started();
|
|
445
|
+
// Children an earlier reply left stopped are reported before the model answers, so it can
|
|
446
|
+
// continue them instead of starting over.
|
|
447
|
+
const notice = await this.delivery(runId, history, false);
|
|
448
|
+
if (notice)
|
|
449
|
+
return { message: { customType: SUBAGENT_RESULTS, content: notice.text, display: false, details: { [SUBAGENT_RECEIPT]: notice.receipt } } };
|
|
310
450
|
});
|
|
311
451
|
const deliver = async (event, ctx, settle) => {
|
|
312
452
|
if (!this.parents.has(runId) || (settle && event.outcome !== 'completed') || ctx.signal?.aborted)
|
|
@@ -11,14 +11,23 @@ export interface SubagentOptions {
|
|
|
11
11
|
export declare function subagentDepth(options: SubagentOptions | undefined): number;
|
|
12
12
|
export interface SubagentInput {
|
|
13
13
|
parentRunId: string;
|
|
14
|
-
|
|
14
|
+
/** The task for a new child; with `continue`, an optional extra instruction. */
|
|
15
|
+
brief?: string;
|
|
15
16
|
/** The short name the roster shows for the child (PROP-0030); the spawn tool requires it. */
|
|
16
17
|
title?: string;
|
|
17
18
|
tools?: string[];
|
|
18
19
|
wait?: boolean;
|
|
19
20
|
/** An agent profile by name (PROP-0029), or one of the parent variant's subagents (c5). */
|
|
20
21
|
agent?: string;
|
|
22
|
+
/**
|
|
23
|
+
* A stopped child to continue instead of starting a fresh one: its run id. The new child reopens
|
|
24
|
+
* that child's own history and keeps its profile, tools, account and variant; `brief` is then an
|
|
25
|
+
* optional extra instruction.
|
|
26
|
+
*/
|
|
27
|
+
continue?: string;
|
|
21
28
|
}
|
|
29
|
+
/** The words that tell a parent a stopped child can be continued rather than started again. */
|
|
30
|
+
export declare function continueHint(runId: string): string;
|
|
22
31
|
/** A subagent title is one short imperative, at most this many words (PROP-0030). */
|
|
23
32
|
export declare const MAX_SUBAGENT_TITLE_WORDS = 6;
|
|
24
33
|
/** The title a subagent title input means after cleaning, or undefined when it is not one. */
|
|
@@ -10,6 +10,10 @@ export function subagentDepth(options) {
|
|
|
10
10
|
const value = Math.trunc(options?.maxDepth ?? DEFAULT_SUBAGENT_DEPTH);
|
|
11
11
|
return Math.min(MAX_SUBAGENT_DEPTH, Math.max(1, Number.isFinite(value) ? value : DEFAULT_SUBAGENT_DEPTH));
|
|
12
12
|
}
|
|
13
|
+
/** The words that tell a parent a stopped child can be continued rather than started again. */
|
|
14
|
+
export function continueHint(runId) {
|
|
15
|
+
return `Its conversation is saved: continue it with spawn_subagent { "continue": "${runId}" } if the work is still needed, instead of starting it again from scratch.`;
|
|
16
|
+
}
|
|
13
17
|
/** A subagent title is one short imperative, at most this many words (PROP-0030). */
|
|
14
18
|
export const MAX_SUBAGENT_TITLE_WORDS = 6;
|
|
15
19
|
const BRIEF_TITLE_LENGTH = 60;
|
|
@@ -7,7 +7,7 @@ export interface WorkSliceInput {
|
|
|
7
7
|
maxToolCalls?: number;
|
|
8
8
|
/** Minutes in one reply; 0 disables this limit. */
|
|
9
9
|
maxMinutes?: number;
|
|
10
|
-
/** New tokens in one reply (input + cache
|
|
10
|
+
/** New tokens in one reply (new input + cache writes + output); 0 disables this limit, and no limit is the default. */
|
|
11
11
|
maxNewTokens?: number;
|
|
12
12
|
/** Slices one task may use before it is handed back to the person; 0 disables the cap. */
|
|
13
13
|
maxSlices?: number;
|
|
@@ -54,7 +54,7 @@ export declare function createSliceState(_policy: SlicePolicy, slice?: number, n
|
|
|
54
54
|
export declare function resetSliceState(state: SliceState, now?: number): void;
|
|
55
55
|
/** The first limit this reply has passed, named as a person would say it. */
|
|
56
56
|
export declare function sliceLimitReached(policy: SlicePolicy, state: SliceState, now?: number): string | null;
|
|
57
|
-
/** Commands that read as a check
|
|
57
|
+
/** Commands that read as a check for the repeated-failure rule. */
|
|
58
58
|
export declare function looksLikeCheck(command: string): boolean;
|
|
59
59
|
interface ToolCall {
|
|
60
60
|
toolName: string;
|
|
@@ -85,12 +85,15 @@ interface GuardApi {
|
|
|
85
85
|
export interface WorkSliceGuardOptions {
|
|
86
86
|
policy: SlicePolicy;
|
|
87
87
|
state: SliceState;
|
|
88
|
-
/**
|
|
88
|
+
/** Whether checkpoint_write is active; a function supports the terminal's live plan-mode switch. */
|
|
89
|
+
checkpointAvailable?: boolean | (() => boolean);
|
|
90
|
+
/** Called when a triggering call terminates the reply; the runner ends it. */
|
|
89
91
|
onEnd?: (end: SliceEnd, limit: string) => void;
|
|
90
92
|
}
|
|
91
93
|
/**
|
|
92
|
-
* Bounds one reply and names repeated work.
|
|
93
|
-
*
|
|
94
|
+
* Bounds one reply and names repeated work. Refusals request a checkpoint when available; without
|
|
95
|
+
* one, they ask for a partial report and prohibit further tools. A repeated call or failing command
|
|
96
|
+
* is named once, then ends the reply.
|
|
94
97
|
*/
|
|
95
98
|
export declare function workSliceGuard(options: WorkSliceGuardOptions): (pi: GuardApi) => void;
|
|
96
99
|
/**
|