clanka 0.16.1 → 0.17.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.
Files changed (85) hide show
  1. package/README.md +61 -0
  2. package/dist/Agent.d.ts.map +1 -1
  3. package/dist/Agent.js +5 -1
  4. package/dist/Agent.js.map +1 -1
  5. package/dist/AgentCallerConfig.test.js +5 -3
  6. package/dist/AgentCallerConfig.test.js.map +1 -1
  7. package/dist/ChunkRepo.d.ts +1 -1
  8. package/dist/ClaudeAgent.d.ts +111 -0
  9. package/dist/ClaudeAgent.d.ts.map +1 -0
  10. package/dist/ClaudeAgent.js +772 -0
  11. package/dist/ClaudeAgent.js.map +1 -0
  12. package/dist/ClaudeAgent.test.d.ts +2 -0
  13. package/dist/ClaudeAgent.test.d.ts.map +1 -0
  14. package/dist/ClaudeAgent.test.js +416 -0
  15. package/dist/ClaudeAgent.test.js.map +1 -0
  16. package/dist/Compaction.test.js +2 -1
  17. package/dist/Compaction.test.js.map +1 -1
  18. package/dist/CompactionTokens.test.js +15 -8
  19. package/dist/CompactionTokens.test.js.map +1 -1
  20. package/dist/ModelLayer.d.ts +2 -2
  21. package/dist/ModelLayer.d.ts.map +1 -1
  22. package/dist/ModelLayer.js +13 -7
  23. package/dist/ModelLayer.js.map +1 -1
  24. package/dist/ModelLayer.test.js +3 -0
  25. package/dist/ModelLayer.test.js.map +1 -1
  26. package/dist/ModelsRepo.d.ts +7 -6
  27. package/dist/ModelsRepo.d.ts.map +1 -1
  28. package/dist/ModelsRepo.js +44 -27
  29. package/dist/ModelsRepo.js.map +1 -1
  30. package/dist/ModelsRepo.test.js +47 -3
  31. package/dist/ModelsRepo.test.js.map +1 -1
  32. package/dist/bin/{Effect-4B1lzxy4.mjs → Effect-DNYYQ84C.mjs} +467 -365
  33. package/dist/bin/Effect-DNYYQ84C.mjs.map +1 -0
  34. package/dist/bin/Latch-BSlIwuxI.mjs +7 -0
  35. package/dist/bin/Latch-BSlIwuxI.mjs.map +1 -0
  36. package/dist/bin/{McpClient-DMfHHEx3.mjs → McpClient-C7ctqJWo.mjs} +4 -5
  37. package/dist/bin/{McpClient-DMfHHEx3.mjs.map → McpClient-C7ctqJWo.mjs.map} +1 -1
  38. package/dist/bin/{OutputFormatter-DRycCEdr.mjs → OutputFormatter-DXej05JW.mjs} +8 -13
  39. package/dist/bin/{OutputFormatter-DRycCEdr.mjs.map → OutputFormatter-DXej05JW.mjs.map} +1 -1
  40. package/dist/bin/{Schema-D4fxUgEU.mjs → Schema-CSQN_Zso.mjs} +754 -800
  41. package/dist/bin/Schema-CSQN_Zso.mjs.map +1 -0
  42. package/dist/bin/{SemanticSearch-BcLFv9qz.mjs → SemanticSearch-BiwCnpKX.mjs} +241 -148
  43. package/dist/bin/SemanticSearch-BiwCnpKX.mjs.map +1 -0
  44. package/dist/bin/{Stream-i37nF1ep.mjs → Stream-Dwvj9X5X.mjs} +244 -120
  45. package/dist/bin/Stream-Dwvj9X5X.mjs.map +1 -0
  46. package/dist/bin/cli.mjs +5122 -15959
  47. package/dist/bin/cli.mjs.map +1 -1
  48. package/dist/bin/helpers-CljL9OKa.mjs +7157 -0
  49. package/dist/bin/helpers-CljL9OKa.mjs.map +1 -0
  50. package/dist/bin/index.min-ClUfQ5ji.mjs +3782 -0
  51. package/dist/bin/index.min-ClUfQ5ji.mjs.map +1 -0
  52. package/dist/bin/{rolldown-runtime-zY4HT0JA.mjs → rolldown-runtime-5zChB7MF.mjs} +15 -3
  53. package/dist/bin/server-HlLriZxF.mjs +319 -0
  54. package/dist/bin/server-HlLriZxF.mjs.map +1 -0
  55. package/dist/bin/{turndown.cjs-LntFxFyd.mjs → turndown.cjs-C2WBxeA-.mjs} +56 -110
  56. package/dist/bin/{turndown.cjs-LntFxFyd.mjs.map → turndown.cjs-C2WBxeA-.mjs.map} +1 -1
  57. package/dist/bin/types-LcwjLVkt.mjs +5260 -0
  58. package/dist/bin/types-LcwjLVkt.mjs.map +1 -0
  59. package/dist/bin/upgrade-BSNjCnra.mjs +342 -0
  60. package/dist/bin/upgrade-BSNjCnra.mjs.map +1 -0
  61. package/dist/cli.js +4 -0
  62. package/dist/cli.js.map +1 -1
  63. package/dist/index.d.ts +4 -0
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +4 -0
  66. package/dist/index.js.map +1 -1
  67. package/package.json +15 -13
  68. package/src/Agent.ts +7 -1
  69. package/src/AgentCallerConfig.test.ts +5 -3
  70. package/src/ClaudeAgent.test.ts +526 -0
  71. package/src/ClaudeAgent.ts +1113 -0
  72. package/src/Compaction.test.ts +2 -1
  73. package/src/CompactionTokens.test.ts +15 -11
  74. package/src/ModelLayer.test.ts +4 -0
  75. package/src/ModelLayer.ts +21 -15
  76. package/src/ModelsRepo.test.ts +69 -3
  77. package/src/ModelsRepo.ts +24 -8
  78. package/src/cli.ts +4 -0
  79. package/src/index.ts +5 -0
  80. package/dist/bin/Effect-4B1lzxy4.mjs.map +0 -1
  81. package/dist/bin/Schema-D4fxUgEU.mjs.map +0 -1
  82. package/dist/bin/SemanticSearch-BcLFv9qz.mjs.map +0 -1
  83. package/dist/bin/Stream-i37nF1ep.mjs.map +0 -1
  84. package/dist/bin/index.min-Bkz7vIWv.mjs +0 -3300
  85. package/dist/bin/index.min-Bkz7vIWv.mjs.map +0 -1
@@ -439,7 +439,8 @@ describe("Compaction.isContextLengthError", () => {
439
439
  openAiError(
440
440
  new AiError.NetworkError({
441
441
  reason: "TransportError",
442
- request,
442
+ method: request.method,
443
+ url: request.url,
443
444
  description: "socket timeout",
444
445
  }),
445
446
  ),
@@ -10,14 +10,15 @@ const user = (value: string) =>
10
10
  Prompt.makeMessage("user", { content: [text(value)] })
11
11
 
12
12
  // Estimation treats image payloads as opaque; no image decoder is involved.
13
- const imageMessage = (size: number) =>
13
+ const imageBytes = (size: number) => new Uint8Array(size).fill(137)
14
+ const imageMessage = (data: string | Uint8Array) =>
14
15
  Prompt.makeMessage("user", {
15
16
  content: [
16
17
  text("Describe this screenshot"),
17
18
  Prompt.makePart("file", {
18
19
  mediaType: "image/png",
19
20
  fileName: "screenshot.png",
20
- data: new Uint8Array(size).fill(137),
21
+ data,
21
22
  }),
22
23
  ],
23
24
  })
@@ -52,9 +53,15 @@ const toolResult = (result: string) =>
52
53
  })
53
54
 
54
55
  describe("Compaction image token estimates", () => {
55
- for (const representation of ["binary", "reloaded base64"] as const) {
56
+ // Older releases persisted image bytes as plain base64 strings, so those
57
+ // histories still reload with string data.
58
+ for (const representation of ["binary", "base64", "reloaded"] as const) {
56
59
  const history = (size: number) => {
57
- const prompt = Prompt.fromMessages([imageMessage(size)])
60
+ const bytes = imageBytes(size)
61
+ if (representation === "base64") {
62
+ return reload(Prompt.fromMessages([imageMessage(Base64.encode(bytes))]))
63
+ }
64
+ const prompt = Prompt.fromMessages([imageMessage(bytes)])
58
65
  return representation === "binary" ? prompt : reload(prompt)
59
66
  }
60
67
 
@@ -130,8 +137,8 @@ describe("Compaction image token estimates", () => {
130
137
  })
131
138
  }
132
139
 
133
- it("preserves estimates across the binary-to-base64 persistence round trip", () => {
134
- const prompt = Prompt.fromMessages([imageMessage(1024)])
140
+ it("preserves binary data and estimates across the persistence round trip", () => {
141
+ const prompt = Prompt.fromMessages([imageMessage(imageBytes(1024))])
135
142
  const restored = reload(prompt)
136
143
  const message = restored.content[0]!
137
144
  assert.strictEqual(message.role, "user")
@@ -139,10 +146,7 @@ describe("Compaction image token estimates", () => {
139
146
  const image = message.content[1]!
140
147
  assert.strictEqual(image.type, "file")
141
148
  if (image.type !== "file") return
142
- assert.strictEqual(
143
- image.data,
144
- Base64.encode(new Uint8Array(1024).fill(137)),
145
- )
149
+ assert.deepStrictEqual(image.data, imageBytes(1024))
146
150
  assert.strictEqual(
147
151
  Compaction.estimateTokens(restored),
148
152
  Compaction.estimateTokens(prompt),
@@ -154,7 +158,7 @@ describe("Compaction image token estimates", () => {
154
158
  })
155
159
 
156
160
  it("charges for each image rather than ignoring all file parts", () => {
157
- const one = imageMessage(32)
161
+ const one = imageMessage(imageBytes(32))
158
162
  const two = Prompt.makeMessage("user", {
159
163
  content: [...one.content, one.content[1]!],
160
164
  })
@@ -132,4 +132,8 @@ describe("ModelLayer.makeAcp", () => {
132
132
  it("rejects ids that are not <provider>:<model>", () => {
133
133
  assert.isTrue(Option.isNone(makeModel("nope", "high")))
134
134
  })
135
+
136
+ it("builds claude models", () => {
137
+ assert.isTrue(Option.isSome(makeModel("claude:claude-opus-5-5", "high")))
138
+ })
135
139
  })
package/src/ModelLayer.ts CHANGED
@@ -13,6 +13,7 @@ import * as Option from "effect/Option"
13
13
  import * as Schema from "effect/Schema"
14
14
  import { ThoughtLevel } from "./Acp.ts"
15
15
  import * as Agent from "./Agent.ts"
16
+ import * as ClaudeAgent from "./ClaudeAgent.ts"
16
17
  import * as Codex from "./Codex.ts"
17
18
  import * as Copilot from "./Copilot.ts"
18
19
  import * as ModelsRepo from "./ModelsRepo.ts"
@@ -59,21 +60,26 @@ export const make = (
59
60
  const openaiOptions = fastMode
60
61
  ? { ...options, service_tier: "priority" }
61
62
  : options
62
- return provider === "openai"
63
- ? openai.apiKey !== undefined
64
- ? withSubagentModel(Codex.model(model, openaiOptions)).pipe(
65
- Layer.provide(OpenAiClient.layer(openai)),
66
- )
67
- : withSubagentModel(Codex.modelWebSocket(model, openaiOptions)).pipe(
68
- Layer.provide(Codex.layerClient),
69
- )
70
- : provider === "xai"
71
- ? withSubagentModel(Xai.modelWebSocket(model, options)).pipe(
72
- Layer.provide(Xai.layerClient),
73
- )
74
- : withSubagentModel(Copilot.model(model, options)).pipe(
75
- Layer.provide(Copilot.layerClient),
76
- )
63
+ switch (provider) {
64
+ case "openai":
65
+ return openai.apiKey !== undefined
66
+ ? withSubagentModel(Codex.model(model, openaiOptions)).pipe(
67
+ Layer.provide(OpenAiClient.layer(openai)),
68
+ )
69
+ : withSubagentModel(Codex.modelWebSocket(model, openaiOptions)).pipe(
70
+ Layer.provide(Codex.layerClient),
71
+ )
72
+ case "xai":
73
+ return withSubagentModel(Xai.modelWebSocket(model, options)).pipe(
74
+ Layer.provide(Xai.layerClient),
75
+ )
76
+ case "claude":
77
+ return withSubagentModel(ClaudeAgent.model(model, { effort }))
78
+ case "copilot":
79
+ return withSubagentModel(Copilot.model(model, options)).pipe(
80
+ Layer.provide(Copilot.layerClient),
81
+ )
82
+ }
77
83
  }
78
84
 
79
85
  const isProvider = Schema.is(ModelsRepo.Provider)
@@ -98,11 +98,26 @@ const apiJson = {
98
98
  id: "anthropic",
99
99
  name: "Anthropic",
100
100
  models: {
101
- "claude-opus-5.5": {
102
- id: "claude-opus-5.5",
101
+ "claude-opus-5-5": {
102
+ id: "claude-opus-5-5",
103
103
  name: "Claude Opus 5.5",
104
104
  tool_call: true,
105
105
  reasoning: true,
106
+ reasoning_options: [
107
+ { type: "effort", values: ["low", "medium", "high", "xhigh", "max"] },
108
+ ],
109
+ },
110
+ },
111
+ },
112
+ google: {
113
+ id: "google",
114
+ name: "Google",
115
+ models: {
116
+ "gemini-4-pro": {
117
+ id: "gemini-4-pro",
118
+ name: "Gemini 4 Pro",
119
+ tool_call: true,
120
+ reasoning: true,
106
121
  },
107
122
  },
108
123
  },
@@ -115,6 +130,12 @@ const catalog = [
115
130
  name: "Claude Fable 5.1",
116
131
  efforts: ["low", "high"],
117
132
  }),
133
+ new ModelsRepo.ModelInfo({
134
+ provider: "claude",
135
+ id: "claude-opus-5-5",
136
+ name: "Claude Opus 5.5",
137
+ efforts: ["low", "medium", "high", "xhigh", "max"],
138
+ }),
118
139
  new ModelsRepo.ModelInfo({
119
140
  provider: "openai",
120
141
  id: "gpt-6-astra",
@@ -135,6 +156,23 @@ const catalog = [
135
156
  }),
136
157
  ]
137
158
 
159
+ const provider = (prefix: string, count: number, year: number) => ({
160
+ models: Object.fromEntries(
161
+ Array.from({ length: count }, (_, i) => {
162
+ const id = `${prefix}-${i}`
163
+ return [
164
+ id,
165
+ {
166
+ id,
167
+ name: id,
168
+ release_date: `${year}-01-${String(i + 1).padStart(2, "0")}`,
169
+ tool_call: true,
170
+ },
171
+ ]
172
+ }),
173
+ ),
174
+ })
175
+
138
176
  const online = HttpClient.make((request) =>
139
177
  Effect.succeed(
140
178
  HttpClientResponse.fromWeb(
@@ -176,7 +214,7 @@ const modelsWith = (client: HttpClient.HttpClient) =>
176
214
 
177
215
  describe("ModelsRepo.layerModelsDev", () => {
178
216
  it.effect(
179
- "lists the openai, copilot and xai text models that accept tool calls",
217
+ "lists the openai, copilot, xai and anthropic text models that accept tool calls",
180
218
  () =>
181
219
  Effect.gen(function* () {
182
220
  assert.deepStrictEqual(yield* modelsWith(online), catalog)
@@ -231,6 +269,34 @@ describe("ModelsRepo.layerModelsDev", () => {
231
269
  }).pipe(Effect.provide(KeyValueStore.layerMemory)),
232
270
  )
233
271
 
272
+ it.effect("caps each provider at its 10 newest models", () =>
273
+ Effect.gen(function* () {
274
+ const client = HttpClient.make((request) =>
275
+ Effect.succeed(
276
+ HttpClientResponse.fromWeb(
277
+ request,
278
+ new Response(
279
+ JSON.stringify({
280
+ openai: provider("gpt", 12, 2026),
281
+ anthropic: provider("claude", 12, 2025),
282
+ }),
283
+ { headers: { "content-type": "application/json" } },
284
+ ),
285
+ ),
286
+ ),
287
+ )
288
+ const models = yield* modelsWith(client)
289
+ assert.strictEqual(
290
+ models.filter((m) => m.provider === "openai").length,
291
+ 10,
292
+ )
293
+ assert.deepStrictEqual(
294
+ models.filter((m) => m.provider === "claude").map((m) => m.id),
295
+ Array.from({ length: 10 }, (_, i) => `claude-${11 - i}`),
296
+ )
297
+ }).pipe(Effect.provide(KeyValueStore.layerMemory)),
298
+ )
299
+
234
300
  it.effect("serves an expired cached catalog when the refresh fails", () =>
235
301
  Effect.gen(function* () {
236
302
  yield* modelsWith(online)
package/src/ModelsRepo.ts CHANGED
@@ -23,7 +23,7 @@ import { ThoughtLevel } from "./Acp.ts"
23
23
  * @since 1.0.0
24
24
  * @category Models
25
25
  */
26
- export const Provider = Schema.Literals(["openai", "copilot", "xai"])
26
+ export const Provider = Schema.Literals(["openai", "copilot", "xai", "claude"])
27
27
 
28
28
  /**
29
29
  * @since 1.0.0
@@ -76,6 +76,12 @@ export const fallback: ReadonlyArray<ModelInfo> = [
76
76
  name: "Grok 4.6",
77
77
  efforts: ["low", "medium", "high", "xhigh"],
78
78
  }),
79
+ new ModelInfo({
80
+ provider: "claude",
81
+ id: "claude-opus-5-5",
82
+ name: "Claude Opus 5.5",
83
+ efforts: ["low", "medium", "high", "xhigh", "max"],
84
+ }),
79
85
  ]
80
86
 
81
87
  // The fields of a models.dev model entry the catalog reads. Entries are
@@ -106,6 +112,7 @@ const providerIds: ReadonlyArray<readonly [string, Provider]> = [
106
112
  ["openai", "openai"],
107
113
  ["github-copilot", "copilot"],
108
114
  ["xai", "xai"],
115
+ ["anthropic", "claude"],
109
116
  ]
110
117
 
111
118
  const ModelsDevApi = Schema.Struct(
@@ -117,8 +124,9 @@ const ModelsDevApi = Schema.Struct(
117
124
  const decodeModel = Schema.decodeUnknownOption(ModelsDevModel)
118
125
  const isThoughtLevel = Schema.is(ThoughtLevel)
119
126
 
120
- const toCatalog = (api: typeof ModelsDevApi.Type): ReadonlyArray<ModelInfo> =>
121
- providerIds
127
+ const toCatalog = (api: typeof ModelsDevApi.Type): ReadonlyArray<ModelInfo> => {
128
+ const counts = new Map<Provider, number>()
129
+ return providerIds
122
130
  .flatMap(([id, provider]) =>
123
131
  Object.values(api[id]?.models ?? {}).flatMap((entry) => {
124
132
  const model = Option.getOrUndefined(decodeModel(entry))
@@ -138,7 +146,13 @@ const toCatalog = (api: typeof ModelsDevApi.Type): ReadonlyArray<ModelInfo> =>
138
146
  (b.release_date ?? "").localeCompare(a.release_date ?? "") ||
139
147
  a.name.localeCompare(b.name),
140
148
  )
141
- .slice(0, 10)
149
+ .filter((model) => {
150
+ // Keep the 10 newest per provider, so providers that list many models
151
+ // (or the same models as another provider) cannot crowd out the rest.
152
+ const count = (counts.get(model.provider) ?? 0) + 1
153
+ counts.set(model.provider, count)
154
+ return count <= 10
155
+ })
142
156
  .map((model) => {
143
157
  const effort = model.reasoning_options?.find(
144
158
  (option) => option.type === "effort",
@@ -150,6 +164,7 @@ const toCatalog = (api: typeof ModelsDevApi.Type): ReadonlyArray<ModelInfo> =>
150
164
  efforts: (effort?.values ?? []).filter(isThoughtLevel),
151
165
  })
152
166
  })
167
+ }
153
168
 
154
169
  class CachedCatalog extends Schema.Class<CachedCatalog>(
155
170
  "clanka/ModelsRepo/CachedCatalog",
@@ -185,10 +200,11 @@ export class ModelsRepo extends Context.Service<
185
200
 
186
201
  /**
187
202
  * The catalog built from `https://models.dev/api.json`: the `openai`,
188
- * `github-copilot` and `xai` text models that are not deprecated and accept
189
- * tool calls. Keeps the 10 newest models by release date, then name
190
- * alphabetically, with undated models last. Cached in the `KeyValueStore`
191
- * for `ttl` (default 24 hours).
203
+ * `github-copilot`, `xai` and `anthropic` (as `claude`) text models that
204
+ * are not deprecated and accept tool calls. Keeps the 10 newest models of
205
+ * each provider by release date, then name alphabetically, with undated
206
+ * models last. The combined catalog is in that same order. Cached
207
+ * in the `KeyValueStore` for `ttl` (default 24 hours).
192
208
  * Serves the cached catalog when the fetch fails, then `fallback`.
193
209
  *
194
210
  * @since 1.0.0
package/src/cli.ts CHANGED
@@ -151,6 +151,10 @@ const provider = Flag.Literals("provider", providers).pipe(
151
151
  title: "xai",
152
152
  value: "xai",
153
153
  },
154
+ {
155
+ title: "claude",
156
+ value: "claude",
157
+ },
154
158
  ],
155
159
  }),
156
160
  ),
package/src/index.ts CHANGED
@@ -24,6 +24,11 @@ export * as AgentOutput from "./AgentOutput.ts"
24
24
  */
25
25
  export * as AgentTools from "./AgentTools.ts"
26
26
 
27
+ /**
28
+ * @since 1.0.0
29
+ */
30
+ export * as ClaudeAgent from "./ClaudeAgent.ts"
31
+
27
32
  /**
28
33
  * @since 1.0.0
29
34
  */