@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,633 @@
|
|
|
1
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, renameSync, lstatSync, readdirSync, readFileSync, writeFileSync, unlinkSync, } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { isRecord } from "../core/config/type-guards.js";
|
|
6
|
+
import { gitEnvironment } from "../core/git-environment.js";
|
|
7
|
+
import { Deadline } from "../core/deadline.js";
|
|
8
|
+
import { realpathWithoutOpening } from "../core/realpath-without-opening.js";
|
|
9
|
+
import { isWorktreeManifest, mergeWorktreeManifest, } from "../core/worktree.js";
|
|
10
|
+
function message(error) {
|
|
11
|
+
return error instanceof Error ? error.message : String(error);
|
|
12
|
+
}
|
|
13
|
+
function contained(root, path) {
|
|
14
|
+
const rel = relative(root, path);
|
|
15
|
+
return (rel === "" ||
|
|
16
|
+
(rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)));
|
|
17
|
+
}
|
|
18
|
+
export const GIT_BASE_TIMEOUT_MS = 10_000;
|
|
19
|
+
export const GIT_SOURCE_TIMEOUT_MS = 15_000;
|
|
20
|
+
export const GIT_HANDOFF_TIMEOUT_MS = 15_000;
|
|
21
|
+
const GIT_OUTPUT_BYTES = 1024 * 1024;
|
|
22
|
+
/** One owned read client; expiry bounds the wait even if descendants hold pipes. */
|
|
23
|
+
async function gitRead(cwd, args, deadline) {
|
|
24
|
+
const timeout = deadline.remainingMs();
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const child = spawn("git", args, {
|
|
27
|
+
cwd,
|
|
28
|
+
env: gitEnvironment(),
|
|
29
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
30
|
+
detached: process.platform !== "win32",
|
|
31
|
+
});
|
|
32
|
+
let settled = false, bytes = 0, errorBytes = 0;
|
|
33
|
+
const output = [], errors = [];
|
|
34
|
+
const fail = (error) => {
|
|
35
|
+
if (settled)
|
|
36
|
+
return;
|
|
37
|
+
settled = true;
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
try {
|
|
40
|
+
if (process.platform !== "win32" && child.pid)
|
|
41
|
+
process.kill(-child.pid, "SIGKILL");
|
|
42
|
+
else
|
|
43
|
+
child.kill("SIGKILL");
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* already exited */
|
|
47
|
+
}
|
|
48
|
+
child.stdout.destroy();
|
|
49
|
+
child.stderr.destroy();
|
|
50
|
+
child.unref();
|
|
51
|
+
reject(error);
|
|
52
|
+
};
|
|
53
|
+
const timer = setTimeout(() => fail(new Error("Git inspection deadline exceeded")), timeout);
|
|
54
|
+
child.on("error", fail);
|
|
55
|
+
child.stdout.on("data", (chunk) => {
|
|
56
|
+
bytes += chunk.length;
|
|
57
|
+
if (bytes > GIT_OUTPUT_BYTES)
|
|
58
|
+
fail(new Error("Git output limit exceeded"));
|
|
59
|
+
else
|
|
60
|
+
output.push(chunk);
|
|
61
|
+
});
|
|
62
|
+
child.stderr.on("data", (chunk) => {
|
|
63
|
+
errorBytes += chunk.length;
|
|
64
|
+
if (errorBytes > GIT_OUTPUT_BYTES)
|
|
65
|
+
fail(new Error("Git error output limit exceeded"));
|
|
66
|
+
else
|
|
67
|
+
errors.push(chunk);
|
|
68
|
+
});
|
|
69
|
+
child.on("close", (code, signal) => {
|
|
70
|
+
if (settled)
|
|
71
|
+
return;
|
|
72
|
+
if (deadline.expired())
|
|
73
|
+
return fail(new Error("Git inspection deadline exceeded"));
|
|
74
|
+
if (code !== 0)
|
|
75
|
+
return fail(new Error(`Git exited ${code ?? signal}: ${Buffer.concat(errors).toString("utf8")}`));
|
|
76
|
+
settled = true;
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
resolve(Buffer.concat(output).toString("utf8"));
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function gitSha(output) {
|
|
83
|
+
const sha = output.trim();
|
|
84
|
+
if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(sha))
|
|
85
|
+
throw new Error("Git returned an invalid commit SHA");
|
|
86
|
+
return sha;
|
|
87
|
+
}
|
|
88
|
+
export async function resolveGitCommit(cwd, ref) {
|
|
89
|
+
return gitSha(await gitRead(cwd, ["rev-parse", "--verify", `${ref}^{commit}`], Deadline.after(GIT_BASE_TIMEOUT_MS)));
|
|
90
|
+
}
|
|
91
|
+
export async function resolveWorktreeProvisionCwd(sourceCwd) {
|
|
92
|
+
const deadline = Deadline.after(GIT_SOURCE_TIMEOUT_MS);
|
|
93
|
+
let gitDir;
|
|
94
|
+
let commonDir;
|
|
95
|
+
try {
|
|
96
|
+
gitDir = await resolveGitPath(sourceCwd, "--git-dir", deadline);
|
|
97
|
+
commonDir = await resolveGitPath(sourceCwd, "--git-common-dir", deadline);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
throw new Error(`Unable to identify the Git checkout for worktree provisioning from ${sourceCwd}: ${errorMessage(error)}`);
|
|
101
|
+
}
|
|
102
|
+
if (gitDir === commonDir)
|
|
103
|
+
return sourceCwd;
|
|
104
|
+
try {
|
|
105
|
+
const output = await gitRead(sourceCwd, ["worktree", "list", "--porcelain", "-z"], deadline);
|
|
106
|
+
const principal = output
|
|
107
|
+
.split("\0")
|
|
108
|
+
.find((record) => record.startsWith("worktree "))
|
|
109
|
+
?.slice("worktree ".length);
|
|
110
|
+
if (!principal)
|
|
111
|
+
throw new Error("Git returned no principal worktree");
|
|
112
|
+
return principal;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
throw new Error(`Unable to determine the principal Git checkout for linked worktree ${sourceCwd}: ${errorMessage(error)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function resolveGitPath(cwd, flag, deadline) {
|
|
119
|
+
const output = await gitRead(cwd, ["rev-parse", "--path-format=absolute", flag], deadline);
|
|
120
|
+
if (!output || output === "\n")
|
|
121
|
+
throw new Error("Git returned no checkout path");
|
|
122
|
+
return output.endsWith("\n") ? output.slice(0, -1) : output;
|
|
123
|
+
}
|
|
124
|
+
export function readWorktreeManifest(path) {
|
|
125
|
+
try {
|
|
126
|
+
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
127
|
+
if (isRecord(value) && isWorktreeManifest(value))
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Unreachable or malformed manifests do not establish ownership.
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
export function writeWorktreeManifest(path, value) {
|
|
136
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
137
|
+
let existing = {};
|
|
138
|
+
if (existsSync(path)) {
|
|
139
|
+
try {
|
|
140
|
+
existing = JSON.parse(readFileSync(path, "utf8"));
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
existing = {};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const tempPath = `${path}.tmp`;
|
|
147
|
+
writeFileSync(tempPath, `${JSON.stringify(mergeWorktreeManifest(existing, value, Date.now()), null, 2)}\n`);
|
|
148
|
+
renameSync(tempPath, path);
|
|
149
|
+
}
|
|
150
|
+
async function gitPathList(cwd, args, deadline) {
|
|
151
|
+
const output = await gitRead(cwd, args, deadline);
|
|
152
|
+
if (output && !output.endsWith("\0"))
|
|
153
|
+
throw new Error("Git returned an incomplete NUL filename list");
|
|
154
|
+
return output.split("\0").filter(Boolean);
|
|
155
|
+
}
|
|
156
|
+
export async function captureWorktreeHandoff(worktree, timeoutMs = GIT_HANDOFF_TIMEOUT_MS) {
|
|
157
|
+
const deadline = Deadline.after(timeoutMs);
|
|
158
|
+
try {
|
|
159
|
+
const headSha = gitSha(await gitRead(worktree.path, ["rev-parse", "--verify", "HEAD^{commit}"], deadline));
|
|
160
|
+
const status = await gitRead(worktree.path, ["status", "--porcelain=v1", "--untracked-files=all", "-z"], deadline);
|
|
161
|
+
if (status && !status.endsWith("\0"))
|
|
162
|
+
throw new Error("Git returned incomplete status");
|
|
163
|
+
const untrackedFiles = await gitPathList(worktree.path, ["ls-files", "--others", "--exclude-standard", "-z"], deadline);
|
|
164
|
+
const conflictedFiles = await gitPathList(worktree.path, ["diff", "--name-only", "--diff-filter=U", "-z"], deadline);
|
|
165
|
+
const changedFiles = new Set([
|
|
166
|
+
...(await gitPathList(worktree.path, ["diff", "--name-only", "-z", `${worktree.baseSha}...HEAD`], deadline)),
|
|
167
|
+
...(await gitPathList(worktree.path, ["diff", "--name-only", "-z"], deadline)),
|
|
168
|
+
...(await gitPathList(worktree.path, ["diff", "--cached", "--name-only", "-z"], deadline)),
|
|
169
|
+
...untrackedFiles,
|
|
170
|
+
]);
|
|
171
|
+
const count = (await gitRead(worktree.path, ["rev-list", "--count", `${worktree.baseSha}..HEAD`], deadline)).trim();
|
|
172
|
+
const commitsAhead = Number(count);
|
|
173
|
+
if (!/^(0|[1-9][0-9]*)$/.test(count) || !Number.isSafeInteger(commitsAhead))
|
|
174
|
+
throw new Error("Git returned an invalid commit count");
|
|
175
|
+
return {
|
|
176
|
+
...worktree,
|
|
177
|
+
headSha,
|
|
178
|
+
commitsAhead,
|
|
179
|
+
clean: status.length === 0,
|
|
180
|
+
conflicted: conflictedFiles.length > 0,
|
|
181
|
+
changedFiles: [...changedFiles].sort(),
|
|
182
|
+
untrackedFiles: untrackedFiles.sort(),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return {
|
|
187
|
+
...worktree,
|
|
188
|
+
headSha: null,
|
|
189
|
+
commitsAhead: null,
|
|
190
|
+
clean: null,
|
|
191
|
+
conflicted: null,
|
|
192
|
+
changedFiles: null,
|
|
193
|
+
untrackedFiles: null,
|
|
194
|
+
gitError: errorMessage(error),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function persistWorktreeResult(worktree, state, handoff) {
|
|
199
|
+
writeWorktreeManifest(worktree.manifestFile, {
|
|
200
|
+
state,
|
|
201
|
+
...worktree,
|
|
202
|
+
...handoff,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function errorMessage(error) {
|
|
206
|
+
return error instanceof Error ? error.message : String(error);
|
|
207
|
+
}
|
|
208
|
+
const CLEANUP_TIMEOUT_MS = 30_000;
|
|
209
|
+
function git(cwd, args) {
|
|
210
|
+
return execFileSync("git", args, {
|
|
211
|
+
cwd,
|
|
212
|
+
env: gitEnvironment(),
|
|
213
|
+
encoding: "utf8",
|
|
214
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
215
|
+
timeout: CLEANUP_TIMEOUT_MS,
|
|
216
|
+
killSignal: "SIGKILL",
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function exists(path) {
|
|
220
|
+
try {
|
|
221
|
+
lstatSync(path);
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
// SAFETY: filesystem calls throw Node errors with an optional errno code.
|
|
226
|
+
if (error.code === "ENOENT")
|
|
227
|
+
return false;
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function directories(path) {
|
|
232
|
+
if (!exists(path))
|
|
233
|
+
return [];
|
|
234
|
+
return readdirSync(path, { withFileTypes: true })
|
|
235
|
+
.filter((item) => item.isDirectory() || item.isSymbolicLink())
|
|
236
|
+
.map((item) => join(path, item.name));
|
|
237
|
+
}
|
|
238
|
+
/** Source identity is resolved independently of status so Git failures remain visible. */
|
|
239
|
+
function resolveSource(path) {
|
|
240
|
+
const common = realpathWithoutOpening(git(path, [
|
|
241
|
+
"rev-parse",
|
|
242
|
+
"--path-format=absolute",
|
|
243
|
+
"--git-common-dir",
|
|
244
|
+
]).trim());
|
|
245
|
+
// A submodule's common directory lives under the superproject's
|
|
246
|
+
// .git/modules; only core.worktree, including included config, names its checkout.
|
|
247
|
+
const configured = git(common, [
|
|
248
|
+
`--git-dir=${common}`,
|
|
249
|
+
"config",
|
|
250
|
+
"--default",
|
|
251
|
+
"",
|
|
252
|
+
"--get",
|
|
253
|
+
"core.worktree",
|
|
254
|
+
]).trim();
|
|
255
|
+
const root = realpathWithoutOpening(configured ? resolve(common, configured) : dirname(common));
|
|
256
|
+
if (realpathWithoutOpening(git(root, ["rev-parse", "--show-toplevel"]).trim()) !== root)
|
|
257
|
+
throw new Error("Cannot prove source repository root");
|
|
258
|
+
if (realpathWithoutOpening(git(root, [
|
|
259
|
+
"rev-parse",
|
|
260
|
+
"--path-format=absolute",
|
|
261
|
+
"--git-common-dir",
|
|
262
|
+
]).trim()) !== common)
|
|
263
|
+
throw new Error("Source Git directory mismatch");
|
|
264
|
+
return root;
|
|
265
|
+
}
|
|
266
|
+
/** Count NUL-delimited file paths without retaining the ignored-file listing. */
|
|
267
|
+
function countIgnoredFiles(cwd) {
|
|
268
|
+
return new Promise((resolve, reject) => {
|
|
269
|
+
const child = spawn("git", ["ls-files", "--others", "--ignored", "--exclude-standard", "-z"], {
|
|
270
|
+
cwd,
|
|
271
|
+
env: gitEnvironment(),
|
|
272
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
273
|
+
timeout: CLEANUP_TIMEOUT_MS,
|
|
274
|
+
killSignal: "SIGKILL",
|
|
275
|
+
});
|
|
276
|
+
let count = 0;
|
|
277
|
+
child.stdout.on("data", (chunk) => {
|
|
278
|
+
for (const byte of chunk)
|
|
279
|
+
if (byte === 0)
|
|
280
|
+
count++;
|
|
281
|
+
});
|
|
282
|
+
child.on("error", reject);
|
|
283
|
+
child.on("close", (code, signal) => {
|
|
284
|
+
if (code === 0)
|
|
285
|
+
resolve(count);
|
|
286
|
+
else
|
|
287
|
+
reject(new Error(`Ignored-file inspection failed (${signal ?? `exit ${code}`})`));
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
async function inspectGit(path, sourceRepo) {
|
|
292
|
+
const records = git(sourceRepo, ["worktree", "list", "--porcelain", "-z"])
|
|
293
|
+
.split("\0\0")
|
|
294
|
+
.map((record) => record.split("\0"));
|
|
295
|
+
const record = records.find((fields) => {
|
|
296
|
+
if (!fields[0]?.startsWith("worktree "))
|
|
297
|
+
return false;
|
|
298
|
+
const registeredPath = fields[0].slice("worktree ".length);
|
|
299
|
+
return (exists(registeredPath) && realpathWithoutOpening(registeredPath) === path);
|
|
300
|
+
});
|
|
301
|
+
// rev-parse returns HEAD for a detached checkout, without treating a valid
|
|
302
|
+
// detached state as an inspection error. Only named refs may be preserved.
|
|
303
|
+
const headRef = git(path, [
|
|
304
|
+
"rev-parse",
|
|
305
|
+
"--symbolic-full-name",
|
|
306
|
+
"HEAD",
|
|
307
|
+
]).trim();
|
|
308
|
+
const branch = headRef.startsWith("refs/heads/")
|
|
309
|
+
? headRef.slice("refs/heads/".length)
|
|
310
|
+
: "";
|
|
311
|
+
const status = git(path, [
|
|
312
|
+
"status",
|
|
313
|
+
"--porcelain=v1",
|
|
314
|
+
"--untracked-files=all",
|
|
315
|
+
"-z",
|
|
316
|
+
]);
|
|
317
|
+
let dirtyFiles = 0;
|
|
318
|
+
const fields = status.split("\0");
|
|
319
|
+
for (let i = 0; i < fields.length; i++) {
|
|
320
|
+
if (!fields[i])
|
|
321
|
+
continue;
|
|
322
|
+
dirtyFiles++;
|
|
323
|
+
if (/^[RC]|^.[RC]/.test(fields[i]))
|
|
324
|
+
i++;
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
branch,
|
|
328
|
+
headSha: git(path, ["rev-parse", "HEAD"]).trim(),
|
|
329
|
+
registered: !!record &&
|
|
330
|
+
path !== sourceRepo &&
|
|
331
|
+
(branch
|
|
332
|
+
? record.includes(`branch refs/heads/${branch}`)
|
|
333
|
+
: record.includes("detached")),
|
|
334
|
+
locked: !!record?.some((field) => field === "locked" || field.startsWith("locked ")),
|
|
335
|
+
dirtyFiles,
|
|
336
|
+
untrackedFiles: git(path, [
|
|
337
|
+
"ls-files",
|
|
338
|
+
"--others",
|
|
339
|
+
"--exclude-standard",
|
|
340
|
+
"-z",
|
|
341
|
+
])
|
|
342
|
+
.split("\0")
|
|
343
|
+
.filter(Boolean).length,
|
|
344
|
+
ignoredFiles: await countIgnoredFiles(path),
|
|
345
|
+
conflicts: git(path, ["diff", "--name-only", "--diff-filter=U", "-z"])
|
|
346
|
+
.split("\0")
|
|
347
|
+
.filter(Boolean).length,
|
|
348
|
+
submodules: git(path, ["submodule", "status", "--recursive"])
|
|
349
|
+
.split("\n")
|
|
350
|
+
.some((line) => line.length > 0 && !line.startsWith("-")),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/** Individual visibility gaps warn; failed enumeration still blocks cleanup. */
|
|
354
|
+
function processHolders(path, idleShellPids = new Set(), procRoot = "/proc", platform = process.platform) {
|
|
355
|
+
const blockers = [];
|
|
356
|
+
const unreadable = new Set();
|
|
357
|
+
const shellNames = new Set(["bash", "zsh", "fish", "sh", "dash"]);
|
|
358
|
+
const checkout = platform === "linux" || platform === "darwin"
|
|
359
|
+
? realpathWithoutOpening(path)
|
|
360
|
+
: path;
|
|
361
|
+
if (!process.getuid)
|
|
362
|
+
throw new Error("Process user identity unavailable");
|
|
363
|
+
const uid = process.getuid();
|
|
364
|
+
if (platform === "linux") {
|
|
365
|
+
// Keep enumeration outside the per-process guard: total failure is a blocker.
|
|
366
|
+
const pids = readdirSync(procRoot).filter((name) => /^\d+$/.test(name));
|
|
367
|
+
if (!pids.length)
|
|
368
|
+
throw new Error("Process enumeration returned no PIDs");
|
|
369
|
+
for (const pid of pids) {
|
|
370
|
+
try {
|
|
371
|
+
if (lstatSync(`${procRoot}/${pid}`).uid !== uid)
|
|
372
|
+
continue;
|
|
373
|
+
let command = "";
|
|
374
|
+
try {
|
|
375
|
+
command = readFileSync(`${procRoot}/${pid}/comm`, "utf8").trim();
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
// An unreadable name cannot exempt a runtime or hide a readable cwd.
|
|
379
|
+
unreadable.add(pid);
|
|
380
|
+
}
|
|
381
|
+
// A shell can exec a runtime without changing PID/process group.
|
|
382
|
+
if (idleShellPids.has(Number(pid)) && shellNames.has(command))
|
|
383
|
+
continue;
|
|
384
|
+
let cwd;
|
|
385
|
+
try {
|
|
386
|
+
cwd = realpathWithoutOpening(`${procRoot}/${pid}/cwd`);
|
|
387
|
+
}
|
|
388
|
+
catch (cwdError) {
|
|
389
|
+
// SAFETY: filesystem probes throw Node errors with an optional errno code.
|
|
390
|
+
const code = cwdError.code ?? "";
|
|
391
|
+
if (["ENOENT", "ESRCH"].includes(code))
|
|
392
|
+
throw cwdError;
|
|
393
|
+
// Same-uid agents can deny stat and readlink here while staying live.
|
|
394
|
+
unreadable.add(pid);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (contained(checkout, cwd))
|
|
398
|
+
blockers.push(`Live process ${pid} holds the checkout`);
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
// SAFETY: filesystem probes throw Node errors with an optional errno code.
|
|
402
|
+
if (["ENOENT", "ESRCH"].includes(error.code ?? "")) {
|
|
403
|
+
try {
|
|
404
|
+
// Confirm disappearance without opening: a dangling /proc
|
|
405
|
+
// entry must not look like a live holder.
|
|
406
|
+
realpathWithoutOpening(`${procRoot}/${pid}`);
|
|
407
|
+
if (/^State:\s+[ZX]/m.test(readFileSync(`${procRoot}/${pid}/status`, "utf8"))) {
|
|
408
|
+
unreadable.delete(pid);
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
// Missing status alone is not proof of process disappearance.
|
|
414
|
+
try {
|
|
415
|
+
realpathWithoutOpening(`${procRoot}/${pid}`);
|
|
416
|
+
}
|
|
417
|
+
catch (presenceError) {
|
|
418
|
+
// SAFETY: these are Node filesystem errors.
|
|
419
|
+
if (["ENOENT", "ESRCH"].includes(presenceError.code ?? "")) {
|
|
420
|
+
unreadable.delete(pid);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
unreadable.add(pid);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else if (platform === "darwin") {
|
|
431
|
+
// A nonzero lsof exit is a global failure, even if partial stdout exists.
|
|
432
|
+
let output;
|
|
433
|
+
try {
|
|
434
|
+
output = execFileSync("lsof", ["-n", "-P", "-a", "-u", String(uid), "-d", "cwd", "-Fpcn"], {
|
|
435
|
+
encoding: "utf8",
|
|
436
|
+
timeout: CLEANUP_TIMEOUT_MS,
|
|
437
|
+
killSignal: "SIGKILL",
|
|
438
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
// Command errors may embed partial process output; never disclose it.
|
|
443
|
+
throw new Error("lsof failed to enumerate processes");
|
|
444
|
+
}
|
|
445
|
+
const records = output.split(/^p/m).slice(1);
|
|
446
|
+
if (!records.length)
|
|
447
|
+
throw new Error("Process enumeration returned no PIDs");
|
|
448
|
+
for (const record of records) {
|
|
449
|
+
const [pid, ...fields] = record.split("\n");
|
|
450
|
+
if (!/^\d+$/.test(pid))
|
|
451
|
+
throw new Error("Invalid process enumeration record");
|
|
452
|
+
const command = fields.find((line) => line.startsWith("c"))?.slice(1);
|
|
453
|
+
if (idleShellPids.has(Number(pid)) && command && shellNames.has(command))
|
|
454
|
+
continue;
|
|
455
|
+
const cwd = fields.find((line) => line.startsWith("n"))?.slice(1);
|
|
456
|
+
if (!command)
|
|
457
|
+
unreadable.add(pid);
|
|
458
|
+
try {
|
|
459
|
+
if (!cwd || !isAbsolute(cwd))
|
|
460
|
+
throw new Error("Process cwd unavailable");
|
|
461
|
+
// Every same-user cwd is resolved, so this must never open a path.
|
|
462
|
+
if (contained(checkout, realpathWithoutOpening(cwd)))
|
|
463
|
+
blockers.push(`Live process ${pid} holds the checkout`);
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
unreadable.add(pid);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
throw new Error(`Process inspection unsupported on ${platform}`);
|
|
472
|
+
}
|
|
473
|
+
const warnings = [
|
|
474
|
+
"Incomplete process coverage: same-user inspection is permission-limited; other-user processes are not inspected. A protected process could hold the checkout undetected.",
|
|
475
|
+
];
|
|
476
|
+
if (unreadable.size)
|
|
477
|
+
warnings.push(`${unreadable.size} process(es) (PIDs ${[...unreadable].slice(0, 10).join(", ")}${unreadable.size > 10 ? ", …" : ""}) have unreadable details; not proven unrelated to the checkout.`);
|
|
478
|
+
return { blockers, warnings };
|
|
479
|
+
}
|
|
480
|
+
export const __worktreeCleanupTest__ = {
|
|
481
|
+
processHolders,
|
|
482
|
+
realpathWithoutOpening,
|
|
483
|
+
};
|
|
484
|
+
export function createWorktreeCleanupOperations(provider, input) {
|
|
485
|
+
const root = input.managedRoot ?? join(homedir(), ".herdr", "worktrees");
|
|
486
|
+
let canonicalRoot;
|
|
487
|
+
return {
|
|
488
|
+
managedRoot: () => canonicalRoot ?? realpathWithoutOpening(root),
|
|
489
|
+
scan: () => {
|
|
490
|
+
if (!exists(root))
|
|
491
|
+
return [];
|
|
492
|
+
canonicalRoot = realpathWithoutOpening(root);
|
|
493
|
+
const checkouts = [];
|
|
494
|
+
for (const repo of directories(canonicalRoot)) {
|
|
495
|
+
let resolvedRepo;
|
|
496
|
+
try {
|
|
497
|
+
resolvedRepo = realpathWithoutOpening(repo);
|
|
498
|
+
}
|
|
499
|
+
catch {
|
|
500
|
+
// Unresolvable residue stays out of the inventory rather than
|
|
501
|
+
// blocking the whole scan; callers never see it as eligible.
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
// Never readdir a managed entry until containment is proven without
|
|
505
|
+
// opening: a symlink to a protected directory would freeze Pi.
|
|
506
|
+
if (!contained(canonicalRoot, resolvedRepo))
|
|
507
|
+
continue;
|
|
508
|
+
checkouts.push(...directories(resolvedRepo));
|
|
509
|
+
}
|
|
510
|
+
return checkouts;
|
|
511
|
+
},
|
|
512
|
+
realpath: realpathWithoutOpening,
|
|
513
|
+
resolveSource,
|
|
514
|
+
inspectGit,
|
|
515
|
+
listWorktrees: (source) => provider.listWorktreeSurfaces({
|
|
516
|
+
cwd: source,
|
|
517
|
+
timeoutMs: CLEANUP_TIMEOUT_MS,
|
|
518
|
+
}),
|
|
519
|
+
readManifests: () => {
|
|
520
|
+
if (!exists(input.manifestDir))
|
|
521
|
+
return [];
|
|
522
|
+
return readdirSync(input.manifestDir)
|
|
523
|
+
.filter((name) => name.endsWith(".json"))
|
|
524
|
+
.flatMap((name) => {
|
|
525
|
+
const file = join(input.manifestDir, name);
|
|
526
|
+
const value = readWorktreeManifest(file);
|
|
527
|
+
return value ? [{ file, value }] : [];
|
|
528
|
+
});
|
|
529
|
+
},
|
|
530
|
+
holders: async (entry) => {
|
|
531
|
+
const blockers = input
|
|
532
|
+
.liveHolders()
|
|
533
|
+
.filter((holder) => realpathWithoutOpening(holder.path) === entry.path)
|
|
534
|
+
.map((holder) => holder.persistent
|
|
535
|
+
? "Persistent-specialist lease holds the worktree"
|
|
536
|
+
: "Live child holds the worktree");
|
|
537
|
+
const idleShellPids = new Set();
|
|
538
|
+
if (entry.workspaceId) {
|
|
539
|
+
const panes = await provider.listSurfaces({
|
|
540
|
+
timeoutMs: CLEANUP_TIMEOUT_MS,
|
|
541
|
+
});
|
|
542
|
+
if (!panes)
|
|
543
|
+
throw new Error("Herdr pane snapshot unavailable");
|
|
544
|
+
const owned = panes.filter((pane) => pane.workspaceId === entry.workspaceId);
|
|
545
|
+
if (!owned.length)
|
|
546
|
+
throw new Error("Open workspace has no observable panes");
|
|
547
|
+
for (const pane of owned) {
|
|
548
|
+
const info = await provider.getProcessInfo(pane.id, {
|
|
549
|
+
timeoutMs: CLEANUP_TIMEOUT_MS,
|
|
550
|
+
});
|
|
551
|
+
if (!info.shellPid || !info.foregroundProcessGroupId)
|
|
552
|
+
throw new Error(`Process state unknown for pane ${pane.id}`);
|
|
553
|
+
// Exempt only Herdr's observed idle retained shell, never a runtime
|
|
554
|
+
// name or a shell running a foreground command.
|
|
555
|
+
if (info.foregroundProcessGroupId === info.shellPid)
|
|
556
|
+
idleShellPids.add(info.shellPid);
|
|
557
|
+
else
|
|
558
|
+
blockers.push(`Live child or foreground process in pane ${pane.id}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
const inspection = processHolders(entry.path, idleShellPids);
|
|
563
|
+
return {
|
|
564
|
+
blockers: [...blockers, ...inspection.blockers],
|
|
565
|
+
warnings: inspection.warnings,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
catch (error) {
|
|
569
|
+
// Preserve known children and leases even when global inspection fails.
|
|
570
|
+
return {
|
|
571
|
+
blockers: [
|
|
572
|
+
...blockers,
|
|
573
|
+
`Process inspection unavailable: ${message(error)}`,
|
|
574
|
+
],
|
|
575
|
+
warnings: [],
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
exists,
|
|
580
|
+
preserve: (entry) => {
|
|
581
|
+
if (!entry.branch ||
|
|
582
|
+
git(entry.path, ["symbolic-ref", "--short", "HEAD"]).trim() !==
|
|
583
|
+
entry.branch)
|
|
584
|
+
throw new Error("Retained branch changed before preservation");
|
|
585
|
+
const index = git(entry.path, [
|
|
586
|
+
"rev-parse",
|
|
587
|
+
"--path-format=absolute",
|
|
588
|
+
"--git-path",
|
|
589
|
+
"index",
|
|
590
|
+
]).trim();
|
|
591
|
+
const originalIndex = exists(index) ? readFileSync(index) : undefined;
|
|
592
|
+
try {
|
|
593
|
+
git(entry.path, ["add", "-A"]);
|
|
594
|
+
git(entry.path, [
|
|
595
|
+
"commit",
|
|
596
|
+
"-m",
|
|
597
|
+
"WIP: preserve worktree before explicit cleanup",
|
|
598
|
+
]);
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
if (originalIndex)
|
|
602
|
+
writeFileSync(index, originalIndex);
|
|
603
|
+
else if (exists(index))
|
|
604
|
+
unlinkSync(index);
|
|
605
|
+
throw error;
|
|
606
|
+
}
|
|
607
|
+
return git(entry.path, ["rev-parse", "HEAD"]).trim();
|
|
608
|
+
},
|
|
609
|
+
removeWorkspace: (id) => provider.removeWorktreeSurface(id, { timeoutMs: CLEANUP_TIMEOUT_MS }),
|
|
610
|
+
reportOpenedPrimaryWorkspace: (sourceRepo, claims) => provider.reportOpenedPrimaryWorkspace({ sourceRepo, claims }),
|
|
611
|
+
removeCheckout: (source, path) => {
|
|
612
|
+
git(source, ["worktree", "remove", "--", path]);
|
|
613
|
+
},
|
|
614
|
+
prune: (source) => {
|
|
615
|
+
git(source, ["worktree", "prune"]);
|
|
616
|
+
},
|
|
617
|
+
writeManifest: (file, value) => {
|
|
618
|
+
if (!readWorktreeManifest(file))
|
|
619
|
+
throw new Error("Manifest ownership became unavailable; checkout removed but manifest unchanged");
|
|
620
|
+
writeWorktreeManifest(file, value);
|
|
621
|
+
},
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
export function createWorktreeOperations() {
|
|
625
|
+
return {
|
|
626
|
+
resolveGitCommit,
|
|
627
|
+
resolveWorktreeProvisionCwd,
|
|
628
|
+
writeWorktreeManifest,
|
|
629
|
+
captureWorktreeHandoff,
|
|
630
|
+
persistWorktreeResult,
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
//# sourceMappingURL=worktree-operations.js.map
|