@sixb/agent 0.2.3 → 0.2.5
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 +3 -3
- package/dist/agent-prompt.d.ts.map +1 -1
- package/dist/artifacts/layout-check/layout-check.d.ts +21 -24
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
- package/dist/artifacts/publish-tool.d.ts +26 -44
- package/dist/artifacts/publish-tool.d.ts.map +1 -1
- package/dist/ask-tool.d.ts +62 -0
- package/dist/ask-tool.d.ts.map +1 -0
- package/dist/attachments.d.ts +1 -1
- package/dist/attachments.d.ts.map +1 -1
- package/dist/background-commands.d.ts +3 -3
- package/dist/background-commands.d.ts.map +1 -1
- package/dist/background-notices.d.ts.map +1 -1
- package/dist/child-files.d.ts +1 -1
- package/dist/child-questions.d.ts +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10457 -7971
- package/dist/index.js.map +46 -38
- package/dist/run-agent-turn.d.ts +3 -14
- package/dist/run-agent-turn.d.ts.map +1 -1
- package/dist/run-conversation-turn.d.ts.map +1 -1
- package/dist/run-environment.d.ts +4 -1
- package/dist/run-environment.d.ts.map +1 -1
- package/dist/run-subagent.d.ts +1 -1
- package/dist/run-subagent.d.ts.map +1 -1
- package/dist/sandbox-api-context.d.ts.map +1 -1
- package/dist/search-script.d.ts +7 -0
- package/dist/search-script.d.ts.map +1 -0
- package/dist/skills/built-in.d.ts.map +1 -1
- package/dist/subagent-tools.d.ts +20 -1
- package/dist/subagent-tools.d.ts.map +1 -1
- package/dist/tools/background.d.ts +50 -18
- package/dist/tools/background.d.ts.map +1 -1
- package/dist/tools/bash.d.ts +1 -0
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/edit-text.d.ts +22 -0
- package/dist/tools/edit-text.d.ts.map +1 -0
- package/dist/tools/edit.d.ts +54 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/file-writes.d.ts +52 -0
- package/dist/tools/file-writes.d.ts.map +1 -0
- package/dist/tools/glob.d.ts +41 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/grep.d.ts +64 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/model-spec.d.ts.map +1 -1
- package/dist/tools/read.d.ts +16 -3
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/sandbox-search.d.ts +26 -0
- package/dist/tools/sandbox-search.d.ts.map +1 -0
- package/dist/tools/search/command.d.ts +15 -0
- package/dist/tools/search/command.d.ts.map +1 -0
- package/dist/tools/search/gitignore.d.ts +28 -0
- package/dist/tools/search/gitignore.d.ts.map +1 -0
- package/dist/tools/search/glob.d.ts +15 -0
- package/dist/tools/search/glob.d.ts.map +1 -0
- package/dist/tools/search/main.d.ts +2 -0
- package/dist/tools/search/main.d.ts.map +1 -0
- package/dist/tools/search/match.d.ts +30 -0
- package/dist/tools/search/match.d.ts.map +1 -0
- package/dist/tools/search/pattern.d.ts +19 -0
- package/dist/tools/search/pattern.d.ts.map +1 -0
- package/dist/tools/search/read.d.ts +62 -0
- package/dist/tools/search/read.d.ts.map +1 -0
- package/dist/tools/search/request.d.ts +80 -0
- package/dist/tools/search/request.d.ts.map +1 -0
- package/dist/tools/search/search.d.ts +4 -0
- package/dist/tools/search/search.d.ts.map +1 -0
- package/dist/tools/search/walk.d.ts +43 -0
- package/dist/tools/search/walk.d.ts.map +1 -0
- package/dist/tools/tool-outputs.d.ts.map +1 -1
- package/dist/tools/view-file.d.ts +20 -23
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools/web-fetch/tool.d.ts +1 -0
- package/dist/tools/web-fetch/tool.d.ts.map +1 -1
- package/dist/tools/web-search.d.ts +1 -0
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/write.d.ts +36 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/turn-inbox.d.ts +75 -0
- package/dist/turn-inbox.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/agent-prompt.ts +10 -9
- package/src/agent-runtime/preflight.ts +1 -0
- package/src/artifacts/layout-check/check.cjs +176 -95
- package/src/artifacts/layout-check/layout-check.ts +118 -76
- package/src/artifacts/publish-tool.ts +123 -192
- package/src/ask-tool.ts +223 -0
- package/src/attachments.ts +7 -6
- package/src/background-commands.ts +5 -5
- package/src/background-notices.ts +5 -12
- package/src/child-files.ts +1 -1
- package/src/child-questions.ts +1 -1
- package/src/context-compaction.ts +4 -1
- package/src/generated/search.mjs +985 -0
- package/src/index.ts +1 -2
- package/src/run-agent-turn.ts +99 -133
- package/src/run-child.ts +1 -1
- package/src/run-conversation-turn.ts +8 -5
- package/src/run-environment.ts +40 -21
- package/src/run-subagent.ts +4 -4
- package/src/sandbox-api-context.ts +3 -0
- package/src/search-script-assets.d.ts +5 -0
- package/src/search-script.ts +9 -0
- package/src/skills/built-in.ts +16 -0
- package/src/skills/sixb-artifacts/SKILL.md +13 -13
- package/src/skills/sixb-artifacts/canvas.md +5 -4
- package/src/skills/sixb-artifacts/document.md +92 -5
- package/src/skills/sixb-artifacts/examples/document/service-proposal/design.css +114 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/document.html +159 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/fieldwise.svg +1 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/harbor-pine.svg +1 -0
- package/src/skills/sixb-artifacts/page.md +2 -2
- package/src/skills/sixb-artifacts/queries.md +2 -1
- package/src/skills/sixb-artifacts/slides.md +2 -2
- package/src/subagent-tools.ts +115 -81
- package/src/tools/background.ts +227 -67
- package/src/tools/bash.ts +2 -1
- package/src/tools/edit-text.ts +241 -0
- package/src/tools/edit.ts +166 -0
- package/src/tools/file-writes.ts +270 -0
- package/src/tools/glob.ts +124 -0
- package/src/tools/grep.ts +190 -0
- package/src/tools/model-spec.ts +13 -13
- package/src/tools/read.ts +75 -9
- package/src/tools/sandbox-search.ts +219 -0
- package/src/tools/search/command.ts +116 -0
- package/src/tools/search/gitignore.ts +101 -0
- package/src/tools/search/glob.ts +90 -0
- package/src/tools/search/main.ts +9 -0
- package/src/tools/search/match.ts +278 -0
- package/src/tools/search/pattern.ts +178 -0
- package/src/tools/search/read.ts +237 -0
- package/src/tools/search/request.ts +101 -0
- package/src/tools/search/search.ts +297 -0
- package/src/tools/search/walk.ts +145 -0
- package/src/tools/tool-outputs.ts +9 -4
- package/src/tools/view-file.ts +78 -80
- package/src/tools/web-fetch/tool.ts +2 -1
- package/src/tools/web-search.ts +1 -0
- package/src/tools/write.ts +95 -0
- package/src/turn-inbox.ts +283 -0
- package/dist/artifacts/board-previews.d.ts +0 -41
- package/dist/artifacts/board-previews.d.ts.map +0 -1
- package/dist/ask-parent-tool.d.ts +0 -36
- package/dist/ask-parent-tool.d.ts.map +0 -1
- package/src/artifacts/board-previews.ts +0 -218
- package/src/ask-parent-tool.ts +0 -100
package/src/subagent-tools.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
type AgentMessagePart,
|
|
8
8
|
type AgentReasoning,
|
|
9
9
|
AgentToolPublicError,
|
|
10
|
-
type AgentToolResult,
|
|
11
10
|
type LanguageModelRef,
|
|
12
11
|
type LanguageModelTier,
|
|
13
12
|
} from "@sixb/core"
|
|
@@ -22,9 +21,9 @@ import {
|
|
|
22
21
|
createSubagentRunId,
|
|
23
22
|
createSubagentThreadId,
|
|
24
23
|
deferredChildQuestion,
|
|
25
|
-
isAgentToolResult,
|
|
26
24
|
isAwaitingAnswerRun,
|
|
27
25
|
isPausedSubagentRun,
|
|
26
|
+
SUBAGENT_RUN_ID_PREFIX,
|
|
28
27
|
} from "@sixb/core/internal/agents"
|
|
29
28
|
import { formatLanguageModelTiers, isLanguageModelTier } from "@sixb/core/internal/model-execution"
|
|
30
29
|
import {
|
|
@@ -58,6 +57,7 @@ import { agentToolErrorText } from "./model-adapters"
|
|
|
58
57
|
import { renderModelLine } from "./model-lines"
|
|
59
58
|
import type { TurnChildren } from "./run-agent-turn"
|
|
60
59
|
import { continuationTrigger } from "./subagent-continuation"
|
|
60
|
+
import type { WaitableChildren } from "./tools/background"
|
|
61
61
|
import type { AgentRunFiles, AgentRunSettings } from "./types"
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -74,6 +74,14 @@ export const CHILD_WAIT_RECHECK_MS = 5_000
|
|
|
74
74
|
* short, so a short poll costs little.
|
|
75
75
|
*/
|
|
76
76
|
export const OTHER_TURN_RECHECK_MS = 250
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* How a wait or a stop looks again for a child it cannot find yet, spawned in the same step: a
|
|
80
|
+
* spawn's call starts once it is published, a moment after the wait's may. A second at most, then
|
|
81
|
+
* the id is refused as unknown.
|
|
82
|
+
*/
|
|
83
|
+
const SPAWN_RECHECK_MS = 100
|
|
84
|
+
const SPAWN_RECHECKS = 10
|
|
77
85
|
const OMIT_MODEL = "Omit model to use the project default."
|
|
78
86
|
|
|
79
87
|
/** With tiers, the model guide says how to choose, so only a list adds advice. */
|
|
@@ -183,7 +191,7 @@ export interface WaitedQuestion extends QuestionRef {
|
|
|
183
191
|
|
|
184
192
|
export interface WaitForSubagentsOutput {
|
|
185
193
|
readonly results: readonly WaitedSubagentResult[]
|
|
186
|
-
/** Every question a child of this turn waits on: `
|
|
194
|
+
/** Every question a child of this turn waits on: `wait` returns as soon as one comes. */
|
|
187
195
|
readonly questions?: readonly WaitedQuestion[]
|
|
188
196
|
/** The files no earlier result held, in the order of `results`. */
|
|
189
197
|
readonly files: readonly InstalledChildFile[]
|
|
@@ -209,11 +217,13 @@ export class SubagentCoordinator {
|
|
|
209
217
|
readonly #installed = new Map<string, readonly InstalledChildFile[]>()
|
|
210
218
|
/** The spawn being admitted: only this turn adds children to it. */
|
|
211
219
|
#admissions: Promise<unknown> = Promise.resolve()
|
|
220
|
+
/** Spawns this turn has started and not settled, by the child's run id. */
|
|
221
|
+
readonly #spawning = new Map<string, Promise<unknown>>()
|
|
212
222
|
/** What this turn sent each child, by its run id, in order. */
|
|
213
223
|
readonly #sent = new Map<string, SentMessage[]>()
|
|
214
224
|
/** What the turn and its children say to each other, in their runner. */
|
|
215
225
|
readonly #family = new FamilyMailbox()
|
|
216
|
-
/** The questions a `
|
|
226
|
+
/** The questions a `wait` returned: one alone no longer stops a wait for other children. */
|
|
217
227
|
readonly #reported = new Set<string>()
|
|
218
228
|
/** What each `message_agent` that answered a question returned, by its mail id, for a replay. */
|
|
219
229
|
readonly #answers = new Map<string, MessageSubagentOutput>()
|
|
@@ -371,13 +381,14 @@ export class SubagentCoordinator {
|
|
|
371
381
|
async createTools(): Promise<readonly ModelTool[]> {
|
|
372
382
|
const spawn: ModelTool<SpawnSubagentInput> = {
|
|
373
383
|
name: "spawn_agent",
|
|
384
|
+
strict: true,
|
|
374
385
|
description: [
|
|
375
386
|
"Start an isolated child agent and return immediately.",
|
|
376
387
|
"Use a short, stable key for the same logical delegation so retries cannot duplicate work.",
|
|
377
388
|
renderSubagentModelGuide(this.models),
|
|
378
389
|
...modelChoice(this.models).advice,
|
|
379
390
|
OMIT_MODEL,
|
|
380
|
-
`Pass files to copy files or directories of your sandbox into the child's, at the same paths, before it starts. What the child writes to out/ comes back with
|
|
391
|
+
`Pass files to copy files or directories of your sandbox into the child's, at the same paths, before it starts. What the child writes to out/ comes back with wait's result when it finishes, which lists where each file is.`,
|
|
381
392
|
`A child that has not answered after ${this.models.maxSteps} steps (model calls) stops and fails with agent.step_limit_reached; pass maxSteps to stop it sooner.`,
|
|
382
393
|
`At most ${this.context.subagentConcurrencyPerRun} child agents may be active for this run.`,
|
|
383
394
|
].join("\n"),
|
|
@@ -390,47 +401,14 @@ export class SubagentCoordinator {
|
|
|
390
401
|
},
|
|
391
402
|
errorText: agentToolErrorText,
|
|
392
403
|
}
|
|
393
|
-
const wait: ModelTool<WaitForSubagentsInput> = {
|
|
394
|
-
name: "wait_agent",
|
|
395
|
-
description: [
|
|
396
|
-
"Wait for previously spawned child agents and return their final text or failure, and the files each wrote to out/, each with its path in your sandbox. Pass every run id whose result is needed.",
|
|
397
|
-
"Shortly before this run must end, it returns children still at work as queued or running, so you can answer with what the others found.",
|
|
398
|
-
"A child paused on calls that wait for the user's approval returns as awaiting_approval, with those calls: it continues once the user decides, unless the user sends a new message or stops instead.",
|
|
399
|
-
"A message you sent a child that it has not read is listed in its unread. When one came as it answered, earlierAnswer holds what it answered before, and text what it wrote after.",
|
|
400
|
-
"A child that failed with agent.step_limit_reached did not finish: partialAnswer holds the last text it wrote.",
|
|
401
|
-
"It returns as soon as a child of this turn asks you a question, listed in questions with its key, whichever children you wait for: the child waits for your answer, which you give with message_agent.",
|
|
402
|
-
].join("\n"),
|
|
403
|
-
inputSchema: waitInputSchema(this.context.subagentConcurrencyPerRun),
|
|
404
|
-
parseInput: (value) => parseWaitInput(value, this.context.subagentConcurrencyPerRun),
|
|
405
|
-
// A rich result, so its files reach later turns through $SIXB_ATTACHMENTS and the work trace.
|
|
406
|
-
execute: async (value, { signal }) => {
|
|
407
|
-
const { files, ...answer } = await this.wait(value, signal)
|
|
408
|
-
const output: AgentToolResult = {
|
|
409
|
-
kind: "agentToolResult",
|
|
410
|
-
content: [
|
|
411
|
-
{ type: "text", text: JSON.stringify(answer) },
|
|
412
|
-
...files.map(({ fileRef }) => ({ type: "file" as const, fileRef })),
|
|
413
|
-
],
|
|
414
|
-
}
|
|
415
|
-
assertJsonValue(output)
|
|
416
|
-
return output
|
|
417
|
-
},
|
|
418
|
-
// The answer lists each file's path this turn; the Agent reads the ones it needs.
|
|
419
|
-
toModelOutput: (output) => ({
|
|
420
|
-
type: "text",
|
|
421
|
-
value: isAgentToolResult(output)
|
|
422
|
-
? output.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("\n")
|
|
423
|
-
: JSON.stringify(output),
|
|
424
|
-
}),
|
|
425
|
-
errorText: agentToolErrorText,
|
|
426
|
-
}
|
|
427
404
|
const message: ModelTool<MessageSubagentInput> = {
|
|
428
405
|
name: "message_agent",
|
|
406
|
+
strict: true,
|
|
429
407
|
description: [
|
|
430
408
|
"Send a message to a child agent still at work, by the key you spawned it with. It reads the message before its next step, or before its first while it is queued, and its answer accounts for it.",
|
|
431
|
-
"Use it to correct its course, add information it needs, or narrow its task, instead of waiting for an answer you would discard. Then collect its answer with
|
|
409
|
+
"Use it to correct its course, add information it needs, or narrow its task, instead of waiting for an answer you would discard. Then collect its answer with wait as usual.",
|
|
432
410
|
"A child that finished, or paused for the user's approval, cannot read one.",
|
|
433
|
-
"While a child waits on the question it asked you, your message is its answer. A child that
|
|
411
|
+
"While a child waits on the question it asked you, your message is its answer. A child that wait listed as awaiting_answer, paused on its question when an earlier turn ended, continues where it stopped with your message as its answer.",
|
|
434
412
|
].join("\n"),
|
|
435
413
|
inputSchema: messageInputSchema(),
|
|
436
414
|
parseInput: parseMessageInput,
|
|
@@ -441,7 +419,52 @@ export class SubagentCoordinator {
|
|
|
441
419
|
},
|
|
442
420
|
errorText: agentToolErrorText,
|
|
443
421
|
}
|
|
444
|
-
return [spawn,
|
|
422
|
+
return [spawn, message]
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** The turn's children as `wait` and `stop` reach them, by key or run id. */
|
|
426
|
+
waitable(): WaitableChildren {
|
|
427
|
+
return {
|
|
428
|
+
wait: (ids, signal) => this.wait({ runIds: ids }, signal),
|
|
429
|
+
stop: (id, signal) => this.stop(id, signal),
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Stop one of this turn's children, then return what `wait` returns for it once it ended: its
|
|
435
|
+
* answer so far, the files it wrote, the messages it did not read.
|
|
436
|
+
*/
|
|
437
|
+
async stop(id: string, signal: AbortSignal): Promise<WaitForSubagentsOutput> {
|
|
438
|
+
const { children } = this.session
|
|
439
|
+
const [resolved = ""] = await this.resolveChildren([requireNonEmpty("stop", id, "id")], signal)
|
|
440
|
+
// A child of an earlier turn is stopped as the child of this one that continues it.
|
|
441
|
+
const runId = await this.continuedChildId(resolved)
|
|
442
|
+
const child = await children.get(runId)
|
|
443
|
+
if (child?.kind !== "subagent" || child.parentRunId !== this.parentRun.id) {
|
|
444
|
+
throw new AgentToolPublicError(
|
|
445
|
+
`[SixbAgent] stop has no background command or child agent of this turn '${id}': pass the id bash returned, or the key you spawned the child with.`
|
|
446
|
+
)
|
|
447
|
+
}
|
|
448
|
+
// Its held calls are the user's to decide; stopping it would not stop them.
|
|
449
|
+
if (isPausedSubagentRun(child)) {
|
|
450
|
+
throw new AgentToolPublicError(
|
|
451
|
+
`[SixbAgent] stop cannot end '${id}': it is paused on calls that wait for the user's approval, and continues only once they decide. If its work is no longer needed, say so in your answer.`
|
|
452
|
+
)
|
|
453
|
+
}
|
|
454
|
+
await children.cancel(runId)
|
|
455
|
+
for (;;) {
|
|
456
|
+
// Taken before the read, so an end that comes during it wakes the wait.
|
|
457
|
+
const changed = this.#family.changed()
|
|
458
|
+
const run = await children.get(runId)
|
|
459
|
+
if (run?.kind !== "subagent" || isTerminalSubagent(run)) break
|
|
460
|
+
await delay(CHILD_WAIT_RECHECK_MS, signal, changed)
|
|
461
|
+
}
|
|
462
|
+
return this.wait({ runIds: [id] }, signal)
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** The run a key names: this turn's child under it. A run id names itself. */
|
|
466
|
+
private childRunId(id: string): string {
|
|
467
|
+
return id.startsWith(SUBAGENT_RUN_ID_PREFIX) ? id : createSubagentRunId(this.parentRun.id, id)
|
|
445
468
|
}
|
|
446
469
|
|
|
447
470
|
/**
|
|
@@ -594,7 +617,7 @@ export class SubagentCoordinator {
|
|
|
594
617
|
const admitted = await this.admitInTurn(async () => {
|
|
595
618
|
if (await this.subagentRun(runId)) {
|
|
596
619
|
throw new AgentToolPublicError(
|
|
597
|
-
`[SixbAgent] '${key}' already continues with the answer you sent it this turn. Message it again once it is at work, or wait for it with
|
|
620
|
+
`[SixbAgent] '${key}' already continues with the answer you sent it this turn. Message it again once it is at work, or wait for it with wait.`
|
|
598
621
|
)
|
|
599
622
|
}
|
|
600
623
|
await this.clearDeadAttempts(paused, signal)
|
|
@@ -727,6 +750,45 @@ export class SubagentCoordinator {
|
|
|
727
750
|
}
|
|
728
751
|
|
|
729
752
|
async spawn(input: SpawnSubagentInput, signal: AbortSignal): Promise<SpawnSubagentOutput> {
|
|
753
|
+
// Known as on its way from its start, so a wait of the same step finds it once it is admitted.
|
|
754
|
+
const runId = createSubagentRunId(this.parentRun.id, input.key?.trim() ?? "")
|
|
755
|
+
const spawning = this.admitSpawn(input, signal)
|
|
756
|
+
this.#spawning.set(runId, spawning)
|
|
757
|
+
try {
|
|
758
|
+
return await spawning
|
|
759
|
+
} finally {
|
|
760
|
+
if (this.#spawning.get(runId) === spawning) this.#spawning.delete(runId)
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* The runs these ids name. A run id names itself. A key names this turn's child under it, the one
|
|
766
|
+
* a spawn of this same step is admitting, or else the conversation's latest child under it, as
|
|
767
|
+
* `message_agent` finds one. Calls of one step run together, each starting once its call is
|
|
768
|
+
* published, so a wait may begin before the spawn beside it: a key that names nothing yet is
|
|
769
|
+
* looked up again a few times, a second at most. What is still missing the caller refuses.
|
|
770
|
+
*/
|
|
771
|
+
private async resolveChildren(ids: readonly string[], signal: AbortSignal): Promise<string[]> {
|
|
772
|
+
const resolved = ids.map((id) => this.childRunId(id))
|
|
773
|
+
for (let check = 0; ; check += 1) {
|
|
774
|
+
await Promise.allSettled(resolved.flatMap((runId) => this.#spawning.get(runId) ?? []))
|
|
775
|
+
const found = new Set((await this.session.children.getMany(resolved)).map((run) => run.id))
|
|
776
|
+
let missing = false
|
|
777
|
+
for (const [index, id] of ids.entries()) {
|
|
778
|
+
if (found.has(resolved[index] ?? "") || id.startsWith(SUBAGENT_RUN_ID_PREFIX)) continue
|
|
779
|
+
const earlier = await this.latestChildUnder(id)
|
|
780
|
+
if (earlier) resolved[index] = earlier.id
|
|
781
|
+
else missing = true
|
|
782
|
+
}
|
|
783
|
+
if (!missing || check === SPAWN_RECHECKS) return resolved
|
|
784
|
+
await delay(SPAWN_RECHECK_MS, signal)
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
private async admitSpawn(
|
|
789
|
+
input: SpawnSubagentInput,
|
|
790
|
+
signal: AbortSignal
|
|
791
|
+
): Promise<SpawnSubagentOutput> {
|
|
730
792
|
signal.throwIfAborted()
|
|
731
793
|
const key = requireNonEmpty("spawn_agent", input.key, "key", 128)
|
|
732
794
|
const task = requireNonEmpty("spawn_agent", input.task, "task")
|
|
@@ -794,8 +856,8 @@ export class SubagentCoordinator {
|
|
|
794
856
|
const after = (await this.continuesAfterAnswer(existing)) ? "your answer" : "the approval"
|
|
795
857
|
throw new AgentToolPublicError(
|
|
796
858
|
isTerminalSubagent(existing)
|
|
797
|
-
? `[SixbAgent] '${key}' already continued after ${after}, and
|
|
798
|
-
: `[SixbAgent] '${key}' is the sub-agent that continues after ${after}; wait for it with
|
|
859
|
+
? `[SixbAgent] '${key}' already continued after ${after}, and wait returns how it ended. To run it again, spawn it with a new key.`
|
|
860
|
+
: `[SixbAgent] '${key}' is the sub-agent that continues after ${after}; wait for it with wait.`
|
|
799
861
|
)
|
|
800
862
|
}
|
|
801
863
|
if (existing.kind === "subagent" && existing.parentRunId === this.parentRun.id) {
|
|
@@ -937,7 +999,8 @@ export class SubagentCoordinator {
|
|
|
937
999
|
const passedIds = normalizeRunIds(input.runIds, this.context.subagentConcurrencyPerRun)
|
|
938
1000
|
// A child of an earlier turn is waited for as the child of this one that continues it, else
|
|
939
1001
|
// as it ended.
|
|
940
|
-
const
|
|
1002
|
+
const resolved = await this.resolveChildren(passedIds, signal)
|
|
1003
|
+
const runIds = await Promise.all(resolved.map((runId) => this.continuedChildId(runId)))
|
|
941
1004
|
const earlierTurns = await this.earlierTurnsOf(runIds)
|
|
942
1005
|
for (;;) {
|
|
943
1006
|
signal.throwIfAborted()
|
|
@@ -953,7 +1016,7 @@ export class SubagentCoordinator {
|
|
|
953
1016
|
(run.parentRunId !== this.parentRun.id && !earlierTurns.has(run.parentRunId))
|
|
954
1017
|
) {
|
|
955
1018
|
throw new AgentToolPublicError(
|
|
956
|
-
`[SixbAgent] '${passedIds[index]}'
|
|
1019
|
+
`[SixbAgent] wait has no background command or child agent '${passedIds[index]}': pass the id bash returned, or the key you spawned the child with.`
|
|
957
1020
|
)
|
|
958
1021
|
}
|
|
959
1022
|
return run
|
|
@@ -1392,38 +1455,21 @@ function messageInputSchema(): JsonObject {
|
|
|
1392
1455
|
}
|
|
1393
1456
|
}
|
|
1394
1457
|
|
|
1395
|
-
function waitInputSchema(maxRunIds: number): JsonObject {
|
|
1396
|
-
return {
|
|
1397
|
-
type: "object",
|
|
1398
|
-
properties: {
|
|
1399
|
-
runIds: {
|
|
1400
|
-
type: "array",
|
|
1401
|
-
minItems: 1,
|
|
1402
|
-
maxItems: maxRunIds,
|
|
1403
|
-
uniqueItems: true,
|
|
1404
|
-
items: { type: "string", minLength: 1 },
|
|
1405
|
-
},
|
|
1406
|
-
},
|
|
1407
|
-
required: ["runIds"],
|
|
1408
|
-
additionalProperties: false,
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
1458
|
function normalizeRunIds(value: readonly string[], maxRunIds: number): readonly string[] {
|
|
1413
1459
|
if (!Array.isArray(value) || value.length < 1 || value.length > maxRunIds) {
|
|
1414
1460
|
throw new AgentToolPublicError(
|
|
1415
|
-
`[SixbAgent]
|
|
1461
|
+
`[SixbAgent] wait takes between 1 and ${maxRunIds} child agents at once.`
|
|
1416
1462
|
)
|
|
1417
1463
|
}
|
|
1418
|
-
const runIds = value.map((runId) => requireNonEmpty("
|
|
1464
|
+
const runIds = value.map((runId) => requireNonEmpty("wait", runId, "id"))
|
|
1419
1465
|
if (new Set(runIds).size !== runIds.length) {
|
|
1420
|
-
throw new AgentToolPublicError("[SixbAgent]
|
|
1466
|
+
throw new AgentToolPublicError("[SixbAgent] wait ids must be unique.")
|
|
1421
1467
|
}
|
|
1422
1468
|
return runIds
|
|
1423
1469
|
}
|
|
1424
1470
|
|
|
1425
1471
|
function requireNonEmpty(
|
|
1426
|
-
toolName: "spawn_agent" | "
|
|
1472
|
+
toolName: "spawn_agent" | "wait" | "stop" | "message_agent",
|
|
1427
1473
|
value: unknown,
|
|
1428
1474
|
field: string,
|
|
1429
1475
|
maxLength?: number
|
|
@@ -1662,22 +1708,10 @@ function parseMessageInput(value: unknown): MessageSubagentInput {
|
|
|
1662
1708
|
}
|
|
1663
1709
|
}
|
|
1664
1710
|
|
|
1665
|
-
function parseWaitInput(value: unknown, maxRunIds: number): WaitForSubagentsInput {
|
|
1666
|
-
if (
|
|
1667
|
-
!isJsonObject(value) ||
|
|
1668
|
-
Object.keys(value).some((key) => key !== "runIds") ||
|
|
1669
|
-
!Array.isArray(value.runIds) ||
|
|
1670
|
-
!value.runIds.every((id) => typeof id === "string")
|
|
1671
|
-
) {
|
|
1672
|
-
throw new AgentToolPublicError("[SixbAgent] wait_agent expects an array of child run ids.")
|
|
1673
|
-
}
|
|
1674
|
-
return { runIds: normalizeRunIds(value.runIds, maxRunIds) }
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
1711
|
/** A child that stopped reading as the turn sent to it: it paused or ended just then. */
|
|
1678
1712
|
function stoppedReading(error: unknown, key: string): unknown {
|
|
1679
1713
|
if (!(error instanceof ChildMailClosedError)) return error
|
|
1680
1714
|
return new AgentToolPublicError(
|
|
1681
|
-
`[SixbAgent] '${key}' stopped as you sent this, so it will not read it: it paused or ended. Wait for it with
|
|
1715
|
+
`[SixbAgent] '${key}' stopped as you sent this, so it will not read it: it paused or ended. Wait for it with wait to see which.`
|
|
1682
1716
|
)
|
|
1683
1717
|
}
|