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
@@ -12,6 +12,7 @@ import * as RpcClient from "effect/rpc/RpcClient"
12
12
  import * as RpcSerialization from "effect/rpc/RpcSerialization"
13
13
  import * as RpcServer from "effect/rpc/RpcServer"
14
14
  import * as AgentExecutor from "./AgentExecutor.ts"
15
+ import { subagentsUnavailable } from "./AgentTools.ts"
15
16
  import type { ImageAttachment } from "./AgentTools.ts"
16
17
  import { equalBytes, supportedImages } from "./fixtures/TestImages.ts"
17
18
 
@@ -83,7 +84,7 @@ describe("RPC image executor", () => {
83
84
  images.push(image)
84
85
  }),
85
86
  onTaskComplete: () => Effect.void,
86
- onSubagent: () => Effect.succeed(""),
87
+ subagents: subagentsUnavailable,
87
88
  })
88
89
  .pipe(Stream.runCollect, Effect.timeout("5 seconds"))
89
90
  assert.strictEqual(images.length, fixtures.length)
@@ -19,6 +19,7 @@ const capabilities = new AgentExecutor.Capabilities({
19
19
  toolsDts: "",
20
20
  agentsMd: Option.none(),
21
21
  supportsSearch: false,
22
+ tools: [],
22
23
  skills: [],
23
24
  })
24
25
 
@@ -264,8 +265,16 @@ describe("Agent images", () => {
264
265
 
265
266
  it.effect("does not copy image bytes into a delegate prompt", () =>
266
267
  Effect.gen(function* () {
267
- const executor = makeExecutor(({ onSubagent }) =>
268
- Stream.fromEffect(onSubagent("child task: describe the layout")),
268
+ const executor = makeExecutor(({ subagents }) =>
269
+ Stream.fromEffect(
270
+ subagents.delegate({
271
+ prompt: "child task: describe the layout",
272
+ background: false,
273
+ }),
274
+ ).pipe(
275
+ Stream.map((result) => result.output ?? ""),
276
+ Stream.orDie,
277
+ ),
269
278
  )
270
279
  const { exit, calls } = yield* runAgent({
271
280
  prompt: imagePrompt,
@@ -4,6 +4,7 @@
4
4
  /** @effect-diagnostics schemaNumber:off */
5
5
  import * as Prompt from "effect/ai/Prompt"
6
6
  import * as AiError from "effect/ai/AiError"
7
+ import * as Effect from "effect/Effect"
7
8
  import * as Schema from "effect/Schema"
8
9
 
9
10
  /**
@@ -127,6 +128,14 @@ export class SubagentStart extends Schema.TaggedClass<SubagentStart>()(
127
128
  prompt: Schema.String,
128
129
  model: Schema.String,
129
130
  provider: Schema.String,
131
+ /**
132
+ * Background agents report only their start and completion; their
133
+ * output is not streamed.
134
+ */
135
+ background: Schema.Boolean.pipe(
136
+ Schema.withDecodingDefaultKey(Effect.succeed(false)),
137
+ Schema.withConstructorDefault(Effect.succeed(false)),
138
+ ),
130
139
  },
131
140
  ) {
132
141
  get modelAndProvider() {
@@ -142,7 +151,14 @@ export class SubagentComplete extends Schema.TaggedClass<SubagentComplete>()(
142
151
  "SubagentComplete",
143
152
  {
144
153
  id: Schema.Number,
154
+ /**
155
+ * The agent's final output, or the error message when it failed.
156
+ */
145
157
  summary: Schema.String,
158
+ status: Schema.Literals(["completed", "failed", "cancelled"]).pipe(
159
+ Schema.withDecodingDefaultKey(Effect.succeed("completed" as const)),
160
+ Schema.withConstructorDefault(Effect.succeed("completed" as const)),
161
+ ),
146
162
  },
147
163
  ) {}
148
164
 
@@ -239,12 +255,51 @@ export class SubagentPart extends Schema.TaggedClass<SubagentPart>()(
239
255
  },
240
256
  ) {}
241
257
 
258
+ /**
259
+ * Emitted when messages are committed to the agent's history: the user
260
+ * prompt, steering messages, and each model step's response and tool
261
+ * results. Applying `HistoryAppended` and `HistoryReplaced` in order to the
262
+ * history the agent started `send` with reproduces `agent.history`, minus
263
+ * the system message, which is rebuilt on every `send`.
264
+ *
265
+ * Only the top-level agent emits history events. Subagents have no history.
266
+ *
267
+ * @since 1.0.0
268
+ * @category Output
269
+ */
270
+ export class HistoryAppended extends Schema.TaggedClass<HistoryAppended>()(
271
+ "HistoryAppended",
272
+ {
273
+ messages: Schema.Array(Prompt.Message),
274
+ },
275
+ ) {}
276
+
277
+ /**
278
+ * Emitted when compaction rewrites the agent's history. `messages` is the
279
+ * whole new history, without the system message.
280
+ *
281
+ * @since 1.0.0
282
+ * @category Output
283
+ */
284
+ export class HistoryReplaced extends Schema.TaggedClass<HistoryReplaced>()(
285
+ "HistoryReplaced",
286
+ {
287
+ messages: Schema.Array(Prompt.Message),
288
+ },
289
+ ) {}
290
+
242
291
  /**
243
292
  * @since 1.0.0
244
293
  * @category Output
245
294
  */
246
295
  export type Output =
247
- AgentStart | ContentPart | SubagentStart | SubagentComplete | SubagentPart
296
+ | AgentStart
297
+ | ContentPart
298
+ | SubagentStart
299
+ | SubagentComplete
300
+ | SubagentPart
301
+ | HistoryAppended
302
+ | HistoryReplaced
248
303
 
249
304
  /**
250
305
  * @since 1.0.0
@@ -256,6 +311,8 @@ export const Output = Schema.Union([
256
311
  SubagentStart,
257
312
  SubagentComplete,
258
313
  SubagentPart,
314
+ HistoryAppended,
315
+ HistoryReplaced,
259
316
  ])
260
317
 
261
318
  /**
@@ -268,3 +325,19 @@ export class AgentFinished extends Schema.TaggedError<AgentFinished>()(
268
325
  summary: Schema.String,
269
326
  },
270
327
  ) {}
328
+
329
+ /**
330
+ * The `send` stream fails with this error when a model call, or a turn that
331
+ * hit `TurnTimeout`, was retried `MaxRetries` times in a row and still failed.
332
+ * `error` is the last failure.
333
+ *
334
+ * @since 1.0.0
335
+ * @category Output
336
+ */
337
+ export class RetriesExhausted extends Schema.TaggedError<RetriesExhausted>()(
338
+ "RetriesExhausted",
339
+ {
340
+ retries: Schema.Number,
341
+ error: AiError.AiError,
342
+ },
343
+ ) {}
@@ -523,6 +523,7 @@ describe("AgentSkills", () => {
523
523
  toolsDts: "",
524
524
  agentsMd: Option.none(),
525
525
  supportsSearch: false,
526
+ tools: [],
526
527
  })
527
528
  assert.deepStrictEqual(capabilities.skills, [])
528
529
  })
@@ -836,6 +837,7 @@ const makeExecutor = (skills: ReadonlyArray<AgentSkills.Skill>) =>
836
837
  toolsDts: "",
837
838
  agentsMd: Option.none(),
838
839
  supportsSearch: false,
840
+ tools: [],
839
841
  skills,
840
842
  }),
841
843
  ),
@@ -149,6 +149,49 @@ paths when accessing them.
149
149
  ${entries}`)
150
150
  }
151
151
 
152
+ /**
153
+ * A skill supplied by the caller instead of discovered on the executor. Its
154
+ * content stays on the loop side and is read with `readSkill`.
155
+ *
156
+ * @since 1.0.0
157
+ * @category Models
158
+ */
159
+ export class ProvidedSkill extends Schema.Class<ProvidedSkill>("ProvidedSkill")(
160
+ {
161
+ name: Schema.String,
162
+ description: Schema.String,
163
+ content: Schema.String,
164
+ },
165
+ ) {}
166
+
167
+ /**
168
+ * Render the skills prompt section for caller-supplied skills, or `None` for
169
+ * an empty catalog.
170
+ *
171
+ * @since 1.0.0
172
+ * @category Rendering
173
+ */
174
+ export const renderProvidedCatalog = (
175
+ skills: ReadonlyArray<ProvidedSkill>,
176
+ ): Option.Option<string> => {
177
+ if (skills.length === 0) return Option.none()
178
+ const entries = skills
179
+ .map(
180
+ (skill) =>
181
+ `- ${singleLine(skill.name)}: ${singleLine(skill.description)}`,
182
+ )
183
+ .join("\n")
184
+ return Option.some(`# Skills
185
+
186
+ The following skills are available. Each one has instructions for a specific
187
+ kind of task.
188
+
189
+ When a task matches a skill's description, call "readSkill" with its name
190
+ BEFORE proceeding, then follow the instructions it returns.
191
+
192
+ ${entries}`)
193
+ }
194
+
152
195
  const Frontmatter = Schema.Struct({
153
196
  name: Schema.optional(Schema.Unknown),
154
197
  description: Schema.String,