clanka 0.23.1 → 0.23.2

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.23.1",
4
+ "version": "0.23.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
package/src/Acp.test.ts CHANGED
@@ -740,11 +740,15 @@ describe("Acp", () => {
740
740
  resumed ? "SECOND-RESULT" : "FIRST-RESULT",
741
741
  )
742
742
  }
743
- const seen = JSON.stringify(prompt.content)
744
- if (seen.includes("SECOND-RESULT")) return assistantSays("done")
743
+ const completions = prompt.content.filter(
744
+ (message) =>
745
+ message.role === "user" &&
746
+ JSON.stringify(message.content).includes("<task "),
747
+ ).length
748
+ if (completions === 2) return assistantSays("done")
745
749
  if (
746
750
  executions === 0 ||
747
- (executions === 1 && seen.includes("FIRST-RESULT"))
751
+ (executions === 1 && completions === 1)
748
752
  ) {
749
753
  return parts({
750
754
  type: "tool-call",
@@ -758,7 +762,7 @@ describe("Acp", () => {
758
762
  {
759
763
  ...executor,
760
764
  // The first script starts a background child; the second
761
- // resumes it once its first result has been delivered.
765
+ // resumes it once its first completion has been delivered.
762
766
  execute: ({ agentTasks, environment }) =>
763
767
  Stream.fromEffect(
764
768
  executions++ === 0
package/src/Agent.ts CHANGED
@@ -1614,7 +1614,7 @@ const taskMessage = (task: Task): string => {
1614
1614
  const exitCode =
1615
1615
  task.exitCode === undefined ? "" : ` exitCode="${task.exitCode}"`
1616
1616
  return `<task id="${task.id}" kind="${task.kind}" status="${task.status}"${exitCode}>
1617
- ${Compaction.capOutput(task.output).output}
1617
+ To read the output, call taskOutput(${JSON.stringify(task.id)}).
1618
1618
  </task>`
1619
1619
  }
1620
1620
 
@@ -1771,7 +1771,7 @@ const taskInstructions = (tools: PromptTools): string => {
1771
1771
  ? ""
1772
1772
  : ` ${functions.length === 1 ? functions[0]! : `${functions.slice(0, -1).join(", ")} and ${functions.at(-1)!}`}.`
1773
1773
  const pushes = tools.taskPushes
1774
- ? ` When a task ends, its status and output are sent to you as a \`<task id="..." kind="..." status="...">\` message, unless a task function already gave you its final status, so you do not need to poll.`
1774
+ ? ` When a task ends, its status and a call to retrieve its output are sent to you as a \`<task id="..." kind="..." status="...">\` message, unless a task function already gave you its final status, so you do not need to poll.`
1775
1775
  : bash && tools.offers("taskOutput")
1776
1776
  ? ` Background commands are not sent to you when they end: check them with "taskOutput".`
1777
1777
  : ""
@@ -24,7 +24,7 @@ import * as AgentExecutor from "./AgentExecutor.ts"
24
24
  //
25
25
  // These drive the real Agent loop and a real executor. When a background bash
26
26
  // task exits, the next model call gets a user message
27
- // `<task id="…" kind="bash" status="…" exitCode="…">output</task>`, unless the
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
29
  // that saw its final status. Task IDs come from the executor's counter: "1",
30
30
  // "2", ...
@@ -161,7 +161,7 @@ for (const [executorName, executorLayer] of executors) {
161
161
  // Each test gets its own executor, so task IDs start at "1".
162
162
  describe(`background bash tasks (${executorName} executor)`, () => {
163
163
  it.live(
164
- "a finished bash task is pushed once with its id, kind, status, exit code and output",
164
+ "a finished bash task is pushed once with its id, kind, status, exit code and an output retrieval call",
165
165
  () =>
166
166
  Effect.gen(function* () {
167
167
  const { exit, prompts } = yield* runAgent((index) => {
@@ -175,7 +175,10 @@ for (const [executorName, executorLayer] of executors) {
175
175
  await sleep(500)`,
176
176
  )
177
177
  case 1:
178
- return execute("again", `console.log("AGAIN")`)
178
+ return execute(
179
+ "again",
180
+ `console.log((await taskOutput("1")).output)`,
181
+ )
179
182
  default:
180
183
  return text("done")
181
184
  }
@@ -187,7 +190,15 @@ await sleep(500)`,
187
190
  assert.strictEqual(pushes.length, 1, "pushed before the next call")
188
191
  assert.match(
189
192
  pushes[0]!,
190
- /^<task id="1" kind="bash" status="failed" exitCode="3">\s*JOB-OUTPUT\s*<\/task>$/,
193
+ /^<task id="1" kind="bash" status="failed" exitCode="3">\s*To read the output, call taskOutput\("1"\)\.\s*<\/task>$/,
194
+ )
195
+ assert.include(
196
+ JSON.stringify(
197
+ prompts[2]!.content.findLast(
198
+ (message) => message.role === "tool",
199
+ ),
200
+ ),
201
+ "JOB-OUTPUT",
191
202
  )
192
203
  assert.deepStrictEqual(
193
204
  taskPushes(prompts[2]!),
@@ -232,7 +243,7 @@ console.log("SCRIPT" + "-DONE")`,
232
243
  assert.strictEqual(pushes.length, 1)
233
244
  assert.match(
234
245
  pushes[0]!,
235
- /^<task id="3" kind="bash" status="completed" exitCode="0">\s*UNREAD\s*<\/task>$/,
246
+ /^<task id="3" kind="bash" status="completed" exitCode="0">\s*To read the output, call taskOutput\("3"\)\.\s*<\/task>$/,
236
247
  )
237
248
  assert.include(JSON.stringify(prompts[1]), "SCRIPT-DONE")
238
249
  }).pipe(Effect.provide(executorLayer)),
@@ -1020,7 +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.match(text, /^Full output saved to: [^\n]+$/)
1023
+ assert.match(text, /^Output was too large\. Saved to: [^\n]+$/)
1024
1024
  }).pipe(
1025
1025
  Effect.timeout("10 seconds"),
1026
1026
  Effect.provide(executorLayer({ commandOutputChars: 10_000 })),
@@ -23,7 +23,6 @@ import * as RpcServer from "effect/rpc/RpcServer"
23
23
  import * as Agent from "./Agent.ts"
24
24
  import * as AgentExecutor from "./AgentExecutor.ts"
25
25
  import type { Output } from "./AgentOutput.ts"
26
- import * as Compaction from "./Compaction.ts"
27
26
 
28
27
  // =============================================================================
29
28
  // Agent tasks: lifetime and completion delivery.
@@ -274,7 +273,7 @@ for (const [executorName, executorLayer] of executors) {
274
273
  ) => it.live(name, () => self().pipe(Effect.provide(executorLayer(limits))))
275
274
 
276
275
  describe(`agent tasks (${executorName} executor)`, () => {
277
- test("an idle conversation turn waits for a running child, then gets its capped output", () =>
276
+ test("an idle conversation turn waits for a running child, then gets an output retrieval call", () =>
278
277
  Effect.gen(function* () {
279
278
  const childRelease = Latch.makeUnsafe(false)
280
279
  const childOutput = "CHILD-HEAD " + "x".repeat(40_000) + " CHILD-TAIL"
@@ -298,6 +297,13 @@ for (const [executorName, executorLayer] of executors) {
298
297
  Stream.ensuring(Effect.sync(() => childRelease.openUnsafe())),
299
298
  )
300
299
  case 2:
300
+ return Stream.make(
301
+ toolCall(
302
+ "read",
303
+ `console.log((await taskOutput("1")).output)`,
304
+ ),
305
+ )
306
+ case 3:
301
307
  return Stream.fromIterable(text("all done"))
302
308
  default:
303
309
  return unexpected(call)
@@ -307,7 +313,7 @@ for (const [executorName, executorLayer] of executors) {
307
313
 
308
314
  assert.deepStrictEqual(exit, Exit.succeed("all done"))
309
315
  const root = calls.filter((call) => call.role === "root")
310
- assert.strictEqual(root.length, 3)
316
+ assert.strictEqual(root.length, 4)
311
317
 
312
318
  const started = lastToolResult(root[1]!.prompt)
313
319
  assert.include(started, '"id":"1"')
@@ -317,13 +323,11 @@ for (const [executorName, executorLayer] of executors) {
317
323
 
318
324
  const push = findPush(root[2]!.prompt, "1", "completed")
319
325
  assert.notStrictEqual(push.index, -1, "completion push delivered")
320
- assert.include(push.text, "CHILD-HEAD")
321
- assert.include(push.text, "CHILD-TAIL")
322
- assert.isAtMost(
323
- push.text.length,
324
- Compaction.executeOutputCapChars + 1_000,
325
- "push output goes through capOutput",
326
- )
326
+ assert.include(push.text, 'taskOutput("1")')
327
+ assert.notInclude(push.text, "CHILD-HEAD")
328
+ assert.notInclude(push.text, "CHILD-TAIL")
329
+ assert.include(lastToolResult(root[3]!.prompt), "CHILD-HEAD")
330
+ assert.include(lastToolResult(root[3]!.prompt), "CHILD-TAIL")
327
331
  }))
328
332
 
329
333
  test("a completion push does not cut off the parent's in-progress response", () =>
@@ -400,7 +404,7 @@ for (const [executorName, executorLayer] of executors) {
400
404
  "the tool call after the push still ran",
401
405
  )
402
406
  const push = findPush(prompt, "1", "completed")
403
- assert.include(push.text, "CHILD-RESULT")
407
+ assert.include(push.text, 'taskOutput("1")')
404
408
  assert.isAbove(
405
409
  push.index,
406
410
  assistantIndex,
@@ -438,7 +442,8 @@ for (const [executorName, executorLayer] of executors) {
438
442
  const root = calls.filter((call) => call.role === "root")
439
443
  const push = findPush(root[2]!.prompt, "1", "failed")
440
444
  assert.notStrictEqual(push.index, -1, "failure push delivered")
441
- assert.include(push.text, "rejected")
445
+ assert.include(push.text, 'taskOutput("1")')
446
+ assert.notInclude(push.text, "rejected")
442
447
  }))
443
448
 
444
449
  test("taskComplete fails while a child is running and leaves it running", () =>
@@ -700,13 +705,10 @@ console.log(JSON.stringify(await taskOutput("1")))`,
700
705
  if (call.index === 0) {
701
706
  return Stream.make(spawnBackground("TASK-CHILD"))
702
707
  }
703
- if (pushes.some((push) => push.includes("SECOND-ANSWER"))) {
708
+ if (pushes.length === 2) {
704
709
  return Stream.fromIterable(text("resumed"))
705
710
  }
706
- if (
707
- messageCall === undefined &&
708
- pushes.some((push) => push.includes("FIRST-ANSWER"))
709
- ) {
711
+ if (messageCall === undefined && pushes.length === 1) {
710
712
  messageCall = call.index
711
713
  return Stream.make(
712
714
  toolCall(
@@ -721,7 +723,7 @@ console.log("MESSAGE-VOID:", result === undefined)`,
721
723
  })
722
724
 
723
725
  assert.deepStrictEqual(exit, Exit.succeed("resumed"))
724
- assert.isDefined(messageCall, "the first answer was pushed")
726
+ assert.isDefined(messageCall, "the first completion was pushed")
725
727
  const root = calls.filter((call) => call.role === "root")
726
728
  const messaged = lastToolResult(root[messageCall! + 1]!.prompt)
727
729
  assert.include(messaged, "MESSAGE-VOID: true")
@@ -747,7 +749,7 @@ console.log("MESSAGE-VOID:", result === undefined)`,
747
749
  case "child":
748
750
  if (
749
751
  findPush(call.prompt, "2", "completed").text.includes(
750
- "GRAND-RESULT",
752
+ 'taskOutput("2")',
751
753
  )
752
754
  ) {
753
755
  return complete("CHILD-DONE")
@@ -1014,8 +1016,8 @@ console.log("WAITED:" + task.status)`,
1014
1016
  assert.strictEqual(root.length, 3)
1015
1017
  assert.include(
1016
1018
  findPush(root[2]!.prompt, "1", "completed").text,
1017
- "CHILD-LATE",
1018
- "its result is pushed once it ends",
1019
+ 'taskOutput("1")',
1020
+ "its completion is pushed once it ends",
1019
1021
  )
1020
1022
  }))
1021
1023
 
@@ -1056,7 +1058,7 @@ console.log("RETURNED")`,
1056
1058
  assert.notInclude(result, "RETURNED")
1057
1059
  assert.isTrue(
1058
1060
  pushTexts(root[1]!.prompt).some((push) =>
1059
- /^<task id="1" kind="bash" status="completed" exitCode="0">\s*BASH-OUT\s*<\/task>$/.test(
1061
+ /^<task id="1" kind="bash" status="completed" exitCode="0">\s*To read the output, call taskOutput\("1"\)\.\s*<\/task>$/.test(
1060
1062
  push,
1061
1063
  ),
1062
1064
  ),
@@ -1064,7 +1066,7 @@ console.log("RETURNED")`,
1064
1066
  )
1065
1067
  assert.include(
1066
1068
  findPush(root[1]!.prompt, "2", "completed").text,
1067
- "CHILD-OUT",
1069
+ 'taskOutput("2")',
1068
1070
  "the agent task is pushed",
1069
1071
  )
1070
1072
  }),