@dev-anywhere/proxy 0.4.68 → 0.4.70

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.
@@ -88,74 +88,11 @@ function extractOscSignals(rawData, provider) {
88
88
  return null;
89
89
  }
90
90
 
91
- // src/common/pty-approval-state.ts
92
- function shouldReleaseApprovalWait(options) {
93
- if (options.currentState !== "approval_wait") return false;
94
- if (options.signalState === void 0) return false;
95
- if (options.signalState === null && options.allowTitleOnlyRelease === false) return false;
96
- return options.signalState !== "approval_wait";
97
- }
98
- function stateAfterApprovalRelease(signalState) {
99
- if (signalState === null) return "turn_complete";
100
- return signalState !== "approval_wait" ? signalState : "working";
101
- }
102
- function shouldReleaseTextApprovalOnInput(data) {
103
- if (data.includes("\r") || data.includes("\n")) return true;
104
- return data === "1" || data === "2" || data === "y" || data === "Y" || data === "n" || data === "N" || data === "\x1B" || data === "";
105
- }
106
-
107
- // src/common/pty-semantic-machine.ts
108
- function withMeta(signal) {
109
- return {
110
- ...signal?.title !== void 0 ? { title: signal.title } : {},
111
- ...signal?.tool !== void 0 ? { tool: signal.tool } : {}
112
- };
113
- }
114
- function decidePtySemanticTransition(input) {
115
- const {
116
- currentState,
117
- signal,
118
- sessionStateIsWaitingApproval,
119
- allowTitleOnlyApprovalRelease = true,
120
- hasTextActivity = false
121
- } = input;
122
- if (signal?.state === "approval_wait") {
123
- return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
124
- }
125
- if (shouldReleaseApprovalWait({
126
- currentState,
127
- signalState: signal === null ? void 0 : signal.state,
128
- allowTitleOnlyRelease: allowTitleOnlyApprovalRelease
129
- })) {
130
- return {
131
- nextState: stateAfterApprovalRelease(signal.state),
132
- emit: true,
133
- meta: withMeta(signal)
134
- };
135
- }
136
- const inApprovalContext = currentState === "approval_wait" || sessionStateIsWaitingApproval === true;
137
- if (inApprovalContext && signal?.state !== "turn_complete") {
138
- return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
139
- }
140
- if (signal !== null && signal.state === null && (currentState === "working" || !hasTextActivity)) {
141
- return { nextState: currentState, emit: false };
142
- }
143
- if (signal && signal.state !== null && signal.state !== "working") {
144
- return { nextState: signal.state, emit: true, meta: withMeta(signal) };
145
- }
146
- if (currentState !== "working") {
147
- return { nextState: "working", emit: true };
148
- }
149
- return { nextState: currentState, emit: false };
150
- }
151
-
152
91
  export {
153
92
  extractOscSequences,
154
93
  normalizePtySemanticText,
155
94
  appendPtySemanticTextTail,
156
95
  extractTextSignals,
157
- extractOscSignals,
158
- shouldReleaseTextApprovalOnInput,
159
- decidePtySemanticTransition
96
+ extractOscSignals
160
97
  };
161
- //# sourceMappingURL=chunk-22TVFFT7.js.map
98
+ //# sourceMappingURL=chunk-B3GHP25U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/osc-extractor.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\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"],"mappings":";;;AAMA,IAAM,cAAc;AAgBpB,IAAM,yBAAyB;AAG/B,IAAM,uBAAuB;AAE7B,IAAM,uBAAuB;AAE7B,IAAM,qBAAqB;AAEpB,SAAS,oBA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O,MAAM,OAAO,KAAK,KAAK;AAAA,EACzC;AAEA,SAAO;AACT;","names":[]}
@@ -974,7 +974,8 @@ var IpcMessageSchema = z9.discriminatedUnion("type", [
974
974
  provider: z9.enum(["claude", "codex"]),
975
975
  cwd: z9.string(),
976
976
  pid: z9.number(),
977
- sessionId: z9.string().optional()
977
+ sessionId: z9.string().optional(),
978
+ kind: z9.enum(["agent", "terminal"]).optional()
978
979
  }),
979
980
  // 服务端响应创建会话
980
981
  z9.object({
@@ -1017,6 +1018,11 @@ var IpcMessageSchema = z9.discriminatedUnion("type", [
1017
1018
  type: z9.literal("pty_detach"),
1018
1019
  sessionId: z9.string()
1019
1020
  }),
1021
+ // serve → terminal worker:终止 Web 创建的纯终端进程。
1022
+ z9.object({
1023
+ type: z9.literal("pty_terminate"),
1024
+ sessionId: z9.string()
1025
+ }),
1020
1026
  // 服务端广播会话状态变更
1021
1027
  z9.object({
1022
1028
  type: z9.literal("session_status_update"),
@@ -1085,6 +1091,13 @@ var IpcMessageSchema = z9.discriminatedUnion("type", [
1085
1091
  cols: z9.number(),
1086
1092
  rows: z9.number()
1087
1093
  }),
1094
+ // serve → terminal worker:Web owns pure terminal geometry, so resize requests flow down.
1095
+ z9.object({
1096
+ type: z9.literal("pty_resize_request"),
1097
+ sessionId: z9.string(),
1098
+ cols: z9.number(),
1099
+ rows: z9.number()
1100
+ }),
1088
1101
  // serve → terminal:请求 HeadlessTerminal serialize() 快照
1089
1102
  z9.object({
1090
1103
  type: z9.literal("pty_subscribe"),
@@ -1273,4 +1286,4 @@ export {
1273
1286
  serializeIpc,
1274
1287
  createIpcReader
1275
1288
  };
1276
- //# sourceMappingURL=chunk-TETUEWVJ.js.map
1289
+ //# sourceMappingURL=chunk-ID6ZXJRH.js.map