create-principles-disciple 1.154.5 → 1.155.1
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 +10 -0
- package/console/dist/server/models/EvidenceChainConsoleModel.js +31 -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 +37 -37
- 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 +1 -1
- 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 +4 -4
- 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/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/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/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 +586 -568
- package/plugin/dist/openclaw-worker.d.ts +92 -0
- package/plugin/dist/openclaw-worker.js +2439 -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 +2 -2
- 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,928 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source revocation sweep — PRI-1283 R3 (SPEC-PD-FEEDBACK-RESILIENCE-001
|
|
3
|
+
* TECH §2.2 "数据清退"), review round 2 (directives A2/A3/B/C/E).
|
|
4
|
+
*
|
|
5
|
+
* When a workspace host's conversation-ingestion consent leaves `granted`,
|
|
6
|
+
* the material already persisted FROM that host's conversations must be
|
|
7
|
+
* purged or made unreadable — UI hiding is not cleanup, and stopping new
|
|
8
|
+
* ingestion is not enough (TECH §2.2.1 R3).
|
|
9
|
+
*
|
|
10
|
+
* What this sweep does, per host whose ledger record exists with a
|
|
11
|
+
* non-granted decision (a MISSING or UNREADABLE ledger is not a revocation —
|
|
12
|
+
* nothing is purged, while the R2 read gates keep blocking consumption):
|
|
13
|
+
*
|
|
14
|
+
* trajectory.db (one connection; each step its own small transaction):
|
|
15
|
+
* 1. governance_observations (host rows, operational+promoted):
|
|
16
|
+
* visible_text / sanitized_tool_facts_json → NULL,
|
|
17
|
+
* retention_class → 'expired', expired_at → revocation time.
|
|
18
|
+
* Reuses the store's own expiry shape; the store's no-regain guard
|
|
19
|
+
* then prevents a later replay from re-bodying these rows — this is
|
|
20
|
+
* what makes RE-GRANTING not resurrect old excerpts.
|
|
21
|
+
* 2. governance_signal_admissions (host markers), classified per marker
|
|
22
|
+
* (directive B):
|
|
23
|
+
* - OWNER-EXPLICIT (correctionEvidence.classification
|
|
24
|
+
* 'owner_statement' / explicit channel / explicit reason marker)
|
|
25
|
+
* → PRESERVED (an explicit Owner submission is an Owner act, not
|
|
26
|
+
* conversation ingestion);
|
|
27
|
+
* - pending_llm_review rows → TERMINATED as abandoned
|
|
28
|
+
* ('source_revoked') with the D6 minimal terminal payload — the
|
|
29
|
+
* nested trigger.text / trigger.matchedTerms / hostTurnId /
|
|
30
|
+
* task_payload copies are dropped and the row becomes
|
|
31
|
+
* unclaimable (directive A3; the claim path re-verifies consent
|
|
32
|
+
* too — A4);
|
|
33
|
+
* - other automatic markers → task_payload_json redacted AND the
|
|
34
|
+
* independent `reason` COLUMN redacted (it quotes detected terms;
|
|
35
|
+
* directive C4);
|
|
36
|
+
* - unparseable payloads → redacted wholesale (fail-closed; the
|
|
37
|
+
* count is reported as unattributable).
|
|
38
|
+
* 3. pain_events of the host's AUTOMATIC admitted pains:
|
|
39
|
+
* text / reason → NULL (row, ids, timestamps survive — the Pain's
|
|
40
|
+
* business identity is NOT deleted). Owner-explicit statement pains
|
|
41
|
+
* are excluded from the purge set (their canonical ids come from the
|
|
42
|
+
* preserved markers).
|
|
43
|
+
*
|
|
44
|
+
* state.db (RuntimeStateManager when applying — task rows go through its
|
|
45
|
+
* CAS authority; a plain readonly connection for dry runs):
|
|
46
|
+
* 4. tasks.diagnostic_json: evidence entries of the revoked source are
|
|
47
|
+
* REMOVED; painIngress.evidenceClass is kept truthful
|
|
48
|
+
* (available.entryCount = remaining, or unavailable/source_revoked
|
|
49
|
+
* when empty); governed correctionEvidence is removed — an
|
|
50
|
+
* OWNER-EXPLICIT channel is kept (directive B); a non-sensitive
|
|
51
|
+
* `sourceRevocation` audit block records the verdict metadata only.
|
|
52
|
+
* Written via updateTaskIfDiagnosticJsonUnchanged (bounded CAS retry).
|
|
53
|
+
* 5. pain_diagnoses.evidence_json: revoked entries removed (row CAS).
|
|
54
|
+
* 6. artifacts (diagnostician_output).content_json: revoked evidence
|
|
55
|
+
* entries removed (row CAS). Model-authored root cause text survives.
|
|
56
|
+
* 7. runs.output_payload: the bare DiagnosticianOutputV2 (or the router
|
|
57
|
+
* envelope) embeds the same evidence[] notes — revoked entries are
|
|
58
|
+
* removed (row CAS; directive C2).
|
|
59
|
+
* 8. pi_artifacts.content_json: revoked evidence entries removed from
|
|
60
|
+
* every artifact kind that carries an evidence array (row CAS;
|
|
61
|
+
* directive C3).
|
|
62
|
+
*
|
|
63
|
+
* Checked, no excerpt fields (reported, never rewritten):
|
|
64
|
+
* - principle_candidates (model-generated description/title),
|
|
65
|
+
* - the principle ledger (reuseEvidence/derivedFromPainIds are ID
|
|
66
|
+
* metadata; principle text is model-authored),
|
|
67
|
+
* - governance_pending_promotion_tails / transcript_checkpoints
|
|
68
|
+
* (progress metadata, no text).
|
|
69
|
+
*
|
|
70
|
+
* Guarantees (SPEC §2.2.1 minimum cleanup contract + directive E):
|
|
71
|
+
* - idempotent: every step converges; a rerun reports zeros;
|
|
72
|
+
* - truly read-only dry run (directive E2): readonly connections
|
|
73
|
+
* (`fileMustExist`, `PRAGMA query_only=ON`), NO RuntimeStateManager
|
|
74
|
+
* initialization, no schema/migration/WAL writes, no database creation,
|
|
75
|
+
* no audit line;
|
|
76
|
+
* - per-table independence (directive E4): a missing table records
|
|
77
|
+
* `not_applicable` for that table ONLY; every other table still sweeps;
|
|
78
|
+
* - counted from writes (directive E5): every purged count comes from an
|
|
79
|
+
* actual successful CAS/UPDATE; a CAS race is a reported failure, never
|
|
80
|
+
* a success; an audit write failure is reported, never swallowed;
|
|
81
|
+
* - visible: an append-only `.state/source-revocation-sweep.jsonl` audit
|
|
82
|
+
* line records counts/verdicts/timestamps per host-run — never excerpt
|
|
83
|
+
* text;
|
|
84
|
+
* - retryable: per-item failures are recorded in the report and the run
|
|
85
|
+
* finishes the remaining items (outcome 'partial'); rerunning is safe;
|
|
86
|
+
* - bounded: busy_timeout + small transactions, per the trajectory
|
|
87
|
+
* retention runner's concurrency posture.
|
|
88
|
+
*/
|
|
89
|
+
import fs from 'node:fs';
|
|
90
|
+
import path from 'node:path';
|
|
91
|
+
import Database from 'better-sqlite3';
|
|
92
|
+
import { readConversationIngestionConsent } from './conversation-ingestion/consent.js';
|
|
93
|
+
import { resolveStateDbPath } from '@principles/core/runtime/storage-paths';
|
|
94
|
+
import { RuntimeStateManager } from '@principles/core/runtime';
|
|
95
|
+
import { GOVERNANCE_OBSERVATION_SOURCE_REF_PREFIX, isOwnerExplicitStatementReason, isOwnerManualCorrectionEvidence, } from '@principles/core/runtime';
|
|
96
|
+
export const SOURCE_REVOCATION_SWEEP_AUDIT_FILENAME = 'source-revocation-sweep.jsonl';
|
|
97
|
+
/** logicalKey host prefixes (mirrors the sourceRef mapping in core). */
|
|
98
|
+
const HOST_LOGICAL_KEY_PREFIX = {
|
|
99
|
+
codex: 'codex|',
|
|
100
|
+
workbuddy: 'wb|',
|
|
101
|
+
openclaw: 'openclaw|',
|
|
102
|
+
};
|
|
103
|
+
function emptyCounts() {
|
|
104
|
+
return {
|
|
105
|
+
governanceObservations: 0,
|
|
106
|
+
admissionPayloads: 0,
|
|
107
|
+
admissionReasons: 0,
|
|
108
|
+
pendingReviewsTerminated: 0,
|
|
109
|
+
preservedOwnerStatements: 0,
|
|
110
|
+
unattributableMarkers: 0,
|
|
111
|
+
painEventTexts: 0,
|
|
112
|
+
tasks: 0,
|
|
113
|
+
taskEvidenceEntries: 0,
|
|
114
|
+
taskCorrectionEvidence: 0,
|
|
115
|
+
painDiagnoses: 0,
|
|
116
|
+
painDiagnosesEvidenceEntries: 0,
|
|
117
|
+
artifacts: 0,
|
|
118
|
+
artifactEvidenceEntries: 0,
|
|
119
|
+
runs: 0,
|
|
120
|
+
runEvidenceEntries: 0,
|
|
121
|
+
piArtifacts: 0,
|
|
122
|
+
piArtifactEvidenceEntries: 0,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function isRecord(value) {
|
|
126
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Audit append. Returns false when the line could not be persisted — the
|
|
130
|
+
* caller reports it (directive E5: an audit write failure is never silently
|
|
131
|
+
* swallowed, but also never turns a successful purge into a failed one; it
|
|
132
|
+
* degrades the run to 'partial' so the operator sees the gap).
|
|
133
|
+
*/
|
|
134
|
+
function appendAuditLine(stateDir, line) {
|
|
135
|
+
try {
|
|
136
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
137
|
+
fs.appendFileSync(path.join(stateDir, SOURCE_REVOCATION_SWEEP_AUDIT_FILENAME), `${JSON.stringify(line)}\n`, 'utf8');
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
void error;
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Entries whose sourceRef belongs to the swept host (exact prefix match). */
|
|
146
|
+
function entryBelongsToHost(sourceRef, logicalKeyPrefix) {
|
|
147
|
+
if (typeof sourceRef !== 'string')
|
|
148
|
+
return false;
|
|
149
|
+
if (!sourceRef.startsWith(GOVERNANCE_OBSERVATION_SOURCE_REF_PREFIX))
|
|
150
|
+
return false;
|
|
151
|
+
return sourceRef.slice(GOVERNANCE_OBSERVATION_SOURCE_REF_PREFIX.length).startsWith(logicalKeyPrefix);
|
|
152
|
+
}
|
|
153
|
+
function filterEvidenceArray(value, logicalKeyPrefix) {
|
|
154
|
+
if (!Array.isArray(value))
|
|
155
|
+
return null;
|
|
156
|
+
const kept = value.filter((entry) => !entryBelongsToHost(isRecord(entry) ? entry.sourceRef : entry, logicalKeyPrefix));
|
|
157
|
+
return { kept, removed: value.length - kept.length };
|
|
158
|
+
}
|
|
159
|
+
const REVOKED_OUTPUT_TEXT_MARKER = '[revoked-source analysis redacted (PRI-1283 R3)]';
|
|
160
|
+
/**
|
|
161
|
+
* Remove revoked-source evidence arrays from a parsed diagnosis output
|
|
162
|
+
* (runs.output_payload bare V2 / router envelope, artifacts, pi_artifacts).
|
|
163
|
+
* The two persisted evidence locations are the top-level `evidence` array
|
|
164
|
+
* (DiagnosticianOutputV2) and the legacy `rootCause.evidence` object shape.
|
|
165
|
+
*
|
|
166
|
+
* Directive C2 ("无法安全拆分的字段应使受影响内容不可用"): an output that
|
|
167
|
+
* LOST revoked evidence entries is an affected output — its model-authored
|
|
168
|
+
* free text (`summary`, the string `rootCause` analysis, `ambiguityNotes`)
|
|
169
|
+
* was derived OVER that revoked material and cannot be proven clean, so the
|
|
170
|
+
* analysis prose is replaced with a neutral marker (the rootCause category
|
|
171
|
+
* prefix is preserved — it is the business classification, not source text).
|
|
172
|
+
* Structure, ids, recommendations and unaffected runs are untouched.
|
|
173
|
+
* Returns null when nothing changed (no write needed).
|
|
174
|
+
*/
|
|
175
|
+
function filterDiagnosisOutputEvidence(parsed, logicalKeyPrefix) {
|
|
176
|
+
if (!isRecord(parsed))
|
|
177
|
+
return null;
|
|
178
|
+
const next = { ...parsed };
|
|
179
|
+
let removed = 0;
|
|
180
|
+
const topLevel = filterEvidenceArray(next.evidence, logicalKeyPrefix);
|
|
181
|
+
if (topLevel !== null && topLevel.removed > 0) {
|
|
182
|
+
next.evidence = topLevel.kept;
|
|
183
|
+
removed += topLevel.removed;
|
|
184
|
+
}
|
|
185
|
+
if (isRecord(next.rootCause)) {
|
|
186
|
+
const parent = next.rootCause;
|
|
187
|
+
const nested = filterEvidenceArray(parent.evidence, logicalKeyPrefix);
|
|
188
|
+
if (nested !== null && nested.removed > 0) {
|
|
189
|
+
next.rootCause = { ...parent, evidence: nested.kept };
|
|
190
|
+
removed += nested.removed;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (removed === 0)
|
|
194
|
+
return null;
|
|
195
|
+
// Affected output: the model-authored prose derived over the revoked
|
|
196
|
+
// evidence is made unavailable (it may quote the source verbatim and
|
|
197
|
+
// cannot be split per-source).
|
|
198
|
+
if (typeof next.summary === 'string' && next.summary.length > 0) {
|
|
199
|
+
next.summary = REVOKED_OUTPUT_TEXT_MARKER;
|
|
200
|
+
}
|
|
201
|
+
if (typeof next.rootCause === 'string' && next.rootCause.length > 0) {
|
|
202
|
+
const colon = next.rootCause.indexOf(':');
|
|
203
|
+
const category = colon > 0 ? next.rootCause.slice(0, colon).trim() : '';
|
|
204
|
+
next.rootCause = `${category}${category.length > 0 ? ': ' : ''}${REVOKED_OUTPUT_TEXT_MARKER}`;
|
|
205
|
+
}
|
|
206
|
+
if (Array.isArray(next.ambiguityNotes) && next.ambiguityNotes.length > 0) {
|
|
207
|
+
delete next.ambiguityNotes;
|
|
208
|
+
}
|
|
209
|
+
return { next, removed };
|
|
210
|
+
}
|
|
211
|
+
// ── marker provenance classification (directive B) ──────────────────────────
|
|
212
|
+
const ADMISSION_REDACTED_REASON = 'source revoked — redacted (PRI-1283 R3)';
|
|
213
|
+
/**
|
|
214
|
+
* Classify one admission marker by its OWN persisted facts — never by
|
|
215
|
+
* hostKind alone (directive B1). Explicit Owner statements (classification
|
|
216
|
+
* 'owner_statement', an explicit channel, or the explicit reason marker) are
|
|
217
|
+
* Owner acts and survive the revocation; pending rows are terminated;
|
|
218
|
+
* everything else automatic is redacted; an unparseable payload is
|
|
219
|
+
* unattributable and redacted wholesale (fail-closed, B3).
|
|
220
|
+
*/
|
|
221
|
+
function classifyAdmissionMarker(row) {
|
|
222
|
+
const payloadText = typeof row.task_payload_json === 'string' ? row.task_payload_json : '';
|
|
223
|
+
const decision = typeof row.decision === 'string' ? row.decision : '';
|
|
224
|
+
const reasonColumn = typeof row.reason === 'string' ? row.reason : '';
|
|
225
|
+
if (decision === 'pending_llm_review') {
|
|
226
|
+
return { kind: 'pending', payload: null, payloadText };
|
|
227
|
+
}
|
|
228
|
+
if (payloadText.length === 0) {
|
|
229
|
+
// No payload: classify by the reason column alone.
|
|
230
|
+
return { kind: isOwnerExplicitStatementReason(reasonColumn) ? 'owner_explicit' : 'automatic', payload: null, payloadText };
|
|
231
|
+
}
|
|
232
|
+
let parsed;
|
|
233
|
+
try {
|
|
234
|
+
parsed = JSON.parse(payloadText);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
return { kind: 'unattributable', payload: null, payloadText };
|
|
238
|
+
}
|
|
239
|
+
if (!isRecord(parsed)) {
|
|
240
|
+
return { kind: 'unattributable', payload: null, payloadText };
|
|
241
|
+
}
|
|
242
|
+
const correction = parsed.correctionEvidence;
|
|
243
|
+
if (isRecord(correction)) {
|
|
244
|
+
// PRI-1283 round 3: when the structured correction record exists, ITS
|
|
245
|
+
// content-binding judgment is authoritative — a failing Owner
|
|
246
|
+
// confirmation (or none) is Agent-derived even when the reason string
|
|
247
|
+
// still carries the legacy owner marker (confirmation must bind to the
|
|
248
|
+
// final submitted content, not to a reason claim).
|
|
249
|
+
return { kind: isOwnerManualCorrectionEvidence(correction) ? 'owner_explicit' : 'automatic', payload: parsed, payloadText };
|
|
250
|
+
}
|
|
251
|
+
if (isOwnerExplicitStatementReason(typeof parsed.reason === 'string' ? parsed.reason : '')
|
|
252
|
+
|| isOwnerExplicitStatementReason(reasonColumn)) {
|
|
253
|
+
return { kind: 'owner_explicit', payload: parsed, payloadText };
|
|
254
|
+
}
|
|
255
|
+
return { kind: 'automatic', payload: parsed, payloadText };
|
|
256
|
+
}
|
|
257
|
+
/** Minimal terminal payload for a terminated pending review (D6 field set). */
|
|
258
|
+
function revokedPendingTerminalPayload(attempts, nowIso) {
|
|
259
|
+
return JSON.stringify({
|
|
260
|
+
decision: 'abandoned',
|
|
261
|
+
reason: 'source_revoked',
|
|
262
|
+
confidence: null,
|
|
263
|
+
attempts,
|
|
264
|
+
settledAt: nowIso,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function sweepTrajectoryDb(args) {
|
|
268
|
+
const { dbPath, hostKind, apply, nowIso } = args;
|
|
269
|
+
const counts = emptyCounts();
|
|
270
|
+
const failures = [];
|
|
271
|
+
const notApplicable = [];
|
|
272
|
+
let db;
|
|
273
|
+
try {
|
|
274
|
+
// Directive E2: a dry run opens trajectory.db READ-ONLY (fileMustExist —
|
|
275
|
+
// a sweep never creates a database) and pins query_only ON; no WAL/journal
|
|
276
|
+
// pragma is touched, so the file bytes cannot change.
|
|
277
|
+
db = apply
|
|
278
|
+
? new Database(dbPath)
|
|
279
|
+
: new Database(dbPath, { readonly: true, fileMustExist: true });
|
|
280
|
+
db.pragma('busy_timeout = 5000');
|
|
281
|
+
if (!apply)
|
|
282
|
+
db.pragma('query_only = ON');
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
return { error: `trajectory_open_failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
286
|
+
}
|
|
287
|
+
const automaticPainIds = [];
|
|
288
|
+
try {
|
|
289
|
+
// Directive E4: each step guards on its OWN table; a missing table is
|
|
290
|
+
// recorded as not_applicable for that table only and every other table
|
|
291
|
+
// still sweeps. No early return short of a hard failure.
|
|
292
|
+
const tableExists = (name) => db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(name) !== undefined;
|
|
293
|
+
// 1. Governance observations: NULL the text columns, mark expired.
|
|
294
|
+
if (!tableExists('governance_observations')) {
|
|
295
|
+
notApplicable.push('governance_observations');
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const observationIds = db.prepare("SELECT id FROM governance_observations WHERE host_kind = ? AND retention_class IN ('operational', 'promoted')").all(hostKind);
|
|
299
|
+
if (apply && observationIds.length > 0) {
|
|
300
|
+
const purge = db.transaction(() => {
|
|
301
|
+
const stmt = db.prepare("UPDATE governance_observations SET visible_text = NULL, sanitized_tool_facts_json = NULL, retention_class = 'expired', expired_at = ? WHERE id = ? AND retention_class IN ('operational', 'promoted')");
|
|
302
|
+
// Directive E5: count comes from actual successful row updates.
|
|
303
|
+
for (const row of observationIds) {
|
|
304
|
+
if (stmt.run(nowIso, row.id).changes === 1)
|
|
305
|
+
counts.governanceObservations += 1;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
purge();
|
|
309
|
+
}
|
|
310
|
+
else if (observationIds.length > 0) {
|
|
311
|
+
counts.governanceObservations = observationIds.length;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// 2. Admission markers — per-marker provenance classification.
|
|
315
|
+
if (!tableExists('governance_signal_admissions')) {
|
|
316
|
+
notApplicable.push('governance_signal_admissions');
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
const markers = db.prepare('SELECT id, decision, reason, task_payload_json, canonical_pain_id, host_kind FROM governance_signal_admissions WHERE host_kind = ?').all(hostKind);
|
|
320
|
+
for (const marker of markers) {
|
|
321
|
+
const classification = classifyAdmissionMarker(marker);
|
|
322
|
+
if (classification.kind === 'owner_explicit') {
|
|
323
|
+
// Directive B: an explicit Owner submission is an Owner act, not
|
|
324
|
+
// conversation ingestion — marker, reason and its canonical pain
|
|
325
|
+
// (excluded from the purge set below) all survive the revocation.
|
|
326
|
+
counts.preservedOwnerStatements += 1;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (classification.kind === 'pending') {
|
|
330
|
+
// Directive A3: terminate the pending review — the row becomes
|
|
331
|
+
// unclaimable and the nested trigger/task_payload copies are
|
|
332
|
+
// dropped by the D6 minimal terminal payload.
|
|
333
|
+
const attempts = (() => {
|
|
334
|
+
try {
|
|
335
|
+
const parsed = JSON.parse(classification.payloadText);
|
|
336
|
+
const review = isRecord(parsed) && isRecord(parsed.review) ? parsed.review : null;
|
|
337
|
+
return review !== null && typeof review.attempts === 'number' && Number.isSafeInteger(review.attempts) ? review.attempts : 0;
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
return 0;
|
|
341
|
+
}
|
|
342
|
+
})();
|
|
343
|
+
if (apply) {
|
|
344
|
+
const { changes } = db.prepare(`UPDATE governance_signal_admissions SET decision = 'abandoned', reason = 'source_revoked', task_payload_json = ?, updated_at = ?
|
|
345
|
+
WHERE id = ? AND decision = 'pending_llm_review' AND task_payload_json IS ?`).run(revokedPendingTerminalPayload(attempts, nowIso), nowIso, marker.id, classification.payloadText);
|
|
346
|
+
if (changes === 1)
|
|
347
|
+
counts.pendingReviewsTerminated += 1;
|
|
348
|
+
else
|
|
349
|
+
failures.push(`admission_${marker.id}: pending termination lost a race — skipped (rerun the sweep)`);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
counts.pendingReviewsTerminated += 1;
|
|
353
|
+
}
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (classification.kind === 'unattributable') {
|
|
357
|
+
// Fail-closed (B3/A2.6): a payload whose provenance cannot be
|
|
358
|
+
// confirmed is redacted wholesale — never preserved on a guess.
|
|
359
|
+
if (apply) {
|
|
360
|
+
const { changes } = db.prepare('UPDATE governance_signal_admissions SET task_payload_json = ?, reason = ?, updated_at = ? WHERE id = ? AND task_payload_json IS ? AND reason IS ?').run(JSON.stringify({ redacted: 'source_revoked' }), ADMISSION_REDACTED_REASON, nowIso, marker.id, classification.payloadText, marker.reason);
|
|
361
|
+
if (changes === 1)
|
|
362
|
+
counts.unattributableMarkers += 1;
|
|
363
|
+
else
|
|
364
|
+
failures.push(`admission_${marker.id}: wholesale redaction lost a race — skipped (rerun the sweep)`);
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
counts.unattributableMarkers += 1;
|
|
368
|
+
}
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
// Automatic admitted/resolved marker: redact payload copies AND the
|
|
372
|
+
// independent reason column (C4 — the reason quotes detected terms).
|
|
373
|
+
const { payload, payloadText } = classification;
|
|
374
|
+
const nextPayload = payload !== null ? { ...payload } : {};
|
|
375
|
+
let payloadChanged = false;
|
|
376
|
+
if (payload !== null) {
|
|
377
|
+
if (Array.isArray(nextPayload.evidence) && nextPayload.evidence.length > 0) {
|
|
378
|
+
nextPayload.evidence = [];
|
|
379
|
+
payloadChanged = true;
|
|
380
|
+
}
|
|
381
|
+
if (nextPayload.correctionEvidence !== undefined) {
|
|
382
|
+
delete nextPayload.correctionEvidence;
|
|
383
|
+
payloadChanged = true;
|
|
384
|
+
}
|
|
385
|
+
if (typeof nextPayload.reason === 'string' && nextPayload.reason.length > 0 && nextPayload.reason !== ADMISSION_REDACTED_REASON) {
|
|
386
|
+
nextPayload.reason = ADMISSION_REDACTED_REASON;
|
|
387
|
+
payloadChanged = true;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const reasonNeedsRedaction = marker.reason !== null && marker.reason.length > 0 && marker.reason !== ADMISSION_REDACTED_REASON;
|
|
391
|
+
if (apply) {
|
|
392
|
+
const { changes } = db.prepare('UPDATE governance_signal_admissions SET task_payload_json = ?, reason = ?, updated_at = ? WHERE id = ? AND task_payload_json IS ? AND reason IS ?').run(payloadChanged ? JSON.stringify(nextPayload) : payloadText, reasonNeedsRedaction ? ADMISSION_REDACTED_REASON : marker.reason, nowIso, marker.id, payloadText, marker.reason);
|
|
393
|
+
if (changes === 1) {
|
|
394
|
+
if (payloadChanged)
|
|
395
|
+
counts.admissionPayloads += 1;
|
|
396
|
+
if (reasonNeedsRedaction)
|
|
397
|
+
counts.admissionReasons += 1;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
failures.push(`admission_${marker.id}: redaction lost a race — skipped (rerun the sweep)`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
if (payloadChanged)
|
|
405
|
+
counts.admissionPayloads += 1;
|
|
406
|
+
if (reasonNeedsRedaction)
|
|
407
|
+
counts.admissionReasons += 1;
|
|
408
|
+
}
|
|
409
|
+
if (typeof marker.canonical_pain_id === 'string' && marker.canonical_pain_id.length > 0) {
|
|
410
|
+
automaticPainIds.push(marker.canonical_pain_id);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// 3. pain_events of the host's AUTOMATIC admitted pains: NULL text/reason.
|
|
415
|
+
if (!tableExists('pain_events')) {
|
|
416
|
+
notApplicable.push('pain_events');
|
|
417
|
+
}
|
|
418
|
+
else if (automaticPainIds.length > 0) {
|
|
419
|
+
const placeholders = automaticPainIds.map(() => '?').join(',');
|
|
420
|
+
const targets = (db.prepare(`SELECT canonical_pain_id FROM pain_events WHERE canonical_pain_id IN (${placeholders}) AND (text IS NOT NULL OR reason IS NOT NULL)`).all(...automaticPainIds));
|
|
421
|
+
if (apply && targets.length > 0) {
|
|
422
|
+
const purge = db.transaction(() => {
|
|
423
|
+
const stmt = db.prepare(`UPDATE pain_events SET text = NULL, reason = NULL WHERE canonical_pain_id = ? AND (text IS NOT NULL OR reason IS NOT NULL)`);
|
|
424
|
+
for (const target of targets) {
|
|
425
|
+
if (stmt.run(target.canonical_pain_id).changes >= 1)
|
|
426
|
+
counts.painEventTexts += 1;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
purge();
|
|
430
|
+
}
|
|
431
|
+
else if (targets.length > 0) {
|
|
432
|
+
counts.painEventTexts = targets.length;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return { counts, failures, notApplicable, automaticPainIds };
|
|
436
|
+
}
|
|
437
|
+
catch (error) {
|
|
438
|
+
failures.push(`trajectory_step_failed: ${error instanceof Error ? error.message.slice(0, 160) : String(error).slice(0, 160)}`);
|
|
439
|
+
return { counts, failures, notApplicable, automaticPainIds };
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
try {
|
|
443
|
+
db.close();
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
// closing must not mask the sweep outcome
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
async function sweepStateDb(args) {
|
|
451
|
+
const { workspaceDir, hostKind, logicalKeyPrefix, apply, nowIso, decidedAt } = args;
|
|
452
|
+
const counts = emptyCounts();
|
|
453
|
+
const failures = [];
|
|
454
|
+
const notApplicable = [];
|
|
455
|
+
const stateDbPath = resolveStateDbPath(workspaceDir);
|
|
456
|
+
if (!fs.existsSync(stateDbPath)) {
|
|
457
|
+
notApplicable.push('state.db');
|
|
458
|
+
return { counts, failures, notApplicable };
|
|
459
|
+
}
|
|
460
|
+
// Directive E1/E2: a DRY RUN must not run RuntimeStateManager.initialize()
|
|
461
|
+
// (schema init / migrations / WAL pragmas are writes). Open state.db with a
|
|
462
|
+
// plain readonly connection instead — the dry run only SELECTs. Applying
|
|
463
|
+
// keeps the manager so task rows go through its CAS authority.
|
|
464
|
+
const stateManager = apply ? new RuntimeStateManager({ workspaceDir }) : null;
|
|
465
|
+
let db;
|
|
466
|
+
if (stateManager !== null) {
|
|
467
|
+
await stateManager.initialize();
|
|
468
|
+
db = stateManager.connection.getDb();
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
db = new Database(stateDbPath, { readonly: true, fileMustExist: true });
|
|
472
|
+
db.pragma('busy_timeout = 5000');
|
|
473
|
+
db.pragma('query_only = ON');
|
|
474
|
+
}
|
|
475
|
+
try {
|
|
476
|
+
const likePattern = `%${GOVERNANCE_OBSERVATION_SOURCE_REF_PREFIX}${logicalKeyPrefix}%`;
|
|
477
|
+
const tableExists = (name) => db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(name) !== undefined;
|
|
478
|
+
// 4. tasks.diagnostic_json — via the manager's CAS authority.
|
|
479
|
+
if (!tableExists('tasks')) {
|
|
480
|
+
notApplicable.push('tasks');
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
// Two candidate sets: (a) rows carrying this host's persisted source
|
|
484
|
+
// refs; (b) rows carrying ANY correctionEvidence — legacy agent-assisted
|
|
485
|
+
// submissions can persist the governed statement text with no session
|
|
486
|
+
// sourceRef at all, and the per-row governed check below decides.
|
|
487
|
+
const taskRows = (db.prepare("SELECT task_id, diagnostic_json FROM tasks WHERE diagnostic_json LIKE ? OR diagnostic_json LIKE '%correctionEvidence%' OR diagnostic_json LIKE '%agent_assisted%' OR diagnostic_json LIKE '%codex_explicit_agent%'").all(likePattern));
|
|
488
|
+
for (const row of taskRows) {
|
|
489
|
+
if (typeof row.diagnostic_json !== 'string')
|
|
490
|
+
continue;
|
|
491
|
+
let payload;
|
|
492
|
+
try {
|
|
493
|
+
payload = JSON.parse(row.diagnostic_json);
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
// Not ours to rewrite blindly; leave the byte content but record it.
|
|
497
|
+
failures.push(`task_${row.task_id}: diagnostic_json unparseable — left untouched`);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
if (!isRecord(payload))
|
|
501
|
+
continue;
|
|
502
|
+
const next = { ...payload };
|
|
503
|
+
let changed = false;
|
|
504
|
+
let removedEvidenceEntries = 0;
|
|
505
|
+
let removedCorrectionBlocks = 0;
|
|
506
|
+
const evidenceResult = filterEvidenceArray(next.evidence, logicalKeyPrefix);
|
|
507
|
+
if (evidenceResult !== null && evidenceResult.removed > 0) {
|
|
508
|
+
next.evidence = evidenceResult.kept;
|
|
509
|
+
removedEvidenceEntries = evidenceResult.removed;
|
|
510
|
+
changed = true;
|
|
511
|
+
}
|
|
512
|
+
// Governed correction evidence (channel prefix or codex/workbuddy task
|
|
513
|
+
// host) — an OWNER-EXPLICIT channel is an Owner act and is KEPT
|
|
514
|
+
// (directive B: the sweep must not purge explicit Owner statements).
|
|
515
|
+
const correction = next.correctionEvidence;
|
|
516
|
+
if (isRecord(correction)) {
|
|
517
|
+
const channel = typeof correction.channel === 'string' ? correction.channel : '';
|
|
518
|
+
const taskHost = typeof next.hostKind === 'string' ? next.hostKind : '';
|
|
519
|
+
const governed = !isOwnerManualCorrectionEvidence(correction)
|
|
520
|
+
&& (channel.startsWith(hostKind) || (channel.length === 0 && (taskHost === 'codex' || taskHost === 'workbuddy') && taskHost === hostKind));
|
|
521
|
+
if (governed) {
|
|
522
|
+
delete next.correctionEvidence;
|
|
523
|
+
removedCorrectionBlocks = 1;
|
|
524
|
+
changed = true;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
// Keep the v1 evidence class truthful, including an agent-assisted
|
|
528
|
+
// bundle that was already unavailable/empty before the sweep.
|
|
529
|
+
// The durable origin survives deletion of correctionEvidence.
|
|
530
|
+
const ingress = next.painIngress;
|
|
531
|
+
const origin = isRecord(ingress) && isRecord(ingress.origin) ? ingress.origin : null;
|
|
532
|
+
const agentDerivedCodexIngress = hostKind === 'codex'
|
|
533
|
+
&& !isOwnerManualCorrectionEvidence(correction)
|
|
534
|
+
&& (origin?.kind === 'agent_assisted'
|
|
535
|
+
|| (origin?.kind === 'owner_manual' && origin.channel === 'codex_explicit_agent')
|
|
536
|
+
|| (isRecord(correction) && correction.channel === 'codex_explicit_agent'));
|
|
537
|
+
if (isRecord(ingress)) {
|
|
538
|
+
const remaining = Array.isArray(next.evidence) ? next.evidence.length : 0;
|
|
539
|
+
const currentClass = isRecord(ingress.evidenceClass) ? ingress.evidenceClass : null;
|
|
540
|
+
const computed = agentDerivedCodexIngress
|
|
541
|
+
? (remaining > 0
|
|
542
|
+
? { status: 'available', entryCount: remaining }
|
|
543
|
+
: { status: 'unavailable', reason: 'source_revoked' })
|
|
544
|
+
: currentClass?.status === 'available'
|
|
545
|
+
? (remaining > 0
|
|
546
|
+
? { status: 'available', entryCount: remaining }
|
|
547
|
+
: { status: 'unavailable', reason: 'source_revoked' })
|
|
548
|
+
: null;
|
|
549
|
+
// Idempotence: only mark changed when the recomputed class differs.
|
|
550
|
+
if (computed !== null && JSON.stringify(computed) !== JSON.stringify(currentClass)) {
|
|
551
|
+
next.painIngress = { ...ingress, evidenceClass: computed };
|
|
552
|
+
changed = true;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
// Even an empty Agent-derived task needs a durable tombstone. This
|
|
556
|
+
// makes revocation irreversible for the old payload after re-grant.
|
|
557
|
+
const existingAudit = isRecord(next.sourceRevocation) ? next.sourceRevocation : {};
|
|
558
|
+
if (agentDerivedCodexIngress && !isRecord(existingAudit.codex))
|
|
559
|
+
changed = true;
|
|
560
|
+
if (changed) {
|
|
561
|
+
// Non-sensitive audit metadata: verdict + counts + time (no text).
|
|
562
|
+
const priorAudit = isRecord(next.sourceRevocation) ? next.sourceRevocation : {};
|
|
563
|
+
next.sourceRevocation = {
|
|
564
|
+
...priorAudit,
|
|
565
|
+
schemaVersion: 1,
|
|
566
|
+
[hostKind]: { decidedAt, sweptAt: nowIso, purgedEvidenceEntries: removedEvidenceEntries },
|
|
567
|
+
};
|
|
568
|
+
if (apply && stateManager !== null) {
|
|
569
|
+
let written = false;
|
|
570
|
+
for (let attempt = 0; attempt < 3 && !written; attempt += 1) {
|
|
571
|
+
try {
|
|
572
|
+
const current = await stateManager.getTask(row.task_id);
|
|
573
|
+
const currentJson = current !== null && typeof current.diagnosticJson === 'string' ? current.diagnosticJson : row.diagnostic_json;
|
|
574
|
+
if (currentJson !== row.diagnostic_json) {
|
|
575
|
+
// Concurrent writer changed the payload — re-evaluate this task
|
|
576
|
+
// on a rerun instead of forcing our snapshot (rc-7).
|
|
577
|
+
failures.push(`task_${row.task_id}: diagnostic_json changed concurrently — skipped (rerun the sweep)`);
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
const result = await stateManager.updateTaskIfDiagnosticJsonUnchanged(row.task_id, currentJson, {
|
|
581
|
+
diagnosticJson: JSON.stringify(next),
|
|
582
|
+
});
|
|
583
|
+
written = result !== null;
|
|
584
|
+
if (!written) {
|
|
585
|
+
// CAS lost a race; loop re-reads the fresh value above.
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
failures.push(`task_${row.task_id}: ${(error instanceof Error ? error.message : String(error)).slice(0, 160)}`);
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
// Directive E5: only successful writes contribute counts.
|
|
595
|
+
if (written) {
|
|
596
|
+
counts.tasks += 1;
|
|
597
|
+
counts.taskEvidenceEntries += removedEvidenceEntries;
|
|
598
|
+
counts.taskCorrectionEvidence += removedCorrectionBlocks;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
counts.tasks += 1;
|
|
603
|
+
counts.taskEvidenceEntries += removedEvidenceEntries;
|
|
604
|
+
counts.taskCorrectionEvidence += removedCorrectionBlocks;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
// 5. pain_diagnoses.evidence_json — row-level CAS rewrite.
|
|
610
|
+
if (!tableExists('pain_diagnoses')) {
|
|
611
|
+
notApplicable.push('pain_diagnoses');
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
const diagnosisRows = (db.prepare('SELECT id, evidence_json FROM pain_diagnoses WHERE evidence_json LIKE ?').all(likePattern));
|
|
615
|
+
for (const row of diagnosisRows) {
|
|
616
|
+
if (typeof row.evidence_json !== 'string')
|
|
617
|
+
continue;
|
|
618
|
+
let parsed;
|
|
619
|
+
try {
|
|
620
|
+
parsed = JSON.parse(row.evidence_json);
|
|
621
|
+
}
|
|
622
|
+
catch {
|
|
623
|
+
failures.push(`pain_diagnoses_${row.id}: evidence_json unparseable — left untouched`);
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
const filtered = filterEvidenceArray(parsed, logicalKeyPrefix);
|
|
627
|
+
if (filtered === null || filtered.removed === 0)
|
|
628
|
+
continue;
|
|
629
|
+
if (apply) {
|
|
630
|
+
const result = db.prepare('UPDATE pain_diagnoses SET evidence_json = ? WHERE id = ? AND evidence_json = ?')
|
|
631
|
+
.run(JSON.stringify(filtered.kept), row.id, row.evidence_json);
|
|
632
|
+
if (result.changes === 1) {
|
|
633
|
+
counts.painDiagnoses += 1;
|
|
634
|
+
counts.painDiagnosesEvidenceEntries += filtered.removed;
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
failures.push(`pain_diagnoses_${row.id}: concurrent change — skipped (rerun the sweep)`);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
counts.painDiagnoses += 1;
|
|
642
|
+
counts.painDiagnosesEvidenceEntries += filtered.removed;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
// 6. diagnostician_output artifacts — row-level CAS rewrite.
|
|
647
|
+
if (!tableExists('artifacts')) {
|
|
648
|
+
notApplicable.push('artifacts');
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
const artifactRows = (db.prepare("SELECT artifact_id, content_json FROM artifacts WHERE artifact_kind = 'diagnostician_output' AND content_json LIKE ?").all(likePattern));
|
|
652
|
+
for (const row of artifactRows) {
|
|
653
|
+
if (typeof row.content_json !== 'string')
|
|
654
|
+
continue;
|
|
655
|
+
let parsed;
|
|
656
|
+
try {
|
|
657
|
+
parsed = JSON.parse(row.content_json);
|
|
658
|
+
}
|
|
659
|
+
catch {
|
|
660
|
+
failures.push(`artifact_${row.artifact_id}: content_json unparseable — left untouched`);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
const filtered = filterDiagnosisOutputEvidence(parsed, logicalKeyPrefix);
|
|
664
|
+
if (filtered === null)
|
|
665
|
+
continue;
|
|
666
|
+
if (apply) {
|
|
667
|
+
const result = db.prepare('UPDATE artifacts SET content_json = ? WHERE artifact_id = ? AND content_json = ?')
|
|
668
|
+
.run(JSON.stringify(filtered.next), row.artifact_id, row.content_json);
|
|
669
|
+
if (result.changes === 1) {
|
|
670
|
+
counts.artifacts += 1;
|
|
671
|
+
counts.artifactEvidenceEntries += filtered.removed;
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
failures.push(`artifact_${row.artifact_id}: concurrent change — skipped (rerun the sweep)`);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
counts.artifacts += 1;
|
|
679
|
+
counts.artifactEvidenceEntries += filtered.removed;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
// 7. runs.output_payload — the bare V2 output (or router envelope) embeds
|
|
684
|
+
// the same evidence notes (directive C2). Execution status and run
|
|
685
|
+
// metadata are untouched — only the revoked evidence entries leave.
|
|
686
|
+
if (!tableExists('runs')) {
|
|
687
|
+
notApplicable.push('runs');
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
const runRows = (db.prepare('SELECT run_id, output_payload FROM runs WHERE output_payload LIKE ?').all(likePattern));
|
|
691
|
+
for (const row of runRows) {
|
|
692
|
+
if (typeof row.output_payload !== 'string')
|
|
693
|
+
continue;
|
|
694
|
+
let parsed;
|
|
695
|
+
try {
|
|
696
|
+
parsed = JSON.parse(row.output_payload);
|
|
697
|
+
}
|
|
698
|
+
catch {
|
|
699
|
+
failures.push(`run_${row.run_id}: output_payload unparseable — left untouched`);
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const filtered = filterDiagnosisOutputEvidence(parsed, logicalKeyPrefix);
|
|
703
|
+
if (filtered === null)
|
|
704
|
+
continue;
|
|
705
|
+
if (apply) {
|
|
706
|
+
const result = db.prepare('UPDATE runs SET output_payload = ? WHERE run_id = ? AND output_payload = ?')
|
|
707
|
+
.run(JSON.stringify(filtered.next), row.run_id, row.output_payload);
|
|
708
|
+
if (result.changes === 1) {
|
|
709
|
+
counts.runs += 1;
|
|
710
|
+
counts.runEvidenceEntries += filtered.removed;
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
failures.push(`run_${row.run_id}: concurrent change — skipped (rerun the sweep)`);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
counts.runs += 1;
|
|
718
|
+
counts.runEvidenceEntries += filtered.removed;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
// 8. pi_artifacts.content_json — the internalization chain's artifact
|
|
723
|
+
// copies carry the same evidence arrays (directive C3).
|
|
724
|
+
if (!tableExists('pi_artifacts')) {
|
|
725
|
+
notApplicable.push('pi_artifacts');
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
const piRows = (db.prepare('SELECT artifact_id, content_json FROM pi_artifacts WHERE content_json LIKE ?').all(likePattern));
|
|
729
|
+
for (const row of piRows) {
|
|
730
|
+
if (typeof row.content_json !== 'string')
|
|
731
|
+
continue;
|
|
732
|
+
let parsed;
|
|
733
|
+
try {
|
|
734
|
+
parsed = JSON.parse(row.content_json);
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
failures.push(`pi_artifact_${row.artifact_id}: content_json unparseable — left untouched`);
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
const filtered = filterDiagnosisOutputEvidence(parsed, logicalKeyPrefix);
|
|
741
|
+
if (filtered === null)
|
|
742
|
+
continue;
|
|
743
|
+
if (apply) {
|
|
744
|
+
const result = db.prepare('UPDATE pi_artifacts SET content_json = ? WHERE artifact_id = ? AND content_json = ?')
|
|
745
|
+
.run(JSON.stringify(filtered.next), row.artifact_id, row.content_json);
|
|
746
|
+
if (result.changes === 1) {
|
|
747
|
+
counts.piArtifacts += 1;
|
|
748
|
+
counts.piArtifactEvidenceEntries += filtered.removed;
|
|
749
|
+
}
|
|
750
|
+
else {
|
|
751
|
+
failures.push(`pi_artifact_${row.artifact_id}: concurrent change — skipped (rerun the sweep)`);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
counts.piArtifacts += 1;
|
|
756
|
+
counts.piArtifactEvidenceEntries += filtered.removed;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return { counts, failures, notApplicable };
|
|
761
|
+
}
|
|
762
|
+
catch (error) {
|
|
763
|
+
failures.push(`state_db_step_failed: ${(error instanceof Error ? error.message : String(error)).slice(0, 160)}`);
|
|
764
|
+
return { counts, failures, notApplicable };
|
|
765
|
+
}
|
|
766
|
+
finally {
|
|
767
|
+
if (stateManager !== null) {
|
|
768
|
+
await stateManager.close().catch(() => undefined);
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
try {
|
|
772
|
+
db.close();
|
|
773
|
+
}
|
|
774
|
+
catch {
|
|
775
|
+
// closing must not mask the sweep outcome
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
// ── Entry point ──────────────────────────────────────────────────────────────
|
|
781
|
+
const CHECKED_ONLY_LOCATIONS = [
|
|
782
|
+
'principle_candidates (model-authored text; no source excerpts)',
|
|
783
|
+
'principle ledger reuseEvidence/derivedFromPainIds (ID metadata only)',
|
|
784
|
+
'governance_pending_promotion_tails / governance_transcript_checkpoints (progress metadata, no text)',
|
|
785
|
+
];
|
|
786
|
+
function mergeCounts(target, source) {
|
|
787
|
+
for (const key of Object.keys(source)) {
|
|
788
|
+
const value = source[key];
|
|
789
|
+
if (typeof value === 'number')
|
|
790
|
+
target[key] += value;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
export async function runSourceRevocationSweep(options) {
|
|
794
|
+
const workspaceDir = path.resolve(options.workspaceDir);
|
|
795
|
+
const apply = options.apply === true;
|
|
796
|
+
const now = options.now ?? (() => new Date());
|
|
797
|
+
const ranAt = now().toISOString();
|
|
798
|
+
const stateDir = path.join(workspaceDir, '.state');
|
|
799
|
+
// Which hosts carry a recorded NON-GRANTED decision? A missing or unreadable
|
|
800
|
+
// ledger is not a revocation — nothing is swept (fail-safe; R2 read gates
|
|
801
|
+
// still block), and the report says so loudly.
|
|
802
|
+
const hostReports = [];
|
|
803
|
+
let ledgerUnreadable = false;
|
|
804
|
+
const toSweep = [];
|
|
805
|
+
for (const hostKind of ['codex', 'workbuddy', 'openclaw']) {
|
|
806
|
+
const read = readConversationIngestionConsent(workspaceDir, hostKind);
|
|
807
|
+
if (!read.ok) {
|
|
808
|
+
ledgerUnreadable = true;
|
|
809
|
+
continue;
|
|
810
|
+
}
|
|
811
|
+
const { record } = read;
|
|
812
|
+
if (record === null)
|
|
813
|
+
continue;
|
|
814
|
+
if (record.decision === 'granted' || record.decision === 'pending' || record.decision === 'failed' || record.decision === 'revoked') {
|
|
815
|
+
if (record.decision !== 'granted') {
|
|
816
|
+
toSweep.push({ hostKind, decidedAt: record.decidedAt });
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
if (ledgerUnreadable) {
|
|
821
|
+
return {
|
|
822
|
+
outcome: 'failed',
|
|
823
|
+
workspaceDir,
|
|
824
|
+
ranAt,
|
|
825
|
+
apply,
|
|
826
|
+
hosts: [],
|
|
827
|
+
reason: 'consent_ledger_unreadable: refusing to purge against an unreadable authority',
|
|
828
|
+
nextAction: 'Fix or delete <workspace>/.state/conversation-ingestion-consent.json, then rerun the sweep (R2 read gates stay blocking meanwhile).',
|
|
829
|
+
checkedOnly: CHECKED_ONLY_LOCATIONS,
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
if (toSweep.length === 0) {
|
|
833
|
+
return {
|
|
834
|
+
outcome: 'skipped',
|
|
835
|
+
workspaceDir,
|
|
836
|
+
ranAt,
|
|
837
|
+
apply,
|
|
838
|
+
hosts: [],
|
|
839
|
+
reason: 'no_host_with_non_granted_consent',
|
|
840
|
+
nextAction: 'Nothing to purge: every recorded consent decision is granted (or no record exists).',
|
|
841
|
+
checkedOnly: CHECKED_ONLY_LOCATIONS,
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
const trajectoryDbPath = path.join(stateDir, 'trajectory.db');
|
|
845
|
+
let outcome = 'completed';
|
|
846
|
+
for (const target of toSweep) {
|
|
847
|
+
const logicalKeyPrefix = HOST_LOGICAL_KEY_PREFIX[target.hostKind];
|
|
848
|
+
const purged = emptyCounts();
|
|
849
|
+
const failures = [];
|
|
850
|
+
const notApplicable = [];
|
|
851
|
+
if (fs.existsSync(trajectoryDbPath)) {
|
|
852
|
+
const trajResult = sweepTrajectoryDb({ dbPath: trajectoryDbPath, hostKind: target.hostKind, apply, nowIso: ranAt });
|
|
853
|
+
if ('error' in trajResult) {
|
|
854
|
+
failures.push(trajResult.error);
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
mergeCounts(purged, trajResult.counts);
|
|
858
|
+
failures.push(...trajResult.failures);
|
|
859
|
+
notApplicable.push(...trajResult.notApplicable);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
else {
|
|
863
|
+
notApplicable.push('trajectory.db');
|
|
864
|
+
}
|
|
865
|
+
const stateResult = await sweepStateDb({ workspaceDir, hostKind: target.hostKind, logicalKeyPrefix, apply, nowIso: ranAt, decidedAt: target.decidedAt });
|
|
866
|
+
mergeCounts(purged, stateResult.counts);
|
|
867
|
+
failures.push(...stateResult.failures);
|
|
868
|
+
notApplicable.push(...stateResult.notApplicable);
|
|
869
|
+
if (apply && purged.unattributableMarkers > 0) {
|
|
870
|
+
// Directive A2.6/B3: unattributable markers were redacted (fail-closed);
|
|
871
|
+
// the count is surfaced as a failure note so the report is explicit
|
|
872
|
+
// about what could not be proven and how it was treated.
|
|
873
|
+
failures.push(`admissions: ${purged.unattributableMarkers} marker payload(s) unparseable — redacted wholesale (provenance unprovable)`);
|
|
874
|
+
}
|
|
875
|
+
if (failures.length > 0)
|
|
876
|
+
outcome = 'partial';
|
|
877
|
+
let hostFailures = failures;
|
|
878
|
+
if (apply) {
|
|
879
|
+
const auditWritten = appendAuditLine(stateDir, {
|
|
880
|
+
schemaVersion: 1,
|
|
881
|
+
ranAt,
|
|
882
|
+
hostKind: target.hostKind,
|
|
883
|
+
decidedAt: target.decidedAt,
|
|
884
|
+
outcome: failures.length > 0 ? 'partial' : 'completed',
|
|
885
|
+
purged,
|
|
886
|
+
notApplicable,
|
|
887
|
+
failureCount: failures.length,
|
|
888
|
+
});
|
|
889
|
+
if (!auditWritten) {
|
|
890
|
+
// Directive E5: an audit write failure is reported, never swallowed.
|
|
891
|
+
outcome = 'partial';
|
|
892
|
+
hostFailures = [...failures, 'audit_write_failed: the sweep audit line could not be appended to .state/source-revocation-sweep.jsonl'];
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
hostReports.push({
|
|
896
|
+
hostKind: target.hostKind,
|
|
897
|
+
// decision value narrowed by toSweep construction
|
|
898
|
+
consentDecision: (() => {
|
|
899
|
+
const read = readConversationIngestionConsent(workspaceDir, target.hostKind);
|
|
900
|
+
const decision = read.ok && read.record !== null ? read.record.decision : 'revoked';
|
|
901
|
+
return decision === 'pending' || decision === 'failed' ? decision : 'revoked';
|
|
902
|
+
})(),
|
|
903
|
+
decidedAt: target.decidedAt,
|
|
904
|
+
swept: apply,
|
|
905
|
+
purged,
|
|
906
|
+
notApplicable,
|
|
907
|
+
failures: hostFailures,
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
if (outcome === 'partial') {
|
|
911
|
+
return {
|
|
912
|
+
outcome,
|
|
913
|
+
workspaceDir,
|
|
914
|
+
ranAt,
|
|
915
|
+
apply,
|
|
916
|
+
hosts: hostReports,
|
|
917
|
+
reason: 'sweep_partial_failures: one or more purge steps failed',
|
|
918
|
+
// cli-6-output-next-action: the retry must name the same workspaceDir —
|
|
919
|
+
// omitting `--workspace` would silently retarget the command at the
|
|
920
|
+
// default workspace (PRI-1283 review). A failed PREVIEW re-previews;
|
|
921
|
+
// only a failed apply suggests `--apply`.
|
|
922
|
+
nextAction: apply
|
|
923
|
+
? `Inspect the per-host failures above; the sweep is idempotent — fix the cause (lock, permission, torn JSON) and rerun \`pd consent sweep-revoked --workspace ${workspaceDir} --apply\` against the same workspace until it reports completed.`
|
|
924
|
+
: `Inspect the per-host failures above; fix the cause (lock, permission, torn JSON) and re-run the preview \`pd consent sweep-revoked --workspace ${workspaceDir}\` against the same workspace before applying.`,
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
return { outcome, workspaceDir, ranAt, apply, hosts: hostReports, reason: null };
|
|
928
|
+
}
|