@nubl/maestro 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -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,714 @@
|
|
|
1
|
+
import { buildSessionContext, SessionManager, } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { appendFileSync, closeSync, copyFileSync, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
4
|
+
import { basename, dirname, join } from "node:path";
|
|
5
|
+
import { isBoolean, isFiniteNumber, isPlainObject, isRecord, isString, } from "../../core/config/type-guards.js";
|
|
6
|
+
const SUBAGENT_POLICY_VERSION = 2;
|
|
7
|
+
const SUBAGENT_POLICY_SUFFIX = ".pi-herdr-subagent-policy.json";
|
|
8
|
+
export function getSubagentSessionPolicyFile(sessionFile) {
|
|
9
|
+
return `${sessionFile}${SUBAGENT_POLICY_SUFFIX}`;
|
|
10
|
+
}
|
|
11
|
+
export function getPersistentTaskEventsFile(sessionFile) {
|
|
12
|
+
return `${sessionFile}.tasks`;
|
|
13
|
+
}
|
|
14
|
+
export function getPersistentDeliveryLedgerFile(sessionFile) {
|
|
15
|
+
return `${sessionFile}.ledger`;
|
|
16
|
+
}
|
|
17
|
+
function normalizePolicyToolNames(tools) {
|
|
18
|
+
const values = isString(tools)
|
|
19
|
+
? tools.split(",")
|
|
20
|
+
: tools === undefined
|
|
21
|
+
? []
|
|
22
|
+
: [...tools];
|
|
23
|
+
const normalized = [
|
|
24
|
+
...new Set(values.map((tool) => tool.trim()).filter(Boolean)),
|
|
25
|
+
];
|
|
26
|
+
return normalized.length > 0 ? normalized : null;
|
|
27
|
+
}
|
|
28
|
+
function canonicalPolicyJson(policy) {
|
|
29
|
+
const canonical = {
|
|
30
|
+
version: policy.version,
|
|
31
|
+
owner: policy.owner,
|
|
32
|
+
tools: policy.tools,
|
|
33
|
+
deniedTools: policy.deniedTools,
|
|
34
|
+
persistent: policy.persistent,
|
|
35
|
+
logicalId: policy.logicalId,
|
|
36
|
+
generationId: policy.generationId,
|
|
37
|
+
};
|
|
38
|
+
if ("agent" in policy)
|
|
39
|
+
canonical.agent = policy.agent;
|
|
40
|
+
if ("selfSpawn" in policy)
|
|
41
|
+
canonical.selfSpawn = policy.selfSpawn;
|
|
42
|
+
if (policy.worktree)
|
|
43
|
+
canonical.worktree = policy.worktree;
|
|
44
|
+
return JSON.stringify(canonical);
|
|
45
|
+
}
|
|
46
|
+
export function writeSubagentSessionPolicy(sessionFile, policy) {
|
|
47
|
+
const unsigned = {
|
|
48
|
+
version: SUBAGENT_POLICY_VERSION,
|
|
49
|
+
owner: policy.owner,
|
|
50
|
+
tools: normalizePolicyToolNames(policy.tools),
|
|
51
|
+
deniedTools: normalizePolicyToolNames(policy.deniedTools) ?? [],
|
|
52
|
+
persistent: policy.persistent ?? false,
|
|
53
|
+
logicalId: policy.logicalId ?? randomUUID(),
|
|
54
|
+
generationId: policy.generationId ?? randomUUID(),
|
|
55
|
+
};
|
|
56
|
+
if (policy.agent !== undefined)
|
|
57
|
+
unsigned.agent = policy.agent;
|
|
58
|
+
if (policy.selfSpawn !== undefined)
|
|
59
|
+
unsigned.selfSpawn = policy.selfSpawn;
|
|
60
|
+
if (policy.worktree)
|
|
61
|
+
unsigned.worktree = policy.worktree;
|
|
62
|
+
const value = {
|
|
63
|
+
...unsigned,
|
|
64
|
+
policyHash: createHash("sha256")
|
|
65
|
+
.update(canonicalPolicyJson(unsigned))
|
|
66
|
+
.digest("hex"),
|
|
67
|
+
};
|
|
68
|
+
writeFileSync(getSubagentSessionPolicyFile(sessionFile), `${JSON.stringify(value)}\n`, "utf8");
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
function policyError(sessionFile, reason) {
|
|
72
|
+
return new Error(`Cannot safely resume ${sessionFile}: ${reason}. ` +
|
|
73
|
+
"Start a new subagent with the required restrictions, or manually resume it only after choosing an explicit Pi tool policy.");
|
|
74
|
+
}
|
|
75
|
+
function isPolicyRecord(value) {
|
|
76
|
+
return isPlainObject(value);
|
|
77
|
+
}
|
|
78
|
+
export function readSubagentSessionPolicy(sessionFile) {
|
|
79
|
+
const path = getSubagentSessionPolicyFile(sessionFile);
|
|
80
|
+
let value;
|
|
81
|
+
try {
|
|
82
|
+
value = JSON.parse(readFileSync(path, "utf8"));
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const reason = error instanceof Error && "code" in error && error.code === "ENOENT"
|
|
86
|
+
? "the saved launch policy is missing"
|
|
87
|
+
: "the saved launch policy cannot be read";
|
|
88
|
+
throw policyError(sessionFile, reason);
|
|
89
|
+
}
|
|
90
|
+
if (!isPolicyRecord(value))
|
|
91
|
+
throw policyError(sessionFile, "the saved launch policy is malformed");
|
|
92
|
+
const version = value.version;
|
|
93
|
+
if (version !== 1 && version !== SUBAGENT_POLICY_VERSION) {
|
|
94
|
+
throw policyError(sessionFile, "the saved launch policy version is unsupported");
|
|
95
|
+
}
|
|
96
|
+
const expected = version === 1
|
|
97
|
+
? new Set(["version", "owner", "tools", "deniedTools"])
|
|
98
|
+
: new Set([
|
|
99
|
+
"version",
|
|
100
|
+
"owner",
|
|
101
|
+
"tools",
|
|
102
|
+
"deniedTools",
|
|
103
|
+
"persistent",
|
|
104
|
+
"logicalId",
|
|
105
|
+
"generationId",
|
|
106
|
+
"policyHash",
|
|
107
|
+
"agent",
|
|
108
|
+
"selfSpawn",
|
|
109
|
+
"worktree",
|
|
110
|
+
]);
|
|
111
|
+
if (Object.keys(value).some((key) => !expected.has(key))) {
|
|
112
|
+
throw policyError(sessionFile, "the saved launch policy has unsupported fields");
|
|
113
|
+
}
|
|
114
|
+
const owner = value.owner;
|
|
115
|
+
if (owner !== "public" && owner !== "managed-worktree") {
|
|
116
|
+
throw policyError(sessionFile, "the saved launch policy owner is invalid");
|
|
117
|
+
}
|
|
118
|
+
const validateTools = (tools, allowNull, allowEmpty) => {
|
|
119
|
+
if (tools === null) {
|
|
120
|
+
if (allowNull)
|
|
121
|
+
return null;
|
|
122
|
+
throw policyError(sessionFile, "the saved denied-tool policy is malformed");
|
|
123
|
+
}
|
|
124
|
+
if (!Array.isArray(tools)) {
|
|
125
|
+
throw policyError(sessionFile, "the saved launch tool policy is malformed");
|
|
126
|
+
}
|
|
127
|
+
const names = [];
|
|
128
|
+
for (const tool of tools) {
|
|
129
|
+
if (!isString(tool) || tool === "" || /[,\s]/.test(tool)) {
|
|
130
|
+
throw policyError(sessionFile, "the saved launch tool policy is malformed");
|
|
131
|
+
}
|
|
132
|
+
names.push(tool);
|
|
133
|
+
}
|
|
134
|
+
if ((!allowEmpty && names.length === 0) ||
|
|
135
|
+
new Set(names).size !== names.length) {
|
|
136
|
+
throw policyError(sessionFile, "the saved launch tool policy is malformed");
|
|
137
|
+
}
|
|
138
|
+
return names;
|
|
139
|
+
};
|
|
140
|
+
const tools = validateTools(value.tools, true, false);
|
|
141
|
+
const deniedTools = validateTools(value.deniedTools, false, true);
|
|
142
|
+
if (deniedTools === null) {
|
|
143
|
+
throw policyError(sessionFile, "the saved denied-tool policy is malformed");
|
|
144
|
+
}
|
|
145
|
+
if (version === 1) {
|
|
146
|
+
return { version: 1, owner, tools, deniedTools, persistent: false };
|
|
147
|
+
}
|
|
148
|
+
if (!isBoolean(value.persistent) ||
|
|
149
|
+
!isString(value.logicalId) ||
|
|
150
|
+
!isString(value.generationId) ||
|
|
151
|
+
!isString(value.policyHash) ||
|
|
152
|
+
!/^[a-f0-9]{64}$/.test(value.policyHash)) {
|
|
153
|
+
throw policyError(sessionFile, "the saved persistent launch policy is malformed");
|
|
154
|
+
}
|
|
155
|
+
let worktree;
|
|
156
|
+
const persistedWorktree = value.worktree;
|
|
157
|
+
if (persistedWorktree !== undefined) {
|
|
158
|
+
if (!isRecord(persistedWorktree))
|
|
159
|
+
throw policyError(sessionFile, "the saved persistent worktree policy is malformed");
|
|
160
|
+
const path = persistedWorktree.path;
|
|
161
|
+
const workspaceId = persistedWorktree.workspaceId;
|
|
162
|
+
const branch = persistedWorktree.branch;
|
|
163
|
+
const baseSha = persistedWorktree.baseSha;
|
|
164
|
+
if (Object.keys(persistedWorktree).some((key) => !["path", "workspaceId", "branch", "baseSha"].includes(key)) ||
|
|
165
|
+
!isString(path) ||
|
|
166
|
+
!path ||
|
|
167
|
+
!isString(workspaceId) ||
|
|
168
|
+
!workspaceId ||
|
|
169
|
+
!isString(branch) ||
|
|
170
|
+
!branch ||
|
|
171
|
+
!isString(baseSha) ||
|
|
172
|
+
!baseSha) {
|
|
173
|
+
throw policyError(sessionFile, "the saved persistent worktree policy is malformed");
|
|
174
|
+
}
|
|
175
|
+
worktree = { path, workspaceId, branch, baseSha };
|
|
176
|
+
}
|
|
177
|
+
const unsigned = {
|
|
178
|
+
version: 2,
|
|
179
|
+
owner,
|
|
180
|
+
tools,
|
|
181
|
+
deniedTools,
|
|
182
|
+
persistent: value.persistent,
|
|
183
|
+
logicalId: value.logicalId,
|
|
184
|
+
generationId: value.generationId,
|
|
185
|
+
};
|
|
186
|
+
if (value.agent !== undefined) {
|
|
187
|
+
if (value.agent !== null && !isString(value.agent)) {
|
|
188
|
+
throw policyError(sessionFile, "the saved launch agent policy is malformed");
|
|
189
|
+
}
|
|
190
|
+
unsigned.agent = value.agent;
|
|
191
|
+
}
|
|
192
|
+
if (value.selfSpawn !== undefined) {
|
|
193
|
+
if (!isBoolean(value.selfSpawn)) {
|
|
194
|
+
throw policyError(sessionFile, "the saved launch self-spawn policy is malformed");
|
|
195
|
+
}
|
|
196
|
+
unsigned.selfSpawn = value.selfSpawn;
|
|
197
|
+
}
|
|
198
|
+
if (worktree)
|
|
199
|
+
unsigned.worktree = worktree;
|
|
200
|
+
if (createHash("sha256").update(canonicalPolicyJson(unsigned)).digest("hex") !==
|
|
201
|
+
value.policyHash) {
|
|
202
|
+
throw policyError(sessionFile, "the saved persistent launch policy hash is invalid");
|
|
203
|
+
}
|
|
204
|
+
const policy = {
|
|
205
|
+
...unsigned,
|
|
206
|
+
policyHash: value.policyHash,
|
|
207
|
+
};
|
|
208
|
+
return policy;
|
|
209
|
+
}
|
|
210
|
+
export function appendPersistentTaskEvent(sessionFile, event) {
|
|
211
|
+
const value = {
|
|
212
|
+
version: 1,
|
|
213
|
+
type: event.type,
|
|
214
|
+
task: event.task,
|
|
215
|
+
generation: event.generation,
|
|
216
|
+
at: event.at ?? new Date().toISOString(),
|
|
217
|
+
};
|
|
218
|
+
if (event.message !== undefined)
|
|
219
|
+
value.message = event.message;
|
|
220
|
+
if (event.sequence !== undefined)
|
|
221
|
+
value.sequence = event.sequence;
|
|
222
|
+
appendFileSync(getPersistentTaskEventsFile(sessionFile), `${JSON.stringify(value)}\n`, "utf8");
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
/** A notice's number; `undefined` when it lacks a message or a positive whole number. */
|
|
226
|
+
function parseNoticeSequence(value) {
|
|
227
|
+
const sequence = value.sequence;
|
|
228
|
+
return isString(value.message) &&
|
|
229
|
+
isFiniteNumber(sequence) &&
|
|
230
|
+
Number.isSafeInteger(sequence) &&
|
|
231
|
+
sequence >= 1
|
|
232
|
+
? sequence
|
|
233
|
+
: undefined;
|
|
234
|
+
}
|
|
235
|
+
export function readPersistentTaskEvents(sessionFile) {
|
|
236
|
+
if (!existsSync(getPersistentTaskEventsFile(sessionFile)))
|
|
237
|
+
return [];
|
|
238
|
+
return readFileSync(getPersistentTaskEventsFile(sessionFile), "utf8")
|
|
239
|
+
.split("\n")
|
|
240
|
+
.flatMap((line) => {
|
|
241
|
+
if (!line.trim())
|
|
242
|
+
return [];
|
|
243
|
+
try {
|
|
244
|
+
const value = JSON.parse(line);
|
|
245
|
+
if (!isRecord(value) ||
|
|
246
|
+
value.version !== 1 ||
|
|
247
|
+
(value.type !== "task-done" &&
|
|
248
|
+
value.type !== "help-request" &&
|
|
249
|
+
value.type !== "notice") ||
|
|
250
|
+
!isString(value.task) ||
|
|
251
|
+
!isString(value.generation) ||
|
|
252
|
+
!isString(value.at) ||
|
|
253
|
+
(value.message !== undefined && !isString(value.message)))
|
|
254
|
+
return [];
|
|
255
|
+
const sequence = parseNoticeSequence(value);
|
|
256
|
+
if (value.type === "notice" && sequence === undefined)
|
|
257
|
+
return [];
|
|
258
|
+
const event = {
|
|
259
|
+
version: 1,
|
|
260
|
+
type: value.type,
|
|
261
|
+
task: value.task,
|
|
262
|
+
generation: value.generation,
|
|
263
|
+
at: value.at,
|
|
264
|
+
};
|
|
265
|
+
if (value.message !== undefined)
|
|
266
|
+
event.message = value.message;
|
|
267
|
+
if (value.type === "notice")
|
|
268
|
+
event.sequence = sequence;
|
|
269
|
+
return [event];
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
export function appendPersistentDeliveryLedger(sessionFile, entry) {
|
|
277
|
+
const value = {
|
|
278
|
+
...entry,
|
|
279
|
+
at: entry.at ?? new Date().toISOString(),
|
|
280
|
+
};
|
|
281
|
+
appendFileSync(getPersistentDeliveryLedgerFile(sessionFile), `${JSON.stringify(value)}\n`, "utf8");
|
|
282
|
+
return value;
|
|
283
|
+
}
|
|
284
|
+
function parsePersistentLedgerOutcome(value) {
|
|
285
|
+
if (value === "dispatched")
|
|
286
|
+
return value;
|
|
287
|
+
if (value === "delivered")
|
|
288
|
+
return value;
|
|
289
|
+
if (value === "rejected-busy")
|
|
290
|
+
return value;
|
|
291
|
+
if (value === "help-requested")
|
|
292
|
+
return value;
|
|
293
|
+
if (value === "stop-pending")
|
|
294
|
+
return value;
|
|
295
|
+
if (value === "stopped")
|
|
296
|
+
return value;
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
export function readPersistentDeliveryLedger(sessionFile) {
|
|
300
|
+
if (!existsSync(getPersistentDeliveryLedgerFile(sessionFile)))
|
|
301
|
+
return [];
|
|
302
|
+
return readFileSync(getPersistentDeliveryLedgerFile(sessionFile), "utf8")
|
|
303
|
+
.split("\n")
|
|
304
|
+
.flatMap((line) => {
|
|
305
|
+
try {
|
|
306
|
+
const value = JSON.parse(line);
|
|
307
|
+
if (!isRecord(value) ||
|
|
308
|
+
!isString(value.task) ||
|
|
309
|
+
!isString(value.generation) ||
|
|
310
|
+
!isString(value.logicalId) ||
|
|
311
|
+
!isString(value.policyHash) ||
|
|
312
|
+
!/^[a-f0-9]{64}$/.test(value.policyHash) ||
|
|
313
|
+
!isString(value.at))
|
|
314
|
+
return [];
|
|
315
|
+
const outcome = parsePersistentLedgerOutcome(value.outcome);
|
|
316
|
+
if (!outcome)
|
|
317
|
+
return [];
|
|
318
|
+
return [
|
|
319
|
+
{
|
|
320
|
+
task: value.task,
|
|
321
|
+
outcome,
|
|
322
|
+
generation: value.generation,
|
|
323
|
+
logicalId: value.logicalId,
|
|
324
|
+
policyHash: value.policyHash,
|
|
325
|
+
at: value.at,
|
|
326
|
+
},
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
export function writePersistentTaskInbox(sessionFile, sequence, entry) {
|
|
335
|
+
const path = `${sessionFile}.task-inbox.${String(sequence).padStart(12, "0")}.json`;
|
|
336
|
+
const temporary = `${path}.tmp`;
|
|
337
|
+
writeFileSync(temporary, `${JSON.stringify({ version: 1, type: "task", ...entry, at: entry.at ?? new Date().toISOString() })}\n`, "utf8");
|
|
338
|
+
renameSync(temporary, path);
|
|
339
|
+
return path;
|
|
340
|
+
}
|
|
341
|
+
export function consumePersistentTaskInbox(sessionFile) {
|
|
342
|
+
const directory = dirname(sessionFile);
|
|
343
|
+
const prefix = `${basename(sessionFile)}.task-inbox.`;
|
|
344
|
+
for (const name of readdirSync(directory)) {
|
|
345
|
+
if (!name.startsWith(prefix) || !name.endsWith(".json.consuming"))
|
|
346
|
+
continue;
|
|
347
|
+
const claimed = join(directory, name);
|
|
348
|
+
try {
|
|
349
|
+
renameSync(claimed, claimed.slice(0, -".consuming".length));
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
// Another poller owns this claim, or recovery cannot safely proceed.
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const inbox = readdirSync(directory)
|
|
356
|
+
.filter((name) => name.startsWith(prefix) && name.endsWith(".json"))
|
|
357
|
+
.sort()[0];
|
|
358
|
+
if (!inbox)
|
|
359
|
+
return null;
|
|
360
|
+
const path = join(directory, inbox);
|
|
361
|
+
const claimed = `${path}.consuming`;
|
|
362
|
+
try {
|
|
363
|
+
renameSync(path, claimed);
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
const value = JSON.parse(readFileSync(claimed, "utf8"));
|
|
370
|
+
if (!isRecord(value) ||
|
|
371
|
+
value.version !== 1 ||
|
|
372
|
+
(value.type !== undefined &&
|
|
373
|
+
value.type !== "task" &&
|
|
374
|
+
value.type !== "stop") ||
|
|
375
|
+
!isString(value.task) ||
|
|
376
|
+
!isString(value.message) ||
|
|
377
|
+
!isString(value.at))
|
|
378
|
+
throw new Error("invalid persistent task inbox entry");
|
|
379
|
+
const entry = {
|
|
380
|
+
version: 1,
|
|
381
|
+
task: value.task,
|
|
382
|
+
message: value.message,
|
|
383
|
+
at: value.at,
|
|
384
|
+
};
|
|
385
|
+
if (value.type === "task" || value.type === "stop")
|
|
386
|
+
entry.type = value.type;
|
|
387
|
+
rmSync(claimed, { force: true });
|
|
388
|
+
return entry;
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
try {
|
|
392
|
+
renameSync(claimed, `${path}.invalid`);
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
// Keep the claimed file when it cannot be moved; never silently delete it.
|
|
396
|
+
}
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function getForkContentLines(parentSessionFile) {
|
|
401
|
+
const branch = SessionManager.open(parentSessionFile).getBranch();
|
|
402
|
+
// Exclude the triggering user turn and its descendants, but only on the
|
|
403
|
+
// active branch. Keep entry IDs and compaction boundaries intact for Pi.
|
|
404
|
+
let truncateAt = branch.length;
|
|
405
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
406
|
+
const entry = branch[i];
|
|
407
|
+
if (entry.type === "message" && entry.message.role === "user") {
|
|
408
|
+
truncateAt = i;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return branch.slice(0, truncateAt).map((entry) => JSON.stringify(entry));
|
|
413
|
+
}
|
|
414
|
+
export function seedSubagentSessionFile(params) {
|
|
415
|
+
const header = {
|
|
416
|
+
type: "session",
|
|
417
|
+
version: 3,
|
|
418
|
+
id: randomUUID(),
|
|
419
|
+
timestamp: new Date().toISOString(),
|
|
420
|
+
cwd: params.childCwd,
|
|
421
|
+
parentSession: params.parentSessionFile,
|
|
422
|
+
};
|
|
423
|
+
const contentLines = params.mode === "fork" ? getForkContentLines(params.parentSessionFile) : [];
|
|
424
|
+
const lines = [JSON.stringify(header), ...contentLines];
|
|
425
|
+
mkdirSync(dirname(params.childSessionFile), { recursive: true });
|
|
426
|
+
writeFileSync(params.childSessionFile, lines.join("\n") + "\n", "utf8");
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Copy only the active Pi branch into a session rooted at another cwd.
|
|
430
|
+
* Pi's native branched-session writer supplies compaction and label fidelity;
|
|
431
|
+
* the temporary source-directory file is rewritten with the target cwd.
|
|
432
|
+
*/
|
|
433
|
+
export function createWorktreeSessionFork(params) {
|
|
434
|
+
const source = SessionManager.open(params.parentSessionFile);
|
|
435
|
+
const temporaryFile = source.createBranchedSession(params.leafId);
|
|
436
|
+
if (!temporaryFile || !existsSync(temporaryFile)) {
|
|
437
|
+
throw new Error("Pi did not persist the worktree session fork");
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const lines = readFileSync(temporaryFile, "utf8")
|
|
441
|
+
.split("\n")
|
|
442
|
+
.filter((line) => line.trim());
|
|
443
|
+
const header = JSON.parse(lines[0]);
|
|
444
|
+
header.cwd = params.childCwd;
|
|
445
|
+
header.parentSession = params.parentSessionFile;
|
|
446
|
+
mkdirSync(dirname(params.childSessionFile), { recursive: true });
|
|
447
|
+
writeFileSync(params.childSessionFile, [JSON.stringify(header), ...lines.slice(1)].join("\n") + "\n", "utf8");
|
|
448
|
+
}
|
|
449
|
+
finally {
|
|
450
|
+
rmSync(temporaryFile, { force: true });
|
|
451
|
+
}
|
|
452
|
+
SessionManager.open(params.childSessionFile).appendCustomMessageEntry("pi-herdr-worktree-handoff", params.handoffMessage, true, {
|
|
453
|
+
sourceSessionFile: params.parentSessionFile,
|
|
454
|
+
childCwd: params.childCwd,
|
|
455
|
+
});
|
|
456
|
+
return {
|
|
457
|
+
sessionFile: params.childSessionFile,
|
|
458
|
+
sourceSessionFile: params.parentSessionFile,
|
|
459
|
+
handoffMessage: params.handoffMessage,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function parseEntry(line) {
|
|
463
|
+
try {
|
|
464
|
+
return JSON.parse(line);
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
throw new Error(`Invalid session entry: ${error instanceof Error ? error.message : String(error)}`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function readEntries(sessionFile) {
|
|
471
|
+
return readFileSync(sessionFile, "utf8")
|
|
472
|
+
.split("\n")
|
|
473
|
+
.filter((line) => line.trim())
|
|
474
|
+
.map(parseEntry);
|
|
475
|
+
}
|
|
476
|
+
const NO_PROGRESS_TAIL_BYTES = 128 * 1024;
|
|
477
|
+
/**
|
|
478
|
+
* Read only the final portion of a session when a no-progress warning is due.
|
|
479
|
+
* Torn or malformed JSONL lines are ignored because Pi can be writing the tail.
|
|
480
|
+
*/
|
|
481
|
+
export function inspectNoProgressSessionTail(sessionFile) {
|
|
482
|
+
const fd = openSync(sessionFile, "r");
|
|
483
|
+
let raw;
|
|
484
|
+
let startsWithinLine = false;
|
|
485
|
+
try {
|
|
486
|
+
const size = fstatSync(fd).size;
|
|
487
|
+
const start = Math.max(0, size - NO_PROGRESS_TAIL_BYTES);
|
|
488
|
+
if (start > 0) {
|
|
489
|
+
const preceding = Buffer.alloc(1);
|
|
490
|
+
startsWithinLine =
|
|
491
|
+
readSync(fd, preceding, 0, preceding.length, start - 1) !== 1 ||
|
|
492
|
+
preceding[0] !== 0x0a;
|
|
493
|
+
}
|
|
494
|
+
const buffer = Buffer.alloc(size - start);
|
|
495
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, start);
|
|
496
|
+
raw = buffer.subarray(0, bytesRead).toString("utf8");
|
|
497
|
+
}
|
|
498
|
+
finally {
|
|
499
|
+
closeSync(fd);
|
|
500
|
+
}
|
|
501
|
+
const lines = raw.split("\n");
|
|
502
|
+
if (startsWithinLine)
|
|
503
|
+
lines.shift();
|
|
504
|
+
const entries = lines.flatMap((line) => {
|
|
505
|
+
if (!line.trim())
|
|
506
|
+
return [];
|
|
507
|
+
try {
|
|
508
|
+
const value = JSON.parse(line);
|
|
509
|
+
return isRecord(value) ? [value] : [];
|
|
510
|
+
}
|
|
511
|
+
catch {
|
|
512
|
+
return [];
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
const last = entries.at(-1);
|
|
516
|
+
const lastEntryKind = !last
|
|
517
|
+
? "none"
|
|
518
|
+
: last.type === "message" && isRecord(last.message)
|
|
519
|
+
? last.message.role === "assistant"
|
|
520
|
+
? "assistant"
|
|
521
|
+
: last.message.role === "toolResult"
|
|
522
|
+
? "tool-result"
|
|
523
|
+
: "message"
|
|
524
|
+
: "other";
|
|
525
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
526
|
+
const entry = entries[index];
|
|
527
|
+
if (entry.type !== "message" || !isRecord(entry.message))
|
|
528
|
+
continue;
|
|
529
|
+
if (entry.message.role !== "assistant")
|
|
530
|
+
continue;
|
|
531
|
+
const content = entry.message.content;
|
|
532
|
+
const toolCallIds = new Set(Array.isArray(content)
|
|
533
|
+
? content.flatMap((block) => isRecord(block) && block.type === "toolCall" && isString(block.id)
|
|
534
|
+
? [block.id]
|
|
535
|
+
: [])
|
|
536
|
+
: []);
|
|
537
|
+
const resolvedToolCallIds = new Set(entries
|
|
538
|
+
.slice(index + 1)
|
|
539
|
+
.flatMap((entry) => entry.type === "message" &&
|
|
540
|
+
isRecord(entry.message) &&
|
|
541
|
+
entry.message.role === "toolResult" &&
|
|
542
|
+
isString(entry.message.toolCallId)
|
|
543
|
+
? [entry.message.toolCallId]
|
|
544
|
+
: []));
|
|
545
|
+
const hasToolCall = toolCallIds.size > 0;
|
|
546
|
+
const hasOutstandingToolCall = [...toolCallIds].some((toolCallId) => !resolvedToolCallIds.has(toolCallId));
|
|
547
|
+
if (hasToolCall && hasOutstandingToolCall) {
|
|
548
|
+
return { classification: "blocked-tool", lastEntryKind };
|
|
549
|
+
}
|
|
550
|
+
if (entry.message.stopReason === "toolUse" && !hasToolCall) {
|
|
551
|
+
return { classification: "truncated-turn", lastEntryKind };
|
|
552
|
+
}
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
return { classification: "generic-no-progress", lastEntryKind };
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Return the id of the last entry in the session file (current branch point / leaf).
|
|
559
|
+
*/
|
|
560
|
+
export function getLeafId(sessionFile) {
|
|
561
|
+
const entries = readEntries(sessionFile);
|
|
562
|
+
return entries.length > 0 ? entries[entries.length - 1].id : null;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Return entries added after `afterLine` (1-indexed count of existing entries).
|
|
566
|
+
*/
|
|
567
|
+
export function getNewEntries(sessionFile, afterLine) {
|
|
568
|
+
return readFileSync(sessionFile, "utf8")
|
|
569
|
+
.split("\n")
|
|
570
|
+
.filter((line) => line.trim())
|
|
571
|
+
.slice(afterLine)
|
|
572
|
+
.map(parseEntry);
|
|
573
|
+
}
|
|
574
|
+
/** Read the effective model and thinking entries recorded by Pi at session startup. */
|
|
575
|
+
export function findObservedSessionRuntime(entries) {
|
|
576
|
+
const observed = {};
|
|
577
|
+
for (const entry of entries) {
|
|
578
|
+
if (entry.type === "model_change") {
|
|
579
|
+
if (isString(entry.provider))
|
|
580
|
+
observed.provider = entry.provider;
|
|
581
|
+
if (isString(entry.modelId))
|
|
582
|
+
observed.modelId = entry.modelId;
|
|
583
|
+
}
|
|
584
|
+
else if (entry.type === "thinking_level_change" &&
|
|
585
|
+
isString(entry.thinkingLevel)) {
|
|
586
|
+
observed.thinking = entry.thinkingLevel;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return observed;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* The model Pi restores when this session is resumed without `--model`, as
|
|
593
|
+
* Pi's own `buildSessionContext()` projects it: the active branch (leaf = last
|
|
594
|
+
* entry, followed through `parentId`) read in order, where each `model_change`
|
|
595
|
+
* and each assistant response sets the model, so the latest one wins.
|
|
596
|
+
* Undefined when the branch records no model or cannot be projected.
|
|
597
|
+
*/
|
|
598
|
+
export function findStoredSessionModel(entries) {
|
|
599
|
+
let model;
|
|
600
|
+
try {
|
|
601
|
+
// The session file's parsed JSONL entries are the input Pi itself
|
|
602
|
+
// projects; a malformed entry throws and is caught below.
|
|
603
|
+
const piEntries = [];
|
|
604
|
+
for (const entry of entries)
|
|
605
|
+
if (isPiSessionEntry(entry))
|
|
606
|
+
piEntries.push(entry);
|
|
607
|
+
model = buildSessionContext(piEntries).model;
|
|
608
|
+
}
|
|
609
|
+
catch {
|
|
610
|
+
return undefined;
|
|
611
|
+
}
|
|
612
|
+
return model && isString(model.provider) && isString(model.modelId)
|
|
613
|
+
? { provider: model.provider, modelId: model.modelId }
|
|
614
|
+
: undefined;
|
|
615
|
+
}
|
|
616
|
+
/** Pi's projection reads an entry's `type`, `id` and `parentId`, and the
|
|
617
|
+
* `message` of a message entry; it skips every other entry type it reads. */
|
|
618
|
+
function isPiSessionEntry(entry) {
|
|
619
|
+
return (isRecord(entry) &&
|
|
620
|
+
isString(entry.type) &&
|
|
621
|
+
isString(entry.id) &&
|
|
622
|
+
(entry.type !== "message" || isRecord(entry.message)));
|
|
623
|
+
}
|
|
624
|
+
/** Inspect only the final assistant message for completion evidence. */
|
|
625
|
+
export function inspectFinalAssistantMessage(entries) {
|
|
626
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
627
|
+
const entry = entries[i];
|
|
628
|
+
if (entry.type !== "message")
|
|
629
|
+
continue;
|
|
630
|
+
// SAFETY: entries with type "message" always carry a `message` field;
|
|
631
|
+
// SessionEntry's index signature can't express this per-variant guarantee.
|
|
632
|
+
const msg = entry;
|
|
633
|
+
if (msg.message.role !== "assistant")
|
|
634
|
+
continue;
|
|
635
|
+
const texts = msg.message.content.flatMap((block) => block.type === "text" && isString(block.text) ? [block.text] : []);
|
|
636
|
+
const text = texts.join("\n");
|
|
637
|
+
const stopReason = msg.message.stopReason;
|
|
638
|
+
const result = {
|
|
639
|
+
text: text.trim() ? text : null,
|
|
640
|
+
contentLength: text.length,
|
|
641
|
+
};
|
|
642
|
+
if (isString(stopReason))
|
|
643
|
+
result.stopReason = stopReason;
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
return { text: null, contentLength: 0 };
|
|
647
|
+
}
|
|
648
|
+
export function findLastAssistantSummary(entries) {
|
|
649
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
650
|
+
const entry = entries[i];
|
|
651
|
+
if (entry.type !== "message")
|
|
652
|
+
continue;
|
|
653
|
+
// SAFETY: entries with type "message" always carry a `message` field;
|
|
654
|
+
// SessionEntry's index signature can't express this per-variant guarantee.
|
|
655
|
+
const msg = entry;
|
|
656
|
+
if (msg.message.role !== "assistant")
|
|
657
|
+
continue;
|
|
658
|
+
const texts = msg.message.content.flatMap((block) => block.type === "text" && isString(block.text) && block.text.trim() !== ""
|
|
659
|
+
? [block.text]
|
|
660
|
+
: []);
|
|
661
|
+
if (texts.length > 0 && texts.join("").trim())
|
|
662
|
+
return { summary: texts.join("\n"), summarySource: "child" };
|
|
663
|
+
const stopReason = msg.message.stopReason;
|
|
664
|
+
const errorMessage = msg.message.errorMessage;
|
|
665
|
+
if (stopReason === "error" &&
|
|
666
|
+
isString(errorMessage) &&
|
|
667
|
+
errorMessage.trim() !== "") {
|
|
668
|
+
return {
|
|
669
|
+
summary: `Subagent error: ${errorMessage.trim()}`,
|
|
670
|
+
summarySource: "child-error",
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Append a branch_summary entry to the session file.
|
|
678
|
+
* Returns the new entry's id.
|
|
679
|
+
*/
|
|
680
|
+
export function appendBranchSummary(sessionFile, branchPointId, fromId, summary) {
|
|
681
|
+
const id = randomBytes(4).toString("hex");
|
|
682
|
+
const entry = {
|
|
683
|
+
type: "branch_summary",
|
|
684
|
+
id,
|
|
685
|
+
parentId: branchPointId,
|
|
686
|
+
timestamp: new Date().toISOString(),
|
|
687
|
+
fromId: fromId ?? branchPointId,
|
|
688
|
+
summary,
|
|
689
|
+
};
|
|
690
|
+
appendFileSync(sessionFile, JSON.stringify(entry) + "\n", "utf8");
|
|
691
|
+
return id;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Copy the session file to destDir for parallel worker isolation.
|
|
695
|
+
* Returns the path of the copy.
|
|
696
|
+
*/
|
|
697
|
+
export function copySessionFile(sessionFile, destDir) {
|
|
698
|
+
const id = randomBytes(4).toString("hex");
|
|
699
|
+
const dest = join(destDir, `subagent-${id}.jsonl`);
|
|
700
|
+
copyFileSync(sessionFile, dest);
|
|
701
|
+
return dest;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Read new entries from sourceFile (after afterLine), append them to targetFile.
|
|
705
|
+
* Returns the appended entries.
|
|
706
|
+
*/
|
|
707
|
+
export function mergeNewEntries(sourceFile, targetFile, afterLine) {
|
|
708
|
+
const entries = getNewEntries(sourceFile, afterLine);
|
|
709
|
+
for (const entry of entries) {
|
|
710
|
+
appendFileSync(targetFile, JSON.stringify(entry) + "\n", "utf8");
|
|
711
|
+
}
|
|
712
|
+
return entries;
|
|
713
|
+
}
|
|
714
|
+
//# sourceMappingURL=session.js.map
|