clanka 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +2 -3
  2. package/dist/Acp.test.js +2 -3
  3. package/dist/Acp.test.js.map +1 -1
  4. package/dist/AcpImage.test.js +0 -1
  5. package/dist/AcpImage.test.js.map +1 -1
  6. package/dist/Agent.d.ts.map +1 -1
  7. package/dist/Agent.js +7 -7
  8. package/dist/Agent.js.map +1 -1
  9. package/dist/Agent.test.js +7 -7
  10. package/dist/Agent.test.js.map +1 -1
  11. package/dist/AgentBashJobs.test.js +7 -7
  12. package/dist/AgentBashJobs.test.js.map +1 -1
  13. package/dist/AgentCallerConfig.test.js +0 -1
  14. package/dist/AgentCallerConfig.test.js.map +1 -1
  15. package/dist/AgentExecutor.d.ts +2 -3
  16. package/dist/AgentExecutor.d.ts.map +1 -1
  17. package/dist/AgentExecutor.js +4 -13
  18. package/dist/AgentExecutor.js.map +1 -1
  19. package/dist/AgentExecutor.test.js +20 -20
  20. package/dist/AgentExecutor.test.js.map +1 -1
  21. package/dist/AgentImage.test.js +1 -2
  22. package/dist/AgentImage.test.js.map +1 -1
  23. package/dist/AgentSkills.test.js +0 -2
  24. package/dist/AgentSkills.test.js.map +1 -1
  25. package/dist/AgentSubagents.test.js +57 -29
  26. package/dist/AgentSubagents.test.js.map +1 -1
  27. package/dist/AgentTools.d.ts +6 -238
  28. package/dist/AgentTools.d.ts.map +1 -1
  29. package/dist/AgentTools.js +11 -39
  30. package/dist/AgentTools.js.map +1 -1
  31. package/dist/ClaudeAgent.test.js +0 -1
  32. package/dist/ClaudeAgent.test.js.map +1 -1
  33. package/dist/ScriptFormatting.d.ts +5 -0
  34. package/dist/ScriptFormatting.d.ts.map +1 -1
  35. package/dist/ScriptFormatting.js +255 -53
  36. package/dist/ScriptFormatting.js.map +1 -1
  37. package/dist/ScriptFormatting.test.js +16 -0
  38. package/dist/ScriptFormatting.test.js.map +1 -1
  39. package/dist/bin/{Latch-DOdbsGMQ.mjs → Latch-BE6_TYRL.mjs} +1 -1
  40. package/dist/bin/{McpClient-B-FFG6Pg.mjs → McpClient-DCt4v5W5.mjs} +2 -2
  41. package/dist/bin/{OutputFormatter-DhhP2i-7.mjs → OutputFormatter-DaFv_C_I.mjs} +2 -3
  42. package/dist/bin/{Schema-CFdSO6iH.mjs → Schema-B3MiG1aD.mjs} +204 -568
  43. package/dist/bin/cli.mjs +5106 -2479
  44. package/dist/bin/{upgrade-C4aOEWJH.mjs → upgrade-WqgIU_21.mjs} +3 -3
  45. package/dist/cli.js +2 -25
  46. package/dist/cli.js.map +1 -1
  47. package/dist/index.d.ts +0 -8
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +0 -8
  50. package/dist/index.js.map +1 -1
  51. package/package.json +1 -7
  52. package/src/Acp.test.ts +2 -3
  53. package/src/AcpImage.test.ts +0 -1
  54. package/src/Agent.test.ts +10 -7
  55. package/src/Agent.ts +8 -10
  56. package/src/AgentBashJobs.test.ts +9 -9
  57. package/src/AgentCallerConfig.test.ts +0 -1
  58. package/src/AgentExecutor.test.ts +20 -20
  59. package/src/AgentExecutor.ts +4 -16
  60. package/src/AgentImage.test.ts +1 -2
  61. package/src/AgentSkills.test.ts +0 -2
  62. package/src/AgentSubagents.test.ts +77 -34
  63. package/src/AgentTools.ts +19 -51
  64. package/src/ClaudeAgent.test.ts +0 -1
  65. package/src/ScriptFormatting.test.ts +20 -0
  66. package/src/ScriptFormatting.ts +234 -47
  67. package/src/cli.ts +1 -56
  68. package/src/index.ts +0 -10
  69. package/dist/ChunkRepo.d.ts +0 -173
  70. package/dist/ChunkRepo.d.ts.map +0 -1
  71. package/dist/ChunkRepo.js +0 -168
  72. package/dist/ChunkRepo.js.map +0 -1
  73. package/dist/ChunkRepo.test.d.ts +0 -2
  74. package/dist/ChunkRepo.test.d.ts.map +0 -1
  75. package/dist/ChunkRepo.test.js +0 -63
  76. package/dist/ChunkRepo.test.js.map +0 -1
  77. package/dist/CodeChunker.d.ts +0 -84
  78. package/dist/CodeChunker.d.ts.map +0 -1
  79. package/dist/CodeChunker.js +0 -658
  80. package/dist/CodeChunker.js.map +0 -1
  81. package/dist/CodeChunker.test.d.ts +0 -2
  82. package/dist/CodeChunker.test.d.ts.map +0 -1
  83. package/dist/CodeChunker.test.js +0 -434
  84. package/dist/CodeChunker.test.js.map +0 -1
  85. package/dist/SemanticSearch/Service.d.ts +0 -31
  86. package/dist/SemanticSearch/Service.d.ts.map +0 -1
  87. package/dist/SemanticSearch/Service.js +0 -29
  88. package/dist/SemanticSearch/Service.js.map +0 -1
  89. package/dist/SemanticSearch.d.ts +0 -34
  90. package/dist/SemanticSearch.d.ts.map +0 -1
  91. package/dist/SemanticSearch.js +0 -171
  92. package/dist/SemanticSearch.js.map +0 -1
  93. package/dist/SemanticSearch.test.d.ts +0 -2
  94. package/dist/SemanticSearch.test.d.ts.map +0 -1
  95. package/dist/SemanticSearch.test.js +0 -34
  96. package/dist/SemanticSearch.test.js.map +0 -1
  97. package/dist/Sqlite.d.ts +0 -15
  98. package/dist/Sqlite.d.ts.map +0 -1
  99. package/dist/Sqlite.js +0 -44
  100. package/dist/Sqlite.js.map +0 -1
  101. package/dist/bin/AiError-DBaKz35C.mjs +0 -2723
  102. package/dist/bin/SemanticSearch-C3a7LAQr.mjs +0 -2558
  103. package/src/ChunkRepo.test.ts +0 -89
  104. package/src/ChunkRepo.ts +0 -260
  105. package/src/CodeChunker.test.ts +0 -493
  106. package/src/CodeChunker.ts +0 -1018
  107. package/src/SemanticSearch/Service.ts +0 -50
  108. package/src/SemanticSearch.test.ts +0 -51
  109. package/src/SemanticSearch.ts +0 -282
  110. package/src/Sqlite.ts +0 -60
@@ -13,7 +13,6 @@ import {
13
13
  agentTasksUnavailable,
14
14
  AgentToolHandlers,
15
15
  AgentTools,
16
- AgentToolsWithSearch,
17
16
  CommandLimits,
18
17
  CurrentDirectory,
19
18
  defaultBashTimeout,
@@ -61,7 +60,6 @@ import * as RpcGroup from "effect/rpc/RpcGroup"
61
60
  import * as Rpc from "effect/rpc/Rpc"
62
61
  import * as Predicate from "effect/Predicate"
63
62
  import * as Result from "effect/Result"
64
- import { SemanticSearch } from "./SemanticSearch/Service.ts"
65
63
  import { preprocessScript } from "./ScriptPreprocessing.ts"
66
64
  import * as References from "effect/References"
67
65
 
@@ -239,7 +237,6 @@ export class Capabilities extends Schema.Class<Capabilities>("Capabilities")({
239
237
  * The startup AGENTS.md as rendered for the system prompt, with its path.
240
238
  */
241
239
  instructions: Schema.Option(Schema.String),
242
- supportsSearch: Schema.Boolean,
243
240
  /**
244
241
  * The environment of an agent's first script.
245
242
  */
@@ -326,7 +323,7 @@ type LocalServices<Toolkit> =
326
323
  | ToolkitRenderer
327
324
  | FileSystem.FileSystem
328
325
  | Path.Path
329
- | Tool.HandlersFor<typeof AgentToolsWithSearch.tools>
326
+ | Tool.HandlersFor<typeof AgentTools.tools>
330
327
  | Exclude<
331
328
  Toolkit extends Toolkit.Toolkit<infer T>
332
329
  ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]>
@@ -405,18 +402,16 @@ const makeLocalWith = Effect.fnUntraced(function* <
405
402
  )
406
403
  const excluded = excludedToolNames(options.excludeTools)
407
404
  const offersFetch = !excluded.has("fetch")
408
- const search = yield* Effect.serviceOption(SemanticSearch)
409
405
  const BuiltInTools = Toolkit.make(
410
406
  ...Object.values(
411
407
  Toolkit.merge(
412
- Option.isSome(search) ? AgentToolsWithSearch : AgentTools,
408
+ AgentTools,
413
409
  // Same tool id, so the handler is unchanged. Only the description,
414
410
  // which states the timeout, differs.
415
411
  Toolkit.make(makeBashTool(commandLimits.timeout ?? defaultBashTimeout)),
416
412
  ).tools as Record<string, Tool.Any>,
417
413
  ).filter((tool) => !excluded.has(tool.name)),
418
- ) as unknown as typeof AgentToolsWithSearch
419
- const hasSearch = "search" in BuiltInTools.tools
414
+ ) as unknown as typeof AgentTools
420
415
  const AllTools = Toolkit.merge(
421
416
  BuiltInTools,
422
417
  (options.tools as unknown as Toolkit.Toolkit<{}>) ?? Toolkit.empty,
@@ -541,9 +536,6 @@ const makeLocalWith = Effect.fnUntraced(function* <
541
536
  Context.add(CommandLimits, commandLimits),
542
537
  Context.add(Console.Console, console),
543
538
  Context.add(References.CurrentLogAnnotations, {}),
544
- Option.isSome(search)
545
- ? Context.add(SemanticSearch, search.value)
546
- : identity,
547
539
  )
548
540
 
549
541
  // The script runs in its own worker thread, so a script that is busy in
@@ -689,7 +681,6 @@ const makeLocalWith = Effect.fnUntraced(function* <
689
681
  Option.fromNullishOr(startup.instructions.at(-1)),
690
682
  AgentEnvironment.renderInstructions,
691
683
  ),
692
- supportsSearch: hasSearch,
693
684
  environment: new ExecutionEnvironment({
694
685
  cwd: startupDirectory,
695
686
  baseline: [
@@ -730,9 +721,6 @@ const makeLocalWith = Effect.fnUntraced(function* <
730
721
  Context.add(ImageAttacher, () => Effect.void),
731
722
  Context.add(CommandLimits, commandLimits),
732
723
  Context.add(References.CurrentLogAnnotations, {}),
733
- Option.isSome(search)
734
- ? Context.add(SemanticSearch, search.value)
735
- : identity,
736
724
  )
737
725
 
738
726
  const encodeSuccess = Schema.encodeUnknownEffect(
@@ -1351,7 +1339,7 @@ const withBuiltInHandlers = <A, E, R>(
1351
1339
  ): Effect.Effect<
1352
1340
  A,
1353
1341
  E,
1354
- | Exclude<R, Tool.HandlersFor<typeof AgentToolsWithSearch.tools>>
1342
+ | Exclude<R, Tool.HandlersFor<typeof AgentTools.tools>>
1355
1343
  | Scope.Scope
1356
1344
  | FileSystem.FileSystem
1357
1345
  | Path.Path
@@ -23,7 +23,6 @@ const capabilities = new AgentExecutor.Capabilities({
23
23
  seen: [],
24
24
  }),
25
25
  instructions: Option.none(),
26
- supportsSearch: false,
27
26
  tools: [],
28
27
  skills: [],
29
28
  })
@@ -273,7 +272,7 @@ describe("Agent images", () => {
273
272
  const executor = makeExecutor(({ agentTasks, environment }) =>
274
273
  Stream.fromEffect(
275
274
  agentTasks.subagent({
276
- id: "1",
275
+ id: "subagent_1",
277
276
  prompt: "child task: describe the layout",
278
277
  background: false,
279
278
  environment: new AgentExecutor.EnvironmentUpdate({
@@ -529,7 +529,6 @@ describe("AgentSkills", () => {
529
529
  seen: [],
530
530
  }),
531
531
  instructions: Option.none(),
532
- supportsSearch: false,
533
532
  tools: [],
534
533
  })
535
534
  assert.deepStrictEqual(capabilities.skills, [])
@@ -879,7 +878,6 @@ const makeExecutor = (skills: ReadonlyArray<AgentSkills.Skill>) =>
879
878
  seen: [],
880
879
  }),
881
880
  instructions: Option.none(),
882
- supportsSearch: false,
883
881
  tools: [],
884
882
  skills,
885
883
  }),
@@ -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
@@ -28,7 +28,6 @@ import * as Array from "effect/Array"
28
28
  import * as Data from "effect/Data"
29
29
  import * as Layer from "effect/Layer"
30
30
  import * as Option from "effect/Option"
31
- import * as SemanticSearch from "./SemanticSearch/Service.ts"
32
31
  import * as Image from "./Image.ts"
33
32
 
34
33
  /**
@@ -127,9 +126,10 @@ export type Task = typeof Task.Type
127
126
  */
128
127
  export interface AgentTasks {
129
128
  /**
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"`.
129
+ * Start a sub-agent under the id the executor allocated, of the form
130
+ * `subagent_<n>`. In the foreground it resolves once the agent has finished,
131
+ * and dies if the agent failed. In the background it resolves straight away
132
+ * with `status: "running"`.
133
133
  */
134
134
  readonly subagent: (options: {
135
135
  readonly id: string
@@ -537,24 +537,6 @@ export const AgentTools = Toolkit.make(
537
537
  }),
538
538
  )
539
539
 
540
- const SearchTool = Toolkit.make(
541
- Tool.make("search", {
542
- description:
543
- "Semantic code search - you just need to describe what you are looking for",
544
- parameters: Schema.String.annotate({
545
- identifier: "query",
546
- }),
547
- success: Schema.String,
548
- dependencies: [SemanticSearch.SemanticSearch],
549
- }),
550
- )
551
-
552
- /**
553
- * @since 1.0.0
554
- * @category Toolkit
555
- */
556
- export const AgentToolsWithSearch = Toolkit.merge(SearchTool, AgentTools)
557
-
558
540
  /**
559
541
  * A built-in tool a caller can leave out. `taskComplete` always stays.
560
542
  *
@@ -562,13 +544,13 @@ export const AgentToolsWithSearch = Toolkit.merge(SearchTool, AgentTools)
562
544
  * @category Toolkit
563
545
  */
564
546
  export type ExcludableTool =
565
- Exclude<keyof typeof AgentToolsWithSearch.tools, "taskComplete"> | "fetch"
547
+ Exclude<keyof typeof AgentTools.tools, "taskComplete"> | "fetch"
566
548
 
567
549
  /**
568
550
  * @since 1.0.0
569
551
  * @category Toolkit
570
552
  */
571
- export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
553
+ export const AgentToolHandlersNoDeps = AgentTools.toLayer(
572
554
  Effect.gen(function* () {
573
555
  const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
574
556
  const fs = yield* FileSystem.FileSystem
@@ -629,7 +611,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
629
611
  const tasks = new Map<string, TaskEntry>()
630
612
  let nextTaskId = 1
631
613
  const registerAgentTask = Effect.gen(function* () {
632
- const id = String(nextTaskId++)
614
+ const id = `subagent_${nextTaskId++}`
633
615
  tasks.set(id, { kind: "agent", id, owner: yield* TaskOwner })
634
616
  return id
635
617
  })
@@ -642,7 +624,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
642
624
  ) {
643
625
  const entry: BashEntry = {
644
626
  kind: "bash",
645
- id: String(nextTaskId++),
627
+ id: `bash_${nextTaskId++}`,
646
628
  owner: yield* TaskOwner,
647
629
  description,
648
630
  command: { ...command, reported: false },
@@ -767,7 +749,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
767
749
  return options.background === true ? task : backgroundRunningOutput(task)
768
750
  }, Effect.orDie)
769
751
 
770
- return AgentToolsWithSearch.of({
752
+ return AgentTools.of({
771
753
  changeDirectory: Effect.fn("AgentTools.changeDirectory")(
772
754
  function* (directory) {
773
755
  yield* Effect.logInfo(`Calling "changeDirectory"`).pipe(
@@ -839,7 +821,6 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
839
821
  yield* typeof options.content === "string"
840
822
  ? fs.writeFileString(path, options.content)
841
823
  : fs.writeFile(path, options.content)
842
- yield* SemanticSearch.maybeUpdateFile(path)
843
824
  }, Effect.orDie),
844
825
  removeFile: Effect.fn("AgentTools.removeFile")(function* (path) {
845
826
  yield* Effect.logInfo(`Calling "removeFile"`).pipe(
@@ -848,7 +829,6 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
848
829
  const cwd = yield* CurrentDirectory
849
830
  const absolutePath = pathService.resolve(cwd, path)
850
831
  yield* fs.remove(absolutePath, { force: true })
851
- yield* SemanticSearch.maybeRemoveFile(absolutePath)
852
832
  }, Effect.orDie),
853
833
  renameFile: Effect.fn("AgentTools.renameFile")(function* (options) {
854
834
  yield* Effect.logInfo(`Calling "renameFile"`).pipe(
@@ -861,8 +841,6 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
861
841
  recursive: true,
862
842
  })
863
843
  yield* fs.rename(from, to)
864
- yield* SemanticSearch.maybeRemoveFile(from)
865
- yield* SemanticSearch.maybeUpdateFile(to)
866
844
  }, Effect.orDie),
867
845
  ls: Effect.fn("AgentTools.ls")(function* (directory) {
868
846
  yield* Effect.logInfo(`Calling "ls"`).pipe(
@@ -873,16 +851,6 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
873
851
  .readDirectory(pathService.resolve(cwd, directory))
874
852
  .pipe(Effect.orDie)
875
853
  }),
876
- search: Effect.fn("AgentTools.search")(function* (query) {
877
- yield* Effect.logInfo(`Calling "search"`).pipe(
878
- Effect.annotateLogs({ query }),
879
- )
880
- const ss = yield* SemanticSearch.SemanticSearch
881
- return yield* ss.search({
882
- query,
883
- limit: 5,
884
- })
885
- }),
886
854
  rg: Effect.fn("AgentTools.rg")(function* (options) {
887
855
  yield* Effect.logInfo(`Calling "rg"`).pipe(Effect.annotateLogs(options))
888
856
  const cwd = yield* CurrentDirectory
@@ -1014,7 +982,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
1014
982
  )
1015
983
  const agentTasks = yield* AgentTaskExecutor
1016
984
  return [...bashTasks, ...(yield* agentTasks.listTasks)].toSorted(
1017
- (a, b) => Number(a.id) - Number(b.id),
985
+ (a, b) => taskNumber(a.id) - taskNumber(b.id),
1018
986
  )
1019
987
  }),
1020
988
  gh: Effect.fn("AgentTools.gh")(function* (args) {
@@ -1175,7 +1143,6 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
1175
1143
  recursive: true,
1176
1144
  })
1177
1145
  yield* fs.writeFileString(step.path, step.next)
1178
- yield* SemanticSearch.maybeUpdateFile(step.path)
1179
1146
  break
1180
1147
  }
1181
1148
  case "move": {
@@ -1184,13 +1151,10 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
1184
1151
  })
1185
1152
  yield* fs.writeFileString(step.movePath, step.next)
1186
1153
  yield* fs.remove(step.path)
1187
- yield* SemanticSearch.maybeRemoveFile(step.path)
1188
- yield* SemanticSearch.maybeUpdateFile(step.movePath)
1189
1154
  break
1190
1155
  }
1191
1156
  case "delete": {
1192
1157
  yield* fs.remove(step.path)
1193
- yield* SemanticSearch.maybeRemoveFile(step.path)
1194
1158
  break
1195
1159
  }
1196
1160
  }
@@ -1243,7 +1207,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
1243
1207
  * @category Layers
1244
1208
  */
1245
1209
  export const AgentToolHandlers: Layer.Layer<
1246
- Tool.HandlersFor<typeof AgentToolsWithSearch.tools>,
1210
+ Tool.HandlersFor<typeof AgentTools.tools>,
1247
1211
  never,
1248
1212
  | FileSystem.FileSystem
1249
1213
  | Path.Path
@@ -1280,23 +1244,27 @@ const decodeSubagent = decodeParams(
1280
1244
  )
1281
1245
  const decodeMessageAgent = decodeParams(
1282
1246
  AgentTools.tools.messageAgent.parametersSchema,
1283
- 'messageAgent requires an options object, for example: messageAgent({ id: "3", message: "..." }).',
1247
+ 'messageAgent requires an options object, for example: messageAgent({ id: "subagent_3", message: "..." }).',
1284
1248
  )
1285
1249
  const decodeTaskOutput = decodeParams(
1286
1250
  AgentTools.tools.taskOutput.parametersSchema,
1287
- 'taskOutput requires a task id, for example: taskOutput("1").',
1251
+ 'taskOutput requires a task id, for example: taskOutput("bash_1").',
1288
1252
  )
1289
1253
  const decodeWaitTasks = decodeParams(
1290
1254
  AgentTools.tools.waitTasks.parametersSchema,
1291
- 'waitTasks requires an options object, for example: waitTasks({ ids: ["3", "4"] }) or waitTasks({ ids: ["3"], timeoutMs: 60000 }).',
1255
+ 'waitTasks requires an options object, for example: waitTasks({ ids: ["subagent_3", "bash_4"] }) or waitTasks({ ids: ["subagent_3"], timeoutMs: 60000 }).',
1292
1256
  )
1293
1257
 
1294
1258
  /** The caller's `bash` timeout, which also bounds `waitTasks`. */
1295
1259
  const bashTimeoutMs = (limits: typeof CommandLimits.Service) =>
1296
1260
  Duration.toMillis(limits.timeout ?? defaultBashTimeout)
1261
+
1262
+ /** The counter in a task id such as `bash_3`, which orders tasks by creation. */
1263
+ const taskNumber = (id: string) => Number(id.slice(id.indexOf("_") + 1))
1264
+
1297
1265
  const decodeStopTask = decodeParams(
1298
1266
  AgentTools.tools.stopTask.parametersSchema,
1299
- 'stopTask requires a task id, for example: stopTask("1").',
1267
+ 'stopTask requires a task id, for example: stopTask("bash_1").',
1300
1268
  )
1301
1269
 
1302
1270
  interface RunningCommand {
@@ -808,7 +808,6 @@ describe("ClaudeAgent.model", () => {
808
808
  seen: [],
809
809
  }),
810
810
  instructions: Option.none(),
811
- supportsSearch: false,
812
811
  tools: [],
813
812
  skills: [],
814
813
  }),
@@ -42,6 +42,14 @@ describe("formatScript", () => {
42
42
  expect(formatScript(output)).toBe(output)
43
43
  })
44
44
 
45
+ it("breaks statement blocks but not the expressions around them", () => {
46
+ const input = "const a=b/2;if(a){x()}else{y()}run(function(){go();});"
47
+ const output =
48
+ "const a=b/2;\nif(a){\nx()\n}else{\ny()\n}\nrun(function(){\ngo();\n});"
49
+ expect(formatScript(input)).toBe(output)
50
+ expect(formatScript(output)).toBe(output)
51
+ })
52
+
45
53
  it("preserves literals, comments, and line-sensitive expressions", () => {
46
54
  const input = [
47
55
  `const text="😀;{}";const re=/[;{}]/g;`,
@@ -56,10 +64,22 @@ describe("formatScript", () => {
56
64
  expect(output).toContain("// comment ;{}\n")
57
65
  expect(output).toContain("/* comment ;{} */")
58
66
  expect(output).toContain("return {value: 1};")
67
+ expect(formatScript("n=a.in/2;re=/x;y/;")).toBe("n=a.in/2;\nre=/x;y/;")
68
+ // A slash after ")" may start a regex or divide, so nothing is changed.
69
+ for (const input of [
70
+ "if (a) /x;y/.test(s);n=1;",
71
+ "for await (const x of []) /x;y/.test(s);n=1;",
72
+ "n=obj.with()/2;re=/x;y/;",
73
+ ]) {
74
+ expect(formatScript(input)).toBe(input)
75
+ }
59
76
  })
60
77
 
61
78
  it("leaves incomplete scripts and existing whitespace alone", () => {
62
79
  expect(formatScript("const x = {;")).toBe("const x = {;")
80
+ expect(formatScript("const x=1; /* unfinished")).toBe(
81
+ "const x=1; /* unfinished",
82
+ )
63
83
  const input = "if (true) {\r\n console.log(1);\r\n}\r\n"
64
84
  expect(formatScript(input)).toBe(input)
65
85
  })