create-principles-disciple 1.92.0 → 1.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/console/dist/server/config/AuthConfig.js +6 -0
- package/console/dist/server/config/pd-config-store.d.ts +7 -1
- package/console/dist/server/config/pd-config-store.js +11 -1
- package/console/dist/server/index.js +41 -22
- package/console/dist/server/models/ApprovalsConsoleModel.js +4 -12
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +6 -3
- package/console/dist/server/models/ConsoleLifecycleDatasource.js +1 -1
- package/console/dist/server/routes/activations.js +4 -0
- package/console/dist/server/routes/approvals.js +24 -4
- package/console/dist/server/routes/feedback-reports.js +7 -5
- package/console/dist/server/routes/lifecycle.js +6 -1
- package/console/dist/server/routes/principles.js +10 -2
- package/console/dist/server/routes/workspaces.js +4 -0
- package/console/dist/ui/components/ui/charts.js +4 -1
- package/console/dist/ui/components/ui/markdown.js +9 -5
- package/console/dist/ui/utils/enum-labels.js +4 -1
- package/console/dist/web/assets/app.js +5 -2
- package/core/dist/index.d.ts +2 -3
- package/core/dist/index.d.ts.map +1 -1
- package/core/dist/index.js +1 -3
- package/core/dist/index.js.map +1 -1
- package/core/dist/pain-signal.d.ts +11 -71
- package/core/dist/pain-signal.d.ts.map +1 -1
- package/core/dist/pain-signal.js +10 -120
- package/core/dist/pain-signal.js.map +1 -1
- package/core/dist/principle-tree-ledger.d.ts +4 -87
- package/core/dist/principle-tree-ledger.d.ts.map +1 -1
- package/core/dist/principle-tree-ledger.js +51 -148
- package/core/dist/principle-tree-ledger.js.map +1 -1
- package/core/dist/prompt-builder/__tests__/model-config.test.d.ts +2 -0
- package/core/dist/prompt-builder/__tests__/model-config.test.d.ts.map +1 -0
- package/core/dist/prompt-builder/__tests__/model-config.test.js +158 -0
- package/core/dist/prompt-builder/__tests__/model-config.test.js.map +1 -0
- package/core/dist/prompt-builder/__tests__/xml-escape.test.d.ts +2 -0
- package/core/dist/prompt-builder/__tests__/xml-escape.test.d.ts.map +1 -0
- package/core/dist/prompt-builder/__tests__/xml-escape.test.js +42 -0
- package/core/dist/prompt-builder/__tests__/xml-escape.test.js.map +1 -0
- package/core/dist/prompt-builder/index.d.ts +3 -0
- package/core/dist/prompt-builder/index.d.ts.map +1 -1
- package/core/dist/prompt-builder/index.js +2 -0
- package/core/dist/prompt-builder/index.js.map +1 -1
- package/core/dist/prompt-builder/model-config.d.ts +42 -0
- package/core/dist/prompt-builder/model-config.d.ts.map +1 -0
- package/core/dist/prompt-builder/model-config.js +84 -0
- package/core/dist/prompt-builder/model-config.js.map +1 -0
- package/core/dist/prompt-builder/xml-escape.d.ts +12 -0
- package/core/dist/prompt-builder/xml-escape.d.ts.map +1 -0
- package/core/dist/prompt-builder/xml-escape.js +19 -0
- package/core/dist/prompt-builder/xml-escape.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +265 -20
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.d.ts +12 -0
- package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.js +46 -0
- package/core/dist/runtime-v2/__tests__/barrel-io-cleanup.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/io-deletion.test.d.ts +12 -0
- package/core/dist/runtime-v2/__tests__/io-deletion.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/io-deletion.test.js +92 -0
- package/core/dist/runtime-v2/__tests__/io-deletion.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/ledger-codec.test.d.ts +2 -0
- package/core/dist/runtime-v2/__tests__/ledger-codec.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/ledger-codec.test.js +429 -0
- package/core/dist/runtime-v2/__tests__/ledger-codec.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/ledger-store.test.d.ts +2 -0
- package/core/dist/runtime-v2/__tests__/ledger-store.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/ledger-store.test.js +65 -0
- package/core/dist/runtime-v2/__tests__/ledger-store.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.d.ts +2 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js +395 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js +146 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.d.ts +2 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.js +150 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-unification.test.js.map +1 -0
- package/core/dist/runtime-v2/adapter/__tests__/test-double-runtime-adapter.test.js +199 -0
- package/core/dist/runtime-v2/adapter/__tests__/test-double-runtime-adapter.test.js.map +1 -1
- package/core/dist/runtime-v2/bridge-result-shaper.d.ts +53 -0
- package/core/dist/runtime-v2/bridge-result-shaper.d.ts.map +1 -0
- package/core/dist/runtime-v2/bridge-result-shaper.js +117 -0
- package/core/dist/runtime-v2/bridge-result-shaper.js.map +1 -0
- package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.d.ts +13 -0
- package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.js +111 -0
- package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.js.map +1 -0
- package/core/dist/runtime-v2/detection/detection-funnel-policy.d.ts +103 -0
- package/core/dist/runtime-v2/detection/detection-funnel-policy.d.ts.map +1 -0
- package/core/dist/runtime-v2/detection/detection-funnel-policy.js +135 -0
- package/core/dist/runtime-v2/detection/detection-funnel-policy.js.map +1 -0
- package/core/dist/runtime-v2/detection/index.d.ts +10 -0
- package/core/dist/runtime-v2/detection/index.d.ts.map +1 -0
- package/core/dist/runtime-v2/detection/index.js +9 -0
- package/core/dist/runtime-v2/detection/index.js.map +1 -0
- package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js +156 -0
- package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.d.ts +12 -0
- package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js +181 -0
- package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js.map +1 -0
- package/core/dist/runtime-v2/evidence-triage/__tests__/triage-policy.test.js +104 -1
- package/core/dist/runtime-v2/evidence-triage/__tests__/triage-policy.test.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/index.d.ts +3 -0
- package/core/dist/runtime-v2/evidence-triage/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/index.js +3 -0
- package/core/dist/runtime-v2/evidence-triage/index.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts +128 -0
- package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts.map +1 -0
- package/core/dist/runtime-v2/evidence-triage/observation-resolver.js +203 -0
- package/core/dist/runtime-v2/evidence-triage/observation-resolver.js.map +1 -0
- package/core/dist/runtime-v2/evidence-triage/triage-policy.d.ts +4 -0
- package/core/dist/runtime-v2/evidence-triage/triage-policy.d.ts.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/triage-policy.js +66 -9
- package/core/dist/runtime-v2/evidence-triage/triage-policy.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/types.d.ts +14 -0
- package/core/dist/runtime-v2/evidence-triage/types.d.ts.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/types.js.map +1 -1
- package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +33 -4
- package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
- package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
- package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +9 -2
- package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
- package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.d.ts +15 -0
- package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.js +450 -0
- package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.js.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.d.ts +13 -0
- package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.js +243 -0
- package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.js.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.d.ts +12 -0
- package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.js +172 -0
- package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.js.map +1 -0
- package/core/dist/runtime-v2/index.d.ts +9 -6
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +8 -4
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.d.ts +2 -0
- package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js +306 -0
- package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/index.d.ts +0 -16
- package/core/dist/runtime-v2/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/index.js +0 -8
- package/core/dist/runtime-v2/internalization/index.js.map +1 -1
- package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.d.ts +15 -0
- package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.js +179 -0
- package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.js.map +1 -0
- package/core/dist/runtime-v2/pain-gate/index.d.ts +10 -0
- package/core/dist/runtime-v2/pain-gate/index.d.ts.map +1 -0
- package/core/dist/runtime-v2/pain-gate/index.js +9 -0
- package/core/dist/runtime-v2/pain-gate/index.js.map +1 -0
- package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts +121 -0
- package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts.map +1 -0
- package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.js +157 -0
- package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.js.map +1 -0
- package/core/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-signal-bridge.js +14 -88
- package/core/dist/runtime-v2/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime-v2/pain-signal-observability.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-signal-observability.js +15 -5
- package/core/dist/runtime-v2/pain-signal-observability.js.map +1 -1
- package/core/dist/runtime-v2/principle-tree/ledger-codec.d.ts +30 -0
- package/core/dist/runtime-v2/principle-tree/ledger-codec.d.ts.map +1 -0
- package/core/dist/runtime-v2/principle-tree/ledger-codec.js +154 -0
- package/core/dist/runtime-v2/principle-tree/ledger-codec.js.map +1 -0
- package/core/dist/runtime-v2/types/event-types.d.ts +0 -27
- package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/event-types.js +2 -17
- package/core/dist/runtime-v2/types/event-types.js.map +1 -1
- package/core/dist/runtime-v2/types/index.d.ts +4 -2
- package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/index.js +4 -1
- package/core/dist/runtime-v2/types/index.js.map +1 -1
- package/core/dist/runtime-v2/types/ledger-store.d.ts +101 -0
- package/core/dist/runtime-v2/types/ledger-store.d.ts.map +1 -0
- package/core/dist/runtime-v2/types/ledger-store.js +15 -0
- package/core/dist/runtime-v2/types/ledger-store.js.map +1 -0
- package/core/dist/runtime-v2/types/pain-signal.d.ts +7 -5
- package/core/dist/runtime-v2/types/pain-signal.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/pain-signal.js +25 -5
- package/core/dist/runtime-v2/types/pain-signal.js.map +1 -1
- package/core/package.json +3 -3
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +9 -3
- package/dist/installer.js.map +1 -1
- package/dist/mvp-config.d.ts +0 -10
- package/dist/mvp-config.d.ts.map +1 -1
- package/dist/mvp-config.js +0 -64
- package/dist/mvp-config.js.map +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +10 -4
- package/dist/utils/env.js.map +1 -1
- package/package.json +1 -1
- package/pd-cli/dist/commands/__tests__/legacy-cleanup.test.js +11 -3
- package/pd-cli/dist/commands/__tests__/legacy-cleanup.test.js.map +1 -1
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +2 -1
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/health.d.ts.map +1 -1
- package/pd-cli/dist/commands/health.js +2 -1
- package/pd-cli/dist/commands/health.js.map +1 -1
- package/pd-cli/dist/commands/mvp-smoke.js +1 -1
- package/pd-cli/dist/commands/mvp-smoke.js.map +1 -1
- package/pd-cli/dist/commands/rulecode.js +1 -1
- package/pd-cli/dist/commands/rulecode.js.map +1 -1
- package/pd-cli/dist/commands/runtime-canary.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-canary.js +10 -11
- package/pd-cli/dist/commands/runtime-canary.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-integrity.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-integrity.js +3 -1
- package/pd-cli/dist/commands/runtime-internalization-integrity.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-queue.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-queue.js +13 -16
- package/pd-cli/dist/commands/runtime-internalization-queue.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 +3 -0
- 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 +61 -7
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.js +4 -1
- package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
- package/pd-cli/dist/commands/runtime.js +1 -1
- package/pd-cli/dist/commands/runtime.js.map +1 -1
- package/pd-cli/dist/index.js +67 -34
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/legacy/session-history-import.js +7 -5
- package/pd-cli/dist/legacy/session-history-import.js.map +1 -1
- package/pd-cli/dist/services/__tests__/rulehost-readiness.test.d.ts +2 -0
- package/pd-cli/dist/services/__tests__/rulehost-readiness.test.d.ts.map +1 -0
- package/pd-cli/dist/services/__tests__/rulehost-readiness.test.js +314 -0
- package/pd-cli/dist/services/__tests__/rulehost-readiness.test.js.map +1 -0
- package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js +33 -14
- package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js.map +1 -1
- package/pd-cli/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/pain-flood-simulation-runner.js +6 -2
- package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
- package/pd-cli/dist/services/rulehost-readiness.d.ts +62 -0
- package/pd-cli/dist/services/rulehost-readiness.d.ts.map +1 -0
- package/pd-cli/dist/services/rulehost-readiness.js +214 -0
- package/pd-cli/dist/services/rulehost-readiness.js.map +1 -0
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.js +9 -7
- package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/plugin/dist/commands/capabilities.js +3 -2
- package/plugin/dist/commands/disable-impl.js +1 -1
- package/plugin/dist/commands/evolution-status.js +0 -2
- package/plugin/dist/commands/focus.js +10 -2
- package/plugin/dist/commands/rollback-impl.js +1 -1
- package/plugin/dist/commands/thinking-os.js +5 -1
- package/plugin/dist/core/correction-cue-learner.js +2 -0
- package/plugin/dist/core/detection-funnel.d.ts +25 -11
- package/plugin/dist/core/detection-funnel.js +32 -80
- package/plugin/dist/core/event-log.d.ts +1 -3
- package/plugin/dist/core/event-log.js +27 -31
- package/plugin/dist/core/evolution-reducer.d.ts +0 -8
- package/plugin/dist/core/evolution-reducer.js +9 -19
- package/plugin/dist/core/focus-history.js +1 -1
- package/plugin/dist/core/hygiene/tracker.js +3 -3
- package/plugin/dist/core/pain-diagnostic-gate.d.ts +37 -28
- package/plugin/dist/core/pain-diagnostic-gate.js +53 -89
- package/plugin/dist/core/pain.d.ts +0 -63
- package/plugin/dist/core/pain.js +0 -167
- package/plugin/dist/core/paths.d.ts +0 -1
- package/plugin/dist/core/paths.js +2 -1
- package/plugin/dist/core/principle-compiler/compiler.js +2 -0
- package/plugin/dist/core/replay-engine.js +1 -1
- package/plugin/dist/core/rule-host.js +3 -1
- package/plugin/dist/core/schema/migrations/001-init-trajectory.js +3 -6
- package/plugin/dist/core/schema/schema-definitions.js +4 -9
- package/plugin/dist/core/thinking-os-parser.js +13 -4
- package/plugin/dist/core/trajectory.d.ts +0 -16
- package/plugin/dist/core/trajectory.js +9 -60
- package/plugin/dist/hooks/after-tool-call-helpers.d.ts +4 -1
- package/plugin/dist/hooks/after-tool-call-helpers.js +13 -17
- package/plugin/dist/hooks/gate-block-helper.js +57 -17
- package/plugin/dist/hooks/lifecycle.js +3 -6
- package/plugin/dist/hooks/llm.js +66 -26
- package/plugin/dist/hooks/pain.d.ts +3 -1
- package/plugin/dist/hooks/pain.js +119 -49
- package/plugin/dist/hooks/prompt-helpers.d.ts +87 -0
- package/plugin/dist/hooks/prompt-helpers.js +251 -0
- package/plugin/dist/hooks/prompt-types.d.ts +66 -0
- package/plugin/dist/hooks/prompt-types.js +12 -0
- package/plugin/dist/hooks/prompt.d.ts +7 -38
- package/plugin/dist/hooks/prompt.js +361 -325
- package/plugin/dist/hooks/raw-observation-adapter.d.ts +9 -50
- package/plugin/dist/hooks/raw-observation-adapter.js +9 -164
- package/plugin/dist/hooks/raw-observation-types.d.ts +6 -57
- package/plugin/dist/hooks/raw-observation-types.js +5 -9
- package/plugin/dist/hooks/trajectory-collector.d.ts +20 -4
- package/plugin/dist/hooks/trajectory-collector.js +95 -156
- package/plugin/dist/hooks/triage-adapter.js +6 -26
- package/plugin/dist/hooks/trigger-cooldown-tracker.d.ts +12 -0
- package/plugin/dist/hooks/trigger-cooldown-tracker.js +25 -0
- package/plugin/dist/index.js +7 -2
- package/plugin/dist/openclaw-sdk.d.ts +4 -1
- package/plugin/dist/service/evolution-worker.js +8 -62
- package/plugin/dist/service/internalization-auto-consumer-service.js +2 -1
- package/plugin/dist/service/runtime-summary-service.d.ts +0 -2
- package/plugin/dist/service/runtime-summary-service.js +8 -5
- package/plugin/dist/service/workflow-watchdog.js +2 -1
- package/plugin/dist/types/event-types.d.ts +1 -1
- package/plugin/dist/utils/retry.js +7 -2
- package/plugin/dist/utils/session-key.js +4 -1
- package/plugin/scripts/sync-plugin.mjs +33 -22
- package/plugin/scripts/validate-live-path.ts +0 -18
- package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +20 -11
- package/plugin/templates/langs/en/skills/pd-runtime-v2/SKILL.md +10 -0
- package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +20 -11
- package/plugin/templates/langs/zh/skills/pd-runtime-v2/SKILL.md +10 -0
- package/console/dist/server/config/feature-flags.d.ts +0 -25
- package/console/dist/server/config/feature-flags.js +0 -101
- package/core/dist/io.d.ts +0 -35
- package/core/dist/io.d.ts.map +0 -1
- package/core/dist/io.js +0 -95
- package/core/dist/io.js.map +0 -1
- package/pd-cli/dist/commands/central-sync.d.ts +0 -10
- package/pd-cli/dist/commands/central-sync.d.ts.map +0 -1
- package/pd-cli/dist/commands/central-sync.js +0 -32
- package/pd-cli/dist/commands/central-sync.js.map +0 -1
- package/pd-cli/dist/services/feature-flag-loader.d.ts +0 -6
- package/pd-cli/dist/services/feature-flag-loader.d.ts.map +0 -1
- package/pd-cli/dist/services/feature-flag-loader.js +0 -53
- package/pd-cli/dist/services/feature-flag-loader.js.map +0 -1
- package/plugin/dist/core/observability.d.ts +0 -40
- package/plugin/dist/core/observability.js +0 -164
- package/plugin/dist/hooks/subagent.d.ts +0 -9
- package/plugin/dist/hooks/subagent.js +0 -122
|
@@ -1,127 +1,79 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Trajectory Collector - message write trajectory recording
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Fallback trajectory collection when llm_output is blocked by missing
|
|
5
|
+
* allowConversationAccess. before_message_write is NOT in
|
|
6
|
+
* CONVERSATION_HOOK_NAMES so OpenClaw always delivers it.
|
|
7
|
+
*
|
|
8
|
+
* SQLite writes are enqueued to an async queue because before_message_write is
|
|
9
|
+
* a SYNCHRONOUS OpenClaw hook — the handler must return immediately. better-sqlite3
|
|
10
|
+
* is synchronous, so calling it directly would block the message-write main path.
|
|
11
|
+
* Trade-off: in degradation mode the last few queued writes may be lost on
|
|
12
|
+
* process exit; this is acceptable because degradation mode is already caused
|
|
13
|
+
* by a config problem (missing allowConversationAccess), and the primary
|
|
14
|
+
* llm_output path is authoritative when authorized.
|
|
15
|
+
*
|
|
16
|
+
* JSONL writing was removed (no consumers — verified zero readers across the
|
|
17
|
+
* codebase; PRI-347 already removed tool_call/llm_output JSONL writers).
|
|
18
|
+
*
|
|
19
|
+
* ERR-002: fallback errors are logged, never silent.
|
|
20
|
+
* ERR-001/005: content is sanitized before persisting.
|
|
7
21
|
*/
|
|
8
|
-
import * as fs from 'fs';
|
|
9
|
-
import * as path from 'path';
|
|
10
22
|
import { MAX_STRING_LENGTH } from '../config/defaults/runtime.js';
|
|
11
23
|
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
12
24
|
import { SystemLogger } from '../core/system-logger.js';
|
|
13
25
|
import { sanitizeForEvidence } from './message-sanitize.js';
|
|
14
26
|
import { checkConversationAccessConfig } from '../core/config-health.js';
|
|
15
|
-
const TRAJECTORY_DIR = 'memory/trajectories/';
|
|
16
|
-
// 敏感字段匹配正则
|
|
17
|
-
const SENSITIVE_KEY_PATTERN = /password|token|authorization|secret|api[_-]?key|credential|cookie|session/i;
|
|
18
|
-
/**
|
|
19
|
-
* 递归脱敏处理:遍历对象/数组,移除敏感字段值
|
|
20
|
-
*/
|
|
21
|
-
function scrubSensitive(obj, depth = 0) {
|
|
22
|
-
// 防止无限递归
|
|
23
|
-
if (depth > 10)
|
|
24
|
-
return '[MAX_DEPTH]';
|
|
25
|
-
// 处理 null/undefined
|
|
26
|
-
if (obj == null)
|
|
27
|
-
return obj;
|
|
28
|
-
// 处理基本类型
|
|
29
|
-
if (typeof obj !== 'object') {
|
|
30
|
-
if (typeof obj === 'string' && obj.length > MAX_STRING_LENGTH) {
|
|
31
|
-
return obj.slice(0, MAX_STRING_LENGTH) + '...[truncated]';
|
|
32
|
-
}
|
|
33
|
-
return obj;
|
|
34
|
-
}
|
|
35
|
-
// 处理数组
|
|
36
|
-
if (Array.isArray(obj)) {
|
|
37
|
-
return obj.map(item => scrubSensitive(item, depth + 1));
|
|
38
|
-
}
|
|
39
|
-
// 处理对象
|
|
40
|
-
const result = {};
|
|
41
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
42
|
-
if (SENSITIVE_KEY_PATTERN.test(key)) {
|
|
43
|
-
result[key] = '[REDACTED]';
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
result[key] = scrubSensitive(value, depth + 1);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
27
|
/**
|
|
52
|
-
*
|
|
28
|
+
* Async write queue — ensures ordered, non-blocking execution of SQLite writes.
|
|
29
|
+
* before_message_write is a sync hook; SQLite I/O must not block it.
|
|
30
|
+
*
|
|
31
|
+
* Tasks are deferred to the microtask queue via `queueMicrotask` so the sync
|
|
32
|
+
* hook handler returns before any synchronous better-sqlite3 work runs.
|
|
53
33
|
*/
|
|
54
34
|
class AsyncWriteQueue {
|
|
55
35
|
queue = [];
|
|
56
36
|
processing = false;
|
|
57
|
-
|
|
37
|
+
enqueue(task) {
|
|
58
38
|
this.queue.push(task);
|
|
59
39
|
if (!this.processing) {
|
|
60
|
-
this.
|
|
40
|
+
this.processing = true;
|
|
41
|
+
queueMicrotask(() => { void this.processNext(); });
|
|
61
42
|
}
|
|
62
43
|
}
|
|
63
44
|
async processNext() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
45
|
+
while (this.queue.length > 0) {
|
|
46
|
+
const task = this.queue.shift();
|
|
47
|
+
if (!task)
|
|
48
|
+
break;
|
|
49
|
+
try {
|
|
50
|
+
await task();
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// EP-03/ERR-002: safety net — tasks should catch their own errors with
|
|
54
|
+
// structured logging. This catches bugs where a task's try/catch is
|
|
55
|
+
// missing or re-throws. Never silently swallow (ERR-002).
|
|
56
|
+
console.warn('[PD:trajectory-queue] uncaught task error:', err);
|
|
57
|
+
}
|
|
73
58
|
}
|
|
74
|
-
|
|
75
|
-
await task();
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// Silently fail - trajectory collection should not block main functionality
|
|
79
|
-
}
|
|
80
|
-
// 处理下一个任务
|
|
81
|
-
this.processNext();
|
|
59
|
+
this.processing = false;
|
|
82
60
|
}
|
|
83
61
|
}
|
|
84
|
-
// 全局写入队列实例
|
|
85
62
|
const writeQueue = new AsyncWriteQueue();
|
|
86
|
-
// 目录缓存(避免重复检查)
|
|
87
|
-
const dirCache = new Map();
|
|
88
63
|
/**
|
|
89
|
-
*
|
|
64
|
+
* Extract text content from a message (string or content-part array).
|
|
90
65
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return dir;
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
await fs.promises.mkdir(dir, { recursive: true });
|
|
98
|
-
dirCache.set(dir, true);
|
|
66
|
+
function extractContent(content) {
|
|
67
|
+
if (typeof content === 'string') {
|
|
68
|
+
return content;
|
|
99
69
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
70
|
+
if (Array.isArray(content)) {
|
|
71
|
+
return content
|
|
72
|
+
.filter((part) => part && typeof part === 'object' && part.type === 'text')
|
|
73
|
+
.map((part) => part.text)
|
|
74
|
+
.join('\n');
|
|
103
75
|
}
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 获取今日轨迹文件名
|
|
108
|
-
*/
|
|
109
|
-
function getTodayFilename() {
|
|
110
|
-
const now = new Date();
|
|
111
|
-
const year = now.getUTCFullYear();
|
|
112
|
-
const month = String(now.getUTCMonth() + 1).padStart(2, '0');
|
|
113
|
-
return `${year}-${month}-${String(now.getUTCDate()).padStart(2, '0')}.jsonl`;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* 写入轨迹记录(JSON Lines 格式)- 异步版本
|
|
117
|
-
*/
|
|
118
|
-
function writeTrajectoryRecord(workspaceDir, record) {
|
|
119
|
-
const line = JSON.stringify(record) + '\n';
|
|
120
|
-
writeQueue.enqueue(async () => {
|
|
121
|
-
const dir = await ensureTrajectoryDirAsync(workspaceDir);
|
|
122
|
-
const filepath = path.join(dir, getTodayFilename());
|
|
123
|
-
await fs.promises.appendFile(filepath, line, 'utf8');
|
|
124
|
-
});
|
|
76
|
+
return '';
|
|
125
77
|
}
|
|
126
78
|
/**
|
|
127
79
|
* PRI-346: Message write hook with SQLite fallback trajectory recording.
|
|
@@ -131,7 +83,9 @@ function writeTrajectoryRecord(workspaceDir, record) {
|
|
|
131
83
|
* CONVERSATION_HOOK_NAMES, so it always fires — making it the natural fallback.
|
|
132
84
|
*
|
|
133
85
|
* De-duplication: only writes to SQLite when llm_output is blocked (unauthorized).
|
|
134
|
-
* When llm_output is working (authorized), this hook
|
|
86
|
+
* When llm_output is working (authorized), this hook is a no-op.
|
|
87
|
+
*
|
|
88
|
+
* SQLite writes are async-queued (see file header) to avoid blocking the sync hook.
|
|
135
89
|
*
|
|
136
90
|
* ERR-002: structured observability when fallback fires.
|
|
137
91
|
* ERR-001/005: content is sanitized before persisting.
|
|
@@ -146,73 +100,58 @@ export function handleBeforeMessageWrite(event, ctx) {
|
|
|
146
100
|
// Only record user and assistant messages
|
|
147
101
|
if (msg.role !== 'user' && msg.role !== 'assistant')
|
|
148
102
|
return;
|
|
149
|
-
// Extract text content (consistent with existing implementation)
|
|
150
|
-
let content = '';
|
|
151
|
-
if (typeof msg.content === 'string') {
|
|
152
|
-
content = msg.content;
|
|
153
|
-
}
|
|
154
|
-
else if (Array.isArray(msg.content)) {
|
|
155
|
-
content = msg.content
|
|
156
|
-
.filter((part) => part && typeof part === 'object' && part.type === 'text')
|
|
157
|
-
.map((part) => part.text)
|
|
158
|
-
.join('\n');
|
|
159
|
-
}
|
|
160
|
-
// Sanitize content preview for JSONL
|
|
161
|
-
const sanitizedPreview = scrubSensitive(content.slice(0, 200));
|
|
162
|
-
// Existing JSONL write (always, for backward compatibility)
|
|
163
|
-
writeTrajectoryRecord(workspaceDir, {
|
|
164
|
-
type: 'message',
|
|
165
|
-
timestamp: new Date().toISOString(),
|
|
166
|
-
sessionId: event.sessionKey || event.sessionId || 'unknown',
|
|
167
|
-
role: msg.role,
|
|
168
|
-
contentLength: content.length,
|
|
169
|
-
contentPreview: typeof sanitizedPreview === 'string' ? sanitizedPreview : '[sanitized]',
|
|
170
|
-
agentId: event.agentId || null,
|
|
171
|
-
fallback: 'before_message_write',
|
|
172
|
-
});
|
|
173
103
|
// ── SQLite fallback (PRI-346): only when conversation hooks are blocked ──
|
|
174
104
|
const accessCheck = checkConversationAccessConfig(ctx.pluginConfig);
|
|
175
105
|
if (accessCheck.authorized) {
|
|
176
106
|
// llm_output is working — do NOT duplicate write to SQLite (de-dup, case D)
|
|
177
107
|
return;
|
|
178
108
|
}
|
|
179
|
-
// Conversation hooks blocked — this hook is the fallback trajectory writer
|
|
109
|
+
// Conversation hooks blocked — this hook is the fallback trajectory writer.
|
|
110
|
+
// Enqueue SQLite writes to avoid blocking the sync before_message_write hook.
|
|
111
|
+
const logger = ctx.logger;
|
|
112
|
+
const content = extractContent(msg.content);
|
|
113
|
+
const sessionId = event.sessionKey ?? ctx.sessionId ?? 'unknown';
|
|
114
|
+
const createdAt = new Date().toISOString();
|
|
180
115
|
if (msg.role === 'assistant') {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
116
|
+
writeQueue.enqueue(async () => {
|
|
117
|
+
try {
|
|
118
|
+
const wctx = WorkspaceContext.fromHookContext({ workspaceDir, logger });
|
|
119
|
+
const sanitized = sanitizeForEvidence(content.slice(0, MAX_STRING_LENGTH), workspaceDir);
|
|
120
|
+
wctx.trajectory?.recordAssistantTurn?.({
|
|
121
|
+
sessionId,
|
|
122
|
+
runId: 'before_message_write_fallback',
|
|
123
|
+
provider: 'unknown',
|
|
124
|
+
model: 'unknown',
|
|
125
|
+
rawText: content,
|
|
126
|
+
sanitizedText: sanitized,
|
|
127
|
+
usageJson: {},
|
|
128
|
+
empathySignalJson: { detected: false, severity: 'mild', confidence: 1 },
|
|
129
|
+
createdAt,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
// EP-03/ERR-002: observable degradation, never silent
|
|
134
|
+
logger?.warn?.(`[PD:before_message_write] SQLite fallback write failed: ${String(err)}`);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
200
137
|
}
|
|
201
138
|
else if (msg.role === 'user') {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
139
|
+
writeQueue.enqueue(async () => {
|
|
140
|
+
try {
|
|
141
|
+
const wctx = WorkspaceContext.fromHookContext({ workspaceDir, logger });
|
|
142
|
+
wctx.trajectory?.recordUserTurn?.({
|
|
143
|
+
sessionId,
|
|
144
|
+
turnIndex: 0,
|
|
145
|
+
rawText: content.slice(0, MAX_STRING_LENGTH),
|
|
146
|
+
correctionDetected: false,
|
|
147
|
+
createdAt,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
// EP-03/ERR-002: observable degradation, never silent
|
|
152
|
+
logger?.warn?.(`[PD:before_message_write] SQLite user turn fallback failed: ${String(err)}`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
216
155
|
}
|
|
217
156
|
// ERR-002: Structured observability — no silent fallback
|
|
218
157
|
SystemLogger.log(workspaceDir, 'CONVERSATION_HOOK_BLOCKED', JSON.stringify({
|
|
@@ -42,38 +42,18 @@ export { resolveSourceKind, buildToolFailureObservation, buildLlmDetectionObserv
|
|
|
42
42
|
* - Falling back to existing behavior when the flag is off
|
|
43
43
|
*/
|
|
44
44
|
export function evaluateEvidenceTriage(sourceKind, score, options) {
|
|
45
|
+
// PRI-446: the risky high-score and repeated-failure upgrade rules now live
|
|
46
|
+
// in core triage-policy.ts (single source of truth). The adapter passes the
|
|
47
|
+
// context flags straight through; core decides whether to upgrade.
|
|
45
48
|
const input = {
|
|
46
49
|
sourceKind,
|
|
47
50
|
score,
|
|
48
51
|
isUnsafeHighConfidence: options?.isUnsafeHighConfidence,
|
|
49
52
|
provenance: options?.provenance,
|
|
53
|
+
isRisky: options?.isRisky,
|
|
54
|
+
consecutiveErrors: options?.consecutiveErrors,
|
|
50
55
|
};
|
|
51
|
-
|
|
52
|
-
// PEAT-B1 upgrade logic: risky high-score overrides evidence_only
|
|
53
|
-
// Matches PainDiagnosticGate.risky_high_score: isRisky && score >= 70 → admit
|
|
54
|
-
if (result.decision === 'evidence_only' &&
|
|
55
|
-
options?.isRisky === true &&
|
|
56
|
-
score >= 70) {
|
|
57
|
-
result = {
|
|
58
|
-
...result,
|
|
59
|
-
decision: 'admit',
|
|
60
|
-
reason: 'Risky high-score operation overrides evidence-only decision. Immediate diagnosis required.',
|
|
61
|
-
nextAction: 'create_diagnostic_task',
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
// PEAT-B1 upgrade logic: repeated failures override evidence_only
|
|
65
|
-
// Threshold: 4 consecutive failures (matches PainDiagnosticGate.repeatedFailure)
|
|
66
|
-
if (result.decision === 'evidence_only' &&
|
|
67
|
-
options?.consecutiveErrors !== undefined &&
|
|
68
|
-
options.consecutiveErrors >= 4) {
|
|
69
|
-
result = {
|
|
70
|
-
...result,
|
|
71
|
-
decision: 'admit',
|
|
72
|
-
reason: 'Repeated failures override evidence-only decision. Pattern suggests systemic issue requiring diagnosis.',
|
|
73
|
-
nextAction: 'create_diagnostic_task',
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
56
|
+
return evaluateTriage(input);
|
|
77
57
|
}
|
|
78
58
|
// ── High-Confidence Unsafe Action Detection ──────────────────────────────────
|
|
79
59
|
/**
|
|
@@ -28,3 +28,15 @@ export declare function clearCooldownState(cooldownMap: Map<string, number>): vo
|
|
|
28
28
|
* Get the cooldown timestamp for a given episode (for tests).
|
|
29
29
|
*/
|
|
30
30
|
export declare function getCooldownTimestamp(source: string, sessionId: string | undefined, errorHash: string | undefined, cooldownMap: ReadonlyMap<string, number>): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Check whether cooldown is currently active using the shared Map.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isSharedCooldownActive(source: string, sessionId: string | undefined, errorHash: string | undefined): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Mark an episode as diagnosed using the shared Map.
|
|
37
|
+
*/
|
|
38
|
+
export declare function markSharedEpisodeAsDiagnosed(source: string, sessionId: string | undefined, errorHash: string | undefined): void;
|
|
39
|
+
/**
|
|
40
|
+
* Clear all shared cooldown state (for tests).
|
|
41
|
+
*/
|
|
42
|
+
export declare function resetSharedCooldownForTest(): void;
|
|
@@ -53,3 +53,28 @@ export function getCooldownTimestamp(source, sessionId, errorHash, cooldownMap)
|
|
|
53
53
|
const episodeKey = buildEpisodeKey(source, sessionId, errorHash);
|
|
54
54
|
return cooldownMap.get(episodeKey);
|
|
55
55
|
}
|
|
56
|
+
// ── Shared Cooldown Map (PRI-454) ───────────────────────────────────────────
|
|
57
|
+
//
|
|
58
|
+
// Module-level singleton Map shared across all Gate B paths.
|
|
59
|
+
// Replaces the per-file TRIGGER_COOLDOWN_MAP in after-tool-call-helpers.ts.
|
|
60
|
+
// All paths (gate-block, llm, empathy, manual pain) use this single Map
|
|
61
|
+
// to ensure unified cooldown state.
|
|
62
|
+
const SHARED_COOLDOWN_MAP = new Map();
|
|
63
|
+
/**
|
|
64
|
+
* Check whether cooldown is currently active using the shared Map.
|
|
65
|
+
*/
|
|
66
|
+
export function isSharedCooldownActive(source, sessionId, errorHash) {
|
|
67
|
+
return isCooldownActive(source, sessionId, errorHash, SHARED_COOLDOWN_MAP);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Mark an episode as diagnosed using the shared Map.
|
|
71
|
+
*/
|
|
72
|
+
export function markSharedEpisodeAsDiagnosed(source, sessionId, errorHash) {
|
|
73
|
+
markEpisodeAsDiagnosed(source, sessionId, errorHash, SHARED_COOLDOWN_MAP);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Clear all shared cooldown state (for tests).
|
|
77
|
+
*/
|
|
78
|
+
export function resetSharedCooldownForTest() {
|
|
79
|
+
SHARED_COOLDOWN_MAP.clear();
|
|
80
|
+
}
|
package/plugin/dist/index.js
CHANGED
|
@@ -266,6 +266,9 @@ const plugin = {
|
|
|
266
266
|
}
|
|
267
267
|
}));
|
|
268
268
|
// ── Hook: Pain & Trust ──
|
|
269
|
+
// timeoutMs=10s: OpenClaw has no default timeout for after_tool_call; without
|
|
270
|
+
// this a stuck SQLite write (busy_timeout=5000ms) leaks the handler promise.
|
|
271
|
+
// 10s gives 2x headroom over busy_timeout. fail-open means agent is unaffected.
|
|
269
272
|
api.on('after_tool_call', guardHook('hook:after_tool_call', api.logger, (event, ctx) => {
|
|
270
273
|
const wsResult = resolveHookWorkspaceDir(ctx, api, 'after_tool_call');
|
|
271
274
|
if (!wsResult.ok) {
|
|
@@ -294,8 +297,10 @@ const plugin = {
|
|
|
294
297
|
}, { flushImmediately: true });
|
|
295
298
|
api.logger.error(`[PD:EmpathyObserver] Error in after_tool_call: ${String(err)}`);
|
|
296
299
|
}
|
|
297
|
-
}));
|
|
300
|
+
}), { timeoutMs: 10_000 });
|
|
298
301
|
// ── Hook: LLM Analysis ──
|
|
302
|
+
// timeoutMs=10s: OpenClaw has no default timeout for llm_output; without
|
|
303
|
+
// this a stuck SQLite write leaks the handler promise. See after_tool_call.
|
|
299
304
|
api.on('llm_output', guardHook('hook:llm_output', api.logger, (event, ctx) => {
|
|
300
305
|
const wsResult = resolveHookWorkspaceDir(ctx, api, 'llm_output');
|
|
301
306
|
if (!wsResult.ok) {
|
|
@@ -325,7 +330,7 @@ const plugin = {
|
|
|
325
330
|
});
|
|
326
331
|
api.logger.error(`[PD] Error in llm_output: ${String(err)}`);
|
|
327
332
|
}
|
|
328
|
-
}));
|
|
333
|
+
}), { timeoutMs: 10_000 });
|
|
329
334
|
// ── Hook: Lifecycle ──
|
|
330
335
|
api.on('before_reset', guardHook('hook:before_reset', api.logger, (event, ctx) => {
|
|
331
336
|
const wsResult = resolveHookWorkspaceDir(ctx, api, 'before_reset');
|
|
@@ -151,7 +151,10 @@ export interface OpenClawPluginApi {
|
|
|
151
151
|
text: (content: string, code?: number) => void;
|
|
152
152
|
}) => boolean | Promise<boolean>;
|
|
153
153
|
}) => void;
|
|
154
|
-
on: (event: string, handler: (...args: any[]) => unknown
|
|
154
|
+
on: (event: string, handler: (...args: any[]) => unknown, opts?: {
|
|
155
|
+
priority?: number;
|
|
156
|
+
timeoutMs?: number;
|
|
157
|
+
}) => void;
|
|
155
158
|
}
|
|
156
159
|
export interface PluginHookBeforePromptBuildEvent {
|
|
157
160
|
agentId?: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* global NodeJS */
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// DetectionService + DictionaryService imports removed — their only consumer
|
|
5
|
+
// (processDetectionQueue) was dead code retired in PRI-451 Wave 1.
|
|
6
6
|
import { ensureStateTemplates, ensureCorePrinciples } from '../core/init.js';
|
|
7
7
|
import { SystemLogger } from '../core/system-logger.js';
|
|
8
8
|
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
@@ -93,7 +93,8 @@ export function purgeStaleFailedTasks(queue, logger) {
|
|
|
93
93
|
// Remove purged items from the queue (mutates in place)
|
|
94
94
|
const purgedIds = new Set(purged.map((t) => t.id));
|
|
95
95
|
for (let i = queue.length - 1; i >= 0; i--) {
|
|
96
|
-
|
|
96
|
+
const task = queue[i];
|
|
97
|
+
if (task && purgedIds.has(task.id))
|
|
97
98
|
queue.splice(i, 1);
|
|
98
99
|
}
|
|
99
100
|
const summary = Object.entries(byReason)
|
|
@@ -350,59 +351,8 @@ async function processEvolutionQueue(wctx, logger, _eventLog, _api) {
|
|
|
350
351
|
}
|
|
351
352
|
}
|
|
352
353
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
try {
|
|
356
|
-
const funnel = DetectionService.get(wctx.stateDir);
|
|
357
|
-
const queue = funnel.flushQueue();
|
|
358
|
-
if (queue.length === 0)
|
|
359
|
-
return;
|
|
360
|
-
if (logger)
|
|
361
|
-
logger.info(`[PD:EvolutionWorker] Processing ${queue.length} items from detection funnel.`);
|
|
362
|
-
const dictionary = DictionaryService.get(wctx.stateDir);
|
|
363
|
-
for (const text of queue) {
|
|
364
|
-
const match = dictionary.match(text);
|
|
365
|
-
if (match) {
|
|
366
|
-
if (eventLog) {
|
|
367
|
-
eventLog.recordRuleMatch(undefined, {
|
|
368
|
-
ruleId: match.ruleId,
|
|
369
|
-
layer: 'L2',
|
|
370
|
-
severity: match.severity,
|
|
371
|
-
textPreview: text.substring(0, 100)
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
// L3 semantic search via trajectory database FTS5 (MEM-04)
|
|
377
|
-
if (wctx.trajectory) {
|
|
378
|
-
const searchResults = wctx.trajectory.searchPainEvents(text, 5);
|
|
379
|
-
if (searchResults.length > 0) {
|
|
380
|
-
// Found similar pain events - record as L3 semantic hit
|
|
381
|
-
if (eventLog) {
|
|
382
|
-
eventLog.recordRuleMatch(undefined, {
|
|
383
|
-
ruleId: 'l3_semantic',
|
|
384
|
-
layer: 'L3',
|
|
385
|
-
severity: searchResults[0].score,
|
|
386
|
-
textPreview: text.substring(0, 100)
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
// Update detection funnel cache with L3 hit result
|
|
390
|
-
funnel.updateCache(text, { detected: true, severity: searchResults[0].score });
|
|
391
|
-
// Don't track as candidate - this is a confirmed L3 hit
|
|
392
|
-
if (logger)
|
|
393
|
-
logger.info(`[PD:EvolutionWorker] L3 semantic hit: found ${searchResults.length} similar pain events for "${text.substring(0, 50)}..."`);
|
|
394
|
-
continue;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
// No L3 hit — pain candidate tracking removed (D-05)
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
catch (err) {
|
|
402
|
-
if (logger)
|
|
403
|
-
logger.warn(`[PD:EvolutionWorker] Detection queue failed: ${String(err)}`);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
354
|
+
// processDetectionQueue removed (PRI-451 Wave 1): dead code. Its only effects
|
|
355
|
+
// were recordRuleMatch (dead) and searchPainEvents (dead) — see PRI-451.
|
|
406
356
|
// PAIN_CANDIDATES system removed (D-05, D-06): trackPainCandidate and processPromotion deleted
|
|
407
357
|
// Evolution queue is now the single active pain→principle path
|
|
408
358
|
export async function registerEvolutionTaskSession(workspaceResolve, taskId, sessionKey, logger) {
|
|
@@ -540,9 +490,7 @@ export const EvolutionWorkerService = {
|
|
|
540
490
|
cycleResult.queue = queueResult.queue;
|
|
541
491
|
if (queueResult.errors)
|
|
542
492
|
cycleResult.errors.push(...queueResult.errors);
|
|
543
|
-
|
|
544
|
-
await processDetectionQueue(wctx, api, eventLog);
|
|
545
|
-
}
|
|
493
|
+
// processDetectionQueue removed (PRI-451 Wave 1) — was dead code.
|
|
546
494
|
// processPromotion removed (D-06) — promotion via PAIN_CANDIDATES no longer needed
|
|
547
495
|
// Correction Observer extracted to independent service (PRI-293) — no longer runs on EvolutionWorker heartbeat
|
|
548
496
|
try {
|
|
@@ -626,9 +574,7 @@ export const EvolutionWorkerService = {
|
|
|
626
574
|
if (queueResult.errors.length > 0) {
|
|
627
575
|
queueResult.errors.forEach((e) => logger?.error?.(`[PD:EvolutionWorker] Startup cycle error: ${e}`));
|
|
628
576
|
}
|
|
629
|
-
|
|
630
|
-
await processDetectionQueue(wctx, api, eventLog);
|
|
631
|
-
}
|
|
577
|
+
// processDetectionQueue removed (PRI-451 Wave 1) — was dead code.
|
|
632
578
|
// processPromotion removed (D-06)
|
|
633
579
|
timeoutId = setTimeout(runCycle, interval);
|
|
634
580
|
timeoutId.unref();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createRuntimeStateHandle, InternalizationOrchestrator, DreamerRunner, DefaultDreamerValidator, PiAiRuntimeAdapter, L2AgentLoopAdapter, buildL2PrincipleReaderFromLedger,
|
|
1
|
+
import { createRuntimeStateHandle, InternalizationOrchestrator, DreamerRunner, DefaultDreamerValidator, PiAiRuntimeAdapter, L2AgentLoopAdapter, buildL2PrincipleReaderFromLedger, OpenClawCliRuntimeAdapter, storeEmitter, resolveRuntimeConfigFromPdConfig, isRuntimeConfigError, computeConsumerDecision, InternalizationQueueReadModel, MVP_CORE_TASK_KINDS, } from '@principles/core/runtime-v2';
|
|
2
|
+
import { loadLedger } from '@principles/core/principle-tree-ledger';
|
|
2
3
|
import { loadPdConfigForPlugin, loadFeatureFlagFromConfig } from '../core/pd-config-loader.js';
|
|
3
4
|
import { SystemLogger } from '../core/system-logger.js';
|
|
4
5
|
const INTERNALIZATION_AUTO_CONSUMER_INTERVAL_MS = 120_000;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import Database from 'better-sqlite3';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
import { readPainFlagData } from '../core/pain.js';
|
|
5
4
|
import { listSessions } from '../core/session-tracker.js';
|
|
6
5
|
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
7
6
|
import { evaluatePhase3Inputs } from './phase3-input-filter.js';
|
|
@@ -130,7 +129,6 @@ export class RuntimeSummaryService {
|
|
|
130
129
|
const directive = this.readJsonFile(wctx.resolve('EVOLUTION_DIRECTIVE'), warnings, false);
|
|
131
130
|
const queueStats = this.buildQueueStats(queue);
|
|
132
131
|
const directiveSummary = this.buildDirectiveSummary(queue, directive, generatedAt, warnings);
|
|
133
|
-
const painFlag = readPainFlagData(workspaceDir);
|
|
134
132
|
const painCandidates = this.readJsonFile(wctx.resolve('PAIN_CANDIDATES'), warnings, false);
|
|
135
133
|
const phase3Inputs = evaluatePhase3Inputs(queue ?? []);
|
|
136
134
|
const lastPainSignal = this.findLastPainSignal(events, selectedSessionId);
|
|
@@ -239,8 +237,6 @@ export class RuntimeSummaryService {
|
|
|
239
237
|
eligibilitySource: 'runtime_truth',
|
|
240
238
|
},
|
|
241
239
|
pain: {
|
|
242
|
-
activeFlag: Object.keys(painFlag).length > 0,
|
|
243
|
-
activeFlagSource: painFlag.source || null,
|
|
244
240
|
candidates: painCandidates?.candidates && typeof painCandidates.candidates === 'object'
|
|
245
241
|
? Object.keys(painCandidates.candidates).length
|
|
246
242
|
: null,
|
|
@@ -290,7 +286,10 @@ export class RuntimeSummaryService {
|
|
|
290
286
|
if (sessions.length === 0) {
|
|
291
287
|
return { session: null, reason: 'none' };
|
|
292
288
|
}
|
|
293
|
-
|
|
289
|
+
const session = sessions[0];
|
|
290
|
+
if (!session)
|
|
291
|
+
return { session: null, reason: 'none' };
|
|
292
|
+
return { session, reason: 'latest_active' };
|
|
294
293
|
}
|
|
295
294
|
static mergeSessionSnapshots(persistedSessions, workspaceDir) {
|
|
296
295
|
const merged = new Map();
|
|
@@ -392,6 +391,8 @@ export class RuntimeSummaryService {
|
|
|
392
391
|
if (!m)
|
|
393
392
|
continue;
|
|
394
393
|
const fileDate = m[1];
|
|
394
|
+
if (!fileDate)
|
|
395
|
+
continue;
|
|
395
396
|
if (fileDate > newestDate) {
|
|
396
397
|
newestDate = fileDate;
|
|
397
398
|
bestFile = path.join(dir, file);
|
|
@@ -463,6 +464,8 @@ export class RuntimeSummaryService {
|
|
|
463
464
|
static findLastPainSignal(events, sessionId) {
|
|
464
465
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
465
466
|
const entry = events[i];
|
|
467
|
+
if (!entry)
|
|
468
|
+
continue;
|
|
466
469
|
if (entry.type !== 'pain_signal')
|
|
467
470
|
continue;
|
|
468
471
|
if (sessionId && entry.sessionId !== sessionId)
|
|
@@ -32,7 +32,8 @@ export async function runWorkflowWatchdog(wctx, api, logger) {
|
|
|
32
32
|
const ageMin = Math.round((now - wf.created_at) / 60000);
|
|
33
33
|
details.push(`stale_active: ${wf.workflow_id} (${wf.workflow_type}, ${ageMin}min old)`);
|
|
34
34
|
const events = store.getEvents(wf.workflow_id);
|
|
35
|
-
const
|
|
35
|
+
const lastEvent = events[events.length - 1];
|
|
36
|
+
const lastEventReason = lastEvent ? lastEvent.reason : 'unknown';
|
|
36
37
|
if (isExpectedSubagentError(lastEventReason)) {
|
|
37
38
|
logger?.debug?.(`[PD:Watchdog] Skipping stale active workflow ${wf.workflow_id}: expected subagent error (${lastEventReason})`);
|
|
38
39
|
continue;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { EventType, EventCategory, EventLogEntry, ToolCallEventData, PainSignalEventData, RuleMatchEventData, RulePromotionEventData, HookExecutionEventData, GateBlockEventData, GateBypassEventData, PlanApprovalEventData, EvolutionTaskEventData, EmpathyRollbackEventData, HeartbeatDiagnosisEventData, DiagnosisTaskEventData, DiagnosticianReportEventData, PrincipleCandidateEventData, RuleEnforcedEventData, RuleHostEvaluatedEventData, RuleHostBlockedEventData, RuleHostRequireApprovalEventData, RuleHostAutoCorrectProposedEventData, RuleHostAutoCorrectAppliedEventData, RuntimeV2PromptActivationsInjectedEventData, RuleHostUnhealthyEventData, ToolCallStats, ErrorStats,
|
|
1
|
+
export type { EventType, EventCategory, EventLogEntry, ToolCallEventData, PainSignalEventData, RuleMatchEventData, RulePromotionEventData, HookExecutionEventData, GateBlockEventData, GateBypassEventData, PlanApprovalEventData, EvolutionTaskEventData, EmpathyRollbackEventData, HeartbeatDiagnosisEventData, DiagnosisTaskEventData, DiagnosticianReportEventData, PrincipleCandidateEventData, RuleEnforcedEventData, RuleHostEvaluatedEventData, RuleHostBlockedEventData, RuleHostRequireApprovalEventData, RuleHostAutoCorrectProposedEventData, RuleHostAutoCorrectAppliedEventData, RuntimeV2PromptActivationsInjectedEventData, RuleHostUnhealthyEventData, ToolCallStats, ErrorStats, EmpathyEventStats, GfiStats, EvolutionStats as EventEvolutionStats, HookStats, DailyStats, } from '@principles/core/runtime-v2';
|
|
2
2
|
export { createEmptyDailyStats, } from '@principles/core/runtime-v2';
|