clanka 0.25.3 → 0.26.1
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/dist/Acp.d.ts +5 -37
- package/dist/Acp.d.ts.map +1 -1
- package/dist/Acp.js +33 -48
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +64 -3
- package/dist/Acp.test.js.map +1 -1
- package/dist/AcpImage.test.js +3 -2
- package/dist/AcpImage.test.js.map +1 -1
- package/dist/AcpSessionStore.d.ts +114 -0
- package/dist/AcpSessionStore.d.ts.map +1 -0
- package/dist/AcpSessionStore.js +327 -0
- package/dist/AcpSessionStore.js.map +1 -0
- package/dist/AcpSessionStore.test.d.ts +2 -0
- package/dist/AcpSessionStore.test.d.ts.map +1 -0
- package/dist/AcpSessionStore.test.js +135 -0
- package/dist/AcpSessionStore.test.js.map +1 -0
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +6 -5
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +7 -6
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentBashJobs.test.js +7 -7
- package/dist/AgentBashJobs.test.js.map +1 -1
- package/dist/AgentExecutor.test.js +20 -20
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentImage.test.js +1 -1
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentSubagents.test.js +57 -29
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +4 -3
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +9 -7
- package/dist/AgentTools.js.map +1 -1
- package/dist/bin/{AiError-CsvdOsKR.mjs → AiError-DBaKz35C.mjs} +2 -2
- package/dist/bin/{Latch-B3e9629m.mjs → Latch-DOdbsGMQ.mjs} +1 -1
- package/dist/bin/{McpClient-BCxZZgnA.mjs → McpClient-B-FFG6Pg.mjs} +1 -1
- package/dist/bin/{OutputFormatter-ByMjyBhe.mjs → OutputFormatter-DhhP2i-7.mjs} +2 -2
- package/dist/bin/{Schema-BfUmMefy.mjs → Schema-CFdSO6iH.mjs} +11 -1
- package/dist/bin/{SemanticSearch-Cw10ozz8.mjs → SemanticSearch-C3a7LAQr.mjs} +2 -2
- package/dist/bin/cli.mjs +360 -154
- package/dist/bin/{upgrade-t590zYhO.mjs → upgrade-C4aOEWJH.mjs} +2 -2
- package/dist/cli.js +10 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +122 -3
- package/src/Acp.ts +41 -55
- package/src/AcpImage.test.ts +7 -2
- package/src/AcpSessionStore.test.ts +220 -0
- package/src/AcpSessionStore.ts +455 -0
- package/src/Agent.test.ts +10 -6
- package/src/Agent.ts +8 -6
- package/src/AgentBashJobs.test.ts +9 -9
- package/src/AgentExecutor.test.ts +20 -20
- package/src/AgentImage.test.ts +1 -1
- package/src/AgentSubagents.test.ts +77 -34
- package/src/AgentTools.ts +15 -10
- package/src/cli.ts +20 -9
- package/src/index.ts +5 -0
package/src/Agent.test.ts
CHANGED
|
@@ -183,7 +183,7 @@ describe("Agent", () => {
|
|
|
183
183
|
(script === "done"
|
|
184
184
|
? onTaskComplete("done")
|
|
185
185
|
: agentTasks.subagent({
|
|
186
|
-
id: "
|
|
186
|
+
id: "subagent_1",
|
|
187
187
|
prompt: "TASK-CHILD",
|
|
188
188
|
background: false,
|
|
189
189
|
environment: new AgentExecutor.EnvironmentUpdate({
|
|
@@ -644,7 +644,7 @@ describe("Agent usage", () => {
|
|
|
644
644
|
yield* agentTasks.waitTasks([task.id], { timeoutMs: 60_000 })
|
|
645
645
|
// Reading completion again must not add the child's usage again.
|
|
646
646
|
yield* agentTasks.taskOutput(task.id)
|
|
647
|
-
if (script === "
|
|
647
|
+
if (script === "subagent_1") {
|
|
648
648
|
yield* agentTasks.messageAgent({
|
|
649
649
|
id: task.id,
|
|
650
650
|
message: "follow up",
|
|
@@ -661,12 +661,12 @@ describe("Agent usage", () => {
|
|
|
661
661
|
switch (index) {
|
|
662
662
|
case 0:
|
|
663
663
|
return Stream.make(
|
|
664
|
-
toolCall("root", "
|
|
664
|
+
toolCall("root", "subagent_1"),
|
|
665
665
|
finish(100, "tool-calls", { read: 10, write: 1 }),
|
|
666
666
|
)
|
|
667
667
|
case 1:
|
|
668
668
|
return Stream.make(
|
|
669
|
-
toolCall("child", "
|
|
669
|
+
toolCall("child", "subagent_2"),
|
|
670
670
|
finish(200, "tool-calls", { read: 20, write: 2 }),
|
|
671
671
|
)
|
|
672
672
|
case 2:
|
|
@@ -695,6 +695,10 @@ describe("Agent usage", () => {
|
|
|
695
695
|
},
|
|
696
696
|
})
|
|
697
697
|
assert.deepStrictEqual(exit, Exit.succeed("complete"))
|
|
698
|
+
assert.deepStrictEqual(
|
|
699
|
+
outputsOfTag(outputs, "SubagentStart").map((part) => part.id),
|
|
700
|
+
[1, 2, 1],
|
|
701
|
+
)
|
|
698
702
|
const usage = outputsOfTag(outputs, "Usage")
|
|
699
703
|
// Child context windows must never replace the parent's window.
|
|
700
704
|
assert.deepStrictEqual(
|
|
@@ -738,7 +742,7 @@ describe("Agent usage", () => {
|
|
|
738
742
|
update: Option.none(),
|
|
739
743
|
})
|
|
740
744
|
const background = yield* agentTasks.subagent({
|
|
741
|
-
id: "
|
|
745
|
+
id: "subagent_1",
|
|
742
746
|
prompt: "sibling-b",
|
|
743
747
|
background: true,
|
|
744
748
|
environment: update,
|
|
@@ -750,7 +754,7 @@ describe("Agent usage", () => {
|
|
|
750
754
|
Effect.forkScoped,
|
|
751
755
|
)
|
|
752
756
|
yield* agentTasks.subagent({
|
|
753
|
-
id: "
|
|
757
|
+
id: "subagent_2",
|
|
754
758
|
prompt: "sibling-a",
|
|
755
759
|
background: false,
|
|
756
760
|
environment: update,
|
package/src/Agent.ts
CHANGED
|
@@ -623,8 +623,8 @@ export const makeWith = Effect.fnUntraced(function* <
|
|
|
623
623
|
)
|
|
624
624
|
})
|
|
625
625
|
|
|
626
|
-
const childTask = ({
|
|
627
|
-
id:
|
|
626
|
+
const childTask = ({ taskId, prompt, turn }: Child): Task => ({
|
|
627
|
+
id: taskId,
|
|
628
628
|
kind: "agent",
|
|
629
629
|
status: turn.status,
|
|
630
630
|
description: prompt,
|
|
@@ -654,7 +654,8 @@ export const makeWith = Effect.fnUntraced(function* <
|
|
|
654
654
|
environment,
|
|
655
655
|
}) {
|
|
656
656
|
const child: Child = {
|
|
657
|
-
id: Number(id),
|
|
657
|
+
id: Number(id.slice("subagent_".length)),
|
|
658
|
+
taskId: id,
|
|
658
659
|
taskOwner: crypto.randomUUID(),
|
|
659
660
|
prompt,
|
|
660
661
|
history: MutableRef.make(Prompt.empty),
|
|
@@ -685,7 +686,7 @@ ${prompt}`,
|
|
|
685
686
|
if (turn.status !== "completed") {
|
|
686
687
|
return yield* Effect.die(
|
|
687
688
|
new Error(
|
|
688
|
-
`Sub-agent ${child.
|
|
689
|
+
`Sub-agent ${child.taskId} ${turn.status}${turn.output ? `: ${turn.output}` : ""}`,
|
|
689
690
|
),
|
|
690
691
|
)
|
|
691
692
|
}
|
|
@@ -740,7 +741,7 @@ ${prompt}`,
|
|
|
740
741
|
Effect.suspend(() => {
|
|
741
742
|
const running = runningChildren()
|
|
742
743
|
if (running.length > 0) {
|
|
743
|
-
const ids = running.map((child) =>
|
|
744
|
+
const ids = running.map((child) => child.taskId)
|
|
744
745
|
const quoted = ids.map((id) => JSON.stringify(id)).join(", ")
|
|
745
746
|
return Effect.fail(
|
|
746
747
|
`taskComplete was rejected: sub-agents ${quoted} are still running. Call waitTasks({ ids: ${JSON.stringify(ids)} }) to wait for them, or stopTask(id) to stop them, before calling taskComplete.`,
|
|
@@ -1640,7 +1641,8 @@ To read the output, call taskOutput(${JSON.stringify(task.id)}).
|
|
|
1640
1641
|
}
|
|
1641
1642
|
|
|
1642
1643
|
interface Child {
|
|
1643
|
-
|
|
1644
|
+
readonly taskId: string
|
|
1645
|
+
/** The numeric task sequence for output events. */
|
|
1644
1646
|
readonly id: number
|
|
1645
1647
|
/** The agent's own owner id for the tasks it starts. */
|
|
1646
1648
|
readonly taskOwner: string
|
|
@@ -26,8 +26,8 @@ import * as AgentExecutor from "./AgentExecutor.ts"
|
|
|
26
26
|
// task exits, the next model call gets a user message
|
|
27
27
|
// `<task id="…" kind="bash" status="…" exitCode="…">output retrieval hint</task>`, unless the
|
|
28
28
|
// task was already reported by `stopTask`, `waitTasks` or a `taskOutput` call
|
|
29
|
-
// that saw its final status. Task IDs come from the executor's counter: "
|
|
30
|
-
// "
|
|
29
|
+
// that saw its final status. Task IDs come from the executor's counter: "bash_1",
|
|
30
|
+
// "bash_2", ...
|
|
31
31
|
// =============================================================================
|
|
32
32
|
|
|
33
33
|
type Respond = (
|
|
@@ -158,7 +158,7 @@ const executors = [
|
|
|
158
158
|
// --- tests -------------------------------------------------------------------
|
|
159
159
|
|
|
160
160
|
for (const [executorName, executorLayer] of executors) {
|
|
161
|
-
// Each test gets its own executor, so task IDs start at "
|
|
161
|
+
// Each test gets its own executor, so task IDs start at "bash_1".
|
|
162
162
|
describe(`background bash tasks (${executorName} executor)`, () => {
|
|
163
163
|
it.live(
|
|
164
164
|
"a finished bash task is pushed once with its id, kind, status, exit code and an output retrieval call",
|
|
@@ -177,7 +177,7 @@ await sleep(500)`,
|
|
|
177
177
|
case 1:
|
|
178
178
|
return execute(
|
|
179
179
|
"again",
|
|
180
|
-
`console.log((await taskOutput("
|
|
180
|
+
`console.log((await taskOutput("bash_1")).output)`,
|
|
181
181
|
)
|
|
182
182
|
default:
|
|
183
183
|
return text("done")
|
|
@@ -190,7 +190,7 @@ await sleep(500)`,
|
|
|
190
190
|
assert.strictEqual(pushes.length, 1, "pushed before the next call")
|
|
191
191
|
assert.match(
|
|
192
192
|
pushes[0]!,
|
|
193
|
-
/^<task id="
|
|
193
|
+
/^<task id="bash_1" kind="bash" status="failed" exitCode="3">\s*To read the output, call taskOutput\("bash_1"\)\.\s*<\/task>$/,
|
|
194
194
|
)
|
|
195
195
|
assert.include(
|
|
196
196
|
JSON.stringify(
|
|
@@ -221,11 +221,11 @@ await sleep(500)`,
|
|
|
221
221
|
`await bash({ command: "sleep 30", background: true })
|
|
222
222
|
await bash({ command: "echo READ", background: true })
|
|
223
223
|
await bash({ command: "echo UNREAD", background: true })
|
|
224
|
-
await stopTask("
|
|
225
|
-
let task = await taskOutput("
|
|
224
|
+
await stopTask("bash_1")
|
|
225
|
+
let task = await taskOutput("bash_2")
|
|
226
226
|
while (task.status === "running") {
|
|
227
227
|
await sleep(20)
|
|
228
|
-
task = await taskOutput("
|
|
228
|
+
task = await taskOutput("bash_2")
|
|
229
229
|
}
|
|
230
230
|
await bash({ command: "echo FOREGROUND" })
|
|
231
231
|
await waitTasks({ ids: [(await bash({ command: "echo WAITED", background: true })).id] })
|
|
@@ -243,7 +243,7 @@ console.log("SCRIPT" + "-DONE")`,
|
|
|
243
243
|
assert.strictEqual(pushes.length, 1)
|
|
244
244
|
assert.match(
|
|
245
245
|
pushes[0]!,
|
|
246
|
-
/^<task id="
|
|
246
|
+
/^<task id="bash_3" kind="bash" status="completed" exitCode="0">\s*To read the output, call taskOutput\("bash_3"\)\.\s*<\/task>$/,
|
|
247
247
|
)
|
|
248
248
|
assert.include(JSON.stringify(prompts[1]), "SCRIPT-DONE")
|
|
249
249
|
}).pipe(Effect.provide(executorLayer)),
|
|
@@ -579,7 +579,7 @@ await sleep(60000)`,
|
|
|
579
579
|
)
|
|
580
580
|
assert.strictEqual(
|
|
581
581
|
JSON.parse(output.split("OUTPUT:")[1]!),
|
|
582
|
-
'Task "
|
|
582
|
+
'Task "bash_1" is still running in the background',
|
|
583
583
|
)
|
|
584
584
|
assert.strictEqual(
|
|
585
585
|
yield* waitForLog(environment.cwd, started),
|
|
@@ -608,7 +608,7 @@ const task = await bash({
|
|
|
608
608
|
console.log("RETURNED:", JSON.stringify(task))`)
|
|
609
609
|
const task = JSON.parse(output.split("RETURNED:")[1]!)
|
|
610
610
|
assert.deepStrictEqual(task, {
|
|
611
|
-
id: "
|
|
611
|
+
id: "bash_1",
|
|
612
612
|
kind: "bash",
|
|
613
613
|
status: "running",
|
|
614
614
|
description: gatedCommand(environment.cwd),
|
|
@@ -644,11 +644,11 @@ try {
|
|
|
644
644
|
}`)
|
|
645
645
|
assert.notInclude(output, "REJECTED:")
|
|
646
646
|
assert.deepStrictEqual(JSON.parse(output.split("RETURNED:")[1]!), {
|
|
647
|
-
id: "
|
|
647
|
+
id: "bash_1",
|
|
648
648
|
kind: "bash",
|
|
649
649
|
status: "running",
|
|
650
650
|
description: command,
|
|
651
|
-
output: 'Task "
|
|
651
|
+
output: 'Task "bash_1" is still running in the background',
|
|
652
652
|
})
|
|
653
653
|
assert.strictEqual(
|
|
654
654
|
yield* waitForLog(environment.cwd, started),
|
|
@@ -657,7 +657,7 @@ try {
|
|
|
657
657
|
)
|
|
658
658
|
assert.include(
|
|
659
659
|
yield* runScript(
|
|
660
|
-
`console.log("OUTPUT:", (await taskOutput("
|
|
660
|
+
`console.log("OUTPUT:", (await taskOutput("bash_1")).output)`,
|
|
661
661
|
),
|
|
662
662
|
"OUTPUT: early",
|
|
663
663
|
)
|
|
@@ -688,7 +688,7 @@ try {
|
|
|
688
688
|
assert.deepStrictEqual(
|
|
689
689
|
JSON.parse(output.split("OK:")[1]!.split("\n")[0]!),
|
|
690
690
|
{
|
|
691
|
-
id: "
|
|
691
|
+
id: "bash_1",
|
|
692
692
|
kind: "bash",
|
|
693
693
|
status: "completed",
|
|
694
694
|
description: "echo hi",
|
|
@@ -719,7 +719,7 @@ await writeFile({ path: "gate", content: "" })
|
|
|
719
719
|
console.log("WAITED:", (await waitTasks({ ids: [task.id] })).map(show).join())`)
|
|
720
720
|
assert.include(
|
|
721
721
|
output,
|
|
722
|
-
'WAITED: {"id":"
|
|
722
|
+
'WAITED: {"id":"bash_1","kind":"bash","status":"completed","exitCode":0,"output":"done\\n"}',
|
|
723
723
|
)
|
|
724
724
|
}).pipe(Effect.timeout("5 seconds"), Effect.provide(executorLayer({}))),
|
|
725
725
|
)
|
|
@@ -747,7 +747,7 @@ console.log("OUTPUTS:", JSON.stringify(waits.map((task) => task.output)))`)
|
|
|
747
747
|
output,
|
|
748
748
|
"OUTPUTS: " +
|
|
749
749
|
JSON.stringify(
|
|
750
|
-
Array(3).fill('Task "
|
|
750
|
+
Array(3).fill('Task "bash_1" is still running in the background'),
|
|
751
751
|
),
|
|
752
752
|
)
|
|
753
753
|
assert.strictEqual(
|
|
@@ -798,9 +798,9 @@ console.log("RETURNED:", JSON.stringify({ id, kind, status }))`,
|
|
|
798
798
|
.pipe(Stream.mkString)
|
|
799
799
|
assert.include(
|
|
800
800
|
output,
|
|
801
|
-
'RETURNED: {"id":"
|
|
801
|
+
'RETURNED: {"id":"bash_2","kind":"bash","status":"running"}',
|
|
802
802
|
)
|
|
803
|
-
assert.deepStrictEqual(watched, ["
|
|
803
|
+
assert.deepStrictEqual(watched, ["bash_2"], "only the running task")
|
|
804
804
|
assert.deepStrictEqual(claims, [true], "reported once, by the watcher")
|
|
805
805
|
}).pipe(Effect.timeout("5 seconds"), Effect.provide(executorLayer({}))),
|
|
806
806
|
)
|
|
@@ -822,21 +822,21 @@ const done = async (id) => {
|
|
|
822
822
|
}
|
|
823
823
|
await bash({ command: ${JSON.stringify(gatedCommand(environment.cwd))}, background: true })
|
|
824
824
|
await bash({ command: "echo out && exit 3", background: true })
|
|
825
|
-
console.log("RUNNING:", show(await taskOutput("
|
|
825
|
+
console.log("RUNNING:", show(await taskOutput("bash_1")))
|
|
826
826
|
await writeFile({ path: "gate", content: "" })
|
|
827
|
-
console.log("COMPLETED:", show(await done("
|
|
828
|
-
console.log("FAILED:", show(await done("
|
|
827
|
+
console.log("COMPLETED:", show(await done("bash_1")))
|
|
828
|
+
console.log("FAILED:", show(await done("bash_2")))`)
|
|
829
829
|
assert.include(
|
|
830
830
|
output,
|
|
831
|
-
'RUNNING: {"id":"
|
|
831
|
+
'RUNNING: {"id":"bash_1","kind":"bash","status":"running","output":""}',
|
|
832
832
|
)
|
|
833
833
|
assert.include(
|
|
834
834
|
output,
|
|
835
|
-
'COMPLETED: {"id":"
|
|
835
|
+
'COMPLETED: {"id":"bash_1","kind":"bash","status":"completed","exitCode":0,"output":""}',
|
|
836
836
|
)
|
|
837
837
|
assert.include(
|
|
838
838
|
output,
|
|
839
|
-
'FAILED: {"id":"
|
|
839
|
+
'FAILED: {"id":"bash_2","kind":"bash","status":"failed","exitCode":3,"output":"out\\n"}',
|
|
840
840
|
)
|
|
841
841
|
}).pipe(Effect.timeout("5 seconds"), Effect.provide(executorLayer({}))),
|
|
842
842
|
)
|
|
@@ -849,12 +849,12 @@ console.log("FAILED:", show(await done("2")))`)
|
|
|
849
849
|
const show = ({ id, kind, status }) => JSON.stringify({ id, kind, status })
|
|
850
850
|
await bash({ command: ${JSON.stringify(gatedCommand(environment.cwd))}, background: true })
|
|
851
851
|
try {
|
|
852
|
-
await messageAgent({ id: "
|
|
852
|
+
await messageAgent({ id: "bash_1", message: "hello" })
|
|
853
853
|
} catch (error) {
|
|
854
854
|
console.log("MESSAGE-REJECTED:", String(error))
|
|
855
855
|
}
|
|
856
|
-
console.log("STOP-VOID:", (await stopTask("
|
|
857
|
-
console.log("STOPPED:", show(await taskOutput("
|
|
856
|
+
console.log("STOP-VOID:", (await stopTask("bash_1")) === undefined)
|
|
857
|
+
console.log("STOPPED:", show(await taskOutput("bash_1")))
|
|
858
858
|
try {
|
|
859
859
|
await stopTask("99")
|
|
860
860
|
} catch (error) {
|
|
@@ -867,7 +867,7 @@ try {
|
|
|
867
867
|
)
|
|
868
868
|
assert.include(
|
|
869
869
|
output,
|
|
870
|
-
'STOPPED: {"id":"
|
|
870
|
+
'STOPPED: {"id":"bash_1","kind":"bash","status":"stopped"}',
|
|
871
871
|
)
|
|
872
872
|
assert.include(output, "STOP-VOID: true")
|
|
873
873
|
assert.match(output, /REJECTED:.*No task with id "99".*listTasks\(\)/)
|
package/src/AgentImage.test.ts
CHANGED
|
@@ -273,7 +273,7 @@ describe("Agent images", () => {
|
|
|
273
273
|
const executor = makeExecutor(({ agentTasks, environment }) =>
|
|
274
274
|
Stream.fromEffect(
|
|
275
275
|
agentTasks.subagent({
|
|
276
|
-
id: "
|
|
276
|
+
id: "subagent_1",
|
|
277
277
|
prompt: "child task: describe the layout",
|
|
278
278
|
background: false,
|
|
279
279
|
environment: new AgentExecutor.EnvironmentUpdate({
|
|
@@ -33,7 +33,7 @@ import type { Output } from "./AgentOutput.ts"
|
|
|
33
33
|
// LanguageModel serves every agent; calls are routed by the task marker in
|
|
34
34
|
// each agent's first user message. Task IDs come from the executor's counter,
|
|
35
35
|
// shared by bash and agent tasks. Each test gets its own executor, so the
|
|
36
|
-
// first task is "
|
|
36
|
+
// first task is "subagent_1".
|
|
37
37
|
//
|
|
38
38
|
// Sub-agents always finish with `taskComplete`: with the local executor they
|
|
39
39
|
// currently run outside the parent's ConversationMode, so a text-only turn
|
|
@@ -300,7 +300,7 @@ for (const [executorName, executorLayer] of executors) {
|
|
|
300
300
|
return Stream.make(
|
|
301
301
|
toolCall(
|
|
302
302
|
"read",
|
|
303
|
-
`console.log((await taskOutput("
|
|
303
|
+
`console.log((await taskOutput("subagent_1")).output)`,
|
|
304
304
|
),
|
|
305
305
|
)
|
|
306
306
|
case 3:
|
|
@@ -316,14 +316,14 @@ for (const [executorName, executorLayer] of executors) {
|
|
|
316
316
|
assert.strictEqual(root.length, 4)
|
|
317
317
|
|
|
318
318
|
const started = lastToolResult(root[1]!.prompt)
|
|
319
|
-
assert.include(started, '"id":"
|
|
319
|
+
assert.include(started, '"id":"subagent_1"')
|
|
320
320
|
assert.include(started, '"kind":"agent"')
|
|
321
321
|
assert.include(started, '"status":"running"')
|
|
322
322
|
assert.include(started, '"description":"TASK-CHILD"')
|
|
323
323
|
|
|
324
|
-
const push = findPush(root[2]!.prompt, "
|
|
324
|
+
const push = findPush(root[2]!.prompt, "subagent_1", "completed")
|
|
325
325
|
assert.notStrictEqual(push.index, -1, "completion push delivered")
|
|
326
|
-
assert.include(push.text, 'taskOutput("
|
|
326
|
+
assert.include(push.text, 'taskOutput("subagent_1")')
|
|
327
327
|
assert.notInclude(push.text, "CHILD-HEAD")
|
|
328
328
|
assert.notInclude(push.text, "CHILD-TAIL")
|
|
329
329
|
assert.include(lastToolResult(root[3]!.prompt), "CHILD-HEAD")
|
|
@@ -383,7 +383,8 @@ for (const [executorName, executorLayer] of executors) {
|
|
|
383
383
|
assert.deepStrictEqual(exit, Exit.succeed("done"))
|
|
384
384
|
const root = calls.filter((call) => call.role === "root")
|
|
385
385
|
const delivery = root.find(
|
|
386
|
-
(call) =>
|
|
386
|
+
(call) =>
|
|
387
|
+
findPush(call.prompt, "subagent_1", "completed").index !== -1,
|
|
387
388
|
)
|
|
388
389
|
assert.isDefined(delivery, "completion push reached the model")
|
|
389
390
|
const prompt = delivery!.prompt
|
|
@@ -403,8 +404,8 @@ for (const [executorName, executorLayer] of executors) {
|
|
|
403
404
|
"AFTER-SCRIPT-RAN",
|
|
404
405
|
"the tool call after the push still ran",
|
|
405
406
|
)
|
|
406
|
-
const push = findPush(prompt, "
|
|
407
|
-
assert.include(push.text, 'taskOutput("
|
|
407
|
+
const push = findPush(prompt, "subagent_1", "completed")
|
|
408
|
+
assert.include(push.text, 'taskOutput("subagent_1")')
|
|
408
409
|
assert.isAbove(
|
|
409
410
|
push.index,
|
|
410
411
|
assistantIndex,
|
|
@@ -412,6 +413,31 @@ for (const [executorName, executorLayer] of executors) {
|
|
|
412
413
|
)
|
|
413
414
|
}))
|
|
414
415
|
|
|
416
|
+
test("a failed foreground child reports its usable task ID", () =>
|
|
417
|
+
Effect.gen(function* () {
|
|
418
|
+
const { exit, calls } = yield* runAgent({
|
|
419
|
+
conversationMode: true,
|
|
420
|
+
respond: (call) => {
|
|
421
|
+
if (call.role === "child") return Stream.fail(invalidRequest)
|
|
422
|
+
if (call.index === 0) {
|
|
423
|
+
return Stream.make(
|
|
424
|
+
toolCall(
|
|
425
|
+
"foreground",
|
|
426
|
+
'await subagent({ prompt: "TASK-CHILD" })',
|
|
427
|
+
),
|
|
428
|
+
)
|
|
429
|
+
}
|
|
430
|
+
return Stream.fromIterable(text("recovered"))
|
|
431
|
+
},
|
|
432
|
+
})
|
|
433
|
+
assert.deepStrictEqual(exit, Exit.succeed("recovered"))
|
|
434
|
+
const root = calls.filter((call) => call.role === "root")
|
|
435
|
+
assert.include(
|
|
436
|
+
lastToolResult(root[1]!.prompt),
|
|
437
|
+
"Sub-agent subagent_1 failed",
|
|
438
|
+
)
|
|
439
|
+
}))
|
|
440
|
+
|
|
415
441
|
test("a failed background child is pushed as failed and the parent keeps going", () =>
|
|
416
442
|
Effect.gen(function* () {
|
|
417
443
|
const childRelease = Latch.makeUnsafe(false)
|
|
@@ -440,9 +466,9 @@ for (const [executorName, executorLayer] of executors) {
|
|
|
440
466
|
|
|
441
467
|
assert.deepStrictEqual(exit, Exit.succeed("recovered"))
|
|
442
468
|
const root = calls.filter((call) => call.role === "root")
|
|
443
|
-
const push = findPush(root[2]!.prompt, "
|
|
469
|
+
const push = findPush(root[2]!.prompt, "subagent_1", "failed")
|
|
444
470
|
assert.notStrictEqual(push.index, -1, "failure push delivered")
|
|
445
|
-
assert.include(push.text, 'taskOutput("
|
|
471
|
+
assert.include(push.text, 'taskOutput("subagent_1")')
|
|
446
472
|
assert.notInclude(push.text, "rejected")
|
|
447
473
|
}))
|
|
448
474
|
|
|
@@ -479,7 +505,7 @@ try {
|
|
|
479
505
|
assert.notInclude(rejected, "ACCEPTED")
|
|
480
506
|
assert.include(
|
|
481
507
|
rejected,
|
|
482
|
-
'waitTasks({ ids: ["
|
|
508
|
+
'waitTasks({ ids: ["subagent_1"] })',
|
|
483
509
|
"quotes the call that waits for the running child",
|
|
484
510
|
)
|
|
485
511
|
assert.include(rejected, "stopTask")
|
|
@@ -487,7 +513,7 @@ try {
|
|
|
487
513
|
return Stream.make(
|
|
488
514
|
toolCall(
|
|
489
515
|
"wait",
|
|
490
|
-
`const results = await waitTasks({ ids: ["
|
|
516
|
+
`const results = await waitTasks({ ids: ["subagent_1"] })
|
|
491
517
|
console.log(JSON.stringify(results))
|
|
492
518
|
await taskComplete("done")`,
|
|
493
519
|
),
|
|
@@ -505,7 +531,7 @@ await taskComplete("done")`,
|
|
|
505
531
|
2,
|
|
506
532
|
)
|
|
507
533
|
const waited = lastToolResult(history)
|
|
508
|
-
assert.include(waited, '"id":"
|
|
534
|
+
assert.include(waited, '"id":"subagent_1"')
|
|
509
535
|
assert.include(
|
|
510
536
|
waited,
|
|
511
537
|
'"status":"completed"',
|
|
@@ -608,8 +634,8 @@ await taskComplete("done")`,
|
|
|
608
634
|
Stream.as(
|
|
609
635
|
toolCall(
|
|
610
636
|
"stop",
|
|
611
|
-
`console.log("STOP-VOID:", (await stopTask("
|
|
612
|
-
console.log(JSON.stringify(await taskOutput("
|
|
637
|
+
`console.log("STOP-VOID:", (await stopTask("subagent_1")) === undefined)
|
|
638
|
+
console.log(JSON.stringify(await taskOutput("subagent_1")))`,
|
|
613
639
|
),
|
|
614
640
|
),
|
|
615
641
|
)
|
|
@@ -628,7 +654,7 @@ console.log(JSON.stringify(await taskOutput("1")))`,
|
|
|
628
654
|
const root = calls.filter((call) => call.role === "root")
|
|
629
655
|
const stopped = lastToolResult(root[2]!.prompt)
|
|
630
656
|
assert.include(stopped, "STOP-VOID: true")
|
|
631
|
-
assert.include(stopped, '"id":"
|
|
657
|
+
assert.include(stopped, '"id":"subagent_1"')
|
|
632
658
|
assert.include(stopped, '"status":"stopped"')
|
|
633
659
|
assert.isTrue(
|
|
634
660
|
interruptedBeforeNextTurn,
|
|
@@ -661,7 +687,7 @@ console.log(JSON.stringify(await taskOutput("1")))`,
|
|
|
661
687
|
Stream.as(
|
|
662
688
|
toolCall(
|
|
663
689
|
"message",
|
|
664
|
-
`console.log("MESSAGE-VOID:", (await messageAgent({ id: "
|
|
690
|
+
`console.log("MESSAGE-VOID:", (await messageAgent({ id: "subagent_1", message: "STEER" })) === undefined)`,
|
|
665
691
|
),
|
|
666
692
|
),
|
|
667
693
|
)
|
|
@@ -713,7 +739,7 @@ console.log(JSON.stringify(await taskOutput("1")))`,
|
|
|
713
739
|
return Stream.make(
|
|
714
740
|
toolCall(
|
|
715
741
|
"message",
|
|
716
|
-
`const result = await messageAgent({ id: "
|
|
742
|
+
`const result = await messageAgent({ id: "subagent_1", message: "FOLLOW-UP" })
|
|
717
743
|
console.log("MESSAGE-VOID:", result === undefined)`,
|
|
718
744
|
),
|
|
719
745
|
)
|
|
@@ -748,9 +774,11 @@ console.log("MESSAGE-VOID:", result === undefined)`,
|
|
|
748
774
|
return complete("GRAND-RESULT")
|
|
749
775
|
case "child":
|
|
750
776
|
if (
|
|
751
|
-
findPush(
|
|
752
|
-
|
|
753
|
-
|
|
777
|
+
findPush(
|
|
778
|
+
call.prompt,
|
|
779
|
+
"subagent_2",
|
|
780
|
+
"completed",
|
|
781
|
+
).text.includes('taskOutput("subagent_2")')
|
|
754
782
|
) {
|
|
755
783
|
return complete("CHILD-DONE")
|
|
756
784
|
}
|
|
@@ -787,12 +815,12 @@ console.log(JSON.stringify(result))`,
|
|
|
787
815
|
const root = calls.filter((call) => call.role === "root")
|
|
788
816
|
assert.strictEqual(root.length, 2)
|
|
789
817
|
const foreground = lastToolResult(root[1]!.prompt)
|
|
790
|
-
assert.include(foreground, '"id":"
|
|
818
|
+
assert.include(foreground, '"id":"subagent_1"')
|
|
791
819
|
assert.include(foreground, '"status":"completed"')
|
|
792
820
|
assert.include(foreground, "CHILD-DONE")
|
|
793
821
|
for (const call of root) {
|
|
794
822
|
assert.isFalse(
|
|
795
|
-
hasAnyPush(call.prompt, "
|
|
823
|
+
hasAnyPush(call.prompt, "subagent_2"),
|
|
796
824
|
"the grandchild's push never reaches the root",
|
|
797
825
|
)
|
|
798
826
|
}
|
|
@@ -869,10 +897,11 @@ console.log("ROOT:" + (await bash({ command: "pwd" })).output.trim())`,
|
|
|
869
897
|
return Stream.make(
|
|
870
898
|
toolCall(
|
|
871
899
|
"mixed",
|
|
872
|
-
`const
|
|
873
|
-
const
|
|
900
|
+
`const agentTask = await subagent({ prompt: "TASK-CHILD", background: true })
|
|
901
|
+
const bashTask = await bash({ command: "echo BASH-OUT", background: true })
|
|
902
|
+
console.log("IDS:" + JSON.stringify((await listTasks()).map(task => task.id)))
|
|
874
903
|
const ended = await waitTasks({ ids: [bashTask.id, agentTask.id] })
|
|
875
|
-
console.log(JSON.stringify(ended.map(({ kind, status, output }) => ({ kind, status, output: output.trim() }))))`,
|
|
904
|
+
console.log(JSON.stringify(ended.map(({ id, kind, status, output }) => ({ id, kind, status, output: output.trim() }))))`,
|
|
876
905
|
),
|
|
877
906
|
)
|
|
878
907
|
case 1:
|
|
@@ -886,11 +915,25 @@ console.log(JSON.stringify(ended.map(({ kind, status, output }) => ({ kind, stat
|
|
|
886
915
|
assert.deepStrictEqual(exit, Exit.succeed("done"))
|
|
887
916
|
const root = calls.filter((call) => call.role === "root")
|
|
888
917
|
assert.strictEqual(root.length, 2, "no late push wakes the run")
|
|
918
|
+
assert.include(
|
|
919
|
+
lastToolResult(root[1]!.prompt),
|
|
920
|
+
'IDS:["subagent_1","bash_2"]',
|
|
921
|
+
)
|
|
889
922
|
assert.include(
|
|
890
923
|
lastToolResult(root[1]!.prompt),
|
|
891
924
|
JSON.stringify([
|
|
892
|
-
{
|
|
893
|
-
|
|
925
|
+
{
|
|
926
|
+
id: "bash_2",
|
|
927
|
+
kind: "bash",
|
|
928
|
+
status: "completed",
|
|
929
|
+
output: "BASH-OUT",
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
id: "subagent_1",
|
|
933
|
+
kind: "agent",
|
|
934
|
+
status: "completed",
|
|
935
|
+
output: "CHILD-OUT",
|
|
936
|
+
},
|
|
894
937
|
]),
|
|
895
938
|
)
|
|
896
939
|
assert.deepStrictEqual(
|
|
@@ -1013,15 +1056,15 @@ console.log("OUTPUT:" + task.output)`,
|
|
|
1013
1056
|
assert.include(waited, "WAITED:running", "returned at the deadline")
|
|
1014
1057
|
assert.include(
|
|
1015
1058
|
waited,
|
|
1016
|
-
'OUTPUT:Task "
|
|
1059
|
+
'OUTPUT:Task "subagent_1" is still running in the background',
|
|
1017
1060
|
)
|
|
1018
1061
|
assert.isFalse(childInterrupted, "the deadline does not stop the agent")
|
|
1019
1062
|
assert.deepStrictEqual(exit, Exit.succeed("done"))
|
|
1020
1063
|
const root = calls.filter((call) => call.role === "root")
|
|
1021
1064
|
assert.strictEqual(root.length, 3)
|
|
1022
1065
|
assert.include(
|
|
1023
|
-
findPush(root[2]!.prompt, "
|
|
1024
|
-
'taskOutput("
|
|
1066
|
+
findPush(root[2]!.prompt, "subagent_1", "completed").text,
|
|
1067
|
+
'taskOutput("subagent_1")',
|
|
1025
1068
|
"its completion is pushed once it ends",
|
|
1026
1069
|
)
|
|
1027
1070
|
}))
|
|
@@ -1063,15 +1106,15 @@ console.log("RETURNED")`,
|
|
|
1063
1106
|
assert.notInclude(result, "RETURNED")
|
|
1064
1107
|
assert.isTrue(
|
|
1065
1108
|
pushTexts(root[1]!.prompt).some((push) =>
|
|
1066
|
-
/^<task id="
|
|
1109
|
+
/^<task id="bash_1" kind="bash" status="completed" exitCode="0">\s*To read the output, call taskOutput\("bash_1"\)\.\s*<\/task>$/.test(
|
|
1067
1110
|
push,
|
|
1068
1111
|
),
|
|
1069
1112
|
),
|
|
1070
1113
|
"the bash task is pushed",
|
|
1071
1114
|
)
|
|
1072
1115
|
assert.include(
|
|
1073
|
-
findPush(root[1]!.prompt, "
|
|
1074
|
-
'taskOutput("
|
|
1116
|
+
findPush(root[1]!.prompt, "subagent_2", "completed").text,
|
|
1117
|
+
'taskOutput("subagent_2")',
|
|
1075
1118
|
"the agent task is pushed",
|
|
1076
1119
|
)
|
|
1077
1120
|
}),
|
package/src/AgentTools.ts
CHANGED
|
@@ -127,9 +127,10 @@ export type Task = typeof Task.Type
|
|
|
127
127
|
*/
|
|
128
128
|
export interface AgentTasks {
|
|
129
129
|
/**
|
|
130
|
-
* Start a sub-agent under the id the executor allocated
|
|
131
|
-
* it resolves once the agent has finished,
|
|
132
|
-
* In the background it resolves straight away
|
|
130
|
+
* Start a sub-agent under the id the executor allocated, of the form
|
|
131
|
+
* `subagent_<n>`. In the foreground it resolves once the agent has finished,
|
|
132
|
+
* and dies if the agent failed. In the background it resolves straight away
|
|
133
|
+
* with `status: "running"`.
|
|
133
134
|
*/
|
|
134
135
|
readonly subagent: (options: {
|
|
135
136
|
readonly id: string
|
|
@@ -629,7 +630,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
629
630
|
const tasks = new Map<string, TaskEntry>()
|
|
630
631
|
let nextTaskId = 1
|
|
631
632
|
const registerAgentTask = Effect.gen(function* () {
|
|
632
|
-
const id =
|
|
633
|
+
const id = `subagent_${nextTaskId++}`
|
|
633
634
|
tasks.set(id, { kind: "agent", id, owner: yield* TaskOwner })
|
|
634
635
|
return id
|
|
635
636
|
})
|
|
@@ -642,7 +643,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
642
643
|
) {
|
|
643
644
|
const entry: BashEntry = {
|
|
644
645
|
kind: "bash",
|
|
645
|
-
id:
|
|
646
|
+
id: `bash_${nextTaskId++}`,
|
|
646
647
|
owner: yield* TaskOwner,
|
|
647
648
|
description,
|
|
648
649
|
command: { ...command, reported: false },
|
|
@@ -1014,7 +1015,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
1014
1015
|
)
|
|
1015
1016
|
const agentTasks = yield* AgentTaskExecutor
|
|
1016
1017
|
return [...bashTasks, ...(yield* agentTasks.listTasks)].toSorted(
|
|
1017
|
-
(a, b) =>
|
|
1018
|
+
(a, b) => taskNumber(a.id) - taskNumber(b.id),
|
|
1018
1019
|
)
|
|
1019
1020
|
}),
|
|
1020
1021
|
gh: Effect.fn("AgentTools.gh")(function* (args) {
|
|
@@ -1280,23 +1281,27 @@ const decodeSubagent = decodeParams(
|
|
|
1280
1281
|
)
|
|
1281
1282
|
const decodeMessageAgent = decodeParams(
|
|
1282
1283
|
AgentTools.tools.messageAgent.parametersSchema,
|
|
1283
|
-
'messageAgent requires an options object, for example: messageAgent({ id: "
|
|
1284
|
+
'messageAgent requires an options object, for example: messageAgent({ id: "subagent_3", message: "..." }).',
|
|
1284
1285
|
)
|
|
1285
1286
|
const decodeTaskOutput = decodeParams(
|
|
1286
1287
|
AgentTools.tools.taskOutput.parametersSchema,
|
|
1287
|
-
'taskOutput requires a task id, for example: taskOutput("
|
|
1288
|
+
'taskOutput requires a task id, for example: taskOutput("bash_1").',
|
|
1288
1289
|
)
|
|
1289
1290
|
const decodeWaitTasks = decodeParams(
|
|
1290
1291
|
AgentTools.tools.waitTasks.parametersSchema,
|
|
1291
|
-
'waitTasks requires an options object, for example: waitTasks({ ids: ["
|
|
1292
|
+
'waitTasks requires an options object, for example: waitTasks({ ids: ["subagent_3", "bash_4"] }) or waitTasks({ ids: ["subagent_3"], timeoutMs: 60000 }).',
|
|
1292
1293
|
)
|
|
1293
1294
|
|
|
1294
1295
|
/** The caller's `bash` timeout, which also bounds `waitTasks`. */
|
|
1295
1296
|
const bashTimeoutMs = (limits: typeof CommandLimits.Service) =>
|
|
1296
1297
|
Duration.toMillis(limits.timeout ?? defaultBashTimeout)
|
|
1298
|
+
|
|
1299
|
+
/** The counter in a task id such as `bash_3`, which orders tasks by creation. */
|
|
1300
|
+
const taskNumber = (id: string) => Number(id.slice(id.indexOf("_") + 1))
|
|
1301
|
+
|
|
1297
1302
|
const decodeStopTask = decodeParams(
|
|
1298
1303
|
AgentTools.tools.stopTask.parametersSchema,
|
|
1299
|
-
'stopTask requires a task id, for example: stopTask("
|
|
1304
|
+
'stopTask requires a task id, for example: stopTask("bash_1").',
|
|
1300
1305
|
)
|
|
1301
1306
|
|
|
1302
1307
|
interface RunningCommand {
|