@zhushanwen/subagent-core 0.5.1 → 0.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.
- package/README.md +1 -1
- package/dist/chunk-KXVBIVOU.js +16 -0
- package/dist/chunk-T2SYBW3I.js +24 -0
- package/dist/chunk-VURUAGMM.js +2305 -0
- package/dist/{types-Dv4QhSJ_.d.cts → engine-discovery-scan-ocpM8FmI.d.cts} +835 -668
- package/dist/{types-Dv4QhSJ_.d.ts → engine-discovery-scan-ocpM8FmI.d.ts} +835 -668
- package/dist/execution/engine/engine-discovery-scan.cjs +2210 -0
- package/dist/execution/engine/engine-discovery-scan.d.cts +4 -0
- package/dist/execution/engine/engine-discovery-scan.d.ts +4 -0
- package/dist/execution/engine/engine-discovery-scan.js +20 -0
- package/dist/execution/engine/paths.cjs +6 -23
- package/dist/execution/engine/paths.d.cts +1 -8
- package/dist/execution/engine/paths.d.ts +1 -8
- package/dist/execution/engine/paths.js +1 -1
- package/dist/execution/relay-env.cjs +12 -28
- package/dist/execution/relay-env.d.cts +1 -33
- package/dist/execution/relay-env.d.ts +1 -33
- package/dist/execution/relay-env.js +5 -3
- package/dist/index.cjs +14123 -15467
- package/dist/index.d.cts +1179 -1540
- package/dist/index.d.ts +1179 -1540
- package/dist/index.js +7694 -10986
- package/dist.bundle/index.cjs +33485 -0
- package/package.json +20 -26
- package/src/__tests__/record-store-last-line.test.ts +16 -7
- package/src/core/error-message.ts +7 -6
- package/src/core/host-services.ts +8 -2
- package/src/core/notify-ports.ts +17 -2
- package/src/execution/__tests__/agent-registry.test.ts +1 -1
- package/src/execution/__tests__/alive-store.test.ts +1 -1
- package/src/execution/__tests__/chat-engine-routing.test.ts +62 -28
- package/src/execution/__tests__/chat-round-first-round-watchdog.test.ts +255 -0
- package/src/execution/__tests__/collect-budget.test.ts +291 -0
- package/src/execution/__tests__/collect-coordinator-service.test.ts +316 -0
- package/src/execution/__tests__/collect-coordinator.test.ts +371 -0
- package/src/execution/__tests__/collect-mixed-dispatch.test.ts +229 -0
- package/src/execution/__tests__/config-collect-sync.test.ts +120 -0
- package/src/execution/__tests__/config.test.ts +1 -1
- package/src/execution/__tests__/delivery-methods.test.ts +179 -237
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -2
- package/src/execution/__tests__/execute-nesting.test.ts +20 -13
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +21 -34
- package/src/execution/__tests__/finalized-marker.test.ts +1 -1
- package/src/execution/__tests__/gc-timer.test.ts +8 -23
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +20 -10
- package/src/execution/__tests__/helpers/fake-engine-port.ts +187 -0
- package/src/execution/__tests__/helpers/spawn-mock.ts +36 -9
- package/src/execution/__tests__/helpers/subagent-service-mocks.ts +1 -1
- package/src/execution/__tests__/idle-gc.test.ts +200 -0
- package/src/execution/__tests__/lifecycle-predicates.test.ts +26 -21
- package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +1 -1
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +5 -2
- package/src/execution/__tests__/notify-batch.test.ts +500 -0
- package/src/execution/__tests__/notify-ledger.test.ts +27 -0
- package/src/execution/__tests__/reconcile-sweep.test.ts +200 -0
- package/src/execution/__tests__/record-entry-collect.test.ts +102 -0
- package/src/execution/__tests__/record-store.test.ts +60 -6
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +20 -13
- package/src/execution/__tests__/relay-env.test.ts +12 -1
- package/src/execution/__tests__/round-supervisor.test.ts +293 -0
- package/src/execution/__tests__/session-file-gc.test.ts +1 -1
- package/src/execution/__tests__/session-pending.test.ts +119 -17
- package/src/execution/__tests__/start-collect-guard.test.ts +255 -0
- package/src/execution/__tests__/stream-sink-retirement.test.ts +10 -10
- package/src/execution/__tests__/subagent-actions-core.test.ts +6 -0
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +14 -11
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +33 -30
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +2 -9
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +59 -129
- package/src/execution/__tests__/subagent-service.test.ts +2 -2
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +109 -7
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +108 -36
- package/src/execution/__tests__/sync-collect-recovery.test.ts +1102 -0
- package/src/execution/__tests__/tombstone-store.test.ts +1 -1
- package/src/execution/__tests__/workflow-state-root.test.ts +232 -0
- package/src/execution/__tests__/worktree-git-ops.test.ts +1 -1
- package/src/execution/__tests__/worktree-reconcile-aging.test.ts +2 -2
- package/src/execution/__tests__/worktree-reconcile.integration.test.ts +1 -1
- package/src/execution/__tests__/worktree-registry.test.ts +1 -1
- package/src/execution/agent-registry.ts +6 -2
- package/src/execution/collect-coordinator.ts +200 -0
- package/src/execution/config.ts +77 -5
- package/src/execution/dialog-queue.ts +6 -73
- package/src/execution/engine/__tests__/common/capability-gate.test.ts +115 -15
- package/src/execution/engine/__tests__/common/errors.test.ts +11 -18
- package/src/execution/engine/__tests__/common/event-journal.test.ts +1 -1
- package/src/execution/engine/__tests__/common/kill-chain.test.ts +7 -0
- package/src/execution/engine/__tests__/common/nesting-guard.test.ts +9 -3
- package/src/execution/engine/__tests__/common/pool-manager.test.ts +2 -2
- package/src/execution/engine/__tests__/common/session-view-service.test.ts +90 -3
- package/src/execution/engine/__tests__/conformance/H9-test-disposition.md +116 -0
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/fake-engine-protocol.mjs +377 -0
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/recorded.fixture.json +331 -0
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/smoke-run.fixture.json +213 -0
- package/src/execution/engine/__tests__/conformance/chat-round-protocol.test.ts +230 -0
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +69 -42
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +4 -81
- package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +67 -44
- package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +82 -55
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +133 -70
- package/src/execution/engine/__tests__/conformance/engine-crash.test.ts +143 -0
- package/src/execution/engine/__tests__/conformance/fake-engine-capabilities.ts +19 -0
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +8 -3
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +6 -5
- package/src/execution/engine/__tests__/conformance/protocol-blackbox.test.ts +398 -0
- package/src/execution/engine/__tests__/conformance/registry-fork-filter.test.ts +221 -0
- package/src/execution/engine/__tests__/conformance/round-liveness-supervisor.test.ts +302 -0
- package/src/execution/engine/__tests__/conformance/static-spawn-guard.test.ts +58 -0
- package/src/execution/engine/__tests__/engine-discovery-scan.test.ts +558 -0
- package/src/execution/engine/__tests__/host-task-spec.test.ts +45 -0
- package/src/execution/engine/__tests__/model-ref-split.test.ts +74 -0
- package/src/execution/engine/__tests__/registry.test.ts +206 -1
- package/src/execution/engine/__tests__/routing.test.ts +97 -0
- package/src/execution/engine/__tests__/run-failure-worktree-cleanup.test.ts +97 -0
- package/src/execution/engine/client/__tests__/__fixtures__/fake-engine.mjs +294 -0
- package/src/execution/engine/client/__tests__/engine-client.test.ts +516 -0
- package/src/execution/engine/client/__tests__/mirror.test.ts +67 -0
- package/src/execution/engine/client/__tests__/pid-file.test.ts +257 -0
- package/src/execution/engine/client/__tests__/protocol-closure.test.ts +95 -0
- package/src/execution/engine/client/__tests__/remote-engine.test.ts +457 -0
- package/src/execution/engine/client/client-options.ts +103 -0
- package/src/execution/engine/client/engine-client.ts +687 -0
- package/src/execution/engine/client/mirror.ts +167 -0
- package/src/execution/engine/client/pid-file.ts +392 -0
- package/src/execution/engine/client/reaper.ts +95 -0
- package/src/execution/engine/client/remote-engine.ts +441 -0
- package/src/execution/engine/client/reverse-router.ts +255 -0
- package/src/execution/engine/common/capability-gate.ts +109 -22
- package/src/execution/engine/common/errors.ts +9 -25
- package/src/execution/engine/common/event-journal.ts +4 -50
- package/src/execution/engine/common/journal-replay.ts +3 -1
- package/src/execution/engine/common/kill-chain.ts +18 -251
- package/src/execution/engine/common/nesting-guard.ts +18 -114
- package/src/execution/engine/common/pool-manager.ts +4 -0
- package/src/execution/engine/common/session-view-service.ts +56 -84
- package/src/execution/engine/config.ts +151 -0
- package/src/execution/engine/d8-compat.ts +346 -0
- package/src/execution/engine/engine-discovery-roots.ts +107 -0
- package/src/execution/engine/engine-discovery-scan.ts +269 -0
- package/src/execution/engine/engine-discovery.ts +30 -7
- package/src/execution/engine/engine-inspect-package.ts +282 -0
- package/src/execution/engine/engine-manifest.ts +244 -0
- package/src/execution/engine/host/__tests__/host-askuser-endpoint.test.ts +123 -0
- package/src/execution/engine/host/__tests__/host-bridge.test.ts +135 -0
- package/src/execution/engine/host/__tests__/spawned-children.test.ts +73 -0
- package/src/execution/engine/host/host-bridge.ts +150 -0
- package/src/execution/engine/host/host-ui-endpoint.ts +47 -0
- package/src/execution/engine/host/pi-host-binding.ts +91 -0
- package/src/execution/engine/host/spawned-children.ts +139 -0
- package/src/execution/engine/host-task-spec.ts +29 -2
- package/src/execution/engine/model-validation.ts +55 -2
- package/src/execution/engine/paths.ts +16 -41
- package/src/execution/engine/port.ts +48 -2
- package/src/execution/engine/registry.ts +153 -34
- package/src/execution/engine/routing.ts +225 -52
- package/src/execution/engine/types.ts +25 -200
- package/src/execution/execution-record.ts +7 -0
- package/src/execution/finalize-record.ts +40 -11
- package/src/execution/idle-gc.ts +89 -14
- package/src/execution/lifecycle-manager.ts +10 -7
- package/src/execution/lifecycle-predicates.ts +10 -8
- package/src/execution/notifier.ts +234 -25
- package/src/execution/notify-host.ts +21 -1
- package/src/execution/record-entry.ts +16 -0
- package/src/execution/record-store.ts +189 -31
- package/src/execution/relay-env.ts +19 -36
- package/src/execution/round-supervisor/domain.ts +89 -0
- package/src/execution/round-supervisor/index.ts +33 -0
- package/src/execution/round-supervisor/notify-accounting.ts +87 -0
- package/src/execution/round-supervisor/reconcile-sweep.ts +235 -0
- package/src/execution/round-supervisor/service-binding.test.ts +661 -0
- package/src/execution/round-supervisor/service-binding.ts +273 -0
- package/src/execution/round-supervisor/supervisor.ts +426 -0
- package/src/execution/session-pending.ts +68 -74
- package/src/execution/settled-watchdog.ts +39 -0
- package/src/execution/subagent-actions-core.ts +62 -6
- package/src/execution/subagent-service.ts +1161 -406
- package/src/execution/subprocess-agent-runner.ts +16 -8
- package/src/execution/sync-rebuild.ts +87 -0
- package/src/execution/types.ts +104 -117
- package/src/execution/ui-channels.ts +13 -214
- package/src/execution/ui-request-handler-factory.ts +7 -4
- package/src/execution/ui-request-observability.ts +2 -2
- package/src/execution/workflow-state-root.ts +67 -0
- package/src/execution/worktree-git-ops.ts +5 -0
- package/src/execution/worktree-manager.ts +11 -1
- package/src/index.ts +55 -26
- package/src/orchestration/__tests__/config-loader.test.ts +1 -1
- package/src/orchestration/__tests__/execute-agent-call.test.ts +1 -1
- package/src/orchestration/__tests__/file-run-store-prune.test.ts +1 -1
- package/src/orchestration/__tests__/file-run-store-throttle.test.ts +1 -1
- package/src/orchestration/__tests__/review-fix-loop-scriptpath-failfast.test.ts +1 -1
- package/src/orchestration/__tests__/script-generate.test.ts +5 -5
- package/src/orchestration/__tests__/skill-discovery.test.ts +2 -2
- package/src/orchestration/__tests__/workflow-files.test.ts +10 -10
- package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +1 -1
- package/src/orchestration/execute-agent-call.ts +1 -1
- package/src/orchestration/file-run-store.ts +144 -59
- package/src/orchestration/models/types.ts +43 -42
- package/src/shared/__tests__/atomic-write.test.ts +1 -1
- package/src/shared/__tests__/resource-discovery-host-roots.test.ts +5 -5
- package/src/shared/zcode-model-ref.ts +31 -0
- package/dist/chunk-43ONBFZX.js +0 -240
- package/dist/chunk-A4IVZWVX.js +0 -31
- package/dist/chunk-APZY4IME.js +0 -27
- package/dist/chunk-V3VHZ2VX.js +0 -59
- package/dist/execution/engine/engines/zcode/constants.cjs +0 -107
- package/dist/execution/engine/engines/zcode/constants.d.cts +0 -135
- package/dist/execution/engine/engines/zcode/constants.d.ts +0 -135
- package/dist/execution/engine/engines/zcode/constants.js +0 -54
- package/dist/execution/engine/engines/zcode/reader.cjs +0 -276
- package/dist/execution/engine/engines/zcode/reader.d.cts +0 -21
- package/dist/execution/engine/engines/zcode/reader.d.ts +0 -21
- package/dist/execution/engine/engines/zcode/reader.js +0 -9
- package/src/__tests__/append-system-prompt-assembly.test.ts +0 -243
- package/src/__tests__/fr4-get-state-handshake.test.ts +0 -125
- package/src/__tests__/session-runner.test.ts +0 -69
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -191
- package/src/execution/__tests__/descendant-sweep-guards.test.ts +0 -220
- package/src/execution/__tests__/descendant-sweep.test.ts +0 -269
- package/src/execution/__tests__/engine-model-validation.test.ts +0 -741
- package/src/execution/__tests__/epipe-fallback.test.ts +0 -248
- package/src/execution/__tests__/execution-runtime-face.test.ts +0 -272
- package/src/execution/__tests__/get-state-handshake.test.ts +0 -127
- package/src/execution/__tests__/helpers/session-runner-mocks.ts +0 -113
- package/src/execution/__tests__/keep-alive-no-progress.test.ts +0 -280
- package/src/execution/__tests__/kill-all-escalation.test.ts +0 -196
- package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +0 -113
- package/src/execution/__tests__/output-collector.test.ts +0 -469
- package/src/execution/__tests__/pi-invocation.test.ts +0 -134
- package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -149
- package/src/execution/__tests__/rpc-mode.test.ts +0 -89
- package/src/execution/__tests__/run-and-finalize-anchoring.test.ts +0 -387
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -277
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -254
- package/src/execution/__tests__/run-spawn-edges.test.ts +0 -1079
- package/src/execution/__tests__/run-spawn-integration.test.ts +0 -933
- package/src/execution/__tests__/run-spawn-resume.test.ts +0 -322
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +0 -196
- package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +0 -207
- package/src/execution/__tests__/service-kill-escalation.test.ts +0 -91
- package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +0 -110
- package/src/execution/__tests__/session-runner-close-prune.test.ts +0 -181
- package/src/execution/__tests__/session-runner-dispatch.test.ts +0 -489
- package/src/execution/__tests__/session-runner-epipe.test.ts +0 -179
- package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +0 -227
- package/src/execution/__tests__/session-runner-lifecycle-helpers.test.ts +0 -290
- package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -352
- package/src/execution/__tests__/settled-watchdog.test.ts +0 -524
- package/src/execution/__tests__/spawn-args.test.ts +0 -446
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -192
- package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -208
- package/src/execution/__tests__/spawned-children.test.ts +0 -236
- package/src/execution/__tests__/start-sync-model-guard.test.ts +0 -150
- package/src/execution/__tests__/stdin-writer.test.ts +0 -464
- package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -693
- package/src/execution/__tests__/temp-prompt.test.ts +0 -53
- package/src/execution/__tests__/timeout-integration.test.ts +0 -616
- package/src/execution/__tests__/turn-limiter-semantics.test.ts +0 -194
- package/src/execution/__tests__/turn-limiter.test.ts +0 -65
- package/src/execution/__tests__/ui-request-handler.test.ts +0 -205
- package/src/execution/__tests__/ui-request-queue.test.ts +0 -298
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -230
- package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
- package/src/execution/engine/__tests__/common/session-view-service-zcode-dbpath.test.ts +0 -149
- package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
- package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +0 -128
- package/src/execution/engine/__tests__/paths.test.ts +0 -39
- package/src/execution/engine/common/schema-emulation.ts +0 -189
- package/src/execution/engine/common/session-view-projection.ts +0 -51
- package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -615
- package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
- package/src/execution/engine/engines/pi/__tests__/spawn-opts-direct.test.ts +0 -257
- package/src/execution/engine/engines/pi/argv-mirror.ts +0 -135
- package/src/execution/engine/engines/pi/get-state-handshake.ts +0 -179
- package/src/execution/engine/engines/pi/output-collector.ts +0 -317
- package/src/execution/engine/engines/pi/pi-engine.ts +0 -811
- package/src/execution/engine/engines/pi/pi-invocation.ts +0 -120
- package/src/execution/engine/engines/pi/reader.ts +0 -59
- package/src/execution/engine/engines/pi/registration.ts +0 -37
- package/src/execution/engine/engines/pi/session-runner.ts +0 -2840
- package/src/execution/engine/engines/pi/spawn-event-adapter.ts +0 -404
- package/src/execution/engine/engines/pi/stdin-writer.ts +0 -199
- package/src/execution/engine/engines/pi/temp-prompt.ts +0 -62
- package/src/execution/engine/engines/pi/turn-limiter.ts +0 -102
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +0 -301
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json +0 -36
- package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +0 -321
- package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +0 -473
- package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -43
- package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -124
- package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
- package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -71
- package/src/execution/engine/engines/zcode/__tests__/session-channel-dispose-harvest.test.ts +0 -247
- package/src/execution/engine/engines/zcode/__tests__/session-channel-turn-timers.test.ts +0 -451
- package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +0 -792
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +0 -782
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +0 -168
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-dispose.test.ts +0 -210
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-retry.test.ts +0 -353
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-status.test.ts +0 -282
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-timeout.test.ts +0 -372
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -145
- package/src/execution/engine/engines/zcode/appserver-launcher.ts +0 -167
- package/src/execution/engine/engines/zcode/connection.ts +0 -598
- package/src/execution/engine/engines/zcode/constants.ts +0 -176
- package/src/execution/engine/engines/zcode/golden-sample.ts +0 -47
- package/src/execution/engine/engines/zcode/parser.ts +0 -102
- package/src/execution/engine/engines/zcode/preparer.ts +0 -235
- package/src/execution/engine/engines/zcode/reader.ts +0 -381
- package/src/execution/engine/engines/zcode/registration.ts +0 -37
- package/src/execution/engine/engines/zcode/session-channel.ts +0 -968
- package/src/execution/engine/engines/zcode/zcode-engine.ts +0 -1431
- package/src/execution/round-settlement.ts +0 -93
- package/src/execution/ui-request-queue.ts +0 -215
- package/src/shared/schema-env.ts +0 -44
|
@@ -1,216 +1,15 @@
|
|
|
1
1
|
// src/execution/ui-channels.ts
|
|
2
2
|
//
|
|
3
|
-
// UI channel 提取(marker 解析)+ channel
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
}
|
|
3
|
+
// UI channel 提取(marker 解析)+ channel 注册表的 re-export shim:实现体单源
|
|
4
|
+
// @zhushanwen/subagent-engine-sdk(自本文件逐字等价移入 SDK,round1-reuse R1;
|
|
5
|
+
// core → SDK 边界正向合法)。core 内消费方(channel-registry-access /
|
|
6
|
+
// ui-request-handler-factory)import 路径保持不变,barrel 导出面零变化。
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
type ChannelHandler,
|
|
10
|
+
createUiChannelRegistry,
|
|
11
|
+
type ExtensionUiRequestLike,
|
|
12
|
+
parseChannel,
|
|
13
|
+
type ParsedChannel,
|
|
14
|
+
type UiChannelRegistry,
|
|
15
|
+
} from "@zhushanwen/subagent-engine-sdk";
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
//
|
|
3
3
|
// UI 请求 handler 工厂(透传 + 排队总控)。
|
|
4
4
|
//
|
|
5
|
-
// 按 ctx.mode(ExtensionMode)创建合适的 UiRequestHandler
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
5
|
+
// 按 ctx.mode(ExtensionMode)创建合适的 UiRequestHandler,SubagentService 持有后经
|
|
6
|
+
// host-ui-endpoint 登记处注入协议客户端——引擎进程的 extension_ui_request 经
|
|
7
|
+
// host/askUser 反向通道到达本 handler([W3] inproc L1 队列 inproc UI 请求队列(已删) 随
|
|
8
|
+
// inproc pi 引擎目录 删除消亡,「run 生命周期内闭包队列」语义由引擎包内等价物 +
|
|
9
|
+
// 协议应答路径承接)。本模块是「handler 注入链路」的组装点:把 channel registry
|
|
10
|
+
//(业务路由)+ dialog queue(L2 跨子进程串行)+ mode 分流(TUI/GUI/headless)
|
|
11
|
+
// 粘合成一个 handler。
|
|
9
12
|
//
|
|
10
13
|
// 设计依据(.fix-plans/00-master-summary.md):
|
|
11
14
|
// - §一冲突 2「透传矩阵」:
|
|
@@ -9,9 +9,9 @@ import type { ExtensionMode } from "./host-mode.ts";
|
|
|
9
9
|
|
|
10
10
|
const logger = getLogger("subagents");
|
|
11
11
|
|
|
12
|
-
// ── 跨模块桥接(
|
|
12
|
+
// ── 跨模块桥接(inproc UI 请求队列(已删) 无 ctx.service 引用时走这里) ──
|
|
13
13
|
//
|
|
14
|
-
//
|
|
14
|
+
// inproc UI 请求队列 handleUiRequest(已删) 在 ctx.uiRequestHandler 缺失时需要触发去重告警,
|
|
15
15
|
// 但 SessionRunnerContext 不持有 service 引用(改 ctx 签名超出本组 4 文件范围)。
|
|
16
16
|
// 解法:SubagentService 构造后调 registerGlobalObservability(this.uiObservability)
|
|
17
17
|
// 把进程单例挂到 globalThis;queue 走 notifyMissingHandlerGlobal 路径调到同一实例,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/execution/workflow-state-root.ts
|
|
2
|
+
//
|
|
3
|
+
// [F-1 修复] pi 宿主 WorkflowRun state 目录解析(与 pi 壳 JsonlRunStore 同源布局)。
|
|
4
|
+
//
|
|
5
|
+
// 为什么存在:pi 宿主 workflow 域的 run state 真实落盘 = JsonlRunStore 的
|
|
6
|
+
// `<sessionDir>/workflow-state/<runId>.jsonl`,sessionDir 由 extension 侧
|
|
7
|
+
// `extensions/universal/subagent-workflow/src/session-lifecycle.ts` 的
|
|
8
|
+
// resolveSessionDir() 推导。core 侧两个读侧装配点(round-supervisor 的注册对账
|
|
9
|
+
// sweep、idle-gc 的 WorkflowRun GC)曾用 FileRunStore 缺省根
|
|
10
|
+
// `<dataRoot>/workflow-state`(zcode 宿主布局)——两目录生产不相交,读侧恒 ENOENT:
|
|
11
|
+
// sweep 把活跃 run 判 missing 补注销(误注销活跃 run),WorkflowRun GC 恒空转。
|
|
12
|
+
//
|
|
13
|
+
// core 不能 import extension——本文件按 resolveSessionDir 同规则在 core 侧重写推导,
|
|
14
|
+
// 两处注释互指锚定([同步纪律] 改 sessionDir 布局时必须同批改本文件与
|
|
15
|
+
// session-lifecycle.ts,漂移信号 = sweep 补注销活跃 run / GC 空转)。
|
|
16
|
+
//
|
|
17
|
+
// agentDir 推导锚定 pi 实装版 0.84.4 dist config.js getAgentDir:
|
|
18
|
+
// `process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent")`
|
|
19
|
+
// (ENV_AGENT_DIR = PI_CODING_AGENT_DIR、CONFIG_DIR_NAME = piConfig.configDir = ".pi",
|
|
20
|
+
// 无 piConfig.name 覆盖)。pi 升级若改 getAgentDir 语义 → 本推导漂移,可见信号同上。
|
|
21
|
+
|
|
22
|
+
import { existsSync } from "node:fs";
|
|
23
|
+
import { homedir } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
|
|
26
|
+
/** pi SDK getAgentDir 的 env 覆盖通道(实装版 dist config.js ENV_AGENT_DIR)。 */
|
|
27
|
+
const PI_AGENT_DIR_ENV = "PI_CODING_AGENT_DIR";
|
|
28
|
+
|
|
29
|
+
/** pi SDK 缺省 agent 目录分量(实装版 dist config.js:CONFIG_DIR_NAME + "agent")。 */
|
|
30
|
+
const DEFAULT_PI_AGENT_DIR_PARTS = [".pi", "agent"] as const;
|
|
31
|
+
|
|
32
|
+
/** resolvePiWorkflowStateDir 的注入面(测试用;生产缺省全走真实推导)。 */
|
|
33
|
+
export interface PiWorkflowStateDirOptions {
|
|
34
|
+
/** agent 配置目录覆盖(缺省 = PI_CODING_AGENT_DIR env 或 ~/.pi/agent)。 */
|
|
35
|
+
agentDir?: string;
|
|
36
|
+
/** cwd 覆盖(缺省 process.cwd()——对齐 session-lifecycle 用进程 cwd 而非 ctx.cwd)。 */
|
|
37
|
+
cwd?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 解析 pi 宿主 WorkflowRun state 目录(`<sessionDir>/workflow-state`)。
|
|
42
|
+
*
|
|
43
|
+
* sessionDir 推导(与 session-lifecycle.resolveSessionDir 逐段同构,见文件头注):
|
|
44
|
+
* - cwd-slug = `--<cwd 去开头分隔符、`/`→`-`>--`(extension 侧字面规则——core 的
|
|
45
|
+
* encodeCwd 额外折叠 `:` 与 `\`,与建目录方不一致,此处不共用);
|
|
46
|
+
* - `<agentDir>/sessions/<slug>` 目录存在则用之(该目录由 workflow 域首次落盘
|
|
47
|
+
* 创建——cwd 有过 workflow run 才存在),否则回退 agentDir 根
|
|
48
|
+
* (JsonlRunStore 的 mkdir recursive 使首写直接落 agentDir 根,两侧探测一致)。
|
|
49
|
+
*
|
|
50
|
+
* 只读解析(existsSync 探测),无目录创建副作用——与 FileRunStore 的 save 侧
|
|
51
|
+
* mkdir 职责分离。
|
|
52
|
+
*/
|
|
53
|
+
export function resolvePiWorkflowStateDir(opts?: PiWorkflowStateDirOptions): string {
|
|
54
|
+
const agentDir = opts?.agentDir ?? resolvePiAgentDir();
|
|
55
|
+
const cwd = opts?.cwd ?? process.cwd();
|
|
56
|
+
const sessionSlug = `--${cwd.replace(/^\//, "").replace(/\//g, "-")}--`;
|
|
57
|
+
const sessionScopedDir = join(agentDir, "sessions", sessionSlug);
|
|
58
|
+
const sessionDir = existsSync(sessionScopedDir) ? sessionScopedDir : agentDir;
|
|
59
|
+
return join(sessionDir, "workflow-state");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** pi agent 目录(getAgentDir 同语义;推导锚定见文件头注)。 */
|
|
63
|
+
function resolvePiAgentDir(): string {
|
|
64
|
+
const envDir = process.env[PI_AGENT_DIR_ENV];
|
|
65
|
+
if (envDir !== undefined && envDir !== "") return envDir;
|
|
66
|
+
return join(homedir(), ...DEFAULT_PI_AGENT_DIR_PARTS);
|
|
67
|
+
}
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
// 职责,不在纯内核复刻——git index.lock 冲突瞬时态正好落降级路径②,而非内核故障。
|
|
26
26
|
|
|
27
27
|
import { execFile } from "node:child_process";
|
|
28
|
+
|
|
29
|
+
import { buildOutboundChildEnv } from "@zhushanwen/subagent-engine-sdk";
|
|
28
30
|
import * as fs from "node:fs";
|
|
29
31
|
|
|
30
32
|
import { getLogger } from "../core/logger.ts";
|
|
@@ -115,6 +117,9 @@ export function gitRun(
|
|
|
115
117
|
timeout: opts.timeout ?? GIT_TIMEOUT_MS,
|
|
116
118
|
...(opts.maxBuffer !== undefined ? { maxBuffer: opts.maxBuffer } : {}),
|
|
117
119
|
encoding: "utf-8",
|
|
120
|
+
// 出站卫生(R3 MF-C,impl-plan §2.12):同 worktree-manager.ts gitRunAsync——
|
|
121
|
+
// deny 键不进 git 子进程,git hooks 后代不再可能消费 deny 键。
|
|
122
|
+
env: buildOutboundChildEnv({ parentEnv: process.env }),
|
|
118
123
|
},
|
|
119
124
|
(err, stdout, stderr) => {
|
|
120
125
|
if (err) {
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
// 声称的「tmpdir + 分支对账兜底」由此成为代码。
|
|
24
24
|
|
|
25
25
|
import { execFile } from "node:child_process";
|
|
26
|
+
|
|
27
|
+
import { buildOutboundChildEnv } from "@zhushanwen/subagent-engine-sdk";
|
|
26
28
|
import * as fs from "node:fs";
|
|
27
29
|
import * as os from "node:os";
|
|
28
30
|
import * as path from "node:path";
|
|
@@ -713,7 +715,15 @@ export class WorktreeManager {
|
|
|
713
715
|
execFile(
|
|
714
716
|
"git",
|
|
715
717
|
args,
|
|
716
|
-
{
|
|
718
|
+
{
|
|
719
|
+
cwd: opts.cwd,
|
|
720
|
+
timeout: opts.timeout ?? GIT_TIMEOUT_MS,
|
|
721
|
+
encoding: "utf-8",
|
|
722
|
+
// 出站卫生(R3 MF-C,impl-plan §2.12):deny 键不进 git 子进程——
|
|
723
|
+
// git hooks 等后代不再可能消费生命周期标志 / WS 令牌。SDK 版缺省
|
|
724
|
+
// 全量继承父 env + deny 剥除,行为差异仅 deny 键剥除。
|
|
725
|
+
env: buildOutboundChildEnv({ parentEnv: process.env }),
|
|
726
|
+
},
|
|
717
727
|
(err, stdout, stderr) => {
|
|
718
728
|
if (err) {
|
|
719
729
|
const execErr = err as Error & { code?: unknown; killed?: boolean; signal?: string };
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @zhushanwen/subagent-core — 公共 API barrel(D5 定稿 + post-convergence B-2 扩面)
|
|
3
3
|
*
|
|
4
4
|
* 公共 API 面 = 本文件导出 + package.json exports 的语义子入口
|
|
5
|
-
* (./
|
|
6
|
-
*
|
|
5
|
+
* (./engine/paths、./engine/engine-discovery-scan、./relay-env——[W11/H3] 引擎
|
|
6
|
+
* 子入口 ./engines/zcode/* 已随内建引擎删除)+ ./workflows/* 资产子入口。exports 面即 semver 契约(D5):收窄不放宽——
|
|
7
7
|
* 新增导出走 minor,本文件刻意不使用 `export *`,逐名列出以使 diff 可审。
|
|
8
8
|
* 内部实现细节(error-recovery / execute-agent-call / worker-script-builder 等
|
|
9
9
|
* engine 编排件)不经 barrel 导出;host-surface 扩面(zsw 回接 U0,2026-08-30)
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// 0.4.0 = 首个公开发布的收敛收口面(0.3.0 为 2026-08-30 裁决的跳号占位,永不单独
|
|
25
25
|
// 发布;+ minor changeset 收口面落本号);与 package.json version 的一致性由
|
|
26
26
|
// src/__tests__/smoke.test.ts 动态守护,改版本须两处同步。
|
|
27
|
-
export const CORE_PACKAGE_VERSION = "0.
|
|
27
|
+
export const CORE_PACKAGE_VERSION = "0.7.0";
|
|
28
28
|
|
|
29
29
|
// ── 宿主端口接线面(core/)────────────────────────────────────
|
|
30
30
|
// HostServices:dataRoot / log / discoveryRoots 端口 + configureCore 注入;
|
|
@@ -88,34 +88,54 @@ export {
|
|
|
88
88
|
type EngineRoutingInput,
|
|
89
89
|
type EngineRoutingSource,
|
|
90
90
|
} from "./execution/engine/routing.ts";
|
|
91
|
+
// [W8 补扫接线面] setEngineDiscoveryRescanOptions:宿主登记 hasEngineWithRescan 的
|
|
92
|
+
// 补扫发现参数(与 session_start 发现扫描同源);壳消费 = runtime
|
|
93
|
+
// subagent-engine-history 的 ensureRuntimeEngineWiring。
|
|
94
|
+
export { setEngineDiscoveryRescanOptions } from "./execution/engine/routing.ts";
|
|
91
95
|
|
|
92
96
|
// ── 引擎注册 / 发现与进程面(execution/engine)────────────────
|
|
93
97
|
// 组合根 index.ts 接线消费(registerXxx 引擎注册、syncEnginesFile engines 文件
|
|
94
98
|
// 同步、killAllSpawnedChildren session 派生进程兜底清理)。
|
|
95
99
|
export { syncEnginesFile } from "./execution/engine/engine-discovery.ts";
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
// [W11/DoD#5] registerPiEngine(inproc 'pi' 注册)已删;[W3 chat 域收口] chat 域 inproc
|
|
101
|
+
// 引擎(inproc pi 引擎目录)与 SubagentService 自持 DI 实例一并删除——registry 'pi' 由三级发现
|
|
102
|
+
// 装载 cli descriptor,chat 轮次与 run 域同路经协议客户端发往 pi-subagent-cli 引擎进程
|
|
103
|
+
// (G1:pi 引擎单一 CLI 形态,core 壳侧零内建引擎)。
|
|
104
|
+
// [W8 D8 薄壳] killAllSpawnedChildren:扩展 index.ts / zsw runner-core.js 的业务调用点
|
|
105
|
+
// 零改动。语义([F-7 注释纠偏,如实口径])= **仅镜像记账**——core 侧 spawnedChildren
|
|
106
|
+
// 镜像整体清空(engine/host/spawned-children.ts 公共面),不发任何进程信号;
|
|
107
|
+
// 子进程活在引擎进程内,其回收链 = ① stdin-EOF 自灭(宿主退出 / EngineClient 销毁
|
|
108
|
+
// → 引擎进程 stdin 断源自灭,正常路径);② disposeEngines()(registry)显式触发全部
|
|
109
|
+
// 已实例化引擎 dispose(cli 形态 = RemoteEngine.dispose → EngineClient 有界收口)——
|
|
110
|
+
// 该入口为宿主 shutdown 链预留,现无生产接线。subagent-workflow 扩展的
|
|
111
|
+
// reapSpawnedChildrenOnShutdown(process hook 调本函数)因此同为镜像置死 no-op,
|
|
112
|
+
// 不构成真实收割(现状登记,workflow 包生产码不动)。
|
|
113
|
+
export { killAllSpawnedChildren } from "./execution/engine/host/spawned-children.ts";
|
|
114
|
+
|
|
115
|
+
// [W8 D8 兼容公共面薄壳](设计 §3.6 D8 表):registerZcodeEngine 确保cli descriptor
|
|
116
|
+
// 注册(vendored 相对定位,失败回退 inproc 过渡)+ engineDataDir 记入;createZcodeEngine
|
|
117
|
+
// 返回 RemoteEngine('zcode')(deps → 协议客户端映射,sources 不跨进程)。实现见
|
|
118
|
+
// execution/engine/d8-compat.ts——engines/zcode/registration.ts 的同名符号不再经
|
|
119
|
+
// barrel 导出(inproc 实现保留至 W11,仅内部测试/过渡消费)。
|
|
120
|
+
export {
|
|
121
|
+
createZcodeEngine,
|
|
122
|
+
registerZcodeEngine,
|
|
123
|
+
type D8CompatZcodeEngineDeps,
|
|
124
|
+
} from "./execution/engine/d8-compat.ts";
|
|
99
125
|
|
|
100
|
-
// pi session-runner 内核件(merge 裁决:dev 侧旧深路径 execution/session-runner.ts
|
|
101
|
-
// 终态已不存在,符号随 u-2a 迁移至 engine/engines/pi/session-runner.ts):
|
|
102
126
|
// maxTurnsToWatchdogMs 为 maxTurns→watchdog 毫秒换算(U3/U4 / D7,floor 语义
|
|
103
|
-
// 文档化——两宿主预算一致性 S2
|
|
104
|
-
//
|
|
127
|
+
// 文档化——两宿主预算一致性 S2 的函数级锚点;[W3] 定义收敛在 pi-host-binding,
|
|
128
|
+
// 原 inproc session-runner(已删) 定义随删件消亡);killRecordChildWithEscalation 为
|
|
129
|
+
// 单 record 子进程终止的镜像记账入口([W3] 实际终止在引擎进程内经协议承载)。
|
|
105
130
|
export {
|
|
106
131
|
killRecordChildWithEscalation,
|
|
107
|
-
|
|
108
|
-
} from "./execution/engine/
|
|
132
|
+
} from "./execution/engine/host/spawned-children.ts";
|
|
133
|
+
export { maxTurnsToWatchdogMs } from "./execution/engine/host/pi-host-binding.ts";
|
|
109
134
|
|
|
110
|
-
// zcode
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
export {
|
|
114
|
-
export type { ZcodeEngineDeps } from "./execution/engine/engines/zcode/registration.ts";
|
|
115
|
-
|
|
116
|
-
// ZcodeTaskShapeError:zcode 任务形状错误类(instanceof 分流用)——
|
|
117
|
-
// execution-runtime-face.test.ts:29 消费,barrel 保留导出(engines 域 A1 裁决)。
|
|
118
|
-
export { ZcodeTaskShapeError } from "./execution/engine/engines/zcode/zcode-engine.ts";
|
|
135
|
+
// zcode 引擎注册面([W8 D8 薄壳] createZcodeEngine 已上移 d8-compat——上方导出)。
|
|
136
|
+
// [W11 收口] ZcodeEngineDeps 与 D8CompatZcodeEngineDeps 合并为别名(zsw 调用面的
|
|
137
|
+
// deps 形状契约保持);barrel 不导出引擎错误类(引擎错误归各引擎包自持)。
|
|
138
|
+
export type { ZcodeEngineDeps } from "./execution/engine/d8-compat.ts";
|
|
119
139
|
|
|
120
140
|
// 引擎注册表原语 + 引擎感知提示面:engine-awareness injector 消费。
|
|
121
141
|
export {
|
|
@@ -132,6 +152,11 @@ export {
|
|
|
132
152
|
// 子入口(D9:每条子入口 bundle 多一份 host-services 副本)。
|
|
133
153
|
export { parseEngineHandle } from "./execution/engine/common/session-view-types.ts";
|
|
134
154
|
export { readSubagentHistoryMessages } from "./execution/engine/common/session-view-service.ts";
|
|
155
|
+
// [W8] registerNativeSessionReader:runtime 成为协议客户端的①级接入点——宿主把
|
|
156
|
+
// 「协议 read」注册为引擎原生 reader,core 三级降级链(①协议 read → ②journal →
|
|
157
|
+
// ③outcome)自动编排(含投影),宿主零投影代码。壳消费 = runtime
|
|
158
|
+
// subagent-engine-history 的协议 reader 注册。
|
|
159
|
+
export { registerNativeSessionReader } from "./execution/engine/common/session-view-service.ts";
|
|
135
160
|
|
|
136
161
|
// ── 执行域(execution/)──────────────────────────────────────
|
|
137
162
|
// types.ts 领域类型族:record / 响应 / 列表项等 subagent 域公共契约(壳消费最高频面,
|
|
@@ -262,7 +287,7 @@ export {
|
|
|
262
287
|
|
|
263
288
|
// 错误类型族(error-recovery.ts 计划路径实测不存在,实测散布于下列源文件):
|
|
264
289
|
// resurrect/fork-depth/dirty-worktree 为动作层守卫抛出点(types.ts),
|
|
265
|
-
// GitRunError 见 worktree
|
|
290
|
+
// GitRunError 见 worktree 内核组裁决。
|
|
266
291
|
export {
|
|
267
292
|
DirtyWorktreeError,
|
|
268
293
|
ForkDepthExceededError,
|
|
@@ -313,14 +338,14 @@ export {
|
|
|
313
338
|
} from "./execution/concurrency-pool.ts";
|
|
314
339
|
|
|
315
340
|
// 模型引用切分原语(U1 契约面批件):provider/model 引用切分与缺省值(两宿主
|
|
316
|
-
// maxTurns/model
|
|
317
|
-
//
|
|
341
|
+
// maxTurns/model 换算同源)。[W11/H2] 实现体随 engines/zcode 删除迁至
|
|
342
|
+
// shared/zcode-model-ref.ts(宿主侧原语,与引擎包各自单源)。
|
|
318
343
|
export {
|
|
319
344
|
DEFAULT_PROVIDER_ID,
|
|
320
345
|
hasApiKey,
|
|
321
346
|
splitZcodeModelRef,
|
|
322
|
-
|
|
323
|
-
|
|
347
|
+
ZCODE_FALLBACK_DEFAULT_MODEL,
|
|
348
|
+
} from "./shared/zcode-model-ref.ts";
|
|
324
349
|
|
|
325
350
|
// ── worktree git 内核(U5 / D5)───────────────────────────────
|
|
326
351
|
// git 语义纯函数单源:保真读(gitRun)、SafeId 校验、dirty 谓词、
|
|
@@ -484,10 +509,14 @@ export type {
|
|
|
484
509
|
// LifecycleDeps.store 用;pi 壳继续用 session 锚定的 JsonlRunStore。
|
|
485
510
|
// DEFAULT_* 两常量:壳 jsonl-run-store.ts 生产消费(D3 判定进 barrel),
|
|
486
511
|
// u-2c 删 ./* 通配后深路径仅测试侧 vitest alias 可解析,生产消费必须走 barrel。
|
|
512
|
+
// pruneStateFilesBeyondCap:磁盘 retention 裁剪单源(S4-A7)——壳 jsonl-run-store
|
|
513
|
+
// 的同构私有实现已删,改 import 本函数并注入自身 logger tag / toErrorMessage。
|
|
487
514
|
export {
|
|
488
515
|
DEFAULT_SAVE_MIN_INTERVAL_MS,
|
|
489
516
|
DEFAULT_STATE_MAX_RUNS,
|
|
490
517
|
FileRunStore,
|
|
518
|
+
pruneStateFilesBeyondCap,
|
|
519
|
+
type PruneStateDeps,
|
|
491
520
|
} from "./orchestration/file-run-store.ts";
|
|
492
521
|
|
|
493
522
|
// ── 快照 codec(U8 / D4)──────────────────────────────────────
|
|
@@ -102,7 +102,7 @@ beforeEach(async () => {
|
|
|
102
102
|
|
|
103
103
|
afterEach(async () => {
|
|
104
104
|
vi.useRealTimers();
|
|
105
|
-
if (ws) await rm(ws.root, { recursive: true, force: true });
|
|
105
|
+
if (ws) await rm(ws.root, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
/** 过滤掉可能从真实 homedir 泄漏进来的 user-agents 文件,只保留临时工作区内结果。 */
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
isDeterministicSchemaFailureMsg,
|
|
13
13
|
isStaleContextErrorMsg,
|
|
14
14
|
STALE_CONTEXT_PATTERNS,
|
|
15
|
-
} from "
|
|
15
|
+
} from "@zhushanwen/pi-subagent-cli";
|
|
16
16
|
import { executeAgentCall } from "../execute-agent-call.ts";
|
|
17
17
|
import { AgentCall } from "../models/agent-call.ts";
|
|
18
18
|
import { Budget } from "../models/budget.ts";
|
|
@@ -39,7 +39,7 @@ beforeEach(() => {
|
|
|
39
39
|
afterEach(() => {
|
|
40
40
|
vi.useRealTimers();
|
|
41
41
|
resetCoreForTests();
|
|
42
|
-
rmSync(dataRoot, { recursive: true, force: true });
|
|
42
|
+
rmSync(dataRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
/** 构造可持久化的 WorkflowRun(对齐 file-run-store.test.ts makeRun 模式)。 */
|
|
@@ -67,7 +67,7 @@ beforeEach(() => {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
afterEach(() => {
|
|
70
|
-
rmSync(sandboxDir, { recursive: true, force: true });
|
|
70
|
+
rmSync(sandboxDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
/** cwd 植入件:若任一脚本回退 process.cwd() 加载依赖,本文件被 require 即抛标记错误。 */
|
|
@@ -168,7 +168,7 @@ describe("generateWorkflowScript 校验闸(文案逐字对齐 pi 现版)", (
|
|
|
168
168
|
);
|
|
169
169
|
expect(existsSync(join(tmpRoot, "esm-wf.js"))).toBe(false);
|
|
170
170
|
} finally {
|
|
171
|
-
rmSync(tmpRoot, { recursive: true, force: true });
|
|
171
|
+
rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
|
|
@@ -216,7 +216,7 @@ describe("generateWorkflowScript 校验闸(文案逐字对齐 pi 现版)", (
|
|
|
216
216
|
}
|
|
217
217
|
expect(existsSync(join(tmpRoot, "bad-wf.js"))).toBe(false);
|
|
218
218
|
} finally {
|
|
219
|
-
rmSync(tmpRoot, { recursive: true, force: true });
|
|
219
|
+
rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
220
220
|
}
|
|
221
221
|
});
|
|
222
222
|
|
|
@@ -247,7 +247,7 @@ describe("generateWorkflowScript 合法样本落 tmp", () => {
|
|
|
247
247
|
expect(existsSync(r.path)).toBe(true);
|
|
248
248
|
expect(readFileSync(r.path, "utf-8")).toBe(PI_META_VALID);
|
|
249
249
|
} finally {
|
|
250
|
-
rmSync(tmpRoot, { recursive: true, force: true });
|
|
250
|
+
rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
251
251
|
}
|
|
252
252
|
});
|
|
253
253
|
|
|
@@ -259,7 +259,7 @@ describe("generateWorkflowScript 合法样本落 tmp", () => {
|
|
|
259
259
|
if (!r.ok) throw new Error(r.error);
|
|
260
260
|
expect(existsSync(r.path)).toBe(true);
|
|
261
261
|
} finally {
|
|
262
|
-
rmSync(tmpRoot, { recursive: true, force: true });
|
|
262
|
+
rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
263
263
|
}
|
|
264
264
|
});
|
|
265
265
|
|
|
@@ -274,7 +274,7 @@ describe("generateWorkflowScript 合法样本落 tmp", () => {
|
|
|
274
274
|
expect(existsSync(r.path)).toBe(true);
|
|
275
275
|
} finally {
|
|
276
276
|
cwdSpy.mockRestore();
|
|
277
|
-
rmSync(fakeCwd, { recursive: true, force: true });
|
|
277
|
+
rmSync(fakeCwd, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
278
278
|
}
|
|
279
279
|
});
|
|
280
280
|
});
|
|
@@ -73,8 +73,8 @@ beforeEach(() => {
|
|
|
73
73
|
afterEach(() => {
|
|
74
74
|
vi.restoreAllMocks();
|
|
75
75
|
resetCoreForTests();
|
|
76
|
-
rmSync(projRoot, { recursive: true, force: true });
|
|
77
|
-
rmSync(homeRoot, { recursive: true, force: true });
|
|
76
|
+
rmSync(projRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
77
|
+
rmSync(homeRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
/** mkdir -p(目录存在即 resolveSkillPath 命中——检查的是目录而非 SKILL.md)。 */
|