clanka 0.17.3 → 0.18.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.
- package/README.md +24 -0
- package/dist/Acp.d.ts.map +1 -1
- package/dist/Acp.js +5 -0
- package/dist/Acp.js.map +1 -1
- package/dist/Agent.d.ts +11 -0
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +35 -15
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +23 -0
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentExecutor.js +15 -2
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +16 -0
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentOutput.d.ts +23 -4
- package/dist/AgentOutput.d.ts.map +1 -1
- package/dist/AgentOutput.js +19 -0
- package/dist/AgentOutput.js.map +1 -1
- package/dist/ClaudeAgent.d.ts.map +1 -1
- package/dist/ClaudeAgent.js +37 -4
- package/dist/ClaudeAgent.js.map +1 -1
- package/dist/ClaudeAgent.test.js +82 -0
- package/dist/ClaudeAgent.test.js.map +1 -1
- package/dist/Codex.js +9 -5
- package/dist/Codex.js.map +1 -1
- package/dist/Codex.test.js +26 -7
- package/dist/Codex.test.js.map +1 -1
- package/dist/Compaction.d.ts +41 -6
- package/dist/Compaction.d.ts.map +1 -1
- package/dist/Compaction.js +52 -11
- package/dist/Compaction.js.map +1 -1
- package/dist/Compaction.test.js +5 -4
- package/dist/Compaction.test.js.map +1 -1
- package/dist/CompactionTransport.test.js +11 -0
- package/dist/CompactionTransport.test.js.map +1 -1
- package/dist/Copilot.d.ts.map +1 -1
- package/dist/Copilot.js +3 -6
- package/dist/Copilot.js.map +1 -1
- package/dist/ModelLayer.d.ts +35 -6
- package/dist/ModelLayer.d.ts.map +1 -1
- package/dist/ModelLayer.js +30 -18
- package/dist/ModelLayer.js.map +1 -1
- package/dist/ModelLayer.test.js +11 -3
- package/dist/ModelLayer.test.js.map +1 -1
- package/dist/OutputFormatter.d.ts.map +1 -1
- package/dist/OutputFormatter.js +3 -0
- package/dist/OutputFormatter.js.map +1 -1
- package/dist/Xai.d.ts.map +1 -1
- package/dist/Xai.js +4 -12
- package/dist/Xai.js.map +1 -1
- package/dist/bin/{Effect-DNYYQ84C.mjs → Effect-5XYMLOiB.mjs} +31 -30
- package/dist/bin/Effect-5XYMLOiB.mjs.map +1 -0
- package/dist/bin/{Latch-BSlIwuxI.mjs → Latch-BnrpWMd1.mjs} +2 -2
- package/dist/bin/{Latch-BSlIwuxI.mjs.map → Latch-BnrpWMd1.mjs.map} +1 -1
- package/dist/bin/{McpClient-C7ctqJWo.mjs → McpClient-DoPNaNzW.mjs} +3 -3
- package/dist/bin/{McpClient-C7ctqJWo.mjs.map → McpClient-DoPNaNzW.mjs.map} +1 -1
- package/dist/bin/{OutputFormatter-DXej05JW.mjs → OutputFormatter-Dqxyk2qD.mjs} +4 -3
- package/dist/bin/{OutputFormatter-DXej05JW.mjs.map → OutputFormatter-Dqxyk2qD.mjs.map} +1 -1
- package/dist/bin/{Schema-CSQN_Zso.mjs → Schema-Box_9VZG.mjs} +6 -3
- package/dist/bin/{Schema-CSQN_Zso.mjs.map → Schema-Box_9VZG.mjs.map} +1 -1
- package/dist/bin/{SemanticSearch-BiwCnpKX.mjs → SemanticSearch-CH125AHH.mjs} +4 -4
- package/dist/bin/{SemanticSearch-BiwCnpKX.mjs.map → SemanticSearch-CH125AHH.mjs.map} +1 -1
- package/dist/bin/{Stream-Dwvj9X5X.mjs → Stream-C51usiew.mjs} +3 -3
- package/dist/bin/{Stream-Dwvj9X5X.mjs.map → Stream-C51usiew.mjs.map} +1 -1
- package/dist/bin/cli.mjs +321 -225
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/bin/{upgrade-BSNjCnra.mjs → upgrade-HMRGSqq8.mjs} +4 -4
- package/dist/bin/{upgrade-BSNjCnra.mjs.map → upgrade-HMRGSqq8.mjs.map} +1 -1
- package/dist/cli.js +45 -5
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/Acp.ts +7 -0
- package/src/Agent.test.ts +27 -0
- package/src/Agent.ts +49 -15
- package/src/AgentExecutor.test.ts +23 -1
- package/src/AgentExecutor.ts +16 -2
- package/src/AgentOutput.ts +23 -0
- package/src/ClaudeAgent.test.ts +113 -0
- package/src/ClaudeAgent.ts +51 -4
- package/src/Codex.test.ts +37 -9
- package/src/Codex.ts +25 -20
- package/src/Compaction.test.ts +18 -15
- package/src/Compaction.ts +89 -20
- package/src/CompactionTransport.test.ts +36 -0
- package/src/Copilot.ts +5 -6
- package/src/ModelLayer.test.ts +17 -2
- package/src/ModelLayer.ts +68 -22
- package/src/OutputFormatter.ts +3 -0
- package/src/Xai.ts +8 -12
- package/src/cli.ts +97 -5
- package/dist/bin/Effect-DNYYQ84C.mjs.map +0 -1
|
@@ -15,6 +15,7 @@ import * as HttpClientResponse from "effect/http/HttpClientResponse"
|
|
|
15
15
|
import * as Codex from "./Codex.ts"
|
|
16
16
|
import * as Compaction from "./Compaction.ts"
|
|
17
17
|
import * as Copilot from "./Copilot.ts"
|
|
18
|
+
import * as Xai from "./Xai.ts"
|
|
18
19
|
|
|
19
20
|
const user = (text: string) =>
|
|
20
21
|
Prompt.makeMessage("user", {
|
|
@@ -225,4 +226,39 @@ describe("Compaction provider transport", () => {
|
|
|
225
226
|
assert.strictEqual(continuation.stream, true)
|
|
226
227
|
}),
|
|
227
228
|
)
|
|
229
|
+
|
|
230
|
+
it.effect(
|
|
231
|
+
"summarizes on the SummarizerModel without the agent model's transform",
|
|
232
|
+
() =>
|
|
233
|
+
Effect.gen(function* () {
|
|
234
|
+
const http = captureHttp()
|
|
235
|
+
yield* compact.pipe(
|
|
236
|
+
Effect.provide(
|
|
237
|
+
Layer.mergeAll(
|
|
238
|
+
// xAI caps summaries with max_output_tokens on the same
|
|
239
|
+
// client Codex uses, so a leaked transform would show up.
|
|
240
|
+
Xai.model("grok-4.6").pipe(
|
|
241
|
+
Layer.provide(
|
|
242
|
+
OpenAiClient.layer({ apiUrl: "https://xai.test" }),
|
|
243
|
+
),
|
|
244
|
+
),
|
|
245
|
+
Compaction.layerSummarizerModel(
|
|
246
|
+
Codex.model("gpt-6-astra").pipe(
|
|
247
|
+
Layer.provide(
|
|
248
|
+
OpenAiClient.layer({ apiUrl: "https://codex.test" }),
|
|
249
|
+
),
|
|
250
|
+
),
|
|
251
|
+
),
|
|
252
|
+
).pipe(Layer.provide(http.layer)),
|
|
253
|
+
),
|
|
254
|
+
Effect.exit,
|
|
255
|
+
)
|
|
256
|
+
assert.strictEqual(http.requests.length, 1)
|
|
257
|
+
assert.strictEqual(
|
|
258
|
+
http.requests[0]!.url,
|
|
259
|
+
"https://codex.test/responses",
|
|
260
|
+
)
|
|
261
|
+
assert.isFalse("max_output_tokens" in body(http.requests[0]!))
|
|
262
|
+
}),
|
|
263
|
+
)
|
|
228
264
|
})
|
package/src/Copilot.ts
CHANGED
|
@@ -42,14 +42,13 @@ export const model = (
|
|
|
42
42
|
config: Struct.omit(
|
|
43
43
|
options ?? {},
|
|
44
44
|
options?.reasoning === null
|
|
45
|
-
? ["reasoning",
|
|
46
|
-
:
|
|
45
|
+
? ["reasoning", ...AgentModelConfig.optionKeys]
|
|
46
|
+
: AgentModelConfig.optionKeys,
|
|
47
47
|
),
|
|
48
48
|
}),
|
|
49
|
-
AgentModelConfig.layer(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}),
|
|
49
|
+
AgentModelConfig.layer(
|
|
50
|
+
Struct.pick(options ?? {}, AgentModelConfig.optionKeys),
|
|
51
|
+
),
|
|
53
52
|
// Cap compaction summaries; Copilot honours max_output_tokens.
|
|
54
53
|
Layer.succeed(Compaction.SummarizerTransform, (effect) =>
|
|
55
54
|
OpenAiLanguageModel.withConfigOverride(effect, {
|
package/src/ModelLayer.test.ts
CHANGED
|
@@ -11,6 +11,7 @@ import * as HttpClientResponse from "effect/http/HttpClientResponse"
|
|
|
11
11
|
import * as KeyValueStore from "effect/persistence/KeyValueStore"
|
|
12
12
|
import * as Socket from "effect/socket/Socket"
|
|
13
13
|
import type * as Acp from "./Acp.ts"
|
|
14
|
+
import * as Agent from "./Agent.ts"
|
|
14
15
|
import { DeviceCodeHandler } from "./DeviceCodeHandler.ts"
|
|
15
16
|
import * as ModelLayer from "./ModelLayer.ts"
|
|
16
17
|
import * as ModelsRepo from "./ModelsRepo.ts"
|
|
@@ -40,6 +41,7 @@ const makeModel = ModelLayer.makeAcp({
|
|
|
40
41
|
apiKey: Redacted.make("test-key"),
|
|
41
42
|
apiUrl: "https://codex.test",
|
|
42
43
|
},
|
|
44
|
+
auxiliary: { subagent: { provider: "openai", model: "gpt-4.1" } },
|
|
43
45
|
})
|
|
44
46
|
|
|
45
47
|
// The other providers' login and socket services, which the API-key openai
|
|
@@ -55,11 +57,12 @@ const unused = Layer.mergeAll(
|
|
|
55
57
|
)
|
|
56
58
|
|
|
57
59
|
// The request body the model for `modelId` sends at session thought level
|
|
58
|
-
// `thoughtLevel`.
|
|
60
|
+
// `thoughtLevel`, or its sub-agent model with `subagent`.
|
|
59
61
|
const requestBody = Effect.fnUntraced(function* (
|
|
60
62
|
modelId: string,
|
|
61
63
|
thoughtLevel: Acp.ThoughtLevel = "high",
|
|
62
64
|
fastMode = false,
|
|
65
|
+
subagent = false,
|
|
63
66
|
) {
|
|
64
67
|
const requests: Array<HttpClientRequest.HttpClientRequest> = []
|
|
65
68
|
const client = HttpClient.make((request) =>
|
|
@@ -72,9 +75,12 @@ const requestBody = Effect.fnUntraced(function* (
|
|
|
72
75
|
}),
|
|
73
76
|
)
|
|
74
77
|
const model = Option.getOrThrow(makeModel(modelId, thoughtLevel, fastMode))
|
|
75
|
-
|
|
78
|
+
const send = Effect.gen(function* () {
|
|
76
79
|
const ai = yield* LanguageModel.LanguageModel
|
|
77
80
|
yield* ai.streamText({ prompt: "hello" }).pipe(Stream.runDrain, Effect.exit)
|
|
81
|
+
})
|
|
82
|
+
yield* Effect.gen(function* () {
|
|
83
|
+
yield* subagent ? Effect.provide(send, yield* Agent.SubagentModel) : send
|
|
78
84
|
}).pipe(
|
|
79
85
|
Effect.provide(
|
|
80
86
|
model.pipe(
|
|
@@ -129,6 +135,15 @@ describe("ModelLayer.makeAcp", () => {
|
|
|
129
135
|
}),
|
|
130
136
|
)
|
|
131
137
|
|
|
138
|
+
it.effect("runs sub-agents on the auxiliary sub-agent model", () =>
|
|
139
|
+
Effect.gen(function* () {
|
|
140
|
+
assert.strictEqual(
|
|
141
|
+
(yield* requestBody("openai:gpt-6-astra", "high", false, true)).model,
|
|
142
|
+
"gpt-4.1",
|
|
143
|
+
)
|
|
144
|
+
}),
|
|
145
|
+
)
|
|
146
|
+
|
|
132
147
|
it("rejects ids that are not <provider>:<model>", () => {
|
|
133
148
|
assert.isTrue(Option.isNone(makeModel("nope", "high")))
|
|
134
149
|
})
|
package/src/ModelLayer.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* @since 1.0.0
|
|
6
6
|
*/
|
|
7
7
|
import { OpenAiClient } from "@effect/ai-openai"
|
|
8
|
-
import type * as LanguageModel from "effect/ai/LanguageModel"
|
|
9
|
-
import type * as Model from "effect/ai/Model"
|
|
10
8
|
import * as Effect from "effect/Effect"
|
|
11
9
|
import * as Layer from "effect/Layer"
|
|
12
10
|
import * as Option from "effect/Option"
|
|
@@ -15,18 +13,11 @@ import { ThoughtLevel } from "./Acp.ts"
|
|
|
15
13
|
import * as Agent from "./Agent.ts"
|
|
16
14
|
import * as ClaudeAgent from "./ClaudeAgent.ts"
|
|
17
15
|
import * as Codex from "./Codex.ts"
|
|
16
|
+
import * as Compaction from "./Compaction.ts"
|
|
18
17
|
import * as Copilot from "./Copilot.ts"
|
|
19
18
|
import * as ModelsRepo from "./ModelsRepo.ts"
|
|
20
19
|
import * as Xai from "./Xai.ts"
|
|
21
20
|
|
|
22
|
-
const withSubagentModel = <E, R>(
|
|
23
|
-
model: Layer.Layer<
|
|
24
|
-
LanguageModel.LanguageModel | Model.ProviderName | Model.ModelName,
|
|
25
|
-
E,
|
|
26
|
-
R
|
|
27
|
-
>,
|
|
28
|
-
) => Layer.merge(model, Agent.layerSubagentModel(model))
|
|
29
|
-
|
|
30
21
|
/**
|
|
31
22
|
* Whether a provider supports fast mode. Only OpenAI does, through the
|
|
32
23
|
* `priority` service tier.
|
|
@@ -38,20 +29,37 @@ export const supportsFastMode = (provider: ModelsRepo.Provider) =>
|
|
|
38
29
|
provider === "openai"
|
|
39
30
|
|
|
40
31
|
/**
|
|
41
|
-
*
|
|
32
|
+
* A provider, model id and reasoning effort. `effort` is `null` for models
|
|
42
33
|
* that take no reasoning effort, and `undefined` to keep the provider's
|
|
43
|
-
* default effort.
|
|
44
|
-
* ignored for providers without fast mode.
|
|
34
|
+
* default effort.
|
|
45
35
|
*
|
|
46
36
|
* @since 1.0.0
|
|
47
|
-
* @category
|
|
37
|
+
* @category Models
|
|
48
38
|
*/
|
|
49
|
-
export
|
|
39
|
+
export interface ModelSpec {
|
|
40
|
+
readonly provider: ModelsRepo.Provider
|
|
41
|
+
readonly model: string
|
|
42
|
+
readonly effort?: string | null | undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The models sub-agents and the compaction summarizer run on, when they
|
|
47
|
+
* should not run on the agent's own model.
|
|
48
|
+
*
|
|
49
|
+
* @since 1.0.0
|
|
50
|
+
* @category Models
|
|
51
|
+
*/
|
|
52
|
+
export interface AuxiliaryModels {
|
|
53
|
+
readonly subagent?: ModelSpec | undefined
|
|
54
|
+
readonly summarizer?: ModelSpec | undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const languageModel = (
|
|
50
58
|
provider: ModelsRepo.Provider,
|
|
51
59
|
model: string,
|
|
52
60
|
effort: string | null | undefined,
|
|
53
61
|
openai: OpenAiClient.Options,
|
|
54
|
-
fastMode
|
|
62
|
+
fastMode: boolean,
|
|
55
63
|
) => {
|
|
56
64
|
const options =
|
|
57
65
|
effort === undefined
|
|
@@ -63,25 +71,61 @@ export const make = (
|
|
|
63
71
|
switch (provider) {
|
|
64
72
|
case "openai":
|
|
65
73
|
return openai.apiKey !== undefined
|
|
66
|
-
?
|
|
74
|
+
? Codex.model(model, openaiOptions).pipe(
|
|
67
75
|
Layer.provide(OpenAiClient.layer(openai)),
|
|
68
76
|
)
|
|
69
|
-
:
|
|
77
|
+
: Codex.modelWebSocket(model, openaiOptions).pipe(
|
|
70
78
|
Layer.provide(Codex.layerClient),
|
|
71
79
|
)
|
|
72
80
|
case "xai":
|
|
73
|
-
return
|
|
81
|
+
return Xai.modelWebSocket(model, options).pipe(
|
|
74
82
|
Layer.provide(Xai.layerClient),
|
|
75
83
|
)
|
|
76
84
|
case "claude":
|
|
77
|
-
return
|
|
85
|
+
return ClaudeAgent.model(model, { effort })
|
|
78
86
|
case "copilot":
|
|
79
|
-
return
|
|
87
|
+
return Copilot.model(model, options).pipe(
|
|
80
88
|
Layer.provide(Copilot.layerClient),
|
|
81
89
|
)
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
|
|
93
|
+
/**
|
|
94
|
+
* The model layer for a provider and model id. `effort` is `null` for models
|
|
95
|
+
* that take no reasoning effort, and `undefined` to keep the provider's
|
|
96
|
+
* default effort. `fastMode` requests the `priority` service tier and is
|
|
97
|
+
* ignored for providers without fast mode; it also applies to the
|
|
98
|
+
* `auxiliary` models.
|
|
99
|
+
*
|
|
100
|
+
* Sub-agents run on `auxiliary.subagent`, or on this model when it is not
|
|
101
|
+
* set. The compaction summarizer runs on `auxiliary.summarizer`, or on the
|
|
102
|
+
* model of the agent that compacts when it is not set.
|
|
103
|
+
*
|
|
104
|
+
* @since 1.0.0
|
|
105
|
+
* @category Layers
|
|
106
|
+
*/
|
|
107
|
+
export const make = (
|
|
108
|
+
provider: ModelsRepo.Provider,
|
|
109
|
+
model: string,
|
|
110
|
+
effort: string | null | undefined,
|
|
111
|
+
openai: OpenAiClient.Options,
|
|
112
|
+
fastMode = false,
|
|
113
|
+
auxiliary?: AuxiliaryModels,
|
|
114
|
+
) => {
|
|
115
|
+
const fromSpec = (spec: ModelSpec) =>
|
|
116
|
+
languageModel(spec.provider, spec.model, spec.effort, openai, fastMode)
|
|
117
|
+
const main = languageModel(provider, model, effort, openai, fastMode)
|
|
118
|
+
return Layer.mergeAll(
|
|
119
|
+
main,
|
|
120
|
+
Agent.layerSubagentModel(
|
|
121
|
+
auxiliary?.subagent === undefined ? main : fromSpec(auxiliary.subagent),
|
|
122
|
+
),
|
|
123
|
+
auxiliary?.summarizer === undefined
|
|
124
|
+
? Layer.empty
|
|
125
|
+
: Compaction.layerSummarizerModel(fromSpec(auxiliary.summarizer)),
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
85
129
|
const isProvider = Schema.is(ModelsRepo.Provider)
|
|
86
130
|
|
|
87
131
|
/**
|
|
@@ -152,7 +196,7 @@ const resolveEffort = (
|
|
|
152
196
|
* A listed model that does not support the session thought level runs at the
|
|
153
197
|
* supported effort nearest to it in `ThoughtLevel` order, the higher one on a
|
|
154
198
|
* tie. Unlisted models run at the session thought level. Fast mode applies
|
|
155
|
-
* to OpenAI models only.
|
|
199
|
+
* to OpenAI models only. Every session uses the same `auxiliary` models.
|
|
156
200
|
*
|
|
157
201
|
* @since 1.0.0
|
|
158
202
|
* @category ACP
|
|
@@ -161,6 +205,7 @@ export const makeAcp =
|
|
|
161
205
|
(options: {
|
|
162
206
|
readonly models: Effect.Effect<ReadonlyArray<ModelsRepo.ModelInfo>>
|
|
163
207
|
readonly openai: OpenAiClient.Options
|
|
208
|
+
readonly auxiliary?: AuxiliaryModels | undefined
|
|
164
209
|
}) =>
|
|
165
210
|
(modelId: string, thoughtLevel: ThoughtLevel, fastMode = false) =>
|
|
166
211
|
Option.map(parseAcpModelId(modelId), ({ provider, model }) =>
|
|
@@ -177,6 +222,7 @@ export const makeAcp =
|
|
|
177
222
|
: resolveEffort(info.efforts, thoughtLevel),
|
|
178
223
|
options.openai,
|
|
179
224
|
fastMode,
|
|
225
|
+
options.auxiliary,
|
|
180
226
|
)
|
|
181
227
|
}),
|
|
182
228
|
),
|
package/src/OutputFormatter.ts
CHANGED
|
@@ -117,6 +117,9 @@ ${chalk.dim(output.summary)}\n\n`
|
|
|
117
117
|
case "CompactionEnded": {
|
|
118
118
|
return `${prefix}${chalkInfoHeading(`${infoIcon} Context compacted (${output.reason}):`)} ~${numberFormat.format(output.tokensBefore)} tokens to ~${numberFormat.format(output.tokensAfter)}\n\n`
|
|
119
119
|
}
|
|
120
|
+
case "SessionRestarted": {
|
|
121
|
+
return `${prefix}${chalkInfoHeading(`${infoIcon} Session restarted (${output.reason}):`)} ${numberFormat.format(output.contextTokens)} context tokens resent, ${numberFormat.format(output.cacheWrite)} cache write\n\n`
|
|
122
|
+
}
|
|
120
123
|
case "EnvironmentUpdated": {
|
|
121
124
|
return `${prefix}${chalkInfoHeading(`${infoIcon} Environment update:`)}\n\n${chalk.dim(truncate(output.update))}\n\n`
|
|
122
125
|
}
|
package/src/Xai.ts
CHANGED
|
@@ -52,8 +52,7 @@ export const model = (
|
|
|
52
52
|
config: {
|
|
53
53
|
...Struct.omit(options ?? {}, [
|
|
54
54
|
"reasoning",
|
|
55
|
-
|
|
56
|
-
"supportsImages",
|
|
55
|
+
...AgentModelConfig.optionKeys,
|
|
57
56
|
]),
|
|
58
57
|
store: options?.store ?? false,
|
|
59
58
|
reasoning:
|
|
@@ -62,10 +61,9 @@ export const model = (
|
|
|
62
61
|
: { effort: "high", ...options?.reasoning },
|
|
63
62
|
},
|
|
64
63
|
}),
|
|
65
|
-
AgentModelConfig.layer(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}),
|
|
64
|
+
AgentModelConfig.layer(
|
|
65
|
+
Struct.pick(options ?? {}, AgentModelConfig.optionKeys),
|
|
66
|
+
),
|
|
69
67
|
// Cap compaction summaries; xAI honours max_output_tokens.
|
|
70
68
|
Layer.succeed(Compaction.SummarizerTransform, (effect) =>
|
|
71
69
|
OpenAiLanguageModel.withConfigOverride(effect, {
|
|
@@ -98,8 +96,7 @@ export const modelWebSocket = (
|
|
|
98
96
|
config: {
|
|
99
97
|
...Struct.omit(options ?? {}, [
|
|
100
98
|
"reasoning",
|
|
101
|
-
|
|
102
|
-
"supportsImages",
|
|
99
|
+
...AgentModelConfig.optionKeys,
|
|
103
100
|
]),
|
|
104
101
|
// xAI needs stored responses to resolve previous_response_id.
|
|
105
102
|
store: true,
|
|
@@ -110,10 +107,9 @@ export const modelWebSocket = (
|
|
|
110
107
|
: { effort: "high", ...options?.reasoning },
|
|
111
108
|
},
|
|
112
109
|
}),
|
|
113
|
-
AgentModelConfig.layer(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}),
|
|
110
|
+
AgentModelConfig.layer(
|
|
111
|
+
Struct.pick(options ?? {}, AgentModelConfig.optionKeys),
|
|
112
|
+
),
|
|
117
113
|
// Cap compaction summaries; xAI honours max_output_tokens.
|
|
118
114
|
Layer.succeed(Compaction.SummarizerTransform, (effect) =>
|
|
119
115
|
OpenAiLanguageModel.withConfigOverride(effect, {
|
package/src/cli.ts
CHANGED
|
@@ -132,6 +132,51 @@ const ModelId = Schema.String.pipe(
|
|
|
132
132
|
),
|
|
133
133
|
)
|
|
134
134
|
|
|
135
|
+
// An `--subagent-model` or `--summarizer-model` value. Without an effort, the
|
|
136
|
+
// provider's default effort is used.
|
|
137
|
+
const auxiliaryModel = (options: {
|
|
138
|
+
readonly name: string
|
|
139
|
+
readonly env: string
|
|
140
|
+
readonly description: string
|
|
141
|
+
}) =>
|
|
142
|
+
Flag.String(options.name).pipe(
|
|
143
|
+
Flag.withDescription(
|
|
144
|
+
`${options.description} As <provider>/<model>[/<effort>], e.g. openai/gpt-6-astra/low; also ${options.env}.`,
|
|
145
|
+
),
|
|
146
|
+
Flag.withFallbackConfig(Config.String(options.env)),
|
|
147
|
+
Flag.withSchema(ModelId),
|
|
148
|
+
Flag.map((modelId): ModelLayer.ModelSpec => {
|
|
149
|
+
const [provider, model, effort] = modelId.split("/") as [
|
|
150
|
+
Provider,
|
|
151
|
+
string,
|
|
152
|
+
string | undefined,
|
|
153
|
+
]
|
|
154
|
+
return { provider, model, effort }
|
|
155
|
+
}),
|
|
156
|
+
Flag.optional,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
const subagentModel = auxiliaryModel({
|
|
160
|
+
name: "subagent-model",
|
|
161
|
+
env: "CLANKA_SUBAGENT_MODEL",
|
|
162
|
+
description: "Run sub-agents on this model instead of the agent's model.",
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const summarizerModel = auxiliaryModel({
|
|
166
|
+
name: "summarizer-model",
|
|
167
|
+
env: "CLANKA_SUMMARIZER_MODEL",
|
|
168
|
+
description:
|
|
169
|
+
"Summarize the history for compaction with this model instead of the agent's model.",
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
const auxiliaryModels = (flags: {
|
|
173
|
+
readonly subagentModel: Option.Option<ModelLayer.ModelSpec>
|
|
174
|
+
readonly summarizerModel: Option.Option<ModelLayer.ModelSpec>
|
|
175
|
+
}): ModelLayer.AuxiliaryModels => ({
|
|
176
|
+
subagent: Option.getOrUndefined(flags.subagentModel),
|
|
177
|
+
summarizer: Option.getOrUndefined(flags.summarizerModel),
|
|
178
|
+
})
|
|
179
|
+
|
|
135
180
|
const provider = Flag.Literals("provider", providers).pipe(
|
|
136
181
|
Flag.withAlias("p"),
|
|
137
182
|
Flag.withFallbackPrompt(
|
|
@@ -209,6 +254,44 @@ const compaction = Flag.Boolean("compaction").pipe(
|
|
|
209
254
|
),
|
|
210
255
|
)
|
|
211
256
|
|
|
257
|
+
const NonNegativeInt = Schema.Int.pipe(
|
|
258
|
+
Schema.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
// A compaction token setting, defaulting to `Compaction.defaultConfig`.
|
|
262
|
+
const tokens = (options: {
|
|
263
|
+
readonly name: string
|
|
264
|
+
readonly env: string
|
|
265
|
+
readonly description: string
|
|
266
|
+
readonly defaultValue: number
|
|
267
|
+
}) =>
|
|
268
|
+
Flag.Int(options.name).pipe(
|
|
269
|
+
Flag.withDescription(
|
|
270
|
+
`${options.description} Defaults to ${options.env} or ${options.defaultValue}.`,
|
|
271
|
+
),
|
|
272
|
+
Flag.withFallbackConfig(
|
|
273
|
+
Config.Int(options.env).pipe(Config.withDefault(options.defaultValue)),
|
|
274
|
+
),
|
|
275
|
+
Flag.withSchema(NonNegativeInt),
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
const compactionThreshold = tokens({
|
|
279
|
+
name: "compaction-threshold",
|
|
280
|
+
env: "CLANKA_COMPACTION_THRESHOLD",
|
|
281
|
+
description:
|
|
282
|
+
"Compact once the context exceeds this many tokens, or the context window minus its reserve when that is lower.",
|
|
283
|
+
defaultValue: Compaction.defaultConfig.thresholdTokens,
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
const compactionConfig = (flags: {
|
|
287
|
+
readonly compaction: boolean
|
|
288
|
+
readonly compactionThreshold: number
|
|
289
|
+
}) =>
|
|
290
|
+
Compaction.CompactionConfig.layer({
|
|
291
|
+
enabled: flags.compaction,
|
|
292
|
+
thresholdTokens: flags.compactionThreshold,
|
|
293
|
+
})
|
|
294
|
+
|
|
212
295
|
// Kill switch: `--no-mcp` or CLANKA_MCP=false.
|
|
213
296
|
const mcp = Flag.Boolean("mcp").pipe(
|
|
214
297
|
Flag.withDescription(
|
|
@@ -319,13 +402,16 @@ const acp = Command.make("acp", {
|
|
|
319
402
|
trustAllTools,
|
|
320
403
|
fast,
|
|
321
404
|
compaction,
|
|
405
|
+
compactionThreshold,
|
|
406
|
+
subagentModel,
|
|
407
|
+
summarizerModel,
|
|
322
408
|
apiKey,
|
|
323
409
|
apiUrl,
|
|
324
410
|
}).pipe(
|
|
325
411
|
Command.withDescription(
|
|
326
412
|
"Run as an Agent Client Protocol (ACP) server over stdio",
|
|
327
413
|
),
|
|
328
|
-
Command.withHandler(({ model, fast, apiKey, apiUrl }) =>
|
|
414
|
+
Command.withHandler(({ model, fast, apiKey, apiUrl, ...flags }) =>
|
|
329
415
|
Effect.gen(function* () {
|
|
330
416
|
const repo = yield* ModelsRepo.ModelsRepo
|
|
331
417
|
const defaultThoughtLevel = yield* reasoning
|
|
@@ -349,16 +435,17 @@ const acp = Command.make("acp", {
|
|
|
349
435
|
apiKey: Option.getOrUndefined(apiKey),
|
|
350
436
|
apiUrl: Option.getOrUndefined(apiUrl),
|
|
351
437
|
},
|
|
438
|
+
auxiliary: auxiliaryModels(flags),
|
|
352
439
|
}),
|
|
353
440
|
})
|
|
354
441
|
}),
|
|
355
442
|
),
|
|
356
|
-
Command.provide((
|
|
443
|
+
Command.provide((flags) =>
|
|
357
444
|
Layer.mergeAll(
|
|
358
445
|
Agent.ConversationMode.layer(false),
|
|
359
446
|
Layer.succeed(Logger.LogToStderr, true),
|
|
360
447
|
DeviceCodeHandler.layerLog,
|
|
361
|
-
|
|
448
|
+
compactionConfig(flags),
|
|
362
449
|
),
|
|
363
450
|
),
|
|
364
451
|
)
|
|
@@ -370,6 +457,9 @@ Command.make("clanka", {
|
|
|
370
457
|
semantic,
|
|
371
458
|
prompt,
|
|
372
459
|
compaction,
|
|
460
|
+
compactionThreshold,
|
|
461
|
+
subagentModel,
|
|
462
|
+
summarizerModel,
|
|
373
463
|
apiKey,
|
|
374
464
|
apiUrl,
|
|
375
465
|
mcp,
|
|
@@ -386,6 +476,7 @@ Command.make("clanka", {
|
|
|
386
476
|
apiUrl,
|
|
387
477
|
mcp,
|
|
388
478
|
mcpConfig,
|
|
479
|
+
...flags
|
|
389
480
|
}) {
|
|
390
481
|
const stdio = yield* Stdio.Stdio
|
|
391
482
|
const mcpServers = yield* McpConfig.load({
|
|
@@ -415,6 +506,7 @@ Command.make("clanka", {
|
|
|
415
506
|
apiUrl: Option.getOrUndefined(apiUrl),
|
|
416
507
|
},
|
|
417
508
|
fast,
|
|
509
|
+
auxiliaryModels(flags),
|
|
418
510
|
)
|
|
419
511
|
|
|
420
512
|
return yield* Effect.gen(function* () {
|
|
@@ -466,10 +558,10 @@ Command.make("clanka", {
|
|
|
466
558
|
)
|
|
467
559
|
}),
|
|
468
560
|
),
|
|
469
|
-
Command.provide(({ prompt,
|
|
561
|
+
Command.provide(({ prompt, ...flags }) =>
|
|
470
562
|
Layer.mergeAll(
|
|
471
563
|
Agent.ConversationMode.layer(Option.isNone(prompt)),
|
|
472
|
-
|
|
564
|
+
compactionConfig(flags),
|
|
473
565
|
),
|
|
474
566
|
),
|
|
475
567
|
Command.withSubcommands([acp]),
|