clanka 0.8.6 → 0.9.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 (85) hide show
  1. package/dist/Acp.d.ts.map +1 -1
  2. package/dist/Acp.js +9 -3
  3. package/dist/Acp.js.map +1 -1
  4. package/dist/Acp.test.js +72 -1
  5. package/dist/Acp.test.js.map +1 -1
  6. package/dist/AcpImage.test.js +1 -0
  7. package/dist/AcpImage.test.js.map +1 -1
  8. package/dist/Agent.d.ts +65 -8
  9. package/dist/Agent.d.ts.map +1 -1
  10. package/dist/Agent.js +481 -113
  11. package/dist/Agent.js.map +1 -1
  12. package/dist/Agent.test.js +77 -4
  13. package/dist/Agent.test.js.map +1 -1
  14. package/dist/AgentCallerConfig.test.d.ts +2 -0
  15. package/dist/AgentCallerConfig.test.d.ts.map +1 -0
  16. package/dist/AgentCallerConfig.test.js +327 -0
  17. package/dist/AgentCallerConfig.test.js.map +1 -0
  18. package/dist/AgentExecutor.d.ts +254 -54
  19. package/dist/AgentExecutor.d.ts.map +1 -1
  20. package/dist/AgentExecutor.js +416 -99
  21. package/dist/AgentExecutor.js.map +1 -1
  22. package/dist/AgentExecutor.test.js +201 -31
  23. package/dist/AgentExecutor.test.js.map +1 -1
  24. package/dist/AgentExecutorImage.test.js +2 -1
  25. package/dist/AgentExecutorImage.test.js.map +1 -1
  26. package/dist/AgentImage.test.js +5 -1
  27. package/dist/AgentImage.test.js.map +1 -1
  28. package/dist/AgentOutput.d.ts +54 -2
  29. package/dist/AgentOutput.d.ts.map +1 -1
  30. package/dist/AgentOutput.js +52 -0
  31. package/dist/AgentOutput.js.map +1 -1
  32. package/dist/AgentSkills.d.ts +22 -0
  33. package/dist/AgentSkills.d.ts.map +1 -1
  34. package/dist/AgentSkills.js +36 -0
  35. package/dist/AgentSkills.js.map +1 -1
  36. package/dist/AgentSkills.test.js +2 -0
  37. package/dist/AgentSkills.test.js.map +1 -1
  38. package/dist/AgentSubagents.test.d.ts +2 -0
  39. package/dist/AgentSubagents.test.d.ts.map +1 -0
  40. package/dist/AgentSubagents.test.js +452 -0
  41. package/dist/AgentSubagents.test.js.map +1 -0
  42. package/dist/AgentTools.d.ts +356 -14
  43. package/dist/AgentTools.d.ts.map +1 -1
  44. package/dist/AgentTools.js +213 -34
  45. package/dist/AgentTools.js.map +1 -1
  46. package/dist/OutputFormatter.d.ts.map +1 -1
  47. package/dist/OutputFormatter.js +16 -2
  48. package/dist/OutputFormatter.js.map +1 -1
  49. package/dist/ToolkitRenderer.d.ts.map +1 -1
  50. package/dist/ToolkitRenderer.js +6 -1
  51. package/dist/ToolkitRenderer.js.map +1 -1
  52. package/dist/bin/{Effect-rADALOOD.mjs → Effect-2jPlJ8eu.mjs} +43 -38
  53. package/dist/bin/Effect-2jPlJ8eu.mjs.map +1 -0
  54. package/dist/bin/{McpClient-NazR2OwL.mjs → McpClient-1W508adc.mjs} +3 -3
  55. package/dist/bin/{McpClient-NazR2OwL.mjs.map → McpClient-1W508adc.mjs.map} +1 -1
  56. package/dist/bin/{OutputFormatter-BVHbgF2b.mjs → OutputFormatter-DXXKo4E8.mjs} +16 -5
  57. package/dist/bin/{OutputFormatter-BVHbgF2b.mjs.map → OutputFormatter-DXXKo4E8.mjs.map} +1 -1
  58. package/dist/bin/{Schema-C7NXAOWA.mjs → Schema-D-7VuCiC.mjs} +2 -2
  59. package/dist/bin/{Schema-C7NXAOWA.mjs.map → Schema-D-7VuCiC.mjs.map} +1 -1
  60. package/dist/bin/{SemanticSearch-4Jes3jCl.mjs → SemanticSearch-Cb8aqvGv.mjs} +4 -4
  61. package/dist/bin/{SemanticSearch-4Jes3jCl.mjs.map → SemanticSearch-Cb8aqvGv.mjs.map} +1 -1
  62. package/dist/bin/{Stream-CSLA1_GD.mjs → Stream-DEu2tfCV.mjs} +12 -3
  63. package/dist/bin/Stream-DEu2tfCV.mjs.map +1 -0
  64. package/dist/bin/cli.mjs +914 -273
  65. package/dist/bin/cli.mjs.map +1 -1
  66. package/package.json +1 -1
  67. package/src/Acp.test.ts +121 -2
  68. package/src/Acp.ts +10 -3
  69. package/src/AcpImage.test.ts +1 -0
  70. package/src/Agent.test.ts +100 -3
  71. package/src/Agent.ts +752 -142
  72. package/src/AgentCallerConfig.test.ts +514 -0
  73. package/src/AgentExecutor.test.ts +297 -37
  74. package/src/AgentExecutor.ts +707 -159
  75. package/src/AgentExecutorImage.test.ts +2 -1
  76. package/src/AgentImage.test.ts +11 -2
  77. package/src/AgentOutput.ts +74 -1
  78. package/src/AgentSkills.test.ts +2 -0
  79. package/src/AgentSkills.ts +43 -0
  80. package/src/AgentSubagents.test.ts +758 -0
  81. package/src/AgentTools.ts +376 -52
  82. package/src/OutputFormatter.ts +16 -2
  83. package/src/ToolkitRenderer.ts +7 -1
  84. package/dist/bin/Effect-rADALOOD.mjs.map +0 -1
  85. package/dist/bin/Stream-CSLA1_GD.mjs.map +0 -1
@@ -0,0 +1,514 @@
1
+ import { assert, describe, it } from "@effect/vitest"
2
+ import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
3
+ import * as NodeServices from "@effect/platform-node/NodeServices"
4
+ import * as Deferred from "effect/Deferred"
5
+ import * as Effect from "effect/Effect"
6
+ import * as Exit from "effect/Exit"
7
+ import * as Fiber from "effect/Fiber"
8
+ import * as FileSystem from "effect/FileSystem"
9
+ import * as FetchHttpClient from "effect/http/FetchHttpClient"
10
+ import * as HttpServer from "effect/http/HttpServer"
11
+ import * as Latch from "effect/Latch"
12
+ import * as Layer from "effect/Layer"
13
+ import * as Option from "effect/Option"
14
+ import * as Path from "effect/Path"
15
+ import * as Schema from "effect/Schema"
16
+ import * as Stream from "effect/Stream"
17
+ import * as LanguageModel from "effect/ai/LanguageModel"
18
+ import * as Model from "effect/ai/Model"
19
+ import type * as Prompt from "effect/ai/Prompt"
20
+ import type * as Response from "effect/ai/Response"
21
+ import * as Tool from "effect/ai/Tool"
22
+ import * as Toolkit from "effect/ai/Toolkit"
23
+ import * as RpcClient from "effect/rpc/RpcClient"
24
+ import * as RpcSerialization from "effect/rpc/RpcSerialization"
25
+ import * as RpcServer from "effect/rpc/RpcServer"
26
+ import * as Agent from "./Agent.ts"
27
+ import * as AgentExecutor from "./AgentExecutor.ts"
28
+ import { type ExcludableTool, subagentsUnavailable } from "./AgentTools.ts"
29
+
30
+ // =============================================================================
31
+ // Caller-selected tools, instructions, skills and loop-side tools.
32
+ //
33
+ // These drive the real Agent loop against a real executor, local and RPC, with
34
+ // a scripted LanguageModel that answers the first call with one `execute`
35
+ // script. Every script ends with `taskComplete`, so a run makes exactly one
36
+ // model call; its system prompt and the final summary are what the tests
37
+ // observe. No SubagentModel is ever provided. The RPC executor talks over a
38
+ // real in-process HTTP server, so the tests run with the live clock.
39
+ // =============================================================================
40
+
41
+ type Mode = "local" | "rpc"
42
+
43
+ const modes: ReadonlyArray<Mode> = ["local", "rpc"]
44
+
45
+ interface ExecutorOptions {
46
+ readonly excludeTools?: ReadonlyArray<ExcludableTool> | undefined
47
+ readonly tools?: Toolkit.Any | undefined
48
+ }
49
+
50
+ // The executor's checkout carries instructions and a skill a caller may
51
+ // replace. Neither marker may leak into a prompt that replaced them.
52
+ const prepareDirectory = Effect.gen(function* () {
53
+ const fs = yield* FileSystem.FileSystem
54
+ const path = yield* Path.Path
55
+ const directory = yield* fs.makeTempDirectoryScoped()
56
+ yield* fs.writeFileString(
57
+ path.join(directory, "AGENTS.md"),
58
+ "EXECUTOR-AGENTS-MD",
59
+ )
60
+ const skillDir = path.join(directory, ".agents", "skills", "executor-skill")
61
+ yield* fs.makeDirectory(skillDir, { recursive: true })
62
+ yield* fs.writeFileString(
63
+ path.join(skillDir, "SKILL.md"),
64
+ "---\nname: executor-skill\ndescription: Executor skill\n---\nEXECUTOR-SKILL-CONTENT",
65
+ )
66
+ return directory
67
+ })
68
+
69
+ const localExecutor = (options: ExecutorOptions) =>
70
+ Layer.unwrap(
71
+ Effect.gen(function* () {
72
+ const directory = yield* prepareDirectory
73
+ return AgentExecutor.layerLocal({ directory, ...options })
74
+ }),
75
+ ).pipe(
76
+ Layer.provide(Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer)),
77
+ )
78
+
79
+ const rpcExecutor = (options: ExecutorOptions) =>
80
+ Layer.unwrap(
81
+ Effect.gen(function* () {
82
+ const directory = yield* prepareDirectory
83
+ const { protocol, httpEffect } =
84
+ yield* RpcServer.makeProtocolWithHttpEffect()
85
+ yield* Layer.build(
86
+ AgentExecutor.layerRpcServer({ directory, ...options }).pipe(
87
+ Layer.provide(Layer.succeed(RpcServer.Protocol, protocol)),
88
+ ),
89
+ )
90
+ yield* HttpServer.serveEffect(httpEffect)
91
+ return AgentExecutor.layerRpc.pipe(
92
+ Layer.provide(RpcClient.layerProtocolHttp({ url: "" })),
93
+ )
94
+ }),
95
+ ).pipe(
96
+ Layer.provide(
97
+ Layer.mergeAll(
98
+ RpcSerialization.layerNdjson,
99
+ NodeHttpServer.layerTest,
100
+ NodeServices.layer,
101
+ ),
102
+ ),
103
+ )
104
+
105
+ const executorLayer = (mode: Mode, options: ExecutorOptions = {}) =>
106
+ mode === "local" ? localExecutor(options) : rpcExecutor(options)
107
+
108
+ const systemText = (prompt: Prompt.Prompt): string =>
109
+ prompt.content
110
+ .filter((message) => message.role === "system")
111
+ .map((message) => message.content)
112
+ .join("\n")
113
+
114
+ // A script that does not reach `taskComplete` leads to a second model call;
115
+ // its tool result carries the script's output, including any thrown error.
116
+ const lastToolResult = (prompt: Prompt.Prompt): string => {
117
+ const message = prompt.content.findLast((message) => message.role === "tool")
118
+ if (message === undefined) return ""
119
+ return message.content
120
+ .map((part) => (part.type === "tool-result" ? String(part.result) : ""))
121
+ .join("")
122
+ }
123
+
124
+ const toolCall = (script: string): Response.StreamPartEncoded => ({
125
+ type: "tool-call",
126
+ id: "call-1",
127
+ name: "execute",
128
+ params: { script },
129
+ })
130
+
131
+ /**
132
+ * Runs one script through the Agent and returns the system prompt the model
133
+ * saw and the summary passed to `taskComplete`.
134
+ */
135
+ const runAgent = <LoopTools extends Toolkit.Any = never>(options: {
136
+ readonly mode: Mode
137
+ readonly executor?: ExecutorOptions | undefined
138
+ readonly agent?: Agent.Options<LoopTools> | undefined
139
+ readonly handlers?: Layer.Layer<Agent.LoopToolServices<LoopTools>> | undefined
140
+ readonly script: string
141
+ }) =>
142
+ Effect.gen(function* () {
143
+ let system = ""
144
+ let calls = 0
145
+ const languageModel = yield* LanguageModel.make({
146
+ generateText: () => Effect.die("unexpected generateText call"),
147
+ streamText: (providerOptions) => {
148
+ if (calls++ > 0) {
149
+ return Stream.die(
150
+ `the script did not call taskComplete: ${lastToolResult(providerOptions.prompt)}`,
151
+ )
152
+ }
153
+ system = systemText(providerOptions.prompt)
154
+ return Stream.make(toolCall(options.script))
155
+ },
156
+ })
157
+ const modelLayer = Layer.mergeAll(
158
+ Layer.succeed(LanguageModel.LanguageModel, languageModel),
159
+ Layer.succeed(Model.ProviderName, "test-provider"),
160
+ Layer.succeed(Model.ModelName, "test-model"),
161
+ )
162
+ const agent = yield* Agent.makeWith(options.agent ?? {})
163
+ const summary = yield* agent.send({ prompt: "hello" }).pipe(
164
+ Effect.flatMap(Stream.runDrain),
165
+ Effect.as(""),
166
+ Effect.catchTag("AgentFinished", (finished) =>
167
+ Effect.succeed(finished.summary),
168
+ ),
169
+ Effect.provide(modelLayer),
170
+ )
171
+ return { system, summary }
172
+ }).pipe(
173
+ Effect.scoped,
174
+ // The executor lives as long as the run, not just the Agent's creation.
175
+ Effect.provide([
176
+ executorLayer(options.mode, options.executor),
177
+ options.handlers ?? Layer.empty,
178
+ ]),
179
+ Effect.timeout("4 seconds"),
180
+ )
181
+
182
+ // A loop-side tool that rejects lines past 50, as janitor rejects lines that
183
+ // are not in the diff.
184
+ const Report = Toolkit.make(
185
+ Tool.make("report", {
186
+ description: "Report a finding on a line of the diff.",
187
+ parameters: Schema.Struct({ line: Schema.Finite }),
188
+ success: Schema.Struct({ line: Schema.Finite }),
189
+ failure: Schema.String,
190
+ }),
191
+ )
192
+
193
+ const reportHandlers = (onCall: (line: number) => Effect.Effect<void>) =>
194
+ Report.toLayer({
195
+ report: ({ line }) =>
196
+ onCall(line).pipe(
197
+ Effect.andThen(
198
+ line > 50
199
+ ? Effect.fail(`line ${line} is not in the diff`)
200
+ : Effect.succeed({ line }),
201
+ ),
202
+ ),
203
+ })
204
+
205
+ // Runs a script on the executor directly, below the Agent.
206
+ const execute = (
207
+ script: string,
208
+ loopTools?: AgentExecutor.LoopToolHandlers | undefined,
209
+ ) =>
210
+ Effect.gen(function* () {
211
+ const executor = yield* AgentExecutor.AgentExecutor
212
+ return yield* executor
213
+ .execute({
214
+ script,
215
+ onTaskComplete: () => Effect.void,
216
+ onImage: () => Effect.void,
217
+ subagents: subagentsUnavailable,
218
+ loopTools,
219
+ })
220
+ .pipe(Stream.mkString)
221
+ })
222
+
223
+ // --- tests -------------------------------------------------------------------
224
+
225
+ // Where the RPC executor takes its own path.
226
+ for (const mode of modes) {
227
+ describe(`${mode} executor`, () => {
228
+ it.live("left-out tools are not offered to the model or the script", () =>
229
+ Effect.gen(function* () {
230
+ const { system, summary } = yield* runAgent({
231
+ mode,
232
+ executor: {
233
+ excludeTools: ["gh", "webSearch", "fetchMarkdown", "delegate"],
234
+ },
235
+ script: `const missing = [typeof gh, typeof webSearch, typeof fetchMarkdown, typeof delegate, typeof waitAgents].join(",")
236
+ let call
237
+ try {
238
+ await gh(["pr", "view"])
239
+ call = "called"
240
+ } catch (error) {
241
+ call = "failed"
242
+ }
243
+ await taskComplete(missing + " " + call)`,
244
+ })
245
+ assert.strictEqual(
246
+ summary,
247
+ "undefined,undefined,undefined,undefined,undefined failed",
248
+ )
249
+ assert.notMatch(
250
+ system,
251
+ /\b(gh|webSearch|fetchMarkdown|delegate|waitAgents|messageAgent|stopAgent|listAgents)\b/,
252
+ )
253
+ assert.include(system, "declare function readFile(")
254
+ }),
255
+ )
256
+
257
+ it.live("a caller tool replaces a left-out built-in of the same name", () =>
258
+ Effect.gen(function* () {
259
+ let calls = 0
260
+ const CallerTools = Toolkit.make(
261
+ Tool.make("readFile", {
262
+ parameters: Schema.Struct({ path: Schema.String }),
263
+ success: Schema.String,
264
+ }),
265
+ )
266
+ const output = yield* execute(
267
+ 'console.log(await readFile({ path: "AGENTS.md" }))',
268
+ ).pipe(
269
+ Effect.provide(
270
+ executorLayer(mode, {
271
+ excludeTools: ["readFile"],
272
+ tools: CallerTools,
273
+ }).pipe(
274
+ Layer.provide(
275
+ CallerTools.toLayer({
276
+ readFile: () =>
277
+ Effect.sync(() => {
278
+ calls++
279
+ return "CALLER"
280
+ }),
281
+ }),
282
+ ),
283
+ ),
284
+ ),
285
+ Effect.scoped,
286
+ Effect.timeout("4 seconds"),
287
+ )
288
+ assert.isTrue(output.endsWith("CALLER\n"))
289
+ assert.strictEqual(calls, 1)
290
+ }),
291
+ )
292
+
293
+ it.live(
294
+ "loop-side tools are declared, decoded on the loop and answer the script",
295
+ () =>
296
+ Effect.gen(function* () {
297
+ // The two valid calls wait for each other: serialized calls never
298
+ // open the latch.
299
+ const bothArrived = yield* Latch.make(false)
300
+ const lines: Array<number> = []
301
+ const { system, summary } = yield* runAgent({
302
+ mode,
303
+ agent: { loopTools: Report },
304
+ handlers: reportHandlers((line) =>
305
+ Effect.gen(function* () {
306
+ if (lines.push(line) === 2) yield* bothArrived.open
307
+ yield* bothArrived.await
308
+ }),
309
+ ),
310
+ script: `const message = (call) => call.then(() => "called", (error) => error.message)
311
+ await taskComplete(JSON.stringify({
312
+ result: await Promise.all([report({ line: 3 }), report({ line: 4 })]),
313
+ invalid: await message(report({ line: "three" })),
314
+ rejected: await message(report({ line: 88 })),
315
+ }))`,
316
+ })
317
+ const { result, invalid, rejected } = JSON.parse(summary)
318
+ assert.deepStrictEqual(result, [{ line: 3 }, { line: 4 }])
319
+ // The rejection names the tool and the argument, and the handler
320
+ // never sees the call.
321
+ assert.include(invalid, "report")
322
+ assert.include(invalid, "line")
323
+ assert.strictEqual(rejected, "line 88 is not in the diff")
324
+ assert.sameMembers(lines, [3, 4, 88])
325
+ assert.include(system, "declare function report(")
326
+ assert.include(system, "Report a finding on a line of the diff.")
327
+ }),
328
+ )
329
+
330
+ it.live("interrupting the run interrupts in-flight loop-side calls", () =>
331
+ Effect.gen(function* () {
332
+ const started = yield* Deferred.make<void>()
333
+ const interrupted = yield* Deferred.make<void>()
334
+ const fiber = yield* Effect.forkChild(
335
+ runAgent({
336
+ mode,
337
+ agent: { loopTools: Report },
338
+ handlers: reportHandlers(() =>
339
+ Deferred.succeed(started, undefined).pipe(
340
+ Effect.andThen(Effect.never),
341
+ Effect.onInterrupt(() =>
342
+ Deferred.succeed(interrupted, undefined),
343
+ ),
344
+ ),
345
+ ),
346
+ script: "await report({ line: 3 })",
347
+ }),
348
+ )
349
+ yield* Deferred.await(started)
350
+ yield* Fiber.interrupt(fiber)
351
+ yield* Deferred.await(interrupted).pipe(Effect.timeout("2 seconds"))
352
+ }),
353
+ )
354
+ })
355
+ }
356
+
357
+ describe("rpc executor", () => {
358
+ it.live("loop-side calls run concurrently within and across scripts", () =>
359
+ Effect.gen(function* () {
360
+ // Every call waits for all four: serialized calls never open the latch.
361
+ const allArrived = yield* Latch.make(false)
362
+ let arrived = 0
363
+ const loopTools: AgentExecutor.LoopToolHandlers = {
364
+ echo: (params) =>
365
+ Effect.gen(function* () {
366
+ if (++arrived === 4) yield* allArrived.open
367
+ yield* allArrived.await
368
+ return params
369
+ }),
370
+ }
371
+ const outputs = yield* Effect.all(
372
+ [
373
+ execute(
374
+ 'console.log((await Promise.all([echo("a1"), echo("a2")])).join())',
375
+ loopTools,
376
+ ),
377
+ execute(
378
+ 'console.log((await Promise.all([echo("b1"), echo("b2")])).join())',
379
+ loopTools,
380
+ ),
381
+ ],
382
+ { concurrency: "unbounded" },
383
+ ).pipe(
384
+ Effect.provide(executorLayer("rpc")),
385
+ Effect.scoped,
386
+ Effect.timeout("4 seconds"),
387
+ )
388
+ assert.isTrue(outputs[0].endsWith("a1,a2\n"))
389
+ assert.isTrue(outputs[1].endsWith("b1,b2\n"))
390
+ }),
391
+ )
392
+ })
393
+
394
+ // Decided by the Agent from the executor's capabilities, whatever the
395
+ // transport.
396
+ describe("agent", () => {
397
+ it.live("a left-out tool is not mentioned anywhere in the prompt", () =>
398
+ Effect.gen(function* () {
399
+ // Each is named outside its own declaration: the delegate bullet, the
400
+ // applyPatch hint and the executor's skills catalog.
401
+ const { system, summary } = yield* runAgent({
402
+ mode: "local",
403
+ executor: { excludeTools: ["waitAgents", "applyPatch", "readFile"] },
404
+ script:
405
+ "await taskComplete([typeof waitAgents, typeof applyPatch, typeof readFile].join())",
406
+ })
407
+ assert.strictEqual(summary, "undefined,undefined,undefined")
408
+ assert.notMatch(system, /\b(waitAgents|applyPatch|readFile)\b/)
409
+ assert.include(system, "declare function delegate(")
410
+ }),
411
+ )
412
+
413
+ it.live("caller instructions and skills replace the executor's", () =>
414
+ Effect.gen(function* () {
415
+ const byDefault = yield* runAgent({
416
+ mode: "local",
417
+ script: 'await taskComplete("ok")',
418
+ })
419
+ assert.include(byDefault.system, "EXECUTOR-AGENTS-MD")
420
+ assert.include(byDefault.system, "executor-skill")
421
+
422
+ const replaced = yield* runAgent({
423
+ mode: "local",
424
+ agent: {
425
+ instructions: Option.some("CALLER-INSTRUCTIONS"),
426
+ skills: [
427
+ {
428
+ name: "caller-skill",
429
+ description: "Caller skill",
430
+ content: "CALLER-SKILL-CONTENT",
431
+ },
432
+ ],
433
+ },
434
+ script: 'await taskComplete(await readSkill("caller-skill"))',
435
+ })
436
+ assert.strictEqual(replaced.summary, "CALLER-SKILL-CONTENT")
437
+ assert.include(replaced.system, "CALLER-INSTRUCTIONS")
438
+ assert.include(replaced.system, "caller-skill: Caller skill")
439
+ assert.notInclude(replaced.system, "EXECUTOR-AGENTS-MD")
440
+ assert.notInclude(replaced.system, "executor-skill")
441
+ // Skill content is only read on demand.
442
+ assert.notInclude(replaced.system, "CALLER-SKILL-CONTENT")
443
+
444
+ const removed = yield* runAgent({
445
+ mode: "local",
446
+ agent: { instructions: Option.none(), skills: [] },
447
+ script: 'await taskComplete("ok")',
448
+ })
449
+ assert.notInclude(removed.system, "EXECUTOR-AGENTS-MD")
450
+ assert.notInclude(removed.system, "# Skills")
451
+ }),
452
+ )
453
+
454
+ it.live("a loop-side tool cannot shadow a built-in tool", () =>
455
+ Effect.gen(function* () {
456
+ const Shadow = Toolkit.make(
457
+ Tool.make("readFile", { parameters: Schema.String }),
458
+ )
459
+ const result = yield* Agent.makeWith({ loopTools: Shadow }).pipe(
460
+ Effect.as("built"),
461
+ Effect.scoped,
462
+ Effect.provide([
463
+ executorLayer("local"),
464
+ Shadow.toLayer({ readFile: () => Effect.void }),
465
+ ]),
466
+ Effect.catchDefect((defect) => Effect.succeed(String(defect))),
467
+ )
468
+ assert.include(result, "readFile")
469
+ assert.notStrictEqual(result, "built")
470
+ }),
471
+ )
472
+
473
+ it.live("a caller readSkill runs when no skills are provided", () =>
474
+ Effect.gen(function* () {
475
+ const CallerTools = Toolkit.make(
476
+ Tool.make("readSkill", {
477
+ parameters: Schema.String,
478
+ success: Schema.String,
479
+ }),
480
+ )
481
+ const { summary } = yield* runAgent({
482
+ mode: "local",
483
+ agent: { loopTools: CallerTools, skills: [] },
484
+ handlers: CallerTools.toLayer({
485
+ readSkill: (name) => Effect.succeed(`CALLER:${name}`),
486
+ }),
487
+ script: 'await taskComplete(await readSkill("anything"))',
488
+ })
489
+ assert.strictEqual(summary, "CALLER:anything")
490
+ }),
491
+ )
492
+ })
493
+
494
+ describe("executor capabilities", () => {
495
+ // Loop and executor are upgraded together, so an executor that does not
496
+ // report its tools is rejected rather than assumed to offer all of them.
497
+ it.effect("require the tools the executor offers", () =>
498
+ Effect.gen(function* () {
499
+ const codec = Schema.toCodecJson(AgentExecutor.Capabilities)
500
+ const encoded = yield* Schema.encodeEffect(codec)(
501
+ new AgentExecutor.Capabilities({
502
+ toolsDts: "",
503
+ agentsMd: Option.none(),
504
+ supportsSearch: false,
505
+ tools: ["readFile"],
506
+ skills: [],
507
+ }),
508
+ )
509
+ const { tools: _, ...older } = encoded as Record<string, Schema.Json>
510
+ const exit = yield* Effect.exit(Schema.decodeUnknownEffect(codec)(older))
511
+ assert.isTrue(Exit.isFailure(exit))
512
+ }),
513
+ )
514
+ })