@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.
- package/package.json +13 -16
- package/relay/relay.mjs +1 -1
- package/src/host/__tests__/pi-host.test.ts +214 -0
- package/src/host/pi-host.ts +109 -0
- package/src/index.ts +142 -32
- package/src/injectors/__tests__/engine-awareness.test.ts +292 -0
- package/src/injectors/__tests__/engine-section-stability.test.ts +341 -0
- package/src/injectors/__tests__/subagent-list-injector.test.ts +5 -5
- package/src/injectors/__tests__/workflow-list-injector.test.ts +5 -5
- package/src/injectors/engine-awareness.ts +123 -0
- package/src/injectors/model-list-injector.ts +1 -1
- package/src/injectors/subagent-list-injector.ts +8 -8
- package/src/injectors/workflow-list-injector.ts +8 -8
- package/src/interface/__tests__/detectors.test.ts +3 -3
- package/src/interface/__tests__/subagent-tool-path-guard.test.ts +157 -0
- package/src/interface/__tests__/subagent-tool-prompt.test.ts +12 -0
- package/src/interface/__tests__/tool-workflow-script-generate.test.ts +2 -2
- package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +1 -1
- package/src/interface/bg-notify-render.ts +34 -13
- package/src/interface/commands.ts +3 -3
- package/src/interface/format.ts +2 -2
- package/src/interface/helpers.ts +3 -3
- package/src/interface/list-component.ts +4 -4
- package/src/interface/list-shared.ts +2 -2
- package/src/interface/list-view.ts +2 -2
- package/src/interface/subagent-actions.ts +288 -19
- package/src/interface/subagent-tool-schema.ts +163 -0
- package/src/interface/subagent-tool.ts +65 -129
- package/src/interface/subagents.ts +5 -5
- package/src/interface/tool-render.ts +34 -2
- package/src/interface/tool-workflow-script.ts +4 -4
- package/src/interface/tool-workflow.ts +6 -6
- package/src/interface/views/WorkflowsView.ts +5 -5
- package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +3 -3
- package/src/interface/views/__tests__/detail-content-session-file.test.ts +2 -2
- package/src/interface/views/detail-content.ts +4 -4
- package/src/interface/views/format.ts +4 -4
- package/src/{orchestration/jsonl-run-store.ts → jsonl-run-store.ts} +132 -18
- package/src/execution/__tests__/__fixtures__/notifier-golden-snapshots.json +0 -53
- package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +0 -1
- package/src/execution/__tests__/agent-registry.test.ts +0 -363
- package/src/execution/__tests__/agent-result-mapper.test.ts +0 -150
- package/src/execution/__tests__/alive-store.test.ts +0 -147
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
- package/src/execution/__tests__/before-agent-start-injection.test.ts +0 -132
- package/src/execution/__tests__/bg-notify-render.test.ts +0 -256
- package/src/execution/__tests__/channel-registry-handshake.test.ts +0 -243
- package/src/execution/__tests__/chat-engine-routing.test.ts +0 -597
- package/src/execution/__tests__/chatmode-first-round-closure-service.test.ts +0 -365
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -190
- package/src/execution/__tests__/chatmode-round-notify-real-chain.test.ts +0 -215
- package/src/execution/__tests__/concurrency-pool.test.ts +0 -250
- package/src/execution/__tests__/config.test.ts +0 -110
- package/src/execution/__tests__/conversation-wiring.test.ts +0 -198
- package/src/execution/__tests__/crash-recovery.test.ts +0 -320
- package/src/execution/__tests__/delivery-methods.test.ts +0 -385
- package/src/execution/__tests__/dialog-queue.test.ts +0 -299
- package/src/execution/__tests__/epipe-fallback.test.ts +0 -241
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -243
- package/src/execution/__tests__/execute-nesting.test.ts +0 -323
- package/src/execution/__tests__/execute-options-mapper.test.ts +0 -189
- package/src/execution/__tests__/execution-record.test.ts +0 -1284
- package/src/execution/__tests__/finalize-record.test.ts +0 -368
- package/src/execution/__tests__/finalized-marker.test.ts +0 -82
- package/src/execution/__tests__/format-schema-instruction.test.ts +0 -138
- package/src/execution/__tests__/format.test.ts +0 -458
- package/src/execution/__tests__/gc-timer.test.ts +0 -184
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +0 -254
- package/src/execution/__tests__/gui-mode-dispatch.test.ts +0 -59
- package/src/execution/__tests__/helpers/mock-extension-api.ts +0 -30
- package/src/execution/__tests__/helpers/spawn-mock.ts +0 -238
- package/src/execution/__tests__/host-mode.test.ts +0 -87
- package/src/execution/__tests__/index-session-start-identity.test.ts +0 -371
- package/src/execution/__tests__/index-session-start.test.ts +0 -593
- package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
- package/src/execution/__tests__/lifecycle-manager.test.ts +0 -337
- package/src/execution/__tests__/lifecycle-predicates.test.ts +0 -116
- package/src/execution/__tests__/list-component.test.ts +0 -401
- package/src/execution/__tests__/list-fields.test.ts +0 -109
- package/src/execution/__tests__/manifest-parentid.test.ts +0 -117
- package/src/execution/__tests__/model-resolver.test.ts +0 -413
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +0 -287
- package/src/execution/__tests__/nested-visibility.test.ts +0 -325
- package/src/execution/__tests__/notifier-flush.test.ts +0 -574
- package/src/execution/__tests__/notifier-golden-snapshot.test.ts +0 -261
- package/src/execution/__tests__/one-shot-upgrade.test.ts +0 -205
- package/src/execution/__tests__/output-collector.test.ts +0 -61
- package/src/execution/__tests__/parent-child-matrix.test.ts +0 -336
- package/src/execution/__tests__/path-encoding.test.ts +0 -104
- package/src/execution/__tests__/pi-invocation.test.ts +0 -134
- package/src/execution/__tests__/record-store.test.ts +0 -1057
- package/src/execution/__tests__/records-cwd-isolation.test.ts +0 -91
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +0 -339
- package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -273
- package/src/execution/__tests__/relay-agent.test.ts +0 -448
- package/src/execution/__tests__/relay-env.test.ts +0 -42
- package/src/execution/__tests__/resource-policy.test.ts +0 -109
- package/src/execution/__tests__/rpc-mode.test.ts +0 -89
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -267
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -253
- package/src/execution/__tests__/run-spawn-edges.test.ts +0 -644
- 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__/sdk-contract.test.ts +0 -273
- package/src/execution/__tests__/session-context-resolver.test.ts +0 -167
- package/src/execution/__tests__/session-file-gc.test.ts +0 -293
- package/src/execution/__tests__/session-pending.test.ts +0 -197
- package/src/execution/__tests__/session-reconstructor.test.ts +0 -379
- package/src/execution/__tests__/session-runner-epipe.test.ts +0 -178
- package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -311
- package/src/execution/__tests__/session-start-reaper.test.ts +0 -233
- package/src/execution/__tests__/spawn-args.test.ts +0 -434
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -189
- package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -207
- package/src/execution/__tests__/spawned-children.test.ts +0 -92
- package/src/execution/__tests__/startup-config-declaration.test.ts +0 -35
- package/src/execution/__tests__/status-refactor.test.ts +0 -345
- package/src/execution/__tests__/stdin-writer.test.ts +0 -463
- package/src/execution/__tests__/stream-sink-retirement.test.ts +0 -261
- package/src/execution/__tests__/subagent-service-abort.test.ts +0 -60
- package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -629
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +0 -180
- package/src/execution/__tests__/subagent-service.test.ts +0 -788
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -310
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +0 -506
- package/src/execution/__tests__/temp-prompt.test.ts +0 -53
- package/src/execution/__tests__/timeout-integration.test.ts +0 -397
- package/src/execution/__tests__/tombstone-store.test.ts +0 -73
- package/src/execution/__tests__/tool-action.test.ts +0 -385
- package/src/execution/__tests__/truncline-snapshot.test.ts +0 -81
- 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-channels.test.ts +0 -187
- package/src/execution/__tests__/ui-interaction-model.test.ts +0 -67
- package/src/execution/__tests__/ui-request-handler-factory.test.ts +0 -370
- package/src/execution/__tests__/ui-request-handler.test.ts +0 -204
- package/src/execution/__tests__/ui-request-observability.test.ts +0 -114
- package/src/execution/__tests__/ui-request-queue.test.ts +0 -133
- package/src/execution/__tests__/worktree-manager.test.ts +0 -633
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -229
- package/src/execution/__tests__/worktree-reconcile.integration.test.ts +0 -181
- package/src/execution/__tests__/worktree-registry.test.ts +0 -199
- package/src/execution/agent-registry.ts +0 -193
- package/src/execution/agent-result-mapper.ts +0 -90
- package/src/execution/alive-store.ts +0 -92
- package/src/execution/argv-mirror.ts +0 -109
- package/src/execution/best-effort.ts +0 -38
- package/src/execution/channel-registry-access.ts +0 -144
- package/src/execution/concurrency-pool.ts +0 -116
- package/src/execution/config.ts +0 -96
- package/src/execution/dialog-queue.ts +0 -330
- package/src/execution/engine/__tests__/common/data-dir.test.ts +0 -53
- package/src/execution/engine/__tests__/common/errors.test.ts +0 -132
- package/src/execution/engine/__tests__/common/event-journal.test.ts +0 -177
- package/src/execution/engine/__tests__/common/kill-chain.test.ts +0 -192
- package/src/execution/engine/__tests__/common/nesting-guard.test.ts +0 -81
- package/src/execution/engine/__tests__/common/persona-router.test.ts +0 -123
- package/src/execution/engine/__tests__/common/pool-manager.test.ts +0 -154
- package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
- package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
- package/src/execution/engine/__tests__/conformance/agent-event-invariants.ts +0 -141
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +0 -109
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +0 -101
- package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +0 -77
- package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +0 -104
- package/src/execution/engine/__tests__/conformance/contract.relay.test.ts +0 -342
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +0 -201
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +0 -76
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +0 -79
- package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -87
- package/src/execution/engine/__tests__/engines-declaration.test.ts +0 -36
- package/src/execution/engine/__tests__/model-prompt.test.ts +0 -85
- package/src/execution/engine/__tests__/paths.test.ts +0 -39
- package/src/execution/engine/__tests__/registry.test.ts +0 -120
- package/src/execution/engine/__tests__/routing.test.ts +0 -231
- package/src/execution/engine/common/data-dir.ts +0 -62
- package/src/execution/engine/common/errors.ts +0 -183
- package/src/execution/engine/common/event-journal.ts +0 -254
- package/src/execution/engine/common/journal-replay.ts +0 -62
- package/src/execution/engine/common/kill-chain.ts +0 -221
- package/src/execution/engine/common/nesting-guard.ts +0 -50
- package/src/execution/engine/common/persona-router.ts +0 -108
- package/src/execution/engine/common/pool-manager.ts +0 -226
- 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/engine-discovery.ts +0 -65
- package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -469
- package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
- package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
- package/src/execution/engine/engines/pi/pi-engine.ts +0 -415
- package/src/execution/engine/engines/pi/reader.ts +0 -48
- package/src/execution/engine/engines/pi/registration.ts +0 -35
- package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
- package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
- package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -246
- package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -228
- package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
- package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -64
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -127
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -567
- package/src/execution/engine/engines/zcode/constants.ts +0 -43
- package/src/execution/engine/engines/zcode/golden-sample.ts +0 -39
- package/src/execution/engine/engines/zcode/launcher.ts +0 -161
- package/src/execution/engine/engines/zcode/parser.ts +0 -436
- package/src/execution/engine/engines/zcode/preparer.ts +0 -363
- 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/zcode-engine.ts +0 -648
- package/src/execution/engine/host-task-spec.ts +0 -47
- package/src/execution/engine/model-prompt.ts +0 -59
- package/src/execution/engine/paths.ts +0 -42
- package/src/execution/engine/port.ts +0 -153
- package/src/execution/engine/registry.ts +0 -123
- package/src/execution/engine/routing.ts +0 -218
- package/src/execution/engine/types.ts +0 -304
- package/src/execution/execute-options-mapper.ts +0 -111
- package/src/execution/execution-record.ts +0 -906
- package/src/execution/finalize-record.ts +0 -251
- package/src/execution/finalized-marker.ts +0 -51
- package/src/execution/get-state-handshake.ts +0 -104
- package/src/execution/host-mode.ts +0 -56
- package/src/execution/idle-gc.ts +0 -47
- package/src/execution/lifecycle-manager.ts +0 -491
- package/src/execution/lifecycle-predicates.ts +0 -65
- package/src/execution/manifest-store.ts +0 -256
- package/src/execution/model-config-service.ts +0 -204
- package/src/execution/model-resolver.ts +0 -276
- package/src/execution/notifier.ts +0 -260
- package/src/execution/output-collector.ts +0 -88
- package/src/execution/path-encoding.ts +0 -60
- package/src/execution/pi-invocation.ts +0 -120
- package/src/execution/record-entry.ts +0 -132
- package/src/execution/record-store.ts +0 -1234
- package/src/execution/relay-env.ts +0 -37
- package/src/execution/session-context-resolver.ts +0 -64
- package/src/execution/session-file-gc.ts +0 -120
- package/src/execution/session-pending.ts +0 -164
- package/src/execution/session-reconstructor.ts +0 -678
- package/src/execution/session-runner.ts +0 -1548
- package/src/execution/sessions-index.ts +0 -304
- package/src/execution/spawn-event-adapter.ts +0 -363
- package/src/execution/stdin-writer.ts +0 -198
- package/src/execution/stream-sink.ts +0 -126
- package/src/execution/subagent-service.ts +0 -2119
- package/src/execution/subprocess-agent-runner.ts +0 -303
- package/src/execution/temp-prompt.ts +0 -62
- package/src/execution/tombstone-store.ts +0 -72
- package/src/execution/turn-limiter.ts +0 -102
- package/src/execution/types.ts +0 -910
- package/src/execution/ui-channels.ts +0 -216
- package/src/execution/ui-interaction-model.ts +0 -48
- package/src/execution/ui-request-handler-factory.ts +0 -212
- package/src/execution/ui-request-observability.ts +0 -81
- package/src/execution/ui-request-queue.ts +0 -174
- package/src/execution/worktree-manager.ts +0 -688
- package/src/execution/worktree-registry.ts +0 -222
- package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +0 -336
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +0 -208
- package/src/orchestration/__tests__/agent-call-stream.test.ts +0 -157
- package/src/orchestration/__tests__/args-validator.test.ts +0 -143
- package/src/orchestration/__tests__/concurrency-gate.test.ts +0 -125
- package/src/orchestration/__tests__/config-loader.test.ts +0 -503
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +0 -724
- package/src/orchestration/__tests__/error-recovery-postmessage-defense.test.ts +0 -405
- package/src/orchestration/__tests__/error-recovery-serialize-failed-result.test.ts +0 -56
- package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +0 -166
- package/src/orchestration/__tests__/execute-agent-call.test.ts +0 -314
- package/src/orchestration/__tests__/jsonl-run-store-loadall-sources.test.ts +0 -171
- package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +0 -1030
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +0 -277
- package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +0 -96
- package/src/orchestration/__tests__/lifecycle.test.ts +0 -625
- package/src/orchestration/__tests__/review-fix-loop-e2e.test.ts +0 -1971
- package/src/orchestration/__tests__/script-lint.test.ts +0 -831
- package/src/orchestration/__tests__/skill-discovery.test.ts +0 -157
- package/src/orchestration/__tests__/test-mocks.ts +0 -197
- package/src/orchestration/__tests__/worker-host.test.ts +0 -120
- package/src/orchestration/__tests__/worker-returnmeta-passthrough.test.ts +0 -164
- package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +0 -520
- package/src/orchestration/__tests__/worker-script-builder.test.ts +0 -309
- package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +0 -110
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +0 -317
- package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +0 -110
- package/src/orchestration/__tests__/workflows-e2e.test.ts +0 -537
- package/src/orchestration/agent-opts-resolver.ts +0 -93
- package/src/orchestration/args-validator.ts +0 -127
- package/src/orchestration/concurrency-gate.ts +0 -69
- package/src/orchestration/config-loader.ts +0 -315
- package/src/orchestration/error-recovery.ts +0 -862
- package/src/orchestration/execute-agent-call.ts +0 -217
- package/src/orchestration/launcher.ts +0 -410
- package/src/orchestration/lifecycle.ts +0 -396
- package/src/orchestration/models/__tests__/budget.test.ts +0 -367
- package/src/orchestration/models/__tests__/trace.test.ts +0 -408
- package/src/orchestration/models/agent-call.ts +0 -83
- package/src/orchestration/models/budget.ts +0 -148
- package/src/orchestration/models/ports.ts +0 -164
- package/src/orchestration/models/run-runtime.ts +0 -89
- package/src/orchestration/models/run-spec.ts +0 -83
- package/src/orchestration/models/run-state.ts +0 -44
- package/src/orchestration/models/trace.ts +0 -183
- package/src/orchestration/models/types.ts +0 -292
- package/src/orchestration/models/workflow-run.ts +0 -254
- package/src/orchestration/models/workflow-script-registry.ts +0 -35
- package/src/orchestration/models/workflow-script.ts +0 -117
- package/src/orchestration/script-lint.ts +0 -766
- package/src/orchestration/skill-discovery.ts +0 -92
- package/src/orchestration/worker-handle.ts +0 -115
- package/src/orchestration/worker-host.ts +0 -98
- package/src/orchestration/worker-script-builder.ts +0 -408
- package/src/orchestration/workflow-files.ts +0 -85
- package/src/orchestration/workflow-script-registry-impl.ts +0 -133
- package/src/shared/__tests__/agent-ref.test.ts +0 -34
- package/src/shared/__tests__/meta-parser.test.ts +0 -304
- package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -280
- package/src/shared/__tests__/resource-discovery.test.ts +0 -736
- package/src/shared/__tests__/resource-meta.test.ts +0 -51
- package/src/shared/__tests__/schema-jsonify.test.ts +0 -81
- package/src/shared/agent-event.ts +0 -13
- package/src/shared/agent-ref.ts +0 -57
- package/src/shared/meta-parser.ts +0 -261
- package/src/shared/resource-discovery.ts +0 -811
- package/src/shared/resource-meta.ts +0 -65
- package/src/shared/schema-jsonify.ts +0 -56
- package/src/shared/xml-injection.ts +0 -35
- package/workflows/README.md +0 -81
- package/workflows/_shared/agent-refs.cjs +0 -40
- package/workflows/chain.js +0 -131
- package/workflows/map-reduce.js +0 -174
- package/workflows/parallel.js +0 -148
- package/workflows/review-fix-loop-utils.cjs +0 -1307
- package/workflows/review-fix-loop.js +0 -1396
- package/workflows/scatter-gather.js +0 -178
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// src/core/path-encoding.ts
|
|
2
|
-
//
|
|
3
|
-
// cwd → 安全目录名的编码逻辑。Core 叶子原语(零依赖)。
|
|
4
|
-
//
|
|
5
|
-
// 被 session-runner(subagent session 持久化目录)与 session-file-gc(清理过期
|
|
6
|
-
// session 文件)共用——两处需要相同的编码,否则同一 cwd 会落到两个不同目录。
|
|
7
|
-
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* cwd → 安全目录名。复用 Pi SDK getDefaultSessionDir 的编码逻辑:
|
|
12
|
-
* 去开头单个分隔符,全量替换剩余分隔符/冒号为 `-`,首尾补 `--`。
|
|
13
|
-
* 例:`/Users/x/proj` → `--Users-x-proj--`。
|
|
14
|
-
*/
|
|
15
|
-
export function encodeCwd(cwd: string): string {
|
|
16
|
-
return "--" + cwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-") + "--";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 获取 subagent session 持久化目录路径。
|
|
21
|
-
*
|
|
22
|
-
* D-004: 用主 cwd 编码——保证同一主 cwd 下所有 subagent 的 session 文件
|
|
23
|
-
* 存放在同一目录,便于 session-file-gc 统一清理。
|
|
24
|
-
* [MF-3] worktree 模式下调用方必须传树根 cwd(ROOT mainCwd,经 PI_SUBAGENT_ROOT_CWD
|
|
25
|
-
* 贯穿),不能传子进程自身的 checkout 路径——否则深层 record 落盘到 enc(worktree) 段,
|
|
26
|
-
* ROOT 磁盘重建扫不到(全树可见性断裂)。根进程传自身 cwd(行为不变)。
|
|
27
|
-
*
|
|
28
|
-
* @param agentDir agent 配置目录(如 ~/.pi/agent)
|
|
29
|
-
* @param mainCwd 树根主 agent 的工作目录(非 subagent 的 effectiveCwd;worktree 模式下
|
|
30
|
-
* 是 ROOT 的 cwd,不是 checkout 路径)
|
|
31
|
-
* @returns session 持久化目录绝对路径
|
|
32
|
-
*/
|
|
33
|
-
export function getSubagentSessionDir(agentDir: string, mainCwd: string): string {
|
|
34
|
-
// [MF#1] 保持既有布局 subagents/<enc>/sessions/——曾改为 subagents/sessions/<enc>/ 会让
|
|
35
|
-
// 升级用户的既有 session 文件全部落到扫描目录外(历史记录消失 + GC 扫不到,双重 orphan)。
|
|
36
|
-
// 本分支未发布,回退到既有布局即无需迁移、无数据丢失。
|
|
37
|
-
return path.join(agentDir, "subagents", encodeCwd(mainCwd), "sessions");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 获取 subagent records(manifest)持久化目录路径。
|
|
42
|
-
*
|
|
43
|
-
* 与 getSubagentSessionDir 同用 encodeCwd(mainCwd),保证 records 与 sessions 在同一
|
|
44
|
-
* <enc> 段下物理相邻。
|
|
45
|
-
* [MF-3] 调用方必须与 getSubagentSessionDir 传同一编码键(进程内 init.cwd /
|
|
46
|
-
* buildSessionRunnerContext.mainCwd / record.worktreeHandle.mainCwd 恒等;worktree 模式
|
|
47
|
-
* 跨进程时统一用贯穿的 ROOT cwd)——sessions 与 records 两套目录同段,GC/重建才不会
|
|
48
|
-
* 互相找不到(enc 段不变量)。
|
|
49
|
-
*
|
|
50
|
-
* D-004 同源:用主 cwd 编码做物理隔离,使 session-file-gc 按 <enc>/records/ 子目录
|
|
51
|
-
* 匹配 manifest .json 时天然限定在当前 cwd 范围内,不会越界清理其他 cwd 的 manifest。
|
|
52
|
-
*
|
|
53
|
-
* @param agentDir agent 配置目录(如 ~/.pi/agent)
|
|
54
|
-
* @param mainCwd 树根主 agent 的工作目录(非 subagent 的 effectiveCwd;worktree 模式下
|
|
55
|
-
* 是 ROOT 的 cwd,不是 checkout 路径)
|
|
56
|
-
* @returns records 持久化目录绝对路径
|
|
57
|
-
*/
|
|
58
|
-
export function getSubagentRecordsDir(agentDir: string, mainCwd: string): string {
|
|
59
|
-
return path.join(agentDir, "subagents", encodeCwd(mainCwd), "records");
|
|
60
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// src/execution/pi-invocation.ts
|
|
2
|
-
//
|
|
3
|
-
// 定位 pi 二进制并组装 spawn 调用。Core 叶子原语(仅依赖 node 内置)。
|
|
4
|
-
//
|
|
5
|
-
// spawn 改造(in-process → spawn pi --mode json)的基座模块。
|
|
6
|
-
// 被 runSpawn(session-runner)调用,决定子进程用哪个命令启动。
|
|
7
|
-
//
|
|
8
|
-
// 移植自 nicobailon subagent example 的 getPiInvocation,处理三种运行时:
|
|
9
|
-
// 1. bun bundle(/$bunfs/root/ 虚拟脚本)→ 退化到 pi-in-PATH
|
|
10
|
-
// 2. 有真实脚本路径(node + script)→ node <script> <args>
|
|
11
|
-
// 3. node/bun generic runtime(无脚本)→ pi <args>(依赖 PATH)
|
|
12
|
-
//
|
|
13
|
-
// 注意:pi 在扩展进程内运行时 process.execPath 是 node/bun,process.argv[1]
|
|
14
|
-
// 是 pi 的入口脚本。子进程需要复现同样的启动方式才能保证扩展/配置一致加载。
|
|
15
|
-
|
|
16
|
-
import * as fs from "node:fs";
|
|
17
|
-
import * as path from "node:path";
|
|
18
|
-
|
|
19
|
-
import { isRelayActive, RELAY_ENV_NODE, RELAY_ENV_SCRIPT } from "./relay-env.ts";
|
|
20
|
-
|
|
21
|
-
/** spawn 调用描述符:command + args(透传给 child_process.spawn)。 */
|
|
22
|
-
export interface PiInvocation {
|
|
23
|
-
/** 可执行文件路径(node/bun/pi 二进制)。 */
|
|
24
|
-
command: string;
|
|
25
|
-
/** 命令行参数(可能含 [scriptPath, ...userArgs] 或直接 [...userArgs])。 */
|
|
26
|
-
args: string[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** getPiInvocation 可选项。 */
|
|
30
|
-
export interface PiInvocationOptions {
|
|
31
|
-
/**
|
|
32
|
-
* false = 强制直连 spawn 真实 pi(不经 relay 代理)。唯一现役消费点是 PiEngine.probe
|
|
33
|
-
* ——探针意图是 pi 本体可解析性,经 relay 探到的是 runtime 健康,语义错位(E 方案 §5.1)。
|
|
34
|
-
* 缺省(undefined / true)时按 relay env 激活判定走代理。
|
|
35
|
-
*/
|
|
36
|
-
relay?: boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* bun 虚拟文件系统前缀。bun bundle 模式下 process.argv[1] 形如
|
|
41
|
-
* /$bunfs/root/pi——这不是磁盘上的真实文件,不能直接 spawn。
|
|
42
|
-
*/
|
|
43
|
-
const BUN_VIRTUAL_PREFIX = "/$bunfs/root/";
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 判断 execPath 的 basename 是否为通用运行时(node/bun)。
|
|
47
|
-
* 通用运行时需要脚本路径才能启动 pi;非通用(如 pi 的 standalone binary)可直接执行。
|
|
48
|
-
*/
|
|
49
|
-
function isGenericRuntime(execPath: string): boolean {
|
|
50
|
-
const execName = path.basename(execPath).toLowerCase();
|
|
51
|
-
return /^(node|bun)(\.exe)?$/.test(execName);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 组装 pi 子进程的 spawn 调用。
|
|
56
|
-
*
|
|
57
|
-
* @param userArgs pi CLI 参数(如 ["--mode", "rpc", "--session-dir", "..."])
|
|
58
|
-
* @param opts 可选项(relay:false 强制直连——probe 用,见 PiInvocationOptions)
|
|
59
|
-
* @returns spawn 描述符(command + 完整 args)
|
|
60
|
-
*
|
|
61
|
-
* 决策链(按优先级):
|
|
62
|
-
* 0. relay 激活(三 env 齐备且未显式禁用)→ <RELAY_NODE> <RELAY_SCRIPT> <userArgs>
|
|
63
|
-
* (E 方案 §5.1:xyz-agent runtime 存在时经代理 spawn,改的是进程拓扑不是 pi 语义)
|
|
64
|
-
* 1. process.argv[1] 是真实磁盘文件且非 bun 虚拟路径 → <execPath> <argv[1]> <userArgs>
|
|
65
|
-
* (复现当前 pi 进程的启动方式,确保扩展/配置/版本一致)
|
|
66
|
-
* 2. execPath 非通用运行时(pi standalone binary)→ <execPath> <userArgs>
|
|
67
|
-
* 3. 通用运行时但无可用脚本路径 → "pi" <userArgs>(依赖 PATH 中可找到 pi)
|
|
68
|
-
*/
|
|
69
|
-
// [perf] 决策链只依赖 process.argv[1] / process.execPath(进程内恒定),其中唯一的
|
|
70
|
-
// 磁盘探测(existsSync)结果 memo 一次——每次 spawn 免重复 syscall。memo 键含
|
|
71
|
-
// argv[1] 值:测试 mock 切换 argv[1] 模拟不同运行时时自动失效重算。
|
|
72
|
-
let scriptExistsCache: { script: string | undefined; exists: boolean } | undefined;
|
|
73
|
-
|
|
74
|
-
/** process.argv[1] 是真实磁盘脚本(非 bun 虚拟路径)且存在。 */
|
|
75
|
-
function currentScriptExists(): boolean {
|
|
76
|
-
const currentScript = process.argv[1];
|
|
77
|
-
if (scriptExistsCache === undefined || scriptExistsCache.script !== currentScript) {
|
|
78
|
-
scriptExistsCache = {
|
|
79
|
-
script: currentScript,
|
|
80
|
-
exists:
|
|
81
|
-
currentScript !== undefined &&
|
|
82
|
-
!currentScript.startsWith(BUN_VIRTUAL_PREFIX) &&
|
|
83
|
-
fs.existsSync(currentScript),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return scriptExistsCache.exists;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function getPiInvocation(userArgs: string[], opts?: PiInvocationOptions): PiInvocation {
|
|
90
|
-
const currentScript = process.argv[1];
|
|
91
|
-
const isBunVirtualScript = currentScript?.startsWith(BUN_VIRTUAL_PREFIX);
|
|
92
|
-
|
|
93
|
-
// 分支 0(前置):relay 激活(E 方案 §5.1)——runtime 注入三 env 齐备且未显式禁用时,
|
|
94
|
-
// spawn 目标切换为 <RELAY_NODE> <RELAY_SCRIPT> <原 pi spawnArgs>,形态与分支 1「node +
|
|
95
|
-
// script」同构(command 是执行器、args[0] 是脚本)。ELECTRON_RUN_AS_NODE 不在此补:
|
|
96
|
-
// 打包态执行器为 Electron 时由 runtime 与三 env 同点注入主 pi 进程 env(E-2
|
|
97
|
-
// getRelaySpawnEnv),本进程 {...process.env} 继承即达代理进程,extension 不重复判定。
|
|
98
|
-
// isRelayActive 已保证三 env 非空,下方取局部变量仅为 TS 收窄(isRelayActive 的
|
|
99
|
-
// 收窄不跨函数边界传导)。
|
|
100
|
-
if (opts?.relay !== false && isRelayActive(process.env)) {
|
|
101
|
-
const relayNode = process.env[RELAY_ENV_NODE];
|
|
102
|
-
const relayScript = process.env[RELAY_ENV_SCRIPT];
|
|
103
|
-
if (relayNode !== undefined && relayScript !== undefined) {
|
|
104
|
-
return { command: relayNode, args: [relayScript, ...userArgs] };
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// 分支 1:有真实脚本路径 → 复现启动方式(node <pi-script> <args>)
|
|
109
|
-
if (currentScript && !isBunVirtualScript && currentScriptExists()) {
|
|
110
|
-
return { command: process.execPath, args: [currentScript, ...userArgs] };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// 分支 2:非通用运行时(pi 自带 binary)→ 直接执行
|
|
114
|
-
if (!isGenericRuntime(process.execPath)) {
|
|
115
|
-
return { command: process.execPath, args: userArgs };
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 分支 3:通用运行时但脚本不可用 → 依赖 PATH
|
|
119
|
-
return { command: "pi", args: userArgs };
|
|
120
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// src/execution/record-entry.ts
|
|
2
|
-
//
|
|
3
|
-
// W16 [D4]:subagent record 自描述持久化 entry 的形态权威。
|
|
4
|
-
//
|
|
5
|
-
// pi 文件(session JSONL)是扩展数据持久化权威:record 状态每次迁移都经
|
|
6
|
-
// pi.appendEntry 落一条自描述完整快照(字段即 SubagentRecord),读取方无需
|
|
7
|
-
// 逆向解析 toolCall/toolResult。内存 record-store 保持运行时权威,entry 是
|
|
8
|
-
// 重建源(两者不冲突)。
|
|
9
|
-
//
|
|
10
|
-
// customType 与既有 `subagent-identity`(session 文件首行身份 entry)同族命名
|
|
11
|
-
//(连字符风格);写点见 record-store.ts 的状态迁移点(register/archive/
|
|
12
|
-
// reportRecordTransition),custom entry 由 pi 写进 session JSONL,不进 LLM context。
|
|
13
|
-
|
|
14
|
-
import type {
|
|
15
|
-
AgentEventLogEntry,
|
|
16
|
-
ClosedReason,
|
|
17
|
-
DisplayItem,
|
|
18
|
-
ExecutionMode,
|
|
19
|
-
ExecutionStatus,
|
|
20
|
-
SubagentRecord,
|
|
21
|
-
} from "./types.ts";
|
|
22
|
-
|
|
23
|
-
/** 自描述 record entry 的 customType。写点字面量与本常量的等值由
|
|
24
|
-
* __tests__/record-store.test.ts 断言钉住(消费方引用本常量,勿用裸字符串)。 */
|
|
25
|
-
export const SUBAGENT_RECORD_CUSTOM_TYPE = "subagent-record";
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* `subagent-record` entry 的 data schema(v1)。
|
|
29
|
-
*
|
|
30
|
-
* = 完整 SubagentRecord 快照(GUI 侧列表/详情需要的全部持久化字段)+ 版本号。
|
|
31
|
-
* 显式排除三个非持久化字段(与 SubagentRecord 的差集):
|
|
32
|
-
* - currentActivity:running 时的瞬时流态,重开 session 无重建价值;
|
|
33
|
-
* - externalInstance:跨重启探活态(pid/startedAt),由 .alive sidecar 重建;
|
|
34
|
-
* - worktreeHandle:不可 JSON 序列化的运行时句柄(布尔投影 worktree 保留)。
|
|
35
|
-
*
|
|
36
|
-
* undefined 字段经 JSON.stringify 自然缺省(与 SubagentRecord 重建侧语义一致)。
|
|
37
|
-
*/
|
|
38
|
-
export interface SubagentRecordEntryData {
|
|
39
|
-
/** schema 版本(W16 起 v1)。消费方按 v 判别解析,不认识的版本跳过而非猜测。 */
|
|
40
|
-
v: 1;
|
|
41
|
-
id: string;
|
|
42
|
-
agent: string;
|
|
43
|
-
/** 任务提示词(详情面板置顶展示)。 */
|
|
44
|
-
task: string;
|
|
45
|
-
/** 短标签(≤35 字符)。 */
|
|
46
|
-
slug: string;
|
|
47
|
-
status: ExecutionStatus;
|
|
48
|
-
/** L2 关闭原因(仅 status="closed" 时有意义)。 */
|
|
49
|
-
closedReason?: ClosedReason;
|
|
50
|
-
mode: ExecutionMode;
|
|
51
|
-
startedAt: number;
|
|
52
|
-
/** 根 Pi session ID(session 隔离过滤用)。 */
|
|
53
|
-
rootSessionId: string | undefined;
|
|
54
|
-
/** 直接父 subagent record ID(层级树构建用)。顶层为 undefined。 */
|
|
55
|
-
parentRecordId: string | undefined;
|
|
56
|
-
/** subagent 递归深度。顶层 = 0。 */
|
|
57
|
-
depth: number;
|
|
58
|
-
endedAt: number | undefined;
|
|
59
|
-
/** turn 计数。 */
|
|
60
|
-
turns: number;
|
|
61
|
-
totalTokens: number;
|
|
62
|
-
model: string;
|
|
63
|
-
thinkingLevel: string | undefined;
|
|
64
|
-
/** 详情事件日志(/subagents 详情面板)。 */
|
|
65
|
-
eventLog: AgentEventLogEntry[];
|
|
66
|
-
/** 从 turns[] 派生的展示项。 */
|
|
67
|
-
displayItems: DisplayItem[];
|
|
68
|
-
result?: string;
|
|
69
|
-
error?: string;
|
|
70
|
-
sessionFile?: string;
|
|
71
|
-
/** [MF#3] worktree 模式改动 patch 文件路径。 */
|
|
72
|
-
patchFile?: string;
|
|
73
|
-
/** 创建时是否启用 worktree 隔离。 */
|
|
74
|
-
worktree?: boolean;
|
|
75
|
-
/** 对话轮次计数(仅 chatMode 有意义;round+1 由轮终迁移写点携带)。 */
|
|
76
|
-
round?: number;
|
|
77
|
-
/**
|
|
78
|
-
* 对话模式标志(residual-fixes):chat 与否——GUI 侧 done/waiting 细分判据
|
|
79
|
-
* (one-shot 轮终 chatMode=false + result 有值 → 完成态)。register 起写入显式值
|
|
80
|
-
* (one-shot 为显式 false);v1 前存量 entry 缺省,消费端按保守方向处理。
|
|
81
|
-
*/
|
|
82
|
-
chatMode?: boolean;
|
|
83
|
-
/** 执行态信号(residual-fixes):true = 无活进程驱动的 running(轮终/孤儿兜底)。 */
|
|
84
|
-
resumable?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* 实际执行引擎 id(P4 路由留痕,D9①)。缺省(存量 entry)= pi 投影,消费方零迁移。
|
|
87
|
-
*/
|
|
88
|
-
engine?: string;
|
|
89
|
-
/** 引擎 fallback 留痕(probe 失败路由回默认引擎)。GUI 警告条数据源。 */
|
|
90
|
-
engineFallback?: { from: string; reason: string };
|
|
91
|
-
/**
|
|
92
|
-
* 引擎自描述定位符(U1:read 降级链①②级数据源)。引擎无关——sessionRef 整体
|
|
93
|
-
* 透传不枚举内部键(zcode = { sessionId, dbPath });缺省 = pi(存量 entry 零迁移)。
|
|
94
|
-
*/
|
|
95
|
-
engineHandle?: { sessionRef: Record<string, string>; journalPath?: string; poolKey: string };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** SubagentRecord → 自描述 entry data(快照投影,不 mutate 源)。 */
|
|
99
|
-
export function toSubagentRecordEntry(record: SubagentRecord): SubagentRecordEntryData {
|
|
100
|
-
return {
|
|
101
|
-
v: 1,
|
|
102
|
-
id: record.id,
|
|
103
|
-
agent: record.agent,
|
|
104
|
-
task: record.task,
|
|
105
|
-
slug: record.slug,
|
|
106
|
-
status: record.status,
|
|
107
|
-
closedReason: record.closedReason,
|
|
108
|
-
mode: record.mode,
|
|
109
|
-
startedAt: record.startedAt,
|
|
110
|
-
rootSessionId: record.rootSessionId,
|
|
111
|
-
parentRecordId: record.parentRecordId,
|
|
112
|
-
depth: record.depth,
|
|
113
|
-
endedAt: record.endedAt,
|
|
114
|
-
turns: record.turns,
|
|
115
|
-
totalTokens: record.totalTokens,
|
|
116
|
-
model: record.model,
|
|
117
|
-
thinkingLevel: record.thinkingLevel,
|
|
118
|
-
eventLog: record.eventLog,
|
|
119
|
-
displayItems: record.displayItems,
|
|
120
|
-
result: record.result,
|
|
121
|
-
error: record.error,
|
|
122
|
-
sessionFile: record.sessionFile,
|
|
123
|
-
patchFile: record.patchFile,
|
|
124
|
-
worktree: record.worktree,
|
|
125
|
-
round: record.round,
|
|
126
|
-
chatMode: record.chatMode,
|
|
127
|
-
resumable: record.resumable,
|
|
128
|
-
engine: record.engine,
|
|
129
|
-
engineFallback: record.engineFallback,
|
|
130
|
-
engineHandle: record.engineHandle,
|
|
131
|
-
};
|
|
132
|
-
}
|