shennian 0.5.0 → 0.5.2

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 (342) hide show
  1. package/README.md +2 -2
  2. package/dist/publish-build-manifest.json +165 -125
  3. package/dist/src/agents/acp/adapter.js +2 -2
  4. package/dist/src/agents/acp/capability-cache.js +2 -2
  5. package/dist/src/agents/acp/catalog.js +2 -2
  6. package/dist/src/agents/acp/manifests.js +2 -2
  7. package/dist/src/agents/claude.js +8 -6
  8. package/dist/src/agents/codex.js +2 -2
  9. package/dist/src/agents/command-spec.js +4 -4
  10. package/dist/src/agents/cursor.js +1 -1
  11. package/dist/src/agents/custom-recovery-conformance.js +2 -2
  12. package/dist/src/agents/gemini.js +1 -1
  13. package/dist/src/agents/model-registry/discovery.js +3 -3
  14. package/dist/src/agents/model-registry/service.js +1 -1
  15. package/dist/src/agents/model-registry.js +1 -1
  16. package/dist/src/agents/openclaw.js +2 -2
  17. package/dist/src/agents/opencode.js +1 -1
  18. package/dist/src/agents/pi-coding-agent.js +3 -4
  19. package/dist/src/agents/pi-session-ownership.js +2 -2
  20. package/dist/src/agents/spawn-errors.js +1 -0
  21. package/dist/src/agents/windows-agent-paths.js +1 -0
  22. package/dist/src/commands/agent-readiness.js +2 -2
  23. package/dist/src/commands/daemon-service-spec.js +1 -1
  24. package/dist/src/commands/daemon.js +6 -6
  25. package/dist/src/commands/queue.js +1 -0
  26. package/dist/src/commands/room.js +3 -3
  27. package/dist/src/config/index.js +2 -2
  28. package/dist/src/fs/atomic-rename.js +1 -0
  29. package/dist/src/index.js +3 -3
  30. package/dist/src/native-fusion/claude-entry-parser.js +7 -0
  31. package/dist/src/native-fusion/local-repository.js +2 -2
  32. package/dist/src/native-fusion/native-source-deletions.js +2 -2
  33. package/dist/src/native-fusion/parsers.js +1 -3
  34. package/dist/src/native-fusion/state.js +2 -2
  35. package/dist/src/personal-sync/epoch.js +2 -2
  36. package/dist/src/personal-sync/identity.js +2 -2
  37. package/dist/src/relay/client.js +1 -1
  38. package/dist/src/room/activation-service.js +6 -6
  39. package/dist/src/room/attachment-cache.js +2 -2
  40. package/dist/src/room/host-session-observations.js +2 -2
  41. package/dist/src/room/managed-context.js +1 -1
  42. package/dist/src/room/managed-room-ipc.js +2 -2
  43. package/dist/src/room/mirror-sync-service.js +1 -1
  44. package/dist/src/room/public-attachment-cache.js +2 -2
  45. package/dist/src/room/room-error-guidance.js +1 -0
  46. package/dist/src/room/session-registry.js +2 -2
  47. package/dist/src/security/managed-agent-policy.js +1 -1
  48. package/dist/src/security/managed-agent-runtime.js +1 -1
  49. package/dist/src/session/attachment-transfer-store.js +2 -2
  50. package/dist/src/session/canonical-store.js +5 -5
  51. package/dist/src/session/deletion-sync-state.js +2 -2
  52. package/dist/src/session/handlers/agent-workspace-validation.js +1 -1
  53. package/dist/src/session/handlers/chat-adapter-config.js +1 -1
  54. package/dist/src/session/handlers/chat-events.js +2 -2
  55. package/dist/src/session/handlers/chat-recovery.js +1 -1
  56. package/dist/src/session/handlers/chat.js +1 -1
  57. package/dist/src/session/manager.js +1 -1
  58. package/dist/src/session/native-cleanup-outbox.js +2 -2
  59. package/dist/src/session/queue-diagnostics.js +1 -0
  60. package/dist/src/session/queue-dispatch-failure.js +1 -0
  61. package/dist/src/session/queue-helpers.js +5 -5
  62. package/dist/src/session/queue-retry.js +1 -1
  63. package/dist/src/session/queue-storage.js +2 -2
  64. package/dist/src/session/queue.js +1 -1
  65. package/dist/src/session/room-reply-notice.js +1 -0
  66. package/dist/src/session/run-recovery/journal.js +2 -2
  67. package/dist/src/session/run-stall.js +1 -0
  68. package/dist/src/session/store.js +2 -2
  69. package/dist/src/session/tool-detail-store.js +2 -2
  70. package/node_modules/@shennian/wire/dist/agent-capabilities.js +1 -1
  71. package/node_modules/@shennian/wire/dist/agent-workspace.js +1 -144
  72. package/node_modules/@shennian/wire/dist/envelope.js +1 -1
  73. package/node_modules/@shennian/wire/dist/events.js +1 -1
  74. package/node_modules/@shennian/wire/dist/external-message-format.js +3 -70
  75. package/node_modules/@shennian/wire/dist/frames.js +1 -1
  76. package/node_modules/@shennian/wire/dist/fs.js +2 -7
  77. package/node_modules/@shennian/wire/dist/index.js +1 -21
  78. package/node_modules/@shennian/wire/dist/machine.js +1 -1
  79. package/node_modules/@shennian/wire/dist/message-payload.js +8 -307
  80. package/node_modules/@shennian/wire/dist/methods.js +1 -3
  81. package/node_modules/@shennian/wire/dist/native-session.js +1 -1
  82. package/node_modules/@shennian/wire/dist/project-fs.js +1 -462
  83. package/node_modules/@shennian/wire/dist/project-path.js +1 -25
  84. package/node_modules/@shennian/wire/dist/project.js +1 -3
  85. package/node_modules/@shennian/wire/dist/relay-connectivity.js +1 -29
  86. package/node_modules/@shennian/wire/dist/room.js +1 -20
  87. package/node_modules/@shennian/wire/dist/schedule.js +1 -1
  88. package/node_modules/@shennian/wire/dist/session-sync.js +1 -123
  89. package/node_modules/@shennian/wire/dist/session.js +1 -60
  90. package/node_modules/@shennian/wire/dist/tool-detail.js +1 -9
  91. package/node_modules/@shennian/wire/dist/voice-chief.js +1 -3
  92. package/package.json +3 -8
  93. package/dist/bin/shennian.d.ts +0 -2
  94. package/dist/src/agent-env.d.ts +0 -44
  95. package/dist/src/agents/acp/adapter.d.ts +0 -82
  96. package/dist/src/agents/acp/auth-state.d.ts +0 -3
  97. package/dist/src/agents/acp/auth.d.ts +0 -7
  98. package/dist/src/agents/acp/capability-cache.d.ts +0 -14
  99. package/dist/src/agents/acp/catalog.d.ts +0 -11
  100. package/dist/src/agents/acp/client-services.d.ts +0 -37
  101. package/dist/src/agents/acp/discovery.d.ts +0 -10
  102. package/dist/src/agents/acp/events.d.ts +0 -4
  103. package/dist/src/agents/acp/manifests.d.ts +0 -63
  104. package/dist/src/agents/acp/metrics.d.ts +0 -24
  105. package/dist/src/agents/acp/package-commands.d.ts +0 -4
  106. package/dist/src/agents/acp/process-client.d.ts +0 -41
  107. package/dist/src/agents/acp/process-tree.d.ts +0 -2
  108. package/dist/src/agents/acp/types.d.ts +0 -31
  109. package/dist/src/agents/acp/watcher.d.ts +0 -22
  110. package/dist/src/agents/adapter.d.ts +0 -180
  111. package/dist/src/agents/auth-status.d.ts +0 -4
  112. package/dist/src/agents/claude-managed-permissions.d.ts +0 -33
  113. package/dist/src/agents/claude.d.ts +0 -69
  114. package/dist/src/agents/codex-managed-permissions.d.ts +0 -32
  115. package/dist/src/agents/codex-managed-room-tools.d.ts +0 -41
  116. package/dist/src/agents/codex-protocol.d.ts +0 -103
  117. package/dist/src/agents/codex-runtime.d.ts +0 -91
  118. package/dist/src/agents/codex-utils.d.ts +0 -29
  119. package/dist/src/agents/codex.d.ts +0 -59
  120. package/dist/src/agents/command-spec.d.ts +0 -55
  121. package/dist/src/agents/config-status.d.ts +0 -18
  122. package/dist/src/agents/cursor-managed-permissions.d.ts +0 -28
  123. package/dist/src/agents/cursor.d.ts +0 -44
  124. package/dist/src/agents/custom-managed-runtime.d.ts +0 -37
  125. package/dist/src/agents/custom-recovery-conformance.d.ts +0 -2
  126. package/dist/src/agents/custom.d.ts +0 -62
  127. package/dist/src/agents/detect.d.ts +0 -23
  128. package/dist/src/agents/event-terminal-gate.d.ts +0 -16
  129. package/dist/src/agents/external-channel-instructions.d.ts +0 -4
  130. package/dist/src/agents/gemini.d.ts +0 -32
  131. package/dist/src/agents/manager.d.ts +0 -57
  132. package/dist/src/agents/model-registry/cache.d.ts +0 -4
  133. package/dist/src/agents/model-registry/discovery.d.ts +0 -4
  134. package/dist/src/agents/model-registry/opencode-api.d.ts +0 -2
  135. package/dist/src/agents/model-registry/parsers.d.ts +0 -20
  136. package/dist/src/agents/model-registry/runner.d.ts +0 -6
  137. package/dist/src/agents/model-registry/service.d.ts +0 -10
  138. package/dist/src/agents/model-registry/types.d.ts +0 -39
  139. package/dist/src/agents/model-registry.d.ts +0 -17
  140. package/dist/src/agents/native-capabilities.d.ts +0 -10
  141. package/dist/src/agents/openclaw.d.ts +0 -29
  142. package/dist/src/agents/opencode-managed-permissions.d.ts +0 -25
  143. package/dist/src/agents/opencode.d.ts +0 -46
  144. package/dist/src/agents/pi-coding-agent-managed-permissions.d.ts +0 -7
  145. package/dist/src/agents/pi-coding-agent.d.ts +0 -63
  146. package/dist/src/agents/pi-managed-extension.d.ts +0 -12
  147. package/dist/src/agents/pi-managed-model-broker.d.ts +0 -27
  148. package/dist/src/agents/pi-managed-model-broker.js +0 -1
  149. package/dist/src/agents/pi-rpc-client.d.ts +0 -31
  150. package/dist/src/agents/pi-session-ownership.d.ts +0 -2
  151. package/dist/src/agents/platform-instructions.d.ts +0 -5
  152. package/dist/src/agents/runtime-compatibility.d.ts +0 -11
  153. package/dist/src/agents/workbuddy-managed-permissions.d.ts +0 -37
  154. package/dist/src/agents/workbuddy.d.ts +0 -63
  155. package/dist/src/commands/agent-readiness.d.ts +0 -17
  156. package/dist/src/commands/agent.d.ts +0 -2
  157. package/dist/src/commands/daemon-instance-lock.d.ts +0 -21
  158. package/dist/src/commands/daemon-process.d.ts +0 -6
  159. package/dist/src/commands/daemon-service-spec.d.ts +0 -26
  160. package/dist/src/commands/daemon-start-wait.d.ts +0 -9
  161. package/dist/src/commands/daemon-state.d.ts +0 -57
  162. package/dist/src/commands/daemon-windows.d.ts +0 -33
  163. package/dist/src/commands/daemon.d.ts +0 -67
  164. package/dist/src/commands/integration.d.ts +0 -3
  165. package/dist/src/commands/logout.d.ts +0 -3
  166. package/dist/src/commands/manager.d.ts +0 -2
  167. package/dist/src/commands/pair-authorization.d.ts +0 -3
  168. package/dist/src/commands/pair-browser.d.ts +0 -44
  169. package/dist/src/commands/pair-qr.d.ts +0 -4
  170. package/dist/src/commands/pair.d.ts +0 -19
  171. package/dist/src/commands/room.d.ts +0 -16
  172. package/dist/src/commands/runtime.d.ts +0 -2
  173. package/dist/src/commands/schedule.d.ts +0 -2
  174. package/dist/src/commands/tools.d.ts +0 -2
  175. package/dist/src/commands/upgrade.d.ts +0 -31
  176. package/dist/src/commands/worker.d.ts +0 -11
  177. package/dist/src/config/index.d.ts +0 -58
  178. package/dist/src/daemon-ipc/agent-readiness.d.ts +0 -15
  179. package/dist/src/daemon-ipc/client.d.ts +0 -8
  180. package/dist/src/daemon-ipc/control.d.ts +0 -16
  181. package/dist/src/daemon-ipc/json.d.ts +0 -3
  182. package/dist/src/daemon-ipc/paths.d.ts +0 -15
  183. package/dist/src/daemon-ipc/protocol.d.ts +0 -31
  184. package/dist/src/daemon-ipc/secret.d.ts +0 -3
  185. package/dist/src/daemon-ipc/server.d.ts +0 -20
  186. package/dist/src/daemon-log.d.ts +0 -9
  187. package/dist/src/env-path.d.ts +0 -15
  188. package/dist/src/fs/boundary.d.ts +0 -23
  189. package/dist/src/fs/handler.d.ts +0 -26
  190. package/dist/src/fs/security.d.ts +0 -2
  191. package/dist/src/fs/text-decoder.d.ts +0 -10
  192. package/dist/src/index.d.ts +0 -1
  193. package/dist/src/log-redaction.d.ts +0 -4
  194. package/dist/src/log-reporter.d.ts +0 -41
  195. package/dist/src/manager/prompt.d.ts +0 -2
  196. package/dist/src/manager/registry.d.ts +0 -184
  197. package/dist/src/manager/retired-external-channel-compat.d.ts +0 -78
  198. package/dist/src/manager/runtime.d.ts +0 -90
  199. package/dist/src/manager/worker-ipc.d.ts +0 -28
  200. package/dist/src/manager/worker-markdown.d.ts +0 -10
  201. package/dist/src/native-fusion/codex-files.d.ts +0 -10
  202. package/dist/src/native-fusion/codex-message-parser.d.ts +0 -9
  203. package/dist/src/native-fusion/codex-parser.d.ts +0 -8
  204. package/dist/src/native-fusion/codex-user-input.d.ts +0 -11
  205. package/dist/src/native-fusion/config.d.ts +0 -1
  206. package/dist/src/native-fusion/file-identity.d.ts +0 -9
  207. package/dist/src/native-fusion/file-watcher.d.ts +0 -26
  208. package/dist/src/native-fusion/local-repository.d.ts +0 -90
  209. package/dist/src/native-fusion/native-source-deletions.d.ts +0 -47
  210. package/dist/src/native-fusion/opencode-parser.d.ts +0 -29
  211. package/dist/src/native-fusion/parser-common.d.ts +0 -35
  212. package/dist/src/native-fusion/parsers.d.ts +0 -13
  213. package/dist/src/native-fusion/service.d.ts +0 -64
  214. package/dist/src/native-fusion/session-header.d.ts +0 -13
  215. package/dist/src/native-fusion/session-native-sources.d.ts +0 -24
  216. package/dist/src/native-fusion/source-visibility-audit.d.ts +0 -16
  217. package/dist/src/native-fusion/source-visibility.d.ts +0 -25
  218. package/dist/src/native-fusion/state.d.ts +0 -4
  219. package/dist/src/native-fusion/types.d.ts +0 -82
  220. package/dist/src/personal-sync/epoch.d.ts +0 -17
  221. package/dist/src/personal-sync/identity.d.ts +0 -1
  222. package/dist/src/personal-sync/machine-authority.d.ts +0 -12
  223. package/dist/src/personal-sync/metrics.d.ts +0 -25
  224. package/dist/src/personal-sync/paths.d.ts +0 -5
  225. package/dist/src/region.d.ts +0 -15
  226. package/dist/src/relay/client.d.ts +0 -81
  227. package/dist/src/room/activation-audit.d.ts +0 -15
  228. package/dist/src/room/activation-policy.d.ts +0 -8
  229. package/dist/src/room/activation-service.d.ts +0 -77
  230. package/dist/src/room/attachment-cache.d.ts +0 -44
  231. package/dist/src/room/attachment-upload.d.ts +0 -20
  232. package/dist/src/room/device-authorization-client.d.ts +0 -91
  233. package/dist/src/room/host-session-observations.d.ts +0 -54
  234. package/dist/src/room/invite-bootstrap.d.ts +0 -49
  235. package/dist/src/room/invite-qr.d.ts +0 -6
  236. package/dist/src/room/live-delivery.d.ts +0 -5
  237. package/dist/src/room/managed-context.d.ts +0 -49
  238. package/dist/src/room/managed-prompt-composer.d.ts +0 -47
  239. package/dist/src/room/managed-room-binding.d.ts +0 -69
  240. package/dist/src/room/managed-room-ipc.d.ts +0 -65
  241. package/dist/src/room/mirror-sync-service.d.ts +0 -49
  242. package/dist/src/room/public-attachment-cache.d.ts +0 -34
  243. package/dist/src/room/public-room-client.d.ts +0 -37
  244. package/dist/src/room/registration-authority.d.ts +0 -4
  245. package/dist/src/room/room-action-client-types.d.ts +0 -137
  246. package/dist/src/room/room-action-client.d.ts +0 -116
  247. package/dist/src/room/room-binding-client.d.ts +0 -62
  248. package/dist/src/room/session-registry.d.ts +0 -158
  249. package/dist/src/runtime-distribution.d.ts +0 -7
  250. package/dist/src/schedules/personal-context.d.ts +0 -2
  251. package/dist/src/schedules/server-client.d.ts +0 -19
  252. package/dist/src/security/managed-agent-credential-paths.d.ts +0 -6
  253. package/dist/src/security/managed-agent-executable.d.ts +0 -19
  254. package/dist/src/security/managed-agent-policy.d.ts +0 -66
  255. package/dist/src/security/managed-agent-runtime.d.ts +0 -44
  256. package/dist/src/session/archive-zip.d.ts +0 -10
  257. package/dist/src/session/attachment-reference.d.ts +0 -2
  258. package/dist/src/session/attachment-transfer-store.d.ts +0 -45
  259. package/dist/src/session/canonical-store.d.ts +0 -104
  260. package/dist/src/session/deletion-sync-state.d.ts +0 -20
  261. package/dist/src/session/deletion-sync-validation.d.ts +0 -2
  262. package/dist/src/session/deletion-synchronizer.d.ts +0 -9
  263. package/dist/src/session/handlers/agent-capabilities.d.ts +0 -3
  264. package/dist/src/session/handlers/agent-config.d.ts +0 -7
  265. package/dist/src/session/handlers/agent-control.d.ts +0 -4
  266. package/dist/src/session/handlers/agent-workspace-validation.d.ts +0 -28
  267. package/dist/src/session/handlers/agents.d.ts +0 -11
  268. package/dist/src/session/handlers/chat-adapter-config.d.ts +0 -11
  269. package/dist/src/session/handlers/chat-context.d.ts +0 -31
  270. package/dist/src/session/handlers/chat-events.d.ts +0 -5
  271. package/dist/src/session/handlers/chat-recovery.d.ts +0 -4
  272. package/dist/src/session/handlers/chat-session-lifecycle.d.ts +0 -9
  273. package/dist/src/session/handlers/chat.d.ts +0 -6
  274. package/dist/src/session/handlers/control.d.ts +0 -5
  275. package/dist/src/session/handlers/fs.d.ts +0 -14
  276. package/dist/src/session/handlers/message-status.d.ts +0 -3
  277. package/dist/src/session/handlers/pi-validation-session.d.ts +0 -7
  278. package/dist/src/session/handlers/pi-validation-session.js +0 -1
  279. package/dist/src/session/handlers/project-fs.d.ts +0 -11
  280. package/dist/src/session/handlers/remote-access.d.ts +0 -4
  281. package/dist/src/session/handlers/room-managed.d.ts +0 -6
  282. package/dist/src/session/handlers/session-refresh.d.ts +0 -3
  283. package/dist/src/session/handlers/title.d.ts +0 -3
  284. package/dist/src/session/handlers/tool-detail.d.ts +0 -3
  285. package/dist/src/session/handlers/voice-window.d.ts +0 -3
  286. package/dist/src/session/history-subscriptions.d.ts +0 -29
  287. package/dist/src/session/index-publisher.d.ts +0 -3
  288. package/dist/src/session/manager-event-authority.d.ts +0 -3
  289. package/dist/src/session/manager.d.ts +0 -95
  290. package/dist/src/session/native-cleanup-outbox.d.ts +0 -64
  291. package/dist/src/session/native-session-lifecycle.d.ts +0 -56
  292. package/dist/src/session/project-fs-store.d.ts +0 -43
  293. package/dist/src/session/projection.d.ts +0 -3
  294. package/dist/src/session/queue-control.d.ts +0 -27
  295. package/dist/src/session/queue-helpers.d.ts +0 -20
  296. package/dist/src/session/queue-message.d.ts +0 -35
  297. package/dist/src/session/queue-retry.d.ts +0 -11
  298. package/dist/src/session/queue-storage.d.ts +0 -8
  299. package/dist/src/session/queue-types.d.ts +0 -31
  300. package/dist/src/session/queue.d.ts +0 -73
  301. package/dist/src/session/queued-chat-dispatch.d.ts +0 -12
  302. package/dist/src/session/run-recovery/barrier.d.ts +0 -12
  303. package/dist/src/session/run-recovery/coordinator.d.ts +0 -32
  304. package/dist/src/session/run-recovery/journal.d.ts +0 -30
  305. package/dist/src/session/run-recovery/schema.d.ts +0 -48
  306. package/dist/src/session/store.d.ts +0 -128
  307. package/dist/src/session/tool-detail-store.d.ts +0 -17
  308. package/dist/src/session/turn-trigger.d.ts +0 -43
  309. package/dist/src/session/types.d.ts +0 -93
  310. package/dist/src/tools/markdown-to-pdf.d.ts +0 -42
  311. package/dist/src/upgrade/channel.d.ts +0 -5
  312. package/dist/src/upgrade/distribution.d.ts +0 -21
  313. package/dist/src/upgrade/engine.d.ts +0 -104
  314. package/dist/src/upgrade/scheduler.d.ts +0 -60
  315. package/dist/src/upgrade/updater-bootstrap.d.ts +0 -12
  316. package/dist/src/upgrade/updater-launcher.d.ts +0 -37
  317. package/dist/src/upgrade/updater-protocol.d.ts +0 -40
  318. package/dist/src/upgrade/updater-service-entry.d.ts +0 -7
  319. package/dist/src/upgrade/updater-worker.d.ts +0 -57
  320. package/dist/src/windows-shell.d.ts +0 -6
  321. package/node_modules/@shennian/wire/dist/agent-capabilities.d.ts +0 -16
  322. package/node_modules/@shennian/wire/dist/agent-workspace.d.ts +0 -133
  323. package/node_modules/@shennian/wire/dist/envelope.d.ts +0 -7
  324. package/node_modules/@shennian/wire/dist/events.d.ts +0 -125
  325. package/node_modules/@shennian/wire/dist/external-message-format.d.ts +0 -37
  326. package/node_modules/@shennian/wire/dist/frames.d.ts +0 -33
  327. package/node_modules/@shennian/wire/dist/fs.d.ts +0 -107
  328. package/node_modules/@shennian/wire/dist/index.d.ts +0 -21
  329. package/node_modules/@shennian/wire/dist/machine.d.ts +0 -160
  330. package/node_modules/@shennian/wire/dist/message-payload.d.ts +0 -71
  331. package/node_modules/@shennian/wire/dist/methods.d.ts +0 -5
  332. package/node_modules/@shennian/wire/dist/native-session.d.ts +0 -20
  333. package/node_modules/@shennian/wire/dist/project-fs.d.ts +0 -146
  334. package/node_modules/@shennian/wire/dist/project-path.d.ts +0 -4
  335. package/node_modules/@shennian/wire/dist/project.d.ts +0 -16
  336. package/node_modules/@shennian/wire/dist/relay-connectivity.d.ts +0 -30
  337. package/node_modules/@shennian/wire/dist/room.d.ts +0 -190
  338. package/node_modules/@shennian/wire/dist/schedule.d.ts +0 -37
  339. package/node_modules/@shennian/wire/dist/session-sync.d.ts +0 -406
  340. package/node_modules/@shennian/wire/dist/session.d.ts +0 -465
  341. package/node_modules/@shennian/wire/dist/tool-detail.d.ts +0 -38
  342. package/node_modules/@shennian/wire/dist/voice-chief.d.ts +0 -116
@@ -1,144 +1 @@
1
- // @arch docs/features/agent-workspaces.md
2
- // @arch docs/features/managed-agent-restricted-runtime.md
3
- export const MANAGED_AGENT_PERMISSION_POLICY_VERSION = 1;
4
- export const DEFAULT_MANAGED_AGENT_PERMISSION_POLICY = {
5
- version: MANAGED_AGENT_PERMISSION_POLICY_VERSION,
6
- executionMode: 'restricted',
7
- fileAccess: 'workspace-read',
8
- externalCapabilities: {
9
- commandNetwork: false,
10
- webSearch: false,
11
- browser: false,
12
- computerUse: false,
13
- mcp: false,
14
- },
15
- };
16
- /** Explicit default sent by current creation surfaces; omission remains restricted. */
17
- export const DEFAULT_NATIVE_FULL_MANAGED_AGENT_PERMISSION_POLICY = {
18
- version: MANAGED_AGENT_PERMISSION_POLICY_VERSION,
19
- executionMode: 'native-full',
20
- fileAccess: 'host-full',
21
- externalCapabilities: {
22
- commandNetwork: true,
23
- webSearch: true,
24
- browser: true,
25
- computerUse: true,
26
- mcp: true,
27
- },
28
- };
29
- /** Named alias used where the old-client fallback must be obvious at the call site. */
30
- export const DEFAULT_RESTRICTED_MANAGED_AGENT_PERMISSION_POLICY = DEFAULT_MANAGED_AGENT_PERMISSION_POLICY;
31
- /**
32
- * Compatibility projection for payloads created before managed permissions existed.
33
- * Missing policy data must never be presented as if a restrictive sandbox were active.
34
- */
35
- export const LEGACY_MANAGED_AGENT_PERMISSION_POLICY = {
36
- version: MANAGED_AGENT_PERMISSION_POLICY_VERSION,
37
- executionMode: 'restricted',
38
- fileAccess: 'host-full',
39
- externalCapabilities: {
40
- commandNetwork: true,
41
- webSearch: true,
42
- browser: true,
43
- computerUse: true,
44
- mcp: true,
45
- },
46
- };
47
- /**
48
- * Project the policy the runtime can actually guarantee. Missing directional
49
- * evidence is treated as possible host-wide file and external access.
50
- */
51
- export function resolveManagedAgentEffectivePermissionPolicy(requested, protection) {
52
- const matrix = protection?.capabilityMatrix;
53
- if (!matrix) {
54
- return {
55
- version: requested.version,
56
- executionMode: requested.executionMode ?? 'restricted',
57
- fileAccess: 'host-full',
58
- externalCapabilities: {
59
- commandNetwork: true,
60
- webSearch: true,
61
- browser: true,
62
- computerUse: true,
63
- mcp: true,
64
- },
65
- };
66
- }
67
- const fileAccess = matrix.fileAccess[requested.fileAccess]
68
- ? requested.fileAccess
69
- : matrix.fileAccess['host-full']
70
- ? 'host-full'
71
- : requested.fileAccess;
72
- const externalCapabilities = { ...requested.externalCapabilities };
73
- for (const capability of Object.keys(externalCapabilities)) {
74
- if (!externalCapabilities[capability] && !matrix.externalCapabilities[capability].deny) {
75
- externalCapabilities[capability] = true;
76
- }
77
- }
78
- return {
79
- version: requested.version,
80
- executionMode: requested.executionMode ?? 'restricted',
81
- fileAccess,
82
- externalCapabilities,
83
- };
84
- }
85
- function copyManagedAgentPermissionPolicy(policy) {
86
- return {
87
- ...policy,
88
- externalCapabilities: { ...policy.externalCapabilities },
89
- };
90
- }
91
- /** Strictly parse an explicit policy. Invalid or incomplete values are not silently repaired. */
92
- export function parseManagedAgentPermissionPolicy(value) {
93
- if (!value || typeof value !== 'object' || Array.isArray(value))
94
- return null;
95
- const policy = value;
96
- if (!Number.isSafeInteger(policy.version) || Number(policy.version) < 1)
97
- return null;
98
- if (policy.executionMode !== undefined &&
99
- policy.executionMode !== 'native-full' &&
100
- policy.executionMode !== 'restricted') {
101
- return null;
102
- }
103
- if (policy.fileAccess !== 'workspace-read' &&
104
- policy.fileAccess !== 'workspace-write' &&
105
- policy.fileAccess !== 'host-full') {
106
- return null;
107
- }
108
- if (!policy.externalCapabilities ||
109
- typeof policy.externalCapabilities !== 'object' ||
110
- Array.isArray(policy.externalCapabilities)) {
111
- return null;
112
- }
113
- const capabilities = policy.externalCapabilities;
114
- if (typeof capabilities.commandNetwork !== 'boolean' ||
115
- typeof capabilities.webSearch !== 'boolean' ||
116
- typeof capabilities.browser !== 'boolean' ||
117
- typeof capabilities.computerUse !== 'boolean' ||
118
- typeof capabilities.mcp !== 'boolean') {
119
- return null;
120
- }
121
- return {
122
- version: Number(policy.version),
123
- executionMode: policy.executionMode === 'native-full' ? 'native-full' : 'restricted',
124
- fileAccess: policy.fileAccess,
125
- externalCapabilities: {
126
- commandNetwork: capabilities.commandNetwork,
127
- webSearch: capabilities.webSearch,
128
- browser: capabilities.browser,
129
- computerUse: capabilities.computerUse,
130
- mcp: capabilities.mcp,
131
- },
132
- };
133
- }
134
- export function managedAgentExecutionMode(policy) {
135
- return policy.executionMode === 'native-full' ? 'native-full' : 'restricted';
136
- }
137
- export function resolveManagedAgentPermissionPolicy(value, fallback = 'legacy') {
138
- const parsed = parseManagedAgentPermissionPolicy(value);
139
- if (parsed)
140
- return parsed;
141
- return copyManagedAgentPermissionPolicy(fallback === 'default'
142
- ? DEFAULT_MANAGED_AGENT_PERMISSION_POLICY
143
- : LEGACY_MANAGED_AGENT_PERMISSION_POLICY);
144
- }
1
+ const u=1,n={version:1,executionMode:"restricted",fileAccess:"workspace-read",externalCapabilities:{commandNetwork:!1,webSearch:!1,browser:!1,computerUse:!1,mcp:!1}},f={version:1,executionMode:"native-full",fileAccess:"host-full",externalCapabilities:{commandNetwork:!0,webSearch:!0,browser:!0,computerUse:!0,mcp:!0}},p=n,s={version:1,executionMode:"restricted",fileAccess:"host-full",externalCapabilities:{commandNetwork:!0,webSearch:!0,browser:!0,computerUse:!0,mcp:!0}};function A(e,t){const r=t?.capabilityMatrix;if(!r)return{version:e.version,executionMode:e.executionMode??"restricted",fileAccess:"host-full",externalCapabilities:{commandNetwork:!0,webSearch:!0,browser:!0,computerUse:!0,mcp:!0}};const c=r.fileAccess[e.fileAccess]?e.fileAccess:r.fileAccess["host-full"]?"host-full":e.fileAccess,i={...e.externalCapabilities};for(const o of Object.keys(i))!i[o]&&!r.externalCapabilities[o].deny&&(i[o]=!0);return{version:e.version,executionMode:e.executionMode??"restricted",fileAccess:c,externalCapabilities:i}}function a(e){return{...e,externalCapabilities:{...e.externalCapabilities}}}function l(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;if(!Number.isSafeInteger(t.version)||Number(t.version)<1||t.executionMode!==void 0&&t.executionMode!=="native-full"&&t.executionMode!=="restricted"||t.fileAccess!=="workspace-read"&&t.fileAccess!=="workspace-write"&&t.fileAccess!=="host-full"||!t.externalCapabilities||typeof t.externalCapabilities!="object"||Array.isArray(t.externalCapabilities))return null;const r=t.externalCapabilities;return typeof r.commandNetwork!="boolean"||typeof r.webSearch!="boolean"||typeof r.browser!="boolean"||typeof r.computerUse!="boolean"||typeof r.mcp!="boolean"?null:{version:Number(t.version),executionMode:t.executionMode==="native-full"?"native-full":"restricted",fileAccess:t.fileAccess,externalCapabilities:{commandNetwork:r.commandNetwork,webSearch:r.webSearch,browser:r.browser,computerUse:r.computerUse,mcp:r.mcp}}}function b(e){return e.executionMode==="native-full"?"native-full":"restricted"}function x(e,t="legacy"){const r=l(e);return r||a(t==="default"?n:s)}export{n as DEFAULT_MANAGED_AGENT_PERMISSION_POLICY,f as DEFAULT_NATIVE_FULL_MANAGED_AGENT_PERMISSION_POLICY,p as DEFAULT_RESTRICTED_MANAGED_AGENT_PERMISSION_POLICY,s as LEGACY_MANAGED_AGENT_PERMISSION_POLICY,u as MANAGED_AGENT_PERMISSION_POLICY_VERSION,b as managedAgentExecutionMode,l as parseManagedAgentPermissionPolicy,A as resolveManagedAgentEffectivePermissionPolicy,x as resolveManagedAgentPermissionPolicy};
@@ -1 +1 @@
1
- export {};
1
+
@@ -1 +1 @@
1
- export {};
1
+
@@ -1,70 +1,3 @@
1
- // @arch docs/features/free-growth-phase.md
2
- // @test packages/wire/src/__tests__/external-message-format.test.ts
3
- function cleanText(value) {
4
- return typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : '';
5
- }
6
- function escapeMarkdownLabel(value) {
7
- return value.replace(/[[\]\\]/g, '\\$&');
8
- }
9
- function markdownLink(label, href) {
10
- return `[${escapeMarkdownLabel(label)}](<${href}>)`;
11
- }
12
- function externalAttachmentHref(attachment) {
13
- return cleanText(attachment.path)
14
- || cleanText(attachment.url)
15
- || cleanText(attachment.localPath)
16
- || cleanText(attachment.thumbnailPath);
17
- }
18
- function externalAttachmentName(attachment, index) {
19
- const pathParts = cleanText(attachment.path || attachment.url || attachment.localPath || attachment.thumbnailPath).split('/').filter(Boolean);
20
- return cleanText(attachment.name)
21
- || pathParts[pathParts.length - 1]
22
- || `attachment-${index + 1}`;
23
- }
24
- function unavailableStatus(attachment) {
25
- return cleanText(attachment.providerError)
26
- || cleanText(attachment.availability)
27
- || '';
28
- }
29
- export function formatExternalAttachmentReference(attachment, index = 0) {
30
- const name = externalAttachmentName(attachment, index);
31
- const href = externalAttachmentHref(attachment);
32
- if (href)
33
- return markdownLink(name, href);
34
- const status = unavailableStatus(attachment);
35
- return status ? `${name} (${status})` : name;
36
- }
37
- export function formatExternalMessageLine(input) {
38
- const sender = cleanText(input.senderName) || cleanText(input.senderId) || '对方';
39
- const text = cleanText(input.text);
40
- const prefix = input.isTrigger ? '=> ' : '';
41
- const time = cleanText(input.timestampLabel);
42
- const head = `${prefix}${time ? `${time} ` : ''}${sender}:`;
43
- return text ? `${head} ${text}` : head;
44
- }
45
- export function formatExternalConversationMessage(message) {
46
- const line = formatExternalMessageLine(message);
47
- const sender = cleanText(message.senderName) || cleanText(message.senderId) || '对方';
48
- const attachmentLines = (message.attachments ?? []).map((attachment, index) => {
49
- return `${sender}: ${formatExternalAttachmentReference(attachment, index)}`;
50
- });
51
- const lines = [
52
- line,
53
- ...attachmentLines,
54
- ].filter(Boolean);
55
- return {
56
- text: lines.join('\n'),
57
- attachmentLines,
58
- };
59
- }
60
- export function formatExternalConversationText(input) {
61
- const conversationName = cleanText(input.conversationName);
62
- const header = [
63
- input.includeContextLabel ? '外部消息上下文(@触发)' : '',
64
- `外部对话: ${conversationName || '未命名对话'}`,
65
- ].filter(Boolean);
66
- const body = input.messages
67
- .map((message) => formatExternalConversationMessage(message).text)
68
- .filter(Boolean);
69
- return [...header, ...body].join('\n');
70
- }
1
+ function n(e){return typeof e=="string"?e.replace(/\s+/g," ").trim():""}function l(e){return e.replace(/[[\]\\]/g,"\\$&")}function c(e,r){return`[${l(e)}](<${r}>)`}function f(e){return n(e.path)||n(e.url)||n(e.localPath)||n(e.thumbnailPath)}function u(e,r){const t=n(e.path||e.url||e.localPath||e.thumbnailPath).split("/").filter(Boolean);return n(e.name)||t[t.length-1]||`attachment-${r+1}`}function x(e){return n(e.providerError)||n(e.availability)||""}function d(e,r=0){const t=u(e,r),o=f(e);if(o)return c(t,o);const a=x(e);return a?`${t} (${a})`:t}function $(e){const r=n(e.senderName)||n(e.senderId)||"\u5BF9\u65B9",t=n(e.text),o=e.isTrigger?"=> ":"",a=n(e.timestampLabel),s=`${o}${a?`${a} `:""}${r}:`;return t?`${s} ${t}`:s}function m(e){const r=$(e),t=n(e.senderName)||n(e.senderId)||"\u5BF9\u65B9",o=(e.attachments??[]).map((s,i)=>`${t}: ${d(s,i)}`);return{text:[r,...o].filter(Boolean).join(`
2
+ `),attachmentLines:o}}function p(e){const r=n(e.conversationName),t=[e.includeContextLabel?"\u5916\u90E8\u6D88\u606F\u4E0A\u4E0B\u6587\uFF08@\u89E6\u53D1\uFF09":"",`\u5916\u90E8\u5BF9\u8BDD: ${r||"\u672A\u547D\u540D\u5BF9\u8BDD"}`].filter(Boolean),o=e.messages.map(a=>m(a).text).filter(Boolean);return[...t,...o].join(`
3
+ `)}export{d as formatExternalAttachmentReference,m as formatExternalConversationMessage,p as formatExternalConversationText,$ as formatExternalMessageLine};
@@ -1 +1 @@
1
- export {};
1
+
@@ -1,7 +1,2 @@
1
- /** Stable input for the aggregate hash of a folder transfer. */
2
- export function serializeFsTransferManifest(entries) {
3
- return [...entries]
4
- .sort((left, right) => left.relativePath.localeCompare(right.relativePath))
5
- .map((entry) => `${entry.relativePath}\0${entry.size}\0${entry.sha256.toLowerCase()}`)
6
- .join('\n');
7
- }
1
+ function t(a){return[...a].sort((e,r)=>e.relativePath.localeCompare(r.relativePath)).map(e=>`${e.relativePath}\0${e.size}\0${e.sha256.toLowerCase()}`).join(`
2
+ `)}export{t as serializeFsTransferManifest};
@@ -1,21 +1 @@
1
- export * from "./envelope.js";
2
- export * from "./events.js";
3
- export * from "./machine.js";
4
- export * from "./methods.js";
5
- export * from "./frames.js";
6
- export * from "./fs.js";
7
- export * from "./session.js";
8
- export * from "./session-sync.js";
9
- export * from "./message-payload.js";
10
- export * from "./external-message-format.js";
11
- export * from "./native-session.js";
12
- export * from "./tool-detail.js";
13
- export * from "./voice-chief.js";
14
- export * from "./project.js";
15
- export * from "./project-fs.js";
16
- export * from "./room.js";
17
- export * from "./agent-capabilities.js";
18
- export * from "./agent-workspace.js";
19
- export * from "./relay-connectivity.js";
20
- export * from "./project-path.js";
21
- export * from "./schedule.js";
1
+ export*from"./envelope.js";export*from"./events.js";export*from"./machine.js";export*from"./methods.js";export*from"./frames.js";export*from"./fs.js";export*from"./session.js";export*from"./session-sync.js";export*from"./message-payload.js";export*from"./external-message-format.js";export*from"./native-session.js";export*from"./tool-detail.js";export*from"./voice-chief.js";export*from"./project.js";export*from"./project-fs.js";export*from"./room.js";export*from"./agent-capabilities.js";export*from"./agent-workspace.js";export*from"./relay-connectivity.js";export*from"./project-path.js";export*from"./schedule.js";
@@ -1 +1 @@
1
- export {};
1
+
@@ -1,307 +1,8 @@
1
- // @arch docs/architecture/app/chat-attachments-preview.md
2
- // @test packages/wire/src/__tests__/message-payload.test.ts
3
- const GIT_DIRECTIVE_LINE_RE = /^\s*::git-[a-z-]+\{[^\n]*\}\s*$/gm;
4
- const TOOL_PAYLOAD_PREFIX_RE = /^\s*\{\s*"v"\s*:\s*1\s*,\s*"type"\s*:\s*"(tool|tool_use|tool_result)"/;
5
- const ENVIRONMENT_CONTEXT_RE = /^\s*<environment_context>\s*[^]*?<\/environment_context>\s*$/i;
6
- const ENVIRONMENT_CONTEXT_REQUIRED_TAG_RE = /<(cwd|shell|current_date|timezone)>[^<]*<\/\1>/gi;
7
- const CODEX_RECOMMENDED_PLUGINS_PREFIX_RE = /^\s*<recommended_plugins>[^]*?<\/recommended_plugins>\s*/i;
8
- const CODEX_TURN_ABORTED_RE = /^\s*<turn_aborted>[^]*?<\/turn_aborted>\s*$/i;
9
- const CODEX_INTERNAL_CONTEXT_RE = /^\s*<codex_internal_context\b[^>]*>[^]*?<\/codex_internal_context>\s*$/i;
10
- const CODEX_PROJECT_INSTRUCTIONS_RE = /^\s*# AGENTS\.md instructions for [^\n]+\n+\s*<INSTRUCTIONS>\s*[^]*?<\/INSTRUCTIONS>\s*(?:<environment_context>[^]*?<\/environment_context>)?\s*$/i;
11
- const APPROVAL_PENDING_PAYLOAD_PREFIX_RE = /^\s*\{\s*"v"\s*:\s*1\s*,\s*"type"\s*:\s*"approval_pending"/;
12
- const PREVIEW_PRIVATE_CONTEXT_RE = /(?:<\/?(?:environment_context|instructions|system|developer|codex_internal_context|recommended_plugins)\b|#\s*AGENTS\.md instructions\b)/i;
13
- const PREVIEW_DATA_URL_RE = /\bdata:[a-z0-9.+-]+\/[a-z0-9.+-]+;base64,[a-z0-9+/=\s]+/i;
14
- const PREVIEW_BASE64_BLOB_RE = /(?:^|\s)(?=[A-Za-z0-9+/]{80,}={0,2}(?=\s|$))(?=[A-Za-z0-9+/]*[A-Z])(?=[A-Za-z0-9+/]*[a-z])(?=[A-Za-z0-9+/]*[0-9])[A-Za-z0-9+/]{80,}={0,2}(?=\s|$)/;
15
- const PREVIEW_HIDDEN_TYPES = new Set([
16
- 'tool',
17
- 'tool_use',
18
- 'tool_result',
19
- 'thinking',
20
- 'system',
21
- 'developer',
22
- 'context',
23
- 'environment_context',
24
- 'channel_delivery_status',
25
- ]);
26
- function escapeMarkdownLabel(label) {
27
- return label.replace(/[[\]\\]/g, '\\$&');
28
- }
29
- function buildAttachmentRef(attachment) {
30
- const label = escapeMarkdownLabel(attachment.name);
31
- return attachment.kind === 'image'
32
- ? `![${label}](<${attachment.path}>)`
33
- : `[${label}](<${attachment.path}>)`;
34
- }
35
- function stripAttachmentRefs(content, attachments) {
36
- if (!attachments?.length)
37
- return content;
38
- const refs = new Set(attachments.map(buildAttachmentRef));
39
- const lines = content
40
- .split('\n')
41
- .filter((line) => !refs.has(line.trim()));
42
- return lines.join('\n').replace(/\n{3,}/g, '\n\n').trim();
43
- }
44
- function parseObjectPayload(payload) {
45
- if (!payload || payload[0] !== '{')
46
- return null;
47
- try {
48
- const parsed = JSON.parse(payload);
49
- if (typeof parsed === 'object' && parsed !== null) {
50
- return parsed;
51
- }
52
- }
53
- catch {
54
- // fall through
55
- }
56
- return null;
57
- }
58
- function parseAttachmentMeta(value) {
59
- if (typeof value !== 'object' || value === null)
60
- return null;
61
- const entry = value;
62
- const path = typeof entry.path === 'string' ? entry.path : '';
63
- const name = typeof entry.name === 'string' ? entry.name : '';
64
- const mimeType = typeof entry.mimeType === 'string' ? entry.mimeType : '';
65
- const kind = entry.kind === 'image' || entry.kind === 'file' || entry.kind === 'folder'
66
- ? entry.kind
67
- : null;
68
- if (!path || !name || !mimeType || !kind)
69
- return null;
70
- const previewData = typeof entry.previewData === 'string' && entry.previewData.trim() ? entry.previewData.trim() : undefined;
71
- const byteSize = typeof entry.byteSize === 'number' && Number.isSafeInteger(entry.byteSize) && entry.byteSize >= 0
72
- ? entry.byteSize
73
- : undefined;
74
- const sha256 = typeof entry.sha256 === 'string' && /^[a-f0-9]{64}$/i.test(entry.sha256)
75
- ? entry.sha256.toLowerCase()
76
- : undefined;
77
- return {
78
- path,
79
- name,
80
- mimeType,
81
- kind,
82
- ...(byteSize !== undefined ? { byteSize } : {}),
83
- ...(sha256 ? { sha256 } : {}),
84
- ...(previewData ? { previewData } : {}),
85
- };
86
- }
87
- export function parseStructuredMessagePayload(payload) {
88
- const parsed = parseObjectPayload(payload);
89
- if (!parsed)
90
- return null;
91
- if (parsed.v !== 1)
92
- return null;
93
- if (parsed.type === 'user' && typeof parsed.content === 'string') {
94
- const attachments = Array.isArray(parsed.attachments)
95
- ? parsed.attachments
96
- .map(parseAttachmentMeta)
97
- .filter((item) => item != null)
98
- : undefined;
99
- return {
100
- v: 1,
101
- type: 'user',
102
- content: parsed.content,
103
- ...(attachments?.length ? { attachments } : {}),
104
- };
105
- }
106
- return parsed;
107
- }
108
- export function parseUserMessagePayload(payload) {
109
- const parsed = parseStructuredMessagePayload(payload);
110
- return parsed?.type === 'user' ? parsed : null;
111
- }
112
- export function buildUserMessagePayload(content, attachments) {
113
- if (!attachments?.length)
114
- return content;
115
- return JSON.stringify({
116
- v: 1,
117
- type: 'user',
118
- content,
119
- attachments,
120
- });
121
- }
122
- export function isToolPayload(payload) {
123
- if (TOOL_PAYLOAD_PREFIX_RE.test(payload))
124
- return true;
125
- const parsed = parseStructuredMessagePayload(payload);
126
- if (!parsed || typeof parsed !== 'object')
127
- return false;
128
- return (parsed.type === 'tool' ||
129
- parsed.type === 'tool_use' ||
130
- parsed.type === 'tool_result');
131
- }
132
- export function isApprovalPendingPayload(payload) {
133
- if (APPROVAL_PENDING_PAYLOAD_PREFIX_RE.test(payload))
134
- return true;
135
- const parsed = parseStructuredMessagePayload(payload);
136
- return parsed?.type === 'approval_pending';
137
- }
138
- export function isAgentHiddenPayload(payload) {
139
- return parseChannelDeliveryStatusPayload(payload)?.agentVisible === false;
140
- }
141
- export function parseChannelDeliveryStatusPayload(payload) {
142
- const parsed = parseStructuredMessagePayload(payload);
143
- if (!parsed || parsed.type !== 'channel_delivery_status')
144
- return null;
145
- const record = parsed;
146
- if (record.v !== 1)
147
- return null;
148
- if (record.channel !== 'wechat')
149
- return null;
150
- if (record.agentVisible !== false)
151
- return null;
152
- const status = typeof record.status === 'string' && record.status.trim() ? record.status.trim() : '';
153
- if (!status)
154
- return null;
155
- const content = typeof record.content === 'string' && record.content.trim()
156
- ? record.content
157
- : status === 'manual_review'
158
- ? '发送状态不确定,请检查微信'
159
- : '未能自动发送到微信';
160
- return {
161
- v: 1,
162
- type: 'channel_delivery_status',
163
- channel: 'wechat',
164
- status,
165
- agentVisible: false,
166
- content,
167
- replyId: stringOrUndefined(record.replyId),
168
- idempotencyKey: stringOrUndefined(record.idempotencyKey),
169
- bindingId: stringOrUndefined(record.bindingId),
170
- reasonCode: stringOrUndefined(record.reasonCode),
171
- copyText: stringOrUndefined(record.copyText),
172
- copyableContentRef: stringOrUndefined(record.copyableContentRef),
173
- errorSummary: stringOrUndefined(record.errorSummary),
174
- };
175
- }
176
- export function buildApprovalPendingPayload(input) {
177
- return JSON.stringify({
178
- v: 1,
179
- type: 'approval_pending',
180
- title: input?.title?.trim() || '需要用户确认',
181
- content: input?.content?.trim() || 'Codex 正在等待用户确认后继续。',
182
- source: input?.source?.trim() || 'codex',
183
- actionHint: input?.permission
184
- ? input?.actionHint?.trim()
185
- : input?.actionHint?.trim() || '当前神念暂不支持远程确认,请回到运行 Codex 的电脑/终端完成确认。',
186
- ...(input?.permission ? { permission: input.permission } : {}),
187
- });
188
- }
189
- export function isSystemEnvironmentContextPayload(payload) {
190
- if (!ENVIRONMENT_CONTEXT_RE.test(payload))
191
- return false;
192
- const found = new Set();
193
- for (const match of payload.matchAll(ENVIRONMENT_CONTEXT_REQUIRED_TAG_RE)) {
194
- if (match[1])
195
- found.add(match[1].toLowerCase());
196
- }
197
- if (found.has('current_date') && found.has('timezone') && payload.includes('<workspace_roots>')) {
198
- return true;
199
- }
200
- return found.has('cwd') && found.has('shell') && found.has('current_date') && found.has('timezone');
201
- }
202
- export function isCodexTurnAbortedPayload(payload) {
203
- return CODEX_TURN_ABORTED_RE.test(payload);
204
- }
205
- export function isCodexProjectInstructionsPayload(payload) {
206
- return CODEX_PROJECT_INSTRUCTIONS_RE.test(payload);
207
- }
208
- export function isSystemControlPayload(payload) {
209
- // Codex can inject the catalog alone or before environment/project metadata.
210
- // Consume only a complete prefix and require the entire remainder to be control
211
- // context, so discussions, code samples and appended user requests stay visible.
212
- const plugins = payload.match(CODEX_RECOMMENDED_PLUGINS_PREFIX_RE);
213
- if (plugins) {
214
- const remainder = payload.slice(plugins[0].length).trim();
215
- return !remainder || isSystemEnvironmentContextPayload(remainder) ||
216
- isCodexProjectInstructionsPayload(remainder);
217
- }
218
- return (isSystemEnvironmentContextPayload(payload) ||
219
- isCodexTurnAbortedPayload(payload) ||
220
- CODEX_INTERNAL_CONTEXT_RE.test(payload) ||
221
- isCodexProjectInstructionsPayload(payload));
222
- }
223
- export function stripGitDirectiveArtifacts(text) {
224
- if (!text)
225
- return '';
226
- const normalized = text.replace(/\r\n/g, '\n');
227
- const hadDirective = /(^|\n)\s*::git-[a-z-]+\{[^\n]*\}\s*(?=\n|$)/.test(normalized);
228
- if (!hadDirective)
229
- return normalized;
230
- const stripped = normalized.replace(GIT_DIRECTIVE_LINE_RE, '');
231
- if (!stripped.trim())
232
- return '';
233
- return stripped.replace(/[ \t]+\n/g, '\n').replace(/\n+$/g, '');
234
- }
235
- export function extractPayloadText(payload) {
236
- if (!payload)
237
- return '';
238
- const parsedUser = parseUserMessagePayload(payload);
239
- if (parsedUser) {
240
- return stripAttachmentRefs(parsedUser.content, parsedUser.attachments);
241
- }
242
- const parsed = parseStructuredMessagePayload(payload);
243
- if (parsed) {
244
- if (typeof parsed.content === 'string')
245
- return stripGitDirectiveArtifacts(parsed.content);
246
- if ('text' in parsed && typeof parsed.text === 'string')
247
- return stripGitDirectiveArtifacts(parsed.text);
248
- }
249
- try {
250
- const parsedJson = JSON.parse(payload);
251
- if (typeof parsedJson === 'string')
252
- return parsedJson;
253
- if (typeof parsedJson === 'object' && parsedJson !== null) {
254
- const record = parsedJson;
255
- if (typeof record.content === 'string')
256
- return stripGitDirectiveArtifacts(record.content);
257
- if (typeof record.text === 'string')
258
- return stripGitDirectiveArtifacts(record.text);
259
- }
260
- }
261
- catch {
262
- // fall through
263
- }
264
- return stripGitDirectiveArtifacts(payload);
265
- }
266
- /**
267
- * Converts already-readable text into the only form allowed in the replicated
268
- * personal-session index. A preview is content, not an opaque transport field:
269
- * private control context and binary payloads are therefore rejected instead
270
- * of being truncated into something that still leaks them.
271
- */
272
- export function sanitizeSessionPreview(value, maxLength = 160) {
273
- if (typeof value !== 'string' || !Number.isSafeInteger(maxLength) || maxLength < 1)
274
- return null;
275
- const normalized = value.replace(/\r\n/g, '\n').trim();
276
- if (!normalized)
277
- return null;
278
- if (PREVIEW_PRIVATE_CONTEXT_RE.test(normalized) ||
279
- PREVIEW_DATA_URL_RE.test(normalized) ||
280
- PREVIEW_BASE64_BLOB_RE.test(normalized) ||
281
- parseObjectPayload(normalized))
282
- return null;
283
- const oneLine = normalized.replace(/\s+/g, ' ');
284
- return oneLine.length > maxLength ? `${oneLine.slice(0, maxLength)}…` : oneLine;
285
- }
286
- /** Extracts a safe, bounded preview from an envelope payload. */
287
- export function sessionPreviewFromPayload(payload, maxLength = 160) {
288
- if (!payload || isToolPayload(payload) || isSystemControlPayload(payload))
289
- return null;
290
- if (isApprovalPendingPayload(payload))
291
- return sanitizeSessionPreview('需要用户确认', maxLength);
292
- const structured = parseStructuredMessagePayload(payload);
293
- if (structured) {
294
- const type = typeof structured.type === 'string' ? structured.type.toLowerCase() : '';
295
- if (!type || PREVIEW_HIDDEN_TYPES.has(type))
296
- return null;
297
- return sanitizeSessionPreview(extractPayloadText(payload), maxLength);
298
- }
299
- // JSON objects that are not a known structured message can contain raw tool
300
- // arguments/results. Never guess which property is safe for an index preview.
301
- if (parseObjectPayload(payload))
302
- return null;
303
- return sanitizeSessionPreview(extractPayloadText(payload), maxLength);
304
- }
305
- function stringOrUndefined(value) {
306
- return typeof value === 'string' && value.trim() ? value : undefined;
307
- }
1
+ const E=/^\s*::git-[a-z-]+\{[^\n]*\}\s*$/gm,g=/^\s*\{\s*"v"\s*:\s*1\s*,\s*"type"\s*:\s*"(tool|tool_use|tool_result)"/,R=/^\s*<environment_context>\s*[^]*?<\/environment_context>\s*$/i,x=/<(cwd|shell|current_date|timezone)>[^<]*<\/\1>/gi,h=/^\s*<recommended_plugins>[^]*?<\/recommended_plugins>\s*/i,T=/^\s*<turn_aborted>[^]*?<\/turn_aborted>\s*$/i,P=/^\s*<codex_internal_context\b[^>]*>[^]*?<\/codex_internal_context>\s*$/i,b=/^\s*# AGENTS\.md instructions for [^\n]+\n+\s*<INSTRUCTIONS>\s*[^]*?<\/INSTRUCTIONS>\s*(?:<environment_context>[^]*?<\/environment_context>)?\s*$/i,N=/^\s*\{\s*"v"\s*:\s*1\s*,\s*"type"\s*:\s*"approval_pending"/,A=/(?:<\/?(?:environment_context|instructions|system|developer|codex_internal_context|recommended_plugins)\b|#\s*AGENTS\.md instructions\b)/i,I=/\bdata:[a-z0-9.+-]+\/[a-z0-9.+-]+;base64,[a-z0-9+/=\s]+/i,S=/(?:^|\s)(?=[A-Za-z0-9+/]{80,}={0,2}(?=\s|$))(?=[A-Za-z0-9+/]*[A-Z])(?=[A-Za-z0-9+/]*[a-z])(?=[A-Za-z0-9+/]*[0-9])[A-Za-z0-9+/]{80,}={0,2}(?=\s|$)/,v=new Set(["tool","tool_use","tool_result","thinking","system","developer","context","environment_context","channel_delivery_status"]);function C(e){return e.replace(/[[\]\\]/g,"\\$&")}function O(e){const t=C(e.name);return e.kind==="image"?`![${t}](<${e.path}>)`:`[${t}](<${e.path}>)`}function D(e,t){if(!t?.length)return e;const n=new Set(t.map(O));return e.split(`
2
+ `).filter(s=>!n.has(s.trim())).join(`
3
+ `).replace(/\n{3,}/g,`
4
+
5
+ `).trim()}function u(e){if(!e||e[0]!=="{")return null;try{const t=JSON.parse(e);if(typeof t=="object"&&t!==null)return t}catch{}return null}function z(e){if(typeof e!="object"||e===null)return null;const t=e,n=typeof t.path=="string"?t.path:"",r=typeof t.name=="string"?t.name:"",s=typeof t.mimeType=="string"?t.mimeType:"",l=t.kind==="image"||t.kind==="file"||t.kind==="folder"?t.kind:null;if(!n||!r||!s||!l)return null;const f=typeof t.previewData=="string"&&t.previewData.trim()?t.previewData.trim():void 0,p=typeof t.byteSize=="number"&&Number.isSafeInteger(t.byteSize)&&t.byteSize>=0?t.byteSize:void 0,d=typeof t.sha256=="string"&&/^[a-f0-9]{64}$/i.test(t.sha256)?t.sha256.toLowerCase():void 0;return{path:n,name:r,mimeType:s,kind:l,...p!==void 0?{byteSize:p}:{},...d?{sha256:d}:{},...f?{previewData:f}:{}}}function o(e){const t=u(e);if(!t||t.v!==1)return null;if(t.type==="user"&&typeof t.content=="string"){const n=Array.isArray(t.attachments)?t.attachments.map(z).filter(r=>r!=null):void 0;return{v:1,type:"user",content:t.content,...n?.length?{attachments:n}:{}}}return t}function w(e){const t=o(e);return t?.type==="user"?t:null}function L(e,t){return t?.length?JSON.stringify({v:1,type:"user",content:e,attachments:t}):e}function $(e){if(g.test(e))return!0;const t=o(e);return!t||typeof t!="object"?!1:t.type==="tool"||t.type==="tool_use"||t.type==="tool_result"}function V(e){return N.test(e)?!0:o(e)?.type==="approval_pending"}function M(e){return U(e)?.agentVisible===!1}function U(e){const t=o(e);if(!t||t.type!=="channel_delivery_status")return null;const n=t;if(n.v!==1||n.channel!=="wechat"||n.agentVisible!==!1)return null;const r=typeof n.status=="string"&&n.status.trim()?n.status.trim():"";if(!r)return null;const s=typeof n.content=="string"&&n.content.trim()?n.content:r==="manual_review"?"\u53D1\u9001\u72B6\u6001\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u68C0\u67E5\u5FAE\u4FE1":"\u672A\u80FD\u81EA\u52A8\u53D1\u9001\u5230\u5FAE\u4FE1";return{v:1,type:"channel_delivery_status",channel:"wechat",status:r,agentVisible:!1,content:s,replyId:i(n.replyId),idempotencyKey:i(n.idempotencyKey),bindingId:i(n.bindingId),reasonCode:i(n.reasonCode),copyText:i(n.copyText),copyableContentRef:i(n.copyableContentRef),errorSummary:i(n.errorSummary)}}function j(e){return JSON.stringify({v:1,type:"approval_pending",title:e?.title?.trim()||"\u9700\u8981\u7528\u6237\u786E\u8BA4",content:e?.content?.trim()||"Codex \u6B63\u5728\u7B49\u5F85\u7528\u6237\u786E\u8BA4\u540E\u7EE7\u7EED\u3002",source:e?.source?.trim()||"codex",actionHint:e?.permission?e?.actionHint?.trim():e?.actionHint?.trim()||"\u5F53\u524D\u795E\u5FF5\u6682\u4E0D\u652F\u6301\u8FDC\u7A0B\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230\u8FD0\u884C Codex \u7684\u7535\u8111/\u7EC8\u7AEF\u5B8C\u6210\u786E\u8BA4\u3002",...e?.permission?{permission:e.permission}:{}})}function _(e){if(!R.test(e))return!1;const t=new Set;for(const n of e.matchAll(x))n[1]&&t.add(n[1].toLowerCase());return t.has("current_date")&&t.has("timezone")&&e.includes("<workspace_roots>")?!0:t.has("cwd")&&t.has("shell")&&t.has("current_date")&&t.has("timezone")}function X(e){return T.test(e)}function m(e){return b.test(e)}function k(e){const t=e.match(h);if(t){const n=e.slice(t[0].length).trim();return!n||_(n)||m(n)}return _(e)||X(e)||P.test(e)||m(e)}function c(e){if(!e)return"";const t=e.replace(/\r\n/g,`
6
+ `);if(!/(^|\n)\s*::git-[a-z-]+\{[^\n]*\}\s*(?=\n|$)/.test(t))return t;const r=t.replace(E,"");return r.trim()?r.replace(/[ \t]+\n/g,`
7
+ `).replace(/\n+$/g,""):""}function y(e){if(!e)return"";const t=w(e);if(t)return D(t.content,t.attachments);const n=o(e);if(n){if(typeof n.content=="string")return c(n.content);if("text"in n&&typeof n.text=="string")return c(n.text)}try{const r=JSON.parse(e);if(typeof r=="string")return r;if(typeof r=="object"&&r!==null){const s=r;if(typeof s.content=="string")return c(s.content);if(typeof s.text=="string")return c(s.text)}}catch{}return c(e)}function a(e,t=160){if(typeof e!="string"||!Number.isSafeInteger(t)||t<1)return null;const n=e.replace(/\r\n/g,`
8
+ `).trim();if(!n||A.test(n)||I.test(n)||S.test(n)||u(n))return null;const r=n.replace(/\s+/g," ");return r.length>t?`${r.slice(0,t)}\u2026`:r}function G(e,t=160){if(!e||$(e)||k(e))return null;if(V(e))return a("\u9700\u8981\u7528\u6237\u786E\u8BA4",t);const n=o(e);if(n){const r=typeof n.type=="string"?n.type.toLowerCase():"";return!r||v.has(r)?null:a(y(e),t)}return u(e)?null:a(y(e),t)}function i(e){return typeof e=="string"&&e.trim()?e:void 0}export{j as buildApprovalPendingPayload,L as buildUserMessagePayload,y as extractPayloadText,M as isAgentHiddenPayload,V as isApprovalPendingPayload,m as isCodexProjectInstructionsPayload,X as isCodexTurnAbortedPayload,k as isSystemControlPayload,_ as isSystemEnvironmentContextPayload,$ as isToolPayload,U as parseChannelDeliveryStatusPayload,o as parseStructuredMessagePayload,w as parseUserMessagePayload,a as sanitizeSessionPreview,G as sessionPreviewFromPayload,c as stripGitDirectiveArtifacts};
@@ -1,3 +1 @@
1
- // @arch docs/features/desktop-project-files-opaque-protocol.md
2
- // @test src/__tests__/project-fs.test.ts
3
- export {};
1
+
@@ -1 +1 @@
1
- export {};
1
+