@selesai/code 0.9.10 → 0.9.12
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 +271 -255
- package/dist/cli/args.js +13 -2
- package/dist/cli/args.test.js +8 -0
- package/dist/cli/credential-print.js +4 -4
- package/dist/cli.js +0 -0
- package/dist/config.d.ts +4 -6
- package/dist/config.js +10 -14
- package/dist/core/agent-session-auto-handoff.test.js +24 -1
- package/dist/core/agent-session.d.ts +10 -4
- package/dist/core/agent-session.js +61 -46
- package/dist/core/compaction/branch-summarization.js +30 -30
- package/dist/core/compaction/compaction.js +81 -81
- package/dist/core/compaction/utils.js +2 -2
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.js +9 -0
- package/dist/core/export-html/template.css +1066 -1066
- package/dist/core/export-html/template.html +55 -55
- package/dist/core/export-html/template.js +1864 -1864
- package/dist/core/export-html/vendor/highlight.min.js +1212 -1212
- package/dist/core/export-html/vendor/marked.min.js +78 -78
- package/dist/core/extensions/loader.js +108 -35
- package/dist/core/extensions/loader.test.js +21 -0
- package/dist/core/extensions/types.d.ts +12 -4
- package/dist/core/keybindings.d.ts +2 -2
- package/dist/core/messages.js +7 -7
- package/dist/core/model-resolver.d.ts +1 -0
- package/dist/core/model-resolver.js +10 -4
- package/dist/core/package-manager.js +4 -4
- package/dist/core/sdk.d.ts +5 -5
- package/dist/core/sdk.js +16 -4
- package/dist/core/settings-manager.d.ts +6 -2
- package/dist/core/settings-manager.js +22 -3
- package/dist/core/tools/bash.d.ts +18 -1
- package/dist/core/tools/bash.js +41 -23
- package/dist/core/tools/index.d.ts +4 -2
- package/dist/core/tools/index.js +9 -2
- package/dist/core/tools/powershell.d.ts +15 -0
- package/dist/core/tools/powershell.js +38 -0
- package/dist/core/tools/powershell.test.d.ts +1 -0
- package/dist/core/tools/powershell.test.js +20 -0
- package/dist/defaults/settings.json +0 -1
- package/dist/extensions/context-compaction-reminder.test.ts +82 -82
- package/dist/extensions/context-compaction-reminder.ts +28 -28
- package/dist/extensions/model-prompt-injector/index.test.ts +0 -10
- package/dist/extensions/model-prompt-injector/index.ts +0 -3
- package/dist/extensions/pi-intercom/CHANGELOG.md +53 -16
- package/dist/extensions/pi-intercom/LICENSE +21 -21
- package/dist/extensions/pi-intercom/README.md +41 -8
- package/dist/extensions/pi-intercom/banner.png +0 -0
- package/dist/extensions/pi-intercom/broker/broker.ts +498 -215
- package/dist/extensions/pi-intercom/broker/client.test.ts +83 -83
- package/dist/extensions/pi-intercom/broker/client.ts +39 -12
- package/dist/extensions/pi-intercom/broker/extension.test.ts +486 -387
- package/dist/extensions/pi-intercom/broker/framing.test.ts +114 -114
- package/dist/extensions/pi-intercom/broker/paths.test.ts +153 -153
- package/dist/extensions/pi-intercom/broker/paths.ts +134 -134
- package/dist/extensions/pi-intercom/broker/protocol.ts +26 -0
- package/dist/extensions/pi-intercom/broker/runtime-claim.test.ts +34 -34
- package/dist/extensions/pi-intercom/broker/runtime-claim.ts +21 -21
- package/dist/extensions/pi-intercom/broker/spawn.test.ts +5 -20
- package/dist/extensions/pi-intercom/config.test.ts +41 -0
- package/dist/extensions/pi-intercom/config.ts +21 -0
- package/dist/extensions/pi-intercom/cwd.test.ts +40 -40
- package/dist/extensions/pi-intercom/cwd.ts +31 -31
- package/dist/extensions/pi-intercom/extension-api.ts +84 -44
- package/dist/extensions/pi-intercom/format-context.test.ts +31 -31
- package/dist/extensions/pi-intercom/format-context.ts +32 -32
- package/dist/extensions/pi-intercom/index.ts +362 -26
- package/dist/extensions/pi-intercom/intercom.integration.test.ts +819 -13
- package/dist/extensions/pi-intercom/package.json +1 -1
- package/dist/extensions/pi-intercom/project-agent.ts +2 -2
- package/dist/extensions/pi-intercom/skills/pi-intercom/SKILL.md +8 -110
- package/dist/extensions/pi-intercom/test/overlay-width.test.ts +66 -66
- package/dist/extensions/pi-intercom/types.ts +32 -5
- package/dist/extensions/pi-intercom/ui/compose.ts +143 -143
- package/dist/extensions/pi-intercom/ui/inline-message.ts +6 -0
- package/dist/extensions/pi-intercom/ui/session-list.ts +166 -166
- package/dist/extensions/pi-powerline-footer/bash-mode/shell-session.ts +286 -286
- package/dist/extensions/pi-powerline-footer/bash-mode/transcript.ts +108 -108
- package/dist/extensions/pi-powerline-footer/separators.ts +57 -57
- package/dist/extensions/pi-powerline-footer/tests/session-usage.test.ts +47 -47
- package/dist/extensions/pi-powerline-footer/tests/tps.test.ts +39 -39
- package/dist/extensions/pi-powerline-footer/theme.example.json +24 -24
- package/dist/extensions/pi-powerline-footer/theme.json +12 -12
- package/dist/extensions/pi-powerline-footer/tps.ts +345 -345
- package/dist/extensions/pi-rewind-hook/README.md +245 -245
- package/dist/extensions/pi-rewind-hook/index.ts +1445 -1445
- package/dist/extensions/pi-rewind-hook/package.json +29 -29
- package/dist/extensions/pi-subagents/.github/assets/subagent-fleet-inspector.png +0 -0
- package/dist/extensions/pi-subagents/.github/workflows/release.yml +28 -0
- package/dist/extensions/pi-subagents/.github/workflows/test.yml +51 -0
- package/dist/extensions/pi-subagents/.greptile/config.json +33 -0
- package/dist/extensions/pi-subagents/.greptile/files.json +8 -0
- package/dist/extensions/pi-subagents/.greptile/rules.md +16 -0
- package/dist/extensions/pi-subagents/CHANGELOG.md +309 -87
- package/dist/extensions/pi-subagents/README.md +15 -17
- package/dist/extensions/pi-subagents/agents/oracle.md +3 -1
- package/dist/extensions/pi-subagents/agents/researcher.md +32 -13
- package/dist/extensions/pi-subagents/agents/reviewer.md +13 -2
- package/dist/extensions/pi-subagents/agents/scout.md +2 -2
- package/dist/extensions/pi-subagents/agents/worker.md +2 -1
- package/dist/extensions/pi-subagents/async-retention-discovery-worker.mjs +180 -0
- package/dist/extensions/pi-subagents/docs/configuration.md +106 -27
- package/dist/extensions/pi-subagents/docs/extension-api.md +85 -21
- package/dist/extensions/pi-subagents/docs/missions.md +41 -4
- package/dist/extensions/pi-subagents/docs/models.md +52 -9
- package/dist/extensions/pi-subagents/docs/observability.md +103 -16
- package/dist/extensions/pi-subagents/docs/tool-reference.md +60 -45
- package/dist/extensions/pi-subagents/docs/watchdog.md +60 -3
- package/dist/extensions/pi-subagents/docs/workflows.md +181 -7
- package/dist/extensions/pi-subagents/index.ts +10 -1
- package/dist/extensions/pi-subagents/install.mjs +4 -4
- package/dist/extensions/pi-subagents/package-lock.json +1483 -1470
- package/dist/extensions/pi-subagents/package.json +6 -3
- package/dist/extensions/pi-subagents/prompts/council.md +60 -0
- package/dist/extensions/pi-subagents/prompts/parallel-review.md +5 -1
- package/dist/extensions/pi-subagents/prompts/review-loop.md +9 -5
- package/dist/extensions/pi-subagents/skills/council-mode/SKILL.md +254 -0
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +18 -17
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/constraints-and-recipes.md +31 -9
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md +107 -140
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +9 -12
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/multi-lane-orchestration.md +39 -0
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/prompting-and-roles.md +44 -92
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +261 -368
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +6 -2
- package/dist/extensions/pi-subagents/src/agents/agents.ts +388 -85
- package/dist/extensions/pi-subagents/src/agents/builtin-names.ts +14 -0
- package/dist/extensions/pi-subagents/src/agents/runtime-agent-registry.ts +418 -0
- package/dist/extensions/pi-subagents/src/agents/skills.ts +1 -1
- package/dist/extensions/pi-subagents/src/api/agents.ts +7 -0
- package/dist/extensions/pi-subagents/src/api/external-job-provider.ts +195 -0
- package/dist/extensions/pi-subagents/src/api/preflight.ts +88 -27
- package/dist/extensions/pi-subagents/src/api/project-panes.ts +2 -0
- package/dist/extensions/pi-subagents/src/api/shared-types.ts +2 -0
- package/dist/extensions/pi-subagents/src/extension/config.ts +20 -11
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +14 -6
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +5 -4
- package/dist/extensions/pi-subagents/src/extension/index.ts +270 -187
- package/dist/extensions/pi-subagents/src/extension/public-execution.ts +65 -28
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +120 -11
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +46 -64
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +51 -37
- package/dist/extensions/pi-subagents/src/extension/tool-result.ts +19 -0
- package/dist/extensions/pi-subagents/src/inspectors/herdr/actions.ts +2 -2
- package/dist/extensions/pi-subagents/src/inspectors/herdr/client.ts +3 -3
- package/dist/extensions/pi-subagents/src/inspectors/herdr/focus.ts +55 -0
- package/dist/extensions/pi-subagents/src/inspectors/herdr/inspector-runner.ts +2 -1
- package/dist/extensions/pi-subagents/src/inspectors/herdr/project-panes.ts +230 -46
- package/dist/extensions/pi-subagents/src/integrations/herdr-status.ts +26 -4
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +32 -10
- package/dist/extensions/pi-subagents/src/missions/lifecycle.ts +6 -1
- package/dist/extensions/pi-subagents/src/missions/store.ts +4 -9
- package/dist/extensions/pi-subagents/src/missions/workflow-state.ts +2 -2
- package/dist/extensions/pi-subagents/src/policy/authority.ts +2 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +3 -1
- package/dist/extensions/pi-subagents/src/runs/background/active-run-index.ts +31 -8
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +210 -52
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +63 -33
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +71 -17
- package/dist/extensions/pi-subagents/src/runs/background/async-retention.ts +886 -0
- package/dist/extensions/pi-subagents/src/runs/background/async-status-snapshot.ts +14 -5
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +49 -56
- package/dist/extensions/pi-subagents/src/runs/background/auto-drain.ts +1 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +3 -33
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +5 -0
- package/dist/extensions/pi-subagents/src/runs/background/completion-dedupe.ts +5 -1
- package/dist/extensions/pi-subagents/src/runs/background/completion-replay.ts +22 -12
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +105 -71
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +68 -19
- package/dist/extensions/pi-subagents/src/runs/background/index-segment.ts +59 -0
- package/dist/extensions/pi-subagents/src/runs/background/inspect-rpc.ts +443 -0
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +94 -10
- package/dist/extensions/pi-subagents/src/runs/background/result-files.ts +158 -90
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +141 -53
- package/dist/extensions/pi-subagents/src/runs/background/resume-guidance.ts +8 -5
- package/dist/extensions/pi-subagents/src/runs/background/retained-children.ts +14 -4
- package/dist/extensions/pi-subagents/src/runs/background/run-id-query.ts +7 -0
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +13 -14
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +46 -25
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +823 -0
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +9 -3
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +11 -1
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +594 -216
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +17 -13
- package/dist/extensions/pi-subagents/src/runs/background/terminal-run-index.ts +138 -0
- package/dist/extensions/pi-subagents/src/runs/background/wait-completions.ts +23 -4
- package/dist/extensions/pi-subagents/src/runs/background/wait-subscriptions.ts +82 -4
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +5 -3
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +21 -14
- package/dist/extensions/pi-subagents/src/runs/foreground/async-stop-action.ts +23 -2
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +153 -58
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-history.ts +7 -9
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +1283 -1657
- package/dist/extensions/pi-subagents/src/runs/foreground/workflow-detach-reconcile.ts +274 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/workflow-foreground-steering.ts +6 -5
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +59 -10
- package/dist/extensions/pi-subagents/src/runs/shared/agent-contract.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/shared/chain-outputs.ts +1 -3
- package/dist/extensions/pi-subagents/src/runs/shared/child-identity.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +52 -2
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/shared/extension-bindings.ts +78 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-runner.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-job-bridge.ts +460 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-job-runner.ts +389 -0
- package/dist/extensions/pi-subagents/src/runs/shared/fast-mode-extension.ts +10 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +14 -0
- package/dist/extensions/pi-subagents/src/runs/shared/model-exclusions.ts +243 -0
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +201 -85
- package/dist/extensions/pi-subagents/src/runs/shared/model-scope.ts +106 -39
- package/dist/extensions/pi-subagents/src/runs/shared/mutation-evidence.ts +145 -0
- package/dist/extensions/pi-subagents/src/runs/shared/orca-progress-tabs.ts +150 -27
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +46 -4
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +19 -15
- package/dist/extensions/pi-subagents/src/runs/shared/permissions.ts +5 -1
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +86 -2
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +9 -9
- package/dist/extensions/pi-subagents/src/runs/shared/session-lease.ts +0 -6
- package/dist/extensions/pi-subagents/src/runs/shared/structured-output.ts +18 -4
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-control.ts +51 -7
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +62 -21
- package/dist/extensions/pi-subagents/src/runs/shared/tool-availability.ts +1 -3
- package/dist/extensions/pi-subagents/src/runs/shared/tool-timeout.ts +1 -3
- package/dist/extensions/pi-subagents/src/runs/shared/workflow-graph.ts +1 -23
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +14 -2
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +2 -2
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +22 -2
- package/dist/extensions/pi-subagents/src/shared/capacity-resilient-json.ts +102 -0
- package/dist/extensions/pi-subagents/src/shared/completion-owner.ts +14 -0
- package/dist/extensions/pi-subagents/src/shared/file-system-retry.ts +49 -1
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +59 -1
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +12 -5
- package/dist/extensions/pi-subagents/src/shared/model-info.ts +20 -0
- package/dist/extensions/pi-subagents/src/shared/prompt-resources.ts +0 -40
- package/dist/extensions/pi-subagents/src/shared/settings.ts +11 -30
- package/dist/extensions/pi-subagents/src/shared/thinking-ceiling.ts +52 -0
- package/dist/extensions/pi-subagents/src/shared/types.ts +228 -49
- package/dist/extensions/pi-subagents/src/shared/utils.ts +11 -3
- package/dist/extensions/pi-subagents/src/shared/watch-strategy.ts +10 -0
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +0 -162
- package/dist/extensions/pi-subagents/src/slash/slash-bridge.ts +2 -5
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +105 -13
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +6 -36
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +829 -0
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +1415 -0
- package/dist/extensions/pi-subagents/src/tui/render.ts +78 -7
- package/dist/extensions/pi-subagents/src/watchdog/change-signature.ts +1 -1
- package/dist/extensions/pi-subagents/src/watchdog/lsp-diagnostics.ts +1 -0
- package/dist/extensions/pi-subagents/src/watchdog/permission-arbiter.ts +59 -51
- package/dist/extensions/pi-subagents/src/watchdog/register-main.ts +8 -2
- package/dist/extensions/pi-subagents/src/watchdog/tool-actions.ts +2 -1
- package/dist/extensions/pi-subagents/src/workflows/chat-progress.ts +4 -4
- package/dist/extensions/pi-subagents/src/workflows/scripted-workflow.ts +471 -86
- package/dist/extensions/pi-subagents/src/workflows/workflow-receipt.ts +140 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/bun/cli.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/bun/register-bedrock.d.ts +2 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/bun/restore-sandbox-env.d.ts +17 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/args.d.ts +57 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/config-selector.d.ts +16 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/file-processor.d.ts +15 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/initial-message.d.ts +18 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/list-models.d.ts +9 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/project-trust.d.ts +10 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/session-picker.d.ts +10 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli/startup-ui.d.ts +20 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/cli.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/config.d.ts +96 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/agent-session-runtime.d.ts +119 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/agent-session-services.d.ts +85 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/agent-session.d.ts +620 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/auth-guidance.d.ts +5 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/auth-storage.d.ts +56 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/bash-executor.d.ts +32 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/cache-stats.d.ts +49 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/compaction/branch-summarization.d.ts +93 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/compaction/compaction.d.ts +128 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/compaction/index.d.ts +7 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/compaction/utils.d.ts +38 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/defaults.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/diagnostics.d.ts +15 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/event-bus.d.ts +9 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/exec.d.ts +29 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/experimental.d.ts +2 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/export-html/index.d.ts +37 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/export-html/tool-renderer.d.ts +34 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/extensions/index.d.ts +12 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/extensions/loader.d.ts +23 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/extensions/runner.d.ts +171 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/extensions/types.d.ts +1261 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/extensions/wrapper.d.ts +20 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/footer-data-provider.d.ts +54 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/http-dispatcher.d.ts +22 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/index.d.ts +13 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/keybindings.d.ts +358 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/messages.d.ts +77 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/model-config.d.ts +512 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/model-registry.d.ts +43 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/model-resolver.d.ts +121 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/model-runtime.d.ts +82 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/models-store.d.ts +17 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/output-guard.d.ts +7 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/package-manager.d.ts +210 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/project-trust.d.ts +15 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/prompt-templates.d.ts +54 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/provider-attribution.d.ts +4 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/provider-composer.d.ts +55 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/radius.d.ts +2 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/remote-catalog-provider.d.ts +5 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/resolve-config-value.d.ts +30 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/resource-loader.d.ts +206 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/sdk.d.ts +106 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/session-cwd.d.ts +19 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/session-manager.d.ts +356 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/settings-manager.d.ts +297 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/skills.d.ts +60 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/slash-commands.d.ts +15 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/source-info.d.ts +18 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/system-prompt.d.ts +28 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/telemetry.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/timings.d.ts +10 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/bash.d.ts +68 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/edit-diff.d.ts +106 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/edit.d.ts +51 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/find.d.ts +35 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/grep.d.ts +37 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/index.d.ts +40 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/ls.d.ts +37 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/output-accumulator.d.ts +52 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/path-utils.d.ts +10 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/read.d.ts +35 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/render-utils.d.ts +24 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/truncate.d.ts +70 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/tools/write.d.ts +26 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/trust-manager.d.ts +36 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/core/usage-totals.d.ts +19 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/extensions/llama/client.d.ts +61 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/extensions/llama/huggingface.d.ts +23 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/extensions/llama/index.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/extensions/llama/provider.d.ts +10 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/extensions/llama/ui.d.ts +42 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/index.d.ts +35 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/main.d.ts +12 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/migrations.d.ts +33 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/index.d.ts +9 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/armin.d.ts +34 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/assistant-message.d.ts +22 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/bash-execution.d.ts +34 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/config-selector.d.ts +102 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/custom-editor.d.ts +21 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/custom-entry.d.ts +19 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/custom-message.d.ts +20 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/daxnuts.d.ts +23 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/extension-editor.d.ts +22 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/extension-selector.d.ts +26 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/first-time-setup.d.ts +25 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/footer.d.ts +32 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/index.d.ts +34 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/login-dialog.d.ts +52 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/model-selector.d.ts +54 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/oauth-selector.d.ts +33 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/scoped-models-selector.d.ts +42 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/settings-selector.d.ts +77 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/status-indicator.d.ts +28 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/tool-execution.d.ts +63 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/tree-selector.d.ts +94 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/trust-selector.d.ts +23 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/user-message.d.ts +14 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/interactive-mode.d.ts +394 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/model-search.d.ts +12 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/theme/theme-controller.d.ts +29 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/interactive/theme/theme.d.ts +120 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/print-mode.d.ts +28 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/rpc/jsonl.d.ts +17 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/rpc/rpc-client.d.ts +246 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/modes/rpc/rpc-types.d.ts +457 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/package-manager-cli.d.ts +8 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/rpc-entry.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/ansi.d.ts +2 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/changelog.d.ts +22 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/child-process.d.ts +18 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/clipboard-native.d.ts +11 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/clipboard.d.ts +4 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/deprecation.d.ts +4 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/exif-orientation.d.ts +5 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/frontmatter.d.ts +8 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/fs-watch.d.ts +5 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/git.d.ts +26 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/html.d.ts +7 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/image-convert.d.ts +10 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/image-process.d.ts +18 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/image-resize-core.d.ts +30 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/image-resize-worker.d.ts +2 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/image-resize.d.ts +16 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/json.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/mime.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/open-browser.d.ts +9 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/paths.d.ts +31 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/photon.d.ts +21 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/shell.d.ts +31 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/sleep.d.ts +5 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/syntax-highlight.d.ts +12 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/tools-manager.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/version-check.d.ts +15 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/dist/utils/windows-self-update.d.ts +3 -0
- package/dist/extensions/pi-subagents/test/fixtures/pi-coding-agent-shim/index.mjs +1 -1
- package/dist/extensions/pi-subagents/test/integration/acceptance-file-report.test.ts +0 -54
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1053 -414
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +194 -4
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +59 -4
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +0 -77
- package/dist/extensions/pi-subagents/test/integration/external-cli-runner.test.ts +107 -6
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +211 -897
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +265 -375
- package/dist/extensions/pi-subagents/test/integration/orca-progress-tabs.test.ts +77 -7
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +10 -10
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +547 -30
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +2112 -310
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +274 -34
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +20 -3
- package/dist/extensions/pi-subagents/test/support/isolated-temp-root.mjs +9 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +30 -5
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +2 -0
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +4 -2
- package/dist/extensions/pi-subagents/test/support/register-loader.mjs +1 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +197 -0
- package/dist/extensions/pi-subagents/test/unit/agent-contract.test.ts +14 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +204 -27
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +444 -145
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +256 -4
- package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +9 -7
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +152 -22
- package/dist/extensions/pi-subagents/test/unit/async-recovery-descriptor.test.ts +29 -0
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +205 -23
- package/dist/extensions/pi-subagents/test/unit/async-retention.test.ts +579 -0
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +24 -0
- package/dist/extensions/pi-subagents/test/unit/authority-policy.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +3 -3
- package/dist/extensions/pi-subagents/test/unit/capacity-resilient-json.test.ts +155 -0
- package/dist/extensions/pi-subagents/test/unit/compaction-resume.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +7 -0
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +123 -0
- package/dist/extensions/pi-subagents/test/unit/completion-replay.test.ts +81 -3
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +109 -7
- package/dist/extensions/pi-subagents/test/unit/default-extensions.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +5 -2
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +3 -2
- package/dist/extensions/pi-subagents/test/unit/extension-bindings.test.ts +79 -0
- package/dist/extensions/pi-subagents/test/unit/external-cli-runner.test.ts +22 -0
- package/dist/extensions/pi-subagents/test/unit/external-job-runner.test.ts +961 -0
- package/dist/extensions/pi-subagents/test/unit/file-system-retry.test.ts +64 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +1110 -0
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +1664 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +81 -1
- package/dist/extensions/pi-subagents/test/unit/herdr-inspector.test.ts +138 -11
- package/dist/extensions/pi-subagents/test/unit/herdr-status-bridge.test.ts +41 -2
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +210 -79
- package/dist/extensions/pi-subagents/test/unit/index-segment.test.ts +95 -0
- package/dist/extensions/pi-subagents/test/unit/inspect-rpc.test.ts +596 -0
- package/dist/extensions/pi-subagents/test/unit/mission-lifecycle.test.ts +10 -1
- package/dist/extensions/pi-subagents/test/unit/mission-store.test.ts +3 -5
- package/dist/extensions/pi-subagents/test/unit/model-exclusions.test.ts +167 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +319 -18
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +78 -0
- package/dist/extensions/pi-subagents/test/unit/model-scope-settings.test.ts +19 -5
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +44 -0
- package/dist/extensions/pi-subagents/test/unit/mutation-evidence.test.ts +129 -0
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +231 -2
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +28 -1
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +106 -2
- package/dist/extensions/pi-subagents/test/unit/orca-progress-tabs.test.ts +204 -7
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +59 -4
- package/dist/extensions/pi-subagents/test/unit/path-handling.test.ts +2 -6
- package/dist/extensions/pi-subagents/test/unit/pi-args-permission-system.test.ts +34 -2
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +116 -6
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +12 -3
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +56 -61
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +416 -1
- package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +9 -2
- package/dist/extensions/pi-subagents/test/unit/project-panes-public-api.test.ts +42 -0
- package/dist/extensions/pi-subagents/test/unit/prompt-workflows.test.ts +21 -30
- package/dist/extensions/pi-subagents/test/unit/public-execution.test.ts +86 -11
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +49 -1
- package/dist/extensions/pi-subagents/test/unit/result-files.test.ts +233 -5
- package/dist/extensions/pi-subagents/test/unit/retained-children.test.ts +28 -5
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +323 -20
- package/dist/extensions/pi-subagents/test/unit/run-id-resolver.test.ts +66 -10
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +68 -5
- package/dist/extensions/pi-subagents/test/unit/runtime-agent-registration.test.ts +174 -0
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +679 -0
- package/dist/extensions/pi-subagents/test/unit/scheduled-store-root.test.ts +67 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +55 -44
- package/dist/extensions/pi-subagents/test/unit/scripted-workflow.test.ts +399 -84
- package/dist/extensions/pi-subagents/test/unit/session-lease.test.ts +13 -0
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/slash-bridge.test.ts +15 -10
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +11 -7
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +2 -0
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +40 -1
- package/dist/extensions/pi-subagents/test/unit/subagent-action-recovery.test.ts +10 -2
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +38 -3
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +110 -12
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +204 -19
- package/dist/extensions/pi-subagents/test/unit/temp-paths.test.ts +25 -0
- package/dist/extensions/pi-subagents/test/unit/thinking-ceiling.test.ts +73 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +90 -50
- package/dist/extensions/pi-subagents/test/unit/tool-timeout.test.ts +1 -2
- package/dist/extensions/pi-subagents/test/unit/wait-subscriptions.test.ts +234 -7
- package/dist/extensions/pi-subagents/test/unit/watch-strategy.test.ts +24 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-permission-arbiter.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-chat-progress.test.ts +37 -9
- package/dist/extensions/pi-subagents/test/unit/workflow-detach-reconcile.test.ts +302 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-launch-params.test.ts +167 -7
- package/dist/extensions/pi-subagents/test/unit/workflow-receipt.test.ts +113 -0
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +6 -6
- package/dist/extensions/pi-web-agent/package.json +31 -31
- package/dist/extensions/pi-web-agent/src/backends/config.ts +205 -205
- package/dist/extensions/pi-web-agent/src/backends/doctor.ts +136 -136
- package/dist/extensions/pi-web-agent/src/backends/factory.ts +152 -152
- package/dist/extensions/pi-web-agent/src/backends/settings-reader.ts +25 -25
- package/dist/extensions/pi-web-agent/src/cache/ttl-cache.ts +28 -28
- package/dist/extensions/pi-web-agent/src/changelog-notice.ts +136 -136
- package/dist/extensions/pi-web-agent/src/commands/web-agent-config.ts +946 -946
- package/dist/extensions/pi-web-agent/src/extension.ts +126 -126
- package/dist/extensions/pi-web-agent/src/extract/readability.ts +118 -118
- package/dist/extensions/pi-web-agent/src/fetch/browser-resolution.ts +199 -199
- package/dist/extensions/pi-web-agent/src/fetch/firecrawl-fetch.ts +100 -100
- package/dist/extensions/pi-web-agent/src/fetch/headless-fetch.ts +117 -117
- package/dist/extensions/pi-web-agent/src/fetch/http-fetch.ts +67 -67
- package/dist/extensions/pi-web-agent/src/orchestration/answer-synthesizer.ts +60 -60
- package/dist/extensions/pi-web-agent/src/orchestration/candidate-selector.ts +50 -50
- package/dist/extensions/pi-web-agent/src/orchestration/direct-url.ts +52 -52
- package/dist/extensions/pi-web-agent/src/orchestration/evidence-quality.ts +105 -105
- package/dist/extensions/pi-web-agent/src/orchestration/evidence-ranker.ts +45 -45
- package/dist/extensions/pi-web-agent/src/orchestration/index.ts +28 -28
- package/dist/extensions/pi-web-agent/src/orchestration/query-planner.ts +47 -47
- package/dist/extensions/pi-web-agent/src/orchestration/research-orchestrator.ts +376 -376
- package/dist/extensions/pi-web-agent/src/orchestration/research-types.ts +64 -64
- package/dist/extensions/pi-web-agent/src/orchestration/research-worker.ts +181 -181
- package/dist/extensions/pi-web-agent/src/orchestration/source-profile.ts +101 -101
- package/dist/extensions/pi-web-agent/src/orchestration/stop-decider.ts +81 -81
- package/dist/extensions/pi-web-agent/src/presentation/config-store.ts +210 -210
- package/dist/extensions/pi-web-agent/src/presentation/config.ts +75 -75
- package/dist/extensions/pi-web-agent/src/presentation/explore-presentation.ts +61 -61
- package/dist/extensions/pi-web-agent/src/presentation/fetch-presentation.ts +54 -54
- package/dist/extensions/pi-web-agent/src/presentation/search-presentation.ts +41 -41
- package/dist/extensions/pi-web-agent/src/presentation/select-view.ts +20 -20
- package/dist/extensions/pi-web-agent/src/presentation/types.ts +63 -63
- package/dist/extensions/pi-web-agent/src/search/brave.ts +114 -114
- package/dist/extensions/pi-web-agent/src/search/duckduckgo.ts +72 -72
- package/dist/extensions/pi-web-agent/src/search/searxng.ts +96 -96
- package/dist/extensions/pi-web-agent/src/tools/web-explore.ts +71 -71
- package/dist/extensions/pi-web-agent/src/tools/web-fetch-headless.ts +31 -31
- package/dist/extensions/pi-web-agent/src/tools/web-fetch.ts +31 -31
- package/dist/extensions/pi-web-agent/src/tools/web-search.ts +157 -157
- package/dist/extensions/pi-web-agent/src/types.ts +88 -88
- package/dist/extensions/ponytail/index.js +31 -25
- package/dist/extensions/ponytail/package.json +8 -8
- package/dist/extensions/ponytail/ponytail-config.cjs +34 -7
- package/dist/extensions/ponytail/ponytail-instructions.cjs +7 -9
- package/dist/extensions/ponytail/test/extension.test.js +7 -8
- package/dist/extensions/ponytail/test/helpers.test.js +1 -1
- package/dist/extensions/question/batch.ts +103 -103
- package/dist/extensions/question/constants.ts +30 -30
- package/dist/extensions/question/helpers.ts +58 -58
- package/dist/extensions/question/navigation.ts +14 -14
- package/dist/extensions/question/package.json +19 -19
- package/dist/extensions/question/schemas.ts +43 -43
- package/dist/extensions/question/selection-mode.ts +46 -46
- package/dist/extensions/question/shortcuts.ts +44 -44
- package/dist/extensions/question/types.ts +132 -132
- package/dist/extensions/test-resolve-hook-impl.mjs +6 -6
- package/dist/extensions/test-resolve-hook.mjs +6 -6
- package/dist/extensions/web-agent-onboarding.ts +222 -222
- package/dist/extensions/workflow/package.json +17 -17
- package/dist/package-manager-cli.js +71 -71
- package/dist/rpc-entry.js +0 -0
- package/dist/skills/agent-browser/SKILL.md +52 -52
- package/dist/skills/batch-grill-me/SKILL.md +19 -19
- package/dist/skills/brandkit/SKILL.md +799 -0
- package/dist/skills/design-taste-frontend/SKILL.md +1207 -0
- package/dist/skills/design-taste-frontend-v1/SKILL.md +227 -0
- package/dist/skills/full-output-enforcement/SKILL.md +50 -0
- package/dist/skills/gpt-taste/SKILL.md +75 -0
- package/dist/skills/grill-me/SKILL.md +10 -10
- package/dist/skills/handoff/SKILL.md +16 -16
- package/dist/skills/handoff-text/SKILL.md +14 -14
- package/dist/skills/high-end-visual-design/SKILL.md +99 -0
- package/dist/skills/image-to-code/SKILL.md +1229 -0
- package/dist/skills/imagegen-frontend-mobile/SKILL.md +1466 -0
- package/dist/skills/imagegen-frontend-web/SKILL.md +988 -0
- package/dist/skills/implanger/SKILL.md +69 -69
- package/dist/skills/improve-codebase/REFERENCE.md +78 -78
- package/dist/skills/improve-codebase/SKILL.md +178 -178
- package/dist/skills/industrial-brutalist-ui/SKILL.md +93 -0
- package/dist/skills/minimalist-ui/SKILL.md +86 -0
- package/dist/skills/pi-subagents/SKILL.md +18 -17
- package/dist/skills/pi-subagents/references/constraints-and-recipes.md +31 -9
- package/dist/skills/pi-subagents/references/execution-controls.md +95 -143
- package/dist/skills/pi-subagents/references/management-authoring-rpc.md +9 -12
- package/dist/skills/pi-subagents/references/multi-lane-orchestration.md +39 -0
- package/dist/skills/pi-subagents/references/prompting-and-roles.md +45 -94
- package/dist/skills/planger/SKILL.md +166 -166
- package/dist/skills/ponytail/SKILL.md +120 -116
- package/dist/skills/ponytail-audit/SKILL.md +41 -42
- package/dist/skills/ponytail-debt/SKILL.md +44 -45
- package/dist/skills/ponytail-gain/SKILL.md +50 -51
- package/dist/skills/ponytail-help/SKILL.md +71 -70
- package/dist/skills/ponytail-review/SKILL.md +57 -58
- package/dist/skills/redesign-existing-projects/SKILL.md +179 -0
- package/dist/skills/selesai-handoff/SKILL.md +20 -20
- package/dist/skills/stitch-design-taste/SKILL.md +185 -0
- package/dist/skills/unlazy/CHANGELOG.md +100 -0
- package/dist/skills/unlazy/CONTRIBUTING.md +66 -0
- package/dist/skills/unlazy/LICENSE +21 -0
- package/dist/skills/unlazy/README.md +242 -0
- package/dist/skills/unlazy/SECURITY.md +70 -0
- package/dist/skills/unlazy/SKILL.md +100 -0
- package/dist/skills/unlazy/package.json +13 -0
- package/dist/skills/unlazy/references/dispatch.md +82 -0
- package/dist/skills/unlazy/references/gates.md +132 -0
- package/dist/skills/unlazy/references/method.md +49 -0
- package/dist/skills/unlazy/references/orchestration.md +99 -0
- package/dist/skills/unlazy/references/parallel.md +123 -0
- package/dist/skills/unlazy/references/token-economy.md +39 -0
- package/dist/skills/unlazy/research/validation-protocol.md +81 -0
- package/dist/skills/unlazy/scripts/dispatch-check.mjs +108 -0
- package/dist/skills/unlazy/scripts/gate-check.mjs +894 -0
- package/dist/skills/unlazy/scripts/gate-lint.mjs +178 -0
- package/dist/skills/unlazy/scripts/install-hooks.mjs +206 -0
- package/dist/skills/unlazy/scripts/lib/check-supervisor.mjs +46 -0
- package/dist/skills/unlazy/scripts/lib/dispatch.mjs +283 -0
- package/dist/skills/unlazy/scripts/lib/gates.mjs +629 -0
- package/dist/skills/unlazy/scripts/lib/process-tree.mjs +161 -0
- package/dist/skills/unlazy/scripts/lib/regex-worker.mjs +9 -0
- package/dist/skills/unlazy/scripts/stop-hook.mjs +174 -0
- package/dist/skills/unlazy/templates/PLAN.md +65 -0
- package/dist/skills/unlazy/templates/gates-leaf.md +51 -0
- package/dist/skills/unlazy/templates/gates-node.md +50 -0
- package/dist/skills/unlazy/tests/contract-tests.mjs +127 -0
- package/dist/skills/unlazy/tests/dispatch-tests.mjs +481 -0
- package/dist/skills/unlazy/tests/hardening-tests.mjs +903 -0
- package/dist/skills/unlazy/tests/lint-tests.mjs +242 -0
- package/dist/skills/unlazy/tests/run-tests.mjs +554 -0
- package/dist/skills/unlazy/tests/self-check.mjs +165 -0
- package/dist/skills/unlazy/tests/stress-tests.mjs +356 -0
- package/dist/skills/web-design-guidelines/SKILL.md +40 -0
- package/dist/skills/workflow-creation/SKILL.md +73 -73
- package/dist/themes/powerline-footer/theme.json +33 -33
- package/dist/utils/shell.d.ts +3 -0
- package/dist/utils/shell.js +17 -5
- package/docs/compaction.md +396 -396
- package/docs/containerization.md +111 -111
- package/docs/development.md +71 -71
- package/docs/docs.json +164 -164
- package/docs/environment-variables.md +86 -86
- package/docs/index.md +83 -83
- package/docs/json.md +82 -82
- package/docs/models.md +502 -502
- package/docs/packages.md +227 -227
- package/docs/plans/subagent-delegation/phase-0-correctness.md +264 -264
- package/docs/plans/subagent-delegation/phase-1-behavioral-contract.md +485 -485
- package/docs/plans/subagent-delegation/phase-2-context-controls.md +281 -281
- package/docs/plans/subagent-delegation/phase-3-advisory-routing.md +361 -361
- package/docs/plans/subagent-delegation/phase-4-optional-enforcement.md +380 -380
- package/docs/prompt-templates.md +95 -95
- package/docs/providers.md +293 -293
- package/docs/sdk.md +1144 -1143
- package/docs/security.md +59 -59
- package/docs/session-format.md +414 -414
- package/docs/sessions.md +145 -145
- package/docs/settings.md +0 -5
- package/docs/shared-host-extensions.md +109 -109
- package/docs/shell-aliases.md +13 -13
- package/docs/skills.md +231 -231
- package/docs/terminal-setup.md +142 -142
- package/docs/termux.md +127 -127
- package/docs/themes.md +295 -295
- package/docs/tmux.md +63 -63
- package/docs/tui.md +927 -927
- package/docs/windows.md +17 -17
- package/examples/README.md +25 -25
- package/examples/extensions/README.md +211 -211
- package/examples/extensions/auto-commit-on-exit.ts +49 -49
- package/examples/extensions/bash-spawn-hook.ts +30 -30
- package/examples/extensions/bookmark.ts +50 -50
- package/examples/extensions/border-status-editor.ts +150 -150
- package/examples/extensions/built-in-tool-renderer.ts +249 -249
- package/examples/extensions/claude-rules.ts +86 -86
- package/examples/extensions/commands.ts +72 -72
- package/examples/extensions/confirm-destructive.ts +59 -59
- package/examples/extensions/custom-compaction.ts +130 -130
- package/examples/extensions/custom-footer.ts +64 -64
- package/examples/extensions/custom-header.ts +73 -73
- package/examples/extensions/custom-provider-anthropic/index.ts +610 -610
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -24
- package/examples/extensions/custom-provider-anthropic/package.json +19 -19
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +404 -404
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -16
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -82
- package/examples/extensions/dirty-repo-guard.ts +56 -56
- package/examples/extensions/doom-overlay/README.md +46 -46
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -21
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -152
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -72
- package/examples/extensions/doom-overlay/doom-component.ts +132 -132
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -173
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -104
- package/examples/extensions/doom-overlay/index.ts +74 -74
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -51
- package/examples/extensions/dynamic-resources/SKILL.md +8 -8
- package/examples/extensions/dynamic-resources/dynamic.json +79 -79
- package/examples/extensions/dynamic-resources/dynamic.md +5 -5
- package/examples/extensions/dynamic-resources/index.ts +15 -15
- package/examples/extensions/dynamic-tools.ts +74 -74
- package/examples/extensions/event-bus.ts +43 -43
- package/examples/extensions/file-trigger.ts +41 -41
- package/examples/extensions/git-checkpoint.ts +53 -53
- package/examples/extensions/git-merge-and-resolve.ts +115 -115
- package/examples/extensions/github-issue-autocomplete.ts +185 -185
- package/examples/extensions/gondolin/index.ts +531 -531
- package/examples/extensions/gondolin/package-lock.json +185 -185
- package/examples/extensions/gondolin/package.json +19 -19
- package/examples/extensions/handoff.ts +199 -199
- package/examples/extensions/hello.ts +26 -26
- package/examples/extensions/hidden-thinking-label.ts +53 -53
- package/examples/extensions/inline-bash.ts +94 -94
- package/examples/extensions/input-transform-streaming.ts +39 -39
- package/examples/extensions/input-transform.ts +43 -43
- package/examples/extensions/interactive-shell.ts +196 -196
- package/examples/extensions/mac-system-theme.ts +47 -47
- package/examples/extensions/message-renderer.ts +59 -59
- package/examples/extensions/minimal-mode.ts +426 -426
- package/examples/extensions/modal-editor.ts +85 -85
- package/examples/extensions/model-status.ts +31 -31
- package/examples/extensions/notify.ts +55 -55
- package/examples/extensions/overlay-qa-tests.ts +1450 -1450
- package/examples/extensions/overlay-test.ts +153 -153
- package/examples/extensions/permission-gate.ts +34 -34
- package/examples/extensions/pirate.ts +47 -47
- package/examples/extensions/plan-mode/README.md +66 -66
- package/examples/extensions/plan-mode/index.ts +390 -390
- package/examples/extensions/plan-mode/utils.ts +168 -168
- package/examples/extensions/preset.ts +436 -436
- package/examples/extensions/project-trust.ts +64 -64
- package/examples/extensions/prompt-customizer.ts +97 -97
- package/examples/extensions/protected-paths.ts +30 -30
- package/examples/extensions/provider-payload.ts +18 -18
- package/examples/extensions/qna.ts +122 -122
- package/examples/extensions/question.ts +285 -285
- package/examples/extensions/questionnaire.ts +448 -448
- package/examples/extensions/rainbow-editor.ts +88 -88
- package/examples/extensions/reload-runtime.ts +37 -37
- package/examples/extensions/rpc-demo.ts +118 -118
- package/examples/extensions/sandbox/index.ts +321 -321
- package/examples/extensions/sandbox/package-lock.json +92 -92
- package/examples/extensions/sandbox/package.json +19 -19
- package/examples/extensions/send-user-message.ts +97 -97
- package/examples/extensions/session-name.ts +27 -27
- package/examples/extensions/shutdown-command.ts +63 -63
- package/examples/extensions/snake.ts +343 -343
- package/examples/extensions/space-invaders.ts +560 -560
- package/examples/extensions/ssh.ts +220 -220
- package/examples/extensions/status-line.ts +32 -32
- package/examples/extensions/structured-output.ts +65 -65
- package/examples/extensions/subagent/README.md +175 -175
- package/examples/extensions/subagent/agents/planner.md +37 -37
- package/examples/extensions/subagent/agents/reviewer.md +35 -35
- package/examples/extensions/subagent/agents/scout.md +50 -50
- package/examples/extensions/subagent/agents/worker.md +24 -24
- package/examples/extensions/subagent/agents.ts +126 -126
- package/examples/extensions/subagent/index.ts +1015 -1015
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -10
- package/examples/extensions/subagent/prompts/implement.md +10 -10
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -9
- package/examples/extensions/summarize.ts +209 -209
- package/examples/extensions/system-prompt-header.ts +17 -17
- package/examples/extensions/tic-tac-toe.ts +1008 -1008
- package/examples/extensions/timed-confirm.ts +70 -70
- package/examples/extensions/titlebar-spinner.ts +58 -58
- package/examples/extensions/todo.ts +297 -297
- package/examples/extensions/tool-override.ts +144 -144
- package/examples/extensions/tools.ts +146 -146
- package/examples/extensions/trigger-compact.ts +50 -50
- package/examples/extensions/truncated-tool.ts +195 -195
- package/examples/extensions/widget-placement.ts +9 -9
- package/examples/extensions/with-deps/index.ts +32 -32
- package/examples/extensions/with-deps/package-lock.json +31 -31
- package/examples/extensions/with-deps/package.json +22 -22
- package/examples/extensions/working-indicator.ts +123 -123
- package/examples/extensions/working-message-test.ts +25 -25
- package/examples/rpc-extension-ui.ts +632 -632
- package/examples/sdk/01-minimal.ts +26 -26
- package/examples/sdk/02-custom-model.ts +53 -53
- package/examples/sdk/03-custom-prompt.ts +75 -75
- package/examples/sdk/04-skills.ts +55 -55
- package/examples/sdk/05-tools.ts +48 -48
- package/examples/sdk/06-extensions.ts +99 -99
- package/examples/sdk/07-context-files.ts +47 -47
- package/examples/sdk/08-prompt-templates.ts +51 -51
- package/examples/sdk/09-api-keys-and-oauth.ts +52 -52
- package/examples/sdk/10-settings.ts +53 -53
- package/examples/sdk/11-sessions.ts +52 -52
- package/examples/sdk/12-full-control.ts +79 -79
- package/examples/sdk/13-session-runtime.ts +67 -67
- package/examples/sdk/README.md +144 -144
- package/package.json +4 -4
- package/dist/core/tools/schema-prune.d.ts +0 -16
- package/dist/core/tools/schema-prune.js +0 -39
- package/dist/core/tools/schema-prune.test.js +0 -111
- package/dist/extensions/pi-subagents/UPSTREAM-V0.50-MAPPING.md +0 -172
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +0 -55
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +0 -61
- package/dist/extensions/pi-subagents/src/agents/task-aware-routing.ts +0 -132
- package/dist/extensions/pi-subagents/src/extension/chain-validation.ts +0 -181
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-clarify.ts +0 -1354
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +0 -1581
- package/dist/extensions/pi-subagents/src/shared/env.ts +0 -16
- package/dist/extensions/pi-subagents/src/shared/session-lineage.ts +0 -71
- package/dist/extensions/pi-subagents/src/slash/inline-subagents.ts +0 -136
- package/dist/extensions/pi-subagents/src/workflows/workflow-auto-relaunch.ts +0 -41
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +0 -466
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +0 -1859
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +0 -733
- package/dist/extensions/pi-subagents/test/unit/builtin-agent-documentation.test.ts +0 -63
- package/dist/extensions/pi-subagents/test/unit/chain-validation.test.ts +0 -326
- package/dist/extensions/pi-subagents/test/unit/handoff-adoption.test.ts +0 -103
- package/dist/extensions/pi-subagents/test/unit/inline-subagents.test.ts +0 -127
- package/dist/extensions/pi-subagents/test/unit/session-lineage.test.ts +0 -73
- package/dist/extensions/pi-subagents/test/unit/task-aware-routing.test.ts +0 -213
- package/dist/extensions/pi-subagents/test/unit/workflow-auto-relaunch.test.ts +0 -65
- /package/dist/core/{tools/schema-prune.test.d.ts → extensions/loader.test.d.ts} +0 -0
|
@@ -0,0 +1,886 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { Worker } from "node:worker_threads";
|
|
7
|
+
import { writeAtomicJson } from "../../shared/atomic-json.ts";
|
|
8
|
+
import type { AsyncStatus } from "../../shared/types.ts";
|
|
9
|
+
import { MISSION_BINDING_FILE } from "../../missions/lifecycle.ts";
|
|
10
|
+
import { ACTIVE_RUN_INDEX_DIR } from "./active-run-index.ts";
|
|
11
|
+
import { encodeIndexSegment } from "./index-segment.ts";
|
|
12
|
+
|
|
13
|
+
export const ASYNC_RETENTION_DAYS = 30;
|
|
14
|
+
export const ASYNC_RETENTION_BATCH_SIZE = 100;
|
|
15
|
+
export const ASYNC_RETENTION_DELAY_MS = 60_000;
|
|
16
|
+
export const ASYNC_RETENTION_TOMBSTONE_GRACE_MS = 24 * 60 * 60 * 1000;
|
|
17
|
+
|
|
18
|
+
const RETENTION_MS = ASYNC_RETENTION_DAYS * 24 * 60 * 60 * 1000;
|
|
19
|
+
const LOCK_NAME = ".async-retention.lock";
|
|
20
|
+
const CURSOR_NAME = ".async-retention-cursor.json";
|
|
21
|
+
const LOG_NAME = "async-retention-maintenance.jsonl";
|
|
22
|
+
const RUN_TOMBSTONE_PREFIX = ".deleting-run-";
|
|
23
|
+
const RESULT_TOMBSTONE_PREFIX = ".deleting-result-";
|
|
24
|
+
const RUN_TOMBSTONE_MARKERS_DIR = "async-retention-run-tombstones";
|
|
25
|
+
const LOCK_STALE_MS = 24 * 60 * 60 * 1000;
|
|
26
|
+
const RUN_MODES = new Set<AsyncStatus["mode"]>(["single", "parallel", "chain", "workflow"]);
|
|
27
|
+
const TERMINAL_STATES = new Set<AsyncStatus["state"]>(["complete", "failed", "stopped", "rejected"]);
|
|
28
|
+
const RESULT_TIMESTAMP_FIELDS = ["endedAt", "completedAt", "createdAt", "writtenAt", "expiresAt", "timestamp"] as const;
|
|
29
|
+
|
|
30
|
+
interface RetentionCursor {
|
|
31
|
+
version: 1;
|
|
32
|
+
runAfter?: string;
|
|
33
|
+
resultAfter?: string;
|
|
34
|
+
resultPublicAfter?: string;
|
|
35
|
+
resultPendingAfterBySession?: Record<string, string>;
|
|
36
|
+
resultReplayAfter?: string;
|
|
37
|
+
resultArchiveAfter?: string;
|
|
38
|
+
pendingSessionAfter?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type ResultCursorKey = keyof Pick<RetentionCursor, "resultPublicAfter" | "resultReplayAfter" | "resultArchiveAfter">;
|
|
42
|
+
type ResultCursorTarget = { type: "result"; key: ResultCursorKey } | { type: "pending"; session: string };
|
|
43
|
+
|
|
44
|
+
interface ResultCandidate {
|
|
45
|
+
path: string;
|
|
46
|
+
relative: string;
|
|
47
|
+
kind: "public" | "pending" | "replay" | "archive" | "tombstone";
|
|
48
|
+
cursor: ResultCursorTarget;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface DiscoveredRunCandidate {
|
|
52
|
+
name: string;
|
|
53
|
+
relative: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type CursorOperation =
|
|
57
|
+
| { type: "set"; key: Exclude<keyof RetentionCursor, "version" | "resultPendingAfterBySession">; value: string }
|
|
58
|
+
| { type: "delete"; key: Exclude<keyof RetentionCursor, "version" | "resultPendingAfterBySession"> }
|
|
59
|
+
| { type: "set-pending"; session: string; value: string }
|
|
60
|
+
| { type: "delete-pending"; session: string };
|
|
61
|
+
|
|
62
|
+
interface RetentionDiscovery {
|
|
63
|
+
discoveryDurationMs: number;
|
|
64
|
+
rawReads: number;
|
|
65
|
+
sourceExhausted: Record<string, boolean>;
|
|
66
|
+
runCandidates: DiscoveredRunCandidate[];
|
|
67
|
+
resultCandidates: Array<Omit<ResultCandidate, "path">>;
|
|
68
|
+
cursorOps: CursorOperation[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface RetentionLockOwner {
|
|
72
|
+
version: 1;
|
|
73
|
+
token: string;
|
|
74
|
+
pid: number;
|
|
75
|
+
hostname: string;
|
|
76
|
+
startedAt: number;
|
|
77
|
+
processStartIdentity?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AsyncRetentionOptions {
|
|
81
|
+
asyncDirRoot: string;
|
|
82
|
+
resultsDir: string;
|
|
83
|
+
waitSubscriptionsDir?: string;
|
|
84
|
+
protectedRunIds?: Iterable<string>;
|
|
85
|
+
now?: () => number;
|
|
86
|
+
retentionMs?: number;
|
|
87
|
+
tombstoneGraceMs?: number;
|
|
88
|
+
batchSize?: number;
|
|
89
|
+
randomId?: () => string;
|
|
90
|
+
maintenanceRoot?: string;
|
|
91
|
+
pid?: number;
|
|
92
|
+
hostname?: string;
|
|
93
|
+
processStartIdentity?: string;
|
|
94
|
+
isProcessAlive?: (pid: number) => boolean | undefined;
|
|
95
|
+
getProcessStartIdentity?: (pid: number) => string | undefined;
|
|
96
|
+
lstatSync?: typeof fs.lstatSync;
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
discoveryWorkerUrl?: URL;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface AsyncRetentionResult {
|
|
102
|
+
acquired: boolean;
|
|
103
|
+
scanned: number;
|
|
104
|
+
deletedRuns: number;
|
|
105
|
+
deletedResults: number;
|
|
106
|
+
reapedTombstones: number;
|
|
107
|
+
skipped: Record<string, number>;
|
|
108
|
+
errors: string[];
|
|
109
|
+
rawReads: number;
|
|
110
|
+
sourceExhausted: Record<string, boolean>;
|
|
111
|
+
discoveryDurationMs: number;
|
|
112
|
+
commitDurationMs: number;
|
|
113
|
+
cancelled: boolean;
|
|
114
|
+
workerFailed: boolean;
|
|
115
|
+
durationMs: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function isNotFound(error: unknown): boolean {
|
|
119
|
+
return typeof error === "object" && error !== null && "code" in error && (error as NodeJS.ErrnoException).code === "ENOENT";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function compactError(error: unknown): string {
|
|
123
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
124
|
+
return message.replace(/\s+/g, " ").slice(0, 240);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function listDir(dir: string): fs.Dirent[] {
|
|
128
|
+
try {
|
|
129
|
+
return fs.readdirSync(dir, { withFileTypes: true });
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (isNotFound(error)) return [];
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function readJson(filePath: string): Record<string, unknown> | undefined {
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, "utf-8")) as unknown;
|
|
139
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed as Record<string, unknown> : undefined;
|
|
140
|
+
} catch {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function readStatus(runDir: string): AsyncStatus | undefined {
|
|
146
|
+
const value = readJson(path.join(runDir, "status.json"));
|
|
147
|
+
if (!value
|
|
148
|
+
|| typeof value.runId !== "string"
|
|
149
|
+
|| typeof value.state !== "string"
|
|
150
|
+
|| typeof value.mode !== "string"
|
|
151
|
+
|| !RUN_MODES.has(value.mode as AsyncStatus["mode"])
|
|
152
|
+
|| typeof value.startedAt !== "number"
|
|
153
|
+
|| !Number.isFinite(value.startedAt)) return undefined;
|
|
154
|
+
return value as unknown as AsyncStatus;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function existingRegularFile(filePath: string | undefined): boolean {
|
|
158
|
+
if (!filePath) return false;
|
|
159
|
+
try {
|
|
160
|
+
const stat = fs.lstatSync(filePath);
|
|
161
|
+
return stat.isFile() && !stat.isSymbolicLink();
|
|
162
|
+
} catch (error) {
|
|
163
|
+
return !isNotFound(error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function validRunId(runId: string): boolean {
|
|
168
|
+
return runId.length > 0 && runId !== "." && runId !== ".." && path.basename(runId) === runId;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function statusTimestamp(status: AsyncStatus, runDir: string): number | undefined {
|
|
172
|
+
if (status.endedAt !== undefined && (typeof status.endedAt !== "number" || !Number.isFinite(status.endedAt))) return undefined;
|
|
173
|
+
if (status.lastUpdate !== undefined && (typeof status.lastUpdate !== "number" || !Number.isFinite(status.lastUpdate))) return undefined;
|
|
174
|
+
const logical = status.endedAt ?? status.lastUpdate;
|
|
175
|
+
try {
|
|
176
|
+
const physical = Math.max(fs.statSync(runDir).mtimeMs, fs.statSync(path.join(runDir, "status.json")).mtimeMs);
|
|
177
|
+
const timestamp = logical === undefined ? physical : Math.max(logical, physical);
|
|
178
|
+
return Number.isFinite(timestamp) ? timestamp : undefined;
|
|
179
|
+
} catch {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function hasNestedReferences(status: AsyncStatus): boolean {
|
|
185
|
+
return status.isNested === true || (status.steps ?? []).some((step) => (step.children?.length ?? 0) > 0);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function hasResumableContract(runDir: string, status: AsyncStatus): boolean {
|
|
189
|
+
const statusSessionFiles = [status.sessionFile, ...(status.steps ?? []).map((step) => step.sessionFile)];
|
|
190
|
+
if (statusSessionFiles.some(existingRegularFile)) return true;
|
|
191
|
+
const descriptorPath = path.join(runDir, "recovery-descriptor.json");
|
|
192
|
+
if (!fs.existsSync(descriptorPath)) return false;
|
|
193
|
+
const descriptor = readJson(descriptorPath);
|
|
194
|
+
if (!descriptor) return true;
|
|
195
|
+
const sessionFiles = [
|
|
196
|
+
typeof descriptor.sessionFile === "string" ? descriptor.sessionFile : undefined,
|
|
197
|
+
];
|
|
198
|
+
if (descriptor.sourceRunId !== status.runId) return true;
|
|
199
|
+
return sessionFiles.some(existingRegularFile);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function activeMarkerExists(asyncDirRoot: string, runId: string): boolean {
|
|
203
|
+
return fs.existsSync(path.join(asyncDirRoot, ACTIVE_RUN_INDEX_DIR, runId));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function missionObserverIndexExists(resultsDir: string, runId: string): boolean {
|
|
207
|
+
return fs.existsSync(path.join(resultsDir, "result-index", "observers", "mission", `${encodeIndexSegment(runId)}.json`));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function runTombstoneMarkerPath(maintenanceRoot: string, runId: string): string {
|
|
211
|
+
return path.join(maintenanceRoot, RUN_TOMBSTONE_MARKERS_DIR, `${encodeIndexSegment(runId)}.json`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function writeRunTombstoneMarker(maintenanceRoot: string, runId: string, tombstonePath: string, now: number): void {
|
|
215
|
+
const markerPath = runTombstoneMarkerPath(maintenanceRoot, runId);
|
|
216
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
217
|
+
writeAtomicJson(markerPath, { version: 1, runId, tombstonePath, createdAt: now });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function removeRunTombstoneMarker(maintenanceRoot: string, runId: string): void {
|
|
221
|
+
fs.rmSync(runTombstoneMarkerPath(maintenanceRoot, runId), { force: true });
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function readRunTombstoneMarker(maintenanceRoot: string, runId: string): { runId: string; tombstonePath: string } | undefined | "unreadable" {
|
|
225
|
+
const markerPath = runTombstoneMarkerPath(maintenanceRoot, runId);
|
|
226
|
+
try {
|
|
227
|
+
const stat = fs.lstatSync(markerPath);
|
|
228
|
+
if (!stat.isFile() || stat.isSymbolicLink()) return "unreadable";
|
|
229
|
+
} catch (error) {
|
|
230
|
+
return isNotFound(error) ? undefined : "unreadable";
|
|
231
|
+
}
|
|
232
|
+
const marker = readJson(markerPath);
|
|
233
|
+
if (marker?.version !== 1 || marker.runId !== runId || typeof marker.tombstonePath !== "string" || !marker.tombstonePath) return "unreadable";
|
|
234
|
+
return { runId, tombstonePath: marker.tombstonePath };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function runTombstoneMarkerMatches(maintenanceRoot: string, runId: string, tombstonePath: string): boolean {
|
|
238
|
+
const marker = readRunTombstoneMarker(maintenanceRoot, runId);
|
|
239
|
+
return marker !== undefined && marker !== "unreadable" && path.resolve(marker.tombstonePath) === path.resolve(tombstonePath);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function runTombstoneMarkerBlocks(maintenanceRoot: string, runId: string): boolean {
|
|
243
|
+
const marker = readRunTombstoneMarker(maintenanceRoot, runId);
|
|
244
|
+
if (marker === undefined) return false;
|
|
245
|
+
if (marker === "unreadable") return true;
|
|
246
|
+
try {
|
|
247
|
+
if (fs.existsSync(marker.tombstonePath)) return true;
|
|
248
|
+
removeRunTombstoneMarker(maintenanceRoot, runId);
|
|
249
|
+
return false;
|
|
250
|
+
} catch {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function unresolvedHandoff(manifestPath: string): boolean {
|
|
256
|
+
const manifest = readJson(manifestPath);
|
|
257
|
+
if (!manifest || manifest.version !== 1 || !Array.isArray(manifest.groups) || manifest.groups.length === 0) return true;
|
|
258
|
+
return manifest.groups.some((value) => {
|
|
259
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return true;
|
|
260
|
+
const cleanup = (value as Record<string, unknown>).cleanup;
|
|
261
|
+
return !cleanup || typeof cleanup !== "object" || Array.isArray(cleanup) || (cleanup as Record<string, unknown>).state !== "complete";
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function hasUnresolvedRunHandoff(runDir: string, status: AsyncStatus): boolean {
|
|
266
|
+
const paths = new Set<string>();
|
|
267
|
+
if (status.parallelHandoff) {
|
|
268
|
+
if (typeof status.parallelHandoff.path !== "string" || !status.parallelHandoff.path) return true;
|
|
269
|
+
paths.add(status.parallelHandoff.path);
|
|
270
|
+
}
|
|
271
|
+
const localPath = path.join(runDir, "handoff.json");
|
|
272
|
+
if (fs.existsSync(localPath)) paths.add(localPath);
|
|
273
|
+
return [...paths].some(unresolvedHandoff);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function runSkipReason(input: {
|
|
277
|
+
runDir: string;
|
|
278
|
+
status: AsyncStatus | undefined;
|
|
279
|
+
asyncDirRoot: string;
|
|
280
|
+
resultsDir: string;
|
|
281
|
+
cutoff: number;
|
|
282
|
+
protectedRunIds: ReadonlySet<string>;
|
|
283
|
+
waitRunIds: ReadonlySet<string>;
|
|
284
|
+
}): string | undefined {
|
|
285
|
+
const { runDir, status } = input;
|
|
286
|
+
if (!status) return "invalid-status";
|
|
287
|
+
if (!validRunId(status.runId)) return "identity-mismatch";
|
|
288
|
+
if (path.basename(runDir) !== status.runId && !path.basename(runDir).startsWith(RUN_TOMBSTONE_PREFIX)) return "identity-mismatch";
|
|
289
|
+
if (input.protectedRunIds.has(status.runId)) return "runtime-reference";
|
|
290
|
+
if (input.waitRunIds.has(status.runId)) return "wait-reference";
|
|
291
|
+
if (activeMarkerExists(input.asyncDirRoot, status.runId)) return "active-index";
|
|
292
|
+
if (!TERMINAL_STATES.has(status.state)) return "non-terminal";
|
|
293
|
+
if (status.mode === "workflow" || status.parentWorkflowRunId || status.workflowKey) return "workflow-reference";
|
|
294
|
+
if (hasNestedReferences(status)) return "nested-reference";
|
|
295
|
+
if (fs.existsSync(path.join(runDir, MISSION_BINDING_FILE)) || missionObserverIndexExists(input.resultsDir, status.runId)) return "mission-reference";
|
|
296
|
+
if (hasUnresolvedRunHandoff(runDir, status)) return "handoff-reference";
|
|
297
|
+
if (hasResumableContract(runDir, status)) return "resumable";
|
|
298
|
+
const timestamp = statusTimestamp(status, runDir);
|
|
299
|
+
if (timestamp === undefined) return "unknown-age";
|
|
300
|
+
if (timestamp > input.cutoff) return "recent";
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function parseWaitRunIds(dir: string): { runIds: Set<string>; safe: boolean } {
|
|
305
|
+
const runIds = new Set<string>();
|
|
306
|
+
for (const entry of listDir(dir)) {
|
|
307
|
+
if (!entry.isFile() || !entry.name.endsWith(".json")) continue;
|
|
308
|
+
const record = readJson(path.join(dir, entry.name));
|
|
309
|
+
if (!record || typeof record.runId !== "string" || typeof record.expiresAt !== "number") return { runIds, safe: false };
|
|
310
|
+
runIds.add(record.runId);
|
|
311
|
+
}
|
|
312
|
+
return { runIds, safe: true };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function readCursor(root: string): RetentionCursor {
|
|
316
|
+
const value = readJson(path.join(root, CURSOR_NAME));
|
|
317
|
+
return value?.version === 1 ? value as unknown as RetentionCursor : { version: 1 };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function processStartIdentity(pid: number): string | undefined {
|
|
321
|
+
if (process.platform === "linux") {
|
|
322
|
+
try {
|
|
323
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
324
|
+
const commandEnd = stat.lastIndexOf(")");
|
|
325
|
+
if (commandEnd === -1) return undefined;
|
|
326
|
+
const fields = stat.slice(commandEnd + 1).trim().split(/\s+/);
|
|
327
|
+
return fields[19] ? `linux:${fields[19]}` : undefined;
|
|
328
|
+
} catch {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (process.platform === "win32") {
|
|
333
|
+
const result = spawnSync("powershell.exe", ["-NoProfile", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CreationDate`], { encoding: "utf-8", windowsHide: true });
|
|
334
|
+
const started = result.status === 0 ? result.stdout.trim() : "";
|
|
335
|
+
return started ? `win:${started}` : undefined;
|
|
336
|
+
}
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function processIsAlive(pid: number): boolean | undefined {
|
|
341
|
+
try {
|
|
342
|
+
process.kill(pid, 0);
|
|
343
|
+
return true;
|
|
344
|
+
} catch (error) {
|
|
345
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
346
|
+
if (code === "ESRCH") return false;
|
|
347
|
+
if (code === "EPERM") return true;
|
|
348
|
+
return undefined;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function parseLockOwner(lockDir: string): RetentionLockOwner | undefined {
|
|
353
|
+
const owner = readJson(path.join(lockDir, "owner.json"));
|
|
354
|
+
if (owner?.version !== 1
|
|
355
|
+
|| typeof owner.token !== "string"
|
|
356
|
+
|| typeof owner.pid !== "number"
|
|
357
|
+
|| !Number.isInteger(owner.pid)
|
|
358
|
+
|| owner.pid <= 0
|
|
359
|
+
|| typeof owner.hostname !== "string"
|
|
360
|
+
|| typeof owner.startedAt !== "number"
|
|
361
|
+
|| !Number.isFinite(owner.startedAt)) return undefined;
|
|
362
|
+
if (owner.processStartIdentity !== undefined && typeof owner.processStartIdentity !== "string") return undefined;
|
|
363
|
+
return owner as unknown as RetentionLockOwner;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function staleLock(lockDir: string, now: number, options: Required<Pick<AsyncRetentionOptions, "hostname" | "isProcessAlive" | "getProcessStartIdentity">>): { stale: boolean; token?: string } {
|
|
367
|
+
const owner = parseLockOwner(lockDir);
|
|
368
|
+
if (!owner) {
|
|
369
|
+
try {
|
|
370
|
+
return { stale: now - fs.statSync(lockDir).mtimeMs >= LOCK_STALE_MS };
|
|
371
|
+
} catch {
|
|
372
|
+
return { stale: false };
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (owner.hostname !== options.hostname) return { stale: false };
|
|
376
|
+
const alive = options.isProcessAlive(owner.pid);
|
|
377
|
+
if (alive === false) return { stale: true, token: owner.token };
|
|
378
|
+
if (alive === true && owner.processStartIdentity) {
|
|
379
|
+
const currentIdentity = options.getProcessStartIdentity(owner.pid);
|
|
380
|
+
if (currentIdentity !== undefined && currentIdentity !== owner.processStartIdentity) return { stale: true, token: owner.token };
|
|
381
|
+
}
|
|
382
|
+
return { stale: now - owner.startedAt >= LOCK_STALE_MS, token: owner.token };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function createLockDirectory(lockDir: string, owner: RetentionLockOwner): boolean {
|
|
386
|
+
try {
|
|
387
|
+
fs.mkdirSync(lockDir, { mode: 0o700 });
|
|
388
|
+
} catch (error) {
|
|
389
|
+
if ((error as NodeJS.ErrnoException).code === "EEXIST") return false;
|
|
390
|
+
throw error;
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
fs.writeFileSync(path.join(lockDir, "owner.json"), JSON.stringify(owner), { encoding: "utf-8", mode: 0o600 });
|
|
394
|
+
return true;
|
|
395
|
+
} catch (error) {
|
|
396
|
+
fs.rmSync(lockDir, { recursive: true, force: true });
|
|
397
|
+
throw error;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function acquireRetentionLock(lockDir: string, owner: RetentionLockOwner, options: Required<Pick<AsyncRetentionOptions, "hostname" | "isProcessAlive" | "getProcessStartIdentity">>): boolean {
|
|
402
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
403
|
+
if (createLockDirectory(lockDir, owner)) return true;
|
|
404
|
+
const stale = staleLock(lockDir, owner.startedAt, options);
|
|
405
|
+
if (!stale.stale) return false;
|
|
406
|
+
const staleKey = (stale.token ?? owner.token).replace(/[^A-Za-z0-9._-]/g, "-");
|
|
407
|
+
const tombstone = `${lockDir}.stale-${staleKey}`;
|
|
408
|
+
try {
|
|
409
|
+
fs.renameSync(lockDir, tombstone);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
412
|
+
if (code === "ENOENT" || fs.existsSync(tombstone)) continue;
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function releaseRetentionLock(lockDir: string, token: string): void {
|
|
420
|
+
if (parseLockOwner(lockDir)?.token !== token) return;
|
|
421
|
+
fs.rmSync(lockDir, { recursive: true, force: true });
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function resultRunId(candidate: ResultCandidate, data: Record<string, unknown>): string | undefined {
|
|
425
|
+
if (typeof data.runId === "string") return data.runId;
|
|
426
|
+
if (typeof data.id === "string") return data.id;
|
|
427
|
+
if ((candidate.kind === "public" || candidate.kind === "pending") && path.basename(candidate.path).endsWith(".json")) return path.basename(candidate.path, ".json");
|
|
428
|
+
return undefined;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function resultTimestamp(data: Record<string, unknown>, filePath: string): number | undefined {
|
|
432
|
+
for (const field of RESULT_TIMESTAMP_FIELDS) {
|
|
433
|
+
const value = data[field];
|
|
434
|
+
if (value !== undefined && (typeof value !== "number" || !Number.isFinite(value))) return undefined;
|
|
435
|
+
}
|
|
436
|
+
const logical = RESULT_TIMESTAMP_FIELDS.map((field) => data[field])
|
|
437
|
+
.filter((value): value is number => typeof value === "number" && Number.isFinite(value));
|
|
438
|
+
try {
|
|
439
|
+
return Math.max(fs.statSync(filePath).mtimeMs, ...logical);
|
|
440
|
+
} catch {
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function terminalResult(data: Record<string, unknown>): boolean {
|
|
446
|
+
return data.success === true || data.success === false || (typeof data.state === "string" && TERMINAL_STATES.has(data.state as AsyncStatus["state"]));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function resultHasResumableSession(data: Record<string, unknown>): boolean {
|
|
450
|
+
if (existingRegularFile(typeof data.sessionFile === "string" ? data.sessionFile : undefined)) return true;
|
|
451
|
+
return Array.isArray(data.results) && data.results.some((value) => {
|
|
452
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
453
|
+
const sessionFile = (value as Record<string, unknown>).sessionFile;
|
|
454
|
+
return existingRegularFile(typeof sessionFile === "string" ? sessionFile : undefined);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function hasUnresolvedResultHandoff(data: Record<string, unknown>): boolean {
|
|
459
|
+
if (data.parallelHandoff === undefined) return false;
|
|
460
|
+
if (!data.parallelHandoff || typeof data.parallelHandoff !== "object" || Array.isArray(data.parallelHandoff)) return true;
|
|
461
|
+
const manifestPath = (data.parallelHandoff as Record<string, unknown>).path;
|
|
462
|
+
return typeof manifestPath !== "string" || !manifestPath || unresolvedHandoff(manifestPath);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function completionMode(data: Record<string, unknown>): unknown {
|
|
466
|
+
return data.completion && typeof data.completion === "object" && !Array.isArray(data.completion)
|
|
467
|
+
? (data.completion as Record<string, unknown>).mode
|
|
468
|
+
: undefined;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function resultSkipReason(input: {
|
|
472
|
+
candidate: ResultCandidate;
|
|
473
|
+
data: Record<string, unknown> | undefined;
|
|
474
|
+
asyncDirRoot: string;
|
|
475
|
+
resultsDir: string;
|
|
476
|
+
maintenanceRoot: string;
|
|
477
|
+
cutoff: number;
|
|
478
|
+
protectedRunIds: ReadonlySet<string>;
|
|
479
|
+
waitRunIds: ReadonlySet<string>;
|
|
480
|
+
}): string | undefined {
|
|
481
|
+
if (!input.data) return "invalid-result";
|
|
482
|
+
const runId = resultRunId(input.candidate, input.data);
|
|
483
|
+
if (!runId || !validRunId(runId)) return "invalid-result";
|
|
484
|
+
if (runTombstoneMarkerBlocks(input.maintenanceRoot, runId)) return "run-tombstone-present";
|
|
485
|
+
if (input.protectedRunIds.has(runId)) return "runtime-reference";
|
|
486
|
+
if (input.waitRunIds.has(runId)) return "wait-reference";
|
|
487
|
+
if (activeMarkerExists(input.asyncDirRoot, runId)) return "active-index";
|
|
488
|
+
if (fs.existsSync(path.join(input.asyncDirRoot, runId))) return "run-present";
|
|
489
|
+
if (missionObserverIndexExists(input.resultsDir, runId)) return "mission-reference";
|
|
490
|
+
if (input.data.mode === "workflow" || completionMode(input.data) === "workflow" || typeof input.data.parentWorkflowRunId === "string" || typeof input.data.workflowKey === "string") return "workflow-reference";
|
|
491
|
+
if (hasUnresolvedResultHandoff(input.data)) return "handoff-reference";
|
|
492
|
+
if (resultHasResumableSession(input.data)) return "resumable";
|
|
493
|
+
if (input.candidate.kind === "archive" && fs.existsSync(path.join(input.resultsDir, "completion-replay", `${encodeURIComponent(runId)}.json`))) return "replay-reference";
|
|
494
|
+
if (!terminalResult(input.data) && input.candidate.kind !== "replay" && input.candidate.kind !== "archive" && input.candidate.kind !== "tombstone") return "non-terminal-result";
|
|
495
|
+
const timestamp = resultTimestamp(input.data, input.candidate.path);
|
|
496
|
+
if (timestamp === undefined) return "unknown-age";
|
|
497
|
+
if (timestamp > input.cutoff) return "recent";
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function appendMaintenanceLog(root: string, result: AsyncRetentionResult, now: number, deletedIds: string[]): void {
|
|
502
|
+
fs.mkdirSync(root, { recursive: true });
|
|
503
|
+
fs.appendFileSync(path.join(root, LOG_NAME), `${JSON.stringify({
|
|
504
|
+
at: new Date(now).toISOString(),
|
|
505
|
+
acquired: result.acquired,
|
|
506
|
+
scanned: result.scanned,
|
|
507
|
+
deletedRuns: result.deletedRuns,
|
|
508
|
+
deletedResults: result.deletedResults,
|
|
509
|
+
reapedTombstones: result.reapedTombstones,
|
|
510
|
+
skipped: result.skipped,
|
|
511
|
+
deleted: deletedIds.slice(0, ASYNC_RETENTION_BATCH_SIZE),
|
|
512
|
+
errors: result.errors.length,
|
|
513
|
+
rawReads: result.rawReads,
|
|
514
|
+
sourceExhausted: result.sourceExhausted,
|
|
515
|
+
discoveryDurationMs: result.discoveryDurationMs,
|
|
516
|
+
commitDurationMs: result.commitDurationMs,
|
|
517
|
+
cancelled: result.cancelled,
|
|
518
|
+
workerFailed: result.workerFailed,
|
|
519
|
+
durationMs: result.durationMs,
|
|
520
|
+
})}\n`, "utf-8");
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function increment(record: Record<string, number>, key: string): void {
|
|
524
|
+
record[key] = (record[key] ?? 0) + 1;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
class RetentionCancelledError extends Error {}
|
|
529
|
+
|
|
530
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
531
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function safeRelative(relative: string): boolean {
|
|
535
|
+
return relative.length > 0 && !path.isAbsolute(relative) && !relative.split(path.sep).includes("..");
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function parseDiscoveryResult(message: unknown, passId: string, runBudget: number, resultBudget: number): RetentionDiscovery {
|
|
539
|
+
if (!isRecord(message) || message.type !== "result" || message.passId !== passId) throw new Error("Retention discovery worker returned a stale or malformed pass id.");
|
|
540
|
+
if (!Number.isFinite(message.discoveryDurationMs) || (message.discoveryDurationMs as number) < 0) throw new Error("Retention discovery worker returned an invalid duration.");
|
|
541
|
+
if (!Number.isInteger(message.rawReads) || (message.rawReads as number) < 0) throw new Error("Retention discovery worker returned an invalid raw-read count.");
|
|
542
|
+
if (!isRecord(message.sourceExhausted) || Object.values(message.sourceExhausted).some((value) => typeof value !== "boolean")) throw new Error("Retention discovery worker returned invalid source telemetry.");
|
|
543
|
+
if (!Array.isArray(message.runCandidates) || message.runCandidates.length > runBudget) throw new Error("Retention discovery worker exceeded the run budget.");
|
|
544
|
+
if (!Array.isArray(message.resultCandidates) || message.resultCandidates.length > resultBudget) throw new Error("Retention discovery worker exceeded the result budget.");
|
|
545
|
+
if (!Array.isArray(message.cursorOps) || message.cursorOps.length > runBudget + resultBudget + 8) throw new Error("Retention discovery worker returned invalid cursor operations.");
|
|
546
|
+
for (const candidate of message.runCandidates) {
|
|
547
|
+
if (!isRecord(candidate) || typeof candidate.name !== "string" || typeof candidate.relative !== "string" || !validRunId(candidate.name) || candidate.relative !== candidate.name) throw new Error("Retention discovery worker returned an unsafe run candidate.");
|
|
548
|
+
}
|
|
549
|
+
const resultKinds = new Set(["public", "pending", "replay", "archive", "tombstone"]);
|
|
550
|
+
const resultKeys = new Set(["resultPublicAfter", "resultReplayAfter", "resultArchiveAfter"]);
|
|
551
|
+
for (const candidate of message.resultCandidates) {
|
|
552
|
+
if (!isRecord(candidate) || typeof candidate.name !== "string" || typeof candidate.relative !== "string" || path.basename(candidate.name) !== candidate.name || !safeRelative(candidate.relative) || path.basename(candidate.relative) !== candidate.name || !resultKinds.has(candidate.kind as string) || !isRecord(candidate.cursor)) throw new Error("Retention discovery worker returned an unsafe result candidate.");
|
|
553
|
+
const cursor = candidate.cursor;
|
|
554
|
+
if (cursor.type === "pending") {
|
|
555
|
+
if (typeof cursor.session !== "string" || !validRunId(cursor.session) || path.dirname(candidate.relative) !== path.join("result-pending", cursor.session)) throw new Error("Retention discovery worker returned an invalid pending candidate.");
|
|
556
|
+
} else if (cursor.type === "result") {
|
|
557
|
+
if (typeof cursor.key !== "string" || !resultKeys.has(cursor.key)) throw new Error("Retention discovery worker returned an invalid result cursor.");
|
|
558
|
+
const expectedDir = cursor.key === "resultPublicAfter" ? "." : cursor.key === "resultReplayAfter" ? "completion-replay" : "output-archives";
|
|
559
|
+
if (path.dirname(candidate.relative) !== expectedDir) throw new Error("Retention discovery worker returned a result from the wrong source.");
|
|
560
|
+
} else throw new Error("Retention discovery worker returned an invalid result cursor target.");
|
|
561
|
+
}
|
|
562
|
+
const scalarKeys = new Set(["runAfter", "resultPublicAfter", "resultReplayAfter", "resultArchiveAfter", "pendingSessionAfter"]);
|
|
563
|
+
for (const operation of message.cursorOps) {
|
|
564
|
+
if (!isRecord(operation) || typeof operation.type !== "string") throw new Error("Retention discovery worker returned a malformed cursor operation.");
|
|
565
|
+
if (operation.type === "set" || operation.type === "delete") {
|
|
566
|
+
if (typeof operation.key !== "string" || !scalarKeys.has(operation.key) || (operation.type === "set" && (typeof operation.value !== "string" || !safeRelative(operation.value)))) throw new Error("Retention discovery worker returned an invalid scalar cursor operation.");
|
|
567
|
+
} else if (operation.type === "set-pending" || operation.type === "delete-pending") {
|
|
568
|
+
if (typeof operation.session !== "string" || !validRunId(operation.session) || (operation.type === "set-pending" && (typeof operation.value !== "string" || !safeRelative(operation.value)))) throw new Error("Retention discovery worker returned an invalid pending cursor operation.");
|
|
569
|
+
} else throw new Error("Retention discovery worker returned an unknown cursor operation.");
|
|
570
|
+
}
|
|
571
|
+
return message as unknown as RetentionDiscovery;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function runRetentionDiscovery(input: {
|
|
575
|
+
passId: string;
|
|
576
|
+
asyncDirRoot: string;
|
|
577
|
+
resultsDir: string;
|
|
578
|
+
cursor: RetentionCursor;
|
|
579
|
+
runBudget: number;
|
|
580
|
+
resultBudget: number;
|
|
581
|
+
workerUrl: URL;
|
|
582
|
+
signal?: AbortSignal;
|
|
583
|
+
}): Promise<RetentionDiscovery> {
|
|
584
|
+
return new Promise((resolve, reject) => {
|
|
585
|
+
if (input.signal?.aborted) {
|
|
586
|
+
reject(new RetentionCancelledError("Retention discovery was cancelled."));
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
const worker = new Worker(input.workerUrl);
|
|
590
|
+
let settled = false;
|
|
591
|
+
const cleanup = (): void => {
|
|
592
|
+
input.signal?.removeEventListener("abort", onAbort);
|
|
593
|
+
void worker.terminate();
|
|
594
|
+
};
|
|
595
|
+
const fail = (error: Error): void => {
|
|
596
|
+
if (settled) return;
|
|
597
|
+
settled = true;
|
|
598
|
+
cleanup();
|
|
599
|
+
reject(error);
|
|
600
|
+
};
|
|
601
|
+
const onAbort = (): void => fail(new RetentionCancelledError("Retention discovery was cancelled."));
|
|
602
|
+
input.signal?.addEventListener("abort", onAbort, { once: true });
|
|
603
|
+
worker.once("error", (error) => fail(error instanceof Error ? error : new Error(String(error))));
|
|
604
|
+
worker.once("exit", (code) => {
|
|
605
|
+
if (!settled) fail(new Error(`Retention discovery worker exited before replying (${code}).`));
|
|
606
|
+
});
|
|
607
|
+
worker.once("message", (message: unknown) => {
|
|
608
|
+
if (settled) return;
|
|
609
|
+
try {
|
|
610
|
+
if (isRecord(message) && message.type === "error" && message.passId === input.passId) throw new Error(`Retention discovery failed: ${String(message.error)}`);
|
|
611
|
+
const discovery = parseDiscoveryResult(message, input.passId, input.runBudget, input.resultBudget);
|
|
612
|
+
settled = true;
|
|
613
|
+
cleanup();
|
|
614
|
+
resolve(discovery);
|
|
615
|
+
} catch (error) {
|
|
616
|
+
fail(error instanceof Error ? error : new Error(String(error)));
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
worker.postMessage({ type: "discover", passId: input.passId, asyncDirRoot: input.asyncDirRoot, resultsDir: input.resultsDir, cursor: input.cursor, runBudget: input.runBudget, resultBudget: input.resultBudget });
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function applyCursorOperations(cursor: RetentionCursor, operations: CursorOperation[]): void {
|
|
624
|
+
for (const operation of operations) {
|
|
625
|
+
if (operation.type === "set") cursor[operation.key] = operation.value;
|
|
626
|
+
else if (operation.type === "delete") delete cursor[operation.key];
|
|
627
|
+
else if (operation.type === "set-pending") {
|
|
628
|
+
cursor.resultPendingAfterBySession ??= {};
|
|
629
|
+
cursor.resultPendingAfterBySession[operation.session] = operation.value;
|
|
630
|
+
} else {
|
|
631
|
+
delete cursor.resultPendingAfterBySession?.[operation.session];
|
|
632
|
+
if (cursor.resultPendingAfterBySession && Object.keys(cursor.resultPendingAfterBySession).length === 0) delete cursor.resultPendingAfterBySession;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export async function cleanupAsyncRetention(options: AsyncRetentionOptions): Promise<AsyncRetentionResult> {
|
|
638
|
+
const startedWall = Date.now();
|
|
639
|
+
const now = options.now ?? Date.now;
|
|
640
|
+
const currentTime = now();
|
|
641
|
+
const retentionMs = options.retentionMs ?? RETENTION_MS;
|
|
642
|
+
const tombstoneGraceMs = options.tombstoneGraceMs ?? ASYNC_RETENTION_TOMBSTONE_GRACE_MS;
|
|
643
|
+
const batchSize = Math.min(ASYNC_RETENTION_BATCH_SIZE, Math.max(1, Math.trunc(options.batchSize ?? ASYNC_RETENTION_BATCH_SIZE)));
|
|
644
|
+
const randomId = options.randomId ?? randomUUID;
|
|
645
|
+
const maintenanceRoot = options.maintenanceRoot ?? path.dirname(options.asyncDirRoot);
|
|
646
|
+
const lockDir = path.join(maintenanceRoot, LOCK_NAME);
|
|
647
|
+
const lockToken = randomId();
|
|
648
|
+
const pid = options.pid ?? process.pid;
|
|
649
|
+
const hostname = options.hostname ?? os.hostname();
|
|
650
|
+
const getProcessStartIdentity = options.getProcessStartIdentity ?? processStartIdentity;
|
|
651
|
+
const currentProcessStartIdentity = options.processStartIdentity ?? getProcessStartIdentity(pid) ?? (pid === process.pid ? `runtime:${Math.round(Date.now() - process.uptime() * 1000)}` : undefined);
|
|
652
|
+
const lockOwner: RetentionLockOwner = { version: 1, token: lockToken, pid, hostname, startedAt: currentTime, ...(currentProcessStartIdentity ? { processStartIdentity: currentProcessStartIdentity } : {}) };
|
|
653
|
+
const lockOptions = { hostname, isProcessAlive: options.isProcessAlive ?? processIsAlive, getProcessStartIdentity };
|
|
654
|
+
const result: AsyncRetentionResult = {
|
|
655
|
+
acquired: false,
|
|
656
|
+
scanned: 0,
|
|
657
|
+
deletedRuns: 0,
|
|
658
|
+
deletedResults: 0,
|
|
659
|
+
reapedTombstones: 0,
|
|
660
|
+
skipped: {},
|
|
661
|
+
errors: [],
|
|
662
|
+
rawReads: 0,
|
|
663
|
+
sourceExhausted: {},
|
|
664
|
+
discoveryDurationMs: 0,
|
|
665
|
+
commitDurationMs: 0,
|
|
666
|
+
cancelled: false,
|
|
667
|
+
workerFailed: false,
|
|
668
|
+
durationMs: 0,
|
|
669
|
+
};
|
|
670
|
+
const deletedIds: string[] = [];
|
|
671
|
+
const lstatSync = options.lstatSync ?? fs.lstatSync;
|
|
672
|
+
let commitStartedAt: number | undefined;
|
|
673
|
+
let cursorCommitUnsafe = false;
|
|
674
|
+
const finish = (): AsyncRetentionResult => {
|
|
675
|
+
if (commitStartedAt !== undefined) result.commitDurationMs = Math.max(0, Date.now() - commitStartedAt);
|
|
676
|
+
result.durationMs = Math.max(0, Date.now() - startedWall);
|
|
677
|
+
appendMaintenanceLog(maintenanceRoot, result, currentTime, deletedIds);
|
|
678
|
+
return result;
|
|
679
|
+
};
|
|
680
|
+
const markCancelled = (): boolean => {
|
|
681
|
+
if (!options.signal?.aborted) return false;
|
|
682
|
+
result.cancelled = true;
|
|
683
|
+
increment(result.skipped, "cancelled");
|
|
684
|
+
return true;
|
|
685
|
+
};
|
|
686
|
+
fs.mkdirSync(maintenanceRoot, { recursive: true });
|
|
687
|
+
if (!acquireRetentionLock(lockDir, lockOwner, lockOptions)) {
|
|
688
|
+
increment(result.skipped, "lock-busy");
|
|
689
|
+
return finish();
|
|
690
|
+
}
|
|
691
|
+
result.acquired = true;
|
|
692
|
+
try {
|
|
693
|
+
if (markCancelled()) return finish();
|
|
694
|
+
const protectedRunIds = new Set(options.protectedRunIds ?? []);
|
|
695
|
+
const cutoff = currentTime - retentionMs;
|
|
696
|
+
const cursor = readCursor(maintenanceRoot);
|
|
697
|
+
const runBudget = Math.ceil(batchSize / 2);
|
|
698
|
+
const resultBudget = batchSize - runBudget;
|
|
699
|
+
const discoveryStartedAt = Date.now();
|
|
700
|
+
let discovery: RetentionDiscovery;
|
|
701
|
+
try {
|
|
702
|
+
discovery = await runRetentionDiscovery({
|
|
703
|
+
passId: randomUUID(),
|
|
704
|
+
asyncDirRoot: options.asyncDirRoot,
|
|
705
|
+
resultsDir: options.resultsDir,
|
|
706
|
+
cursor,
|
|
707
|
+
runBudget,
|
|
708
|
+
resultBudget,
|
|
709
|
+
workerUrl: options.discoveryWorkerUrl ?? new URL("../../../async-retention-discovery-worker.mjs", import.meta.url),
|
|
710
|
+
signal: options.signal,
|
|
711
|
+
});
|
|
712
|
+
} catch (error) {
|
|
713
|
+
result.discoveryDurationMs = Math.max(0, Date.now() - discoveryStartedAt);
|
|
714
|
+
if (error instanceof RetentionCancelledError) {
|
|
715
|
+
result.cancelled = true;
|
|
716
|
+
increment(result.skipped, "cancelled");
|
|
717
|
+
} else {
|
|
718
|
+
result.workerFailed = true;
|
|
719
|
+
increment(result.skipped, "worker-failure");
|
|
720
|
+
result.errors.push(compactError(error));
|
|
721
|
+
}
|
|
722
|
+
return finish();
|
|
723
|
+
}
|
|
724
|
+
result.discoveryDurationMs = Math.max(0, Date.now() - discoveryStartedAt);
|
|
725
|
+
result.rawReads = discovery.rawReads;
|
|
726
|
+
result.sourceExhausted = discovery.sourceExhausted;
|
|
727
|
+
commitStartedAt = Date.now();
|
|
728
|
+
if (markCancelled()) return finish();
|
|
729
|
+
if (parseLockOwner(lockDir)?.token !== lockToken) {
|
|
730
|
+
increment(result.skipped, "lock-owner-changed");
|
|
731
|
+
return finish();
|
|
732
|
+
}
|
|
733
|
+
const waitSubscriptionsDir = options.waitSubscriptionsDir ?? path.join(maintenanceRoot, "wait-subscriptions");
|
|
734
|
+
// This safety scan stays on the commit thread. Wait records are the active,
|
|
735
|
+
// swept subscription set. Each destructive action re-reads it to close the
|
|
736
|
+
// race with a newly armed wait.
|
|
737
|
+
const waitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
738
|
+
if (!waitReferences.safe) {
|
|
739
|
+
increment(result.skipped, "wait-references-unknown");
|
|
740
|
+
return finish();
|
|
741
|
+
}
|
|
742
|
+
for (const entry of discovery.runCandidates) {
|
|
743
|
+
if (markCancelled()) return finish();
|
|
744
|
+
result.scanned += 1;
|
|
745
|
+
const runDir = path.join(options.asyncDirRoot, entry.name);
|
|
746
|
+
let mutationStateChanged = false;
|
|
747
|
+
try {
|
|
748
|
+
const stat = lstatSync(runDir);
|
|
749
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
750
|
+
increment(result.skipped, "unsafe-run-path");
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
const status = readStatus(runDir);
|
|
754
|
+
const initialReason = runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
755
|
+
if (initialReason) {
|
|
756
|
+
increment(result.skipped, initialReason);
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
if (entry.name.startsWith(RUN_TOMBSTONE_PREFIX)) {
|
|
760
|
+
if (!runTombstoneMarkerMatches(maintenanceRoot, status!.runId, runDir)) {
|
|
761
|
+
increment(result.skipped, "run-tombstone-marker");
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
if (currentTime - stat.mtimeMs < tombstoneGraceMs) {
|
|
765
|
+
increment(result.skipped, "tombstone-grace");
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
769
|
+
const finalReason = freshWaitReferences.safe ? runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
770
|
+
if (finalReason) {
|
|
771
|
+
increment(result.skipped, `recheck-${finalReason}`);
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
mutationStateChanged = true;
|
|
775
|
+
fs.rmSync(runDir, { recursive: true });
|
|
776
|
+
removeRunTombstoneMarker(maintenanceRoot, status!.runId);
|
|
777
|
+
result.reapedTombstones += 1;
|
|
778
|
+
deletedIds.push(`run-tombstone:${status!.runId}`);
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
const tombstone = path.join(options.asyncDirRoot, `${RUN_TOMBSTONE_PREFIX}${randomId()}`);
|
|
782
|
+
writeRunTombstoneMarker(maintenanceRoot, status!.runId, tombstone, currentTime);
|
|
783
|
+
mutationStateChanged = true;
|
|
784
|
+
try {
|
|
785
|
+
fs.renameSync(runDir, tombstone);
|
|
786
|
+
} catch (error) {
|
|
787
|
+
removeRunTombstoneMarker(maintenanceRoot, status!.runId);
|
|
788
|
+
mutationStateChanged = false;
|
|
789
|
+
throw error;
|
|
790
|
+
}
|
|
791
|
+
const recheckStatus = readStatus(tombstone);
|
|
792
|
+
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
793
|
+
const recheckReason = freshWaitReferences.safe ? runSkipReason({ runDir: tombstone, status: recheckStatus, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
794
|
+
if (recheckReason) {
|
|
795
|
+
if (!fs.existsSync(runDir)) {
|
|
796
|
+
fs.renameSync(tombstone, runDir);
|
|
797
|
+
mutationStateChanged = false;
|
|
798
|
+
}
|
|
799
|
+
removeRunTombstoneMarker(maintenanceRoot, status!.runId);
|
|
800
|
+
if (mutationStateChanged) cursorCommitUnsafe = true;
|
|
801
|
+
increment(result.skipped, `recheck-${recheckReason}`);
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
fs.rmSync(tombstone, { recursive: true });
|
|
805
|
+
removeRunTombstoneMarker(maintenanceRoot, status!.runId);
|
|
806
|
+
result.deletedRuns += 1;
|
|
807
|
+
deletedIds.push(`run:${status!.runId}`);
|
|
808
|
+
} catch (error) {
|
|
809
|
+
if (mutationStateChanged) cursorCommitUnsafe = true;
|
|
810
|
+
if (!isNotFound(error)) result.errors.push(compactError(error));
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
for (const discoveredCandidate of discovery.resultCandidates) {
|
|
814
|
+
if (markCancelled()) return finish();
|
|
815
|
+
result.scanned += 1;
|
|
816
|
+
const candidate: ResultCandidate = { ...discoveredCandidate, path: path.join(options.resultsDir, discoveredCandidate.relative) };
|
|
817
|
+
let mutationStateChanged = false;
|
|
818
|
+
try {
|
|
819
|
+
const stat = lstatSync(candidate.path);
|
|
820
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
821
|
+
increment(result.skipped, "unsafe-result-path");
|
|
822
|
+
continue;
|
|
823
|
+
}
|
|
824
|
+
const data = readJson(candidate.path);
|
|
825
|
+
const reason = resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
826
|
+
if (reason) {
|
|
827
|
+
increment(result.skipped, reason);
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
if (candidate.kind === "tombstone") {
|
|
831
|
+
if (currentTime - stat.mtimeMs < tombstoneGraceMs) {
|
|
832
|
+
increment(result.skipped, "tombstone-grace");
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
836
|
+
const finalReason = freshWaitReferences.safe ? resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
837
|
+
if (finalReason) {
|
|
838
|
+
increment(result.skipped, `recheck-${finalReason}`);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
fs.rmSync(candidate.path);
|
|
842
|
+
mutationStateChanged = true;
|
|
843
|
+
result.reapedTombstones += 1;
|
|
844
|
+
deletedIds.push(`result-tombstone:${resultRunId(candidate, data!)}`);
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
const tombstone = path.join(path.dirname(candidate.path), `${RESULT_TOMBSTONE_PREFIX}${candidate.kind}-${randomId()}`);
|
|
848
|
+
fs.renameSync(candidate.path, tombstone);
|
|
849
|
+
mutationStateChanged = true;
|
|
850
|
+
const tombstoneCandidate = { ...candidate, path: tombstone, kind: "tombstone" as const };
|
|
851
|
+
const recheckData = readJson(tombstone);
|
|
852
|
+
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
853
|
+
const recheckReason = freshWaitReferences.safe ? resultSkipReason({ candidate: tombstoneCandidate, data: recheckData, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
854
|
+
if (recheckReason) {
|
|
855
|
+
if (!fs.existsSync(candidate.path)) {
|
|
856
|
+
fs.renameSync(tombstone, candidate.path);
|
|
857
|
+
mutationStateChanged = false;
|
|
858
|
+
}
|
|
859
|
+
if (mutationStateChanged) cursorCommitUnsafe = true;
|
|
860
|
+
increment(result.skipped, `recheck-${recheckReason}`);
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
fs.rmSync(tombstone);
|
|
864
|
+
result.deletedResults += 1;
|
|
865
|
+
deletedIds.push(`result:${resultRunId(candidate, data!)}`);
|
|
866
|
+
} catch (error) {
|
|
867
|
+
if (mutationStateChanged) cursorCommitUnsafe = true;
|
|
868
|
+
if (!isNotFound(error)) result.errors.push(compactError(error));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (cursorCommitUnsafe) {
|
|
872
|
+
increment(result.skipped, "commit-failure");
|
|
873
|
+
return finish();
|
|
874
|
+
}
|
|
875
|
+
if (markCancelled()) return finish();
|
|
876
|
+
if (parseLockOwner(lockDir)?.token !== lockToken) {
|
|
877
|
+
increment(result.skipped, "lock-owner-changed");
|
|
878
|
+
return finish();
|
|
879
|
+
}
|
|
880
|
+
applyCursorOperations(cursor, discovery.cursorOps);
|
|
881
|
+
writeAtomicJson(path.join(maintenanceRoot, CURSOR_NAME), cursor);
|
|
882
|
+
return finish();
|
|
883
|
+
} finally {
|
|
884
|
+
try { releaseRetentionLock(lockDir, lockToken); } catch { /* a stale lock blocks the next pass safely */ }
|
|
885
|
+
}
|
|
886
|
+
}
|