@lucascouts/claude-agent-tui 0.17.5 → 0.17.7
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/dist/acp-agent.d.ts +39 -0
- package/dist/acp-agent.js +110 -6
- package/dist/add-dir-trust.d.ts +48 -0
- package/dist/add-dir-trust.js +119 -0
- package/dist/permissions/gate-wiring.js +3 -0
- package/package.json +6 -6
package/dist/acp-agent.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type { DetectorSchedule, EndOfTurnDetector } from "./end-of-turn.js";
|
|
|
19
19
|
import { type SupportedModelsSource } from "./live-model-catalog.js";
|
|
20
20
|
import { type AgentCatalogEntry } from "./agent-catalog.js";
|
|
21
21
|
import type { SessionGate, SessionGateOptions } from "./permissions/gate-wiring.js";
|
|
22
|
+
import { AddDirTrustWatcher } from "./add-dir-trust.js";
|
|
22
23
|
export declare const CLAUDE_CONFIG_DIR: string;
|
|
23
24
|
/**
|
|
24
25
|
* Logger interface for customizing logging output
|
|
@@ -90,6 +91,12 @@ type Session = {
|
|
|
90
91
|
* is the RAW list (per-dir sanitization is the engine's job); absent on pre-057 / replay records.
|
|
91
92
|
*/
|
|
92
93
|
additionalDirectories?: string[];
|
|
94
|
+
/**
|
|
95
|
+
* Parity round 26 (item 238): watches the claude PTY for the `--add-dir` trust dialog, which
|
|
96
|
+
* claude 2.1.326+ opens for a folder it does not trust yet. Asked at the first prompt, because the
|
|
97
|
+
* client does not know the session id during `session/new`. Absent when the session added no folder.
|
|
98
|
+
*/
|
|
99
|
+
addDirTrust?: AddDirTrustWatcher;
|
|
93
100
|
/**
|
|
94
101
|
* Story 057 (R2.3/R2.4, sub-task 2.3) — the CURRENT MCP scratch path ({@link writeMcpScratch})
|
|
95
102
|
* threaded into this session's spawn as `--mcp-config "<file>"`. Retained so {@link teardownSession}
|
|
@@ -246,6 +253,13 @@ type Session = {
|
|
|
246
253
|
* `onExit` hook both call `gate.teardown()` (idempotent).
|
|
247
254
|
*/
|
|
248
255
|
gate?: SessionGate;
|
|
256
|
+
/**
|
|
257
|
+
* The current PTY's exit hook that tears the gate down. Kept so a re-spawn can drop it before it
|
|
258
|
+
* kills the old PTY: otherwise that exit would tear down the gate the new PTY still uses.
|
|
259
|
+
*/
|
|
260
|
+
gateExitHook?: {
|
|
261
|
+
dispose(): void;
|
|
262
|
+
};
|
|
249
263
|
/**
|
|
250
264
|
* Story 044 (R2.2/R2.3) — the per-session Option-B sub-agent watcher: polls the story-041 SDK
|
|
251
265
|
* sidechain readers while a `Task`/`Agent` spawn is OPEN on the main chain, feeding turn liveness
|
|
@@ -294,6 +308,12 @@ export interface StartedEngine {
|
|
|
294
308
|
export interface StartEngineArgs {
|
|
295
309
|
/** Requested session id (resume/fork). Undefined for a fresh session (engine generates it). */
|
|
296
310
|
sessionId?: string;
|
|
311
|
+
/**
|
|
312
|
+
* Parity round 26 (item 238): called with the claude PTY the instant it is spawned, before any
|
|
313
|
+
* await. node-pty does not buffer output for a listener that attaches later, and claude draws its
|
|
314
|
+
* `--add-dir` trust dialog once, early: a tap attached after the model catalogue read would miss it.
|
|
315
|
+
*/
|
|
316
|
+
onSpawn?: (pty: IPty) => void;
|
|
297
317
|
/** Host working directory the TUI spawns in. */
|
|
298
318
|
cwd: string;
|
|
299
319
|
/** True when reattaching to a prior session (story 014 robust resume argv). */
|
|
@@ -886,6 +906,25 @@ export declare class ClaudeAcpAgent {
|
|
|
886
906
|
* their current values, so the resume argv always carries all three flags.
|
|
887
907
|
*/
|
|
888
908
|
private respawnSession;
|
|
909
|
+
/**
|
|
910
|
+
* Retire a re-spawned session's previous claude. The gate's exit hook on that PTY is dropped first,
|
|
911
|
+
* so its exit does not tear down the gate the new PTY uses; then the PTY is killed BEFORE cleanup(),
|
|
912
|
+
* because SessionEngine.kill() is inert once the engine is disposed (R3.4) — the old order, cleanup()
|
|
913
|
+
* then kill(), left the previous claude running until the adapter exited (found 2026-11-25).
|
|
914
|
+
*/
|
|
915
|
+
private retireEngine;
|
|
916
|
+
/** Parity round 26 (item 238): a trust-dialog watcher for a PTY started with `--add-dir` folders. */
|
|
917
|
+
private watchAddDirTrust;
|
|
918
|
+
/**
|
|
919
|
+
* Parity round 26 (item 238): ask the client about each folder claude's trust dialog names, then
|
|
920
|
+
* answer it. Yes types `2` and claude goes on; No (or a cancelled request) starts claude again
|
|
921
|
+
* without that folder, through the same pre-interaction re-spawn a mode change uses, because
|
|
922
|
+
* claude's own "No, exit" ends the process. Refusing is never silent: it is logged and the folder
|
|
923
|
+
* leaves the session's scope. Bounded by the folder count, since each round settles one folder.
|
|
924
|
+
*/
|
|
925
|
+
private resolveAddDirTrust;
|
|
926
|
+
/** Parity round 26 (item 238): one permission request for one folder of the trust dialog. */
|
|
927
|
+
private askAddDirTrust;
|
|
889
928
|
/** Story 046 — the session's current effort configOption value (undefined when no effort option). */
|
|
890
929
|
private currentEffort;
|
|
891
930
|
/** Story 056 — the session's current agent configOption value (undefined when no agent option). */
|
package/dist/acp-agent.js
CHANGED
|
@@ -47,6 +47,7 @@ import { setupSessionGate } from "./permissions/gate-wiring.js";
|
|
|
47
47
|
import { translateMcpServers, writeMcpScratch, removeMcpScratch } from "./mcp-config-writer.js";
|
|
48
48
|
import { materializeImage, cleanupMaterializedImages } from "./image-input.js";
|
|
49
49
|
import { deleteSessionIfStored } from "./session-delete.js";
|
|
50
|
+
import { AddDirTrustWatcher, DEFAULT_TRUST_SETTLE_MS } from "./add-dir-trust.js";
|
|
50
51
|
export const CLAUDE_CONFIG_DIR = process.env.CLAUDE_CONFIG_DIR ?? path.join(os.homedir(), ".claude");
|
|
51
52
|
const MAX_TITLE_LENGTH = 256;
|
|
52
53
|
function sanitizeTitle(text) {
|
|
@@ -230,6 +231,7 @@ export async function defaultStartEngine(args) {
|
|
|
230
231
|
// carries `--mcp-config "<file>"`; respawnSession regenerates the scratch before this call.
|
|
231
232
|
mcpConfigFile: args.mcpConfigFile,
|
|
232
233
|
});
|
|
234
|
+
args.onSpawn?.(handle.pty);
|
|
233
235
|
if (args.inPlaceRespawn) {
|
|
234
236
|
// === SEAM(046 R3.4 LIVE FIX): DEFER discovery for an in-place re-spawn ======================
|
|
235
237
|
// An in-place re-spawn (respawnSession: dontAsk/bypass or effort) can fire BEFORE the first
|
|
@@ -321,6 +323,7 @@ export async function defaultStartEngine(args) {
|
|
|
321
323
|
// servers declared) keeps the pre-057 argv byte-for-byte.
|
|
322
324
|
mcpConfigFile: args.mcpConfigFile,
|
|
323
325
|
});
|
|
326
|
+
args.onSpawn?.(engine.pty);
|
|
324
327
|
// Hand the engine the cancellation handle for the background poll. STORE-ONLY here — the
|
|
325
328
|
// cleanup→`.abort()` wiring (so tearing a never-interacted session down cancels this dangling poll)
|
|
326
329
|
// is sub-task 3.1. The `signal` is threaded into resolveWatchTarget below so 3.1's abort unblocks it.
|
|
@@ -1121,6 +1124,11 @@ export class ClaudeAcpAgent {
|
|
|
1121
1124
|
throw new Error(`session engine disposed — the claude PTY for session ${params.sessionId} has exited; ` +
|
|
1122
1125
|
"reload or recreate the session to continue");
|
|
1123
1126
|
}
|
|
1127
|
+
// Parity round 26 (item 238): answer an open `--add-dir` trust dialog before anything is typed,
|
|
1128
|
+
// or the prompt would land in the dialog. Awaited only while a watcher is live, so a session
|
|
1129
|
+
// with no added folder keeps the synchronous submit below (R2.3).
|
|
1130
|
+
if (sessionRecord.addDirTrust)
|
|
1131
|
+
await this.resolveAddDirTrust(params.sessionId, sessionRecord);
|
|
1124
1132
|
// === SEAM(030) — Degrau-2 ACP-side input (R1, R1.2, R5, R5.1, R5.2). The Degrau-1 read-only
|
|
1125
1133
|
// no-op is replaced by the real prompt loop: assemble the §8 PTY payload, submit it, and resolve
|
|
1126
1134
|
// the pending `session/prompt` SOLELY through the story-024 end-of-turn detector — never by this
|
|
@@ -1322,8 +1330,10 @@ export class ClaudeAcpAgent {
|
|
|
1322
1330
|
// (story 014) idempotently kills the PTY and stops the JSONL watcher; if no engine handle is
|
|
1323
1331
|
// present (e.g. an injected fake), fall back to stopping the watcher directly. ===
|
|
1324
1332
|
if (session.engine) {
|
|
1325
|
-
|
|
1333
|
+
// kill() BEFORE cleanup(): kill() is inert once the engine is disposed (R3.4), so the old
|
|
1334
|
+
// order left claude running after its session was torn down (found 2026-11-25).
|
|
1326
1335
|
session.engine.kill();
|
|
1336
|
+
session.engine.cleanup();
|
|
1327
1337
|
}
|
|
1328
1338
|
else {
|
|
1329
1339
|
// `watcher` is now OPTIONAL (story 028, sub-task 2.1): a fresh session may be torn down before
|
|
@@ -1761,13 +1771,16 @@ export class ClaudeAcpAgent {
|
|
|
1761
1771
|
// there is no transcript to preserve. RESUME re-spawn: keep the R3.7 order (bring the new PTY up
|
|
1762
1772
|
// BEFORE retiring the old, so a failed re-spawn leaves the prior PTY + currentValue intact).
|
|
1763
1773
|
if (fresh) {
|
|
1764
|
-
oldEngine
|
|
1765
|
-
oldEngine?.kill();
|
|
1774
|
+
this.retireEngine(session, oldEngine);
|
|
1766
1775
|
}
|
|
1767
1776
|
// Re-spawn through the SAME startEngine seam createSession uses, reusing the sessionId so the
|
|
1768
1777
|
// transcript is reattached on resume (R3.4) or freshly created on the pre-interaction path; the
|
|
1769
1778
|
// flags flow into the flag-carrying spawn argv (fresh `buildClaudeCmd` or `buildResumeArgv`).
|
|
1779
|
+
let addDirTrust;
|
|
1770
1780
|
const started = await this.startEngine({
|
|
1781
|
+
onSpawn: (pty) => {
|
|
1782
|
+
addDirTrust = this.watchAddDirTrust(pty, session.additionalDirectories);
|
|
1783
|
+
},
|
|
1771
1784
|
sessionId,
|
|
1772
1785
|
cwd: session.cwd,
|
|
1773
1786
|
resume: !fresh,
|
|
@@ -1788,12 +1801,20 @@ export class ClaudeAcpAgent {
|
|
|
1788
1801
|
});
|
|
1789
1802
|
if (!fresh) {
|
|
1790
1803
|
// New PTY is live — only now retire the old one (idle ⇒ no pending turn to double-resolve).
|
|
1791
|
-
oldEngine
|
|
1792
|
-
oldEngine?.kill();
|
|
1804
|
+
this.retireEngine(session, oldEngine);
|
|
1793
1805
|
}
|
|
1794
1806
|
session.pty = started.pty;
|
|
1795
1807
|
session.engine = started.engine;
|
|
1796
1808
|
session.watcher = started.watcher;
|
|
1809
|
+
// The gate follows the new PTY: its allow/deny keystrokes and output reads go to the live claude,
|
|
1810
|
+
// and the new PTY's exit is the one that tears the gate down.
|
|
1811
|
+
const liveGate = session.gate;
|
|
1812
|
+
if (liveGate && !liveGate.isTorndown) {
|
|
1813
|
+
liveGate.bindPty(started.pty);
|
|
1814
|
+
session.gateExitHook = started.pty.onExit(() => void liveGate.teardown());
|
|
1815
|
+
}
|
|
1816
|
+
session.addDirTrust?.dispose();
|
|
1817
|
+
session.addDirTrust = addDirTrust;
|
|
1797
1818
|
if (change.permissionMode) {
|
|
1798
1819
|
session.modes = { ...session.modes, currentModeId: change.permissionMode };
|
|
1799
1820
|
}
|
|
@@ -1802,6 +1823,81 @@ export class ClaudeAcpAgent {
|
|
|
1802
1823
|
session.respawning = false;
|
|
1803
1824
|
}
|
|
1804
1825
|
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Retire a re-spawned session's previous claude. The gate's exit hook on that PTY is dropped first,
|
|
1828
|
+
* so its exit does not tear down the gate the new PTY uses; then the PTY is killed BEFORE cleanup(),
|
|
1829
|
+
* because SessionEngine.kill() is inert once the engine is disposed (R3.4) — the old order, cleanup()
|
|
1830
|
+
* then kill(), left the previous claude running until the adapter exited (found 2026-11-25).
|
|
1831
|
+
*/
|
|
1832
|
+
retireEngine(session, engine) {
|
|
1833
|
+
session.gateExitHook?.dispose();
|
|
1834
|
+
session.gateExitHook = undefined;
|
|
1835
|
+
engine?.kill();
|
|
1836
|
+
engine?.cleanup();
|
|
1837
|
+
}
|
|
1838
|
+
/** Parity round 26 (item 238): a trust-dialog watcher for a PTY started with `--add-dir` folders. */
|
|
1839
|
+
watchAddDirTrust(pty, dirs) {
|
|
1840
|
+
if (!dirs || dirs.length === 0)
|
|
1841
|
+
return undefined;
|
|
1842
|
+
return new AddDirTrustWatcher(pty, dirs, os.homedir());
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Parity round 26 (item 238): ask the client about each folder claude's trust dialog names, then
|
|
1846
|
+
* answer it. Yes types `2` and claude goes on; No (or a cancelled request) starts claude again
|
|
1847
|
+
* without that folder, through the same pre-interaction re-spawn a mode change uses, because
|
|
1848
|
+
* claude's own "No, exit" ends the process. Refusing is never silent: it is logged and the folder
|
|
1849
|
+
* leaves the session's scope. Bounded by the folder count, since each round settles one folder.
|
|
1850
|
+
*/
|
|
1851
|
+
async resolveAddDirTrust(sessionId, session) {
|
|
1852
|
+
const rounds = (session.additionalDirectories?.length ?? 0) + 1;
|
|
1853
|
+
for (let round = 0; round < rounds; round++) {
|
|
1854
|
+
const watcher = session.addDirTrust;
|
|
1855
|
+
if (!watcher)
|
|
1856
|
+
return;
|
|
1857
|
+
await watcher.settled(DEFAULT_TRUST_SETTLE_MS, this.schedule);
|
|
1858
|
+
const dir = watcher.pending();
|
|
1859
|
+
if (!dir) {
|
|
1860
|
+
if (watcher.done())
|
|
1861
|
+
session.addDirTrust = undefined;
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
const trust = await this.askAddDirTrust(sessionId, dir);
|
|
1865
|
+
if (trust) {
|
|
1866
|
+
watcher.answer(true);
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
this.logger.error(`[add-dir] sessionId=${sessionId} event=refused dir=${JSON.stringify(dir)} ` +
|
|
1870
|
+
"action=restart-without-dir");
|
|
1871
|
+
watcher.dispose();
|
|
1872
|
+
session.addDirTrust = undefined;
|
|
1873
|
+
session.additionalDirectories = (session.additionalDirectories ?? []).filter((d) => d !== dir);
|
|
1874
|
+
await this.respawnSession(sessionId, session, {});
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
/** Parity round 26 (item 238): one permission request for one folder of the trust dialog. */
|
|
1878
|
+
async askAddDirTrust(sessionId, dir) {
|
|
1879
|
+
try {
|
|
1880
|
+
const result = await this.client.requestPermission({
|
|
1881
|
+
sessionId,
|
|
1882
|
+
toolCall: {
|
|
1883
|
+
toolCallId: `add-dir-trust-${randomUUID()}`,
|
|
1884
|
+
title: `Trust ${dir} for this session?`,
|
|
1885
|
+
kind: "other",
|
|
1886
|
+
status: "pending",
|
|
1887
|
+
rawInput: { directory: dir },
|
|
1888
|
+
},
|
|
1889
|
+
options: [
|
|
1890
|
+
{ optionId: "trust", name: "Yes, add it", kind: "allow_once" },
|
|
1891
|
+
{ optionId: "refuse", name: "No, start without it", kind: "reject_once" },
|
|
1892
|
+
],
|
|
1893
|
+
});
|
|
1894
|
+
return result.outcome.outcome === "selected" && result.outcome.optionId === "trust";
|
|
1895
|
+
}
|
|
1896
|
+
catch (error) {
|
|
1897
|
+
this.logger.error(`[add-dir] sessionId=${sessionId} event=ask-failed dir=${JSON.stringify(dir)}:`, error);
|
|
1898
|
+
return false;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1805
1901
|
/** Story 046 — the session's current effort configOption value (undefined when no effort option). */
|
|
1806
1902
|
currentEffort(session) {
|
|
1807
1903
|
const opt = session.configOptions.find((o) => o.id === "effort");
|
|
@@ -2826,8 +2922,13 @@ export class ClaudeAcpAgent {
|
|
|
2826
2922
|
// resume/fork we hand it the requested id. A failed resume (transcript never found by the
|
|
2827
2923
|
// file-discovery watchdog) surfaces as resourceNotFound so the client can recover.
|
|
2828
2924
|
let started;
|
|
2925
|
+
let addDirTrust;
|
|
2829
2926
|
try {
|
|
2830
2927
|
started = await this.startEngine({
|
|
2928
|
+
onSpawn: (pty) => {
|
|
2929
|
+
if (!creationOpts.replayOnly)
|
|
2930
|
+
addDirTrust = this.watchAddDirTrust(pty, additionalDirs);
|
|
2931
|
+
},
|
|
2831
2932
|
sessionId: isResume || creationOpts.forkSession ? requestedSessionId : undefined,
|
|
2832
2933
|
cwd: params.cwd,
|
|
2833
2934
|
resume: isResume || !!creationOpts.forkSession,
|
|
@@ -2870,6 +2971,7 @@ export class ClaudeAcpAgent {
|
|
|
2870
2971
|
if (started.engine) {
|
|
2871
2972
|
this.engines.set(startedSessionId, started.engine);
|
|
2872
2973
|
}
|
|
2974
|
+
let gateExitHook;
|
|
2873
2975
|
// === SEAM(034): bind the gate to the AUTHORITATIVE session id (engine-spawn-generated) and the
|
|
2874
2976
|
// live PTY. The nudge forces a pump re-read on every hook arrival, shrinking the JSONL
|
|
2875
2977
|
// tool_use-correlation race; the PTY binding powers the #52822 allow keystroke + prompt probe.
|
|
@@ -2896,7 +2998,7 @@ export class ClaudeAcpAgent {
|
|
|
2896
2998
|
// so a slow human decision (JSONL silent meanwhile) is not mistaken for a dead turn.
|
|
2897
2999
|
() => this.sessions[startedSessionId]?.turnDetector?.noteActivity());
|
|
2898
3000
|
boundGate.bindPty(started.pty);
|
|
2899
|
-
started.pty.onExit(() => void boundGate.teardown());
|
|
3001
|
+
gateExitHook = started.pty.onExit(() => void boundGate.teardown());
|
|
2900
3002
|
}
|
|
2901
3003
|
// Story 046: advertise the full curated model catalog (was a single static "Default" entry),
|
|
2902
3004
|
// with the current model seeded to the safe `default`. Populating the catalog also unlocks the
|
|
@@ -2952,6 +3054,7 @@ export class ClaudeAcpAgent {
|
|
|
2952
3054
|
// Story 057 (R1.3): the resolved additional-directory list, stored so sub-task 2.3's
|
|
2953
3055
|
// respawnSession can re-thread the SAME `--add-dir` scope into the in-place re-spawn.
|
|
2954
3056
|
additionalDirectories: additionalDirs,
|
|
3057
|
+
addDirTrust,
|
|
2955
3058
|
// Story 057 (R2.3/R2.4): the CURRENT MCP scratch path (for teardown removal + re-spawn regen)
|
|
2956
3059
|
// and the RAW ACP server array (so respawnSession can re-translate + regenerate the scratch).
|
|
2957
3060
|
mcpConfigFile,
|
|
@@ -2972,6 +3075,7 @@ export class ClaudeAcpAgent {
|
|
|
2972
3075
|
contextWindowSize: inferContextWindowFromModel(DEFAULT_MODEL_INFO.value) ?? DEFAULT_CONTEXT_WINDOW,
|
|
2973
3076
|
taskState,
|
|
2974
3077
|
gate,
|
|
3078
|
+
gateExitHook,
|
|
2975
3079
|
};
|
|
2976
3080
|
// Story 073 (R1) — the seed model is Opus (`default`), so probe fast-mode availability out of band
|
|
2977
3081
|
// and advertise the toggle when available. Fire-and-forget (like sendAvailableCommandsUpdate): the
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Text the CLI prints at the top of the dialog (2.1.330). */
|
|
2
|
+
export declare const TRUST_DIALOG_MARKER = "Adding a new directory:";
|
|
3
|
+
/** Keystroke that picks "Yes, add it" (the second option; measured on 2.1.330). */
|
|
4
|
+
export declare const TRUST_YES_KEY = "2";
|
|
5
|
+
/** Keystroke that cancels the dialog, which ends the claude process (measured on 2.1.330). */
|
|
6
|
+
export declare const TRUST_NO_KEY = "\u001B";
|
|
7
|
+
/** Footer text of claude's main screen: once seen, no dialog is open. */
|
|
8
|
+
export declare const MAIN_SCREEN_MARKERS: string[];
|
|
9
|
+
/** How long the first prompt waits for claude's startup screen before it is sent anyway. */
|
|
10
|
+
export declare const DEFAULT_TRUST_SETTLE_MS = 8000;
|
|
11
|
+
/** The PTY surface this module needs (structurally satisfied by node-pty's IPty). */
|
|
12
|
+
export interface TrustPty {
|
|
13
|
+
onData(listener: (data: string) => void): {
|
|
14
|
+
dispose(): void;
|
|
15
|
+
};
|
|
16
|
+
write(data: string): void;
|
|
17
|
+
}
|
|
18
|
+
/** Strip ANSI control sequences and collapse whitespace, so markers match across redraws. */
|
|
19
|
+
export declare function screenText(raw: string): string;
|
|
20
|
+
/** The folder `text` names after the dialog marker, matched against the folders the session added.
|
|
21
|
+
* The CLI may print a home folder as `~/…`; the longest match wins, so `/a/b` beats `/a`. */
|
|
22
|
+
export declare function dialogDirectory(text: string, dirs: readonly string[], home: string): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Watches one claude PTY from spawn for the trust dialog. `pending()` names the folder of an open
|
|
25
|
+
* dialog; `settled()` resolves once claude reached its main screen, opened a dialog, exited, or
|
|
26
|
+
* `settleMs` passed. The tap is removed as soon as the main screen shows with no dialog open.
|
|
27
|
+
*/
|
|
28
|
+
export declare class AddDirTrustWatcher {
|
|
29
|
+
private readonly pty;
|
|
30
|
+
private readonly dirs;
|
|
31
|
+
private readonly home;
|
|
32
|
+
private buffer;
|
|
33
|
+
private openDir;
|
|
34
|
+
private mainScreen;
|
|
35
|
+
private subscription;
|
|
36
|
+
private wake;
|
|
37
|
+
constructor(pty: TrustPty, dirs: readonly string[], home: string);
|
|
38
|
+
private feed;
|
|
39
|
+
/** The folder an open dialog names, if one is open. */
|
|
40
|
+
pending(): string | undefined;
|
|
41
|
+
/** Whether claude reached its main screen with no dialog open. */
|
|
42
|
+
done(): boolean;
|
|
43
|
+
/** Resolves once a dialog is open, the main screen showed, or `settleMs` passed. */
|
|
44
|
+
settled(settleMs: number, schedule: (fn: () => void, ms: number) => void): Promise<void>;
|
|
45
|
+
/** Answer the open dialog: `2` keeps the folder, Esc refuses it (and ends claude). */
|
|
46
|
+
answer(trust: boolean): void;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The `--add-dir` trust dialog (parity round 26, item 238).
|
|
2
|
+
//
|
|
3
|
+
// Since CLI 2.1.326 a folder passed with `--add-dir` that claude does not trust yet opens a dialog
|
|
4
|
+
// before the main screen: "Adding a new directory: <dir> … No, exit · Yes, add it". Measured live on
|
|
5
|
+
// claude 2.1.330 (2026-11-24): the default is "No, exit"; Enter and Esc both end the process (Esc
|
|
6
|
+
// prints "start again with the same flags but without --add-dir <dir>"); typing `2` adds the folder
|
|
7
|
+
// and the session goes on. Unanswered, the dialog swallows the first prompt and the turn waits for
|
|
8
|
+
// the watchdog.
|
|
9
|
+
//
|
|
10
|
+
// The dialog appears during `session/new`, before the client knows the session id, so it cannot be
|
|
11
|
+
// asked then. This module only WATCHES the PTY and remembers which folder the open dialog names; the
|
|
12
|
+
// agent asks the client at the first prompt and answers through {@link answerTrustDialog}.
|
|
13
|
+
/** Text the CLI prints at the top of the dialog (2.1.330). */
|
|
14
|
+
export const TRUST_DIALOG_MARKER = "Adding a new directory:";
|
|
15
|
+
/** Keystroke that picks "Yes, add it" (the second option; measured on 2.1.330). */
|
|
16
|
+
export const TRUST_YES_KEY = "2";
|
|
17
|
+
/** Keystroke that cancels the dialog, which ends the claude process (measured on 2.1.330). */
|
|
18
|
+
export const TRUST_NO_KEY = "\x1b";
|
|
19
|
+
/** Footer text of claude's main screen: once seen, no dialog is open. */
|
|
20
|
+
export const MAIN_SCREEN_MARKERS = ["? for shortcuts", "shift+tab to cycle"];
|
|
21
|
+
/** How long the first prompt waits for claude's startup screen before it is sent anyway. */
|
|
22
|
+
export const DEFAULT_TRUST_SETTLE_MS = 8000;
|
|
23
|
+
/** Strip ANSI control sequences and collapse whitespace, so markers match across redraws. */
|
|
24
|
+
export function screenText(raw) {
|
|
25
|
+
// These patterns match terminal escape sequences (ESC/BEL), never printable text, so
|
|
26
|
+
// no-control-regex is a false positive here (the model-catalog.ts precedent).
|
|
27
|
+
/* eslint-disable no-control-regex */
|
|
28
|
+
return raw
|
|
29
|
+
.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, " ")
|
|
30
|
+
.replace(/\x1b\][^\x07]*\x07/g, " ")
|
|
31
|
+
.replace(/\x1b[()][0-9A-B]/g, " ")
|
|
32
|
+
.replace(/\x1b[=>]/g, " ")
|
|
33
|
+
.replace(/\s+/g, " ");
|
|
34
|
+
/* eslint-enable no-control-regex */
|
|
35
|
+
}
|
|
36
|
+
/** The folder `text` names after the dialog marker, matched against the folders the session added.
|
|
37
|
+
* The CLI may print a home folder as `~/…`; the longest match wins, so `/a/b` beats `/a`. */
|
|
38
|
+
export function dialogDirectory(text, dirs, home) {
|
|
39
|
+
const at = text.lastIndexOf(TRUST_DIALOG_MARKER);
|
|
40
|
+
if (at === -1)
|
|
41
|
+
return undefined;
|
|
42
|
+
const tail = text.slice(at + TRUST_DIALOG_MARKER.length).replace(/\s+/g, "");
|
|
43
|
+
let best;
|
|
44
|
+
for (const dir of dirs) {
|
|
45
|
+
const shown = home && dir.startsWith(home + "/") ? "~" + dir.slice(home.length) : dir;
|
|
46
|
+
const candidates = [dir, shown].map((d) => d.replace(/\s+/g, ""));
|
|
47
|
+
if (candidates.some((c) => tail.startsWith(c)) && (!best || dir.length > best.length)) {
|
|
48
|
+
best = dir;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return best;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Watches one claude PTY from spawn for the trust dialog. `pending()` names the folder of an open
|
|
55
|
+
* dialog; `settled()` resolves once claude reached its main screen, opened a dialog, exited, or
|
|
56
|
+
* `settleMs` passed. The tap is removed as soon as the main screen shows with no dialog open.
|
|
57
|
+
*/
|
|
58
|
+
export class AddDirTrustWatcher {
|
|
59
|
+
constructor(pty, dirs, home) {
|
|
60
|
+
this.pty = pty;
|
|
61
|
+
this.dirs = dirs;
|
|
62
|
+
this.home = home;
|
|
63
|
+
this.buffer = "";
|
|
64
|
+
this.mainScreen = false;
|
|
65
|
+
this.subscription = pty.onData((data) => this.feed(data));
|
|
66
|
+
}
|
|
67
|
+
feed(data) {
|
|
68
|
+
this.buffer = (this.buffer + screenText(data)).slice(-8192);
|
|
69
|
+
const dir = dialogDirectory(this.buffer, this.dirs, this.home);
|
|
70
|
+
if (dir) {
|
|
71
|
+
this.openDir = dir;
|
|
72
|
+
this.mainScreen = false;
|
|
73
|
+
}
|
|
74
|
+
else if (MAIN_SCREEN_MARKERS.some((m) => this.buffer.includes(m))) {
|
|
75
|
+
this.mainScreen = true;
|
|
76
|
+
this.openDir = undefined;
|
|
77
|
+
this.dispose();
|
|
78
|
+
}
|
|
79
|
+
if (this.openDir || this.mainScreen)
|
|
80
|
+
this.wake?.();
|
|
81
|
+
}
|
|
82
|
+
/** The folder an open dialog names, if one is open. */
|
|
83
|
+
pending() {
|
|
84
|
+
return this.openDir;
|
|
85
|
+
}
|
|
86
|
+
/** Whether claude reached its main screen with no dialog open. */
|
|
87
|
+
done() {
|
|
88
|
+
return this.mainScreen;
|
|
89
|
+
}
|
|
90
|
+
/** Resolves once a dialog is open, the main screen showed, or `settleMs` passed. */
|
|
91
|
+
settled(settleMs, schedule) {
|
|
92
|
+
if (this.openDir || this.mainScreen)
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
let finished = false;
|
|
96
|
+
const finish = () => {
|
|
97
|
+
if (finished)
|
|
98
|
+
return;
|
|
99
|
+
finished = true;
|
|
100
|
+
this.wake = undefined;
|
|
101
|
+
resolve();
|
|
102
|
+
};
|
|
103
|
+
this.wake = finish;
|
|
104
|
+
schedule(finish, settleMs);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** Answer the open dialog: `2` keeps the folder, Esc refuses it (and ends claude). */
|
|
108
|
+
answer(trust) {
|
|
109
|
+
this.pty.write(trust ? TRUST_YES_KEY : TRUST_NO_KEY);
|
|
110
|
+
// The screen redraws after the answer; forget what was read so the same dialog is not
|
|
111
|
+
// matched twice and a dialog for the next folder is recognised on its own.
|
|
112
|
+
this.buffer = "";
|
|
113
|
+
this.openDir = undefined;
|
|
114
|
+
}
|
|
115
|
+
dispose() {
|
|
116
|
+
this.subscription?.dispose();
|
|
117
|
+
this.subscription = undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -266,6 +266,9 @@ class SessionGateImpl {
|
|
|
266
266
|
this.noteActivity = noteActivity;
|
|
267
267
|
}
|
|
268
268
|
bindPty(pty) {
|
|
269
|
+
// A re-spawn binds the session's new PTY: drop the tap on the old one first.
|
|
270
|
+
this.outputTap?.dispose();
|
|
271
|
+
this.outputTap = undefined;
|
|
269
272
|
this.pty = pty;
|
|
270
273
|
if (typeof pty.onData === "function") {
|
|
271
274
|
this.outputTap = pty.onData((data) => {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.17.
|
|
6
|
+
"version": "0.17.7",
|
|
7
7
|
"description": "Runs the official Claude Code TUI over a PTY and exposes it via ACP, so Claude Code threads render natively in Zed's agent panel. Built for Anthropic's June 2026 billing split (since paused).",
|
|
8
8
|
"main": "dist/lib.js",
|
|
9
9
|
"types": "dist/lib.d.ts",
|
|
@@ -70,15 +70,15 @@
|
|
|
70
70
|
"zod": "^4.0.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@anthropic-ai/sdk": "1.
|
|
73
|
+
"@anthropic-ai/sdk": "1.10.0",
|
|
74
74
|
"@eslint/js": "10.0.1",
|
|
75
75
|
"@types/node": "26.6.6",
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
77
|
-
"@typescript-eslint/parser": "8.
|
|
78
|
-
"eslint": "10.
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "8.73.0",
|
|
77
|
+
"@typescript-eslint/parser": "8.73.0",
|
|
78
|
+
"eslint": "10.15.0",
|
|
79
79
|
"eslint-config-prettier": "10.1.8",
|
|
80
80
|
"globals": "17.14.0",
|
|
81
|
-
"prettier": "3.
|
|
81
|
+
"prettier": "3.10.1",
|
|
82
82
|
"ts-node": "10.9.2",
|
|
83
83
|
"typescript": "6.0.3"
|
|
84
84
|
},
|