clanka 0.13.2 → 0.15.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.
@@ -0,0 +1,99 @@
1
+ import { assert, describe, it } from "@effect/vitest"
2
+ import * as NodeServices from "@effect/platform-node/NodeServices"
3
+ import * as Effect from "effect/Effect"
4
+ import * as FileSystem from "effect/FileSystem"
5
+ import { execFile, spawn } from "node:child_process"
6
+ import * as Path from "node:path"
7
+ import * as Readline from "node:readline"
8
+
9
+ const cli = Path.join(import.meta.dirname, "cli.ts")
10
+
11
+ // Runs the CLI with its config and cache files kept out of the user's home.
12
+ const cliEnv = Effect.gen(function* () {
13
+ const fs = yield* FileSystem.FileSystem
14
+ const configHome = yield* fs.makeTempDirectoryScoped()
15
+ return { ...process.env, XDG_CONFIG_HOME: configHome }
16
+ })
17
+
18
+ const run = (args: ReadonlyArray<string>) =>
19
+ Effect.gen(function* () {
20
+ const env = yield* cliEnv
21
+ return yield* Effect.promise(
22
+ () =>
23
+ new Promise<string>((resolve, reject) =>
24
+ execFile(
25
+ process.execPath,
26
+ [cli, ...args],
27
+ { env },
28
+ (error, stdout) => (error ? reject(error) : resolve(stdout)),
29
+ ),
30
+ ),
31
+ )
32
+ })
33
+
34
+ // Starts `clanka <args>` as an ACP server and returns its reply to
35
+ // `initialize`.
36
+ const initialize = (args: ReadonlyArray<string>) =>
37
+ Effect.gen(function* () {
38
+ const env = yield* cliEnv
39
+ const child = yield* Effect.acquireRelease(
40
+ Effect.sync(() => spawn(process.execPath, [cli, ...args], { env })),
41
+ (child) => Effect.sync(() => child.kill()),
42
+ )
43
+ child.stdin.write(
44
+ `${JSON.stringify({
45
+ jsonrpc: "2.0",
46
+ id: 1,
47
+ method: "initialize",
48
+ params: { protocolVersion: 1 },
49
+ })}\n`,
50
+ )
51
+ return yield* Effect.promise(
52
+ () =>
53
+ new Promise<any>((resolve, reject) => {
54
+ let output = ""
55
+ child.stderr.on("data", (chunk) => {
56
+ output += chunk
57
+ })
58
+ const lines = Readline.createInterface({ input: child.stdout })
59
+ lines.on("line", (line) => {
60
+ if (!line.startsWith("{")) {
61
+ output += `${line}\n`
62
+ return
63
+ }
64
+ const message = JSON.parse(line)
65
+ if (message.id === 1) resolve(message)
66
+ })
67
+ child.on("exit", (code) =>
68
+ reject(new Error(`clanka exited with code ${code}:\n${output}`)),
69
+ )
70
+ }),
71
+ )
72
+ })
73
+
74
+ describe("cli", () => {
75
+ it.effect(
76
+ "prints the --reported-version override for --version",
77
+ () =>
78
+ Effect.gen(function* () {
79
+ const stdout = yield* run(["--reported-version", "2.33.0", "--version"])
80
+ assert.include(stdout, "2.33.0")
81
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
82
+ 60_000,
83
+ )
84
+
85
+ it.effect(
86
+ "runs acp with --trust-all-tools and the --reported-version override",
87
+ () =>
88
+ Effect.gen(function* () {
89
+ const response = yield* initialize([
90
+ "--reported-version",
91
+ "2.33.0",
92
+ "acp",
93
+ "--trust-all-tools",
94
+ ])
95
+ assert.strictEqual(response.result.agentInfo.version, "2.33.0")
96
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
97
+ 60_000,
98
+ )
99
+ })
package/src/cli.ts CHANGED
@@ -4,6 +4,7 @@ import * as Prompt from "effect/cli/Prompt"
4
4
  import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient"
5
5
  import * as Command from "effect/cli/Command"
6
6
  import * as Flag from "effect/cli/Flag"
7
+ import * as GlobalFlag from "effect/cli/GlobalFlag"
7
8
  import * as NodeServices from "@effect/platform-node/NodeServices"
8
9
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime"
9
10
  import * as GlobalWebSocket from "./GlobalWebSocket.ts"
@@ -29,7 +30,31 @@ import { OpenAiClient, OpenAiEmbeddingModel } from "@effect/ai-openai"
29
30
  import * as DeviceCodeHandler from "./DeviceCodeHandler.ts"
30
31
  import packageJson from "../package.json" with { type: "json" }
31
32
 
32
- const version = packageJson.version
33
+ // `--reported-version` replaces the version clanka reports, for `--version`
34
+ // and to ACP clients, so it can pass the version gates of kiro launchers such
35
+ // as Multica. The built-in `--version` prints the version given to
36
+ // `Command.run`, so the value is read from argv before the CLI parses it.
37
+ const ReportedVersion = GlobalFlag.Setting("reported-version")({
38
+ flag: Flag.String("reported-version").pipe(
39
+ Flag.withDescription(
40
+ "Report this version instead of clanka's own, for --version and to ACP clients",
41
+ ),
42
+ Flag.optional,
43
+ ),
44
+ })
45
+
46
+ const reportedVersion = (args: ReadonlyArray<string>) => {
47
+ for (const [index, arg] of args.entries()) {
48
+ if (arg === "--") return undefined
49
+ if (arg === "--reported-version") return args[index + 1]
50
+ if (arg.startsWith("--reported-version=")) {
51
+ return arg.slice("--reported-version=".length)
52
+ }
53
+ }
54
+ return undefined
55
+ }
56
+
57
+ const version = reportedVersion(process.argv.slice(2)) ?? packageJson.version
33
58
 
34
59
  // node:http instead of undici: the undici package adds ~15 MB of RSS on top of
35
60
  // the HTTP stack Node loads anyway, and unlike fetch it imposes no request
@@ -142,6 +167,16 @@ const apiUrl = Flag.String("api-url").pipe(
142
167
  Flag.optional,
143
168
  )
144
169
 
170
+ // OpenAI's `priority` service tier.
171
+ const fast = Flag.Boolean("fast").pipe(
172
+ Flag.withDescription(
173
+ "Use OpenAI fast mode (the priority service tier) for faster responses at a higher cost. Applies to the openai provider only; also CLANKA_FAST=true.",
174
+ ),
175
+ Flag.withFallbackConfig(
176
+ Config.Boolean("CLANKA_FAST").pipe(Config.withDefault(false)),
177
+ ),
178
+ )
179
+
145
180
  const semantic = Flag.Directory("search").pipe(
146
181
  Flag.withDescription(
147
182
  "Directory for semantic search data (uses OPENAI_API_KEY env var)",
@@ -255,8 +290,18 @@ const acpModel = Flag.String("model").pipe(
255
290
  Flag.map((modelId) => Option.getOrThrow(parseModelId(modelId))),
256
291
  )
257
292
 
293
+ // kiro launchers pass it to every `acp` run; clanka has no tool permissions to
294
+ // skip.
295
+ const trustAllTools = Flag.Boolean("trust-all-tools").pipe(
296
+ Flag.withDescription(
297
+ "Accepted for kiro-cli compatibility. Has no effect: clanka runs every tool call without asking.",
298
+ ),
299
+ )
300
+
258
301
  const acp = Command.make("acp", {
259
302
  model: acpModel,
303
+ trustAllTools,
304
+ fast,
260
305
  compaction,
261
306
  apiKey,
262
307
  apiUrl,
@@ -264,13 +309,15 @@ const acp = Command.make("acp", {
264
309
  Command.withDescription(
265
310
  "Run as an Agent Client Protocol (ACP) server over stdio",
266
311
  ),
267
- Command.withHandler(({ model, apiKey, apiUrl }) =>
312
+ Command.withHandler(({ model, fast, apiKey, apiUrl }) =>
268
313
  Effect.gen(function* () {
269
314
  const repo = yield* ModelsRepo.ModelsRepo
270
315
  return yield* Acp.runStdio({
271
316
  version,
272
317
  defaultModel: model.model,
273
318
  defaultThoughtLevel: model.thoughtLevel,
319
+ defaultFastMode: fast,
320
+ supportsFastMode: ModelLayer.acpSupportsFastMode,
274
321
  availableModels: Effect.map(repo.models, ModelLayer.acpModels),
275
322
  makeAgent: (cwd) =>
276
323
  Agent.make.pipe(
@@ -299,6 +346,7 @@ const acp = Command.make("acp", {
299
346
  Command.make("clanka", {
300
347
  provider,
301
348
  model,
349
+ fast,
302
350
  semantic,
303
351
  prompt,
304
352
  compaction,
@@ -311,6 +359,7 @@ Command.make("clanka", {
311
359
  Effect.fnUntraced(function* ({
312
360
  provider,
313
361
  model: modelRaw,
362
+ fast,
314
363
  semantic,
315
364
  prompt: nonInteractivePrompt,
316
365
  apiKey,
@@ -337,10 +386,16 @@ Command.make("clanka", {
337
386
  },
338
387
  onNone: () => selectModel(provider),
339
388
  })
340
- const Model = ModelLayer.make(provider, model, effort, {
341
- apiKey: Option.getOrUndefined(apiKey),
342
- apiUrl: Option.getOrUndefined(apiUrl),
343
- })
389
+ const Model = ModelLayer.make(
390
+ provider,
391
+ model,
392
+ effort,
393
+ {
394
+ apiKey: Option.getOrUndefined(apiKey),
395
+ apiUrl: Option.getOrUndefined(apiUrl),
396
+ },
397
+ fast,
398
+ )
344
399
 
345
400
  return yield* Effect.gen(function* () {
346
401
  const agent = yield* Agent.Agent
@@ -398,6 +453,7 @@ Command.make("clanka", {
398
453
  ),
399
454
  ),
400
455
  Command.withSubcommands([acp]),
456
+ Command.withGlobalFlags([ReportedVersion]),
401
457
  Command.run({
402
458
  version,
403
459
  }),