@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,1446 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Packaged persistent local music playback controlled-service helper.
|
|
5
|
+
*
|
|
6
|
+
* This script backs the singleton music-player/playback Recipe. It scans local music
|
|
7
|
+
* sources, builds playback queues, launches an available backend player, and
|
|
8
|
+
* consumes generation-bound Controls such as play, pause, next, previous,
|
|
9
|
+
* stop, and status.
|
|
10
|
+
*
|
|
11
|
+
* Keep the helper focused on one maintained controlled Run implementation; Recipe
|
|
12
|
+
* metadata and invocation arguments choose source paths and backend behavior.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
16
|
+
import { randomUUID } from "node:crypto";
|
|
17
|
+
import {
|
|
18
|
+
accessSync,
|
|
19
|
+
constants,
|
|
20
|
+
existsSync,
|
|
21
|
+
mkdirSync,
|
|
22
|
+
readdirSync,
|
|
23
|
+
readFileSync,
|
|
24
|
+
renameSync,
|
|
25
|
+
rmSync,
|
|
26
|
+
statSync,
|
|
27
|
+
watch,
|
|
28
|
+
writeFileSync,
|
|
29
|
+
} from "node:fs";
|
|
30
|
+
import { createServer } from "node:net";
|
|
31
|
+
import { homedir } from "node:os";
|
|
32
|
+
import {
|
|
33
|
+
basename,
|
|
34
|
+
delimiter,
|
|
35
|
+
dirname,
|
|
36
|
+
extname,
|
|
37
|
+
isAbsolute,
|
|
38
|
+
join,
|
|
39
|
+
resolve,
|
|
40
|
+
} from "node:path";
|
|
41
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
42
|
+
|
|
43
|
+
function packageRoot() {
|
|
44
|
+
return dirname(dirname(dirname(dirname(fileURLToPath(import.meta.url)))));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function importRuntimeModule(name) {
|
|
48
|
+
const root = packageRoot();
|
|
49
|
+
const compiled = join(root, "lib", `${name}.js`);
|
|
50
|
+
const installedCompiled = join(root, "dist", "lib", `${name}.js`);
|
|
51
|
+
const source = join(root, "lib", `${name}.ts`);
|
|
52
|
+
const module = existsSync(compiled)
|
|
53
|
+
? compiled
|
|
54
|
+
: root.includes(`${delimiter}node_modules${delimiter}`) && existsSync(installedCompiled)
|
|
55
|
+
? installedCompiled
|
|
56
|
+
: source;
|
|
57
|
+
return await import(pathToFileURL(module).href);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const actorAdapterEnabled = process.argv[2] !== "serve";
|
|
61
|
+
let appendRunControlInStateDir;
|
|
62
|
+
let claimRunControlByIdInStateDir;
|
|
63
|
+
let processRunControlsInStateDir;
|
|
64
|
+
let readRunControlJournalFromStateDir;
|
|
65
|
+
let updateRunControlStatusInStateDir;
|
|
66
|
+
let isAlive;
|
|
67
|
+
let verifyRunProcessIdentity;
|
|
68
|
+
let appendRunTraceEvent = () => {};
|
|
69
|
+
if (actorAdapterEnabled) {
|
|
70
|
+
({
|
|
71
|
+
appendRunControlInStateDir,
|
|
72
|
+
claimRunControlByIdInStateDir,
|
|
73
|
+
processRunControlsInStateDir,
|
|
74
|
+
readRunControlJournalFromStateDir,
|
|
75
|
+
updateRunControlStatusInStateDir,
|
|
76
|
+
} = await importRuntimeModule("runs-controls"));
|
|
77
|
+
({ isAlive, verifyRunProcessIdentity } =
|
|
78
|
+
await importRuntimeModule("runs-process"));
|
|
79
|
+
({ appendRunTraceEvent } = await importRuntimeModule("runs-trace"));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const AUDIO_EXTENSIONS = new Set([
|
|
83
|
+
".aac",
|
|
84
|
+
".aif",
|
|
85
|
+
".aiff",
|
|
86
|
+
".flac",
|
|
87
|
+
".m4a",
|
|
88
|
+
".mp3",
|
|
89
|
+
".ogg",
|
|
90
|
+
".wav",
|
|
91
|
+
]);
|
|
92
|
+
const PLAYLIST_EXTENSIONS = new Set([".m3u", ".m3u8", ".txt"]);
|
|
93
|
+
const CONTROL_COMMANDS = new Set([
|
|
94
|
+
"play",
|
|
95
|
+
"resume",
|
|
96
|
+
"pause",
|
|
97
|
+
"toggle",
|
|
98
|
+
"next",
|
|
99
|
+
"previous",
|
|
100
|
+
"seek",
|
|
101
|
+
"volume",
|
|
102
|
+
"stop",
|
|
103
|
+
"status",
|
|
104
|
+
]);
|
|
105
|
+
function usage() {
|
|
106
|
+
console.error(`Usage:
|
|
107
|
+
playback.mjs <play|serve> <source-file-dir-url-playlist-or-list> [loop=true] [volume=70] [player=auto] [state-dir]
|
|
108
|
+
playback.mjs <pause|resume|toggle|next|previous|stop|status> <state-dir>
|
|
109
|
+
playback.mjs <seek|volume> <state-dir> <percent>
|
|
110
|
+
playback.mjs control <state-dir> <play|pause|toggle|next|previous|seek|volume|stop|status> [percent]
|
|
111
|
+
|
|
112
|
+
Runs a foreground music player so pi-actors can own it as a controlled Run.
|
|
113
|
+
Controls use canonical records in <state-dir>/controls.jsonl.
|
|
114
|
+
Prefer message target=run:<run> action=<command>, or use direct control commands below.
|
|
115
|
+
Supported players: auto, mpv, afplay, ffplay, cvlc, play, wmp.
|
|
116
|
+
`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function fail(message, code = 1) {
|
|
120
|
+
console.error(`music-player: ${message}`);
|
|
121
|
+
process.exit(code);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function sleep(ms) {
|
|
125
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function expandPath(value) {
|
|
129
|
+
if (value === "~") return homedir();
|
|
130
|
+
if (value.startsWith("~/")) return join(homedir(), value.slice(2));
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isUrl(value) {
|
|
135
|
+
return /^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function exists(path) {
|
|
139
|
+
try {
|
|
140
|
+
return existsSync(path);
|
|
141
|
+
} catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function isLocalProcessAlive(pid) {
|
|
147
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
148
|
+
try {
|
|
149
|
+
process.kill(pid, 0);
|
|
150
|
+
return true;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
return error?.code === "EPERM";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isDirectory(path) {
|
|
157
|
+
try {
|
|
158
|
+
return statSync(path).isDirectory();
|
|
159
|
+
} catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function isFile(path) {
|
|
165
|
+
try {
|
|
166
|
+
return statSync(path).isFile();
|
|
167
|
+
} catch {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function have(command) {
|
|
173
|
+
const paths = (process.env.PATH || "").split(delimiter).filter(Boolean);
|
|
174
|
+
const extensions =
|
|
175
|
+
process.platform === "win32"
|
|
176
|
+
? (process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM").split(";")
|
|
177
|
+
: [""];
|
|
178
|
+
for (const dir of paths) {
|
|
179
|
+
for (const extension of extensions) {
|
|
180
|
+
const candidate = join(dir, `${command}${extension}`);
|
|
181
|
+
try {
|
|
182
|
+
accessSync(candidate, constants.X_OK);
|
|
183
|
+
return true;
|
|
184
|
+
} catch {
|
|
185
|
+
// Keep searching PATH.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function parseBool(value) {
|
|
193
|
+
switch (String(value).toLowerCase()) {
|
|
194
|
+
case "1":
|
|
195
|
+
case "true":
|
|
196
|
+
case "yes":
|
|
197
|
+
case "y":
|
|
198
|
+
case "on":
|
|
199
|
+
return true;
|
|
200
|
+
case "0":
|
|
201
|
+
case "false":
|
|
202
|
+
case "no":
|
|
203
|
+
case "n":
|
|
204
|
+
case "off":
|
|
205
|
+
return false;
|
|
206
|
+
default:
|
|
207
|
+
fail(`invalid loop value: ${value}`, 2);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function parsePercent(value, label) {
|
|
212
|
+
const candidate =
|
|
213
|
+
value && typeof value === "object" && !Array.isArray(value)
|
|
214
|
+
? value.percent
|
|
215
|
+
: value;
|
|
216
|
+
if (!/^\d+$/.test(String(candidate))) {
|
|
217
|
+
throw new Error(`${label} percent must be an integer 0..100`);
|
|
218
|
+
}
|
|
219
|
+
const percent = Number(candidate);
|
|
220
|
+
if (percent < 0 || percent > 100) {
|
|
221
|
+
throw new Error(`${label} percent must be an integer 0..100`);
|
|
222
|
+
}
|
|
223
|
+
return percent;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function parseSeekPercent(value) {
|
|
227
|
+
return parsePercent(value, "seek");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function parseVolumePercent(value) {
|
|
231
|
+
return parsePercent(value, "volume");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function normalizeVolume(value) {
|
|
235
|
+
try {
|
|
236
|
+
return parseVolumePercent(value);
|
|
237
|
+
} catch (error) {
|
|
238
|
+
fail(error instanceof Error ? error.message : String(error), 2);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function powershellCommand() {
|
|
243
|
+
return have("powershell") ? "powershell.exe" : undefined;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function windowsMediaPlayerExecutable() {
|
|
247
|
+
if (process.platform !== "win32") return undefined;
|
|
248
|
+
const roots = [
|
|
249
|
+
process.env.ProgramFiles,
|
|
250
|
+
process.env["ProgramFiles(x86)"],
|
|
251
|
+
process.env.SystemDrive
|
|
252
|
+
? join(process.env.SystemDrive, "Program Files")
|
|
253
|
+
: undefined,
|
|
254
|
+
process.env.SystemDrive
|
|
255
|
+
? join(process.env.SystemDrive, "Program Files (x86)")
|
|
256
|
+
: undefined,
|
|
257
|
+
];
|
|
258
|
+
for (const root of roots.filter(Boolean)) {
|
|
259
|
+
const candidate = join(root, "Windows Media Player", "wmplayer.exe");
|
|
260
|
+
if (exists(candidate)) return candidate;
|
|
261
|
+
}
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function havePlayer(player) {
|
|
266
|
+
if (player === "wmp") {
|
|
267
|
+
return (
|
|
268
|
+
process.platform === "win32" &&
|
|
269
|
+
Boolean(powershellCommand()) &&
|
|
270
|
+
Boolean(windowsMediaPlayerExecutable())
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return have(player);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function selectPlayer(requested) {
|
|
277
|
+
let selected = requested;
|
|
278
|
+
if (selected === "auto") {
|
|
279
|
+
let candidates;
|
|
280
|
+
if (process.platform === "win32") {
|
|
281
|
+
candidates = ["wmp", "mpv", "ffplay", "cvlc"];
|
|
282
|
+
} else if (process.platform === "darwin") {
|
|
283
|
+
candidates = ["mpv", "afplay", "ffplay", "cvlc", "play"];
|
|
284
|
+
} else {
|
|
285
|
+
candidates = ["mpv", "ffplay", "cvlc", "play"];
|
|
286
|
+
}
|
|
287
|
+
selected = candidates.find(havePlayer) || selected;
|
|
288
|
+
}
|
|
289
|
+
if (!["mpv", "afplay", "ffplay", "cvlc", "play", "wmp"].includes(selected)) {
|
|
290
|
+
fail(`unsupported player: ${requested}`, 2);
|
|
291
|
+
}
|
|
292
|
+
if (selected === "wmp" && !havePlayer(selected)) {
|
|
293
|
+
fail(
|
|
294
|
+
"player not found: wmp requires native Windows, powershell.exe, and wmplayer.exe under Program Files/Windows Media Player",
|
|
295
|
+
127,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
if (!havePlayer(selected)) fail(`player not found: ${selected}`, 127);
|
|
299
|
+
return selected;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function addTrack(tracks, item) {
|
|
303
|
+
const track = expandPath(item.trim());
|
|
304
|
+
if (!track) return;
|
|
305
|
+
if (isUrl(track) || exists(track)) {
|
|
306
|
+
tracks.push(track);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
console.error(`music-player: source entry not found: ${track}`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function collectAudioFiles(dir, result = []) {
|
|
313
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
314
|
+
for (const entry of entries) {
|
|
315
|
+
const path = join(dir, entry.name);
|
|
316
|
+
if (entry.isDirectory()) {
|
|
317
|
+
collectAudioFiles(path, result);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (
|
|
321
|
+
entry.isFile() &&
|
|
322
|
+
AUDIO_EXTENSIONS.has(extname(entry.name).toLowerCase())
|
|
323
|
+
) {
|
|
324
|
+
result.push(path);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function loadPlaylist(source) {
|
|
331
|
+
const sourceArg = expandPath(source);
|
|
332
|
+
const tracks = [];
|
|
333
|
+
if (sourceArg.includes("|")) {
|
|
334
|
+
for (const item of sourceArg.split("|")) addTrack(tracks, item);
|
|
335
|
+
} else if (isUrl(sourceArg)) {
|
|
336
|
+
tracks.push(sourceArg);
|
|
337
|
+
} else if (isDirectory(sourceArg)) {
|
|
338
|
+
tracks.push(
|
|
339
|
+
...collectAudioFiles(sourceArg).sort((a, b) => a.localeCompare(b)),
|
|
340
|
+
);
|
|
341
|
+
} else if (
|
|
342
|
+
isFile(sourceArg) &&
|
|
343
|
+
PLAYLIST_EXTENSIONS.has(extname(sourceArg).toLowerCase())
|
|
344
|
+
) {
|
|
345
|
+
const baseDir = dirname(resolve(sourceArg));
|
|
346
|
+
const lines = readFileSync(sourceArg, "utf8").split("\n");
|
|
347
|
+
for (const rawLine of lines) {
|
|
348
|
+
const line = rawLine.replace(/\r$/, "").trim();
|
|
349
|
+
if (!line || line.startsWith("#")) continue;
|
|
350
|
+
if (isUrl(line) || isAbsolute(line) || line.startsWith("~"))
|
|
351
|
+
addTrack(tracks, line);
|
|
352
|
+
else addTrack(tracks, join(baseDir, line));
|
|
353
|
+
}
|
|
354
|
+
} else if (exists(sourceArg)) {
|
|
355
|
+
tracks.push(sourceArg);
|
|
356
|
+
} else {
|
|
357
|
+
fail(`source not found: ${sourceArg}`, 66);
|
|
358
|
+
}
|
|
359
|
+
if (tracks.length === 0)
|
|
360
|
+
fail(`source has no playable tracks: ${sourceArg}`, 66);
|
|
361
|
+
return tracks;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function windowsMediaPlayerCommand(ctx, volume, track) {
|
|
365
|
+
const command = powershellCommand();
|
|
366
|
+
const wmplayer = windowsMediaPlayerExecutable();
|
|
367
|
+
if (!command || !wmplayer) {
|
|
368
|
+
fail(
|
|
369
|
+
"Windows Media Player backend requires powershell.exe and wmplayer.exe",
|
|
370
|
+
127,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
const script = String.raw`
|
|
374
|
+
$ErrorActionPreference = 'Stop'
|
|
375
|
+
$track = $args[0]
|
|
376
|
+
$volume = [int]$args[1]
|
|
377
|
+
$controlFile = $args[2]
|
|
378
|
+
$wmplayerExe = $args[3]
|
|
379
|
+
if (-not (Test-Path -LiteralPath $wmplayerExe)) { throw "wmplayer.exe not found: $wmplayerExe" }
|
|
380
|
+
$player = New-Object -ComObject WMPlayer.OCX
|
|
381
|
+
$player.settings.volume = [Math]::Min([Math]::Max($volume, 0), 100)
|
|
382
|
+
$player.URL = $track
|
|
383
|
+
$player.controls.play()
|
|
384
|
+
try {
|
|
385
|
+
while ($true) {
|
|
386
|
+
Start-Sleep -Milliseconds 100
|
|
387
|
+
if (Test-Path -LiteralPath $controlFile) {
|
|
388
|
+
$control = (Get-Content -LiteralPath $controlFile -Raw -ErrorAction SilentlyContinue).Trim().ToLowerInvariant()
|
|
389
|
+
Clear-Content -LiteralPath $controlFile -ErrorAction SilentlyContinue
|
|
390
|
+
switch ($control) {
|
|
391
|
+
'play' { $player.controls.play() }
|
|
392
|
+
'pause' { $player.controls.pause() }
|
|
393
|
+
'stop' { $player.controls.stop(); break }
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if ($player.playState -eq 1 -or $player.playState -eq 8) { break }
|
|
397
|
+
}
|
|
398
|
+
} finally {
|
|
399
|
+
$player.close()
|
|
400
|
+
}
|
|
401
|
+
`;
|
|
402
|
+
return [
|
|
403
|
+
command,
|
|
404
|
+
[
|
|
405
|
+
"-NoLogo",
|
|
406
|
+
"-NoProfile",
|
|
407
|
+
"-NonInteractive",
|
|
408
|
+
"-ExecutionPolicy",
|
|
409
|
+
"Bypass",
|
|
410
|
+
"-Command",
|
|
411
|
+
script,
|
|
412
|
+
track,
|
|
413
|
+
String(volume),
|
|
414
|
+
ctx.playerControlFile,
|
|
415
|
+
wmplayer,
|
|
416
|
+
],
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function probeDurationSeconds(track) {
|
|
421
|
+
if (!have("ffprobe")) return undefined;
|
|
422
|
+
const result = spawnSync(
|
|
423
|
+
"ffprobe",
|
|
424
|
+
[
|
|
425
|
+
"-v",
|
|
426
|
+
"error",
|
|
427
|
+
"-show_entries",
|
|
428
|
+
"format=duration",
|
|
429
|
+
"-of",
|
|
430
|
+
"default=noprint_wrappers=1:nokey=1",
|
|
431
|
+
track,
|
|
432
|
+
],
|
|
433
|
+
{ encoding: "utf8", timeout: 5_000, windowsHide: true },
|
|
434
|
+
);
|
|
435
|
+
const duration = Number(String(result.stdout).trim());
|
|
436
|
+
return result.status === 0 && Number.isFinite(duration) && duration > 0
|
|
437
|
+
? duration
|
|
438
|
+
: undefined;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function playerCommand(ctx, player, volume, track, startSeconds = 0) {
|
|
442
|
+
switch (player) {
|
|
443
|
+
case "mpv":
|
|
444
|
+
return [
|
|
445
|
+
"mpv",
|
|
446
|
+
[
|
|
447
|
+
"--no-video",
|
|
448
|
+
"--really-quiet",
|
|
449
|
+
"--force-window=no",
|
|
450
|
+
`--volume=${volume}`,
|
|
451
|
+
...(startSeconds > 0 ? [`--start=${startSeconds}`] : []),
|
|
452
|
+
track,
|
|
453
|
+
],
|
|
454
|
+
];
|
|
455
|
+
case "afplay":
|
|
456
|
+
return [
|
|
457
|
+
"afplay",
|
|
458
|
+
["-v", String(Math.min(Math.max(volume / 100, 0), 1)), track],
|
|
459
|
+
];
|
|
460
|
+
case "ffplay":
|
|
461
|
+
return [
|
|
462
|
+
"ffplay",
|
|
463
|
+
[
|
|
464
|
+
"-nodisp",
|
|
465
|
+
"-hide_banner",
|
|
466
|
+
"-loglevel",
|
|
467
|
+
"warning",
|
|
468
|
+
"-autoexit",
|
|
469
|
+
"-volume",
|
|
470
|
+
String(volume),
|
|
471
|
+
...(startSeconds > 0 ? ["-ss", String(startSeconds)] : []),
|
|
472
|
+
track,
|
|
473
|
+
],
|
|
474
|
+
];
|
|
475
|
+
case "cvlc":
|
|
476
|
+
return [
|
|
477
|
+
"cvlc",
|
|
478
|
+
[
|
|
479
|
+
"--intf",
|
|
480
|
+
"dummy",
|
|
481
|
+
"--no-video",
|
|
482
|
+
"--play-and-exit",
|
|
483
|
+
"--volume",
|
|
484
|
+
String(Math.floor((volume * 256) / 100)),
|
|
485
|
+
...(startSeconds > 0 ? ["--start-time", String(startSeconds)] : []),
|
|
486
|
+
track,
|
|
487
|
+
],
|
|
488
|
+
];
|
|
489
|
+
case "play":
|
|
490
|
+
return [
|
|
491
|
+
"play",
|
|
492
|
+
["-q", track, ...(startSeconds > 0 ? ["trim", String(startSeconds)] : [])],
|
|
493
|
+
];
|
|
494
|
+
case "wmp":
|
|
495
|
+
return windowsMediaPlayerCommand(ctx, volume, track);
|
|
496
|
+
default:
|
|
497
|
+
fail(`unsupported player: ${player}`, 2);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function writeText(path, value) {
|
|
502
|
+
writeFileSync(path, value, "utf8");
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function readText(path) {
|
|
506
|
+
try {
|
|
507
|
+
return readFileSync(path, "utf8");
|
|
508
|
+
} catch {
|
|
509
|
+
return "";
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function emitPlayerEvent(ctx, kind, summary, data = {}) {
|
|
514
|
+
appendRunTraceEvent(ctx.stateDir, {
|
|
515
|
+
data,
|
|
516
|
+
kind,
|
|
517
|
+
level: "info",
|
|
518
|
+
summary,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function emitTrackEvent(ctx, index, count, track, player) {
|
|
523
|
+
const title = track.split(/[\\/]/).filter(Boolean).pop() || track;
|
|
524
|
+
emitPlayerEvent(ctx, "player.track", `Now playing: ${title}`, {
|
|
525
|
+
count,
|
|
526
|
+
index,
|
|
527
|
+
player,
|
|
528
|
+
track,
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function emitStoppedEvent(ctx, reason = "stop") {
|
|
533
|
+
emitPlayerEvent(ctx, "player.stopped", "Music player stopped", { reason });
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function positionSnapshot(ctx, state, nowMs = Date.now()) {
|
|
537
|
+
const duration = Number(ctx.durationSeconds);
|
|
538
|
+
let position = Number(ctx.positionSeconds ?? 0);
|
|
539
|
+
if (state === "playing" && Number.isFinite(ctx.positionStartedAtMs)) {
|
|
540
|
+
position += Math.max(0, nowMs - ctx.positionStartedAtMs) / 1000;
|
|
541
|
+
}
|
|
542
|
+
if (Number.isFinite(duration) && duration > 0) {
|
|
543
|
+
position = Math.min(Math.max(position, 0), duration);
|
|
544
|
+
} else {
|
|
545
|
+
position = Math.max(position, 0);
|
|
546
|
+
}
|
|
547
|
+
const progressPercent = Number.isFinite(duration) && duration > 0
|
|
548
|
+
? Math.min(100, Math.max(0, (position / duration) * 100))
|
|
549
|
+
: undefined;
|
|
550
|
+
return { duration, position, progressPercent, updatedAtMs: nowMs };
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function freezePosition(ctx) {
|
|
554
|
+
const snapshot = positionSnapshot(ctx, "playing");
|
|
555
|
+
ctx.positionSeconds = snapshot.position;
|
|
556
|
+
ctx.positionStartedAtMs = undefined;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function resumePosition(ctx) {
|
|
560
|
+
ctx.positionStartedAtMs = Date.now();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function writeStatus(ctx, state, index, count, track, player, pid = "") {
|
|
564
|
+
const updatedAt = new Date().toISOString();
|
|
565
|
+
const position = positionSnapshot(ctx, state);
|
|
566
|
+
writeText(
|
|
567
|
+
ctx.statusFile,
|
|
568
|
+
`state=${state}\nindex=${index}\ncount=${count}\ntrack=${track}\nplayer=${player}\nvolume=${ctx.volume}\nseek_percent=${ctx.seekPercent ?? 0}\nprogress_percent=${position.progressPercent === undefined ? "" : Math.round(position.progressPercent)}\npid=${pid}\nupdated_at=${updatedAt}\n`,
|
|
569
|
+
);
|
|
570
|
+
writeText(
|
|
571
|
+
ctx.statusJsonFile,
|
|
572
|
+
`${JSON.stringify({ state, index, count, track, player, volume: ctx.volume, seek_percent: ctx.seekPercent ?? 0, progress_percent: position.progressPercent === undefined ? null : Math.round(position.progressPercent), position_seconds: position.position, duration_seconds: Number.isFinite(position.duration) ? position.duration : null, position_updated_at_ms: position.updatedAtMs, pid: String(pid), updated_at: updatedAt })}\n`,
|
|
573
|
+
);
|
|
574
|
+
ctx.current = {
|
|
575
|
+
count,
|
|
576
|
+
index,
|
|
577
|
+
pid: String(pid),
|
|
578
|
+
player,
|
|
579
|
+
state,
|
|
580
|
+
track,
|
|
581
|
+
volume: ctx.volume,
|
|
582
|
+
seekPercent: ctx.seekPercent ?? 0,
|
|
583
|
+
progressPercent: position.progressPercent,
|
|
584
|
+
};
|
|
585
|
+
writePlaybackCheckpoint(ctx, state, index, track);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function setState(ctx, state) {
|
|
589
|
+
ctx.desiredState = state;
|
|
590
|
+
writeText(ctx.stateFile, state);
|
|
591
|
+
if (ctx.current) {
|
|
592
|
+
writeStatus(
|
|
593
|
+
ctx,
|
|
594
|
+
state,
|
|
595
|
+
ctx.current.index,
|
|
596
|
+
ctx.current.count,
|
|
597
|
+
ctx.current.track,
|
|
598
|
+
ctx.current.player,
|
|
599
|
+
ctx.current.pid,
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function sendSignalToCurrent(ctx, signal) {
|
|
605
|
+
const pid = Number(readText(ctx.pidFile).trim());
|
|
606
|
+
if (!Number.isInteger(pid) || pid <= 0) return;
|
|
607
|
+
if (process.platform === "win32") {
|
|
608
|
+
if (signal === "SIGTERM") {
|
|
609
|
+
spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
610
|
+
stdio: "ignore",
|
|
611
|
+
windowsHide: true,
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
try {
|
|
617
|
+
process.kill(-pid, signal);
|
|
618
|
+
return;
|
|
619
|
+
} catch {
|
|
620
|
+
// Fall through to the direct child fallback.
|
|
621
|
+
}
|
|
622
|
+
try {
|
|
623
|
+
process.kill(pid, signal);
|
|
624
|
+
} catch {
|
|
625
|
+
// Best effort control signal.
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function controlCurrentPlayback(ctx, command) {
|
|
630
|
+
if (ctx.current?.player === "wmp") {
|
|
631
|
+
writeText(ctx.playerControlFile, command);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
switch (command) {
|
|
635
|
+
case "play":
|
|
636
|
+
sendSignalToCurrent(ctx, "SIGCONT");
|
|
637
|
+
break;
|
|
638
|
+
case "pause":
|
|
639
|
+
sendSignalToCurrent(ctx, "SIGSTOP");
|
|
640
|
+
break;
|
|
641
|
+
case "stop":
|
|
642
|
+
sendSignalToCurrent(ctx, "SIGCONT");
|
|
643
|
+
sendSignalToCurrent(ctx, "SIGTERM");
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function pipeWireAudioStreamIds() {
|
|
649
|
+
if (process.platform !== "linux" || !have("wpctl")) return [];
|
|
650
|
+
const result = spawnSync("wpctl", ["status", "-n"], {
|
|
651
|
+
encoding: "utf8",
|
|
652
|
+
windowsHide: true,
|
|
653
|
+
});
|
|
654
|
+
if (result.status !== 0) return [];
|
|
655
|
+
const audio = (String(result.stdout).split(/\nVideo\n/u)[0] ?? "");
|
|
656
|
+
const streams = audio.split(/\n\s*└─ Streams:\s*\n/u)[1] ?? "";
|
|
657
|
+
return [...streams.matchAll(/^\s+(\d+)\.\s/gmu)]
|
|
658
|
+
.map((match) => Number(match[1]))
|
|
659
|
+
.filter((id) => Number.isInteger(id) && id > 0);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function wpctlInspect(id) {
|
|
663
|
+
const result = spawnSync("wpctl", ["inspect", String(id)], {
|
|
664
|
+
encoding: "utf8",
|
|
665
|
+
windowsHide: true,
|
|
666
|
+
});
|
|
667
|
+
return result.status === 0 ? String(result.stdout) : "";
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function findPipeWireAudioStreamForPid(pid) {
|
|
671
|
+
for (const nodeId of pipeWireAudioStreamIds()) {
|
|
672
|
+
const node = wpctlInspect(nodeId);
|
|
673
|
+
if (!/media\.class = "Stream\/Output\/Audio"/u.test(node)) continue;
|
|
674
|
+
const clientId = Number(node.match(/client\.id = "(\d+)"/u)?.[1]);
|
|
675
|
+
if (!Number.isInteger(clientId) || clientId <= 0) continue;
|
|
676
|
+
const client = wpctlInspect(clientId);
|
|
677
|
+
const processId = Number(client.match(/application\.process\.id = "(\d+)"/u)?.[1]);
|
|
678
|
+
if (processId === pid) return nodeId;
|
|
679
|
+
}
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function setCurrentPlaybackVolume(ctx, percent) {
|
|
684
|
+
const pid = Number(ctx.child?.pid);
|
|
685
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
686
|
+
const cached = ctx.pipeWireVolumeTarget;
|
|
687
|
+
const nodeId = cached?.pid === pid
|
|
688
|
+
? cached.nodeId
|
|
689
|
+
: findPipeWireAudioStreamForPid(pid);
|
|
690
|
+
if (!Number.isInteger(nodeId) || nodeId <= 0) return false;
|
|
691
|
+
const result = spawnSync(
|
|
692
|
+
"wpctl",
|
|
693
|
+
["set-volume", String(nodeId), `${percent}%`],
|
|
694
|
+
{ encoding: "utf8", windowsHide: true },
|
|
695
|
+
);
|
|
696
|
+
if (result.status !== 0) {
|
|
697
|
+
ctx.pipeWireVolumeTarget = undefined;
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
ctx.pipeWireVolumeTarget = { nodeId, pid };
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function seekCurrentPlayback(ctx, percent) {
|
|
705
|
+
if (!["mpv", "ffplay", "cvlc", "play"].includes(ctx.player)) {
|
|
706
|
+
throw new Error(`player ${ctx.player} does not support percentage seeking`);
|
|
707
|
+
}
|
|
708
|
+
const track = ctx.current?.track;
|
|
709
|
+
if (!track) throw new Error("current track is unavailable for seeking");
|
|
710
|
+
const duration = probeDurationSeconds(track);
|
|
711
|
+
if (duration === undefined) {
|
|
712
|
+
throw new Error("current track duration is unavailable for seeking");
|
|
713
|
+
}
|
|
714
|
+
ctx.seekPercent = percent;
|
|
715
|
+
ctx.seekSeconds = (duration * percent) / 100;
|
|
716
|
+
writeText(ctx.commandFile, "seek");
|
|
717
|
+
emitPlayerEvent(
|
|
718
|
+
ctx,
|
|
719
|
+
"player.seek",
|
|
720
|
+
`Music player seek set to ${percent}%`,
|
|
721
|
+
{ percent, seconds: ctx.seekSeconds },
|
|
722
|
+
);
|
|
723
|
+
controlCurrentPlayback(ctx, "stop");
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function handleControl(ctx, input, controlInput) {
|
|
727
|
+
const command = input.trim().toLowerCase();
|
|
728
|
+
if (!command) return;
|
|
729
|
+
if (!CONTROL_COMMANDS.has(command)) {
|
|
730
|
+
console.error(`music-player: unknown control command: ${command}`);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
switch (command) {
|
|
734
|
+
case "play":
|
|
735
|
+
case "resume":
|
|
736
|
+
resumePosition(ctx);
|
|
737
|
+
setState(ctx, "playing");
|
|
738
|
+
controlCurrentPlayback(ctx, "play");
|
|
739
|
+
break;
|
|
740
|
+
case "pause":
|
|
741
|
+
freezePosition(ctx);
|
|
742
|
+
setState(ctx, "paused");
|
|
743
|
+
controlCurrentPlayback(ctx, "pause");
|
|
744
|
+
break;
|
|
745
|
+
case "toggle": {
|
|
746
|
+
const current = readText(ctx.stateFile).trim();
|
|
747
|
+
if (current === "paused") {
|
|
748
|
+
resumePosition(ctx);
|
|
749
|
+
setState(ctx, "playing");
|
|
750
|
+
controlCurrentPlayback(ctx, "play");
|
|
751
|
+
} else {
|
|
752
|
+
freezePosition(ctx);
|
|
753
|
+
setState(ctx, "paused");
|
|
754
|
+
controlCurrentPlayback(ctx, "pause");
|
|
755
|
+
}
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
case "next":
|
|
759
|
+
writeText(ctx.commandFile, "next");
|
|
760
|
+
controlCurrentPlayback(ctx, "stop");
|
|
761
|
+
break;
|
|
762
|
+
case "previous":
|
|
763
|
+
case "prev":
|
|
764
|
+
writeText(ctx.commandFile, "previous");
|
|
765
|
+
controlCurrentPlayback(ctx, "stop");
|
|
766
|
+
break;
|
|
767
|
+
case "seek":
|
|
768
|
+
seekCurrentPlayback(ctx, parseSeekPercent(controlInput));
|
|
769
|
+
break;
|
|
770
|
+
case "volume": {
|
|
771
|
+
const percent = parseVolumePercent(controlInput);
|
|
772
|
+
ctx.volume = percent;
|
|
773
|
+
if (ctx.current) {
|
|
774
|
+
writeStatus(
|
|
775
|
+
ctx,
|
|
776
|
+
ctx.current.state,
|
|
777
|
+
ctx.current.index,
|
|
778
|
+
ctx.current.count,
|
|
779
|
+
ctx.current.track,
|
|
780
|
+
ctx.current.player,
|
|
781
|
+
ctx.current.pid,
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
const adjustedInPlace = setCurrentPlaybackVolume(ctx, percent);
|
|
785
|
+
emitPlayerEvent(
|
|
786
|
+
ctx,
|
|
787
|
+
"player.volume",
|
|
788
|
+
`Music player volume set to ${percent}%`,
|
|
789
|
+
{ adjusted_in_place: adjustedInPlace, percent },
|
|
790
|
+
);
|
|
791
|
+
if (ctx.child?.pid && !adjustedInPlace) {
|
|
792
|
+
writeText(ctx.commandFile, "replay");
|
|
793
|
+
controlCurrentPlayback(ctx, "stop");
|
|
794
|
+
}
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
case "stop":
|
|
798
|
+
ctx.stopping = true;
|
|
799
|
+
writeText(ctx.commandFile, "stop");
|
|
800
|
+
controlCurrentPlayback(ctx, "stop");
|
|
801
|
+
break;
|
|
802
|
+
case "status":
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function runJsonFile(ctx) {
|
|
808
|
+
return join(ctx.stateDir, "run.json");
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function readJsonFile(path, fallback) {
|
|
812
|
+
try {
|
|
813
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
814
|
+
} catch {
|
|
815
|
+
return fallback;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function writeJsonFile(path, value) {
|
|
820
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
821
|
+
writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
822
|
+
renameSync(temporary, path);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function readPlaybackCheckpoint(path) {
|
|
826
|
+
if (!existsSync(path)) return { checkpoint: undefined, state: "new" };
|
|
827
|
+
let raw;
|
|
828
|
+
try {
|
|
829
|
+
raw = JSON.parse(readFileSync(path, "utf8"));
|
|
830
|
+
} catch {
|
|
831
|
+
return { checkpoint: undefined, recovery: "invalid-json", state: "recovered" };
|
|
832
|
+
}
|
|
833
|
+
const checkpoint = normalizeCheckpoint(raw);
|
|
834
|
+
return checkpoint
|
|
835
|
+
? { checkpoint, state: "valid" }
|
|
836
|
+
: { checkpoint: undefined, recovery: "invalid-shape", state: "recovered" };
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
function normalizeCheckpoint(value) {
|
|
840
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
841
|
+
if (
|
|
842
|
+
value.version !== 1 ||
|
|
843
|
+
typeof value.source !== "string" ||
|
|
844
|
+
!["playing", "paused", "stopped"].includes(value.state) ||
|
|
845
|
+
!Array.isArray(value.tracks) ||
|
|
846
|
+
value.tracks.length === 0 ||
|
|
847
|
+
value.tracks.some((track) => typeof track !== "string" || !track)
|
|
848
|
+
) return undefined;
|
|
849
|
+
const index = Number(value.index);
|
|
850
|
+
if (!Number.isInteger(index) || index < 0 || index >= value.tracks.length)
|
|
851
|
+
return undefined;
|
|
852
|
+
return { ...value, index, tracks: value.tracks };
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function writePlaybackCheckpoint(ctx, state, index, track) {
|
|
856
|
+
if (!ctx.playbackFile || !ctx.tracks?.length) return;
|
|
857
|
+
writeJsonFile(ctx.playbackFile, {
|
|
858
|
+
version: 1,
|
|
859
|
+
source: ctx.source,
|
|
860
|
+
tracks: ctx.tracks,
|
|
861
|
+
index,
|
|
862
|
+
track,
|
|
863
|
+
state,
|
|
864
|
+
loop: ctx.loop,
|
|
865
|
+
volume: ctx.volume,
|
|
866
|
+
seek_percent: ctx.seekPercent ?? 0,
|
|
867
|
+
player: ctx.player,
|
|
868
|
+
updated_at: new Date().toISOString(),
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
function writePlaybackEndpoint(ctx, path) {
|
|
873
|
+
writeJsonFile(join(ctx.stateDir, "playback-endpoint.json"), {
|
|
874
|
+
owner_mode: ctx.ownerMode,
|
|
875
|
+
path,
|
|
876
|
+
service_instance_id: ctx.serviceInstanceId,
|
|
877
|
+
service_pid: process.pid,
|
|
878
|
+
type: "named-pipe",
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
async function startPlaybackProtocolServer(ctx) {
|
|
883
|
+
const path = process.platform === "win32"
|
|
884
|
+
? `\\\\.\\pipe\\pi-music-player-${ctx.serviceInstanceId}`
|
|
885
|
+
: join(ctx.stateDir, "playback.sock");
|
|
886
|
+
if (process.platform !== "win32") rmSync(path, { force: true });
|
|
887
|
+
const server = createServer((socket) => {
|
|
888
|
+
let content = "";
|
|
889
|
+
let handled = false;
|
|
890
|
+
const respond = () => {
|
|
891
|
+
if (handled) return;
|
|
892
|
+
handled = true;
|
|
893
|
+
try {
|
|
894
|
+
const wire = JSON.parse(content.trim());
|
|
895
|
+
if (
|
|
896
|
+
!wire ||
|
|
897
|
+
typeof wire !== "object" ||
|
|
898
|
+
Array.isArray(wire) ||
|
|
899
|
+
wire.service_instance_id !== ctx.serviceInstanceId ||
|
|
900
|
+
typeof wire.action !== "string" ||
|
|
901
|
+
!CONTROL_COMMANDS.has(wire.action)
|
|
902
|
+
) throw new Error("invalid playback protocol command");
|
|
903
|
+
handleControl(ctx, wire.action, wire.input);
|
|
904
|
+
socket.end(`${JSON.stringify({ ok: true })}\n`);
|
|
905
|
+
} catch (error) {
|
|
906
|
+
socket.end(`${JSON.stringify({
|
|
907
|
+
error: error instanceof Error ? error.message : String(error),
|
|
908
|
+
ok: false,
|
|
909
|
+
})}\n`);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
socket.setEncoding("utf8");
|
|
913
|
+
socket.on("data", (chunk) => {
|
|
914
|
+
content += chunk;
|
|
915
|
+
if (Buffer.byteLength(content, "utf8") > 4096) {
|
|
916
|
+
handled = true;
|
|
917
|
+
socket.destroy();
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
if (content.includes("\n")) respond();
|
|
921
|
+
});
|
|
922
|
+
socket.on("end", respond);
|
|
923
|
+
socket.resume();
|
|
924
|
+
});
|
|
925
|
+
await new Promise((resolveReady, rejectReady) => {
|
|
926
|
+
server.once("error", rejectReady);
|
|
927
|
+
server.listen(path, () => {
|
|
928
|
+
server.off("error", rejectReady);
|
|
929
|
+
writePlaybackEndpoint(ctx, path);
|
|
930
|
+
resolveReady();
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
return () => {
|
|
934
|
+
server.close();
|
|
935
|
+
rmSync(join(ctx.stateDir, "playback-endpoint.json"), { force: true });
|
|
936
|
+
if (process.platform !== "win32") rmSync(path, { force: true });
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
async function startControlServer(ctx, wakeControlLoop) {
|
|
941
|
+
if (!ctx.runInstanceId) return undefined;
|
|
942
|
+
const path = process.platform === "win32"
|
|
943
|
+
? `\\\\.\\pipe\\pi-actors-music-${String(process.env.run_id ?? process.pid).replaceAll(/[^A-Za-z0-9_-]/g, "-")}`
|
|
944
|
+
: join(ctx.stateDir, "control.sock");
|
|
945
|
+
if (process.platform !== "win32") rmSync(path, { force: true });
|
|
946
|
+
const server = createServer((socket) => {
|
|
947
|
+
let content = "";
|
|
948
|
+
socket.setEncoding("utf8");
|
|
949
|
+
socket.on("data", (chunk) => { content += chunk; });
|
|
950
|
+
socket.on("end", () => {
|
|
951
|
+
for (const line of content.split("\n")) {
|
|
952
|
+
if (!line.trim()) continue;
|
|
953
|
+
try {
|
|
954
|
+
const claimed = claimControl(ctx, JSON.parse(line));
|
|
955
|
+
if (!claimed) continue;
|
|
956
|
+
handleControl(ctx, claimed.action, claimed.input);
|
|
957
|
+
finalizeControl(ctx, claimed.id, "handled");
|
|
958
|
+
} catch (error) {
|
|
959
|
+
const id = (() => { try { return JSON.parse(line).id; } catch { return undefined; } })();
|
|
960
|
+
finalizeControl(ctx, id, "failed", error instanceof Error ? error.message : String(error));
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
wakeControlLoop();
|
|
964
|
+
});
|
|
965
|
+
socket.resume();
|
|
966
|
+
});
|
|
967
|
+
await new Promise((resolveReady, rejectReady) => {
|
|
968
|
+
server.once("error", rejectReady);
|
|
969
|
+
server.listen(path, () => {
|
|
970
|
+
server.off("error", rejectReady);
|
|
971
|
+
writeJsonFile(join(ctx.stateDir, "control-endpoint.json"), {
|
|
972
|
+
path,
|
|
973
|
+
ready_at: new Date().toISOString(),
|
|
974
|
+
run_instance_id: ctx.runInstanceId,
|
|
975
|
+
type: "named-pipe",
|
|
976
|
+
});
|
|
977
|
+
resolveReady();
|
|
978
|
+
});
|
|
979
|
+
});
|
|
980
|
+
return () => {
|
|
981
|
+
server.close();
|
|
982
|
+
rmSync(join(ctx.stateDir, "control-endpoint.json"), { force: true });
|
|
983
|
+
if (process.platform !== "win32") rmSync(path, { force: true });
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function commandFromControl(control) {
|
|
988
|
+
if (typeof control.action !== "string") return undefined;
|
|
989
|
+
const action = control.action.trim();
|
|
990
|
+
return CONTROL_COMMANDS.has(action) ? action : undefined;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function appendControl(ctx, action, input) {
|
|
994
|
+
const run = readJsonFile(runJsonFile(ctx), {});
|
|
995
|
+
return appendRunControlInStateDir(ctx.stateDir, {
|
|
996
|
+
action,
|
|
997
|
+
...(input !== undefined ? { input } : {}),
|
|
998
|
+
run_instance_id: run.run_instance_id,
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function claimControl(ctx, wire) {
|
|
1003
|
+
const control = claimRunControlByIdInStateDir(
|
|
1004
|
+
ctx.stateDir, ctx.runInstanceId, wire.id,
|
|
1005
|
+
);
|
|
1006
|
+
const action = control ? commandFromControl(control) : undefined;
|
|
1007
|
+
if (!action && control) {
|
|
1008
|
+
updateRunControlStatusInStateDir(ctx.stateDir, control.id, "failed", {
|
|
1009
|
+
error: "Unsupported music-player Control",
|
|
1010
|
+
}, ["claimed"]);
|
|
1011
|
+
}
|
|
1012
|
+
return action && control
|
|
1013
|
+
? { action, id: control.id, input: control.input }
|
|
1014
|
+
: undefined;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
function finalizeControl(ctx, id, status, error) {
|
|
1018
|
+
if (!id) return;
|
|
1019
|
+
updateRunControlStatusInStateDir(
|
|
1020
|
+
ctx.stateDir, id, status, error ? { error } : {}, ["claimed"],
|
|
1021
|
+
);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
function controlsSignature(ctx) {
|
|
1025
|
+
try {
|
|
1026
|
+
const stat = statSync(ctx.controlsFile);
|
|
1027
|
+
return `${stat.size}:${stat.mtimeMs}`;
|
|
1028
|
+
} catch {
|
|
1029
|
+
return "missing";
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
function startControlLoop(ctx) {
|
|
1034
|
+
let closed = false;
|
|
1035
|
+
let dirty = true;
|
|
1036
|
+
let watcher;
|
|
1037
|
+
if (process.platform !== "win32") {
|
|
1038
|
+
try {
|
|
1039
|
+
watcher = watch(ctx.stateDir, { persistent: false }, (_eventType, file) => {
|
|
1040
|
+
const name = file ? String(file) : "";
|
|
1041
|
+
if (
|
|
1042
|
+
!name ||
|
|
1043
|
+
name === basename(ctx.controlsFile)
|
|
1044
|
+
) {
|
|
1045
|
+
dirty = true;
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
} catch {
|
|
1049
|
+
// fs.watch is advisory; signature checks remain the portable fallback.
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const close = () => {
|
|
1053
|
+
closed = true;
|
|
1054
|
+
watcher?.close();
|
|
1055
|
+
};
|
|
1056
|
+
const promise = (async () => {
|
|
1057
|
+
let lastSignature = "";
|
|
1058
|
+
while (!ctx.stopping && !closed) {
|
|
1059
|
+
const signature = controlsSignature(ctx);
|
|
1060
|
+
if (dirty || signature !== lastSignature) {
|
|
1061
|
+
dirty = false;
|
|
1062
|
+
if (ctx.runInstanceId) {
|
|
1063
|
+
await processRunControlsInStateDir(
|
|
1064
|
+
ctx.stateDir,
|
|
1065
|
+
ctx.runInstanceId,
|
|
1066
|
+
(control) => {
|
|
1067
|
+
const action = commandFromControl(control);
|
|
1068
|
+
if (!action) throw new Error("Unsupported music-player Control");
|
|
1069
|
+
handleControl(ctx, action, control.input);
|
|
1070
|
+
},
|
|
1071
|
+
8,
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
lastSignature = controlsSignature(ctx);
|
|
1075
|
+
}
|
|
1076
|
+
await sleep(250);
|
|
1077
|
+
}
|
|
1078
|
+
})();
|
|
1079
|
+
return { close, promise, wake: () => { dirty = true; } };
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function playOne(ctx, player, track, index, count) {
|
|
1083
|
+
return new Promise((resolveDone) => {
|
|
1084
|
+
if (ctx.stopping) {
|
|
1085
|
+
resolveDone();
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
rmSync(ctx.playerControlFile, { force: true });
|
|
1089
|
+
ctx.durationSeconds = probeDurationSeconds(track);
|
|
1090
|
+
ctx.positionSeconds = ctx.seekSeconds ?? 0;
|
|
1091
|
+
ctx.positionStartedAtMs = Date.now();
|
|
1092
|
+
const [command, args] = playerCommand(
|
|
1093
|
+
ctx,
|
|
1094
|
+
player,
|
|
1095
|
+
ctx.volume,
|
|
1096
|
+
track,
|
|
1097
|
+
ctx.seekSeconds ?? 0,
|
|
1098
|
+
);
|
|
1099
|
+
writeStatus(ctx, "playing", index, count, track, player, "");
|
|
1100
|
+
const child = spawn(command, args, {
|
|
1101
|
+
detached: process.platform === "win32",
|
|
1102
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
1103
|
+
});
|
|
1104
|
+
ctx.child = child;
|
|
1105
|
+
ctx.pipeWireVolumeTarget = undefined;
|
|
1106
|
+
const pid = child.pid || "";
|
|
1107
|
+
if (pid) writeText(ctx.pidFile, String(pid));
|
|
1108
|
+
if (ctx.stopping) controlCurrentPlayback(ctx, "stop");
|
|
1109
|
+
writeStatus(ctx, "playing", index, count, track, player, pid);
|
|
1110
|
+
if (ctx.desiredState === "paused") {
|
|
1111
|
+
controlCurrentPlayback(ctx, "pause");
|
|
1112
|
+
freezePosition(ctx);
|
|
1113
|
+
writeStatus(ctx, "paused", index, count, track, player, pid);
|
|
1114
|
+
}
|
|
1115
|
+
emitTrackEvent(ctx, index, count, track, player);
|
|
1116
|
+
child.once("error", (error) => {
|
|
1117
|
+
console.error(
|
|
1118
|
+
`music-player: failed to start ${command}: ${error.message}`,
|
|
1119
|
+
);
|
|
1120
|
+
resolveDone();
|
|
1121
|
+
});
|
|
1122
|
+
child.once("exit", () => {
|
|
1123
|
+
rmSync(ctx.pidFile, { force: true });
|
|
1124
|
+
ctx.child = undefined;
|
|
1125
|
+
resolveDone();
|
|
1126
|
+
});
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
function readAndClearCommand(ctx) {
|
|
1131
|
+
const command = readText(ctx.commandFile).trim();
|
|
1132
|
+
writeText(ctx.commandFile, "");
|
|
1133
|
+
return command;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
async function playMain(args) {
|
|
1137
|
+
const [
|
|
1138
|
+
sourceArg,
|
|
1139
|
+
loopArg = "true",
|
|
1140
|
+
volumeArg = "70",
|
|
1141
|
+
playerArg = "auto",
|
|
1142
|
+
rawStateDir,
|
|
1143
|
+
] = args;
|
|
1144
|
+
if (!sourceArg || sourceArg === "-h" || sourceArg === "--help") {
|
|
1145
|
+
usage();
|
|
1146
|
+
process.exit(2);
|
|
1147
|
+
}
|
|
1148
|
+
const stateDir = expandPath(
|
|
1149
|
+
rawStateDir ||
|
|
1150
|
+
join(
|
|
1151
|
+
process.env.TMPDIR || "/tmp",
|
|
1152
|
+
`pi-actors-music-player-${process.pid}`,
|
|
1153
|
+
),
|
|
1154
|
+
);
|
|
1155
|
+
mkdirSync(stateDir, { recursive: true });
|
|
1156
|
+
const existingEndpoint = readJsonFile(
|
|
1157
|
+
join(stateDir, "playback-endpoint.json"),
|
|
1158
|
+
{},
|
|
1159
|
+
);
|
|
1160
|
+
if (isLocalProcessAlive(Number(existingEndpoint.service_pid))) {
|
|
1161
|
+
if (actorAdapterEnabled && existingEndpoint.owner_mode === "standalone") {
|
|
1162
|
+
fail(`standalone playback service already owns state: ${stateDir}`, 3);
|
|
1163
|
+
}
|
|
1164
|
+
if (!actorAdapterEnabled) {
|
|
1165
|
+
fail(`active playback service already owns state: ${stateDir}`, 3);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
const startupRun = actorAdapterEnabled
|
|
1169
|
+
? readJsonFile(runJsonFile({ stateDir }), {})
|
|
1170
|
+
: {};
|
|
1171
|
+
const source = expandPath(sourceArg);
|
|
1172
|
+
const loop = parseBool(loopArg);
|
|
1173
|
+
const volume = normalizeVolume(volumeArg);
|
|
1174
|
+
const player = selectPlayer(playerArg);
|
|
1175
|
+
const playbackFile = join(stateDir, "playback.json");
|
|
1176
|
+
const checkpointLoad = readPlaybackCheckpoint(playbackFile);
|
|
1177
|
+
const checkpoint = checkpointLoad.checkpoint;
|
|
1178
|
+
const checkpointTracksUsable =
|
|
1179
|
+
checkpoint?.source === source &&
|
|
1180
|
+
checkpoint.player === player &&
|
|
1181
|
+
checkpoint.tracks.every((track) => isUrl(track) || exists(track));
|
|
1182
|
+
const tracks = checkpointTracksUsable ? checkpoint.tracks : loadPlaylist(source);
|
|
1183
|
+
let index = checkpointTracksUsable ? checkpoint.index : 0;
|
|
1184
|
+
const ctx = {
|
|
1185
|
+
commandFile: join(stateDir, "command.txt"),
|
|
1186
|
+
current: undefined,
|
|
1187
|
+
controlsFile: join(stateDir, "controls.jsonl"),
|
|
1188
|
+
desiredState:
|
|
1189
|
+
checkpointTracksUsable && checkpoint.state === "paused"
|
|
1190
|
+
? "paused"
|
|
1191
|
+
: "playing",
|
|
1192
|
+
index,
|
|
1193
|
+
loop,
|
|
1194
|
+
pidFile: join(stateDir, "current.pid"),
|
|
1195
|
+
playbackFile,
|
|
1196
|
+
ownerMode: actorAdapterEnabled ? "actor" : "standalone",
|
|
1197
|
+
player,
|
|
1198
|
+
playerControlFile: join(stateDir, "player-control.txt"),
|
|
1199
|
+
positionSeconds: 0,
|
|
1200
|
+
positionStartedAtMs: undefined,
|
|
1201
|
+
runInstanceId: typeof startupRun.run_instance_id === "string"
|
|
1202
|
+
? startupRun.run_instance_id
|
|
1203
|
+
: undefined,
|
|
1204
|
+
seekPercent: 0,
|
|
1205
|
+
seekSeconds: 0,
|
|
1206
|
+
serviceInstanceId: randomUUID(),
|
|
1207
|
+
source,
|
|
1208
|
+
stateDir,
|
|
1209
|
+
stateFile: join(stateDir, "player-state.txt"),
|
|
1210
|
+
statusFile: join(stateDir, "status.txt"),
|
|
1211
|
+
statusJsonFile: join(stateDir, "player.json"),
|
|
1212
|
+
stopping: false,
|
|
1213
|
+
tracks,
|
|
1214
|
+
volume,
|
|
1215
|
+
};
|
|
1216
|
+
rmSync(ctx.commandFile, { force: true });
|
|
1217
|
+
rmSync(ctx.pidFile, { force: true });
|
|
1218
|
+
rmSync(ctx.playerControlFile, { force: true });
|
|
1219
|
+
let controlLoop;
|
|
1220
|
+
let closeControlServer;
|
|
1221
|
+
let closePlaybackProtocolServer;
|
|
1222
|
+
const cleanup = () => {
|
|
1223
|
+
ctx.stopping = true;
|
|
1224
|
+
if (ctx.current) {
|
|
1225
|
+
freezePosition(ctx);
|
|
1226
|
+
writeStatus(ctx, "stopped", index, tracks.length, tracks[index] ?? "", player, "");
|
|
1227
|
+
} else writeText(ctx.stateFile, "stopped");
|
|
1228
|
+
if (ctx.child?.pid) controlCurrentPlayback(ctx, "stop");
|
|
1229
|
+
controlLoop?.close();
|
|
1230
|
+
closeControlServer?.();
|
|
1231
|
+
closePlaybackProtocolServer?.();
|
|
1232
|
+
rmSync(ctx.pidFile, { force: true });
|
|
1233
|
+
rmSync(ctx.playerControlFile, { force: true });
|
|
1234
|
+
};
|
|
1235
|
+
process.once("SIGTERM", () => {
|
|
1236
|
+
cleanup();
|
|
1237
|
+
process.exit(143);
|
|
1238
|
+
});
|
|
1239
|
+
process.once("SIGINT", () => {
|
|
1240
|
+
cleanup();
|
|
1241
|
+
process.exit(130);
|
|
1242
|
+
});
|
|
1243
|
+
process.once("SIGHUP", () => {
|
|
1244
|
+
cleanup();
|
|
1245
|
+
process.exit(129);
|
|
1246
|
+
});
|
|
1247
|
+
try {
|
|
1248
|
+
controlLoop = startControlLoop(ctx);
|
|
1249
|
+
closePlaybackProtocolServer = await startPlaybackProtocolServer(ctx);
|
|
1250
|
+
closeControlServer = await startControlServer(ctx, controlLoop.wake);
|
|
1251
|
+
if (checkpointLoad.recovery) {
|
|
1252
|
+
console.error(
|
|
1253
|
+
`music-player: checkpoint_recovery=${checkpointLoad.recovery} state_dir=${stateDir}`,
|
|
1254
|
+
);
|
|
1255
|
+
emitPlayerEvent(
|
|
1256
|
+
ctx,
|
|
1257
|
+
"player.checkpoint-recovered",
|
|
1258
|
+
"Ignored malformed playback checkpoint and rebuilt the queue",
|
|
1259
|
+
{ reason: checkpointLoad.recovery },
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
setState(ctx, ctx.desiredState);
|
|
1263
|
+
const checkpointState = checkpointTracksUsable
|
|
1264
|
+
? "resumed"
|
|
1265
|
+
: checkpointLoad.recovery
|
|
1266
|
+
? "recovered"
|
|
1267
|
+
: checkpoint
|
|
1268
|
+
? "rebuilt"
|
|
1269
|
+
: "new";
|
|
1270
|
+
console.error(
|
|
1271
|
+
`music-player: player=${player} loop=${loop} volume=${ctx.volume} tracks=${tracks.length} checkpoint=${checkpointState} start_index=${index} state_dir=${stateDir}`,
|
|
1272
|
+
);
|
|
1273
|
+
const count = tracks.length;
|
|
1274
|
+
while (!ctx.stopping) {
|
|
1275
|
+
const track = tracks[index];
|
|
1276
|
+
await playOne(ctx, player, track, index, count);
|
|
1277
|
+
const command = readAndClearCommand(ctx);
|
|
1278
|
+
if (command === "stop") {
|
|
1279
|
+
freezePosition(ctx);
|
|
1280
|
+
writeStatus(ctx, "stopped", index, count, track, player, "");
|
|
1281
|
+
emitStoppedEvent(ctx, "message");
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
if (command === "previous" || command === "prev") {
|
|
1285
|
+
ctx.seekPercent = 0;
|
|
1286
|
+
ctx.seekSeconds = 0;
|
|
1287
|
+
index = (index - 1 + count) % count;
|
|
1288
|
+
continue;
|
|
1289
|
+
}
|
|
1290
|
+
if (command === "next") {
|
|
1291
|
+
ctx.seekPercent = 0;
|
|
1292
|
+
ctx.seekSeconds = 0;
|
|
1293
|
+
index = (index + 1) % count;
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
if (command === "seek" || command === "replay") continue;
|
|
1297
|
+
ctx.seekPercent = 0;
|
|
1298
|
+
ctx.seekSeconds = 0;
|
|
1299
|
+
if (index + 1 >= count) {
|
|
1300
|
+
if (loop) index = 0;
|
|
1301
|
+
else break;
|
|
1302
|
+
} else {
|
|
1303
|
+
index += 1;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
freezePosition(ctx);
|
|
1307
|
+
writeStatus(ctx, "stopped", index, tracks.length, "", player, "");
|
|
1308
|
+
emitStoppedEvent(ctx, "complete");
|
|
1309
|
+
} finally {
|
|
1310
|
+
cleanup();
|
|
1311
|
+
await Promise.race([controlLoop?.promise ?? Promise.resolve(), sleep(100)]);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
function projectCurrentProgress(status, nowMs = Date.now()) {
|
|
1316
|
+
if (!status || typeof status !== "object" || Array.isArray(status)) return status;
|
|
1317
|
+
const duration = Number(status.duration_seconds);
|
|
1318
|
+
let position = Number(status.position_seconds);
|
|
1319
|
+
const updatedAtMs = Number(status.position_updated_at_ms);
|
|
1320
|
+
if (!Number.isFinite(position)) position = 0;
|
|
1321
|
+
if (status.state === "playing" && Number.isFinite(updatedAtMs)) {
|
|
1322
|
+
position += Math.max(0, nowMs - updatedAtMs) / 1000;
|
|
1323
|
+
}
|
|
1324
|
+
if (!Number.isFinite(duration) || duration <= 0) {
|
|
1325
|
+
return { ...status, progress_percent: null };
|
|
1326
|
+
}
|
|
1327
|
+
position = Math.min(Math.max(position, 0), duration);
|
|
1328
|
+
return {
|
|
1329
|
+
...status,
|
|
1330
|
+
progress_percent: Math.round((position / duration) * 100),
|
|
1331
|
+
position_seconds: position,
|
|
1332
|
+
position_updated_at_ms: nowMs,
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
function actorControlAvailability(stateDir) {
|
|
1337
|
+
const run = readJsonFile(join(stateDir, "run.json"), {});
|
|
1338
|
+
const result = readJsonFile(join(stateDir, "result.json"), {});
|
|
1339
|
+
const endpoint = readJsonFile(join(stateDir, "control-endpoint.json"), {});
|
|
1340
|
+
const playerStatus = readJsonFile(join(stateDir, "player.json"), {});
|
|
1341
|
+
const pid = Number(run.pid || 0);
|
|
1342
|
+
const hasProcessIdentity = pid > 0 || run.process_identity !== undefined;
|
|
1343
|
+
const processIdentity = pid > 0
|
|
1344
|
+
? verifyRunProcessIdentity(pid, run.process_identity)
|
|
1345
|
+
: { valid: false };
|
|
1346
|
+
const available =
|
|
1347
|
+
typeof run.run_instance_id === "string" &&
|
|
1348
|
+
typeof result.completedAt !== "string" &&
|
|
1349
|
+
(!hasProcessIdentity || (pid > 0 && isAlive(pid) && processIdentity.valid === true)) &&
|
|
1350
|
+
endpoint.run_instance_id === run.run_instance_id &&
|
|
1351
|
+
["playing", "paused"].includes(playerStatus.state);
|
|
1352
|
+
return {
|
|
1353
|
+
available,
|
|
1354
|
+
runInstanceId: typeof run.run_instance_id === "string"
|
|
1355
|
+
? run.run_instance_id
|
|
1356
|
+
: undefined,
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
async function controlMain(args) {
|
|
1361
|
+
const stateDir = expandPath(args[0] || "");
|
|
1362
|
+
const command = args[1] || "status";
|
|
1363
|
+
const rawInput = args[2];
|
|
1364
|
+
if (!stateDir) {
|
|
1365
|
+
usage();
|
|
1366
|
+
process.exit(2);
|
|
1367
|
+
}
|
|
1368
|
+
mkdirSync(stateDir, { recursive: true });
|
|
1369
|
+
if (command === "status") {
|
|
1370
|
+
const statusFile = join(stateDir, "player.json");
|
|
1371
|
+
const status = exists(statusFile)
|
|
1372
|
+
? readJsonFile(statusFile, { state: "unknown" })
|
|
1373
|
+
: { state: "unknown" };
|
|
1374
|
+
const actor = actorControlAvailability(stateDir);
|
|
1375
|
+
process.stdout.write(`${JSON.stringify({
|
|
1376
|
+
...projectCurrentProgress(status),
|
|
1377
|
+
actor_available: actor.available,
|
|
1378
|
+
...(actor.runInstanceId
|
|
1379
|
+
? { actor_run_instance_id: actor.runInstanceId }
|
|
1380
|
+
: {}),
|
|
1381
|
+
})}\n`);
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
if (!actorControlAvailability(stateDir).available) {
|
|
1385
|
+
fail(`Run playback is not active: ${stateDir}`, 3);
|
|
1386
|
+
}
|
|
1387
|
+
let input;
|
|
1388
|
+
if (command === "seek" || command === "volume") {
|
|
1389
|
+
try {
|
|
1390
|
+
input = {
|
|
1391
|
+
percent: command === "seek"
|
|
1392
|
+
? parseSeekPercent(rawInput)
|
|
1393
|
+
: parseVolumePercent(rawInput),
|
|
1394
|
+
};
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
fail(error instanceof Error ? error.message : String(error), 2);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
const queued = appendControl(
|
|
1400
|
+
{ controlsFile: join(stateDir, "controls.jsonl"), stateDir },
|
|
1401
|
+
command,
|
|
1402
|
+
input,
|
|
1403
|
+
);
|
|
1404
|
+
const deadline = Date.now() + 5_000;
|
|
1405
|
+
while (Date.now() < deadline) {
|
|
1406
|
+
const current = readRunControlJournalFromStateDir(stateDir).records.find(
|
|
1407
|
+
(record) => record.id === queued.id,
|
|
1408
|
+
);
|
|
1409
|
+
if (current?.status === "handled") {
|
|
1410
|
+
console.log(
|
|
1411
|
+
`music-player: command=${command} handled control_id=${queued.id} state_dir=${stateDir}`,
|
|
1412
|
+
);
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
if (current?.status === "failed") {
|
|
1416
|
+
fail(current.error || `Control ${queued.id} failed`, 3);
|
|
1417
|
+
}
|
|
1418
|
+
await sleep(50);
|
|
1419
|
+
}
|
|
1420
|
+
fail(`Control ${queued.id} did not become terminal`, 3);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
const [mode, ...rest] = process.argv.slice(2);
|
|
1424
|
+
const directControlCommands = new Set([
|
|
1425
|
+
"pause",
|
|
1426
|
+
"resume",
|
|
1427
|
+
"toggle",
|
|
1428
|
+
"next",
|
|
1429
|
+
"previous",
|
|
1430
|
+
"seek",
|
|
1431
|
+
"volume",
|
|
1432
|
+
"stop",
|
|
1433
|
+
"status",
|
|
1434
|
+
]);
|
|
1435
|
+
if (mode === "play" || mode === "serve") await playMain(rest);
|
|
1436
|
+
else if (mode === "control") await controlMain(rest);
|
|
1437
|
+
else if (mode === "seek" || mode === "volume") {
|
|
1438
|
+
await controlMain([rest[0], mode, rest[1]]);
|
|
1439
|
+
} else if (directControlCommands.has(mode)) {
|
|
1440
|
+
await controlMain([rest.at(-1), mode === "resume" ? "play" : mode]);
|
|
1441
|
+
} else if (!mode || mode === "-h" || mode === "--help" || mode === "help") {
|
|
1442
|
+
usage();
|
|
1443
|
+
process.exit(mode ? 0 : 2);
|
|
1444
|
+
} else {
|
|
1445
|
+
await playMain([mode, ...rest]);
|
|
1446
|
+
}
|