clanka 0.23.0 → 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.23.0",
4
+ "version": "0.23.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -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 })),
@@ -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
  }
package/src/AgentTools.ts CHANGED
@@ -17,6 +17,7 @@ import * as Fiber from "effect/Fiber"
17
17
  import * as Toolkit from "effect/ai/Toolkit"
18
18
  import * as Tool from "effect/ai/Tool"
19
19
  import * as Schema from "effect/Schema"
20
+ import * as Scope from "effect/Scope"
20
21
  import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"
21
22
  import * as FileSystem from "effect/FileSystem"
22
23
  import * as Path from "effect/Path"
@@ -581,23 +582,46 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
581
582
  const commandScope = yield* Effect.scope
582
583
  const startCommand = Effect.fnUntraced(function* (
583
584
  command: ChildProcess.Command,
585
+ saveLargeOutput = false,
584
586
  ) {
585
587
  const { outputChars } = yield* CommandLimits
586
- const output = makeOutputBuffer(outputChars)
588
+ const maxChars = saveLargeOutput ? (outputChars ?? 30_000) : outputChars
589
+ const output = makeOutputBuffer(maxChars)
590
+ let total = 0
591
+ let outputFile: string | undefined
592
+ const append = Effect.fnUntraced(function* (chunk: string) {
593
+ if (saveLargeOutput) {
594
+ if (outputFile !== undefined) {
595
+ yield* fs.writeFileString(outputFile, chunk, { flag: "a" })
596
+ } else if (total + chunk.length > maxChars!) {
597
+ const file = yield* fs
598
+ .makeTempFileScoped({ prefix: "clanka-bash-" })
599
+ .pipe(Effect.provideService(Scope.Scope, commandScope))
600
+ yield* fs.writeFileString(file, output.render() + chunk)
601
+ outputFile = file
602
+ }
603
+ }
604
+ total += chunk.length
605
+ output.append(chunk)
606
+ })
587
607
  const fiber = yield* spawner.spawn(command).pipe(
588
608
  Effect.flatMap((handle) =>
589
609
  handle.all.pipe(
590
610
  Stream.decodeText,
591
- Stream.runForEach((chunk) =>
592
- Effect.sync(() => output.append(chunk)),
593
- ),
611
+ Stream.runForEach(append),
594
612
  Effect.andThen(handle.exitCode),
595
613
  ),
596
614
  ),
597
615
  Effect.scoped,
598
616
  Effect.forkIn(commandScope),
599
617
  )
600
- return { fiber, output: output.render }
618
+ return {
619
+ fiber,
620
+ output: () =>
621
+ outputFile === undefined
622
+ ? output.render()
623
+ : `Output was too large. Saved to: ${outputFile}`,
624
+ }
601
625
  })
602
626
 
603
627
  // Every task started on this executor, bash and agent alike, so both
@@ -605,7 +629,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
605
629
  // started it.
606
630
  const tasks = new Map<string, TaskEntry>()
607
631
  let nextTaskId = 1
608
- const registerAgentTask = Effect.fnUntraced(function* () {
632
+ const registerAgentTask = Effect.gen(function* () {
609
633
  const id = String(nextTaskId++)
610
634
  tasks.set(id, { kind: "agent", id, owner: yield* TaskOwner })
611
635
  return id
@@ -883,7 +907,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
883
907
  })
884
908
  const entry = yield* addBashTask(
885
909
  options.command,
886
- yield* startCommand(cmd),
910
+ yield* startCommand(cmd, true),
887
911
  )
888
912
  if (options.background !== true) {
889
913
  const exit = yield* awaitCommand(
@@ -1179,7 +1203,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
1179
1203
  yield* Effect.logInfo(`Calling "subagent"`).pipe(
1180
1204
  Effect.annotateLogs({ background }),
1181
1205
  )
1182
- const id = yield* registerAgentTask()
1206
+ const id = yield* registerAgentTask
1183
1207
  const agentTasks = yield* AgentTaskExecutor
1184
1208
  return yield* agentTasks.subagent({ id, prompt, background })
1185
1209
  }),