clanka 0.9.0 → 0.10.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 (74) hide show
  1. package/dist/Acp.d.ts +6 -1
  2. package/dist/Acp.d.ts.map +1 -1
  3. package/dist/Acp.js +25 -0
  4. package/dist/Acp.js.map +1 -1
  5. package/dist/Acp.test.js +109 -4
  6. package/dist/Acp.test.js.map +1 -1
  7. package/dist/AcpImage.test.js +6 -1
  8. package/dist/AcpImage.test.js.map +1 -1
  9. package/dist/Agent.d.ts +17 -0
  10. package/dist/Agent.d.ts.map +1 -1
  11. package/dist/Agent.js +90 -15
  12. package/dist/Agent.js.map +1 -1
  13. package/dist/Agent.test.js +9 -1
  14. package/dist/Agent.test.js.map +1 -1
  15. package/dist/AgentCallerConfig.test.js +9 -1
  16. package/dist/AgentCallerConfig.test.js.map +1 -1
  17. package/dist/AgentEnvironment.d.ts +76 -0
  18. package/dist/AgentEnvironment.d.ts.map +1 -0
  19. package/dist/AgentEnvironment.js +119 -0
  20. package/dist/AgentEnvironment.js.map +1 -0
  21. package/dist/AgentEnvironment.test.d.ts +2 -0
  22. package/dist/AgentEnvironment.test.d.ts.map +1 -0
  23. package/dist/AgentEnvironment.test.js +304 -0
  24. package/dist/AgentEnvironment.test.js.map +1 -0
  25. package/dist/AgentExecutor.d.ts +146 -187
  26. package/dist/AgentExecutor.d.ts.map +1 -1
  27. package/dist/AgentExecutor.js +212 -49
  28. package/dist/AgentExecutor.js.map +1 -1
  29. package/dist/AgentExecutor.test.js +94 -8
  30. package/dist/AgentExecutor.test.js.map +1 -1
  31. package/dist/AgentExecutorImage.test.js +3 -0
  32. package/dist/AgentExecutorImage.test.js.map +1 -1
  33. package/dist/AgentImage.test.js +11 -2
  34. package/dist/AgentImage.test.js.map +1 -1
  35. package/dist/AgentOutput.d.ts +17 -4
  36. package/dist/AgentOutput.d.ts.map +1 -1
  37. package/dist/AgentOutput.js +13 -0
  38. package/dist/AgentOutput.js.map +1 -1
  39. package/dist/AgentSkills.d.ts +15 -0
  40. package/dist/AgentSkills.d.ts.map +1 -1
  41. package/dist/AgentSkills.js +60 -32
  42. package/dist/AgentSkills.js.map +1 -1
  43. package/dist/AgentSkills.test.js +12 -2
  44. package/dist/AgentSkills.test.js.map +1 -1
  45. package/dist/AgentSubagents.test.js +42 -0
  46. package/dist/AgentSubagents.test.js.map +1 -1
  47. package/dist/AgentTools.js +1 -1
  48. package/dist/AgentTools.js.map +1 -1
  49. package/dist/OutputFormatter.d.ts.map +1 -1
  50. package/dist/OutputFormatter.js +3 -0
  51. package/dist/OutputFormatter.js.map +1 -1
  52. package/dist/bin/{OutputFormatter-DXXKo4E8.mjs → OutputFormatter-BFAv48k9.mjs} +2 -1
  53. package/dist/bin/{OutputFormatter-DXXKo4E8.mjs.map → OutputFormatter-BFAv48k9.mjs.map} +1 -1
  54. package/dist/bin/cli.mjs +13316 -13094
  55. package/dist/bin/cli.mjs.map +1 -1
  56. package/package.json +1 -1
  57. package/src/Acp.test.ts +162 -5
  58. package/src/Acp.ts +24 -1
  59. package/src/AcpImage.test.ts +6 -1
  60. package/src/Agent.test.ts +9 -1
  61. package/src/Agent.ts +136 -12
  62. package/src/AgentCallerConfig.test.ts +9 -1
  63. package/src/AgentEnvironment.test.ts +504 -0
  64. package/src/AgentEnvironment.ts +161 -0
  65. package/src/AgentExecutor.test.ts +121 -4
  66. package/src/AgentExecutor.ts +388 -99
  67. package/src/AgentExecutorImage.test.ts +3 -0
  68. package/src/AgentImage.test.ts +11 -2
  69. package/src/AgentOutput.ts +17 -0
  70. package/src/AgentSkills.test.ts +12 -2
  71. package/src/AgentSkills.ts +74 -34
  72. package/src/AgentSubagents.test.ts +66 -0
  73. package/src/AgentTools.ts +1 -1
  74. package/src/OutputFormatter.ts +3 -0
@@ -3,6 +3,7 @@ import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
3
3
  import * as NodeServices from "@effect/platform-node/NodeServices"
4
4
  import * as Deferred from "effect/Deferred"
5
5
  import * as Effect from "effect/Effect"
6
+ import * as Fiber from "effect/Fiber"
6
7
  import * as FileSystem from "effect/FileSystem"
7
8
  import * as Layer from "effect/Layer"
8
9
  import * as Stream from "effect/Stream"
@@ -59,12 +60,15 @@ describe("RPC subagent executor", () => {
59
60
  it.live("routes concurrent delegates to their originating scripts", () =>
60
61
  withRpc((executor) =>
61
62
  Effect.gen(function* () {
63
+ const { environment } = yield* executor.capabilities
62
64
  const firstStarted = yield* Deferred.make<void>()
63
65
  const secondStarted = yield* Deferred.make<void>()
64
66
  const outputs = yield* Effect.all(
65
67
  [
66
68
  executor
67
69
  .execute({
70
+ environment,
71
+ onEnvironment: () => Effect.void,
68
72
  script:
69
73
  'console.log("first:" + (await delegate({ prompt: "first" })).output)',
70
74
  onTaskComplete: () => Effect.void,
@@ -87,6 +91,8 @@ describe("RPC subagent executor", () => {
87
91
  .pipe(Stream.runCollect),
88
92
  executor
89
93
  .execute({
94
+ environment,
95
+ onEnvironment: () => Effect.void,
90
96
  script:
91
97
  'console.log("second:" + (await delegate({ prompt: "second" })).output)',
92
98
  onTaskComplete: () => Effect.void,
@@ -121,8 +127,11 @@ describe("RPC subagent executor", () => {
121
127
  () =>
122
128
  withRpc((executor) =>
123
129
  Effect.gen(function* () {
130
+ const { environment } = yield* executor.capabilities
124
131
  const output = yield* executor
125
132
  .execute({
133
+ environment,
134
+ onEnvironment: () => Effect.void,
126
135
  script:
127
136
  'console.log("parent:" + (await delegate({ prompt: "outer" })).output)',
128
137
  onTaskComplete: () => Effect.void,
@@ -134,6 +143,8 @@ describe("RPC subagent executor", () => {
134
143
  assert.strictEqual(prompt, "outer")
135
144
  const childOutput = yield* executor
136
145
  .execute({
146
+ environment,
147
+ onEnvironment: () => Effect.void,
137
148
  script:
138
149
  'console.log("child:" + (await delegate({ prompt: "inner" })).output)',
139
150
  onTaskComplete: () => Effect.void,
@@ -218,16 +229,20 @@ const executorModes = {
218
229
  }
219
230
 
220
231
  const runScript = (script: string) =>
221
- AgentExecutor.AgentExecutor.use((executor) =>
222
- executor
232
+ Effect.gen(function* () {
233
+ const executor = yield* AgentExecutor.AgentExecutor
234
+ const { environment } = yield* executor.capabilities
235
+ return yield* executor
223
236
  .execute({
237
+ environment,
238
+ onEnvironment: () => Effect.void,
224
239
  script,
225
240
  onTaskComplete: () => Effect.void,
226
241
  subagents: subagentsUnavailable,
227
242
  onImage: () => Effect.void,
228
243
  })
229
- .pipe(Stream.mkString),
230
- )
244
+ .pipe(Stream.mkString)
245
+ })
231
246
 
232
247
  // Puts a `gh` that only sleeps first on PATH, so the test needs neither the
233
248
  // real CLI nor the network.
@@ -253,6 +268,105 @@ const withSlowGh = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
253
268
  )
254
269
 
255
270
  for (const [mode, executorLayer] of Object.entries(executorModes)) {
271
+ describe(`${mode} executor environment`, () => {
272
+ // A cancelled script keeps the directory it changed to, as an ACP
273
+ // `session/cancel` or a `stopAgent` continues the same agent afterwards.
274
+ it.live("returns the environment when the caller interrupts", () =>
275
+ Effect.gen(function* () {
276
+ const executor = yield* AgentExecutor.AgentExecutor
277
+ const { environment } = yield* executor.capabilities
278
+ const ready = yield* Deferred.make<void>()
279
+ const updates: Array<AgentExecutor.ExecutionEnvironment> = []
280
+ const fiber = yield* executor
281
+ .execute({
282
+ script: `await changeDirectory("..")
283
+ console.log("ready")
284
+ await sleep(60000)`,
285
+ environment,
286
+ onEnvironment: (update) =>
287
+ Effect.sync(() => {
288
+ updates.push(update)
289
+ }),
290
+ onTaskComplete: () => Effect.void,
291
+ subagents: subagentsUnavailable,
292
+ onImage: () => Effect.void,
293
+ })
294
+ .pipe(
295
+ Stream.runForEach((text) =>
296
+ text.includes("ready")
297
+ ? Deferred.succeed(ready, undefined)
298
+ : Effect.void,
299
+ ),
300
+ Effect.forkScoped,
301
+ )
302
+ yield* Deferred.await(ready)
303
+ yield* Fiber.interrupt(fiber)
304
+ assert.strictEqual(updates.length, 1)
305
+ assert.strictEqual(updates[0]!.cwd, NodePath.dirname(environment.cwd))
306
+ }).pipe(
307
+ Effect.scoped,
308
+ Effect.timeout("5 seconds"),
309
+ Effect.provide(executorLayer({})),
310
+ ),
311
+ )
312
+
313
+ // The caller is still busy with output from before the change when it
314
+ // interrupts. Whatever the script got done by then, the environment
315
+ // returned matches it: the marker shows it got past `changeDirectory`.
316
+ it.live(
317
+ "returns the environment when the caller interrupts while behind",
318
+ () =>
319
+ Effect.gen(function* () {
320
+ const executor = yield* AgentExecutor.AgentExecutor
321
+ const { environment } = yield* executor.capabilities
322
+ const marker = NodePath.join(environment.cwd, "changed")
323
+ const busy = yield* Deferred.make<void>()
324
+ const updates: Array<AgentExecutor.ExecutionEnvironment> = []
325
+ const fiber = yield* executor
326
+ .execute({
327
+ script: `console.log("before")
328
+ await sleep(50)
329
+ await changeDirectory("..")
330
+ await writeFile({ path: ${JSON.stringify(marker)}, content: "" })
331
+ await sleep(60000)`,
332
+ environment,
333
+ onEnvironment: (update) =>
334
+ Effect.sync(() => {
335
+ updates.push(update)
336
+ }),
337
+ onTaskComplete: () => Effect.void,
338
+ subagents: subagentsUnavailable,
339
+ onImage: () => Effect.void,
340
+ })
341
+ .pipe(
342
+ Stream.runForEach(() =>
343
+ Deferred.succeed(busy, undefined).pipe(
344
+ Effect.andThen(Effect.never),
345
+ ),
346
+ ),
347
+ Effect.forkScoped,
348
+ )
349
+ yield* Deferred.await(busy)
350
+ yield* Effect.gen(function* () {
351
+ while (!NodeFs.existsSync(marker)) {
352
+ yield* Effect.sleep("10 millis")
353
+ }
354
+ }).pipe(Effect.timeoutOption("500 millis"))
355
+ const changed = NodeFs.existsSync(marker)
356
+ yield* Fiber.interrupt(fiber)
357
+ assert.strictEqual(updates.length, 1)
358
+ assert.strictEqual(
359
+ updates[0]!.cwd,
360
+ changed ? NodePath.dirname(environment.cwd) : environment.cwd,
361
+ )
362
+ }).pipe(
363
+ Effect.scoped,
364
+ Effect.timeout("5 seconds"),
365
+ Effect.provide(executorLayer({})),
366
+ ),
367
+ )
368
+ })
369
+
256
370
  describe(`${mode} executor limits`, () => {
257
371
  it.live("stops a bash command at the caller's command timeout", () =>
258
372
  Effect.gen(function* () {
@@ -354,8 +468,11 @@ console.log("MAIN" + "_DONE")`)
354
468
  () =>
355
469
  Effect.gen(function* () {
356
470
  const executor = yield* AgentExecutor.AgentExecutor
471
+ const { environment } = yield* executor.capabilities
357
472
  const output = yield* executor
358
473
  .execute({
474
+ environment,
475
+ onEnvironment: () => Effect.void,
359
476
  // `delegate` never finishes. The worker then exits through
360
477
  // the host's `process`, the way a crashed worker would.
361
478
  script: `