@sixb/agent 0.2.2 → 0.2.4
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 +2 -2
- package/dist/artifacts/board-previews.d.ts +41 -0
- package/dist/artifacts/board-previews.d.ts.map +1 -0
- package/dist/artifacts/layout-check/layout-check.d.ts +38 -6
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
- package/dist/artifacts/layout-check/overview.d.ts +17 -0
- package/dist/artifacts/layout-check/overview.d.ts.map +1 -0
- package/dist/artifacts/materialize.d.ts +56 -24
- package/dist/artifacts/materialize.d.ts.map +1 -1
- package/dist/artifacts/publish-tool.d.ts +35 -27
- 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 +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12309 -10490
- package/dist/index.js.map +41 -35
- 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/sandbox-files.d.ts +19 -0
- package/dist/sandbox-files.d.ts.map +1 -1
- package/dist/subagent-tools.d.ts +23 -2
- 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/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/tool-files.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/types.d.ts +5 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/agent-prompt.ts +10 -10
- package/src/artifacts/board-previews.ts +218 -0
- package/src/artifacts/layout-check/check.cjs +304 -80
- package/src/artifacts/layout-check/layout-check.ts +119 -9
- package/src/artifacts/layout-check/overview.ts +291 -0
- package/src/artifacts/materialize.ts +181 -55
- package/src/artifacts/publish-tool.ts +475 -163
- 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/index.ts +2 -1
- package/src/run-agent-turn.ts +14 -4
- package/src/run-child.ts +1 -1
- package/src/run-conversation-turn.ts +4 -1
- package/src/run-environment.ts +40 -26
- package/src/run-subagent.ts +3 -3
- package/src/sandbox-api-context.ts +1 -1
- package/src/sandbox-files.ts +86 -0
- package/src/skills/sixb-artifacts/SKILL.md +48 -25
- package/src/skills/sixb-artifacts/canvas.md +140 -18
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +1 -1
- package/src/skills/sixb-artifacts/page.md +2 -2
- package/src/skills/sixb-artifacts/references.md +15 -12
- package/src/skills/sixb-artifacts/sheet.md +1 -1
- package/src/skills/sixb-artifacts/slides.md +2 -2
- package/src/subagent-tools.ts +134 -88
- 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/model-spec.ts +9 -12
- package/src/tools/read.ts +75 -9
- package/src/tools/tool-files.ts +3 -1
- package/src/tools/tool-outputs.ts +2 -2
- 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/types.ts +5 -4
- package/dist/ask-parent-tool.d.ts +0 -36
- package/dist/ask-parent-tool.d.ts.map +0 -1
- 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,12 +191,14 @@ 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[]
|
|
190
198
|
/** Why what the children published is not all in `$SIXB_ARTIFACTS`. */
|
|
191
199
|
readonly artifactsError?: string
|
|
200
|
+
/** The folders the Agent published from that took what the children wrote. */
|
|
201
|
+
readonly artifactsNote?: string
|
|
192
202
|
}
|
|
193
203
|
|
|
194
204
|
/** What a turn offers the children it spawns. */
|
|
@@ -207,11 +217,13 @@ export class SubagentCoordinator {
|
|
|
207
217
|
readonly #installed = new Map<string, readonly InstalledChildFile[]>()
|
|
208
218
|
/** The spawn being admitted: only this turn adds children to it. */
|
|
209
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>>()
|
|
210
222
|
/** What this turn sent each child, by its run id, in order. */
|
|
211
223
|
readonly #sent = new Map<string, SentMessage[]>()
|
|
212
224
|
/** What the turn and its children say to each other, in their runner. */
|
|
213
225
|
readonly #family = new FamilyMailbox()
|
|
214
|
-
/** The questions a `
|
|
226
|
+
/** The questions a `wait` returned: one alone no longer stops a wait for other children. */
|
|
215
227
|
readonly #reported = new Set<string>()
|
|
216
228
|
/** What each `message_agent` that answered a question returned, by its mail id, for a replay. */
|
|
217
229
|
readonly #answers = new Map<string, MessageSubagentOutput>()
|
|
@@ -369,13 +381,14 @@ export class SubagentCoordinator {
|
|
|
369
381
|
async createTools(): Promise<readonly ModelTool[]> {
|
|
370
382
|
const spawn: ModelTool<SpawnSubagentInput> = {
|
|
371
383
|
name: "spawn_agent",
|
|
384
|
+
strict: true,
|
|
372
385
|
description: [
|
|
373
386
|
"Start an isolated child agent and return immediately.",
|
|
374
387
|
"Use a short, stable key for the same logical delegation so retries cannot duplicate work.",
|
|
375
388
|
renderSubagentModelGuide(this.models),
|
|
376
389
|
...modelChoice(this.models).advice,
|
|
377
390
|
OMIT_MODEL,
|
|
378
|
-
`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.`,
|
|
379
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.`,
|
|
380
393
|
`At most ${this.context.subagentConcurrencyPerRun} child agents may be active for this run.`,
|
|
381
394
|
].join("\n"),
|
|
@@ -388,47 +401,14 @@ export class SubagentCoordinator {
|
|
|
388
401
|
},
|
|
389
402
|
errorText: agentToolErrorText,
|
|
390
403
|
}
|
|
391
|
-
const wait: ModelTool<WaitForSubagentsInput> = {
|
|
392
|
-
name: "wait_agent",
|
|
393
|
-
description: [
|
|
394
|
-
"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.",
|
|
395
|
-
"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.",
|
|
396
|
-
"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.",
|
|
397
|
-
"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.",
|
|
398
|
-
"A child that failed with agent.step_limit_reached did not finish: partialAnswer holds the last text it wrote.",
|
|
399
|
-
"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.",
|
|
400
|
-
].join("\n"),
|
|
401
|
-
inputSchema: waitInputSchema(this.context.subagentConcurrencyPerRun),
|
|
402
|
-
parseInput: (value) => parseWaitInput(value, this.context.subagentConcurrencyPerRun),
|
|
403
|
-
// A rich result, so its files reach later turns through $SIXB_ATTACHMENTS and the work trace.
|
|
404
|
-
execute: async (value, { signal }) => {
|
|
405
|
-
const { files, ...answer } = await this.wait(value, signal)
|
|
406
|
-
const output: AgentToolResult = {
|
|
407
|
-
kind: "agentToolResult",
|
|
408
|
-
content: [
|
|
409
|
-
{ type: "text", text: JSON.stringify(answer) },
|
|
410
|
-
...files.map(({ fileRef }) => ({ type: "file" as const, fileRef })),
|
|
411
|
-
],
|
|
412
|
-
}
|
|
413
|
-
assertJsonValue(output)
|
|
414
|
-
return output
|
|
415
|
-
},
|
|
416
|
-
// The answer lists each file's path this turn; the Agent reads the ones it needs.
|
|
417
|
-
toModelOutput: (output) => ({
|
|
418
|
-
type: "text",
|
|
419
|
-
value: isAgentToolResult(output)
|
|
420
|
-
? output.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("\n")
|
|
421
|
-
: JSON.stringify(output),
|
|
422
|
-
}),
|
|
423
|
-
errorText: agentToolErrorText,
|
|
424
|
-
}
|
|
425
404
|
const message: ModelTool<MessageSubagentInput> = {
|
|
426
405
|
name: "message_agent",
|
|
406
|
+
strict: true,
|
|
427
407
|
description: [
|
|
428
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.",
|
|
429
|
-
"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.",
|
|
430
410
|
"A child that finished, or paused for the user's approval, cannot read one.",
|
|
431
|
-
"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.",
|
|
432
412
|
].join("\n"),
|
|
433
413
|
inputSchema: messageInputSchema(),
|
|
434
414
|
parseInput: parseMessageInput,
|
|
@@ -439,7 +419,52 @@ export class SubagentCoordinator {
|
|
|
439
419
|
},
|
|
440
420
|
errorText: agentToolErrorText,
|
|
441
421
|
}
|
|
442
|
-
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)
|
|
443
468
|
}
|
|
444
469
|
|
|
445
470
|
/**
|
|
@@ -592,7 +617,7 @@ export class SubagentCoordinator {
|
|
|
592
617
|
const admitted = await this.admitInTurn(async () => {
|
|
593
618
|
if (await this.subagentRun(runId)) {
|
|
594
619
|
throw new AgentToolPublicError(
|
|
595
|
-
`[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.`
|
|
596
621
|
)
|
|
597
622
|
}
|
|
598
623
|
await this.clearDeadAttempts(paused, signal)
|
|
@@ -725,6 +750,45 @@ export class SubagentCoordinator {
|
|
|
725
750
|
}
|
|
726
751
|
|
|
727
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> {
|
|
728
792
|
signal.throwIfAborted()
|
|
729
793
|
const key = requireNonEmpty("spawn_agent", input.key, "key", 128)
|
|
730
794
|
const task = requireNonEmpty("spawn_agent", input.task, "task")
|
|
@@ -792,8 +856,8 @@ export class SubagentCoordinator {
|
|
|
792
856
|
const after = (await this.continuesAfterAnswer(existing)) ? "your answer" : "the approval"
|
|
793
857
|
throw new AgentToolPublicError(
|
|
794
858
|
isTerminalSubagent(existing)
|
|
795
|
-
? `[SixbAgent] '${key}' already continued after ${after}, and
|
|
796
|
-
: `[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.`
|
|
797
861
|
)
|
|
798
862
|
}
|
|
799
863
|
if (existing.kind === "subagent" && existing.parentRunId === this.parentRun.id) {
|
|
@@ -935,7 +999,8 @@ export class SubagentCoordinator {
|
|
|
935
999
|
const passedIds = normalizeRunIds(input.runIds, this.context.subagentConcurrencyPerRun)
|
|
936
1000
|
// A child of an earlier turn is waited for as the child of this one that continues it, else
|
|
937
1001
|
// as it ended.
|
|
938
|
-
const
|
|
1002
|
+
const resolved = await this.resolveChildren(passedIds, signal)
|
|
1003
|
+
const runIds = await Promise.all(resolved.map((runId) => this.continuedChildId(runId)))
|
|
939
1004
|
const earlierTurns = await this.earlierTurnsOf(runIds)
|
|
940
1005
|
for (;;) {
|
|
941
1006
|
signal.throwIfAborted()
|
|
@@ -951,7 +1016,7 @@ export class SubagentCoordinator {
|
|
|
951
1016
|
(run.parentRunId !== this.parentRun.id && !earlierTurns.has(run.parentRunId))
|
|
952
1017
|
) {
|
|
953
1018
|
throw new AgentToolPublicError(
|
|
954
|
-
`[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.`
|
|
955
1020
|
)
|
|
956
1021
|
}
|
|
957
1022
|
return run
|
|
@@ -997,6 +1062,9 @@ export class SubagentCoordinator {
|
|
|
997
1062
|
...(delivered.artifactsError === undefined
|
|
998
1063
|
? {}
|
|
999
1064
|
: { artifactsError: delivered.artifactsError }),
|
|
1065
|
+
...(delivered.artifactsNote === undefined
|
|
1066
|
+
? {}
|
|
1067
|
+
: { artifactsNote: delivered.artifactsNote }),
|
|
1000
1068
|
}
|
|
1001
1069
|
}
|
|
1002
1070
|
// A child of an earlier turn ends into that turn's mailbox, which this one does not hear.
|
|
@@ -1093,7 +1161,7 @@ export class SubagentCoordinator {
|
|
|
1093
1161
|
|
|
1094
1162
|
/**
|
|
1095
1163
|
* Copy what each finished child wrote under `out/` into the parent's sandbox, once, and install
|
|
1096
|
-
*
|
|
1164
|
+
* the artifacts the children wrote in its `$SIXB_ARTIFACTS`, as the parent's own. A result holds at
|
|
1097
1165
|
* most the attachment limits of new files, a child's whole or not at all; a child that does not
|
|
1098
1166
|
* fit, or whose files cannot be copied, says so, and its files come with a later wait.
|
|
1099
1167
|
*/
|
|
@@ -1104,6 +1172,7 @@ export class SubagentCoordinator {
|
|
|
1104
1172
|
readonly byChild: ReadonlyMap<string, ChildFiles>
|
|
1105
1173
|
readonly attached: readonly InstalledChildFile[]
|
|
1106
1174
|
readonly artifactsError?: string
|
|
1175
|
+
readonly artifactsNote?: string
|
|
1107
1176
|
}> {
|
|
1108
1177
|
const byChild = new Map<string, ChildFiles>()
|
|
1109
1178
|
const attached: InstalledChildFile[] = []
|
|
@@ -1166,16 +1235,22 @@ export class SubagentCoordinator {
|
|
|
1166
1235
|
}
|
|
1167
1236
|
|
|
1168
1237
|
let artifactsError: string | undefined
|
|
1238
|
+
let artifactsNote: string | undefined
|
|
1169
1239
|
try {
|
|
1170
|
-
await this.#runFiles?.
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1240
|
+
const folders = (await this.#runFiles?.installTurnArtifacts(signal)) ?? []
|
|
1241
|
+
if (folders.length > 0) {
|
|
1242
|
+
artifactsNote = `What these children wrote is installed in $SIXB_ARTIFACTS and written into the folders you published those artifacts from: ${folders.join(", ")}. Update from them as they are now.`
|
|
1243
|
+
}
|
|
1174
1244
|
} catch (error) {
|
|
1175
1245
|
if (signal.aborted) throw error
|
|
1176
|
-
artifactsError = `What these children
|
|
1246
|
+
artifactsError = `What these children wrote could not all be installed in $SIXB_ARTIFACTS (${errorMessage(error)}). The addresses in their answers still work.`
|
|
1247
|
+
}
|
|
1248
|
+
return {
|
|
1249
|
+
byChild,
|
|
1250
|
+
attached,
|
|
1251
|
+
...(artifactsError === undefined ? {} : { artifactsError }),
|
|
1252
|
+
...(artifactsNote === undefined ? {} : { artifactsNote }),
|
|
1177
1253
|
}
|
|
1178
|
-
return { byChild, attached, ...(artifactsError === undefined ? {} : { artifactsError }) }
|
|
1179
1254
|
}
|
|
1180
1255
|
|
|
1181
1256
|
private runFiles(): AgentRunFiles {
|
|
@@ -1380,38 +1455,21 @@ function messageInputSchema(): JsonObject {
|
|
|
1380
1455
|
}
|
|
1381
1456
|
}
|
|
1382
1457
|
|
|
1383
|
-
function waitInputSchema(maxRunIds: number): JsonObject {
|
|
1384
|
-
return {
|
|
1385
|
-
type: "object",
|
|
1386
|
-
properties: {
|
|
1387
|
-
runIds: {
|
|
1388
|
-
type: "array",
|
|
1389
|
-
minItems: 1,
|
|
1390
|
-
maxItems: maxRunIds,
|
|
1391
|
-
uniqueItems: true,
|
|
1392
|
-
items: { type: "string", minLength: 1 },
|
|
1393
|
-
},
|
|
1394
|
-
},
|
|
1395
|
-
required: ["runIds"],
|
|
1396
|
-
additionalProperties: false,
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
1458
|
function normalizeRunIds(value: readonly string[], maxRunIds: number): readonly string[] {
|
|
1401
1459
|
if (!Array.isArray(value) || value.length < 1 || value.length > maxRunIds) {
|
|
1402
1460
|
throw new AgentToolPublicError(
|
|
1403
|
-
`[SixbAgent]
|
|
1461
|
+
`[SixbAgent] wait takes between 1 and ${maxRunIds} child agents at once.`
|
|
1404
1462
|
)
|
|
1405
1463
|
}
|
|
1406
|
-
const runIds = value.map((runId) => requireNonEmpty("
|
|
1464
|
+
const runIds = value.map((runId) => requireNonEmpty("wait", runId, "id"))
|
|
1407
1465
|
if (new Set(runIds).size !== runIds.length) {
|
|
1408
|
-
throw new AgentToolPublicError("[SixbAgent]
|
|
1466
|
+
throw new AgentToolPublicError("[SixbAgent] wait ids must be unique.")
|
|
1409
1467
|
}
|
|
1410
1468
|
return runIds
|
|
1411
1469
|
}
|
|
1412
1470
|
|
|
1413
1471
|
function requireNonEmpty(
|
|
1414
|
-
toolName: "spawn_agent" | "
|
|
1472
|
+
toolName: "spawn_agent" | "wait" | "stop" | "message_agent",
|
|
1415
1473
|
value: unknown,
|
|
1416
1474
|
field: string,
|
|
1417
1475
|
maxLength?: number
|
|
@@ -1650,22 +1708,10 @@ function parseMessageInput(value: unknown): MessageSubagentInput {
|
|
|
1650
1708
|
}
|
|
1651
1709
|
}
|
|
1652
1710
|
|
|
1653
|
-
function parseWaitInput(value: unknown, maxRunIds: number): WaitForSubagentsInput {
|
|
1654
|
-
if (
|
|
1655
|
-
!isJsonObject(value) ||
|
|
1656
|
-
Object.keys(value).some((key) => key !== "runIds") ||
|
|
1657
|
-
!Array.isArray(value.runIds) ||
|
|
1658
|
-
!value.runIds.every((id) => typeof id === "string")
|
|
1659
|
-
) {
|
|
1660
|
-
throw new AgentToolPublicError("[SixbAgent] wait_agent expects an array of child run ids.")
|
|
1661
|
-
}
|
|
1662
|
-
return { runIds: normalizeRunIds(value.runIds, maxRunIds) }
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
1711
|
/** A child that stopped reading as the turn sent to it: it paused or ended just then. */
|
|
1666
1712
|
function stoppedReading(error: unknown, key: string): unknown {
|
|
1667
1713
|
if (!(error instanceof ChildMailClosedError)) return error
|
|
1668
1714
|
return new AgentToolPublicError(
|
|
1669
|
-
`[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.`
|
|
1670
1716
|
)
|
|
1671
1717
|
}
|