@selesai/code 0.12.0 → 0.13.1
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 +17 -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/core/usage-totals.d.ts +2 -0
- package/dist/core/usage-totals.js +10 -0
- package/dist/extensions/ascii.txt +9 -0
- 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-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 -3
- 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 +132 -0
- 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/extensions/pi-zentui/extensions/zentui/format.ts +2 -1
- package/dist/extensions/pi-zentui/test/format.test.ts +15 -1
- package/dist/modes/interactive/components/footer.js +2 -2
- package/dist/modes/interactive/interactive-mode.js +11 -11
- 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,349 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { describe, it } from "node:test";
|
|
7
|
+
import {
|
|
8
|
+
__testables,
|
|
9
|
+
buildWorktreeCleanupPlan,
|
|
10
|
+
createWorktreeCleanupPlan,
|
|
11
|
+
formatWorktreeCleanupPlan,
|
|
12
|
+
type BuildWorktreeCleanupPlanInput,
|
|
13
|
+
type WorktreeCleanupPlan,
|
|
14
|
+
} from "../../src/runs/shared/worktree-cleanup-plan.ts";
|
|
15
|
+
import { DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS } from "../../src/runs/background/active-run-index.ts";
|
|
16
|
+
import { createWorktrees, type WorktreeSetup } from "../../src/runs/shared/worktree.ts";
|
|
17
|
+
|
|
18
|
+
function git(cwd: string, args: string[]): string {
|
|
19
|
+
return execFileSync("git", ["-C", cwd, ...args], { encoding: "utf-8" }).trim();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function createRepo(prefix: string): string {
|
|
23
|
+
const repo = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
24
|
+
git(repo, ["init"]);
|
|
25
|
+
git(repo, ["config", "user.email", "cleanup-tests@example.com"]);
|
|
26
|
+
git(repo, ["config", "user.name", "Cleanup Tests"]);
|
|
27
|
+
fs.writeFileSync(path.join(repo, "tracked.txt"), "initial\n", "utf-8");
|
|
28
|
+
git(repo, ["add", "tracked.txt"]);
|
|
29
|
+
git(repo, ["commit", "-m", "initial"]);
|
|
30
|
+
return repo;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function removeGeneratedWorktrees(repo: string, setup: WorktreeSetup | undefined): void {
|
|
34
|
+
for (const worktree of setup?.worktrees ?? []) {
|
|
35
|
+
try { execFileSync("git", ["-C", repo, "worktree", "remove", "--force", worktree.path], { stdio: "ignore" }); } catch {}
|
|
36
|
+
try { execFileSync("git", ["-C", repo, "branch", "-D", worktree.branch], { stdio: "ignore" }); } catch {}
|
|
37
|
+
}
|
|
38
|
+
try { execFileSync("git", ["-C", repo, "worktree", "prune"], { stdio: "ignore" }); } catch {}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function writeManifest(input: {
|
|
42
|
+
repo: string;
|
|
43
|
+
manifestPath: string;
|
|
44
|
+
setup: WorktreeSetup;
|
|
45
|
+
runId?: string;
|
|
46
|
+
source?: "foreground" | "async";
|
|
47
|
+
childStatus?: string;
|
|
48
|
+
baseCommit?: string;
|
|
49
|
+
preserved?: boolean;
|
|
50
|
+
outputPath?: string;
|
|
51
|
+
patch?: { path: string; changed: boolean; error?: string };
|
|
52
|
+
}): void {
|
|
53
|
+
const worktree = input.setup.worktrees[0]!;
|
|
54
|
+
const baseCommit = input.baseCommit ?? git(input.repo, ["rev-parse", "HEAD"]);
|
|
55
|
+
const patch = input.patch ?? {
|
|
56
|
+
path: path.join(path.dirname(input.manifestPath), "worktree.patch"),
|
|
57
|
+
changed: false,
|
|
58
|
+
};
|
|
59
|
+
fs.mkdirSync(path.dirname(input.manifestPath), { recursive: true });
|
|
60
|
+
fs.writeFileSync(input.manifestPath, JSON.stringify({
|
|
61
|
+
version: 1,
|
|
62
|
+
runId: input.runId ?? "cleanup-run",
|
|
63
|
+
mode: "parallel",
|
|
64
|
+
source: input.source ?? "foreground",
|
|
65
|
+
cwd: input.repo,
|
|
66
|
+
createdAt: 1,
|
|
67
|
+
updatedAt: 1,
|
|
68
|
+
groups: [{
|
|
69
|
+
stepIndex: 0,
|
|
70
|
+
baseCommit,
|
|
71
|
+
repoRoot: input.repo,
|
|
72
|
+
children: [{
|
|
73
|
+
index: 0,
|
|
74
|
+
taskIndex: worktree.index,
|
|
75
|
+
agent: "worker",
|
|
76
|
+
status: input.childStatus ?? "completed",
|
|
77
|
+
summary: "done",
|
|
78
|
+
...(input.outputPath ? { outputPath: input.outputPath } : {}),
|
|
79
|
+
patch: {
|
|
80
|
+
path: patch.path,
|
|
81
|
+
branch: worktree.branch,
|
|
82
|
+
changed: patch.changed,
|
|
83
|
+
diffStat: "",
|
|
84
|
+
filesChanged: patch.changed ? 1 : 0,
|
|
85
|
+
insertions: patch.changed ? 1 : 0,
|
|
86
|
+
deletions: 0,
|
|
87
|
+
...(patch.error ? { error: patch.error } : {}),
|
|
88
|
+
},
|
|
89
|
+
}],
|
|
90
|
+
cleanup: {
|
|
91
|
+
state: "partial",
|
|
92
|
+
pruned: false,
|
|
93
|
+
tasks: [{
|
|
94
|
+
index: worktree.index,
|
|
95
|
+
path: worktree.path,
|
|
96
|
+
branch: worktree.branch,
|
|
97
|
+
worktreeRemoved: false,
|
|
98
|
+
branchRemoved: false,
|
|
99
|
+
preserved: input.preserved ?? true,
|
|
100
|
+
}],
|
|
101
|
+
},
|
|
102
|
+
}],
|
|
103
|
+
}, null, 2), "utf-8");
|
|
104
|
+
if (patch.changed) fs.writeFileSync(patch.path, "captured patch\n", "utf-8");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function entriesByPath(plan: WorktreeCleanupPlan): Map<string, WorktreeCleanupPlan["entries"][number]> {
|
|
108
|
+
return new Map(plan.entries.map((entry) => [entry.path, entry]));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildPlan(input: BuildWorktreeCleanupPlanInput): WorktreeCleanupPlan {
|
|
112
|
+
return buildWorktreeCleanupPlan({ ...input, foregroundRunOwnership: input.foregroundRunOwnership ?? (() => "terminal") });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
describe("worktree cleanup plan", () => {
|
|
116
|
+
it("prefers native realpath for Windows alias normalization and falls back when unavailable", () => {
|
|
117
|
+
let fallbackCalls = 0;
|
|
118
|
+
const nativePath = "C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cleanup";
|
|
119
|
+
assert.equal(
|
|
120
|
+
__testables.realpathExisting(
|
|
121
|
+
"C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\cleanup",
|
|
122
|
+
() => nativePath,
|
|
123
|
+
() => { fallbackCalls++; return "fallback"; },
|
|
124
|
+
),
|
|
125
|
+
nativePath,
|
|
126
|
+
);
|
|
127
|
+
assert.equal(fallbackCalls, 0);
|
|
128
|
+
assert.equal(
|
|
129
|
+
__testables.realpathExisting(
|
|
130
|
+
"C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\cleanup",
|
|
131
|
+
() => { throw new Error("native realpath unavailable"); },
|
|
132
|
+
() => { fallbackCalls++; return "fallback"; },
|
|
133
|
+
),
|
|
134
|
+
"fallback",
|
|
135
|
+
);
|
|
136
|
+
assert.equal(fallbackCalls, 1);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("builds and persists a deterministic metadata-backed plan without removing worktrees", () => {
|
|
140
|
+
const repo = createRepo("pi-cleanup-plan-safe-");
|
|
141
|
+
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-cleanup-plan-base-"));
|
|
142
|
+
let setup: WorktreeSetup | undefined;
|
|
143
|
+
try {
|
|
144
|
+
setup = createWorktrees(repo, "safe", 1, { baseDir });
|
|
145
|
+
const manifestPath = path.join(repo, ".pi-subagents", "artifacts", "handoff.json");
|
|
146
|
+
writeManifest({ repo, manifestPath, setup });
|
|
147
|
+
fs.mkdirSync(path.join(baseDir, "unrelated-directory"));
|
|
148
|
+
|
|
149
|
+
const first = buildPlan({ repo, worktreeBaseDir: baseDir, now: 10_000, planId: "fixed-plan" });
|
|
150
|
+
const second = buildPlan({ repo, worktreeBaseDir: baseDir, now: 10_000, planId: "another-plan" });
|
|
151
|
+
assert.deepEqual(first.entries, second.entries);
|
|
152
|
+
assert.equal(first.contentHash, second.contentHash);
|
|
153
|
+
assert.equal(first.entries.length, 1);
|
|
154
|
+
assert.equal(first.entries[0]?.decision, "remove");
|
|
155
|
+
assert.equal(first.entries[0]?.state, "safe");
|
|
156
|
+
assert.equal(first.entries[0]?.willDeleteBranch, true);
|
|
157
|
+
assert.match(first.entries[0]?.preconditions.statusDigest ?? "", /^[0-9a-f]{64}$/);
|
|
158
|
+
assert.equal(first.entries.some((entry) => entry.path.includes("unrelated-directory")), false);
|
|
159
|
+
|
|
160
|
+
const created = createWorktreeCleanupPlan({ repo, worktreeBaseDir: baseDir, now: 10_000, planId: "fixed-plan", foregroundRunOwnership: () => "terminal" });
|
|
161
|
+
assert.equal(created.plan.planId, "fixed-plan");
|
|
162
|
+
assert.ok(fs.existsSync(created.planPath));
|
|
163
|
+
assert.match(formatWorktreeCleanupPlan(created), /Will remove[\s\S]*Will delete local branches[\s\S]*Plan-only mode: no worktrees or branches were removed/);
|
|
164
|
+
assert.ok(fs.existsSync(setup.worktrees[0]!.path));
|
|
165
|
+
assert.notEqual(git(repo, ["branch", "--list", setup.worktrees[0]!.branch]), "");
|
|
166
|
+
|
|
167
|
+
for (const childStatus of ["complete", "rejected"] as const) {
|
|
168
|
+
writeManifest({ repo, manifestPath, setup, childStatus });
|
|
169
|
+
const compatibilityPlan = buildPlan({ repo, worktreeBaseDir: baseDir, now: 10_000, planId: `${childStatus}-plan` });
|
|
170
|
+
assert.equal(compatibilityPlan.entries[0]?.decision, "remove");
|
|
171
|
+
assert.equal(compatibilityPlan.entries[0]?.state, "safe");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
writeManifest({ repo, manifestPath, setup, childStatus: "detached" });
|
|
175
|
+
const detachedPlan = buildPlan({ repo, worktreeBaseDir: baseDir, now: 10_000, planId: "detached-plan" });
|
|
176
|
+
assert.equal(detachedPlan.entries[0]?.decision, "keep");
|
|
177
|
+
assert.equal(detachedPlan.entries[0]?.state, "active");
|
|
178
|
+
} finally {
|
|
179
|
+
removeGeneratedWorktrees(repo, setup);
|
|
180
|
+
fs.rmSync(repo, { recursive: true, force: true });
|
|
181
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("keeps dirty and unowned worktrees out of the removable set", () => {
|
|
186
|
+
const repo = createRepo("pi-cleanup-plan-unknown-");
|
|
187
|
+
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-cleanup-plan-base-"));
|
|
188
|
+
let setup: WorktreeSetup | undefined;
|
|
189
|
+
try {
|
|
190
|
+
setup = createWorktrees(repo, "unknown", 2, { baseDir });
|
|
191
|
+
const manifestPath = path.join(repo, ".pi-subagents", "artifacts", "handoff.json");
|
|
192
|
+
writeManifest({ repo, manifestPath, setup });
|
|
193
|
+
fs.writeFileSync(path.join(setup.worktrees[0]!.path, "tracked.txt"), "dirty\n", "utf-8");
|
|
194
|
+
|
|
195
|
+
const plan = buildPlan({ repo, worktreeBaseDir: baseDir, now: 20_000, planId: "unknown-plan" });
|
|
196
|
+
const entries = entriesByPath(plan);
|
|
197
|
+
const dirty = entries.get(__testables.realpathExisting(setup.worktrees[0]!.path));
|
|
198
|
+
const unowned = entries.get(__testables.realpathExisting(setup.worktrees[1]!.path));
|
|
199
|
+
assert.equal(dirty?.decision, "keep");
|
|
200
|
+
assert.equal(dirty?.state, "dirty");
|
|
201
|
+
assert.match(dirty?.reasons.join(" ") ?? "", /uncommitted|untracked/i);
|
|
202
|
+
assert.equal(unowned?.decision, "unknown");
|
|
203
|
+
assert.equal(unowned?.state, "unknown");
|
|
204
|
+
assert.match(unowned?.reasons.join(" ") ?? "", /no matching extension-owned/i);
|
|
205
|
+
assert.ok(fs.existsSync(setup.worktrees[0]!.path));
|
|
206
|
+
assert.ok(fs.existsSync(setup.worktrees[1]!.path));
|
|
207
|
+
} finally {
|
|
208
|
+
removeGeneratedWorktrees(repo, setup);
|
|
209
|
+
fs.rmSync(repo, { recursive: true, force: true });
|
|
210
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("keeps active async ownership and reports missing Git worktrees as stale", () => {
|
|
215
|
+
const repo = createRepo("pi-cleanup-plan-active-");
|
|
216
|
+
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-cleanup-plan-base-"));
|
|
217
|
+
let setup: WorktreeSetup | undefined;
|
|
218
|
+
try {
|
|
219
|
+
setup = createWorktrees(repo, "active", 1, { baseDir });
|
|
220
|
+
const asyncDir = path.join(repo, ".pi-subagents", "async", "active-run");
|
|
221
|
+
const manifestPath = path.join(asyncDir, "handoff.json");
|
|
222
|
+
writeManifest({ repo, manifestPath, setup, runId: "active-run", source: "async" });
|
|
223
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({ runId: "active-run", state: "running" }), "utf-8");
|
|
224
|
+
fs.mkdirSync(path.join(path.dirname(asyncDir), ".active-runs"), { recursive: true });
|
|
225
|
+
fs.writeFileSync(path.join(path.dirname(asyncDir), ".active-runs", path.basename(asyncDir)), "", "utf-8");
|
|
226
|
+
const activePlan = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 30_000, planId: "active-plan" });
|
|
227
|
+
assert.equal(activePlan.entries[0]?.state, "active");
|
|
228
|
+
assert.equal(activePlan.entries[0]?.decision, "keep");
|
|
229
|
+
|
|
230
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({ runId: "active-run", state: "complete" }), "utf-8");
|
|
231
|
+
fs.rmSync(setup.worktrees[0]!.path, { recursive: true, force: true });
|
|
232
|
+
const stalePlan = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 30_000, planId: "stale-plan" });
|
|
233
|
+
assert.equal(stalePlan.entries[0]?.state, "stale");
|
|
234
|
+
assert.equal(stalePlan.entries[0]?.decision, "unknown");
|
|
235
|
+
assert.match(stalePlan.entries[0]?.reasons.join(" ") ?? "", /not present in Git worktree state|missing from disk/i);
|
|
236
|
+
} finally {
|
|
237
|
+
removeGeneratedWorktrees(repo, setup);
|
|
238
|
+
fs.rmSync(repo, { recursive: true, force: true });
|
|
239
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("requires foreground ownership proof instead of inferring activity from the artifacts directory", () => {
|
|
244
|
+
const repo = createRepo("pi-cleanup-plan-foreground-");
|
|
245
|
+
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-cleanup-plan-base-"));
|
|
246
|
+
let setup: WorktreeSetup | undefined;
|
|
247
|
+
try {
|
|
248
|
+
setup = createWorktrees(repo, "foreground", 1, { baseDir });
|
|
249
|
+
const manifestPath = path.join(repo, ".pi-subagents", "artifacts", "handoff.json");
|
|
250
|
+
writeManifest({ repo, manifestPath, setup, runId: "foreground-run", source: "foreground" });
|
|
251
|
+
const noProof = buildWorktreeCleanupPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 35_000, planId: "foreground-no-proof" });
|
|
252
|
+
assert.equal(noProof.entries[0]?.state, "unknown");
|
|
253
|
+
assert.equal(noProof.entries[0]?.decision, "unknown");
|
|
254
|
+
assert.match(noProof.entries[0]?.reasons.join(" ") ?? "", /foreground owning-run state is not provably terminal/i);
|
|
255
|
+
|
|
256
|
+
const active = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 35_000, planId: "foreground-active", foregroundRunOwnership: () => "active" });
|
|
257
|
+
assert.equal(active.entries[0]?.state, "active");
|
|
258
|
+
assert.equal(active.entries[0]?.decision, "keep");
|
|
259
|
+
} finally {
|
|
260
|
+
removeGeneratedWorktrees(repo, setup);
|
|
261
|
+
fs.rmSync(repo, { recursive: true, force: true });
|
|
262
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("requires a recorded patch or local target ancestry for committed divergence", () => {
|
|
267
|
+
const repo = createRepo("pi-cleanup-plan-divergence-");
|
|
268
|
+
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-cleanup-plan-base-"));
|
|
269
|
+
let setup: WorktreeSetup | undefined;
|
|
270
|
+
try {
|
|
271
|
+
setup = createWorktrees(repo, "divergence", 1, { baseDir });
|
|
272
|
+
const manifestPath = path.join(repo, ".pi-subagents", "artifacts", "handoff.json");
|
|
273
|
+
writeManifest({ repo, manifestPath, setup });
|
|
274
|
+
const worktree = setup.worktrees[0]!;
|
|
275
|
+
fs.writeFileSync(path.join(worktree.path, "unmerged.txt"), "unmerged\n", "utf-8");
|
|
276
|
+
git(worktree.path, ["add", "unmerged.txt"]);
|
|
277
|
+
git(worktree.path, ["commit", "-m", "unmerged"]);
|
|
278
|
+
|
|
279
|
+
const unmerged = buildPlan({ repo, worktreeBaseDir: baseDir, now: 40_000, planId: "unmerged-plan" });
|
|
280
|
+
assert.equal(unmerged.entries[0]?.decision, "keep");
|
|
281
|
+
assert.equal(unmerged.entries[0]?.state, "ineligible");
|
|
282
|
+
assert.match(unmerged.entries[0]?.reasons.join(" ") ?? "", /neither preserved.*nor merged/i);
|
|
283
|
+
|
|
284
|
+
const patchPath = path.join(repo, ".pi-subagents", "artifacts", "divergence.patch");
|
|
285
|
+
writeManifest({ repo, manifestPath, setup, patch: { path: patchPath, changed: true } });
|
|
286
|
+
const captured = buildPlan({ repo, worktreeBaseDir: baseDir, now: 40_000, planId: "captured-plan" });
|
|
287
|
+
assert.equal(captured.entries[0]?.decision, "remove");
|
|
288
|
+
assert.equal(captured.entries[0]?.state, "safe");
|
|
289
|
+
assert.equal(captured.entries[0]?.willDeleteBranch, false);
|
|
290
|
+
} finally {
|
|
291
|
+
removeGeneratedWorktrees(repo, setup);
|
|
292
|
+
fs.rmSync(repo, { recursive: true, force: true });
|
|
293
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("keeps stale markers, pending captures, and inconsistent cleanup metadata non-removable", () => {
|
|
298
|
+
const repo = createRepo("pi-cleanup-plan-stale-");
|
|
299
|
+
const baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-cleanup-plan-base-"));
|
|
300
|
+
let setup: WorktreeSetup | undefined;
|
|
301
|
+
try {
|
|
302
|
+
setup = createWorktrees(repo, "stale", 1, { baseDir });
|
|
303
|
+
const asyncDir = path.join(repo, ".pi-subagents", "async", "stale-run");
|
|
304
|
+
const manifestPath = path.join(asyncDir, "handoff.json");
|
|
305
|
+
writeManifest({ repo, manifestPath, setup, runId: "stale-run", source: "async" });
|
|
306
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({ runId: "stale-run", state: "complete" }), "utf-8");
|
|
307
|
+
const markerPath = path.join(path.dirname(asyncDir), ".active-runs", path.basename(asyncDir));
|
|
308
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
309
|
+
fs.writeFileSync(markerPath, "", "utf-8");
|
|
310
|
+
fs.utimesSync(markerPath, new Date(0), new Date(0));
|
|
311
|
+
const stale = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS + 1, planId: "stale-marker-plan" });
|
|
312
|
+
assert.equal(stale.entries[0]?.state, "stale");
|
|
313
|
+
assert.equal(stale.entries[0]?.decision, "unknown");
|
|
314
|
+
|
|
315
|
+
fs.rmSync(markerPath, { force: true });
|
|
316
|
+
writeManifest({ repo, manifestPath, setup, source: "foreground" });
|
|
317
|
+
fs.rmSync(path.join(asyncDir, "status.json"), { force: true });
|
|
318
|
+
const pending = JSON.parse(fs.readFileSync(manifestPath, "utf-8")) as { groups: Array<{ children: Array<{ taskIndex: number }>; cleanup: { state: string; tasks: Array<{ reason?: string }> } }> };
|
|
319
|
+
pending.groups[0]!.cleanup.tasks[0]!.reason = "cleanup pending durable handoff capture";
|
|
320
|
+
fs.writeFileSync(manifestPath, JSON.stringify(pending), "utf-8");
|
|
321
|
+
const pendingPlan = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 50_000, planId: "pending-capture-plan" });
|
|
322
|
+
assert.equal(pendingPlan.entries[0]?.state, "ineligible");
|
|
323
|
+
assert.equal(pendingPlan.entries[0]?.decision, "keep");
|
|
324
|
+
|
|
325
|
+
pending.groups[0]!.cleanup.tasks[0]!.reason = undefined;
|
|
326
|
+
pending.groups[0]!.cleanup.state = "complete";
|
|
327
|
+
fs.writeFileSync(manifestPath, JSON.stringify(pending), "utf-8");
|
|
328
|
+
const inconsistent = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 50_000, planId: "inconsistent-cleanup-plan" });
|
|
329
|
+
assert.equal(inconsistent.entries[0]?.state, "unknown");
|
|
330
|
+
assert.equal(inconsistent.entries[0]?.decision, "unknown");
|
|
331
|
+
|
|
332
|
+
pending.groups[0]!.cleanup.state = "partial";
|
|
333
|
+
pending.groups[0]!.children.push({ taskIndex: pending.groups[0]!.children[0]!.taskIndex });
|
|
334
|
+
fs.writeFileSync(manifestPath, JSON.stringify(pending), "utf-8");
|
|
335
|
+
const duplicateChild = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 50_000, planId: "duplicate-child-plan" });
|
|
336
|
+
assert.equal(duplicateChild.entries[0]?.state, "unknown");
|
|
337
|
+
assert.match(duplicateChild.entries[0]?.reasons.join(" ") ?? "", /no matching extension-owned/i);
|
|
338
|
+
|
|
339
|
+
writeManifest({ repo, manifestPath, setup, source: "foreground", outputPath: path.join(repo, "missing-output.json") });
|
|
340
|
+
const missingReport = buildPlan({ repo, handoffPath: manifestPath, worktreeBaseDir: baseDir, now: 50_000, planId: "missing-report-plan" });
|
|
341
|
+
assert.equal(missingReport.entries[0]?.state, "unknown");
|
|
342
|
+
assert.match(missingReport.entries[0]?.reasons.join(" ") ?? "", /durable handoff path is missing/i);
|
|
343
|
+
} finally {
|
|
344
|
+
removeGeneratedWorktrees(repo, setup);
|
|
345
|
+
fs.rmSync(repo, { recursive: true, force: true });
|
|
346
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
});
|
|
@@ -74,6 +74,27 @@ describe("worktree", () => {
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
+
it("invokes beforeCreate with deterministic ownership metadata before creating worktrees", () => {
|
|
78
|
+
const repoDir = createRepo("pi-worktree-before-create-");
|
|
79
|
+
let setup: WorktreeSetup | undefined;
|
|
80
|
+
let planned: WorktreeSetup | undefined;
|
|
81
|
+
try {
|
|
82
|
+
setup = createWorktrees(repoDir, "before-create", 1, {
|
|
83
|
+
beforeCreate: (candidate) => {
|
|
84
|
+
planned = candidate;
|
|
85
|
+
assert.equal(fs.existsSync(candidate.worktrees[0]!.path), false);
|
|
86
|
+
assert.equal(candidate.worktrees[0]!.branch, "pi-parallel-before-create-0");
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
assert.equal(planned?.baseCommit, setup.baseCommit);
|
|
90
|
+
assert.equal(planned?.worktrees[0]?.path, setup.worktrees[0]?.path);
|
|
91
|
+
assert.equal(fs.existsSync(setup.worktrees[0]!.path), true);
|
|
92
|
+
} finally {
|
|
93
|
+
if (setup) cleanupWorktrees(setup);
|
|
94
|
+
cleanupRepo(repoDir);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
77
98
|
it("createWorktrees maps subdirectory cwd to each agentCwd", () => {
|
|
78
99
|
const repoDir = createRepo("pi-worktree-subdir-");
|
|
79
100
|
const nestedDir = path.join(repoDir, "packages", "app");
|
|
@@ -6,13 +6,13 @@ import { describe, it } from "node:test";
|
|
|
6
6
|
const readProjectFile = (file: string): string => readFileSync(join(process.cwd(), file), "utf-8");
|
|
7
7
|
|
|
8
8
|
describe("writer budget guidance", () => {
|
|
9
|
-
it("keeps hard
|
|
9
|
+
it("keeps hard tool and usage caps off mutation-capable workers", () => {
|
|
10
10
|
const toolReference = readProjectFile("docs/tool-reference.md");
|
|
11
11
|
const skill = readProjectFile("skills/pi-subagents/SKILL.md");
|
|
12
12
|
const reviewLoop = readProjectFile("prompts/review-loop.md");
|
|
13
13
|
|
|
14
14
|
for (const text of [toolReference, skill, reviewLoop]) {
|
|
15
|
-
assert.match(text, /As a conservative orchestration policy, do not (?:pass|set)
|
|
15
|
+
assert.match(text, /As a conservative orchestration policy, do not (?:pass|set) a hard `toolBudget`/);
|
|
16
16
|
assert.match(text, /default tool budget blocks read\/search tools rather than mutation tools/i);
|
|
17
17
|
assert.match(text, /checkpoint after the current tool returns/);
|
|
18
18
|
assert.match(text, /changed files/);
|
|
@@ -22,9 +22,4 @@ describe("writer budget guidance", () => {
|
|
|
22
22
|
assert.match(toolReference, /elapsed timeout is not a mutation-safe boundary/i);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it("documents deferred hard-limit termination at tool-using boundaries", () => {
|
|
26
|
-
const toolReference = readProjectFile("docs/tool-reference.md");
|
|
27
|
-
assert.match(toolReference, /termination occurs at the next assistant boundary/);
|
|
28
|
-
assert.match(toolReference, /`termination-deferred`/);
|
|
29
|
-
});
|
|
30
25
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.ts";
|
|
4
|
+
|
|
5
|
+
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
6
|
+
const antiSlopEffectPlugin = eslintCompatPlugin({
|
|
7
|
+
meta: { name: "anti-slop-effect" },
|
|
8
|
+
rules: {
|
|
9
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export default antiSlopEffectPlugin;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
+
|
|
5
|
+
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
6
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
7
|
+
|
|
8
|
+
function isProjectLocalImport(source: string): boolean {
|
|
9
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getImportedName(specifier: ESTree.ImportSpecifier): string {
|
|
13
|
+
if (specifier.imported.type === "Identifier") return specifier.imported.name;
|
|
14
|
+
return specifier.imported.value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
18
|
+
export const noServiceConstructorImportsRule = defineRule({
|
|
19
|
+
meta: {
|
|
20
|
+
type: "problem",
|
|
21
|
+
docs: {
|
|
22
|
+
description:
|
|
23
|
+
"Disallow project-local make<CapabilityName> imports outside test and spec files.",
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
serviceConstructorImport:
|
|
27
|
+
'Do not import Effect service constructor "{{name}}" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root.',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
ImportDeclaration(node) {
|
|
35
|
+
if (isTestFile || !isProjectLocalImport(node.source.value)) return;
|
|
36
|
+
|
|
37
|
+
for (const specifier of node.specifiers) {
|
|
38
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
39
|
+
|
|
40
|
+
const importedName = getImportedName(specifier);
|
|
41
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName)) continue;
|
|
42
|
+
|
|
43
|
+
context.report({
|
|
44
|
+
node: specifier,
|
|
45
|
+
messageId: "serviceConstructorImport",
|
|
46
|
+
data: { name: importedName },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.ts";
|
|
4
|
+
import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.ts";
|
|
5
|
+
import { noKnownValueWideningRule } from "./rules/no-known-value-widening.ts";
|
|
6
|
+
import { noModuleMockingRule } from "./rules/no-module-mocking.ts";
|
|
7
|
+
import { noObjectParametersRule } from "./rules/no-object-parameters.ts";
|
|
8
|
+
import { noReflectApplyRule } from "./rules/no-reflect-apply.ts";
|
|
9
|
+
import { noReflectGetRule } from "./rules/no-reflect-get.ts";
|
|
10
|
+
import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.ts";
|
|
11
|
+
import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.ts";
|
|
12
|
+
import { noUnknownParametersRule } from "./rules/no-unknown-parameters.ts";
|
|
13
|
+
import { noUnknownReturnsRule } from "./rules/no-unknown-returns.ts";
|
|
14
|
+
import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.ts";
|
|
15
|
+
import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.ts";
|
|
16
|
+
import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.ts";
|
|
17
|
+
import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.ts";
|
|
18
|
+
|
|
19
|
+
/** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
|
|
20
|
+
const antiSlopPlugin = eslintCompatPlugin({
|
|
21
|
+
meta: { name: "anti-slop" },
|
|
22
|
+
rules: {
|
|
23
|
+
"no-chained-type-assertions": noChainedTypeAssertionsRule,
|
|
24
|
+
"no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
|
|
25
|
+
"no-known-value-widening": noKnownValueWideningRule,
|
|
26
|
+
"no-module-mocking": noModuleMockingRule,
|
|
27
|
+
"no-object-parameters": noObjectParametersRule,
|
|
28
|
+
"no-reflect-apply": noReflectApplyRule,
|
|
29
|
+
"no-reflect-get": noReflectGetRule,
|
|
30
|
+
"no-runtime-typeof": noRuntimeTypeofRule,
|
|
31
|
+
"no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
|
|
32
|
+
"no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
|
|
33
|
+
"no-unknown-parameters": noUnknownParametersRule,
|
|
34
|
+
"no-unknown-returns": noUnknownReturnsRule,
|
|
35
|
+
"no-unknown-type-aliases": noUnknownTypeAliasesRule,
|
|
36
|
+
"no-widen-then-assert": noWidenThenAssertRule,
|
|
37
|
+
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default antiSlopPlugin;
|
package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-chained-type-assertions.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
type TypeAssertionExpression = ESTree.TSAsExpression | ESTree.TSTypeAssertion;
|
|
5
|
+
|
|
6
|
+
function isTypeAssertionExpression(node: ESTree.Node): node is TypeAssertionExpression {
|
|
7
|
+
return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function unwrapParenthesizedExpression(expression: ESTree.Expression): ESTree.Expression {
|
|
11
|
+
let current = expression;
|
|
12
|
+
while (current.type === "ParenthesizedExpression") {
|
|
13
|
+
current = current.expression;
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isConstAssertion(node: TypeAssertionExpression): boolean {
|
|
19
|
+
const { typeAnnotation } = node;
|
|
20
|
+
return (
|
|
21
|
+
typeAnnotation.type === "TSTypeReference" &&
|
|
22
|
+
typeAnnotation.typeName.type === "Identifier" &&
|
|
23
|
+
typeAnnotation.typeName.name === "const"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isOutermostAssertionInChain(node: TypeAssertionExpression): boolean {
|
|
28
|
+
let current: ESTree.Expression = node;
|
|
29
|
+
let parent = node.parent;
|
|
30
|
+
|
|
31
|
+
while (parent.type === "ParenthesizedExpression" && parent.expression === current) {
|
|
32
|
+
current = parent;
|
|
33
|
+
parent = parent.parent;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return !isTypeAssertionExpression(parent) || parent.expression !== current;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isForbiddenAssertionChain(node: TypeAssertionExpression): boolean {
|
|
40
|
+
let assertionCount = 0;
|
|
41
|
+
let hasNonConstAssertion = false;
|
|
42
|
+
let current: ESTree.Expression = node;
|
|
43
|
+
|
|
44
|
+
while (isTypeAssertionExpression(current)) {
|
|
45
|
+
assertionCount += 1;
|
|
46
|
+
hasNonConstAssertion ||= !isConstAssertion(current);
|
|
47
|
+
current = unwrapParenthesizedExpression(current.expression);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return assertionCount > 1 && hasNonConstAssertion;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
|
|
54
|
+
export const noChainedTypeAssertionsRule = defineRule({
|
|
55
|
+
meta: {
|
|
56
|
+
type: "problem",
|
|
57
|
+
docs: {
|
|
58
|
+
description:
|
|
59
|
+
"Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains.",
|
|
60
|
+
},
|
|
61
|
+
messages: {
|
|
62
|
+
chained:
|
|
63
|
+
"This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it.",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
createOnce(context) {
|
|
67
|
+
const checkTypeAssertion = (node: TypeAssertionExpression) => {
|
|
68
|
+
if (!isOutermostAssertionInChain(node) || !isForbiddenAssertionChain(node)) return;
|
|
69
|
+
context.report({ node, messageId: "chained" });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
TSAsExpression: checkTypeAssertion,
|
|
74
|
+
TSTypeAssertion: checkTypeAssertion,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
function unwrapParentheses(node: ESTree.Expression): ESTree.Expression {
|
|
5
|
+
let current = node;
|
|
6
|
+
while (current.type === "ParenthesizedExpression") {
|
|
7
|
+
current = current.expression;
|
|
8
|
+
}
|
|
9
|
+
return current;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function isEmptyObjectExpression(node: ESTree.Expression): boolean {
|
|
13
|
+
return node.type === "ObjectExpression" && node.properties.length === 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isConditionalEmptyObjectSpread(node: ESTree.Expression): boolean {
|
|
17
|
+
const conditional = unwrapParentheses(node);
|
|
18
|
+
return (
|
|
19
|
+
conditional.type === "ConditionalExpression" &&
|
|
20
|
+
(isEmptyObjectExpression(conditional.consequent) ||
|
|
21
|
+
isEmptyObjectExpression(conditional.alternate))
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Ban conditional empty-object spreads without changing their omission semantics. */
|
|
26
|
+
export const noConditionalEmptyObjectSpreadRule = defineRule({
|
|
27
|
+
meta: {
|
|
28
|
+
type: "suggestion",
|
|
29
|
+
docs: {
|
|
30
|
+
description:
|
|
31
|
+
"Disallow object spreads that conditionally spread an empty object to omit fields.",
|
|
32
|
+
},
|
|
33
|
+
messages: {
|
|
34
|
+
avoid:
|
|
35
|
+
"This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
createOnce(context) {
|
|
39
|
+
return {
|
|
40
|
+
SpreadElement(node) {
|
|
41
|
+
if (node.parent.type !== "ObjectExpression") return;
|
|
42
|
+
|
|
43
|
+
if (isConditionalEmptyObjectSpread(node.argument)) {
|
|
44
|
+
context.report({ node, messageId: "avoid" });
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|