clanka 0.14.0 → 0.15.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.
@@ -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
@@ -265,8 +290,18 @@ const acpModel = Flag.String("model").pipe(
265
290
  Flag.map((modelId) => Option.getOrThrow(parseModelId(modelId))),
266
291
  )
267
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
+ Flag.withDefault(false),
300
+ )
301
+
268
302
  const acp = Command.make("acp", {
269
303
  model: acpModel,
304
+ trustAllTools,
270
305
  fast,
271
306
  compaction,
272
307
  apiKey,
@@ -419,6 +454,7 @@ Command.make("clanka", {
419
454
  ),
420
455
  ),
421
456
  Command.withSubcommands([acp]),
457
+ Command.withGlobalFlags([ReportedVersion]),
422
458
  Command.run({
423
459
  version,
424
460
  }),