clanka 0.22.6 → 0.23.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "clanka",
3
3
  "type": "module",
4
- "version": "0.22.6",
4
+ "version": "0.23.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
package/src/Acp.test.ts CHANGED
@@ -646,7 +646,7 @@ describe("Acp", () => {
646
646
  ),
647
647
  )
648
648
 
649
- it.effect("reports subagents with a delegate prompt preview", () =>
649
+ it.effect("reports subagents with a subagent prompt preview", () =>
650
650
  withStore(
651
651
  Effect.scoped(
652
652
  Effect.gen(function* () {
@@ -661,14 +661,14 @@ describe("Acp", () => {
661
661
  type: "tool-call",
662
662
  id: "call-1",
663
663
  name: "execute",
664
- params: { script: "await delegate()" },
664
+ params: { script: "await subagent()" },
665
665
  })
666
666
  : assistantSays(summary),
667
667
  {
668
668
  ...executor,
669
669
  execute: ({ agentTasks, environment }) =>
670
670
  Stream.fromEffect(
671
- agentTasks.delegate({
671
+ agentTasks.subagent({
672
672
  id: "1",
673
673
  prompt,
674
674
  background: false,
@@ -706,13 +706,13 @@ describe("Acp", () => {
706
706
  assert.strictEqual(tools[1].sessionUpdate, "tool_call_update")
707
707
  assert.strictEqual(tools[1].toolCallId, tools[0].toolCallId)
708
708
  assert.strictEqual(tools[1].status, "completed")
709
- assert.match(tools[0].title, /^delegate: Inspect the repository/)
709
+ assert.match(tools[0].title, /^subagent: Inspect the repository/)
710
710
  assert.notMatch(tools[0].title, /[\r\n]/)
711
711
  assert.strictEqual(
712
712
  tools[0].title,
713
- "delegate: " + prompt.replace(/\s+/g, " ").slice(0, 120),
713
+ "subagent: " + prompt.replace(/\s+/g, " ").slice(0, 120),
714
714
  )
715
- assert.strictEqual(tools[0].title.length, "delegate: ".length + 120)
715
+ assert.strictEqual(tools[0].title.length, "subagent: ".length + 120)
716
716
  assert.deepStrictEqual(tools[1].content, [
717
717
  { type: "content", content: { type: "text", text: summary } },
718
718
  ])
@@ -763,7 +763,7 @@ describe("Acp", () => {
763
763
  Stream.fromEffect(
764
764
  executions++ === 0
765
765
  ? agentTasks
766
- .delegate({
766
+ .subagent({
767
767
  id: "1",
768
768
  prompt: "TASK-CHILD",
769
769
  background: true,
package/src/Acp.ts CHANGED
@@ -934,7 +934,7 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
934
934
  return update(session.id, {
935
935
  sessionUpdate: announced ? "tool_call_update" : "tool_call",
936
936
  toolCallId: `subagent-${part.id}`,
937
- title: `delegate: ${part.prompt.replace(/\s+/g, " ").trim().slice(0, 120)}`,
937
+ title: `subagent: ${part.prompt.replace(/\s+/g, " ").trim().slice(0, 120)}`,
938
938
  kind: "think",
939
939
  status: "in_progress",
940
940
  rawInput: { prompt: part.prompt },
package/src/Agent.test.ts CHANGED
@@ -180,7 +180,7 @@ describe("Agent", () => {
180
180
  Stream.fromEffect(
181
181
  (script === "done"
182
182
  ? onTaskComplete("done")
183
- : agentTasks.delegate({
183
+ : agentTasks.subagent({
184
184
  id: "1",
185
185
  prompt: "TASK-CHILD",
186
186
  background: false,
package/src/Agent.ts CHANGED
@@ -620,7 +620,7 @@ export const makeWith = Effect.fnUntraced(function* <
620
620
  })
621
621
 
622
622
  const agentTasks: AgentExecutor.ExecuteAgentTasks = {
623
- delegate: Effect.fnUntraced(function* ({
623
+ subagent: Effect.fnUntraced(function* ({
624
624
  id,
625
625
  prompt,
626
626
  background,
@@ -640,7 +640,7 @@ export const makeWith = Effect.fnUntraced(function* <
640
640
  yield* startTurn({
641
641
  child,
642
642
  label: prompt,
643
- prompt: `You have been asked using the "delegate" function to complete the following task. Try to avoid using the "delegate" function yourself unless strictly necessary:
643
+ prompt: `You have been asked using the "subagent" function to complete the following task. Try to avoid using the "subagent" function yourself unless strictly necessary:
644
644
 
645
645
  ${prompt}`,
646
646
  // The update goes into the child's first prompt.
@@ -1745,8 +1745,8 @@ const when = (condition: boolean, text: string) => (condition ? text : "")
1745
1745
  // model. Only offered functions are named.
1746
1746
  const taskInstructions = (tools: PromptTools): string => {
1747
1747
  const bash = tools.offers("bash")
1748
- const delegate = tools.offers("delegate")
1749
- if (!bash && !delegate) return ""
1748
+ const subagent = tools.offers("subagent")
1749
+ if (!bash && !subagent) return ""
1750
1750
  const functions = (
1751
1751
  [
1752
1752
  ["taskOutput", `"taskOutput" reads one`],
@@ -1761,7 +1761,7 @@ const taskInstructions = (tools: PromptTools): string => {
1761
1761
  .filter(([name]) => tools.offers(name))
1762
1762
  .map(([, text]) => text)
1763
1763
  const kinds =
1764
- bash && delegate
1764
+ bash && subagent
1765
1765
  ? "Background commands and sub-agents are"
1766
1766
  : bash
1767
1767
  ? "Background commands are"
@@ -1805,7 +1805,7 @@ const generateSystemTools = (
1805
1805
 
1806
1806
  When you have fully completed your task, call the "taskComplete" function with the final output.
1807
1807
  Make sure every detail of the task is done before calling "taskComplete".${when(
1808
- tools.offers("delegate"),
1808
+ tools.offers("subagent"),
1809
1809
  `
1810
1810
  Any sub-agents you started must finish first: "taskComplete" fails while they are running.`,
1811
1811
  )}`,
@@ -260,9 +260,9 @@ await taskComplete(result)`,
260
260
  const { system, summary } = yield* runAgent({
261
261
  mode,
262
262
  executor: {
263
- excludeTools: ["gh", "webSearch", "fetchMarkdown", "delegate"],
263
+ excludeTools: ["gh", "webSearch", "fetchMarkdown", "subagent"],
264
264
  },
265
- script: `const missing = [typeof gh, typeof webSearch, typeof fetchMarkdown, typeof delegate, typeof messageAgent].join(",")
265
+ script: `const missing = [typeof gh, typeof webSearch, typeof fetchMarkdown, typeof subagent, typeof messageAgent].join(",")
266
266
  let call
267
267
  try {
268
268
  await gh(["pr", "view"])
@@ -278,7 +278,7 @@ await taskComplete(missing + " " + call)`,
278
278
  )
279
279
  assert.notMatch(
280
280
  system,
281
- /\b(gh|webSearch|fetchMarkdown|delegate|messageAgent)\b/,
281
+ /\b(gh|webSearch|fetchMarkdown|subagent|messageAgent)\b/,
282
282
  )
283
283
  assert.include(system, "declare function readFile(")
284
284
  }),
@@ -286,13 +286,13 @@ await taskComplete(missing + " " + call)`,
286
286
 
287
287
  // The shared task functions address bash and agent tasks, so they stay
288
288
  // while either kind can still be started.
289
- it.live("the task functions go only when bash and delegate both go", () =>
289
+ it.live("the task functions go only when bash and subagent both go", () =>
290
290
  Effect.gen(function* () {
291
291
  const tasks =
292
292
  "[typeof taskOutput, typeof waitTasks, typeof stopTask, typeof listTasks].join()"
293
293
  const withBash = yield* runAgent({
294
294
  mode,
295
- executor: { excludeTools: ["delegate"] },
295
+ executor: { excludeTools: ["subagent"] },
296
296
  script: `await taskComplete(${tasks})`,
297
297
  })
298
298
  assert.strictEqual(
@@ -301,7 +301,7 @@ await taskComplete(missing + " " + call)`,
301
301
  )
302
302
  const withNeither = yield* runAgent({
303
303
  mode,
304
- executor: { excludeTools: ["bash", "delegate"] },
304
+ executor: { excludeTools: ["bash", "subagent"] },
305
305
  script: `await taskComplete(${tasks})`,
306
306
  })
307
307
  assert.strictEqual(
@@ -458,17 +458,21 @@ describe("rpc executor", () => {
458
458
  describe("agent", () => {
459
459
  it.live("a left-out tool is not mentioned anywhere in the prompt", () =>
460
460
  Effect.gen(function* () {
461
- // Each is named outside its own declaration: the delegate bullet, the
461
+ // Each is named outside its own declaration: the subagent bullet, the
462
462
  // applyPatch hint and the executor's skills catalog.
463
463
  const { system, summary } = yield* runAgent({
464
464
  mode: "local",
465
465
  executor: { excludeTools: ["waitTasks", "applyPatch", "readFile"] },
466
466
  script:
467
- "await taskComplete([typeof waitTasks, typeof applyPatch, typeof readFile].join())",
467
+ "await taskComplete([typeof waitTasks, typeof applyPatch, typeof readFile, typeof subagent, typeof delegate].join())",
468
468
  })
469
- assert.strictEqual(summary, "undefined,undefined,undefined")
469
+ assert.strictEqual(
470
+ summary,
471
+ "undefined,undefined,undefined,function,undefined",
472
+ )
470
473
  assert.notMatch(system, /\b(waitTasks|applyPatch|readFile)\b/)
471
- assert.include(system, "declare function delegate(")
474
+ assert.include(system, "declare function subagent(")
475
+ assert.notInclude(system, "declare function delegate(")
472
476
  }),
473
477
  )
474
478
 
@@ -277,7 +277,7 @@ for (const [mode, executorLayer] of Object.entries(executors)) {
277
277
  return Stream.make(toolCall(`await changeDirectory("pkg")`))
278
278
  case 3:
279
279
  return Stream.make(
280
- toolCall(`await delegate({ prompt: "TASK-CHILD" })`),
280
+ toolCall(`await subagent({ prompt: "TASK-CHILD" })`),
281
281
  )
282
282
  default:
283
283
  return Stream.fromIterable(text("done"))
@@ -326,7 +326,7 @@ for (const [mode, executorLayer] of Object.entries(executors)) {
326
326
  assert.include(
327
327
  JSON.stringify(encodePrompt(child!.prompt)),
328
328
  "PKG-RULES",
329
- "a delegate started after the cd sees pkg's instructions",
329
+ "a subagent started after the cd sees pkg's instructions",
330
330
  )
331
331
  const childUpdates = outputs.flatMap((output) =>
332
332
  output._tag === "SubagentPart" &&
@@ -23,7 +23,7 @@ import * as NodePath from "node:path"
23
23
  import * as AgentExecutor from "./AgentExecutor.ts"
24
24
  import { agentTasksUnavailable, type Task } from "./AgentTools.ts"
25
25
 
26
- // The task a stub `delegate` resolves with once its agent has finished.
26
+ // The task a stub `subagent` resolves with once its agent has finished.
27
27
  const completedAgent = (id: string, prompt: string, output: string): Task => ({
28
28
  id,
29
29
  kind: "agent",
@@ -74,7 +74,7 @@ const withRpc = <A, E, R>(
74
74
  )
75
75
 
76
76
  describe("RPC subagent executor", () => {
77
- it.live("routes concurrent delegates to their originating scripts", () =>
77
+ it.live("routes concurrent subagents to their originating scripts", () =>
78
78
  withRpc((executor) =>
79
79
  Effect.gen(function* () {
80
80
  const { environment } = yield* executor.capabilities
@@ -87,12 +87,12 @@ describe("RPC subagent executor", () => {
87
87
  environment,
88
88
  onEnvironment: () => Effect.void,
89
89
  script:
90
- 'console.log("first:" + (await delegate({ prompt: "first" })).output)',
90
+ 'console.log("first:" + (await subagent({ prompt: "first" })).output)',
91
91
  onTaskComplete: () => Effect.void,
92
92
  onImage: () => Effect.void,
93
93
  agentTasks: {
94
94
  ...agentTasksUnavailable,
95
- delegate: ({ id, prompt }) =>
95
+ subagent: ({ id, prompt }) =>
96
96
  Effect.gen(function* () {
97
97
  assert.strictEqual(prompt, "first")
98
98
  yield* Deferred.succeed(firstStarted, undefined)
@@ -107,12 +107,12 @@ describe("RPC subagent executor", () => {
107
107
  environment,
108
108
  onEnvironment: () => Effect.void,
109
109
  script:
110
- 'console.log("second:" + (await delegate({ prompt: "second" })).output)',
110
+ 'console.log("second:" + (await subagent({ prompt: "second" })).output)',
111
111
  onTaskComplete: () => Effect.void,
112
112
  onImage: () => Effect.void,
113
113
  agentTasks: {
114
114
  ...agentTasksUnavailable,
115
- delegate: ({ id, prompt }) =>
115
+ subagent: ({ id, prompt }) =>
116
116
  Effect.gen(function* () {
117
117
  assert.strictEqual(prompt, "second")
118
118
  yield* Deferred.succeed(secondStarted, undefined)
@@ -142,12 +142,12 @@ describe("RPC subagent executor", () => {
142
142
  environment,
143
143
  onEnvironment: () => Effect.void,
144
144
  script:
145
- 'console.log("parent:" + (await delegate({ prompt: "outer" })).output)',
145
+ 'console.log("parent:" + (await subagent({ prompt: "outer" })).output)',
146
146
  onTaskComplete: () => Effect.void,
147
147
  onImage: () => Effect.void,
148
148
  agentTasks: {
149
149
  ...agentTasksUnavailable,
150
- delegate: ({ id, prompt }) =>
150
+ subagent: ({ id, prompt }) =>
151
151
  Effect.gen(function* () {
152
152
  assert.strictEqual(prompt, "outer")
153
153
  const childOutput = yield* executor
@@ -155,12 +155,12 @@ describe("RPC subagent executor", () => {
155
155
  environment,
156
156
  onEnvironment: () => Effect.void,
157
157
  script:
158
- 'console.log("child:" + (await delegate({ prompt: "inner" })).output)',
158
+ 'console.log("child:" + (await subagent({ prompt: "inner" })).output)',
159
159
  onTaskComplete: () => Effect.void,
160
160
  onImage: () => Effect.void,
161
161
  agentTasks: {
162
162
  ...agentTasksUnavailable,
163
- delegate: ({ id: innerId, prompt: innerPrompt }) =>
163
+ subagent: ({ id: innerId, prompt: innerPrompt }) =>
164
164
  Effect.sync(() => {
165
165
  assert.strictEqual(innerPrompt, "inner")
166
166
  return completedAgent(
@@ -994,15 +994,15 @@ console.log("MAIN" + "_DONE")`)
994
994
  .execute({
995
995
  environment,
996
996
  onEnvironment: () => Effect.void,
997
- // `delegate` never finishes. The worker then exits through
997
+ // `subagent` never finishes. The worker then exits through
998
998
  // the host's `process`, the way a crashed worker would.
999
999
  script: `
1000
- delegate({ prompt: "never finishes" })
1000
+ subagent({ prompt: "never finishes" })
1001
1001
  sleep(100).then(() => console.constructor.constructor("return process")().exit(7))`,
1002
1002
  onTaskComplete: () => Effect.void,
1003
1003
  agentTasks: {
1004
1004
  ...agentTasksUnavailable,
1005
- delegate: () => Effect.never,
1005
+ subagent: () => Effect.never,
1006
1006
  },
1007
1007
  onImage: () => Effect.void,
1008
1008
  })
@@ -1011,7 +1011,7 @@ sleep(100).then(() => console.constructor.constructor("return process")().exit(7
1011
1011
  }).pipe(Effect.timeout("3 seconds"), Effect.provide(executorLayer({}))),
1012
1012
  )
1013
1013
 
1014
- it.live("keeps the start and end of long bash output", () =>
1014
+ it.live("returns only the file notice for long bash output", () =>
1015
1015
  Effect.gen(function* () {
1016
1016
  const executor = yield* AgentExecutor.AgentExecutor
1017
1017
  const output = yield* executor.executeUnsafe({
@@ -1020,8 +1020,7 @@ sleep(100).then(() => console.constructor.constructor("return process")().exit(7
1020
1020
  })
1021
1021
  const { output: text } = output as { readonly output: string }
1022
1022
  assert.isBelow(text.length, 10_000 + 500)
1023
- assert.isTrue(text.startsWith("1\n2\n3\n"), "start kept")
1024
- assert.isTrue(text.trimEnd().endsWith("999999\n1000000"), "end kept")
1023
+ assert.match(text, /^Full output saved to: [^\n]+$/)
1025
1024
  }).pipe(
1026
1025
  Effect.timeout("10 seconds"),
1027
1026
  Effect.provide(executorLayer({ commandOutputChars: 10_000 })),
@@ -158,16 +158,16 @@ export interface ExecuteOptions {
158
158
  }
159
159
 
160
160
  /**
161
- * The sub-agents of the agent running a script. `delegate` also receives the
161
+ * The sub-agents of the agent running a script. `subagent` also receives the
162
162
  * environment the new agent starts in: the script's directory at the moment
163
- * `delegate` was called, with an update holding everything that applies to
163
+ * `subagent` was called, with an update holding everything that applies to
164
164
  * it beyond the system prompt.
165
165
  *
166
166
  * @since 1.0.0
167
167
  * @category Models
168
168
  */
169
- export interface ExecuteAgentTasks extends Omit<AgentTasks, "delegate"> {
170
- readonly delegate: (options: {
169
+ export interface ExecuteAgentTasks extends Omit<AgentTasks, "subagent"> {
170
+ readonly subagent: (options: {
171
171
  readonly id: string
172
172
  readonly prompt: string
173
173
  readonly background: boolean
@@ -293,10 +293,12 @@ export interface Limits {
293
293
  readonly scriptTimeout?: Duration.Input | undefined
294
294
  /**
295
295
  * The most characters of `bash` and `gh` output held in memory per command.
296
- * Longer output keeps its start and end, with a marker in place of the
297
- * middle.
296
+ * Bash output exceeding this limit is saved to a temporary file; only a
297
+ * message with the file path is returned. Files are removed when the
298
+ * executor closes. Longer gh output keeps its start and end, with a marker
299
+ * in place of the middle.
298
300
  *
299
- * Defaults to no limit.
301
+ * Defaults to 30,000 characters for bash and no limit for gh.
300
302
  */
301
303
  readonly commandOutputChars?: number | undefined
302
304
  }
@@ -313,8 +315,8 @@ export interface LocalOptions<Toolkit extends Toolkit.Any = never> {
313
315
  readonly limits?: Limits | undefined
314
316
  /**
315
317
  * Built-in tools to leave out of the sandbox and the type declarations.
316
- * Leaving out `delegate` also leaves out `messageAgent`, and leaving out
317
- * both `delegate` and `bash` leaves out the task functions.
318
+ * Leaving out `subagent` also leaves out `messageAgent`, and leaving out
319
+ * both `subagent` and `bash` leaves out the task functions.
318
320
  * Leaving out `fetch` removes the global Fetch API.
319
321
  */
320
322
  readonly excludeTools?: ReadonlyArray<ExcludableTool> | undefined
@@ -526,10 +528,10 @@ const makeLocalWith = Effect.fnUntraced(function* <
526
528
  ...opts.agentTasks,
527
529
  // A new agent has only the system prompt, so it gets everything that
528
530
  // applies to the directory.
529
- delegate: (options) =>
531
+ subagent: (options) =>
530
532
  renderEnvironment(currentEnvironment(), { reset: true }).pipe(
531
533
  Effect.flatMap((environment) =>
532
- opts.agentTasks.delegate({ ...options, environment }),
534
+ opts.agentTasks.subagent({ ...options, environment }),
533
535
  ),
534
536
  ),
535
537
  }),
@@ -992,10 +994,10 @@ export const layerRpcServer = <Toolkit extends Toolkit.Any = never>(
992
994
  request<void>({ _tag: "TaskComplete", summary }),
993
995
  agentId,
994
996
  agentTasks: {
995
- delegate: (options) =>
997
+ subagent: (options) =>
996
998
  Effect.orDie(
997
999
  request<Task>({
998
- _tag: "Delegate",
1000
+ _tag: "Subagent",
999
1001
  ...options,
1000
1002
  }),
1001
1003
  ),
@@ -1108,7 +1110,7 @@ export const layerRpcServer = <Toolkit extends Toolkit.Any = never>(
1108
1110
  */
1109
1111
  export const AgentRequest = Schema.TaggedUnion({
1110
1112
  TaskComplete: { summary: Schema.String },
1111
- Delegate: {
1113
+ Subagent: {
1112
1114
  id: Schema.String,
1113
1115
  prompt: Schema.String,
1114
1116
  background: Schema.Boolean,
@@ -1129,7 +1131,7 @@ export const AgentRequest = Schema.TaggedUnion({
1129
1131
 
1130
1132
  /**
1131
1133
  * The client's answer to a `Request`. `Failure` carries a message for the
1132
- * script; a failed foreground `delegate` is raised there as a defect.
1134
+ * script; a failed foreground `subagent` is raised there as a defect.
1133
1135
  *
1134
1136
  * @since 1.0.0
1135
1137
  * @category Rpcs
@@ -1305,8 +1307,8 @@ const handleRequest = (
1305
1307
  switch (request._tag) {
1306
1308
  case "TaskComplete":
1307
1309
  return opts.onTaskComplete(request.summary)
1308
- case "Delegate":
1309
- return opts.agentTasks.delegate(request)
1310
+ case "Subagent":
1311
+ return opts.agentTasks.subagent(request)
1310
1312
  case "TaskOutput":
1311
1313
  return opts.agentTasks.taskOutput(request.id)
1312
1314
  case "WaitTasks":
@@ -1380,13 +1382,13 @@ const errorMessage = (error: unknown): string =>
1380
1382
  ? error.message
1381
1383
  : String(error)
1382
1384
 
1383
- // Leaving out `delegate` leaves out `messageAgent`. The task functions
1385
+ // Leaving out `subagent` leaves out `messageAgent`. The task functions
1384
1386
  // address both kinds, so they go once neither can be started.
1385
1387
  const excludedToolNames = (
1386
1388
  excludeTools: ReadonlyArray<ExcludableTool> | undefined,
1387
1389
  ): ReadonlySet<string> => {
1388
1390
  const names = new Set<string>(excludeTools)
1389
- if (names.has("delegate")) {
1391
+ if (names.has("subagent")) {
1390
1392
  names.add("messageAgent")
1391
1393
  if (names.has("bash")) {
1392
1394
  for (const name of ["taskOutput", "waitTasks", "stopTask", "listTasks"]) {
@@ -268,11 +268,11 @@ describe("Agent images", () => {
268
268
  }),
269
269
  )
270
270
 
271
- it.effect("does not copy image bytes into a delegate prompt", () =>
271
+ it.effect("does not copy image bytes into a subagent prompt", () =>
272
272
  Effect.gen(function* () {
273
273
  const executor = makeExecutor(({ agentTasks, environment }) =>
274
274
  Stream.fromEffect(
275
- agentTasks.delegate({
275
+ agentTasks.subagent({
276
276
  id: "1",
277
277
  prompt: "child task: describe the layout",
278
278
  background: false,
@@ -292,7 +292,7 @@ describe("Agent images", () => {
292
292
  respond: (call, index) => {
293
293
  if (index === 0) {
294
294
  return Stream.make(
295
- toolCall("call-1", 'await delegate("describe the layout")'),
295
+ toolCall("call-1", 'await subagent("describe the layout")'),
296
296
  )
297
297
  }
298
298
  const isChild = userText(call.prompt).includes("child task")
@@ -305,7 +305,7 @@ describe("Agent images", () => {
305
305
  const child = calls.find((call) =>
306
306
  userText(call.prompt).includes("child task"),
307
307
  )
308
- assert.isDefined(child, "the delegate call reached the model")
308
+ assert.isDefined(child, "the subagent call reached the model")
309
309
  assert.strictEqual(fileParts(child!.prompt).length, 0)
310
310
  // The parent still has its image.
311
311
  assert.strictEqual(fileParts(calls[0]!.prompt).length, 1)
@@ -29,7 +29,7 @@ import * as Compaction from "./Compaction.ts"
29
29
  // Agent tasks: lifetime and completion delivery.
30
30
  //
31
31
  // These drive the real Agent loop and a real executor, so the model only
32
- // talks to the script API: `delegate({ prompt, background })`, `waitTasks`,
32
+ // talks to the script API: `subagent({ prompt, background })`, `waitTasks`,
33
33
  // `messageAgent`, `stopTask`, `listTasks` and `taskOutput`. One scripted
34
34
  // LanguageModel serves every agent; calls are routed by the task marker in
35
35
  // each agent's first user message. Task IDs come from the executor's counter,
@@ -159,7 +159,7 @@ const complete = (output: string) =>
159
159
  const spawnBackground = (task: string) =>
160
160
  toolCall(
161
161
  `spawn-${task}`,
162
- `const result = await delegate({ prompt: "${task}", background: true })
162
+ `const result = await subagent({ prompt: "${task}", background: true })
163
163
  console.log(JSON.stringify(result))`,
164
164
  )
165
165
 
@@ -459,7 +459,7 @@ for (const [executorName, executorLayer] of executors) {
459
459
  return Stream.make(
460
460
  toolCall(
461
461
  "too-early",
462
- `await delegate({ prompt: "TASK-CHILD", background: true })
462
+ `await subagent({ prompt: "TASK-CHILD", background: true })
463
463
  try {
464
464
  await taskComplete("too early")
465
465
  console.log("ACCEPTED")
@@ -768,7 +768,7 @@ console.log("MESSAGE-VOID:", result === undefined)`,
768
768
  return Stream.make(
769
769
  toolCall(
770
770
  "foreground",
771
- `const result = await delegate({ prompt: "TASK-CHILD" })
771
+ `const result = await subagent({ prompt: "TASK-CHILD" })
772
772
  console.log(JSON.stringify(result))`,
773
773
  ),
774
774
  )
@@ -834,8 +834,8 @@ await taskComplete("${name.toUpperCase()}:" + pwd.output.trim())`,
834
834
  "spawn",
835
835
  `await bash({ command: "mkdir -p a/one a/two" })
836
836
  await changeDirectory("a")
837
- const one = await delegate({ prompt: "TASK-CHILD-ONE", background: true })
838
- const two = await delegate({ prompt: "TASK-CHILD-TWO", background: true })
837
+ const one = await subagent({ prompt: "TASK-CHILD-ONE", background: true })
838
+ const two = await subagent({ prompt: "TASK-CHILD-TWO", background: true })
839
839
  console.log(JSON.stringify(await waitTasks({ ids: [one.id, two.id] })))
840
840
  console.log("ROOT:" + (await bash({ command: "pwd" })).output.trim())`,
841
841
  ),
@@ -868,7 +868,7 @@ console.log("ROOT:" + (await bash({ command: "pwd" })).output.trim())`,
868
868
  toolCall(
869
869
  "mixed",
870
870
  `const bashTask = await bash({ command: "echo BASH-OUT", background: true })
871
- const agentTask = await delegate({ prompt: "TASK-CHILD", background: true })
871
+ const agentTask = await subagent({ prompt: "TASK-CHILD", background: true })
872
872
  const ended = await waitTasks({ ids: [bashTask.id, agentTask.id] })
873
873
  console.log(JSON.stringify(ended.map(({ kind, status, output }) => ({ kind, status, output: output.trim() }))))`,
874
874
  ),
@@ -931,7 +931,7 @@ await taskComplete(JSON.stringify({ seen, attempts }))`,
931
931
  toolCall(
932
932
  "spawn",
933
933
  `const server = await bash({ command: "sleep 30", background: true })
934
- const child = await delegate({ prompt: "TASK-CHILD BASH-ID:" + server.id })
934
+ const child = await subagent({ prompt: "TASK-CHILD BASH-ID:" + server.id })
935
935
  console.log("CHILD:" + child.output)
936
936
  const mine = await listTasks()
937
937
  console.log("ROOT:" + JSON.stringify(mine.map((task) => task.kind + ":" + task.status).sort()))`,
@@ -988,7 +988,7 @@ console.log("ROOT:" + JSON.stringify(mine.map((task) => task.kind + ":" + task.s
988
988
  return Stream.make(
989
989
  toolCall(
990
990
  "wait",
991
- `const child = await delegate({ prompt: "TASK-CHILD", background: true })
991
+ `const child = await subagent({ prompt: "TASK-CHILD", background: true })
992
992
  const [task] = await waitTasks({ ids: [child.id], timeoutMs: 200 })
993
993
  console.log("WAITED:" + task.status)`,
994
994
  ),
@@ -1035,7 +1035,7 @@ console.log("WAITED:" + task.status)`,
1035
1035
  toolCall(
1036
1036
  "wait",
1037
1037
  `const quick = await bash({ command: "echo BASH-OUT", background: true })
1038
- const child = await delegate({ prompt: "TASK-CHILD", background: true })
1038
+ const child = await subagent({ prompt: "TASK-CHILD", background: true })
1039
1039
  const slow = await bash({ command: "sleep 30", background: true })
1040
1040
  await waitTasks({ ids: [quick.id, child.id, slow.id] })
1041
1041
  console.log("RETURNED")`,
@@ -1118,8 +1118,8 @@ describe("agent tasks (rpc executor, slow callbacks)", () => {
1118
1118
  return Stream.make(
1119
1119
  toolCall(
1120
1120
  "wait",
1121
- `const a = await delegate({ prompt: "TASK-CHILD-A", background: true })
1122
- const b = await delegate({ prompt: "TASK-CHILD-B", background: true })
1121
+ `const a = await subagent({ prompt: "TASK-CHILD-A", background: true })
1122
+ const b = await subagent({ prompt: "TASK-CHILD-B", background: true })
1123
1123
  const ended = await waitTasks({ ids: [a.id, b.id] })
1124
1124
  console.log(ended.map((task) => task.output).join(" "))`,
1125
1125
  ),