@llblab/pi-kit 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/AGENTS.md +35 -0
- package/BACKLOG.md +3 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/node_modules/@llblab/pi-actors/AGENTS.md +150 -0
- package/node_modules/@llblab/pi-actors/BACKLOG.md +6 -0
- package/node_modules/@llblab/pi-actors/CHANGELOG.md +865 -0
- package/node_modules/@llblab/pi-actors/README.md +231 -0
- package/node_modules/@llblab/pi-actors/banner.jpg +0 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/artifact-manifest.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/control-endpoint.json +6 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/control-record.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/recipe-summary.json +8 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/run-state.json +10 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/trace-event.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/index.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/index.js +17 -0
- package/node_modules/@llblab/pi-actors/dist/lib/async-runs.d.ts +146 -0
- package/node_modules/@llblab/pi-actors/dist/lib/async-runs.js +800 -0
- package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.js +103 -0
- package/node_modules/@llblab/pi-actors/dist/lib/command-templates.d.ts +85 -0
- package/node_modules/@llblab/pi-actors/dist/lib/command-templates.js +804 -0
- package/node_modules/@llblab/pi-actors/dist/lib/config.d.ts +34 -0
- package/node_modules/@llblab/pi-actors/dist/lib/config.js +216 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control-projection.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control-projection.js +66 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control.d.ts +15 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control.js +97 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation-transaction.d.ts +65 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation-transaction.js +610 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation.d.ts +35 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation.js +126 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-review.d.ts +56 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-review.js +254 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-sleep.d.ts +65 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-sleep.js +467 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-output.d.ts +25 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-output.js +88 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.d.ts +17 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.js +85 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution.d.ts +99 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution.js +725 -0
- package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.js +141 -0
- package/node_modules/@llblab/pi-actors/dist/lib/file-state.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/file-state.js +310 -0
- package/node_modules/@llblab/pi-actors/dist/lib/identity.d.ts +9 -0
- package/node_modules/@llblab/pi-actors/dist/lib/identity.js +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.d.ts +16 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.js +57 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-command.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-command.js +37 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.d.ts +100 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.js +824 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector.js +136 -0
- package/node_modules/@llblab/pi-actors/dist/lib/limits.d.ts +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/limits.js +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/model-context.d.ts +56 -0
- package/node_modules/@llblab/pi-actors/dist/lib/model-context.js +220 -0
- package/node_modules/@llblab/pi-actors/dist/lib/observability.d.ts +186 -0
- package/node_modules/@llblab/pi-actors/dist/lib/observability.js +951 -0
- package/node_modules/@llblab/pi-actors/dist/lib/paths.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/paths.js +72 -0
- package/node_modules/@llblab/pi-actors/dist/lib/pi.d.ts +19 -0
- package/node_modules/@llblab/pi-actors/dist/lib/pi.js +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/preflight-diagnostics.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/preflight-diagnostics.js +86 -0
- package/node_modules/@llblab/pi-actors/dist/lib/prompts.d.ts +24 -0
- package/node_modules/@llblab/pi-actors/dist/lib/prompts.js +49 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipe-control.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipe-control.js +43 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.d.ts +36 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.js +197 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-discovery.d.ts +77 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-discovery.js +783 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-references.d.ts +113 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-references.js +1108 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-usage.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-usage.js +494 -0
- package/node_modules/@llblab/pi-actors/dist/lib/registry.d.ts +67 -0
- package/node_modules/@llblab/pi-actors/dist/lib/registry.js +504 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-control.d.ts +14 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-control.js +110 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-diagnostics.d.ts +11 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-diagnostics.js +148 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-projection.d.ts +14 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-projection.js +166 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-evidence-policy.d.ts +95 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-evidence-policy.js +177 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.js +125 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.js +68 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control-delivery.d.ts +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control-delivery.js +150 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control.js +89 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-controls.d.ts +39 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-controls.js +283 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-identity.d.ts +5 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-identity.js +11 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-index.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-index.js +142 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.js +96 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-parent-teardown.d.ts +51 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-parent-teardown.js +172 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-process.d.ts +22 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-process.js +125 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.js +108 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-start.d.ts +12 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-start.js +68 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-status.d.ts +10 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-status.js +68 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.d.ts +48 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.js +491 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-identity.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-identity.js +35 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-triage.d.ts +29 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-triage.js +60 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime.d.ts +69 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime.js +339 -0
- package/node_modules/@llblab/pi-actors/dist/lib/schema.d.ts +60 -0
- package/node_modules/@llblab/pi-actors/dist/lib/schema.js +428 -0
- package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.d.ts +45 -0
- package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.js +204 -0
- package/node_modules/@llblab/pi-actors/dist/lib/state-readers.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/state-readers.js +74 -0
- package/node_modules/@llblab/pi-actors/dist/lib/temp.d.ts +10 -0
- package/node_modules/@llblab/pi-actors/dist/lib/temp.js +90 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage-transaction.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage-transaction.js +597 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage.d.ts +24 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage.js +98 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-scheduler.d.ts +80 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-scheduler.js +494 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-transaction.d.ts +50 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-transaction.js +362 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review.d.ts +56 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review.js +197 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-access.d.ts +19 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-access.js +44 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.d.ts +15 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.js +532 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-local.d.ts +17 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-local.js +191 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-message.d.ts +9 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-message.js +139 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-register.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-register.js +41 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-response.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-response.js +243 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.d.ts +15 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.js +133 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools.d.ts +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools.js +49 -0
- package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.d.ts +22 -0
- package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.js +231 -0
- package/node_modules/@llblab/pi-actors/dist/pi-actors/index.js +1 -0
- package/node_modules/@llblab/pi-actors/dist/scripts/async-runner.mjs +555 -0
- package/node_modules/@llblab/pi-actors/dist/scripts/build-dist.mjs +60 -0
- package/node_modules/@llblab/pi-actors/dist/scripts/conformance.mjs +63 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/SKILL.md +126 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/command-validate.json +13 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/jsonl-tail.json +10 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/recipe-validate.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/resource-locker-snapshot.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/resource-locker.json +25 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-ops-snapshot.json +15 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-state-files.json +13 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/diagnostics.md +44 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/persistent-tools.md +76 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/recipes.md +51 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/runs.md +41 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/resource-locker.mjs +425 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/run-utils.mjs +164 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/validate-recipe.mjs +370 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/SKILL.md +33 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/bundle.json +77 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/file-write.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/manifest.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/report.json +39 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/write.json +53 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/scripts/artifact-utils.mjs +63 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/SKILL.md +57 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/genapps/music-player.mjs +360 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/recipes/playback.json +29 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/scripts/playback-client.mjs +143 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/scripts/playback.mjs +1446 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/SKILL.md +37 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/changelog-head.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/changelog-section.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/docs-maintenance.json +66 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/git-log.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/git-status.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/markdown-index.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/package-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/release-readiness.json +115 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/release-summary.json +74 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/repo-health.json +75 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/run-ops.json +56 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/skill-summary.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/scripts/project-utils.mjs +89 -0
- package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/SKILL.md +36 -0
- package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/recipes/draft-review.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/recipes/tool-review.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/SKILL.md +84 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/architect.json +82 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/checkpoint-continuation.json +51 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/development-tasking.json +67 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/lens-review.json +63 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/quorum-review.json +65 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/research-synthesis.json +81 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/review-readiness.json +59 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-artifact.json +21 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-checkpoint.json +21 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-conflict-report.json +19 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-contradiction-map.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-critic.json +22 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-evidence-map.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-followup.json +21 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-judge.json +22 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-merge.json +24 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-normalize.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-plan.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-preflight.json +18 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-prompt.json +16 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-prompts.json +39 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-quorum.json +31 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-review-coordinator.json +170 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-review.json +26 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-task-card.json +22 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-tools.json +15 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-verify.json +23 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/references/development-swarm.md +189 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/references/review-swarms.md +115 -0
- package/node_modules/@llblab/pi-actors/docs/README.md +20 -0
- package/node_modules/@llblab/pi-actors/docs/actor-inspector.md +50 -0
- package/node_modules/@llblab/pi-actors/docs/async-runs.md +141 -0
- package/node_modules/@llblab/pi-actors/docs/command-templates.md +321 -0
- package/node_modules/@llblab/pi-actors/docs/recipe-library.md +89 -0
- package/node_modules/@llblab/pi-actors/docs/releasing.md +28 -0
- package/node_modules/@llblab/pi-actors/docs/template-recipes.md +175 -0
- package/node_modules/@llblab/pi-actors/docs/tool-registry.md +90 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/artifact-manifest.json +9 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/control-endpoint.json +6 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/control-record.json +9 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/recipe-summary.json +8 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/run-state.json +10 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/trace-event.json +9 -0
- package/node_modules/@llblab/pi-actors/index.ts +30 -0
- package/node_modules/@llblab/pi-actors/lib/async-runs.ts +1245 -0
- package/node_modules/@llblab/pi-actors/lib/automatic-review-runtime.ts +148 -0
- package/node_modules/@llblab/pi-actors/lib/command-templates.ts +1116 -0
- package/node_modules/@llblab/pi-actors/lib/config.ts +261 -0
- package/node_modules/@llblab/pi-actors/lib/control-projection.ts +105 -0
- package/node_modules/@llblab/pi-actors/lib/control.ts +117 -0
- package/node_modules/@llblab/pi-actors/lib/draft-consolidation-transaction.ts +821 -0
- package/node_modules/@llblab/pi-actors/lib/draft-consolidation.ts +181 -0
- package/node_modules/@llblab/pi-actors/lib/draft-review.ts +325 -0
- package/node_modules/@llblab/pi-actors/lib/draft-sleep.ts +575 -0
- package/node_modules/@llblab/pi-actors/lib/execution-output.ts +123 -0
- package/node_modules/@llblab/pi-actors/lib/execution-sessions.ts +111 -0
- package/node_modules/@llblab/pi-actors/lib/execution.ts +1153 -0
- package/node_modules/@llblab/pi-actors/lib/extension-runtime.ts +181 -0
- package/node_modules/@llblab/pi-actors/lib/file-state.ts +306 -0
- package/node_modules/@llblab/pi-actors/lib/identity.ts +29 -0
- package/node_modules/@llblab/pi-actors/lib/inspector-actions.ts +79 -0
- package/node_modules/@llblab/pi-actors/lib/inspector-command.ts +54 -0
- package/node_modules/@llblab/pi-actors/lib/inspector-overlay.ts +901 -0
- package/node_modules/@llblab/pi-actors/lib/inspector.ts +204 -0
- package/node_modules/@llblab/pi-actors/lib/limits.ts +29 -0
- package/node_modules/@llblab/pi-actors/lib/model-context.ts +359 -0
- package/node_modules/@llblab/pi-actors/lib/observability.ts +1337 -0
- package/node_modules/@llblab/pi-actors/lib/paths.ts +111 -0
- package/node_modules/@llblab/pi-actors/lib/pi.ts +47 -0
- package/node_modules/@llblab/pi-actors/lib/preflight-diagnostics.ts +132 -0
- package/node_modules/@llblab/pi-actors/lib/prompts.ts +69 -0
- package/node_modules/@llblab/pi-actors/lib/recipe-control.ts +52 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-context.ts +268 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-discovery.ts +1060 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-references.ts +1598 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-usage.ts +638 -0
- package/node_modules/@llblab/pi-actors/lib/registry.ts +806 -0
- package/node_modules/@llblab/pi-actors/lib/review-control.ts +136 -0
- package/node_modules/@llblab/pi-actors/lib/review-diagnostics.ts +164 -0
- package/node_modules/@llblab/pi-actors/lib/review-projection.ts +196 -0
- package/node_modules/@llblab/pi-actors/lib/run-evidence-policy.ts +242 -0
- package/node_modules/@llblab/pi-actors/lib/run-ui-runtime.ts +155 -0
- package/node_modules/@llblab/pi-actors/lib/runs-artifacts.ts +96 -0
- package/node_modules/@llblab/pi-actors/lib/runs-control-delivery.ts +209 -0
- package/node_modules/@llblab/pi-actors/lib/runs-control.ts +148 -0
- package/node_modules/@llblab/pi-actors/lib/runs-controls.ts +282 -0
- package/node_modules/@llblab/pi-actors/lib/runs-identity.ts +14 -0
- package/node_modules/@llblab/pi-actors/lib/runs-index.ts +192 -0
- package/node_modules/@llblab/pi-actors/lib/runs-ownership.ts +136 -0
- package/node_modules/@llblab/pi-actors/lib/runs-parent-teardown.ts +257 -0
- package/node_modules/@llblab/pi-actors/lib/runs-process.ts +174 -0
- package/node_modules/@llblab/pi-actors/lib/runs-retention.ts +140 -0
- package/node_modules/@llblab/pi-actors/lib/runs-start.ts +113 -0
- package/node_modules/@llblab/pi-actors/lib/runs-status.ts +101 -0
- package/node_modules/@llblab/pi-actors/lib/runs-trace.ts +611 -0
- package/node_modules/@llblab/pi-actors/lib/runtime-identity.ts +39 -0
- package/node_modules/@llblab/pi-actors/lib/runtime-triage.ts +106 -0
- package/node_modules/@llblab/pi-actors/lib/runtime.ts +430 -0
- package/node_modules/@llblab/pi-actors/lib/schema.ts +525 -0
- package/node_modules/@llblab/pi-actors/lib/session-evidence.ts +302 -0
- package/node_modules/@llblab/pi-actors/lib/state-readers.ts +93 -0
- package/node_modules/@llblab/pi-actors/lib/temp.ts +99 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-lineage-transaction.ts +881 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-lineage.ts +145 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-scheduler.ts +635 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-transaction.ts +563 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review.ts +270 -0
- package/node_modules/@llblab/pi-actors/lib/tools-access.ts +68 -0
- package/node_modules/@llblab/pi-actors/lib/tools-inspect.ts +673 -0
- package/node_modules/@llblab/pi-actors/lib/tools-local.ts +303 -0
- package/node_modules/@llblab/pi-actors/lib/tools-message.ts +176 -0
- package/node_modules/@llblab/pi-actors/lib/tools-register.ts +63 -0
- package/node_modules/@llblab/pi-actors/lib/tools-response.ts +285 -0
- package/node_modules/@llblab/pi-actors/lib/tools-spawn.ts +212 -0
- package/node_modules/@llblab/pi-actors/lib/tools.ts +88 -0
- package/node_modules/@llblab/pi-actors/lib/trace-projection.ts +306 -0
- package/node_modules/@llblab/pi-actors/package.json +76 -0
- package/node_modules/@llblab/pi-actors/scripts/async-runner.mjs +555 -0
- package/node_modules/@llblab/pi-actors/scripts/build-dist.mjs +60 -0
- package/node_modules/@llblab/pi-actors/scripts/conformance.mjs +63 -0
- package/node_modules/@llblab/pi-actors/skills/actors/SKILL.md +126 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/command-validate.json +13 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/jsonl-tail.json +10 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/recipe-validate.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/resource-locker-snapshot.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/resource-locker.json +25 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-ops-snapshot.json +15 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-state-files.json +13 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/diagnostics.md +44 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/persistent-tools.md +76 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/recipes.md +51 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/runs.md +41 -0
- package/node_modules/@llblab/pi-actors/skills/actors/scripts/resource-locker.mjs +425 -0
- package/node_modules/@llblab/pi-actors/skills/actors/scripts/run-utils.mjs +164 -0
- package/node_modules/@llblab/pi-actors/skills/actors/scripts/validate-recipe.mjs +370 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/SKILL.md +33 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/bundle.json +77 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/file-write.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/manifest.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/report.json +39 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/write.json +53 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/scripts/artifact-utils.mjs +63 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/SKILL.md +57 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/genapps/music-player.mjs +360 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/recipes/playback.json +29 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/scripts/playback-client.mjs +143 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/scripts/playback.mjs +1446 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/SKILL.md +37 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/changelog-head.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/changelog-section.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/docs-maintenance.json +66 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/git-log.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/git-status.json +9 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/markdown-index.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/package-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/release-readiness.json +115 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/release-summary.json +74 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/repo-health.json +75 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/run-ops.json +56 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/skill-summary.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/scripts/project-utils.mjs +89 -0
- package/node_modules/@llblab/pi-actors/skills/recipe-memory/SKILL.md +36 -0
- package/node_modules/@llblab/pi-actors/skills/recipe-memory/recipes/draft-review.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/recipe-memory/recipes/tool-review.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/SKILL.md +84 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/architect.json +82 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/checkpoint-continuation.json +51 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/development-tasking.json +67 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/lens-review.json +63 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/quorum-review.json +65 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/research-synthesis.json +81 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/review-readiness.json +59 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-artifact.json +21 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-checkpoint.json +21 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-conflict-report.json +19 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-contradiction-map.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-critic.json +22 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-evidence-map.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-followup.json +21 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-judge.json +22 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-merge.json +24 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-normalize.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-plan.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-preflight.json +18 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-prompt.json +16 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-prompts.json +39 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-quorum.json +31 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-review-coordinator.json +170 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-review.json +26 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-task-card.json +22 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-tools.json +15 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-verify.json +23 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/references/development-swarm.md +189 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/references/review-swarms.md +115 -0
- package/node_modules/@llblab/pi-codex-usage/AGENTS.md +17 -0
- package/node_modules/@llblab/pi-codex-usage/BACKLOG.md +8 -0
- package/node_modules/@llblab/pi-codex-usage/CHANGELOG.md +80 -0
- package/node_modules/@llblab/pi-codex-usage/LICENSE +22 -0
- package/node_modules/@llblab/pi-codex-usage/README.md +113 -0
- package/node_modules/@llblab/pi-codex-usage/banner.jpg +0 -0
- package/node_modules/@llblab/pi-codex-usage/index.ts +1525 -0
- package/node_modules/@llblab/pi-codex-usage/package.json +59 -0
- package/node_modules/@llblab/pi-grow-loop/AGENTS.md +56 -0
- package/node_modules/@llblab/pi-grow-loop/BACKLOG.md +3 -0
- package/node_modules/@llblab/pi-grow-loop/CHANGELOG.md +126 -0
- package/node_modules/@llblab/pi-grow-loop/README.md +216 -0
- package/node_modules/@llblab/pi-grow-loop/banner.jpg +0 -0
- package/node_modules/@llblab/pi-grow-loop/index.ts +219 -0
- package/node_modules/@llblab/pi-grow-loop/package.json +64 -0
- package/node_modules/@llblab/pi-grow-loop/skills/grow-loop/SKILL.md +131 -0
- package/node_modules/@llblab/pi-grow-loop/skills/while-true/SKILL.md +233 -0
- package/node_modules/@llblab/pi-telegram/AGENTS.md +157 -0
- package/node_modules/@llblab/pi-telegram/BACKLOG.md +15 -0
- package/node_modules/@llblab/pi-telegram/CHANGELOG.md +886 -0
- package/node_modules/@llblab/pi-telegram/README.md +330 -0
- package/node_modules/@llblab/pi-telegram/api/activity.ts +15 -0
- package/node_modules/@llblab/pi-telegram/api/commands.ts +11 -0
- package/node_modules/@llblab/pi-telegram/api/delivery.ts +21 -0
- package/node_modules/@llblab/pi-telegram/api/inbound.ts +14 -0
- package/node_modules/@llblab/pi-telegram/api/keyboard.ts +11 -0
- package/node_modules/@llblab/pi-telegram/api/outbound.ts +11 -0
- package/node_modules/@llblab/pi-telegram/api/sections.ts +17 -0
- package/node_modules/@llblab/pi-telegram/api/status.ts +12 -0
- package/node_modules/@llblab/pi-telegram/api/updates.ts +16 -0
- package/node_modules/@llblab/pi-telegram/api/voice.ts +24 -0
- package/node_modules/@llblab/pi-telegram/docs/README.md +25 -0
- package/node_modules/@llblab/pi-telegram/docs/activity.md +304 -0
- package/node_modules/@llblab/pi-telegram/docs/architecture.md +418 -0
- package/node_modules/@llblab/pi-telegram/docs/callback-namespaces.md +48 -0
- package/node_modules/@llblab/pi-telegram/docs/command-templates.md +365 -0
- package/node_modules/@llblab/pi-telegram/docs/compact-matrix-literal.md +176 -0
- package/node_modules/@llblab/pi-telegram/docs/delivery.md +225 -0
- package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +310 -0
- package/node_modules/@llblab/pi-telegram/docs/inbound.md +136 -0
- package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +467 -0
- package/node_modules/@llblab/pi-telegram/docs/outbound.md +193 -0
- package/node_modules/@llblab/pi-telegram/docs/public-api.md +599 -0
- package/node_modules/@llblab/pi-telegram/docs/sections.md +452 -0
- package/node_modules/@llblab/pi-telegram/docs/ui-style.md +256 -0
- package/node_modules/@llblab/pi-telegram/docs/updates.md +171 -0
- package/node_modules/@llblab/pi-telegram/docs/voice.md +217 -0
- package/node_modules/@llblab/pi-telegram/index.ts +1336 -0
- package/node_modules/@llblab/pi-telegram/lib/activity-verbosity.ts +714 -0
- package/node_modules/@llblab/pi-telegram/lib/activity.ts +782 -0
- package/node_modules/@llblab/pi-telegram/lib/agent-messages.ts +121 -0
- package/node_modules/@llblab/pi-telegram/lib/bindings.ts +1129 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-api.ts +379 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +1941 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +2119 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-transport.ts +244 -0
- package/node_modules/@llblab/pi-telegram/lib/bus.ts +2645 -0
- package/node_modules/@llblab/pi-telegram/lib/command-templates.ts +954 -0
- package/node_modules/@llblab/pi-telegram/lib/commands.ts +1854 -0
- package/node_modules/@llblab/pi-telegram/lib/config.ts +1143 -0
- package/node_modules/@llblab/pi-telegram/lib/delivery.ts +891 -0
- package/node_modules/@llblab/pi-telegram/lib/generative-app-worker.mjs +104 -0
- package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +958 -0
- package/node_modules/@llblab/pi-telegram/lib/inbound.ts +824 -0
- package/node_modules/@llblab/pi-telegram/lib/journal.ts +3140 -0
- package/node_modules/@llblab/pi-telegram/lib/keyboard.ts +59 -0
- package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +623 -0
- package/node_modules/@llblab/pi-telegram/lib/locks.ts +1422 -0
- package/node_modules/@llblab/pi-telegram/lib/logs.ts +393 -0
- package/node_modules/@llblab/pi-telegram/lib/media.ts +921 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-model.ts +1182 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-queue.ts +926 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +876 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-status.ts +274 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-thinking.ts +185 -0
- package/node_modules/@llblab/pi-telegram/lib/menu.ts +867 -0
- package/node_modules/@llblab/pi-telegram/lib/model.ts +672 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-attachments.ts +981 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-buttons.ts +331 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +515 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-voice.ts +285 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound.ts +1007 -0
- package/node_modules/@llblab/pi-telegram/lib/ownership.ts +298 -0
- package/node_modules/@llblab/pi-telegram/lib/paths.ts +127 -0
- package/node_modules/@llblab/pi-telegram/lib/pi.ts +197 -0
- package/node_modules/@llblab/pi-telegram/lib/polling.ts +1588 -0
- package/node_modules/@llblab/pi-telegram/lib/preview.ts +846 -0
- package/node_modules/@llblab/pi-telegram/lib/prompt-templates.ts +158 -0
- package/node_modules/@llblab/pi-telegram/lib/prompts.ts +218 -0
- package/node_modules/@llblab/pi-telegram/lib/queue.ts +3075 -0
- package/node_modules/@llblab/pi-telegram/lib/recovery.ts +464 -0
- package/node_modules/@llblab/pi-telegram/lib/rendering.ts +1213 -0
- package/node_modules/@llblab/pi-telegram/lib/replies.ts +892 -0
- package/node_modules/@llblab/pi-telegram/lib/routing.ts +2889 -0
- package/node_modules/@llblab/pi-telegram/lib/runtime.ts +628 -0
- package/node_modules/@llblab/pi-telegram/lib/sections.ts +710 -0
- package/node_modules/@llblab/pi-telegram/lib/setup.ts +220 -0
- package/node_modules/@llblab/pi-telegram/lib/skills.ts +21 -0
- package/node_modules/@llblab/pi-telegram/lib/status.ts +1550 -0
- package/node_modules/@llblab/pi-telegram/lib/sync.ts +883 -0
- package/node_modules/@llblab/pi-telegram/lib/target.ts +49 -0
- package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +1747 -0
- package/node_modules/@llblab/pi-telegram/lib/text-groups.ts +487 -0
- package/node_modules/@llblab/pi-telegram/lib/thread-reconciler.ts +1002 -0
- package/node_modules/@llblab/pi-telegram/lib/threads.ts +3183 -0
- package/node_modules/@llblab/pi-telegram/lib/time-injection.ts +78 -0
- package/node_modules/@llblab/pi-telegram/lib/turns.ts +753 -0
- package/node_modules/@llblab/pi-telegram/lib/updates.ts +4950 -0
- package/node_modules/@llblab/pi-telegram/lib/voice.ts +340 -0
- package/node_modules/@llblab/pi-telegram/package.json +83 -0
- package/node_modules/@llblab/pi-telegram/screenshot.png +0 -0
- package/node_modules/@llblab/pi-telegram/scripts/check-downgrade.mjs +435 -0
- package/node_modules/@llblab/pi-telegram/skills/generated-control-surface/SKILL.md +241 -0
- package/node_modules/@llblab/pi-telegram/skills/generative-apps/SKILL.md +114 -0
- package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/SKILL.md +149 -0
- package/package.json +67 -0
|
@@ -0,0 +1,1116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command-template execution standard.
|
|
3
|
+
* Zones: shell-free command parsing, placeholder expansion, local process execution, composition semantics
|
|
4
|
+
* Owns portable command-template parsing, expansion, risk checks, retries, timeouts, and direct execution.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { accessSync, appendFileSync, constants, mkdirSync, mkdtempSync, statSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { homedir, tmpdir } from "node:os";
|
|
10
|
+
import { basename, delimiter, extname, isAbsolute, join, resolve as resolvePath } from "node:path";
|
|
11
|
+
|
|
12
|
+
export type CommandTemplateFailureScope = "continue" | "branch" | "root";
|
|
13
|
+
|
|
14
|
+
export interface CommandTemplateActorRecipeContext {
|
|
15
|
+
alias?: string;
|
|
16
|
+
file?: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
path?: string;
|
|
19
|
+
role?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CommandTemplateObjectConfig {
|
|
23
|
+
actorRecipeContext?: CommandTemplateActorRecipeContext;
|
|
24
|
+
label?: string;
|
|
25
|
+
parallel?: boolean;
|
|
26
|
+
concurrency?: number | string;
|
|
27
|
+
min_successful?: number | string;
|
|
28
|
+
when?: boolean | string;
|
|
29
|
+
template?: CommandTemplateValue;
|
|
30
|
+
args?: string[];
|
|
31
|
+
defaults?: Record<string, unknown>;
|
|
32
|
+
timeout?: number | string;
|
|
33
|
+
delay?: number | string;
|
|
34
|
+
accept_output?: "review_evidence";
|
|
35
|
+
output?: string;
|
|
36
|
+
retry?: number | string;
|
|
37
|
+
failure?: CommandTemplateFailureScope;
|
|
38
|
+
recover?: CommandTemplateValue;
|
|
39
|
+
repeat?: number | string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type CommandTemplateValue =
|
|
43
|
+
| string
|
|
44
|
+
| CommandTemplateConfig[]
|
|
45
|
+
| CommandTemplateObjectConfig;
|
|
46
|
+
|
|
47
|
+
export type CommandTemplateConfig = string | CommandTemplateObjectConfig;
|
|
48
|
+
|
|
49
|
+
export interface CommandTemplateLeafConfig extends CommandTemplateObjectConfig {
|
|
50
|
+
template: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface CommandTemplateInvocation {
|
|
54
|
+
command: string;
|
|
55
|
+
args: string[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface CommandTemplateExecOptions {
|
|
59
|
+
cwd?: string;
|
|
60
|
+
timeout?: number;
|
|
61
|
+
signal?: AbortSignal;
|
|
62
|
+
stdin?: string;
|
|
63
|
+
killGrace?: number;
|
|
64
|
+
retry?: number;
|
|
65
|
+
captureDir?: string;
|
|
66
|
+
captureLimitBytes?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface CommandTemplateExecResult {
|
|
70
|
+
stdout: string;
|
|
71
|
+
stderr: string;
|
|
72
|
+
code: number;
|
|
73
|
+
killed: boolean;
|
|
74
|
+
stdoutBytes?: number;
|
|
75
|
+
stderrBytes?: number;
|
|
76
|
+
stdoutFile?: string;
|
|
77
|
+
stderrFile?: string;
|
|
78
|
+
stdoutTruncated?: boolean;
|
|
79
|
+
stderrTruncated?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type CommandTemplateRiskLabel =
|
|
83
|
+
| "risk.shell"
|
|
84
|
+
| "risk.eval"
|
|
85
|
+
| "risk.broad_fs_write"
|
|
86
|
+
| "risk.destructive_fs"
|
|
87
|
+
| "risk.network"
|
|
88
|
+
| "risk.external_side_effect"
|
|
89
|
+
| "risk.long_running"
|
|
90
|
+
| "risk.platform_specific"
|
|
91
|
+
| "risk.secret_touching";
|
|
92
|
+
|
|
93
|
+
const DEFAULT_COMMAND_CAPTURE_LIMIT_BYTES = 1024 * 1024;
|
|
94
|
+
|
|
95
|
+
const COMMAND_TEMPLATE_RISK_LABEL_ORDER: CommandTemplateRiskLabel[] = [
|
|
96
|
+
"risk.shell",
|
|
97
|
+
"risk.eval",
|
|
98
|
+
"risk.destructive_fs",
|
|
99
|
+
"risk.broad_fs_write",
|
|
100
|
+
"risk.external_side_effect",
|
|
101
|
+
"risk.secret_touching",
|
|
102
|
+
"risk.network",
|
|
103
|
+
"risk.long_running",
|
|
104
|
+
"risk.platform_specific",
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
export type CommandTemplateExecCommand = (
|
|
108
|
+
command: string,
|
|
109
|
+
args: string[],
|
|
110
|
+
options?: CommandTemplateExecOptions,
|
|
111
|
+
) => Promise<CommandTemplateExecResult>;
|
|
112
|
+
|
|
113
|
+
function normalizeCommandTemplateArgs(value: string[] | undefined): string[] {
|
|
114
|
+
if (!Array.isArray(value)) return [];
|
|
115
|
+
return value.map(String).map((item) => item.trim());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function normalizeCommandTemplateConfig(
|
|
119
|
+
config: CommandTemplateConfig,
|
|
120
|
+
): CommandTemplateObjectConfig {
|
|
121
|
+
return typeof config === "string" ? { template: config } : config;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function normalizeRecoverConfig(
|
|
125
|
+
config: CommandTemplateValue | undefined,
|
|
126
|
+
): CommandTemplateConfig | undefined {
|
|
127
|
+
if (config === undefined) return undefined;
|
|
128
|
+
return Array.isArray(config) ? { template: config } : config;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function normalizeCommandTemplateDefaults(
|
|
132
|
+
defaults: Record<string, unknown> | undefined,
|
|
133
|
+
): Record<string, unknown> | undefined {
|
|
134
|
+
if (!defaults) return undefined;
|
|
135
|
+
const normalized: Record<string, unknown> = {};
|
|
136
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
137
|
+
normalized[key] = Array.isArray(value)
|
|
138
|
+
? value
|
|
139
|
+
: value === undefined || value === null
|
|
140
|
+
? ""
|
|
141
|
+
: String(value);
|
|
142
|
+
}
|
|
143
|
+
return normalized;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function resolveInheritedDefaultReferences(
|
|
147
|
+
ownDefaults: Record<string, unknown> | undefined,
|
|
148
|
+
inheritedDefaults: Record<string, unknown> | undefined,
|
|
149
|
+
runtimeValues: Record<string, unknown> = {},
|
|
150
|
+
): Record<string, unknown> | undefined {
|
|
151
|
+
if (!ownDefaults) return ownDefaults;
|
|
152
|
+
const resolved = { ...ownDefaults };
|
|
153
|
+
const values = { ...(inheritedDefaults ?? {}), ...runtimeValues };
|
|
154
|
+
for (const [key, value] of Object.entries(ownDefaults)) {
|
|
155
|
+
if (typeof value !== "string") continue;
|
|
156
|
+
const exact = /^\{([A-Za-z_][A-Za-z0-9_-]*)\}$/.exec(value);
|
|
157
|
+
if (exact && Object.hasOwn(values, exact[1])) {
|
|
158
|
+
resolved[key] = values[exact[1]];
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const indexed = value.match(
|
|
162
|
+
/^\{([A-Za-z_][A-Za-z0-9_-]*)\[([A-Za-z_][A-Za-z0-9_-]*|\d+)\]\}$/,
|
|
163
|
+
);
|
|
164
|
+
if (!indexed) continue;
|
|
165
|
+
const source = values[indexed[1]];
|
|
166
|
+
const indexValue = /^\d+$/.test(indexed[2])
|
|
167
|
+
? indexed[2]
|
|
168
|
+
: values[indexed[2]];
|
|
169
|
+
const index = Number(indexValue);
|
|
170
|
+
if (
|
|
171
|
+
Array.isArray(source) &&
|
|
172
|
+
Number.isInteger(index) &&
|
|
173
|
+
index >= 0 &&
|
|
174
|
+
index < source.length
|
|
175
|
+
) {
|
|
176
|
+
resolved[key] = source[index] ?? "";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return resolved;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function resolveCommandTemplateRepeat(
|
|
183
|
+
value: number | string | undefined,
|
|
184
|
+
values: Record<string, unknown> = {},
|
|
185
|
+
): number | undefined {
|
|
186
|
+
if (value === undefined) return undefined;
|
|
187
|
+
if (typeof value === "number") {
|
|
188
|
+
if (!Number.isInteger(value) || value < 1)
|
|
189
|
+
throw new Error("Command template repeat must be a positive integer.");
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
const trimmed = value.trim();
|
|
193
|
+
if (/^\d+$/.test(trimmed)) return Number(trimmed);
|
|
194
|
+
const lengthMatch = trimmed.match(
|
|
195
|
+
/^\{?([A-Za-z_][A-Za-z0-9_-]*)\.length\}?$/,
|
|
196
|
+
);
|
|
197
|
+
if (lengthMatch) {
|
|
198
|
+
const source = values[lengthMatch[1]];
|
|
199
|
+
if (Array.isArray(source)) return source.length;
|
|
200
|
+
if (source === undefined) return undefined;
|
|
201
|
+
}
|
|
202
|
+
throw new Error(
|
|
203
|
+
"Command template repeat must be a positive integer or {array.length}.",
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function getExecutableName(command: string | undefined): string {
|
|
208
|
+
if (!command) return "";
|
|
209
|
+
return command.split(/[\\/]/).pop()?.toLowerCase() ?? "";
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function matchesFlag(arg: string, flag: string): boolean {
|
|
213
|
+
if (arg === flag) return true;
|
|
214
|
+
if (/^-[A-Za-z]$/.test(flag) && /^-[A-Za-z]+$/.test(arg))
|
|
215
|
+
return arg.slice(1).includes(flag.slice(1));
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function hasAnyFlag(args: string[], flags: string[]): boolean {
|
|
220
|
+
return args.some((arg) => flags.some((flag) => matchesFlag(arg, flag)));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function hasRiskyPathArg(args: string[]): boolean {
|
|
224
|
+
return args.some(
|
|
225
|
+
(arg) =>
|
|
226
|
+
arg === "/" ||
|
|
227
|
+
arg === "~" ||
|
|
228
|
+
arg === "./" ||
|
|
229
|
+
arg === "../" ||
|
|
230
|
+
arg.includes("{") ||
|
|
231
|
+
arg.startsWith("~/") ||
|
|
232
|
+
arg.startsWith("/"),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function sortRiskLabels(
|
|
237
|
+
labels: Iterable<CommandTemplateRiskLabel>,
|
|
238
|
+
): CommandTemplateRiskLabel[] {
|
|
239
|
+
const unique = new Set(labels);
|
|
240
|
+
return COMMAND_TEMPLATE_RISK_LABEL_ORDER.filter((label) => unique.has(label));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function hasAnyArg(args: string[], values: string[]): boolean {
|
|
244
|
+
return args.some((arg) => values.includes(arg.toLowerCase()));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function hasSecretTouchingText(parts: string[]): boolean {
|
|
248
|
+
return parts.some((part) =>
|
|
249
|
+
/(^|[{}._\-\s/])(?:secret|token|password|passwd|credential|api[_-]?key|private[_-]?key|\.env|ssh[_-]?key)(?:[{}._\-\s/]|$)/i.test(
|
|
250
|
+
part,
|
|
251
|
+
),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function getLeafCommandTemplateRiskLabels(
|
|
256
|
+
config: CommandTemplateLeafConfig,
|
|
257
|
+
): CommandTemplateRiskLabel[] {
|
|
258
|
+
const parts = splitCommandTemplate(config.template);
|
|
259
|
+
const command = getExecutableName(parts[0]);
|
|
260
|
+
const args = parts.slice(1);
|
|
261
|
+
const labels = new Set<CommandTemplateRiskLabel>();
|
|
262
|
+
if (["bash", "sh", "zsh", "fish"].includes(command) || command.endsWith(".sh")) {
|
|
263
|
+
labels.add("risk.shell");
|
|
264
|
+
if (hasAnyFlag(args, ["-c"])) labels.add("risk.eval");
|
|
265
|
+
}
|
|
266
|
+
if (
|
|
267
|
+
["node", "deno", "bun"].includes(command) &&
|
|
268
|
+
hasAnyFlag(args, ["-e", "--eval"])
|
|
269
|
+
) {
|
|
270
|
+
labels.add("risk.eval");
|
|
271
|
+
}
|
|
272
|
+
if (
|
|
273
|
+
["python", "python3", "perl", "ruby"].includes(command) &&
|
|
274
|
+
hasAnyFlag(args, ["-c", "-e"])
|
|
275
|
+
) {
|
|
276
|
+
labels.add("risk.eval");
|
|
277
|
+
}
|
|
278
|
+
if (
|
|
279
|
+
command === "rm" &&
|
|
280
|
+
(args.some((arg) => /^-[^-]*r/.test(arg) || /^-[^-]*f/.test(arg)) ||
|
|
281
|
+
hasRiskyPathArg(args))
|
|
282
|
+
) {
|
|
283
|
+
labels.add("risk.destructive_fs");
|
|
284
|
+
}
|
|
285
|
+
if (["mv", "cp", "rsync"].includes(command) && hasRiskyPathArg(args)) {
|
|
286
|
+
labels.add("risk.broad_fs_write");
|
|
287
|
+
}
|
|
288
|
+
if (
|
|
289
|
+
["curl", "wget", "ssh", "scp", "sftp", "rsync", "nc", "ncat", "telnet", "ftp"].includes(
|
|
290
|
+
command,
|
|
291
|
+
) ||
|
|
292
|
+
(command === "git" &&
|
|
293
|
+
hasAnyArg(args, ["clone", "fetch", "pull", "push", "ls-remote"])) ||
|
|
294
|
+
["npm", "pnpm", "yarn", "pip", "cargo"].includes(command)
|
|
295
|
+
) {
|
|
296
|
+
labels.add("risk.network");
|
|
297
|
+
}
|
|
298
|
+
if (
|
|
299
|
+
["gh", "glab", "hub", "kubectl", "terraform"].includes(command) ||
|
|
300
|
+
(command === "git" && hasAnyArg(args, ["push"])) ||
|
|
301
|
+
(["npm", "pnpm", "yarn"].includes(command) &&
|
|
302
|
+
hasAnyArg(args, ["publish", "login", "logout", "deprecate"]))
|
|
303
|
+
) {
|
|
304
|
+
labels.add("risk.external_side_effect");
|
|
305
|
+
}
|
|
306
|
+
if (
|
|
307
|
+
command === "sleep" ||
|
|
308
|
+
command === "watch" ||
|
|
309
|
+
(command === "tail" && hasAnyFlag(args, ["-f"])) ||
|
|
310
|
+
hasAnyArg(args, ["--watch", "--serve", "serve"])
|
|
311
|
+
) {
|
|
312
|
+
labels.add("risk.long_running");
|
|
313
|
+
}
|
|
314
|
+
if (
|
|
315
|
+
["systemctl", "launchctl", "osascript", "open", "xdg-open", "powershell", "pwsh", "cmd.exe", "apt", "apt-get", "dnf", "yum", "brew", "pacman", "apk", "xclip", "wl-copy"].includes(
|
|
316
|
+
command,
|
|
317
|
+
)
|
|
318
|
+
) {
|
|
319
|
+
labels.add("risk.platform_specific");
|
|
320
|
+
}
|
|
321
|
+
if (["pass", "gpg", "ssh-add"].includes(command) || hasSecretTouchingText(parts)) {
|
|
322
|
+
labels.add("risk.secret_touching");
|
|
323
|
+
}
|
|
324
|
+
return sortRiskLabels(labels);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function getLeafCommandTemplateWarnings(
|
|
328
|
+
config: CommandTemplateLeafConfig,
|
|
329
|
+
): string[] {
|
|
330
|
+
const parts = splitCommandTemplate(config.template);
|
|
331
|
+
const command = getExecutableName(parts[0]);
|
|
332
|
+
const args = parts.slice(1);
|
|
333
|
+
const warnings: string[] = [];
|
|
334
|
+
if (["bash", "sh", "zsh", "fish"].includes(command)) {
|
|
335
|
+
const shellContent = hasAnyFlag(args, ["-c"])
|
|
336
|
+
? "shell command strings"
|
|
337
|
+
: "shell scripts";
|
|
338
|
+
warnings.push(
|
|
339
|
+
`${config.label ?? command}: invokes ${command}; ${shellContent} are trusted executable content and are not sandboxed by command-template argv splitting. Mitigation: keep scripts local, reviewed, and parameterized with explicit placeholders.`,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
if (
|
|
343
|
+
["node", "deno", "bun"].includes(command) &&
|
|
344
|
+
hasAnyFlag(args, ["-e", "--eval"])
|
|
345
|
+
) {
|
|
346
|
+
warnings.push(
|
|
347
|
+
`${config.label ?? command}: invokes ${command} eval mode; code strings are trusted executable content and are not sandboxed. Mitigation: prefer a checked-in script file or keep eval input fixed and reviewed.`,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
if (
|
|
351
|
+
["python", "python3", "perl", "ruby"].includes(command) &&
|
|
352
|
+
hasAnyFlag(args, ["-c", "-e"])
|
|
353
|
+
) {
|
|
354
|
+
warnings.push(
|
|
355
|
+
`${config.label ?? command}: invokes ${command} code-eval mode; code strings are trusted executable content and are not sandboxed. Mitigation: prefer a checked-in script file or keep eval input fixed and reviewed.`,
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
if (
|
|
359
|
+
command === "rm" &&
|
|
360
|
+
(args.some((arg) => /^-[^-]*r/.test(arg) || /^-[^-]*f/.test(arg)) ||
|
|
361
|
+
hasRiskyPathArg(args))
|
|
362
|
+
) {
|
|
363
|
+
warnings.push(
|
|
364
|
+
`${config.label ?? command}: removes filesystem paths; verify placeholders and paths before running trusted destructive commands. Mitigation: constrain path placeholders and consider dry-run or explicit confirmation.`,
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
if (["mv", "cp", "rsync"].includes(command) && hasRiskyPathArg(args)) {
|
|
368
|
+
warnings.push(
|
|
369
|
+
`${config.label ?? command}: mutates broad filesystem paths; verify placeholders and paths before running trusted commands. Mitigation: constrain path placeholders and prefer narrow source/destination paths.`,
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return warnings;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function pad(value: number, width: number): string {
|
|
376
|
+
return String(value).padStart(width, "0");
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function isCommandTemplateRepeatPlaceholder(name: string): boolean {
|
|
380
|
+
return /^_{0,6}(?:index|prev|next|repeat)$/.test(name);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function getCommandTemplateRepeatDefaults(
|
|
384
|
+
index: number,
|
|
385
|
+
repeat: number,
|
|
386
|
+
): Record<string, string> {
|
|
387
|
+
const prev = (index - 1 + repeat) % repeat;
|
|
388
|
+
const next = (index + 1) % repeat;
|
|
389
|
+
const values: Record<string, string> = {
|
|
390
|
+
index: String(index),
|
|
391
|
+
next: String(next),
|
|
392
|
+
prev: String(prev),
|
|
393
|
+
repeat: String(repeat),
|
|
394
|
+
};
|
|
395
|
+
for (const name of ["index", "prev", "next", "repeat"]) {
|
|
396
|
+
const numeric = Number(values[name]);
|
|
397
|
+
for (let underscores = 1; underscores <= 6; underscores += 1) {
|
|
398
|
+
values[`${"_".repeat(underscores)}${name}`] = pad(
|
|
399
|
+
numeric,
|
|
400
|
+
underscores + 1,
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return values;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function expandRepeatConfig(
|
|
408
|
+
config: CommandTemplateObjectConfig,
|
|
409
|
+
context: Pick<CommandTemplateObjectConfig, "args" | "defaults">,
|
|
410
|
+
): CommandTemplateObjectConfig[] | undefined {
|
|
411
|
+
const repeat = resolveCommandTemplateRepeat(
|
|
412
|
+
config.repeat,
|
|
413
|
+
context.defaults ?? {},
|
|
414
|
+
);
|
|
415
|
+
if (repeat === undefined) return undefined;
|
|
416
|
+
return Array.from({ length: repeat }, (_unused, index0) => {
|
|
417
|
+
const { repeat: _repeat, ...rest } = config;
|
|
418
|
+
return {
|
|
419
|
+
...rest,
|
|
420
|
+
defaults: {
|
|
421
|
+
...(context.defaults ?? {}),
|
|
422
|
+
...(rest.defaults ?? {}),
|
|
423
|
+
...getCommandTemplateRepeatDefaults(index0, repeat),
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export function expandCommandTemplateConfigs(
|
|
430
|
+
config: CommandTemplateConfig,
|
|
431
|
+
inherited: Pick<CommandTemplateObjectConfig, "args" | "defaults"> = {},
|
|
432
|
+
): CommandTemplateLeafConfig[] {
|
|
433
|
+
const normalizedConfig = normalizeCommandTemplateConfig(config);
|
|
434
|
+
const inheritedDefaults = normalizeCommandTemplateDefaults(
|
|
435
|
+
inherited.defaults,
|
|
436
|
+
);
|
|
437
|
+
const ownDefaults = resolveInheritedDefaultReferences(
|
|
438
|
+
normalizeCommandTemplateDefaults(normalizedConfig.defaults),
|
|
439
|
+
inheritedDefaults,
|
|
440
|
+
);
|
|
441
|
+
const context = {
|
|
442
|
+
...(inherited.args !== undefined ? { args: inherited.args } : {}),
|
|
443
|
+
...(inheritedDefaults ? { defaults: inheritedDefaults } : {}),
|
|
444
|
+
...(normalizedConfig.args !== undefined
|
|
445
|
+
? { args: normalizedConfig.args }
|
|
446
|
+
: {}),
|
|
447
|
+
...(ownDefaults
|
|
448
|
+
? { defaults: { ...(inheritedDefaults ?? {}), ...ownDefaults } }
|
|
449
|
+
: {}),
|
|
450
|
+
};
|
|
451
|
+
const repeated = expandRepeatConfig(normalizedConfig, context);
|
|
452
|
+
if (repeated) {
|
|
453
|
+
return repeated.flatMap((step) =>
|
|
454
|
+
expandCommandTemplateConfigs(step, context),
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
const recoverConfig = normalizeRecoverConfig(normalizedConfig.recover);
|
|
458
|
+
const recoverSteps = recoverConfig
|
|
459
|
+
? expandCommandTemplateConfigs(recoverConfig, context)
|
|
460
|
+
: [];
|
|
461
|
+
if (Array.isArray(normalizedConfig.template)) {
|
|
462
|
+
return [
|
|
463
|
+
...normalizedConfig.template.flatMap((step) =>
|
|
464
|
+
expandCommandTemplateConfigs(step, context),
|
|
465
|
+
),
|
|
466
|
+
...recoverSteps,
|
|
467
|
+
];
|
|
468
|
+
}
|
|
469
|
+
if (typeof normalizedConfig.template !== "string") return recoverSteps;
|
|
470
|
+
return [
|
|
471
|
+
{
|
|
472
|
+
...normalizedConfig,
|
|
473
|
+
...context,
|
|
474
|
+
template: normalizedConfig.template,
|
|
475
|
+
retry: normalizedConfig.retry,
|
|
476
|
+
},
|
|
477
|
+
...recoverSteps,
|
|
478
|
+
];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export function getCommandTemplateWarnings(
|
|
482
|
+
config: CommandTemplateConfig,
|
|
483
|
+
): string[] {
|
|
484
|
+
return [
|
|
485
|
+
...new Set(
|
|
486
|
+
expandCommandTemplateConfigs(config).flatMap((leaf) =>
|
|
487
|
+
getLeafCommandTemplateWarnings(leaf),
|
|
488
|
+
),
|
|
489
|
+
),
|
|
490
|
+
];
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export function getCommandTemplateRiskLabels(
|
|
494
|
+
config: CommandTemplateConfig,
|
|
495
|
+
): CommandTemplateRiskLabel[] {
|
|
496
|
+
return sortRiskLabels(
|
|
497
|
+
expandCommandTemplateConfigs(config).flatMap((leaf) =>
|
|
498
|
+
getLeafCommandTemplateRiskLabels(leaf),
|
|
499
|
+
),
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function parseCommandTemplateArgToken(value: string): {
|
|
504
|
+
name: string;
|
|
505
|
+
defaultValue?: string;
|
|
506
|
+
} {
|
|
507
|
+
const separatorIndex = value.indexOf("=");
|
|
508
|
+
const rawName =
|
|
509
|
+
separatorIndex === -1 ? value : value.slice(0, separatorIndex);
|
|
510
|
+
const colonIndex = rawName.indexOf(":");
|
|
511
|
+
return {
|
|
512
|
+
name: (colonIndex === -1 ? rawName : rawName.slice(0, colonIndex)).trim(),
|
|
513
|
+
...(separatorIndex === -1
|
|
514
|
+
? {}
|
|
515
|
+
: { defaultValue: value.slice(separatorIndex + 1).trim() }),
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function parseCommandTemplatePlaceholderContent(
|
|
520
|
+
content: string,
|
|
521
|
+
): { name: string; inlineDefault?: string } | undefined {
|
|
522
|
+
const match = content.match(
|
|
523
|
+
/^([A-Za-z_][A-Za-z0-9_-]*)(?::(?:string|path|int|number|bool|array|enum\([^)]*\)))?(?:=([^}]*))?$/,
|
|
524
|
+
);
|
|
525
|
+
if (!match) return undefined;
|
|
526
|
+
return {
|
|
527
|
+
name: match[1],
|
|
528
|
+
...(match[2] !== undefined ? { inlineDefault: match[2] } : {}),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export function getCommandTemplateDefaults(
|
|
533
|
+
config: CommandTemplateConfig | undefined,
|
|
534
|
+
): Record<string, string> {
|
|
535
|
+
const normalizedConfig = config
|
|
536
|
+
? normalizeCommandTemplateConfig(config)
|
|
537
|
+
: undefined;
|
|
538
|
+
const defaults: Record<string, string> = {};
|
|
539
|
+
for (const item of normalizeCommandTemplateArgs(normalizedConfig?.args)) {
|
|
540
|
+
if (!item) continue;
|
|
541
|
+
const parsed = parseCommandTemplateArgToken(item);
|
|
542
|
+
if (!parsed.name || parsed.defaultValue === undefined) continue;
|
|
543
|
+
defaults[parsed.name] = parsed.defaultValue;
|
|
544
|
+
}
|
|
545
|
+
for (const [key, value] of Object.entries(normalizedConfig?.defaults ?? {})) {
|
|
546
|
+
defaults[key] = value === undefined || value === null ? "" : String(value);
|
|
547
|
+
}
|
|
548
|
+
return defaults;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export function splitCommandTemplate(input: string): string[] {
|
|
552
|
+
const words: string[] = [];
|
|
553
|
+
let current = "";
|
|
554
|
+
let quote: "'" | '"' | undefined;
|
|
555
|
+
let escaped = false;
|
|
556
|
+
let active = false;
|
|
557
|
+
for (const char of input) {
|
|
558
|
+
if (escaped) {
|
|
559
|
+
current += /[\s'"\\]/u.test(char) ? char : `\\${char}`;
|
|
560
|
+
escaped = false;
|
|
561
|
+
active = true;
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (char === "\\" && quote !== "'") {
|
|
565
|
+
escaped = true;
|
|
566
|
+
active = true;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (quote) {
|
|
570
|
+
if (char === quote) quote = undefined;
|
|
571
|
+
else current += char;
|
|
572
|
+
active = true;
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
if (char === "'" || char === '"') {
|
|
576
|
+
quote = char;
|
|
577
|
+
active = true;
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
if (/\s/.test(char)) {
|
|
581
|
+
if (active) words.push(current);
|
|
582
|
+
if (active) current = "";
|
|
583
|
+
active = false;
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
current += char;
|
|
587
|
+
active = true;
|
|
588
|
+
}
|
|
589
|
+
if (escaped) current += "\\";
|
|
590
|
+
if (active || current) words.push(current);
|
|
591
|
+
return words;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export function expandCommandTemplateExecutable(
|
|
595
|
+
command: string,
|
|
596
|
+
cwd: string,
|
|
597
|
+
): string {
|
|
598
|
+
if (command === "~") return homedir();
|
|
599
|
+
if (command.startsWith("~/")) return resolvePath(homedir(), command.slice(2));
|
|
600
|
+
if (command.includes("/") && !isAbsolute(command))
|
|
601
|
+
return resolvePath(cwd, command);
|
|
602
|
+
return command;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export type CommandTemplateExecutableResolver = (name: string) => string | undefined;
|
|
606
|
+
|
|
607
|
+
function resolveExecutableOnPath(name: string): string | undefined {
|
|
608
|
+
if (name === "node" && /^node(?:\.exe)?$/i.test(basename(process.execPath)))
|
|
609
|
+
return process.execPath;
|
|
610
|
+
const pathValue = Object.entries(process.env)
|
|
611
|
+
.find(([key]) => key.toLowerCase() === "path")?.[1] ?? "";
|
|
612
|
+
const suffixes = process.platform === "win32" ? [".exe", ".com"] : [""];
|
|
613
|
+
for (const entry of pathValue.split(delimiter).filter(Boolean)) {
|
|
614
|
+
const directory = entry.replace(/^"|"$/g, "");
|
|
615
|
+
for (const suffix of suffixes) {
|
|
616
|
+
const candidate = join(directory, `${name}${suffix}`);
|
|
617
|
+
try {
|
|
618
|
+
accessSync(candidate, constants.X_OK);
|
|
619
|
+
if (statSync(candidate).isFile()) return candidate;
|
|
620
|
+
} catch {}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return undefined;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export function resolveCommandTemplateScriptInvocation(
|
|
627
|
+
invocation: CommandTemplateInvocation,
|
|
628
|
+
resolveExecutable: CommandTemplateExecutableResolver = resolveExecutableOnPath,
|
|
629
|
+
): CommandTemplateInvocation {
|
|
630
|
+
const extension = extname(invocation.command).toLowerCase();
|
|
631
|
+
const interpreters = extension === ".js" || extension === ".mjs"
|
|
632
|
+
? [["node"], ["bun"], ["deno", "run"]]
|
|
633
|
+
: extension === ".sh" ? [["bash"]] : [];
|
|
634
|
+
if (interpreters.length === 0) return invocation;
|
|
635
|
+
for (const [name, ...prefix] of interpreters) {
|
|
636
|
+
const executable = resolveExecutable(name);
|
|
637
|
+
if (executable)
|
|
638
|
+
return { command: executable, args: [...prefix, invocation.command, ...invocation.args] };
|
|
639
|
+
}
|
|
640
|
+
throw new Error(
|
|
641
|
+
`No interpreter available for command-template ${extension} script; tried ${interpreters.map(([name]) => name).join(", ")}.`,
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function evaluateCommandTemplateExpression(
|
|
646
|
+
expression: string,
|
|
647
|
+
values: Record<string, unknown>,
|
|
648
|
+
): number {
|
|
649
|
+
let index = 0;
|
|
650
|
+
const source = expression.replace(/\s+/g, "");
|
|
651
|
+
function peek(): string | undefined {
|
|
652
|
+
return source[index];
|
|
653
|
+
}
|
|
654
|
+
function consume(char: string): boolean {
|
|
655
|
+
if (peek() !== char) return false;
|
|
656
|
+
index += 1;
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
function parsePrimary(): number {
|
|
660
|
+
if (consume("(")) {
|
|
661
|
+
const value = parseExpression();
|
|
662
|
+
if (!consume(")"))
|
|
663
|
+
throw new Error(`Invalid command template expression: ${expression}`);
|
|
664
|
+
return value;
|
|
665
|
+
}
|
|
666
|
+
const numberMatch = source.slice(index).match(/^\d+/);
|
|
667
|
+
if (numberMatch) {
|
|
668
|
+
index += numberMatch[0].length;
|
|
669
|
+
return Number(numberMatch[0]);
|
|
670
|
+
}
|
|
671
|
+
const nameMatch = source.slice(index).match(/^[A-Za-z_][A-Za-z0-9_-]*/);
|
|
672
|
+
if (nameMatch) {
|
|
673
|
+
index += nameMatch[0].length;
|
|
674
|
+
const value = values[nameMatch[0]];
|
|
675
|
+
if (value === undefined || !/^-?\d+$/.test(String(value)))
|
|
676
|
+
throw new Error(
|
|
677
|
+
`Invalid command template expression variable: ${nameMatch[0]}`,
|
|
678
|
+
);
|
|
679
|
+
return Number(value);
|
|
680
|
+
}
|
|
681
|
+
throw new Error(`Invalid command template expression: ${expression}`);
|
|
682
|
+
}
|
|
683
|
+
function parseTerm(): number {
|
|
684
|
+
let value = parsePrimary();
|
|
685
|
+
while (true) {
|
|
686
|
+
if (consume("*")) value *= parsePrimary();
|
|
687
|
+
else if (consume("/")) value = Math.trunc(value / parsePrimary());
|
|
688
|
+
else if (consume("%")) value %= parsePrimary();
|
|
689
|
+
else return value;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function parseExpression(): number {
|
|
693
|
+
let value = parseTerm();
|
|
694
|
+
while (true) {
|
|
695
|
+
if (consume("+")) value += parseTerm();
|
|
696
|
+
else if (consume("-")) value -= parseTerm();
|
|
697
|
+
else return value;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
const value = parseExpression();
|
|
701
|
+
if (index !== source.length)
|
|
702
|
+
throw new Error(`Invalid command template expression: ${expression}`);
|
|
703
|
+
return value;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function substituteCommandTemplateExpression(
|
|
707
|
+
content: string,
|
|
708
|
+
values: Record<string, unknown>,
|
|
709
|
+
): string | undefined {
|
|
710
|
+
const padded = content.match(/^(_{1,6})\((.+)\)$/);
|
|
711
|
+
if (padded) {
|
|
712
|
+
return pad(
|
|
713
|
+
evaluateCommandTemplateExpression(padded[2], values),
|
|
714
|
+
padded[1].length + 1,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
if (!/[()+\-*\/%]/.test(content)) return undefined;
|
|
718
|
+
return String(evaluateCommandTemplateExpression(content, values));
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function shouldResolveEmbeddedCommandTemplateToken(
|
|
722
|
+
token: string,
|
|
723
|
+
values: Record<string, unknown>,
|
|
724
|
+
): boolean {
|
|
725
|
+
const matches = [...token.matchAll(/\{([^{}]+)\}/g)];
|
|
726
|
+
if (matches.length === 0) return false;
|
|
727
|
+
return matches.every((match) => {
|
|
728
|
+
const content = match[1];
|
|
729
|
+
if (resolveCommandTemplateNullish(content, values) !== undefined)
|
|
730
|
+
return true;
|
|
731
|
+
if (resolveCommandTemplateTernary(content, values) !== undefined)
|
|
732
|
+
return true;
|
|
733
|
+
const indexed = content.match(
|
|
734
|
+
/^([A-Za-z_][A-Za-z0-9_-]*)\[([A-Za-z_][A-Za-z0-9_-]*|\d+)\]$/,
|
|
735
|
+
);
|
|
736
|
+
if (indexed) return Object.hasOwn(values, indexed[1]);
|
|
737
|
+
const simple = parseCommandTemplatePlaceholderContent(content);
|
|
738
|
+
if (simple)
|
|
739
|
+
return (
|
|
740
|
+
Object.hasOwn(values, simple.name) || simple.inlineDefault !== undefined
|
|
741
|
+
);
|
|
742
|
+
try {
|
|
743
|
+
return substituteCommandTemplateExpression(content, values) !== undefined;
|
|
744
|
+
} catch {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function isFalsyCommandTemplateValue(value: unknown): boolean {
|
|
751
|
+
if (value === undefined || value === null || value === false) return true;
|
|
752
|
+
const normalized = String(value).trim().toLowerCase();
|
|
753
|
+
return (
|
|
754
|
+
normalized === "" ||
|
|
755
|
+
normalized === "0" ||
|
|
756
|
+
normalized === "false" ||
|
|
757
|
+
normalized === "no"
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function resolveCommandTemplateCondition(
|
|
762
|
+
condition: string,
|
|
763
|
+
values: Record<string, unknown>,
|
|
764
|
+
): unknown {
|
|
765
|
+
const trimmed = condition.trim();
|
|
766
|
+
const negated = trimmed.startsWith("!");
|
|
767
|
+
const name = negated ? trimmed.slice(1).trim() : trimmed;
|
|
768
|
+
const value = /^[A-Za-z_][A-Za-z0-9_-]*$/.test(name)
|
|
769
|
+
? values[name]
|
|
770
|
+
: undefined;
|
|
771
|
+
return negated ? isFalsyCommandTemplateValue(value) : value;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
export function shouldRunCommandTemplateNode(
|
|
775
|
+
value: boolean | string | undefined,
|
|
776
|
+
values: Record<string, unknown>,
|
|
777
|
+
): boolean {
|
|
778
|
+
if (value === undefined) return true;
|
|
779
|
+
if (typeof value === "boolean") return value;
|
|
780
|
+
const trimmed = value.trim();
|
|
781
|
+
if (!trimmed) return false;
|
|
782
|
+
const exact = /^\{([^{}]+)\}$/.exec(trimmed);
|
|
783
|
+
const resolved = exact
|
|
784
|
+
? resolveCommandTemplateValue(exact[1], values, "command template when")
|
|
785
|
+
: resolveCommandTemplateCondition(trimmed, values);
|
|
786
|
+
return !isFalsyCommandTemplateValue(resolved);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function resolveCommandTemplateNullish(
|
|
790
|
+
content: string,
|
|
791
|
+
values: Record<string, unknown>,
|
|
792
|
+
): string | undefined {
|
|
793
|
+
const coalescing = content.match(/^([A-Za-z_][A-Za-z0-9_-]*)\?\?(.*)$/);
|
|
794
|
+
if (!coalescing) return undefined;
|
|
795
|
+
const value = values[coalescing[1]];
|
|
796
|
+
return isFalsyCommandTemplateValue(value) ? coalescing[2] : String(value);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function resolveCommandTemplateTernary(
|
|
800
|
+
content: string,
|
|
801
|
+
values: Record<string, unknown>,
|
|
802
|
+
): string | undefined {
|
|
803
|
+
const ternary = content.match(/^([^?:]+)\?([^:]*):(.*)$/);
|
|
804
|
+
if (!ternary) return undefined;
|
|
805
|
+
const condition = resolveCommandTemplateCondition(ternary[1], values);
|
|
806
|
+
return isFalsyCommandTemplateValue(condition) ? ternary[3] : ternary[2];
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
function resolveCommandTemplateValue(
|
|
810
|
+
content: string,
|
|
811
|
+
values: Record<string, unknown>,
|
|
812
|
+
missingLabel: string,
|
|
813
|
+
depth = 0,
|
|
814
|
+
): string | undefined {
|
|
815
|
+
if (depth > 5)
|
|
816
|
+
throw new Error(`Command template value recursion exceeded: ${content}`);
|
|
817
|
+
const nullish = resolveCommandTemplateNullish(content, values);
|
|
818
|
+
if (nullish !== undefined) return nullish;
|
|
819
|
+
const ternary = resolveCommandTemplateTernary(content, values);
|
|
820
|
+
if (ternary !== undefined) return ternary;
|
|
821
|
+
const indexed = content.match(
|
|
822
|
+
/^([A-Za-z_][A-Za-z0-9_-]*)\[([A-Za-z_][A-Za-z0-9_-]*|\d+)\]$/,
|
|
823
|
+
);
|
|
824
|
+
if (indexed) {
|
|
825
|
+
const source = values[indexed[1]];
|
|
826
|
+
const indexValue = /^\d+$/.test(indexed[2])
|
|
827
|
+
? indexed[2]
|
|
828
|
+
: values[indexed[2]];
|
|
829
|
+
const index = Number(indexValue);
|
|
830
|
+
if (
|
|
831
|
+
!Array.isArray(source) ||
|
|
832
|
+
!Number.isInteger(index) ||
|
|
833
|
+
index < 0 ||
|
|
834
|
+
index >= source.length
|
|
835
|
+
) {
|
|
836
|
+
throw new Error(`Missing ${missingLabel} value: ${content}`);
|
|
837
|
+
}
|
|
838
|
+
return String(source[index] ?? "");
|
|
839
|
+
}
|
|
840
|
+
const simple = parseCommandTemplatePlaceholderContent(content);
|
|
841
|
+
if (simple) {
|
|
842
|
+
if (Object.hasOwn(values, simple.name)) {
|
|
843
|
+
const raw = values[simple.name] ?? "";
|
|
844
|
+
if (
|
|
845
|
+
typeof raw === "string" &&
|
|
846
|
+
shouldResolveEmbeddedCommandTemplateToken(raw, values)
|
|
847
|
+
) {
|
|
848
|
+
return substituteCommandTemplateToken(
|
|
849
|
+
raw,
|
|
850
|
+
values,
|
|
851
|
+
missingLabel,
|
|
852
|
+
depth + 1,
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
return Array.isArray(raw) ? JSON.stringify(raw) : String(raw);
|
|
856
|
+
}
|
|
857
|
+
if (simple.inlineDefault !== undefined) return simple.inlineDefault;
|
|
858
|
+
}
|
|
859
|
+
const expression = substituteCommandTemplateExpression(content, values);
|
|
860
|
+
if (expression !== undefined) return expression;
|
|
861
|
+
return undefined;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
export function substituteCommandTemplateToken(
|
|
865
|
+
token: string,
|
|
866
|
+
values: Record<string, unknown>,
|
|
867
|
+
missingLabel = "command template",
|
|
868
|
+
depth = 0,
|
|
869
|
+
): string {
|
|
870
|
+
return token.replace(/\{([^{}]+)\}/g, (_match, content: string) => {
|
|
871
|
+
const resolved = resolveCommandTemplateValue(
|
|
872
|
+
content,
|
|
873
|
+
values,
|
|
874
|
+
missingLabel,
|
|
875
|
+
depth,
|
|
876
|
+
);
|
|
877
|
+
if (resolved !== undefined) return resolved;
|
|
878
|
+
throw new Error(`Missing ${missingLabel} value: ${content}`);
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
export async function execCommandTemplate(
|
|
883
|
+
command: string,
|
|
884
|
+
args: string[],
|
|
885
|
+
options: CommandTemplateExecOptions = {},
|
|
886
|
+
): Promise<CommandTemplateExecResult> {
|
|
887
|
+
const maxAttempts = options.retry ?? 1;
|
|
888
|
+
let lastResult: CommandTemplateExecResult = {
|
|
889
|
+
stdout: "",
|
|
890
|
+
stderr: "",
|
|
891
|
+
code: 1,
|
|
892
|
+
killed: false,
|
|
893
|
+
};
|
|
894
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
895
|
+
const attemptOptions = options.captureDir
|
|
896
|
+
? {
|
|
897
|
+
...options,
|
|
898
|
+
captureDir: join(
|
|
899
|
+
options.captureDir,
|
|
900
|
+
`attempt-${String(attempt).padStart(3, "0")}`,
|
|
901
|
+
),
|
|
902
|
+
}
|
|
903
|
+
: options;
|
|
904
|
+
const result = await execCommandTemplateOnce(command, args, attemptOptions);
|
|
905
|
+
if (result.code === 0) return result;
|
|
906
|
+
lastResult = result;
|
|
907
|
+
}
|
|
908
|
+
return lastResult;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
interface BoundedCommandCapture {
|
|
912
|
+
append(value: Buffer | string): void;
|
|
913
|
+
result(): {
|
|
914
|
+
bytes: number;
|
|
915
|
+
content: string;
|
|
916
|
+
file?: string;
|
|
917
|
+
truncated: boolean;
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function trimCaptureTail(value: Buffer, limit: number): Buffer {
|
|
922
|
+
if (value.length <= limit) return value;
|
|
923
|
+
let start = value.length - limit;
|
|
924
|
+
while (start < value.length && (value[start]! & 0xc0) === 0x80) start += 1;
|
|
925
|
+
return value.subarray(start);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function createBoundedCommandCapture(
|
|
929
|
+
stream: "stdout" | "stderr",
|
|
930
|
+
limit: number,
|
|
931
|
+
getCaptureDir: () => string,
|
|
932
|
+
persistCompleteStream: boolean,
|
|
933
|
+
): BoundedCommandCapture {
|
|
934
|
+
let bytes = 0;
|
|
935
|
+
let content: Buffer = Buffer.alloc(0);
|
|
936
|
+
let file = persistCompleteStream
|
|
937
|
+
? join(getCaptureDir(), `${stream}.log`)
|
|
938
|
+
: undefined;
|
|
939
|
+
if (file) writeFileSync(file, Buffer.alloc(0));
|
|
940
|
+
let truncated = false;
|
|
941
|
+
return {
|
|
942
|
+
append(value) {
|
|
943
|
+
const chunk = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
944
|
+
bytes += chunk.length;
|
|
945
|
+
if (bytes > limit) truncated = true;
|
|
946
|
+
if (!file && bytes <= limit) {
|
|
947
|
+
content = Buffer.concat([content, chunk]);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (!file) {
|
|
951
|
+
file = join(getCaptureDir(), `${stream}.log`);
|
|
952
|
+
writeFileSync(file, content);
|
|
953
|
+
}
|
|
954
|
+
appendFileSync(file, chunk);
|
|
955
|
+
content = trimCaptureTail(Buffer.concat([content, chunk]), limit);
|
|
956
|
+
},
|
|
957
|
+
result() {
|
|
958
|
+
if (!file && persistCompleteStream) {
|
|
959
|
+
file = join(getCaptureDir(), `${stream}.log`);
|
|
960
|
+
writeFileSync(file, content);
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
bytes,
|
|
964
|
+
content: content.toString("utf8"),
|
|
965
|
+
...(file ? { file } : {}),
|
|
966
|
+
truncated,
|
|
967
|
+
};
|
|
968
|
+
},
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function execCommandTemplateOnce(
|
|
973
|
+
command: string,
|
|
974
|
+
args: string[],
|
|
975
|
+
options: CommandTemplateExecOptions = {},
|
|
976
|
+
): Promise<CommandTemplateExecResult> {
|
|
977
|
+
return new Promise((resolve) => {
|
|
978
|
+
const proc = spawn(command, args, {
|
|
979
|
+
cwd: options.cwd,
|
|
980
|
+
shell: false,
|
|
981
|
+
stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
982
|
+
});
|
|
983
|
+
const captureLimit = Math.max(
|
|
984
|
+
1,
|
|
985
|
+
options.captureLimitBytes ?? DEFAULT_COMMAND_CAPTURE_LIMIT_BYTES,
|
|
986
|
+
);
|
|
987
|
+
let captureDir: string | undefined;
|
|
988
|
+
const getCaptureDir = (): string => {
|
|
989
|
+
if (captureDir) return captureDir;
|
|
990
|
+
captureDir = options.captureDir
|
|
991
|
+
? resolvePath(options.captureDir)
|
|
992
|
+
: mkdtempSync(join(tmpdir(), "pi-actors-command-"));
|
|
993
|
+
mkdirSync(captureDir, { recursive: true });
|
|
994
|
+
return captureDir;
|
|
995
|
+
};
|
|
996
|
+
const persistCompleteStreams = options.captureDir !== undefined;
|
|
997
|
+
const stdoutCapture = createBoundedCommandCapture(
|
|
998
|
+
"stdout",
|
|
999
|
+
captureLimit,
|
|
1000
|
+
getCaptureDir,
|
|
1001
|
+
persistCompleteStreams,
|
|
1002
|
+
);
|
|
1003
|
+
const stderrCapture = createBoundedCommandCapture(
|
|
1004
|
+
"stderr",
|
|
1005
|
+
captureLimit,
|
|
1006
|
+
getCaptureDir,
|
|
1007
|
+
persistCompleteStreams,
|
|
1008
|
+
);
|
|
1009
|
+
let killed = false;
|
|
1010
|
+
let settled = false;
|
|
1011
|
+
let timeoutId: NodeJS.Timeout | undefined;
|
|
1012
|
+
let killTimeoutId: NodeJS.Timeout | undefined;
|
|
1013
|
+
const killProcess = (): void => {
|
|
1014
|
+
if (killed) return;
|
|
1015
|
+
killed = true;
|
|
1016
|
+
proc.kill("SIGTERM");
|
|
1017
|
+
killTimeoutId = setTimeout(() => {
|
|
1018
|
+
if (!settled) proc.kill("SIGKILL");
|
|
1019
|
+
}, options.killGrace ?? 5000);
|
|
1020
|
+
};
|
|
1021
|
+
const settle = (code: number): void => {
|
|
1022
|
+
if (settled) return;
|
|
1023
|
+
settled = true;
|
|
1024
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1025
|
+
if (killTimeoutId) clearTimeout(killTimeoutId);
|
|
1026
|
+
if (options.signal)
|
|
1027
|
+
options.signal.removeEventListener("abort", killProcess);
|
|
1028
|
+
const stdout = stdoutCapture.result();
|
|
1029
|
+
const stderr = stderrCapture.result();
|
|
1030
|
+
resolve({
|
|
1031
|
+
stdout: stdout.content,
|
|
1032
|
+
stderr: stderr.content,
|
|
1033
|
+
code,
|
|
1034
|
+
killed,
|
|
1035
|
+
stdoutBytes: stdout.bytes,
|
|
1036
|
+
stderrBytes: stderr.bytes,
|
|
1037
|
+
...(stdout.file ? { stdoutFile: stdout.file } : {}),
|
|
1038
|
+
...(stderr.file ? { stderrFile: stderr.file } : {}),
|
|
1039
|
+
...(stdout.truncated ? { stdoutTruncated: true } : {}),
|
|
1040
|
+
...(stderr.truncated ? { stderrTruncated: true } : {}),
|
|
1041
|
+
});
|
|
1042
|
+
};
|
|
1043
|
+
if (options.signal) {
|
|
1044
|
+
if (options.signal.aborted) killProcess();
|
|
1045
|
+
else
|
|
1046
|
+
options.signal.addEventListener("abort", killProcess, { once: true });
|
|
1047
|
+
}
|
|
1048
|
+
if (options.timeout !== undefined && options.timeout > 0)
|
|
1049
|
+
timeoutId = setTimeout(killProcess, options.timeout);
|
|
1050
|
+
proc.stdout?.on("data", (data: Buffer) => {
|
|
1051
|
+
stdoutCapture.append(data);
|
|
1052
|
+
});
|
|
1053
|
+
proc.stderr?.on("data", (data: Buffer) => {
|
|
1054
|
+
stderrCapture.append(data);
|
|
1055
|
+
});
|
|
1056
|
+
proc.stdin?.on("error", () => {});
|
|
1057
|
+
if (options.stdin !== undefined) proc.stdin?.end(options.stdin);
|
|
1058
|
+
proc.on("error", (error) => {
|
|
1059
|
+
stderrCapture.append(error instanceof Error ? error.message : String(error));
|
|
1060
|
+
settle(1);
|
|
1061
|
+
});
|
|
1062
|
+
proc.on("close", (code) => {
|
|
1063
|
+
settle(code ?? (killed ? 1 : 0));
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
export function buildCommandTemplateInvocation(
|
|
1069
|
+
config: CommandTemplateConfig,
|
|
1070
|
+
values: Record<string, unknown>,
|
|
1071
|
+
cwd: string,
|
|
1072
|
+
options: { emptyMessage?: string; missingLabel?: string } = {},
|
|
1073
|
+
): CommandTemplateInvocation {
|
|
1074
|
+
const normalizedConfig = normalizeCommandTemplateConfig(config);
|
|
1075
|
+
if (Array.isArray(normalizedConfig.template)) {
|
|
1076
|
+
throw new Error(
|
|
1077
|
+
options.emptyMessage ??
|
|
1078
|
+
"Command template sequence cannot be executed as one command",
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
if (!normalizedConfig.template)
|
|
1082
|
+
throw new Error(options.emptyMessage ?? "Command template is required");
|
|
1083
|
+
if (typeof normalizedConfig.template !== "string") {
|
|
1084
|
+
throw new Error(
|
|
1085
|
+
options.emptyMessage ??
|
|
1086
|
+
"Command template object cannot be executed as one command",
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1089
|
+
const parts = splitCommandTemplate(normalizedConfig.template);
|
|
1090
|
+
const commandPart = parts[0];
|
|
1091
|
+
if (!commandPart)
|
|
1092
|
+
throw new Error(options.emptyMessage ?? "Command template is empty");
|
|
1093
|
+
const resolvedValues = {
|
|
1094
|
+
...getCommandTemplateDefaults(normalizedConfig),
|
|
1095
|
+
...values,
|
|
1096
|
+
};
|
|
1097
|
+
const command = expandCommandTemplateExecutable(
|
|
1098
|
+
substituteCommandTemplateToken(
|
|
1099
|
+
commandPart,
|
|
1100
|
+
resolvedValues,
|
|
1101
|
+
options.missingLabel,
|
|
1102
|
+
),
|
|
1103
|
+
cwd,
|
|
1104
|
+
);
|
|
1105
|
+
const args = parts
|
|
1106
|
+
.slice(1)
|
|
1107
|
+
.map((part) =>
|
|
1108
|
+
substituteCommandTemplateToken(
|
|
1109
|
+
part,
|
|
1110
|
+
resolvedValues,
|
|
1111
|
+
options.missingLabel,
|
|
1112
|
+
),
|
|
1113
|
+
)
|
|
1114
|
+
.filter((part) => part !== "");
|
|
1115
|
+
return resolveCommandTemplateScriptInvocation({ command, args });
|
|
1116
|
+
}
|