@selesai/code 0.13.15 → 0.13.18
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 +37 -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/capability-gateway/index.ts +12 -1
- package/dist/extensions/capability-gateway/integration.test.ts +23 -0
- 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/src/backends/config.ts +1 -0
- package/dist/extensions/pi-web-agent/src/backends/settings-reader.ts +5 -3
- package/dist/extensions/pi-web-agent/src/search/tokenin.ts +7 -3
- package/dist/extensions/pi-web-agent/src/types.ts +1 -1
- 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 +4 -4
- 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/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,70 @@
|
|
|
1
|
+
// Child-runner-only fault injection. Barriers are filesystem events, not elapsed waits.
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
5
|
+
|
|
6
|
+
const root = process.env.RESULT_PUBLICATION_TEST_ROOT;
|
|
7
|
+
if (root) {
|
|
8
|
+
const write = fs.writeFileSync;
|
|
9
|
+
const rename = fs.renameSync;
|
|
10
|
+
let resultAttempts = 0;
|
|
11
|
+
let runningWritten = false;
|
|
12
|
+
let statusDeferred = false;
|
|
13
|
+
let asyncDir;
|
|
14
|
+
let failedRecovery = false;
|
|
15
|
+
const earlyTerminal = fs.existsSync(path.join(root, "early-terminal"));
|
|
16
|
+
const barrier = (name, data) => {
|
|
17
|
+
write(path.join(root, `${name}.tmp`), JSON.stringify(data));
|
|
18
|
+
rename(path.join(root, `${name}.tmp`), path.join(root, name));
|
|
19
|
+
};
|
|
20
|
+
const full = () => Object.assign(new Error("injected result publication capacity failure"), { code: "ENOSPC" });
|
|
21
|
+
fs.writeFileSync = function (file, data, ...args) {
|
|
22
|
+
const target = String(file);
|
|
23
|
+
if (path.basename(target).startsWith(".status.json.") && typeof data === "string") {
|
|
24
|
+
const status = JSON.parse(data);
|
|
25
|
+
asyncDir = path.dirname(target);
|
|
26
|
+
if (!earlyTerminal && runningWritten && resultAttempts === 0) {
|
|
27
|
+
statusDeferred = true;
|
|
28
|
+
throw full();
|
|
29
|
+
}
|
|
30
|
+
if (status.state === "running") runningWritten = true;
|
|
31
|
+
}
|
|
32
|
+
if (target.includes(`${path.sep}result-pending${path.sep}`) && target.endsWith(".tmp")) {
|
|
33
|
+
resultAttempts++;
|
|
34
|
+
if (!fs.existsSync(path.join(root, "release"))) {
|
|
35
|
+
if (resultAttempts >= 2) {
|
|
36
|
+
const status = JSON.parse(fs.readFileSync(path.join(asyncDir, "status.json"), "utf8"));
|
|
37
|
+
barrier("blocked.json", {
|
|
38
|
+
state: status.state, statusDeferred,
|
|
39
|
+
active: fs.existsSync(path.join(path.dirname(asyncDir), ".active-runs", path.basename(asyncDir))),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
throw full();
|
|
43
|
+
}
|
|
44
|
+
if (!failedRecovery && fs.existsSync(path.join(root, "fail-on-recovery"))) {
|
|
45
|
+
failedRecovery = true;
|
|
46
|
+
throw Object.assign(new Error("injected non-capacity publication failure"), { code: "EIO" });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return write.call(this, file, data, ...args);
|
|
50
|
+
};
|
|
51
|
+
fs.renameSync = function (source, target) {
|
|
52
|
+
const result = rename.call(this, source, target);
|
|
53
|
+
if (!earlyTerminal && path.basename(String(target)) === "steer-inbox-closed.json") {
|
|
54
|
+
// A request queued just before inbox closure is consumed during finalization.
|
|
55
|
+
const dir = path.join(path.dirname(String(target)), "steer-requests");
|
|
56
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
write(path.join(dir, "publication-steer.json"), JSON.stringify({ type: "steer", id: "publication-steer", ts: 1, message: "Late queued request", targetIndex: 0 }));
|
|
58
|
+
}
|
|
59
|
+
if (path.basename(String(target)) === "status.json") {
|
|
60
|
+
const status = JSON.parse(fs.readFileSync(target, "utf8"));
|
|
61
|
+
if (status.state === "complete" || status.state === "failed") barrier("terminal.json", status);
|
|
62
|
+
}
|
|
63
|
+
if (earlyTerminal && path.basename(String(target)) === "process-terminal-candidate.json") {
|
|
64
|
+
const candidate = JSON.parse(fs.readFileSync(target, "utf8"));
|
|
65
|
+
if (candidate.expectedWriters) barrier("drained.json", candidate);
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
syncBuiltinESMExports();
|
|
70
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripted `ChildSessionFactory` for the detached async runner under test.
|
|
3
|
+
*
|
|
4
|
+
* The runner is a separate Node process, so it cannot share the parent's
|
|
5
|
+
* in-memory fake. `createMockPi().install()` names this module in the runner
|
|
6
|
+
* config; the runner imports it and replays the responses queued in the
|
|
7
|
+
* directory `MOCK_PI_QUEUE_DIR` points at.
|
|
8
|
+
*/
|
|
9
|
+
import { createFakeChildSessions } from "./fake-child-session.ts";
|
|
10
|
+
|
|
11
|
+
export default function createRunnerChildSessionFactory() {
|
|
12
|
+
return createFakeChildSessions(() => {
|
|
13
|
+
const dir = process.env.MOCK_PI_QUEUE_DIR;
|
|
14
|
+
if (!dir) throw new Error("MOCK_PI_QUEUE_DIR is required for the scripted runner child session factory.");
|
|
15
|
+
return dir;
|
|
16
|
+
}).factory;
|
|
17
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for single (sync) agent execution.
|
|
3
|
+
*
|
|
4
|
+
* Uses the local createMockPi() helper to simulate the pi CLI.
|
|
5
|
+
* Tests the full spawn→parse→result pipeline in runSync without a real LLM.
|
|
6
|
+
*
|
|
7
|
+
* These tests require pi packages to be importable (they run inside a pi
|
|
8
|
+
* environment or with pi packages installed). If unavailable, tests skip
|
|
9
|
+
* gracefully.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { before, after, beforeEach, afterEach } from "node:test";
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import type { MockPi } from "./helpers.ts";
|
|
17
|
+
import {
|
|
18
|
+
createMockPi,
|
|
19
|
+
createTempDir,
|
|
20
|
+
createEventBus,
|
|
21
|
+
removeTempDir,
|
|
22
|
+
makeAgentConfigs,
|
|
23
|
+
makeAgent,
|
|
24
|
+
resolveMockPiCallArgs,
|
|
25
|
+
tryImport,
|
|
26
|
+
} from "./helpers.ts";
|
|
27
|
+
import type { ChildWatchdogProgress, SubagentState } from "../../src/shared/types.ts";
|
|
28
|
+
import { CHILD_WATCHDOG_STATUS_EVENT } from "../../src/watchdog/child-status.ts";
|
|
29
|
+
import type { ChildRuntimeConfig } from "../../src/runs/shared/child-runtime-config.ts";
|
|
30
|
+
import { clearExclusions } from "../../src/runs/shared/model-exclusions.ts";
|
|
31
|
+
|
|
32
|
+
interface ModelAttempt {
|
|
33
|
+
success?: boolean;
|
|
34
|
+
exitCode?: number;
|
|
35
|
+
error?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ProgressSummary {
|
|
39
|
+
agent: string;
|
|
40
|
+
index: number;
|
|
41
|
+
status: string;
|
|
42
|
+
task?: string;
|
|
43
|
+
activityState?: string;
|
|
44
|
+
lastActivityAt?: number;
|
|
45
|
+
currentTool?: string;
|
|
46
|
+
currentToolArgs?: string;
|
|
47
|
+
currentToolStartedAt?: number;
|
|
48
|
+
currentPath?: string;
|
|
49
|
+
turnCount?: number;
|
|
50
|
+
tokens?: number;
|
|
51
|
+
durationMs: number;
|
|
52
|
+
toolCount: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ArtifactPaths {
|
|
56
|
+
inputPath?: string;
|
|
57
|
+
outputPath: string;
|
|
58
|
+
transcriptPath?: string;
|
|
59
|
+
metadataPath?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface LaunchResolvedExtensions {
|
|
63
|
+
version?: number;
|
|
64
|
+
source?: string;
|
|
65
|
+
disableAmbientExtensions?: boolean;
|
|
66
|
+
runtime?: string[];
|
|
67
|
+
configured?: string[];
|
|
68
|
+
effective?: string[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface RuntimeAcknowledgedExtensions {
|
|
72
|
+
version?: number;
|
|
73
|
+
source?: string;
|
|
74
|
+
ids?: string[];
|
|
75
|
+
omitted?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface RunSyncResult {
|
|
79
|
+
exitCode: number;
|
|
80
|
+
agent: string;
|
|
81
|
+
task?: string;
|
|
82
|
+
messages: unknown[];
|
|
83
|
+
error?: string;
|
|
84
|
+
model?: string;
|
|
85
|
+
skills?: string[];
|
|
86
|
+
skillsWarning?: string;
|
|
87
|
+
attemptedModels?: string[];
|
|
88
|
+
modelAttempts?: ModelAttempt[];
|
|
89
|
+
contextOverflow?: boolean;
|
|
90
|
+
usage: { turns: number; input: number; output: number };
|
|
91
|
+
progress: ProgressSummary;
|
|
92
|
+
controlEvents?: Array<{ type?: string; message: string; reason?: string; turns?: number; tokens?: number; currentPath?: string; recentFailureSummary?: string }>;
|
|
93
|
+
artifactPaths?: ArtifactPaths;
|
|
94
|
+
transcriptPath?: string;
|
|
95
|
+
transcriptError?: string;
|
|
96
|
+
finalOutput?: string;
|
|
97
|
+
processSignal?: string | null;
|
|
98
|
+
interrupted?: boolean;
|
|
99
|
+
timedOut?: boolean;
|
|
100
|
+
timeoutRecovery?: { changedFiles?: string[]; message?: string; recoveryNeeded?: boolean; reason?: string; reportStatus?: string };
|
|
101
|
+
turnBudget?: { maxTurns: number; graceTurns: number; outcome: string; turnCount: number; wrapUpRequestedAtTurn?: number; exceededAtTurn?: number };
|
|
102
|
+
turnBudgetExceeded?: boolean;
|
|
103
|
+
wrapUpRequested?: boolean;
|
|
104
|
+
detached?: boolean;
|
|
105
|
+
detachedReason?: string;
|
|
106
|
+
savedOutputPath?: string;
|
|
107
|
+
outputMode?: "inline" | "file-only";
|
|
108
|
+
outputReference?: { path: string; bytes: number; lines: number; message: string };
|
|
109
|
+
outputSaveError?: string;
|
|
110
|
+
sessionFile?: string;
|
|
111
|
+
structuredOutput?: unknown;
|
|
112
|
+
agentContract?: { version: 1 };
|
|
113
|
+
execution?: { status?: string; success?: boolean; exitCode?: number; error?: string };
|
|
114
|
+
review?: { status?: string };
|
|
115
|
+
effects?: { fileMutation?: { status?: string; expected?: boolean; attempted?: boolean; message?: string } };
|
|
116
|
+
acceptance?: {
|
|
117
|
+
status?: string;
|
|
118
|
+
verifyRuns?: Array<{ status?: string }>;
|
|
119
|
+
runtimeChecks?: Array<{ id?: string; status?: string; message?: string }>;
|
|
120
|
+
};
|
|
121
|
+
watchdog?: ChildWatchdogProgress;
|
|
122
|
+
launchResolvedExtensions?: LaunchResolvedExtensions;
|
|
123
|
+
runtimeAcknowledgedExtensions?: RuntimeAcknowledgedExtensions;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface MockPiCallRecord {
|
|
127
|
+
args?: string[];
|
|
128
|
+
effectiveArgs?: string[];
|
|
129
|
+
cwd?: string;
|
|
130
|
+
systemPrompts?: Array<{ mode?: string; path?: string; text?: string; error?: string }>;
|
|
131
|
+
/** In-process child session launch (foreground children). */
|
|
132
|
+
launch?: { cwd: string; storage: { kind: string; sessionFile?: string; sessionDir?: string }; model?: string; tools?: string[]; excludeTools?: string[]; extensionPaths: string[]; hooks: string[]; noSkills: boolean; noContextFiles: boolean };
|
|
133
|
+
/** Typed child runtime config the in-process hooks received. */
|
|
134
|
+
runtime?: Record<string, unknown> & { sessionName?: string; intercomSessionName?: string; orchestratorTarget?: string; runId?: string; agent?: string; childIndex?: number; fanoutChild?: boolean; nestedParent?: { parentRunId: string; parentChildIndex?: number; depth: number }; depth?: number; maxDepth?: number; waitTool?: { enabled: boolean }; inheritProjectContext?: boolean; inheritSkills?: boolean; toolBudget?: unknown };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function writeWatchdogSettings(projectDir: string, tailMs = 120_000): void {
|
|
138
|
+
const settingsPath = path.join(projectDir, ".selesai", "settings.json");
|
|
139
|
+
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
|
|
140
|
+
fs.writeFileSync(settingsPath, JSON.stringify({
|
|
141
|
+
subagents: {
|
|
142
|
+
watchdog: {
|
|
143
|
+
enabled: true,
|
|
144
|
+
children: {
|
|
145
|
+
enabled: true,
|
|
146
|
+
watchdogTailTimeoutMs: tailMs,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
}, null, 2), "utf-8");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function withIsolatedWatchdogSettings<T>(projectDir: string, run: () => Promise<T>): Promise<T> {
|
|
154
|
+
const previousAgentDir = process.env.SELESAI_CODING_AGENT_DIR;
|
|
155
|
+
const previousHome = process.env.HOME;
|
|
156
|
+
const previousUserProfile = process.env.USERPROFILE;
|
|
157
|
+
const isolatedHome = path.join(projectDir, "isolated-home");
|
|
158
|
+
process.env.SELESAI_CODING_AGENT_DIR = path.join(isolatedHome, ".selesai", "agent");
|
|
159
|
+
process.env.HOME = isolatedHome;
|
|
160
|
+
process.env.USERPROFILE = isolatedHome;
|
|
161
|
+
try {
|
|
162
|
+
return await run();
|
|
163
|
+
} finally {
|
|
164
|
+
if (previousAgentDir === undefined) delete process.env.SELESAI_CODING_AGENT_DIR;
|
|
165
|
+
else process.env.SELESAI_CODING_AGENT_DIR = previousAgentDir;
|
|
166
|
+
if (previousHome === undefined) delete process.env.HOME;
|
|
167
|
+
else process.env.HOME = previousHome;
|
|
168
|
+
if (previousUserProfile === undefined) delete process.env.USERPROFILE;
|
|
169
|
+
else process.env.USERPROFILE = previousUserProfile;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function childWatchdogStatus(phase: "idle" | "reviewing" | "stale" | "failed", seq: number) {
|
|
174
|
+
return {
|
|
175
|
+
type: CHILD_WATCHDOG_STATUS_EVENT,
|
|
176
|
+
runId: "watchdog-child-run",
|
|
177
|
+
agent: "echo",
|
|
178
|
+
childIndex: 0,
|
|
179
|
+
stepIndex: 0,
|
|
180
|
+
seq,
|
|
181
|
+
phase,
|
|
182
|
+
ts: Date.now() + seq,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function mockAssistantMessage(text: string, stopReason: "stop" | "tool_use" = "stop") {
|
|
187
|
+
return {
|
|
188
|
+
type: "message_end",
|
|
189
|
+
message: {
|
|
190
|
+
role: "assistant",
|
|
191
|
+
content: stopReason === "tool_use"
|
|
192
|
+
? [{ type: "text", text }, { type: "toolCall", name: "bash", arguments: { command: "echo test" } }]
|
|
193
|
+
: [{ type: "text", text }],
|
|
194
|
+
model: "mock/test-model",
|
|
195
|
+
stopReason,
|
|
196
|
+
usage: {
|
|
197
|
+
input: 10,
|
|
198
|
+
output: 5,
|
|
199
|
+
cacheRead: 0,
|
|
200
|
+
cacheWrite: 0,
|
|
201
|
+
cost: { total: 0.001 },
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
interface ExecutionModule {
|
|
208
|
+
runSync(
|
|
209
|
+
runtimeCwd: string,
|
|
210
|
+
agents: ReturnType<typeof makeAgentConfigs>,
|
|
211
|
+
agentName: string,
|
|
212
|
+
task: string,
|
|
213
|
+
options: Record<string, unknown>,
|
|
214
|
+
): Promise<RunSyncResult>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface UtilsModule {
|
|
218
|
+
getFinalOutput(messages: unknown[]): string;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface ExecutorToolResult {
|
|
222
|
+
content: Array<{ text?: string }>;
|
|
223
|
+
isError?: boolean;
|
|
224
|
+
details?: {
|
|
225
|
+
totalCost?: { inputTokens: number; outputTokens: number; costUsd: number };
|
|
226
|
+
controlEvents?: Array<{ type?: string }>;
|
|
227
|
+
asyncId?: string;
|
|
228
|
+
timeoutMs?: number;
|
|
229
|
+
turnBudget?: { maxTurns: number; graceTurns: number };
|
|
230
|
+
artifacts?: { dir: string; files: ArtifactPaths[] };
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
interface ExecutorModule {
|
|
235
|
+
createSubagentExecutor?: (...args: unknown[]) => {
|
|
236
|
+
execute: (...args: unknown[]) => Promise<ExecutorToolResult>;
|
|
237
|
+
executeDelegated: (...args: unknown[]) => Promise<ExecutorToolResult>;
|
|
238
|
+
};
|
|
239
|
+
DEFAULT_FOREGROUND_TIMEOUT_MS?: number;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const execution = await tryImport<ExecutionModule>("./src/runs/foreground/execution.ts");
|
|
243
|
+
const utils = await tryImport<UtilsModule>("./src/shared/utils.ts");
|
|
244
|
+
const executorMod = await tryImport<ExecutorModule>("./src/runs/foreground/subagent-executor.ts");
|
|
245
|
+
const available = !!(execution && utils);
|
|
246
|
+
|
|
247
|
+
const runSync = execution?.runSync;
|
|
248
|
+
const getFinalOutput = utils?.getFinalOutput;
|
|
249
|
+
const createSubagentExecutor = executorMod?.createSubagentExecutor;
|
|
250
|
+
|
|
251
|
+
function escapeRegExp(value: string): string {
|
|
252
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function pathContainsSegments(filePath: string, ...segments: string[]): boolean {
|
|
256
|
+
return segments.every((segment) => filePath.split(path.sep).includes(segment));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function waitForFileContent(filePath: string, expected: string): Promise<string> {
|
|
260
|
+
for (let attempt = 0; attempt < 300; attempt++) {
|
|
261
|
+
if (fs.existsSync(filePath)) {
|
|
262
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
263
|
+
if (content.includes(expected)) return content;
|
|
264
|
+
}
|
|
265
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
266
|
+
}
|
|
267
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function writePackageSkill(packageRoot: string, skillName: string): void {
|
|
271
|
+
const skillDir = path.join(packageRoot, "skills", skillName);
|
|
272
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
273
|
+
fs.writeFileSync(
|
|
274
|
+
path.join(packageRoot, "package.json"),
|
|
275
|
+
JSON.stringify({ name: `${skillName}-pkg`, version: "1.0.0", pi: { skills: [`./skills/${skillName}`] } }, null, 2),
|
|
276
|
+
"utf-8",
|
|
277
|
+
);
|
|
278
|
+
fs.writeFileSync(
|
|
279
|
+
path.join(skillDir, "SKILL.md"),
|
|
280
|
+
`---\nname: ${skillName}\ndescription: test skill\n---\nbody\n`,
|
|
281
|
+
"utf-8",
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let tempDir: string;
|
|
286
|
+
let agentDir: string;
|
|
287
|
+
let mockPi: MockPi;
|
|
288
|
+
let previousAgentDir: string | undefined;
|
|
289
|
+
|
|
290
|
+
export function installSingleExecutionHooks() {
|
|
291
|
+
before(() => {
|
|
292
|
+
mockPi = createMockPi();
|
|
293
|
+
mockPi.install();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
after(() => {
|
|
297
|
+
mockPi.uninstall();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
beforeEach(() => {
|
|
301
|
+
tempDir = createTempDir();
|
|
302
|
+
agentDir = createTempDir("pi-subagent-agent-");
|
|
303
|
+
previousAgentDir = process.env.SELESAI_CODING_AGENT_DIR;
|
|
304
|
+
process.env.SELESAI_CODING_AGENT_DIR = agentDir;
|
|
305
|
+
mockPi.reset();
|
|
306
|
+
clearExclusions();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
afterEach(() => {
|
|
310
|
+
clearExclusions();
|
|
311
|
+
if (previousAgentDir === undefined) delete process.env.SELESAI_CODING_AGENT_DIR;
|
|
312
|
+
else process.env.SELESAI_CODING_AGENT_DIR = previousAgentDir;
|
|
313
|
+
removeTempDir(agentDir);
|
|
314
|
+
removeTempDir(tempDir);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function readCall(): { args: string[]; effectiveArgs?: string[]; cwd?: string; systemPrompts: NonNullable<MockPiCallRecord["systemPrompts"]>; launch: MockPiCallRecord["launch"]; runtime: MockPiCallRecord["runtime"] } {
|
|
319
|
+
const callFile = fs.readdirSync(mockPi.dir)
|
|
320
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
321
|
+
.sort()
|
|
322
|
+
.at(-1);
|
|
323
|
+
assert.ok(callFile, "expected a recorded mock pi call");
|
|
324
|
+
const payload = JSON.parse(fs.readFileSync(path.join(mockPi.dir, callFile), "utf-8")) as MockPiCallRecord;
|
|
325
|
+
assert.ok(Array.isArray(payload.args), "expected recorded args");
|
|
326
|
+
return { args: payload.args, effectiveArgs: payload.effectiveArgs, cwd: payload.cwd, systemPrompts: payload.systemPrompts ?? [], launch: payload.launch, runtime: payload.runtime };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function readCallArgs(): string[] {
|
|
330
|
+
const call = readCall();
|
|
331
|
+
return resolveMockPiCallArgs(call);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function readAllCallArgs(effective = false): string[][] {
|
|
335
|
+
return fs.readdirSync(mockPi.dir)
|
|
336
|
+
.filter((name) => name.startsWith("call-") && name.endsWith(".json"))
|
|
337
|
+
.sort()
|
|
338
|
+
.map((name) => {
|
|
339
|
+
const call = JSON.parse(fs.readFileSync(path.join(mockPi.dir, name), "utf-8")) as MockPiCallRecord;
|
|
340
|
+
return effective ? resolveMockPiCallArgs(call) : call.args ?? [];
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function makeExecutor(
|
|
345
|
+
agents = [makeAgent("echo")],
|
|
346
|
+
config: Record<string, unknown> = {},
|
|
347
|
+
asyncByDefault = false,
|
|
348
|
+
initialSpawnState?: NonNullable<SubagentState["subagentSpawns"]>,
|
|
349
|
+
allowMutatingManagementActions = true,
|
|
350
|
+
initialAsyncJobs: SubagentState["asyncJobs"] = new Map(),
|
|
351
|
+
workflowControllers?: Map<string, AbortController>,
|
|
352
|
+
handleScheduledRunAction?: Parameters<typeof createSubagentExecutor>[0]["handleScheduledRunAction"],
|
|
353
|
+
piEvents = createEventBus(),
|
|
354
|
+
discoverAgentsForCwd?: (cwd: string) => typeof agents,
|
|
355
|
+
childRuntime?: ChildRuntimeConfig,
|
|
356
|
+
) {
|
|
357
|
+
return createSubagentExecutor!({
|
|
358
|
+
pi: { events: piEvents, getSessionName: () => undefined },
|
|
359
|
+
...(childRuntime ? { childRuntime } : {}),
|
|
360
|
+
state: {
|
|
361
|
+
baseCwd: tempDir,
|
|
362
|
+
currentSessionId: initialSpawnState?.sessionId ?? null,
|
|
363
|
+
...(initialSpawnState ? { subagentSpawns: initialSpawnState } : {}),
|
|
364
|
+
asyncJobs: initialAsyncJobs,
|
|
365
|
+
...(workflowControllers ? { workflowControllers } : {}),
|
|
366
|
+
foregroundControls: new Map(),
|
|
367
|
+
lastForegroundControlId: null,
|
|
368
|
+
},
|
|
369
|
+
config,
|
|
370
|
+
asyncByDefault,
|
|
371
|
+
tempArtifactsDir: tempDir,
|
|
372
|
+
getSubagentSessionRoot: () => path.join(tempDir, ".pi-subagents", "sessions"),
|
|
373
|
+
expandTilde: (value: string) => value,
|
|
374
|
+
discoverAgents: (cwd: string) => ({ agents: discoverAgentsForCwd ? discoverAgentsForCwd(cwd) : agents }),
|
|
375
|
+
allowMutatingManagementActions,
|
|
376
|
+
...(handleScheduledRunAction ? { handleScheduledRunAction } : {}),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export {
|
|
381
|
+
tempDir, agentDir, mockPi, available, runSync, getFinalOutput, utils,
|
|
382
|
+
createSubagentExecutor, executorMod, escapeRegExp, pathContainsSegments,
|
|
383
|
+
waitForFileContent, writePackageSkill, writeWatchdogSettings,
|
|
384
|
+
withIsolatedWatchdogSettings, childWatchdogStatus, mockAssistantMessage,
|
|
385
|
+
readCall, readCallArgs, readAllCallArgs, makeExecutor,
|
|
386
|
+
};
|
|
387
|
+
export type {
|
|
388
|
+
ProgressSummary, ArtifactPaths, LaunchResolvedExtensions,
|
|
389
|
+
RuntimeAcknowledgedExtensions, RunSyncResult, ExecutorToolResult,
|
|
390
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { it } from "node:test";
|
|
7
|
+
import type { AgentSessionEvent, SessionBeforeCompactEvent } from "@selesai/code";
|
|
8
|
+
import { createDefaultChildSessionFactory, type PiCodingAgentModule } from "../../src/runs/shared/child-session.ts";
|
|
9
|
+
import { runSync } from "../../src/runs/foreground/execution.ts";
|
|
10
|
+
import { runSingleStepInner } from "../../src/runs/background/subagent-runner.ts";
|
|
11
|
+
import { formatAcceptancePrompt, resolveEffectiveAcceptance } from "../../src/runs/shared/acceptance.ts";
|
|
12
|
+
import type { AgentConfig } from "../../src/agents/agents.ts";
|
|
13
|
+
import { createStructuredOutputRuntime } from "../../src/runs/shared/structured-output.ts";
|
|
14
|
+
|
|
15
|
+
// Uses the existing isolated SDK fixture; never install dependencies or call a provider.
|
|
16
|
+
const sdkRoot = process.env.SELESAI_SUBAGENTS_NATIVE_SDK;
|
|
17
|
+
for (const host of ["foreground", "runner"] as const) {
|
|
18
|
+
for (const [systemPromptMode, structured] of [["append", false], ["replace", false], ["append", true], ["replace", true]] as const) {
|
|
19
|
+
it(`exact acceptance survives actual SDK split-turn compaction: ${host}/${systemPromptMode}/${structured ? "structured" : "fenced"}`, { skip: !sdkRoot && "Set SELESAI_SUBAGENTS_NATIVE_SDK to the isolated 0.85.1 SDK root" }, async () => {
|
|
20
|
+
const entry = execFileSync(process.execPath, ["--input-type=module", "-e", "console.log(import.meta.resolve('@selesai/code'))"], { cwd: sdkRoot, encoding: "utf8" }).trim();
|
|
21
|
+
const pi: PiCodingAgentModule = await import(entry);
|
|
22
|
+
assert.equal(pi.VERSION, "0.85.1");
|
|
23
|
+
const cwd = mkdtempSync(join(tmpdir(), "acceptance-compaction-"));
|
|
24
|
+
const agentDir = join(cwd, "agent"); mkdirSync(agentDir);
|
|
25
|
+
const oldDir = process.env.SELESAI_CODING_AGENT_DIR;
|
|
26
|
+
const oldFetch = globalThis.fetch;
|
|
27
|
+
process.env.SELESAI_CODING_AGENT_DIR = agentDir;
|
|
28
|
+
writeFileSync(join(agentDir, "settings.json"), JSON.stringify({ retry: { enabled: false, provider: { maxRetries: 0 } }, compaction: { enabled: true, reserveTokens: 2048, keepRecentTokens: 32 } }));
|
|
29
|
+
writeFileSync(join(agentDir, "models.json"), JSON.stringify({ providers: { baseten: { baseUrl: "https://synthetic.invalid/v1", apiKey: "fixture-key", models: [{ id: "acceptance", name: "acceptance", api: "openai-completions", reasoning: false, input: ["text"], contextWindow: 128000, maxTokens: 512, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } }] } } }));
|
|
30
|
+
writeFileSync(join(cwd, "marker.txt"), "WORK_EVIDENCE");
|
|
31
|
+
const task = "UNIQUE_TASK read marker.txt once and report evidence.";
|
|
32
|
+
const explicit = { level: "checked" as const, criteria: [{ id: "read-marker", must: "Read the marker exactly once" }], evidence: ["commands-run" as const, "no-staged-files" as const] };
|
|
33
|
+
const acceptance = resolveEffectiveAcceptance({ explicit, task, agentName: "reader", mode: "single" });
|
|
34
|
+
const structuredOutput = structured ? createStructuredOutputRuntime({ type: "object", properties: { ok: { type: "boolean" } }, required: ["ok"] }, cwd, { acceptanceReport: "optional" }) : undefined;
|
|
35
|
+
const protocol = formatAcceptancePrompt(acceptance, { structuredOutput: structured });
|
|
36
|
+
const report = { criteriaSatisfied: [{ id: "read-marker", status: "satisfied", evidence: "WORK_EVIDENCE" }], changedFiles: [], testsAddedOrUpdated: [], residualRisks: ["none"], commandsRun: [{ command: "read marker.txt", result: "passed", summary: "WORK_EVIDENCE" }], noStagedFiles: true };
|
|
37
|
+
const requests: any[] = [];
|
|
38
|
+
const preparations: SessionBeforeCompactEvent["preparation"][] = [];
|
|
39
|
+
const events: AgentSessionEvent[] = [];
|
|
40
|
+
let prompts = 0;
|
|
41
|
+
let creates = 0;
|
|
42
|
+
let reads = 0;
|
|
43
|
+
let summaries = 0;
|
|
44
|
+
globalThis.fetch = async (input, init) => {
|
|
45
|
+
assert.equal(input instanceof Request ? input.url : String(input), "https://synthetic.invalid/v1/chat/completions");
|
|
46
|
+
const body = JSON.parse(String(init?.body)); requests.push(body);
|
|
47
|
+
assert.ok(requests.length <= 3, "no extra request or correction turn");
|
|
48
|
+
const summary = !body.tools?.length;
|
|
49
|
+
let delta: unknown;
|
|
50
|
+
let finish = "stop";
|
|
51
|
+
let tokens = 10;
|
|
52
|
+
if (summary) {
|
|
53
|
+
summaries++;
|
|
54
|
+
// Deliberately lossy model output: real SDK summary generation/rebuild remains intact.
|
|
55
|
+
delta = { content: "The marker was read. Finish the work." };
|
|
56
|
+
} else if (reads++ === 0) {
|
|
57
|
+
delta = { content: "Inspecting the marker for evidence. ".repeat(12), tool_calls: [{ index: 0, id: "read-once", type: "function", function: { name: "read", arguments: JSON.stringify({ path: "marker.txt" }) } }] };
|
|
58
|
+
finish = "tool_calls"; tokens = 127000;
|
|
59
|
+
} else {
|
|
60
|
+
const system = body.messages.filter((m: any) => m.role === "system" || m.role === "developer").map((m: any) => m.content).join("\n");
|
|
61
|
+
delta = { content: system.includes(protocol) ? `Completed.\n\`\`\`acceptance-report\n${JSON.stringify(report)}\n\`\`\`` : "Completed the read. Validation passed; no staged files." };
|
|
62
|
+
if (structured) {
|
|
63
|
+
delta = { tool_calls: [{ index: 0, id: "final-output", type: "function", function: { name: "structured_output", arguments: JSON.stringify({ value: { ok: true }, ...(system.includes(protocol) ? { acceptanceReport: report } : {}) }) } }] };
|
|
64
|
+
finish = "tool_calls";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const chunk = { id: "synthetic", object: "chat.completion.chunk", created: 1, model: "acceptance", choices: [{ index: 0, delta, finish_reason: finish }], usage: { prompt_tokens: tokens, completion_tokens: 1, total_tokens: tokens + 1 } };
|
|
68
|
+
return new Response(`data: ${JSON.stringify(chunk)}\n\ndata: [DONE]\n\n`, { headers: { "content-type": "text/event-stream" } });
|
|
69
|
+
};
|
|
70
|
+
const factory = createDefaultChildSessionFactory({ loadPiCodingAgent: async () => ({ ...pi, createAgentSession: async (options) => {
|
|
71
|
+
const result = await pi.createAgentSession(options);
|
|
72
|
+
assert.deepEqual(result.session.settingsManager.getCompactionSettings(), { enabled: true, reserveTokens: 2048, keepRecentTokens: 32 });
|
|
73
|
+
result.session.subscribe((event) => events.push(event));
|
|
74
|
+
return result;
|
|
75
|
+
} }) });
|
|
76
|
+
const observedFactory = { ...factory, async create(launch: Parameters<typeof factory.create>[0]) {
|
|
77
|
+
creates++;
|
|
78
|
+
const child = await factory.create({ ...launch, hooks: [...launch.hooks, (api) => {
|
|
79
|
+
api.on("session_before_compact", (event) => { preparations.push(event.preparation); });
|
|
80
|
+
}] });
|
|
81
|
+
const prompt = child.prompt.bind(child);
|
|
82
|
+
child.prompt = (text) => { prompts++; return prompt(text); };
|
|
83
|
+
return child;
|
|
84
|
+
} };
|
|
85
|
+
const agent: AgentConfig = { name: "reader", description: "Read marker", source: "project", filePath: join(cwd, "reader.md"), model: "baseten/acceptance", systemPrompt: "Read only.", systemPromptMode, inheritProjectContext: false, inheritGlobalContext: false, inheritSkills: false, tools: ["read"], extensions: [], allowNestedSubagents: false };
|
|
86
|
+
try {
|
|
87
|
+
const result = host === "foreground"
|
|
88
|
+
? await runSync(cwd, [agent], agent.name, task, { acceptance: explicit, structuredOutput, waitToolEnabled: false, childSessionFactory: observedFactory })
|
|
89
|
+
: await runSingleStepInner({ ...agent, agent: agent.name, task, context: "fresh", effectiveAcceptance: acceptance, structuredOutput, modelCandidates: [agent.model!], waitToolEnabled: false }, { cwd, id: "compact-runner", flatIndex: 0, flatStepCount: 1, previousOutput: "", placeholder: "{previous}", outputFile: join(cwd, "output.log"), sessionEnabled: false, childSessions: observedFactory });
|
|
90
|
+
assert.equal(result.exitCode, 0, `${result.error}; ${JSON.stringify(events.filter((e) => e.type.includes("compact") || (e.type === "message_end" && e.message.role === "assistant" && e.message.stopReason === "error")))}`);
|
|
91
|
+
assert.equal(result.acceptance?.status, "checked");
|
|
92
|
+
if (structured) assert.deepEqual(result.structuredOutput, { ok: true });
|
|
93
|
+
assert.equal(creates, 1); assert.equal(prompts, 1, "no replay or correction prompt");
|
|
94
|
+
assert.equal(summaries, 1);
|
|
95
|
+
assert.equal(preparations.length, 1);
|
|
96
|
+
assert.ok(preparations[0]);
|
|
97
|
+
assert.equal(preparations[0].isSplitTurn, true);
|
|
98
|
+
assert.ok(JSON.stringify(preparations[0].turnPrefixMessages).includes("UNIQUE_TASK"));
|
|
99
|
+
assert.equal(events.filter((e) => e.type === "tool_execution_end" && e.toolName === "read").length, 1);
|
|
100
|
+
assert.equal(events.filter((e) => e.type === "compaction_end" && e.result).length, 1);
|
|
101
|
+
assert.ok(events.some((e) => e.type === "compaction_end" && e.reason === "threshold" && e.willRetry === false));
|
|
102
|
+
const normal = requests.filter((r) => r.tools?.length);
|
|
103
|
+
assert.equal(normal.length, 2, "one tool request and one terminal request");
|
|
104
|
+
assert.ok(!JSON.stringify(normal[0].messages.filter((m: any) => m.role === "user")).includes("Acceptance Contract"), "protocol is moved, not duplicated into user history");
|
|
105
|
+
for (const request of normal) {
|
|
106
|
+
const system = request.messages.filter((m: any) => m.role === "system" || m.role === "developer").map((m: any) => m.content).join("\n");
|
|
107
|
+
assert.equal(system.split(protocol).length - 1, 1, "verbatim contract exactly once in durable resources");
|
|
108
|
+
}
|
|
109
|
+
const retained = JSON.stringify(normal[1].messages.filter((m: any) => m.role !== "system" && m.role !== "developer"));
|
|
110
|
+
assert.ok(!retained.includes("UNIQUE_TASK"), "actual SDK removed original user task");
|
|
111
|
+
assert.ok(!retained.includes("acceptance-report"), "lossy conversation no longer contains envelope");
|
|
112
|
+
assert.ok(retained.includes("WORK_EVIDENCE"), "tool evidence survives");
|
|
113
|
+
} finally {
|
|
114
|
+
await factory.dispose(); globalThis.fetch = oldFetch;
|
|
115
|
+
if (oldDir === undefined) delete process.env.SELESAI_CODING_AGENT_DIR; else process.env.SELESAI_CODING_AGENT_DIR = oldDir;
|
|
116
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -190,7 +190,7 @@ describe("acceptance gates", () => {
|
|
|
190
190
|
assert.equal(resolved.verify[0]?.id, "ok");
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
it("agent contract
|
|
193
|
+
it("agent contract disables inferred acceptance without changing current defaults", () => {
|
|
194
194
|
const current = resolveEffectiveAcceptance({ agentName: "worker", acceptanceRole: "writer", task: "Implement the fix", mode: "single", async: true });
|
|
195
195
|
assert.equal(current.level, "checked");
|
|
196
196
|
assert.equal(current.review && current.review !== false ? current.review.required : undefined, true);
|
|
@@ -204,7 +204,7 @@ describe("acceptance gates", () => {
|
|
|
204
204
|
}
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
-
it("agent contract
|
|
207
|
+
it("agent contract keeps explicit acceptance report-optional and verify-only", async () => {
|
|
208
208
|
const checked = resolveEffectiveAcceptance({
|
|
209
209
|
agentName: "worker",
|
|
210
210
|
task: "Implement the fix",
|
|
@@ -1220,6 +1220,17 @@ describe("acceptance gates", () => {
|
|
|
1220
1220
|
assert.match(errors.join("\n"), /acceptance\.review\.required/);
|
|
1221
1221
|
});
|
|
1222
1222
|
|
|
1223
|
+
it("rejects transport-permitted true acceptance before execution, including nested inputs", () => {
|
|
1224
|
+
const errors = validateExecutionAcceptance({
|
|
1225
|
+
acceptance: true,
|
|
1226
|
+
tasks: [{ acceptance: true }],
|
|
1227
|
+
chain: [{ acceptance: true }, { parallel: [{ acceptance: true }] }, { parallel: { acceptance: true } }],
|
|
1228
|
+
});
|
|
1229
|
+
const paths = ["acceptance", "tasks[0].acceptance", "chain[0].acceptance", "chain[1].parallel[0].acceptance", "chain[2].parallel.acceptance"];
|
|
1230
|
+
assert.equal(errors.length, paths.length);
|
|
1231
|
+
paths.forEach((path, index) => assert.ok(errors[index]?.startsWith(`${path} must be a string level, false, or an object.`)));
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1223
1234
|
it("requires outputSchema for explicit structured acceptance report mode", () => {
|
|
1224
1235
|
const schema = { type: "object" as const };
|
|
1225
1236
|
const errors = validateExecutionAcceptance({
|
|
@@ -1312,6 +1323,16 @@ describe("acceptance gates", () => {
|
|
|
1312
1323
|
const conflictingGate = normalizeGateAcceptance("npm test", "checked");
|
|
1313
1324
|
assert.equal(conflictingGate.ok, false);
|
|
1314
1325
|
assert.match(conflictingGate.error, /cannot be combined with acceptance/);
|
|
1326
|
+
assert.match(conflictingGate.error, /Both fields were present: gate="npm test" acceptance="checked"/);
|
|
1327
|
+
const oversizedAcceptance = normalizeGateAcceptance("npm test", { level: "checked", evidence: ["a".repeat(200)] });
|
|
1328
|
+
assert.equal(oversizedAcceptance.ok, false);
|
|
1329
|
+
assert.match(oversizedAcceptance.error || "", /Both fields were present/);
|
|
1330
|
+
assert.ok(!(oversizedAcceptance.error || "").includes("a".repeat(200)));
|
|
1331
|
+
const disabledAcceptance = normalizeGateAcceptance("npm test", false);
|
|
1332
|
+
assert.deepEqual(disabledAcceptance, {
|
|
1333
|
+
ok: true,
|
|
1334
|
+
acceptance: { level: "verified", verify: [{ id: "gate", command: "npm test" }] },
|
|
1335
|
+
});
|
|
1315
1336
|
});
|
|
1316
1337
|
|
|
1317
1338
|
it("keeps explicit acceptance.verify arrays as existing verified acceptance", async () => {
|
|
@@ -1553,4 +1574,4 @@ describe("quoteExecutableForShell", () => {
|
|
|
1553
1574
|
assert.equal(quoteExecutableForShell(command, "win32"), command);
|
|
1554
1575
|
}
|
|
1555
1576
|
});
|
|
1556
|
-
});
|
|
1577
|
+
});
|