evolcore 0.0.48 → 0.0.50

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 (302) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/bin/ecmsg.js +9 -4
  3. package/dist/ability/caller/authorization.js +21 -0
  4. package/dist/ability/caller/command.js +164 -0
  5. package/dist/ability/caller/contract.js +102 -0
  6. package/dist/ability/caller/daemon.js +158 -0
  7. package/dist/ability/caller/service.js +380 -0
  8. package/dist/ability/command-contract.js +5 -0
  9. package/dist/ability/daemon.js +5 -1
  10. package/dist/ability/interop-v1.js +10 -3
  11. package/dist/ability/management.js +1 -0
  12. package/dist/agent-template/jobs.js +173 -1
  13. package/dist/agent-template/runtime.js +285 -8
  14. package/dist/agent-template/service.js +1159 -40
  15. package/dist/agent-template/types.js +2 -1
  16. package/dist/agents/baseagent-availability.js +27 -3
  17. package/dist/agents/baseagent-capability-adapter.js +102 -0
  18. package/dist/agents/baseagent-plugin-descriptor.js +274 -0
  19. package/dist/agents/baseagent-plugin-loader.js +145 -0
  20. package/dist/agents/baseagent.js +68 -2
  21. package/dist/agents/claude-gateway/agent-registration.js +389 -0
  22. package/dist/agents/claude-gateway/binding.js +96 -0
  23. package/dist/agents/claude-gateway/inbox.js +138 -0
  24. package/dist/agents/claude-gateway/index.js +125 -0
  25. package/dist/agents/claude-gateway/listing.js +330 -0
  26. package/dist/agents/claude-gateway/router.js +328 -0
  27. package/dist/agents/claude-gateway/sessions.js +128 -0
  28. package/dist/agents/claude-gateway/terminal.js +250 -0
  29. package/dist/agents/claude-gateway/transcript.js +272 -0
  30. package/dist/agents/claude-gateway/types.js +14 -0
  31. package/dist/agents/claude-runner.js +6 -10
  32. package/dist/agents/codex-runner.js +9 -2
  33. package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
  34. package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
  35. package/dist/agents/gemini/index.js +51 -0
  36. package/dist/aun/aid/control-aid.js +52 -32
  37. package/dist/aun/group/invite-service.js +6 -36
  38. package/dist/aun/group/operations.js +6 -0
  39. package/dist/aun/msg/mention-schema.js +1 -1
  40. package/dist/aun/msg/p2p.js +31 -2
  41. package/dist/aun/msg/upload.js +126 -3
  42. package/dist/build-identity.json +1 -1
  43. package/dist/channels/aun.js +1175 -457
  44. package/dist/cli/ability-command.js +42 -0
  45. package/dist/cli/agent-command.js +20 -1
  46. package/dist/cli/agent-create.js +78 -18
  47. package/dist/cli/agent-template.js +5 -3
  48. package/dist/cli/agent.js +91 -0
  49. package/dist/cli/aun-commands.js +92 -34
  50. package/dist/cli/bench.js +5 -2
  51. package/dist/cli/config.js +22 -6
  52. package/dist/cli/daemon-commands.js +245 -101
  53. package/dist/cli/directory.js +6 -1
  54. package/dist/cli/ecmsg-gateway.js +11 -9
  55. package/dist/cli/index.js +30 -5
  56. package/dist/cli/init.js +39 -63
  57. package/dist/cli/managed-command-guard.js +3 -0
  58. package/dist/cli/menu-client.js +32 -7
  59. package/dist/cli/model.js +20 -5
  60. package/dist/cli/pay-command.js +30 -0
  61. package/dist/cli/provider-command.js +6 -2
  62. package/dist/cli/quota.js +89 -0
  63. package/dist/cli/restart-monitor.js +2 -2
  64. package/dist/cli/role.js +1 -0
  65. package/dist/cli/services-command.js +12 -9
  66. package/dist/cli/team-workspace-command.js +56 -2
  67. package/dist/cli/thread-command.js +78 -12
  68. package/dist/config/access-policy.js +16 -3
  69. package/dist/config/config-field-policy.js +88 -9
  70. package/dist/config/config-manager.js +97 -47
  71. package/dist/config/config-operation-service.js +22 -1
  72. package/dist/config/gateway-config.js +9 -8
  73. package/dist/config/owner-config.js +0 -16
  74. package/dist/config/peer-role-resolver.js +1 -7
  75. package/dist/config/providers-config.js +107 -20
  76. package/dist/config/providers-management.js +45 -21
  77. package/dist/config/resolved-config-op.js +4 -44
  78. package/dist/config/schema-migration.js +78 -5
  79. package/dist/config/schema-registry.js +52 -7
  80. package/dist/config-store.js +1309 -17
  81. package/dist/core/agent-application-service.js +220 -1
  82. package/dist/core/agent-ipc-registration.js +19 -2
  83. package/dist/core/agent-reload-coordinator.js +5 -0
  84. package/dist/core/agent-runtime.js +198 -54
  85. package/dist/core/auth/agent-delegation.js +14 -0
  86. package/dist/core/auth/delegation-authorization.js +33 -26
  87. package/dist/core/auth/operation-authorizer.js +16 -1
  88. package/dist/core/auth/operation-catalog.js +59 -7
  89. package/dist/core/baseagent-loader.js +30 -3
  90. package/dist/core/capability/capability-manager.js +16 -7
  91. package/dist/core/channel-runtime.js +4 -2
  92. package/dist/core/command/agent-control.js +20 -2
  93. package/dist/core/command/agent-template-menu.js +4 -3
  94. package/dist/core/command/cli-intent-parser.js +28 -0
  95. package/dist/core/command/command-handler.js +45 -2
  96. package/dist/core/command/menu-catalog.js +20 -4
  97. package/dist/core/command/menu-file-path.js +70 -0
  98. package/dist/core/command/menu-handler.js +97 -73
  99. package/dist/core/command/menu-protocol.js +29 -0
  100. package/dist/core/command/menu-query-batch.js +2 -2
  101. package/dist/core/command/private-mention-menu.js +71 -0
  102. package/dist/core/command/remote-shell.js +565 -0
  103. package/dist/core/command/slash-handler.js +17 -26
  104. package/dist/core/command/team-workspace-bootstrap.js +2 -1
  105. package/dist/core/command/topic-slash.js +7 -1
  106. package/dist/core/daemon-bootstrap.js +0 -4
  107. package/dist/core/daemon-control.js +58 -1
  108. package/dist/core/daemon-lifecycle.js +29 -7
  109. package/dist/core/evolagent-registry.js +18 -9
  110. package/dist/core/handoff/runtime.js +1 -1
  111. package/dist/core/host-snapshot.js +8 -3
  112. package/dist/core/initialization/service.js +3 -0
  113. package/dist/core/interaction-router.js +130 -0
  114. package/dist/core/ipc-registration.js +5 -0
  115. package/dist/core/memory/consolidation-context.js +2 -1
  116. package/dist/core/memory/consolidation.js +35 -64
  117. package/dist/core/message/aun-ipc-sender.js +213 -74
  118. package/dist/core/message/aun-request-registry.js +31 -0
  119. package/dist/core/message/contact-admission.js +91 -6
  120. package/dist/core/message/contact-pending-inbound.js +113 -0
  121. package/dist/core/message/contact-thread-approval.js +212 -0
  122. package/dist/core/message/im-renderer.js +40 -1
  123. package/dist/core/message/message-admission.js +5 -39
  124. package/dist/core/message/message-bridge.js +197 -45
  125. package/dist/core/message/message-log.js +32 -0
  126. package/dist/core/message/message-queue.js +102 -18
  127. package/dist/core/message/peer-mode.js +15 -4
  128. package/dist/core/message/response-engine.js +174 -26
  129. package/dist/core/message/send-options.js +37 -3
  130. package/dist/core/message/send-routing.js +11 -7
  131. package/dist/core/model/config-scope.js +6 -14
  132. package/dist/core/model/model-catalog.js +5 -5
  133. package/dist/core/model/model-diagnostics.js +19 -0
  134. package/dist/core/model/model-fallback.js +13 -2
  135. package/dist/core/ownership/owner-resolver.js +12 -86
  136. package/dist/core/pack-auth.js +7 -0
  137. package/dist/core/pack-install.js +1 -1
  138. package/dist/core/permission/ec-command-parser.js +288 -77
  139. package/dist/core/permission/protected-paths.js +64 -9
  140. package/dist/core/permission/services-path-acl.js +458 -0
  141. package/dist/core/permission/tool-policy.js +26 -10
  142. package/dist/core/relation/peer-identity.js +13 -0
  143. package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
  144. package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
  145. package/dist/core/session/session-manager.js +47 -10
  146. package/dist/core/session/session-mapper.js +16 -0
  147. package/dist/core/skill/index-generator.js +2 -3
  148. package/dist/core/skill/switch-resolver.js +3 -0
  149. package/dist/core/task/task-recovery-service.js +1 -0
  150. package/dist/core/thread/command-parser.js +4 -1
  151. package/dist/core/thread/ipc-operation.js +4 -2
  152. package/dist/core/thread/thread-operation.js +25 -10
  153. package/dist/core/thread/thread-service.js +294 -55
  154. package/dist/core/thread/topic-id.js +67 -2
  155. package/dist/core/thread/types.js +15 -1
  156. package/dist/directory/owner-directory-admission.js +11 -8
  157. package/dist/directory/owner-directory-cache.js +19 -0
  158. package/dist/directory/owner-directory-markdown.js +1 -1
  159. package/dist/directory/owner-directory-policy.js +5 -30
  160. package/dist/directory/owner-directory-request-operation.js +5 -2
  161. package/dist/eck/kit-renderer.js +3 -2
  162. package/dist/eck/message-renderer.js +28 -5
  163. package/dist/ecweb/basic-settings-service.js +5 -9
  164. package/dist/ecweb/providers-service.js +4 -2
  165. package/dist/ecweb/runtime/supervisor.js +36 -8
  166. package/dist/event-center/center-config.js +9 -5
  167. package/dist/event-center/dispatcher.js +10 -1
  168. package/dist/event-center/ipc-operation.js +19 -0
  169. package/dist/event-center/registry.js +20 -5
  170. package/dist/event-center/runtime.js +10 -7
  171. package/dist/index.js +120 -41
  172. package/dist/ipc.js +83 -3
  173. package/dist/outputs/authorization.js +16 -0
  174. package/dist/outputs/cards.js +336 -0
  175. package/dist/outputs/events.js +3 -2
  176. package/dist/outputs/protocol.js +1 -0
  177. package/dist/outputs/service.js +2 -15
  178. package/dist/paths.js +48 -1
  179. package/dist/pay/command.js +38 -0
  180. package/dist/pay/protocol.js +136 -0
  181. package/dist/pay/runtime.js +188 -0
  182. package/dist/pay/service.js +384 -0
  183. package/dist/pay/store.js +81 -0
  184. package/dist/response-system/engines/v1/proactive-flow.js +29 -2
  185. package/dist/services/dispatcher.js +23 -5
  186. package/dist/services/host/main.js +388 -0
  187. package/dist/services/host/protocol.js +118 -0
  188. package/dist/services/host/resident.js +310 -0
  189. package/dist/services/host-client.js +386 -0
  190. package/dist/services/host-deploy.js +180 -0
  191. package/dist/services/host-launch.js +117 -0
  192. package/dist/services/host-recycle.js +203 -0
  193. package/dist/services/host-runtime.js +802 -0
  194. package/dist/services/idempotency.js +44 -86
  195. package/dist/services/index-generator.js +4 -3
  196. package/dist/services/index.js +204 -22
  197. package/dist/services/ipc-operation.js +288 -44
  198. package/dist/services/pack-manager.js +1 -0
  199. package/dist/services/script-runner.js +515 -83
  200. package/dist/services/service-payload.js +13 -7
  201. package/dist/services/validation.js +109 -4
  202. package/dist/stats/budget.js +1 -1
  203. package/dist/stats/model-resolver.js +2 -2
  204. package/dist/stats/quota-query.js +95 -0
  205. package/dist/trigger/application-service.js +6 -4
  206. package/dist/trigger/local-files.js +19 -9
  207. package/dist/trigger/scheduler.js +22 -12
  208. package/dist/trigger/script-sandbox.js +51 -8
  209. package/dist/utils/aid-bind.js +3 -0
  210. package/dist/utils/atomic-write.js +22 -8
  211. package/dist/utils/evolcore-version.js +2 -2
  212. package/dist/utils/host-info.js +173 -1
  213. package/dist/utils/logger.js +2 -2
  214. package/dist/utils/media-cache.js +190 -43
  215. package/dist/utils/npm-ops.js +43 -8
  216. package/dist/utils/restart-safety.js +14 -1
  217. package/dist/utils/system-memory.js +113 -25
  218. package/dist/utils/systemd-lifecycle.js +154 -0
  219. package/dist/utils/windows-shell-trust.js +7 -3
  220. package/dist/workbench/service.js +1 -1
  221. package/kits/docs/INDEX.md +3 -2
  222. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
  223. package/kits/docs/channels/aun.md +1 -1
  224. package/kits/docs/evolcore/INDEX.md +9 -6
  225. package/kits/docs/evolcore/agent.md +36 -1
  226. package/kits/docs/evolcore/aid.md +45 -3
  227. package/kits/docs/evolcore/config.md +5 -2
  228. package/kits/docs/evolcore/directory.md +8 -9
  229. package/kits/docs/evolcore/group.md +2 -1
  230. package/kits/docs/evolcore/memory-tags.md +2 -0
  231. package/kits/docs/evolcore/menu-client.md +3 -3
  232. package/kits/docs/evolcore/menu-protocol.md +7 -0
  233. package/kits/docs/evolcore/model.md +3 -0
  234. package/kits/docs/evolcore/msg.md +77 -10
  235. package/kits/docs/evolcore/pay.md +34 -0
  236. package/kits/docs/evolcore/provider.md +22 -1
  237. package/kits/docs/evolcore/quota.md +54 -0
  238. package/kits/docs/evolcore/role.md +3 -0
  239. package/kits/docs/evolcore/services.md +46 -18
  240. package/kits/docs/evolcore/stats.md +2 -0
  241. package/kits/docs/evolcore/thread-chain.md +2 -0
  242. package/kits/docs/evolcore/tool-authorization.md +10 -0
  243. package/kits/docs/evolcore/trigger.md +2 -0
  244. package/kits/rules/01-overview.md +11 -32
  245. package/kits/rules/02-navigation.md +7 -0
  246. package/kits/rules/06-channel.md +3 -3
  247. package/kits/schemas/_meta.json +38 -5
  248. package/kits/schemas/agent-config.schema.20.json +24 -0
  249. package/kits/schemas/agent-config.schema.21.json +974 -0
  250. package/kits/schemas/agent-config.schema.22.json +977 -0
  251. package/kits/schemas/agent-config.schema.23.json +958 -0
  252. package/kits/schemas/daemon.schema.10.json +373 -0
  253. package/kits/schemas/daemon.schema.9.json +12 -0
  254. package/kits/schemas/defaults.schema.7.json +472 -0
  255. package/kits/schemas/providers.schema.3.json +18 -2
  256. package/kits/schemas/relation-config.schema.13.json +289 -0
  257. package/kits/skills/.switches.json +17 -1
  258. package/kits/skills/ability/SKILL.md +229 -34
  259. package/kits/skills/ability/STRUCTURE.md +333 -0
  260. package/kits/skills/ability/references/cli.md +208 -0
  261. package/kits/skills/ability/references/development.md +107 -37
  262. package/kits/skills/ability/references/management.md +106 -46
  263. package/kits/skills/ability/references/runtime-protocol.md +65 -63
  264. package/kits/skills/agent-output-cards/SKILL.md +64 -0
  265. package/kits/skills/ec-group/SKILL.md +8 -6
  266. package/kits/skills/ec-group/TASK.md +186 -0
  267. package/kits/skills/ec-group/WORKLOG.md +180 -0
  268. package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
  269. package/kits/skills/ec-pay/SKILL.md +101 -0
  270. package/kits/skills/ec-pay/references/pay-cli.md +110 -0
  271. package/kits/skills/ec-provider/SKILL.md +58 -9
  272. package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
  273. package/kits/skills/ec-service-call/SKILL.md +135 -0
  274. package/kits/skills/ec-service-pack/SKILL.md +277 -0
  275. package/kits/skills/ec-trigger/SKILL.md +1 -1
  276. package/kits/templates/memory-consolidation/notes.md +2 -2
  277. package/kits/templates/memory-consolidation/workflow.md +46 -0
  278. package/kits/templates/roles/visitor.json +1 -0
  279. package/kits/templates/system-fragments/channel.md +13 -4
  280. package/kits/templates/system-fragments/commands.md +5 -3
  281. package/kits/templates/system-fragments/directory-contacts.md +3 -4
  282. package/kits/templates/system-fragments/reply.md +1 -0
  283. package/kits/templates/system-fragments/session.md +1 -1
  284. package/kits/templates/system-fragments/thread.md +27 -128
  285. package/kits/templates/system-fragments/venue.md +27 -0
  286. package/package.json +4 -5
  287. package/scripts/agent-template/inspect.mjs +79 -29
  288. package/scripts/agent-template/overlay.mjs +20 -2
  289. package/scripts/agent-template/shared/common.mjs +24 -6
  290. package/scripts/agent-template/shared/team-schema.json +23 -5
  291. package/scripts/agent-template/shared/template-contract.mjs +107 -17
  292. package/scripts/agent-template/shared/template-package.mjs +254 -29
  293. package/scripts/agent-template/shared/template-runtime.mjs +145 -2
  294. package/scripts/agent-template/shared/template.mjs +67 -9
  295. package/scripts/agent-template/team-pack.mjs +132 -41
  296. package/scripts/agent-template/team-preview.mjs +249 -5
  297. package/kits/docs/aun/ABILITY_CALLING.md +0 -280
  298. package/kits/docs/evolcore/ability.md +0 -185
  299. package/kits/skills/ability/references/calling.md +0 -56
  300. package/kits/skills/ability/references/contract-checklist.md +0 -37
  301. package/kits/skills/ability/references/recovery.md +0 -27
  302. /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
@@ -0,0 +1,250 @@
1
+ /**
2
+ * 在终端里拉起一个 Claude Code 会话。
3
+ *
4
+ * ## 实测结论(2026-11-15,本机 Windows 11 + Windows Terminal 1.24)
5
+ *
6
+ * 1. `wt.exe` 位于 `WindowsApps` 下的应用执行别名,能从命令行走通;
7
+ * 2. 它**只做转交**:spawn 后立刻返回,退出码 0 不代表窗口真的开了;
8
+ * 3. `-w "<名字>"` 复用同名窗口,两次调用开在同一窗口的不同标签页 —— 幂等成立;
9
+ * 4. `-w -1` 才是强制新窗口;
10
+ * 5. 窗口**不会**在命令结束后自动关闭,标签页会残留;
11
+ * 6. daemon 与 Windows Terminal 同处一个交互式 Windows 会话,没有 Session 0 隔离。
12
+ *
13
+ * 因此「拉起成功」不能用退出码判断,必须轮询会话目录,等管道能连上。
14
+ */
15
+ import { spawn } from 'node:child_process';
16
+ import fs from 'node:fs';
17
+ import { logger } from '../../utils/logger.js';
18
+ import { findClaudeSession, listClaudeSessions } from './sessions.js';
19
+ import { findTranscript } from './transcript.js';
20
+ /** 路径比较用的归一化:Windows 大小写不敏感,斜杠统一。 */
21
+ function normalizePath(value) {
22
+ const normalized = value.replace(/\//g, '\\').replace(/\\+$/, '');
23
+ return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
24
+ }
25
+ /**
26
+ * 拉起新会话时必须从环境里摘掉的变量。
27
+ *
28
+ * 由 evolcore 主动拉起时,`spawn` 会把当前进程的环境整份传下去。若当前进程
29
+ * 本身就跑在 Claude Code 里(用户从 CC 终端里启动 daemon、或 CC 启动的子进程),
30
+ * 这些变量会让新会话误认为自己是「子会话」:
31
+ *
32
+ * - `CLAUDE_CODE_CHILD_SESSION=1` → **关闭转录保存**
33
+ * (实测提示:`Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker`),
34
+ * 于是它永远不写 `~/.claude/sessions/<pid>.json`,轮询认不出它、也无法绑定话题。
35
+ * - `CLAUDE_CODE_SESSION_ID` / `CLAUDE_PID` → 指向别人的会话标识。
36
+ * - `CLAUDE_CODE_MESSAGING_*` → 把父会话的收消息管道当成自己的。
37
+ * - `CLAUDECODE` → 标记「我在 Claude Code 里」。
38
+ *
39
+ * 清掉它们,新会话才是一个独立、可被发现、能正常保存转录的会话。
40
+ */
41
+ const INHERITED_SESSION_ENV_KEYS = [
42
+ 'CLAUDECODE',
43
+ 'CLAUDE_CODE_CHILD_SESSION',
44
+ 'CLAUDE_CODE_SESSION_ID',
45
+ 'CLAUDE_CODE_SESSION_ATTENDED',
46
+ 'CLAUDE_CODE_MESSAGING_SOCKET',
47
+ 'CLAUDE_CODE_MESSAGING_TOKEN',
48
+ 'CLAUDE_CODE_ENTRYPOINT',
49
+ 'CLAUDE_PID',
50
+ ];
51
+ /** 复制一份环境,摘掉会让新会话误认父会话身份的变量。 */
52
+ function buildChildEnv() {
53
+ const env = { ...process.env };
54
+ for (const key of INHERITED_SESSION_ENV_KEYS)
55
+ delete env[key];
56
+ return env;
57
+ }
58
+ /** 轮询会话上线的间隔。 */
59
+ const POLL_INTERVAL_MS = 500;
60
+ /** 默认等待上线时长。Claude Code 冷启动通常 2-5 秒,留足余量。 */
61
+ const DEFAULT_WAIT_MS = 30_000;
62
+ /** 窗口名最大长度,太长的名字会被 Windows Terminal 拒绝。 */
63
+ const MAX_WINDOW_NAME = 64;
64
+ /** 把任意标题收敛成可用的窗口名。 */
65
+ function sanitizeWindowName(raw) {
66
+ const cleaned = raw.replace(/["<>\r\n]/g, '').trim();
67
+ if (!cleaned)
68
+ return 'claude';
69
+ return cleaned.length <= MAX_WINDOW_NAME ? cleaned : cleaned.slice(0, MAX_WINDOW_NAME);
70
+ }
71
+ /**
72
+ * 构造拉起命令的参数。
73
+ *
74
+ * ## 为什么 Windows 上要经 cmd.exe
75
+ *
76
+ * `wt.exe` 用 `CreateProcess` 启动命令,它只会给无扩展名的名字补 `.exe`。
77
+ * 而 npm 安装的 `claude` 在 PATH 里是 `claude.cmd`(还有一份 sh 脚本和 `.ps1`),
78
+ * 没有 `claude.exe`——直接写 `claude` 会得到 `0x80070002 系统找不到指定的文件`
79
+ * (实测)。交给 `cmd.exe /k` 后由它按 PATHEXT 解析,同时 `/k` 让窗口在
80
+ * claude 退出后保持打开,用户能看到错误信息而不是窗口一闪而过。
81
+ *
82
+ * Linux/macOS 走各自的 shell,不用 cmd。
83
+ *
84
+ * 抽成独立函数便于单测,也便于将来换终端实现时只改这一处。
85
+ */
86
+ export function buildLaunchArgs(options) {
87
+ const windowName = sanitizeWindowName(options.windowName ?? (options.sessionId ? `claude-${options.sessionId.slice(0, 8)}` : 'claude-new'));
88
+ const title = options.title ?? windowName;
89
+ const claudeCommand = options.sessionId
90
+ ? `claude --resume ${quoteArgument(options.sessionId)}`
91
+ : 'claude';
92
+ if (process.platform === 'win32') {
93
+ return {
94
+ command: 'wt.exe',
95
+ args: [
96
+ '-w', windowName,
97
+ 'new-tab',
98
+ '--title', title,
99
+ '-d', options.cwd,
100
+ 'cmd.exe', '/k', claudeCommand,
101
+ ],
102
+ };
103
+ }
104
+ const shell = process.env.SHELL || '/bin/sh';
105
+ return {
106
+ command: shell,
107
+ args: ['-c', `cd ${quoteArgument(options.cwd)} && ${claudeCommand}`],
108
+ };
109
+ }
110
+ /** 给 shell 命令里的参数加引号:只允许安全字符原样出现。 */
111
+ function quoteArgument(value) {
112
+ return /^[A-Za-z0-9._:-]+$/.test(value) ? value : `"${value.replace(/"/g, '\\"')}"`;
113
+ }
114
+ /**
115
+ * 校验一个会话能否被恢复。
116
+ *
117
+ * 检查三件事,任一不满足都返回失败原因。**这是恢复可行性的唯一判定处**——
118
+ * 路由层不再自己判断,避免两处逻辑漂移。
119
+ *
120
+ * 1. 工作目录有值(调用方解析失败时可以传空);
121
+ * 2. 工作目录存在且是目录——`--resume` 要在这个目录下找转录;
122
+ * 3. 转录文件存在——没有它就没有可恢复的对话。
123
+ *
124
+ * 注意转录是按 cwd 编码定位的,所以第 2 步不通过时第 3 步也一定不通过;
125
+ * 分别报错是为了给出准确原因。
126
+ */
127
+ export function checkResumable(sessionId, cwd) {
128
+ if (!cwd) {
129
+ return { ok: false, error: '找不到这个会话的工作目录,无法恢复上下文' };
130
+ }
131
+ if (!fs.existsSync(cwd)) {
132
+ return { ok: false, error: `会话的工作目录不存在(${cwd}),无法恢复上下文` };
133
+ }
134
+ let isDirectory = false;
135
+ try {
136
+ isDirectory = fs.statSync(cwd).isDirectory();
137
+ }
138
+ catch {
139
+ isDirectory = false;
140
+ }
141
+ if (!isDirectory) {
142
+ return { ok: false, error: `会话的工作目录不是目录(${cwd}),无法恢复上下文` };
143
+ }
144
+ if (!findTranscript(sessionId)) {
145
+ return { ok: false, error: '找不到这个会话的历史记录,无法恢复上下文' };
146
+ }
147
+ return { ok: true, cwd };
148
+ }
149
+ /**
150
+ * 拉起会话并等待其上线。
151
+ *
152
+ * ## 恢复一个已有会话 vs 新建一个会话
153
+ *
154
+ * `options.sessionId` 有值时是**恢复**:用户期望看到原来的对话。
155
+ * 所以拉起前必须确认两件事,任一不满足就失败退出,绝不退化成新会话——
156
+ * 悄悄开出空白对话等于吞掉了「历史还在」这个承诺:
157
+ *
158
+ * 1. **工作目录存在**。`--resume` 按当前目录编码去找转录,目录不对就找不到。
159
+ * 2. **转录文件存在**。没有转录就是没有可恢复的上下文。
160
+ *
161
+ * `options.sessionId` 为空才是**新建**,那是调用方显式请求的,不做这些检查。
162
+ *
163
+ * 若会话已经在线,直接返回(不重复开窗)。
164
+ */
165
+ export async function launchSession(options) {
166
+ const waitMs = options.waitMs ?? DEFAULT_WAIT_MS;
167
+ // 已经在线就不重复拉起
168
+ if (options.sessionId) {
169
+ const existing = await findClaudeSession({ sessionId: options.sessionId }, { probe: true });
170
+ if (existing?.online) {
171
+ return { online: true, launched: false };
172
+ }
173
+ }
174
+ // 恢复场景的前置校验:目录 + 转录,缺一个就失败。
175
+ // 校验通过后用它给出的 cwd 拉起——保证「检查的目录」和「启动的目录」是同一个。
176
+ let launchCwd = options.cwd;
177
+ if (options.sessionId) {
178
+ const check = checkResumable(options.sessionId, options.cwd);
179
+ if (!check.ok) {
180
+ logger.warn(`[claude-gateway] 拒绝拉起 ${options.sessionId.slice(0, 8)}:${check.error}`);
181
+ return { online: false, launched: false, error: check.error };
182
+ }
183
+ launchCwd = check.cwd;
184
+ }
185
+ // 新会话:拉起后要认出「哪个才是刚起来的那个」。
186
+ // 用拉起时刻做基线,之后只认该目录下 startingAt 晚于它的会话。
187
+ const baseline = Date.now();
188
+ const { command, args } = buildLaunchArgs({ ...options, cwd: launchCwd });
189
+ const printable = [command, ...args].join(' ');
190
+ try {
191
+ await new Promise((resolve, reject) => {
192
+ const child = spawn(command, args, {
193
+ detached: true,
194
+ stdio: 'ignore',
195
+ windowsHide: false,
196
+ // 摘掉继承来的 CC 会话标记,否则新会话会关闭转录保存(认不出来)
197
+ env: buildChildEnv(),
198
+ });
199
+ child.once('error', reject);
200
+ // wt.exe 会立刻退出,等它退出只是为了拿到错误
201
+ child.once('exit', () => resolve());
202
+ // 它也可能不退出,兜底继续
203
+ setTimeout(() => resolve(), 2_000).unref?.();
204
+ });
205
+ }
206
+ catch (error) {
207
+ const message = error.message;
208
+ logger.warn('[claude-gateway] 拉起终端失败:', message);
209
+ return { online: false, launched: true, command: printable, error: message };
210
+ }
211
+ // 不信任退出码,轮询会话目录确认真的起来了
212
+ const deadline = Date.now() + waitMs;
213
+ while (Date.now() < deadline) {
214
+ await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS));
215
+ if (options.sessionId) {
216
+ const session = await findClaudeSession({ sessionId: options.sessionId }, { probe: true });
217
+ if (session?.online) {
218
+ return { online: true, launched: true, command: printable, sessionId: session.sessionId };
219
+ }
220
+ continue;
221
+ }
222
+ // 新会话:在该目录下找拉起之后才出现的那个
223
+ const found = await findNewSessionInDirectory(launchCwd, baseline);
224
+ if (found) {
225
+ return { online: true, launched: true, command: printable, sessionId: found };
226
+ }
227
+ }
228
+ return {
229
+ online: false,
230
+ launched: true,
231
+ command: printable,
232
+ error: options.sessionId
233
+ ? `等待 ${waitMs}ms 后会话仍未上线(窗口可能已开但 claude 启动失败)`
234
+ : `等待 ${waitMs}ms 后没有出现新会话(窗口可能已开但 claude 启动失败)`,
235
+ };
236
+ }
237
+ /**
238
+ * 在指定目录下找「拉起之后才出现」的会话。
239
+ *
240
+ * 判据是 `startedAt` 晚于基线,再加目录匹配。只在探测到管道可用时才认,
241
+ * 避免把刚写了一半的元数据当成有效会话。
242
+ */
243
+ async function findNewSessionInDirectory(cwd, baseline) {
244
+ const sessions = await listClaudeSessions({ includeEvolcore: true, probe: true });
245
+ const normalizedCwd = normalizePath(cwd);
246
+ const candidates = sessions
247
+ .filter(s => normalizePath(s.cwd) === normalizedCwd && s.startedAt >= baseline - 2_000)
248
+ .sort((a, b) => b.startedAt - a.startedAt);
249
+ return candidates[0]?.sessionId;
250
+ }
@@ -0,0 +1,272 @@
1
+ /**
2
+ * 跟读 Claude Code 会话的转录文件。
3
+ *
4
+ * 转录位置:`~/.claude/projects/<编码后的cwd>/<sessionId>.jsonl`
5
+ *
6
+ * 编码规则是「非字母数字一律换成 '-'」,但同一目录可能出现大小写不同的两份
7
+ * (实测本机 `...EvolCore` 与 `...evolcore` 并存),所以**不按 cwd 推算路径**,
8
+ * 而是直接用 sessionId 在所有项目目录下 glob,取最新的一份。
9
+ *
10
+ * 写入是追加式的,按字节偏移增量读即可;文件变小说明被重写/压缩,归零重读。
11
+ */
12
+ import fs from 'node:fs';
13
+ import os from 'node:os';
14
+ import path from 'node:path';
15
+ import { logger } from '../../utils/logger.js';
16
+ const PROJECTS_DIR = path.join(os.homedir(), '.claude', 'projects');
17
+ /** 跨会话消息的外壳前缀,读出来要剥掉。 */
18
+ const PEER_PREFIXES = [
19
+ 'Another Claude session sent a message while you were working:',
20
+ 'Another Claude session sent a message:',
21
+ 'A peer session sent a message while you were working:',
22
+ ];
23
+ /** 外壳尾部的说明段落起点。 */
24
+ const PEER_TAIL = '\n\nThis came from another Claude session';
25
+ /** 按 sessionId 定位转录文件,找不到返回 undefined。 */
26
+ export function findTranscript(sessionId) {
27
+ if (!sessionId)
28
+ return undefined;
29
+ let projects;
30
+ try {
31
+ projects = fs.readdirSync(PROJECTS_DIR);
32
+ }
33
+ catch {
34
+ return undefined;
35
+ }
36
+ let best;
37
+ for (const project of projects) {
38
+ const file = path.join(PROJECTS_DIR, project, `${sessionId}.jsonl`);
39
+ try {
40
+ const stat = fs.statSync(file);
41
+ if (!stat.isFile())
42
+ continue;
43
+ if (!best || stat.mtimeMs > best.mtime) {
44
+ best = { file, mtime: stat.mtimeMs };
45
+ }
46
+ }
47
+ catch {
48
+ // 不存在,继续找
49
+ }
50
+ }
51
+ return best?.file;
52
+ }
53
+ /** 剥掉跨会话投递加在正文外面的说明,只留用户实际发的内容。 */
54
+ export function stripPeerWrapper(text) {
55
+ let body = text;
56
+ for (const prefix of PEER_PREFIXES) {
57
+ const index = body.indexOf(prefix);
58
+ if (index >= 0) {
59
+ body = body.slice(index + prefix.length);
60
+ break;
61
+ }
62
+ }
63
+ const tail = body.indexOf(PEER_TAIL);
64
+ if (tail >= 0)
65
+ body = body.slice(0, tail);
66
+ const tag = body.indexOf('\n\n<cross-session-message');
67
+ if (tag >= 0)
68
+ body = body.slice(0, tag);
69
+ return body.trim();
70
+ }
71
+ /** 把 content 摊平成 [{kind, text}]。 */
72
+ function flattenContent(content) {
73
+ if (typeof content === 'string')
74
+ return [{ kind: 'text', text: content }];
75
+ if (!Array.isArray(content))
76
+ return [];
77
+ const blocks = [];
78
+ for (const block of content) {
79
+ if (!block || typeof block !== 'object')
80
+ continue;
81
+ const record = block;
82
+ const kind = typeof record.type === 'string' ? record.type : 'unknown';
83
+ if (kind === 'text' && typeof record.text === 'string') {
84
+ blocks.push({ kind, text: record.text });
85
+ }
86
+ else if (kind === 'thinking' && typeof record.thinking === 'string') {
87
+ blocks.push({ kind, text: record.thinking });
88
+ }
89
+ else if (kind === 'tool_use') {
90
+ const name = typeof record.name === 'string' ? record.name : 'tool';
91
+ const input = record.input === undefined ? '' : JSON.stringify(record.input);
92
+ blocks.push({ kind, text: `${name}(${input.slice(0, 200)})` });
93
+ }
94
+ else if (kind === 'tool_result') {
95
+ const inner = flattenContent(record.content);
96
+ blocks.push({ kind, text: inner.map(i => i.text).join('\n') });
97
+ }
98
+ }
99
+ return blocks;
100
+ }
101
+ /**
102
+ * 把一条转录原始条目转成 TranscriptEntry。
103
+ *
104
+ * 返回 undefined 表示这条不需要展示(工具回执、元数据等)。
105
+ */
106
+ export function toTranscriptEntry(raw) {
107
+ const type = typeof raw.type === 'string' ? raw.type : '';
108
+ if (type !== 'user' && type !== 'assistant')
109
+ return undefined;
110
+ const message = raw.message;
111
+ if (!message || typeof message !== 'object')
112
+ return undefined;
113
+ const content = message.content;
114
+ const originRecord = raw.origin;
115
+ const origin = originRecord && typeof originRecord === 'object'
116
+ ? originRecord.kind
117
+ : undefined;
118
+ const blocks = flattenContent(content).filter(block => block.kind !== 'tool_result');
119
+ const text = blocks
120
+ .filter(block => block.kind === 'text')
121
+ .map(block => block.text)
122
+ .join('\n')
123
+ .trim();
124
+ if (!text)
125
+ return undefined;
126
+ const isPeer = raw.isMeta === true && origin === 'peer';
127
+ const body = isPeer ? stripPeerWrapper(text) : text;
128
+ if (!body)
129
+ return undefined;
130
+ return {
131
+ type,
132
+ origin: typeof origin === 'string' ? origin : undefined,
133
+ text: body,
134
+ timestamp: typeof raw.timestamp === 'number' ? raw.timestamp : undefined,
135
+ };
136
+ }
137
+ /**
138
+ * 读出整个会话的历史(一次性回放用)。
139
+ *
140
+ * 话题第一次绑定时把这份历史灌进消息流,用户切过去就能看到之前聊了什么,
141
+ * 而不是面对一个空白对话。跟 `TranscriptTail` 的区别:这个从头读、一次读完,
142
+ * 不记录偏移。
143
+ *
144
+ * @param limit 最多返回多少条(从最新往前取,返回时仍是时间正序)
145
+ */
146
+ export function readTranscriptHistory(sessionId, limit = 200) {
147
+ const file = findTranscript(sessionId);
148
+ if (!file)
149
+ return [];
150
+ let content;
151
+ try {
152
+ content = fs.readFileSync(file, 'utf-8');
153
+ }
154
+ catch (error) {
155
+ logger.debug('[ccagent] 读取会话历史失败:', error.message);
156
+ return [];
157
+ }
158
+ const entries = [];
159
+ for (const line of content.split('\n')) {
160
+ if (!line.trim())
161
+ continue;
162
+ let raw;
163
+ try {
164
+ raw = JSON.parse(line);
165
+ }
166
+ catch {
167
+ continue;
168
+ }
169
+ const entry = toTranscriptEntry(raw);
170
+ if (entry)
171
+ entries.push(entry);
172
+ }
173
+ return entries.length <= limit ? entries : entries.slice(entries.length - limit);
174
+ }
175
+ /**
176
+ * 增量跟读器。
177
+ *
178
+ * 构造时跳到文件末尾(只看新内容);`poll()` 返回上次之后新增的条目。
179
+ * 文件不存在或变小时自动处理,调用方不用关心。
180
+ */
181
+ export class TranscriptTail {
182
+ filePath;
183
+ offset = 0;
184
+ buffer = '';
185
+ constructor(filePath) {
186
+ this.filePath = filePath;
187
+ if (filePath) {
188
+ try {
189
+ this.offset = fs.statSync(filePath).size;
190
+ }
191
+ catch {
192
+ this.offset = 0;
193
+ }
194
+ }
195
+ }
196
+ /** 当前跟读的文件,可能是 undefined(会话还没有转录)。 */
197
+ get path() {
198
+ return this.filePath;
199
+ }
200
+ /** 会话转录迟到时补挂。 */
201
+ attach(sessionId, fromBeginning = false) {
202
+ if (this.filePath)
203
+ return false;
204
+ const found = findTranscript(sessionId);
205
+ if (!found)
206
+ return false;
207
+ this.filePath = found;
208
+ try {
209
+ this.offset = fromBeginning ? 0 : fs.statSync(found).size;
210
+ }
211
+ catch {
212
+ this.offset = 0;
213
+ }
214
+ return true;
215
+ }
216
+ /** 读出自上次以来的新增条目。 */
217
+ poll() {
218
+ if (!this.filePath)
219
+ return [];
220
+ let size;
221
+ try {
222
+ size = fs.statSync(this.filePath).size;
223
+ }
224
+ catch {
225
+ return [];
226
+ }
227
+ if (size < this.offset) {
228
+ // 文件被重写或压缩,从头读
229
+ this.offset = 0;
230
+ this.buffer = '';
231
+ }
232
+ if (size === this.offset)
233
+ return [];
234
+ let chunk;
235
+ try {
236
+ const fd = fs.openSync(this.filePath, 'r');
237
+ try {
238
+ const length = size - this.offset;
239
+ const buffer = Buffer.alloc(length);
240
+ fs.readSync(fd, buffer, 0, length, this.offset);
241
+ chunk = buffer.toString('utf-8');
242
+ }
243
+ finally {
244
+ fs.closeSync(fd);
245
+ }
246
+ this.offset = size;
247
+ }
248
+ catch (error) {
249
+ logger.debug('[claude-gateway] 读取转录失败:', error);
250
+ return [];
251
+ }
252
+ // 可能读到半行,留到下次
253
+ const lines = (this.buffer + chunk).split('\n');
254
+ this.buffer = lines.pop() ?? '';
255
+ const entries = [];
256
+ for (const line of lines) {
257
+ if (!line.trim())
258
+ continue;
259
+ let raw;
260
+ try {
261
+ raw = JSON.parse(line);
262
+ }
263
+ catch {
264
+ continue;
265
+ }
266
+ const entry = toTranscriptEntry(raw);
267
+ if (entry)
268
+ entries.push(entry);
269
+ }
270
+ return entries;
271
+ }
272
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Claude Code 会话网关的类型定义。
3
+ *
4
+ * 网关把「本机正在运行的 Claude Code 终端会话」当作可寻址对象暴露给 evolcore,
5
+ * 使 AUN 消息能投递到某个具体会话、并把该会话的输出读回来。
6
+ *
7
+ * 设计依据(均为实测结论,2026-11-15):
8
+ * - 会话地址:`~/.claude/sessions/<pid>.json` 的 `messagingSocketPath`(Windows 命名管道)
9
+ * - 投递令牌:同目录 `<pid>.<sha256>.key`,内容是 JSON,取 `peerToken`
10
+ * - 帧格式:换行分隔 JSON,首行 auth,次行 user,写完即关
11
+ * - 上下文恢复:`claude --resume <sessionId>`,因此话题可以稳定绑定 sessionId
12
+ * - 终端拉起:`wt.exe -w <name> new-tab ...`,同名窗口会复用(实测)
13
+ */
14
+ export {};
@@ -37,7 +37,7 @@ import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessCon
37
37
  import { getGatewayPricing as getSharedGatewayPricing } from '../stats/model-resolver.js';
38
38
  import { contextTokensForUsage, usageForContext, realContextWindowForModel } from './runner-types.js';
39
39
  import { CLAUDE_AUTO_COMPACT_MAX_TOKENS, CLAUDE_AUTO_COMPACT_MIN_TOKENS, resolveCatalogAutoCompactPolicy, resolveModelCapabilities, } from '../core/model/model-capabilities.js';
40
- import { hasContextWindowSuffix, stripContextWindowSuffix } from '../core/model/context-window-suffix.js';
40
+ import { hasContextWindowSuffix } from '../core/model/context-window-suffix.js';
41
41
  const resolveModule = createRequire(import.meta.url);
42
42
  const CLAUDE_INTERRUPT_TIMEOUT_MS = 5_000;
43
43
  export function summarizeClaudeQueryOptions(options, context) {
@@ -464,17 +464,13 @@ async function assertClaudeSettingSourcesHaveLiteralSandboxPaths(cwd, settingSou
464
464
  /**
465
465
  * 为支持 1M 上下文的模型追加 `[1m]` 后缀——仅在交给 SDK query() 时调用。
466
466
  *
467
- * 若网关把窗口变体作为独立条目下发(目录里同时有 `claude-opus-5` 与
468
- * `claude-opus-5[1m]`),裸 ID 就是用户明确选的非 1M 变体,不能擅自升级,
469
- * 否则两条列表项的实际效果无法区分。只有目录未提供任何窗口变体时,才按已解析的
470
- * 模型参数(缺失时才回退本地名单)补 `[1m]`。
467
+ * 以所选模型的有效窗口为准,即使目录同时列出裸 ID 和 `[1m]` 变体,也要
468
+ * 为声明了百万窗口的裸 ID 补后缀,否则 Claude Code 仍可能按 200k 限制压缩。
469
+ * 已显式选择的窗口后缀保持原样。
471
470
  */
472
- function applyContextWindow(modelId, contextWindow, catalog) {
471
+ function applyContextWindow(modelId, contextWindow) {
473
472
  if (hasContextWindowSuffix(modelId))
474
473
  return modelId; // 窗口已显式指定
475
- const variantListed = catalog?.models.some(m => hasContextWindowSuffix(m.id) && stripContextWindowSuffix(m.id) === modelId);
476
- if (variantListed)
477
- return modelId;
478
474
  if (contextWindow >= 1_000_000)
479
475
  return `${modelId}[1m]`;
480
476
  return modelId;
@@ -487,7 +483,7 @@ function resolveClaudeModelContext(modelId, catalog) {
487
483
  const policy = resolveCatalogAutoCompactPolicy(catalog, modelId);
488
484
  const contextWindow = policy?.contextWindow ?? capabilities.contextWindow;
489
485
  return {
490
- sdkModel: applyContextWindow(capabilities.model, contextWindow, catalog),
486
+ sdkModel: applyContextWindow(capabilities.model, contextWindow),
491
487
  contextWindow,
492
488
  autoCompactTokens: policy?.autoCompactTokens,
493
489
  };
@@ -949,6 +949,7 @@ export class CodexRunner {
949
949
  || shellCarrier !== undefined
950
950
  && classifyEvolcoreShellCommand(shellCarrier.command, {
951
951
  dialect: shellCarrier.dialect,
952
+ posixShell: shellCarrier.posixShell,
952
953
  }).kind !== 'none'
953
954
  || rawArgv.length === 1
954
955
  && classifyEvolcoreShellCommand(rawArgv[0], {
@@ -3979,10 +3980,16 @@ export class CodexRunner {
3979
3980
  };
3980
3981
  if (managedEcIntent && !approvedCommand) {
3981
3982
  if (canonicalEcApproval?.parseFailure?.issue === 'untrusted-shell') {
3982
- return await denyInfrastructure('ec_shell_untrusted_executable', 'EC command approval denied because the shell executable failed Windows Authenticode trust validation');
3983
+ const failure = canonicalEcApproval.parseFailure.shellTrustFailure;
3984
+ logger.warn('[CodexRunner] EC shell trust validation failed', failure);
3985
+ return await denyInfrastructure('ec_shell_untrusted_executable', 'EC command approval denied because shell trust validation failed'
3986
+ + (failure ? `: ${failure.message}` : ''));
3983
3987
  }
3984
3988
  if (canonicalEcApproval?.parseFailure?.issue === 'unsupported-escape') {
3985
- return await denyInfrastructure('ec_shell_unsupported_escape', 'EC inline text does not support PowerShell `n. Use literal \\n in the argument instead.');
3989
+ return await denyInfrastructure('ec_shell_unsupported_escape', canonicalEcApproval.parseFailure.dialect === 'powershell'
3990
+ ? 'EC inline text does not support PowerShell `n. Use literal \\n in the argument instead.'
3991
+ : literalShellParseRemedy(canonicalEcApproval.parseFailure)
3992
+ ?? 'EC command contains unsupported shell escaping');
3986
3993
  }
3987
3994
  if (canonicalEcApproval?.parseFailure?.issue === 'lossy-cmd-shim') {
3988
3995
  return await denyInfrastructure('ec_shell_lossy_cmd_shim', 'PowerShell cannot pass physical multiline EC arguments through ec.cmd intact. Use ec ... via the PowerShell-native shim instead.');
@@ -1,6 +1,6 @@
1
- import { assertRunnerModelAllowed, getRunnerCatalog, assertCatalogSelectable } from '../core/model/model-catalog.js';
1
+ import { assertRunnerModelAllowed, getRunnerCatalog, assertCatalogSelectable } from '../../core/model/model-catalog.js';
2
2
  // Gemini API 不认识 Claude Code SDK 的窗口后缀,必须传入基础模型 ID。
3
- import { stripContextWindowSuffix } from '../core/model/context-window-suffix.js';
3
+ import { stripContextWindowSuffix } from '../../core/model/context-window-suffix.js';
4
4
  /**
5
5
  * Gemini Agent Runner
6
6
  *
@@ -12,25 +12,25 @@ import { stripContextWindowSuffix } from '../core/model/context-window-suffix.js
12
12
  * GeminiRunner → spawn `gemini -p ...` → stdout JSONL stream
13
13
  */
14
14
  import { spawn } from 'child_process';
15
- import { MAIN_CLI_BIN } from '../product.js';
15
+ import { MAIN_CLI_BIN } from '../../product.js';
16
16
  import { createInterface } from 'readline';
17
17
  import fs from 'fs';
18
18
  import path from 'path';
19
19
  import os from 'os';
20
20
  import crypto from 'crypto';
21
- import { hasTrustedFullAccessContext } from './runner-types.js';
22
- import { resolveGoogleConfig } from './baseagent.js';
23
- import { resolveEffective } from '../config/config-manager.js';
24
- import { commandExists } from '../utils/cross-platform.js';
25
- import { GeminiSessionFileAdapter } from '../core/session/adapters/gemini-session-file-adapter.js';
26
- import { logger } from '../utils/logger.js';
27
- import { normalizeExecutionPermissionMode, normalizePermissionMode } from '../core/permission/mode.js';
28
- import { resolveRoot } from '../paths.js';
29
- import { getGatewayPricing as getSharedGatewayPricing } from '../stats/model-resolver.js';
30
- import { workspaceContainsHClassPaths } from '../core/permission/protected-paths.js';
31
- import { buildBubblewrapCommand } from '../core/permission/sandbox-runtime.js';
32
- import { getManagedTaskTempDir } from '../cli/task-context.js';
33
- import { auditPermissionLifecycle } from '../core/auth/authorization-audit.js';
21
+ import { hasTrustedFullAccessContext } from '../runner-types.js';
22
+ import { resolveGoogleConfig } from '../baseagent.js';
23
+ import { resolveEffective } from '../../config/config-manager.js';
24
+ import { commandExists } from '../../utils/cross-platform.js';
25
+ import { GeminiSessionFileAdapter } from './gemini-session-file-adapter.js';
26
+ import { logger } from '../../utils/logger.js';
27
+ import { normalizeExecutionPermissionMode, normalizePermissionMode } from '../../core/permission/mode.js';
28
+ import { resolveRoot } from '../../paths.js';
29
+ import { getGatewayPricing as getSharedGatewayPricing } from '../../stats/model-resolver.js';
30
+ import { workspaceContainsHClassPaths } from '../../core/permission/protected-paths.js';
31
+ import { buildBubblewrapCommand } from '../../core/permission/sandbox-runtime.js';
32
+ import { getManagedTaskTempDir } from '../../cli/task-context.js';
33
+ import { auditPermissionLifecycle } from '../../core/auth/authorization-audit.js';
34
34
  // Strip ANSI escape codes from Gemini CLI text output.
35
35
  // Gemini embeds raw terminal colors from tool stdout (e.g. vitest, npm)
36
36
  // into its assistant text, unlike Claude SDK which strips them internally.
@@ -111,7 +111,7 @@ const GEMINI_H_CLASS_PATTERNS = [
111
111
  String.raw `(?:^|[/\\"])(?:AIDs|aids)(?:[/\\"]|$)`,
112
112
  String.raw `\.snapshots`,
113
113
  String.raw `(?:^|[/\\"])CA(?:[/\\"]|$)`,
114
- String.raw `(?:^|[/\\"])\.device_id(?:[/\\"]|$)`,
114
+ String.raw `(?:^|[/\\"])\.device_id(?:\.[^/\\"]*)?(?:[/\\"]|$)`,
115
115
  String.raw `(?:^|[/\\"])\.env(?:[/\\"]|$)`,
116
116
  String.raw `(?:^|[/\\"])\.seed(?:[/\\"]|$)`,
117
117
  String.raw `(?:^|[/\\"])\.seed\.[^/\\"]+`,
@@ -10,8 +10,8 @@
10
10
  *
11
11
  * Messages have type: 'user' | 'gemini' (not 'role').
12
12
  */
13
- import { logger } from '../../../utils/logger.js';
14
- import { buildCliSessionPreview } from '../session-title.js';
13
+ import { logger } from '../../utils/logger.js';
14
+ import { buildCliSessionPreview } from '../../core/session/session-title.js';
15
15
  import path from 'path';
16
16
  import fs from 'fs';
17
17
  import os from 'os';