@lucascouts/claude-agent-tui 0.9.0 → 0.10.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 CHANGED
@@ -25,7 +25,11 @@ This project bridges the two: it drives the **official Claude Code TUI** over a
25
25
  ## Requirements
26
26
 
27
27
  - The **`claude` CLI** (Claude Code subscription) available on your `PATH`.
28
- - **Node.js ≥ 23** — the runtime and test suite use native TypeScript type-stripping.
28
+ - **Node.js ≥ 24** — the runtime and test suite use native TypeScript type-stripping (`node --experimental-strip-types`). Raising this floor from the previous `>=20` is a **breaking change** for consumers still on Node 20–23.
29
+
30
+ > **Why 24, and not upstream's `>=22`?** The floor is a support policy, not a measured minimum: this project targets the **active LTS** line, which is Node 24. It is verified rather than copied — a fresh clone with no host `node_modules` or `dist/`, then `npm ci` → `npm run build` → `npm test`, inside `node:24` pinned by digest `sha256:934240a162082fd8b8a2f90cd5114446443f1eba1c5378f6687167ca405e6584` (Node v24.19.0). Green in both the fork and mirror trees: 1222 tests in the fork, 1183 here, 0 failures.
31
+ >
32
+ > A bare `>=22` cannot keep its own promise: `--experimental-strip-types` only landed in Node 22.6, so `>=22` still admits 22.0–22.5, where `npm install` succeeds and `npm test` cannot start. Any floor of 23 or higher closes that gap.
29
33
 
30
34
  ## Register in Zed
31
35
 
package/dist/index.js CHANGED
@@ -37,6 +37,17 @@ if (process.argv.includes("--cli")) {
37
37
  process.exit(1);
38
38
  });
39
39
  }
40
+ else if (process.argv.includes("--version")) {
41
+ // Story 080 (R3.1–R3.3) — the `--version` flag ported from upstream #813. Matched AFTER `--cli` on
42
+ // purpose: `--cli` is a passthrough to the real binary, so `--cli --version` must report CLAUDE's
43
+ // version, not ours. R3.2 — this branch prints and exits 0 before the ACP bootstrap below is ever
44
+ // reached, so no session is opened, no PTY is spawned and no turn is started. The payload module is
45
+ // imported dynamically so it stays off the hot path of the other two branches. It writes to stdout
46
+ // directly and NOT via console.log, which the branch below rewires to stderr for the ACP protocol.
47
+ const { collectVersionInfo, formatVersionInfo } = await import("./version-info.js");
48
+ process.stdout.write(`${formatVersionInfo(collectVersionInfo())}\n`);
49
+ process.exit(0);
50
+ }
40
51
  else {
41
52
  // Apply env vars from the managed-policy tier before any SDK call so the
42
53
  // SDK subprocess inherits them. Going through resolveSettings (vs. a raw
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Upstream tag currently vendored into src/ — kept in lockstep with `.fork-provenance.json`'s `tag`
3
+ * (re-anchored by sync stories; v0.57.0 came from story 074). A constant rather than a runtime read
4
+ * because the provenance JSON is not published with the package (see the header).
5
+ */
6
+ export declare const FORK_POINT_TAG = "v0.57.0";
7
+ /** Full 40-char upstream commit for {@link FORK_POINT_TAG} — lockstep with `.fork-provenance.json`'s `sha`. */
8
+ export declare const FORK_POINT_SHA = "2bf865eb42bbe744c476d38a005444eab8f4b624";
9
+ /**
10
+ * Printed in place of the `claude` version when the binary is not resolvable on PATH (R3.3).
11
+ *
12
+ * Deliberately carries NO `x.y.z` triple: a reader (or a test) scanning the output for a version must
13
+ * never mistake the marker for one, and a stale pin must never leak in as a consolation value.
14
+ */
15
+ export declare const CLAUDE_UNRESOLVED = "unresolved (not found on PATH)";
16
+ /** The three facts `--version` reports (R3.1). `claudeVersion` is `null` when unresolved/undetected. */
17
+ export interface VersionInfo {
18
+ /** `version` of THIS tree's package.json — read, never pinned (fork 0.5.2 vs mirror 0.8.0, R3.4). */
19
+ packageVersion: string;
20
+ /** Upstream tag the vendored src/ is anchored to ({@link FORK_POINT_TAG}). */
21
+ forkPointTag: string;
22
+ /** Full upstream commit for that tag ({@link FORK_POINT_SHA}). */
23
+ forkPointSha: string;
24
+ /** Live `claude --version`, or `null` when the binary is unresolvable or the probe failed. */
25
+ claudeVersion: string | null;
26
+ }
27
+ /**
28
+ * PURE renderer: three lines, one fact each — package version, fork point (tag + FULL sha), `claude`
29
+ * version or {@link CLAUDE_UNRESOLVED}.
30
+ *
31
+ * Returns a BARE string with NO trailing newline; the caller appends it. Depends only on its argument.
32
+ */
33
+ export declare function formatVersionInfo(info: VersionInfo): string;
34
+ /** Injectable seams for {@link collectVersionInfo} so tests never spawn a real `claude`. */
35
+ export interface VersionInfoDeps {
36
+ /** Override the package.json read (default: {@link readOwnPackageVersion}). */
37
+ readPackageVersion?: () => string;
38
+ /** Override the PATH resolve (default: {@link resolveQuietly}); throwing means "not installed". */
39
+ resolveClaude?: () => string;
40
+ /** Override the version probe (default: `detectClaudeVersion` — claude-path.ts). */
41
+ detectVersion?: (binPath: string) => string | null;
42
+ }
43
+ /**
44
+ * Collect the three `--version` facts (R3.1), degrading instead of failing (R3.3).
45
+ *
46
+ * Every source of truth is an injectable seam with a production default, so the whole payload is
47
+ * unit-checkable without spawning a `claude`. An unresolvable binary costs only the `claudeVersion`
48
+ * field: the package version and the fork point are still collected and nothing escapes to the caller.
49
+ */
50
+ export declare function collectVersionInfo(deps?: VersionInfoDeps): VersionInfo;
@@ -0,0 +1,122 @@
1
+ // === Story 080 / Task 4.2 (R3.1–R3.3) — the `--version` payload: pure collect + pure format ======
2
+ //
3
+ // Ports upstream #813's `--version` flag. The entrypoint (src/index.ts) short-circuits on the flag,
4
+ // prints the three fields this module produces, and exits 0 BEFORE any session is opened, any PTY is
5
+ // spawned or any turn is started (R3.2).
6
+ //
7
+ // WHY ITS OWN MODULE: src/index.ts is a side-effecting entrypoint with a top-level await into the ACP
8
+ // bootstrap — importing it from a test WOULD start the agent. Keeping the collect/format halves here
9
+ // makes them reachable as plain functions, so the whole payload is unit-checkable without a process
10
+ // (the usage-env.ts / live-diff-env.ts precedent). It imports nothing from the ACP, PTY or engine
11
+ // side of the tree, and it is pinned that way by test/version-flag.test.ts.
12
+ //
13
+ // WHY THE FORK POINT IS TWO CONSTANTS, NOT A READ OF .fork-provenance.json: that file is NOT listed in
14
+ // package.json `files`, so a published install ships no such file to read — a runtime read would work
15
+ // in the repo and fail for every user. The constants are instead held in lockstep with the JSON by an
16
+ // assertion in test/version-flag.test.ts, which is what stops them drifting. Same precedent as
17
+ // PROVENANCE_CLAUDE_VERSION in src/claude-path.ts.
18
+ //
19
+ // INVARIANTS:
20
+ // - formatVersionInfo is PURE and returns a BARE 3-line string (no trailing newline — the caller
21
+ // adds it), so the shape is assertable without touching stdout.
22
+ // - collectVersionInfo NEVER throws when `claude` is missing from PATH: the fail-loud resolver error
23
+ // is caught and degraded to `claudeVersion: null`, the remaining fields are still collected, and
24
+ // the entrypoint still exits 0 (R3.3).
25
+ // - The `claude` binary is spawned AT MOST ONCE (see resolveQuietly below), and only to read its
26
+ // version — args-list, no shell, via claude-path.ts's detector.
27
+ //
28
+ // node:test runner: `node --experimental-strip-types --test test/version-flag.test.ts`
29
+ import { readFileSync } from "node:fs";
30
+ import { detectClaudeVersion, resolveClaudePath } from "./claude-path.js";
31
+ /**
32
+ * Upstream tag currently vendored into src/ — kept in lockstep with `.fork-provenance.json`'s `tag`
33
+ * (re-anchored by sync stories; v0.57.0 came from story 074). A constant rather than a runtime read
34
+ * because the provenance JSON is not published with the package (see the header).
35
+ */
36
+ export const FORK_POINT_TAG = "v0.57.0";
37
+ /** Full 40-char upstream commit for {@link FORK_POINT_TAG} — lockstep with `.fork-provenance.json`'s `sha`. */
38
+ export const FORK_POINT_SHA = "2bf865eb42bbe744c476d38a005444eab8f4b624";
39
+ /**
40
+ * Printed in place of the `claude` version when the binary is not resolvable on PATH (R3.3).
41
+ *
42
+ * Deliberately carries NO `x.y.z` triple: a reader (or a test) scanning the output for a version must
43
+ * never mistake the marker for one, and a stale pin must never leak in as a consolation value.
44
+ */
45
+ export const CLAUDE_UNRESOLVED = "unresolved (not found on PATH)";
46
+ /** Fallback for line 1 when the shipped package.json carries no readable `version` string. */
47
+ const UNKNOWN_PACKAGE_VERSION = "unknown";
48
+ /**
49
+ * PURE renderer: three lines, one fact each — package version, fork point (tag + FULL sha), `claude`
50
+ * version or {@link CLAUDE_UNRESOLVED}.
51
+ *
52
+ * Returns a BARE string with NO trailing newline; the caller appends it. Depends only on its argument.
53
+ */
54
+ export function formatVersionInfo(info) {
55
+ return [
56
+ `claude-agent-tui ${info.packageVersion}`,
57
+ `fork point: ${info.forkPointTag} (${info.forkPointSha})`,
58
+ `claude: ${info.claudeVersion ?? CLAUDE_UNRESOLVED}`,
59
+ ].join("\n");
60
+ }
61
+ /**
62
+ * Read `version` out of the package.json that ships NEXT TO this module's own directory.
63
+ *
64
+ * Resolved against `import.meta.url`, not `process.cwd()`, so it reports the installed package's own
65
+ * version from `dist/` no matter where the binary was invoked from. Falls back to
66
+ * {@link UNKNOWN_PACKAGE_VERSION} if the field is missing or not a string.
67
+ */
68
+ function readOwnPackageVersion() {
69
+ const raw = readFileSync(new URL("../package.json", import.meta.url), "utf8");
70
+ const parsed = JSON.parse(raw);
71
+ return typeof parsed.version === "string" ? parsed.version : UNKNOWN_PACKAGE_VERSION;
72
+ }
73
+ /**
74
+ * Resolve `claude` from PATH with the resolver's own observability DISABLED.
75
+ *
76
+ * `resolveClaudePath` normally runs a best-effort `claude --version` probe and logs a resolve/drift
77
+ * line to stderr. Both are unwanted here: `--version` must print the version block and nothing else,
78
+ * and the binary must be spawned exactly once. Passing a null-returning `detectVersion` plus a no-op
79
+ * `log` suppresses the probe and the log, leaving {@link detectResolvedClaudeVersion}'s own detector
80
+ * call the single spawn (measured: one `claude --version`, no other argv). Still THROWS when nothing
81
+ * is on PATH — that fail-loud signal is exactly what R3.3 degrades to `null`.
82
+ */
83
+ function resolveQuietly() {
84
+ return resolveClaudePath({ detectVersion: () => null, log: () => { } });
85
+ }
86
+ /**
87
+ * Resolve `claude`, then read its version — degrading BOTH failure modes to `null` (R3.3).
88
+ *
89
+ * The two steps are deliberately sequential rather than combined: when `resolve` throws (the fail-loud
90
+ * "no claude on PATH" error) this returns EARLY, so `detect` is never handed a path that does not
91
+ * exist. When `detect` itself fails it already answers `null` by contract (`detectClaudeVersion` never
92
+ * throws — claude-path.ts). Either way the caller gets `null` and no exception escapes.
93
+ */
94
+ function detectResolvedClaudeVersion(resolve, detect) {
95
+ let binPath;
96
+ try {
97
+ binPath = resolve();
98
+ }
99
+ catch {
100
+ // A missing `claude` is not an error for `--version`: report the rest and exit 0 (R3.3).
101
+ return null;
102
+ }
103
+ return detect(binPath);
104
+ }
105
+ /**
106
+ * Collect the three `--version` facts (R3.1), degrading instead of failing (R3.3).
107
+ *
108
+ * Every source of truth is an injectable seam with a production default, so the whole payload is
109
+ * unit-checkable without spawning a `claude`. An unresolvable binary costs only the `claudeVersion`
110
+ * field: the package version and the fork point are still collected and nothing escapes to the caller.
111
+ */
112
+ export function collectVersionInfo(deps = {}) {
113
+ const readPackageVersion = deps.readPackageVersion ?? readOwnPackageVersion;
114
+ const resolveClaude = deps.resolveClaude ?? resolveQuietly;
115
+ const detectVersion = deps.detectVersion ?? detectClaudeVersion;
116
+ return {
117
+ packageVersion: readPackageVersion(),
118
+ forkPointTag: FORK_POINT_TAG,
119
+ forkPointSha: FORK_POINT_SHA,
120
+ claudeVersion: detectResolvedClaudeVersion(resolveClaude, detectVersion),
121
+ };
122
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.0",
6
+ "version": "0.10.0",
7
7
  "description": "Run the official Claude Code TUI in Zed's agent panel on your Claude Pro/Max subscription — an ACP-over-PTY bridge created for Anthropic's billing split (paused June 15; see README).",
8
8
  "main": "dist/lib.js",
9
9
  "types": "dist/lib.d.ts",
@@ -60,7 +60,7 @@
60
60
  "author": "lucascouts",
61
61
  "license": "Apache-2.0",
62
62
  "engines": {
63
- "node": ">=20"
63
+ "node": ">=24"
64
64
  },
65
65
  "dependencies": {
66
66
  "@agentclientprotocol/sdk": "1.3.0",
@@ -71,7 +71,7 @@
71
71
  "devDependencies": {
72
72
  "@anthropic-ai/sdk": "0.115.0",
73
73
  "@eslint/js": "10.0.1",
74
- "@types/node": "26.1.1",
74
+ "@types/node": "26.1.2",
75
75
  "@typescript-eslint/eslint-plugin": "8.65.0",
76
76
  "@typescript-eslint/parser": "8.65.0",
77
77
  "eslint": "10.8.0",