create-principles-disciple 1.152.2 → 1.152.4
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 +1 -1
- package/codex-adapter/dist/pd-hook.js +34 -4
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/config/pd-config-store.d.ts +48 -0
- package/console/dist/server/config/pd-config-store.js +273 -93
- package/console/dist/server/index.js +16 -1
- package/console/dist/server/models/ActivationsConsoleModel.d.ts +72 -1
- package/console/dist/server/models/ActivationsConsoleModel.js +92 -14
- package/console/dist/server/models/AdaptiveActivationConsoleModel.d.ts +79 -0
- package/console/dist/server/models/AdaptiveActivationConsoleModel.js +151 -0
- package/console/dist/server/models/ApprovalsConsoleModel.d.ts +28 -0
- package/console/dist/server/models/ApprovalsConsoleModel.js +118 -3
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.d.ts +38 -0
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +158 -26
- package/console/dist/server/models/IntentDecisionModel.d.ts +6 -1
- package/console/dist/server/models/IntentDecisionModel.js +17 -9
- package/console/dist/server/models/pipeline-health-metrics.d.ts +128 -0
- package/console/dist/server/models/pipeline-health-metrics.js +225 -0
- package/console/dist/server/routes/approvals.js +14 -0
- package/console/dist/server/routes/config.js +212 -1
- package/console/dist/server/routes/diagnostician.js +13 -2
- package/console/dist/server/routes/intent-decisions.js +19 -1
- package/console/dist/server/routes/pipeline-health.d.ts +9 -0
- package/console/dist/server/routes/pipeline-health.js +124 -0
- package/console/dist/web/assets/app.css +484 -67
- package/console/dist/web/assets/app.js +36 -31
- package/console/dist/web/assets/evidence-art-1.webp +0 -0
- package/console/dist/web/assets/evidence-art-2.webp +0 -0
- package/console/dist/web/assets/evidence-art-3.webp +0 -0
- package/console/dist/web/assets/evidence-art-4.webp +0 -0
- package/console/dist/web/assets/principle-grove.jpg +0 -0
- package/console/dist/web/assets/principle-stone-steps.jpg +0 -0
- package/console/dist/web/assets/principles-art-1.webp +0 -0
- package/console/dist/web/assets/principles-art-2.webp +0 -0
- package/console/dist/web/assets/principles-art-3.webp +0 -0
- package/console/dist/web/assets/principles-art-4.webp +0 -0
- package/console/dist/web/assets/today-art-1.webp +0 -0
- package/console/dist/web/assets/today-art-2.webp +0 -0
- package/console/dist/web/assets/today-art-3.webp +0 -0
- package/console/dist/web/assets/today-art-4.webp +0 -0
- package/core/dist/runtime/activation/activation-types.d.ts +6 -0
- package/core/dist/runtime/activation/activation-types.d.ts.map +1 -1
- package/core/dist/runtime/activation/activation-types.js.map +1 -1
- package/core/dist/runtime/activation/index.d.ts +2 -1
- package/core/dist/runtime/activation/index.d.ts.map +1 -1
- package/core/dist/runtime/activation/index.js +1 -1
- package/core/dist/runtime/activation/index.js.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.d.ts +8 -0
- package/core/dist/runtime/activation/ledger-identity.d.ts.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.js +20 -1
- package/core/dist/runtime/activation/ledger-identity.js.map +1 -1
- package/core/dist/runtime/activation/sqlite-approval-store.d.ts +18 -0
- package/core/dist/runtime/activation/sqlite-approval-store.d.ts.map +1 -1
- package/core/dist/runtime/activation/sqlite-approval-store.js +146 -20
- package/core/dist/runtime/activation/sqlite-approval-store.js.map +1 -1
- package/core/dist/runtime/adapter/artificer-l2-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/artificer-l2-adapter.js +11 -4
- package/core/dist/runtime/adapter/artificer-l2-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.js +11 -4
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/output-repair-contract.d.ts +21 -1
- package/core/dist/runtime/adapter/output-repair-contract.d.ts.map +1 -1
- package/core/dist/runtime/adapter/output-repair-contract.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-catalog.d.ts +42 -0
- package/core/dist/runtime/adapter/pi-ai-catalog.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-catalog.js +68 -0
- package/core/dist/runtime/adapter/pi-ai-catalog.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts +45 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts.map +1 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.js +321 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.js.map +1 -0
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +27 -2
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +71 -10
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/schema-prompt-adapter.js +39 -6
- package/core/dist/runtime/adapter/schema-prompt-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/structured-output-repair.d.ts +26 -0
- package/core/dist/runtime/adapter/structured-output-repair.d.ts.map +1 -1
- package/core/dist/runtime/adapter/structured-output-repair.js +140 -2
- package/core/dist/runtime/adapter/structured-output-repair.js.map +1 -1
- package/core/dist/runtime/config/execution-timing.d.ts +56 -0
- package/core/dist/runtime/config/execution-timing.d.ts.map +1 -0
- package/core/dist/runtime/config/execution-timing.js +76 -0
- package/core/dist/runtime/config/execution-timing.js.map +1 -0
- package/core/dist/runtime/config/index.d.ts +4 -0
- package/core/dist/runtime/config/index.d.ts.map +1 -1
- package/core/dist/runtime/config/index.js +2 -0
- package/core/dist/runtime/config/index.js.map +1 -1
- package/core/dist/runtime/config/pd-config-redaction.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-redaction.js +4 -0
- package/core/dist/runtime/config/pd-config-redaction.js.map +1 -1
- package/core/dist/runtime/config/pd-config-types.d.ts +5 -0
- package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-types.js.map +1 -1
- package/core/dist/runtime/config/pd-credentials.d.ts +105 -0
- package/core/dist/runtime/config/pd-credentials.d.ts.map +1 -0
- package/core/dist/runtime/config/pd-credentials.js +409 -0
- package/core/dist/runtime/config/pd-credentials.js.map +1 -0
- package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts +13 -2
- package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician/diag-rootcause-output.js.map +1 -1
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.d.ts +45 -0
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.d.ts.map +1 -0
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.js +74 -0
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.js.map +1 -0
- package/core/dist/runtime/diagnostician/prompt-projection.d.ts +51 -0
- package/core/dist/runtime/diagnostician/prompt-projection.d.ts.map +1 -0
- package/core/dist/runtime/diagnostician/prompt-projection.js +192 -0
- package/core/dist/runtime/diagnostician/prompt-projection.js.map +1 -0
- package/core/dist/runtime/diagnostician-output.d.ts +1 -1
- package/core/dist/runtime/diagnostician-output.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician-output.js +2 -2
- package/core/dist/runtime/diagnostician-output.js.map +1 -1
- package/core/dist/runtime/index.d.ts +5 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +11 -1
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/intent/index.d.ts +2 -0
- package/core/dist/runtime/intent/index.d.ts.map +1 -1
- package/core/dist/runtime/intent/index.js +2 -0
- package/core/dist/runtime/intent/index.js.map +1 -1
- package/core/dist/runtime/intent/intent-decision-record.d.ts +51 -3
- package/core/dist/runtime/intent/intent-decision-record.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.d.ts +104 -0
- package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -0
- package/core/dist/runtime/intent/intent-snapshot.js +164 -0
- package/core/dist/runtime/intent/intent-snapshot.js.map +1 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.d.ts +70 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.d.ts.map +1 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.js +148 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.js.map +1 -0
- package/core/dist/runtime/internalization/artificer-runner.js +1 -1
- package/core/dist/runtime/internalization/artificer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-distiller-runner.d.ts +6 -0
- package/core/dist/runtime/internalization/diag-distiller-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-distiller-runner.js +62 -5
- package/core/dist/runtime/internalization/diag-distiller-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +41 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.js +190 -43
- package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.d.ts +6 -0
- package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.js +114 -69
- package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
- package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/dreamer-prompt-builder.js +3 -0
- package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/dreamer-runner.js +1 -1
- package/core/dist/runtime/internalization/dreamer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/evaluator-runner.js +4 -4
- package/core/dist/runtime/internalization/evaluator-runner.js.map +1 -1
- package/core/dist/runtime/internalization/formation-context.d.ts +54 -0
- package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
- package/core/dist/runtime/internalization/formation-context.js +135 -3
- package/core/dist/runtime/internalization/formation-context.js.map +1 -1
- package/core/dist/runtime/internalization/index.d.ts +2 -2
- 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/intent-contract.d.ts +107 -0
- package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
- package/core/dist/runtime/internalization/intent-contract.js +315 -4
- package/core/dist/runtime/internalization/intent-contract.js.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +8 -0
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.js.map +1 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts +22 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.js +22 -3
- package/core/dist/runtime/internalization/philosopher-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/philosopher-runner.d.ts +15 -0
- package/core/dist/runtime/internalization/philosopher-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/philosopher-runner.js +74 -2
- package/core/dist/runtime/internalization/philosopher-runner.js.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts +32 -0
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.js +44 -0
- package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +6 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +31 -15
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-output.d.ts +21 -0
- package/core/dist/runtime/internalization/scribe-output.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-output.js +125 -2
- package/core/dist/runtime/internalization/scribe-output.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +26 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.js +33 -3
- package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.d.ts +32 -2
- package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.js +106 -8
- package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +46 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +220 -20
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/internalization-integrity-remediation.d.ts +7 -0
- package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
- package/core/dist/runtime/internalization-integrity-remediation.js +44 -12
- package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +25 -4
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +5 -5
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/runner/base-peer-runner.d.ts +90 -2
- package/core/dist/runtime/runner/base-peer-runner.d.ts.map +1 -1
- package/core/dist/runtime/runner/base-peer-runner.js +463 -170
- package/core/dist/runtime/runner/base-peer-runner.js.map +1 -1
- package/core/dist/runtime/runner/peer-runner-types.d.ts +19 -0
- package/core/dist/runtime/runner/peer-runner-types.d.ts.map +1 -1
- package/core/dist/runtime/runtime-protocol.d.ts +19 -0
- package/core/dist/runtime/runtime-protocol.d.ts.map +1 -1
- package/core/dist/runtime/signal-collector/llm-stage.d.ts +5 -0
- package/core/dist/runtime/signal-collector/llm-stage.d.ts.map +1 -1
- package/core/dist/runtime/signal-collector/llm-stage.js.map +1 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts +14 -0
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts.map +1 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js +16 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js.map +1 -1
- package/core/dist/runtime/store/commit/diagnostician-committer.d.ts +19 -0
- package/core/dist/runtime/store/commit/diagnostician-committer.d.ts.map +1 -1
- package/core/dist/runtime/store/commit/diagnostician-committer.js +11 -0
- package/core/dist/runtime/store/commit/diagnostician-committer.js.map +1 -1
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts +2 -2
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js +285 -35
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js.map +1 -1
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.d.ts +64 -0
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.d.ts.map +1 -0
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.js +231 -0
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.js.map +1 -0
- package/core/dist/runtime/store/lifecycle/index.d.ts +2 -0
- package/core/dist/runtime/store/lifecycle/index.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/index.js +1 -0
- package/core/dist/runtime/store/lifecycle/index.js.map +1 -1
- package/core/dist/runtime/store/lifecycle/lease-fence.d.ts +80 -0
- package/core/dist/runtime/store/lifecycle/lease-fence.d.ts.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-fence.js +79 -0
- package/core/dist/runtime/store/lifecycle/lease-fence.js.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.d.ts +118 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.d.ts.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.js +187 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.js.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-manager.d.ts +30 -20
- package/core/dist/runtime/store/lifecycle/lease-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/lease-manager.js +94 -53
- package/core/dist/runtime/store/lifecycle/lease-manager.js.map +1 -1
- package/core/dist/runtime/store/lifecycle/recovery-sweep.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/recovery-sweep.js +32 -15
- package/core/dist/runtime/store/lifecycle/recovery-sweep.js.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts +29 -0
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.js +40 -0
- package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts +64 -10
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js +154 -89
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.js +73 -4
- package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.js +6 -3
- package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime/task-status.d.ts +16 -0
- package/core/dist/runtime/task-status.d.ts.map +1 -1
- package/core/dist/runtime/task-status.js +8 -0
- package/core/dist/runtime/task-status.js.map +1 -1
- package/core/dist/runtime/trajectory-schema.d.ts.map +1 -1
- package/core/dist/runtime/trajectory-schema.js +20 -1
- package/core/dist/runtime/trajectory-schema.js.map +1 -1
- package/core/dist/runtime/types/event-types.d.ts +20 -0
- package/core/dist/runtime/types/event-types.d.ts.map +1 -1
- package/core/dist/runtime/types/event-types.js +7 -0
- package/core/dist/runtime/types/event-types.js.map +1 -1
- package/core/dist/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +27 -2
- package/core/dist/telemetry-event.js.map +1 -1
- package/core/dist/trajectory-types.d.ts +33 -0
- package/core/dist/trajectory-types.d.ts.map +1 -1
- package/core/package.json +1 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +12 -5
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +9 -12
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/host-runtime/dist/adaptive-consumer-schedule.d.ts +103 -0
- package/host-runtime/dist/adaptive-consumer-schedule.js +145 -0
- package/host-runtime/dist/adaptive-priority-provider.d.ts +7 -1
- package/host-runtime/dist/adaptive-priority-provider.js +6 -3
- package/host-runtime/dist/adaptive-selection.d.ts +1 -1
- package/host-runtime/dist/adaptive-selection.js +2 -1
- package/host-runtime/dist/degraded-enforcement-marker.d.ts +35 -0
- package/host-runtime/dist/degraded-enforcement-marker.js +79 -0
- package/host-runtime/dist/index.d.ts +2 -0
- package/host-runtime/dist/index.js +8 -0
- package/host-runtime/dist/internalization-consumer-cycle.d.ts +35 -0
- package/host-runtime/dist/internalization-consumer-cycle.js +51 -17
- package/host-runtime/dist/prompt-activation-deliverability.d.ts +10 -0
- package/host-runtime/dist/prompt-activation-deliverability.js +5 -2
- package/host-runtime/dist/prompt-injection-event-evidence.d.ts +34 -0
- package/host-runtime/dist/prompt-injection-event-evidence.js +96 -0
- package/host-runtime/dist/signal-classifier.js +4 -4
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/mcp-binding-contract.js +4 -15
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/health-codex.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-codex.js +26 -1
- package/pd-cli/dist/commands/health-codex.js.map +1 -1
- package/pd-cli/dist/commands/health.d.ts.map +1 -1
- package/pd-cli/dist/commands/health.js +32 -2
- package/pd-cli/dist/commands/health.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +6 -4
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-init.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-init.js +29 -1
- package/pd-cli/dist/commands/runtime-init.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js +9 -14
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +5 -5
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
- package/pd-cli/dist/commands/runtime-usage.d.ts +62 -0
- package/pd-cli/dist/commands/runtime-usage.d.ts.map +1 -0
- package/pd-cli/dist/commands/runtime-usage.js +315 -0
- package/pd-cli/dist/commands/runtime-usage.js.map +1 -0
- package/pd-cli/dist/commands/runtime.js +6 -6
- package/pd-cli/dist/commands/runtime.js.map +1 -1
- package/pd-cli/dist/index.d.ts.map +1 -1
- package/pd-cli/dist/index.js +51 -17
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/program.d.ts.map +1 -1
- package/pd-cli/dist/program.js +4 -0
- package/pd-cli/dist/program.js.map +1 -1
- package/pd-cli/dist/services/cli-invocation-log.d.ts +66 -0
- package/pd-cli/dist/services/cli-invocation-log.d.ts.map +1 -0
- package/pd-cli/dist/services/cli-invocation-log.js +139 -0
- package/pd-cli/dist/services/cli-invocation-log.js.map +1 -0
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
- package/pd-cli/dist/services/config-doctor.js +5 -4
- package/pd-cli/dist/services/config-doctor.js.map +1 -1
- package/pd-cli/dist/services/demo-story-a-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/demo-story-a-runner.js +6 -2
- package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.d.ts +3 -1
- package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.js +20 -8
- package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.js +5 -5
- package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +632 -536
- package/plugin/dist/core/signal-collector-host.d.ts +5 -0
- package/plugin/dist/governance-audit.js +2 -2
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +13 -10
- package/plugin/dist/service/internalization-auto-consumer-service.d.ts +2 -1
- package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +1 -1
- package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +1 -1
- package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +1 -1
- package/release-manager/dist/installer.js +12 -5
- package/release-manager/dist/installers/codex-host-installer.js +9 -12
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +1 -1
- package/dist/installers/mcp-binding-shape-mirror.d.ts +0 -27
- package/dist/installers/mcp-binding-shape-mirror.d.ts.map +0 -1
- package/dist/installers/mcp-binding-shape-mirror.js +0 -105
- package/dist/installers/mcp-binding-shape-mirror.js.map +0 -1
- package/release-manager/dist/installers/mcp-binding-shape-mirror.js +0 -105
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fenced Task Lifecycle Writer — the ONE write authority for execution-owned
|
|
3
|
+
* task/run transitions.
|
|
4
|
+
*
|
|
5
|
+
* SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §5.3 (remediation).
|
|
6
|
+
*
|
|
7
|
+
* Before this module `RuntimeStateManager.markTaskSucceeded/Failed/RetryWait`
|
|
8
|
+
* (a) guarded only some paths, (b) cleared the lease and THEN looked up the
|
|
9
|
+
* newest run to update, and (c) therefore let a superseded worker stamp a new
|
|
10
|
+
* execution's run as failed. This module:
|
|
11
|
+
*
|
|
12
|
+
* - fences the task UPDATE with the caller's lease identity (owner +
|
|
13
|
+
* generation + not-expired) in the same statement;
|
|
14
|
+
* - updates the run identified by the EXPLICIT `runId` supplied by the
|
|
15
|
+
* executing context — never "the latest run";
|
|
16
|
+
* - performs both writes inside ONE SQLite transaction, so a fence failure
|
|
17
|
+
* rolls back the run write and a missing run rolls back the task write.
|
|
18
|
+
*
|
|
19
|
+
* The SQL lives here (store-owned) rather than in the manager (PRI-47).
|
|
20
|
+
*/
|
|
21
|
+
import { PDRuntimeError } from '../../error-categories.js';
|
|
22
|
+
import { assertLeaseFenceShape, leaseFenceValues } from './lease-fence.js';
|
|
23
|
+
function isValidFence(fence) {
|
|
24
|
+
try {
|
|
25
|
+
assertLeaseFenceShape(fence);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function buildTaskPatch(input, terminal, nowIso) {
|
|
33
|
+
if (terminal === 'retry_wait') {
|
|
34
|
+
return {
|
|
35
|
+
setSql: 'status = ?, lease_owner = NULL, lease_expires_at = ?, last_error = ?, updated_at = ?',
|
|
36
|
+
values: ['retry_wait', input.retryAfterIso, input.errorCategory, nowIso],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (terminal === 'failed') {
|
|
40
|
+
return {
|
|
41
|
+
setSql: 'status = ?, lease_owner = NULL, lease_expires_at = NULL, last_error = ?, updated_at = ?',
|
|
42
|
+
values: ['failed', input.errorCategory, nowIso],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
setSql: 'status = ?, lease_owner = NULL, lease_expires_at = NULL, last_error = NULL, result_ref = ?, updated_at = ?',
|
|
47
|
+
values: ['succeeded', input.resultRef ?? null, nowIso],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Narrow a raw task row into a TaskRecord.
|
|
52
|
+
*
|
|
53
|
+
* Duplicated deliberately from SqliteTaskStore's private mapper: importing a
|
|
54
|
+
* private method across modules would be a shallow seam, and the fields read
|
|
55
|
+
* here are validated structurally (rc-1/rc-3).
|
|
56
|
+
*/
|
|
57
|
+
function rowToTaskRecord(row) {
|
|
58
|
+
const record = {
|
|
59
|
+
taskId: String(row.task_id),
|
|
60
|
+
taskKind: String(row.task_kind),
|
|
61
|
+
status: String(row.status),
|
|
62
|
+
createdAt: String(row.created_at),
|
|
63
|
+
updatedAt: String(row.updated_at),
|
|
64
|
+
attemptCount: Number(row.attempt_count ?? 0),
|
|
65
|
+
maxAttempts: Number(row.max_attempts ?? 3),
|
|
66
|
+
lastError: (row.last_error ?? null),
|
|
67
|
+
leaseGeneration: Number(row.lease_generation ?? 0),
|
|
68
|
+
};
|
|
69
|
+
if (typeof row.lease_owner === 'string')
|
|
70
|
+
record.leaseOwner = row.lease_owner;
|
|
71
|
+
if (typeof row.lease_expires_at === 'string')
|
|
72
|
+
record.leaseExpiresAt = row.lease_expires_at;
|
|
73
|
+
if (typeof row.input_ref === 'string')
|
|
74
|
+
record.inputRef = row.input_ref;
|
|
75
|
+
if (typeof row.result_ref === 'string')
|
|
76
|
+
record.resultRef = row.result_ref;
|
|
77
|
+
if (typeof row.diagnostic_json === 'string')
|
|
78
|
+
record.diagnosticJson = row.diagnostic_json;
|
|
79
|
+
return record;
|
|
80
|
+
}
|
|
81
|
+
export class SqliteFencedTaskLifecycle {
|
|
82
|
+
connection;
|
|
83
|
+
constructor(connection) {
|
|
84
|
+
this.connection = connection;
|
|
85
|
+
}
|
|
86
|
+
/** Fenced success: task → succeeded, the caller's run → succeeded. */
|
|
87
|
+
async markSucceeded(input) {
|
|
88
|
+
return this.markTerminalSync(input, 'succeeded');
|
|
89
|
+
}
|
|
90
|
+
/** Sync variant for composing the terminal write into a larger transaction. */
|
|
91
|
+
markSucceededSync(input) {
|
|
92
|
+
return this.markTerminalSync(input, 'succeeded');
|
|
93
|
+
}
|
|
94
|
+
/** Fenced failure: task → failed, the caller's run → failed. */
|
|
95
|
+
async markFailed(input) {
|
|
96
|
+
return this.markTerminalSync(input, 'failed');
|
|
97
|
+
}
|
|
98
|
+
/** Fenced retry: task → retry_wait, the caller's run → failed. */
|
|
99
|
+
async markRetryWait(input) {
|
|
100
|
+
return this.markTerminalSync(input, 'retry_wait');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Apply a diagnostic-JSON mutation under the fence.
|
|
104
|
+
*
|
|
105
|
+
* Read and write happen inside one transaction: the mutation receives the
|
|
106
|
+
* CURRENT persisted JSON, so two concurrent fenced writers cannot overwrite
|
|
107
|
+
* each other from a stale snapshot, and a superseded worker cannot write at
|
|
108
|
+
* all.
|
|
109
|
+
*
|
|
110
|
+
* @throws PDRuntimeError{lease_conflict} when the fence no longer holds.
|
|
111
|
+
*/
|
|
112
|
+
async applyDiagnosticJson(fence, mutate) {
|
|
113
|
+
assertLeaseFenceShape(fence);
|
|
114
|
+
const db = this.connection.getDb();
|
|
115
|
+
const nowIso = new Date().toISOString();
|
|
116
|
+
db.transaction(() => {
|
|
117
|
+
const row = db
|
|
118
|
+
.prepare('SELECT diagnostic_json FROM tasks WHERE task_id = ?')
|
|
119
|
+
.get(fence.taskId);
|
|
120
|
+
if (!row) {
|
|
121
|
+
throw new PDRuntimeError('storage_unavailable', `Task not found: ${fence.taskId}`, {
|
|
122
|
+
taskId: fence.taskId,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const nextJson = mutate(row.diagnostic_json ?? null);
|
|
126
|
+
const { changes } = db
|
|
127
|
+
.prepare(`UPDATE tasks SET diagnostic_json = ?, updated_at = ?
|
|
128
|
+
WHERE task_id = ?
|
|
129
|
+
AND status = 'leased'
|
|
130
|
+
AND lease_owner = ?
|
|
131
|
+
AND lease_generation = ?
|
|
132
|
+
AND lease_expires_at IS NOT NULL
|
|
133
|
+
AND lease_expires_at >= ?`)
|
|
134
|
+
.run(nextJson, nowIso, fence.taskId, ...leaseFenceValues(fence, nowIso));
|
|
135
|
+
if (changes === 0) {
|
|
136
|
+
throw new PDRuntimeError('lease_conflict', `Task ${fence.taskId} diagnostic write refused: lease generation ${fence.leaseGeneration} is no longer the owner`, { taskId: fence.taskId, owner: fence.owner, leaseGeneration: fence.leaseGeneration });
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
const updated = await this.readTask(fence.taskId);
|
|
140
|
+
if (!updated) {
|
|
141
|
+
throw new PDRuntimeError('storage_unavailable', `Task not found after diagnostic write: ${fence.taskId}`, {
|
|
142
|
+
taskId: fence.taskId,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return updated;
|
|
146
|
+
}
|
|
147
|
+
/** Fence-only probe used by heartbeat/ownership checks. */
|
|
148
|
+
async assertOwned(fence) {
|
|
149
|
+
if (!isValidFence(fence))
|
|
150
|
+
return false;
|
|
151
|
+
const db = this.connection.getDb();
|
|
152
|
+
const nowIso = new Date().toISOString();
|
|
153
|
+
const row = db
|
|
154
|
+
.prepare(`SELECT 1 AS ok FROM tasks
|
|
155
|
+
WHERE task_id = ?
|
|
156
|
+
AND status = 'leased'
|
|
157
|
+
AND lease_owner = ?
|
|
158
|
+
AND lease_generation = ?
|
|
159
|
+
AND lease_expires_at IS NOT NULL
|
|
160
|
+
AND lease_expires_at >= ?`)
|
|
161
|
+
.get(fence.taskId, ...leaseFenceValues(fence, nowIso));
|
|
162
|
+
return row !== undefined;
|
|
163
|
+
}
|
|
164
|
+
// ── internals ──────────────────────────────────────────────────────────────
|
|
165
|
+
markTerminalSync(input, terminal) {
|
|
166
|
+
assertLeaseFenceShape(input.fence);
|
|
167
|
+
if (!input.runId) {
|
|
168
|
+
throw new PDRuntimeError('input_invalid', 'Fenced terminal write requires the execution runId', {
|
|
169
|
+
taskId: input.fence.taskId,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (terminal === 'retry_wait' && !input.retryAfterIso) {
|
|
173
|
+
throw new PDRuntimeError('input_invalid', 'markRetryWait requires retryAfterIso', {
|
|
174
|
+
taskId: input.fence.taskId,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const db = this.connection.getDb();
|
|
178
|
+
const nowIso = new Date().toISOString();
|
|
179
|
+
const { fence } = input;
|
|
180
|
+
db.transaction(() => {
|
|
181
|
+
const patch = buildTaskPatch(input, terminal, nowIso);
|
|
182
|
+
const { changes } = db
|
|
183
|
+
.prepare(`UPDATE tasks SET ${patch.setSql}
|
|
184
|
+
WHERE task_id = ?
|
|
185
|
+
AND status = 'leased'
|
|
186
|
+
AND lease_owner = ?
|
|
187
|
+
AND lease_generation = ?
|
|
188
|
+
AND lease_expires_at IS NOT NULL
|
|
189
|
+
AND lease_expires_at >= ?`)
|
|
190
|
+
.run(...patch.values, fence.taskId, ...leaseFenceValues(fence, nowIso));
|
|
191
|
+
if (changes === 0) {
|
|
192
|
+
throw new PDRuntimeError('lease_conflict', `Task ${fence.taskId} ${terminal} write refused: lease generation ${fence.leaseGeneration} (owner ${fence.owner}) is no longer the owner`, {
|
|
193
|
+
taskId: fence.taskId,
|
|
194
|
+
owner: fence.owner,
|
|
195
|
+
leaseGeneration: fence.leaseGeneration,
|
|
196
|
+
terminal,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// The run is addressed explicitly. A missing/mismatched run means the
|
|
200
|
+
// caller's execution context does not describe this task's run — a
|
|
201
|
+
// storage fault that must roll the task write back (rc-3).
|
|
202
|
+
const runChanges = db
|
|
203
|
+
.prepare(`UPDATE runs SET execution_status = ?, ended_at = ?, reason = ?, error_category = ?
|
|
204
|
+
WHERE run_id = ? AND task_id = ?`)
|
|
205
|
+
.run(terminal === 'succeeded' ? 'succeeded' : 'failed', nowIso, terminal === 'succeeded'
|
|
206
|
+
? 'task_completed'
|
|
207
|
+
: terminal === 'failed'
|
|
208
|
+
? 'task_failed'
|
|
209
|
+
: (input.failureReason ?? 'task_retry'), input.errorCategory, input.runId, fence.taskId).changes;
|
|
210
|
+
if (runChanges === 0) {
|
|
211
|
+
throw new PDRuntimeError('storage_unavailable', `Run ${input.runId} does not belong to task ${fence.taskId}; fenced ${terminal} write rolled back`, { taskId: fence.taskId, runId: input.runId });
|
|
212
|
+
}
|
|
213
|
+
})();
|
|
214
|
+
const updated = this.readTaskSync(fence.taskId);
|
|
215
|
+
if (!updated) {
|
|
216
|
+
throw new PDRuntimeError('storage_unavailable', `Task not found after fenced write: ${fence.taskId}`, {
|
|
217
|
+
taskId: fence.taskId,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return updated;
|
|
221
|
+
}
|
|
222
|
+
async readTask(taskId) {
|
|
223
|
+
return this.readTaskSync(taskId);
|
|
224
|
+
}
|
|
225
|
+
readTaskSync(taskId) {
|
|
226
|
+
const db = this.connection.getDb();
|
|
227
|
+
const row = db.prepare('SELECT * FROM tasks WHERE task_id = ?').get(taskId);
|
|
228
|
+
return row ? rowToTaskRecord(row) : null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=fenced-task-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fenced-task-writer.js","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/fenced-task-writer.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AC,uCAAuC,CAAC,CAAC,GAAG,CAAC,MAAM,CAE7D,CAAC;QACd,OAAO,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -4,4 +4,6 @@ export type { RetryPolicy, RetryPolicyConfig } from './retry-policy.js';
|
|
|
4
4
|
export { DefaultRetryPolicy } from './retry-policy.js';
|
|
5
5
|
export type { RecoverySweep, RecoveryResult } from './recovery-sweep.js';
|
|
6
6
|
export { DefaultRecoverySweep } from './recovery-sweep.js';
|
|
7
|
+
export type { LeaseHeartbeatState, LeaseHeartbeatOptions, LeaseHeartbeatEvent, LeaseOwnershipSnapshot, } from './lease-heartbeat.js';
|
|
8
|
+
export { LeaseHeartbeat } from './lease-heartbeat.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,YAAY,EACV,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAO3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lease Fence — the execution identity that guards every write a worker may
|
|
3
|
+
* perform on a task it claims to own.
|
|
4
|
+
*
|
|
5
|
+
* SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §5.3 (remediation).
|
|
6
|
+
*
|
|
7
|
+
* Why this exists: `lease_owner` is a *string* chosen by the caller, so two
|
|
8
|
+
* workers can legitimately use the same owner label (`pain-signal-bridge`,
|
|
9
|
+
* `split-diagnostician-orchestrator`). Before this module, ownership was
|
|
10
|
+
* decided by comparing that label, which means worker A could be mistaken for
|
|
11
|
+
* the legal owner after its lease expired and worker B re-acquired the task
|
|
12
|
+
* with the same label.
|
|
13
|
+
*
|
|
14
|
+
* `lease_generation` is a monotonic integer minted by the ONE acquisition
|
|
15
|
+
* statement in `DefaultLeaseManager`. A fence (`taskId + owner + generation`)
|
|
16
|
+
* therefore identifies one acquisition, not one label:
|
|
17
|
+
*
|
|
18
|
+
* worker A acquires → generation 1
|
|
19
|
+
* lease expires → recovery bumps generation to 2 (invalidation)
|
|
20
|
+
* worker B acquires → generation 3
|
|
21
|
+
* worker A writes → generation 1 ≠ 3 → refused
|
|
22
|
+
*
|
|
23
|
+
* Every guarded write embeds `leaseFencePredicate()` in the SAME SQL
|
|
24
|
+
* statement that performs the mutation. A read-then-write (`assertOwned()`
|
|
25
|
+
* followed by an unguarded UPDATE) is explicitly NOT sufficient: the lease can
|
|
26
|
+
* be reclaimed in the interval, and that pattern is what this module replaces.
|
|
27
|
+
*/
|
|
28
|
+
import type { Database } from 'better-sqlite3';
|
|
29
|
+
import type { TaskRecord } from '../../task-status.js';
|
|
30
|
+
/**
|
|
31
|
+
* The identity of ONE lease acquisition.
|
|
32
|
+
*
|
|
33
|
+
* All three fields are required: there is no "owner-only" variant, and no
|
|
34
|
+
* optional-token default that lets a caller bypass fencing.
|
|
35
|
+
*/
|
|
36
|
+
export interface LeaseFence {
|
|
37
|
+
readonly taskId: string;
|
|
38
|
+
readonly owner: string;
|
|
39
|
+
readonly leaseGeneration: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Values that pair with the fence predicate below.
|
|
43
|
+
*
|
|
44
|
+
* The predicate is written LITERALLY in every statement rather than shared as a
|
|
45
|
+
* string constant: the architecture guard forbids interpolated DML, because a
|
|
46
|
+
* predicate assembled at runtime can silently lose a clause.
|
|
47
|
+
*
|
|
48
|
+
* status = 'leased'
|
|
49
|
+
* AND lease_owner = ?
|
|
50
|
+
* AND lease_generation = ?
|
|
51
|
+
* AND lease_expires_at IS NOT NULL
|
|
52
|
+
* AND lease_expires_at >= ? -- an expired lease is NOT owned
|
|
53
|
+
*/
|
|
54
|
+
export declare function leaseFenceValues(fence: LeaseFence, nowIso: string): [string, number, string];
|
|
55
|
+
/** Runtime guard: a fence with a non-integer generation proves nothing. */
|
|
56
|
+
export declare function isLeaseFence(value: unknown): value is LeaseFence;
|
|
57
|
+
/** Fail loud on a malformed fence instead of degrading to an unfenced write. */
|
|
58
|
+
export declare function assertLeaseFenceShape(fence: LeaseFence): void;
|
|
59
|
+
/**
|
|
60
|
+
* Build the fence for a task this process just acquired.
|
|
61
|
+
*
|
|
62
|
+
* Returns null when the record does not describe an acquirable lease (a test
|
|
63
|
+
* double that does not model leases, or a synthetic record). Callers must treat
|
|
64
|
+
* null as "no fence" — never as "fence passed".
|
|
65
|
+
*/
|
|
66
|
+
export declare function leaseFenceOf(task: TaskRecord): LeaseFence | null;
|
|
67
|
+
/**
|
|
68
|
+
* Verify the fence against the persisted row INSIDE the caller's transaction
|
|
69
|
+
* and abort the transaction when it no longer holds.
|
|
70
|
+
*
|
|
71
|
+
* This is the building block for multi-statement commit units
|
|
72
|
+
* (artifacts / commits / candidates / pi_artifacts). It is deliberately a
|
|
73
|
+
* throwing assertion: a caller that keeps writing after it fails would be
|
|
74
|
+
* publishing a result the execution no longer owns.
|
|
75
|
+
*
|
|
76
|
+
* @throws PDRuntimeError{lease_conflict} when the row is missing, no longer
|
|
77
|
+
* leased, owned by another identity, or expired.
|
|
78
|
+
*/
|
|
79
|
+
export declare function assertLeaseFenceInTransaction(db: Database, fence: LeaseFence, nowIso: string): void;
|
|
80
|
+
//# sourceMappingURL=lease-fence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease-fence.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/lease-fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAE5F;AAED,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAQhE;AAED,gFAAgF;AAChF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAM7D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAKhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC3C,EAAE,EAAE,QAAQ,EACZ,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,GACb,IAAI,CAoBN"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { PDRuntimeError } from '../../error-categories.js';
|
|
2
|
+
/**
|
|
3
|
+
* Values that pair with the fence predicate below.
|
|
4
|
+
*
|
|
5
|
+
* The predicate is written LITERALLY in every statement rather than shared as a
|
|
6
|
+
* string constant: the architecture guard forbids interpolated DML, because a
|
|
7
|
+
* predicate assembled at runtime can silently lose a clause.
|
|
8
|
+
*
|
|
9
|
+
* status = 'leased'
|
|
10
|
+
* AND lease_owner = ?
|
|
11
|
+
* AND lease_generation = ?
|
|
12
|
+
* AND lease_expires_at IS NOT NULL
|
|
13
|
+
* AND lease_expires_at >= ? -- an expired lease is NOT owned
|
|
14
|
+
*/
|
|
15
|
+
export function leaseFenceValues(fence, nowIso) {
|
|
16
|
+
return [fence.owner, fence.leaseGeneration, nowIso];
|
|
17
|
+
}
|
|
18
|
+
/** Runtime guard: a fence with a non-integer generation proves nothing. */
|
|
19
|
+
export function isLeaseFence(value) {
|
|
20
|
+
if (typeof value !== 'object' || value === null)
|
|
21
|
+
return false;
|
|
22
|
+
const candidate = value;
|
|
23
|
+
return typeof candidate.taskId === 'string'
|
|
24
|
+
&& typeof candidate.owner === 'string'
|
|
25
|
+
&& typeof candidate.leaseGeneration === 'number'
|
|
26
|
+
&& Number.isInteger(candidate.leaseGeneration)
|
|
27
|
+
&& candidate.leaseGeneration >= 0;
|
|
28
|
+
}
|
|
29
|
+
/** Fail loud on a malformed fence instead of degrading to an unfenced write. */
|
|
30
|
+
export function assertLeaseFenceShape(fence) {
|
|
31
|
+
if (!isLeaseFence(fence)) {
|
|
32
|
+
throw new PDRuntimeError('input_invalid', 'Invalid lease fence: taskId, owner and integer leaseGeneration are required', {
|
|
33
|
+
taskId: fence?.taskId ?? null,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build the fence for a task this process just acquired.
|
|
39
|
+
*
|
|
40
|
+
* Returns null when the record does not describe an acquirable lease (a test
|
|
41
|
+
* double that does not model leases, or a synthetic record). Callers must treat
|
|
42
|
+
* null as "no fence" — never as "fence passed".
|
|
43
|
+
*/
|
|
44
|
+
export function leaseFenceOf(task) {
|
|
45
|
+
if (task.status !== 'leased' || !task.leaseOwner)
|
|
46
|
+
return null;
|
|
47
|
+
const generation = task.leaseGeneration;
|
|
48
|
+
if (typeof generation !== 'number' || !Number.isInteger(generation) || generation < 1)
|
|
49
|
+
return null;
|
|
50
|
+
return { taskId: task.taskId, owner: task.leaseOwner, leaseGeneration: generation };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Verify the fence against the persisted row INSIDE the caller's transaction
|
|
54
|
+
* and abort the transaction when it no longer holds.
|
|
55
|
+
*
|
|
56
|
+
* This is the building block for multi-statement commit units
|
|
57
|
+
* (artifacts / commits / candidates / pi_artifacts). It is deliberately a
|
|
58
|
+
* throwing assertion: a caller that keeps writing after it fails would be
|
|
59
|
+
* publishing a result the execution no longer owns.
|
|
60
|
+
*
|
|
61
|
+
* @throws PDRuntimeError{lease_conflict} when the row is missing, no longer
|
|
62
|
+
* leased, owned by another identity, or expired.
|
|
63
|
+
*/
|
|
64
|
+
export function assertLeaseFenceInTransaction(db, fence, nowIso) {
|
|
65
|
+
assertLeaseFenceShape(fence);
|
|
66
|
+
const row = db
|
|
67
|
+
.prepare(`SELECT 1 AS ok FROM tasks
|
|
68
|
+
WHERE task_id = ?
|
|
69
|
+
AND status = 'leased'
|
|
70
|
+
AND lease_owner = ?
|
|
71
|
+
AND lease_generation = ?
|
|
72
|
+
AND lease_expires_at IS NOT NULL
|
|
73
|
+
AND lease_expires_at >= ?`)
|
|
74
|
+
.get(fence.taskId, ...leaseFenceValues(fence, nowIso));
|
|
75
|
+
if (row === undefined) {
|
|
76
|
+
throw new PDRuntimeError('lease_conflict', `Task ${fence.taskId} is no longer owned by lease generation ${fence.leaseGeneration} (owner ${fence.owner}); the execution has been superseded or has expired`, { taskId: fence.taskId, owner: fence.owner, leaseGeneration: fence.leaseGeneration });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=lease-fence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease-fence.js","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/lease-fence.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAe3D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAiB,EAAE,MAAc;IACh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C;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,6BAA6B,CAC3C,EAAY,EACZ,KAAiB,EACjB,MAAc;IAEd,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,EAAE;SACX,OAAO,CACN;;;;;;mCAM6B,CAC9B;SACA,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACzD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,cAAc,CACtB,gBAAgB,EAChB,QAAQ,KAAK,CAAC,MAAM,2CAA2C,KAAK,CAAC,eAAe,WAAW,KAAK,CAAC,KAAK,qDAAqD,EAC/J,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,eAAe,EAAE,CACrF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lease Heartbeat — SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §5.2.
|
|
3
|
+
*
|
|
4
|
+
* Before this module the pipeline had no production lease renewal at all:
|
|
5
|
+
* `BasePeerRunner` acquired a 300 s lease and ran a 300 s stage, and the
|
|
6
|
+
* consumer cycle reclaims expired leases every cycle. Any stage that crossed
|
|
7
|
+
* its lease was therefore recovered *while still executing*, and the reclaimed
|
|
8
|
+
* worker could still write a terminal state.
|
|
9
|
+
*
|
|
10
|
+
* The heartbeat keeps a lease alive for as long as the worker is genuinely
|
|
11
|
+
* working, and — more importantly — records a *lost* verdict when renewal
|
|
12
|
+
* cannot prove ownership. Callers MUST consult `assertOwned()` before any
|
|
13
|
+
* terminal write, so a worker that lost the lease cannot "come back" and
|
|
14
|
+
* commit a stale result.
|
|
15
|
+
*
|
|
16
|
+
* Design constraints:
|
|
17
|
+
* - same `owner` identity as acquisition (renewal is owner-checked in SQL);
|
|
18
|
+
* - a recursive timeout, never `setInterval`: renewals cannot overlap;
|
|
19
|
+
* - failures are loud (event + `lastError`), never swallowed;
|
|
20
|
+
* - timers and clock are injectable so tests never wait on wall-clock time.
|
|
21
|
+
*/
|
|
22
|
+
import type { LeaseFence } from './lease-fence.js';
|
|
23
|
+
export type LeaseHeartbeatState = 'idle' | 'running' | 'stopped' | 'lost';
|
|
24
|
+
export interface LeaseOwnershipSnapshot {
|
|
25
|
+
readonly status: string;
|
|
26
|
+
readonly leaseOwner?: string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Fencing token of the acquisition that currently owns the row
|
|
29
|
+
* (SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §5.3). Required for a
|
|
30
|
+
* positive verdict: an owner label alone cannot distinguish two workers.
|
|
31
|
+
*/
|
|
32
|
+
readonly leaseGeneration?: number | null;
|
|
33
|
+
readonly leaseExpiresAt?: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface LeaseHeartbeatEvent {
|
|
36
|
+
readonly type: 'renewed' | 'renewal_failed' | 'ownership_lost';
|
|
37
|
+
readonly taskId: string;
|
|
38
|
+
readonly owner: string;
|
|
39
|
+
readonly renewalCount: number;
|
|
40
|
+
readonly occurredAt: string;
|
|
41
|
+
readonly detail?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface LeaseHeartbeatOptions {
|
|
44
|
+
readonly taskId: string;
|
|
45
|
+
readonly owner: string;
|
|
46
|
+
/** The fencing token returned by the acquisition this heartbeat belongs to. */
|
|
47
|
+
readonly leaseGeneration: number;
|
|
48
|
+
/** Lease validity window that each renewal must re-establish. */
|
|
49
|
+
readonly leaseTtlMs: number;
|
|
50
|
+
/** Renewal cadence; must be strictly below `leaseTtlMs`. */
|
|
51
|
+
readonly intervalMs: number;
|
|
52
|
+
readonly renewLease: (fence: LeaseFence, durationMs: number) => Promise<unknown>;
|
|
53
|
+
/**
|
|
54
|
+
* Ownership probe used at commit time. The persisted row is the authority;
|
|
55
|
+
* without it no positive verdict exists (see `unfencedTestMode`).
|
|
56
|
+
*/
|
|
57
|
+
readonly readOwnership?: (taskId: string) => Promise<LeaseOwnershipSnapshot | null>;
|
|
58
|
+
/**
|
|
59
|
+
* EXPLICIT opt-in for harnesses whose state manager does not persist leases
|
|
60
|
+
* (unit-test doubles, in-memory runners). Production callers never set it —
|
|
61
|
+
* the constructor refuses to start without a probe otherwise, because the
|
|
62
|
+
* old `if (!snapshot) return true` fail-open let a worker whose lease had
|
|
63
|
+
* been reclaimed commit a stale result.
|
|
64
|
+
*/
|
|
65
|
+
readonly unfencedTestMode?: boolean;
|
|
66
|
+
readonly emit?: (event: LeaseHeartbeatEvent) => void;
|
|
67
|
+
readonly setTimeoutFn?: (handler: () => void, ms: number) => unknown;
|
|
68
|
+
readonly clearTimeoutFn?: (handle: unknown) => void;
|
|
69
|
+
readonly now?: () => Date;
|
|
70
|
+
}
|
|
71
|
+
export declare class LeaseHeartbeat {
|
|
72
|
+
private readonly options;
|
|
73
|
+
private state;
|
|
74
|
+
private timerHandle;
|
|
75
|
+
private inFlight;
|
|
76
|
+
private renewalCountValue;
|
|
77
|
+
private lastRenewedAtValue;
|
|
78
|
+
private lastErrorValue;
|
|
79
|
+
private readonly setTimeoutFn;
|
|
80
|
+
private readonly clearTimeoutFn;
|
|
81
|
+
private readonly now;
|
|
82
|
+
constructor(options: LeaseHeartbeatOptions);
|
|
83
|
+
/** The identity every renewal and every fenced write must carry. */
|
|
84
|
+
get fence(): LeaseFence;
|
|
85
|
+
get status(): LeaseHeartbeatState;
|
|
86
|
+
/** True once a renewal (or ownership probe) proved the worker lost the lease. */
|
|
87
|
+
get lost(): boolean;
|
|
88
|
+
get renewalCount(): number;
|
|
89
|
+
get lastRenewedAt(): string | null;
|
|
90
|
+
get lastError(): string | null;
|
|
91
|
+
/** Begin periodic renewal. Idempotent while running. */
|
|
92
|
+
start(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Stop renewing and wait for an in-flight renewal to settle.
|
|
95
|
+
*
|
|
96
|
+
* Awaiting matters: a renewal racing with `stop()` must not update the row
|
|
97
|
+
* after the caller believes the lease is released.
|
|
98
|
+
*/
|
|
99
|
+
stop(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Commit-time ownership verdict.
|
|
102
|
+
*
|
|
103
|
+
* A positive verdict requires ALL of: the persisted task exists, is still
|
|
104
|
+
* `leased`, carries OUR owner, carries OUR fencing generation, and has not
|
|
105
|
+
* expired. Anything else — a missing row, a probe error, a different
|
|
106
|
+
* generation under the same owner string — is a lost lease.
|
|
107
|
+
*
|
|
108
|
+
* A probe error and a missing row are BOTH fail-closed: an unprovable
|
|
109
|
+
* ownership claim must never be treated as proof (Evidence Over Assumption),
|
|
110
|
+
* and the recovery sweep may simply have deleted the row.
|
|
111
|
+
*/
|
|
112
|
+
assertOwned(): Promise<boolean>;
|
|
113
|
+
private scheduleNext;
|
|
114
|
+
private tick;
|
|
115
|
+
private markLost;
|
|
116
|
+
private clearTimer;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=lease-heartbeat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease-heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/lifecycle/lease-heartbeat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,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