@dev-anywhere/proxy 0.5.42 → 0.5.44
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/chunk-UTV3TB7J.js +219 -0
- package/dist/chunk-UTV3TB7J.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/serve.js +39 -4
- package/dist/serve.js.map +1 -1
- package/dist/{terminal-AVTYE4MO.js → terminal-YHGOCQ33.js} +47 -9
- package/dist/terminal-YHGOCQ33.js.map +1 -0
- package/package.json +3 -3
- package/dist/chunk-5WZ6B735.js +0 -71
- package/dist/chunk-5WZ6B735.js.map +0 -1
- package/dist/terminal-AVTYE4MO.js.map +0 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/common/pty-approval-state.ts
|
|
4
|
+
function shouldReleaseApprovalWait(options) {
|
|
5
|
+
if (options.currentState !== "approval_wait") return false;
|
|
6
|
+
if (options.signalState === void 0) return false;
|
|
7
|
+
if (options.signalState === null && options.allowTitleOnlyRelease === false) return false;
|
|
8
|
+
return options.signalState !== "approval_wait";
|
|
9
|
+
}
|
|
10
|
+
function stateAfterApprovalRelease(signalState) {
|
|
11
|
+
if (signalState === null) return "turn_complete";
|
|
12
|
+
return signalState !== "approval_wait" ? signalState : "working";
|
|
13
|
+
}
|
|
14
|
+
function shouldReleaseTextApprovalOnInput(data) {
|
|
15
|
+
if (data.includes("\r") || data.includes("\n")) return true;
|
|
16
|
+
return data === "1" || data === "2" || data === "y" || data === "Y" || data === "n" || data === "N" || data === "\x1B" || data === "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/common/pty-semantic-machine.ts
|
|
20
|
+
function withMeta(signal) {
|
|
21
|
+
return {
|
|
22
|
+
...signal?.title !== void 0 ? { title: signal.title } : {},
|
|
23
|
+
...signal?.tool !== void 0 ? { tool: signal.tool } : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function decidePtySemanticTransition(input) {
|
|
27
|
+
const {
|
|
28
|
+
currentState,
|
|
29
|
+
signal,
|
|
30
|
+
sessionStateIsWaitingApproval,
|
|
31
|
+
allowTitleOnlyApprovalRelease = true
|
|
32
|
+
} = input;
|
|
33
|
+
if (signal?.state === "approval_wait") {
|
|
34
|
+
return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
|
|
35
|
+
}
|
|
36
|
+
if (shouldReleaseApprovalWait({
|
|
37
|
+
currentState,
|
|
38
|
+
signalState: signal === null ? void 0 : signal.state,
|
|
39
|
+
allowTitleOnlyRelease: allowTitleOnlyApprovalRelease
|
|
40
|
+
})) {
|
|
41
|
+
return {
|
|
42
|
+
nextState: stateAfterApprovalRelease(signal.state),
|
|
43
|
+
emit: true,
|
|
44
|
+
meta: withMeta(signal)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const inApprovalContext = currentState === "approval_wait" || sessionStateIsWaitingApproval === true;
|
|
48
|
+
if (inApprovalContext && signal?.state !== "turn_complete") {
|
|
49
|
+
return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
|
|
50
|
+
}
|
|
51
|
+
if (signal !== null && signal.state === null) {
|
|
52
|
+
return { nextState: currentState, emit: false };
|
|
53
|
+
}
|
|
54
|
+
if (signal && signal.state !== null && signal.state !== "working") {
|
|
55
|
+
return { nextState: signal.state, emit: true, meta: withMeta(signal) };
|
|
56
|
+
}
|
|
57
|
+
if (currentState !== "working" && signal?.state === "working") {
|
|
58
|
+
return { nextState: "working", emit: true };
|
|
59
|
+
}
|
|
60
|
+
return { nextState: currentState, emit: false };
|
|
61
|
+
}
|
|
62
|
+
function shouldStartPtyTurnOnInput(currentState, data) {
|
|
63
|
+
return currentState === "turn_complete" && (data.includes("\r") || data.includes("\n"));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/common/codex-xterm-history-compat.ts
|
|
67
|
+
var SYNC_OUTPUT_START = "\x1B[?2026h";
|
|
68
|
+
var SYNC_OUTPUT_END = "\x1B[?2026l";
|
|
69
|
+
var MAX_SYNC_BLOCK_CHARS = 1024 * 1024;
|
|
70
|
+
var ALT_SCREEN_SEQUENCE_RE = /\x1b\[\?(?:47|1047|1049)([hl])/g;
|
|
71
|
+
var HISTORY_INSERT_RE = /\x1b\[1;([1-9]\d*)r\x1b\[(\d*)S\x1b\[r\x1b\[([1-9]\d*);1H\x1b\[J/g;
|
|
72
|
+
var CODEX_XTERM_HISTORY_COMPAT_ENV = "DEV_ANYWHERE_CODEX_XTERM_HISTORY_COMPAT";
|
|
73
|
+
var CodexXtermHistoryCompat = class {
|
|
74
|
+
pending = "";
|
|
75
|
+
state = "outside";
|
|
76
|
+
alternateScreen = false;
|
|
77
|
+
altScanCarry = "";
|
|
78
|
+
terminalRows;
|
|
79
|
+
rewrittenTransactions = 0;
|
|
80
|
+
preservedRows = 0;
|
|
81
|
+
constructor(rows) {
|
|
82
|
+
this.terminalRows = rows;
|
|
83
|
+
}
|
|
84
|
+
get stats() {
|
|
85
|
+
return {
|
|
86
|
+
rewrittenTransactions: this.rewrittenTransactions,
|
|
87
|
+
preservedRows: this.preservedRows
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
push(data) {
|
|
91
|
+
if (!data) return "";
|
|
92
|
+
this.pending += data;
|
|
93
|
+
let output = "";
|
|
94
|
+
while (this.pending.length > 0) {
|
|
95
|
+
if (this.state === "buffering-sync") {
|
|
96
|
+
const endIndex = this.pending.indexOf(SYNC_OUTPUT_END, SYNC_OUTPUT_START.length);
|
|
97
|
+
if (endIndex === -1) {
|
|
98
|
+
if (this.pending.length <= MAX_SYNC_BLOCK_CHARS) break;
|
|
99
|
+
const keep2 = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);
|
|
100
|
+
const passthrough2 = this.pending.slice(0, this.pending.length - keep2);
|
|
101
|
+
output += passthrough2;
|
|
102
|
+
this.scanAlternateScreen(passthrough2);
|
|
103
|
+
this.pending = this.pending.slice(this.pending.length - keep2);
|
|
104
|
+
this.state = "passthrough-sync";
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const blockEnd = endIndex + SYNC_OUTPUT_END.length;
|
|
108
|
+
const block = this.pending.slice(0, blockEnd);
|
|
109
|
+
this.pending = this.pending.slice(blockEnd);
|
|
110
|
+
output += this.rewriteSynchronizedBlock(block);
|
|
111
|
+
this.state = "outside";
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (this.state === "passthrough-sync") {
|
|
115
|
+
const endIndex = this.pending.indexOf(SYNC_OUTPUT_END);
|
|
116
|
+
if (endIndex === -1) {
|
|
117
|
+
const keep2 = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);
|
|
118
|
+
const passthrough3 = this.pending.slice(0, this.pending.length - keep2);
|
|
119
|
+
output += passthrough3;
|
|
120
|
+
this.scanAlternateScreen(passthrough3);
|
|
121
|
+
this.pending = this.pending.slice(this.pending.length - keep2);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
const blockEnd = endIndex + SYNC_OUTPUT_END.length;
|
|
125
|
+
const passthrough2 = this.pending.slice(0, blockEnd);
|
|
126
|
+
output += passthrough2;
|
|
127
|
+
this.scanAlternateScreen(passthrough2);
|
|
128
|
+
this.pending = this.pending.slice(blockEnd);
|
|
129
|
+
this.state = "outside";
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const startIndex = this.pending.indexOf(SYNC_OUTPUT_START);
|
|
133
|
+
if (startIndex !== -1) {
|
|
134
|
+
const passthrough2 = this.pending.slice(0, startIndex);
|
|
135
|
+
output += passthrough2;
|
|
136
|
+
this.scanAlternateScreen(passthrough2);
|
|
137
|
+
this.pending = this.pending.slice(startIndex);
|
|
138
|
+
this.state = "buffering-sync";
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const keep = longestSuffixPrefix(this.pending, SYNC_OUTPUT_START);
|
|
142
|
+
const passthrough = this.pending.slice(0, this.pending.length - keep);
|
|
143
|
+
output += passthrough;
|
|
144
|
+
this.scanAlternateScreen(passthrough);
|
|
145
|
+
this.pending = this.pending.slice(this.pending.length - keep);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
return output;
|
|
149
|
+
}
|
|
150
|
+
/** Flushes an incomplete candidate byte-for-byte, for resize/exit boundaries. */
|
|
151
|
+
flush() {
|
|
152
|
+
const pending = this.pending;
|
|
153
|
+
this.pending = "";
|
|
154
|
+
this.state = "outside";
|
|
155
|
+
this.scanAlternateScreen(pending);
|
|
156
|
+
return pending;
|
|
157
|
+
}
|
|
158
|
+
setTerminalRows(rows) {
|
|
159
|
+
this.terminalRows = rows;
|
|
160
|
+
}
|
|
161
|
+
rewriteSynchronizedBlock(block) {
|
|
162
|
+
const startsInAlternateScreen = this.alternateScreen;
|
|
163
|
+
ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
|
|
164
|
+
const switchesScreenBuffer = ALT_SCREEN_SEQUENCE_RE.test(block);
|
|
165
|
+
ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
|
|
166
|
+
let rewritten = block;
|
|
167
|
+
if (!startsInAlternateScreen && !switchesScreenBuffer) {
|
|
168
|
+
rewritten = block.replace(
|
|
169
|
+
HISTORY_INSERT_RE,
|
|
170
|
+
(original, bottomRaw, countRaw, repaintRowRaw) => {
|
|
171
|
+
const bottom = Number.parseInt(bottomRaw, 10);
|
|
172
|
+
const parsedCount = countRaw === "" ? 1 : Number.parseInt(countRaw, 10);
|
|
173
|
+
const count = parsedCount === 0 ? 1 : parsedCount;
|
|
174
|
+
const repaintRow = Number.parseInt(repaintRowRaw, 10);
|
|
175
|
+
const expectedRepaintRow = bottom - count + 1;
|
|
176
|
+
if (!Number.isSafeInteger(bottom) || !Number.isSafeInteger(count) || !Number.isSafeInteger(repaintRow) || bottom >= this.terminalRows || count < 1 || count > bottom || repaintRow !== expectedRepaintRow) {
|
|
177
|
+
return original;
|
|
178
|
+
}
|
|
179
|
+
this.rewrittenTransactions += 1;
|
|
180
|
+
this.preservedRows += count;
|
|
181
|
+
return `\x1B[r\x1B[999;1H${"\n".repeat(count)}\x1B[H\x1B[${repaintRow};1H\x1B[J`;
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
this.scanAlternateScreen(block);
|
|
186
|
+
return rewritten;
|
|
187
|
+
}
|
|
188
|
+
scanAlternateScreen(data) {
|
|
189
|
+
if (!data) return;
|
|
190
|
+
const scan = this.altScanCarry + data;
|
|
191
|
+
ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
|
|
192
|
+
for (const match of scan.matchAll(ALT_SCREEN_SEQUENCE_RE)) {
|
|
193
|
+
this.alternateScreen = match[1] === "h";
|
|
194
|
+
}
|
|
195
|
+
ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
|
|
196
|
+
this.altScanCarry = scan.slice(-(SYNC_OUTPUT_START.length - 1));
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
function createCodexXtermHistoryCompat(provider, rows, env) {
|
|
200
|
+
if (provider !== "codex") return null;
|
|
201
|
+
const configured = env[CODEX_XTERM_HISTORY_COMPAT_ENV]?.trim().toLowerCase();
|
|
202
|
+
if (configured === "0" || configured === "false" || configured === "off") return null;
|
|
203
|
+
return new CodexXtermHistoryCompat(rows);
|
|
204
|
+
}
|
|
205
|
+
function longestSuffixPrefix(value, marker) {
|
|
206
|
+
const max = Math.min(value.length, marker.length - 1);
|
|
207
|
+
for (let length = max; length > 0; length -= 1) {
|
|
208
|
+
if (value.endsWith(marker.slice(0, length))) return length;
|
|
209
|
+
}
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export {
|
|
214
|
+
shouldReleaseTextApprovalOnInput,
|
|
215
|
+
decidePtySemanticTransition,
|
|
216
|
+
shouldStartPtyTurnOnInput,
|
|
217
|
+
createCodexXtermHistoryCompat
|
|
218
|
+
};
|
|
219
|
+
//# sourceMappingURL=chunk-UTV3TB7J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common/pty-approval-state.ts","../src/common/pty-semantic-machine.ts","../src/common/codex-xterm-history-compat.ts"],"sourcesContent":["import type { PtySemanticState } from \"@dev-anywhere/shared\";\n\n// signalState 三态:undefined 表示本帧没有任何 signal;null 表示有 signal 但只承载 title(OSC 0\n// only,无明确语义);其它值是明确语义状态。title-only signal 也视为对 approval_wait 的释放\n// 信号——codex 取消审批后 OSC 0 标题脱离 \"Action Required\" 即走这条路径。\nexport function shouldReleaseApprovalWait(options: {\n currentState: PtySemanticState;\n signalState: PtySemanticState | null | undefined;\n allowTitleOnlyRelease?: boolean;\n}): boolean {\n if (options.currentState !== \"approval_wait\") return false;\n if (options.signalState === undefined) return false;\n if (options.signalState === null && options.allowTitleOnlyRelease === false) return false;\n return options.signalState !== \"approval_wait\";\n}\n\nexport function stateAfterApprovalRelease(signalState: PtySemanticState | null): PtySemanticState {\n // title-only 释放(signal.state===null)= codex 取消审批语义,等用户下一轮输入。\n if (signalState === null) return \"turn_complete\";\n return signalState !== \"approval_wait\" ? signalState : \"working\";\n}\n\nexport function shouldReleaseTextApprovalOnInput(data: string): boolean {\n if (data.includes(\"\\r\") || data.includes(\"\\n\")) return true;\n return (\n data === \"1\" ||\n data === \"2\" ||\n data === \"y\" ||\n data === \"Y\" ||\n data === \"n\" ||\n data === \"N\" ||\n data === \"\\x1b\" ||\n data === \"\\x03\"\n );\n}\n","import type { PtySemanticState } from \"@dev-anywhere/shared\";\nimport { shouldReleaseApprovalWait, stateAfterApprovalRelease } from \"./pty-approval-state.js\";\n\n// PTY 语义状态机的纯决策层。从一段 PTY 输出抽到的 OSC 信号 + 当前 PTY 局部状态出发,\n// 决定下一态以及是否要 emit 一次 pty_state 事件。\n// 副作用(changeSessionState、onTurnComplete、IPC 写)由调用方负责,本模块零 IO,便于单测。\n//\n// signal.state 三态:明确语义(working/turn_complete/approval_wait)、null(仅 OSC 0 title\n// 更新无语义)、signal 整体为 null(本帧无 OSC)。title-only signal 在 approval_wait 上下文\n// 下视为释放信号(codex 取消审批),其它上下文不参与 FSM 决策。\n\ninterface PtySignal {\n state: PtySemanticState | null;\n title?: string;\n tool?: string;\n}\n\ninterface PtyTransitionInput {\n currentState: PtySemanticState;\n signal: PtySignal | null;\n // hosted-pty 在 JSON FSM 维度也维护 session.state;当外部 hook 已先把 session 推到\n // WAITING_APPROVAL 而本地 currentState 还停在 working 时,本帧仍应被解释为审批等待中。\n // terminal.ts 没有这个上下文,传 false / undefined 即可。\n sessionStateIsWaitingApproval?: boolean;\n // Codex 的审批取消依赖 title-only OSC 释放;Claude hook 文本审批期间也会继续发普通\n // title-only spinner,此时不能把它当成审批结束。\n allowTitleOnlyApprovalRelease?: boolean;\n}\n\ninterface PtyTransitionResult {\n // 决策后应当采用的 currentState 值;与 input.currentState 相同表示局部状态不变。\n nextState: PtySemanticState;\n // 是否要把这次决策作为一次 pty_state 事件外发(含 hosted 端的 sessionFsm 副作用)。\n emit: boolean;\n // 透传给 emit 事件的 meta;emit=false 时忽略。\n meta?: { title?: string; tool?: string };\n}\n\nfunction withMeta(signal: PtySignal | null | undefined): { title?: string; tool?: string } {\n return {\n ...(signal?.title !== undefined ? { title: signal.title } : {}),\n ...(signal?.tool !== undefined ? { tool: signal.tool } : {}),\n };\n}\n\nexport function decidePtySemanticTransition(input: PtyTransitionInput): PtyTransitionResult {\n const {\n currentState,\n signal,\n sessionStateIsWaitingApproval,\n allowTitleOnlyApprovalRelease = true,\n } = input;\n\n // 1. 显式 approval_wait 信号:进入 / 维持审批等待。\n if (signal?.state === \"approval_wait\") {\n return { nextState: \"approval_wait\", emit: true, meta: withMeta(signal) };\n }\n\n // 2. 已在 approval_wait 且收到非 approval_wait 信号(含 title-only):审批解除,\n // 落到 stateAfterApprovalRelease 决定的状态上。\n if (\n shouldReleaseApprovalWait({\n currentState,\n signalState: signal === null ? undefined : signal.state,\n allowTitleOnlyRelease: allowTitleOnlyApprovalRelease,\n })\n ) {\n return {\n nextState: stateAfterApprovalRelease(signal!.state),\n emit: true,\n meta: withMeta(signal),\n };\n }\n\n // 3. 审批上下文兜底:currentState=approval_wait 或 sessionState 已是 WAITING_APPROVAL 但还没收到\n // 解除信号。此时即便有其它信号也不应让 PTY 状态偏离审批等待,仍 re-emit approval_wait。\n // turn_complete 不在此列:它是合法的解除终点(由 #2 处理)。\n const inApprovalContext =\n currentState === \"approval_wait\" || sessionStateIsWaitingApproval === true;\n if (inApprovalContext && signal?.state !== \"turn_complete\") {\n return { nextState: \"approval_wait\", emit: true, meta: withMeta(signal) };\n }\n\n // 4. title-only signal(state=null,且不在审批上下文):纯标题刷新不参与 FSM 决策,title 由调用方\n // 单独经 sendTerminalTitle 推。\n if (signal !== null && signal.state === null) {\n return { nextState: currentState, emit: false };\n }\n\n // 5. 任意非 working 显式信号(turn_complete):直接落到 signal.state。\n if (signal && signal.state !== null && signal.state !== \"working\") {\n return { nextState: signal.state, emit: true, meta: withMeta(signal) };\n }\n\n // 6. 进入 working:输出侧只接受 provider 的显式 working 信号。turn_complete 是锁存态,\n // TUI 在空闲提示符上的可见重绘不能开启新一轮;新一轮由用户提交输入或\n // provider hook 明确启动。\n if (currentState !== \"working\" && signal?.state === \"working\") {\n return { nextState: \"working\", emit: true };\n }\n\n // 7. 没有有效信号,维持当前状态。\n return { nextState: currentState, emit: false };\n}\n\nexport function shouldStartPtyTurnOnInput(currentState: PtySemanticState, data: string): boolean {\n return currentState === \"turn_complete\" && (data.includes(\"\\r\") || data.includes(\"\\n\"));\n}\n","const SYNC_OUTPUT_START = \"\\x1b[?2026h\";\nconst SYNC_OUTPUT_END = \"\\x1b[?2026l\";\nconst MAX_SYNC_BLOCK_CHARS = 1024 * 1024;\nconst ALT_SCREEN_SEQUENCE_RE = /\\x1b\\[\\?(?:47|1047|1049)([hl])/g;\nconst HISTORY_INSERT_RE = /\\x1b\\[1;([1-9]\\d*)r\\x1b\\[(\\d*)S\\x1b\\[r\\x1b\\[([1-9]\\d*);1H\\x1b\\[J/g;\n\nexport const CODEX_XTERM_HISTORY_COMPAT_ENV = \"DEV_ANYWHERE_CODEX_XTERM_HISTORY_COMPAT\";\n\ntype StreamState = \"outside\" | \"buffering-sync\" | \"passthrough-sync\";\n\nexport interface CodexXtermHistoryCompatStats {\n rewrittenTransactions: number;\n preservedRows: number;\n}\n\n/**\n * Rewrites Codex inline-history inserts into a full-screen scroll that xterm.js records in\n * scrollback. The matcher deliberately requires Codex's synchronized-output transaction and\n * immediate composer repaint; all other bytes pass through unchanged.\n *\n * Upstream context: https://github.com/openai/codex/issues/27644\n */\nexport class CodexXtermHistoryCompat {\n private pending = \"\";\n private state: StreamState = \"outside\";\n private alternateScreen = false;\n private altScanCarry = \"\";\n private terminalRows: number;\n private rewrittenTransactions = 0;\n private preservedRows = 0;\n\n constructor(rows: number) {\n this.terminalRows = rows;\n }\n\n get stats(): CodexXtermHistoryCompatStats {\n return {\n rewrittenTransactions: this.rewrittenTransactions,\n preservedRows: this.preservedRows,\n };\n }\n\n push(data: string): string {\n if (!data) return \"\";\n this.pending += data;\n let output = \"\";\n\n while (this.pending.length > 0) {\n if (this.state === \"buffering-sync\") {\n const endIndex = this.pending.indexOf(SYNC_OUTPUT_END, SYNC_OUTPUT_START.length);\n if (endIndex === -1) {\n if (this.pending.length <= MAX_SYNC_BLOCK_CHARS) break;\n const keep = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);\n const passthrough = this.pending.slice(0, this.pending.length - keep);\n output += passthrough;\n this.scanAlternateScreen(passthrough);\n this.pending = this.pending.slice(this.pending.length - keep);\n this.state = \"passthrough-sync\";\n continue;\n }\n\n const blockEnd = endIndex + SYNC_OUTPUT_END.length;\n const block = this.pending.slice(0, blockEnd);\n this.pending = this.pending.slice(blockEnd);\n output += this.rewriteSynchronizedBlock(block);\n this.state = \"outside\";\n continue;\n }\n\n if (this.state === \"passthrough-sync\") {\n const endIndex = this.pending.indexOf(SYNC_OUTPUT_END);\n if (endIndex === -1) {\n const keep = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);\n const passthrough = this.pending.slice(0, this.pending.length - keep);\n output += passthrough;\n this.scanAlternateScreen(passthrough);\n this.pending = this.pending.slice(this.pending.length - keep);\n break;\n }\n\n const blockEnd = endIndex + SYNC_OUTPUT_END.length;\n const passthrough = this.pending.slice(0, blockEnd);\n output += passthrough;\n this.scanAlternateScreen(passthrough);\n this.pending = this.pending.slice(blockEnd);\n this.state = \"outside\";\n continue;\n }\n\n const startIndex = this.pending.indexOf(SYNC_OUTPUT_START);\n if (startIndex !== -1) {\n const passthrough = this.pending.slice(0, startIndex);\n output += passthrough;\n this.scanAlternateScreen(passthrough);\n this.pending = this.pending.slice(startIndex);\n this.state = \"buffering-sync\";\n continue;\n }\n\n const keep = longestSuffixPrefix(this.pending, SYNC_OUTPUT_START);\n const passthrough = this.pending.slice(0, this.pending.length - keep);\n output += passthrough;\n this.scanAlternateScreen(passthrough);\n this.pending = this.pending.slice(this.pending.length - keep);\n break;\n }\n\n return output;\n }\n\n /** Flushes an incomplete candidate byte-for-byte, for resize/exit boundaries. */\n flush(): string {\n const pending = this.pending;\n this.pending = \"\";\n this.state = \"outside\";\n this.scanAlternateScreen(pending);\n return pending;\n }\n\n setTerminalRows(rows: number): void {\n this.terminalRows = rows;\n }\n\n private rewriteSynchronizedBlock(block: string): string {\n const startsInAlternateScreen = this.alternateScreen;\n ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;\n const switchesScreenBuffer = ALT_SCREEN_SEQUENCE_RE.test(block);\n ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;\n\n let rewritten = block;\n if (!startsInAlternateScreen && !switchesScreenBuffer) {\n rewritten = block.replace(\n HISTORY_INSERT_RE,\n (original, bottomRaw: string, countRaw: string, repaintRowRaw: string) => {\n const bottom = Number.parseInt(bottomRaw, 10);\n const parsedCount = countRaw === \"\" ? 1 : Number.parseInt(countRaw, 10);\n const count = parsedCount === 0 ? 1 : parsedCount;\n const repaintRow = Number.parseInt(repaintRowRaw, 10);\n const expectedRepaintRow = bottom - count + 1;\n\n if (\n !Number.isSafeInteger(bottom) ||\n !Number.isSafeInteger(count) ||\n !Number.isSafeInteger(repaintRow) ||\n bottom >= this.terminalRows ||\n count < 1 ||\n count > bottom ||\n repaintRow !== expectedRepaintRow\n ) {\n return original;\n }\n\n this.rewrittenTransactions += 1;\n this.preservedRows += count;\n return `\\x1b[r\\x1b[999;1H${\"\\n\".repeat(count)}\\x1b[H\\x1b[${repaintRow};1H\\x1b[J`;\n },\n );\n }\n\n this.scanAlternateScreen(block);\n return rewritten;\n }\n\n private scanAlternateScreen(data: string): void {\n if (!data) return;\n const scan = this.altScanCarry + data;\n ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;\n for (const match of scan.matchAll(ALT_SCREEN_SEQUENCE_RE)) {\n this.alternateScreen = match[1] === \"h\";\n }\n ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;\n this.altScanCarry = scan.slice(-(SYNC_OUTPUT_START.length - 1));\n }\n}\n\nexport function createCodexXtermHistoryCompat(\n provider: string | null | undefined,\n rows: number,\n env: NodeJS.ProcessEnv,\n): CodexXtermHistoryCompat | null {\n if (provider !== \"codex\") return null;\n const configured = env[CODEX_XTERM_HISTORY_COMPAT_ENV]?.trim().toLowerCase();\n if (configured === \"0\" || configured === \"false\" || configured === \"off\") return null;\n return new CodexXtermHistoryCompat(rows);\n}\n\nfunction longestSuffixPrefix(value: string, marker: string): number {\n const max = Math.min(value.length, marker.length - 1);\n for (let length = max; length > 0; length -= 1) {\n if (value.endsWith(marker.slice(0, length))) return length;\n }\n return 0;\n}\n"],"mappings":";;;AAKO,SAAS,0BAA0B,SAI9B;AACV,MAAI,QAAQ,iBAAiB,gBAAiB,QAAO;AACrD,MAAI,QAAQ,gBAAgB,OAAW,QAAO;AAC9C,MAAI,QAAQ,gBAAgB,QAAQ,QAAQ,0BAA0B,MAAO,QAAO;AACpF,SAAO,QAAQ,gBAAgB;AACjC;AAEO,SAAS,0BAA0B,aAA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EQ,oBAAoB,MAAoB;AAC9C,QAAI,CAAC,KAAM;AACX,UAAM,OAAO,KAAK,eAAe;AACjC,2BAAuB,YAAY;AACnC,eAAW,SAAS,KAAK,SAAS,sBAAsB,GAAG;AACzD,WAAK,kBAAkB,MAAM,CAAC,MAAM;AAAA,IACtC;AACA,2BAAuB,YAAY;AACnC,SAAK,eAAe,KAAK,MAAM,EAAE,kBAAkB,SAAS,EAAE;AAAA,EAChE;AACF;AAEO,SAAS,8BACd,UACA,MACA,KACgC;AAChC,MAAI,aAAa,QAAS,QAAO;AACjC,QAAM,aAAa,IAAI,8BAA8B,GAAG,KAAK,EAAE,YAAY;AAC3E,MAAI,eAAe,OAAO,eAAe,WAAW,eAAe,MAAO,QAAO;AACjF,SAAO,IAAI,wBAAwB,IAAI;AACzC;AAEA,SAAS,oBAAoB,OAAe,QAAwB;AAClE,QAAM,MAAM,KAAK,IAAI,MAAM,QAAQ,OAAO,SAAS,CAAC;AACpD,WAAS,SAAS,KAAK,SAAS,GAAG,UAAU,GAAG;AAC9C,QAAI,MAAM,SAAS,OAAO,MAAM,GAAG,MAAM,CAAC,EAAG,QAAO;AAAA,EACtD;AACA,SAAO;AACT;","names":["keep","passthrough"]}
|
package/dist/index.js
CHANGED
|
@@ -269,7 +269,7 @@ var program = new Command("dev-anywhere").description("Dev Anywhere - transparen
|
|
|
269
269
|
console.error(err instanceof Error ? err.message : String(err));
|
|
270
270
|
process.exit(1);
|
|
271
271
|
}
|
|
272
|
-
const { startTerminal } = await import("./terminal-
|
|
272
|
+
const { startTerminal } = await import("./terminal-YHGOCQ33.js");
|
|
273
273
|
const { provider, args } = invocation;
|
|
274
274
|
await startTerminal(args, provider);
|
|
275
275
|
});
|
package/dist/serve.js
CHANGED
|
@@ -14,10 +14,11 @@ import {
|
|
|
14
14
|
getSeqCounterFor
|
|
15
15
|
} from "./chunk-NXELIU46.js";
|
|
16
16
|
import {
|
|
17
|
+
createCodexXtermHistoryCompat,
|
|
17
18
|
decidePtySemanticTransition,
|
|
18
19
|
shouldReleaseTextApprovalOnInput,
|
|
19
20
|
shouldStartPtyTurnOnInput
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-UTV3TB7J.js";
|
|
21
22
|
import {
|
|
22
23
|
CLAUDE_PROVIDER,
|
|
23
24
|
CODEX_PROVIDER,
|
|
@@ -3915,6 +3916,12 @@ var HostedPtyRegistry = class {
|
|
|
3915
3916
|
child,
|
|
3916
3917
|
terminal,
|
|
3917
3918
|
serializeAddon,
|
|
3919
|
+
xtermHistoryCompat: createCodexXtermHistoryCompat(
|
|
3920
|
+
options.kind === "terminal" ? null : options.provider,
|
|
3921
|
+
rows,
|
|
3922
|
+
this.deps.getProviderEnv()
|
|
3923
|
+
),
|
|
3924
|
+
xtermHistoryCompatReported: false,
|
|
3918
3925
|
idleTimer: setInterval(() => this.checkIdle(options.sessionId), IDLE_CHECK_INTERVAL_MS),
|
|
3919
3926
|
startedAt: Date.now(),
|
|
3920
3927
|
lastOutputTime: 0,
|
|
@@ -3981,6 +3988,8 @@ var HostedPtyRegistry = class {
|
|
|
3981
3988
|
resize(sessionId, cols, rows) {
|
|
3982
3989
|
const hosted = this.sessions.get(sessionId);
|
|
3983
3990
|
if (!hosted) return false;
|
|
3991
|
+
this.flushPendingRenderData(sessionId, hosted);
|
|
3992
|
+
hosted.xtermHistoryCompat?.setTerminalRows(rows);
|
|
3984
3993
|
hosted.child.resize(cols, rows);
|
|
3985
3994
|
hosted.terminal.resize(cols, rows);
|
|
3986
3995
|
this.deps.relayConnection.sendRaw(
|
|
@@ -4030,11 +4039,12 @@ var HostedPtyRegistry = class {
|
|
|
4030
4039
|
const hosted = this.sessions.get(sessionId);
|
|
4031
4040
|
if (!hosted) return;
|
|
4032
4041
|
hosted.lastOutputTime = Date.now();
|
|
4033
|
-
hosted.outputSeq += 1;
|
|
4034
4042
|
hosted.startupOutput = appendStartupOutput(hosted.startupOutput, data);
|
|
4035
|
-
hosted.terminal.write(data);
|
|
4036
4043
|
this.deps.touchSessionActivity(sessionId);
|
|
4037
|
-
|
|
4044
|
+
const previousRewriteCount = hosted.xtermHistoryCompat?.stats.rewrittenTransactions ?? 0;
|
|
4045
|
+
const renderData = hosted.xtermHistoryCompat?.push(data) ?? data;
|
|
4046
|
+
this.emitRenderData(sessionId, hosted, renderData);
|
|
4047
|
+
this.reportXtermHistoryCompatRewrite(sessionId, hosted, previousRewriteCount);
|
|
4038
4048
|
const oscSequences = extractOscSequences(data);
|
|
4039
4049
|
const cwd = extractOscWorkingDirectory(data);
|
|
4040
4050
|
const session = this.deps.sessionManager.getSession(sessionId);
|
|
@@ -4140,10 +4150,35 @@ var HostedPtyRegistry = class {
|
|
|
4140
4150
|
sendBinary(sessionId, data, outputSeq) {
|
|
4141
4151
|
this.deps.relayConnection.sendBinary(encodeBinaryFrame(sessionId, outputSeq, data));
|
|
4142
4152
|
}
|
|
4153
|
+
emitRenderData(sessionId, hosted, data) {
|
|
4154
|
+
if (!data) return;
|
|
4155
|
+
hosted.outputSeq += 1;
|
|
4156
|
+
hosted.terminal.write(data);
|
|
4157
|
+
this.sendBinary(sessionId, Buffer.from(data, "utf-8"), hosted.outputSeq);
|
|
4158
|
+
}
|
|
4159
|
+
flushPendingRenderData(sessionId, hosted) {
|
|
4160
|
+
this.emitRenderData(sessionId, hosted, hosted.xtermHistoryCompat?.flush() ?? "");
|
|
4161
|
+
}
|
|
4162
|
+
reportXtermHistoryCompatRewrite(sessionId, hosted, previousRewriteCount) {
|
|
4163
|
+
const stats = hosted.xtermHistoryCompat?.stats;
|
|
4164
|
+
if (!stats || stats.rewrittenTransactions === previousRewriteCount) return;
|
|
4165
|
+
const payload = {
|
|
4166
|
+
sessionId,
|
|
4167
|
+
rewrittenTransactions: stats.rewrittenTransactions,
|
|
4168
|
+
preservedRows: stats.preservedRows
|
|
4169
|
+
};
|
|
4170
|
+
if (!hosted.xtermHistoryCompatReported) {
|
|
4171
|
+
hosted.xtermHistoryCompatReported = true;
|
|
4172
|
+
serviceLogger.info(payload, "Codex xterm history compatibility activated");
|
|
4173
|
+
} else {
|
|
4174
|
+
serviceLogger.debug(payload, "Codex xterm history transaction rewritten");
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4143
4177
|
close(sessionId, options) {
|
|
4144
4178
|
const hosted = this.sessions.get(sessionId);
|
|
4145
4179
|
if (!hosted) return false;
|
|
4146
4180
|
clearInterval(hosted.idleTimer);
|
|
4181
|
+
this.flushPendingRenderData(sessionId, hosted);
|
|
4147
4182
|
if (options.kill) {
|
|
4148
4183
|
try {
|
|
4149
4184
|
hosted.child.kill();
|