@zhushanwen/pi-subagent-workflow 8.6.0 → 8.8.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 +5 -11
- package/package.json +13 -20
- package/relay/relay.mjs +1 -1
- package/skills/workflow-script-format/SKILL.md +32 -13
- package/src/host/__tests__/pi-host.test.ts +235 -0
- package/src/host/pi-host.ts +163 -0
- package/src/index.ts +141 -138
- package/src/injectors/__tests__/engine-awareness.test.ts +292 -0
- package/src/injectors/__tests__/engine-section-stability.test.ts +343 -0
- package/src/injectors/__tests__/model-list-injector.test.ts +18 -21
- package/src/injectors/__tests__/subagent-list-injector.test.ts +59 -19
- package/src/injectors/__tests__/workflow-list-injector.test.ts +31 -17
- package/src/injectors/engine-awareness.ts +119 -0
- package/src/injectors/model-list-injector.ts +15 -58
- package/src/injectors/subagent-list-injector.ts +56 -114
- package/src/injectors/workflow-list-injector.ts +37 -70
- package/src/interface/__tests__/detectors.test.ts +48 -37
- package/src/interface/__tests__/subagent-tool-path-guard.test.ts +2 -2
- package/src/interface/__tests__/subagent-tool-prompt.test.ts +6 -3
- package/src/interface/__tests__/tool-workflow-run-builtin-name.test.ts +216 -0
- package/src/interface/__tests__/tool-workflow-script-generate.test.ts +17 -6
- package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +38 -2
- package/src/interface/bg-notify-render.ts +7 -17
- package/src/interface/command-actions.ts +5 -15
- package/src/interface/commands.ts +4 -4
- package/src/interface/format.ts +17 -6
- package/src/interface/gui-mappers.ts +18 -22
- package/src/interface/helpers.ts +9 -130
- package/src/interface/list-component.ts +5 -5
- package/src/interface/list-shared.ts +3 -3
- package/src/interface/list-view.ts +3 -3
- package/src/interface/subagent-actions.ts +66 -439
- package/src/interface/subagent-tool-schema.ts +21 -17
- package/src/interface/subagent-tool.ts +12 -7
- package/src/interface/subagents.ts +4 -4
- package/src/interface/tool-render.ts +37 -15
- package/src/interface/tool-workflow-script.ts +34 -76
- package/src/interface/tool-workflow.ts +57 -94
- package/src/interface/views/WorkflowsView.ts +8 -16
- 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 +23 -62
- package/src/{orchestration/jsonl-run-store.ts → jsonl-run-store.ts} +137 -225
- package/agents/analyst.md +0 -61
- package/agents/coder.md +0 -70
- package/agents/debugger.md +0 -67
- package/agents/doc-reviewer.md +0 -50
- package/agents/explorer.md +0 -64
- package/agents/general-purpose.md +0 -32
- package/agents/orchestrator.md +0 -63
- package/agents/planner.md +0 -54
- package/agents/researcher.md +0 -65
- package/agents/reviewer.md +0 -74
- 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 -329
- package/src/execution/__tests__/channel-registry-handshake.test.ts +0 -243
- package/src/execution/__tests__/chat-engine-routing.test.ts +0 -601
- 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 -422
- 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 -200
- package/src/execution/__tests__/execution-record.test.ts +0 -1394
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +0 -171
- 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 -169
- 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 -242
- 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 -672
- package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
- package/src/execution/__tests__/lifecycle-manager.test.ts +0 -383
- 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 -140
- package/src/execution/__tests__/manifest-parentid.test.ts +0 -117
- package/src/execution/__tests__/model-resolver.test.ts +0 -465
- 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 -612
- package/src/execution/__tests__/notifier-golden-snapshot.test.ts +0 -261
- package/src/execution/__tests__/notify-ledger.test.ts +0 -826
- package/src/execution/__tests__/one-shot-upgrade.test.ts +0 -205
- package/src/execution/__tests__/output-collector.test.ts +0 -358
- 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 -687
- 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 -199
- 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 -350
- package/src/execution/__tests__/session-start-reaper.test.ts +0 -233
- package/src/execution/__tests__/spawn-args.test.ts +0 -445
- 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__/start-sync-model-guard.test.ts +0 -150
- 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 -599
- package/src/execution/__tests__/temp-prompt.test.ts +0 -53
- package/src/execution/__tests__/timeout-integration.test.ts +0 -615
- package/src/execution/__tests__/tombstone-store.test.ts +0 -73
- package/src/execution/__tests__/tool-action.test.ts +0 -476
- 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 -199
- package/src/execution/agent-result-mapper.ts +0 -90
- package/src/execution/alive-store.ts +0 -92
- package/src/execution/argv-mirror.ts +0 -113
- 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 -580
- 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 -658
- 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 -309
- package/src/execution/execute-options-mapper.ts +0 -112
- package/src/execution/execution-record.ts +0 -965
- 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 -513
- package/src/execution/lifecycle-predicates.ts +0 -65
- package/src/execution/manifest-store.ts +0 -256
- package/src/execution/model-config-service.ts +0 -219
- package/src/execution/model-resolver.ts +0 -248
- package/src/execution/notifier.ts +0 -330
- package/src/execution/notify-ledger.ts +0 -580
- package/src/execution/output-collector.ts +0 -228
- 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 -1781
- 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 -2141
- package/src/execution/subprocess-agent-runner.ts +0 -317
- 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 -973
- 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 -184
- 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 -349
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +0 -202
- package/src/orchestration/__tests__/agent-call-stream.test.ts +0 -152
- package/src/orchestration/__tests__/args-validator.test.ts +0 -143
- package/src/orchestration/__tests__/config-loader.test.ts +0 -503
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +0 -809
- 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 -451
- package/src/orchestration/__tests__/jsonl-run-store-corrupt-entry.test.ts +0 -150
- package/src/orchestration/__tests__/jsonl-run-store-loadall-sources.test.ts +0 -171
- package/src/orchestration/__tests__/jsonl-run-store-retention.test.ts +0 -202
- package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +0 -1030
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +0 -600
- package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +0 -96
- package/src/orchestration/__tests__/lifecycle.test.ts +0 -659
- package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +0 -95
- package/src/orchestration/__tests__/review-fix-loop-e2e.test.ts +0 -2025
- package/src/orchestration/__tests__/script-lint.test.ts +0 -831
- package/src/orchestration/__tests__/skill-discovery.test.ts +0 -201
- package/src/orchestration/__tests__/test-mocks.ts +0 -197
- package/src/orchestration/__tests__/worker-exit-without-result.test.ts +0 -368
- 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 -563
- package/src/orchestration/__tests__/worker-script-builder.test.ts +0 -309
- package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +0 -129
- 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 -174
- package/src/orchestration/args-validator.ts +0 -127
- package/src/orchestration/config-loader.ts +0 -315
- package/src/orchestration/error-recovery.ts +0 -1018
- package/src/orchestration/execute-agent-call.ts +0 -256
- package/src/orchestration/launcher.ts +0 -455
- package/src/orchestration/lifecycle.ts +0 -399
- package/src/orchestration/models/__tests__/budget.test.ts +0 -307
- 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 -118
- package/src/orchestration/models/ports.ts +0 -164
- package/src/orchestration/models/run-runtime.ts +0 -104
- 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 -301
- 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 -115
- package/src/orchestration/worker-handle.ts +0 -115
- package/src/orchestration/worker-host.ts +0 -98
- package/src/orchestration/worker-script-builder.ts +0 -421
- 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__/model-ref.test.ts +0 -306
- 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/__tests__/timer-delay.test.ts +0 -61
- 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/model-ref.ts +0 -286
- package/src/shared/resource-discovery.ts +0 -811
- package/src/shared/resource-meta.ts +0 -65
- package/src/shared/schema-env.ts +0 -44
- package/src/shared/schema-jsonify.ts +0 -58
- package/src/shared/timer-delay.ts +0 -54
- 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 -1309
- package/workflows/review-fix-loop.js +0 -1404
- package/workflows/scatter-gather.js +0 -178
|
@@ -16,11 +16,11 @@ import type { AgentToolResult, ExtensionAPI, ExtensionContext, Theme } from "@ea
|
|
|
16
16
|
import { getLogger } from "@zhushanwen/pi-extension-logger";
|
|
17
17
|
import type { Static } from "typebox";
|
|
18
18
|
|
|
19
|
-
import { getSubagentService } from "
|
|
20
|
-
import type { SubagentToolResult } from "
|
|
19
|
+
import { getSubagentService } from "@zhushanwen/subagent-core/execution/subagent-service.ts";
|
|
20
|
+
import type { SubagentToolResult } from "@zhushanwen/subagent-core/execution/types.ts";
|
|
21
21
|
import { extractAgentName } from "./format.ts";
|
|
22
22
|
import { toGuiCtx } from "./gui-mappers.ts";
|
|
23
|
-
import { adapter, cancelHandler, closeHandler, listHandler, messageHandler, startHandler } from "./subagent-actions.ts";
|
|
23
|
+
import { adapter, cancelHandler, closeHandler, forkFromHandler, listHandler, messageHandler, startHandler } from "./subagent-actions.ts";
|
|
24
24
|
import { SubagentParams } from "./subagent-tool-schema.ts";
|
|
25
25
|
import { type RenderContext,renderSubagentCall, renderSubagentResult } from "./tool-render.ts";
|
|
26
26
|
|
|
@@ -63,7 +63,7 @@ type SubagentRenderResultCb = (
|
|
|
63
63
|
// schema 常量经真实 typebox 编译校验(SW 自身 vitest 把 typebox alias 到 mock,
|
|
64
64
|
// 丢 options——required/description 断言必须以真实构造为基准)。
|
|
65
65
|
|
|
66
|
-
// extractAgentName 已上移到
|
|
66
|
+
// extractAgentName 已上移到 ./format.ts 共享(tool-render / subagent-tool 复用)。
|
|
67
67
|
|
|
68
68
|
/** exhaustiveness 承重 helper:default 分支把 action 收敛为 never,新增 action 时 tsc 报错。 */
|
|
69
69
|
function assertNever(value: never): string {
|
|
@@ -71,13 +71,14 @@ function assertNever(value: never): string {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/** Subagent action 字面量联合(与 parameters schema 的 StringEnum 取值一致)。 */
|
|
74
|
-
type SubagentAction = "start" | "list" | "cancel" | "message" | "close";
|
|
74
|
+
type SubagentAction = "start" | "list" | "cancel" | "message" | "close" | "fork-from";
|
|
75
75
|
|
|
76
76
|
/** 类型守卫:把 schema 投影出的 string 形式 action 收窄回字面量联合。
|
|
77
77
|
* typebox v1 的 StringEnum Static 退化为 string,需运行时校验 + 类型收窄
|
|
78
78
|
* 才能恢复 switch 的 exhaustiveness 约束。 */
|
|
79
79
|
function isSubagentAction(value: string): value is SubagentAction {
|
|
80
|
-
return value === "start" || value === "list" || value === "cancel" || value === "message"
|
|
80
|
+
return value === "start" || value === "list" || value === "cancel" || value === "message"
|
|
81
|
+
|| value === "close" || value === "fork-from";
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
/** unknown 是否为含 model/thinkingLevel 的对象(类型守卫,替代全可选结构 `as`)。 */
|
|
@@ -165,6 +166,7 @@ action:"list" before action:"start" — a reusable running subagent may exist; c
|
|
|
165
166
|
- action:"close" — end a running subagent and release its resources. REQUIRED closeParam: { subagentId }. Optional: force (default false; true terminates mid-round immediately). Always close when done.
|
|
166
167
|
- action:"list" — list subagents. Pass listParam: { includeFinished?, limit? } (all optional). Read an item's sessionFile for full detail.
|
|
167
168
|
- action:"cancel" — stop a background subagent (legacy verb; for conversation-mode use close). REQUIRED cancelParam: { subagentId }.
|
|
169
|
+
- action:"fork-from" — recovery for subagents disconnected by a session restart/exit: spawns a NEW subagent inheriting the old one's full history via --fork (source read-only, old record untouched). REQUIRED forkFromParam: { sourceSubagentId }. Optional: prompt (continuation instruction; handover frame injected if omitted). Returns { newSubagentId, sourceSessionFile }. Rejected with guidance: cancelled / worktree-bound / still-running sources.
|
|
168
170
|
|
|
169
171
|
## Examples
|
|
170
172
|
|
|
@@ -177,6 +179,7 @@ action:"list" before action:"start" — a reusable running subagent may exist; c
|
|
|
177
179
|
{"action":"close","closeParam":{"subagentId":"sa-550e8400"}}
|
|
178
180
|
{"action":"list","listParam":{"includeFinished":false,"limit":20}}
|
|
179
181
|
{"action":"cancel","cancelParam":{"subagentId":"sa-550e8400"}}
|
|
182
|
+
{"action":"fork-from","forkFromParam":{"sourceSubagentId":"sa-550e8400","prompt":"continue from where it stopped; verify tests first"}}
|
|
180
183
|
\`\`\`
|
|
181
184
|
|
|
182
185
|
## After launching — do NOT wait
|
|
@@ -204,7 +207,7 @@ When to use:
|
|
|
204
207
|
- ✅ Long-interval rounds (>5min apart) → conversation:true + idleTimeoutMs increased
|
|
205
208
|
- ❌ Single exploration/lookup → default (one-shot)
|
|
206
209
|
|
|
207
|
-
idleTimeoutMs: per-subagent idle timeout (default 300000 / 5min). Env XYZ_SUBAGENT_IDLE_TIMEOUT_MS sets the global default; per-call param takes precedence.
|
|
210
|
+
idleTimeoutMs: per-subagent idle timeout (default 300000 / 5min). Env XYZ_SUBAGENT_IDLE_TIMEOUT_MS sets the global default; per-call param takes precedence.
|
|
208
211
|
|
|
209
212
|
## You cannot
|
|
210
213
|
|
|
@@ -323,6 +326,8 @@ const executeSubagent: SubagentExecuteCb = async (
|
|
|
323
326
|
return adapter({ action: "message", domain: await messageHandler(service, params.messageParam) }, toGuiCtx(_ctx));
|
|
324
327
|
case "close":
|
|
325
328
|
return adapter({ action: "close", domain: await closeHandler(service, params.closeParam) }, toGuiCtx(_ctx));
|
|
329
|
+
case "fork-from":
|
|
330
|
+
return adapter({ action: "fork-from", domain: await forkFromHandler(service, params.forkFromParam) }, toGuiCtx(_ctx));
|
|
326
331
|
default:
|
|
327
332
|
// assertNever:让 exhaustiveness 成为承重约束——新增 action 时 tsc 报错,
|
|
328
333
|
// 而非悄悄落入此分支。
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/interface/subagents.ts
|
|
2
2
|
//
|
|
3
3
|
// /subagents 命令。薄壳——打开 list overlay(等同原 /subagents list [<id>])。
|
|
4
4
|
//
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
11
11
|
|
|
12
|
-
import { getSubagentService } from "
|
|
13
|
-
import type { SubagentService } from "
|
|
14
|
-
import { displayAgentName } from "
|
|
12
|
+
import { getSubagentService } from "@zhushanwen/subagent-core/execution/subagent-service.ts";
|
|
13
|
+
import type { SubagentService } from "@zhushanwen/subagent-core/execution/subagent-service.ts";
|
|
14
|
+
import { displayAgentName } from "@zhushanwen/subagent-core/shared/agent-ref.ts";
|
|
15
15
|
import { messageHandler, startHandler } from "./subagent-actions.ts";
|
|
16
16
|
import { parseSubagentRpcCommand } from "./command-actions.ts";
|
|
17
17
|
import type { SubagentRpcAction } from "./command-actions.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/interface/tool-render.ts
|
|
2
2
|
//
|
|
3
3
|
// 对话流 tool block 渲染。renderCall(标题行)+ renderResult(背景色 block)。
|
|
4
4
|
//
|
|
@@ -24,13 +24,12 @@ import type { AgentToolResult, Theme } from "@earendil-works/pi-coding-agent";
|
|
|
24
24
|
import type {
|
|
25
25
|
ListResponse,
|
|
26
26
|
SubagentToolResult,
|
|
27
|
-
} from "
|
|
28
|
-
import { displayAgentName } from "
|
|
27
|
+
} from "@zhushanwen/subagent-core/execution/types.ts";
|
|
28
|
+
import { displayAgentName } from "@zhushanwen/subagent-core/shared/agent-ref.ts";
|
|
29
29
|
import {
|
|
30
30
|
extractAgentName,
|
|
31
|
-
|
|
31
|
+
firstLineSanitized,
|
|
32
32
|
formatElapsedSeconds,
|
|
33
|
-
sanitizeLabel,
|
|
34
33
|
statusGlyph,
|
|
35
34
|
type ThemeLike,
|
|
36
35
|
truncLine,
|
|
@@ -208,6 +207,15 @@ function buildCompactLines(d: SubagentToolResult, theme: ThemeLike): string[] {
|
|
|
208
207
|
width,
|
|
209
208
|
)];
|
|
210
209
|
}
|
|
210
|
+
// ── fork-from 分支:接续确认行([v8.5 B])──
|
|
211
|
+
if (d.action === "fork-from" && d.forkFromResponse) {
|
|
212
|
+
const src = shortSessionLabel(d.forkFromResponse.sourceSessionFile);
|
|
213
|
+
return [truncLine(
|
|
214
|
+
`${theme.fg("accent", "⑂")} ${theme.fg("dim", "forked-from ")}${theme.fg("accent", src)}` +
|
|
215
|
+
` ${theme.fg("dim", "→ new: ")}${theme.fg("accent", d.subagentId ?? "?")}`,
|
|
216
|
+
width,
|
|
217
|
+
)];
|
|
218
|
+
}
|
|
211
219
|
// ── start 分支:background ──
|
|
212
220
|
if ("bgResponse" in d) {
|
|
213
221
|
return [truncLine(
|
|
@@ -234,6 +242,16 @@ function buildExpandedLines(d: SubagentToolResult, theme: ThemeLike): string[] {
|
|
|
234
242
|
width,
|
|
235
243
|
)];
|
|
236
244
|
}
|
|
245
|
+
if (d.action === "fork-from" && d.forkFromResponse) {
|
|
246
|
+
// expanded 与 compact 同形(一次性 block 无细节可展开),另附源文件完整路径行。
|
|
247
|
+
return [
|
|
248
|
+
truncLine(
|
|
249
|
+
`${theme.fg("accent", "⑂")} ${theme.fg("dim", "forked-from ")}${theme.fg("accent", d.forkFromResponse.sourceSessionFile)}` +
|
|
250
|
+
` ${theme.fg("dim", "→ new: ")}${theme.fg("accent", d.subagentId ?? "?")}`,
|
|
251
|
+
width,
|
|
252
|
+
),
|
|
253
|
+
];
|
|
254
|
+
}
|
|
237
255
|
|
|
238
256
|
const lines: string[] = [];
|
|
239
257
|
// bg 占位 expanded 与 compact 同(一次性 block 无细节可展开)
|
|
@@ -261,18 +279,31 @@ function isDetailsStructurallyComplete(d: SubagentToolResult): boolean {
|
|
|
261
279
|
return "listResponse" in d;
|
|
262
280
|
case "cancel":
|
|
263
281
|
return "cancelResponse" in d;
|
|
282
|
+
case "fork-from":
|
|
283
|
+
// [v8.5 B] 新 action 直接纳入 guard:缺内层分组才 fallback。
|
|
284
|
+
// message/close 维持历史现状(不落此 switch 显式分支,走 extractResultError
|
|
285
|
+
// 回显 content 首行)不变,避免触碰现有渲染回归面——review MF-13 曾引入
|
|
286
|
+
// message/close 显式分支后回退:无对应渲染分支却判「结构完整」会改走
|
|
287
|
+
// generic 无响应渲染,属静默行为变更。
|
|
288
|
+
return "forkFromResponse" in d;
|
|
264
289
|
default:
|
|
265
290
|
return false;
|
|
266
291
|
}
|
|
267
292
|
}
|
|
268
293
|
|
|
294
|
+
/** fork-from 渲染用的源文件短标签(basename;失败时原样返回——渲染不应抛错)。 */
|
|
295
|
+
function shortSessionLabel(file: string): string {
|
|
296
|
+
const idx = file.lastIndexOf("/");
|
|
297
|
+
return idx >= 0 ? file.slice(idx + 1) : file;
|
|
298
|
+
}
|
|
299
|
+
|
|
269
300
|
/**
|
|
270
301
|
* 从 tool result 的 content 里提取错误文本。
|
|
271
302
|
*
|
|
272
303
|
* execute 抛错(如 hub disposed / task 缺失)时,subagents handler 不 catch,
|
|
273
304
|
* Pi 框架会把 error.message 塞进 result.content[0].text。renderResult 的 fallback
|
|
274
305
|
* 分支用它把真实原因显示出来,避免只显「no details available」让 AI 盲猜。
|
|
275
|
-
* content
|
|
306
|
+
* content 可能多行,只取首行(共享 firstLineSanitized 裁断 + sanitize)。
|
|
276
307
|
*/
|
|
277
308
|
function extractResultError(content: AgentToolResult<SubagentToolResult>["content"]): string | undefined {
|
|
278
309
|
if (!Array.isArray(content)) return undefined;
|
|
@@ -290,15 +321,6 @@ function getStringText(item: unknown): string | undefined {
|
|
|
290
321
|
return typeof val === "string" && val.trim().length > 0 ? val : undefined;
|
|
291
322
|
}
|
|
292
323
|
|
|
293
|
-
/**
|
|
294
|
-
* 取文本首个非空行(多行压成首行展示),并 sanitize。
|
|
295
|
-
* 用于 done/failed 的交付物预览。
|
|
296
|
-
* 共享 firstLine(./format.ts)取首行,本 wrapper 叠加 sanitizeLabel。
|
|
297
|
-
*/
|
|
298
|
-
function firstLineSanitized(text?: string): string {
|
|
299
|
-
return sanitizeLabel(firstLine(text));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
324
|
// ============================================================
|
|
303
325
|
// list 渲染 helper(action:"list" 分支)
|
|
304
326
|
// ============================================================
|
|
@@ -10,32 +10,40 @@
|
|
|
10
10
|
* - delete: 删除脚本(前查 isRunning 防删运行中脚本)
|
|
11
11
|
* - list: 列出可用脚本(调 registry.loadAll)
|
|
12
12
|
*
|
|
13
|
+
* C5②(convergence D-6):generate 五道闸校验管线 + tmp 写盘下沉 core
|
|
14
|
+
* generateWorkflowScript(报错文案逐字平移,CA2 前提);save/delete 改调 core
|
|
15
|
+
* barrel(第三可选目录参数缺省即 pi 布局 .pi/workflows——pi 现两参调用形态零变化)。
|
|
16
|
+
* 结构化 {ok}|{error} → pi 的 execute-throw 契约转换在本层(pi 只对 execute throw
|
|
17
|
+
* 置 isError:true);AbortSignal 的 aborted 检查留宿主层(C4 偏差 #4 已声明)。
|
|
18
|
+
*
|
|
13
19
|
* 层归属:Interface。依赖 Pi SDK + engine script-lint + infra workflow-files。
|
|
14
20
|
*
|
|
15
21
|
* 参考:domain-models.md §FR-5(tool 收口 4→2)。
|
|
16
22
|
*/
|
|
17
23
|
|
|
18
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
19
|
-
import { resolve as pathResolve } from "node:path";
|
|
20
|
-
|
|
21
24
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
22
25
|
import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
23
26
|
import { Text } from "@earendil-works/pi-tui";
|
|
24
27
|
import { type Static, Type } from "typebox";
|
|
25
28
|
|
|
26
29
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
guiComponent,
|
|
31
|
+
type GuiContext,
|
|
32
|
+
type GuiRenderResult,
|
|
33
|
+
guiResult,
|
|
34
|
+
isGuiCapable,
|
|
32
35
|
} from "@xyz-agent/extension-protocol";
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import {
|
|
36
|
+
// C5②/C5⑦:创作闭环统一走 core barrel(generateWorkflowScript/saveWorkflow/
|
|
37
|
+
// deleteWorkflow/lintScript 均为 barrel 导出面;深路径在 npm/vendored 形态不可达)
|
|
38
|
+
import {
|
|
39
|
+
deleteWorkflow,
|
|
40
|
+
generateWorkflowScript,
|
|
41
|
+
lintScript,
|
|
42
|
+
saveWorkflow,
|
|
43
|
+
} from "@zhushanwen/subagent-core";
|
|
44
|
+
import type { WorkflowScriptRegistry } from "@zhushanwen/subagent-core/orchestration/models/workflow-script-registry.ts";
|
|
36
45
|
import { toGuiCtx } from "./gui-mappers.ts";
|
|
37
46
|
import { renderTextFallback } from "./views/format.ts";
|
|
38
|
-
import { parseResourceMetaDetailed } from "../shared/meta-parser.ts";
|
|
39
47
|
|
|
40
48
|
// ── Parameter schema ─────────────────────────────────────────
|
|
41
49
|
|
|
@@ -242,73 +250,23 @@ export function registerWorkflowScriptTool(
|
|
|
242
250
|
|
|
243
251
|
export function actionGenerate(params: ScriptParams, signal: AbortSignal | undefined): TextContent {
|
|
244
252
|
if (signal?.aborted) {
|
|
245
|
-
// throw(W4b):pi 只对 execute throw 置 isError:true(返回值 isError
|
|
253
|
+
// throw(W4b):pi 只对 execute throw 置 isError:true(返回值 isError 被丢弃)。
|
|
254
|
+
// AbortSignal 是 pi tool 契约层关注——core 管线不含 signal 检查,宿主自留(C4 偏差 #4)
|
|
246
255
|
throw new Error("Operation aborted before start");
|
|
247
256
|
}
|
|
248
|
-
const name = params.name;
|
|
249
|
-
const script = params.script;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
257
|
-
throw new Error(
|
|
258
|
-
"Script uses ESM 'import' syntax. Workflow scripts run in a CJS Worker — use require() instead.",
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
const hasExportMeta = /\bexport\s+const\s+meta\s*=/.test(stripped);
|
|
262
|
-
const otherExports = stripped.match(/\bexport\s+(?:const|let|var|function|default|\{)/g);
|
|
263
|
-
if (otherExports && !hasExportMeta) {
|
|
264
|
-
throw new Error(
|
|
265
|
-
"Script uses ESM 'export' (non-meta). Use 'const meta = {...}' at top level instead.",
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// 2. Validate meta declaration (/* @pi-meta */ new format preferred; legacy const meta accepted during transition — m0)
|
|
270
|
-
const hasPiMeta = /\/\*\s*@pi-meta\s*\n/.test(script);
|
|
271
|
-
const hasLegacyMeta = script.includes("const meta") || script.includes("export const meta");
|
|
272
|
-
if (!hasPiMeta && !hasLegacyMeta) {
|
|
273
|
-
throw new Error(
|
|
274
|
-
"Script must contain a meta declaration: a /* @pi-meta */ YAML block comment (preferred) or legacy const meta = { ... }. The block has the form: a block comment starting with /* @pi-meta followed by YAML (name/description/phases/parameters?/usage?), closed by */ on its own line.",
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// 3. Check agent usage
|
|
279
|
-
if (!/\bagent\s*\(/.test(stripped)) {
|
|
280
|
-
throw new Error(
|
|
281
|
-
"Script does not contain any agent() calls. A workflow must call agent() at least once.",
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// 4. Syntax check (wrap in async IIFE like runtime)
|
|
286
|
-
const cjsScript = script.replace(/\bexport\s+const\s+meta\b/, "const meta");
|
|
287
|
-
try {
|
|
288
|
-
new Function(`(async () => { ${cjsScript} })();`);
|
|
289
|
-
} catch (err: unknown) {
|
|
290
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
291
|
-
throw new Error(`Syntax error in script: ${msg}`);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// 4b. Round-trip: validate /* @pi-meta */ YAML before writing (v5 §4.7 / ERR4 — report linePos, don't write bad files)
|
|
295
|
-
if (hasPiMeta) {
|
|
296
|
-
const detailed = parseResourceMetaDetailed(script, "workflow");
|
|
297
|
-
if (!detailed.ok) {
|
|
298
|
-
const loc = "linePos" in detailed && detailed.linePos
|
|
299
|
-
? ` (line ${detailed.linePos.line}, col ${detailed.linePos.col})`
|
|
300
|
-
: "";
|
|
301
|
-
throw new Error(
|
|
302
|
-
`Generated /* @pi-meta */ YAML cannot be parsed${loc}: ${detailed.error}. Common causes: YAML indent errors, patternProperties regex must use double backslash (\\d not \d), or a stray star-slash inside the YAML body. Fix the meta block and retry.`,
|
|
303
|
-
);
|
|
304
|
-
}
|
|
257
|
+
const name = params.name ?? "";
|
|
258
|
+
const script = params.script ?? "";
|
|
259
|
+
|
|
260
|
+
// C5②:五道闸(ESM 拒/meta 必需/agent() 必需/语法/@pi-meta round-trip)+ tmp 写盘
|
|
261
|
+
// 全部在 core generateWorkflowScript(缺省 tmpDir 即 pi 布局 .pi/workflows/.tmp,
|
|
262
|
+
// 相对 cwd resolve——与旧本地实现一致)。结构化 {ok}|{error} → execute-throw 契约
|
|
263
|
+
// 转换在此(报错文案逐字平移自 pi 旧版,含 round-trip 行列信息)。
|
|
264
|
+
const result = generateWorkflowScript(name, script);
|
|
265
|
+
if (!result.ok) {
|
|
266
|
+
throw new Error(result.error);
|
|
305
267
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const tmpDir = pathResolve(".pi/workflows/.tmp");
|
|
309
|
-
mkdirSync(tmpDir, { recursive: true });
|
|
310
|
-
const filePath = pathResolve(tmpDir, `${name}.js`);
|
|
311
|
-
writeFileSync(filePath, script, "utf-8");
|
|
268
|
+
// result.ok ⇒ name/script 非空(core 对空入参返回 error)
|
|
269
|
+
const filePath = result.path;
|
|
312
270
|
|
|
313
271
|
return {
|
|
314
272
|
content: [
|
|
@@ -31,12 +31,18 @@ import {
|
|
|
31
31
|
} from "@xyz-agent/extension-protocol";
|
|
32
32
|
import { type Static, Type } from "typebox";
|
|
33
33
|
|
|
34
|
-
import { SLUG_MAX_LENGTH } from "
|
|
35
|
-
import { THINKING_ORDER } from "
|
|
36
|
-
import
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
import { SLUG_MAX_LENGTH } from "@zhushanwen/subagent-core/execution/execute-options-mapper.ts";
|
|
35
|
+
import { THINKING_ORDER } from "@zhushanwen/subagent-core/execution/model-resolver.ts";
|
|
36
|
+
import { MAX_TIMER_DELAY_MS } from "@zhushanwen/subagent-core/shared/timer-delay.ts";
|
|
37
|
+
import {
|
|
38
|
+
argKeysFromMeta,
|
|
39
|
+
findFlattenedArgKeys,
|
|
40
|
+
} from "@zhushanwen/subagent-core/orchestration/args-meta.ts";
|
|
41
|
+
import type { LauncherDeps } from "@zhushanwen/subagent-core/orchestration/launcher.ts";
|
|
42
|
+
import { abortRun, runWorkflow } from "@zhushanwen/subagent-core/orchestration/lifecycle.ts";
|
|
43
|
+
import type { RunStore } from "@zhushanwen/subagent-core/orchestration/models/ports.ts";
|
|
44
|
+
import type { WorkflowRun } from "@zhushanwen/subagent-core/orchestration/models/workflow-run.ts";
|
|
45
|
+
import { runSummary } from "@zhushanwen/subagent-core/orchestration/workflow-run-summary.ts";
|
|
40
46
|
import { mapRunIcon, mapRunStatus, toGuiCtx } from "./gui-mappers.ts";
|
|
41
47
|
import {
|
|
42
48
|
acquireReentryGuard,
|
|
@@ -63,7 +69,7 @@ const WORKFLOW_ACTIONS: readonly WorkflowAction[] = [
|
|
|
63
69
|
const WorkflowParams = Type.Object({
|
|
64
70
|
action: StringEnum(WORKFLOW_ACTIONS, { description: "Workflow action to execute" }),
|
|
65
71
|
name: Type.Optional(
|
|
66
|
-
Type.String({ description: "Workflow ref: absolute path to the .js script (use <location
|
|
72
|
+
Type.String({ description: "Workflow ref: builtin/saved workflow name from <available_workflows> (C5: run accepts names), or absolute path to the .js script (use <location>; run action)" }),
|
|
67
73
|
),
|
|
68
74
|
slug: Type.Optional(
|
|
69
75
|
Type.String({
|
|
@@ -82,7 +88,7 @@ const WorkflowParams = Type.Object({
|
|
|
82
88
|
}),
|
|
83
89
|
),
|
|
84
90
|
tokens: Type.Optional(Type.Number({ description: "Max token budget — ONLY set when user explicitly requests a limit; omit = unlimited (default)" })),
|
|
85
|
-
time: Type.Optional(Type.Number({ description:
|
|
91
|
+
time: Type.Optional(Type.Number({ description: `Max time budget in ms — ONLY set when user explicitly requests a limit; omit = unlimited (default; hard ceiling ${MAX_TIMER_DELAY_MS} ms — larger values fail fast at entry)` })),
|
|
86
92
|
error: Type.Optional(
|
|
87
93
|
Type.String({ description: "Error/reason message (optional, used with abort)" }),
|
|
88
94
|
),
|
|
@@ -105,8 +111,12 @@ const RUNID_SHORT = 8;
|
|
|
105
111
|
* tool 自身顶层键(workflow params schema 键)——workflow 参数名与 tool 键撞名时
|
|
106
112
|
* (如 workflow 声明参数 name),顶层同名键是 tool 参数而非平铺(m6 评审 M-3)。
|
|
107
113
|
* 未来新增 tool 顶层键需同步此集合。
|
|
114
|
+
*
|
|
115
|
+
* D9 下沉后作为 core args-meta 的 reservedKeys 注入(ArgMetaOptions)——core 缺省
|
|
116
|
+
* 空集,不注入则撞名保护失效(run 调用顶层必有 action/name,会被误判平铺)。
|
|
117
|
+
* export 供 detectors.test 复用同一集合防漂移。
|
|
108
118
|
*/
|
|
109
|
-
const TOOL_TOP_LEVEL = new Set([
|
|
119
|
+
export const TOOL_TOP_LEVEL = new Set([
|
|
110
120
|
"action",
|
|
111
121
|
"name",
|
|
112
122
|
"slug",
|
|
@@ -124,76 +134,11 @@ const TOOL_TOP_LEVEL = new Set([
|
|
|
124
134
|
]);
|
|
125
135
|
|
|
126
136
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* - exact:properties keys(精确匹配)
|
|
131
|
-
* - patterns:patternProperties 原样转正则数组(如 /^batch\\d+$/——与旧
|
|
132
|
-
* KNOWN_ARG_KEY_PREFIXES 语义一致,自动兼容 \\d{2} 等变体;schema pattern 已是
|
|
133
|
-
* 正则源码,直接 new RegExp 即可)
|
|
134
|
-
* - 构建时排除 TOOL_TOP_LEVEL(撞名保护)
|
|
137
|
+
* core args-meta 的宿主差异注入项(D9 下沉):reservedKeys = TOOL_TOP_LEVEL。
|
|
138
|
+
* core 版 argKeysFromMeta / findFlattenedArgKeys 缺省 reservedKeys 为空集(core
|
|
139
|
+
* 中性形态),不传此项则失去撞名保护、行为不等值——调用点必须携带(等值契约)。
|
|
135
140
|
*/
|
|
136
|
-
|
|
137
|
-
parameters: Record<string, unknown> | undefined,
|
|
138
|
-
): { exact: ReadonlySet<string>; patterns: readonly RegExp[] } {
|
|
139
|
-
const exact = new Set<string>();
|
|
140
|
-
const patterns: RegExp[] = [];
|
|
141
|
-
if (parameters === undefined || parameters === null || typeof parameters !== "object") {
|
|
142
|
-
return { exact, patterns };
|
|
143
|
-
}
|
|
144
|
-
const props = parameters.properties;
|
|
145
|
-
if (props !== null && typeof props === "object") {
|
|
146
|
-
for (const k of Object.keys(props as Record<string, unknown>)) {
|
|
147
|
-
if (!TOOL_TOP_LEVEL.has(k)) exact.add(k);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const pp = parameters.patternProperties;
|
|
151
|
-
if (pp !== null && typeof pp === "object") {
|
|
152
|
-
for (const p of Object.keys(pp as Record<string, unknown>)) {
|
|
153
|
-
try {
|
|
154
|
-
const re = new RegExp(p); // schema pattern 已是正则源码
|
|
155
|
-
// S1(m6 exec-review):跳过能命中 tool 顶层键的 pattern——否则
|
|
156
|
-
// ^run.*$ 类 pattern 会匹配 runId/name 等 tool 键,合法调用恒误报
|
|
157
|
-
if ([...TOOL_TOP_LEVEL].some((tk) => re.test(tk))) continue;
|
|
158
|
-
patterns.push(re);
|
|
159
|
-
} catch (err) {
|
|
160
|
-
// 非法 pattern(schema 校验 m3 已保证合法,双保险)——跳过并记录
|
|
161
|
-
logger.warn(`[tool-workflow] patternProperties 非法正则跳过: ${p}`, {
|
|
162
|
-
reason: err instanceof Error ? err.message : String(err),
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return { exact, patterns };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 检测弱模型把 args 子字段平铺到 workflow params 顶层(P0 静默失败防护)。
|
|
172
|
-
* 返回被平铺的键名列表(空 = 未平铺)。export 供 behavioral 测试(trigger/no-trigger/edge)。
|
|
173
|
-
* 参数取 unknown 以便测试构造任意对象、并解耦 WorkflowToolParams 的 index-signature 限制。
|
|
174
|
-
*
|
|
175
|
-
* knownKeys/knownPatterns 由 argKeysFromMeta 动态构建(m6)——匹配谓词:
|
|
176
|
-
* knownKeys.has(k) || knownPatterns.some(re => re.test(k))(pattern 自带数字后缀
|
|
177
|
-
* 语义——loose startsWith 会误报 batchl/target1);保留 args-排除(顶层 + args
|
|
178
|
-
* 内共存不算平铺)。
|
|
179
|
-
*/
|
|
180
|
-
export function findFlattenedArgKeys(
|
|
181
|
-
params: unknown,
|
|
182
|
-
knownKeys: ReadonlySet<string>,
|
|
183
|
-
knownPatterns: readonly RegExp[],
|
|
184
|
-
): string[] {
|
|
185
|
-
if (typeof params !== "object" || params === null) return [];
|
|
186
|
-
const p = params as Record<string, unknown>;
|
|
187
|
-
const args = typeof p.args === "object" && p.args !== null ? p.args : undefined;
|
|
188
|
-
const isKnownKey = (k: string) =>
|
|
189
|
-
knownKeys.has(k) || knownPatterns.some((re) => re.test(k));
|
|
190
|
-
// hasOwnProperty.call 而非 in(原型链——constructor/toString 类参数名不被继承键掩盖)
|
|
191
|
-
return Object.keys(p).filter(
|
|
192
|
-
(k) =>
|
|
193
|
-
isKnownKey(k) &&
|
|
194
|
-
!(args !== undefined && Object.prototype.hasOwnProperty.call(args, k)),
|
|
195
|
-
);
|
|
196
|
-
}
|
|
141
|
+
const ARGS_META_OPTIONS = { reservedKeys: TOOL_TOP_LEVEL };
|
|
197
142
|
|
|
198
143
|
// ── Types ────────────────────────────────────────────────────
|
|
199
144
|
|
|
@@ -321,7 +266,7 @@ export function registerWorkflowTool(
|
|
|
321
266
|
"<available_workflows> (injected each turn). For parameter details, read the <location> " +
|
|
322
267
|
"script file (script header has @pi-meta parameters + usage + phases). Do NOT use " +
|
|
323
268
|
"workflow-script generate for patterns already covered by available workflows.",
|
|
324
|
-
"run: pass the absolute .js path from <available_workflows>
|
|
269
|
+
"run: pass the workflow ref as name — the listed <name> (builtin/saved workflow) or its <location> absolute .js path from <available_workflows> — then start in background (no user confirmation needed).",
|
|
325
270
|
"Do NOT poll status after starting — results appear automatically via notifyDone.",
|
|
326
271
|
"Runs are one-shot: there is no pause/resume — to stop a run early use abort; for a fresh result start a new run.",
|
|
327
272
|
"Call shapes (JSON): " +
|
|
@@ -425,7 +370,17 @@ export async function actionRun(
|
|
|
425
370
|
// 顶层(缺 args 嵌套)。args ?? {} 会静默 args={},启动缺参 run 不报错——比 subagent
|
|
426
371
|
// 平铺事故更严重。m6:先 registry.getPath(动态参数集来源——schema 即 SSOT),
|
|
427
372
|
// not_found 优先返回;平铺检测报错带 Correct 正例纠正。
|
|
428
|
-
|
|
373
|
+
//
|
|
374
|
+
// C5③(convergence D-4 pi 半边):name 解析先查内置/已保存 workflow 名
|
|
375
|
+
// (registry.get——内置 chain/parallel/map-reduce/scatter-gather/review-fix-loop 或
|
|
376
|
+
// 用户 project/user 级脚本名,按 tmp>project>user>npm 优先级合并)——内置名命中
|
|
377
|
+
// 直接用内置脚本;未命中再走 getPath(绝对路径,~/ 展开——normalizeRef 既有)。
|
|
378
|
+
// 严格超集:现有路径用法零变化(路径串不会撞 workflow 名——名字是简单标识符),
|
|
379
|
+
// 两者都未命中仍走原 not_found 报错(建议清单不变)。
|
|
380
|
+
let script = await deps.registry.get(name);
|
|
381
|
+
if (!script) {
|
|
382
|
+
script = await deps.registry.getPath(name);
|
|
383
|
+
}
|
|
429
384
|
// W4c:config-loader 的 toCachedMeta 对不可读/不存在文件返回 available:false 的
|
|
430
385
|
// stub(非 undefined),仅判 !script 会绕过 not_found → 空 sourceCode 假启动
|
|
431
386
|
//(W4b verifier 探针实测复现)。与下方 suggestions 分支的 wf.available 过滤口径对齐。
|
|
@@ -444,7 +399,10 @@ export async function actionRun(
|
|
|
444
399
|
|
|
445
400
|
// m6:动态参数集(schema 即 SSOT)→ 平铺检测;无 parameters → 单次 warn + 跳过
|
|
446
401
|
// (legacy const-meta 类永久无检测——D1 无 adapter 声明)
|
|
447
|
-
const { exact: knownKeys, patterns: knownPatterns } = argKeysFromMeta(
|
|
402
|
+
const { exact: knownKeys, patterns: knownPatterns } = argKeysFromMeta(
|
|
403
|
+
script.meta.parameters,
|
|
404
|
+
ARGS_META_OPTIONS,
|
|
405
|
+
);
|
|
448
406
|
if (knownKeys.size === 0 && knownPatterns.length === 0) {
|
|
449
407
|
// M-2 显式信号:无参数契约(未声明/解析空)→ 单次 warn——静默退化变显式
|
|
450
408
|
// (m6 exec-review M1:原实现排除 undefined 与设计相反)
|
|
@@ -452,7 +410,9 @@ export async function actionRun(
|
|
|
452
410
|
`[tool-workflow] ${script.name}: 未声明参数契约(或解析为空)——平铺检测跳过,args 不校验`,
|
|
453
411
|
);
|
|
454
412
|
}
|
|
455
|
-
|
|
413
|
+
// core 版接收 meta 内联构建键集(签名与本地版键集三参不同,判定谓词逐字同源)——
|
|
414
|
+
// 键集构建两次(此处 + core 内部)仅为 M-2 空契约信号,成本每 run 一次可忽略
|
|
415
|
+
const flattened = findFlattenedArgKeys(params, script.meta.parameters, ARGS_META_OPTIONS);
|
|
456
416
|
if (flattened.length > 0) {
|
|
457
417
|
throw new Error(
|
|
458
418
|
`Detected ${flattened.join(", ")} at top level — they belong inside 'args'. ` +
|
|
@@ -468,6 +428,16 @@ export async function actionRun(
|
|
|
468
428
|
const args = params.args ?? {};
|
|
469
429
|
const tokens = params.tokens;
|
|
470
430
|
const time = params.time;
|
|
431
|
+
// OR-1 入口 fail-fast(unbounded-wait-audit §7.2 T3①):schema 的 time 是
|
|
432
|
+
// Type.Number 直通(无上界)——超 setTimeout 安全域的值会穿透到 lifecycle 内层
|
|
433
|
+
// 防线(assertSafeTimerDelay),而入口拦截让它永不进入副作用链。错误带合法上限
|
|
434
|
+
// 与实际传入值,LLM 可据消息自纠(clamp 或省略走 unlimited 语义)。
|
|
435
|
+
if (time !== undefined && time > MAX_TIMER_DELAY_MS) {
|
|
436
|
+
throw new Error(
|
|
437
|
+
`time budget ${time} ms exceeds the maximum of ${MAX_TIMER_DELAY_MS} ms (~24.8 days). ` +
|
|
438
|
+
`Retry with a smaller "time", or omit it for unlimited.`,
|
|
439
|
+
);
|
|
440
|
+
}
|
|
471
441
|
|
|
472
442
|
// 构建 RunSpec + 启动(m3:parameters 从 script.meta 拷贝——chokepoint 校验用;
|
|
473
443
|
// 校验失败 → ArgsValidationError 直接 throw 给 pi(W4:err.message 含 §5.3 指引,
|
|
@@ -568,19 +538,12 @@ async function actionLifecycle(
|
|
|
568
538
|
|
|
569
539
|
// ── helpers ──────────────────────────────────────────────────
|
|
570
540
|
|
|
571
|
-
/** WorkflowRun → 摘要(status action
|
|
541
|
+
/** WorkflowRun → 摘要(status action 用):core runSummary 单源投影 + 宿主扩展 stateFile。
|
|
542
|
+
*
|
|
543
|
+
* 字段集不再本地维护(runSummary 双投影分叉的收口点,D8/B5);stateFile 依赖
|
|
544
|
+
* RunStore 实例,属宿主扩展——core 投影刻意不依赖具体 store。 */
|
|
572
545
|
function toRunSummary(run: WorkflowRun, store: RunStore): RunSummary {
|
|
573
|
-
return {
|
|
574
|
-
runId: run.runId,
|
|
575
|
-
name: run.spec.scriptName,
|
|
576
|
-
slug: run.spec.slug,
|
|
577
|
-
status: run.state.status,
|
|
578
|
-
reason: run.state.reason,
|
|
579
|
-
startedAt: run.meta.startedAt,
|
|
580
|
-
completedAt: run.meta.completedAt,
|
|
581
|
-
error: run.state.error,
|
|
582
|
-
stateFile: store.stateFilePath(run.runId),
|
|
583
|
-
};
|
|
546
|
+
return { ...runSummary(run), stateFile: store.stateFilePath(run.runId) };
|
|
584
547
|
}
|
|
585
548
|
|
|
586
549
|
// W4b:原 textResult(text, isError) helper 已删除——23 处错误路径全部改 throw
|
|
@@ -33,11 +33,11 @@ import {
|
|
|
33
33
|
countAllToolCalls,
|
|
34
34
|
getAllToolCalls,
|
|
35
35
|
projectLiveProgress,
|
|
36
|
-
} from "
|
|
37
|
-
import type { ExecutionTraceNode } from "
|
|
38
|
-
import type { WorkflowRun } from "
|
|
39
|
-
import { saveWorkflow } from "
|
|
40
|
-
import { displayAgentName } from "
|
|
36
|
+
} from "@zhushanwen/subagent-core/execution/execution-record.ts";
|
|
37
|
+
import type { ExecutionTraceNode } from "@zhushanwen/subagent-core/orchestration/models/types.ts";
|
|
38
|
+
import type { WorkflowRun } from "@zhushanwen/subagent-core/orchestration/models/workflow-run.ts";
|
|
39
|
+
import { saveWorkflow } from "@zhushanwen/subagent-core/orchestration/workflow-files.ts";
|
|
40
|
+
import { displayAgentName } from "@zhushanwen/subagent-core/shared/agent-ref.ts";
|
|
41
41
|
import {
|
|
42
42
|
BOX_BORDER_CHARS,
|
|
43
43
|
BUDGET_TOKENS_DIVISOR,
|
|
@@ -57,16 +57,8 @@ import {
|
|
|
57
57
|
visibleLen,
|
|
58
58
|
} from "./format.ts";
|
|
59
59
|
|
|
60
|
-
// L2 详情内容构建 + 滚动按键(纯函数)抽到 detail-content.ts
|
|
61
|
-
|
|
62
|
-
export {
|
|
63
|
-
buildDetailContent,
|
|
64
|
-
detailContentLength,
|
|
65
|
-
type DetailKeyResult,
|
|
66
|
-
type DetailScrollContext,
|
|
67
|
-
processDetailKey,
|
|
68
|
-
} from "./detail-content.ts";
|
|
69
|
-
import { buildDetailContent, detailContentLength, type DetailScrollContext,processDetailKey } from "./detail-content.ts";
|
|
60
|
+
// L2 详情内容构建 + 滚动按键(纯函数)抽到 detail-content.ts(view 与其测试直接 import)。
|
|
61
|
+
import { buildDetailContent, detailContentLength, type DetailScrollContext, processDetailKey } from "./detail-content.ts";
|
|
70
62
|
|
|
71
63
|
// ── TUI layout constants ──────────────────────────────────────
|
|
72
64
|
|
|
@@ -93,7 +85,7 @@ const PRINTABLE_CHAR_MIN = 32;
|
|
|
93
85
|
function b(theme: ThemeLike, s: string): string {
|
|
94
86
|
return theme.fg("borderMuted", s);
|
|
95
87
|
}
|
|
96
|
-
/** 着色单字符填充用的
|
|
88
|
+
/** 着色单字符填充用的 ─(本文件 dashes() 满宽填充复用)。 */
|
|
97
89
|
function dash(theme: ThemeLike): string {
|
|
98
90
|
return theme.fg("borderMuted", "─");
|
|
99
91
|
}
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
14
14
|
|
|
15
15
|
import { computeRenderSignature } from "../WorkflowsView.ts";
|
|
16
|
-
import type { ExecutionRecord } from "
|
|
17
|
-
import type { ExecutionTraceNode, WorkerLogEntry } from "
|
|
18
|
-
import type { WorkflowRun } from "
|
|
16
|
+
import type { ExecutionRecord } from "@zhushanwen/subagent-core/execution/types.ts";
|
|
17
|
+
import type { ExecutionTraceNode, WorkerLogEntry } from "@zhushanwen/subagent-core/orchestration/models/types.ts";
|
|
18
|
+
import type { WorkflowRun } from "@zhushanwen/subagent-core/orchestration/models/workflow-run.ts";
|
|
19
19
|
|
|
20
20
|
// ── Fixtures(duck typing,对齐 detail-content-session-file.test.ts 先例)──
|
|
21
21
|
|
|
@@ -9,8 +9,8 @@ import { describe, expect, it } from "vitest";
|
|
|
9
9
|
|
|
10
10
|
import { buildDetailContent } from "../detail-content.ts";
|
|
11
11
|
import type { ThemeLike } from "../format.ts";
|
|
12
|
-
import type { ExecutionTraceNode } from "
|
|
13
|
-
import type { WorkflowRun } from "
|
|
12
|
+
import type { ExecutionTraceNode } from "@zhushanwen/subagent-core/orchestration/models/types.ts";
|
|
13
|
+
import type { WorkflowRun } from "@zhushanwen/subagent-core/orchestration/models/workflow-run.ts";
|
|
14
14
|
|
|
15
15
|
/** plain theme: fg/bold 直接返回原文,无 ANSI 色码——测试断言纯文本。 */
|
|
16
16
|
const plainTheme: ThemeLike = {
|