@selesai/code 0.13.0 → 0.13.2
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/CHANGELOG.md +22 -0
- package/dist/core/agent-session.d.ts +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.js +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/extensions/package.json +1 -2
- package/dist/extensions/pi-hermes-memory/CHANGELOG.md +371 -0
- package/dist/extensions/pi-hermes-memory/LICENSE +21 -0
- package/dist/extensions/pi-hermes-memory/README.md +643 -0
- package/dist/extensions/pi-hermes-memory/docs/0.1/TASKS.md +197 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/PLAN.md +290 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/TASKS.md +134 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/TEST-PLAN.md +216 -0
- package/dist/extensions/pi-hermes-memory/docs/0.3/PLAN.md +330 -0
- package/dist/extensions/pi-hermes-memory/docs/0.3/TASKS.md +125 -0
- package/dist/extensions/pi-hermes-memory/docs/0.4/PLAN.md +160 -0
- package/dist/extensions/pi-hermes-memory/docs/0.4/TASKS.md +113 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/CHANGELOG.md +57 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/PLAN.md +202 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/TASKS.md +144 -0
- package/dist/extensions/pi-hermes-memory/docs/0.7/PLAN.md +349 -0
- package/dist/extensions/pi-hermes-memory/docs/0.7/TASKS.md +110 -0
- package/dist/extensions/pi-hermes-memory/docs/PUBLISHING.md +149 -0
- package/dist/extensions/pi-hermes-memory/docs/ROADMAP.md +468 -0
- package/dist/extensions/pi-hermes-memory/docs/images/memory-architecture.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi-logo.svg +22 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.png +0 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.svg +19 -0
- package/dist/extensions/pi-hermes-memory/docs/images/security-flow.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/session-lifecycle.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/source-architecture.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/memory-architecture.mmd +49 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/security-flow.mmd +40 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/session-lifecycle.mmd +56 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/source-architecture.mmd +54 -0
- package/dist/extensions/pi-hermes-memory/package-lock.json +3799 -0
- package/dist/extensions/pi-hermes-memory/package.json +66 -0
- package/dist/extensions/pi-hermes-memory/scripts/check-min-sdk.mjs +99 -0
- package/dist/extensions/pi-hermes-memory/scripts/ensure-dev.mjs +57 -0
- package/dist/extensions/pi-hermes-memory/src/auto-consolidation-warning.ts +6 -0
- package/dist/extensions/pi-hermes-memory/src/config.ts +178 -0
- package/dist/extensions/pi-hermes-memory/src/constants.ts +424 -0
- package/dist/extensions/pi-hermes-memory/src/extension-root-migration.ts +639 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/auto-consolidate.ts +401 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/background-review.ts +297 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/child-process-watchdog.mjs +90 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/correction-detector.ts +300 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/index-sessions.ts +86 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/insights.ts +78 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/interview.ts +37 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/learn-memory.ts +186 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/message-parts.ts +27 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/pi-child-process.ts +485 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/preview-context.ts +105 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/review-memory-ops.ts +506 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-backfill.ts +145 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-flush.ts +151 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-live-index.ts +94 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/skills-command.ts +1334 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/standing-pin.ts +111 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/switch-project.ts +75 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/sync-markdown-memories.ts +266 -0
- package/dist/extensions/pi-hermes-memory/src/index.ts +378 -0
- package/dist/extensions/pi-hermes-memory/src/lifecycle-timing.ts +54 -0
- package/dist/extensions/pi-hermes-memory/src/paths.ts +61 -0
- package/dist/extensions/pi-hermes-memory/src/project-context.ts +13 -0
- package/dist/extensions/pi-hermes-memory/src/project-memory-migration.ts +93 -0
- package/dist/extensions/pi-hermes-memory/src/project.ts +157 -0
- package/dist/extensions/pi-hermes-memory/src/prompt-context.ts +55 -0
- package/dist/extensions/pi-hermes-memory/src/store/atomic-lock-coordinator.ts +375 -0
- package/dist/extensions/pi-hermes-memory/src/store/canonical-storage-path.ts +54 -0
- package/dist/extensions/pi-hermes-memory/src/store/content-scanner.ts +101 -0
- package/dist/extensions/pi-hermes-memory/src/store/db.ts +1180 -0
- package/dist/extensions/pi-hermes-memory/src/store/fts-query.ts +101 -0
- package/dist/extensions/pi-hermes-memory/src/store/markdown-mutation-lock.ts +38 -0
- package/dist/extensions/pi-hermes-memory/src/store/memory-lookup.ts +24 -0
- package/dist/extensions/pi-hermes-memory/src/store/memory-store.ts +1191 -0
- package/dist/extensions/pi-hermes-memory/src/store/recovery-maintenance.ts +66 -0
- package/dist/extensions/pi-hermes-memory/src/store/schema.ts +118 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-anchor-search.ts +472 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-indexer.ts +511 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-parser.ts +213 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-search.ts +234 -0
- package/dist/extensions/pi-hermes-memory/src/store/skill-store.ts +950 -0
- package/dist/extensions/pi-hermes-memory/src/store/skill-utils.ts +133 -0
- package/dist/extensions/pi-hermes-memory/src/store/sqlite-memory-store.ts +1002 -0
- package/dist/extensions/pi-hermes-memory/src/store/sqlite-native.ts +241 -0
- package/dist/extensions/pi-hermes-memory/src/store/standing-instructions.ts +247 -0
- package/dist/extensions/pi-hermes-memory/src/tools/memory-search-tool.ts +95 -0
- package/dist/extensions/pi-hermes-memory/src/tools/memory-tool.ts +469 -0
- package/dist/extensions/pi-hermes-memory/src/tools/session-search-tool.ts +246 -0
- package/dist/extensions/pi-hermes-memory/src/tools/shared-output-view.ts +170 -0
- package/dist/extensions/pi-hermes-memory/src/tools/skill-tool.ts +333 -0
- package/dist/extensions/pi-hermes-memory/src/tools/tool-result-views.ts +105 -0
- package/dist/extensions/pi-hermes-memory/src/types.ts +214 -0
- package/dist/extensions/pi-hermes-memory/tests/config.test.ts +434 -0
- package/dist/extensions/pi-hermes-memory/tests/extension-root-migration.test.ts +368 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/auto-consolidate.test.ts +984 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/background-review.test.ts +950 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/correction-detector.test.ts +671 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/insights.test.ts +157 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/interview.test.ts +127 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/pi-child-process.test.ts +905 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/preview-context.test.ts +152 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/prompt-context.test.ts +166 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/resources-discover.test.ts +71 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/review-memory-ops.test.ts +614 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-backfill.test.ts +192 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-flush.test.ts +677 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-live-index.test.ts +225 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/skills-command.test.ts +827 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/standing-pin.test.ts +134 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/sync-markdown-memories.test.ts +491 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/system-prompt.test.ts +199 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/thinking-max.test.ts +64 -0
- package/dist/extensions/pi-hermes-memory/tests/index.test.ts +30 -0
- package/dist/extensions/pi-hermes-memory/tests/integration/flow.test.ts +126 -0
- package/dist/extensions/pi-hermes-memory/tests/lifecycle-timing.test.ts +76 -0
- package/dist/extensions/pi-hermes-memory/tests/paths.test.ts +23 -0
- package/dist/extensions/pi-hermes-memory/tests/project-memory-migration.test.ts +80 -0
- package/dist/extensions/pi-hermes-memory/tests/project-rebinding.test.ts +115 -0
- package/dist/extensions/pi-hermes-memory/tests/project.test.ts +120 -0
- package/dist/extensions/pi-hermes-memory/tests/run-all-timeout.test.ts +107 -0
- package/dist/extensions/pi-hermes-memory/tests/run-all.sh +45 -0
- package/dist/extensions/pi-hermes-memory/tests/store/atomic-lock-coordinator.test.ts +381 -0
- package/dist/extensions/pi-hermes-memory/tests/store/content-scanner.test.ts +388 -0
- package/dist/extensions/pi-hermes-memory/tests/store/db.test.ts +1046 -0
- package/dist/extensions/pi-hermes-memory/tests/store/markdown-mutation-lock.test.ts +34 -0
- package/dist/extensions/pi-hermes-memory/tests/store/memory-store.test.ts +2150 -0
- package/dist/extensions/pi-hermes-memory/tests/store/recovery-maintenance.test.ts +170 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-anchor-search.test.ts +210 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-indexer.test.ts +643 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-parser.test.ts +282 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-search.test.ts +287 -0
- package/dist/extensions/pi-hermes-memory/tests/store/skill-store.test.ts +678 -0
- package/dist/extensions/pi-hermes-memory/tests/store/skill-utils.test.ts +21 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-lazy-load.test.ts +78 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-memory-store.test.ts +543 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-native.test.ts +164 -0
- package/dist/extensions/pi-hermes-memory/tests/store/standing-instructions.test.ts +171 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-search-tool.test.ts +84 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-tool.test.ts +709 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/session-search-tool.test.ts +345 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/shared-output-view.test.ts +362 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/skill-tool.test.ts +478 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/tool-result-renderer-wiring.test.ts +40 -0
- package/dist/extensions/pi-hermes-memory/tsconfig.json +19 -0
- package/dist/extensions/pi-rewind-hook/README.md +4 -1
- package/dist/extensions/pi-rewind-hook/index.ts +151 -21
- package/dist/extensions/pi-rewind-hook/package.json +5 -3
- package/dist/extensions/pi-subagents/.oxlintrc.json +43 -0
- package/dist/extensions/pi-subagents/AGENTS.md +5 -0
- package/dist/extensions/pi-subagents/CHANGELOG.md +157 -0
- package/dist/extensions/pi-subagents/README.md +12 -6
- package/dist/extensions/pi-subagents/VISION.md +81 -0
- package/dist/extensions/pi-subagents/agents/claude-code-writer.md +15 -0
- package/dist/extensions/pi-subagents/agents/claude-code.md +15 -0
- package/dist/extensions/pi-subagents/agents/codex-exec-writer.md +15 -0
- package/dist/extensions/pi-subagents/agents/codex-exec.md +15 -0
- package/dist/extensions/pi-subagents/agents/cursor-agent-writer.md +14 -0
- package/dist/extensions/pi-subagents/agents/cursor-agent.md +14 -0
- package/dist/extensions/pi-subagents/agents/reviewer.md +1 -3
- package/dist/extensions/pi-subagents/docs/agents.md +488 -0
- package/dist/extensions/pi-subagents/docs/configuration.md +46 -9
- package/dist/extensions/pi-subagents/docs/extension-api.md +42 -3
- package/dist/extensions/pi-subagents/docs/models.md +27 -4
- package/dist/extensions/pi-subagents/docs/observability.md +10 -9
- package/dist/extensions/pi-subagents/docs/tool-reference.md +102 -6
- package/dist/extensions/pi-subagents/docs/workflows.md +135 -0
- package/dist/extensions/pi-subagents/package-lock.json +389 -2
- package/dist/extensions/pi-subagents/package.json +3 -1
- package/dist/extensions/pi-subagents/prompts/review-loop.md +2 -2
- package/dist/extensions/pi-subagents/skills/council-mode/SKILL.md +1 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +3 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md +7 -3
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/prompting-and-roles.md +26 -5
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +41 -22
- package/dist/extensions/pi-subagents/src/agents/agent-refinements.ts +4 -4
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +9 -2
- package/dist/extensions/pi-subagents/src/agents/agents.ts +322 -75
- package/dist/extensions/pi-subagents/src/agents/builtin-names.ts +6 -0
- package/dist/extensions/pi-subagents/src/agents/runtime-agent-events.ts +70 -0
- package/dist/extensions/pi-subagents/src/agents/runtime-agent-registry.ts +27 -20
- package/dist/extensions/pi-subagents/src/api/agents.ts +10 -5
- package/dist/extensions/pi-subagents/src/api/background-work.ts +5 -1
- package/dist/extensions/pi-subagents/src/api/delegation.ts +0 -7
- package/dist/extensions/pi-subagents/src/api/preflight.ts +34 -12
- package/dist/extensions/pi-subagents/src/extension/config.ts +70 -0
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +3 -3
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +5 -3
- package/dist/extensions/pi-subagents/src/extension/index.ts +83 -30
- package/dist/extensions/pi-subagents/src/extension/public-execution.ts +44 -15
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +55 -19
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +41 -15
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -31
- package/dist/extensions/pi-subagents/src/inspectors/herdr/actions.ts +2 -1
- package/dist/extensions/pi-subagents/src/inspectors/herdr/inspector-runner.ts +2 -10
- package/dist/extensions/pi-subagents/src/inspectors/herdr/session-roots-codec.ts +42 -0
- package/dist/extensions/pi-subagents/src/integrations/herdr-status.ts +51 -7
- package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +2 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +5 -6
- package/dist/extensions/pi-subagents/src/runs/background/active-async-capacity.ts +77 -10
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +176 -53
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +19 -12
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +29 -27
- package/dist/extensions/pi-subagents/src/runs/background/async-retention.ts +20 -3
- package/dist/extensions/pi-subagents/src/runs/background/async-status-snapshot.ts +23 -261
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +73 -7
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +8 -3
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +74 -8
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +37 -21
- package/dist/extensions/pi-subagents/src/runs/background/inspect-rpc.ts +8 -8
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +184 -9
- package/dist/extensions/pi-subagents/src/runs/background/result-delivery-ownership.ts +45 -0
- package/dist/extensions/pi-subagents/src/runs/background/result-files.ts +28 -14
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +38 -15
- package/dist/extensions/pi-subagents/src/runs/background/resume-guidance.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/retained-children.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +50 -13
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +93 -8
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +10 -4
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +4 -14
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +549 -377
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +58 -10
- package/dist/extensions/pi-subagents/src/runs/background/terminal-run-index.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-completions.ts +26 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +23 -9
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +9 -2
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +2 -2
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +204 -129
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +9 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-history.ts +23 -1
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +773 -311
- package/dist/extensions/pi-subagents/src/runs/foreground/workflow-detach-reconcile.ts +140 -115
- package/dist/extensions/pi-subagents/src/runs/shared/abort-recovery.ts +119 -0
- package/dist/extensions/pi-subagents/src/runs/shared/async-status-projection.ts +463 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-identity.ts +19 -4
- package/dist/extensions/pi-subagents/src/runs/shared/child-launch-plan.ts +151 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +21 -7
- package/dist/extensions/pi-subagents/src/runs/shared/claude-code-adapter.ts +129 -0
- package/dist/extensions/pi-subagents/src/runs/shared/codex-exec-adapter.ts +129 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-evidence.ts +89 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +5 -4
- package/dist/extensions/pi-subagents/src/runs/shared/cursor-agent-adapter.ts +114 -0
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +3 -3
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-contract.ts +167 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-preflight.ts +122 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-runner.ts +348 -55
- package/dist/extensions/pi-subagents/src/runs/shared/fast-mode-extension.ts +5 -5
- package/dist/extensions/pi-subagents/src/runs/shared/host-step-status.ts +230 -0
- package/dist/extensions/pi-subagents/src/runs/shared/lane-metadata.ts +105 -0
- package/dist/extensions/pi-subagents/src/runs/shared/launch-cwd.ts +16 -0
- package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-config-sources.ts +422 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +221 -158
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-grant.ts +197 -0
- package/dist/extensions/pi-subagents/src/runs/shared/model-exclusions.ts +69 -7
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +47 -6
- package/dist/extensions/pi-subagents/src/runs/shared/mutation-evidence.ts +7 -2
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +9 -3
- package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +9 -5
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +419 -7
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +15 -1
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +81 -8
- package/dist/extensions/pi-subagents/src/runs/shared/process-signal.ts +13 -0
- package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +21 -1
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +44 -4
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +98 -13
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-startup-retry.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/shared/worktree-cleanup-plan.ts +847 -0
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +18 -0
- package/dist/extensions/pi-subagents/src/shared/child-session-name.ts +46 -0
- package/dist/extensions/pi-subagents/src/shared/extension-context.ts +24 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +21 -0
- package/dist/extensions/pi-subagents/src/shared/formatters.ts +18 -3
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +5 -1
- package/dist/extensions/pi-subagents/src/shared/pruned-fork.ts +450 -0
- package/dist/extensions/pi-subagents/src/shared/session-file-trust.ts +19 -0
- package/dist/extensions/pi-subagents/src/shared/session-tokens.ts +14 -3
- package/dist/extensions/pi-subagents/src/shared/settings.ts +19 -105
- package/dist/extensions/pi-subagents/src/shared/shortcuts.ts +17 -0
- package/dist/extensions/pi-subagents/src/shared/types.ts +359 -40
- package/dist/extensions/pi-subagents/src/shared/utils.ts +41 -84
- package/dist/extensions/pi-subagents/src/shared/workflow-child-permit.ts +116 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +1 -9
- package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +0 -4
- package/dist/extensions/pi-subagents/src/slash/slash-bridge.ts +1 -2
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +378 -88
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +22 -11
- package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +3 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +147 -79
- package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +11 -5
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +39 -18
- package/dist/extensions/pi-subagents/src/tui/render.ts +369 -46
- package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +1 -1
- package/dist/extensions/pi-subagents/src/workflows/chat-progress.ts +6 -3
- package/dist/extensions/pi-subagents/src/workflows/host-command.ts +230 -0
- package/dist/extensions/pi-subagents/src/workflows/scripted-workflow.ts +740 -58
- package/dist/extensions/pi-subagents/src/workflows/workflow-child-summary.ts +121 -0
- package/dist/extensions/pi-subagents/src/workflows/workflow-preflight.ts +270 -0
- package/dist/extensions/pi-subagents/src/workflows/workflow-receipt.ts +195 -6
- package/dist/extensions/pi-subagents/src/workflows/workflow-settlement.ts +246 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1114 -260
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +34 -0
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +150 -3
- package/dist/extensions/pi-subagents/test/integration/claude-code-smoke.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/integration/claude-code-writer-smoke.test.ts +55 -0
- package/dist/extensions/pi-subagents/test/integration/codex-exec-smoke.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/integration/codex-exec-writer-smoke.test.ts +57 -0
- package/dist/extensions/pi-subagents/test/integration/cursor-agent-smoke.test.ts +59 -0
- package/dist/extensions/pi-subagents/test/integration/cursor-agent-writer-smoke.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +57 -1
- package/dist/extensions/pi-subagents/test/integration/external-cli-runner.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +20 -0
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +4 -3
- package/dist/extensions/pi-subagents/test/integration/orca-progress-tabs.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +54 -4
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +482 -4
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +157 -9
- package/dist/extensions/pi-subagents/test/integration/session-tokens.test.ts +5 -5
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1508 -291
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +423 -1
- package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +8 -0
- package/dist/extensions/pi-subagents/test/support/cursor-smoke-inputs.ts +51 -0
- package/dist/extensions/pi-subagents/test/support/helpers.ts +2 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +5 -5
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +6 -6
- package/dist/extensions/pi-subagents/test/unit/abort-recovery.test.ts +152 -0
- package/dist/extensions/pi-subagents/test/unit/active-async-capacity.test.ts +48 -0
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +184 -6
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +66 -6
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +77 -0
- package/dist/extensions/pi-subagents/test/unit/agent-refinements.test.ts +18 -0
- package/dist/extensions/pi-subagents/test/unit/anti-slop-oxlint.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +101 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +121 -0
- package/dist/extensions/pi-subagents/test/unit/async-recovery-descriptor.test.ts +28 -0
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +14 -7
- package/dist/extensions/pi-subagents/test/unit/async-retention.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/unit/async-status-projection.test.ts +190 -0
- package/dist/extensions/pi-subagents/test/unit/async-status-snapshot.test.ts +42 -0
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +8 -4
- package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +78 -1
- package/dist/extensions/pi-subagents/test/unit/child-launch-plan.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/child-session-name.test.ts +50 -0
- package/dist/extensions/pi-subagents/test/unit/claude-code-adapter.test.ts +245 -0
- package/dist/extensions/pi-subagents/test/unit/codex-exec-adapter.test.ts +192 -0
- package/dist/extensions/pi-subagents/test/unit/compaction-resume.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/completion-evidence.test.ts +150 -0
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/cursor-agent-adapter.test.ts +259 -0
- package/dist/extensions/pi-subagents/test/unit/cursor-smoke-inputs.test.ts +77 -0
- package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +1 -4
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/extension-context.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/external-cli-runner.test.ts +223 -0
- package/dist/extensions/pi-subagents/test/unit/fast-mode-extension.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +208 -2
- package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +29 -1
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +110 -1
- package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +10 -0
- package/dist/extensions/pi-subagents/test/unit/formatters.test.ts +14 -0
- package/dist/extensions/pi-subagents/test/unit/herdr-inspector.test.ts +18 -9
- package/dist/extensions/pi-subagents/test/unit/herdr-session-roots-codec.test.ts +63 -0
- package/dist/extensions/pi-subagents/test/unit/herdr-shell-command.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/herdr-status-bridge.test.ts +136 -6
- package/dist/extensions/pi-subagents/test/unit/host-command.test.ts +156 -0
- package/dist/extensions/pi-subagents/test/unit/host-step-status.test.ts +98 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +178 -26
- package/dist/extensions/pi-subagents/test/unit/index-segment.test.ts +2 -1
- package/dist/extensions/pi-subagents/test/unit/inspect-rpc.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/mcp-direct-tool-grant.test.ts +138 -0
- package/dist/extensions/pi-subagents/test/unit/mission-lifecycle.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/model-exclusions.test.ts +91 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +72 -7
- package/dist/extensions/pi-subagents/test/unit/mutation-evidence.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +20 -2
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +129 -1
- package/dist/extensions/pi-subagents/test/unit/orca-progress-tabs.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +4 -0
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +358 -0
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +574 -21
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +109 -1
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +71 -1
- package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +7 -7
- package/dist/extensions/pi-subagents/test/unit/pruned-fork.test.ts +214 -0
- package/dist/extensions/pi-subagents/test/unit/public-execution.test.ts +29 -8
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/unit/result-delivery-ownership.test.ts +34 -0
- package/dist/extensions/pi-subagents/test/unit/result-files.test.ts +101 -3
- package/dist/extensions/pi-subagents/test/unit/retained-children.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +10 -8
- package/dist/extensions/pi-subagents/test/unit/run-fanout-budget.test.ts +71 -1
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +41 -7
- package/dist/extensions/pi-subagents/test/unit/runtime-agent-registration.test.ts +136 -2
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +137 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +33 -12
- package/dist/extensions/pi-subagents/test/unit/scripted-workflow.test.ts +504 -1
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +8 -0
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +12 -1
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +3 -5
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +5 -6
- package/dist/extensions/pi-subagents/test/unit/subagent-action-recovery.test.ts +0 -8
- package/dist/extensions/pi-subagents/test/unit/subagent-guide.test.ts +5 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +157 -2
- package/dist/extensions/pi-subagents/test/unit/subagent-startup-retry.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +63 -4
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +27 -23
- package/dist/extensions/pi-subagents/test/unit/wait-completions.test.ts +44 -0
- package/dist/extensions/pi-subagents/test/unit/wait-subscriptions.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +7 -5
- package/dist/extensions/pi-subagents/test/unit/workflow-chat-progress.test.ts +106 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-detach-reconcile.test.ts +484 -9
- package/dist/extensions/pi-subagents/test/unit/workflow-launch-params.test.ts +38 -4
- package/dist/extensions/pi-subagents/test/unit/workflow-preflight.test.ts +155 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-receipt.test.ts +318 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-resume-hint.test.ts +365 -0
- package/dist/extensions/pi-subagents/test/unit/worktree-cleanup-plan.test.ts +349 -0
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +2 -7
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/index.ts +13 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/rules/no-service-constructor-imports.ts +52 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/index.ts +41 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-chained-type-assertions.ts +77 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-conditional-empty-object-spread.ts +49 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-known-value-widening.ts +247 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-module-mocking.ts +91 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-object-parameters.ts +126 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-apply.ts +28 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-get.ts +28 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-runtime-typeof.ts +67 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-shape-in-symbol-names.ts +39 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-parameters.ts +83 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-returns.ts +115 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-type-aliases.ts +72 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unsafe-dictionary-type.ts +134 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-widen-then-assert.ts +366 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/require-safety-comment-for-type-assertion.ts +62 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/dictionary-types.ts +502 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/lexical-type-parameters.ts +60 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/reflect-method.ts +35 -0
- package/dist/extensions/pi-tool-display/tests/capabilities.test.ts +1 -1
- package/dist/extensions/pi-tool-display/tests/settings-inspector.test.ts +2 -2
- package/dist/extensions/pi-tool-display/tests/tool-overrides-mcp.test.ts +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -7
- package/dist/skills/workflow/SKILL.md +65 -50
- package/package.json +112 -110
- package/dist/extensions/enable-readonly-tools.test.ts +0 -63
- package/dist/extensions/enable-readonly-tools.ts +0 -24
- package/dist/extensions/model-prompt-injector/config.json +0 -16
- package/dist/extensions/model-prompt-injector/index.test.ts +0 -102
- package/dist/extensions/model-prompt-injector/index.ts +0 -148
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +0 -98
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +0 -250
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { afterEach, describe, it } from "node:test";
|
|
6
|
+
import { executeWorkflowHostCommand, normalizeWorkflowHostCommandParams } from "../../src/workflows/host-command.ts";
|
|
7
|
+
|
|
8
|
+
const roots: string[] = [];
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
function commandFor(root: string, source: string): string {
|
|
15
|
+
const script = path.join(root, `command-${Math.random().toString(16).slice(2)}.cjs`);
|
|
16
|
+
fs.writeFileSync(script, source, "utf8");
|
|
17
|
+
return `${JSON.stringify(process.execPath)} ${JSON.stringify(script)}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("workflow host commands", () => {
|
|
21
|
+
it("validates the narrow command shape", () => {
|
|
22
|
+
assert.deepEqual(normalizeWorkflowHostCommandParams({ kind: "command", command: "npm test", timeoutMs: 1000, output: "reports/test.log", role: "ci", provider: "local" }), {
|
|
23
|
+
kind: "command",
|
|
24
|
+
command: "npm test",
|
|
25
|
+
timeoutMs: 1000,
|
|
26
|
+
output: "reports/test.log",
|
|
27
|
+
role: "ci",
|
|
28
|
+
provider: "local",
|
|
29
|
+
});
|
|
30
|
+
assert.throws(() => normalizeWorkflowHostCommandParams({ kind: "http", command: "true", timeoutMs: 1000 }), /kind must be 'command'/);
|
|
31
|
+
assert.throws(() => normalizeWorkflowHostCommandParams({ kind: "command", command: "true" }), /timeoutMs/);
|
|
32
|
+
assert.throws(() => normalizeWorkflowHostCommandParams({ kind: "command", command: "true", timeoutMs: 1000, output: "../outside.log" }), /relative path/);
|
|
33
|
+
assert.throws(() => normalizeWorkflowHostCommandParams({ kind: "command", command: "true", timeoutMs: 86_400_001 }), /integer from 1/);
|
|
34
|
+
assert.throws(() => normalizeWorkflowHostCommandParams({ kind: "command", command: "true", timeoutMs: 1000, output: path.resolve("outside.log") }), /relative path/);
|
|
35
|
+
assert.throws(() => normalizeWorkflowHostCommandParams({ kind: "command", command: "true", timeoutMs: 1000, provider: "bad\nprovider" }), /single-line/);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("runs without stdin and saves bounded command evidence", async () => {
|
|
39
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-host-command-"));
|
|
40
|
+
roots.push(root);
|
|
41
|
+
const outputPath = path.join(root, "reports", "command.log");
|
|
42
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
43
|
+
fs.writeFileSync(outputPath, "stale", "utf8");
|
|
44
|
+
const result = await executeWorkflowHostCommand({
|
|
45
|
+
key: "unit-tests",
|
|
46
|
+
params: { kind: "command", command: commandFor(root, `process.stdout.write("passed\\n"); process.stderr.write("warning\\n");`), timeoutMs: 5000, output: "reports/command.log" },
|
|
47
|
+
cwd: root,
|
|
48
|
+
defaultOutputPath: path.join(root, "fallback.log"),
|
|
49
|
+
signal: new AbortController().signal,
|
|
50
|
+
});
|
|
51
|
+
assert.equal(result.ok, true);
|
|
52
|
+
assert.equal(result.state, "passed");
|
|
53
|
+
assert.equal(result.exitCode, 0);
|
|
54
|
+
assert.match(result.stdout, /passed/);
|
|
55
|
+
assert.match(result.stderr, /warning/);
|
|
56
|
+
assert.equal(result.outputPath, outputPath);
|
|
57
|
+
assert.match(fs.readFileSync(outputPath, "utf8"), /passed/);
|
|
58
|
+
if (process.platform !== "win32") assert.equal(fs.statSync(outputPath).mode & 0o777, 0o600);
|
|
59
|
+
assert.deepEqual(fs.readdirSync(path.dirname(outputPath)), ["command.log"]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("returns failed and timed-out command evidence", async () => {
|
|
63
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-host-command-failure-"));
|
|
64
|
+
roots.push(root);
|
|
65
|
+
const failed = await executeWorkflowHostCommand({
|
|
66
|
+
key: "failed",
|
|
67
|
+
params: { kind: "command", command: commandFor(root, `process.stderr.write("bad\\n"); process.exit(3);`), timeoutMs: 5000 },
|
|
68
|
+
cwd: root,
|
|
69
|
+
defaultOutputPath: path.join(root, "failed.log"),
|
|
70
|
+
signal: new AbortController().signal,
|
|
71
|
+
});
|
|
72
|
+
assert.equal(failed.state, "failed");
|
|
73
|
+
assert.equal(failed.exitCode, 3);
|
|
74
|
+
assert.match(failed.error ?? "", /code 3/);
|
|
75
|
+
|
|
76
|
+
const timedOut = await executeWorkflowHostCommand({
|
|
77
|
+
key: "timeout",
|
|
78
|
+
params: { kind: "command", command: commandFor(root, `setTimeout(() => {}, 10000);`), timeoutMs: 20 },
|
|
79
|
+
cwd: root,
|
|
80
|
+
defaultOutputPath: path.join(root, "timeout.log"),
|
|
81
|
+
signal: new AbortController().signal,
|
|
82
|
+
});
|
|
83
|
+
assert.equal(timedOut.state, "timed-out");
|
|
84
|
+
assert.match(timedOut.error ?? "", /timed out/);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("rejects symlinked output parents before creating outside directories", { skip: process.platform === "win32" ? "symlink permissions vary on Windows" : undefined }, async () => {
|
|
88
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-host-command-symlink-"));
|
|
89
|
+
const outside = fs.mkdtempSync(path.join(os.tmpdir(), "pi-host-command-outside-"));
|
|
90
|
+
roots.push(root, outside);
|
|
91
|
+
fs.symlinkSync(outside, path.join(root, "link-out"), "dir");
|
|
92
|
+
|
|
93
|
+
await assert.rejects(
|
|
94
|
+
executeWorkflowHostCommand({
|
|
95
|
+
key: "symlink-output",
|
|
96
|
+
params: { kind: "command", command: commandFor(root, `process.stdout.write("unused");`), timeoutMs: 5000, output: "link-out/sub/report.log" },
|
|
97
|
+
cwd: root,
|
|
98
|
+
defaultOutputPath: path.join(root, "fallback.log"),
|
|
99
|
+
signal: new AbortController().signal,
|
|
100
|
+
}),
|
|
101
|
+
/resolves outside the workflow cwd/,
|
|
102
|
+
);
|
|
103
|
+
assert.equal(fs.existsSync(path.join(outside, "sub")), false);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("rejects an explicit output parent redirected while the command runs", { skip: process.platform === "win32" ? "symlink permissions vary on Windows" : undefined }, async () => {
|
|
107
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-host-command-symlink-race-"));
|
|
108
|
+
const outside = fs.mkdtempSync(path.join(os.tmpdir(), "pi-host-command-symlink-target-"));
|
|
109
|
+
roots.push(root, outside);
|
|
110
|
+
const outputParent = path.join(root, "reports");
|
|
111
|
+
const outsidePath = path.join(outside, "outside.log");
|
|
112
|
+
const command = commandFor(root, `
|
|
113
|
+
const fs = require("node:fs");
|
|
114
|
+
fs.rmdirSync(${JSON.stringify(outputParent)});
|
|
115
|
+
fs.symlinkSync(${JSON.stringify(outside)}, ${JSON.stringify(outputParent)}, "dir");
|
|
116
|
+
process.stdout.write("captured");
|
|
117
|
+
`);
|
|
118
|
+
|
|
119
|
+
await assert.rejects(executeWorkflowHostCommand({
|
|
120
|
+
key: "replaced-output",
|
|
121
|
+
params: { kind: "command", command, timeoutMs: 5000, output: "reports/command.log" },
|
|
122
|
+
cwd: root,
|
|
123
|
+
defaultOutputPath: path.join(root, "fallback.log"),
|
|
124
|
+
signal: new AbortController().signal,
|
|
125
|
+
}), /resolves outside the workflow cwd/);
|
|
126
|
+
assert.equal(fs.existsSync(outsidePath), false);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("stops the owned process tree when the workflow aborts", async () => {
|
|
130
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-host-command-abort-"));
|
|
131
|
+
roots.push(root);
|
|
132
|
+
const readyPath = path.join(root, "ready");
|
|
133
|
+
const leakedPath = path.join(root, "leaked");
|
|
134
|
+
const command = commandFor(root, `
|
|
135
|
+
const { spawn } = require("node:child_process");
|
|
136
|
+
const fs = require("node:fs");
|
|
137
|
+
fs.writeFileSync(${JSON.stringify(readyPath)}, "ready");
|
|
138
|
+
spawn(process.execPath, ["-e", ${JSON.stringify(`setTimeout(() => require("node:fs").writeFileSync(${JSON.stringify(leakedPath)}, "leaked"), 400)}`)}], { stdio: "ignore" });
|
|
139
|
+
setTimeout(() => {}, 10000);
|
|
140
|
+
`);
|
|
141
|
+
const controller = new AbortController();
|
|
142
|
+
const pending = executeWorkflowHostCommand({
|
|
143
|
+
key: "abort",
|
|
144
|
+
params: { kind: "command", command, timeoutMs: 5000 },
|
|
145
|
+
cwd: root,
|
|
146
|
+
defaultOutputPath: path.join(root, "abort.log"),
|
|
147
|
+
signal: controller.signal,
|
|
148
|
+
});
|
|
149
|
+
for (let attempt = 0; attempt < 100 && !fs.existsSync(readyPath); attempt += 1) await new Promise((resolve) => setTimeout(resolve, 10));
|
|
150
|
+
assert.equal(fs.existsSync(readyPath), true);
|
|
151
|
+
controller.abort();
|
|
152
|
+
assert.equal((await pending).state, "stopped");
|
|
153
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
154
|
+
assert.equal(fs.existsSync(leakedPath), false);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import type { AsyncStatus, HostStepNodeV1 } from "../../src/shared/types.ts";
|
|
4
|
+
import {
|
|
5
|
+
HOST_STEP_MAX_LABEL_CHARS,
|
|
6
|
+
assertHostStepNode,
|
|
7
|
+
assertWorkflowGraphHostSteps,
|
|
8
|
+
hostStepWorkflowNode,
|
|
9
|
+
parseHostStepNode,
|
|
10
|
+
assertUniqueHostStepIds,
|
|
11
|
+
upsertHostStep,
|
|
12
|
+
validHostStepNodes,
|
|
13
|
+
} from "../../src/runs/shared/host-step-status.ts";
|
|
14
|
+
|
|
15
|
+
function hostStep(overrides: Partial<HostStepNodeV1> = {}): HostStepNodeV1 {
|
|
16
|
+
return {
|
|
17
|
+
version: 1,
|
|
18
|
+
kind: "host-step",
|
|
19
|
+
monitorKind: "gate",
|
|
20
|
+
id: "gate-ci",
|
|
21
|
+
label: "CI and review gate",
|
|
22
|
+
provider: "github-ci",
|
|
23
|
+
state: "running",
|
|
24
|
+
updatedAt: 10,
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("host step status", () => {
|
|
30
|
+
it("validates host monitor states and command exit evidence", () => {
|
|
31
|
+
const running = parseHostStepNode(hostStep({ monitorKind: "ci" }), "fixture");
|
|
32
|
+
assert.equal(running.monitorKind, "ci");
|
|
33
|
+
assert.equal(hostStepWorkflowNode(running).status, "running");
|
|
34
|
+
assert.equal(hostStepWorkflowNode(hostStep({ state: "done", verdict: "pass" })).status, "completed");
|
|
35
|
+
assert.equal(hostStepWorkflowNode(hostStep({ state: "done", verdict: "inconclusive" })).status, "partial");
|
|
36
|
+
assert.equal(hostStepWorkflowNode(hostStep({ state: "done" })).status, "partial");
|
|
37
|
+
assert.equal(hostStepWorkflowNode(hostStep({ state: "done", verdict: "fail" })).status, "failed");
|
|
38
|
+
assert.equal(hostStepWorkflowNode(hostStep({ state: "cancelled" })).status, "stopped");
|
|
39
|
+
assert.equal(hostStepWorkflowNode(hostStep({ state: "error" })).status, "failed");
|
|
40
|
+
assert.equal(parseHostStepNode(hostStep({ monitorKind: "command", state: "done", verdict: "pass", exitCode: 0 })).exitCode, 0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("rejects unbounded or incomplete terminal data", () => {
|
|
44
|
+
assert.throws(() => assertHostStepNode(hostStep({ label: "x".repeat(HOST_STEP_MAX_LABEL_CHARS + 1) }), "fixture"), /label exceeds/);
|
|
45
|
+
assert.throws(() => assertHostStepNode(hostStep({ state: "running", verdict: "pass" }), "fixture"), /verdict is only valid/);
|
|
46
|
+
assert.throws(() => assertHostStepNode(hostStep({ state: "done", verdict: "inconclusive", freshness: {} as HostStepNodeV1["freshness"] }), "fixture"), /expected/);
|
|
47
|
+
assert.throws(() => assertHostStepNode(hostStep({ state: "done", verdict: "pass", freshness: { expectedRef: "head", stale: true } }), "fixture"), /stale freshness/);
|
|
48
|
+
assert.throws(() => assertHostStepNode(hostStep({ exitCode: 1 }), "fixture"), /only valid for command/);
|
|
49
|
+
assert.throws(() => assertHostStepNode(hostStep({ monitorKind: "command", exitCode: 1 }), "fixture"), /only valid after command settlement/);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("upserts through the host-owned persistence callback without touching legacy child steps", () => {
|
|
53
|
+
const status: AsyncStatus = {
|
|
54
|
+
runId: "workflow-1",
|
|
55
|
+
mode: "workflow",
|
|
56
|
+
state: "running",
|
|
57
|
+
startedAt: 1,
|
|
58
|
+
steps: [{ agent: "reviewer", workflowKey: "review", runId: "child-1", status: "running" }],
|
|
59
|
+
};
|
|
60
|
+
const writes: AsyncStatus[] = [];
|
|
61
|
+
const next = upsertHostStep({ status, hostStep: hostStep({ state: "done", verdict: "pass", updatedAt: 20 }), persist: (value) => writes.push(value) });
|
|
62
|
+
assert.equal(writes.length, 1);
|
|
63
|
+
assert.deepEqual(next.steps, status.steps);
|
|
64
|
+
assert.equal(next.workflowGraph?.nodes[0]?.kind, "host-step");
|
|
65
|
+
assert.equal(next.workflowGraph?.nodes[0]?.hostStep?.monitorKind, "gate");
|
|
66
|
+
assert.equal(next.workflowGraph?.nodes[0]?.status, "completed");
|
|
67
|
+
assert.equal(next.lastUpdate, 20);
|
|
68
|
+
|
|
69
|
+
const replaced = upsertHostStep({ status: next, hostStep: hostStep({ state: "error", updatedAt: 30 }), persist: (value) => writes.push(value) });
|
|
70
|
+
assert.equal(replaced.workflowGraph?.nodes.length, 1);
|
|
71
|
+
assert.equal(replaced.workflowGraph?.nodes[0]?.status, "failed");
|
|
72
|
+
assert.equal(writes.length, 2);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("fails closed for malformed graph nodes while strict loaders can reject them", () => {
|
|
76
|
+
const graph = {
|
|
77
|
+
runId: "workflow-1",
|
|
78
|
+
mode: "workflow" as const,
|
|
79
|
+
phases: [],
|
|
80
|
+
nodes: [{ id: "bad", kind: "host-step" as const, label: "bad", status: "running" as const }],
|
|
81
|
+
};
|
|
82
|
+
assert.deepEqual(validHostStepNodes(graph), []);
|
|
83
|
+
assert.throws(() => assertHostStepNode(graph.nodes[0]?.hostStep, "status"), /expected an object/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("rejects ambiguous host-step identities", () => {
|
|
87
|
+
const duplicate = hostStep({ id: "duplicate" });
|
|
88
|
+
assert.throws(() => assertUniqueHostStepIds([duplicate, duplicate], "receipt"), /duplicate host step id/);
|
|
89
|
+
const graph = {
|
|
90
|
+
runId: "workflow-1",
|
|
91
|
+
mode: "workflow" as const,
|
|
92
|
+
phases: [],
|
|
93
|
+
nodes: [hostStepWorkflowNode(duplicate), hostStepWorkflowNode(duplicate)],
|
|
94
|
+
};
|
|
95
|
+
assert.deepEqual(validHostStepNodes(graph), []);
|
|
96
|
+
assert.throws(() => assertWorkflowGraphHostSteps(graph, "status", "workflow-1"), /duplicate host step id/);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -20,6 +20,76 @@ function parentToolEnv(agentDir?: string): NodeJS.ProcessEnv {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
describe("subagent extension child mode", () => {
|
|
23
|
+
it("defers persistence when startup config expires a cached exclusion", () => {
|
|
24
|
+
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-model-exclusion-startup-"));
|
|
25
|
+
const exclusionPath = path.join(agentDir, "model-exclusions.json");
|
|
26
|
+
try {
|
|
27
|
+
const configDir = path.join(agentDir, "extensions", "subagent");
|
|
28
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
29
|
+
fs.writeFileSync(path.join(configDir, "config.json"), JSON.stringify({ modelExclusions: { defaultTtlMs: 300_000 } }), "utf-8");
|
|
30
|
+
const recordedAt = Date.now() - 600_000;
|
|
31
|
+
const originalExpiry = Date.now() + 3_600_000;
|
|
32
|
+
fs.writeFileSync(exclusionPath, JSON.stringify({
|
|
33
|
+
version: 1,
|
|
34
|
+
exclusions: [{ provider: "openai", modelId: "old-model", reason: "503", recordedAt, expiresAt: originalExpiry }],
|
|
35
|
+
}), "utf-8");
|
|
36
|
+
const script = String.raw`
|
|
37
|
+
import registerSubagentExtension from "./index.ts";
|
|
38
|
+
import { isExcluded } from "./src/runs/shared/model-exclusions.ts";
|
|
39
|
+
const events = { on() { return () => {}; }, emit() {} };
|
|
40
|
+
const fakePi = new Proxy({
|
|
41
|
+
events,
|
|
42
|
+
registerTool() {}, registerCommand() {}, registerShortcut() {}, registerMessageRenderer() {}, sendMessage() {}, getSessionName() {},
|
|
43
|
+
}, { get(target, prop) { return prop in target ? target[prop] : () => undefined; } });
|
|
44
|
+
registerSubagentExtension(fakePi);
|
|
45
|
+
if (isExcluded("old-model", "openai")) throw new Error("startup TTL clamp did not expire the cached exclusion in memory");
|
|
46
|
+
`;
|
|
47
|
+
const env = parentToolEnv(agentDir);
|
|
48
|
+
env.PI_MODEL_EXCLUSIONS_PATH = exclusionPath;
|
|
49
|
+
execFileSync(process.execPath, ["--experimental-strip-types", "--import", "./test/support/register-loader.mjs", "--input-type=module", "--eval", script], { cwd: projectRoot, env, stdio: "pipe" });
|
|
50
|
+
const persisted = JSON.parse(fs.readFileSync(exclusionPath, "utf-8")).exclusions[0] as { expiresAt: number };
|
|
51
|
+
assert.equal(persisted.expiresAt, originalExpiry);
|
|
52
|
+
} finally {
|
|
53
|
+
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("applies model exclusion TTL from extension config at registration", () => {
|
|
58
|
+
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-model-exclusion-config-"));
|
|
59
|
+
const exclusionPath = path.join(agentDir, "model-exclusions.json");
|
|
60
|
+
try {
|
|
61
|
+
const configDir = path.join(agentDir, "extensions", "subagent");
|
|
62
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
63
|
+
fs.writeFileSync(path.join(configDir, "config.json"), JSON.stringify({ modelExclusions: { defaultTtlMs: 300_000 } }), "utf-8");
|
|
64
|
+
const recordedAt = Date.now();
|
|
65
|
+
fs.writeFileSync(exclusionPath, JSON.stringify({
|
|
66
|
+
version: 1,
|
|
67
|
+
exclusions: [{ provider: "openai", modelId: "old-model", reason: "503", recordedAt, expiresAt: recordedAt + 3_600_000 }],
|
|
68
|
+
}), "utf-8");
|
|
69
|
+
const script = String.raw`
|
|
70
|
+
import * as fs from "node:fs";
|
|
71
|
+
import registerSubagentExtension from "./index.ts";
|
|
72
|
+
import { recordModelFailure } from "./src/runs/shared/model-exclusions.ts";
|
|
73
|
+
const events = { on() { return () => {}; }, emit() {} };
|
|
74
|
+
const fakePi = new Proxy({
|
|
75
|
+
events,
|
|
76
|
+
registerTool() {}, registerCommand() {}, registerShortcut() {}, registerMessageRenderer() {}, sendMessage() {}, getSessionName() {},
|
|
77
|
+
}, { get(target, prop) { return prop in target ? target[prop] : () => undefined; } });
|
|
78
|
+
registerSubagentExtension(fakePi);
|
|
79
|
+
recordModelFailure({ modelId: "gpt-5", provider: "openai", reason: "test" });
|
|
80
|
+
const entries = JSON.parse(fs.readFileSync(process.env.PI_MODEL_EXCLUSIONS_PATH, "utf-8")).exclusions;
|
|
81
|
+
for (const entry of entries) {
|
|
82
|
+
if (entry.expiresAt - entry.recordedAt !== 300_000) throw new Error("configured model exclusion TTL was not applied: " + JSON.stringify(entry));
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
const env = parentToolEnv(agentDir);
|
|
86
|
+
env.PI_MODEL_EXCLUSIONS_PATH = exclusionPath;
|
|
87
|
+
execFileSync(process.execPath, ["--experimental-strip-types", "--import", "./test/support/register-loader.mjs", "--input-type=module", "--eval", script], { cwd: projectRoot, env, stdio: "pipe" });
|
|
88
|
+
} finally {
|
|
89
|
+
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
23
93
|
it("collapses tool detail before direct subagent tool execution", () => {
|
|
24
94
|
const script = String.raw`
|
|
25
95
|
import registerSubagentExtension from "./index.ts";
|
|
@@ -565,9 +635,13 @@ describe("subagent extension child mode", () => {
|
|
|
565
635
|
const handlers = new Map();
|
|
566
636
|
const events = { on(channel, handler) { eventHandlers.set(channel, handler); return () => {}; }, emit() {} };
|
|
567
637
|
const widgets = [];
|
|
638
|
+
const herdrCommands = [];
|
|
639
|
+
process.env.HERDR_ENV = "1";
|
|
640
|
+
process.env.HERDR_PANE_ID = "w1:p1";
|
|
568
641
|
const fakePi = new Proxy({
|
|
569
642
|
events,
|
|
570
643
|
on(channel, handler) { handlers.set(channel, handler); },
|
|
644
|
+
exec(command, args) { herdrCommands.push({ command, args }); return Promise.resolve({ code: 0, stdout: "", stderr: "", killed: false }); },
|
|
571
645
|
registerTool() {}, registerCommand() {}, registerShortcut() {}, registerMessageRenderer() {},
|
|
572
646
|
sendMessage() {}, getSessionName() { return undefined; },
|
|
573
647
|
}, { get(target, prop) { return prop in target ? target[prop] : () => undefined; } });
|
|
@@ -593,6 +667,10 @@ describe("subagent extension child mode", () => {
|
|
|
593
667
|
handlers.get("tool_result")({ toolName: "subagent" }, ctx);
|
|
594
668
|
const fleetWidgets = widgets.filter((entry) => entry.key === "subagent-fleet-status");
|
|
595
669
|
if (!fleetWidgets.some((entry) => typeof entry.value === "function")) throw new Error("management result did not restore active fleet status: " + JSON.stringify(fleetWidgets));
|
|
670
|
+
if (!herdrCommands.some(({ args }) => args.includes("summary=⏳ 1 subagent"))) throw new Error("management result did not restore Herdr status: " + JSON.stringify(herdrCommands));
|
|
671
|
+
const herdrCommandCount = herdrCommands.length;
|
|
672
|
+
handlers.get("tool_result")({ toolName: "subagent" }, ctx);
|
|
673
|
+
if (herdrCommands.length !== herdrCommandCount) throw new Error("unchanged active jobs redundantly refreshed Herdr status: " + JSON.stringify(herdrCommands));
|
|
596
674
|
handlers.get("session_shutdown")();
|
|
597
675
|
fs.rmSync(asyncDir, { recursive: true, force: true });
|
|
598
676
|
`;
|
|
@@ -925,6 +1003,106 @@ describe("subagent extension child mode", () => {
|
|
|
925
1003
|
}
|
|
926
1004
|
});
|
|
927
1005
|
|
|
1006
|
+
it("ignores the current stale UI context during runtime reload cleanup", () => {
|
|
1007
|
+
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-stale-ui-reload-"));
|
|
1008
|
+
const configDir = path.join(agentDir, "extensions", "subagent");
|
|
1009
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
1010
|
+
fs.writeFileSync(path.join(configDir, "config.json"), JSON.stringify({ asyncWidget: false, fleetView: false }), "utf-8");
|
|
1011
|
+
const script = String.raw`
|
|
1012
|
+
import registerSubagentExtension from "./index.ts";
|
|
1013
|
+
const handlers = new Map();
|
|
1014
|
+
const events = { on() { return () => {}; }, emit() {} };
|
|
1015
|
+
const fakePi = new Proxy({
|
|
1016
|
+
events,
|
|
1017
|
+
on(channel, handler) { handlers.set(channel, handler); },
|
|
1018
|
+
registerTool() {}, registerCommand() {}, registerShortcut() {}, registerMessageRenderer() {},
|
|
1019
|
+
sendMessage() {}, getSessionName() { return undefined; },
|
|
1020
|
+
}, { get(target, prop) { return prop in target ? target[prop] : () => undefined; } });
|
|
1021
|
+
let stale = false;
|
|
1022
|
+
const ctx = {
|
|
1023
|
+
cwd: process.cwd(),
|
|
1024
|
+
get hasUI() {
|
|
1025
|
+
if (stale) throw new Error("This extension ctx is stale after session replacement or reload.");
|
|
1026
|
+
return true;
|
|
1027
|
+
},
|
|
1028
|
+
ui: {
|
|
1029
|
+
setWidget() {}, requestRender() {}, setToolsExpanded() {}, getToolsExpanded() { return false; },
|
|
1030
|
+
theme: { fg(_name, text) { return text; }, bg(_name, text) { return text; }, bold(text) { return text; } },
|
|
1031
|
+
},
|
|
1032
|
+
sessionManager: { getSessionId() { return "stale-ui-session"; }, getSessionFile() { return null; }, getEntries() { return []; } },
|
|
1033
|
+
modelRegistry: { getAvailable() { return []; } },
|
|
1034
|
+
};
|
|
1035
|
+
registerSubagentExtension(fakePi);
|
|
1036
|
+
handlers.get("session_start")({ reason: "startup" }, ctx);
|
|
1037
|
+
stale = true;
|
|
1038
|
+
handlers.get("session_shutdown")({ reason: "reload" });
|
|
1039
|
+
`;
|
|
1040
|
+
|
|
1041
|
+
try {
|
|
1042
|
+
const env = parentToolEnv(agentDir);
|
|
1043
|
+
env.SELESAI_CODING_AGENT_DIR = agentDir;
|
|
1044
|
+
execFileSync(
|
|
1045
|
+
process.execPath,
|
|
1046
|
+
["--experimental-strip-types", "--import", "./test/support/register-loader.mjs", "--input-type=module", "--eval", script],
|
|
1047
|
+
{ cwd: projectRoot, env, stdio: "pipe" },
|
|
1048
|
+
);
|
|
1049
|
+
} finally {
|
|
1050
|
+
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
it("claims the explicit predecessor session during session replacement", () => {
|
|
1055
|
+
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-session-transition-"));
|
|
1056
|
+
const configDir = path.join(agentDir, "extensions", "subagent");
|
|
1057
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
1058
|
+
fs.writeFileSync(path.join(configDir, "config.json"), JSON.stringify({ completionBatch: { enabled: false } }), "utf-8");
|
|
1059
|
+
const script = String.raw`
|
|
1060
|
+
import fs from "node:fs";
|
|
1061
|
+
import path from "node:path";
|
|
1062
|
+
import registerSubagentExtension from "./index.ts";
|
|
1063
|
+
import { currentCompletionOwnerId } from "./src/shared/completion-owner.ts";
|
|
1064
|
+
const handlers = new Map();
|
|
1065
|
+
const listeners = new Map();
|
|
1066
|
+
const events = {
|
|
1067
|
+
on(channel, handler) { let set = listeners.get(channel); if (!set) listeners.set(channel, set = new Set()); set.add(handler); return () => set.delete(handler); },
|
|
1068
|
+
emit(channel, payload) { for (const handler of [...(listeners.get(channel) ?? [])]) handler(payload); },
|
|
1069
|
+
};
|
|
1070
|
+
const sent = [];
|
|
1071
|
+
const pi = new Proxy({
|
|
1072
|
+
events,
|
|
1073
|
+
on(channel, handler) { handlers.set(channel, handler); },
|
|
1074
|
+
registerTool() {}, registerCommand() {}, registerShortcut() {}, registerMessageRenderer() {},
|
|
1075
|
+
sendMessage(message) { sent.push(message); }, getSessionName() { return undefined; },
|
|
1076
|
+
}, { get(target, prop) { return prop in target ? target[prop] : () => undefined; } });
|
|
1077
|
+
const sessions = path.join(process.env.SELESAI_CODING_AGENT_DIR, "sessions");
|
|
1078
|
+
fs.mkdirSync(sessions, { recursive: true });
|
|
1079
|
+
const oldSession = path.join(sessions, "old.jsonl");
|
|
1080
|
+
const newSession = path.join(sessions, "new.jsonl");
|
|
1081
|
+
fs.writeFileSync(oldSession, "");
|
|
1082
|
+
fs.writeFileSync(newSession, "");
|
|
1083
|
+
let currentSession = oldSession;
|
|
1084
|
+
const sessionManager = { getSessionId() { return path.basename(currentSession); }, getSessionFile() { return currentSession; }, getEntries() { return []; } };
|
|
1085
|
+
const ctx = { cwd: process.cwd(), hasUI: false, ui: { setWidget() {}, requestRender() {}, theme: { fg(_name, text) { return text; }, bg(_name, text) { return text; }, bold(text) { return text; } } }, sessionManager, modelRegistry: { getAvailable() { return []; } } };
|
|
1086
|
+
registerSubagentExtension(pi);
|
|
1087
|
+
handlers.get("session_start")({ reason: "startup" }, ctx);
|
|
1088
|
+
currentSession = newSession;
|
|
1089
|
+
handlers.get("session_start")({ reason: "new", previousSessionFile: oldSession }, ctx);
|
|
1090
|
+
const owner = currentCompletionOwnerId();
|
|
1091
|
+
events.emit("subagent:async-complete", { id: "old-owned", agent: "worker", success: true, summary: "old", timestamp: 1, sessionId: oldSession, completionOwnerId: owner });
|
|
1092
|
+
events.emit("subagent:async-complete", { id: "foreign", agent: "worker", success: true, summary: "foreign", timestamp: 2, sessionId: path.join(sessions, "foreign.jsonl"), completionOwnerId: owner });
|
|
1093
|
+
if (sent.length !== 1) throw new Error("expected only the claimed predecessor completion, got " + sent.length);
|
|
1094
|
+
await handlers.get("session_shutdown")({ reason: "quit" });
|
|
1095
|
+
`;
|
|
1096
|
+
|
|
1097
|
+
try {
|
|
1098
|
+
const env = parentToolEnv();
|
|
1099
|
+
env.SELESAI_CODING_AGENT_DIR = agentDir;
|
|
1100
|
+
execFileSync(process.execPath, ["--experimental-strip-types", "--import", "./test/support/register-loader.mjs", "--input-type=module", "--eval", script], { cwd: projectRoot, env, stdio: "pipe" });
|
|
1101
|
+
} finally {
|
|
1102
|
+
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
|
|
928
1106
|
it("registers the main watchdog command and renderer in parent mode", () => {
|
|
929
1107
|
const script = String.raw`
|
|
930
1108
|
import registerSubagentExtension from "./index.ts";
|
|
@@ -1077,32 +1255,6 @@ describe("subagent extension child mode", () => {
|
|
|
1077
1255
|
);
|
|
1078
1256
|
});
|
|
1079
1257
|
|
|
1080
|
-
it("omits legacy chain controls from the child-safe fanout tool", () => {
|
|
1081
|
-
const readRegisteredTool = (): { description: string; properties: string[]; id: string; runId: string } => {
|
|
1082
|
-
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-fanout-schema-"));
|
|
1083
|
-
fs.mkdirSync(path.join(agentDir, "extensions", "subagent"), { recursive: true });
|
|
1084
|
-
const script = String.raw`
|
|
1085
|
-
import registerFanoutChildSubagentExtension from "./src/extension/fanout-child.ts";
|
|
1086
|
-
import { SUBAGENT_CHILD_ENV, SUBAGENT_FANOUT_CHILD_ENV } from "./src/runs/shared/pi-args.ts";
|
|
1087
|
-
process.env[SUBAGENT_CHILD_ENV] = "1";
|
|
1088
|
-
process.env[SUBAGENT_FANOUT_CHILD_ENV] = "1";
|
|
1089
|
-
let tool;
|
|
1090
|
-
registerFanoutChildSubagentExtension({ events: { on() { return () => {}; }, emit() {} }, registerTool(value) { tool = value; }, getSessionName() { return undefined; } });
|
|
1091
|
-
process.stdout.write(JSON.stringify({ description: tool.description, properties: Object.keys(tool.parameters.properties), id: tool.parameters.properties.id.description, runId: tool.parameters.properties.runId.description }));
|
|
1092
|
-
`;
|
|
1093
|
-
const output = execFileSync(process.execPath, ["--experimental-strip-types", "--import", "./test/support/register-loader.mjs", "--input-type=module", "--eval", script], {
|
|
1094
|
-
cwd: projectRoot,
|
|
1095
|
-
env: parentToolEnv(agentDir),
|
|
1096
|
-
encoding: "utf-8",
|
|
1097
|
-
});
|
|
1098
|
-
return JSON.parse(output) as { description: string; properties: string[]; id: string; runId: string };
|
|
1099
|
-
};
|
|
1100
|
-
|
|
1101
|
-
const tool = readRegisteredTool();
|
|
1102
|
-
assert.equal(tool.properties.includes("step"), false);
|
|
1103
|
-
assert.doesNotMatch(`${tool.description}\n${tool.id}\n${tool.runId}`, /append-step|approve-checkpoint|reject-checkpoint/);
|
|
1104
|
-
});
|
|
1105
|
-
|
|
1106
1258
|
it("lets fanout children call read-only list but blocks mutating management actions", () => {
|
|
1107
1259
|
const script = String.raw`
|
|
1108
1260
|
import assert from "node:assert/strict";
|
|
@@ -21,11 +21,12 @@ describe("bounded index segments", () => {
|
|
|
21
21
|
assert.equal(first, encodeIndexSegment(longId));
|
|
22
22
|
assert.match(first, /^~sha256-[a-f0-9]{64}$/);
|
|
23
23
|
assert.ok(Buffer.byteLength(first, "utf-8") <= MAX_INDEX_SEGMENT_BYTES);
|
|
24
|
+
assert.deepEqual(indexSegmentAliases(longId), [first]);
|
|
24
25
|
assert.notEqual(first, encodeIndexSegment(`${longId}other`));
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
it("hashes Windows session file paths that stay under the byte limit", () => {
|
|
28
|
-
const sessionId = String.raw`C:\Users\theap\.
|
|
29
|
+
const sessionId = String.raw`C:\Users\theap\.selesai\agent\sessions\--C--Users-theap--\2026-08-17T07-29-51-353Z_01a00ea0-72f9-754f-82ca-2b74ded94746.jsonl`;
|
|
29
30
|
assert.ok(Buffer.byteLength(encodeURIComponent(sessionId), "utf-8") <= MAX_INDEX_SEGMENT_BYTES);
|
|
30
31
|
assert.match(encodeIndexSegment(sessionId), /^~sha256-[a-f0-9]{64}$/);
|
|
31
32
|
assert.equal(encodeIndexSegment(sessionId), encodeIndexSegment(sessionId));
|
|
@@ -146,6 +146,27 @@ describe("inspect-rpc resolution and ownership", () => {
|
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
describe("inspect-rpc reply content", () => {
|
|
149
|
+
it("reads an exact runtime-recorded session under the Pi sessions base", () => {
|
|
150
|
+
const sessionsBase = fs.mkdtempSync(path.join(os.tmpdir(), "pi-inspect-recorded-session-"));
|
|
151
|
+
const root = path.join(sessionsBase, "project");
|
|
152
|
+
try {
|
|
153
|
+
fs.mkdirSync(root);
|
|
154
|
+
const { resultsDir } = makeRun(root, {
|
|
155
|
+
runId: "run-recorded",
|
|
156
|
+
sessionMessages: [userMessage("recorded task"), assistantMessage("recorded answer")],
|
|
157
|
+
resultPayload: { summary: "done", results: [{ agent: "worker", output: "recorded answer", success: true }] },
|
|
158
|
+
});
|
|
159
|
+
const state = makeState(path.join(sessionsBase, "unrelated"));
|
|
160
|
+
state.trustedSessionFileRoot = sessionsBase;
|
|
161
|
+
const reply = buildInspectReply({ requestId: "r-recorded", asyncId: "run-recorded" }, makeDeps(root, resultsDir, state));
|
|
162
|
+
assert.equal(reply.error, undefined);
|
|
163
|
+
assert.equal(reply.task, "recorded task");
|
|
164
|
+
assert.equal(reply.messages?.at(-1)?.text, "recorded answer");
|
|
165
|
+
} finally {
|
|
166
|
+
fs.rmSync(sessionsBase, { recursive: true, force: true });
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
149
170
|
it("returns task, messages, and final output without leaking paths", () => {
|
|
150
171
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-inspect-full-"));
|
|
151
172
|
const sessionFile = path.join(root, "run-1-session.jsonl");
|