clanka 0.26.0 → 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.
@@ -579,7 +579,7 @@ await sleep(60000)`,
579
579
  )
580
580
  assert.strictEqual(
581
581
  JSON.parse(output.split("OUTPUT:")[1]!),
582
- 'Task "1" is still running in the background',
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: "1",
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: "1",
647
+ id: "bash_1",
648
648
  kind: "bash",
649
649
  status: "running",
650
650
  description: command,
651
- output: 'Task "1" is still running in the background',
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("1")).output)`,
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: "1",
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":"1","kind":"bash","status":"completed","exitCode":0,"output":"done\\n"}',
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 "1" is still running in the background'),
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":"2","kind":"bash","status":"running"}',
801
+ 'RETURNED: {"id":"bash_2","kind":"bash","status":"running"}',
802
802
  )
803
- assert.deepStrictEqual(watched, ["2"], "only the running task")
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("1")))
825
+ console.log("RUNNING:", show(await taskOutput("bash_1")))
826
826
  await writeFile({ path: "gate", content: "" })
827
- console.log("COMPLETED:", show(await done("1")))
828
- console.log("FAILED:", show(await done("2")))`)
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":"1","kind":"bash","status":"running","output":""}',
831
+ 'RUNNING: {"id":"bash_1","kind":"bash","status":"running","output":""}',
832
832
  )
833
833
  assert.include(
834
834
  output,
835
- 'COMPLETED: {"id":"1","kind":"bash","status":"completed","exitCode":0,"output":""}',
835
+ 'COMPLETED: {"id":"bash_1","kind":"bash","status":"completed","exitCode":0,"output":""}',
836
836
  )
837
837
  assert.include(
838
838
  output,
839
- 'FAILED: {"id":"2","kind":"bash","status":"failed","exitCode":3,"output":"out\\n"}',
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: "1", message: "hello" })
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("1")) === undefined)
857
- console.log("STOPPED:", show(await taskOutput("1")))
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":"1","kind":"bash","status":"stopped"}',
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\(\)/)
@@ -273,7 +273,7 @@ describe("Agent images", () => {
273
273
  const executor = makeExecutor(({ agentTasks, environment }) =>
274
274
  Stream.fromEffect(
275
275
  agentTasks.subagent({
276
- id: "1",
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 "1".
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("1")).output)`,
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":"1"')
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, "1", "completed")
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("1")')
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) => findPush(call.prompt, "1", "completed").index !== -1,
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, "1", "completed")
407
- assert.include(push.text, 'taskOutput("1")')
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, "1", "failed")
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("1")')
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: ["1"] })',
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: ["1"] })
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":"1"')
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("1")) === undefined)
612
- console.log(JSON.stringify(await taskOutput("1")))`,
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":"1"')
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: "1", message: "STEER" })) === undefined)`,
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: "1", message: "FOLLOW-UP" })
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(call.prompt, "2", "completed").text.includes(
752
- 'taskOutput("2")',
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":"1"')
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, "2"),
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 bashTask = await bash({ command: "echo BASH-OUT", background: true })
873
- const agentTask = await subagent({ prompt: "TASK-CHILD", background: true })
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
- { kind: "bash", status: "completed", output: "BASH-OUT" },
893
- { kind: "agent", status: "completed", output: "CHILD-OUT" },
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 "1" is still running in the background',
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, "1", "completed").text,
1024
- 'taskOutput("1")',
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="1" kind="bash" status="completed" exitCode="0">\s*To read the output, call taskOutput\("1"\)\.\s*<\/task>$/.test(
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, "2", "completed").text,
1074
- 'taskOutput("2")',
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. In the foreground
131
- * it resolves once the agent has finished, and dies if the agent failed.
132
- * In the background it resolves straight away with `status: "running"`.
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 = String(nextTaskId++)
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: String(nextTaskId++),
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) => Number(a.id) - Number(b.id),
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: "3", message: "..." }).',
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("1").',
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: ["3", "4"] }) or waitTasks({ ids: ["3"], timeoutMs: 60000 }).',
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("1").',
1304
+ 'stopTask requires a task id, for example: stopTask("bash_1").',
1300
1305
  )
1301
1306
 
1302
1307
  interface RunningCommand {