@dev-anywhere/proxy 0.5.24 → 0.5.25
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-F53HQ6GP.js → chunk-6D4UN567.js} +15 -2
- package/dist/chunk-6D4UN567.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/serve.js +37 -33
- package/dist/serve.js.map +1 -1
- package/dist/{terminal-C3CVPFOD.js → terminal-VGCVESF6.js} +29 -22
- package/dist/terminal-VGCVESF6.js.map +1 -0
- package/dist/terminal-worker.js +16 -13
- package/dist/terminal-worker.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-F53HQ6GP.js.map +0 -1
- package/dist/terminal-C3CVPFOD.js.map +0 -1
|
@@ -100,11 +100,24 @@ function extractOscSignals(rawData, provider) {
|
|
|
100
100
|
return null;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
// src/common/pty-snapshot.ts
|
|
104
|
+
function capturePtySnapshot(terminal, serializer, outputSeq, onSnapshot) {
|
|
105
|
+
terminal.write("", () => {
|
|
106
|
+
onSnapshot({
|
|
107
|
+
cols: terminal.cols,
|
|
108
|
+
rows: terminal.rows,
|
|
109
|
+
data: serializer.serialize(),
|
|
110
|
+
outputSeq
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
103
115
|
export {
|
|
104
116
|
extractOscSequences,
|
|
105
117
|
extractOscWorkingDirectory,
|
|
106
118
|
appendPtySemanticTextTail,
|
|
107
119
|
extractTextSignals,
|
|
108
|
-
extractOscSignals
|
|
120
|
+
extractOscSignals,
|
|
121
|
+
capturePtySnapshot
|
|
109
122
|
};
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-6D4UN567.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common/osc-extractor.ts","../src/common/pty-snapshot.ts"],"sourcesContent":["import type { PtySemanticState } from \"@dev-anywhere/shared\";\n\n// OSC 0: 窗口标题 -- ESC ] 0 ; <title> BEL/ST\n// OSC 9: 通知 -- ESC ] 9 ; <text> BEL/ST\n// 每次调用创建新的 regex 实例避免 g flag 导致的 lastIndex 状态泄漏\n// eslint-disable-next-line no-control-regex\nconst OSC_PATTERN = /\\x1b\\](\\d+);([^\\x07\\x1b]*?)(?:\\x07|\\x1b\\\\)/g;\n\ntype PtySignalProvider = \"claude\" | \"codex\";\n\ninterface PtyStateEvent {\n state: PtySemanticState | null;\n title?: string;\n tool?: string;\n}\n\ninterface OscSequence {\n code: number;\n text: string;\n}\n\n// Keep enough recent text to bridge PTY chunk splits without retaining whole scrollback.\nconst SEMANTIC_TEXT_TAIL_MAX = 4096;\n\n// eslint-disable-next-line no-control-regex\nconst OSC_SEQUENCE_PATTERN = /\\x1b\\](?:\\d+);[^\\x07\\x1b]*?(?:\\x07|\\x1b\\\\)/g;\n// eslint-disable-next-line no-control-regex\nconst CSI_SEQUENCE_PATTERN = /\\x1b\\[[0-?]*[ -/]*[@-~]/g;\n// eslint-disable-next-line no-control-regex\nconst SIMPLE_ESC_PATTERN = /\\x1b[@-Z\\\\-_]/g;\n\nexport function extractOscSequences(rawData: string): OscSequence[] {\n const regex = new RegExp(OSC_PATTERN.source, OSC_PATTERN.flags);\n const matches: OscSequence[] = [];\n\n let match: RegExpExecArray | null;\n while ((match = regex.exec(rawData)) !== null) {\n matches.push({ code: parseInt(match[1], 10), text: match[2] });\n }\n\n return matches;\n}\n\nfunction lastSequence(matches: OscSequence[], code: number): OscSequence | undefined {\n for (let i = matches.length - 1; i >= 0; i -= 1) {\n if (matches[i].code === code) return matches[i];\n }\n return undefined;\n}\n\nexport function extractOscWorkingDirectory(rawData: string): string | null {\n const osc7 = lastSequence(extractOscSequences(rawData), 7);\n if (!osc7) return null;\n\n try {\n const uri = new URL(osc7.text);\n if (uri.protocol !== \"file:\") return null;\n const pathname = decodeURIComponent(uri.pathname);\n return pathname.startsWith(\"/\") ? pathname : null;\n } catch {\n return null;\n }\n}\n\nfunction isCodexActionRequiredTitle(title: string): boolean {\n return /\\bAction Required\\b/i.test(title);\n}\n\nexport function normalizePtySemanticText(rawData: string): string {\n return rawData\n .replace(OSC_SEQUENCE_PATTERN, \" \")\n .replace(CSI_SEQUENCE_PATTERN, \" \")\n .replace(SIMPLE_ESC_PATTERN, \" \")\n .replace(/\\r/g, \"\\n\")\n .replace(/[^\\S\\n]+/g, \" \")\n .replace(/\\n+/g, \"\\n\")\n .trim();\n}\n\nexport function appendPtySemanticTextTail(previous: string, chunk: string): string {\n const next = `${previous}\\n${normalizePtySemanticText(chunk)}`.slice(-SEMANTIC_TEXT_TAIL_MAX);\n return next.trim();\n}\n\nfunction extractClaudeTextSignal(text: string): PtyStateEvent | null {\n const toolMatch = text.match(/\\bHook\\s+PreToolUse:([A-Za-z0-9_.:-]+)/i);\n if (\n toolMatch?.[1] &&\n /\\brequires confirmation for this (?:command|tool)\\b/i.test(text) &&\n /\\bDo you want to proceed\\?/i.test(text)\n ) {\n return {\n state: \"approval_wait\",\n tool: toolMatch[1],\n title: `Hook confirmation: ${toolMatch[1]}`,\n };\n }\n\n const nativePermissionMatch = text.match(\n /\\bDo you want to (?<action>make this edit to|create|update|delete|run|execute)\\b[^\\n?]*\\?/i,\n );\n if (\n nativePermissionMatch?.groups?.action &&\n /\\b1\\.\\s*Yes\\b/i.test(text) &&\n /\\b3\\.\\s*No\\b/i.test(text)\n ) {\n const action = nativePermissionMatch.groups.action.toLowerCase();\n const tool = action === \"run\" || action === \"execute\" ? \"Bash\" : \"Edit\";\n return {\n state: \"approval_wait\",\n tool,\n title: `Claude permission: ${tool}`,\n };\n }\n return null;\n}\n\nexport function extractTextSignals(\n semanticText: string,\n provider?: PtySignalProvider,\n): PtyStateEvent | null {\n if (provider === \"claude\") {\n return extractClaudeTextSignal(semanticText);\n }\n return null;\n}\n\n// 从 PTY 原始数据中提取 OSC 语义信号。\n// OSC 9 优先级高于 OSC 0,无匹配时返回 null。\n// 仅 OSC 0(spinner/标题)返回 { state: null, title },让调用方推 title 但不动 FSM。\nexport function extractOscSignals(\n rawData: string,\n provider?: PtySignalProvider,\n): PtyStateEvent | null {\n const matches = extractOscSequences(rawData);\n\n if (matches.length === 0) return null;\n\n const osc0 = lastSequence(matches, 0);\n\n // OSC 9 优先级更高,包含具体的语义信号;同帧 OSC 0 仍保留 title 给 UI。\n const osc9 = lastSequence(matches, 9);\n if (osc9) {\n if (osc9.text.includes(\"waiting for your input\") || osc9.text.trim() === \"4;0;\") {\n return { state: \"turn_complete\", ...(osc0 ? { title: osc0.text } : {}) };\n }\n if (osc9.text.includes(\"needs your permission\")) {\n const toolMatch = osc9.text.match(/permission.*?:\\s*(\\S+)/);\n return {\n state: \"approval_wait\",\n ...(osc0 ? { title: osc0.text } : {}),\n ...(toolMatch?.[1] ? { tool: toolMatch[1] } : {}),\n };\n }\n }\n\n if (provider === \"codex\" && osc0 && isCodexActionRequiredTitle(osc0.text)) {\n return { state: \"approval_wait\", title: osc0.text };\n }\n\n // 仅 OSC 0:标题/spinner 更新,没有明确语义信号。state=null 让上层只推 title。\n if (osc0 && !osc9) {\n return { state: null, title: osc0.text };\n }\n\n return null;\n}\n","export interface PtySnapshot {\n cols: number;\n rows: number;\n data: string;\n outputSeq: number;\n}\n\ninterface PtySnapshotTerminal {\n readonly cols: number;\n readonly rows: number;\n write(data: string | Uint8Array, callback?: () => void): void;\n}\n\ninterface PtySnapshotSerializer {\n serialize(): string;\n}\n\nexport function capturePtySnapshot(\n terminal: PtySnapshotTerminal,\n serializer: PtySnapshotSerializer,\n outputSeq: number,\n onSnapshot: (snapshot: PtySnapshot) => void,\n): void {\n // xterm processes write() asynchronously. An empty write is an ordered barrier:\n // its callback runs after all output represented by outputSeq has reached the buffer.\n terminal.write(\"\", () => {\n onSnapshot({\n cols: terminal.cols,\n rows: terminal.rows,\n data: serializer.serialize(),\n outputSeq,\n });\n });\n}\n"],"mappings":";;;AAMA,IAAM,cAAc;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AAuB,GAAG;AAC/C,YAAM,YAAY,KAAK,KAAK,MAAM,wBAAwB;AAC1D,aAAO;AAAA,QACL,OAAO;AAAA,QACP,GAAI,OAAO,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC;AAAA,QACnC,GAAI,YAAY,CAAC,IAAI,EAAE,MAAM,UAAU,CAAC,EAAE,IAAI,CAAC;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AAEA,MAAI,aAAa,WAAW,QAAQ,2BAA2B,KAAK,IAAI,GAAG;AACzE,WAAO,EAAE,OAAO,iBAAiB,OAAO,KAAK,KAAK;AAAA,EACpD;AAGA,MAAI,QAAQ,CAAC,MAAM;AACjB,WAAO,EAAE,OAAO,MAAM,OAAO,KAAK,KAAK;AAAA,EACzC;AAEA,SAAO;AACT;;;ACrJO,SAAS,mBACd,UACA,YACA,WACA,YACM;AAGN,WAAS,MAAM,IAAI,MAAM;AACvB,eAAW;AAAA,MACT,MAAM,SAAS;AAAA,MACf,MAAM,SAAS;AAAA,MACf,MAAM,WAAW,UAAU;AAAA,MAC3B;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
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-VGCVESF6.js");
|
|
273
273
|
const { provider, args } = invocation;
|
|
274
274
|
await startTerminal(args, provider);
|
|
275
275
|
});
|
package/dist/serve.js
CHANGED
|
@@ -25,11 +25,12 @@ import {
|
|
|
25
25
|
} from "./chunk-26JRYTYF.js";
|
|
26
26
|
import {
|
|
27
27
|
appendPtySemanticTextTail,
|
|
28
|
+
capturePtySnapshot,
|
|
28
29
|
extractOscSequences,
|
|
29
30
|
extractOscSignals,
|
|
30
31
|
extractOscWorkingDirectory,
|
|
31
32
|
extractTextSignals
|
|
32
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-6D4UN567.js";
|
|
33
34
|
import {
|
|
34
35
|
ControlErrorCode,
|
|
35
36
|
MessageEnvelopeSchema,
|
|
@@ -1877,22 +1878,20 @@ function createControlMessageHandlers(send, sessionManager) {
|
|
|
1877
1878
|
// relay 重连时同步 session 列表并重新推送控制数据
|
|
1878
1879
|
async reinitializeOnReconnect() {
|
|
1879
1880
|
const activeSessions = sessionManager.listSessions().filter((s) => s.state !== "terminated");
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
serviceLogger.info({ count: activeSessions.length }, "Session list synced to relay");
|
|
1895
|
-
}
|
|
1881
|
+
send(
|
|
1882
|
+
serializeControl({
|
|
1883
|
+
type: "session_sync",
|
|
1884
|
+
sessions: activeSessions.map((s) => ({
|
|
1885
|
+
id: s.id,
|
|
1886
|
+
...s.kind !== void 0 ? { kind: s.kind } : {},
|
|
1887
|
+
mode: s.mode,
|
|
1888
|
+
provider: s.provider,
|
|
1889
|
+
...s.ptyOwner !== void 0 ? { ptyOwner: s.ptyOwner } : {},
|
|
1890
|
+
state: s.state
|
|
1891
|
+
}))
|
|
1892
|
+
})
|
|
1893
|
+
);
|
|
1894
|
+
serviceLogger.info({ count: activeSessions.length }, "Session list synced to relay");
|
|
1896
1895
|
for (const session of activeSessions) {
|
|
1897
1896
|
const resources = sessionResources.get(session.id);
|
|
1898
1897
|
const workDir = resources?.fileTreeWorkDir;
|
|
@@ -3472,22 +3471,27 @@ var HostedPtyRegistry = class {
|
|
|
3472
3471
|
snapshot(sessionId, requestId) {
|
|
3473
3472
|
const hosted = this.sessions.get(sessionId);
|
|
3474
3473
|
if (!hosted) return false;
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3474
|
+
capturePtySnapshot(hosted.terminal, hosted.serializeAddon, hosted.outputSeq, (snapshot2) => {
|
|
3475
|
+
if (this.sessions.get(sessionId) !== hosted) return;
|
|
3476
|
+
this.deps.relayConnection.sendRaw(
|
|
3477
|
+
serializeControl({
|
|
3478
|
+
type: "session_snapshot",
|
|
3479
|
+
sessionId,
|
|
3480
|
+
...snapshot2,
|
|
3481
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
3482
|
+
})
|
|
3483
|
+
);
|
|
3484
|
+
serviceLogger.info(
|
|
3485
|
+
{
|
|
3486
|
+
sessionId,
|
|
3487
|
+
cols: snapshot2.cols,
|
|
3488
|
+
rows: snapshot2.rows,
|
|
3489
|
+
bytes: snapshot2.data.length,
|
|
3490
|
+
outputSeq: snapshot2.outputSeq
|
|
3491
|
+
},
|
|
3492
|
+
"Hosted PTY snapshot sent"
|
|
3493
|
+
);
|
|
3494
|
+
});
|
|
3491
3495
|
return true;
|
|
3492
3496
|
}
|
|
3493
3497
|
terminate(sessionId) {
|