@selesai/code 0.13.16 → 0.13.19
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 +41 -0
- package/README.md +2 -14
- package/dist/bun/cli.d.ts +3 -1
- package/dist/bun/cli.js +3 -9
- package/dist/bun/{register-bedrock.js → runtime-setup.js} +5 -0
- package/dist/bun/sandbox-env-setup.d.ts +1 -0
- package/dist/bun/sandbox-env-setup.js +3 -0
- package/dist/cli/auth-command.d.ts +23 -0
- package/dist/cli/auth-command.js +102 -0
- package/dist/cli/config-selector.js +2 -1
- package/dist/cli/setup.d.ts +1 -0
- package/dist/cli/setup.js +11 -0
- package/dist/cli.js +2 -14
- package/dist/config.d.ts +3 -2
- package/dist/config.js +9 -4
- package/dist/core/agent-session-runtime.js +15 -7
- package/dist/core/agent-session.d.ts +2 -6
- package/dist/core/agent-session.js +15 -4
- package/dist/core/compaction/branch-summarization.d.ts +1 -1
- package/dist/core/compaction/branch-summarization.js +2 -1
- package/dist/core/extensions/loader.js +3 -0
- package/dist/core/extensions/types.d.ts +16 -2
- package/dist/core/http-dispatcher.js +2 -0
- package/dist/core/keybindings.d.ts +5 -0
- package/dist/core/keybindings.js +4 -0
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/model-config.d.ts +15 -0
- package/dist/core/model-config.js +3 -0
- package/dist/core/model-runtime.d.ts +1 -0
- package/dist/core/model-runtime.js +5 -2
- package/dist/core/provider-composer.js +8 -2
- package/dist/core/session-export.d.ts +3 -0
- package/dist/core/session-export.js +31 -0
- package/dist/core/session-manager.d.ts +3 -2
- package/dist/core/session-manager.js +40 -13
- package/dist/core/skills.d.ts +1 -1
- package/dist/core/skills.js +4 -2
- package/dist/core/system-prompt.js +10 -10
- package/dist/core/tools/bash.js +3 -117
- package/dist/core/tools/edit.d.ts +1 -12
- package/dist/core/tools/edit.js +5 -163
- package/dist/core/tools/find.js +4 -55
- package/dist/core/tools/grep.js +4 -60
- package/dist/core/tools/ls.js +4 -49
- package/dist/core/tools/read.d.ts +4 -0
- package/dist/core/tools/read.js +10 -122
- package/dist/core/tools/renderers/bash.d.ts +11 -0
- package/dist/core/tools/renderers/bash.js +129 -0
- package/dist/core/tools/renderers/edit.d.ts +22 -0
- package/dist/core/tools/renderers/edit.js +166 -0
- package/dist/core/tools/renderers/find.d.ts +9 -0
- package/dist/core/tools/renderers/find.js +63 -0
- package/dist/core/tools/renderers/grep.d.ts +9 -0
- package/dist/core/tools/renderers/grep.js +68 -0
- package/dist/core/tools/renderers/index.d.ts +27 -0
- package/dist/core/tools/renderers/index.js +46 -0
- package/dist/core/tools/renderers/ls.d.ts +9 -0
- package/dist/core/tools/renderers/ls.js +57 -0
- package/dist/core/tools/renderers/read.d.ts +10 -0
- package/dist/core/tools/renderers/read.js +128 -0
- package/dist/core/tools/renderers/write.d.ts +9 -0
- package/dist/core/tools/renderers/write.js +152 -0
- package/dist/core/tools/write.js +5 -146
- package/dist/extensions/agent-browser.ts +1 -2
- package/dist/extensions/package.json +0 -1
- package/dist/extensions/pi-hermes-memory/CHANGELOG.md +18 -0
- package/dist/extensions/pi-hermes-memory/README.md +16 -12
- package/dist/extensions/pi-hermes-memory/docs/ROADMAP.md +1 -1
- package/dist/extensions/pi-hermes-memory/package-lock.json +587 -62
- package/dist/extensions/pi-hermes-memory/package.json +4 -4
- package/dist/extensions/pi-hermes-memory/src/config.ts +32 -0
- package/dist/extensions/pi-hermes-memory/src/constants.ts +12 -2
- package/dist/extensions/pi-hermes-memory/src/handlers/background-review.ts +109 -51
- package/dist/extensions/pi-hermes-memory/src/handlers/index-sessions.ts +9 -3
- package/dist/extensions/pi-hermes-memory/src/handlers/review-memory-ops.ts +257 -98
- package/dist/extensions/pi-hermes-memory/src/handlers/session-backfill.ts +9 -2
- package/dist/extensions/pi-hermes-memory/src/handlers/sync-markdown-memories.ts +5 -0
- package/dist/extensions/pi-hermes-memory/src/index.ts +22 -2
- package/dist/extensions/pi-hermes-memory/src/paths.ts +1 -1
- package/dist/extensions/pi-hermes-memory/src/store/db.ts +6 -0
- package/dist/extensions/pi-hermes-memory/src/store/fts-query.ts +58 -1
- package/dist/extensions/pi-hermes-memory/src/store/memory-store.ts +60 -8
- package/dist/extensions/pi-hermes-memory/src/store/session-indexer.ts +169 -7
- package/dist/extensions/pi-hermes-memory/src/store/session-search.ts +7 -21
- package/dist/extensions/pi-hermes-memory/src/store/sqlite-memory-store.ts +134 -15
- package/dist/extensions/pi-hermes-memory/src/tools/memory-search-tool.ts +4 -2
- package/dist/extensions/pi-hermes-memory/src/tools/memory-tool.ts +24 -9
- package/dist/extensions/pi-hermes-memory/src/types.ts +11 -0
- package/dist/extensions/pi-hermes-memory/tests/config.test.ts +42 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/background-review.test.ts +159 -3
- package/dist/extensions/pi-hermes-memory/tests/handlers/review-memory-ops.test.ts +452 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-backfill.test.ts +39 -0
- package/dist/extensions/pi-hermes-memory/tests/integration/corruption-recovery-integration.test.ts +91 -0
- package/dist/extensions/pi-hermes-memory/tests/store/db.test.ts +29 -0
- package/dist/extensions/pi-hermes-memory/tests/store/fts-query.test.ts +116 -0
- package/dist/extensions/pi-hermes-memory/tests/store/memory-store.test.ts +163 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-indexer.test.ts +233 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-search.test.ts +12 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-memory-store.test.ts +175 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-native.test.ts +2 -2
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-search-tool.test.ts +22 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-tool.test.ts +37 -1
- package/dist/extensions/pi-intercom/CHANGELOG.md +13 -0
- package/dist/extensions/pi-intercom/README.md +16 -2
- package/dist/extensions/pi-intercom/broker/spawn.test.ts +19 -2
- package/dist/extensions/pi-intercom/broker/spawn.ts +4 -4
- package/dist/extensions/pi-intercom/index.ts +1 -1
- package/dist/extensions/pi-intercom/intercom.integration.test.ts +121 -2
- package/dist/extensions/pi-intercom/package.json +1 -1
- package/dist/extensions/pi-intercom/project-agent.test.ts +1 -1
- package/dist/extensions/pi-intercom/project-agent.ts +1 -6
- package/dist/extensions/pi-intercom/skills/pi-intercom/SKILL.md +7 -6
- package/dist/extensions/pi-rewind-hook/index.test.ts +7 -0
- package/dist/extensions/pi-subagents/.github/workflows/test.yml +36 -4
- package/dist/extensions/pi-subagents/CHANGELOG.md +120 -0
- package/dist/extensions/pi-subagents/README.md +3 -3
- package/dist/extensions/pi-subagents/agents/researcher.md +23 -13
- package/dist/extensions/pi-subagents/agents/reviewer.md +1 -1
- package/dist/extensions/pi-subagents/agents/scout.md +1 -1
- package/dist/extensions/pi-subagents/docs/agents.md +32 -16
- package/dist/extensions/pi-subagents/docs/configuration.md +41 -15
- package/dist/extensions/pi-subagents/docs/extension-api.md +109 -6
- package/dist/extensions/pi-subagents/docs/missions.md +2 -0
- package/dist/extensions/pi-subagents/docs/models.md +58 -1
- package/dist/extensions/pi-subagents/docs/observability.md +50 -12
- package/dist/extensions/pi-subagents/docs/tool-reference.md +17 -10
- package/dist/extensions/pi-subagents/docs/watchdog.md +1 -1
- package/dist/extensions/pi-subagents/docs/workflows.md +26 -9
- package/dist/extensions/pi-subagents/package-lock.json +747 -177
- package/dist/extensions/pi-subagents/package.json +6 -4
- package/dist/extensions/pi-subagents/runner-server-preload.mjs +13 -0
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +2 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/constraints-and-recipes.md +1 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md +21 -4
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +2 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/multi-lane-orchestration.md +2 -0
- package/dist/extensions/pi-subagents/src/agents/advertised-agent-prompt.ts +63 -0
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +61 -16
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +2 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +8 -0
- package/dist/extensions/pi-subagents/src/api/capability-ceiling.ts +0 -1
- package/dist/extensions/pi-subagents/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
- package/dist/extensions/pi-subagents/src/api/preflight.ts +7 -4
- package/dist/extensions/pi-subagents/src/api/shared-types.ts +2 -2
- package/dist/extensions/pi-subagents/src/api/workflow-resources.ts +6 -0
- package/dist/extensions/pi-subagents/src/extension/config.ts +4 -2
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +2 -10
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +9 -11
- package/dist/extensions/pi-subagents/src/extension/index.ts +99 -10
- package/dist/extensions/pi-subagents/src/extension/public-execution.ts +13 -0
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +7 -23
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +11 -8
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +25 -7
- package/dist/extensions/pi-subagents/src/integrations/pi-web-session-liveness.ts +73 -0
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +228 -136
- package/dist/extensions/pi-subagents/src/intercom/supervisor-ui.ts +244 -0
- package/dist/extensions/pi-subagents/src/missions/workflow-state.ts +37 -16
- package/dist/extensions/pi-subagents/src/runs/background/active-async-capacity.ts +18 -18
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +51 -25
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +46 -3
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +14 -3
- package/dist/extensions/pi-subagents/src/runs/background/async-retention.ts +9 -0
- package/dist/extensions/pi-subagents/src/runs/background/async-status-snapshot.ts +10 -12
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +18 -15
- package/dist/extensions/pi-subagents/src/runs/background/auto-drain.ts +40 -29
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +8 -0
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +79 -247
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +88 -12
- package/dist/extensions/pi-subagents/src/runs/background/owned-process-tree.ts +6 -6
- package/dist/extensions/pi-subagents/src/runs/background/process-terminal.ts +24 -24
- package/dist/extensions/pi-subagents/src/runs/background/retained-nested-route-tracker.ts +96 -0
- package/dist/extensions/pi-subagents/src/runs/background/run-child-session.ts +642 -0
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +75 -6
- package/dist/extensions/pi-subagents/src/runs/background/runner-aliases.ts +163 -0
- package/dist/extensions/pi-subagents/src/runs/background/runner-child-launch.ts +86 -0
- package/dist/extensions/pi-subagents/src/runs/background/runner-child-sessions.ts +31 -0
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +18 -4
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +3 -1
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +597 -1092
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +3 -0
- package/dist/extensions/pi-subagents/src/runs/background/wait-completions.ts +4 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +20 -17
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +296 -394
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +4 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-history.ts +3 -1
- package/dist/extensions/pi-subagents/src/runs/foreground/prompt-audit.ts +9 -5
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +630 -283
- package/dist/extensions/pi-subagents/src/runs/foreground/workflow-detach-reconcile.ts +8 -5
- package/dist/extensions/pi-subagents/src/runs/foreground/workflow-foreground-steering.ts +78 -98
- package/dist/extensions/pi-subagents/src/runs/shared/abort-recovery.ts +3 -3
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +16 -3
- package/dist/extensions/pi-subagents/src/runs/shared/agent-contract.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/shared/async-status-projection.ts +47 -47
- package/dist/extensions/pi-subagents/src/runs/shared/capability-ceiling.ts +1 -2
- package/dist/extensions/pi-subagents/src/runs/shared/child-hooks.ts +174 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-identity.ts +14 -3
- package/dist/extensions/pi-subagents/src/runs/shared/child-launch.ts +319 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-lifecycle.ts +25 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-runtime-config.ts +126 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-session.ts +373 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-tool-plan.ts +530 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-evidence.ts +2 -2
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-preflight.ts +16 -0
- package/dist/extensions/pi-subagents/src/runs/shared/host-step-status.ts +11 -11
- package/dist/extensions/pi-subagents/src/runs/shared/llm-intent-arbiter.ts +30 -20
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +5 -4
- package/dist/extensions/pi-subagents/src/runs/shared/model-exclusions.ts +84 -15
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +88 -12
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +37 -53
- package/dist/extensions/pi-subagents/src/runs/shared/nested-path.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/shared/orca-progress-tabs.ts +18 -7
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +57 -12
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +3 -4
- package/dist/extensions/pi-subagents/src/runs/shared/permissions.ts +0 -11
- package/dist/extensions/pi-subagents/src/runs/shared/process-signal.ts +4 -1
- package/dist/extensions/pi-subagents/src/runs/shared/readonly-drain-observation.ts +42 -0
- package/dist/extensions/pi-subagents/src/runs/shared/readonly-model-continuation.ts +69 -0
- package/dist/extensions/pi-subagents/src/runs/shared/readonly-session-evidence.ts +307 -0
- package/dist/extensions/pi-subagents/src/runs/shared/run-fanout-budget.ts +8 -21
- package/dist/extensions/pi-subagents/src/runs/shared/runtime-acknowledged-extensions.ts +3 -30
- package/dist/extensions/pi-subagents/src/runs/shared/structured-output.ts +17 -4
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-control.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +99 -386
- package/dist/extensions/pi-subagents/src/runs/shared/tool-availability.ts +18 -62
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +0 -14
- package/dist/extensions/pi-subagents/src/runs/shared/worktree-cleanup-plan.ts +31 -9
- package/dist/extensions/pi-subagents/src/runs/shared/worktree-setup-command.ts +190 -0
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +506 -226
- package/dist/extensions/pi-subagents/src/shared/child-session-name.ts +1 -1
- package/dist/extensions/pi-subagents/src/shared/jsonl-writer.ts +11 -0
- package/dist/extensions/pi-subagents/src/shared/model-response-aliases.ts +13 -0
- package/dist/extensions/pi-subagents/src/shared/thinking-ceiling.ts +0 -6
- package/dist/extensions/pi-subagents/src/shared/types.ts +145 -89
- package/dist/extensions/pi-subagents/src/shared/utils.ts +13 -6
- package/dist/extensions/pi-subagents/src/shared/watch-strategy.ts +2 -0
- package/dist/extensions/pi-subagents/src/shared/workflow-child-permit.ts +18 -13
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +0 -6
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +1 -1
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +11 -6
- package/dist/extensions/pi-subagents/src/tui/render.ts +277 -46
- package/dist/extensions/pi-subagents/src/watchdog/child-status.ts +0 -1
- package/dist/extensions/pi-subagents/src/watchdog/register-child.ts +12 -12
- package/dist/extensions/pi-subagents/src/workflows/chat-progress.ts +3 -3
- package/dist/extensions/pi-subagents/src/workflows/scripted-workflow.ts +116 -15
- package/dist/extensions/pi-subagents/src/workflows/workflow-checklist.ts +15 -18
- package/dist/extensions/pi-subagents/src/workflows/workflow-child-summary.ts +57 -8
- package/dist/extensions/pi-subagents/src/workflows/workflow-preflight.ts +19 -19
- package/dist/extensions/pi-subagents/src/workflows/workflow-receipt.ts +3 -3
- package/dist/extensions/pi-subagents/src/workflows/workflow-resources.ts +97 -22
- package/dist/extensions/pi-subagents/src/workflows/workflow-settlement.ts +3 -0
- package/dist/extensions/pi-subagents/test/integration/acceptance-file-report.test.ts +336 -21
- package/dist/extensions/pi-subagents/test/integration/async-execution.part-1.test.ts +1181 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.part-2.test.ts +2240 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.part-3.test.ts +2268 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.part-4.test.ts +1512 -0
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +231 -16
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +4 -18
- package/dist/extensions/pi-subagents/test/integration/foreign-workflow-steering.test.ts +95 -0
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +9 -15
- package/dist/extensions/pi-subagents/test/integration/in-process-child.test.ts +374 -0
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +20 -10
- package/dist/extensions/pi-subagents/test/integration/orca-progress-tabs.test.ts +18 -6
- package/dist/extensions/pi-subagents/test/integration/recovered-assistant-error.test.ts +151 -0
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +42 -1
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +150 -25
- package/dist/extensions/pi-subagents/test/integration/result-publication.test.ts +354 -0
- package/dist/extensions/pi-subagents/test/integration/shared-cwd-terminal-evidence.test.ts +117 -0
- package/dist/extensions/pi-subagents/test/integration/single-execution.part-1.test.ts +3678 -0
- package/dist/extensions/pi-subagents/test/integration/{single-execution.test.ts → single-execution.part-2.test.ts} +500 -4207
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +1 -2
- package/dist/extensions/pi-subagents/test/integration/workflow-result-publication.test.ts +127 -0
- package/dist/extensions/pi-subagents/test/integration/workflow-steer-inbox.test.ts +365 -0
- package/dist/extensions/pi-subagents/test/smoke/pi085-child.ts +31 -0
- package/dist/extensions/pi-subagents/test/smoke/pi085-clean-install.mjs +74 -0
- package/dist/extensions/pi-subagents/test/smoke/pi085-extension.ts +16 -0
- package/dist/extensions/pi-subagents/test/support/async-execution-fixture.ts +699 -0
- package/dist/extensions/pi-subagents/test/support/fake-child-session.ts +418 -0
- package/dist/extensions/pi-subagents/test/support/foreign-workflow-steer-host.mjs +13 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +30 -76
- package/dist/extensions/pi-subagents/test/support/notify-diagnostics-fixture.ts +84 -0
- package/dist/extensions/pi-subagents/test/support/result-publication-capacity-preload.mjs +70 -0
- package/dist/extensions/pi-subagents/test/support/runner-child-session-factory.ts +17 -0
- package/dist/extensions/pi-subagents/test/support/single-execution-fixture.ts +390 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance-compaction.test.ts +120 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +24 -3
- package/dist/extensions/pi-subagents/test/unit/advertised-agent-prompt.test.ts +87 -0
- package/dist/extensions/pi-subagents/test/unit/advertised-agent-refresh.test.ts +163 -0
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +70 -31
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +78 -3
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +2 -8
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +73 -66
- package/dist/extensions/pi-subagents/test/unit/async-recovery-descriptor.test.ts +51 -1
- package/dist/extensions/pi-subagents/test/unit/async-retention.test.ts +49 -1
- package/dist/extensions/pi-subagents/test/unit/async-spawn-preload.test.ts +103 -0
- package/dist/extensions/pi-subagents/test/unit/async-status-projection.test.ts +3 -3
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling-agent-allowlist.test.ts +9 -8
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling.test.ts +10 -7
- package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +48 -6
- package/dist/extensions/pi-subagents/test/unit/child-runtime-config.test.ts +90 -0
- package/dist/extensions/pi-subagents/test/unit/{pi-args-permission-system.test.ts → child-tool-plan-permission-system.test.ts} +48 -86
- package/dist/extensions/pi-subagents/test/unit/child-tool-plan.test.ts +33 -0
- package/dist/extensions/pi-subagents/test/unit/compaction-resume.test.ts +18 -18
- package/dist/extensions/pi-subagents/test/unit/completion-evidence.test.ts +9 -9
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +8 -7
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +225 -65
- package/dist/extensions/pi-subagents/test/unit/extension-bindings.test.ts +17 -22
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +11 -1
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +47 -3
- package/dist/extensions/pi-subagents/test/unit/foreign-workflow-steering.test.ts +74 -0
- package/dist/extensions/pi-subagents/test/unit/fork-cache-key.test.ts +23 -29
- package/dist/extensions/pi-subagents/test/unit/host-peer-runtime-imports.test.ts +96 -4
- package/dist/extensions/pi-subagents/test/unit/host-step-status.test.ts +4 -4
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +116 -55
- package/dist/extensions/pi-subagents/test/unit/index-segment.test.ts +58 -1
- package/dist/extensions/pi-subagents/test/unit/llm-intent-arbiter.test.ts +104 -3
- package/dist/extensions/pi-subagents/test/unit/mission-lifecycle.test.ts +10 -1
- package/dist/extensions/pi-subagents/test/unit/mission-store.test.ts +31 -1
- package/dist/extensions/pi-subagents/test/unit/model-exclusions.test.ts +102 -51
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +196 -6
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +181 -38
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +62 -70
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +58 -53
- package/dist/extensions/pi-subagents/test/unit/notify-diagnostics.test.ts +42 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +84 -0
- package/dist/extensions/pi-subagents/test/unit/orca-progress-tabs.test.ts +13 -5
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +21 -5
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +5 -4
- package/dist/extensions/pi-subagents/test/unit/permissions.test.ts +2 -6
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +28 -2
- package/dist/extensions/pi-subagents/test/unit/pi-web-session-liveness.test.ts +209 -0
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +38 -1
- package/dist/extensions/pi-subagents/test/unit/prompt-audit-optional-peers.test.ts +43 -0
- package/dist/extensions/pi-subagents/test/unit/public-execution.test.ts +24 -2
- package/dist/extensions/pi-subagents/test/unit/readonly-drain-observation.test.ts +174 -0
- package/dist/extensions/pi-subagents/test/unit/readonly-model-continuation.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/unit/readonly-session-evidence.test.ts +1329 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +29 -80
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +11 -8
- package/dist/extensions/pi-subagents/test/unit/result-files.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/retained-nested-route-tracker.test.ts +175 -0
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +38 -12
- package/dist/extensions/pi-subagents/test/unit/run-fanout-budget.test.ts +2 -5
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +89 -1
- package/dist/extensions/pi-subagents/test/unit/runtime-acknowledged-extensions.test.ts +2 -16
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +27 -3
- package/dist/extensions/pi-subagents/test/unit/scheduled-supervisor-demand.test.ts +215 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +15 -11
- package/dist/extensions/pi-subagents/test/unit/scripted-workflow.test.ts +237 -1
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +2 -5
- package/dist/extensions/pi-subagents/test/unit/streamed-progress-bounds.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/subagent-guide.test.ts +14 -1
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +130 -739
- package/dist/extensions/pi-subagents/test/unit/supervisor-ask-registration.test.ts +682 -0
- package/dist/extensions/pi-subagents/test/unit/supervisor-ui.test.ts +137 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +1 -11
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +23 -3
- package/dist/extensions/pi-subagents/test/unit/wait-completions.test.ts +8 -1
- package/dist/extensions/pi-subagents/test/unit/watchdog-tool-actions.test.ts +19 -1
- package/dist/extensions/pi-subagents/test/unit/workflow-chat-progress.test.ts +72 -4
- package/dist/extensions/pi-subagents/test/unit/workflow-checklist.test.ts +17 -3
- package/dist/extensions/pi-subagents/test/unit/workflow-child-summary.test.ts +34 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-detach-reconcile.test.ts +12 -2
- package/dist/extensions/pi-subagents/test/unit/workflow-launch-params.test.ts +46 -6
- package/dist/extensions/pi-subagents/test/unit/workflow-receipt.test.ts +3 -3
- package/dist/extensions/pi-subagents/test/unit/workflow-resources.test.ts +133 -1
- package/dist/extensions/pi-subagents/test/unit/workflow-resume-hint.test.ts +53 -2
- package/dist/extensions/pi-subagents/test/unit/worktree-cleanup-plan.test.ts +222 -14
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +526 -85
- package/dist/extensions/pi-web-agent/README.md +6 -5
- package/dist/extensions/pi-web-agent/src/backends/config.ts +12 -6
- package/dist/extensions/pi-web-agent/src/backends/factory.ts +2 -2
- package/dist/extensions/pi-web-agent/src/backends/settings-reader.ts +4 -5
- package/dist/extensions/pi-web-agent/src/commands/web-agent-config.ts +8 -8
- package/dist/extensions/pi-web-agent/src/extension.ts +3 -3
- package/dist/extensions/pi-web-agent/src/presentation/config-store.ts +2 -2
- package/dist/extensions/pi-web-agent/src/search/tokenin.ts +14 -3
- package/dist/extensions/pi-zentui/README.md +17 -0
- package/dist/extensions/pi-zentui/assets/screenshots/footer-status-hyperlink.png +0 -0
- package/dist/extensions/pi-zentui/docs/configuration.md +71 -2
- package/dist/extensions/pi-zentui/extensions/zentui/config.ts +11 -0
- package/dist/extensions/pi-zentui/extensions/zentui/editor-transfer.ts +14 -0
- package/dist/extensions/pi-zentui/extensions/zentui/extension-status.ts +29 -13
- package/dist/extensions/pi-zentui/extensions/zentui/footer-layout.ts +5 -4
- package/dist/extensions/pi-zentui/extensions/zentui/footer-text.ts +11 -0
- package/dist/extensions/pi-zentui/extensions/zentui/footer.ts +11 -10
- package/dist/extensions/pi-zentui/extensions/zentui/index.ts +77 -3
- package/dist/extensions/pi-zentui/extensions/zentui/presets.ts +77 -0
- package/dist/extensions/pi-zentui/extensions/zentui/settings-command.ts +103 -2
- package/dist/extensions/pi-zentui/extensions/zentui/working-line-extension-segments.ts +115 -0
- package/dist/extensions/pi-zentui/extensions/zentui/working-line.ts +87 -5
- package/dist/extensions/pi-zentui/package-lock.json +277 -517
- package/dist/extensions/pi-zentui/package.json +7 -4
- package/dist/extensions/pi-zentui/test/config-presets.test.ts +238 -0
- package/dist/extensions/pi-zentui/test/editor-transfer.test.ts +24 -1
- package/dist/extensions/pi-zentui/test/extension-compliance.test.ts +570 -2
- package/dist/extensions/pi-zentui/test/extension-status.test.ts +90 -0
- package/dist/extensions/pi-zentui/test/footer-hyperlink.test.ts +243 -0
- package/dist/extensions/pi-zentui/test/package-contents.mjs +1 -0
- package/dist/extensions/pi-zentui/test/presets.test.ts +121 -0
- package/dist/extensions/pi-zentui/test/settings-command.test.ts +205 -1
- package/dist/extensions/pi-zentui/test/working-line-extension-segments.test.ts +139 -0
- package/dist/extensions/pi-zentui/test/working-line-lifecycle.integration.test.ts +237 -3
- package/dist/extensions/pi-zentui/test/working-line.test.ts +94 -2
- package/dist/index.d.ts +1 -1
- package/dist/main.js +4 -1
- package/dist/modes/interactive/chat-viewport.d.ts +19 -0
- package/dist/modes/interactive/chat-viewport.js +27 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +6 -2
- package/dist/modes/interactive/components/assistant-message.js +30 -13
- package/dist/modes/interactive/components/custom-editor.d.ts +10 -1
- package/dist/modes/interactive/components/custom-editor.js +39 -1
- package/dist/modes/interactive/components/first-time-setup.js +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +2 -0
- package/dist/modes/interactive/components/markdown-transform.js +18 -0
- package/dist/modes/interactive/components/model-selector.js +19 -17
- package/dist/modes/interactive/components/scoped-models-selector.js +21 -23
- package/dist/modes/interactive/components/settings-selector.d.ts +7 -1
- package/dist/modes/interactive/components/settings-selector.js +128 -20
- package/dist/modes/interactive/components/settings-submenu.d.ts +71 -0
- package/dist/modes/interactive/components/settings-submenu.js +164 -0
- package/dist/modes/interactive/components/status-indicator.d.ts +3 -1
- package/dist/modes/interactive/components/status-indicator.js +10 -3
- package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
- package/dist/modes/interactive/components/thinking-selector.js +75 -18
- package/dist/modes/interactive/components/tool-execution.d.ts +21 -4
- package/dist/modes/interactive/components/tool-execution.js +35 -33
- package/dist/modes/interactive/components/trust-selector.js +2 -2
- package/dist/modes/interactive/interactive-mode.d.ts +13 -15
- package/dist/modes/interactive/interactive-mode.js +144 -80
- package/dist/modes/interactive/session-share.d.ts +15 -0
- package/dist/modes/interactive/session-share.js +183 -0
- package/dist/modes/interactive/theme/dark.json +2 -1
- package/dist/modes/interactive/theme/light.json +2 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts +1 -0
- package/dist/modes/interactive/theme/theme-controller.js +5 -0
- package/dist/modes/interactive/theme/theme-json.d.ts +83 -0
- package/dist/modes/interactive/theme/theme-json.js +129 -0
- package/dist/modes/interactive/theme/theme-schema.json +9 -1
- package/dist/modes/interactive/theme/theme.d.ts +14 -5
- package/dist/modes/interactive/theme/theme.js +18 -119
- package/dist/modes/interactive/tui-renderer.d.ts +20 -0
- package/dist/modes/interactive/tui-renderer.js +65 -0
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/management-http.d.ts +24 -0
- package/dist/utils/management-http.js +53 -0
- package/dist/utils/text.d.ts +7 -0
- package/dist/utils/text.js +8 -0
- package/dist/utils/tools-manager.d.ts +1 -0
- package/dist/utils/tools-manager.js +43 -21
- package/docs/docs.json +0 -4
- package/package.json +6 -6
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +0 -415
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +0 -1059
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-startup-retry.ts +0 -116
- package/dist/extensions/pi-subagents/src/shared/post-exit-stdio-guard.ts +0 -85
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +0 -224
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +0 -6986
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +0 -447
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +0 -185
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +0 -311
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling-pi-args.test.ts +0 -84
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +0 -202
- package/dist/extensions/pi-subagents/test/unit/close-grace-timer.test.ts +0 -101
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +0 -2347
- package/dist/extensions/pi-subagents/test/unit/subagent-startup-retry.test.ts +0 -104
- package/dist/extensions/pi-subagents/test/unit/windows-hide-spawn.test.ts +0 -49
- package/dist/extensions/web-agent-onboarding.test.ts +0 -415
- package/dist/extensions/web-agent-onboarding.ts +0 -222
- package/dist/skills/imagegen-frontend-mobile/SKILL.md +0 -1465
- package/dist/skills/imagegen-frontend-web/SKILL.md +0 -987
- package/dist/skills/implanger/SKILL.md +0 -70
- package/dist/skills/output/SKILL.md +0 -49
- package/dist/skills/planger/SKILL.md +0 -167
- package/dist/skills/workflow/SKILL.md +0 -95
- package/docs/workflows.md +0 -18
- /package/dist/bun/{register-bedrock.d.ts → runtime-setup.d.ts} +0 -0
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for async (background) agent execution.
|
|
3
|
+
*
|
|
4
|
+
* Tests the async support utilities: jiti availability check,
|
|
5
|
+
* status file reading/caching.
|
|
6
|
+
*
|
|
7
|
+
* Requires pi packages to be importable. Skips gracefully if unavailable.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { after, afterEach, before, beforeEach } from "node:test";
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
import { ChildProcess, spawnSync } from "node:child_process";
|
|
13
|
+
import { channel } from "node:diagnostics_channel";
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as os from "node:os";
|
|
16
|
+
import * as path from "node:path";
|
|
17
|
+
import { createEventBus, createMockPi, createTempDir, makeAgent, removeTempDir, resolveMockPiCallArgs, tryImport } from "./helpers.ts";
|
|
18
|
+
import type { MockPi } from "./helpers.ts";
|
|
19
|
+
import { CHILD_WATCHDOG_STATUS_EVENT } from "../../src/watchdog/child-status.ts";
|
|
20
|
+
import { clearExclusions } from "../../src/runs/shared/model-exclusions.ts";
|
|
21
|
+
|
|
22
|
+
interface LaunchResolvedExtensions {
|
|
23
|
+
version?: number;
|
|
24
|
+
source?: string;
|
|
25
|
+
disableAmbientExtensions?: boolean;
|
|
26
|
+
runtime?: string[];
|
|
27
|
+
configured?: string[];
|
|
28
|
+
effective?: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface RuntimeAcknowledgedExtensions {
|
|
32
|
+
version?: number;
|
|
33
|
+
source?: string;
|
|
34
|
+
ids?: string[];
|
|
35
|
+
omitted?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface UsageBudgetState {
|
|
39
|
+
version?: number;
|
|
40
|
+
source?: string;
|
|
41
|
+
exhausted?: boolean;
|
|
42
|
+
reason?: string;
|
|
43
|
+
tokens?: { used?: number; hard?: number; exhausted?: boolean };
|
|
44
|
+
costUsd?: { used?: number; hard?: number; exhausted?: boolean };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface AsyncExecutionResult {
|
|
48
|
+
content: Array<{ text?: string }>;
|
|
49
|
+
isError?: boolean;
|
|
50
|
+
details: { asyncId?: string; asyncDir?: string; launchContractDigest?: string; launchResolvedExtensions?: LaunchResolvedExtensions; runtimeAcknowledgedExtensions?: RuntimeAcknowledgedExtensions; usageBudget?: UsageBudgetState };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface AsyncResultPayload {
|
|
54
|
+
lifecycleArtifactVersion?: number;
|
|
55
|
+
success: boolean;
|
|
56
|
+
state?: string;
|
|
57
|
+
exitCode?: number;
|
|
58
|
+
sessionId?: string;
|
|
59
|
+
mode?: string;
|
|
60
|
+
launchContractDigest?: string;
|
|
61
|
+
launchResolvedExtensions?: LaunchResolvedExtensions;
|
|
62
|
+
runtimeAcknowledgedExtensions?: RuntimeAcknowledgedExtensions;
|
|
63
|
+
summary?: string;
|
|
64
|
+
error?: string;
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
deadlineAt?: number;
|
|
67
|
+
timedOut?: boolean;
|
|
68
|
+
stopped?: boolean;
|
|
69
|
+
turnBudget?: { maxTurns: number; graceTurns: number; outcome: string; turnCount: number; wrapUpRequestedAtTurn?: number; terminationDeferredAtTurn?: number; exceededAtTurn?: number };
|
|
70
|
+
turnBudgetExceeded?: boolean;
|
|
71
|
+
wrapUpRequested?: boolean;
|
|
72
|
+
totalTokens?: { input: number; output: number; total: number };
|
|
73
|
+
totalCost?: { inputTokens: number; outputTokens: number; costUsd: number };
|
|
74
|
+
usageBudget?: UsageBudgetState;
|
|
75
|
+
results: Array<{ agent?: string; sessionName?: string; launchContractDigest?: string; launchResolvedExtensions?: LaunchResolvedExtensions; runtimeAcknowledgedExtensions?: RuntimeAcknowledgedExtensions; output?: string; outputState?: "present" | "absent" | "unknown"; success?: boolean; error?: string; timedOut?: boolean; timeoutRecovery?: { changedFiles?: string[]; message?: string; warning?: string; recoveryNeeded?: boolean; reason?: string; reportStatus?: string }; stopped?: boolean; turnBudget?: { maxTurns: number; graceTurns: number; outcome: string; turnCount: number; wrapUpRequestedAtTurn?: number; terminationDeferredAtTurn?: number; exceededAtTurn?: number }; turnBudgetExceeded?: boolean; wrapUpRequested?: boolean; model?: string; thinking?: string; attemptedModels?: string[]; modelAttempts?: Array<{ success?: boolean; error?: string }>; totalCost?: { inputTokens: number; outputTokens: number; costUsd: number }; usage?: { input: number; output: number; cacheRead: number; cacheWrite: number; cost: number; turns: number }; structuredOutput?: unknown; agentContract?: { version: 1 }; execution?: { status?: string; success?: boolean; exitCode?: number }; effects?: { fileMutation?: { status?: string; expected?: boolean; attempted?: boolean; message?: string }; settlementDiagnostic?: { finalTextPresent?: boolean; mutation?: { expected?: boolean; attempted?: boolean; observed?: boolean }; requiredOutput?: { kind?: string; path?: string; missing?: boolean }; afterCompactionSettlement?: boolean } }; intercomTarget?: string; acceptance?: { status?: string; effectiveAcceptance?: { level?: string }; childReport?: unknown; runtimeChecks?: Array<{ id?: string; status?: string; message?: string }> }; artifactPaths?: { outputPath?: string; inputPath?: string; metadataPath?: string; transcriptPath?: string }; outputSaveError?: string; metadataSaveError?: string; capabilityCeiling?: { version?: number; allowedTools?: string[]; denyExtensions?: boolean; sources?: string[] }; capabilityAudit?: { effectiveTools?: string[]; removedTools?: string[]; extensionsDenied?: boolean } }>;
|
|
76
|
+
outputs?: Record<string, { text?: string; structured?: unknown }>;
|
|
77
|
+
workflowGraph?: { nodes?: Array<{ kind?: string; label?: string; phase?: string; status?: string; acceptanceStatus?: string; error?: string; outputName?: string; structured?: boolean; children?: Array<{ label?: string; outputName?: string; itemKey?: string; status?: string; acceptanceStatus?: string; error?: string }> }> };
|
|
78
|
+
parallelHandoff?: { version?: number; path?: string; groupCount?: number; childCount?: number; changedPatches?: number; cleanupState?: string };
|
|
79
|
+
capabilityCeiling?: { version?: number; allowedTools?: string[]; denyExtensions?: boolean; sources?: string[] };
|
|
80
|
+
capabilityAudit?: { effectiveTools?: string[]; removedTools?: string[]; extensionsDenied?: boolean };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface AsyncStatusPayload {
|
|
84
|
+
lifecycleArtifactVersion?: number;
|
|
85
|
+
sessionId?: string;
|
|
86
|
+
pid?: number;
|
|
87
|
+
activityState?: string;
|
|
88
|
+
currentTool?: string;
|
|
89
|
+
currentPath?: string;
|
|
90
|
+
state?: string;
|
|
91
|
+
endedAt?: number;
|
|
92
|
+
launchContractDigest?: string;
|
|
93
|
+
launchResolvedExtensions?: LaunchResolvedExtensions;
|
|
94
|
+
runtimeAcknowledgedExtensions?: RuntimeAcknowledgedExtensions;
|
|
95
|
+
error?: string;
|
|
96
|
+
timeoutMs?: number;
|
|
97
|
+
deadlineAt?: number;
|
|
98
|
+
timedOut?: boolean;
|
|
99
|
+
stopped?: boolean;
|
|
100
|
+
turnBudget?: { maxTurns: number; graceTurns: number; outcome: string; turnCount: number; wrapUpRequestedAtTurn?: number; terminationDeferredAtTurn?: number; exceededAtTurn?: number };
|
|
101
|
+
turnBudgetExceeded?: boolean;
|
|
102
|
+
wrapUpRequested?: boolean;
|
|
103
|
+
totalTokens?: { total: number };
|
|
104
|
+
totalCost?: { inputTokens: number; outputTokens: number; costUsd: number };
|
|
105
|
+
usageBudget?: UsageBudgetState;
|
|
106
|
+
parallelGroups?: Array<{ start: number; count: number; stepIndex: number }>;
|
|
107
|
+
parallelHandoff?: { version?: number; path?: string; groupCount?: number; childCount?: number; changedPatches?: number; cleanupState?: string };
|
|
108
|
+
capabilityCeiling?: { version?: number; allowedTools?: string[]; denyExtensions?: boolean; sources?: string[] };
|
|
109
|
+
capabilityAudit?: { effectiveTools?: string[]; removedTools?: string[]; extensionsDenied?: boolean };
|
|
110
|
+
steps?: Array<{
|
|
111
|
+
agent?: string;
|
|
112
|
+
sessionName?: string;
|
|
113
|
+
label?: string;
|
|
114
|
+
phase?: string;
|
|
115
|
+
outputName?: string;
|
|
116
|
+
structured?: boolean;
|
|
117
|
+
skills?: string[];
|
|
118
|
+
activityState?: string;
|
|
119
|
+
currentTool?: string;
|
|
120
|
+
status?: string;
|
|
121
|
+
exitCode?: number;
|
|
122
|
+
timedOut?: boolean;
|
|
123
|
+
timeoutRecovery?: { changedFiles?: string[]; message?: string; warning?: string; recoveryNeeded?: boolean; reason?: string; reportStatus?: string };
|
|
124
|
+
error?: string;
|
|
125
|
+
model?: string;
|
|
126
|
+
thinking?: string;
|
|
127
|
+
tokens?: { total: number };
|
|
128
|
+
totalCost?: { inputTokens: number; outputTokens: number; costUsd: number };
|
|
129
|
+
agentContract?: { version: 1 };
|
|
130
|
+
launchContractDigest?: string;
|
|
131
|
+
launchResolvedExtensions?: LaunchResolvedExtensions;
|
|
132
|
+
runtimeAcknowledgedExtensions?: RuntimeAcknowledgedExtensions;
|
|
133
|
+
execution?: { status?: string; success?: boolean; exitCode?: number };
|
|
134
|
+
effects?: { fileMutation?: { status?: string; expected?: boolean; attempted?: boolean }; settlementDiagnostic?: { finalTextPresent?: boolean; mutation?: { expected?: boolean; attempted?: boolean; observed?: boolean }; requiredOutput?: { kind?: string; path?: string; missing?: boolean }; afterCompactionSettlement?: boolean } };
|
|
135
|
+
acceptance?: { status?: string };
|
|
136
|
+
contextLimit?: number;
|
|
137
|
+
turnBudget?: { maxTurns: number; graceTurns: number; outcome: string; turnCount: number; wrapUpRequestedAtTurn?: number; terminationDeferredAtTurn?: number; exceededAtTurn?: number };
|
|
138
|
+
turnBudgetExceeded?: boolean;
|
|
139
|
+
wrapUpRequested?: boolean;
|
|
140
|
+
capabilityCeiling?: { version?: number; allowedTools?: string[]; denyExtensions?: boolean; sources?: string[] };
|
|
141
|
+
capabilityAudit?: { effectiveTools?: string[]; removedTools?: string[]; extensionsDenied?: boolean };
|
|
142
|
+
}>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface MockPiCallRecord {
|
|
146
|
+
args?: string[];
|
|
147
|
+
effectiveArgs?: string[];
|
|
148
|
+
systemPrompts?: Array<{ mode?: string; path?: string; text?: string; error?: string }>;
|
|
149
|
+
requiredChildTools?: string[];
|
|
150
|
+
/** The `ChildRuntimeConfig` the scripted child session was launched with. */
|
|
151
|
+
runtime?: Record<string, unknown>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Recorded child runtime config of the mock call at `index`, once it exists. */
|
|
155
|
+
async function waitForMockPiRuntime(mockPi: MockPi, index: number, timeoutMs = 30_000): Promise<Record<string, unknown>> {
|
|
156
|
+
const deadline = Date.now() + timeoutMs;
|
|
157
|
+
for (;;) {
|
|
158
|
+
const callFile = fs.readdirSync(mockPi.dir)
|
|
159
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
160
|
+
.sort()
|
|
161
|
+
.at(index);
|
|
162
|
+
if (callFile) {
|
|
163
|
+
const payload = JSON.parse(fs.readFileSync(path.join(mockPi.dir, callFile), "utf-8")) as MockPiCallRecord;
|
|
164
|
+
assert.ok(payload.runtime, "expected a recorded child runtime config");
|
|
165
|
+
return payload.runtime;
|
|
166
|
+
}
|
|
167
|
+
if (Date.now() > deadline) assert.fail(`Timed out waiting for recorded mock pi call ${index}`);
|
|
168
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function writeWatchdogSettings(projectDir: string, tailMs = 120_000): void {
|
|
173
|
+
const settingsPath = path.join(projectDir, ".selesai", "settings.json");
|
|
174
|
+
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
|
|
175
|
+
fs.writeFileSync(settingsPath, JSON.stringify({
|
|
176
|
+
subagents: {
|
|
177
|
+
watchdog: {
|
|
178
|
+
enabled: true,
|
|
179
|
+
children: {
|
|
180
|
+
enabled: true,
|
|
181
|
+
watchdogTailTimeoutMs: tailMs,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
}, null, 2), "utf-8");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function withIsolatedWatchdogSettings<T>(projectDir: string, run: () => Promise<T>): Promise<T> {
|
|
189
|
+
const previousAgentDir = process.env.SELESAI_CODING_AGENT_DIR;
|
|
190
|
+
const previousHome = process.env.HOME;
|
|
191
|
+
const previousUserProfile = process.env.USERPROFILE;
|
|
192
|
+
const isolatedHome = path.join(projectDir, "isolated-home");
|
|
193
|
+
process.env.SELESAI_CODING_AGENT_DIR = path.join(isolatedHome, ".selesai", "agent");
|
|
194
|
+
process.env.HOME = isolatedHome;
|
|
195
|
+
process.env.USERPROFILE = isolatedHome;
|
|
196
|
+
try {
|
|
197
|
+
return await run();
|
|
198
|
+
} finally {
|
|
199
|
+
if (previousAgentDir === undefined) delete process.env.SELESAI_CODING_AGENT_DIR;
|
|
200
|
+
else process.env.SELESAI_CODING_AGENT_DIR = previousAgentDir;
|
|
201
|
+
if (previousHome === undefined) delete process.env.HOME;
|
|
202
|
+
else process.env.HOME = previousHome;
|
|
203
|
+
if (previousUserProfile === undefined) delete process.env.USERPROFILE;
|
|
204
|
+
else process.env.USERPROFILE = previousUserProfile;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function childWatchdogStatus(runId: string, phase: "idle" | "reviewing" | "stale" | "failed", seq: number) {
|
|
209
|
+
return {
|
|
210
|
+
type: CHILD_WATCHDOG_STATUS_EVENT,
|
|
211
|
+
runId,
|
|
212
|
+
agent: "worker",
|
|
213
|
+
childIndex: 0,
|
|
214
|
+
stepIndex: 0,
|
|
215
|
+
seq,
|
|
216
|
+
phase,
|
|
217
|
+
ts: Date.now() + seq,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function mockAssistantMessage(text: string, stopReason: "stop" | "tool_use" = "stop") {
|
|
222
|
+
return {
|
|
223
|
+
type: "message_end",
|
|
224
|
+
message: {
|
|
225
|
+
role: "assistant",
|
|
226
|
+
content: stopReason === "tool_use"
|
|
227
|
+
? [{ type: "text", text }, { type: "toolCall", name: "bash", arguments: { command: "echo test" } }]
|
|
228
|
+
: [{ type: "text", text }],
|
|
229
|
+
model: "mock/test-model",
|
|
230
|
+
stopReason,
|
|
231
|
+
usage: {
|
|
232
|
+
input: 10,
|
|
233
|
+
output: 5,
|
|
234
|
+
cacheRead: 0,
|
|
235
|
+
cacheWrite: 0,
|
|
236
|
+
cost: { total: 0.001 },
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface AsyncExecutionModule {
|
|
243
|
+
isAsyncAvailable(): boolean;
|
|
244
|
+
executeAsyncSingle(id: string, params: Record<string, unknown>): AsyncExecutionResult;
|
|
245
|
+
executeAsyncChain(id: string, params: Record<string, unknown>): AsyncExecutionResult;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
interface AsyncStatusModule {
|
|
249
|
+
resolveTargetedAsyncRun(root: string, id: string, sessionId?: string): { kind: string };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface UtilsModule {
|
|
253
|
+
readStatus(dir: string): { runId: string; state: string; mode: string } | null;
|
|
254
|
+
pruneStatusCacheForAsyncRoot(root: string, runIds: Iterable<string>): number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
interface TypesModule {
|
|
258
|
+
ASYNC_DIR: string;
|
|
259
|
+
RESULTS_DIR: string;
|
|
260
|
+
TEMP_ROOT_DIR: string;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
interface ExecutorModule {
|
|
264
|
+
createSubagentExecutor?: (...args: unknown[]) => {
|
|
265
|
+
execute: (...args: unknown[]) => Promise<{ content: Array<{ text?: string }>; isError?: boolean; details?: { asyncId?: string } }>;
|
|
266
|
+
executePublic: (...args: unknown[]) => Promise<{ content: Array<{ text?: string }>; isError?: boolean; details?: { asyncId?: string } }>;
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const asyncMod = await tryImport<AsyncExecutionModule>("./src/runs/background/async-execution.ts");
|
|
271
|
+
const asyncStatusMod = await tryImport<AsyncStatusModule>("./src/runs/background/async-status.ts");
|
|
272
|
+
const utils = await tryImport<UtilsModule>("./src/shared/utils.ts");
|
|
273
|
+
const typesMod = await tryImport<TypesModule>("./src/shared/types.ts");
|
|
274
|
+
const executorMod = await tryImport<ExecutorModule>("./src/runs/foreground/subagent-executor.ts");
|
|
275
|
+
const available = !!(asyncMod && utils && typesMod);
|
|
276
|
+
|
|
277
|
+
const isAsyncAvailable = asyncMod?.isAsyncAvailable;
|
|
278
|
+
const executeAsyncSingle = asyncMod?.executeAsyncSingle;
|
|
279
|
+
const executeAsyncChain = asyncMod?.executeAsyncChain;
|
|
280
|
+
const resolveTargetedAsyncRun = asyncStatusMod?.resolveTargetedAsyncRun;
|
|
281
|
+
const readStatus = utils?.readStatus;
|
|
282
|
+
const pruneStatusCacheForAsyncRoot = utils?.pruneStatusCacheForAsyncRoot;
|
|
283
|
+
const ASYNC_DIR = typesMod?.ASYNC_DIR;
|
|
284
|
+
const RESULTS_DIR = typesMod?.RESULTS_DIR;
|
|
285
|
+
const TEMP_ROOT_DIR = typesMod?.TEMP_ROOT_DIR;
|
|
286
|
+
const createSubagentExecutor = executorMod?.createSubagentExecutor;
|
|
287
|
+
|
|
288
|
+
function escapeRegExp(value: string): string {
|
|
289
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function git(cwd: string, args: string[]): string {
|
|
293
|
+
const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf-8" });
|
|
294
|
+
if (result.status !== 0) {
|
|
295
|
+
throw new Error(result.stderr.trim() || result.stdout.trim() || `git ${args.join(" ")} failed`);
|
|
296
|
+
}
|
|
297
|
+
return result.stdout.trim();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function createRepo(prefix: string): string {
|
|
301
|
+
const repoDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
302
|
+
git(repoDir, ["init"]);
|
|
303
|
+
git(repoDir, ["config", "user.email", "tests@example.com"]);
|
|
304
|
+
git(repoDir, ["config", "user.name", "Async Tests"]);
|
|
305
|
+
fs.writeFileSync(path.join(repoDir, "input.md"), "input\n", "utf-8");
|
|
306
|
+
git(repoDir, ["add", "-A"]);
|
|
307
|
+
git(repoDir, ["commit", "-m", "initial commit"]);
|
|
308
|
+
return repoDir;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function writePackageSkill(packageRoot: string, skillName: string): void {
|
|
312
|
+
const skillDir = path.join(packageRoot, "skills", skillName);
|
|
313
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
314
|
+
fs.writeFileSync(
|
|
315
|
+
path.join(packageRoot, "package.json"),
|
|
316
|
+
JSON.stringify({ name: `${skillName}-pkg`, version: "1.0.0", pi: { skills: [`./skills/${skillName}`] } }, null, 2),
|
|
317
|
+
"utf-8",
|
|
318
|
+
);
|
|
319
|
+
fs.writeFileSync(
|
|
320
|
+
path.join(skillDir, "SKILL.md"),
|
|
321
|
+
`---\nname: ${skillName}\ndescription: test skill\n---\nbody\n`,
|
|
322
|
+
"utf-8",
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function readIfExists(filePath: string): string | undefined {
|
|
327
|
+
try {
|
|
328
|
+
const text = fs.readFileSync(filePath, "utf-8").trim();
|
|
329
|
+
return text || undefined;
|
|
330
|
+
} catch {
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async function waitForAsyncResultFile(id: string, timeoutMs = 15_000): Promise<string> {
|
|
336
|
+
const resultPath = path.join(RESULTS_DIR, `${id}.json`);
|
|
337
|
+
const deadline = Date.now() + timeoutMs;
|
|
338
|
+
while (!fs.existsSync(resultPath)) {
|
|
339
|
+
if (Date.now() > deadline) {
|
|
340
|
+
const asyncDir = path.join(ASYNC_DIR, id);
|
|
341
|
+
// Summarize before teardown; never print free-form output, prompts or tokens.
|
|
342
|
+
const evidence = ["status.json", "runner-startup-proceed.json", "process-terminal.json", "events.jsonl", "runner.stdout.log", "runner.stderr.log"].map((name) => {
|
|
343
|
+
let text: string;
|
|
344
|
+
try {
|
|
345
|
+
text = fs.readFileSync(path.join(asyncDir, name), "utf-8");
|
|
346
|
+
} catch (error) {
|
|
347
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
348
|
+
return `${name}: ${code === "ENOENT" ? "absent" : `unreadable (${code ?? "unknown"})`}`;
|
|
349
|
+
}
|
|
350
|
+
if (!text.length) return `${name}: empty`;
|
|
351
|
+
const size = `${Buffer.byteLength(text)} bytes (contents withheld)`;
|
|
352
|
+
if (name !== "status.json") return `${name}: readable, ${size}`;
|
|
353
|
+
try {
|
|
354
|
+
const status = JSON.parse(text) as AsyncStatusPayload;
|
|
355
|
+
const knownState = (value: unknown) => ["pending", "running", "complete", "failed", "cancelled"].includes(String(value)) ? value : "other/absent";
|
|
356
|
+
return `${name}: ${JSON.stringify({ state: knownState(status.state), steps: status.steps?.map((step) => knownState(step.status)), endedAtPresent: typeof status.endedAt === "number" })}`;
|
|
357
|
+
} catch {
|
|
358
|
+
return `${name}: invalid status JSON, ${size}`;
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
// The current fixture queue proves prompt entry, not per-run identity or settlement.
|
|
362
|
+
const queueDir = process.env.MOCK_PI_QUEUE_DIR;
|
|
363
|
+
let mockEvidence = "mock queue: not configured";
|
|
364
|
+
if (queueDir) {
|
|
365
|
+
try {
|
|
366
|
+
const calls = fs.readdirSync(queueDir).filter((name) => name.startsWith("call-") && name.endsWith(".json"));
|
|
367
|
+
mockEvidence = `mock queue: readable, prompt call records=${calls.length} (current fixture, not correlated to run)`;
|
|
368
|
+
} catch (error) {
|
|
369
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
370
|
+
mockEvidence = `mock queue: ${code === "ENOENT" ? "absent" : `unreadable (${code ?? "unknown"})`}`;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
assert.fail([
|
|
374
|
+
`Timed out waiting for async result file: ${resultPath}`,
|
|
375
|
+
mockEvidence,
|
|
376
|
+
...evidence,
|
|
377
|
+
].join("\n"));
|
|
378
|
+
}
|
|
379
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
380
|
+
}
|
|
381
|
+
return resultPath;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// #1906 only: observation, never a terminality predicate or process controller.
|
|
385
|
+
export function observeSharedCwdRunner(id: string) {
|
|
386
|
+
const number = (value: unknown) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
387
|
+
const known = (value: unknown, values: string[]) => typeof value === "string" && values.includes(value) ? value : undefined;
|
|
388
|
+
const record = (value: unknown): Record<string, unknown> => value !== null && typeof value === "object" ? value as Record<string, unknown> : {};
|
|
389
|
+
const errorCode = (error: unknown) => known(record(error).code, ["ENOENT", "EACCES", "EPERM", "EBUSY", "EIO", "EMFILE", "ENFILE", "ENOSPC"]) ?? "other";
|
|
390
|
+
const project = (value: unknown) => {
|
|
391
|
+
const raw = record(value);
|
|
392
|
+
return {
|
|
393
|
+
runMatches: (raw.runId ?? raw.id) === id,
|
|
394
|
+
runnerProcessInstanceId: typeof raw.runnerProcessInstanceId === "string" && /^[a-zA-Z0-9:-]{1,128}$/.test(raw.runnerProcessInstanceId) ? raw.runnerProcessInstanceId : undefined,
|
|
395
|
+
state: known(raw.state, ["pending", "running", "complete", "failed", "cancelled", "observed", "unknown", "not-started"]),
|
|
396
|
+
reason: known(raw.reason, ["observer-unavailable", "runner-candidate-missing", "runner-instance-mismatch", "writer-close-unverified", "process-tree-unverified", "canonical-session-unavailable", "canonical-session-lease-active", "canonical-session-release-unverified", "proof-write-failed", "stale-repair"]),
|
|
397
|
+
pid: number(raw.pid), ts: number(raw.ts), timestamp: number(raw.timestamp),
|
|
398
|
+
startedAt: number(raw.startedAt), endedAt: number(raw.endedAt), observedAt: number(raw.observedAt),
|
|
399
|
+
exitCode: number(raw.exitCode), success: typeof raw.success === "boolean" ? raw.success : undefined,
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
const marks: Record<string, number | boolean> = {};
|
|
403
|
+
const notifications: unknown[] = [];
|
|
404
|
+
const processes: Array<{ proc: ChildProcess; events: unknown[]; dispose: () => void }> = [];
|
|
405
|
+
let pid: number | undefined;
|
|
406
|
+
let reported = false;
|
|
407
|
+
let signalZero: { at: number; state: string } | undefined;
|
|
408
|
+
const diagnosticChannel = channel("child_process");
|
|
409
|
+
const onProcess = (message: unknown) => {
|
|
410
|
+
const proc = record(message).process;
|
|
411
|
+
if (!(proc instanceof ChildProcess) || processes.length >= 8) return;
|
|
412
|
+
const events: unknown[] = [];
|
|
413
|
+
const add = (type: string, code?: unknown, signal?: unknown) => events.push({ type, at: Date.now(), pid: proc.pid, code: number(code) ?? (code === null ? null : undefined), signal: known(signal, ["SIGTERM", "SIGKILL", "SIGINT", "SIGABRT", "SIGSEGV"]) });
|
|
414
|
+
const spawn = () => add("spawn");
|
|
415
|
+
const error = (err: Error) => events.push({ type: "error", at: Date.now(), code: errorCode(err) });
|
|
416
|
+
const exit = (code: number | null, signal: NodeJS.Signals | null) => add("exit", code, signal);
|
|
417
|
+
const close = (code: number | null, signal: NodeJS.Signals | null) => add("close", code, signal);
|
|
418
|
+
proc.once("spawn", spawn).once("error", error).once("exit", exit).once("close", close);
|
|
419
|
+
processes.push({ proc, events, dispose: () => { proc.off("spawn", spawn).off("error", error).off("exit", exit).off("close", close); } });
|
|
420
|
+
};
|
|
421
|
+
return {
|
|
422
|
+
marks,
|
|
423
|
+
emit(type: string, value: unknown) {
|
|
424
|
+
const raw = record(value);
|
|
425
|
+
if (type === "subagent:async-started" && raw.id === id) pid = number(raw.pid);
|
|
426
|
+
else if (type !== "subagent:process-terminal" || raw.runId !== id) return;
|
|
427
|
+
if (notifications.length < 8) notifications.push({ type, at: Date.now(), ...project(raw) });
|
|
428
|
+
},
|
|
429
|
+
launch(run: () => AsyncExecutionResult) {
|
|
430
|
+
diagnosticChannel.subscribe(onProcess);
|
|
431
|
+
try {
|
|
432
|
+
const receipt = run();
|
|
433
|
+
marks.launchReturnedAt = Date.now();
|
|
434
|
+
marks.launchIsError = receipt.isError === true;
|
|
435
|
+
marks.launchIdMatches = receipt.details.asyncId === id;
|
|
436
|
+
return receipt;
|
|
437
|
+
} finally {
|
|
438
|
+
diagnosticChannel.unsubscribe(onProcess);
|
|
439
|
+
for (const entry of processes) if (pid === undefined || entry.proc.pid !== pid) entry.dispose();
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
summary() {
|
|
443
|
+
const matched = processes.filter(({ proc }) => pid !== undefined && proc.pid === pid);
|
|
444
|
+
return { id, pid, marks, notifications, capturedProcesses: processes.length, correlatedProcesses: matched.length, processEvents: matched.map(({ events }) => events) };
|
|
445
|
+
},
|
|
446
|
+
// One bounded read per known file, only after failure. No arbitrary text escapes.
|
|
447
|
+
snapshot() {
|
|
448
|
+
const snapshotAt = Date.now();
|
|
449
|
+
const matched = processes.filter(({ proc }) => pid !== undefined && proc.pid === pid);
|
|
450
|
+
const processState = matched.map(({ proc }) => ({
|
|
451
|
+
exitCode: proc.exitCode,
|
|
452
|
+
signalCode: proc.signalCode === null ? null : known(proc.signalCode, ["SIGTERM", "SIGKILL", "SIGINT", "SIGABRT", "SIGSEGV"]) ?? "other",
|
|
453
|
+
}));
|
|
454
|
+
// PID presence is not identity or cleanup authority. Probe at most once.
|
|
455
|
+
if (!signalZero && matched.length === 1 && pid !== undefined) {
|
|
456
|
+
const at = Date.now();
|
|
457
|
+
try { process.kill(pid, 0); signalZero = { at, state: "present" }; }
|
|
458
|
+
catch (error) { signalZero = { at, state: known(record(error).code, ["ESRCH", "EPERM", "EACCES", "EINVAL"]) ?? "other" }; }
|
|
459
|
+
}
|
|
460
|
+
const files = ["process-terminal.json", "process-terminal-candidate.json", "status.json", "result", "events.jsonl", "runner.stdout.log", "runner.stderr.log"].map((name) => {
|
|
461
|
+
const file = name === "result" ? path.join(RESULTS_DIR, `${id}.json`) : path.join(ASYNC_DIR, id, name);
|
|
462
|
+
let fd: number | undefined;
|
|
463
|
+
const readAt = Date.now();
|
|
464
|
+
try {
|
|
465
|
+
fd = fs.openSync(file, "r");
|
|
466
|
+
const size = fs.fstatSync(fd).size;
|
|
467
|
+
const tail = name === "events.jsonl" || name.endsWith(".log");
|
|
468
|
+
const limit = name.endsWith(".log") ? 8192 : 65536;
|
|
469
|
+
if (!tail && size > limit) return { name, readAt, size, state: "oversized; not parsed" };
|
|
470
|
+
const offset = tail ? Math.max(0, size - limit) : 0;
|
|
471
|
+
const buffer = Buffer.alloc(Math.min(size, limit));
|
|
472
|
+
const text = buffer.subarray(0, fs.readSync(fd, buffer, 0, buffer.length, offset)).toString("utf-8");
|
|
473
|
+
const base = { name, readAt, size, truncated: offset > 0 };
|
|
474
|
+
if (name.endsWith(".log")) {
|
|
475
|
+
const phases = [];
|
|
476
|
+
for (const line of text.split("\n").slice(offset > 0 ? 1 : 0)) {
|
|
477
|
+
const match = /^#1906 phase=(dispose-entry|dispose-return|exit) invocation=(\d{1,16}) ts=(\d{1,16}) pid=(\d{1,16})$/.exec(line);
|
|
478
|
+
if (!match || matched.length !== 1) continue;
|
|
479
|
+
const [invocation, ts, markerPid] = match.slice(2).map(Number);
|
|
480
|
+
if (![invocation, ts, markerPid].every(Number.isSafeInteger) || markerPid !== pid || ts <= 0) continue;
|
|
481
|
+
if (match[1] === "exit" ? invocation !== 0 : invocation < 1) continue;
|
|
482
|
+
phases.push({ phase: match[1], invocation, ts, pid: markerPid });
|
|
483
|
+
}
|
|
484
|
+
return { ...base, markers: ["ENOENT", "EACCES", "EPERM", "EBUSY", "ENOSPC", "SyntaxError", "TypeError", "UnhandledPromiseRejection"].filter((marker) => text.includes(marker)), phases: phases.slice(-16) };
|
|
485
|
+
}
|
|
486
|
+
if (name === "events.jsonl") {
|
|
487
|
+
let parseErrors = 0;
|
|
488
|
+
const lifecycle = [];
|
|
489
|
+
for (const line of text.split("\n").slice(offset > 0 ? 1 : 0).filter(Boolean)) {
|
|
490
|
+
try {
|
|
491
|
+
const event = record(JSON.parse(line));
|
|
492
|
+
if (["subagent.run.started", "subagent.run.completed", "subagent.run.process_terminal"].includes(String(event.type))) lifecycle.push({ type: event.type, ...project(event), proof: project(event.processTerminal) });
|
|
493
|
+
} catch { parseErrors++; }
|
|
494
|
+
}
|
|
495
|
+
return { ...base, parseErrors, lifecycle: lifecycle.slice(-16), terminalPresentInRead: lifecycle.some((event) => event.type === "subagent.run.process_terminal") };
|
|
496
|
+
}
|
|
497
|
+
const raw = record(JSON.parse(text));
|
|
498
|
+
return { ...base, ...project(raw), proof: project(raw.processTerminal), writers: ["0", "1"].map((index) => ({ index, count: Array.isArray(record(raw.writers)[index]) ? (record(raw.writers)[index] as unknown[]).length : undefined, expected: number(record(raw.expectedWriters)[index]) })) };
|
|
499
|
+
} catch (error) { return { name, readAt, state: error instanceof SyntaxError ? "invalid-json" : errorCode(error) }; }
|
|
500
|
+
finally { if (fd !== undefined) fs.closeSync(fd); }
|
|
501
|
+
});
|
|
502
|
+
return { snapshotAt, finishedAt: Date.now(), waitElapsedMs: typeof marks.waitStartedAt === "number" ? snapshotAt - marks.waitStartedAt : undefined, processState, signalZero, files };
|
|
503
|
+
},
|
|
504
|
+
// Called only at the failing assertion boundary, before fixture cleanup.
|
|
505
|
+
reportFailure(diagnostic: (message: string) => void) {
|
|
506
|
+
if (reported) return;
|
|
507
|
+
reported = true;
|
|
508
|
+
let text: string;
|
|
509
|
+
try { text = JSON.stringify({ ...this.summary(), snapshot: this.snapshot() }); }
|
|
510
|
+
catch { diagnostic("#1906 failure snapshot unavailable (contents withheld)"); return; }
|
|
511
|
+
diagnostic(`#1906 ${text}`);
|
|
512
|
+
const directory = process.env.SELESAI_SUBAGENTS_TERMINAL_EVIDENCE_DIR;
|
|
513
|
+
if (!directory) return;
|
|
514
|
+
try {
|
|
515
|
+
// Persist only the existing allowlisted projection, never copy run files.
|
|
516
|
+
if (Buffer.byteLength(text) > 65536) throw new Error("snapshot exceeds bound");
|
|
517
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
518
|
+
fs.writeFileSync(path.join(directory, "shared-cwd-terminal.json"), text, { mode: 0o600 });
|
|
519
|
+
} catch { diagnostic("#1906 failure artifact unavailable (contents withheld)"); }
|
|
520
|
+
},
|
|
521
|
+
dispose() { for (const entry of processes) entry.dispose(); },
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
async function waitForAsyncEvent(id: string, type: string, timeoutMs = 10_000): Promise<Record<string, unknown>> {
|
|
526
|
+
const eventsPath = path.join(ASYNC_DIR, id, "events.jsonl");
|
|
527
|
+
const deadline = Date.now() + timeoutMs;
|
|
528
|
+
while (Date.now() <= deadline) {
|
|
529
|
+
const event = readIfExists(eventsPath)
|
|
530
|
+
?.split("\n")
|
|
531
|
+
.map((line) => JSON.parse(line) as Record<string, unknown>)
|
|
532
|
+
.find((candidate) => candidate.type === type);
|
|
533
|
+
if (event) return event;
|
|
534
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
535
|
+
}
|
|
536
|
+
assert.fail(`Timed out waiting for async event '${type}': ${eventsPath}`);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
async function waitForAsyncState(id: string, predicate: (status: AsyncStatusPayload) => boolean, timeoutMs = 10_000): Promise<AsyncStatusPayload> {
|
|
540
|
+
const statusPath = path.join(ASYNC_DIR, id, "status.json");
|
|
541
|
+
const deadline = Date.now() + timeoutMs;
|
|
542
|
+
let last: AsyncStatusPayload | undefined;
|
|
543
|
+
while (Date.now() <= deadline) {
|
|
544
|
+
if (fs.existsSync(statusPath)) {
|
|
545
|
+
const status = JSON.parse(fs.readFileSync(statusPath, "utf-8")) as AsyncStatusPayload;
|
|
546
|
+
last = status;
|
|
547
|
+
if (predicate(status)) return status;
|
|
548
|
+
}
|
|
549
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
550
|
+
}
|
|
551
|
+
assert.fail(`Timed out waiting for async status: ${statusPath} (last state: ${last?.state ?? "missing"}, error: ${last?.error ?? "none"}, step statuses: ${last?.steps?.map((step) => step.status).join(",") ?? "none"})`);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
async function waitForMockPiCall(mockPi: MockPi, index: number, timeoutMs = 30_000): Promise<{ args: string[]; systemPrompts: NonNullable<MockPiCallRecord["systemPrompts"]> }> {
|
|
555
|
+
const deadline = Date.now() + timeoutMs;
|
|
556
|
+
for (;;) {
|
|
557
|
+
const callFile = fs.readdirSync(mockPi.dir)
|
|
558
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
559
|
+
.sort()
|
|
560
|
+
.at(index);
|
|
561
|
+
if (callFile) {
|
|
562
|
+
const payload = JSON.parse(fs.readFileSync(path.join(mockPi.dir, callFile), "utf-8")) as MockPiCallRecord;
|
|
563
|
+
assert.ok(Array.isArray(payload.args), "expected recorded args");
|
|
564
|
+
return { args: resolveMockPiCallArgs(payload), systemPrompts: payload.systemPrompts ?? [] };
|
|
565
|
+
}
|
|
566
|
+
if (Date.now() > deadline) assert.fail(`Timed out waiting for recorded mock pi call ${index}`);
|
|
567
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
async function waitForMockPiArgs(mockPi: MockPi, index: number, timeoutMs = 30_000): Promise<string[]> {
|
|
572
|
+
return (await waitForMockPiCall(mockPi, index, timeoutMs)).args;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function readLastMockPiArgs(mockPi: MockPi): string[] {
|
|
576
|
+
const callFile = fs.readdirSync(mockPi.dir)
|
|
577
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
578
|
+
.sort()
|
|
579
|
+
.at(-1);
|
|
580
|
+
assert.ok(callFile, "expected a recorded mock pi call");
|
|
581
|
+
const payload = JSON.parse(fs.readFileSync(path.join(mockPi.dir, callFile), "utf-8")) as MockPiCallRecord;
|
|
582
|
+
assert.ok(Array.isArray(payload.args), "expected recorded args");
|
|
583
|
+
return resolveMockPiCallArgs(payload);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function readMockPiArgs(mockPi: MockPi, index: number): string[] {
|
|
587
|
+
const callFile = fs.readdirSync(mockPi.dir)
|
|
588
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
589
|
+
.sort()
|
|
590
|
+
.at(index);
|
|
591
|
+
assert.ok(callFile, `expected recorded call ${index}`);
|
|
592
|
+
const payload = JSON.parse(fs.readFileSync(path.join(mockPi.dir, callFile), "utf-8")) as MockPiCallRecord;
|
|
593
|
+
assert.ok(Array.isArray(payload.args), "expected recorded args");
|
|
594
|
+
return resolveMockPiCallArgs(payload);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function readMockPiRequiredTools(mockPi: MockPi, index: number): string[] {
|
|
598
|
+
const callFile = fs.readdirSync(mockPi.dir)
|
|
599
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
600
|
+
.sort()
|
|
601
|
+
.at(index);
|
|
602
|
+
assert.ok(callFile, `expected recorded call ${index}`);
|
|
603
|
+
const payload = JSON.parse(fs.readFileSync(path.join(mockPi.dir, callFile), "utf-8")) as MockPiCallRecord;
|
|
604
|
+
assert.ok(Array.isArray(payload.requiredChildTools), "expected recorded required child tools");
|
|
605
|
+
return payload.requiredChildTools;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function readMockPiArgsMatching(mockPi: MockPi, text: string): string[] {
|
|
609
|
+
const callFiles = fs.readdirSync(mockPi.dir)
|
|
610
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
611
|
+
.sort();
|
|
612
|
+
for (const callFile of callFiles) {
|
|
613
|
+
const payload = JSON.parse(fs.readFileSync(path.join(mockPi.dir, callFile), "utf-8")) as MockPiCallRecord;
|
|
614
|
+
assert.ok(Array.isArray(payload.args), "expected recorded args");
|
|
615
|
+
const args = resolveMockPiCallArgs(payload);
|
|
616
|
+
if (args.join("\n").includes(text)) return args;
|
|
617
|
+
}
|
|
618
|
+
assert.fail(`expected recorded call containing ${text}`);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Each physical suite installs these hooks inside its describe callback.
|
|
622
|
+
// Mutable bindings stay live and process-local under the default test isolation.
|
|
623
|
+
let tempDir: string;
|
|
624
|
+
let mockPi: MockPi;
|
|
625
|
+
|
|
626
|
+
export function installAsyncExecutionHooks(): void {
|
|
627
|
+
before(() => {
|
|
628
|
+
mockPi = createMockPi();
|
|
629
|
+
mockPi.install();
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
after(() => {
|
|
633
|
+
mockPi.uninstall();
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
beforeEach(() => {
|
|
637
|
+
tempDir = createTempDir();
|
|
638
|
+
mockPi.reset();
|
|
639
|
+
clearExclusions();
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
afterEach(() => {
|
|
643
|
+
clearExclusions();
|
|
644
|
+
removeTempDir(tempDir);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function makeAsyncExecutor(
|
|
649
|
+
agents: ReturnType<typeof makeAgent>[],
|
|
650
|
+
config: Record<string, unknown> = {},
|
|
651
|
+
discoverOverride?: (cwd: string) => { agents: ReturnType<typeof makeAgent>[]; cwd?: string; scope?: "user" | "project" | "both"; directories?: Array<{ source: "builtin" | "package" | "user" | "project" | "runtime"; path: string; state: "absent" | "empty" | "candidates" | "unreadable" | "not-directory"; candidateCount?: number }> },
|
|
652
|
+
) {
|
|
653
|
+
return createSubagentExecutor!({
|
|
654
|
+
pi: { events: createEventBus(), getSessionName: () => undefined },
|
|
655
|
+
state: { baseCwd: tempDir, currentSessionId: null, asyncJobs: new Map(), foregroundControls: new Map(), lastForegroundControlId: null },
|
|
656
|
+
config,
|
|
657
|
+
asyncByDefault: false,
|
|
658
|
+
tempArtifactsDir: tempDir,
|
|
659
|
+
getSubagentSessionRoot: () => tempDir,
|
|
660
|
+
expandTilde: (p: string) => p,
|
|
661
|
+
discoverAgents: (cwd: string) => discoverOverride ? discoverOverride(cwd) : ({ agents }),
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
async function readAsyncPayload(id: string): Promise<AsyncResultPayload> {
|
|
666
|
+
const resultPath = await waitForAsyncResultFile(id, 10_000);
|
|
667
|
+
return JSON.parse(fs.readFileSync(resultPath, "utf-8")) as AsyncResultPayload;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function launchProtocolTest(id: string): void {
|
|
671
|
+
const receipt = executeAsyncSingle(id, {
|
|
672
|
+
agent: "worker",
|
|
673
|
+
task: "Exercise child protocol",
|
|
674
|
+
agentConfig: makeAgent("worker", { completionGuard: false }),
|
|
675
|
+
ctx: { pi: { events: { emit() {} } }, cwd: tempDir, currentSessionId: "session-1" },
|
|
676
|
+
artifactConfig: { enabled: false, includeInput: false, includeOutput: false, includeJsonl: false, includeMetadata: false, cleanupDays: 7 },
|
|
677
|
+
shareEnabled: false,
|
|
678
|
+
sessionRoot: path.join(tempDir, "sessions"),
|
|
679
|
+
maxSubagentDepth: 2,
|
|
680
|
+
acceptance: false,
|
|
681
|
+
});
|
|
682
|
+
if (receipt.isError) console.error("DBG receipt:", JSON.stringify(receipt, null, 2));
|
|
683
|
+
assert.equal(receipt.isError === true, false, "protocol launch must succeed");
|
|
684
|
+
assert.equal(receipt.details.asyncId === id, true, "protocol launch must identify the requested run");
|
|
685
|
+
assert.equal(receipt.details.asyncDir === path.join(ASYNC_DIR, id), true, "protocol launch must identify the expected artifacts");
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
export type { AsyncExecutionResult, AsyncResultPayload, AsyncStatusPayload, MockPiCallRecord };
|
|
689
|
+
export {
|
|
690
|
+
available, isAsyncAvailable, executeAsyncSingle, executeAsyncChain,
|
|
691
|
+
resolveTargetedAsyncRun, readStatus, pruneStatusCacheForAsyncRoot,
|
|
692
|
+
ASYNC_DIR, RESULTS_DIR, TEMP_ROOT_DIR, createSubagentExecutor,
|
|
693
|
+
tempDir, mockPi, makeAsyncExecutor, readAsyncPayload, launchProtocolTest,
|
|
694
|
+
waitForMockPiRuntime, writeWatchdogSettings, withIsolatedWatchdogSettings,
|
|
695
|
+
childWatchdogStatus, mockAssistantMessage, escapeRegExp, createRepo,
|
|
696
|
+
writePackageSkill, readIfExists, waitForAsyncResultFile, waitForAsyncEvent,
|
|
697
|
+
waitForAsyncState, waitForMockPiCall, readLastMockPiArgs,
|
|
698
|
+
readMockPiArgs, readMockPiRequiredTools, readMockPiArgsMatching,
|
|
699
|
+
};
|