@0xmaxma/claude-gateway 1.2.32 → 1.3.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.
Files changed (45) hide show
  1. package/README.md +23 -4
  2. package/config.template.json +5 -5
  3. package/dist/api/router.d.ts.map +1 -1
  4. package/dist/api/router.js +2 -4
  5. package/dist/api/router.js.map +1 -1
  6. package/dist/apps/agent-manager.d.ts.map +1 -1
  7. package/dist/apps/agent-manager.js +0 -1
  8. package/dist/apps/agent-manager.js.map +1 -1
  9. package/dist/config/watcher.d.ts.map +1 -1
  10. package/dist/config/watcher.js +21 -4
  11. package/dist/config/watcher.js.map +1 -1
  12. package/dist/index.js +8 -3
  13. package/dist/index.js.map +1 -1
  14. package/dist/session/process.d.ts.map +1 -1
  15. package/dist/session/process.js +32 -5
  16. package/dist/session/process.js.map +1 -1
  17. package/dist/shell/args.d.ts +22 -0
  18. package/dist/shell/args.d.ts.map +1 -0
  19. package/dist/shell/args.js +105 -0
  20. package/dist/shell/args.js.map +1 -0
  21. package/dist/shell/claude-pty-shell.d.ts +3 -0
  22. package/dist/shell/claude-pty-shell.d.ts.map +1 -0
  23. package/dist/shell/claude-pty-shell.js +407 -0
  24. package/dist/shell/claude-pty-shell.js.map +1 -0
  25. package/dist/shell/emitter.d.ts +36 -0
  26. package/dist/shell/emitter.d.ts.map +1 -0
  27. package/dist/shell/emitter.js +85 -0
  28. package/dist/shell/emitter.js.map +1 -0
  29. package/dist/shell/pty-host.d.ts +21 -0
  30. package/dist/shell/pty-host.d.ts.map +1 -0
  31. package/dist/shell/pty-host.js +102 -0
  32. package/dist/shell/pty-host.js.map +1 -0
  33. package/dist/shell/screen.d.ts +44 -0
  34. package/dist/shell/screen.d.ts.map +1 -0
  35. package/dist/shell/screen.js +89 -0
  36. package/dist/shell/screen.js.map +1 -0
  37. package/dist/shell/tailer.d.ts +64 -0
  38. package/dist/shell/tailer.d.ts.map +1 -0
  39. package/dist/shell/tailer.js +181 -0
  40. package/dist/shell/tailer.js.map +1 -0
  41. package/dist/types.d.ts +7 -1
  42. package/dist/types.d.ts.map +1 -1
  43. package/mcp/tools/telegram/dedup.ts +46 -0
  44. package/mcp/tools/telegram/receiver-server.ts +25 -0
  45. package/package.json +3 -1
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProtocolEmitter = void 0;
4
+ /**
5
+ * Synthesizes the stream-json events the gateway's SessionProcess stdout
6
+ * parser consumes (src/session/process.ts). Every assistant event is emitted
7
+ * as a FINAL message (top-level stop_reason set): the parser then appends the
8
+ * full text as a fresh delta and resets its partial tracking, which is what
9
+ * makes mid-turn (message-level streaming) emission safe.
10
+ */
11
+ class ProtocolEmitter {
12
+ constructor(out = process.stdout) {
13
+ this.out = out;
14
+ }
15
+ writeLine(obj) {
16
+ this.out.write(JSON.stringify(obj) + '\n');
17
+ }
18
+ emitInit(sessionId, model, cwd) {
19
+ this.writeLine({
20
+ type: 'system',
21
+ subtype: 'init',
22
+ session_id: sessionId,
23
+ model,
24
+ cwd,
25
+ tools: [],
26
+ });
27
+ }
28
+ /**
29
+ * Context-size shim: the gateway reads usage from stream_event/message_start
30
+ * to display context %. Transcript assistant records carry the same usage,
31
+ * so replay it. Emitted before each assistant event; the gateway keeps the
32
+ * latest value and applies it at result time.
33
+ */
34
+ emitMessageStartShim(usage, sessionId) {
35
+ this.writeLine({
36
+ type: 'stream_event',
37
+ session_id: sessionId,
38
+ event: {
39
+ type: 'message_start',
40
+ message: {
41
+ usage: {
42
+ input_tokens: usage.input_tokens ?? 0,
43
+ cache_read_input_tokens: usage.cache_read_input_tokens ?? 0,
44
+ cache_creation_input_tokens: usage.cache_creation_input_tokens ?? 0,
45
+ },
46
+ },
47
+ },
48
+ });
49
+ }
50
+ /**
51
+ * Emit one transcript assistant record as a final assistant event.
52
+ * Thinking blocks are stripped (the gateway only consumes text and
53
+ * tool_use blocks; thinking content must not leak into chat history).
54
+ * Returns the text contained in the record, '' if none.
55
+ */
56
+ emitAssistant(record, sessionId) {
57
+ const blocks = record.message.content.filter((b) => b.type === 'text' || b.type === 'tool_use');
58
+ if (blocks.length === 0)
59
+ return '';
60
+ this.writeLine({
61
+ type: 'assistant',
62
+ session_id: sessionId,
63
+ stop_reason: record.message.stop_reason ?? 'end_turn',
64
+ message: { role: 'assistant', content: blocks },
65
+ });
66
+ return blocks
67
+ .filter((b) => b.type === 'text')
68
+ .map((b) => String(b.text ?? ''))
69
+ .join('');
70
+ }
71
+ emitResult(opts) {
72
+ this.writeLine({
73
+ type: 'result',
74
+ subtype: opts.isError ? 'error_during_execution' : 'success',
75
+ is_error: opts.isError,
76
+ result: opts.text,
77
+ duration_ms: opts.durationMs,
78
+ num_turns: 1,
79
+ session_id: opts.sessionId,
80
+ usage: { output_tokens: opts.usage?.output_tokens ?? 0 },
81
+ });
82
+ }
83
+ }
84
+ exports.ProtocolEmitter = ProtocolEmitter;
85
+ //# sourceMappingURL=emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/shell/emitter.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACH,MAAa,eAAe;IAC1B,YAA6B,MAA6B,OAAO,CAAC,MAAM;QAA3C,QAAG,GAAH,GAAG,CAAwC;IAAG,CAAC;IAEpE,SAAS,CAAC,GAA4B;QAC5C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,QAAQ,CAAC,SAAiB,EAAE,KAAa,EAAE,GAAW;QACpD,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,SAAS;YACrB,KAAK;YACL,GAAG;YACH,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAAC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AQ;YACd,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,SAAS;YAC5D,QAAQ,EAAE,IAAI,CAAC,OAAO;YACtB,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,WAAW,EAAE,IAAI,CAAC,UAAU;YAC5B,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,IAAI,CAAC,SAAS;YAC1B,KAAK,EAAE,EAAE,aAAa,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC,EAAE;SACzD,CAAC,CAAC;IACL,CAAC;CACF;AApFD,0CAoFC"}
@@ -0,0 +1,21 @@
1
+ export interface PtyHostOptions {
2
+ cols: number;
3
+ rows: number;
4
+ cwd: string;
5
+ onData: (data: string) => void;
6
+ onExit: (exitCode: number) => void;
7
+ }
8
+ /** Hosts the real interactive `claude` inside a pseudo-terminal. */
9
+ export declare class PtyHost {
10
+ private child;
11
+ constructor(binary: string, args: string[], opts: PtyHostOptions);
12
+ /** Raw keystroke write (control sequences allowed — caller sanitizes user text). */
13
+ writeRaw(data: string): void;
14
+ /**
15
+ * Paste large text without overwhelming the PTY line discipline:
16
+ * chunked writes with small delays.
17
+ */
18
+ writeChunked(data: string): Promise<void>;
19
+ kill(signal?: string): void;
20
+ }
21
+ //# sourceMappingURL=pty-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-host.d.ts","sourceRoot":"","sources":["../../src/shell/pty-host.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,oEAAoE;AACpE,qBAAa,OAAO;IAClB,OAAO,CAAC,KAAK,CAAW;gBAEZ,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc;IAiBhE,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI5B;;;OAGG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/C,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;CAO5B"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PtyHost = void 0;
37
+ const path = __importStar(require("path"));
38
+ const pty = __importStar(require("node-pty"));
39
+ const WRITE_CHUNK_BYTES = 8 * 1024;
40
+ const WRITE_CHUNK_DELAY_MS = 10;
41
+ // Keys matching these prefixes are scrubbed before spawning the child PTY:
42
+ // CLAUDECODE/CLAUDE_CODE_ prevent nested-claude child-session behavior that
43
+ // silently stops transcript JSONL writes; CLAUDE_REAL_BIN is a wrapper-only
44
+ // variable and must not leak into the child.
45
+ const SCRUB_ENV_PREFIXES = ['CLAUDECODE', 'CLAUDE_CODE_', 'CLAUDE_REAL_BIN', 'PTY_SHELL_'];
46
+ // Auth vars that share the CLAUDE_CODE_ prefix but must be kept.
47
+ const SCRUB_ENV_KEEPLIST = new Set(['CLAUDE_CODE_OAUTH_TOKEN']);
48
+ function childEnv() {
49
+ const env = { ...process.env };
50
+ for (const key of Object.keys(env)) {
51
+ if (!SCRUB_ENV_KEEPLIST.has(key) &&
52
+ SCRUB_ENV_PREFIXES.some((p) => key.startsWith(p))) {
53
+ delete env[key];
54
+ }
55
+ }
56
+ return env;
57
+ }
58
+ /** Hosts the real interactive `claude` inside a pseudo-terminal. */
59
+ class PtyHost {
60
+ constructor(binary, args, opts) {
61
+ // Recursion guard: CLAUDE_BIN points at this wrapper; the wrapper must
62
+ // never resolve the "real" binary back to itself.
63
+ if (path.basename(binary).includes('claude-pty-shell')) {
64
+ throw new Error(`refusing to spawn self as claude binary: ${binary}`);
65
+ }
66
+ this.child = pty.spawn(binary, args, {
67
+ name: 'xterm-256color',
68
+ cols: opts.cols,
69
+ rows: opts.rows,
70
+ cwd: opts.cwd,
71
+ env: childEnv(),
72
+ });
73
+ this.child.onData(opts.onData);
74
+ this.child.onExit(({ exitCode }) => opts.onExit(exitCode));
75
+ }
76
+ /** Raw keystroke write (control sequences allowed — caller sanitizes user text). */
77
+ writeRaw(data) {
78
+ this.child.write(data);
79
+ }
80
+ /**
81
+ * Paste large text without overwhelming the PTY line discipline:
82
+ * chunked writes with small delays.
83
+ */
84
+ async writeChunked(data) {
85
+ for (let i = 0; i < data.length; i += WRITE_CHUNK_BYTES) {
86
+ this.child.write(data.slice(i, i + WRITE_CHUNK_BYTES));
87
+ if (i + WRITE_CHUNK_BYTES < data.length) {
88
+ await new Promise((r) => setTimeout(r, WRITE_CHUNK_DELAY_MS));
89
+ }
90
+ }
91
+ }
92
+ kill(signal) {
93
+ try {
94
+ this.child.kill(signal);
95
+ }
96
+ catch {
97
+ /* already dead */
98
+ }
99
+ }
100
+ }
101
+ exports.PtyHost = PtyHost;
102
+ //# sourceMappingURL=pty-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-host.js","sourceRoot":"","sources":["../../src/shell/pty-host.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,8CAAgC;AAEhC,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,CAAC;AACnC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,6CAA6C;AAC7C,MAAM,kBAAkB,GAAG,CAAC,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;AAE3F,iEAAiE;AACjE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC;AAEhE,SAAS,QAAQ;IACf,MAAM,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAA4B,CAAC;IACzD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,IACE,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC;YAC5B,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACjD,CAAC;YACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;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AAC,MAAM,EAAE,CAAC;gBACxC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,CAAC,MAAe;QAClB,IAAI,CAAC;YACH,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,kBAAkB;QACpB,CAAC;IACH,CAAC;CACF;AA7CD,0BA6CC"}
@@ -0,0 +1,44 @@
1
+ export type DialogKind = 'bypass-permissions' | 'trust-folder' | 'unknown-select';
2
+ /**
3
+ * TUI string constants — verified against Claude Code v2.1.x.
4
+ * When upgrading Claude Code, re-check each constant against the new TUI output.
5
+ * All matchers live here so a UI change requires touching exactly one file.
6
+ *
7
+ * BUSY_MARKER status bar text during an active turn
8
+ * PROMPT_RE idle input caret pattern
9
+ * BYPASS_PERMS "Bypass Permissions" dialog markers
10
+ * TRUST_FOLDER workspace trust dialog marker
11
+ * NUMBERED_SELECT_RE generic numbered select — combined with CONFIRM_MARKER
12
+ */
13
+ export declare const TUI_BUSY_MARKER = "esc to interrupt";
14
+ export declare const TUI_PROMPT_RE: RegExp;
15
+ export declare const TUI_BYPASS_PERMS: readonly ["Bypass Permissions mode", "Yes, I accept"];
16
+ export declare const TUI_TRUST_FOLDER = "Do you trust the files in this folder";
17
+ export declare const TUI_NUMBERED_SELECT_RE: RegExp;
18
+ export declare const TUI_CONFIRM_MARKER = "Enter to confirm";
19
+ /**
20
+ * Virtual terminal fed with raw PTY bytes. Used ONLY for liveness signals
21
+ * (busy / idle / dialog detection) — assistant text is never parsed from
22
+ * the screen; the transcript JSONL is the text source of truth.
23
+ */
24
+ export declare class ScreenModel {
25
+ readonly cols: number;
26
+ readonly rows: number;
27
+ private term;
28
+ private lastDataTs;
29
+ /** Set when a busy marker is seen in a raw chunk; survives fast busy→idle flips between polls. */
30
+ private busySeenInRaw;
31
+ constructor(cols?: number, rows?: number);
32
+ write(data: string): void;
33
+ /** Milliseconds since the PTY last produced output. */
34
+ quietMs(): number;
35
+ text(): string;
36
+ /** Claude is processing a turn (spinner area shows "esc to interrupt"). */
37
+ isBusy(): boolean;
38
+ /** Consume the raw-chunk busy flag (catches turns faster than the poll interval). */
39
+ consumeBusySeen(): boolean;
40
+ /** Idle input prompt is on screen. */
41
+ hasPrompt(): boolean;
42
+ detectDialog(): DialogKind | null;
43
+ }
44
+ //# sourceMappingURL=screen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../../src/shell/screen.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,oBAAoB,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAOlF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,aAAa,QAAS,CAAC;AACpC,eAAO,MAAM,gBAAgB,uDAAwD,CAAC;AACtF,eAAO,MAAM,gBAAgB,0CAA0C,CAAC;AACxE,eAAO,MAAM,sBAAsB,QAAU,CAAC;AAC9C,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AAErD;;;;GAIG;AACH,qBAAa,WAAW;aAMM,IAAI;aAAwB,IAAI;IAL5D,OAAO,CAAC,IAAI,CAAW;IACvB,OAAO,CAAC,UAAU,CAAc;IAChC,kGAAkG;IAClG,OAAO,CAAC,aAAa,CAAS;gBAEF,IAAI,SAAM,EAAkB,IAAI,SAAK;IAIjE,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAMzB,uDAAuD;IACvD,OAAO,IAAI,MAAM;IAIjB,IAAI,IAAI,MAAM;IAUd,2EAA2E;IAC3E,MAAM,IAAI,OAAO;IAIjB,qFAAqF;IACrF,eAAe,IAAI,OAAO;IAM1B,sCAAsC;IACtC,SAAS,IAAI,OAAO;IAIpB,YAAY,IAAI,UAAU,GAAG,IAAI;CAclC"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScreenModel = exports.TUI_CONFIRM_MARKER = exports.TUI_NUMBERED_SELECT_RE = exports.TUI_TRUST_FOLDER = exports.TUI_BYPASS_PERMS = exports.TUI_PROMPT_RE = exports.TUI_BUSY_MARKER = void 0;
4
+ const headless_1 = require("@xterm/headless");
5
+ /** The TUI renders spaces as U+00A0 (non-breaking) — normalize before matching. */
6
+ function normalize(text) {
7
+ return text.replace(/ /g, ' ');
8
+ }
9
+ /**
10
+ * TUI string constants — verified against Claude Code v2.1.x.
11
+ * When upgrading Claude Code, re-check each constant against the new TUI output.
12
+ * All matchers live here so a UI change requires touching exactly one file.
13
+ *
14
+ * BUSY_MARKER status bar text during an active turn
15
+ * PROMPT_RE idle input caret pattern
16
+ * BYPASS_PERMS "Bypass Permissions" dialog markers
17
+ * TRUST_FOLDER workspace trust dialog marker
18
+ * NUMBERED_SELECT_RE generic numbered select — combined with CONFIRM_MARKER
19
+ */
20
+ exports.TUI_BUSY_MARKER = 'esc to interrupt';
21
+ exports.TUI_PROMPT_RE = /^❯ /m;
22
+ exports.TUI_BYPASS_PERMS = ['Bypass Permissions mode', 'Yes, I accept'];
23
+ exports.TUI_TRUST_FOLDER = 'Do you trust the files in this folder';
24
+ exports.TUI_NUMBERED_SELECT_RE = /❯ 1\./;
25
+ exports.TUI_CONFIRM_MARKER = 'Enter to confirm';
26
+ /**
27
+ * Virtual terminal fed with raw PTY bytes. Used ONLY for liveness signals
28
+ * (busy / idle / dialog detection) — assistant text is never parsed from
29
+ * the screen; the transcript JSONL is the text source of truth.
30
+ */
31
+ class ScreenModel {
32
+ constructor(cols = 200, rows = 50) {
33
+ this.cols = cols;
34
+ this.rows = rows;
35
+ this.lastDataTs = Date.now();
36
+ /** Set when a busy marker is seen in a raw chunk; survives fast busy→idle flips between polls. */
37
+ this.busySeenInRaw = false;
38
+ this.term = new headless_1.Terminal({ cols, rows, allowProposedApi: true });
39
+ }
40
+ write(data) {
41
+ this.lastDataTs = Date.now();
42
+ if (normalize(data).includes(exports.TUI_BUSY_MARKER))
43
+ this.busySeenInRaw = true;
44
+ this.term.write(data);
45
+ }
46
+ /** Milliseconds since the PTY last produced output. */
47
+ quietMs() {
48
+ return Date.now() - this.lastDataTs;
49
+ }
50
+ text() {
51
+ const buf = this.term.buffer.active;
52
+ const lines = [];
53
+ for (let i = 0; i < this.term.rows; i++) {
54
+ const line = buf.getLine(buf.viewportY + i);
55
+ lines.push(line ? line.translateToString(true) : '');
56
+ }
57
+ return normalize(lines.join('\n'));
58
+ }
59
+ /** Claude is processing a turn (spinner area shows "esc to interrupt"). */
60
+ isBusy() {
61
+ return this.text().includes(exports.TUI_BUSY_MARKER);
62
+ }
63
+ /** Consume the raw-chunk busy flag (catches turns faster than the poll interval). */
64
+ consumeBusySeen() {
65
+ const seen = this.busySeenInRaw;
66
+ this.busySeenInRaw = false;
67
+ return seen;
68
+ }
69
+ /** Idle input prompt is on screen. */
70
+ hasPrompt() {
71
+ return exports.TUI_PROMPT_RE.test(this.text());
72
+ }
73
+ detectDialog() {
74
+ const text = this.text();
75
+ if (exports.TUI_BYPASS_PERMS.every((s) => text.includes(s))) {
76
+ return 'bypass-permissions';
77
+ }
78
+ if (text.includes(exports.TUI_TRUST_FOLDER)) {
79
+ return 'trust-folder';
80
+ }
81
+ // Generic numbered select dialog while no turn output is flowing.
82
+ if (!text.includes(exports.TUI_BUSY_MARKER) && exports.TUI_NUMBERED_SELECT_RE.test(text) && text.includes(exports.TUI_CONFIRM_MARKER)) {
83
+ return 'unknown-select';
84
+ }
85
+ return null;
86
+ }
87
+ }
88
+ exports.ScreenModel = ScreenModel;
89
+ //# sourceMappingURL=screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.js","sourceRoot":"","sources":["../../src/shell/screen.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAI3C,mFAAmF;AACnF,SA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AI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,0BAAkB,CAAC,EAAE,CAAC;YAC9G,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA9DD,kCA8DC"}
@@ -0,0 +1,64 @@
1
+ export interface UsageInfo {
2
+ input_tokens?: number;
3
+ cache_read_input_tokens?: number;
4
+ cache_creation_input_tokens?: number;
5
+ output_tokens?: number;
6
+ }
7
+ export interface AssistantRecord {
8
+ type: 'assistant';
9
+ isSidechain?: boolean;
10
+ message: {
11
+ role: 'assistant';
12
+ content: Array<{
13
+ type: string;
14
+ [k: string]: unknown;
15
+ }>;
16
+ stop_reason?: string | null;
17
+ usage?: UsageInfo;
18
+ };
19
+ uuid?: string;
20
+ timestamp?: string;
21
+ }
22
+ export interface TailerEvents {
23
+ /** A new (non-sidechain) assistant record was appended. */
24
+ onAssistant: (record: AssistantRecord) => void;
25
+ /** Claude finished a turn (system/turn_duration record). */
26
+ onTurnEnd: (durationMs: number) => void;
27
+ onError: (err: Error) => void;
28
+ }
29
+ /**
30
+ * cwd → Claude Code project-dir slug (verified against v2.1.x: `/` and `.` both become `-`).
31
+ * If Claude Code ever changes this scheme, findFile()'s fallback UUID scan will still
32
+ * locate the transcript — the primary path is just an optimistic fast path.
33
+ */
34
+ export declare function projectSlug(cwd: string): string;
35
+ export declare function transcriptPath(cwd: string, sessionId: string): string;
36
+ /**
37
+ * Incrementally reads the session transcript JSONL that interactive Claude
38
+ * Code appends to *during* a turn. This is the text source of truth and the
39
+ * streaming source: records are surfaced the moment they hit the file.
40
+ */
41
+ export declare class TranscriptTailer {
42
+ private readonly cwd;
43
+ private readonly sessionId;
44
+ private readonly events;
45
+ private readonly pollMs;
46
+ private offset;
47
+ private partialLine;
48
+ private timer;
49
+ private resolvedPath;
50
+ /** Total records dispatched since start — non-zero means claude is writing output. */
51
+ seenRecords: number;
52
+ /** Timestamp of last fallback scan — caps expensive readdirSync to once per 2s. */
53
+ private lastFallbackScanMs;
54
+ private static readonly FALLBACK_SCAN_INTERVAL_MS;
55
+ constructor(cwd: string, sessionId: string, events: TailerEvents, pollMs?: number);
56
+ start(): void;
57
+ stop(): void;
58
+ /** Force one synchronous read (used right before emitting a result). */
59
+ flush(): void;
60
+ private findFile;
61
+ private poll;
62
+ private dispatch;
63
+ }
64
+ //# sourceMappingURL=tailer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tailer.d.ts","sourceRoot":"","sources":["../../src/shell/tailer.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE;QACP,IAAI,EAAE,WAAW,CAAC;QAClB,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAC,CAAC;QACvD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,KAAK,CAAC,EAAE,SAAS,CAAC;KACnB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,WAAW,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;IAC/C,4DAA4D;IAC5D,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAYzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAdzB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,KAAK,CAA+C;IAC5D,OAAO,CAAC,YAAY,CAAuB;IAC3C,sFAAsF;IACtF,WAAW,SAAK;IAChB,mFAAmF;IACnF,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAS;gBAGvC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,EACpB,MAAM,SAAM;IAG/B,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI;IAKZ,wEAAwE;IACxE,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,QAAQ;IA0BhB,OAAO,CAAC,IAAI;IA2CZ,OAAO,CAAC,QAAQ;CAejB"}
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TranscriptTailer = void 0;
37
+ exports.projectSlug = projectSlug;
38
+ exports.transcriptPath = transcriptPath;
39
+ const fs = __importStar(require("fs"));
40
+ const os = __importStar(require("os"));
41
+ const path = __importStar(require("path"));
42
+ /**
43
+ * cwd → Claude Code project-dir slug (verified against v2.1.x: `/` and `.` both become `-`).
44
+ * If Claude Code ever changes this scheme, findFile()'s fallback UUID scan will still
45
+ * locate the transcript — the primary path is just an optimistic fast path.
46
+ */
47
+ function projectSlug(cwd) {
48
+ return cwd.replace(/[/.]/g, '-');
49
+ }
50
+ function transcriptPath(cwd, sessionId) {
51
+ return path.join(os.homedir(), '.claude', 'projects', projectSlug(cwd), `${sessionId}.jsonl`);
52
+ }
53
+ /**
54
+ * Incrementally reads the session transcript JSONL that interactive Claude
55
+ * Code appends to *during* a turn. This is the text source of truth and the
56
+ * streaming source: records are surfaced the moment they hit the file.
57
+ */
58
+ class TranscriptTailer {
59
+ constructor(cwd, sessionId, events, pollMs = 150) {
60
+ this.cwd = cwd;
61
+ this.sessionId = sessionId;
62
+ this.events = events;
63
+ this.pollMs = pollMs;
64
+ this.offset = 0;
65
+ this.partialLine = '';
66
+ this.timer = null;
67
+ this.resolvedPath = null;
68
+ /** Total records dispatched since start — non-zero means claude is writing output. */
69
+ this.seenRecords = 0;
70
+ /** Timestamp of last fallback scan — caps expensive readdirSync to once per 2s. */
71
+ this.lastFallbackScanMs = 0;
72
+ }
73
+ start() {
74
+ this.timer = setInterval(() => this.poll(), this.pollMs);
75
+ }
76
+ stop() {
77
+ if (this.timer)
78
+ clearInterval(this.timer);
79
+ this.timer = null;
80
+ }
81
+ /** Force one synchronous read (used right before emitting a result). */
82
+ flush() {
83
+ this.poll();
84
+ }
85
+ findFile() {
86
+ if (this.resolvedPath)
87
+ return this.resolvedPath;
88
+ const expected = transcriptPath(this.cwd, this.sessionId);
89
+ if (fs.existsSync(expected)) {
90
+ this.resolvedPath = expected;
91
+ return expected;
92
+ }
93
+ // Fallback if the slug scheme ever changes: scan project dirs for the uuid.
94
+ // Capped to once per 2s — readdirSync over hundreds of project dirs every 150ms poll
95
+ // is expensive before the transcript file has been created.
96
+ const now = Date.now();
97
+ if (now - this.lastFallbackScanMs < TranscriptTailer.FALLBACK_SCAN_INTERVAL_MS)
98
+ return null;
99
+ this.lastFallbackScanMs = now;
100
+ const projectsRoot = path.join(os.homedir(), '.claude', 'projects');
101
+ let dirs = [];
102
+ try {
103
+ dirs = fs.readdirSync(projectsRoot);
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ for (const dir of dirs) {
109
+ const candidate = path.join(projectsRoot, dir, `${this.sessionId}.jsonl`);
110
+ if (fs.existsSync(candidate)) {
111
+ this.resolvedPath = candidate;
112
+ return candidate;
113
+ }
114
+ }
115
+ return null;
116
+ }
117
+ poll() {
118
+ const file = this.findFile();
119
+ if (!file)
120
+ return;
121
+ let size;
122
+ try {
123
+ size = fs.statSync(file).size;
124
+ }
125
+ catch {
126
+ return; // transient: file rotated/removed
127
+ }
128
+ if (size <= this.offset)
129
+ return;
130
+ let chunk;
131
+ try {
132
+ const fd = fs.openSync(file, 'r');
133
+ const buf = Buffer.alloc(size - this.offset);
134
+ fs.readSync(fd, buf, 0, buf.length, this.offset);
135
+ fs.closeSync(fd);
136
+ chunk = buf.toString('utf8');
137
+ }
138
+ catch (err) {
139
+ this.events.onError(err instanceof Error ? err : new Error(String(err)));
140
+ return;
141
+ }
142
+ this.offset = size;
143
+ const data = this.partialLine + chunk;
144
+ const lines = data.split('\n');
145
+ this.partialLine = lines.pop() ?? '';
146
+ for (const line of lines) {
147
+ if (!line.trim())
148
+ continue;
149
+ let record;
150
+ try {
151
+ record = JSON.parse(line);
152
+ }
153
+ catch {
154
+ // Mid-write torn line should be impossible (we split on \n), so a bad
155
+ // line is real corruption — surface it, never swallow.
156
+ this.events.onError(new Error(`unparseable transcript line (${line.length} bytes)`));
157
+ continue;
158
+ }
159
+ this.dispatch(record);
160
+ }
161
+ }
162
+ dispatch(record) {
163
+ if (record.isSidechain === true)
164
+ return; // subagent-internal records
165
+ this.seenRecords++;
166
+ if (record.type === 'assistant') {
167
+ const message = record.message;
168
+ if (message && Array.isArray(message.content)) {
169
+ this.events.onAssistant(record);
170
+ }
171
+ return;
172
+ }
173
+ if (record.type === 'system' && record.subtype === 'turn_duration') {
174
+ const durationMs = typeof record.durationMs === 'number' ? record.durationMs : 0;
175
+ this.events.onTurnEnd(durationMs);
176
+ }
177
+ }
178
+ }
179
+ exports.TranscriptTailer = TranscriptTailer;
180
+ TranscriptTailer.FALLBACK_SCAN_INTERVAL_MS = 2000;
181
+ //# sourceMappingURL=tailer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tailer.js","sourceRoot":"","sources":["../../src/shell/tailer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,kCAEC;AAED,wCAEC;AA3CD,uCAAyB;AACzB,uCAAyB;AACzB,2CAA6B;AA8B7B;;;;GAIG;AACH,SAAgB,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CA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C;YACvD,CAAC;YAAC,MAAM,CAAC;gBACP,sEAAsE;gBACtE,uDAAuD;gBACvD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC;gBACrF,SAAS;YACX,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAEO,QAAQ,CAAC,MAA+B;QAC9C,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI;YAAE,OAAO,CAAC,4BAA4B;QACrE,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAiD,CAAC;YACzE,IAAI,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC9C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAoC,CAAC,CAAC;YAChE,CAAC;YACD,OAAO;QACT,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO,KAAK,eAAe,EAAE,CAAC;YACnE,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YACjF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;;AAnHH,4CAoHC;AA3GyB,0CAAyB,GAAG,IAAK,AAAR,CAAS"}
package/dist/types.d.ts CHANGED
@@ -29,7 +29,8 @@ export interface AgentConfig {
29
29
  };
30
30
  claude: {
31
31
  model: string;
32
- dangerouslySkipPermissions: boolean;
32
+ /** @deprecated --dangerously-skip-permissions is always passed now; this field is ignored. */
33
+ dangerouslySkipPermissions?: boolean;
33
34
  extraFlags: string[];
34
35
  };
35
36
  /** Heartbeat / cron settings */
@@ -81,6 +82,11 @@ export interface GatewayConfig {
81
82
  api?: {
82
83
  keys: ApiKey[];
83
84
  };
85
+ /**
86
+ * true (default) = headless backend (claude --print + stream-json).
87
+ * false = interactive backend: claude TUI under the claude-pty-shell PTY wrapper.
88
+ */
89
+ headless?: boolean;
84
90
  /** Global history retention/cleanup defaults */
85
91
  history?: HistoryConfig & {
86
92
  cleanupHour?: number;