@zhushanwen/pi-subagent-workflow 8.5.0 → 8.7.0

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 (336) hide show
  1. package/package.json +13 -16
  2. package/relay/relay.mjs +1 -1
  3. package/src/host/__tests__/pi-host.test.ts +214 -0
  4. package/src/host/pi-host.ts +109 -0
  5. package/src/index.ts +142 -32
  6. package/src/injectors/__tests__/engine-awareness.test.ts +292 -0
  7. package/src/injectors/__tests__/engine-section-stability.test.ts +341 -0
  8. package/src/injectors/__tests__/subagent-list-injector.test.ts +5 -5
  9. package/src/injectors/__tests__/workflow-list-injector.test.ts +5 -5
  10. package/src/injectors/engine-awareness.ts +123 -0
  11. package/src/injectors/model-list-injector.ts +1 -1
  12. package/src/injectors/subagent-list-injector.ts +8 -8
  13. package/src/injectors/workflow-list-injector.ts +8 -8
  14. package/src/interface/__tests__/detectors.test.ts +3 -3
  15. package/src/interface/__tests__/subagent-tool-path-guard.test.ts +157 -0
  16. package/src/interface/__tests__/subagent-tool-prompt.test.ts +12 -0
  17. package/src/interface/__tests__/tool-workflow-script-generate.test.ts +2 -2
  18. package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +1 -1
  19. package/src/interface/bg-notify-render.ts +34 -13
  20. package/src/interface/commands.ts +3 -3
  21. package/src/interface/format.ts +2 -2
  22. package/src/interface/helpers.ts +3 -3
  23. package/src/interface/list-component.ts +4 -4
  24. package/src/interface/list-shared.ts +2 -2
  25. package/src/interface/list-view.ts +2 -2
  26. package/src/interface/subagent-actions.ts +288 -19
  27. package/src/interface/subagent-tool-schema.ts +163 -0
  28. package/src/interface/subagent-tool.ts +65 -129
  29. package/src/interface/subagents.ts +5 -5
  30. package/src/interface/tool-render.ts +34 -2
  31. package/src/interface/tool-workflow-script.ts +4 -4
  32. package/src/interface/tool-workflow.ts +6 -6
  33. package/src/interface/views/WorkflowsView.ts +5 -5
  34. package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +3 -3
  35. package/src/interface/views/__tests__/detail-content-session-file.test.ts +2 -2
  36. package/src/interface/views/detail-content.ts +4 -4
  37. package/src/interface/views/format.ts +4 -4
  38. package/src/{orchestration/jsonl-run-store.ts → jsonl-run-store.ts} +132 -18
  39. package/src/execution/__tests__/__fixtures__/notifier-golden-snapshots.json +0 -53
  40. package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +0 -1
  41. package/src/execution/__tests__/agent-registry.test.ts +0 -363
  42. package/src/execution/__tests__/agent-result-mapper.test.ts +0 -150
  43. package/src/execution/__tests__/alive-store.test.ts +0 -147
  44. package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
  45. package/src/execution/__tests__/before-agent-start-injection.test.ts +0 -132
  46. package/src/execution/__tests__/bg-notify-render.test.ts +0 -256
  47. package/src/execution/__tests__/channel-registry-handshake.test.ts +0 -243
  48. package/src/execution/__tests__/chat-engine-routing.test.ts +0 -597
  49. package/src/execution/__tests__/chatmode-first-round-closure-service.test.ts +0 -365
  50. package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -190
  51. package/src/execution/__tests__/chatmode-round-notify-real-chain.test.ts +0 -215
  52. package/src/execution/__tests__/concurrency-pool.test.ts +0 -250
  53. package/src/execution/__tests__/config.test.ts +0 -110
  54. package/src/execution/__tests__/conversation-wiring.test.ts +0 -198
  55. package/src/execution/__tests__/crash-recovery.test.ts +0 -320
  56. package/src/execution/__tests__/delivery-methods.test.ts +0 -385
  57. package/src/execution/__tests__/dialog-queue.test.ts +0 -299
  58. package/src/execution/__tests__/epipe-fallback.test.ts +0 -241
  59. package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -243
  60. package/src/execution/__tests__/execute-nesting.test.ts +0 -323
  61. package/src/execution/__tests__/execute-options-mapper.test.ts +0 -189
  62. package/src/execution/__tests__/execution-record.test.ts +0 -1284
  63. package/src/execution/__tests__/finalize-record.test.ts +0 -368
  64. package/src/execution/__tests__/finalized-marker.test.ts +0 -82
  65. package/src/execution/__tests__/format-schema-instruction.test.ts +0 -138
  66. package/src/execution/__tests__/format.test.ts +0 -458
  67. package/src/execution/__tests__/gc-timer.test.ts +0 -184
  68. package/src/execution/__tests__/get-record-for-action-restart.test.ts +0 -254
  69. package/src/execution/__tests__/gui-mode-dispatch.test.ts +0 -59
  70. package/src/execution/__tests__/helpers/mock-extension-api.ts +0 -30
  71. package/src/execution/__tests__/helpers/spawn-mock.ts +0 -238
  72. package/src/execution/__tests__/host-mode.test.ts +0 -87
  73. package/src/execution/__tests__/index-session-start-identity.test.ts +0 -371
  74. package/src/execution/__tests__/index-session-start.test.ts +0 -593
  75. package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
  76. package/src/execution/__tests__/lifecycle-manager.test.ts +0 -337
  77. package/src/execution/__tests__/lifecycle-predicates.test.ts +0 -116
  78. package/src/execution/__tests__/list-component.test.ts +0 -401
  79. package/src/execution/__tests__/list-fields.test.ts +0 -109
  80. package/src/execution/__tests__/manifest-parentid.test.ts +0 -117
  81. package/src/execution/__tests__/model-resolver.test.ts +0 -413
  82. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +0 -287
  83. package/src/execution/__tests__/nested-visibility.test.ts +0 -325
  84. package/src/execution/__tests__/notifier-flush.test.ts +0 -574
  85. package/src/execution/__tests__/notifier-golden-snapshot.test.ts +0 -261
  86. package/src/execution/__tests__/one-shot-upgrade.test.ts +0 -205
  87. package/src/execution/__tests__/output-collector.test.ts +0 -61
  88. package/src/execution/__tests__/parent-child-matrix.test.ts +0 -336
  89. package/src/execution/__tests__/path-encoding.test.ts +0 -104
  90. package/src/execution/__tests__/pi-invocation.test.ts +0 -134
  91. package/src/execution/__tests__/record-store.test.ts +0 -1057
  92. package/src/execution/__tests__/records-cwd-isolation.test.ts +0 -91
  93. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +0 -339
  94. package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -273
  95. package/src/execution/__tests__/relay-agent.test.ts +0 -448
  96. package/src/execution/__tests__/relay-env.test.ts +0 -42
  97. package/src/execution/__tests__/resource-policy.test.ts +0 -109
  98. package/src/execution/__tests__/rpc-mode.test.ts +0 -89
  99. package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -267
  100. package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -253
  101. package/src/execution/__tests__/run-spawn-edges.test.ts +0 -644
  102. package/src/execution/__tests__/run-spawn-integration.test.ts +0 -933
  103. package/src/execution/__tests__/run-spawn-resume.test.ts +0 -322
  104. package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +0 -196
  105. package/src/execution/__tests__/sdk-contract.test.ts +0 -273
  106. package/src/execution/__tests__/session-context-resolver.test.ts +0 -167
  107. package/src/execution/__tests__/session-file-gc.test.ts +0 -293
  108. package/src/execution/__tests__/session-pending.test.ts +0 -197
  109. package/src/execution/__tests__/session-reconstructor.test.ts +0 -379
  110. package/src/execution/__tests__/session-runner-epipe.test.ts +0 -178
  111. package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -311
  112. package/src/execution/__tests__/session-start-reaper.test.ts +0 -233
  113. package/src/execution/__tests__/spawn-args.test.ts +0 -434
  114. package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -189
  115. package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
  116. package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -207
  117. package/src/execution/__tests__/spawned-children.test.ts +0 -92
  118. package/src/execution/__tests__/startup-config-declaration.test.ts +0 -35
  119. package/src/execution/__tests__/status-refactor.test.ts +0 -345
  120. package/src/execution/__tests__/stdin-writer.test.ts +0 -463
  121. package/src/execution/__tests__/stream-sink-retirement.test.ts +0 -261
  122. package/src/execution/__tests__/subagent-service-abort.test.ts +0 -60
  123. package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -629
  124. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +0 -180
  125. package/src/execution/__tests__/subagent-service.test.ts +0 -788
  126. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -310
  127. package/src/execution/__tests__/subprocess-agent-runner.test.ts +0 -506
  128. package/src/execution/__tests__/temp-prompt.test.ts +0 -53
  129. package/src/execution/__tests__/timeout-integration.test.ts +0 -397
  130. package/src/execution/__tests__/tombstone-store.test.ts +0 -73
  131. package/src/execution/__tests__/tool-action.test.ts +0 -385
  132. package/src/execution/__tests__/truncline-snapshot.test.ts +0 -81
  133. package/src/execution/__tests__/turn-limiter-semantics.test.ts +0 -194
  134. package/src/execution/__tests__/turn-limiter.test.ts +0 -65
  135. package/src/execution/__tests__/ui-channels.test.ts +0 -187
  136. package/src/execution/__tests__/ui-interaction-model.test.ts +0 -67
  137. package/src/execution/__tests__/ui-request-handler-factory.test.ts +0 -370
  138. package/src/execution/__tests__/ui-request-handler.test.ts +0 -204
  139. package/src/execution/__tests__/ui-request-observability.test.ts +0 -114
  140. package/src/execution/__tests__/ui-request-queue.test.ts +0 -133
  141. package/src/execution/__tests__/worktree-manager.test.ts +0 -633
  142. package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -229
  143. package/src/execution/__tests__/worktree-reconcile.integration.test.ts +0 -181
  144. package/src/execution/__tests__/worktree-registry.test.ts +0 -199
  145. package/src/execution/agent-registry.ts +0 -193
  146. package/src/execution/agent-result-mapper.ts +0 -90
  147. package/src/execution/alive-store.ts +0 -92
  148. package/src/execution/argv-mirror.ts +0 -109
  149. package/src/execution/best-effort.ts +0 -38
  150. package/src/execution/channel-registry-access.ts +0 -144
  151. package/src/execution/concurrency-pool.ts +0 -116
  152. package/src/execution/config.ts +0 -96
  153. package/src/execution/dialog-queue.ts +0 -330
  154. package/src/execution/engine/__tests__/common/data-dir.test.ts +0 -53
  155. package/src/execution/engine/__tests__/common/errors.test.ts +0 -132
  156. package/src/execution/engine/__tests__/common/event-journal.test.ts +0 -177
  157. package/src/execution/engine/__tests__/common/kill-chain.test.ts +0 -192
  158. package/src/execution/engine/__tests__/common/nesting-guard.test.ts +0 -81
  159. package/src/execution/engine/__tests__/common/persona-router.test.ts +0 -123
  160. package/src/execution/engine/__tests__/common/pool-manager.test.ts +0 -154
  161. package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
  162. package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
  163. package/src/execution/engine/__tests__/conformance/agent-event-invariants.ts +0 -141
  164. package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +0 -109
  165. package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +0 -101
  166. package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +0 -77
  167. package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +0 -104
  168. package/src/execution/engine/__tests__/conformance/contract.relay.test.ts +0 -342
  169. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +0 -201
  170. package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +0 -76
  171. package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +0 -79
  172. package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -87
  173. package/src/execution/engine/__tests__/engines-declaration.test.ts +0 -36
  174. package/src/execution/engine/__tests__/model-prompt.test.ts +0 -85
  175. package/src/execution/engine/__tests__/paths.test.ts +0 -39
  176. package/src/execution/engine/__tests__/registry.test.ts +0 -120
  177. package/src/execution/engine/__tests__/routing.test.ts +0 -231
  178. package/src/execution/engine/common/data-dir.ts +0 -62
  179. package/src/execution/engine/common/errors.ts +0 -183
  180. package/src/execution/engine/common/event-journal.ts +0 -254
  181. package/src/execution/engine/common/journal-replay.ts +0 -62
  182. package/src/execution/engine/common/kill-chain.ts +0 -221
  183. package/src/execution/engine/common/nesting-guard.ts +0 -50
  184. package/src/execution/engine/common/persona-router.ts +0 -108
  185. package/src/execution/engine/common/pool-manager.ts +0 -226
  186. package/src/execution/engine/common/schema-emulation.ts +0 -189
  187. package/src/execution/engine/common/session-view-projection.ts +0 -51
  188. package/src/execution/engine/engine-discovery.ts +0 -65
  189. package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -469
  190. package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
  191. package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
  192. package/src/execution/engine/engines/pi/pi-engine.ts +0 -415
  193. package/src/execution/engine/engines/pi/reader.ts +0 -48
  194. package/src/execution/engine/engines/pi/registration.ts +0 -35
  195. package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
  196. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
  197. package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
  198. package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -246
  199. package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -228
  200. package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
  201. package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -64
  202. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -127
  203. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -567
  204. package/src/execution/engine/engines/zcode/constants.ts +0 -43
  205. package/src/execution/engine/engines/zcode/golden-sample.ts +0 -39
  206. package/src/execution/engine/engines/zcode/launcher.ts +0 -161
  207. package/src/execution/engine/engines/zcode/parser.ts +0 -436
  208. package/src/execution/engine/engines/zcode/preparer.ts +0 -363
  209. package/src/execution/engine/engines/zcode/reader.ts +0 -381
  210. package/src/execution/engine/engines/zcode/registration.ts +0 -37
  211. package/src/execution/engine/engines/zcode/zcode-engine.ts +0 -648
  212. package/src/execution/engine/host-task-spec.ts +0 -47
  213. package/src/execution/engine/model-prompt.ts +0 -59
  214. package/src/execution/engine/paths.ts +0 -42
  215. package/src/execution/engine/port.ts +0 -153
  216. package/src/execution/engine/registry.ts +0 -123
  217. package/src/execution/engine/routing.ts +0 -218
  218. package/src/execution/engine/types.ts +0 -304
  219. package/src/execution/execute-options-mapper.ts +0 -111
  220. package/src/execution/execution-record.ts +0 -906
  221. package/src/execution/finalize-record.ts +0 -251
  222. package/src/execution/finalized-marker.ts +0 -51
  223. package/src/execution/get-state-handshake.ts +0 -104
  224. package/src/execution/host-mode.ts +0 -56
  225. package/src/execution/idle-gc.ts +0 -47
  226. package/src/execution/lifecycle-manager.ts +0 -491
  227. package/src/execution/lifecycle-predicates.ts +0 -65
  228. package/src/execution/manifest-store.ts +0 -256
  229. package/src/execution/model-config-service.ts +0 -204
  230. package/src/execution/model-resolver.ts +0 -276
  231. package/src/execution/notifier.ts +0 -260
  232. package/src/execution/output-collector.ts +0 -88
  233. package/src/execution/path-encoding.ts +0 -60
  234. package/src/execution/pi-invocation.ts +0 -120
  235. package/src/execution/record-entry.ts +0 -132
  236. package/src/execution/record-store.ts +0 -1234
  237. package/src/execution/relay-env.ts +0 -37
  238. package/src/execution/session-context-resolver.ts +0 -64
  239. package/src/execution/session-file-gc.ts +0 -120
  240. package/src/execution/session-pending.ts +0 -164
  241. package/src/execution/session-reconstructor.ts +0 -678
  242. package/src/execution/session-runner.ts +0 -1548
  243. package/src/execution/sessions-index.ts +0 -304
  244. package/src/execution/spawn-event-adapter.ts +0 -363
  245. package/src/execution/stdin-writer.ts +0 -198
  246. package/src/execution/stream-sink.ts +0 -126
  247. package/src/execution/subagent-service.ts +0 -2119
  248. package/src/execution/subprocess-agent-runner.ts +0 -303
  249. package/src/execution/temp-prompt.ts +0 -62
  250. package/src/execution/tombstone-store.ts +0 -72
  251. package/src/execution/turn-limiter.ts +0 -102
  252. package/src/execution/types.ts +0 -910
  253. package/src/execution/ui-channels.ts +0 -216
  254. package/src/execution/ui-interaction-model.ts +0 -48
  255. package/src/execution/ui-request-handler-factory.ts +0 -212
  256. package/src/execution/ui-request-observability.ts +0 -81
  257. package/src/execution/ui-request-queue.ts +0 -174
  258. package/src/execution/worktree-manager.ts +0 -688
  259. package/src/execution/worktree-registry.ts +0 -222
  260. package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +0 -336
  261. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +0 -208
  262. package/src/orchestration/__tests__/agent-call-stream.test.ts +0 -157
  263. package/src/orchestration/__tests__/args-validator.test.ts +0 -143
  264. package/src/orchestration/__tests__/concurrency-gate.test.ts +0 -125
  265. package/src/orchestration/__tests__/config-loader.test.ts +0 -503
  266. package/src/orchestration/__tests__/error-recovery-handlers.test.ts +0 -724
  267. package/src/orchestration/__tests__/error-recovery-postmessage-defense.test.ts +0 -405
  268. package/src/orchestration/__tests__/error-recovery-serialize-failed-result.test.ts +0 -56
  269. package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +0 -166
  270. package/src/orchestration/__tests__/execute-agent-call.test.ts +0 -314
  271. package/src/orchestration/__tests__/jsonl-run-store-loadall-sources.test.ts +0 -171
  272. package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +0 -1030
  273. package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +0 -277
  274. package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +0 -96
  275. package/src/orchestration/__tests__/lifecycle.test.ts +0 -625
  276. package/src/orchestration/__tests__/review-fix-loop-e2e.test.ts +0 -1971
  277. package/src/orchestration/__tests__/script-lint.test.ts +0 -831
  278. package/src/orchestration/__tests__/skill-discovery.test.ts +0 -157
  279. package/src/orchestration/__tests__/test-mocks.ts +0 -197
  280. package/src/orchestration/__tests__/worker-host.test.ts +0 -120
  281. package/src/orchestration/__tests__/worker-returnmeta-passthrough.test.ts +0 -164
  282. package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +0 -520
  283. package/src/orchestration/__tests__/worker-script-builder.test.ts +0 -309
  284. package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +0 -110
  285. package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +0 -317
  286. package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +0 -110
  287. package/src/orchestration/__tests__/workflows-e2e.test.ts +0 -537
  288. package/src/orchestration/agent-opts-resolver.ts +0 -93
  289. package/src/orchestration/args-validator.ts +0 -127
  290. package/src/orchestration/concurrency-gate.ts +0 -69
  291. package/src/orchestration/config-loader.ts +0 -315
  292. package/src/orchestration/error-recovery.ts +0 -862
  293. package/src/orchestration/execute-agent-call.ts +0 -217
  294. package/src/orchestration/launcher.ts +0 -410
  295. package/src/orchestration/lifecycle.ts +0 -396
  296. package/src/orchestration/models/__tests__/budget.test.ts +0 -367
  297. package/src/orchestration/models/__tests__/trace.test.ts +0 -408
  298. package/src/orchestration/models/agent-call.ts +0 -83
  299. package/src/orchestration/models/budget.ts +0 -148
  300. package/src/orchestration/models/ports.ts +0 -164
  301. package/src/orchestration/models/run-runtime.ts +0 -89
  302. package/src/orchestration/models/run-spec.ts +0 -83
  303. package/src/orchestration/models/run-state.ts +0 -44
  304. package/src/orchestration/models/trace.ts +0 -183
  305. package/src/orchestration/models/types.ts +0 -292
  306. package/src/orchestration/models/workflow-run.ts +0 -254
  307. package/src/orchestration/models/workflow-script-registry.ts +0 -35
  308. package/src/orchestration/models/workflow-script.ts +0 -117
  309. package/src/orchestration/script-lint.ts +0 -766
  310. package/src/orchestration/skill-discovery.ts +0 -92
  311. package/src/orchestration/worker-handle.ts +0 -115
  312. package/src/orchestration/worker-host.ts +0 -98
  313. package/src/orchestration/worker-script-builder.ts +0 -408
  314. package/src/orchestration/workflow-files.ts +0 -85
  315. package/src/orchestration/workflow-script-registry-impl.ts +0 -133
  316. package/src/shared/__tests__/agent-ref.test.ts +0 -34
  317. package/src/shared/__tests__/meta-parser.test.ts +0 -304
  318. package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -280
  319. package/src/shared/__tests__/resource-discovery.test.ts +0 -736
  320. package/src/shared/__tests__/resource-meta.test.ts +0 -51
  321. package/src/shared/__tests__/schema-jsonify.test.ts +0 -81
  322. package/src/shared/agent-event.ts +0 -13
  323. package/src/shared/agent-ref.ts +0 -57
  324. package/src/shared/meta-parser.ts +0 -261
  325. package/src/shared/resource-discovery.ts +0 -811
  326. package/src/shared/resource-meta.ts +0 -65
  327. package/src/shared/schema-jsonify.ts +0 -56
  328. package/src/shared/xml-injection.ts +0 -35
  329. package/workflows/README.md +0 -81
  330. package/workflows/_shared/agent-refs.cjs +0 -40
  331. package/workflows/chain.js +0 -131
  332. package/workflows/map-reduce.js +0 -174
  333. package/workflows/parallel.js +0 -148
  334. package/workflows/review-fix-loop-utils.cjs +0 -1307
  335. package/workflows/review-fix-loop.js +0 -1396
  336. package/workflows/scatter-gather.js +0 -178
@@ -1,506 +0,0 @@
1
- // src/execution/__tests__/subprocess-agent-runner.test.ts
2
- //
3
- // Wave 4: SubprocessAgentRunner 委托重写测试
4
- //
5
- // 覆盖 test-matrix 用例:
6
- // T3.1 (正常): SAR 委托 executeAndAwait 返回 content
7
- // T3.2 (正常): parsedOutput 透传
8
- // T3.4 (边界): cwd 透传(非 git worktree)
9
- // T3.5 (边界): model 填底(opts.model 空 → ctxModel)
10
- // T3.6 (异常): timeoutMs 超时 → signal abort → error
11
- // T3.7 (正常): onEvent 桥接 AgentEvent 透传
12
- // T3.17 (NFR): mergeTimeoutSignal listener 清理
13
- // T3.18 (NFR): dispose 兜底覆盖(delegate 后子进程进 spawnedChildren)
14
- // T3.19 (NFR): AgentCallOpts→ExecuteOptions 映射保真
15
-
16
- import { mkdtempSync, readdirSync, rmSync } from "node:fs";
17
- import { tmpdir } from "node:os";
18
- import { join } from "node:path";
19
-
20
- import { describe, expect, it, vi } from "vitest";
21
-
22
- import type { AgentCallOpts, AgentResult } from "../../orchestration/models/types.ts";
23
- import { replayJournal } from "../engine/common/event-journal.ts";
24
- import type { SubprocessAgentRunnerDeps } from "../subprocess-agent-runner.ts";
25
- import { SubprocessAgentRunner } from "../subprocess-agent-runner.ts";
26
-
27
- // ── 测试辅助 ──
28
-
29
- /** 构造 mock SubagentService.executeAndAwait 返回值 */
30
- function makeMockResult(overrides: Partial<AgentResult> = {}): AgentResult {
31
- return {
32
- content: "OK",
33
- parsedOutput: undefined,
34
- durationMs: 100,
35
- error: undefined,
36
- sessionId: undefined,
37
- toolCalls: [],
38
- ...overrides,
39
- };
40
- }
41
-
42
- /** 创建 mock SubagentService(只实现 executeAndAwait) */
43
- function createMockService(impl?: typeof vi.fn) {
44
- const executeAndAwait = impl ?? vi.fn().mockResolvedValue(makeMockResult());
45
- return { executeAndAwait } as unknown as {
46
- executeAndAwait: (
47
- opts: Record<string, unknown>,
48
- signal?: AbortSignal,
49
- onEvent?: (e: Record<string, unknown>) => void,
50
- stream?: unknown,
51
- ) => Promise<AgentResult>;
52
- };
53
- }
54
-
55
- function makeBaseOpts(): AgentCallOpts {
56
- return {
57
- prompt: "test task",
58
- agent: "worker",
59
- cwd: "/some/path",
60
- schema: undefined,
61
- model: undefined,
62
- scene: undefined,
63
- description: undefined,
64
- timeoutMs: undefined,
65
- skill: undefined,
66
- skillPath: undefined,
67
- appendSystemPrompt: undefined,
68
- schemaEnv: undefined,
69
- };
70
- }
71
-
72
- // ── T3.1: 正常路径 ──
73
-
74
- describe("SubprocessAgentRunner (wave-4 delegate)", () => {
75
- // ────────────────────────────────────────────────
76
- // T3.1: 正常路径 — SAR 委托 executeAndAwait 返回 content
77
- // ────────────────────────────────────────────────
78
- describe("T3.1 主流程", () => {
79
- it("委托 executeAndAwait 并返回 content", async () => {
80
- const mockService = createMockService(
81
- vi.fn().mockResolvedValue(makeMockResult({ content: "hello world" })),
82
- );
83
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
84
- const sar = new SubprocessAgentRunner(deps);
85
-
86
- const opts = makeBaseOpts();
87
- const signal = new AbortController().signal;
88
-
89
- const result = await sar.run(opts, signal);
90
-
91
- expect(result.content).toBe("hello world");
92
- expect(mockService.executeAndAwait).toHaveBeenCalledTimes(1);
93
- });
94
-
95
- it("不 reject — 失败信息入 result.error", async () => {
96
- const mockService = createMockService(
97
- vi.fn().mockResolvedValue(makeMockResult({ error: "some error" })),
98
- );
99
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
100
- const sar = new SubprocessAgentRunner(deps);
101
-
102
- const result = await sar.run(makeBaseOpts(), new AbortController().signal);
103
- expect(result.error).toBe("some error");
104
- });
105
- });
106
-
107
- // ────────────────────────────────────────────────
108
- // T3.2: parsedOutput 透传
109
- // ────────────────────────────────────────────────
110
- describe("T3.2 parsedOutput 透传", () => {
111
- it("parsedOutput 直通", async () => {
112
- const parsedData = { x: 1, y: 2 };
113
- const mockService = createMockService(
114
- vi.fn().mockResolvedValue(makeMockResult({ content: "ok", parsedOutput: parsedData })),
115
- );
116
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
117
- const sar = new SubprocessAgentRunner(deps);
118
-
119
- const result = await sar.run(makeBaseOpts(), new AbortController().signal);
120
- expect(result.parsedOutput).toEqual(parsedData);
121
- });
122
- });
123
-
124
- // ────────────────────────────────────────────────
125
- // T3.4: cwd 透传
126
- // ────────────────────────────────────────────────
127
- describe("T3.4 cwd 透传", () => {
128
- it("cwd 传入 executeAndAwait 的 ExecuteOptions", async () => {
129
- let capturedOpts: Record<string, unknown> | undefined;
130
- const mockService = createMockService(
131
- vi.fn().mockImplementation((opts: Record<string, unknown>) => {
132
- capturedOpts = opts;
133
- return Promise.resolve(makeMockResult());
134
- }),
135
- );
136
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
137
- const sar = new SubprocessAgentRunner(deps);
138
-
139
- const opts = { ...makeBaseOpts(), cwd: "/custom/cwd" };
140
- await sar.run(opts, new AbortController().signal);
141
-
142
- expect(capturedOpts).toBeDefined();
143
- expect(capturedOpts!.cwd).toBe("/custom/cwd");
144
- });
145
- });
146
-
147
- // ────────────────────────────────────────────────
148
- // T3.5: model 填底
149
- // ────────────────────────────────────────────────
150
- describe("T3.5 model 填底 (D-008)", () => {
151
- it("opts.model 优先", async () => {
152
- let capturedOpts: Record<string, unknown> | undefined;
153
- const mockService = createMockService(
154
- vi.fn().mockImplementation((opts: Record<string, unknown>) => {
155
- capturedOpts = opts;
156
- return Promise.resolve(makeMockResult());
157
- }),
158
- );
159
- const ctxModel = { id: "ctx-model", provider: "test", input: [] };
160
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService, ctxModel };
161
- const sar = new SubprocessAgentRunner(deps);
162
-
163
- const opts = { ...makeBaseOpts(), model: "explicit-model" };
164
- await sar.run(opts, new AbortController().signal);
165
-
166
- expect(capturedOpts!.model).toBe("explicit-model");
167
- });
168
-
169
- it("opts.model 空 → ctxModel", async () => {
170
- let capturedOpts: Record<string, unknown> | undefined;
171
- const mockService = createMockService(
172
- vi.fn().mockImplementation((opts: Record<string, unknown>) => {
173
- capturedOpts = opts;
174
- return Promise.resolve(makeMockResult());
175
- }),
176
- );
177
- const ctxModel = { id: "ctx-model", provider: "test", input: [] };
178
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService, ctxModel };
179
- const sar = new SubprocessAgentRunner(deps);
180
-
181
- const opts = { ...makeBaseOpts(), model: undefined };
182
- await sar.run(opts, new AbortController().signal);
183
-
184
- // 修复后:opts.model 不再从 ctxModel.id 填底,ctxModel 作为完整对象透传
185
- expect(capturedOpts!.model).toBeUndefined();
186
- expect(capturedOpts!.ctxModel).toBe(ctxModel);
187
- });
188
- });
189
-
190
- // ────────────────────────────────────────────────
191
- // H1: SAR ctxModel 刷新(model_select 后不再 stale)
192
- // ────────────────────────────────────────────────
193
- describe("H1 ctxModel refresh via updateCtxModel", () => {
194
- it("updateCtxModel 后 run() 传入新的 ctxModel 而非旧值", async () => {
195
- let capturedOpts: Record<string, unknown> | undefined;
196
- const mockService = createMockService(
197
- vi.fn().mockImplementation((opts: Record<string, unknown>) => {
198
- capturedOpts = opts;
199
- return Promise.resolve(makeMockResult());
200
- }),
201
- );
202
- const oldModel = { id: "old-model", provider: "test", input: [] };
203
- const newModel = { id: "new-model", provider: "test", input: [] };
204
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService, ctxModel: oldModel };
205
- const sar = new SubprocessAgentRunner(deps);
206
-
207
- // 模拟 model_select:刷新 ctxModel
208
- sar.updateCtxModel(newModel);
209
-
210
- const opts = { ...makeBaseOpts(), model: undefined };
211
- await sar.run(opts, new AbortController().signal);
212
-
213
- expect(capturedOpts!.ctxModel).toBe(newModel);
214
- expect(capturedOpts!.ctxModel).not.toBe(oldModel);
215
- });
216
- });
217
-
218
- // ────────────────────────────────────────────────
219
- // T3.6: timeoutMs 超时 → signal abort → error
220
- // ────────────────────────────────────────────────
221
- describe("T3.6 timeoutMs 超时", () => {
222
- it("timeoutMs > 0 → merged signal 传给 executeAndAwait", async () => {
223
- let capturedSignal: AbortSignal | undefined;
224
- const mockService = createMockService(
225
- vi.fn().mockImplementation((_opts: Record<string, unknown>, signal?: AbortSignal) => {
226
- capturedSignal = signal;
227
- return Promise.resolve(makeMockResult());
228
- }),
229
- );
230
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
231
- const sar = new SubprocessAgentRunner(deps);
232
-
233
- const opts = { ...makeBaseOpts(), timeoutMs: 5000 };
234
- await sar.run(opts, new AbortController().signal);
235
-
236
- // 有 timeoutMs 时 merged signal 不等于原始 signal
237
- expect(capturedSignal).toBeDefined();
238
- });
239
-
240
- it("timeoutMs 到期 → merged signal.aborted=true", async () => {
241
- vi.useFakeTimers();
242
- let capturedSignal: AbortSignal | undefined;
243
- const mockService = createMockService(
244
- vi.fn().mockImplementation((_opts: Record<string, unknown>, signal?: AbortSignal) => {
245
- capturedSignal = signal;
246
- return Promise.resolve(makeMockResult());
247
- }),
248
- );
249
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
250
- const sar = new SubprocessAgentRunner(deps);
251
-
252
- const opts = { ...makeBaseOpts(), timeoutMs: 50 };
253
- sar.run(opts, new AbortController().signal);
254
-
255
- // 推进 51ms 后 merged signal 应 abort
256
- vi.advanceTimersByTime(51);
257
-
258
- expect(capturedSignal?.aborted).toBe(true);
259
- vi.useRealTimers();
260
- });
261
- });
262
-
263
- // ────────────────────────────────────────────────
264
- // T3.7: onEvent 桥接
265
- // ────────────────────────────────────────────────
266
- describe("T3.7 onEvent 桥接", () => {
267
- it("executeAndAwait 的 onEvent 透传到 workflow onEvent", async () => {
268
- const mockService = createMockService(
269
- vi.fn().mockImplementation(
270
- (_opts: Record<string, unknown>, _signal?: AbortSignal, onEvent?: (e: Record<string, unknown>) => void) => {
271
- // 模拟 executeAndAwait 触发 onEvent
272
- onEvent?.({ type: "tool_start", toolName: "read", args: { path: "/a.txt" } });
273
- return Promise.resolve(makeMockResult());
274
- },
275
- ),
276
- );
277
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
278
- const sar = new SubprocessAgentRunner(deps);
279
-
280
- const workflowOnEvent = vi.fn();
281
- await sar.run(makeBaseOpts(), new AbortController().signal, workflowOnEvent);
282
-
283
- // workflow 的 onEvent 应被调用
284
- expect(workflowOnEvent).toHaveBeenCalledTimes(1);
285
- expect(workflowOnEvent).toHaveBeenCalledWith({
286
- type: "tool_start",
287
- toolName: "read",
288
- args: { path: "/a.txt" },
289
- });
290
- });
291
-
292
- it("无 workflow onEvent → 引擎仍收到包装 onEvent(P2 journal 通道恒开)", async () => {
293
- let engineOnEvent: ((e: Record<string, unknown>) => void) | undefined;
294
- const mockService = createMockService(
295
- vi.fn().mockImplementation(
296
- (_opts: Record<string, unknown>, _signal?: AbortSignal, onEvent?: (e: Record<string, unknown>) => void) => {
297
- engineOnEvent = onEvent;
298
- return Promise.resolve(makeMockResult());
299
- },
300
- ),
301
- );
302
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
303
- const sar = new SubprocessAgentRunner(deps);
304
-
305
- await sar.run(makeBaseOpts(), new AbortController().signal);
306
-
307
- // P2 接线(设计 D6 第②级):SAR 包装 onEvent 写 journal 后转发——原 onEvent
308
- // 未传时也恒传包装版(全引擎免费获得 journal;P1「undefined 透传」细节已被
309
- // 有意变更,本用例锁定新语义:引擎侧 onEvent 通道恒开)
310
- expect(typeof engineOnEvent).toBe("function");
311
- // 包装版不向外抛(journal append 是同步入队)
312
- expect(() => engineOnEvent?.({ type: "turn_end" })).not.toThrow();
313
- });
314
-
315
- it("P2 journal 接线:run 期间事件落盘 journal-<taskId>.jsonl(中立格式,可重放)", async () => {
316
- vi.useFakeTimers({ toFake: [] }); // 真实 timers:journal 写盘走真实 fs
317
- const dataDir = mkdtempSync(join(tmpdir(), "sar-journal-test-"));
318
- const prevEnv = process.env.XYZ_AGENT_DATA_DIR;
319
- process.env.XYZ_AGENT_DATA_DIR = dataDir;
320
- try {
321
- const mockService = createMockService(
322
- vi.fn().mockImplementation(
323
- (_opts: Record<string, unknown>, _signal?: AbortSignal, onEvent?: (e: Record<string, unknown>) => void) => {
324
- onEvent?.({ type: "tool_start", toolName: "bash", args: { cmd: "ls" } });
325
- onEvent?.({ type: "turn_end" });
326
- return Promise.resolve(makeMockResult());
327
- },
328
- ),
329
- );
330
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
331
- const sar = new SubprocessAgentRunner(deps);
332
-
333
- const workflowOnEvent = vi.fn();
334
- await sar.run(makeBaseOpts(), new AbortController().signal, workflowOnEvent);
335
-
336
- // journal 落在 <dataDir>/engines/pi/shared/journal-<taskId>.jsonl
337
- const journalFile = join(dataDir, "engines", "pi", "shared");
338
- const files = readdirSync(journalFile).filter((f) => f.startsWith("journal-") && f.endsWith(".jsonl"));
339
- expect(files.length).toBe(1);
340
- const replayed = replayJournal(join(journalFile, files[0] ?? ""));
341
- expect(replayed).toEqual([
342
- { type: "tool_start", toolName: "bash", args: { cmd: "ls" } },
343
- { type: "turn_end" },
344
- ]);
345
- // workflow onEvent 照常透传(journal 包装不吞事件)
346
- expect(workflowOnEvent).toHaveBeenCalledTimes(2);
347
- } finally {
348
- if (prevEnv === undefined) delete process.env.XYZ_AGENT_DATA_DIR;
349
- else process.env.XYZ_AGENT_DATA_DIR = prevEnv;
350
- rmSync(dataDir, { recursive: true, force: true });
351
- }
352
- });
353
- });
354
-
355
- // ────────────────────────────────────────────────
356
- // T3.17: mergeTimeoutSignal listener 清理
357
- // ────────────────────────────────────────────────
358
- describe("T3.17 mergeTimeoutSignal listener 清理", () => {
359
- it("外部 signal abort → timer 清理", async () => {
360
- vi.useFakeTimers();
361
- const mockService = createMockService(
362
- vi.fn().mockResolvedValue(makeMockResult()),
363
- );
364
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
365
- const sar = new SubprocessAgentRunner(deps);
366
-
367
- const ctrl = new AbortController();
368
- const opts = { ...makeBaseOpts(), timeoutMs: 5000 };
369
-
370
- // 启动 run(不 await,让它在后台)
371
- const runPromise = sar.run(opts, ctrl.signal);
372
-
373
- // 外部 abort
374
- ctrl.abort();
375
-
376
- await runPromise;
377
-
378
- // 推进时间——timer 应已清理,不会造成副作用
379
- vi.advanceTimersByTime(6000);
380
- // 无异常 = listener 已正确清理
381
- vi.useRealTimers();
382
- });
383
- });
384
-
385
- // ────────────────────────────────────────────────
386
- // T3.19: AgentCallOpts → ExecuteOptions 映射保真
387
- // ────────────────────────────────────────────────
388
- describe("T3.19 映射保真", () => {
389
- it("prompt → task, agent → agent, schemaEnv 透传", async () => {
390
- let capturedOpts: Record<string, unknown> | undefined;
391
- const mockService = createMockService(
392
- vi.fn().mockImplementation((opts: Record<string, unknown>) => {
393
- capturedOpts = opts;
394
- return Promise.resolve(makeMockResult());
395
- }),
396
- );
397
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
398
- const sar = new SubprocessAgentRunner(deps);
399
-
400
- const opts: AgentCallOpts = {
401
- ...makeBaseOpts(),
402
- prompt: "do the thing",
403
- agent: "code-reviewer",
404
- schemaEnv: '{"type":"object"}',
405
- skillPath: "/skills/code-review.md",
406
- };
407
- await sar.run(opts, new AbortController().signal);
408
-
409
- expect(capturedOpts).toBeDefined();
410
- expect(capturedOpts!.task).toBe("do the thing");
411
- expect(capturedOpts!.agent).toBe("code-reviewer");
412
- expect(capturedOpts!.skillPath).toBe("/skills/code-review.md");
413
- // schemaEnv 应通过 ExecuteOptions 透传
414
- expect((capturedOpts as Record<string, unknown>).schemaEnv).toBe('{"type":"object"}');
415
- });
416
-
417
- it("schema 透传为原始对象", async () => {
418
- let capturedOpts: Record<string, unknown> | undefined;
419
- const mockService = createMockService(
420
- vi.fn().mockImplementation((opts: Record<string, unknown>) => {
421
- capturedOpts = opts;
422
- return Promise.resolve(makeMockResult());
423
- }),
424
- );
425
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
426
- const sar = new SubprocessAgentRunner(deps);
427
-
428
- const opts = {
429
- ...makeBaseOpts(),
430
- schema: { type: "object", properties: { name: { type: "string" } } },
431
- };
432
- await sar.run(opts, new AbortController().signal);
433
-
434
- expect(capturedOpts!.schema).toEqual({
435
- type: "object",
436
- properties: { name: { type: "string" } },
437
- });
438
- });
439
- });
440
-
441
- // ────────────────────────────────────────────────
442
- // T3.18: executeAndAwait throw → catch → error
443
- // ────────────────────────────────────────────────
444
- describe("T3.18 异常处理", () => {
445
- it("executeAndAwait throw → 不 reject,返回 error", async () => {
446
- const mockService = createMockService(
447
- vi.fn().mockRejectedValue(new Error("nesting depth exceeded")),
448
- );
449
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
450
- const sar = new SubprocessAgentRunner(deps);
451
-
452
- const result = await sar.run(makeBaseOpts(), new AbortController().signal);
453
- expect(result.error).toContain("nesting depth exceeded");
454
- expect(result.content).toBe("");
455
- });
456
-
457
- it("非 Error throw → error 字段含 message", async () => {
458
- const mockService = createMockService(
459
- vi.fn().mockRejectedValue("raw string error"),
460
- );
461
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
462
- const sar = new SubprocessAgentRunner(deps);
463
-
464
- const result = await sar.run(makeBaseOpts(), new AbortController().signal);
465
- expect(result.error).toBe("raw string error");
466
- });
467
- });
468
-
469
- // ────────────────────────────────────────────────
470
- // U1: stream 透传给 executeAndAwait
471
- // ────────────────────────────────────────────────
472
- describe("U1 stream 透传", () => {
473
- it("SAR.run 传 stream → executeAndAwait 第 4 参收到同一 stream 对象", async () => {
474
- let capturedStream: unknown;
475
- const mockService = createMockService(
476
- vi.fn().mockImplementation((_opts, _sig, _onEvt, stream) => {
477
- capturedStream = stream;
478
- return Promise.resolve(makeMockResult());
479
- }),
480
- );
481
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
482
- const sar = new SubprocessAgentRunner(deps);
483
-
484
- const fakeStream = { onDelta: vi.fn(), dispose: vi.fn() };
485
- await sar.run(makeBaseOpts(), new AbortController().signal, undefined, fakeStream as never);
486
-
487
- expect(capturedStream).toBe(fakeStream);
488
- });
489
-
490
- it("SAR.run 不传 stream → executeAndAwait 第 4 参为 undefined", async () => {
491
- let capturedStream: unknown = "sentinel";
492
- const mockService = createMockService(
493
- vi.fn().mockImplementation((_opts, _sig, _onEvt, stream) => {
494
- capturedStream = stream;
495
- return Promise.resolve(makeMockResult());
496
- }),
497
- );
498
- const deps: SubprocessAgentRunnerDeps = { subagentService: mockService };
499
- const sar = new SubprocessAgentRunner(deps);
500
-
501
- await sar.run(makeBaseOpts(), new AbortController().signal);
502
-
503
- expect(capturedStream).toBeUndefined();
504
- });
505
- });
506
- });
@@ -1,53 +0,0 @@
1
- // src/__tests__/temp-prompt.test.ts
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
-
5
- import { describe, expect, it } from "vitest";
6
-
7
- import { cleanupTempPrompt, writePromptToTempFile } from "../temp-prompt.ts";
8
-
9
- describe("writePromptToTempFile", () => {
10
- it("创建临时目录 + 写入 prompt 文件", async () => {
11
- const result = await writePromptToTempFile("test-agent", "You are a helper.");
12
- expect(result.dir).toBeTruthy();
13
- expect(result.filePath).toBeTruthy();
14
- expect(fs.existsSync(result.dir)).toBe(true);
15
- expect(fs.existsSync(result.filePath)).toBe(true);
16
-
17
- const content = fs.readFileSync(result.filePath, "utf-8");
18
- expect(content).toBe("You are a helper.");
19
-
20
- // 清理
21
- await cleanupTempPrompt(result);
22
- expect(fs.existsSync(result.dir)).toBe(false);
23
- });
24
-
25
- it("agentName 非法字符替换为下划线", async () => {
26
- const result = await writePromptToTempFile("my agent/v2:spec", "prompt");
27
- expect(path.basename(result.filePath)).toBe("prompt-my_agent_v2_spec.md");
28
- await cleanupTempPrompt(result);
29
- });
30
-
31
- it("文件权限 0o600(仅 owner 读写)", async () => {
32
- const result = await writePromptToTempFile("secure", "secret prompt");
33
- const stat = fs.statSync(result.filePath);
34
- // 只取低 9 位(rwxrwxrwx),忽略文件类型位
35
- const mode = stat.mode & 0o777;
36
- expect(mode).toBe(0o600);
37
- await cleanupTempPrompt(result);
38
- });
39
-
40
- it("多字节内容(中文)正确写入", async () => {
41
- const result = await writePromptToTempFile("cn", "你是一个助手。");
42
- const content = fs.readFileSync(result.filePath, "utf-8");
43
- expect(content).toBe("你是一个助手。");
44
- await cleanupTempPrompt(result);
45
- });
46
- });
47
-
48
- describe("cleanupTempPrompt", () => {
49
- it("不存在的目录不抛错(best-effort)", async () => {
50
- const fake = { dir: "/nonexistent/path/xyz", filePath: "/nonexistent/path/xyz/p.md" };
51
- await expect(cleanupTempPrompt(fake)).resolves.not.toThrow();
52
- });
53
- });