@nubl/maestro 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -2
- 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,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable kernel facts naming one Pi child process for its whole life.
|
|
3
|
+
* Mutable command-line text (Pi rewrites `process.title`) is never identity.
|
|
4
|
+
*/
|
|
5
|
+
export interface PiProcessIdentity {
|
|
6
|
+
pid: number;
|
|
7
|
+
/** `/proc/<pid>/stat` field 22: clock ticks after boot, fixed at fork. */
|
|
8
|
+
startTime: string;
|
|
9
|
+
/** `/proc/sys/kernel/random/boot_id`; start times are per boot. */
|
|
10
|
+
bootId: string;
|
|
11
|
+
/** `/proc/self/ns/pid` link target; PIDs are per PID namespace. */
|
|
12
|
+
pidNamespace: string;
|
|
13
|
+
}
|
|
14
|
+
/** One sidecar per session, so a reused run ID can never inherit a record. */
|
|
15
|
+
export declare function getSubagentProcessIdentityFile(sessionFile: string): string;
|
|
16
|
+
/** The child's self-recorded identity sidecar, bound to one run and session. */
|
|
17
|
+
export interface PiProcessIdentityRecord extends PiProcessIdentity {
|
|
18
|
+
version: 1;
|
|
19
|
+
id: string;
|
|
20
|
+
sessionFile: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ProcessStat {
|
|
23
|
+
/** Single-letter state; Z (zombie) and X (dead) have exited. */
|
|
24
|
+
state: string;
|
|
25
|
+
ppid: number;
|
|
26
|
+
startTime: string;
|
|
27
|
+
}
|
|
28
|
+
/** This host's kernel process facts; tests inject a fake. */
|
|
29
|
+
export interface ProcessIdentityProbe {
|
|
30
|
+
/** The calling process's namespace facts; throws when unreadable or unsupported. */
|
|
31
|
+
host(): {
|
|
32
|
+
bootId: string;
|
|
33
|
+
pidNamespace: string;
|
|
34
|
+
};
|
|
35
|
+
/** `undefined` only when no such PID exists; throws on any other read failure. */
|
|
36
|
+
stat(pid: number): ProcessStat | undefined;
|
|
37
|
+
/** Sends SIGTERM to a PID; throws ESRCH when it is already gone. */
|
|
38
|
+
terminate(pid: number): void;
|
|
39
|
+
}
|
|
40
|
+
export type ProcessIdentityState = {
|
|
41
|
+
kind: "alive";
|
|
42
|
+
} | {
|
|
43
|
+
kind: "exited";
|
|
44
|
+
} | {
|
|
45
|
+
kind: "unknown";
|
|
46
|
+
reason: string;
|
|
47
|
+
};
|
|
48
|
+
export declare function parseProcessStat(text: string): ProcessStat;
|
|
49
|
+
/** Linux `/proc` facts; the reader is injectable only for error-path tests. */
|
|
50
|
+
export declare function createLinuxProcessProbe(read?: (path: string) => string): ProcessIdentityProbe;
|
|
51
|
+
export declare const linuxProcessProbe: ProcessIdentityProbe;
|
|
52
|
+
/**
|
|
53
|
+
* A process's environment as it was at exec. Unlike its command line, Pi's
|
|
54
|
+
* process-title rewrite leaves this intact. `undefined` only when no such PID
|
|
55
|
+
* exists; throws on non-Linux hosts and any other read failure.
|
|
56
|
+
*/
|
|
57
|
+
export type ProcessEnvironmentReader = (pid: number) => Map<string, string> | undefined;
|
|
58
|
+
export declare function createLinuxProcessEnvironmentReader(read?: (path: string) => string): ProcessEnvironmentReader;
|
|
59
|
+
export declare const readLinuxProcessEnvironment: ProcessEnvironmentReader;
|
|
60
|
+
/** The calling process's identity; throws when this host cannot establish it. */
|
|
61
|
+
export declare function readOwnProcessIdentity(probe?: ProcessIdentityProbe): PiProcessIdentity;
|
|
62
|
+
/**
|
|
63
|
+
* Publish the record atomically and only once: a torn read is impossible and
|
|
64
|
+
* a later writer (a reload in the same process, or any other process) never
|
|
65
|
+
* replaces the first identity.
|
|
66
|
+
*/
|
|
67
|
+
export declare function writeProcessIdentityRecord(file: string, record: PiProcessIdentityRecord): void;
|
|
68
|
+
/** `undefined` until the child has published; throws on a malformed record. */
|
|
69
|
+
export declare function readProcessIdentityRecord(file: string): PiProcessIdentityRecord | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Whether THAT process still exists. Only an absent PID or a zombie is exit
|
|
72
|
+
* evidence; a different start time, another boot or namespace, or any read
|
|
73
|
+
* failure is unknown, never guessed exited.
|
|
74
|
+
*/
|
|
75
|
+
export declare function judgeProcessIdentity(identity: PiProcessIdentity, probe?: ProcessIdentityProbe): ProcessIdentityState;
|
|
76
|
+
/**
|
|
77
|
+
* Accept a child's record only for this run and session, while it is alive in
|
|
78
|
+
* this host's namespace, and only as the pane shell or a descendant of it.
|
|
79
|
+
*/
|
|
80
|
+
export declare function verifyProcessIdentityRecord(record: PiProcessIdentityRecord, expected: {
|
|
81
|
+
id: string;
|
|
82
|
+
sessionFile: string;
|
|
83
|
+
shellPid: number;
|
|
84
|
+
}, probe?: ProcessIdentityProbe): PiProcessIdentity;
|
|
85
|
+
/**
|
|
86
|
+
* SIGTERM only the recorded identity, re-verified immediately before the
|
|
87
|
+
* signal. A mismatch or unreadable state is never signalled. The kernel can
|
|
88
|
+
* still reuse the PID between that read and `kill(2)`; Node exposes no pidfd
|
|
89
|
+
* signal to close the window.
|
|
90
|
+
*/
|
|
91
|
+
export declare function terminateProcessIdentity(identity: PiProcessIdentity, probe?: ProcessIdentityProbe): ProcessIdentityState;
|
|
92
|
+
//# sourceMappingURL=process-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-identity.d.ts","sourceRoot":"","sources":["../../../../maestro/adapters/pi/process-identity.ts"],"names":[],"mappings":"AA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BAAoB,CAiCtB;AAED,eAAO,MAAM,iBAAiB,sBAA4B,CAAC;AAE3D;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,CACtC,GAAG,EAAE,MAAM,KACP,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;AAErC,wBAAgB,mCAAmC,CAClD,IAAI,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAA6C,GACnE,wBAAwB,CAsB1B;AAED,eAAO,MAAM,2BAA2B,0BACF,CAAC;AAEvC,iFAAiF;AACjF,wBAAgB,sBAAsB,CACrC,KAAK,GAAE,oBAAwC,GAC7C,iBAAiB,CAKnB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,uBAAuB,GAC7B,IAAI,CAWN;AAED,+EAA+E;AAC/E,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,MAAM,GACV,uBAAuB,GAAG,SAAS,CAyCrC;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,GAAE,oBAAwC,GAC7C,oBAAoB,CA6BtB;AAID;;;GAGG;AACH,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC/D,KAAK,GAAE,oBAAwC,GAC7C,iBAAiB,CA0BnB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACvC,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,GAAE,oBAAwC,GAC7C,oBAAoB,CActB"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { linkSync, mkdirSync, readFileSync, readlinkSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { isFiniteNumber, isRecord, isString, } from "../../core/config/type-guards.js";
|
|
4
|
+
/** One sidecar per session, so a reused run ID can never inherit a record. */
|
|
5
|
+
export function getSubagentProcessIdentityFile(sessionFile) {
|
|
6
|
+
return `${sessionFile}.process.json`;
|
|
7
|
+
}
|
|
8
|
+
// `pid (comm) state ppid ...`: comm may hold spaces or parentheses, so fields
|
|
9
|
+
// are counted after the last `)`. Field 3 is index 0; starttime (22) is 19.
|
|
10
|
+
export function parseProcessStat(text) {
|
|
11
|
+
const fields = text.slice(text.lastIndexOf(")") + 2).split(" ");
|
|
12
|
+
const ppid = Number(fields[1]);
|
|
13
|
+
const startTime = fields[19];
|
|
14
|
+
if (!fields[0] ||
|
|
15
|
+
!Number.isInteger(ppid) ||
|
|
16
|
+
!startTime ||
|
|
17
|
+
!/^\d+$/.test(startTime))
|
|
18
|
+
throw new Error("unparseable /proc stat");
|
|
19
|
+
return { state: fields[0], ppid, startTime };
|
|
20
|
+
}
|
|
21
|
+
function errnoCode(error) {
|
|
22
|
+
// SAFETY: fs and process.kill failures are Node errors with an optional code.
|
|
23
|
+
return error.code;
|
|
24
|
+
}
|
|
25
|
+
/** Linux `/proc` facts; the reader is injectable only for error-path tests. */
|
|
26
|
+
export function createLinuxProcessProbe(read = (path) => readFileSync(path, "utf8")) {
|
|
27
|
+
return {
|
|
28
|
+
host() {
|
|
29
|
+
if (process.platform !== "linux")
|
|
30
|
+
throw new Error(`process identity is unsupported on ${process.platform}; only Linux /proc is read`);
|
|
31
|
+
// /proc must describe this process's own PID namespace before any PID read
|
|
32
|
+
// through it is evidence.
|
|
33
|
+
const self = read("/proc/self/stat");
|
|
34
|
+
parseProcessStat(self);
|
|
35
|
+
if (Number(self.slice(0, self.indexOf(" "))) !== process.pid)
|
|
36
|
+
throw new Error("/proc does not describe this process's PID namespace");
|
|
37
|
+
return {
|
|
38
|
+
bootId: read("/proc/sys/kernel/random/boot_id").trim(),
|
|
39
|
+
pidNamespace: readlinkSync("/proc/self/ns/pid"),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
stat(pid) {
|
|
43
|
+
let text;
|
|
44
|
+
try {
|
|
45
|
+
text = read(`/proc/${pid}/stat`);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const code = error instanceof Error ? errnoCode(error) : undefined;
|
|
49
|
+
if (code === "ENOENT" || code === "ESRCH")
|
|
50
|
+
return undefined;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
return parseProcessStat(text);
|
|
54
|
+
},
|
|
55
|
+
terminate(pid) {
|
|
56
|
+
process.kill(pid, "SIGTERM");
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export const linuxProcessProbe = createLinuxProcessProbe();
|
|
61
|
+
export function createLinuxProcessEnvironmentReader(read = (path) => readFileSync(path, "utf8")) {
|
|
62
|
+
return (pid) => {
|
|
63
|
+
if (process.platform !== "linux")
|
|
64
|
+
throw new Error(`process environment is unreadable on ${process.platform}; only Linux /proc is read`);
|
|
65
|
+
let text;
|
|
66
|
+
try {
|
|
67
|
+
text = read(`/proc/${pid}/environ`);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const code = error instanceof Error ? errnoCode(error) : undefined;
|
|
71
|
+
if (code === "ENOENT" || code === "ESRCH")
|
|
72
|
+
return undefined;
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
const environment = new Map();
|
|
76
|
+
for (const entry of text.split("\0")) {
|
|
77
|
+
const separator = entry.indexOf("=");
|
|
78
|
+
if (separator > 0 && !environment.has(entry.slice(0, separator)))
|
|
79
|
+
environment.set(entry.slice(0, separator), entry.slice(separator + 1));
|
|
80
|
+
}
|
|
81
|
+
return environment;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export const readLinuxProcessEnvironment = createLinuxProcessEnvironmentReader();
|
|
85
|
+
/** The calling process's identity; throws when this host cannot establish it. */
|
|
86
|
+
export function readOwnProcessIdentity(probe = linuxProcessProbe) {
|
|
87
|
+
const host = probe.host();
|
|
88
|
+
const stat = probe.stat(process.pid);
|
|
89
|
+
if (!stat)
|
|
90
|
+
throw new Error("own /proc stat is missing");
|
|
91
|
+
return { pid: process.pid, startTime: stat.startTime, ...host };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Publish the record atomically and only once: a torn read is impossible and
|
|
95
|
+
* a later writer (a reload in the same process, or any other process) never
|
|
96
|
+
* replaces the first identity.
|
|
97
|
+
*/
|
|
98
|
+
export function writeProcessIdentityRecord(file, record) {
|
|
99
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
100
|
+
const temporary = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
101
|
+
writeFileSync(temporary, JSON.stringify(record), { flag: "wx" });
|
|
102
|
+
try {
|
|
103
|
+
linkSync(temporary, file);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (!(error instanceof Error) || errnoCode(error) !== "EEXIST")
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
unlinkSync(temporary);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** `undefined` until the child has published; throws on a malformed record. */
|
|
114
|
+
export function readProcessIdentityRecord(file) {
|
|
115
|
+
let text;
|
|
116
|
+
try {
|
|
117
|
+
text = readFileSync(file, "utf8");
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error instanceof Error && errnoCode(error) === "ENOENT")
|
|
121
|
+
return undefined;
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
let value;
|
|
125
|
+
try {
|
|
126
|
+
const parsed = JSON.parse(text);
|
|
127
|
+
if (isRecord(parsed))
|
|
128
|
+
value = parsed;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Malformed JSON is the same failure as a malformed record below.
|
|
132
|
+
}
|
|
133
|
+
if (!value ||
|
|
134
|
+
value.version !== 1 ||
|
|
135
|
+
!isString(value.id) ||
|
|
136
|
+
!isString(value.sessionFile) ||
|
|
137
|
+
!isFiniteNumber(value.pid) ||
|
|
138
|
+
!Number.isInteger(value.pid) ||
|
|
139
|
+
value.pid <= 0 ||
|
|
140
|
+
!isString(value.startTime) ||
|
|
141
|
+
!/^\d+$/.test(value.startTime) ||
|
|
142
|
+
!isString(value.bootId) ||
|
|
143
|
+
!value.bootId ||
|
|
144
|
+
!isString(value.pidNamespace) ||
|
|
145
|
+
!value.pidNamespace)
|
|
146
|
+
throw new Error(`malformed process identity record ${file}`);
|
|
147
|
+
return {
|
|
148
|
+
version: 1,
|
|
149
|
+
id: value.id,
|
|
150
|
+
sessionFile: value.sessionFile,
|
|
151
|
+
pid: value.pid,
|
|
152
|
+
startTime: value.startTime,
|
|
153
|
+
bootId: value.bootId,
|
|
154
|
+
pidNamespace: value.pidNamespace,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Whether THAT process still exists. Only an absent PID or a zombie is exit
|
|
159
|
+
* evidence; a different start time, another boot or namespace, or any read
|
|
160
|
+
* failure is unknown, never guessed exited.
|
|
161
|
+
*/
|
|
162
|
+
export function judgeProcessIdentity(identity, probe = linuxProcessProbe) {
|
|
163
|
+
let stat;
|
|
164
|
+
try {
|
|
165
|
+
const host = probe.host();
|
|
166
|
+
if (host.bootId !== identity.bootId)
|
|
167
|
+
return {
|
|
168
|
+
kind: "unknown",
|
|
169
|
+
reason: `process ${identity.pid} was recorded on another boot or host`,
|
|
170
|
+
};
|
|
171
|
+
if (host.pidNamespace !== identity.pidNamespace)
|
|
172
|
+
return {
|
|
173
|
+
kind: "unknown",
|
|
174
|
+
reason: `process ${identity.pid} was recorded in another PID namespace (${identity.pidNamespace}, not ${host.pidNamespace})`,
|
|
175
|
+
};
|
|
176
|
+
stat = probe.stat(identity.pid);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
return {
|
|
180
|
+
kind: "unknown",
|
|
181
|
+
reason: `process ${identity.pid} is unreadable: ${error instanceof Error ? error.message : String(error)}`,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (!stat)
|
|
185
|
+
return { kind: "exited" };
|
|
186
|
+
if (stat.startTime !== identity.startTime)
|
|
187
|
+
return {
|
|
188
|
+
kind: "unknown",
|
|
189
|
+
reason: `PID ${identity.pid} now names a different process (start time ${stat.startTime}, recorded ${identity.startTime})`,
|
|
190
|
+
};
|
|
191
|
+
if (stat.state === "Z" || stat.state === "X")
|
|
192
|
+
return { kind: "exited" };
|
|
193
|
+
return { kind: "alive" };
|
|
194
|
+
}
|
|
195
|
+
const MAX_ANCESTRY_DEPTH = 64;
|
|
196
|
+
/**
|
|
197
|
+
* Accept a child's record only for this run and session, while it is alive in
|
|
198
|
+
* this host's namespace, and only as the pane shell or a descendant of it.
|
|
199
|
+
*/
|
|
200
|
+
export function verifyProcessIdentityRecord(record, expected, probe = linuxProcessProbe) {
|
|
201
|
+
if (record.id !== expected.id || record.sessionFile !== expected.sessionFile)
|
|
202
|
+
throw new Error("process identity record belongs to another run");
|
|
203
|
+
const identity = {
|
|
204
|
+
pid: record.pid,
|
|
205
|
+
startTime: record.startTime,
|
|
206
|
+
bootId: record.bootId,
|
|
207
|
+
pidNamespace: record.pidNamespace,
|
|
208
|
+
};
|
|
209
|
+
const state = judgeProcessIdentity(identity, probe);
|
|
210
|
+
if (state.kind !== "alive")
|
|
211
|
+
throw new Error(state.kind === "exited"
|
|
212
|
+
? `process ${identity.pid} exited before its identity was verified`
|
|
213
|
+
: state.reason);
|
|
214
|
+
let pid = identity.pid;
|
|
215
|
+
for (let depth = 0; depth < MAX_ANCESTRY_DEPTH; depth++) {
|
|
216
|
+
if (pid === expected.shellPid)
|
|
217
|
+
return identity;
|
|
218
|
+
const stat = probe.stat(pid);
|
|
219
|
+
if (!stat || stat.ppid <= 0)
|
|
220
|
+
break;
|
|
221
|
+
pid = stat.ppid;
|
|
222
|
+
}
|
|
223
|
+
throw new Error(`process ${identity.pid} is not the Herdr pane shell ${expected.shellPid} or its descendant`);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* SIGTERM only the recorded identity, re-verified immediately before the
|
|
227
|
+
* signal. A mismatch or unreadable state is never signalled. The kernel can
|
|
228
|
+
* still reuse the PID between that read and `kill(2)`; Node exposes no pidfd
|
|
229
|
+
* signal to close the window.
|
|
230
|
+
*/
|
|
231
|
+
export function terminateProcessIdentity(identity, probe = linuxProcessProbe) {
|
|
232
|
+
const state = judgeProcessIdentity(identity, probe);
|
|
233
|
+
if (state.kind !== "alive")
|
|
234
|
+
return state;
|
|
235
|
+
try {
|
|
236
|
+
probe.terminate(identity.pid);
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (error instanceof Error && errnoCode(error) === "ESRCH")
|
|
240
|
+
return { kind: "exited" };
|
|
241
|
+
return {
|
|
242
|
+
kind: "unknown",
|
|
243
|
+
reason: `SIGTERM to process ${identity.pid} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return state;
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=process-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-identity.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/process-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,aAAa,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACN,cAAc,EACd,QAAQ,EACR,QAAQ,GAER,MAAM,kCAAkC,CAAC;AAgB1C,8EAA8E;AAC9E,MAAM,UAAU,8BAA8B,CAAC,WAAmB;IACjE,OAAO,GAAG,WAAW,eAAe,CAAC;AACtC,CAAC;AA+BD,8EAA8E;AAC9E,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,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IAAI,CAAC;QACJ,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,KAAK,YAAY,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,OAAO;YACzD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC3B,OAAO;YACN,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,sBAAsB,QAAQ,CAAC,GAAG,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAC9G,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import {\n\tlinkSync,\n\tmkdirSync,\n\treadFileSync,\n\treadlinkSync,\n\tunlinkSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport {\n\tisFiniteNumber,\n\tisRecord,\n\tisString,\n\ttype JsonObject,\n} from \"../../core/config/type-guards.ts\";\n\n/**\n * Immutable kernel facts naming one Pi child process for its whole life.\n * Mutable command-line text (Pi rewrites `process.title`) is never identity.\n */\nexport interface PiProcessIdentity {\n\tpid: number;\n\t/** `/proc/<pid>/stat` field 22: clock ticks after boot, fixed at fork. */\n\tstartTime: string;\n\t/** `/proc/sys/kernel/random/boot_id`; start times are per boot. */\n\tbootId: string;\n\t/** `/proc/self/ns/pid` link target; PIDs are per PID namespace. */\n\tpidNamespace: string;\n}\n\n/** One sidecar per session, so a reused run ID can never inherit a record. */\nexport function getSubagentProcessIdentityFile(sessionFile: string): string {\n\treturn `${sessionFile}.process.json`;\n}\n\n/** The child's self-recorded identity sidecar, bound to one run and session. */\nexport interface PiProcessIdentityRecord extends PiProcessIdentity {\n\tversion: 1;\n\tid: string;\n\tsessionFile: string;\n}\n\nexport interface ProcessStat {\n\t/** Single-letter state; Z (zombie) and X (dead) have exited. */\n\tstate: string;\n\tppid: number;\n\tstartTime: string;\n}\n\n/** This host's kernel process facts; tests inject a fake. */\nexport interface ProcessIdentityProbe {\n\t/** The calling process's namespace facts; throws when unreadable or unsupported. */\n\thost(): { bootId: string; pidNamespace: string };\n\t/** `undefined` only when no such PID exists; throws on any other read failure. */\n\tstat(pid: number): ProcessStat | undefined;\n\t/** Sends SIGTERM to a PID; throws ESRCH when it is already gone. */\n\tterminate(pid: number): void;\n}\n\nexport type ProcessIdentityState =\n\t| { kind: \"alive\" }\n\t| { kind: \"exited\" }\n\t| { kind: \"unknown\"; reason: string };\n\n// `pid (comm) state ppid ...`: comm may hold spaces or parentheses, so fields\n// are counted after the last `)`. Field 3 is index 0; starttime (22) is 19.\nexport function parseProcessStat(text: string): ProcessStat {\n\tconst fields = text.slice(text.lastIndexOf(\")\") + 2).split(\" \");\n\tconst ppid = Number(fields[1]);\n\tconst startTime = fields[19];\n\tif (\n\t\t!fields[0] ||\n\t\t!Number.isInteger(ppid) ||\n\t\t!startTime ||\n\t\t!/^\\d+$/.test(startTime)\n\t)\n\t\tthrow new Error(\"unparseable /proc stat\");\n\treturn { state: fields[0], ppid, startTime };\n}\n\nfunction errnoCode(error: Error): string | undefined {\n\t// SAFETY: fs and process.kill failures are Node errors with an optional code.\n\treturn (error as NodeJS.ErrnoException).code;\n}\n\n/** Linux `/proc` facts; the reader is injectable only for error-path tests. */\nexport function createLinuxProcessProbe(\n\tread: (path: string) => string = (path) => readFileSync(path, \"utf8\"),\n): ProcessIdentityProbe {\n\treturn {\n\t\thost() {\n\t\t\tif (process.platform !== \"linux\")\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`process identity is unsupported on ${process.platform}; only Linux /proc is read`,\n\t\t\t\t);\n\t\t\t// /proc must describe this process's own PID namespace before any PID read\n\t\t\t// through it is evidence.\n\t\t\tconst self = read(\"/proc/self/stat\");\n\t\t\tparseProcessStat(self);\n\t\t\tif (Number(self.slice(0, self.indexOf(\" \"))) !== process.pid)\n\t\t\t\tthrow new Error(\"/proc does not describe this process's PID namespace\");\n\t\t\treturn {\n\t\t\t\tbootId: read(\"/proc/sys/kernel/random/boot_id\").trim(),\n\t\t\t\tpidNamespace: readlinkSync(\"/proc/self/ns/pid\"),\n\t\t\t};\n\t\t},\n\t\tstat(pid) {\n\t\t\tlet text: string;\n\t\t\ttry {\n\t\t\t\ttext = read(`/proc/${pid}/stat`);\n\t\t\t} catch (error) {\n\t\t\t\tconst code = error instanceof Error ? errnoCode(error) : undefined;\n\t\t\t\tif (code === \"ENOENT\" || code === \"ESRCH\") return undefined;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn parseProcessStat(text);\n\t\t},\n\t\tterminate(pid) {\n\t\t\tprocess.kill(pid, \"SIGTERM\");\n\t\t},\n\t};\n}\n\nexport const linuxProcessProbe = createLinuxProcessProbe();\n\n/**\n * A process's environment as it was at exec. Unlike its command line, Pi's\n * process-title rewrite leaves this intact. `undefined` only when no such PID\n * exists; throws on non-Linux hosts and any other read failure.\n */\nexport type ProcessEnvironmentReader = (\n\tpid: number,\n) => Map<string, string> | undefined;\n\nexport function createLinuxProcessEnvironmentReader(\n\tread: (path: string) => string = (path) => readFileSync(path, \"utf8\"),\n): ProcessEnvironmentReader {\n\treturn (pid) => {\n\t\tif (process.platform !== \"linux\")\n\t\t\tthrow new Error(\n\t\t\t\t`process environment is unreadable on ${process.platform}; only Linux /proc is read`,\n\t\t\t);\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = read(`/proc/${pid}/environ`);\n\t\t} catch (error) {\n\t\t\tconst code = error instanceof Error ? errnoCode(error) : undefined;\n\t\t\tif (code === \"ENOENT\" || code === \"ESRCH\") return undefined;\n\t\t\tthrow error;\n\t\t}\n\t\tconst environment = new Map<string, string>();\n\t\tfor (const entry of text.split(\"\\0\")) {\n\t\t\tconst separator = entry.indexOf(\"=\");\n\t\t\tif (separator > 0 && !environment.has(entry.slice(0, separator)))\n\t\t\t\tenvironment.set(entry.slice(0, separator), entry.slice(separator + 1));\n\t\t}\n\t\treturn environment;\n\t};\n}\n\nexport const readLinuxProcessEnvironment =\n\tcreateLinuxProcessEnvironmentReader();\n\n/** The calling process's identity; throws when this host cannot establish it. */\nexport function readOwnProcessIdentity(\n\tprobe: ProcessIdentityProbe = linuxProcessProbe,\n): PiProcessIdentity {\n\tconst host = probe.host();\n\tconst stat = probe.stat(process.pid);\n\tif (!stat) throw new Error(\"own /proc stat is missing\");\n\treturn { pid: process.pid, startTime: stat.startTime, ...host };\n}\n\n/**\n * Publish the record atomically and only once: a torn read is impossible and\n * a later writer (a reload in the same process, or any other process) never\n * replaces the first identity.\n */\nexport function writeProcessIdentityRecord(\n\tfile: string,\n\trecord: PiProcessIdentityRecord,\n): void {\n\tmkdirSync(dirname(file), { recursive: true });\n\tconst temporary = `${file}.${process.pid}.${Date.now()}.tmp`;\n\twriteFileSync(temporary, JSON.stringify(record), { flag: \"wx\" });\n\ttry {\n\t\tlinkSync(temporary, file);\n\t} catch (error) {\n\t\tif (!(error instanceof Error) || errnoCode(error) !== \"EEXIST\") throw error;\n\t} finally {\n\t\tunlinkSync(temporary);\n\t}\n}\n\n/** `undefined` until the child has published; throws on a malformed record. */\nexport function readProcessIdentityRecord(\n\tfile: string,\n): PiProcessIdentityRecord | undefined {\n\tlet text: string;\n\ttry {\n\t\ttext = readFileSync(file, \"utf8\");\n\t} catch (error) {\n\t\tif (error instanceof Error && errnoCode(error) === \"ENOENT\")\n\t\t\treturn undefined;\n\t\tthrow error;\n\t}\n\tlet value: JsonObject | undefined;\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(text);\n\t\tif (isRecord(parsed)) value = parsed;\n\t} catch {\n\t\t// Malformed JSON is the same failure as a malformed record below.\n\t}\n\tif (\n\t\t!value ||\n\t\tvalue.version !== 1 ||\n\t\t!isString(value.id) ||\n\t\t!isString(value.sessionFile) ||\n\t\t!isFiniteNumber(value.pid) ||\n\t\t!Number.isInteger(value.pid) ||\n\t\tvalue.pid <= 0 ||\n\t\t!isString(value.startTime) ||\n\t\t!/^\\d+$/.test(value.startTime) ||\n\t\t!isString(value.bootId) ||\n\t\t!value.bootId ||\n\t\t!isString(value.pidNamespace) ||\n\t\t!value.pidNamespace\n\t)\n\t\tthrow new Error(`malformed process identity record ${file}`);\n\treturn {\n\t\tversion: 1,\n\t\tid: value.id,\n\t\tsessionFile: value.sessionFile,\n\t\tpid: value.pid,\n\t\tstartTime: value.startTime,\n\t\tbootId: value.bootId,\n\t\tpidNamespace: value.pidNamespace,\n\t};\n}\n\n/**\n * Whether THAT process still exists. Only an absent PID or a zombie is exit\n * evidence; a different start time, another boot or namespace, or any read\n * failure is unknown, never guessed exited.\n */\nexport function judgeProcessIdentity(\n\tidentity: PiProcessIdentity,\n\tprobe: ProcessIdentityProbe = linuxProcessProbe,\n): ProcessIdentityState {\n\tlet stat: ProcessStat | undefined;\n\ttry {\n\t\tconst host = probe.host();\n\t\tif (host.bootId !== identity.bootId)\n\t\t\treturn {\n\t\t\t\tkind: \"unknown\",\n\t\t\t\treason: `process ${identity.pid} was recorded on another boot or host`,\n\t\t\t};\n\t\tif (host.pidNamespace !== identity.pidNamespace)\n\t\t\treturn {\n\t\t\t\tkind: \"unknown\",\n\t\t\t\treason: `process ${identity.pid} was recorded in another PID namespace (${identity.pidNamespace}, not ${host.pidNamespace})`,\n\t\t\t};\n\t\tstat = probe.stat(identity.pid);\n\t} catch (error) {\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\treason: `process ${identity.pid} is unreadable: ${error instanceof Error ? error.message : String(error)}`,\n\t\t};\n\t}\n\tif (!stat) return { kind: \"exited\" };\n\tif (stat.startTime !== identity.startTime)\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\treason: `PID ${identity.pid} now names a different process (start time ${stat.startTime}, recorded ${identity.startTime})`,\n\t\t};\n\tif (stat.state === \"Z\" || stat.state === \"X\") return { kind: \"exited\" };\n\treturn { kind: \"alive\" };\n}\n\nconst MAX_ANCESTRY_DEPTH = 64;\n\n/**\n * Accept a child's record only for this run and session, while it is alive in\n * this host's namespace, and only as the pane shell or a descendant of it.\n */\nexport function verifyProcessIdentityRecord(\n\trecord: PiProcessIdentityRecord,\n\texpected: { id: string; sessionFile: string; shellPid: number },\n\tprobe: ProcessIdentityProbe = linuxProcessProbe,\n): PiProcessIdentity {\n\tif (record.id !== expected.id || record.sessionFile !== expected.sessionFile)\n\t\tthrow new Error(\"process identity record belongs to another run\");\n\tconst identity: PiProcessIdentity = {\n\t\tpid: record.pid,\n\t\tstartTime: record.startTime,\n\t\tbootId: record.bootId,\n\t\tpidNamespace: record.pidNamespace,\n\t};\n\tconst state = judgeProcessIdentity(identity, probe);\n\tif (state.kind !== \"alive\")\n\t\tthrow new Error(\n\t\t\tstate.kind === \"exited\"\n\t\t\t\t? `process ${identity.pid} exited before its identity was verified`\n\t\t\t\t: state.reason,\n\t\t);\n\tlet pid = identity.pid;\n\tfor (let depth = 0; depth < MAX_ANCESTRY_DEPTH; depth++) {\n\t\tif (pid === expected.shellPid) return identity;\n\t\tconst stat = probe.stat(pid);\n\t\tif (!stat || stat.ppid <= 0) break;\n\t\tpid = stat.ppid;\n\t}\n\tthrow new Error(\n\t\t`process ${identity.pid} is not the Herdr pane shell ${expected.shellPid} or its descendant`,\n\t);\n}\n\n/**\n * SIGTERM only the recorded identity, re-verified immediately before the\n * signal. A mismatch or unreadable state is never signalled. The kernel can\n * still reuse the PID between that read and `kill(2)`; Node exposes no pidfd\n * signal to close the window.\n */\nexport function terminateProcessIdentity(\n\tidentity: PiProcessIdentity,\n\tprobe: ProcessIdentityProbe = linuxProcessProbe,\n): ProcessIdentityState {\n\tconst state = judgeProcessIdentity(identity, probe);\n\tif (state.kind !== \"alive\") return state;\n\ttry {\n\t\tprobe.terminate(identity.pid);\n\t} catch (error) {\n\t\tif (error instanceof Error && errnoCode(error) === \"ESRCH\")\n\t\t\treturn { kind: \"exited\" };\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\treason: `SIGTERM to process ${identity.pid} failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t};\n\t}\n\treturn state;\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Runs one command and reports whether it exited 0. */
|
|
2
|
+
export type CommandRunner = (command: string, args: string[]) => boolean;
|
|
3
|
+
export type AsyncCommandRunner = (command: string, args: string[]) => Promise<boolean>;
|
|
4
|
+
/**
|
|
5
|
+
* Seams for the Windows branch, so Linux tests can drive it. Production code
|
|
6
|
+
* passes nothing except `alive`.
|
|
7
|
+
*/
|
|
8
|
+
export interface ProcessTreeOptions {
|
|
9
|
+
platform?: NodeJS.Platform;
|
|
10
|
+
/** Where `SystemRoot` is read from; defaults to `process.env`. */
|
|
11
|
+
env?: NodeJS.ProcessEnv;
|
|
12
|
+
/** Blocking `taskkill`, for the `exit` hook and the final sweep. */
|
|
13
|
+
run?: CommandRunner;
|
|
14
|
+
/** Non-blocking `taskkill`, for everything on Pi's main thread. */
|
|
15
|
+
runAsync?: AsyncCommandRunner;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the shell that leads the tree is still running. Once it has
|
|
18
|
+
* exited its pid is free to be reused by an unrelated process, and
|
|
19
|
+
* `taskkill /T` cannot find a dead root's descendants anyway, so on Windows
|
|
20
|
+
* a false answer means no tree kill is attempted. POSIX ignores it: a process
|
|
21
|
+
* group outlives its leader and `kill(-pid)` only reaches that group.
|
|
22
|
+
*/
|
|
23
|
+
alive?: () => boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Signal a process and everything it started. POSIX children are spawned
|
|
27
|
+
* `detached`, so each leads its own process group and `kill(-pid)` reaches the
|
|
28
|
+
* whole tree. Windows has no process groups or signals: `taskkill /T /F`
|
|
29
|
+
* force-ends the process and its descendants instead, so every signal (even
|
|
30
|
+
* SIGTERM) is final there and a grace period before SIGKILL buys nothing.
|
|
31
|
+
*
|
|
32
|
+
* This form blocks (up to the `taskkill` timeout on Windows), so it is for the
|
|
33
|
+
* `exit` hook and the final shutdown sweep. Everything else uses
|
|
34
|
+
* `signalProcessTree`.
|
|
35
|
+
*
|
|
36
|
+
* Returns whether the signal was delivered. False is not an error: the
|
|
37
|
+
* process may already be gone, and Windows cannot find the descendants of a
|
|
38
|
+
* parent that has already exited.
|
|
39
|
+
*/
|
|
40
|
+
export declare function killProcessTree(pid: number, signal: NodeJS.Signals, options?: ProcessTreeOptions): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Like `killProcessTree`, but never blocks: on Windows `taskkill` runs
|
|
43
|
+
* asynchronously. `onMiss` runs when nothing was signalled (the group is gone,
|
|
44
|
+
* `taskkill` found nothing or failed, or the shell had already exited), so the
|
|
45
|
+
* caller can fall back to signalling the shell alone.
|
|
46
|
+
*/
|
|
47
|
+
export declare function signalProcessTree(pid: number, signal: NodeJS.Signals, onMiss: () => void, options?: ProcessTreeOptions): void;
|
|
48
|
+
//# sourceMappingURL=process-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-tree.d.ts","sourceRoot":"","sources":["../../../../maestro/adapters/pi/process-tree.ts"],"names":[],"mappings":"AAMA,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;AACzE,MAAM,MAAM,kBAAkB,GAAG,CAChC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,KACV,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,oEAAoE;IACpE,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC;CACtB;AA6BD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,OAAO,EACtB,OAAO,GAAE,kBAAuB,GAC9B,OAAO,CAcT;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,OAAO,EACtB,MAAM,EAAE,MAAM,IAAI,EAClB,OAAO,GAAE,kBAAuB,GAC9B,IAAI,CAYN"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { execFile, spawnSync } from "node:child_process";
|
|
2
|
+
import { win32 } from "node:path";
|
|
3
|
+
/** `taskkill` is a quick local call; this bounds it if the system is wedged. */
|
|
4
|
+
const TASKKILL_TIMEOUT_MS = 5_000;
|
|
5
|
+
const runSync = (command, args) => spawnSync(command, args, {
|
|
6
|
+
stdio: "ignore",
|
|
7
|
+
windowsHide: true,
|
|
8
|
+
timeout: TASKKILL_TIMEOUT_MS,
|
|
9
|
+
}).status === 0;
|
|
10
|
+
const runAsync = (command, args) => new Promise((resolve) => {
|
|
11
|
+
execFile(command, args, { windowsHide: true, timeout: TASKKILL_TIMEOUT_MS }, (error) => resolve(error === null));
|
|
12
|
+
});
|
|
13
|
+
/** `taskkill` from System32, so a `PATH` entry cannot stand in for it. */
|
|
14
|
+
function taskkillCommand(env) {
|
|
15
|
+
const root = env.SystemRoot ?? env.SYSTEMROOT ?? env.windir ?? "C:\\Windows";
|
|
16
|
+
return win32.join(root, "System32", "taskkill.exe");
|
|
17
|
+
}
|
|
18
|
+
function taskkillArguments(pid) {
|
|
19
|
+
return ["/PID", String(pid), "/T", "/F"];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Signal a process and everything it started. POSIX children are spawned
|
|
23
|
+
* `detached`, so each leads its own process group and `kill(-pid)` reaches the
|
|
24
|
+
* whole tree. Windows has no process groups or signals: `taskkill /T /F`
|
|
25
|
+
* force-ends the process and its descendants instead, so every signal (even
|
|
26
|
+
* SIGTERM) is final there and a grace period before SIGKILL buys nothing.
|
|
27
|
+
*
|
|
28
|
+
* This form blocks (up to the `taskkill` timeout on Windows), so it is for the
|
|
29
|
+
* `exit` hook and the final shutdown sweep. Everything else uses
|
|
30
|
+
* `signalProcessTree`.
|
|
31
|
+
*
|
|
32
|
+
* Returns whether the signal was delivered. False is not an error: the
|
|
33
|
+
* process may already be gone, and Windows cannot find the descendants of a
|
|
34
|
+
* parent that has already exited.
|
|
35
|
+
*/
|
|
36
|
+
export function killProcessTree(pid, signal, options = {}) {
|
|
37
|
+
if ((options.platform ?? process.platform) === "win32") {
|
|
38
|
+
if (options.alive && !options.alive())
|
|
39
|
+
return false;
|
|
40
|
+
return (options.run ?? runSync)(taskkillCommand(options.env ?? process.env), taskkillArguments(pid));
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
process.kill(-pid, signal);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Like `killProcessTree`, but never blocks: on Windows `taskkill` runs
|
|
52
|
+
* asynchronously. `onMiss` runs when nothing was signalled (the group is gone,
|
|
53
|
+
* `taskkill` found nothing or failed, or the shell had already exited), so the
|
|
54
|
+
* caller can fall back to signalling the shell alone.
|
|
55
|
+
*/
|
|
56
|
+
export function signalProcessTree(pid, signal, onMiss, options = {}) {
|
|
57
|
+
if ((options.platform ?? process.platform) !== "win32") {
|
|
58
|
+
if (!killProcessTree(pid, signal, options))
|
|
59
|
+
onMiss();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (options.alive && !options.alive())
|
|
63
|
+
return onMiss();
|
|
64
|
+
(options.runAsync ?? runAsync)(taskkillCommand(options.env ?? process.env), taskkillArguments(pid)).then((delivered) => {
|
|
65
|
+
if (!delivered)
|
|
66
|
+
onMiss();
|
|
67
|
+
}, onMiss);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=process-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-tree.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/process-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,gFAAgF;AAChF,MAAM,mBAAmB,GAAG,KAAK,CAAC;AA+BlC,MAAM,OAAO,GAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAChD,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE;IACxB,KAAK,EAAE,QAAQ;IACf,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,mBAAmB;CAC5B,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAEjB,MAAM,QAAQ,GAAuB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CACtD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACvB,QAAQ,CACP,OAAO,EACP,IAAI,EACJ,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,mBAAmB,EAAE,EACnD,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC,CAClC,CAAC;AACH,CAAC,CAAC,CAAC;AAEJ,0EAA0E;AAC1E,SAAS,eAAe,CAAC,GAAsB;IAC9C,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,MAAM,IAAI,aAAa,CAAC;IAC7E,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACrC,OAAO,CAAC,MAAM,E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,EAC3C,iBAAiB,CAAC,GAAG,CAAC,CACtB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;QACpB,IAAI,CAAC,SAAS;YAAE,MAAM,EAAE,CAAC;IAC1B,CAAC,EAAE,MAAM,CAAC,CAAC;AACZ,CAAC","sourcesContent":["import { execFile, spawnSync } from \"node:child_process\";\nimport { win32 } from \"node:path\";\n\n/** `taskkill` is a quick local call; this bounds it if the system is wedged. */\nconst TASKKILL_TIMEOUT_MS = 5_000;\n\n/** Runs one command and reports whether it exited 0. */\nexport type CommandRunner = (command: string, args: string[]) => boolean;\nexport type AsyncCommandRunner = (\n\tcommand: string,\n\targs: string[],\n) => Promise<boolean>;\n\n/**\n * Seams for the Windows branch, so Linux tests can drive it. Production code\n * passes nothing except `alive`.\n */\nexport interface ProcessTreeOptions {\n\tplatform?: NodeJS.Platform;\n\t/** Where `SystemRoot` is read from; defaults to `process.env`. */\n\tenv?: NodeJS.ProcessEnv;\n\t/** Blocking `taskkill`, for the `exit` hook and the final sweep. */\n\trun?: CommandRunner;\n\t/** Non-blocking `taskkill`, for everything on Pi's main thread. */\n\trunAsync?: AsyncCommandRunner;\n\t/**\n\t * Whether the shell that leads the tree is still running. Once it has\n\t * exited its pid is free to be reused by an unrelated process, and\n\t * `taskkill /T` cannot find a dead root's descendants anyway, so on Windows\n\t * a false answer means no tree kill is attempted. POSIX ignores it: a process\n\t * group outlives its leader and `kill(-pid)` only reaches that group.\n\t */\n\talive?: () => boolean;\n}\n\nconst runSync: CommandRunner = (command, args) =>\n\tspawnSync(command, args, {\n\t\tstdio: \"ignore\",\n\t\twindowsHide: true,\n\t\ttimeout: TASKKILL_TIMEOUT_MS,\n\t}).status === 0;\n\nconst runAsync: AsyncCommandRunner = (command, args) =>\n\tnew Promise((resolve) => {\n\t\texecFile(\n\t\t\tcommand,\n\t\t\targs,\n\t\t\t{ windowsHide: true, timeout: TASKKILL_TIMEOUT_MS },\n\t\t\t(error) => resolve(error === null),\n\t\t);\n\t});\n\n/** `taskkill` from System32, so a `PATH` entry cannot stand in for it. */\nfunction taskkillCommand(env: NodeJS.ProcessEnv): string {\n\tconst root = env.SystemRoot ?? env.SYSTEMROOT ?? env.windir ?? \"C:\\\\Windows\";\n\treturn win32.join(root, \"System32\", \"taskkill.exe\");\n}\n\nfunction taskkillArguments(pid: number): string[] {\n\treturn [\"/PID\", String(pid), \"/T\", \"/F\"];\n}\n\n/**\n * Signal a process and everything it started. POSIX children are spawned\n * `detached`, so each leads its own process group and `kill(-pid)` reaches the\n * whole tree. Windows has no process groups or signals: `taskkill /T /F`\n * force-ends the process and its descendants instead, so every signal (even\n * SIGTERM) is final there and a grace period before SIGKILL buys nothing.\n *\n * This form blocks (up to the `taskkill` timeout on Windows), so it is for the\n * `exit` hook and the final shutdown sweep. Everything else uses\n * `signalProcessTree`.\n *\n * Returns whether the signal was delivered. False is not an error: the\n * process may already be gone, and Windows cannot find the descendants of a\n * parent that has already exited.\n */\nexport function killProcessTree(\n\tpid: number,\n\tsignal: NodeJS.Signals,\n\toptions: ProcessTreeOptions = {},\n): boolean {\n\tif ((options.platform ?? process.platform) === \"win32\") {\n\t\tif (options.alive && !options.alive()) return false;\n\t\treturn (options.run ?? runSync)(\n\t\t\ttaskkillCommand(options.env ?? process.env),\n\t\t\ttaskkillArguments(pid),\n\t\t);\n\t}\n\ttry {\n\t\tprocess.kill(-pid, signal);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Like `killProcessTree`, but never blocks: on Windows `taskkill` runs\n * asynchronously. `onMiss` runs when nothing was signalled (the group is gone,\n * `taskkill` found nothing or failed, or the shell had already exited), so the\n * caller can fall back to signalling the shell alone.\n */\nexport function signalProcessTree(\n\tpid: number,\n\tsignal: NodeJS.Signals,\n\tonMiss: () => void,\n\toptions: ProcessTreeOptions = {},\n): void {\n\tif ((options.platform ?? process.platform) !== \"win32\") {\n\t\tif (!killProcessTree(pid, signal, options)) onMiss();\n\t\treturn;\n\t}\n\tif (options.alive && !options.alive()) return onMiss();\n\t(options.runAsync ?? runAsync)(\n\t\ttaskkillCommand(options.env ?? process.env),\n\t\ttaskkillArguments(pid),\n\t).then((delivered) => {\n\t\tif (!delivered) onMiss();\n\t}, onMiss);\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ScriptShellResolver } from "../../core/script-launch.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Which settings the launch reads `shellPath` from: the launching session's
|
|
4
|
+
* directory and its project-trust decision, so an untrusted project cannot
|
|
5
|
+
* choose the executable and the host reads what the parent's bash tool reads.
|
|
6
|
+
*/
|
|
7
|
+
export interface PiScriptShellContext {
|
|
8
|
+
cwd: string;
|
|
9
|
+
projectTrusted: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface PiScriptShellDeps {
|
|
12
|
+
/** Pi's `shellPath` setting, as the bash tool reads it for this session. */
|
|
13
|
+
readShellPath: (context: PiScriptShellContext) => string | undefined;
|
|
14
|
+
/** Pi's bash-tool shell resolution; throws when no bash is found. */
|
|
15
|
+
resolveShell: (shellPath?: string) => {
|
|
16
|
+
shell: string;
|
|
17
|
+
};
|
|
18
|
+
/** Base Pi's own bash tool resolves a relative `shellPath` against. */
|
|
19
|
+
baseDir: () => string;
|
|
20
|
+
}
|
|
21
|
+
/** True when this Pi gates project-local settings behind a trust decision. */
|
|
22
|
+
export declare function piHasProjectTrustGating(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the launching session trusts its project. A context that reports its
|
|
25
|
+
* decision (`ctx.isProjectTrusted`, Pi 0.79.1 and later) is believed. A context
|
|
26
|
+
* that does not is untrusted when this Pi still gates project settings (0.79.0
|
|
27
|
+
* has the gate but no accessor), and trusted only when Pi has no trust concept
|
|
28
|
+
* at all (0.74 to 0.78), where it loads project settings unconditionally.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveProjectTrusted(reported: boolean | undefined, hasTrustGating?: boolean): boolean;
|
|
31
|
+
export declare const piScriptShellDeps: PiScriptShellDeps;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the bash that runs launch scripts the way Pi resolves it for its own
|
|
34
|
+
* bash tool: the `shellPath` setting (project settings only when the session
|
|
35
|
+
* trusts the project), then Git Bash, then bash on PATH, made absolute against
|
|
36
|
+
* the directory Pi resolves against. Pi's own error
|
|
37
|
+
* (missing custom path, no bash installed) propagates unchanged.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createPiScriptShellResolver(context: PiScriptShellContext, deps?: PiScriptShellDeps): ScriptShellResolver;
|
|
40
|
+
//# sourceMappingURL=script-shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-shell.d.ts","sourceRoot":"","sources":["../../../../maestro/adapters/pi/script-shell.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IACjC,4EAA4E;IAC5E,aAAa,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,MAAM,GAAG,SAAS,CAAC;IACrE,qEAAqE;IACrE,YAAY,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,uEAAuE;IACvE,OAAO,EAAE,MAAM,MAAM,CAAC;CACtB;AAED,8EAA8E;AAC9E,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAC7B,cAAc,GAAE,OAAmC,GACjD,OAAO,CAET;AAED,eAAO,MAAM,iBAAiB,EAAE,iBAS/B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAC1C,OAAO,EAAE,oBAAoB,EAC7B,IAAI,GAAE,iBAAqC,GACzC,mBAAmB,CASrB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getAgentDir, getShellConfig, SettingsManager, } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { isAbsolute, resolve, win32 } from "node:path";
|
|
3
|
+
/** True when this Pi gates project-local settings behind a trust decision. */
|
|
4
|
+
export function piHasProjectTrustGating() {
|
|
5
|
+
return "isProjectTrusted" in SettingsManager.prototype;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Whether the launching session trusts its project. A context that reports its
|
|
9
|
+
* decision (`ctx.isProjectTrusted`, Pi 0.79.1 and later) is believed. A context
|
|
10
|
+
* that does not is untrusted when this Pi still gates project settings (0.79.0
|
|
11
|
+
* has the gate but no accessor), and trusted only when Pi has no trust concept
|
|
12
|
+
* at all (0.74 to 0.78), where it loads project settings unconditionally.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveProjectTrusted(reported, hasTrustGating = piHasProjectTrustGating()) {
|
|
15
|
+
return reported ?? !hasTrustGating;
|
|
16
|
+
}
|
|
17
|
+
export const piScriptShellDeps = {
|
|
18
|
+
// `projectTrusted` is ignored by Pi releases without trust gating (0.74 to
|
|
19
|
+
// 0.78), which also load project settings unconditionally for the parent.
|
|
20
|
+
readShellPath: ({ cwd, projectTrusted }) => SettingsManager.create(cwd, getAgentDir(), {
|
|
21
|
+
projectTrusted,
|
|
22
|
+
}).getShellPath(),
|
|
23
|
+
resolveShell: getShellConfig,
|
|
24
|
+
baseDir: () => process.cwd(),
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the bash that runs launch scripts the way Pi resolves it for its own
|
|
28
|
+
* bash tool: the `shellPath` setting (project settings only when the session
|
|
29
|
+
* trusts the project), then Git Bash, then bash on PATH, made absolute against
|
|
30
|
+
* the directory Pi resolves against. Pi's own error
|
|
31
|
+
* (missing custom path, no bash installed) propagates unchanged.
|
|
32
|
+
*/
|
|
33
|
+
export function createPiScriptShellResolver(context, deps = piScriptShellDeps) {
|
|
34
|
+
return () => {
|
|
35
|
+
const shell = deps.resolveShell(deps.readShellPath(context)).shell;
|
|
36
|
+
// Pi validates a relative path against its own working directory; the
|
|
37
|
+
// pane starts elsewhere, so type the path that Pi checked.
|
|
38
|
+
return win32.isAbsolute(shell) || isAbsolute(shell)
|
|
39
|
+
? shell
|
|
40
|
+
: resolve(deps.baseDir(), shell);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=script-shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-shell.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/script-shell.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAAW,EACX,cAAc,EACd,eAAe,GACf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAsBvD,8EAA8E;AAC9E,MAAM,UAAU,uBAAuB;IACtC,OAAO,kBAAkB,IAAI,eAAe,CAAC,SAAS,CAAC;AACxD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACpC,QAA6B,EAC7B,iBAA0B,uBAAuB,EAAE;IAEnD,OAAO,QAAQ,IAAI,CAAC,cAAc,CAAC;AACpC,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAsB;IACnD,2EAA2E;IAC3E,0EAA0E;IAC1E,aAAa,EAAE,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,CAC1C,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,EAAE;QAC1C,cAAc;KACd,CAAC,CAAC,YAAY,EAAE;IAClB,YAAY,EAAE,cAAc;IAC5B,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAC1C,OAA6B,EAC7B,OAA0B,iBAAiB;IAE3C,OAAO,GAAG,EAAE;QACX,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;QACnE,sEAAsE;QACtE,2DAA2D;QAC3D,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC;YAClD,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC;AACH,CAAC","sourcesContent":["import {\n\tgetAgentDir,\n\tgetShellConfig,\n\tSettingsManager,\n} from \"@earendil-works/pi-coding-agent\";\nimport { isAbsolute, resolve, win32 } from \"node:path\";\nimport type { ScriptShellResolver } from \"../../core/script-launch.ts\";\n\n/**\n * Which settings the launch reads `shellPath` from: the launching session's\n * directory and its project-trust decision, so an untrusted project cannot\n * choose the executable and the host reads what the parent's bash tool reads.\n */\nexport interface PiScriptShellContext {\n\tcwd: string;\n\tprojectTrusted: boolean;\n}\n\nexport interface PiScriptShellDeps {\n\t/** Pi's `shellPath` setting, as the bash tool reads it for this session. */\n\treadShellPath: (context: PiScriptShellContext) => string | undefined;\n\t/** Pi's bash-tool shell resolution; throws when no bash is found. */\n\tresolveShell: (shellPath?: string) => { shell: string };\n\t/** Base Pi's own bash tool resolves a relative `shellPath` against. */\n\tbaseDir: () => string;\n}\n\n/** True when this Pi gates project-local settings behind a trust decision. */\nexport function piHasProjectTrustGating(): boolean {\n\treturn \"isProjectTrusted\" in SettingsManager.prototype;\n}\n\n/**\n * Whether the launching session trusts its project. A context that reports its\n * decision (`ctx.isProjectTrusted`, Pi 0.79.1 and later) is believed. A context\n * that does not is untrusted when this Pi still gates project settings (0.79.0\n * has the gate but no accessor), and trusted only when Pi has no trust concept\n * at all (0.74 to 0.78), where it loads project settings unconditionally.\n */\nexport function resolveProjectTrusted(\n\treported: boolean | undefined,\n\thasTrustGating: boolean = piHasProjectTrustGating(),\n): boolean {\n\treturn reported ?? !hasTrustGating;\n}\n\nexport const piScriptShellDeps: PiScriptShellDeps = {\n\t// `projectTrusted` is ignored by Pi releases without trust gating (0.74 to\n\t// 0.78), which also load project settings unconditionally for the parent.\n\treadShellPath: ({ cwd, projectTrusted }) =>\n\t\tSettingsManager.create(cwd, getAgentDir(), {\n\t\t\tprojectTrusted,\n\t\t}).getShellPath(),\n\tresolveShell: getShellConfig,\n\tbaseDir: () => process.cwd(),\n};\n\n/**\n * Resolve the bash that runs launch scripts the way Pi resolves it for its own\n * bash tool: the `shellPath` setting (project settings only when the session\n * trusts the project), then Git Bash, then bash on PATH, made absolute against\n * the directory Pi resolves against. Pi's own error\n * (missing custom path, no bash installed) propagates unchanged.\n */\nexport function createPiScriptShellResolver(\n\tcontext: PiScriptShellContext,\n\tdeps: PiScriptShellDeps = piScriptShellDeps,\n): ScriptShellResolver {\n\treturn () => {\n\t\tconst shell = deps.resolveShell(deps.readShellPath(context)).shell;\n\t\t// Pi validates a relative path against its own working directory; the\n\t\t// pane starts elsewhere, so type the path that Pi checked.\n\t\treturn win32.isAbsolute(shell) || isAbsolute(shell)\n\t\t\t? shell\n\t\t\t: resolve(deps.baseDir(), shell);\n\t};\n}\n"]}
|