create-principles-disciple 1.154.5 → 1.155.2
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/_release/product-identity.json +2 -2
- package/codex-adapter/dist/codec/input-decoder.d.ts +17 -0
- package/codex-adapter/dist/codec/input-decoder.js +39 -0
- package/codex-adapter/dist/ingestion/explicit-owner-statement.js +125 -1
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +46 -0
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +193 -0
- package/codex-adapter/dist/ingestion/turn-context.d.ts +10 -15
- package/codex-adapter/dist/ingestion/turn-context.js +35 -9
- package/codex-adapter/dist/pd-hook.js +57 -1
- package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
- package/codex-adapter/dist/worker/workspace-worker.js +91 -12
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.js +11 -0
- package/console/dist/server/models/EvidenceChainConsoleModel.js +31 -0
- package/console/dist/server/routes/health.d.ts +1 -0
- package/console/dist/server/routes/health.js +12 -0
- package/console/dist/server/routes/service-host.d.ts +19 -0
- package/console/dist/server/routes/service-host.js +129 -0
- package/console/dist/web/assets/app.js +39 -39
- package/console/package.json +1 -1
- package/core/dist/runtime/adapter/pi-ai-http-transport.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-http-transport.js.map +1 -1
- package/core/dist/runtime/context-payload.d.ts +48 -0
- package/core/dist/runtime/context-payload.d.ts.map +1 -1
- package/core/dist/runtime/context-payload.js +12 -0
- package/core/dist/runtime/context-payload.js.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +18 -0
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.js +18 -2
- package/core/dist/runtime/diagnostician-candidate.js.map +1 -1
- package/core/dist/runtime/evidence-guards.d.ts +7 -3
- package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
- package/core/dist/runtime/evidence-guards.js +9 -7
- package/core/dist/runtime/evidence-guards.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
- package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +8 -0
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
- package/core/dist/runtime/host-submission-context.d.ts +83 -0
- package/core/dist/runtime/host-submission-context.d.ts.map +1 -0
- package/core/dist/runtime/host-submission-context.js +183 -0
- package/core/dist/runtime/host-submission-context.js.map +1 -0
- package/core/dist/runtime/index.d.ts +9 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +29 -2
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-doc.js +29 -5
- package/core/dist/runtime/intent/intent-doc.js.map +1 -1
- package/core/dist/runtime/internalization/diag-distiller-runner.d.ts +9 -0
- package/core/dist/runtime/internalization/diag-distiller-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-distiller-runner.js +13 -0
- package/core/dist/runtime/internalization/diag-distiller-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +11 -0
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.js +10 -0
- package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.d.ts +9 -0
- package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.js +13 -0
- package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
- package/core/dist/runtime/internalization/index.d.ts +1 -1
- package/core/dist/runtime/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime/internalization/index.js +1 -1
- package/core/dist/runtime/internalization/index.js.map +1 -1
- package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts +19 -0
- package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts.map +1 -1
- package/core/dist/runtime/internalization/intake-to-internalization-bridge.js +24 -0
- package/core/dist/runtime/internalization/intake-to-internalization-bridge.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +8 -0
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.js +36 -4
- package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
- package/core/dist/runtime/internalization/source-authorization-boundary.d.ts +39 -0
- package/core/dist/runtime/internalization/source-authorization-boundary.d.ts.map +1 -0
- package/core/dist/runtime/internalization/source-authorization-boundary.js +57 -0
- package/core/dist/runtime/internalization/source-authorization-boundary.js.map +1 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +72 -5
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/pain-admission-disposition.d.ts +60 -0
- package/core/dist/runtime/pain-admission-disposition.d.ts.map +1 -0
- package/core/dist/runtime/pain-admission-disposition.js +37 -0
- package/core/dist/runtime/pain-admission-disposition.js.map +1 -0
- package/core/dist/runtime/pain-ingress-payload.d.ts +36 -2
- package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.js +63 -6
- package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
- package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress.js +28 -0
- package/core/dist/runtime/pain-ingress.js.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.d.ts +13 -1
- package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.js +50 -7
- package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.d.ts +147 -0
- package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -0
- package/core/dist/runtime/pain-receipt-recovery.js +475 -0
- package/core/dist/runtime/pain-receipt-recovery.js.map +1 -0
- package/core/dist/runtime/pain-signal-bridge.d.ts +13 -1
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +174 -0
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts +9 -0
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +8 -3
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +11 -0
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +77 -3
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +55 -0
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -0
- package/core/dist/runtime/pain-target-evidence-reconcile.js +164 -0
- package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts +8 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js +1 -0
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/source-material-authorization.d.ts +166 -0
- package/core/dist/runtime/source-material-authorization.d.ts.map +1 -0
- package/core/dist/runtime/source-material-authorization.js +250 -0
- package/core/dist/runtime/source-material-authorization.js.map +1 -0
- package/core/dist/runtime/store/context/index.d.ts +1 -0
- package/core/dist/runtime/store/context/index.d.ts.map +1 -1
- package/core/dist/runtime/store/context/index.js +1 -0
- package/core/dist/runtime/store/context/index.js.map +1 -1
- package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts +8 -0
- package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts.map +1 -1
- package/core/dist/runtime/store/context/promoted-evidence-reader.js +15 -1
- package/core/dist/runtime/store/context/promoted-evidence-reader.js.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts +22 -0
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +153 -3
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts +13 -0
- package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/lease-manager.d.ts +15 -0
- package/core/dist/runtime/store/lifecycle/lease-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/lease-manager.js +16 -1
- package/core/dist/runtime/store/lifecycle/lease-manager.js.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -0
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.d.ts +1 -0
- package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.js +37 -0
- package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.d.ts +10 -0
- package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.js +20 -0
- package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/task-store.d.ts +16 -0
- package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
- package/core/dist/runtime/task-status.d.ts +13 -0
- package/core/dist/runtime/task-status.d.ts.map +1 -1
- package/core/dist/runtime/task-status.js +9 -0
- package/core/dist/runtime/task-status.js.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.d.ts +10 -0
- package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.js +7 -0
- package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
- package/core/package.json +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +77 -30
- package/dist/installer.js.map +1 -1
- package/dist/installers/mcp-registration-conflict.d.ts +8 -0
- package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
- package/dist/installers/mcp-registration-conflict.js +34 -1
- package/dist/installers/mcp-registration-conflict.js.map +1 -1
- package/dist/installers/workbuddy-host-installer.d.ts +45 -13
- package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +284 -21
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/dist/prompts.d.ts +11 -0
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +4 -0
- package/dist/prompts.js.map +1 -1
- package/dist/service-host-bridge.d.ts +67 -0
- package/dist/service-host-bridge.d.ts.map +1 -0
- package/dist/service-host-bridge.js +292 -0
- package/dist/service-host-bridge.js.map +1 -0
- package/dist/uninstaller.d.ts.map +1 -1
- package/dist/uninstaller.js +26 -0
- package/dist/uninstaller.js.map +1 -1
- package/dist/update/install-layout.d.ts +0 -12
- package/dist/update/install-layout.d.ts.map +1 -1
- package/dist/update/install-layout.js +42 -15
- package/dist/update/install-layout.js.map +1 -1
- package/host-runtime/dist/diagnostician-auto-run.js +4 -1
- package/host-runtime/dist/governance-observation-store.d.ts +7 -0
- package/host-runtime/dist/governance-observation-store.js +15 -4
- package/host-runtime/dist/governance-signal-admission.d.ts +49 -0
- package/host-runtime/dist/governance-signal-admission.js +355 -94
- package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +20 -4
- package/host-runtime/dist/governance-trajectory-turn-reader.js +77 -5
- package/host-runtime/dist/index.d.ts +2 -0
- package/host-runtime/dist/index.js +5 -0
- package/host-runtime/dist/internalization-consumer-cycle.js +4 -1
- package/host-runtime/dist/pd-config.d.ts +10 -0
- package/host-runtime/dist/pd-config.js +37 -0
- package/host-runtime/dist/signal-stage2-cycle.js +28 -1
- package/host-runtime/dist/source-material-authorization.d.ts +53 -0
- package/host-runtime/dist/source-material-authorization.js +67 -0
- package/host-runtime/dist/source-revocation-sweep.d.ts +172 -0
- package/host-runtime/dist/source-revocation-sweep.js +928 -0
- package/host-runtime/package.json +5 -1
- package/install-layout/dist/background-execution-transition.d.ts +258 -0
- package/install-layout/dist/background-execution-transition.js +836 -0
- package/install-layout/dist/index.d.ts +8 -0
- package/install-layout/dist/index.js +8 -0
- package/install-layout/package.json +6 -2
- package/package.json +7 -6
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +16 -5
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/codex-setup.d.ts.map +1 -1
- package/pd-cli/dist/commands/codex-setup.js +17 -1
- package/pd-cli/dist/commands/codex-setup.js.map +1 -1
- package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/codex-worker.js +8 -4
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/consent-sweep-revoked.d.ts +20 -0
- package/pd-cli/dist/commands/consent-sweep-revoked.d.ts.map +1 -0
- package/pd-cli/dist/commands/consent-sweep-revoked.js +85 -0
- package/pd-cli/dist/commands/consent-sweep-revoked.js.map +1 -0
- package/pd-cli/dist/commands/console.d.ts.map +1 -1
- package/pd-cli/dist/commands/console.js +9 -0
- package/pd-cli/dist/commands/console.js.map +1 -1
- package/pd-cli/dist/commands/context.d.ts.map +1 -1
- package/pd-cli/dist/commands/context.js +9 -1
- package/pd-cli/dist/commands/context.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +12 -6
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/health-console.d.ts +1 -1
- package/pd-cli/dist/commands/health-console.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-console.js +15 -1
- package/pd-cli/dist/commands/health-console.js.map +1 -1
- package/pd-cli/dist/commands/health.d.ts.map +1 -1
- package/pd-cli/dist/commands/health.js +7 -1
- package/pd-cli/dist/commands/health.js.map +1 -1
- package/pd-cli/dist/commands/openclaw-worker.d.ts +11 -0
- package/pd-cli/dist/commands/openclaw-worker.d.ts.map +1 -0
- package/pd-cli/dist/commands/openclaw-worker.js +199 -0
- package/pd-cli/dist/commands/openclaw-worker.js.map +1 -0
- package/pd-cli/dist/commands/pain-explicit.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-explicit.js +1 -0
- package/pd-cli/dist/commands/pain-explicit.js.map +1 -1
- package/pd-cli/dist/commands/pain-recall.d.ts +2 -2
- package/pd-cli/dist/commands/pain-recall.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-recall.js +7 -1
- package/pd-cli/dist/commands/pain-recall.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +12 -6
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +2 -1
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts +1 -0
- package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js +32 -8
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-wake-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-wake-once.js +2 -1
- package/pd-cli/dist/commands/runtime-internalization-wake-once.js.map +1 -1
- package/pd-cli/dist/commands/service-handover.d.ts +12 -0
- package/pd-cli/dist/commands/service-handover.d.ts.map +1 -0
- package/pd-cli/dist/commands/service-handover.js +117 -0
- package/pd-cli/dist/commands/service-handover.js.map +1 -0
- package/pd-cli/dist/commands/service-lifecycle.d.ts +31 -0
- package/pd-cli/dist/commands/service-lifecycle.d.ts.map +1 -0
- package/pd-cli/dist/commands/service-lifecycle.js +207 -0
- package/pd-cli/dist/commands/service-lifecycle.js.map +1 -0
- package/pd-cli/dist/commands/service-run-once.d.ts +96 -0
- package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/service-run-once.js +432 -13
- package/pd-cli/dist/commands/service-run-once.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
- package/pd-cli/dist/commands/workbuddy-setup.js +22 -2
- package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
- package/pd-cli/dist/program.d.ts.map +1 -1
- package/pd-cli/dist/program.js +167 -9
- package/pd-cli/dist/program.js.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts +3 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.js +1 -0
- package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
- package/pd-cli/dist/services/console-launcher.d.ts +93 -1
- package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
- package/pd-cli/dist/services/console-launcher.js +375 -10
- package/pd-cli/dist/services/console-launcher.js.map +1 -1
- package/pd-cli/dist/services/service-host/coordinator-common.d.ts +49 -0
- package/pd-cli/dist/services/service-host/coordinator-common.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/coordinator-common.js +158 -0
- package/pd-cli/dist/services/service-host/coordinator-common.js.map +1 -0
- package/pd-cli/dist/services/service-host/handover-claims.d.ts +14 -0
- package/pd-cli/dist/services/service-host/handover-claims.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/handover-claims.js +50 -0
- package/pd-cli/dist/services/service-host/handover-claims.js.map +1 -0
- package/pd-cli/dist/services/service-host/index.d.ts +19 -3
- package/pd-cli/dist/services/service-host/index.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/index.js +21 -3
- package/pd-cli/dist/services/service-host/index.js.map +1 -1
- package/pd-cli/dist/services/service-host/install-identity.d.ts +23 -3
- package/pd-cli/dist/services/service-host/install-identity.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/install-identity.js +15 -5
- package/pd-cli/dist/services/service-host/install-identity.js.map +1 -1
- package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts +130 -9
- package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/locking/service-run-lock.js +99 -19
- package/pd-cli/dist/services/service-host/locking/service-run-lock.js.map +1 -1
- package/pd-cli/dist/services/service-host/managed-run.d.ts +75 -0
- package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/managed-run.js +550 -0
- package/pd-cli/dist/services/service-host/managed-run.js.map +1 -0
- package/pd-cli/dist/services/service-host/progress-evidence.d.ts +38 -0
- package/pd-cli/dist/services/service-host/progress-evidence.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/progress-evidence.js +155 -0
- package/pd-cli/dist/services/service-host/progress-evidence.js.map +1 -0
- package/pd-cli/dist/services/service-host/run-once.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/run-once.js +4 -136
- package/pd-cli/dist/services/service-host/run-once.js.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/contract.d.ts +184 -0
- package/pd-cli/dist/services/service-host/scheduler/contract.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/contract.js +86 -0
- package/pd-cli/dist/services/service-host/scheduler/contract.js.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/index.d.ts +76 -0
- package/pd-cli/dist/services/service-host/scheduler/index.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/index.js +128 -0
- package/pd-cli/dist/services/service-host/scheduler/index.js.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/linux.d.ts +27 -0
- package/pd-cli/dist/services/service-host/scheduler/linux.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/linux.js +1010 -0
- package/pd-cli/dist/services/service-host/scheduler/linux.js.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/macos.d.ts +13 -0
- package/pd-cli/dist/services/service-host/scheduler/macos.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/macos.js +819 -0
- package/pd-cli/dist/services/service-host/scheduler/macos.js.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts +13 -0
- package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/runtime-io.js +141 -0
- package/pd-cli/dist/services/service-host/scheduler/runtime-io.js.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +99 -0
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/service-status.js +202 -0
- package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/windows.d.ts +40 -0
- package/pd-cli/dist/services/service-host/scheduler/windows.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/scheduler/windows.js +688 -0
- package/pd-cli/dist/services/service-host/scheduler/windows.js.map +1 -0
- package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts +43 -0
- package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/shadow-progress-store.js +156 -0
- package/pd-cli/dist/services/service-host/shadow-progress-store.js.map +1 -0
- package/pd-cli/dist/services/service-host/shadow-run.d.ts +87 -0
- package/pd-cli/dist/services/service-host/shadow-run.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/shadow-run.js +549 -0
- package/pd-cli/dist/services/service-host/shadow-run.js.map +1 -0
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +114 -4
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.js +37 -0
- package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
- package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts +2 -0
- package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/worker-adapter-codex.js +76 -0
- package/pd-cli/dist/services/service-host/worker-adapter-codex.js.map +1 -0
- package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts +2 -0
- package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js +49 -0
- package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js.map +1 -0
- package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts +2 -0
- package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js +36 -0
- package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js.map +1 -0
- package/pd-cli/dist/services/service-host/worker-adapter.d.ts +187 -0
- package/pd-cli/dist/services/service-host/worker-adapter.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/worker-adapter.js +609 -0
- package/pd-cli/dist/services/service-host/worker-adapter.js.map +1 -0
- package/pd-cli/dist/services/service-host/worker-env.d.ts +84 -0
- package/pd-cli/dist/services/service-host/worker-env.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/worker-env.js +195 -0
- package/pd-cli/dist/services/service-host/worker-env.js.map +1 -0
- package/pd-cli/dist/services/service-host/worker-process.d.ts +75 -0
- package/pd-cli/dist/services/service-host/worker-process.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/worker-process.js +225 -0
- package/pd-cli/dist/services/service-host/worker-process.js.map +1 -0
- package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts +61 -0
- package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/workspace-dispatch.js +105 -0
- package/pd-cli/dist/services/service-host/workspace-dispatch.js.map +1 -0
- package/pd-cli/dist/services/service-host/workspace-handover.d.ts +190 -0
- package/pd-cli/dist/services/service-host/workspace-handover.d.ts.map +1 -0
- package/pd-cli/dist/services/service-host/workspace-handover.js +1393 -0
- package/pd-cli/dist/services/service-host/workspace-handover.js.map +1 -0
- package/pd-cli/package.json +6 -5
- package/pd-mcp-server/dist/submit-assembly.js +159 -42
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +662 -637
- package/plugin/dist/openclaw-worker.d.ts +92 -0
- package/plugin/dist/openclaw-worker.js +2446 -0
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/service/gateway-consumer-lease.d.ts +142 -0
- package/plugin/dist/service/gateway-quiesce-ack.d.ts +40 -0
- package/plugin/dist/service/internalization-auto-consumer-service.d.ts +68 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +5 -1
- package/release-manager/dist/installer.js +77 -30
- package/release-manager/dist/installers/mcp-registration-conflict.js +34 -1
- package/release-manager/dist/installers/workbuddy-host-installer.js +284 -21
- package/release-manager/dist/service-host-bridge.js +292 -0
- package/release-manager/dist/update/install-layout.js +42 -15
- package/release-manager/package.json +5 -4
- package/workbuddy-adapter/dist/index.d.ts +1 -1
- package/workbuddy-adapter/dist/index.js +1 -1
- package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +7 -0
- package/workbuddy-adapter/dist/worker/workspace-worker.js +179 -10
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/.codebuddy-plugin/plugin.json +2 -2
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* macOS scheduler adapter — current-user LaunchAgent (SPEC §10.2, task §3.3).
|
|
3
|
+
*
|
|
4
|
+
* Registration: `~/Library/LaunchAgents/com.principles-disciple.service-host.<key>.plist`
|
|
5
|
+
* with RunAtLoad + StartInterval. Managed with `launchctl bootstrap/bootout/
|
|
6
|
+
* enable/disable` against the caller's own `gui/<uid>` domain — never a
|
|
7
|
+
* LaunchDaemon, never root (task §3.3).
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle contract (task §3 review):
|
|
10
|
+
* - install writes the plist + the log directory ONLY (no bootstrap, no
|
|
11
|
+
* Worker) and persistently DISABLES the label — a LaunchAgent left
|
|
12
|
+
* enabled would auto-load with RunAtLoad at the next login, which would
|
|
13
|
+
* break the installed_disabled contract;
|
|
14
|
+
* - enable verifies ownership, `launchctl enable`, then `bootstrap` when
|
|
15
|
+
* not loaded, and verifies the job is loaded before reporting enabled;
|
|
16
|
+
* - disable `launchctl disable` (persistent) + `bootout`, and verifies
|
|
17
|
+
* the job is actually unloaded — never reports stopped without proof;
|
|
18
|
+
* - status reads each witness independently (plist existence/ownership,
|
|
19
|
+
* launchd loaded state, launchd disabled flag); an unreadable witness
|
|
20
|
+
* yields unknown, never a guessed false;
|
|
21
|
+
* - uninstall verifies ownership, stops+unloads, then removes ONLY our
|
|
22
|
+
* own plist — an external same-label LaunchAgent is never deleted.
|
|
23
|
+
*
|
|
24
|
+
* Honest platform semantics (SPEC §10.2 audit): a LaunchAgent exists only
|
|
25
|
+
* inside an interactive login session — no pre-login trigger, no trigger
|
|
26
|
+
* after logout. This adapter never claims otherwise.
|
|
27
|
+
*
|
|
28
|
+
* IMPORTANT (task §9.F): this implementation is unit-tested against a faked
|
|
29
|
+
* command boundary; real-platform acceptance on macOS is recorded as
|
|
30
|
+
* NOT_VERIFIED until it runs on a real Darwin host.
|
|
31
|
+
*/
|
|
32
|
+
import * as path from 'node:path';
|
|
33
|
+
import plistLib from 'plist';
|
|
34
|
+
import { schedulerInvocationArgs } from './contract.js';
|
|
35
|
+
function escapeXml(value) {
|
|
36
|
+
return value.replace(/[&<>"']/g, (c) => {
|
|
37
|
+
switch (c) {
|
|
38
|
+
case '&': return '&';
|
|
39
|
+
case '<': return '<';
|
|
40
|
+
case '>': return '>';
|
|
41
|
+
case '"': return '"';
|
|
42
|
+
default: return ''';
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** The LaunchAgent plist document. Exported for unit tests. */
|
|
47
|
+
export function buildMacosLaunchAgentPlist(registration) {
|
|
48
|
+
const programArguments = [
|
|
49
|
+
registration.nodePath,
|
|
50
|
+
...schedulerInvocationArgs(registration),
|
|
51
|
+
].map((part) => ` <string>${escapeXml(part)}</string>`);
|
|
52
|
+
return [
|
|
53
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
54
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
55
|
+
'<plist version="1.0">',
|
|
56
|
+
'<dict>',
|
|
57
|
+
` <key>Label</key>`,
|
|
58
|
+
` <string>${escapeXml(registration.identity.macosLabel)}</string>`,
|
|
59
|
+
' <key>ProgramArguments</key>',
|
|
60
|
+
' <array>',
|
|
61
|
+
...programArguments,
|
|
62
|
+
' </array>',
|
|
63
|
+
' <key>RunAtLoad</key>',
|
|
64
|
+
' <true/>',
|
|
65
|
+
' <key>StartInterval</key>',
|
|
66
|
+
` <integer>${Math.round(registration.intervalMs / 1000)}</integer>`,
|
|
67
|
+
' <key>WorkingDirectory</key>',
|
|
68
|
+
` <string>${escapeXml(registration.pdHome)}</string>`,
|
|
69
|
+
' <key>StandardOutPath</key>',
|
|
70
|
+
` <string>${escapeXml(path.join(registration.pdHome, 'service', 'scheduler-stdout.log'))}</string>`,
|
|
71
|
+
' <key>StandardErrorPath</key>',
|
|
72
|
+
` <string>${escapeXml(path.join(registration.pdHome, 'service', 'scheduler-stderr.log'))}</string>`,
|
|
73
|
+
'</dict>',
|
|
74
|
+
'</plist>',
|
|
75
|
+
'',
|
|
76
|
+
].join('\n');
|
|
77
|
+
}
|
|
78
|
+
/** Parse `<key>StartInterval</key><integer>N</integer>` (seconds) from the plist. */
|
|
79
|
+
export function parseMacosStartIntervalMs(plist) {
|
|
80
|
+
const match = /<key>StartInterval<\/key>\s*<integer>(\d+)<\/integer>/i.exec(plist);
|
|
81
|
+
if (match === null)
|
|
82
|
+
return null;
|
|
83
|
+
const seconds = Number(match[1] ?? 0);
|
|
84
|
+
return seconds > 0 ? seconds * 1000 : null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The complete set of keys a PD-built LaunchAgent may declare (see
|
|
88
|
+
* buildMacosLaunchAgentPlist). Any additional top-level key — an extra
|
|
89
|
+
* trigger like StartCalendarInterval, environment overrides, or an
|
|
90
|
+
* unexpected action — makes the plist FOREIGN: PD never claims a document
|
|
91
|
+
* that does more than the builder can emit.
|
|
92
|
+
*/
|
|
93
|
+
const LAUNCH_AGENT_KEYS = new Set([
|
|
94
|
+
'Label',
|
|
95
|
+
'ProgramArguments',
|
|
96
|
+
'WorkingDirectory',
|
|
97
|
+
'RunAtLoad',
|
|
98
|
+
'StartInterval',
|
|
99
|
+
'StandardOutPath',
|
|
100
|
+
'StandardErrorPath',
|
|
101
|
+
]);
|
|
102
|
+
function escapeRegExp(value) {
|
|
103
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Structural LaunchAgent plist reader: parses the real plist document with
|
|
107
|
+
* the project-locked `plist` library, then verifies the result against the
|
|
108
|
+
* builder's key/type contract. A plist fails the parse (ok=false) when it
|
|
109
|
+
* is unparseable, has a non-dict root, declares an unknown top-level key,
|
|
110
|
+
* duplicates any of the required keys anywhere in the raw text (covers
|
|
111
|
+
* comment-forgery — the XML parser drops comments but the raw count
|
|
112
|
+
* still exposes the duplicate), or carries fields of the wrong type. A
|
|
113
|
+
* plist that fails the parse can never equal our registration, so it is
|
|
114
|
+
* FOREIGN.
|
|
115
|
+
*/
|
|
116
|
+
function parseLaunchAgent(plistText) {
|
|
117
|
+
let root;
|
|
118
|
+
try {
|
|
119
|
+
root = plistLib.parse(plistText);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return { ok: false };
|
|
123
|
+
}
|
|
124
|
+
if (typeof root !== 'object' || root === null || Array.isArray(root)) {
|
|
125
|
+
return { ok: false };
|
|
126
|
+
}
|
|
127
|
+
const dict = root;
|
|
128
|
+
for (const key of Object.keys(dict)) {
|
|
129
|
+
if (!LAUNCH_AGENT_KEYS.has(key))
|
|
130
|
+
return { ok: false };
|
|
131
|
+
// Duplicate-key guard: the parsed value keeps only one instance, so
|
|
132
|
+
// count raw `<key>NAME</key>` occurrences — a comment- or nesting-forged
|
|
133
|
+
// duplicate still shows up in the raw text.
|
|
134
|
+
const occurrences = plistText.match(new RegExp(`<key>${escapeRegExp(key)}</key>`, 'g'));
|
|
135
|
+
if ((occurrences?.length ?? 0) > 1)
|
|
136
|
+
return { ok: false };
|
|
137
|
+
}
|
|
138
|
+
const label = dict.Label;
|
|
139
|
+
const programArguments = dict.ProgramArguments;
|
|
140
|
+
const workingDirectory = dict.WorkingDirectory;
|
|
141
|
+
return {
|
|
142
|
+
ok: true,
|
|
143
|
+
parsed: {
|
|
144
|
+
label: typeof label === 'string' ? label : null,
|
|
145
|
+
programArguments: Array.isArray(programArguments) && programArguments.every((a) => typeof a === 'string')
|
|
146
|
+
? (programArguments)
|
|
147
|
+
: null,
|
|
148
|
+
workingDirectory: typeof workingDirectory === 'string' ? workingDirectory : null,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** launchctl print stderr/stdout patterns that definitively mean "not loaded". */
|
|
153
|
+
const LAUNCHCTL_NOT_LOADED = /could not find|no such|not loaded|can't find|cannot find|does not exist/i;
|
|
154
|
+
/** launchctl bootout stderr patterns that definitively mean "nothing to unload". */
|
|
155
|
+
const LAUNCHCTL_NOT_LOADED_BOOTOUT = /no such process|not loaded|No process existing with specified identity/i;
|
|
156
|
+
export function createMacosSchedulerAdapter(deps) {
|
|
157
|
+
const { runner, fileIo } = deps;
|
|
158
|
+
const getUid = deps.getUid ?? (() => (typeof process.getuid === 'function' ? process.getuid() : undefined));
|
|
159
|
+
function guiDomain() {
|
|
160
|
+
const uid = getUid();
|
|
161
|
+
if (uid === undefined) {
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
reason: 'macos_uid_unavailable',
|
|
165
|
+
nextAction: 'The LaunchAgent domain needs the current user uid (process.getuid); it is unavailable in this process context.',
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return { ok: true, domain: `gui/${uid}`, uid };
|
|
169
|
+
}
|
|
170
|
+
function plistPath(registration, homeDir) {
|
|
171
|
+
return path.join(homeDir, 'Library', 'LaunchAgents', `${registration.identity.macosLabel}.plist`);
|
|
172
|
+
}
|
|
173
|
+
/** homeDir derived from the trusted pdHome (…/<home>/.pd → <home>). */
|
|
174
|
+
function homeDirFor(registration) {
|
|
175
|
+
return path.dirname(registration.pdHome);
|
|
176
|
+
}
|
|
177
|
+
function logDirFor(registration) {
|
|
178
|
+
return path.join(registration.pdHome, 'service');
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Ownership verdict from the PARSED plist (task §5 review): Label must be
|
|
182
|
+
* exactly our label, ProgramArguments must be exactly [nodePath, ...
|
|
183
|
+
* schedulerInvocationArgs()] and WorkingDirectory exactly our pdHome.
|
|
184
|
+
* Anything that fails to parse, or merely contains our strings inside a
|
|
185
|
+
* different job definition, is foreign — never overwritten or deleted.
|
|
186
|
+
*/
|
|
187
|
+
function ownershipVerdict(registration, plist) {
|
|
188
|
+
const result = parseLaunchAgent(plist);
|
|
189
|
+
if (!result.ok)
|
|
190
|
+
return { ours: false };
|
|
191
|
+
const { parsed } = result;
|
|
192
|
+
if (parsed.label !== registration.identity.macosLabel)
|
|
193
|
+
return { ours: false };
|
|
194
|
+
if (parsed.workingDirectory !== registration.pdHome)
|
|
195
|
+
return { ours: false };
|
|
196
|
+
const expected = [registration.nodePath, ...schedulerInvocationArgs(registration)];
|
|
197
|
+
if (parsed.programArguments === null || parsed.programArguments.length !== expected.length) {
|
|
198
|
+
return { ours: false };
|
|
199
|
+
}
|
|
200
|
+
return parsed.programArguments.every((token, index) => token === expected[index])
|
|
201
|
+
? { ours: true }
|
|
202
|
+
: { ours: false };
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Strict launchctl print-disabled reader. Current macOS emits
|
|
206
|
+
* quoted labels followed by => disabled|enabled; older releases emit
|
|
207
|
+
* boolean true|false (with : or =). The command lists only overrides,
|
|
208
|
+
* so an absent target label means not disabled. Malformed structure,
|
|
209
|
+
* duplicate target labels, or unknown values are UNKNOWN.
|
|
210
|
+
*/
|
|
211
|
+
function parseDisabledFlag(stdout, label) {
|
|
212
|
+
const lines = stdout.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== '');
|
|
213
|
+
if (lines.length < 2 || !/^disabled\s+services\s*=\s*\{$/i.test(lines[0] ?? ''))
|
|
214
|
+
return { ok: false };
|
|
215
|
+
let closed = false;
|
|
216
|
+
let targetCount = 0;
|
|
217
|
+
let disabled = false;
|
|
218
|
+
for (const line of lines.slice(1)) {
|
|
219
|
+
if (line === '}') {
|
|
220
|
+
if (closed)
|
|
221
|
+
return { ok: false };
|
|
222
|
+
closed = true;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (closed)
|
|
226
|
+
return { ok: false };
|
|
227
|
+
const entry = /^"([^"]+)"\s*(?:=>|:|=)\s*(disabled|enabled|true|false|1|0)$/i.exec(line);
|
|
228
|
+
if (entry === null)
|
|
229
|
+
return { ok: false };
|
|
230
|
+
if (entry[1] !== label)
|
|
231
|
+
continue;
|
|
232
|
+
targetCount += 1;
|
|
233
|
+
if (targetCount > 1)
|
|
234
|
+
return { ok: false };
|
|
235
|
+
const value = (entry[2] ?? '').toLowerCase();
|
|
236
|
+
disabled = value === 'disabled' || value === 'true' || value === '1';
|
|
237
|
+
}
|
|
238
|
+
if (!closed)
|
|
239
|
+
return { ok: false };
|
|
240
|
+
return { ok: true, disabled: targetCount === 0 ? false : disabled };
|
|
241
|
+
}
|
|
242
|
+
async function run(command, args) {
|
|
243
|
+
return runner.run(command, args);
|
|
244
|
+
}
|
|
245
|
+
/** Loaded + disabled state from launchctl print / print-disabled. */
|
|
246
|
+
async function loadState(label) {
|
|
247
|
+
const domain = guiDomain();
|
|
248
|
+
if (!domain.ok) {
|
|
249
|
+
return { loaded: false, loadedKnown: false, disabledKnown: false, disabled: null, lastResult: null, unreadableReasons: [domain.reason] };
|
|
250
|
+
}
|
|
251
|
+
const reasons = [];
|
|
252
|
+
const print = await run('launchctl', ['print', `${domain.domain}/${label}`]);
|
|
253
|
+
const loaded = print.code === 0;
|
|
254
|
+
// A failed print is only proof of "not loaded" when launchd says so;
|
|
255
|
+
// any other failure (spawn, permission, timeout) leaves the loaded
|
|
256
|
+
// state UNKNOWN — an unknown state must not drive bootout/delete.
|
|
257
|
+
const notFound = LAUNCHCTL_NOT_LOADED.test(`${print.stderr}\n${print.stdout}`);
|
|
258
|
+
const loadedKnown = loaded || notFound;
|
|
259
|
+
if (!loaded && !notFound) {
|
|
260
|
+
reasons.push(`launchctl_print_failed:${print.code ?? 'spawn'}:${(print.spawnError ?? print.stderr.trim() ?? print.stdout.trim()).slice(0, 100)}`);
|
|
261
|
+
}
|
|
262
|
+
let lastResult = null;
|
|
263
|
+
if (loaded) {
|
|
264
|
+
const match = /last exit code\s*=\s*(\d+)/.exec(print.stdout);
|
|
265
|
+
lastResult = match !== null ? match[1] ?? null : null;
|
|
266
|
+
}
|
|
267
|
+
const disabledList = await run('launchctl', ['print-disabled', domain.domain]);
|
|
268
|
+
let disabled = null;
|
|
269
|
+
if (disabledList.code === 0) {
|
|
270
|
+
const probe = parseDisabledFlag(disabledList.stdout, label);
|
|
271
|
+
const flag = probe.ok ? probe.disabled : null;
|
|
272
|
+
if (flag !== null) {
|
|
273
|
+
disabled = flag;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
reasons.push('launchctl_print_disabled_unparseable');
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
reasons.push(`launchctl_print_disabled_failed:${disabledList.code ?? 'spawn'}:${(disabledList.spawnError ?? disabledList.stderr).trim().slice(0, 100)}`);
|
|
281
|
+
}
|
|
282
|
+
return { loaded, loadedKnown, disabledKnown: disabled !== null, disabled, lastResult, unreadableReasons: reasons };
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* launchctl print tri-state: 'loaded' only on exit 0; 'not_loaded' only
|
|
286
|
+
* on launchd's definitive not-found answer; anything else is 'unknown'
|
|
287
|
+
* and must fail closed — never treated as unloaded.
|
|
288
|
+
*/
|
|
289
|
+
async function probeLoaded(label) {
|
|
290
|
+
const domain = guiDomain();
|
|
291
|
+
if (!domain.ok)
|
|
292
|
+
return { state: 'unknown', reason: domain.reason };
|
|
293
|
+
const print = await run('launchctl', ['print', `${domain.domain}/${label}`]);
|
|
294
|
+
if (print.code === 0)
|
|
295
|
+
return { state: 'loaded' };
|
|
296
|
+
if (LAUNCHCTL_NOT_LOADED.test(`${print.stderr}\n${print.stdout}`))
|
|
297
|
+
return { state: 'not_loaded' };
|
|
298
|
+
return {
|
|
299
|
+
state: 'unknown',
|
|
300
|
+
reason: `launchctl_print_failed:${print.code ?? 'spawn'}:${(print.spawnError ?? print.stderr.trim() ?? print.stdout.trim()).slice(0, 100)}`,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** launchctl print confirms the job is loaded. */
|
|
304
|
+
async function verifyLoaded(label) {
|
|
305
|
+
return (await probeLoaded(label)).state === 'loaded';
|
|
306
|
+
}
|
|
307
|
+
function baseFacts(registration, fields) {
|
|
308
|
+
return {
|
|
309
|
+
platform: 'darwin',
|
|
310
|
+
taskName: registration.identity.macosLabel,
|
|
311
|
+
registered: null,
|
|
312
|
+
enabled: null,
|
|
313
|
+
active: null,
|
|
314
|
+
lastRunAt: null,
|
|
315
|
+
lastResult: null,
|
|
316
|
+
...fields,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function commandFailed(reason, nextAction) {
|
|
320
|
+
return { ok: false, kind: 'command_failed', reason, nextAction };
|
|
321
|
+
}
|
|
322
|
+
async function status(registration) {
|
|
323
|
+
const plistFile = plistPath(registration, homeDirFor(registration));
|
|
324
|
+
const existing = fileIo.readIfExists(plistFile);
|
|
325
|
+
if (!existing.ok) {
|
|
326
|
+
if (existing.reason === 'missing') {
|
|
327
|
+
return {
|
|
328
|
+
ok: true,
|
|
329
|
+
changed: false,
|
|
330
|
+
facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
ok: false,
|
|
335
|
+
kind: 'command_failed',
|
|
336
|
+
reason: `launchagent_plist_unreadable:${existing.detail ?? existing.reason}`,
|
|
337
|
+
nextAction: `The plist at ${plistFile} exists but cannot be read; fix its permissions. PD does not treat an unreadable registration as "not installed".`,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
// Ownership is a status witness too (task §5): a foreign same-label
|
|
341
|
+
// LaunchAgent is NOT our registration.
|
|
342
|
+
if (!ownershipVerdict(registration, existing.content).ours) {
|
|
343
|
+
return {
|
|
344
|
+
ok: false,
|
|
345
|
+
kind: 'external_conflict',
|
|
346
|
+
reason: 'launchagent_conflict_foreign_plist',
|
|
347
|
+
nextAction: `${plistFile} exists but its Label/ProgramArguments/WorkingDirectory do not match this PD install (${registration.pdHome}); PD does not report a foreign LaunchAgent as its own — inspect it manually.`,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
const state = await loadState(registration.identity.macosLabel);
|
|
351
|
+
// enabled (will fire) = the launchd disabled flag is clear; unreadable
|
|
352
|
+
// flag = null, never folded into loaded/unloaded or guessed (task §9).
|
|
353
|
+
const enabled = state.disabled === null ? null : !state.disabled;
|
|
354
|
+
const active = state.loadedKnown ? state.loaded : null;
|
|
355
|
+
return {
|
|
356
|
+
ok: true,
|
|
357
|
+
changed: false,
|
|
358
|
+
facts: baseFacts(registration, {
|
|
359
|
+
registered: true,
|
|
360
|
+
enabled,
|
|
361
|
+
active,
|
|
362
|
+
triggerIntervalMs: parseMacosStartIntervalMs(existing.content),
|
|
363
|
+
lastResult: state.lastResult,
|
|
364
|
+
...(state.unreadableReasons.length > 0 ? { degradedReasons: state.unreadableReasons } : {}),
|
|
365
|
+
}),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/** Create + verify the scheduler log directory (`<pdHome>/service`). */
|
|
369
|
+
function ensureLogDir(registration) {
|
|
370
|
+
const dir = logDirFor(registration);
|
|
371
|
+
const made = fileIo.mkdirs(dir);
|
|
372
|
+
if (!made.ok) {
|
|
373
|
+
return {
|
|
374
|
+
ok: false,
|
|
375
|
+
result: {
|
|
376
|
+
ok: false,
|
|
377
|
+
kind: 'command_failed',
|
|
378
|
+
reason: `launchagent_log_dir_unwritable:${made.reason.slice(0, 80)}`,
|
|
379
|
+
nextAction: `The stdout/stderr log directory ${dir} could not be created; the first triggered run would fail on missing logs. Fix permissions and retry.`,
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return { ok: true };
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
platform: 'darwin',
|
|
387
|
+
async install(registration) {
|
|
388
|
+
const domain = guiDomain();
|
|
389
|
+
if (!domain.ok) {
|
|
390
|
+
return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
|
|
391
|
+
}
|
|
392
|
+
const homeDir = homeDirFor(registration);
|
|
393
|
+
const plistFile = plistPath(registration, homeDir);
|
|
394
|
+
const agentsDir = path.dirname(plistFile);
|
|
395
|
+
const existing = fileIo.readIfExists(plistFile);
|
|
396
|
+
let refreshOnly = false;
|
|
397
|
+
if (existing.ok) {
|
|
398
|
+
const ownership = ownershipVerdict(registration, existing.content);
|
|
399
|
+
if (!ownership.ours) {
|
|
400
|
+
return {
|
|
401
|
+
ok: false,
|
|
402
|
+
kind: 'external_conflict',
|
|
403
|
+
reason: 'launchagent_conflict_foreign_plist',
|
|
404
|
+
nextAction: `${plistFile} already exists but is not this PD install's LaunchAgent (Label/ProgramArguments/WorkingDirectory mismatch). PD never overwrites a foreign LaunchAgent — inspect it manually.`,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
refreshOnly = true;
|
|
408
|
+
}
|
|
409
|
+
else if (existing.reason === 'unreadable') {
|
|
410
|
+
return {
|
|
411
|
+
ok: false,
|
|
412
|
+
kind: 'command_failed',
|
|
413
|
+
reason: `launchagent_plist_unreadable:${existing.detail ?? existing.reason}`,
|
|
414
|
+
nextAction: `${plistFile} exists but cannot be read; PD refuses to overwrite an unreadable registration — fix its permissions first.`,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
// install never bootstraps and never starts a Worker (task §3): the
|
|
418
|
+
// log directory is created up-front so the first ENABLED trigger can
|
|
419
|
+
// write stdout/stderr (task §6 review).
|
|
420
|
+
const logDir = ensureLogDir(registration);
|
|
421
|
+
if (!logDir.ok)
|
|
422
|
+
return logDir.result;
|
|
423
|
+
// Refresh semantics (task §15): an existing OWN registration keeps its
|
|
424
|
+
// interval — only the node/CLI entry and args move forward.
|
|
425
|
+
const preservedInterval = refreshOnly && registration.intervalExplicit !== true
|
|
426
|
+
? (existing.ok ? parseMacosStartIntervalMs(existing.content) : null)
|
|
427
|
+
: null;
|
|
428
|
+
const effective = preservedInterval !== null
|
|
429
|
+
? { ...registration, intervalMs: preservedInterval }
|
|
430
|
+
: registration;
|
|
431
|
+
const label = registration.identity.macosLabel;
|
|
432
|
+
// Read launchd state BEFORE replacing the plist (review §4 matrix):
|
|
433
|
+
// a refresh whose enabled flag is UNREADABLE must refuse before any
|
|
434
|
+
// mutation — a blind swap could leave a still-enabled job firing a
|
|
435
|
+
// stale definition.
|
|
436
|
+
const state = await loadState(label);
|
|
437
|
+
if (refreshOnly && state.disabled === null) {
|
|
438
|
+
return {
|
|
439
|
+
ok: false,
|
|
440
|
+
kind: 'command_failed',
|
|
441
|
+
reason: `launchagent_disabled_state_unverified:${(state.unreadableReasons[0] ?? 'print_disabled_unreadable').slice(0, 100)}`,
|
|
442
|
+
nextAction: `print-disabled could not prove the enabled flag of the existing registration; ${plistFile} was NOT replaced. Fix the launchctl error above and retry pd service install.`,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
const wasEnabled = refreshOnly && state.disabled === false;
|
|
446
|
+
const priorContent = existing.ok ? existing.content : null;
|
|
447
|
+
const mkdir = fileIo.mkdirs(agentsDir);
|
|
448
|
+
if (!mkdir.ok) {
|
|
449
|
+
return { ok: false, kind: 'command_failed', reason: `launchagents_dir_unwritable:${mkdir.reason.slice(0, 80)}`, nextAction: `Could not create ${agentsDir}; check permissions and retry pd service install.` };
|
|
450
|
+
}
|
|
451
|
+
const written = fileIo.writeAtomic(plistFile, buildMacosLaunchAgentPlist(effective));
|
|
452
|
+
if (!written.ok) {
|
|
453
|
+
return { ok: false, kind: 'command_failed', reason: `launchagent_write_failed:${written.reason.slice(0, 80)}`, nextAction: `Could not write ${plistFile}; retry pd service install after fixing the filesystem issue.` };
|
|
454
|
+
}
|
|
455
|
+
/** Roll the plist back: fresh install removes the file it created; a
|
|
456
|
+
* refresh restores the pre-call content. The primary error stays —
|
|
457
|
+
* a rollback failure is appended, never hidden. */
|
|
458
|
+
const rollbackPlist = (reason) => {
|
|
459
|
+
if (priorContent === null) {
|
|
460
|
+
const removed = fileIo.remove(plistFile);
|
|
461
|
+
return removed.ok ? reason : `${reason}+rollback_remove_failed:${removed.reason.slice(0, 60)}`;
|
|
462
|
+
}
|
|
463
|
+
const restored = fileIo.writeAtomic(plistFile, priorContent);
|
|
464
|
+
return restored.ok ? reason : `${reason}+rollback_restore_failed:${restored.reason.slice(0, 60)}`;
|
|
465
|
+
};
|
|
466
|
+
let pinnedDisabled = false;
|
|
467
|
+
if (wasEnabled) {
|
|
468
|
+
// When the loaded state is UNKNOWN a possibly-loaded job must still
|
|
469
|
+
// be reloaded — bootout tolerates a definitive not-loaded answer.
|
|
470
|
+
if (!state.loadedKnown || state.loaded) {
|
|
471
|
+
const bootout = await run('launchctl', ['bootout', `${domain.domain}/${label}`]);
|
|
472
|
+
if (bootout.code !== 0) {
|
|
473
|
+
const stderr = bootout.stderr.trim();
|
|
474
|
+
const notLoaded = bootout.spawnError === undefined && LAUNCHCTL_NOT_LOADED_BOOTOUT.test(stderr);
|
|
475
|
+
if (!notLoaded) {
|
|
476
|
+
return {
|
|
477
|
+
ok: false,
|
|
478
|
+
kind: 'command_failed',
|
|
479
|
+
reason: rollbackPlist(`launchctl_bootout_failed:${bootout.code ?? 'spawn'}:${(bootout.spawnError ?? stderr).slice(0, 120)}`),
|
|
480
|
+
nextAction: 'The refreshed plist could not replace the loaded job (bootout failed); the previous plist was restored and its definition stays active. Inspect the stderr above and retry.',
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
// Reload the definition while the enabled flag stays enabled: also
|
|
486
|
+
// covers enabled+unloaded — a confirmed-unloaded job is bootstrapped
|
|
487
|
+
// straight back (bootout is skipped, nothing to unload).
|
|
488
|
+
const bootstrap = await run('launchctl', ['bootstrap', domain.domain, plistFile]);
|
|
489
|
+
if (bootstrap.code !== 0 || !(await verifyLoaded(label))) {
|
|
490
|
+
return {
|
|
491
|
+
ok: false,
|
|
492
|
+
kind: 'command_failed',
|
|
493
|
+
reason: rollbackPlist(bootstrap.code === 0 ? 'launchagent_reload_unverified' : `launchctl_bootstrap_failed:${bootstrap.code ?? 'spawn'}:${(bootstrap.spawnError ?? bootstrap.stderr).trim().slice(0, 120)}`),
|
|
494
|
+
nextAction: 'The refreshed plist could not be reloaded; the previous plist was restored but the job may now be unloaded — run pd service status, then retry (a retry re-bootstraps safely).',
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
else if (state.disabled !== true) {
|
|
499
|
+
// installed_disabled (task §3): a never-disabled LaunchAgent
|
|
500
|
+
// auto-loads at the next login and RunAtLoad would fire it — so
|
|
501
|
+
// install explicitly pins the persistent disabled flag.
|
|
502
|
+
const disable = await run('launchctl', ['disable', `${domain.domain}/${label}`]);
|
|
503
|
+
if (disable.code !== 0) {
|
|
504
|
+
return {
|
|
505
|
+
ok: false,
|
|
506
|
+
kind: 'command_failed',
|
|
507
|
+
reason: rollbackPlist(`launchctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? disable.stderr).trim().slice(0, 120)}`),
|
|
508
|
+
nextAction: `The plist was written but the persistent disable could not be verified — the install was rolled back, leaving the label enabled would fire it at the next login (RunAtLoad). Inspect the stderr above and re-run pd service install.`,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
pinnedDisabled = true;
|
|
512
|
+
}
|
|
513
|
+
if (!refreshOnly) {
|
|
514
|
+
// First install is transactional: the disabled pin must be PROVABLE.
|
|
515
|
+
// On any doubt, remove the plist this call created and restore the
|
|
516
|
+
// disable override to its pre-install value (pinned -> enable).
|
|
517
|
+
const verify = await loadState(label);
|
|
518
|
+
if (verify.disabled !== true) {
|
|
519
|
+
let reason = rollbackPlist(`launchagent_disable_unverified:${(verify.unreadableReasons[0] ?? 'flag_not_set').slice(0, 80)}`);
|
|
520
|
+
if (pinnedDisabled) {
|
|
521
|
+
const enable = await run('launchctl', ['enable', `${domain.domain}/${label}`]);
|
|
522
|
+
if (enable.code !== 0) {
|
|
523
|
+
reason += `+rollback_enable_failed:${(enable.spawnError ?? enable.stderr).trim().slice(0, 60)}`;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
ok: false,
|
|
528
|
+
kind: 'command_failed',
|
|
529
|
+
reason,
|
|
530
|
+
nextAction: 'The plist was written but the persistent disable could not be proven; the install was rolled back — the new plist was removed and the disable override restored. Inspect launchctl print-disabled and retry pd service install.',
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
const after = await loadState(label);
|
|
535
|
+
return {
|
|
536
|
+
ok: true,
|
|
537
|
+
changed: !refreshOnly,
|
|
538
|
+
facts: baseFacts(registration, {
|
|
539
|
+
registered: true,
|
|
540
|
+
enabled: after.disabled === null ? null : !after.disabled,
|
|
541
|
+
active: after.loaded,
|
|
542
|
+
triggerIntervalMs: effective.intervalMs,
|
|
543
|
+
lastResult: after.lastResult,
|
|
544
|
+
...(after.unreadableReasons.length > 0 ? { degradedReasons: after.unreadableReasons } : {}),
|
|
545
|
+
}),
|
|
546
|
+
};
|
|
547
|
+
},
|
|
548
|
+
async enable(registration) {
|
|
549
|
+
const domain = guiDomain();
|
|
550
|
+
if (!domain.ok) {
|
|
551
|
+
return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
|
|
552
|
+
}
|
|
553
|
+
const plistFile = plistPath(registration, homeDirFor(registration));
|
|
554
|
+
const existing = fileIo.readIfExists(plistFile);
|
|
555
|
+
if (!existing.ok) {
|
|
556
|
+
if (existing.reason === 'missing') {
|
|
557
|
+
return {
|
|
558
|
+
ok: false,
|
|
559
|
+
kind: 'unsafe_state',
|
|
560
|
+
reason: 'scheduler_not_registered',
|
|
561
|
+
nextAction: `No LaunchAgent plist at ${plistFile}. Run pd service install first — enable never creates one.`,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
return commandFailed(`launchagent_plist_unreadable:${existing.detail ?? existing.reason}`, `${plistFile} exists but cannot be read; PD refuses to enable an unverifiable registration — fix its permissions first.`);
|
|
565
|
+
}
|
|
566
|
+
if (!ownershipVerdict(registration, existing.content).ours) {
|
|
567
|
+
return {
|
|
568
|
+
ok: false,
|
|
569
|
+
kind: 'external_conflict',
|
|
570
|
+
reason: 'launchagent_conflict_foreign_plist',
|
|
571
|
+
nextAction: `${plistFile} is not PD's own LaunchAgent; PD refuses to modify it.`,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
// The log dir must exist before bootstrap so the first fired run can
|
|
575
|
+
// write its stdout/stderr (task §6 review).
|
|
576
|
+
const logDir = ensureLogDir(registration);
|
|
577
|
+
if (!logDir.ok)
|
|
578
|
+
return logDir.result;
|
|
579
|
+
const label = registration.identity.macosLabel;
|
|
580
|
+
const state = await loadState(label);
|
|
581
|
+
if (state.loaded && state.disabled === false) {
|
|
582
|
+
return {
|
|
583
|
+
ok: true,
|
|
584
|
+
changed: false,
|
|
585
|
+
facts: baseFacts(registration, { registered: true, enabled: true, active: true, lastResult: state.lastResult }),
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
// enable BEFORE bootstrap (task §3): the flag must be clear so the
|
|
589
|
+
// bootstrapped job is actually armed.
|
|
590
|
+
if (state.disabled !== false) {
|
|
591
|
+
const enable = await run('launchctl', ['enable', `${domain.domain}/${label}`]);
|
|
592
|
+
if (enable.code !== 0) {
|
|
593
|
+
return {
|
|
594
|
+
ok: false,
|
|
595
|
+
kind: 'command_failed',
|
|
596
|
+
reason: `launchctl_enable_failed:${enable.code ?? 'spawn'}:${(enable.spawnError ?? enable.stderr).trim().slice(0, 120)}`,
|
|
597
|
+
nextAction: 'launchctl enable failed; the registration exists but stays disabled. Inspect the stderr above and retry.',
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (!state.loaded) {
|
|
602
|
+
const bootstrap = await run('launchctl', ['bootstrap', domain.domain, plistFile]);
|
|
603
|
+
if (bootstrap.code !== 0) {
|
|
604
|
+
return {
|
|
605
|
+
ok: false,
|
|
606
|
+
kind: 'command_failed',
|
|
607
|
+
reason: `launchctl_bootstrap_failed:${bootstrap.code ?? 'spawn'}:${(bootstrap.spawnError ?? bootstrap.stderr).trim().slice(0, 120)}`,
|
|
608
|
+
nextAction: 'bootstrap after enable failed; inspect the stderr above and retry pd service enable.',
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
// Verify before reporting success (task §3): a confirmed-loaded job
|
|
613
|
+
// AND a proven-clear disabled flag are both required — either
|
|
614
|
+
// UNKNOWN means the enable is unverified, never a success.
|
|
615
|
+
const postEnable = await loadState(label);
|
|
616
|
+
if (!postEnable.loaded || postEnable.disabled !== false) {
|
|
617
|
+
return {
|
|
618
|
+
ok: false,
|
|
619
|
+
kind: 'command_failed',
|
|
620
|
+
reason: postEnable.loaded
|
|
621
|
+
? 'launchagent_enable_flag_unverified'
|
|
622
|
+
: 'launchagent_enable_unverified',
|
|
623
|
+
nextAction: 'launchctl enable/bootstrap returned success but the job is not provably loaded+enabled in the gui domain. Run pd service status to inspect and retry.',
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
ok: true,
|
|
628
|
+
changed: true,
|
|
629
|
+
facts: baseFacts(registration, { registered: true, enabled: true, active: true }),
|
|
630
|
+
};
|
|
631
|
+
},
|
|
632
|
+
async disable(registration) {
|
|
633
|
+
const domain = guiDomain();
|
|
634
|
+
if (!domain.ok) {
|
|
635
|
+
return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
|
|
636
|
+
}
|
|
637
|
+
const label = registration.identity.macosLabel;
|
|
638
|
+
const plistFile = plistPath(registration, homeDirFor(registration));
|
|
639
|
+
const existing = fileIo.readIfExists(plistFile);
|
|
640
|
+
if (!existing.ok) {
|
|
641
|
+
if (existing.reason === 'missing') {
|
|
642
|
+
return {
|
|
643
|
+
ok: false,
|
|
644
|
+
kind: 'unsafe_state',
|
|
645
|
+
reason: 'scheduler_not_registered',
|
|
646
|
+
nextAction: `No LaunchAgent plist at ${plistFile}; nothing to disable.`,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
return commandFailed(`launchagent_plist_unreadable:${existing.detail ?? existing.reason}`, `${plistFile} exists but cannot be read; PD refuses to touch an unverifiable registration — fix its permissions first.`);
|
|
650
|
+
}
|
|
651
|
+
if (!ownershipVerdict(registration, existing.content).ours) {
|
|
652
|
+
return {
|
|
653
|
+
ok: false,
|
|
654
|
+
kind: 'external_conflict',
|
|
655
|
+
reason: 'launchagent_conflict_foreign_plist',
|
|
656
|
+
nextAction: `${plistFile} is not PD's own LaunchAgent; PD refuses to modify it.`,
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
const state = await loadState(label);
|
|
660
|
+
if (state.disabled === true && state.loadedKnown && !state.loaded) {
|
|
661
|
+
return {
|
|
662
|
+
ok: true,
|
|
663
|
+
changed: false,
|
|
664
|
+
facts: baseFacts(registration, { registered: true, enabled: false, active: false, lastResult: state.lastResult }),
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
// Persistent disable first (survives logout/login), then bootout the
|
|
668
|
+
// currently-loaded job (task §3).
|
|
669
|
+
if (state.disabled !== true) {
|
|
670
|
+
const disable = await run('launchctl', ['disable', `${domain.domain}/${label}`]);
|
|
671
|
+
if (disable.code !== 0) {
|
|
672
|
+
return {
|
|
673
|
+
ok: false,
|
|
674
|
+
kind: 'command_failed',
|
|
675
|
+
reason: `launchctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? disable.stderr).trim().slice(0, 120)}`,
|
|
676
|
+
nextAction: 'launchctl disable failed; future automatic triggers may still fire. Inspect the stderr above and retry.',
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
// A possibly-loaded job (loaded state UNKNOWN) is bootout-ed too —
|
|
681
|
+
// the command tolerates a definitive not-loaded answer, and a stale
|
|
682
|
+
// loaded job must not keep firing under the disabled flag.
|
|
683
|
+
if (state.loaded || !state.loadedKnown) {
|
|
684
|
+
const bootout = await run('launchctl', ['bootout', `${domain.domain}/${label}`]);
|
|
685
|
+
if (bootout.code !== 0) {
|
|
686
|
+
const stderr = bootout.stderr.trim();
|
|
687
|
+
if (bootout.spawnError !== undefined || !LAUNCHCTL_NOT_LOADED_BOOTOUT.test(stderr)) {
|
|
688
|
+
return {
|
|
689
|
+
ok: false,
|
|
690
|
+
kind: 'command_failed',
|
|
691
|
+
reason: `launchctl_bootout_failed:${bootout.code ?? 'spawn'}:${stderr.slice(0, 120)}`,
|
|
692
|
+
nextAction: 'bootout failed; the agent may still be loaded. Inspect the stderr above and retry.',
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
// Prove it is unloaded before reporting stopped (task §3): UNKNOWN
|
|
698
|
+
// is a distinct, never-successful verdict.
|
|
699
|
+
const probe = await probeLoaded(label);
|
|
700
|
+
if (probe.state !== 'not_loaded') {
|
|
701
|
+
return {
|
|
702
|
+
ok: false,
|
|
703
|
+
kind: 'command_failed',
|
|
704
|
+
reason: probe.state === 'unknown' ? `launchagent_disable_unverified:${(probe.reason ?? 'print_failed').slice(0, 80)}` : 'launchagent_disable_unverified',
|
|
705
|
+
nextAction: 'launchctl disable/bootout returned success but the job still reports loaded — or the loaded state could not be proven. Run pd service status to inspect and retry.',
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
const after = await loadState(label);
|
|
709
|
+
return {
|
|
710
|
+
ok: true,
|
|
711
|
+
changed: true,
|
|
712
|
+
facts: baseFacts(registration, {
|
|
713
|
+
registered: true,
|
|
714
|
+
enabled: after.disabled === null ? null : !after.disabled,
|
|
715
|
+
active: after.loaded,
|
|
716
|
+
lastResult: after.lastResult,
|
|
717
|
+
...(after.unreadableReasons.length > 0 ? { degradedReasons: after.unreadableReasons } : {}),
|
|
718
|
+
}),
|
|
719
|
+
};
|
|
720
|
+
},
|
|
721
|
+
status,
|
|
722
|
+
async uninstall(registration) {
|
|
723
|
+
const domain = guiDomain();
|
|
724
|
+
if (!domain.ok) {
|
|
725
|
+
return { ok: false, kind: 'unavailable', reason: domain.reason, nextAction: domain.nextAction };
|
|
726
|
+
}
|
|
727
|
+
const label = registration.identity.macosLabel;
|
|
728
|
+
const plistFile = plistPath(registration, homeDirFor(registration));
|
|
729
|
+
const existing = fileIo.readIfExists(plistFile);
|
|
730
|
+
if (!existing.ok) {
|
|
731
|
+
if (existing.reason === 'missing') {
|
|
732
|
+
return {
|
|
733
|
+
ok: true,
|
|
734
|
+
changed: false,
|
|
735
|
+
facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
return {
|
|
739
|
+
ok: false,
|
|
740
|
+
kind: 'command_failed',
|
|
741
|
+
reason: `launchagent_plist_unreadable:${existing.detail ?? existing.reason}`,
|
|
742
|
+
nextAction: `${plistFile} exists but cannot be read; PD never removes an unverifiable registration — fix its permissions first.`,
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
if (!ownershipVerdict(registration, existing.content).ours) {
|
|
746
|
+
return {
|
|
747
|
+
ok: false,
|
|
748
|
+
kind: 'external_conflict',
|
|
749
|
+
reason: 'launchagent_conflict_foreign_plist',
|
|
750
|
+
nextAction: `${plistFile} is not PD's own LaunchAgent; PD never deletes foreign LaunchAgents. Inspect it manually.`,
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
// Stop + unload OUR job first, verify it is gone, then remove ONLY our
|
|
754
|
+
// plist (task §3).
|
|
755
|
+
const state = await loadState(label);
|
|
756
|
+
// An UNREADABLE loaded state is not proof the job is unloaded —
|
|
757
|
+
// deleting the plist while a stale-loaded job still points at it
|
|
758
|
+
// would leave an untracked registration. Fail closed instead (the
|
|
759
|
+
// plist is NOT removed; re-run once launchctl answers).
|
|
760
|
+
if (!state.loadedKnown) {
|
|
761
|
+
return {
|
|
762
|
+
ok: false,
|
|
763
|
+
kind: 'command_failed',
|
|
764
|
+
reason: `launchagent_loaded_state_unverified:${(state.unreadableReasons[0] ?? 'launchctl_print_failed').slice(0, 120)}`,
|
|
765
|
+
nextAction: '`launchctl print` could not prove whether the job is loaded; the plist was NOT removed. Inspect the error above and re-run pd service uninstall.',
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
if (state.disabled !== true) {
|
|
769
|
+
const disable = await run('launchctl', ['disable', `${domain.domain}/${label}`]);
|
|
770
|
+
if (disable.code !== 0) {
|
|
771
|
+
return {
|
|
772
|
+
ok: false,
|
|
773
|
+
kind: 'command_failed',
|
|
774
|
+
reason: `launchctl_disable_failed:${disable.code ?? 'spawn'}:${(disable.spawnError ?? disable.stderr).trim().slice(0, 120)}`,
|
|
775
|
+
nextAction: 'launchctl disable failed; the job could re-load at the next login — the plist was NOT removed. Inspect the stderr above, then re-run pd service uninstall.',
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (state.loaded) {
|
|
780
|
+
const bootout = await run('launchctl', ['bootout', `${domain.domain}/${label}`]);
|
|
781
|
+
if (bootout.code !== 0) {
|
|
782
|
+
const stderr = bootout.stderr.trim();
|
|
783
|
+
if (bootout.spawnError !== undefined || !LAUNCHCTL_NOT_LOADED_BOOTOUT.test(stderr)) {
|
|
784
|
+
return {
|
|
785
|
+
ok: false,
|
|
786
|
+
kind: 'command_failed',
|
|
787
|
+
reason: `launchctl_bootout_failed:${bootout.code ?? 'spawn'}:${stderr.slice(0, 120)}`,
|
|
788
|
+
nextAction: 'bootout failed; the agent may still be loaded and its plist was NOT removed. Inspect the stderr above, then re-run pd service uninstall.',
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
const probe = await probeLoaded(label);
|
|
793
|
+
if (probe.state !== 'not_loaded') {
|
|
794
|
+
return {
|
|
795
|
+
ok: false,
|
|
796
|
+
kind: 'command_failed',
|
|
797
|
+
reason: probe.state === 'unknown' ? `launchagent_unload_unverified:${(probe.reason ?? 'print_failed').slice(0, 80)}` : 'launchagent_unload_unverified',
|
|
798
|
+
nextAction: 'The job still reports loaded after bootout — or the unload could not be proven; the plist was NOT removed. Inspect with pd service status and retry.',
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
const removed = fileIo.remove(plistFile);
|
|
803
|
+
if (!removed.ok) {
|
|
804
|
+
return {
|
|
805
|
+
ok: false,
|
|
806
|
+
kind: 'command_failed',
|
|
807
|
+
reason: `launchagent_remove_failed:${removed.reason.slice(0, 80)}`,
|
|
808
|
+
nextAction: `The agent was unloaded but ${plistFile} could not be removed; delete it manually after reviewing why.`,
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
return {
|
|
812
|
+
ok: true,
|
|
813
|
+
changed: true,
|
|
814
|
+
facts: baseFacts(registration, { registered: false, enabled: false, active: false }),
|
|
815
|
+
};
|
|
816
|
+
},
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
//# sourceMappingURL=macos.js.map
|