@nubl/maestro 0.0.0 → 0.1.0
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/README.md +56 -3
- package/dist/config.json.example +30 -0
- package/dist/maestro/adapters/fake/fake-harness-adapter.d.ts +24 -0
- package/dist/maestro/adapters/fake/fake-harness-adapter.d.ts.map +1 -0
- package/dist/maestro/adapters/fake/fake-harness-adapter.js +210 -0
- package/dist/maestro/adapters/fake/fake-harness-adapter.js.map +1 -0
- package/dist/maestro/adapters/pi/accept-groups.d.ts +35 -0
- package/dist/maestro/adapters/pi/accept-groups.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/accept-groups.js +70 -0
- package/dist/maestro/adapters/pi/accept-groups.js.map +1 -0
- package/dist/maestro/adapters/pi/accept-runner.d.ts +37 -0
- package/dist/maestro/adapters/pi/accept-runner.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/accept-runner.js +161 -0
- package/dist/maestro/adapters/pi/accept-runner.js.map +1 -0
- package/dist/maestro/adapters/pi/activity-file.d.ts +39 -0
- package/dist/maestro/adapters/pi/activity-file.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/activity-file.js +454 -0
- package/dist/maestro/adapters/pi/activity-file.js.map +1 -0
- package/dist/maestro/adapters/pi/child/accept-check.d.ts +24 -0
- package/dist/maestro/adapters/pi/child/accept-check.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/child/accept-check.js +82 -0
- package/dist/maestro/adapters/pi/child/accept-check.js.map +1 -0
- package/dist/maestro/adapters/pi/child/declared-skills.d.ts +51 -0
- package/dist/maestro/adapters/pi/child/declared-skills.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/child/declared-skills.js +148 -0
- package/dist/maestro/adapters/pi/child/declared-skills.js.map +1 -0
- package/dist/maestro/adapters/pi/child/done-nudge.d.ts +38 -0
- package/dist/maestro/adapters/pi/child/done-nudge.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/child/done-nudge.js +77 -0
- package/dist/maestro/adapters/pi/child/done-nudge.js.map +1 -0
- package/dist/maestro/adapters/pi/child/entry.d.ts +3 -0
- package/dist/maestro/adapters/pi/child/entry.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/child/entry.js +3 -0
- package/dist/maestro/adapters/pi/child/entry.js.map +1 -0
- package/dist/maestro/adapters/pi/child/protocol.d.ts +56 -0
- package/dist/maestro/adapters/pi/child/protocol.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/child/protocol.js +510 -0
- package/dist/maestro/adapters/pi/child/protocol.js.map +1 -0
- package/dist/maestro/adapters/pi/completion.d.ts +45 -0
- package/dist/maestro/adapters/pi/completion.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/completion.js +295 -0
- package/dist/maestro/adapters/pi/completion.js.map +1 -0
- package/dist/maestro/adapters/pi/launch-command.d.ts +27 -0
- package/dist/maestro/adapters/pi/launch-command.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/launch-command.js +75 -0
- package/dist/maestro/adapters/pi/launch-command.js.map +1 -0
- package/dist/maestro/adapters/pi/launch-operations.d.ts +78 -0
- package/dist/maestro/adapters/pi/launch-operations.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/launch-operations.js +270 -0
- package/dist/maestro/adapters/pi/launch-operations.js.map +1 -0
- package/dist/maestro/adapters/pi/launch-resume.d.ts +4 -0
- package/dist/maestro/adapters/pi/launch-resume.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/launch-resume.js +183 -0
- package/dist/maestro/adapters/pi/launch-resume.js.map +1 -0
- package/dist/maestro/adapters/pi/launch.d.ts +148 -0
- package/dist/maestro/adapters/pi/launch.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/launch.js +655 -0
- package/dist/maestro/adapters/pi/launch.js.map +1 -0
- package/dist/maestro/adapters/pi/model-registry.d.ts +3 -0
- package/dist/maestro/adapters/pi/model-registry.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/model-registry.js +29 -0
- package/dist/maestro/adapters/pi/model-registry.js.map +1 -0
- package/dist/maestro/adapters/pi/pi-harness-adapter.d.ts +95 -0
- package/dist/maestro/adapters/pi/pi-harness-adapter.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/pi-harness-adapter.js +549 -0
- package/dist/maestro/adapters/pi/pi-harness-adapter.js.map +1 -0
- package/dist/maestro/adapters/pi/process-identity.d.ts +92 -0
- package/dist/maestro/adapters/pi/process-identity.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/process-identity.js +248 -0
- package/dist/maestro/adapters/pi/process-identity.js.map +1 -0
- package/dist/maestro/adapters/pi/process-tree.d.ts +48 -0
- package/dist/maestro/adapters/pi/process-tree.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/process-tree.js +69 -0
- package/dist/maestro/adapters/pi/process-tree.js.map +1 -0
- package/dist/maestro/adapters/pi/script-shell.d.ts +40 -0
- package/dist/maestro/adapters/pi/script-shell.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/script-shell.js +43 -0
- package/dist/maestro/adapters/pi/script-shell.js.map +1 -0
- package/dist/maestro/adapters/pi/session.d.ts +207 -0
- package/dist/maestro/adapters/pi/session.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/session.js +714 -0
- package/dist/maestro/adapters/pi/session.js.map +1 -0
- package/dist/maestro/adapters/pi/task-model-init.d.ts +4 -0
- package/dist/maestro/adapters/pi/task-model-init.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/task-model-init.js +47 -0
- package/dist/maestro/adapters/pi/task-model-init.js.map +1 -0
- package/dist/maestro/core/accept.d.ts +150 -0
- package/dist/maestro/core/accept.d.ts.map +1 -0
- package/dist/maestro/core/accept.js +243 -0
- package/dist/maestro/core/accept.js.map +1 -0
- package/dist/maestro/core/activity.d.ts +4 -0
- package/dist/maestro/core/activity.d.ts.map +1 -0
- package/dist/maestro/core/activity.js +18 -0
- package/dist/maestro/core/activity.js.map +1 -0
- package/dist/maestro/core/child-busy.d.ts +14 -0
- package/dist/maestro/core/child-busy.d.ts.map +1 -0
- package/dist/maestro/core/child-busy.js +14 -0
- package/dist/maestro/core/child-busy.js.map +1 -0
- package/dist/maestro/core/config/guidelines-config.d.ts +8 -0
- package/dist/maestro/core/config/guidelines-config.d.ts.map +1 -0
- package/dist/maestro/core/config/guidelines-config.js +60 -0
- package/dist/maestro/core/config/guidelines-config.js.map +1 -0
- package/dist/maestro/core/config/herdr-config.d.ts +13 -0
- package/dist/maestro/core/config/herdr-config.d.ts.map +1 -0
- package/dist/maestro/core/config/herdr-config.js +65 -0
- package/dist/maestro/core/config/herdr-config.js.map +1 -0
- package/dist/maestro/core/config/model-config.d.ts +92 -0
- package/dist/maestro/core/config/model-config.d.ts.map +1 -0
- package/dist/maestro/core/config/model-config.js +522 -0
- package/dist/maestro/core/config/model-config.js.map +1 -0
- package/dist/maestro/core/config/outcome-ledger-config.d.ts +8 -0
- package/dist/maestro/core/config/outcome-ledger-config.d.ts.map +1 -0
- package/dist/maestro/core/config/outcome-ledger-config.js +49 -0
- package/dist/maestro/core/config/outcome-ledger-config.js.map +1 -0
- package/dist/maestro/core/config/pane-config.d.ts +15 -0
- package/dist/maestro/core/config/pane-config.d.ts.map +1 -0
- package/dist/maestro/core/config/pane-config.js +101 -0
- package/dist/maestro/core/config/pane-config.js.map +1 -0
- package/dist/maestro/core/config/persistent-config.d.ts +7 -0
- package/dist/maestro/core/config/persistent-config.d.ts.map +1 -0
- package/dist/maestro/core/config/persistent-config.js +72 -0
- package/dist/maestro/core/config/persistent-config.js.map +1 -0
- package/dist/maestro/core/config/role-config.d.ts +7 -0
- package/dist/maestro/core/config/role-config.d.ts.map +1 -0
- package/dist/maestro/core/config/role-config.js +74 -0
- package/dist/maestro/core/config/role-config.js.map +1 -0
- package/dist/maestro/core/config/spawning-config.d.ts +7 -0
- package/dist/maestro/core/config/spawning-config.d.ts.map +1 -0
- package/dist/maestro/core/config/spawning-config.js +65 -0
- package/dist/maestro/core/config/spawning-config.js.map +1 -0
- package/dist/maestro/core/config/supervision-config.d.ts +7 -0
- package/dist/maestro/core/config/supervision-config.d.ts.map +1 -0
- package/dist/maestro/core/config/supervision-config.js +69 -0
- package/dist/maestro/core/config/supervision-config.js.map +1 -0
- package/dist/maestro/core/config/task-model-init.d.ts +118 -0
- package/dist/maestro/core/config/task-model-init.d.ts.map +1 -0
- package/dist/maestro/core/config/task-model-init.js +168 -0
- package/dist/maestro/core/config/task-model-init.js.map +1 -0
- package/dist/maestro/core/config/task-model-types.d.ts +36 -0
- package/dist/maestro/core/config/task-model-types.d.ts.map +1 -0
- package/dist/maestro/core/config/task-model-types.js +17 -0
- package/dist/maestro/core/config/task-model-types.js.map +1 -0
- package/dist/maestro/core/config/type-guards.d.ts +22 -0
- package/dist/maestro/core/config/type-guards.d.ts.map +1 -0
- package/dist/maestro/core/config/type-guards.js +31 -0
- package/dist/maestro/core/config/type-guards.js.map +1 -0
- package/dist/maestro/core/deadline.d.ts +11 -0
- package/dist/maestro/core/deadline.d.ts.map +1 -0
- package/dist/maestro/core/deadline.js +30 -0
- package/dist/maestro/core/deadline.js.map +1 -0
- package/dist/maestro/core/declared-skills.d.ts +16 -0
- package/dist/maestro/core/declared-skills.d.ts.map +1 -0
- package/dist/maestro/core/declared-skills.js +52 -0
- package/dist/maestro/core/declared-skills.js.map +1 -0
- package/dist/maestro/core/delegation-depth.d.ts +38 -0
- package/dist/maestro/core/delegation-depth.d.ts.map +1 -0
- package/dist/maestro/core/delegation-depth.js +59 -0
- package/dist/maestro/core/delegation-depth.js.map +1 -0
- package/dist/maestro/core/git-environment.d.ts +3 -0
- package/dist/maestro/core/git-environment.d.ts.map +1 -0
- package/dist/maestro/core/git-environment.js +29 -0
- package/dist/maestro/core/git-environment.js.map +1 -0
- package/dist/maestro/core/harness-adapter.d.ts +89 -0
- package/dist/maestro/core/harness-adapter.d.ts.map +1 -0
- package/dist/maestro/core/harness-adapter.js +2 -0
- package/dist/maestro/core/harness-adapter.js.map +1 -0
- package/dist/maestro/core/host-text.d.ts +49 -0
- package/dist/maestro/core/host-text.d.ts.map +1 -0
- package/dist/maestro/core/host-text.js +106 -0
- package/dist/maestro/core/host-text.js.map +1 -0
- package/dist/maestro/core/index.d.ts +4 -0
- package/dist/maestro/core/index.d.ts.map +1 -0
- package/dist/maestro/core/index.js +2 -0
- package/dist/maestro/core/index.js.map +1 -0
- package/dist/maestro/core/lifecycle.d.ts +16 -0
- package/dist/maestro/core/lifecycle.d.ts.map +1 -0
- package/dist/maestro/core/lifecycle.js +429 -0
- package/dist/maestro/core/lifecycle.js.map +1 -0
- package/dist/maestro/core/opened-primary-workspace.d.ts +31 -0
- package/dist/maestro/core/opened-primary-workspace.d.ts.map +1 -0
- package/dist/maestro/core/opened-primary-workspace.js +49 -0
- package/dist/maestro/core/opened-primary-workspace.js.map +1 -0
- package/dist/maestro/core/platform-support.d.ts +15 -0
- package/dist/maestro/core/platform-support.d.ts.map +1 -0
- package/dist/maestro/core/platform-support.js +23 -0
- package/dist/maestro/core/platform-support.js.map +1 -0
- package/dist/maestro/core/realpath-without-opening.d.ts +9 -0
- package/dist/maestro/core/realpath-without-opening.d.ts.map +1 -0
- package/dist/maestro/core/realpath-without-opening.js +45 -0
- package/dist/maestro/core/realpath-without-opening.js.map +1 -0
- package/dist/maestro/core/roles/discovery.d.ts +64 -0
- package/dist/maestro/core/roles/discovery.d.ts.map +1 -0
- package/dist/maestro/core/roles/discovery.js +422 -0
- package/dist/maestro/core/roles/discovery.js.map +1 -0
- package/dist/maestro/core/routing.d.ts +115 -0
- package/dist/maestro/core/routing.d.ts.map +1 -0
- package/dist/maestro/core/routing.js +449 -0
- package/dist/maestro/core/routing.js.map +1 -0
- package/dist/maestro/core/script-launch.d.ts +47 -0
- package/dist/maestro/core/script-launch.d.ts.map +1 -0
- package/dist/maestro/core/script-launch.js +102 -0
- package/dist/maestro/core/script-launch.js.map +1 -0
- package/dist/maestro/core/shell.d.ts +2 -0
- package/dist/maestro/core/shell.d.ts.map +1 -0
- package/dist/maestro/core/shell.js +4 -0
- package/dist/maestro/core/shell.js.map +1 -0
- package/dist/maestro/core/specialist-notice.d.ts +36 -0
- package/dist/maestro/core/specialist-notice.d.ts.map +1 -0
- package/dist/maestro/core/specialist-notice.js +41 -0
- package/dist/maestro/core/specialist-notice.js.map +1 -0
- package/dist/maestro/core/status.d.ts +87 -0
- package/dist/maestro/core/status.d.ts.map +1 -0
- package/dist/maestro/core/status.js +369 -0
- package/dist/maestro/core/status.js.map +1 -0
- package/dist/maestro/core/supervision.d.ts +56 -0
- package/dist/maestro/core/supervision.d.ts.map +1 -0
- package/dist/maestro/core/supervision.js +249 -0
- package/dist/maestro/core/supervision.js.map +1 -0
- package/dist/maestro/core/surface-provider.d.ts +200 -0
- package/dist/maestro/core/surface-provider.d.ts.map +1 -0
- package/dist/maestro/core/surface-provider.js +71 -0
- package/dist/maestro/core/surface-provider.js.map +1 -0
- package/dist/maestro/core/types.d.ts +388 -0
- package/dist/maestro/core/types.d.ts.map +1 -0
- package/dist/maestro/core/types.js +2 -0
- package/dist/maestro/core/types.js.map +1 -0
- package/dist/maestro/core/undelivered-children.d.ts +27 -0
- package/dist/maestro/core/undelivered-children.d.ts.map +1 -0
- package/dist/maestro/core/undelivered-children.js +31 -0
- package/dist/maestro/core/undelivered-children.js.map +1 -0
- package/dist/maestro/core/wake.d.ts +32 -0
- package/dist/maestro/core/wake.d.ts.map +1 -0
- package/dist/maestro/core/wake.js +125 -0
- package/dist/maestro/core/wake.js.map +1 -0
- package/dist/maestro/core/worktree-cleanup.d.ts +75 -0
- package/dist/maestro/core/worktree-cleanup.d.ts.map +1 -0
- package/dist/maestro/core/worktree-cleanup.js +278 -0
- package/dist/maestro/core/worktree-cleanup.js.map +1 -0
- package/dist/maestro/core/worktree.d.ts +50 -0
- package/dist/maestro/core/worktree.d.ts.map +1 -0
- package/dist/maestro/core/worktree.js +23 -0
- package/dist/maestro/core/worktree.js.map +1 -0
- package/dist/maestro/engine.d.ts +5 -0
- package/dist/maestro/engine.d.ts.map +1 -0
- package/dist/maestro/engine.js +5 -0
- package/dist/maestro/engine.js.map +1 -0
- package/dist/maestro/pi/child.d.ts +8 -0
- package/dist/maestro/pi/child.d.ts.map +1 -0
- package/dist/maestro/pi/child.js +8 -0
- package/dist/maestro/pi/child.js.map +1 -0
- package/dist/maestro/pi/extension.d.ts +10 -0
- package/dist/maestro/pi/extension.d.ts.map +1 -0
- package/dist/maestro/pi/extension.js +8 -0
- package/dist/maestro/pi/extension.js.map +1 -0
- package/dist/maestro/pi/subagents-index.d.ts +9 -0
- package/dist/maestro/pi/subagents-index.d.ts.map +1 -0
- package/dist/maestro/pi/subagents-index.js +9 -0
- package/dist/maestro/pi/subagents-index.js.map +1 -0
- package/dist/maestro/pi.d.ts +9 -0
- package/dist/maestro/pi.d.ts.map +1 -0
- package/dist/maestro/pi.js +7 -0
- package/dist/maestro/pi.js.map +1 -0
- package/dist/maestro/runtime/accept-recheck.d.ts +32 -0
- package/dist/maestro/runtime/accept-recheck.d.ts.map +1 -0
- package/dist/maestro/runtime/accept-recheck.js +92 -0
- package/dist/maestro/runtime/accept-recheck.js.map +1 -0
- package/dist/maestro/runtime/delegated-marker.d.ts +112 -0
- package/dist/maestro/runtime/delegated-marker.d.ts.map +1 -0
- package/dist/maestro/runtime/delegated-marker.js +200 -0
- package/dist/maestro/runtime/delegated-marker.js.map +1 -0
- package/dist/maestro/runtime/host-surface-binding.d.ts +25 -0
- package/dist/maestro/runtime/host-surface-binding.d.ts.map +1 -0
- package/dist/maestro/runtime/host-surface-binding.js +2 -0
- package/dist/maestro/runtime/host-surface-binding.js.map +1 -0
- package/dist/maestro/runtime/index.d.ts +10 -0
- package/dist/maestro/runtime/index.d.ts.map +1 -0
- package/dist/maestro/runtime/index.js +6 -0
- package/dist/maestro/runtime/index.js.map +1 -0
- package/dist/maestro/runtime/pi-persistent-io.d.ts +7 -0
- package/dist/maestro/runtime/pi-persistent-io.d.ts.map +1 -0
- package/dist/maestro/runtime/pi-persistent-io.js +64 -0
- package/dist/maestro/runtime/pi-persistent-io.js.map +1 -0
- package/dist/maestro/runtime/pi-run-session-types.d.ts +328 -0
- package/dist/maestro/runtime/pi-run-session-types.d.ts.map +1 -0
- package/dist/maestro/runtime/pi-run-session-types.js +2 -0
- package/dist/maestro/runtime/pi-run-session-types.js.map +1 -0
- package/dist/maestro/runtime/pi-run-session.d.ts +12 -0
- package/dist/maestro/runtime/pi-run-session.d.ts.map +1 -0
- package/dist/maestro/runtime/pi-run-session.js +809 -0
- package/dist/maestro/runtime/pi-run-session.js.map +1 -0
- package/dist/maestro/runtime/run-session.d.ts +129 -0
- package/dist/maestro/runtime/run-session.d.ts.map +1 -0
- package/dist/maestro/runtime/run-session.js +680 -0
- package/dist/maestro/runtime/run-session.js.map +1 -0
- package/dist/maestro/runtime/surface-retention.d.ts +3 -0
- package/dist/maestro/runtime/surface-retention.d.ts.map +1 -0
- package/dist/maestro/runtime/surface-retention.js +5 -0
- package/dist/maestro/runtime/surface-retention.js.map +1 -0
- package/dist/maestro/runtime/task-model-init.d.ts +34 -0
- package/dist/maestro/runtime/task-model-init.d.ts.map +1 -0
- package/dist/maestro/runtime/task-model-init.js +78 -0
- package/dist/maestro/runtime/task-model-init.js.map +1 -0
- package/dist/maestro/runtime/worktree-operations.d.ts +31 -0
- package/dist/maestro/runtime/worktree-operations.d.ts.map +1 -0
- package/dist/maestro/runtime/worktree-operations.js +633 -0
- package/dist/maestro/runtime/worktree-operations.js.map +1 -0
- package/dist/maestro/surfaces/fake/fake-surface-provider.d.ts +54 -0
- package/dist/maestro/surfaces/fake/fake-surface-provider.d.ts.map +1 -0
- package/dist/maestro/surfaces/fake/fake-surface-provider.js +231 -0
- package/dist/maestro/surfaces/fake/fake-surface-provider.js.map +1 -0
- package/dist/maestro/testing/harness-adapter.conformance.d.ts +31 -0
- package/dist/maestro/testing/harness-adapter.conformance.d.ts.map +1 -0
- package/dist/maestro/testing/harness-adapter.conformance.js +181 -0
- package/dist/maestro/testing/harness-adapter.conformance.js.map +1 -0
- package/dist/maestro/testing/index.d.ts +5 -0
- package/dist/maestro/testing/index.d.ts.map +1 -0
- package/dist/maestro/testing/index.js +5 -0
- package/dist/maestro/testing/index.js.map +1 -0
- package/dist/maestro/testing/surface-provider.conformance.d.ts +20 -0
- package/dist/maestro/testing/surface-provider.conformance.d.ts.map +1 -0
- package/dist/maestro/testing/surface-provider.conformance.js +167 -0
- package/dist/maestro/testing/surface-provider.conformance.js.map +1 -0
- package/dist/pi-extension/subagents/catalog.d.ts +70 -0
- package/dist/pi-extension/subagents/catalog.d.ts.map +1 -0
- package/dist/pi-extension/subagents/catalog.js +231 -0
- package/dist/pi-extension/subagents/catalog.js.map +1 -0
- package/dist/pi-extension/subagents/config-path.d.ts +6 -0
- package/dist/pi-extension/subagents/config-path.d.ts.map +1 -0
- package/dist/pi-extension/subagents/config-path.js +21 -0
- package/dist/pi-extension/subagents/config-path.js.map +1 -0
- package/dist/pi-extension/subagents/control-tools.d.ts +21 -0
- package/dist/pi-extension/subagents/control-tools.d.ts.map +1 -0
- package/dist/pi-extension/subagents/control-tools.js +150 -0
- package/dist/pi-extension/subagents/control-tools.js.map +1 -0
- package/dist/pi-extension/subagents/controls.d.ts +52 -0
- package/dist/pi-extension/subagents/controls.d.ts.map +1 -0
- package/dist/pi-extension/subagents/controls.js +173 -0
- package/dist/pi-extension/subagents/controls.js.map +1 -0
- package/dist/pi-extension/subagents/deferred-tools.d.ts +43 -0
- package/dist/pi-extension/subagents/deferred-tools.d.ts.map +1 -0
- package/dist/pi-extension/subagents/deferred-tools.js +67 -0
- package/dist/pi-extension/subagents/deferred-tools.js.map +1 -0
- package/dist/pi-extension/subagents/delivery.d.ts +22 -0
- package/dist/pi-extension/subagents/delivery.d.ts.map +1 -0
- package/dist/pi-extension/subagents/delivery.js +365 -0
- package/dist/pi-extension/subagents/delivery.js.map +1 -0
- package/dist/pi-extension/subagents/extension.d.ts +100 -0
- package/dist/pi-extension/subagents/extension.d.ts.map +1 -0
- package/dist/pi-extension/subagents/extension.js +367 -0
- package/dist/pi-extension/subagents/extension.js.map +1 -0
- package/dist/pi-extension/subagents/launch-tools.d.ts +33 -0
- package/dist/pi-extension/subagents/launch-tools.d.ts.map +1 -0
- package/dist/pi-extension/subagents/launch-tools.js +373 -0
- package/dist/pi-extension/subagents/launch-tools.js.map +1 -0
- package/dist/pi-extension/subagents/launch.d.ts +86 -0
- package/dist/pi-extension/subagents/launch.d.ts.map +1 -0
- package/dist/pi-extension/subagents/launch.js +133 -0
- package/dist/pi-extension/subagents/launch.js.map +1 -0
- package/dist/pi-extension/subagents/model-registry.d.ts +13 -0
- package/dist/pi-extension/subagents/model-registry.d.ts.map +1 -0
- package/dist/pi-extension/subagents/model-registry.js +52 -0
- package/dist/pi-extension/subagents/model-registry.js.map +1 -0
- package/dist/pi-extension/subagents/observation.d.ts +38 -0
- package/dist/pi-extension/subagents/observation.d.ts.map +1 -0
- package/dist/pi-extension/subagents/observation.js +168 -0
- package/dist/pi-extension/subagents/observation.js.map +1 -0
- package/dist/pi-extension/subagents/persistent.d.ts +72 -0
- package/dist/pi-extension/subagents/persistent.d.ts.map +1 -0
- package/dist/pi-extension/subagents/persistent.js +322 -0
- package/dist/pi-extension/subagents/persistent.js.map +1 -0
- package/dist/pi-extension/subagents/presentation-hooks.d.ts +25 -0
- package/dist/pi-extension/subagents/presentation-hooks.d.ts.map +1 -0
- package/dist/pi-extension/subagents/presentation-hooks.js +2 -0
- package/dist/pi-extension/subagents/presentation-hooks.js.map +1 -0
- package/dist/pi-extension/subagents/presentation.d.ts +149 -0
- package/dist/pi-extension/subagents/presentation.d.ts.map +1 -0
- package/dist/pi-extension/subagents/presentation.js +419 -0
- package/dist/pi-extension/subagents/presentation.js.map +1 -0
- package/dist/pi-extension/subagents/state.d.ts +183 -0
- package/dist/pi-extension/subagents/state.d.ts.map +1 -0
- package/dist/pi-extension/subagents/state.js +92 -0
- package/dist/pi-extension/subagents/state.js.map +1 -0
- package/dist/pi-extension/subagents/task-models.d.ts +9 -0
- package/dist/pi-extension/subagents/task-models.d.ts.map +1 -0
- package/dist/pi-extension/subagents/task-models.js +293 -0
- package/dist/pi-extension/subagents/task-models.js.map +1 -0
- package/dist/pi-extension/subagents/tool-boundary.d.ts +16 -0
- package/dist/pi-extension/subagents/tool-boundary.d.ts.map +1 -0
- package/dist/pi-extension/subagents/tool-boundary.js +53 -0
- package/dist/pi-extension/subagents/tool-boundary.js.map +1 -0
- package/dist/pi-extension/subagents/worktree-tools.d.ts +16 -0
- package/dist/pi-extension/subagents/worktree-tools.d.ts.map +1 -0
- package/dist/pi-extension/subagents/worktree-tools.js +185 -0
- package/dist/pi-extension/subagents/worktree-tools.js.map +1 -0
- package/dist/provenance.json +5 -0
- package/package.json +540 -27
- package/index.d.ts +0 -1
- package/index.js +0 -2
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { win32 } from "node:path";
|
|
2
|
+
import { Deadline } from "../../core/deadline.js";
|
|
3
|
+
import { linuxProcessProbe, readLinuxProcessEnvironment, readProcessIdentityRecord, verifyProcessIdentityRecord, } from "./process-identity.js";
|
|
4
|
+
function placementFromPaneConfig(config) {
|
|
5
|
+
if (config.mode === "split") {
|
|
6
|
+
return { kind: "split", direction: config.direction };
|
|
7
|
+
}
|
|
8
|
+
if (config.mode === "tab")
|
|
9
|
+
return { kind: "tab" };
|
|
10
|
+
return { kind: "grouped" };
|
|
11
|
+
}
|
|
12
|
+
function worktreeSurfaceForLaunch(worktree) {
|
|
13
|
+
const surface = {
|
|
14
|
+
path: worktree.path,
|
|
15
|
+
branch: worktree.branch,
|
|
16
|
+
workspaceId: worktree.workspaceId,
|
|
17
|
+
paneId: worktree.surfaceId,
|
|
18
|
+
};
|
|
19
|
+
if (worktree.diagnostics?.length)
|
|
20
|
+
surface.diagnostics = worktree.diagnostics;
|
|
21
|
+
return surface;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Names the launched session in the Pi process's exec-time environment. Pi
|
|
25
|
+
* rewrites its command line, so `--session` is never readiness evidence.
|
|
26
|
+
* Nothing inside Pi reads it.
|
|
27
|
+
*/
|
|
28
|
+
export const PI_LAUNCH_SESSION_ENV = "PI_HERDR_AGENTS_SESSION";
|
|
29
|
+
export function isExpectedPiProcess(process, sessionFile, cwd, readEnvironment = readLinuxProcessEnvironment, platform = globalThis.process.platform) {
|
|
30
|
+
if (platform === "win32")
|
|
31
|
+
return isExpectedWindowsPiProcess(process, sessionFile, cwd);
|
|
32
|
+
return ((process.name === "pi" || process.argv0?.split("/").pop() === "pi") &&
|
|
33
|
+
process.cwd === cwd &&
|
|
34
|
+
readEnvironment(process.pid)?.get(PI_LAUNCH_SESSION_ENV) === sessionFile);
|
|
35
|
+
}
|
|
36
|
+
/** A Windows path in one comparable form: separators, `.`/`..`, case, trailing `\`. */
|
|
37
|
+
function comparableWindowsPath(path) {
|
|
38
|
+
const normal = win32.normalize(path).toLowerCase();
|
|
39
|
+
return win32.parse(normal).root === normal
|
|
40
|
+
? normal
|
|
41
|
+
: normal.replace(/[\\/]+$/, "");
|
|
42
|
+
}
|
|
43
|
+
/** Runtimes that can be Pi itself on Windows: Node, Bun, or a compiled `pi`. */
|
|
44
|
+
const WINDOWS_PI_RUNTIMES = new Set(["node", "bun", "pi"]);
|
|
45
|
+
/** Node options whose value is the next argument, so it is not the script. */
|
|
46
|
+
const NODE_OPTIONS_WITH_VALUE = new Set([
|
|
47
|
+
"-r",
|
|
48
|
+
"--require",
|
|
49
|
+
"--import",
|
|
50
|
+
"--loader",
|
|
51
|
+
"--experimental-loader",
|
|
52
|
+
"-e",
|
|
53
|
+
"--eval",
|
|
54
|
+
"-p",
|
|
55
|
+
"--print",
|
|
56
|
+
]);
|
|
57
|
+
/** The entrypoint basenames Pi's package `bin` and a source checkout use. */
|
|
58
|
+
const PI_ENTRYPOINT = /^cli\.(?:[cm]?js|ts)$/i;
|
|
59
|
+
/**
|
|
60
|
+
* Where `--session` sits in `argv` if this is Pi's own command line, else
|
|
61
|
+
* `-1`. Pi's own means the runtime is Node, Bun or a compiled `pi` (so not
|
|
62
|
+
* `sh`, `bash`, `cmd` or PowerShell running npm's shim), and for Node and Bun
|
|
63
|
+
* the script it runs is Pi's CLI entrypoint (so not the managed install's
|
|
64
|
+
* `pi-launcher.js`, which forwards the same arguments and then spawns Pi, and
|
|
65
|
+
* not an unrelated script). `--session` must follow the entrypoint, because
|
|
66
|
+
* only then is it an argument to Pi.
|
|
67
|
+
*/
|
|
68
|
+
function windowsPiSessionFlag(argv) {
|
|
69
|
+
const runtime = win32
|
|
70
|
+
.basename(argv[0] ?? "")
|
|
71
|
+
.toLowerCase()
|
|
72
|
+
.replace(/\.exe$/, "");
|
|
73
|
+
if (!WINDOWS_PI_RUNTIMES.has(runtime))
|
|
74
|
+
return -1;
|
|
75
|
+
let entry = 1;
|
|
76
|
+
if (runtime === "pi")
|
|
77
|
+
entry = 0;
|
|
78
|
+
else {
|
|
79
|
+
if (runtime === "bun" && argv[entry] === "run")
|
|
80
|
+
entry++;
|
|
81
|
+
while (argv[entry]?.startsWith("-")) {
|
|
82
|
+
const option = argv[entry];
|
|
83
|
+
entry += NODE_OPTIONS_WITH_VALUE.has(option) ? 2 : 1;
|
|
84
|
+
}
|
|
85
|
+
const script = argv[entry];
|
|
86
|
+
if (script === undefined || !PI_ENTRYPOINT.test(win32.basename(script)))
|
|
87
|
+
return -1;
|
|
88
|
+
}
|
|
89
|
+
return argv.indexOf("--session", entry + 1);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* On Windows there is no `/proc/<pid>/environ` to read, and no process-title
|
|
93
|
+
* rewrite either: the pane's process reports the command line it really was
|
|
94
|
+
* started with. So the launched session is proved by `--session <file>` in
|
|
95
|
+
* that argv, but only on a command line that is Pi's own (`windowsPiSessionFlag`).
|
|
96
|
+
* A launcher in front of Pi carries the same `--session` before Pi has started
|
|
97
|
+
* and must not mark the launch ready. Herdr names Pi's process `node.exe` (or
|
|
98
|
+
* `pi.exe`), so the reported name proves nothing and `argv[0]` is read instead;
|
|
99
|
+
* its cwd arrives with a trailing `\`.
|
|
100
|
+
*/
|
|
101
|
+
function isExpectedWindowsPiProcess(process, sessionFile, cwd) {
|
|
102
|
+
const { argv, cwd: processCwd } = process;
|
|
103
|
+
if (!argv || processCwd === undefined)
|
|
104
|
+
return false;
|
|
105
|
+
const flag = windowsPiSessionFlag(argv);
|
|
106
|
+
const value = flag === -1 ? undefined : argv[flag + 1];
|
|
107
|
+
return (value !== undefined &&
|
|
108
|
+
comparableWindowsPath(value) === comparableWindowsPath(sessionFile) &&
|
|
109
|
+
comparableWindowsPath(processCwd) === comparableWindowsPath(cwd));
|
|
110
|
+
}
|
|
111
|
+
async function waitForSurfacePiReady(provider, surface, sessionFile, cwd, options = {}) {
|
|
112
|
+
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
113
|
+
const intervalMs = options.intervalMs ?? 50;
|
|
114
|
+
const deadline = Deadline.after(timeoutMs);
|
|
115
|
+
let lastError = "expected Pi process not observed";
|
|
116
|
+
while (!deadline.expired()) {
|
|
117
|
+
try {
|
|
118
|
+
const info = await provider.getProcessInfo(surface, {
|
|
119
|
+
timeoutMs: deadline.remainingMs(),
|
|
120
|
+
});
|
|
121
|
+
deadline.remainingMs();
|
|
122
|
+
// An unreadable process (one that is exiting) proves nothing, but must
|
|
123
|
+
// not hide a matching sibling.
|
|
124
|
+
for (const process of info.foregroundProcesses) {
|
|
125
|
+
try {
|
|
126
|
+
if (isExpectedPiProcess(process, sessionFile, cwd))
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
lastError = errorMessage(error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
lastError = errorMessage(error);
|
|
136
|
+
}
|
|
137
|
+
if (deadline.expired())
|
|
138
|
+
break;
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(intervalMs, deadline.remainingMs())));
|
|
140
|
+
}
|
|
141
|
+
throw new Error(`Timed out waiting for Pi session ${sessionFile} in Herdr pane ${surface}: ${lastError}`);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Wait for the child to publish its own identity, then accept it only while
|
|
145
|
+
* that process is alive in this host's namespace as the Herdr pane shell or a
|
|
146
|
+
* descendant of it. Command-line text is never consulted: Pi rewrites it.
|
|
147
|
+
*/
|
|
148
|
+
export async function captureSurfacePiProcessIdentity(provider, surface, expected, options = {}) {
|
|
149
|
+
const timeoutMs = options.timeoutMs ?? 15_000;
|
|
150
|
+
const intervalMs = options.intervalMs ?? 100;
|
|
151
|
+
const deadline = Date.now() + timeoutMs;
|
|
152
|
+
let lastError = "the child has not recorded its process identity";
|
|
153
|
+
let answered = false;
|
|
154
|
+
for (;;) {
|
|
155
|
+
if (Date.now() >= deadline)
|
|
156
|
+
break;
|
|
157
|
+
try {
|
|
158
|
+
const record = readProcessIdentityRecord(expected.file);
|
|
159
|
+
if (record) {
|
|
160
|
+
// The deadline bounds Herdr too; a late answer is dropped, never accepted.
|
|
161
|
+
const info = await settleBefore(Promise.resolve().then(() => {
|
|
162
|
+
const remaining = deadline - Date.now();
|
|
163
|
+
if (remaining <= 0)
|
|
164
|
+
return undefined;
|
|
165
|
+
return provider.getProcessInfo(surface, { timeoutMs: remaining });
|
|
166
|
+
}), deadline, { unref: true });
|
|
167
|
+
if (!info) {
|
|
168
|
+
// The deadline passed; an earlier answer's refusal says more.
|
|
169
|
+
if (!answered)
|
|
170
|
+
lastError = `Herdr process info for pane ${surface} timed out`;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
answered = true;
|
|
174
|
+
if (info.shellPid === undefined)
|
|
175
|
+
throw new Error(`Herdr reports no shell for pane ${surface}`);
|
|
176
|
+
return verifyProcessIdentityRecord(record, { ...expected, shellPid: info.shellPid }, options.probe ?? linuxProcessProbe);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
lastError = errorMessage(error);
|
|
181
|
+
}
|
|
182
|
+
const remaining = deadline - Date.now();
|
|
183
|
+
if (remaining <= 0)
|
|
184
|
+
break;
|
|
185
|
+
// Background capture must never hold the parent process open.
|
|
186
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(intervalMs, remaining)).unref());
|
|
187
|
+
}
|
|
188
|
+
throw new Error(`Process identity not captured within ${timeoutMs}ms: ${lastError}`);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The pending value if it settles before the deadline; otherwise undefined.
|
|
192
|
+
* A value that arrives after the deadline is dropped, never reported, even
|
|
193
|
+
* when a delayed event loop runs it before the overdue timer.
|
|
194
|
+
*/
|
|
195
|
+
export async function settleBefore(pending, deadline, options = {}) {
|
|
196
|
+
if (!pending)
|
|
197
|
+
return undefined;
|
|
198
|
+
let expire;
|
|
199
|
+
const expired = new Promise((resolve) => {
|
|
200
|
+
expire = () => resolve(undefined);
|
|
201
|
+
});
|
|
202
|
+
const timer = setTimeout(expire, Math.max(0, deadline - Date.now()));
|
|
203
|
+
if (options.unref)
|
|
204
|
+
timer.unref();
|
|
205
|
+
try {
|
|
206
|
+
const onTime = pending.then((value) => Date.now() > deadline ? undefined : value);
|
|
207
|
+
return await Promise.race([onTime, expired]);
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
clearTimeout(timer);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export function launchOperationsFromSurface(provider, config, worktree) {
|
|
214
|
+
return {
|
|
215
|
+
nativeExecution: provider.nativeExecution,
|
|
216
|
+
worktree,
|
|
217
|
+
createPane(name, cwd, control) {
|
|
218
|
+
return provider.createSurface({
|
|
219
|
+
name,
|
|
220
|
+
cwd: cwd ?? process.cwd(),
|
|
221
|
+
placement: placementFromPaneConfig(config),
|
|
222
|
+
signal: control?.signal,
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
async createWorktree(name, cwd, branch, base, control) {
|
|
226
|
+
const worktree = await Promise.resolve(provider.createWorktreeSurface({
|
|
227
|
+
name,
|
|
228
|
+
cwd,
|
|
229
|
+
branch,
|
|
230
|
+
base,
|
|
231
|
+
signal: control?.signal,
|
|
232
|
+
}));
|
|
233
|
+
return worktreeSurfaceForLaunch(worktree);
|
|
234
|
+
},
|
|
235
|
+
waitForShellReady(surface) {
|
|
236
|
+
return provider.waitForShellReady(surface);
|
|
237
|
+
},
|
|
238
|
+
runScript(surface, command, options) {
|
|
239
|
+
return provider.runScript(surface, command, options);
|
|
240
|
+
},
|
|
241
|
+
async closePane(pane) {
|
|
242
|
+
let closeError;
|
|
243
|
+
try {
|
|
244
|
+
await provider.closeSurface(pane);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
closeError = error;
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
await provider.waitForSurfaceAbsence(pane);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
throw new Error(`${closeError ? `${errorMessage(closeError)}; ` : ""}${errorMessage(error)}`);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
waitForPiReady(surface, sessionFile, cwd) {
|
|
257
|
+
return waitForSurfacePiReady(provider, surface, sessionFile, cwd);
|
|
258
|
+
},
|
|
259
|
+
focusWorkspace(workspaceId) {
|
|
260
|
+
return provider.focusWorkspace(workspaceId);
|
|
261
|
+
},
|
|
262
|
+
captureProcessIdentity(surface, expected, options) {
|
|
263
|
+
return captureSurfacePiProcessIdentity(provider, surface, expected, options);
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function errorMessage(error) {
|
|
268
|
+
return error instanceof Error ? error.message : String(error);
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=launch-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-operations.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/launch-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,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AC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import { win32 } from \"node:path\";\nimport type { PaneConfig } from \"../../core/config/pane-config.ts\";\nimport type {\n\tSurfaceProvider,\n\tAcquisitionControl,\n\tWorktreeSurface,\n\tNativeExecution,\n} from \"../../core/surface-provider.ts\";\nimport type { WorktreeOperations } from \"../../core/worktree.ts\";\nimport { Deadline } from \"../../core/deadline.ts\";\nimport {\n\tlinuxProcessProbe,\n\treadLinuxProcessEnvironment,\n\treadProcessIdentityRecord,\n\tverifyProcessIdentityRecord,\n\ttype PiProcessIdentity,\n\ttype ProcessEnvironmentReader,\n\ttype ProcessIdentityProbe,\n} from \"./process-identity.ts\";\n\n/** What a captured identity must match: this run, its session, and its pane. */\nexport interface ProcessIdentityExpectation {\n\tfile: string;\n\tid: string;\n\tsessionFile: string;\n}\n\ntype MaybePromise<T> = T | Promise<T>;\n\nexport interface WorktreeSurfaceForLaunch {\n\tpath: string;\n\tbranch: string;\n\tworkspaceId: string;\n\tpaneId: string;\n\tdiagnostics?: string[];\n}\n\nexport interface PiLaunchOperations {\n\t/** Present only for atomic native program launches, without a shell pane. */\n\tnativeExecution?: NativeExecution;\n\t/** Required for managed worktree launches; ordinary panes need no Git effects. */\n\tworktree?: WorktreeOperations;\n\tcreatePane(\n\t\tname: string,\n\t\tcwd?: string,\n\t\tcontrol?: AcquisitionControl,\n\t): MaybePromise<string>;\n\tcreateWorktree(\n\t\tname: string,\n\t\tcwd: string,\n\t\tbranch: string,\n\t\tbase: string,\n\t\tcontrol?: AcquisitionControl,\n\t): MaybePromise<WorktreeSurfaceForLaunch>;\n\twaitForShellReady(surface: string): Promise<void>;\n\t/**\n\t * Rejects with a command-dispatch `AcquisitionUncertainError` only when Pi\n\t * may have started; any other rejection means nothing was dispatched, so the\n\t * launch rolls back as a definite failure.\n\t */\n\trunScript(\n\t\tsurface: string,\n\t\tcommand: string,\n\t\toptions: { scriptPath: string; scriptPreamble: string },\n\t): MaybePromise<string>;\n\t/** Rollback resolves only once this ordinary pane is confirmed absent. */\n\tclosePane(pane: string): MaybePromise<void>;\n\twaitForPiReady?(\n\t\tsurface: string,\n\t\tsessionFile: string,\n\t\tcwd: string,\n\t): Promise<void>;\n\tfocusWorkspace?(workspaceId: string): MaybePromise<void>;\n\t/** Bounded readiness capture of a worktree child's verified process identity. */\n\tcaptureProcessIdentity?(\n\t\tsurface: string,\n\t\texpected: ProcessIdentityExpectation,\n\t\toptions?: { timeoutMs?: number },\n\t): Promise<PiProcessIdentity>;\n}\n\nfunction placementFromPaneConfig(config: PaneConfig) {\n\tif (config.mode === \"split\") {\n\t\treturn { kind: \"split\" as const, direction: config.direction };\n\t}\n\tif (config.mode === \"tab\") return { kind: \"tab\" as const };\n\treturn { kind: \"grouped\" as const };\n}\n\nfunction worktreeSurfaceForLaunch(\n\tworktree: WorktreeSurface,\n): WorktreeSurfaceForLaunch {\n\tconst surface: WorktreeSurfaceForLaunch = {\n\t\tpath: worktree.path,\n\t\tbranch: worktree.branch,\n\t\tworkspaceId: worktree.workspaceId,\n\t\tpaneId: worktree.surfaceId,\n\t};\n\tif (worktree.diagnostics?.length) surface.diagnostics = worktree.diagnostics;\n\treturn surface;\n}\n\n/**\n * Names the launched session in the Pi process's exec-time environment. Pi\n * rewrites its command line, so `--session` is never readiness evidence.\n * Nothing inside Pi reads it.\n */\nexport const PI_LAUNCH_SESSION_ENV = \"PI_HERDR_AGENTS_SESSION\";\n\nexport function isExpectedPiProcess(\n\tprocess: {\n\t\tpid: number;\n\t\tname?: string;\n\t\targv0?: string;\n\t\targv?: string[];\n\t\tcwd?: string;\n\t},\n\tsessionFile: string,\n\tcwd: string,\n\treadEnvironment: ProcessEnvironmentReader = readLinuxProcessEnvironment,\n\tplatform: NodeJS.Platform = globalThis.process.platform,\n): boolean {\n\tif (platform === \"win32\")\n\t\treturn isExpectedWindowsPiProcess(process, sessionFile, cwd);\n\treturn (\n\t\t(process.name === \"pi\" || process.argv0?.split(\"/\").pop() === \"pi\") &&\n\t\tprocess.cwd === cwd &&\n\t\treadEnvironment(process.pid)?.get(PI_LAUNCH_SESSION_ENV) === sessionFile\n\t);\n}\n\n/** A Windows path in one comparable form: separators, `.`/`..`, case, trailing `\\`. */\nfunction comparableWindowsPath(path: string): string {\n\tconst normal = win32.normalize(path).toLowerCase();\n\treturn win32.parse(normal).root === normal\n\t\t? normal\n\t\t: normal.replace(/[\\\\/]+$/, \"\");\n}\n\n/** Runtimes that can be Pi itself on Windows: Node, Bun, or a compiled `pi`. */\nconst WINDOWS_PI_RUNTIMES = new Set([\"node\", \"bun\", \"pi\"]);\n\n/** Node options whose value is the next argument, so it is not the script. */\nconst NODE_OPTIONS_WITH_VALUE = new Set([\n\t\"-r\",\n\t\"--require\",\n\t\"--import\",\n\t\"--loader\",\n\t\"--experimental-loader\",\n\t\"-e\",\n\t\"--eval\",\n\t\"-p\",\n\t\"--print\",\n]);\n\n/** The entrypoint basenames Pi's package `bin` and a source checkout use. */\nconst PI_ENTRYPOINT = /^cli\\.(?:[cm]?js|ts)$/i;\n\n/**\n * Where `--session` sits in `argv` if this is Pi's own command line, else\n * `-1`. Pi's own means the runtime is Node, Bun or a compiled `pi` (so not\n * `sh`, `bash`, `cmd` or PowerShell running npm's shim), and for Node and Bun\n * the script it runs is Pi's CLI entrypoint (so not the managed install's\n * `pi-launcher.js`, which forwards the same arguments and then spawns Pi, and\n * not an unrelated script). `--session` must follow the entrypoint, because\n * only then is it an argument to Pi.\n */\nfunction windowsPiSessionFlag(argv: string[]): number {\n\tconst runtime = win32\n\t\t.basename(argv[0] ?? \"\")\n\t\t.toLowerCase()\n\t\t.replace(/\\.exe$/, \"\");\n\tif (!WINDOWS_PI_RUNTIMES.has(runtime)) return -1;\n\tlet entry = 1;\n\tif (runtime === \"pi\") entry = 0;\n\telse {\n\t\tif (runtime === \"bun\" && argv[entry] === \"run\") entry++;\n\t\twhile (argv[entry]?.startsWith(\"-\")) {\n\t\t\tconst option = argv[entry]!;\n\t\t\tentry += NODE_OPTIONS_WITH_VALUE.has(option) ? 2 : 1;\n\t\t}\n\t\tconst script = argv[entry];\n\t\tif (script === undefined || !PI_ENTRYPOINT.test(win32.basename(script)))\n\t\t\treturn -1;\n\t}\n\treturn argv.indexOf(\"--session\", entry + 1);\n}\n\n/**\n * On Windows there is no `/proc/<pid>/environ` to read, and no process-title\n * rewrite either: the pane's process reports the command line it really was\n * started with. So the launched session is proved by `--session <file>` in\n * that argv, but only on a command line that is Pi's own (`windowsPiSessionFlag`).\n * A launcher in front of Pi carries the same `--session` before Pi has started\n * and must not mark the launch ready. Herdr names Pi's process `node.exe` (or\n * `pi.exe`), so the reported name proves nothing and `argv[0]` is read instead;\n * its cwd arrives with a trailing `\\`.\n */\nfunction isExpectedWindowsPiProcess(\n\tprocess: { argv?: string[]; cwd?: string },\n\tsessionFile: string,\n\tcwd: string,\n): boolean {\n\tconst { argv, cwd: processCwd } = process;\n\tif (!argv || processCwd === undefined) return false;\n\tconst flag = windowsPiSessionFlag(argv);\n\tconst value = flag === -1 ? undefined : argv[flag + 1];\n\treturn (\n\t\tvalue !== undefined &&\n\t\tcomparableWindowsPath(value) === comparableWindowsPath(sessionFile) &&\n\t\tcomparableWindowsPath(processCwd) === comparableWindowsPath(cwd)\n\t);\n}\n\nasync function waitForSurfacePiReady(\n\tprovider: SurfaceProvider,\n\tsurface: string,\n\tsessionFile: string,\n\tcwd: string,\n\toptions: { timeoutMs?: number; intervalMs?: number } = {},\n): Promise<void> {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst intervalMs = options.intervalMs ?? 50;\n\tconst deadline = Deadline.after(timeoutMs);\n\tlet lastError = \"expected Pi process not observed\";\n\n\twhile (!deadline.expired()) {\n\t\ttry {\n\t\t\tconst info = await provider.getProcessInfo(surface, {\n\t\t\t\ttimeoutMs: deadline.remainingMs(),\n\t\t\t});\n\t\t\tdeadline.remainingMs();\n\t\t\t// An unreadable process (one that is exiting) proves nothing, but must\n\t\t\t// not hide a matching sibling.\n\t\t\tfor (const process of info.foregroundProcesses) {\n\t\t\t\ttry {\n\t\t\t\t\tif (isExpectedPiProcess(process, sessionFile, cwd)) return;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlastError = errorMessage(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlastError = errorMessage(error);\n\t\t}\n\t\tif (deadline.expired()) break;\n\t\tawait new Promise((resolve) =>\n\t\t\tsetTimeout(resolve, Math.min(intervalMs, deadline.remainingMs())),\n\t\t);\n\t}\n\tthrow new Error(\n\t\t`Timed out waiting for Pi session ${sessionFile} in Herdr pane ${surface}: ${lastError}`,\n\t);\n}\n\n/**\n * Wait for the child to publish its own identity, then accept it only while\n * that process is alive in this host's namespace as the Herdr pane shell or a\n * descendant of it. Command-line text is never consulted: Pi rewrites it.\n */\nexport async function captureSurfacePiProcessIdentity(\n\tprovider: Pick<SurfaceProvider, \"getProcessInfo\">,\n\tsurface: string,\n\texpected: ProcessIdentityExpectation,\n\toptions: {\n\t\ttimeoutMs?: number;\n\t\tintervalMs?: number;\n\t\tprobe?: ProcessIdentityProbe;\n\t} = {},\n): Promise<PiProcessIdentity> {\n\tconst timeoutMs = options.timeoutMs ?? 15_000;\n\tconst intervalMs = options.intervalMs ?? 100;\n\tconst deadline = Date.now() + timeoutMs;\n\tlet lastError = \"the child has not recorded its process identity\";\n\tlet answered = false;\n\tfor (;;) {\n\t\tif (Date.now() >= deadline) break;\n\t\ttry {\n\t\t\tconst record = readProcessIdentityRecord(expected.file);\n\t\t\tif (record) {\n\t\t\t\t// The deadline bounds Herdr too; a late answer is dropped, never accepted.\n\t\t\t\tconst info = await settleBefore(\n\t\t\t\t\tPromise.resolve().then(() => {\n\t\t\t\t\t\tconst remaining = deadline - Date.now();\n\t\t\t\t\t\tif (remaining <= 0) return undefined;\n\t\t\t\t\t\treturn provider.getProcessInfo(surface, { timeoutMs: remaining });\n\t\t\t\t\t}),\n\t\t\t\t\tdeadline,\n\t\t\t\t\t{ unref: true },\n\t\t\t\t);\n\t\t\t\tif (!info) {\n\t\t\t\t\t// The deadline passed; an earlier answer's refusal says more.\n\t\t\t\t\tif (!answered)\n\t\t\t\t\t\tlastError = `Herdr process info for pane ${surface} timed out`;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tanswered = true;\n\t\t\t\tif (info.shellPid === undefined)\n\t\t\t\t\tthrow new Error(`Herdr reports no shell for pane ${surface}`);\n\t\t\t\treturn verifyProcessIdentityRecord(\n\t\t\t\t\trecord,\n\t\t\t\t\t{ ...expected, shellPid: info.shellPid },\n\t\t\t\t\toptions.probe ?? linuxProcessProbe,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlastError = errorMessage(error);\n\t\t}\n\t\tconst remaining = deadline - Date.now();\n\t\tif (remaining <= 0) break;\n\t\t// Background capture must never hold the parent process open.\n\t\tawait new Promise((resolve) =>\n\t\t\tsetTimeout(resolve, Math.min(intervalMs, remaining)).unref(),\n\t\t);\n\t}\n\tthrow new Error(\n\t\t`Process identity not captured within ${timeoutMs}ms: ${lastError}`,\n\t);\n}\n\n/**\n * The pending value if it settles before the deadline; otherwise undefined.\n * A value that arrives after the deadline is dropped, never reported, even\n * when a delayed event loop runs it before the overdue timer.\n */\nexport async function settleBefore<T>(\n\tpending: Promise<T> | undefined,\n\tdeadline: number,\n\toptions: { unref?: boolean } = {},\n): Promise<T | undefined> {\n\tif (!pending) return undefined;\n\tlet expire!: () => void;\n\tconst expired = new Promise<undefined>((resolve) => {\n\t\texpire = () => resolve(undefined);\n\t});\n\tconst timer = setTimeout(expire, Math.max(0, deadline - Date.now()));\n\tif (options.unref) timer.unref();\n\ttry {\n\t\tconst onTime = pending.then((value) =>\n\t\t\tDate.now() > deadline ? undefined : value,\n\t\t);\n\t\treturn await Promise.race([onTime, expired]);\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\nexport function launchOperationsFromSurface(\n\tprovider: SurfaceProvider,\n\tconfig: PaneConfig,\n\tworktree?: WorktreeOperations,\n): PiLaunchOperations {\n\treturn {\n\t\tnativeExecution: provider.nativeExecution,\n\t\tworktree,\n\t\tcreatePane(name, cwd, control) {\n\t\t\treturn provider.createSurface({\n\t\t\t\tname,\n\t\t\t\tcwd: cwd ?? process.cwd(),\n\t\t\t\tplacement: placementFromPaneConfig(config),\n\t\t\t\tsignal: control?.signal,\n\t\t\t});\n\t\t},\n\t\tasync createWorktree(name, cwd, branch, base, control) {\n\t\t\tconst worktree = await Promise.resolve(\n\t\t\t\tprovider.createWorktreeSurface({\n\t\t\t\t\tname,\n\t\t\t\t\tcwd,\n\t\t\t\t\tbranch,\n\t\t\t\t\tbase,\n\t\t\t\t\tsignal: control?.signal,\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn worktreeSurfaceForLaunch(worktree);\n\t\t},\n\t\twaitForShellReady(surface) {\n\t\t\treturn provider.waitForShellReady(surface);\n\t\t},\n\t\trunScript(surface, command, options) {\n\t\t\treturn provider.runScript(surface, command, options);\n\t\t},\n\t\tasync closePane(pane) {\n\t\t\tlet closeError: unknown;\n\t\t\ttry {\n\t\t\t\tawait provider.closeSurface(pane);\n\t\t\t} catch (error) {\n\t\t\t\tcloseError = error;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait provider.waitForSurfaceAbsence(pane);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`${closeError ? `${errorMessage(closeError)}; ` : \"\"}${errorMessage(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\twaitForPiReady(surface, sessionFile, cwd) {\n\t\t\treturn waitForSurfacePiReady(provider, surface, sessionFile, cwd);\n\t\t},\n\t\tfocusWorkspace(workspaceId) {\n\t\t\treturn provider.focusWorkspace(workspaceId);\n\t\t},\n\t\tcaptureProcessIdentity(surface, expected, options) {\n\t\t\treturn captureSurfacePiProcessIdentity(\n\t\t\t\tprovider,\n\t\t\t\tsurface,\n\t\t\t\texpected,\n\t\t\t\toptions,\n\t\t\t);\n\t\t},\n\t};\n}\n\nfunction errorMessage(error: any): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PiLaunchOperations } from "./launch-operations.ts";
|
|
2
|
+
import { type PiRunningChild, type ResumePiLaunchRequest } from "./launch.ts";
|
|
3
|
+
export declare function launchResumedPiSubagent(callerRequest: ResumePiLaunchRequest, operations: PiLaunchOperations): Promise<PiRunningChild>;
|
|
4
|
+
//# sourceMappingURL=launch-resume.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-resume.d.ts","sourceRoot":"","sources":["../../../../maestro/adapters/pi/launch-resume.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,MAAM,aAAa,CAAC;AAUrB,wBAAsB,uBAAuB,CAC5C,aAAa,EAAE,qBAAqB,EACpC,UAAU,EAAE,kBAAkB,GAC5B,OAAO,CAAC,cAAc,CAAC,CAqNzB"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { getSubagentActivityFile } from "./activity-file.js";
|
|
4
|
+
import { createLifecycle } from "../../core/lifecycle.js";
|
|
5
|
+
import { assertModelInScope, modelScopeOf } from "../../core/routing.js";
|
|
6
|
+
import { isNonEmptyString } from "../../core/config/type-guards.js";
|
|
7
|
+
import { DECLARED_SKILLS_ENV, formatDeclaredSkillsEnv, } from "../../core/declared-skills.js";
|
|
8
|
+
import { shellQuote } from "../../core/shell.js";
|
|
9
|
+
import { findStoredSessionModel, getNewEntries, readSubagentSessionPolicy, } from "./session.js";
|
|
10
|
+
import { buildSubagentToolAllowlist, childDepthAssignment, modelScopeArgs, modelScopeAssignment, safeName, shellComment, DEFAULT_CHILD_ENTRY_PATH, timestampForFile, } from "./launch-command.js";
|
|
11
|
+
import { AcquiredPiLaunchError, } from "./launch.js";
|
|
12
|
+
import { AcquisitionUncertainError, isAcquisitionUncertainError, } from "../../core/surface-provider.js";
|
|
13
|
+
function emptyDeclaredSkillsAssignment() {
|
|
14
|
+
return `${DECLARED_SKILLS_ENV}=${shellQuote(formatDeclaredSkillsEnv([]))}`;
|
|
15
|
+
}
|
|
16
|
+
export async function launchResumedPiSubagent(callerRequest, operations) {
|
|
17
|
+
// Pi resolves `--session` against the pane's cwd, not the caller's. Resolve
|
|
18
|
+
// it here once, so every read, the command, and the running child's
|
|
19
|
+
// session file name the same absolute path that Pi then reports to Herdr.
|
|
20
|
+
const request = {
|
|
21
|
+
...callerRequest,
|
|
22
|
+
sessionFile: resolve(callerRequest.sessionFile),
|
|
23
|
+
};
|
|
24
|
+
const id = request.id ?? Math.random().toString(16).slice(2, 10);
|
|
25
|
+
const policy = readSubagentSessionPolicy(request.sessionFile);
|
|
26
|
+
if (policy.owner !== "public") {
|
|
27
|
+
throw new Error(`Cannot resume ${policy.owner} session through subagent_resume. ` +
|
|
28
|
+
"Use its retained managed-worktree workspace instead.");
|
|
29
|
+
}
|
|
30
|
+
if (policy.persistent) {
|
|
31
|
+
throw new Error(`Cannot resume persistent specialist ${request.sessionFile}. Spawn a new specialist instead; persistent sessions retain their evidence but do not revive in v1.`);
|
|
32
|
+
}
|
|
33
|
+
const autoExit = request.behavior?.autoExit ?? true;
|
|
34
|
+
const interactive = request.behavior?.interactive ?? !autoExit;
|
|
35
|
+
const startTime = Date.now();
|
|
36
|
+
const artifactDir = join(request.parent.sessionDir, "artifacts", request.parent.sessionId);
|
|
37
|
+
const header = getNewEntries(request.sessionFile, 0).find((entry) => entry.type === "session");
|
|
38
|
+
const cwd = isNonEmptyString(header?.cwd) ? header.cwd : process.cwd();
|
|
39
|
+
// A scoped parent pins the stored model after checking it, so Pi cannot
|
|
40
|
+
// restore an out-of-scope model on resume.
|
|
41
|
+
const scopeArgs = modelScopeArgs(request.modelScope);
|
|
42
|
+
let pinnedModel;
|
|
43
|
+
if (modelScopeOf({ scope: request.modelScope })) {
|
|
44
|
+
const stored = findStoredSessionModel(getNewEntries(request.sessionFile, 0));
|
|
45
|
+
if (!stored)
|
|
46
|
+
throw new Error(`Cannot resume ${request.sessionFile} in a scoped session: it records no model to check against the scope (--models / enabledModels).`);
|
|
47
|
+
pinnedModel = `${stored.provider}/${stored.modelId}`;
|
|
48
|
+
assertModelInScope(pinnedModel, { scope: request.modelScope }, "the resumed session's stored model", "resume keeps a session's model, so launch a new subagent with an in-scope model instead");
|
|
49
|
+
}
|
|
50
|
+
request.acquisitionSignal?.throwIfAborted();
|
|
51
|
+
const surface = operations.nativeExecution
|
|
52
|
+
? undefined
|
|
53
|
+
: await operations.createPane(request.name, cwd, {
|
|
54
|
+
signal: request.acquisitionSignal,
|
|
55
|
+
});
|
|
56
|
+
let running;
|
|
57
|
+
try {
|
|
58
|
+
request.acquisitionSignal?.throwIfAborted();
|
|
59
|
+
if (surface)
|
|
60
|
+
await operations.waitForShellReady(surface);
|
|
61
|
+
request.acquisitionSignal?.throwIfAborted();
|
|
62
|
+
const activityFile = getSubagentActivityFile(artifactDir, id);
|
|
63
|
+
mkdirSync(dirname(activityFile), { recursive: true });
|
|
64
|
+
let messageFile;
|
|
65
|
+
if (request.message) {
|
|
66
|
+
messageFile = join(artifactDir, "subagent-resume", `${safeName(request.name) || "resume"}-${timestampForFile(false)}.md`);
|
|
67
|
+
mkdirSync(dirname(messageFile), { recursive: true });
|
|
68
|
+
writeFileSync(messageFile, request.message, "utf8");
|
|
69
|
+
}
|
|
70
|
+
const env = [
|
|
71
|
+
...(process.env.PI_CODING_AGENT_DIR
|
|
72
|
+
? [`PI_CODING_AGENT_DIR=${shellQuote(process.env.PI_CODING_AGENT_DIR)}`]
|
|
73
|
+
: []),
|
|
74
|
+
...(policy.deniedTools.length > 0
|
|
75
|
+
? [`PI_DENY_TOOLS=${shellQuote(policy.deniedTools.join(","))}`]
|
|
76
|
+
: []),
|
|
77
|
+
childDepthAssignment(),
|
|
78
|
+
modelScopeAssignment(request.modelScope),
|
|
79
|
+
`PI_SUBAGENT_SELF_SPAWN=${policy.version === 2 && policy.selfSpawn ? "1" : "0"}`,
|
|
80
|
+
emptyDeclaredSkillsAssignment(),
|
|
81
|
+
`PI_SUBAGENT_NAME=${shellQuote(request.name)}`,
|
|
82
|
+
...(policy.version === 2 && policy.agent
|
|
83
|
+
? [`PI_SUBAGENT_AGENT=${shellQuote(policy.agent)}`]
|
|
84
|
+
: []),
|
|
85
|
+
`PI_SUBAGENT_SESSION=${shellQuote(request.sessionFile)}`,
|
|
86
|
+
`PI_SUBAGENT_ID=${shellQuote(id)}`,
|
|
87
|
+
`PI_SUBAGENT_ACTIVITY_FILE=${shellQuote(activityFile)}`,
|
|
88
|
+
`PI_SUBAGENT_AUTO_EXIT=${autoExit ? "1" : "0"}`,
|
|
89
|
+
];
|
|
90
|
+
const toolAllowlist = buildSubagentToolAllowlist(policy.tools?.join(","), autoExit);
|
|
91
|
+
const command = [
|
|
92
|
+
...env,
|
|
93
|
+
"pi",
|
|
94
|
+
"--session",
|
|
95
|
+
shellQuote(request.sessionFile),
|
|
96
|
+
...(pinnedModel ? ["--model", shellQuote(pinnedModel)] : []),
|
|
97
|
+
...scopeArgs,
|
|
98
|
+
...(toolAllowlist ? ["--tools", shellQuote(toolAllowlist)] : []),
|
|
99
|
+
"-e",
|
|
100
|
+
shellQuote(request.childEntryPath ?? DEFAULT_CHILD_ENTRY_PATH),
|
|
101
|
+
...(messageFile ? [shellQuote(`@${messageFile}`)] : []),
|
|
102
|
+
].join(" ");
|
|
103
|
+
const launchScriptFile = join(artifactDir, "subagent-scripts", `${safeName(request.name) || "resume"}-resume-${Date.now()}.sh`);
|
|
104
|
+
const initialized = {
|
|
105
|
+
id,
|
|
106
|
+
name: request.name,
|
|
107
|
+
task: request.message ?? "resumed session",
|
|
108
|
+
ownsSurface: true,
|
|
109
|
+
startTime,
|
|
110
|
+
sessionFile: request.sessionFile,
|
|
111
|
+
launchScriptFile,
|
|
112
|
+
activityFile,
|
|
113
|
+
interactive,
|
|
114
|
+
runtimePlan: undefined,
|
|
115
|
+
cwd,
|
|
116
|
+
lifecycle: createLifecycle(startTime),
|
|
117
|
+
};
|
|
118
|
+
request.acquisitionSignal?.throwIfAborted();
|
|
119
|
+
if (operations.nativeExecution) {
|
|
120
|
+
try {
|
|
121
|
+
const nativeSurface = await operations.nativeExecution.start({
|
|
122
|
+
cwd,
|
|
123
|
+
command: `${command}; piha_exit=$?; echo "__SUBAGENT_DONE_\${piha_exit}__"; exit "$piha_exit"`,
|
|
124
|
+
scriptPath: launchScriptFile,
|
|
125
|
+
scriptPreamble: shellComment(`Subagent resume script for ${request.name}`),
|
|
126
|
+
signal: request.acquisitionSignal,
|
|
127
|
+
});
|
|
128
|
+
return { ...initialized, surface: nativeSurface };
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (isAcquisitionUncertainError(error) &&
|
|
132
|
+
error.uncertainty.kind === "execution-start" &&
|
|
133
|
+
error.uncertainty.acquiredSurfaceId)
|
|
134
|
+
throw new AcquiredPiLaunchError({ ...initialized, surface: error.uncertainty.acquiredSurfaceId }, error);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!surface)
|
|
139
|
+
throw new Error("Resume requires an acquired shell surface");
|
|
140
|
+
try {
|
|
141
|
+
initialized.launchScriptFile = await operations.runScript(surface, `${command}; echo '__SUBAGENT_DONE_'$?'__'`, {
|
|
142
|
+
scriptPath: launchScriptFile,
|
|
143
|
+
scriptPreamble: [
|
|
144
|
+
shellComment(`Subagent resume script for ${request.name}`),
|
|
145
|
+
shellComment(`Generated: ${new Date().toISOString()}`),
|
|
146
|
+
shellComment(`Session: ${request.sessionFile}`),
|
|
147
|
+
shellComment(`Surface: ${surface}`),
|
|
148
|
+
...(messageFile
|
|
149
|
+
? [shellComment(`Resume message file: ${messageFile}`)]
|
|
150
|
+
: []),
|
|
151
|
+
].join("\n"),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (isAcquisitionUncertainError(error) &&
|
|
156
|
+
error.uncertainty.kind === "command-dispatch")
|
|
157
|
+
running = { ...initialized, surface };
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
running = { ...initialized, surface };
|
|
161
|
+
return running;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (operations.nativeExecution || !surface)
|
|
165
|
+
throw error;
|
|
166
|
+
try {
|
|
167
|
+
await operations.closePane(surface);
|
|
168
|
+
}
|
|
169
|
+
catch (rollback) {
|
|
170
|
+
if (running)
|
|
171
|
+
throw new AcquiredPiLaunchError(running, new Error(`${String(error)}; rollback unconfirmed: ${String(rollback)}`, { cause: error }));
|
|
172
|
+
throw new AcquisitionUncertainError(`${String(error)}; rollback unconfirmed: ${String(rollback)}; pane retained: ${surface}; no fallback`, {
|
|
173
|
+
kind: "surface-create",
|
|
174
|
+
placement: "tab",
|
|
175
|
+
observedSurfaceId: surface,
|
|
176
|
+
}, { cause: error });
|
|
177
|
+
}
|
|
178
|
+
if (running)
|
|
179
|
+
throw new AcquiredPiLaunchError(running, error);
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=launch-resume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-resume.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/launch-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,M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7D,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC","sourcesContent":["import { mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { getSubagentActivityFile } from \"./activity-file.ts\";\nimport { createLifecycle } from \"../../core/lifecycle.ts\";\nimport { assertModelInScope, modelScopeOf } from \"../../core/routing.ts\";\nimport { isNonEmptyString } from \"../../core/config/type-guards.ts\";\nimport {\n\tDECLARED_SKILLS_ENV,\n\tformatDeclaredSkillsEnv,\n} from \"../../core/declared-skills.ts\";\nimport { shellQuote } from \"../../core/shell.ts\";\nimport {\n\tfindStoredSessionModel,\n\tgetNewEntries,\n\treadSubagentSessionPolicy,\n} from \"./session.ts\";\nimport {\n\tbuildSubagentToolAllowlist,\n\tchildDepthAssignment,\n\tmodelScopeArgs,\n\tmodelScopeAssignment,\n\tsafeName,\n\tshellComment,\n\tDEFAULT_CHILD_ENTRY_PATH,\n\ttimestampForFile,\n} from \"./launch-command.ts\";\nimport type { PiLaunchOperations } from \"./launch-operations.ts\";\nimport {\n\tAcquiredPiLaunchError,\n\ttype PiRunningChild,\n\ttype ResumePiLaunchRequest,\n} from \"./launch.ts\";\nimport {\n\tAcquisitionUncertainError,\n\tisAcquisitionUncertainError,\n} from \"../../core/surface-provider.ts\";\n\nfunction emptyDeclaredSkillsAssignment(): string {\n\treturn `${DECLARED_SKILLS_ENV}=${shellQuote(formatDeclaredSkillsEnv([]))}`;\n}\n\nexport async function launchResumedPiSubagent(\n\tcallerRequest: ResumePiLaunchRequest,\n\toperations: PiLaunchOperations,\n): Promise<PiRunningChild> {\n\t// Pi resolves `--session` against the pane's cwd, not the caller's. Resolve\n\t// it here once, so every read, the command, and the running child's\n\t// session file name the same absolute path that Pi then reports to Herdr.\n\tconst request = {\n\t\t...callerRequest,\n\t\tsessionFile: resolve(callerRequest.sessionFile),\n\t};\n\tconst id = request.id ?? Math.random().toString(16).slice(2, 10);\n\tconst policy = readSubagentSessionPolicy(request.sessionFile);\n\tif (policy.owner !== \"public\") {\n\t\tthrow new Error(\n\t\t\t`Cannot resume ${policy.owner} session through subagent_resume. ` +\n\t\t\t\t\"Use its retained managed-worktree workspace instead.\",\n\t\t);\n\t}\n\tif (policy.persistent) {\n\t\tthrow new Error(\n\t\t\t`Cannot resume persistent specialist ${request.sessionFile}. Spawn a new specialist instead; persistent sessions retain their evidence but do not revive in v1.`,\n\t\t);\n\t}\n\tconst autoExit = request.behavior?.autoExit ?? true;\n\tconst interactive = request.behavior?.interactive ?? !autoExit;\n\tconst startTime = Date.now();\n\tconst artifactDir = join(\n\t\trequest.parent.sessionDir,\n\t\t\"artifacts\",\n\t\trequest.parent.sessionId,\n\t);\n\tconst header = getNewEntries(request.sessionFile, 0).find(\n\t\t(entry) => entry.type === \"session\",\n\t);\n\tconst cwd = isNonEmptyString(header?.cwd) ? header.cwd : process.cwd();\n\t// A scoped parent pins the stored model after checking it, so Pi cannot\n\t// restore an out-of-scope model on resume.\n\tconst scopeArgs = modelScopeArgs(request.modelScope);\n\tlet pinnedModel: string | undefined;\n\tif (modelScopeOf({ scope: request.modelScope })) {\n\t\tconst stored = findStoredSessionModel(\n\t\t\tgetNewEntries(request.sessionFile, 0),\n\t\t);\n\t\tif (!stored)\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot resume ${request.sessionFile} in a scoped session: it records no model to check against the scope (--models / enabledModels).`,\n\t\t\t);\n\t\tpinnedModel = `${stored.provider}/${stored.modelId}`;\n\t\tassertModelInScope(\n\t\t\tpinnedModel,\n\t\t\t{ scope: request.modelScope },\n\t\t\t\"the resumed session's stored model\",\n\t\t\t\"resume keeps a session's model, so launch a new subagent with an in-scope model instead\",\n\t\t);\n\t}\n\trequest.acquisitionSignal?.throwIfAborted();\n\tconst surface = operations.nativeExecution\n\t\t? undefined\n\t\t: await operations.createPane(request.name, cwd, {\n\t\t\t\tsignal: request.acquisitionSignal,\n\t\t\t});\n\tlet running: PiRunningChild | undefined;\n\ttry {\n\t\trequest.acquisitionSignal?.throwIfAborted();\n\t\tif (surface) await operations.waitForShellReady(surface);\n\t\trequest.acquisitionSignal?.throwIfAborted();\n\t\tconst activityFile = getSubagentActivityFile(artifactDir, id);\n\t\tmkdirSync(dirname(activityFile), { recursive: true });\n\n\t\tlet messageFile: string | undefined;\n\t\tif (request.message) {\n\t\t\tmessageFile = join(\n\t\t\t\tartifactDir,\n\t\t\t\t\"subagent-resume\",\n\t\t\t\t`${safeName(request.name) || \"resume\"}-${timestampForFile(false)}.md`,\n\t\t\t);\n\t\t\tmkdirSync(dirname(messageFile), { recursive: true });\n\t\t\twriteFileSync(messageFile, request.message, \"utf8\");\n\t\t}\n\n\t\tconst env = [\n\t\t\t...(process.env.PI_CODING_AGENT_DIR\n\t\t\t\t? [`PI_CODING_AGENT_DIR=${shellQuote(process.env.PI_CODING_AGENT_DIR)}`]\n\t\t\t\t: []),\n\t\t\t...(policy.deniedTools.length > 0\n\t\t\t\t? [`PI_DENY_TOOLS=${shellQuote(policy.deniedTools.join(\",\"))}`]\n\t\t\t\t: []),\n\t\t\tchildDepthAssignment(),\n\t\t\tmodelScopeAssignment(request.modelScope),\n\t\t\t`PI_SUBAGENT_SELF_SPAWN=${policy.version === 2 && policy.selfSpawn ? \"1\" : \"0\"}`,\n\t\t\temptyDeclaredSkillsAssignment(),\n\t\t\t`PI_SUBAGENT_NAME=${shellQuote(request.name)}`,\n\t\t\t...(policy.version === 2 && policy.agent\n\t\t\t\t? [`PI_SUBAGENT_AGENT=${shellQuote(policy.agent)}`]\n\t\t\t\t: []),\n\t\t\t`PI_SUBAGENT_SESSION=${shellQuote(request.sessionFile)}`,\n\t\t\t`PI_SUBAGENT_ID=${shellQuote(id)}`,\n\t\t\t`PI_SUBAGENT_ACTIVITY_FILE=${shellQuote(activityFile)}`,\n\t\t\t`PI_SUBAGENT_AUTO_EXIT=${autoExit ? \"1\" : \"0\"}`,\n\t\t];\n\t\tconst toolAllowlist = buildSubagentToolAllowlist(\n\t\t\tpolicy.tools?.join(\",\"),\n\t\t\tautoExit,\n\t\t);\n\t\tconst command = [\n\t\t\t...env,\n\t\t\t\"pi\",\n\t\t\t\"--session\",\n\t\t\tshellQuote(request.sessionFile),\n\t\t\t...(pinnedModel ? [\"--model\", shellQuote(pinnedModel)] : []),\n\t\t\t...scopeArgs,\n\t\t\t...(toolAllowlist ? [\"--tools\", shellQuote(toolAllowlist)] : []),\n\t\t\t\"-e\",\n\t\t\tshellQuote(request.childEntryPath ?? DEFAULT_CHILD_ENTRY_PATH),\n\t\t\t...(messageFile ? [shellQuote(`@${messageFile}`)] : []),\n\t\t].join(\" \");\n\t\tconst launchScriptFile = join(\n\t\t\tartifactDir,\n\t\t\t\"subagent-scripts\",\n\t\t\t`${safeName(request.name) || \"resume\"}-resume-${Date.now()}.sh`,\n\t\t);\n\t\tconst initialized: Omit<PiRunningChild, \"surface\"> = {\n\t\t\tid,\n\t\t\tname: request.name,\n\t\t\ttask: request.message ?? \"resumed session\",\n\t\t\townsSurface: true,\n\t\t\tstartTime,\n\t\t\tsessionFile: request.sessionFile,\n\t\t\tlaunchScriptFile,\n\t\t\tactivityFile,\n\t\t\tinteractive,\n\t\t\truntimePlan: undefined,\n\t\t\tcwd,\n\t\t\tlifecycle: createLifecycle(startTime),\n\t\t};\n\t\trequest.acquisitionSignal?.throwIfAborted();\n\t\tif (operations.nativeExecution) {\n\t\t\ttry {\n\t\t\t\tconst nativeSurface = await operations.nativeExecution.start({\n\t\t\t\t\tcwd,\n\t\t\t\t\tcommand: `${command}; piha_exit=$?; echo \"__SUBAGENT_DONE_\\${piha_exit}__\"; exit \"$piha_exit\"`,\n\t\t\t\t\tscriptPath: launchScriptFile,\n\t\t\t\t\tscriptPreamble: shellComment(\n\t\t\t\t\t\t`Subagent resume script for ${request.name}`,\n\t\t\t\t\t),\n\t\t\t\t\tsignal: request.acquisitionSignal,\n\t\t\t\t});\n\t\t\t\treturn { ...initialized, surface: nativeSurface };\n\t\t\t} catch (error) {\n\t\t\t\tif (\n\t\t\t\t\tisAcquisitionUncertainError(error) &&\n\t\t\t\t\terror.uncertainty.kind === \"execution-start\" &&\n\t\t\t\t\terror.uncertainty.acquiredSurfaceId\n\t\t\t\t)\n\t\t\t\t\tthrow new AcquiredPiLaunchError(\n\t\t\t\t\t\t{ ...initialized, surface: error.uncertainty.acquiredSurfaceId },\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif (!surface) throw new Error(\"Resume requires an acquired shell surface\");\n\t\ttry {\n\t\t\tinitialized.launchScriptFile = await operations.runScript(\n\t\t\t\tsurface,\n\t\t\t\t`${command}; echo '__SUBAGENT_DONE_'$?'__'`,\n\t\t\t\t{\n\t\t\t\t\tscriptPath: launchScriptFile,\n\t\t\t\t\tscriptPreamble: [\n\t\t\t\t\t\tshellComment(`Subagent resume script for ${request.name}`),\n\t\t\t\t\t\tshellComment(`Generated: ${new Date().toISOString()}`),\n\t\t\t\t\t\tshellComment(`Session: ${request.sessionFile}`),\n\t\t\t\t\t\tshellComment(`Surface: ${surface}`),\n\t\t\t\t\t\t...(messageFile\n\t\t\t\t\t\t\t? [shellComment(`Resume message file: ${messageFile}`)]\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t].join(\"\\n\"),\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\tisAcquisitionUncertainError(error) &&\n\t\t\t\terror.uncertainty.kind === \"command-dispatch\"\n\t\t\t)\n\t\t\t\trunning = { ...initialized, surface };\n\t\t\tthrow error;\n\t\t}\n\t\trunning = { ...initialized, surface };\n\t\treturn running;\n\t} catch (error) {\n\t\tif (operations.nativeExecution || !surface) throw error;\n\t\ttry {\n\t\t\tawait operations.closePane(surface);\n\t\t} catch (rollback) {\n\t\t\tif (running)\n\t\t\t\tthrow new AcquiredPiLaunchError(\n\t\t\t\t\trunning,\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t`${String(error)}; rollback unconfirmed: ${String(rollback)}`,\n\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\tthrow new AcquisitionUncertainError(\n\t\t\t\t`${String(error)}; rollback unconfirmed: ${String(rollback)}; pane retained: ${surface}; no fallback`,\n\t\t\t\t{\n\t\t\t\t\tkind: \"surface-create\",\n\t\t\t\t\tplacement: \"tab\",\n\t\t\t\t\tobservedSurfaceId: surface,\n\t\t\t\t},\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\t\tif (running) throw new AcquiredPiLaunchError(running, error);\n\t\tthrow error;\n\t}\n}\n"]}
|