@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,216 +0,0 @@
1
- // src/execution/ui-channels.ts
2
- //
3
- // UI channel 提取(marker 解析)+ channel 注册表。
4
- //
5
- // channel 是扩展协议自定义的业务路由标识,由 NUL 前缀 marker 标记。
6
- // 已知 marker(来自 @xyz-agent/extension-protocol):
7
- // - ASK_USER_MARKER = "\0XYZ_ASK_USER" 走 select method,出现在 title
8
- // (options[0] = JSON payload {questions, allowCancel})
9
- // - GUI_WIDGET_MARKER = "\0XYZ_GUI_WIDGET:" 走 setWidget method,出现在 widgetLines[0]
10
- // (同行 marker 后紧跟 JSON payload {component})
11
- //
12
- // channel 提取位置随 method 变(.fix-plans/00-master-summary.md §一冲突 2):
13
- // - select → 从 title 解析 NUL 前缀(payload 从 options[0] 取)
14
- // - setWidget → 从 widgetLines[0] 解析 NUL 前缀(payload 从同行 marker 后取)
15
- // - 其他 method → 无 channel(返回 {})
16
- //
17
- // channel 名规范化:去 "XYZ_" 命名空间前缀,去尾部 ":",小写化。
18
- // XYZ_ASK_USER → ask_user
19
- // XYZ_GUI_WIDGET → gui_widget
20
- //
21
- // 本模块是协议层工具(method/marker 都是协议概念),不感知业务。
22
-
23
- /** NUL 前缀字符。Pi extension-protocol 用 NUL(\0)标记控制行,
24
- * 避免与用户可见文本冲突。 */
25
- const NUL = "\0";
26
-
27
- /** channel 提取结果。channel 无 NUL 前缀、字段缺失、JSON parse 失败时
28
- * channel 与 channelPayload 均为 undefined(返回 {})。 */
29
- export interface ParsedChannel {
30
- /** 规范化后的 channel 名(如 "ask_user"、"gui_widget")。
31
- * 无 marker 或解析失败时为 undefined。 */
32
- channel?: string;
33
- /** marker 标记的结构化 payload(已 JSON.parse)。
34
- * ask_user: {questions, allowCancel};gui_widget: {component}。
35
- * payload 来源缺失或 JSON parse 失败时为 undefined(channel 仍可解析)。 */
36
- channelPayload?: unknown;
37
- }
38
-
39
- /** parseChannel 入参的最小形状。
40
- * method 是判别字段;按 method 不同,对应字段(select 的 title/options、
41
- * setWidget 的 widgetLines)可选出现。其他 method 的字段统称 [key:string]。 */
42
- export interface ExtensionUiRequestLike {
43
- method: string;
44
- /** select method:title 字段(可能含 ASK_USER_MARKER NUL 前缀)。 */
45
- title?: string;
46
- /** select method:options 数组(options[0] 可能是 channel payload 的 JSON)。 */
47
- options?: string[];
48
- /** setWidget method:widgetKey 字段。 */
49
- widgetKey?: string;
50
- /** setWidget method:widgetLines 数组(widgetLines[0] 可能含 GUI_WIDGET_MARKER)。 */
51
- widgetLines?: string[] | undefined;
52
- /** 其他 method 的任意字段(容错:允许测试和未来扩展传入额外字段)。 */
53
- [key: string]: unknown;
54
- }
55
-
56
- /** channel handler 签名:接收 UiRequest,返回 UiResponse。
57
- * 具体类型定义在 session-runner.ts(W2 工作),此处用最小形状避免循环依赖。
58
- * handler 实现方按 channel 注册,由 session-runner 按 req.channel 分派。 */
59
- export type ChannelHandler = (req: unknown) => Promise<unknown>;
60
-
61
- /** channel 注册表接口。职责单一:只管业务路由,不管排队、不管透传判定。
62
- * - register(channel, handler):注册 channel 对应的 handler(同名覆盖)
63
- * - resolve(channel):取 channel 对应的 handler,未注册返回 undefined
64
- * - list():列举所有已注册 channel 名 */
65
- export interface UiChannelRegistry {
66
- register(channel: string, handler: ChannelHandler): void;
67
- resolve(channel: string): ChannelHandler | undefined;
68
- list(): string[];
69
- }
70
-
71
- /** 规范化 channel 名。
72
- * 输入是 NUL 前缀后的字面量(如 "XYZ_ASK_USER"、"XYZ_GUI_WIDGET:")。
73
- * 规则:
74
- * 1. 去 "XYZ_" 命名空间前缀(协议命名空间标识,非业务语义)
75
- * 2. 去尾部 ":"(GUI_WIDGET 等"行内 payload"型 marker 的分隔符)
76
- * 3. 小写化(XYZ_ASK_USER → ask_user)
77
- *
78
- * 例:
79
- * "XYZ_ASK_USER" → "ask_user"
80
- * "XYZ_GUI_WIDGET:" → "gui_widget"
81
- * "FOO_BAR" → "foo_bar"(无 XYZ_ 前缀也容忍,去前缀仅当字面量以 XYZ_ 开头) */
82
- function normalizeChannelName(markerLiteral: string): string {
83
- let name = markerLiteral;
84
- // 去 "XYZ_" 命名空间前缀(仅当以此开头)
85
- if (name.startsWith("XYZ_")) {
86
- name = name.slice("XYZ_".length);
87
- }
88
- // 去尾部 ":"(行内 payload 型 marker 的分隔符)
89
- if (name.endsWith(":")) {
90
- name = name.slice(0, -1);
91
- }
92
- return name.toLowerCase();
93
- }
94
-
95
- /** 从 marker 字面量字符串解析 channel 名。
96
- * 输入 str 形如 "\0XYZ_ASK_USER"(marker 占满整个字段,payload 在别处)。
97
- * 无 NUL 前缀返回 undefined。 */
98
- function parseMarkerFromField(str: string): string | undefined {
99
- if (!str.startsWith(NUL)) return undefined;
100
- // 去掉 NUL 前缀,取剩余字面量作为 marker literal
101
- const literal = str.slice(NUL.length);
102
- if (literal === "") return undefined;
103
- return normalizeChannelName(literal);
104
- }
105
-
106
- /** 从 marker + 行内 payload 字符串解析 channel 名 + payload。
107
- * 输入 str 形如 "\0XYZ_GUI_WIDGET:{...json...}"(marker 与 payload 在同一行)。
108
- * 无 NUL 前缀返回 undefined。
109
- * payload 解析失败时不抛(返回 channel 名,payload 由调用方处理)。 */
110
- function parseInlineMarkerFromField(str: string): { channel: string } | undefined {
111
- if (!str.startsWith(NUL)) return undefined;
112
- const rest = str.slice(NUL.length);
113
- // marker literal 与 payload 的分界:第一个 ":" 或行尾
114
- // GUI_WIDGET_MARKER 格式为 "\0XYZ_GUI_WIDGET:" + json,分界是 ":"
115
- const colonIdx = rest.indexOf(":");
116
- let literal: string;
117
- if (colonIdx >= 0) {
118
- literal = rest.slice(0, colonIdx + 1); // 含 ":",normalizeChannelName 会去尾部 ":"
119
- } else {
120
- literal = rest;
121
- }
122
- if (literal === "") return undefined;
123
- return { channel: normalizeChannelName(literal) };
124
- }
125
-
126
- /** 从 select.title 解析 channel(payload 从 options[0] 取)。
127
- * - title 无 NUL 前缀 → undefined
128
- * - title 含 marker → channel 名;payload 从 options[0] JSON.parse(失败/缺失 → undefined) */
129
- function parseFromMarkerString(
130
- title: string | undefined,
131
- options: string[] | undefined,
132
- ): ParsedChannel {
133
- if (title === undefined) return {};
134
- const channel = parseMarkerFromField(title);
135
- if (channel === undefined) return {};
136
- // payload 从 options[0] 取(ask_user 协议:title 是 marker,options[0] 是 JSON payload)
137
- let payload: unknown;
138
- if (options !== undefined && options.length > 0) {
139
- try {
140
- payload = JSON.parse(options[0]);
141
- } catch {
142
- payload = undefined; // JSON parse 失败:不抛,channel 仍解析
143
- }
144
- }
145
- return { channel, channelPayload: payload };
146
- }
147
-
148
- /** 从 setWidget.widgetLines[0] 解析 channel(payload 从同行 marker 后取)。
149
- * - widgetLines 缺失/空数组/首行无 NUL 前缀 → undefined
150
- * - 首行含 marker → channel 名;payload 从 marker 后的 JSON 取(失败 → undefined) */
151
- function parseFromMarkerArray(
152
- widgetLines: string[] | undefined,
153
- ): ParsedChannel {
154
- if (widgetLines === undefined || widgetLines.length === 0) return {};
155
- const firstLine = widgetLines[0];
156
- if (typeof firstLine !== "string") return {};
157
- const parsed = parseInlineMarkerFromField(firstLine);
158
- if (parsed === undefined) return {};
159
- // payload 从 marker 后的 JSON 取(GUI_WIDGET 协议:marker 与 payload 同行)
160
- let payload: unknown;
161
- const rest = firstLine.slice(NUL.length);
162
- const colonIdx = rest.indexOf(":");
163
- if (colonIdx >= 0) {
164
- const jsonStr = rest.slice(colonIdx + 1);
165
- if (jsonStr !== "") {
166
- try {
167
- payload = JSON.parse(jsonStr);
168
- } catch {
169
- payload = undefined; // JSON parse 失败:不抛,channel 仍解析
170
- }
171
- }
172
- }
173
- return { channel: parsed.channel, channelPayload: payload };
174
- }
175
-
176
- /** 按 method 分派解析 channel。
177
- *
178
- * - select → 从 title 解析 NUL 前缀(payload 从 options[0])
179
- * - setWidget → 从 widgetLines[0] 解析 NUL 前缀(payload 从同行 marker 后)
180
- * - 其他 method → {}(无 channel 提取位置)
181
- *
182
- * 边界(均不抛错):
183
- * - title/widgetLines 字段缺失 → {}
184
- * - 无 NUL 前缀 → {}
185
- * - JSON parse 失败 → channel 仍解析,channelPayload 为 undefined
186
- *
187
- * @param req ExtensionUiRequestLike(method + 对应字段)
188
- * @returns ParsedChannel(channel/channelPayload 可选) */
189
- export function parseChannel(req: ExtensionUiRequestLike): ParsedChannel {
190
- switch (req.method) {
191
- case "select":
192
- return parseFromMarkerString(req.title, req.options);
193
- case "setWidget":
194
- return parseFromMarkerArray(req.widgetLines);
195
- default:
196
- return {};
197
- }
198
- }
199
-
200
- /** 创建 channel 注册表实例。
201
- * 进程级单例(通常由 SubagentService 持有一个实例,跨所有子进程共享)。
202
- * register 同名 channel 会覆盖旧 handler。 */
203
- export function createUiChannelRegistry(): UiChannelRegistry {
204
- const handlers = new Map<string, ChannelHandler>();
205
- return {
206
- register(channel: string, handler: ChannelHandler): void {
207
- handlers.set(channel, handler);
208
- },
209
- resolve(channel: string): ChannelHandler | undefined {
210
- return handlers.get(channel);
211
- },
212
- list(): string[] {
213
- return Array.from(handlers.keys());
214
- },
215
- };
216
- }
@@ -1,48 +0,0 @@
1
- // src/execution/ui-interaction-model.ts
2
- //
3
- // Pi ctx.ui method 的交互模型分类。
4
- //
5
- // 固化 Pi rpc-mode.ts(--mode rpc 子进程的 ctx.ui 实现)中 10 个会发
6
- // extension_ui_request 的 method 的交互模型分类,供 session-runner 决定:
7
- // - 是否透传到主进程 handler(dialog 类才透传,fire-and-forget 不透传)
8
- // - 是否进 L2 全局串行队列(dialog 类才排队,争输入焦点)
9
- //
10
- // 分类依据(.fix-plans/00-master-summary.md §一冲突 2「维度 1」):
11
- //
12
- // | 交互模型 | method | 行为 | 子进程不回会怎样 |
13
- // |---|---|---|---|
14
- // | dialog(占输入焦点,等响应) | select confirm input editor |
15
- // 子进程在 pendingExtensionRequests 注册 Promise 等 id 对应 response |
16
- // Promise 永挂 + 内存泄漏 |
17
- // | fire-and-forget(纯展示/写入,不等响应) |
18
- // notify setStatus setWidget setTitle set_editor_text | output() 完即返回 |
19
- // 无影响 |
20
- //
21
- // 未知 method 默认按 fire-and-forget 处理(保守:不透传、不排队),
22
- // 避免 Pi 未来新增 method 时误判为 dialog 导致不必要的串行。
23
-
24
- /** dialog 类 method 集合:占输入焦点、等响应、需透传 + 排队。
25
- * 与 Pi rpc-mode.ts 的 pendingExtensionRequests 注册逻辑一一对应。 */
26
- const DIALOG_METHODS: ReadonlySet<string> = new Set([
27
- "select",
28
- "confirm",
29
- "input",
30
- "editor",
31
- ]);
32
-
33
- /** 判断 method 是否为 dialog 类(占输入焦点,等响应)。
34
- *
35
- * dialog 类(select/confirm/input/editor):
36
- * - 子进程在 pendingExtensionRequests 注册 Promise 等对应 id 的 response
37
- * - 主进程必须透传 + 进 L2 全局串行队列(争输入焦点)
38
- * - 不响应会导致子进程 Promise 永挂 + 内存泄漏
39
- *
40
- * fire-and-forget 类(notify/setStatus/setWidget/setTitle/set_editor_text 及未知 method):
41
- * - 子进程 output() 完即返回,不注册 pending
42
- * - 默认不透传(TUI 下不影响输入交互),不排队
43
- *
44
- * @param method Pi rpc-types.ts 的 method 字段值
45
- * @returns dialog 类返回 true,fire-and-forget 类(含未知 method)返回 false */
46
- export function isDialogMethod(method: string): boolean {
47
- return DIALOG_METHODS.has(method);
48
- }
@@ -1,212 +0,0 @@
1
- // src/execution/ui-request-handler-factory.ts
2
- //
3
- // UI 请求 handler 工厂(透传 + 排队总控)。
4
- //
5
- // 按 ctx.mode(ExtensionMode)创建合适的 UiRequestHandler,让 SubagentService 持有后
6
- // 经 session-runner 透传给子进程的 extension_ui_request。本模块是「handler 注入链路」的
7
- // 组装点:把 channel registry(业务路由)+ dialog queue(L2 跨子进程串行)+ mode 分流
8
- //(TUI/GUI/headless)粘合成一个 handler。
9
- //
10
- // 设计依据(.fix-plans/00-master-summary.md):
11
- // - §一冲突 2「透传矩阵」:
12
- // TUI dialog 透传 + L2 排队;fire-and-forget 不透传(回 ack,不影响 TUI 输入交互)
13
- // GUI 全透传;dialog 走 L2 排队,fire-and-forget 直接转发
14
- // headless 不注入(返回 undefined)
15
- // - §一冲突 3「L2 队列接入点」:dialog 类进 dialogQueue.enqueue 串行
16
- // - §二 2.7「handler 工厂 + 透传/排队总控」:createUiRequestHandlerForMode 完整实现
17
- //
18
- // SR-3:调用方(index.ts session_start)无论 new 还是 existing SubagentService 都必须调
19
- // setUiRequestHandler——/resume /fork 复用 existingService 时旧 handler 可能已失效。
20
-
21
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
22
- import { getLogger } from "@zhushanwen/pi-extension-logger";
23
-
24
- import { DialogGlobalQueue, type UiRequest, type UiRequestHandler, type UiResponse } from "./dialog-queue.ts";
25
- import { type HostMode, resolveHostMode } from "./host-mode.ts";
26
- import type { UiChannelRegistry } from "./ui-channels.ts";
27
- import { isDialogMethod } from "./ui-interaction-model.ts";
28
-
29
- const logger = getLogger("subagents");
30
-
31
- /** 按 ctx.mode 创建 UI 请求 handler(透传 + 排队总控)。
32
- *
33
- * 透传矩阵(§一冲突 2):
34
- * - headless(json/print/undefined):返回 undefined(不注入任何 UI handler)
35
- * - TUI:dialog 透传 + L2 排队;fire-and-forget 回 ack 不透传(不影响 TUI 输入交互)
36
- * - GUI(rpc):全透传;dialog 走 L2 排队,fire-and-forget 直接转发
37
- *
38
- * 业务路由(§一冲突 2 维度 2):
39
- * - channel 命中 registry(ask_user/gui_widget)→ 走注册的 channel handler
40
- * - 无 channel 的 dialog → defaultDialogForward(调主 agent ctx.ui.select/confirm/...)
41
- *
42
- * SR-3:调用方(index.ts session_start)无论 new 还是 existing SubagentService 都必须调
43
- * setUiRequestHandler。headless 下本函数返回 undefined,调用方应据此走不注入路径。
44
- *
45
- * @param ctx Pi ExtensionContext(读 ctx.mode 分流)
46
- * @param registry channel 注册表(业务路由;W3 当前为空,ask-user 扩展 Stage 4a 注册)
47
- * @param dialogQueue L2 跨子进程全局 dialog 串行队列
48
- * @returns UiRequestHandler(tui/gui);headless 返回 undefined */
49
- export function createUiRequestHandlerForMode(
50
- ctx: ExtensionContext,
51
- registry: UiChannelRegistry,
52
- dialogQueue: DialogGlobalQueue,
53
- ): UiRequestHandler | undefined {
54
- const hostMode = resolveHostMode(ctx.mode);
55
- if (hostMode === "headless") return undefined;
56
-
57
- const realHandler = createRealHandler(ctx, hostMode, registry);
58
-
59
- return async (req: UiRequest): Promise<UiResponse> => {
60
- // 维度 1:TUI 下 fire-and-forget 不透传(回 ack,不写 stdin——由 session-runner respond 处理)
61
- if (hostMode === "tui" && !isDialogMethod(req.method)) {
62
- return { ack: true };
63
- }
64
- // L2 全局队列:dialog 类必须串行(争输入焦点)。fire-and-forget(GUI 下)直接转发。
65
- // [SR-4] 透传 req._childPid(session-runner 从 child.pid 填入)给 enqueue——
66
- // L2 据此关联 child close 时的 rejectChildDialogs 批量 reject(防全局死锁)。
67
- if (isDialogMethod(req.method)) {
68
- return dialogQueue.enqueue(req, realHandler, {
69
- child: req._childPid !== undefined ? { pid: req._childPid } : undefined,
70
- });
71
- }
72
- // GUI 下 fire-and-forget 直接转发
73
- return realHandler(req);
74
- };
75
- }
76
-
77
- /** 创建实际处理请求的 handler(channel 路由 + 默认转发)。
78
- * - channel 命中 registry(ask_user)→ channel handler(结果经 coerceUiResponse 形变)
79
- * - 无 channel 的 dialog → defaultDialogForward(主 agent ctx.ui.*) */
80
- function createRealHandler(
81
- ctx: ExtensionContext,
82
- _hostMode: HostMode,
83
- registry: UiChannelRegistry,
84
- ): UiRequestHandler {
85
- return async (req: UiRequest): Promise<UiResponse> => {
86
- // 维度 2:channel 业务路由。channel handler 签名是 (unknown)=>Promise<unknown>
87
- //(ui-channels.ts 定义,避免循环依赖),此处经 coerceUiResponse 形变为 UiResponse。
88
- const channelHandler = registry.resolve(req.channel ?? "");
89
- if (channelHandler) {
90
- const raw = await channelHandler(req);
91
- return coerceUiResponse(raw, req.id);
92
- }
93
-
94
- // 无 channel 的 dialog → 默认转发到主 agent ctx.ui.*
95
- return defaultDialogForward(req, ctx);
96
- };
97
- }
98
-
99
- /** channel handler 返回值(unknown)形变为 UiResponse。
100
- * channel handler 由扩展注册(如 ask-user 扩展返回 {value}/{confirmed}/{cancelled}),
101
- * 但 ChannelHandler 类型签名用 unknown(协议层避免循环依赖)。本函数做运行时收窄:
102
- * - 已是合法 UiResponse shape → 原样返回
103
- * - 形状不匹配 → 降级 {cancelled:true}(保守,不阻塞队列) */
104
- function coerceUiResponse(raw: unknown, reqId: string): UiResponse {
105
- if (typeof raw !== "object" || raw === null) {
106
- logger.warn("[subagents] channel handler returned non-object, coercing to cancelled", { detail: { reqId } });
107
- return { cancelled: true };
108
- }
109
- const obj = raw as Record<string, unknown>;
110
- if (typeof obj.value === "string") return { value: obj.value };
111
- if (typeof obj.confirmed === "boolean") return { confirmed: obj.confirmed };
112
- if (obj.cancelled === true) return { cancelled: true };
113
- if (obj.ack === true) return { ack: true };
114
- logger.warn("[subagents] channel handler returned unrecognized shape, coercing to cancelled", { detail: { reqId } });
115
- return { cancelled: true };
116
- }
117
-
118
- /** 无 channel 的 dialog 默认转发:调主 agent 的 ctx.ui.select/confirm/input/editor。
119
- * ask_user channel 未注册时(ask-user 扩展未安装)也会落到这里——
120
- * select 请求转发为普通 select(title 可能含 marker,主 agent 会忽略或当普通 select 渲染)。
121
- *
122
- * 实现依据(SDK ExtensionUIContext 真实签名,read from
123
- * @earendil-works/pi-coding-agent dist/core/extensions/types.d.ts):
124
- * select(title: string, options: string[], opts?): Promise<string | undefined>
125
- * confirm(title: string, message: string, opts?): Promise<boolean>
126
- * input(title: string, placeholder?: string, opts?): Promise<string | undefined>
127
- * editor(title: string, prefill?: string): Promise<string | undefined>
128
- * 注意:SDK 是位置参数(非对象参数);返回 undefined 表示用户取消。
129
- *
130
- * Stage 4 风险点:TUI 下 ask_user channel 未注册时,select 会以普通列表渲染
131
- * (title 可能含 marker)。channel 注册后由 createRealHandler 优先走 channel handler,
132
- * 不进这里。editor 不可用/抛错时降级 cancelled + warn,不卡队列。 */
133
- async function defaultDialogForward(
134
- req: UiRequest,
135
- ctx: ExtensionContext,
136
- ): Promise<UiResponse> {
137
- const ui = ctx.ui;
138
- switch (req.method) {
139
- case "select": {
140
- const selected = await ui.select(req.title ?? "", req.options ?? []);
141
- return selected === undefined ? { cancelled: true } : { value: selected };
142
- }
143
- case "confirm": {
144
- // SDK confirm 必传 message(req.message 缺失时降级空串,不报错阻塞)
145
- const confirmed = await ui.confirm(req.title ?? "", req.message ?? "");
146
- return { confirmed };
147
- }
148
- case "input": {
149
- const text = await ui.input(req.title ?? "", req.placeholder);
150
- return text === undefined ? { cancelled: true } : { value: text };
151
- }
152
- case "editor": {
153
- // SDK editor 必填,但部分 host 运行时未实现——try/catch 降级 cancelled + warn(不卡队列)。
154
- // 不用 typeof 守卫:editor 在类型上必填,typeof 检查会被 TS2367 拒(条件永假)。
155
- try {
156
- const text = await ui.editor(req.title ?? "", req.prefill);
157
- return text === undefined ? { cancelled: true } : { value: text };
158
- } catch (err) {
159
- logger.warn(
160
- "[subagents] ctx.ui.editor unavailable/threw, returning cancelled",
161
- { detail: { id: req.id, error: err instanceof Error ? err.message : String(err) } },
162
- );
163
- return { cancelled: true };
164
- }
165
- }
166
- // ── fire-and-forget 类(§3.2 映射表:GUI 模式下由 createUiRequestHandlerForMode 直接转发)
167
- // 子进程 rpc-mode 发出的 fire-and-forget method,channel miss 后落到此处。
168
- // 全部回 {ack:true}(fire-and-forget 语义:子进程不等响应)。
169
- case "notify": {
170
- // notifyType 运行时收窄:UiRequest.notifyType 是宽 string,ctx.ui.notify 要字面量联合。
171
- // 非法值 fallback "info"(pi 侧也会静默降级 info,此处显式 fallback 避免类型不安全)。
172
- const rawType = req.notifyType;
173
- const notifyType = rawType === "info" || rawType === "warning" || rawType === "error"
174
- ? rawType
175
- : "info";
176
- ui.notify(req.message ?? "", notifyType);
177
- return { ack: true };
178
- }
179
- case "setStatus": {
180
- ui.setStatus(req.statusKey ?? "", req.statusText);
181
- return { ack: true };
182
- }
183
- case "setWidget": {
184
- // setWidget channel-miss 语义(§3.2 D1):
185
- // req.channel === "gui_widget"(带 marker 但 channel 未注册)→ 不转发(marker 行无渲染意义)
186
- // req.channel === undefined(普通 widget)→ 转发文本行到主 agent
187
- // channel 命中 registry 时由 createRealHandler 优先走 channel handler,不进这里。
188
- if (req.channel === "gui_widget") {
189
- return { ack: true };
190
- }
191
- ui.setWidget(req.widgetKey ?? "", req.widgetLines, { placement: req.widgetPlacement });
192
- return { ack: true };
193
- }
194
- case "setTitle": {
195
- ui.setTitle(req.title ?? "");
196
- return { ack: true };
197
- }
198
- case "set_editor_text": {
199
- ui.setEditorText(req.text ?? "");
200
- return { ack: true };
201
- }
202
- default: {
203
- // 未知 method(非 dialog 非 fire-and-forget)——保留 warn(协议演进信号,P3 限流兜底),
204
- // 回 ack(落到 default 的一定不是 dialog,fire-and-forget 正确应答是 ack,与 TUI 分支先例一致)。
205
- logger.warn(
206
- "[subagents] defaultDialogForward: unknown method",
207
- { detail: { method: req.method, id: req.id } },
208
- );
209
- return { ack: true };
210
- }
211
- }
212
- }
@@ -1,81 +0,0 @@
1
- // src/execution/ui-request-observability.ts
2
- //
3
- // UI 请求可观测性状态(从 subagent-service.ts 提取,降低主文件行数)。
4
- // 持有 sessionMode + handler 缺失告警去重集合,供 SubagentService 委托调用。
5
-
6
- import { getLogger } from "@zhushanwen/pi-extension-logger";
7
-
8
- import type { ExtensionMode } from "./host-mode.ts";
9
-
10
- const logger = getLogger("subagents");
11
-
12
- // ── 跨模块桥接(ui-request-queue 无 ctx.service 引用时走这里) ──
13
- //
14
- // ui-request-queue.handleUiRequest 在 ctx.uiRequestHandler 缺失时需要触发去重告警,
15
- // 但 SessionRunnerContext 不持有 service 引用(改 ctx 签名超出本组 4 文件范围)。
16
- // 解法:SubagentService 构造后调 registerGlobalObservability(this.uiObservability)
17
- // 把进程单例挂到 globalThis;queue 走 notifyMissingHandlerGlobal 路径调到同一实例,
18
- // 共享 warnedMissingHandlerSessions 去重集合。
19
- //
20
- // 遗留:SubagentService 接线(构造/初始化时调 registerGlobalObservability)需在后续 PR 完成,
21
- // 本组仅提供桥接入口 + queue 侧调用。未注册时 notifyMissingHandlerGlobal 走 fallback warn(不去重),
22
- // 保证可观测性不回归。
23
- const GLOBAL_OBSERVABILITY_KEY = Symbol.for("pi-subagent-workflow.ui-observability");
24
-
25
- /** 注册进程级 observability 单例(SubagentService 构造后调用一次)。 */
26
- export function registerGlobalObservability(obs: UiRequestObservability): void {
27
- (globalThis as Record<symbol, unknown>)[GLOBAL_OBSERVABILITY_KEY] = obs;
28
- }
29
-
30
- /** 触发 handler 缺失告警(经全局单例,per-session 去重)。
31
- * 未注册全局单例时走 fallback warn(不去重),保证可观测性不丢。 */
32
- export function notifyMissingHandlerGlobal(sessionId: string): void {
33
- const obs = (globalThis as Record<symbol, unknown>)[GLOBAL_OBSERVABILITY_KEY] as
34
- | UiRequestObservability
35
- | undefined;
36
- if (obs) {
37
- obs.notifyMissingHandler(sessionId);
38
- } else {
39
- logger.warn(
40
- `[subagents] uiRequestHandler missing (session=${sessionId}, global observability not registered)`,
41
- );
42
- }
43
- }
44
-
45
- /** warnedMissingHandlerSessions 容量上限(#14 防 Set 无界增长)。
46
- * 长生命周期进程(GUI 主进程长开)下,不同子进程会话 id 不断积累;
47
- * 超过阈值时清空集合(简单策略,LRU 留作后续优化)。 */
48
- const MAX_WARNED_SESSIONS = 1024;
49
-
50
- /** UI 请求可观测性状态。
51
- * 持有 sessionMode(主进程运行模式,W4 守卫透传)+ handler 缺失告警去重集合。
52
- * 外部通过 setMode/resetMissingHandlerWarnings/notifyMissingHandler 驱动。 */
53
- export class UiRequestObservability {
54
- private sessionMode: ExtensionMode | undefined;
55
- private warnedMissingHandlerSessions = new Set<string>();
56
-
57
- setMode(mode: ExtensionMode | undefined): void {
58
- this.sessionMode = mode;
59
- }
60
-
61
- getMode(): ExtensionMode | undefined {
62
- return this.sessionMode;
63
- }
64
-
65
- /** handler 变化时重置告警去重(新 handler 就位后允许重新 warn)。 */
66
- resetMissingHandlerWarnings(): void {
67
- this.warnedMissingHandlerSessions.clear();
68
- }
69
-
70
- /** 记录 handler 缺失(per-session 去重,每 session 只 warn 一次)。
71
- * #14:Set 加 cap——超 MAX_WARNED_SESSIONS 时先清空再 add,防无界增长。
72
- * 清空策略:当前会话首条告警丢失可接受(去重本身只是降噪,非数据完整性约束)。 */
73
- notifyMissingHandler(sessionId: string): void {
74
- if (this.warnedMissingHandlerSessions.has(sessionId)) return;
75
- if (this.warnedMissingHandlerSessions.size >= MAX_WARNED_SESSIONS) {
76
- this.warnedMissingHandlerSessions.clear();
77
- }
78
- this.warnedMissingHandlerSessions.add(sessionId);
79
- logger.warn(`[subagents] uiRequestHandler missing (session=${sessionId}, mode=${this.sessionMode})`);
80
- }
81
- }