create-principles-disciple 1.103.0 → 1.104.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/README.md +2 -2
- package/console/dist/server/config/pd-config-store.d.ts +8 -1
- package/console/dist/server/config/pd-config-store.js +50 -0
- package/console/dist/server/index.js +24 -3
- package/console/dist/server/models/HealthCheckModel.d.ts +27 -0
- package/console/dist/server/models/HealthCheckModel.js +56 -0
- package/console/dist/server/routes/failed-tasks.d.ts +24 -0
- package/console/dist/server/routes/failed-tasks.js +207 -0
- package/console/dist/server/routes/feedback-reports.d.ts +1 -0
- package/console/dist/server/routes/feedback-reports.js +29 -2
- package/console/dist/server/routes/lifecycle.js +19 -1
- package/console/dist/server/routes/onboarding.js +2 -2
- package/console/dist/server/routes/update.js +290 -27
- package/console/dist/server/utils/gateway.d.ts +25 -0
- package/console/dist/server/utils/gateway.js +131 -0
- package/console/dist/ui/App.d.ts +1 -1
- package/console/dist/ui/App.js +2 -1
- package/console/dist/ui/api.d.ts +2 -1
- package/console/dist/ui/api.js +14 -2
- package/console/dist/ui/components/auth/login-form.d.ts +2 -1
- package/console/dist/ui/components/auth/splash-screen.d.ts +2 -1
- package/console/dist/ui/components/error-boundary.d.ts +1 -1
- package/console/dist/ui/components/focus/daily-thought-card.d.ts +1 -1
- package/console/dist/ui/components/language-switcher.d.ts +2 -1
- package/console/dist/ui/components/layout/app-sidebar.d.ts +6 -1
- package/console/dist/ui/components/layout/app-sidebar.js +10 -2
- package/console/dist/ui/components/layout/page-loading.d.ts +1 -1
- package/console/dist/ui/components/layout/page-shell.d.ts +1 -1
- package/console/dist/ui/components/layout/section-title.d.ts +1 -1
- package/console/dist/ui/components/notifications/NotificationProvider.d.ts +1 -1
- package/console/dist/ui/components/onboarding/CircuitDiagram.d.ts +1 -1
- package/console/dist/ui/components/onboarding/DemoResultView.d.ts +1 -1
- package/console/dist/ui/components/onboarding/SlashCommandsCard.d.ts +16 -0
- package/console/dist/ui/components/onboarding/SlashCommandsCard.js +20 -0
- package/console/dist/ui/components/onboarding/slashCommands.d.ts +20 -0
- package/console/dist/ui/components/onboarding/slashCommands.js +23 -0
- package/console/dist/ui/components/theme-provider.d.ts +1 -1
- package/console/dist/ui/components/theme-toggle.d.ts +2 -1
- package/console/dist/ui/components/ui/alert-dialog.d.ts +8 -8
- package/console/dist/ui/components/ui/badge.d.ts +2 -2
- package/console/dist/ui/components/ui/button.d.ts +2 -2
- package/console/dist/ui/components/ui/charts.d.ts +5 -5
- package/console/dist/ui/components/ui/dialog.d.ts +8 -8
- package/console/dist/ui/components/ui/markdown.d.ts +4 -4
- package/console/dist/ui/components/ui/progress-bar.d.ts +2 -2
- package/console/dist/ui/components/ui/sheet.d.ts +9 -9
- package/console/dist/ui/components/ui/shiny-text.d.ts +1 -1
- package/console/dist/ui/components/ui/skeleton.d.ts +1 -1
- package/console/dist/ui/components/ui/sonner.d.ts +1 -1
- package/console/dist/ui/i18n/en.json +51 -7
- package/console/dist/ui/i18n/zh-CN.json +51 -7
- package/console/dist/ui/pages/ReportProblemValidators.d.ts +63 -0
- package/console/dist/ui/pages/ReportProblemValidators.js +238 -0
- package/console/dist/ui/pages/activation/ActivationPage.d.ts +1 -1
- package/console/dist/ui/pages/activation/ActivationPage.js +1 -1
- package/console/dist/ui/pages/control-center/AgentCard.d.ts +1 -1
- package/console/dist/ui/pages/control-center/AgentCard.js +1 -1
- package/console/dist/ui/pages/control-center/AgentGroup.d.ts +1 -1
- package/console/dist/ui/pages/control-center/ControlCenterPage.d.ts +1 -1
- package/console/dist/ui/pages/control-center/ControlCenterPage.js +1 -1
- package/console/dist/ui/pages/control-center/EmpathyObserverCostHint.d.ts +1 -1
- package/console/dist/ui/pages/control-center/RuntimeProfileManager.d.ts +1 -1
- package/console/dist/ui/pages/control-center/RuntimeProfileManager.js +1 -1
- package/console/dist/ui/pages/control-center/WorkflowDiagram.d.ts +1 -1
- package/console/dist/ui/pages/debt/DebtPage.d.ts +2 -1
- package/console/dist/ui/pages/debt/DebtPage.js +1 -1
- package/console/dist/ui/pages/design-system/DesignSystemPage.d.ts +2 -1
- package/console/dist/ui/pages/failed-tasks/FailedTasksPage.d.ts +1 -0
- package/console/dist/ui/pages/failed-tasks/FailedTasksPage.js +229 -0
- package/console/dist/ui/pages/focus/FocusPage.d.ts +1 -1
- package/console/dist/ui/pages/focus/FocusPage.js +2 -2
- package/console/dist/ui/pages/intent/IntentOnboarding.d.ts +4 -4
- package/console/dist/ui/pages/intent/IntentOnboarding.js +1 -1
- package/console/dist/ui/pages/intent/IntentPage.d.ts +1 -1
- package/console/dist/ui/pages/intent/IntentPage.js +1 -1
- package/console/dist/ui/pages/pain/PainPage.d.ts +1 -1
- package/console/dist/ui/pages/pain/PainPage.js +1 -1
- package/console/dist/ui/pages/principles/PrincipleDetailPage.d.ts +1 -1
- package/console/dist/ui/pages/principles/PrincipleDetailPage.js +1 -1
- package/console/dist/ui/pages/principles/PrinciplesPage.d.ts +1 -1
- package/console/dist/ui/pages/report-problem/ReportProblemPage.d.ts +1 -1
- package/console/dist/ui/pages/report-problem/ReportProblemPage.js +36 -9
- package/console/dist/ui/pages/settings/SettingsPage.d.ts +1 -1
- package/console/dist/ui/pages/settings/SettingsPage.js +1 -1
- package/console/dist/ui/pages/settings/UpdatePage.d.ts +1 -1
- package/console/dist/ui/pages/settings/UpdatePage.js +35 -3
- package/console/dist/ui/pages/signal-keywords/KeywordEditDialog.d.ts +1 -1
- package/console/dist/ui/pages/signal-keywords/KeywordListSection.d.ts +1 -1
- package/console/dist/ui/pages/signal-keywords/PendingTermsSection.d.ts +1 -1
- package/console/dist/ui/pages/signal-keywords/SignalKeywordsPage.d.ts +1 -1
- package/console/dist/ui/pages/welcome/WelcomePage.d.ts +1 -1
- package/console/dist/ui/pages/welcome/WelcomePage.js +7 -5
- package/console/dist/ui/utils/agent-metadata.js +9 -9
- package/console/dist/ui/utils/validators.d.ts +12 -2
- package/console/dist/ui/utils/validators.js +16 -0
- package/console/dist/web/assets/app.css +421 -716
- package/console/dist/web/assets/app.js +1582 -871
- package/console/package.json +14 -14
- package/core/dist/adapters/__tests__/code-review-pain-adapter.test.d.ts +2 -0
- package/core/dist/adapters/__tests__/code-review-pain-adapter.test.d.ts.map +1 -0
- package/core/dist/adapters/__tests__/code-review-pain-adapter.test.js +346 -0
- package/core/dist/adapters/__tests__/code-review-pain-adapter.test.js.map +1 -0
- package/core/dist/adapters/__tests__/openclaw-pain-adapter.test.d.ts +2 -0
- package/core/dist/adapters/__tests__/openclaw-pain-adapter.test.d.ts.map +1 -0
- package/core/dist/adapters/__tests__/openclaw-pain-adapter.test.js +290 -0
- package/core/dist/adapters/__tests__/openclaw-pain-adapter.test.js.map +1 -0
- package/core/dist/adapters/__tests__/writing-pain-adapter.test.d.ts +2 -0
- package/core/dist/adapters/__tests__/writing-pain-adapter.test.d.ts.map +1 -0
- package/core/dist/adapters/__tests__/writing-pain-adapter.test.js +239 -0
- package/core/dist/adapters/__tests__/writing-pain-adapter.test.js.map +1 -0
- package/core/dist/adapters/code-review/code-review-pain-adapter.d.ts.map +1 -1
- package/core/dist/adapters/coding/openclaw-pain-adapter.d.ts.map +1 -1
- package/core/dist/adapters/writing/writing-pain-adapter.d.ts.map +1 -1
- package/core/dist/evolution-store.js.map +1 -1
- package/core/dist/evolution-store.test.d.ts +2 -0
- package/core/dist/evolution-store.test.d.ts.map +1 -0
- package/core/dist/evolution-store.test.js +291 -0
- package/core/dist/evolution-store.test.js.map +1 -0
- package/core/dist/host/__tests__/host-adapter.test.d.ts +2 -0
- package/core/dist/host/__tests__/host-adapter.test.d.ts.map +1 -0
- package/core/dist/host/__tests__/host-adapter.test.js +96 -0
- package/core/dist/host/__tests__/host-adapter.test.js.map +1 -0
- package/core/dist/host/host-adapter.d.ts +185 -0
- package/core/dist/host/host-adapter.d.ts.map +1 -0
- package/core/dist/host/host-adapter.js +81 -0
- package/core/dist/host/host-adapter.js.map +1 -0
- package/core/dist/host/host-installer.d.ts +165 -0
- package/core/dist/host/host-installer.d.ts.map +1 -0
- package/core/dist/host/host-installer.js +55 -0
- package/core/dist/host/host-installer.js.map +1 -0
- package/core/dist/host/index.d.ts +14 -0
- package/core/dist/host/index.d.ts.map +1 -0
- package/core/dist/host/index.js +3 -0
- package/core/dist/host/index.js.map +1 -0
- package/core/dist/index.d.ts +2 -0
- package/core/dist/index.d.ts.map +1 -1
- package/core/dist/index.js +1 -0
- package/core/dist/index.js.map +1 -1
- package/core/dist/principle-injector.d.ts.map +1 -1
- package/core/dist/principle-injector.test.d.ts +2 -0
- package/core/dist/principle-injector.test.d.ts.map +1 -0
- package/core/dist/principle-injector.test.js +158 -0
- package/core/dist/principle-injector.test.js.map +1 -0
- package/core/dist/principle-tree-ledger-lifecycle.test.d.ts +2 -0
- package/core/dist/principle-tree-ledger-lifecycle.test.d.ts.map +1 -0
- package/core/dist/principle-tree-ledger-lifecycle.test.js +530 -0
- package/core/dist/principle-tree-ledger-lifecycle.test.js.map +1 -0
- package/core/dist/principle-tree-ledger.d.ts.map +1 -1
- package/core/dist/principle-tree-ledger.js +55 -30
- package/core/dist/principle-tree-ledger.js.map +1 -1
- package/core/dist/prompt-builder/__tests__/attitude-directive.test.d.ts +2 -0
- package/core/dist/prompt-builder/__tests__/attitude-directive.test.d.ts.map +1 -0
- package/core/dist/prompt-builder/__tests__/attitude-directive.test.js +49 -0
- package/core/dist/prompt-builder/__tests__/attitude-directive.test.js.map +1 -0
- package/core/dist/prompt-builder/__tests__/correction-cue.test.d.ts +2 -0
- package/core/dist/prompt-builder/__tests__/correction-cue.test.d.ts.map +1 -0
- package/core/dist/prompt-builder/__tests__/correction-cue.test.js +61 -0
- package/core/dist/prompt-builder/__tests__/correction-cue.test.js.map +1 -0
- package/core/dist/prompt-builder/__tests__/message-extraction.test.d.ts +2 -0
- package/core/dist/prompt-builder/__tests__/message-extraction.test.d.ts.map +1 -0
- package/core/dist/prompt-builder/__tests__/message-extraction.test.js +90 -0
- package/core/dist/prompt-builder/__tests__/message-extraction.test.js.map +1 -0
- package/core/dist/prompt-builder/__tests__/minimal-trigger.test.d.ts +2 -0
- package/core/dist/prompt-builder/__tests__/minimal-trigger.test.d.ts.map +1 -0
- package/core/dist/prompt-builder/__tests__/minimal-trigger.test.js +45 -0
- package/core/dist/prompt-builder/__tests__/minimal-trigger.test.js.map +1 -0
- package/core/dist/prompt-builder/__tests__/principle-selection.test.js.map +1 -1
- package/core/dist/prompt-builder/empathy-keyword-matching.js.map +1 -1
- package/core/dist/prompt-builder/empathy-types.js.map +1 -1
- package/core/dist/prompt-builder/focus-compression.js.map +1 -1
- package/core/dist/prompt-builder/routing-guidance.d.ts +3 -3
- package/core/dist/prompt-builder/routing-guidance.d.ts.map +1 -1
- package/core/dist/prompt-builder/routing-guidance.js.map +1 -1
- package/core/dist/quality-scorecard/__tests__/quality-scorecard.test.js +399 -1
- package/core/dist/quality-scorecard/__tests__/quality-scorecard.test.js.map +1 -1
- package/core/dist/quality-scorecard/__tests__/report-generator.test.d.ts +2 -0
- package/core/dist/quality-scorecard/__tests__/report-generator.test.d.ts.map +1 -0
- package/core/dist/quality-scorecard/__tests__/report-generator.test.js +627 -0
- package/core/dist/quality-scorecard/__tests__/report-generator.test.js.map +1 -0
- package/core/dist/quality-scorecard/types.d.ts +1 -1
- package/core/dist/quality-scorecard/types.d.ts.map +1 -1
- package/core/dist/runtime-v2/__tests__/admission-gate.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/adversarial-loop.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +317 -6
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/artificer-runner-vslice.test.js +839 -0
- package/core/dist/runtime-v2/__tests__/artificer-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/attack-e2e-pipeline-smoke.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/bridge-result-shaper.test.d.ts +26 -0
- package/core/dist/runtime-v2/__tests__/bridge-result-shaper.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/bridge-result-shaper.test.js +402 -0
- package/core/dist/runtime-v2/__tests__/bridge-result-shaper.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/build-golden-trace-from-artificer.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/context-payload-validation.test.d.ts +11 -0
- package/core/dist/runtime-v2/__tests__/context-payload-validation.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/context-payload-validation.test.js +309 -0
- package/core/dist/runtime-v2/__tests__/context-payload-validation.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/diagnostician-output-schema.test.d.ts +25 -0
- package/core/dist/runtime-v2/__tests__/diagnostician-output-schema.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/diagnostician-output-schema.test.js +405 -0
- package/core/dist/runtime-v2/__tests__/diagnostician-output-schema.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/dreamer-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/dreamer-runner.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/error-categories.test.js +1 -0
- package/core/dist/runtime-v2/__tests__/error-categories.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/evaluator-repair-loop.test.d.ts +2 -0
- package/core/dist/runtime-v2/__tests__/evaluator-repair-loop.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/evaluator-repair-loop.test.js +562 -0
- package/core/dist/runtime-v2/__tests__/evaluator-repair-loop.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/feedback/create-report.test.js +51 -0
- package/core/dist/runtime-v2/__tests__/feedback/create-report.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/feedback/privacy-preview.test.js +1 -1
- package/core/dist/runtime-v2/__tests__/feedback/privacy-preview.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/feedback/render-markdown.test.js +1 -1
- package/core/dist/runtime-v2/__tests__/feedback/render-markdown.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/fixtures/test-helpers.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/golden-trace-candidate-builder.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/intake-to-internalization-bridge.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/internalization-consumer-product-path.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/internalization-contracts.test.js +1 -1
- package/core/dist/runtime-v2/__tests__/internalization-contracts.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/internalization-orchestrator.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/internalization-route.test.js +1 -1
- package/core/dist/runtime-v2/__tests__/internalization-route.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/internalization-state-machine.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/l1-hard-cap.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/operator-health-cold-start-guard.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/pain-signal-runtime-factory-edge-cases.test.d.ts +8 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-runtime-factory-edge-cases.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-runtime-factory-edge-cases.test.js +168 -0
- package/core/dist/runtime-v2/__tests__/pain-signal-runtime-factory-edge-cases.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/pain-to-principle-service.test.js +13 -2
- package/core/dist/runtime-v2/__tests__/pain-to-principle-service.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/philosopher-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/pi-artifact-store.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/pitask-metadata.test.js +150 -0
- package/core/dist/runtime-v2/__tests__/pitask-metadata.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/pruning-mask.test.d.ts +25 -0
- package/core/dist/runtime-v2/__tests__/pruning-mask.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/pruning-mask.test.js +281 -0
- package/core/dist/runtime-v2/__tests__/pruning-mask.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/resolve-runtime-config-from-pd-config.test.js +8 -8
- package/core/dist/runtime-v2/__tests__/resolve-runtime-config-from-pd-config.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/rollout-reviewer-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/schema-version.test.d.ts +19 -0
- package/core/dist/runtime-v2/__tests__/schema-version.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/schema-version.test.js +176 -0
- package/core/dist/runtime-v2/__tests__/schema-version.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/scribe-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/story-a-demo.test.js +20 -5
- package/core/dist/runtime-v2/__tests__/story-a-demo.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/task-state-semantics.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/task-three-strikes.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/workflow-funnel-loader.test.d.ts +29 -0
- package/core/dist/runtime-v2/__tests__/workflow-funnel-loader.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/workflow-funnel-loader.test.js +431 -0
- package/core/dist/runtime-v2/__tests__/workflow-funnel-loader.test.js.map +1 -0
- package/core/dist/runtime-v2/__tests__/workspace-leak-guard.test.d.ts +2 -0
- package/core/dist/runtime-v2/__tests__/workspace-leak-guard.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/workspace-leak-guard.test.js +110 -0
- package/core/dist/runtime-v2/__tests__/workspace-leak-guard.test.js.map +1 -0
- package/core/dist/runtime-v2/activation/__tests__/activation-dispatcher.test.js +109 -0
- package/core/dist/runtime-v2/activation/__tests__/activation-dispatcher.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/__tests__/approval-completion-service.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/__tests__/approval-store-extended.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/__tests__/helpers.js.map +1 -1
- package/core/dist/runtime-v2/activation/__tests__/memory-activation-state-store.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/__tests__/prompt-activation-reader-contract.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/activation-dispatcher.d.ts +11 -0
- package/core/dist/runtime-v2/activation/activation-dispatcher.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/activation-dispatcher.js +60 -6
- package/core/dist/runtime-v2/activation/activation-dispatcher.js.map +1 -1
- package/core/dist/runtime-v2/activation/activation-types.d.ts +4 -0
- package/core/dist/runtime-v2/activation/activation-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/approval-completion-service.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/approval-completion-service.js.map +1 -1
- package/core/dist/runtime-v2/activation/approval-queue.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/approval-queue.js.map +1 -1
- package/core/dist/runtime-v2/activation/low-risk-writers.d.ts +2 -2
- package/core/dist/runtime-v2/activation/low-risk-writers.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/memory-activation-state-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/memory-approval-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/prompt-activation-reader-contract.js.map +1 -1
- package/core/dist/runtime-v2/activation/sqlite-activation-state-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js.map +1 -1
- package/core/dist/runtime-v2/activation/sqlite-approval-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/sqlite-approval-store.js.map +1 -1
- package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts +1 -1
- package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/artificer-l2-adapter.test.js +13 -3
- package/core/dist/runtime-v2/adapter/__tests__/artificer-l2-adapter.test.js.map +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/l2-agent-loop-adapter.test.js +3 -2
- package/core/dist/runtime-v2/adapter/__tests__/l2-agent-loop-adapter.test.js.map +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/openclaw-cli-runtime-adapter-message-file.test.d.ts +19 -0
- package/core/dist/runtime-v2/adapter/__tests__/openclaw-cli-runtime-adapter-message-file.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/adapter/__tests__/openclaw-cli-runtime-adapter-message-file.test.js +188 -0
- package/core/dist/runtime-v2/adapter/__tests__/openclaw-cli-runtime-adapter-message-file.test.js.map +1 -0
- package/core/dist/runtime-v2/adapter/__tests__/openclaw-cli-runtime-adapter.test.js +102 -9
- package/core/dist/runtime-v2/adapter/__tests__/openclaw-cli-runtime-adapter.test.js.map +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/pi-ai-runtime-adapter.test.js +57 -29
- package/core/dist/runtime-v2/adapter/__tests__/pi-ai-runtime-adapter.test.js.map +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.js.map +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/runtime-config-contract.test.js +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/runtime-config-contract.test.js.map +1 -1
- package/core/dist/runtime-v2/adapter/artificer-l2-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/artificer-l2-adapter.js +2 -1
- package/core/dist/runtime-v2/adapter/artificer-l2-adapter.js.map +1 -1
- package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.d.ts +1 -1
- package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.js +2 -2
- package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.js.map +1 -1
- package/core/dist/runtime-v2/adapter/openclaw-cli-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/openclaw-cli-runtime-adapter.js +42 -16
- package/core/dist/runtime-v2/adapter/openclaw-cli-runtime-adapter.js.map +1 -1
- package/core/dist/runtime-v2/adapter/output-repair-contract.d.ts +1 -1
- package/core/dist/runtime-v2/adapter/output-repair-contract.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/output-schema-registry.d.ts +36 -0
- package/core/dist/runtime-v2/adapter/output-schema-registry.d.ts.map +1 -0
- package/core/dist/runtime-v2/adapter/output-schema-registry.js +44 -0
- package/core/dist/runtime-v2/adapter/output-schema-registry.js.map +1 -0
- package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts +17 -0
- package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js +61 -33
- package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js.map +1 -1
- package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/schema-prompt-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/structured-output-repair.js.map +1 -1
- package/core/dist/runtime-v2/adapter/test-double-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/test-double-runtime-adapter.js +1 -1
- package/core/dist/runtime-v2/adapter/test-double-runtime-adapter.js.map +1 -1
- package/core/dist/runtime-v2/admission-gate.js.map +1 -1
- package/core/dist/runtime-v2/agent-spec.d.ts +10 -10
- package/core/dist/runtime-v2/agent-spec.d.ts.map +1 -1
- package/core/dist/runtime-v2/candidate-intake-service.d.ts.map +1 -1
- package/core/dist/runtime-v2/candidate-intake.d.ts +5 -5
- package/core/dist/runtime-v2/candidate-intake.d.ts.map +1 -1
- package/core/dist/runtime-v2/candidate-intake.js.map +1 -1
- package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js +29 -1
- package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js.map +1 -1
- package/core/dist/runtime-v2/config/__tests__/pd-config-context-injection.test.d.ts +2 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-context-injection.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-context-injection.test.js +308 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-context-injection.test.js.map +1 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js +5 -4
- package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js.map +1 -1
- package/core/dist/runtime-v2/config/__tests__/pd-config-validation-edge-cases.test.js +44 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-validation-edge-cases.test.js.map +1 -1
- package/core/dist/runtime-v2/config/index.d.ts +1 -1
- package/core/dist/runtime-v2/config/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/index.js.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-agent-binding.d.ts +2 -0
- package/core/dist/runtime-v2/config/pd-config-agent-binding.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-agent-binding.js +16 -0
- package/core/dist/runtime-v2/config/pd-config-agent-binding.js.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-defaults.d.ts +2 -2
- package/core/dist/runtime-v2/config/pd-config-defaults.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-defaults.js +5 -15
- package/core/dist/runtime-v2/config/pd-config-defaults.js.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-effective.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-effective.js.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-feature-flags.d.ts +1 -1
- package/core/dist/runtime-v2/config/pd-config-feature-flags.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-types.d.ts +25 -10
- package/core/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-types.js.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-validate.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-validate.js +9 -0
- package/core/dist/runtime-v2/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime-v2/context-payload.d.ts +8 -8
- package/core/dist/runtime-v2/core-principles/core-axiom-block.js.map +1 -1
- package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.js.map +1 -1
- package/core/dist/runtime-v2/detection/detection-funnel-policy.d.ts.map +1 -1
- package/core/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.js +46 -0
- package/core/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.js.map +1 -1
- package/core/dist/runtime-v2/diagnostician/diag-distiller-output.d.ts +2 -0
- package/core/dist/runtime-v2/diagnostician/diag-distiller-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/diagnostician/diag-distiller-output.js +29 -2
- package/core/dist/runtime-v2/diagnostician/diag-distiller-output.js.map +1 -1
- package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/diagnostician/distiller-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/diagnostician/distiller-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/diagnostician/router-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/diagnostician/router-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/diagnostician-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/diagnostician-output.js +7 -1
- package/core/dist/runtime-v2/diagnostician-output.js.map +1 -1
- package/core/dist/runtime-v2/error-categories.d.ts +2 -2
- package/core/dist/runtime-v2/error-categories.d.ts.map +1 -1
- package/core/dist/runtime-v2/error-categories.js +4 -1
- package/core/dist/runtime-v2/error-categories.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/__tests__/admission-events.test.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/__tests__/triage-policy.test.js.map +1 -1
- package/core/dist/runtime-v2/evidence-triage/trigger-controller.js.map +1 -1
- package/core/dist/runtime-v2/feature-flags/__tests__/artifact-summary-redundancy-flag.test.d.ts +15 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/artifact-summary-redundancy-flag.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/artifact-summary-redundancy-flag.test.js +90 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/artifact-summary-redundancy-flag.test.js.map +1 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/context-manifest-budget-flag.test.d.ts +12 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/context-manifest-budget-flag.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/context-manifest-budget-flag.test.js +114 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/context-manifest-budget-flag.test.js.map +1 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +66 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
- package/core/dist/runtime-v2/feature-flags/__tests__/progressive-evaluator-flag.test.d.ts +8 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/progressive-evaluator-flag.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/progressive-evaluator-flag.test.js +56 -0
- package/core/dist/runtime-v2/feature-flags/__tests__/progressive-evaluator-flag.test.js.map +1 -0
- package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts +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 +56 -1
- package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
- package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.js.map +1 -1
- package/core/dist/runtime-v2/feature-flags/surface-guard-policy.js.map +1 -1
- package/core/dist/runtime-v2/feedback/__tests__/create-report-agent-draft.test.d.ts +2 -0
- package/core/dist/runtime-v2/feedback/__tests__/create-report-agent-draft.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/create-report-agent-draft.test.js +221 -0
- package/core/dist/runtime-v2/feedback/__tests__/create-report-agent-draft.test.js.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/mailto-url.test.d.ts +11 -0
- package/core/dist/runtime-v2/feedback/__tests__/mailto-url.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/mailto-url.test.js +160 -0
- package/core/dist/runtime-v2/feedback/__tests__/mailto-url.test.js.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/pending-agent-draft-store.test.d.ts +2 -0
- package/core/dist/runtime-v2/feedback/__tests__/pending-agent-draft-store.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/feedback/__tests__/pending-agent-draft-store.test.js +342 -0
- package/core/dist/runtime-v2/feedback/__tests__/pending-agent-draft-store.test.js.map +1 -0
- package/core/dist/runtime-v2/feedback/create-report.d.ts +7 -1
- package/core/dist/runtime-v2/feedback/create-report.d.ts.map +1 -1
- package/core/dist/runtime-v2/feedback/create-report.js +65 -7
- package/core/dist/runtime-v2/feedback/create-report.js.map +1 -1
- package/core/dist/runtime-v2/feedback/feedback-types.d.ts +18 -1
- package/core/dist/runtime-v2/feedback/feedback-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/feedback/feedback-types.js +19 -12
- package/core/dist/runtime-v2/feedback/feedback-types.js.map +1 -1
- package/core/dist/runtime-v2/feedback/index.d.ts +3 -1
- package/core/dist/runtime-v2/feedback/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/feedback/index.js +7 -1
- package/core/dist/runtime-v2/feedback/index.js.map +1 -1
- package/core/dist/runtime-v2/feedback/pending-agent-draft-store.d.ts +106 -0
- package/core/dist/runtime-v2/feedback/pending-agent-draft-store.d.ts.map +1 -0
- package/core/dist/runtime-v2/feedback/pending-agent-draft-store.js +220 -0
- package/core/dist/runtime-v2/feedback/pending-agent-draft-store.js.map +1 -0
- package/core/dist/runtime-v2/feedback/privacy-preview.d.ts +16 -0
- package/core/dist/runtime-v2/feedback/privacy-preview.d.ts.map +1 -1
- package/core/dist/runtime-v2/feedback/privacy-preview.js +54 -0
- package/core/dist/runtime-v2/feedback/privacy-preview.js.map +1 -1
- package/core/dist/runtime-v2/feedback/redact-sensitive.js.map +1 -1
- package/core/dist/runtime-v2/feedback/render-markdown.js.map +1 -1
- package/core/dist/runtime-v2/full-trace-contract.d.ts +8 -8
- package/core/dist/runtime-v2/full-trace-contract.d.ts.map +1 -1
- package/core/dist/runtime-v2/gfi/__tests__/gfi-kernel.test.js.map +1 -1
- package/core/dist/runtime-v2/gfi/__tests__/gfi-read-model.test.js.map +1 -1
- package/core/dist/runtime-v2/gfi/gfi-kernel.js.map +1 -1
- package/core/dist/runtime-v2/golden-trace.js.map +1 -1
- package/core/dist/runtime-v2/index.d.ts +11 -2
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +13 -1
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.js.map +1 -1
- package/core/dist/runtime-v2/intent/intent-doc-reader-port.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/adversarial-case.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/adversarial-feedback.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/artifact-content-hash.property.test.d.ts +11 -0
- package/core/dist/runtime-v2/internalization/__tests__/artifact-content-hash.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/artifact-content-hash.property.test.js +124 -0
- package/core/dist/runtime-v2/internalization/__tests__/artifact-content-hash.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/artifact-summary.property.test.d.ts +12 -0
- package/core/dist/runtime-v2/internalization/__tests__/artifact-summary.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/artifact-summary.property.test.js +253 -0
- package/core/dist/runtime-v2/internalization/__tests__/artifact-summary.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/artificer-prompt-builder.test.js +175 -0
- package/core/dist/runtime-v2/internalization/__tests__/artificer-prompt-builder.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/behavior-example-pack.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js +32 -5
- package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/candidate-lineage.property.test.d.ts +15 -0
- package/core/dist/runtime-v2/internalization/__tests__/candidate-lineage.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/candidate-lineage.property.test.js +301 -0
- package/core/dist/runtime-v2/internalization/__tests__/candidate-lineage.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/context-manifest.property.test.d.ts +12 -0
- package/core/dist/runtime-v2/internalization/__tests__/context-manifest.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/context-manifest.property.test.js +176 -0
- package/core/dist/runtime-v2/internalization/__tests__/context-manifest.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/internalization-consumer-decision.test.js +27 -1
- package/core/dist/runtime-v2/internalization/__tests__/internalization-consumer-decision.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/internalization-task-guards.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-toggle-characterization.test.d.ts +2 -0
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-toggle-characterization.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-toggle-characterization.test.js +279 -0
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-toggle-characterization.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-scope-regression.test.d.ts +22 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-scope-regression.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-scope-regression.test.js +92 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-scope-regression.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.d.ts +165 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.js +659 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.test.d.ts +22 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.test.js +229 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike-fixtures.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike.test.d.ts +2 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike.test.js +1039 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-disclosure-spike.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator-stage-isolation.property.test.d.ts +13 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator-stage-isolation.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator-stage-isolation.property.test.js +257 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator-stage-isolation.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator.property.test.d.ts +11 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator.property.test.js +154 -0
- package/core/dist/runtime-v2/internalization/__tests__/progressive-evaluator.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/prompt-budget-manager.property.test.d.ts +12 -0
- package/core/dist/runtime-v2/internalization/__tests__/prompt-budget-manager.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/prompt-budget-manager.property.test.js +254 -0
- package/core/dist/runtime-v2/internalization/__tests__/prompt-budget-manager.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/queue-actionability.test.js +14 -5
- package/core/dist/runtime-v2/internalization/__tests__/queue-actionability.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/refiner-rulehost-gate.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/refiner-sandbox-wrapper.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/resolve-injection.property.test.d.ts +15 -0
- package/core/dist/runtime-v2/internalization/__tests__/resolve-injection.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/resolve-injection.property.test.js +150 -0
- package/core/dist/runtime-v2/internalization/__tests__/resolve-injection.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/rule-code-dialect.test.js +29 -0
- package/core/dist/runtime-v2/internalization/__tests__/rule-code-dialect.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/rule-context-v2.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/split-diagnostician-runner-retry.test.js +173 -0
- package/core/dist/runtime-v2/internalization/__tests__/split-diagnostician-runner-retry.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/summary-chain-flow.property.test.d.ts +22 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-chain-flow.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-chain-flow.property.test.js +280 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-chain-flow.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-envelope-writer.property.test.d.ts +25 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-envelope-writer.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-envelope-writer.property.test.js +413 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-envelope-writer.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-freshness.property.test.d.ts +12 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-freshness.property.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-freshness.property.test.js +176 -0
- package/core/dist/runtime-v2/internalization/__tests__/summary-freshness.property.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/artifact-content-hash.d.ts +19 -0
- package/core/dist/runtime-v2/internalization/artifact-content-hash.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/artifact-content-hash.js +116 -0
- package/core/dist/runtime-v2/internalization/artifact-content-hash.js.map +1 -0
- package/core/dist/runtime-v2/internalization/artifact-summary.d.ts +106 -0
- package/core/dist/runtime-v2/internalization/artifact-summary.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/artifact-summary.js +331 -0
- package/core/dist/runtime-v2/internalization/artifact-summary.js.map +1 -0
- package/core/dist/runtime-v2/internalization/artificer-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts +42 -1
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js +22 -3
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-runner.d.ts +22 -0
- package/core/dist/runtime-v2/internalization/artificer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-runner.js +229 -3
- package/core/dist/runtime-v2/internalization/artificer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/attach-summary-envelope.d.ts +60 -0
- package/core/dist/runtime-v2/internalization/attach-summary-envelope.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/attach-summary-envelope.js +126 -0
- package/core/dist/runtime-v2/internalization/attach-summary-envelope.js.map +1 -0
- package/core/dist/runtime-v2/internalization/candidate-lineage.d.ts +136 -0
- package/core/dist/runtime-v2/internalization/candidate-lineage.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/candidate-lineage.js +230 -0
- package/core/dist/runtime-v2/internalization/candidate-lineage.js.map +1 -0
- package/core/dist/runtime-v2/internalization/context-manifest.d.ts +117 -0
- package/core/dist/runtime-v2/internalization/context-manifest.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/context-manifest.js +156 -0
- package/core/dist/runtime-v2/internalization/context-manifest.js.map +1 -0
- package/core/dist/runtime-v2/internalization/context-manifests.d.ts +74 -0
- package/core/dist/runtime-v2/internalization/context-manifests.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/context-manifests.js +192 -0
- package/core/dist/runtime-v2/internalization/context-manifests.js.map +1 -0
- package/core/dist/runtime-v2/internalization/correction-proposal.js.map +1 -1
- package/core/dist/runtime-v2/internalization/diag-distiller-runner.d.ts +1 -1
- package/core/dist/runtime-v2/internalization/diag-distiller-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/diag-distiller-runner.js +23 -2
- package/core/dist/runtime-v2/internalization/diag-distiller-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js +9 -1
- package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/diag-router-runner.d.ts +7 -2
- package/core/dist/runtime-v2/internalization/diag-router-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/diag-router-runner.js +28 -1
- package/core/dist/runtime-v2/internalization/diag-router-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/dimension-coverage-policy.d.ts +54 -0
- package/core/dist/runtime-v2/internalization/dimension-coverage-policy.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/dimension-coverage-policy.js +70 -0
- package/core/dist/runtime-v2/internalization/dimension-coverage-policy.js.map +1 -0
- package/core/dist/runtime-v2/internalization/dreamer-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-runner.d.ts +9 -1
- package/core/dist/runtime-v2/internalization/dreamer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-runner.js +41 -7
- package/core/dist/runtime-v2/internalization/dreamer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-output.d.ts +27 -1
- package/core/dist/runtime-v2/internalization/evaluator-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-output.js +7 -1
- package/core/dist/runtime-v2/internalization/evaluator-output.js.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.d.ts +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.js +12 -0
- package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts +115 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.js +384 -5
- package/core/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/index.d.ts +2 -0
- package/core/dist/runtime-v2/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/index.js +2 -0
- package/core/dist/runtime-v2/internalization/index.js.map +1 -1
- package/core/dist/runtime-v2/internalization/internalization-consumer-decision.d.ts +24 -0
- package/core/dist/runtime-v2/internalization/internalization-consumer-decision.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/internalization-consumer-decision.js +25 -2
- package/core/dist/runtime-v2/internalization/internalization-consumer-decision.js.map +1 -1
- package/core/dist/runtime-v2/internalization/internalization-orchestrator.d.ts +1 -1
- package/core/dist/runtime-v2/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/internalization-orchestrator.js +44 -1
- package/core/dist/runtime-v2/internalization/internalization-orchestrator.js.map +1 -1
- package/core/dist/runtime-v2/internalization/internalization-task-guards.js.map +1 -1
- package/core/dist/runtime-v2/internalization/lifecycle-read-model.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts +3 -0
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.js.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-runner.js +25 -1
- package/core/dist/runtime-v2/internalization/philosopher-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/pi-artifact-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/pitask-metadata.d.ts +35 -1
- package/core/dist/runtime-v2/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/pitask-metadata.js +64 -0
- package/core/dist/runtime-v2/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime-v2/internalization/progressive-evaluator.d.ts +115 -0
- package/core/dist/runtime-v2/internalization/progressive-evaluator.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/progressive-evaluator.js +248 -0
- package/core/dist/runtime-v2/internalization/progressive-evaluator.js.map +1 -0
- package/core/dist/runtime-v2/internalization/prompt-budget-manager.d.ts +90 -0
- package/core/dist/runtime-v2/internalization/prompt-budget-manager.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/prompt-budget-manager.js +149 -0
- package/core/dist/runtime-v2/internalization/prompt-budget-manager.js.map +1 -0
- package/core/dist/runtime-v2/internalization/queue-actionability.d.ts +11 -0
- package/core/dist/runtime-v2/internalization/queue-actionability.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/queue-actionability.js +12 -0
- package/core/dist/runtime-v2/internalization/queue-actionability.js.map +1 -1
- package/core/dist/runtime-v2/internalization/resolve-injection.d.ts +62 -0
- package/core/dist/runtime-v2/internalization/resolve-injection.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/resolve-injection.js +78 -0
- package/core/dist/runtime-v2/internalization/resolve-injection.js.map +1 -0
- package/core/dist/runtime-v2/internalization/rollout-reviewer-output.d.ts +1 -1
- package/core/dist/runtime-v2/internalization/rollout-reviewer-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/rollout-reviewer-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/routing-policy.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/rule-code-validator.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/rule-code-validator.js +7 -1
- package/core/dist/runtime-v2/internalization/rule-code-validator.js.map +1 -1
- package/core/dist/runtime-v2/internalization/rule-host-input-builder.js.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-runner.js +33 -1
- package/core/dist/runtime-v2/internalization/scribe-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/split-diagnostician-runner.js +75 -13
- package/core/dist/runtime-v2/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/summary-field-reader.d.ts +38 -0
- package/core/dist/runtime-v2/internalization/summary-field-reader.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/summary-field-reader.js +108 -0
- package/core/dist/runtime-v2/internalization/summary-field-reader.js.map +1 -0
- package/core/dist/runtime-v2/internalization-chain-integrity-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization-integrity-remediation.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization-queue-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization-queue-read-model.js.map +1 -1
- package/core/dist/runtime-v2/language-directive.d.ts +1 -1
- package/core/dist/runtime-v2/language-directive.d.ts.map +1 -1
- package/core/dist/runtime-v2/language-directive.js.map +1 -1
- package/core/dist/runtime-v2/mainline-contract.js.map +1 -1
- package/core/dist/runtime-v2/observer/agent-scheduler.d.ts.map +1 -1
- package/core/dist/runtime-v2/observer/correction-observer.d.ts.map +1 -1
- package/core/dist/runtime-v2/observer/empathy-observer.d.ts.map +1 -1
- package/core/dist/runtime-v2/operator-health-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-chain-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.js.map +1 -1
- package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts +1 -1
- package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts +4 -0
- package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-signal-runtime-factory.js +3 -1
- package/core/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime-v2/pain-to-principle-service.d.ts +2 -0
- package/core/dist/runtime-v2/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-to-principle-service.js +2 -0
- package/core/dist/runtime-v2/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime-v2/proven-channel-baseline.js +1 -1
- package/core/dist/runtime-v2/proven-channel-baseline.js.map +1 -1
- package/core/dist/runtime-v2/pruning-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/recovery-sweep-service.js.map +1 -1
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-agent-draft.test.d.ts +2 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-agent-draft.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-agent-draft.test.js +459 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-agent-draft.test.js.map +1 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-rate-limit-degradation.test.d.ts +2 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-rate-limit-degradation.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-rate-limit-degradation.test.js +320 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-rate-limit-degradation.test.js.map +1 -0
- package/core/dist/runtime-v2/runner/__tests__/default-validator.test.js +63 -0
- package/core/dist/runtime-v2/runner/__tests__/default-validator.test.js.map +1 -1
- package/core/dist/runtime-v2/runner/__tests__/diagnose.test.js.map +1 -1
- package/core/dist/runtime-v2/runner/base-peer-runner.d.ts +117 -4
- package/core/dist/runtime-v2/runner/base-peer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/runner/base-peer-runner.js +403 -0
- package/core/dist/runtime-v2/runner/base-peer-runner.js.map +1 -1
- package/core/dist/runtime-v2/runner/default-validator.d.ts.map +1 -1
- package/core/dist/runtime-v2/runner/default-validator.js +31 -3
- package/core/dist/runtime-v2/runner/default-validator.js.map +1 -1
- package/core/dist/runtime-v2/runner/diagnostician-validator.d.ts.map +1 -1
- package/core/dist/runtime-v2/runner/peer-runner-types.d.ts +36 -0
- package/core/dist/runtime-v2/runner/peer-runner-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/runtime-protocol.d.ts +1 -1
- package/core/dist/runtime-v2/schema-conformance-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/signal-collector/types.d.ts.map +1 -1
- package/core/dist/runtime-v2/stalled-diagnostician-task-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/artifact/memory-artifact-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/artifact/memory-artifact-store.js.map +1 -1
- package/core/dist/runtime-v2/store/artifact/sqlite-artifact-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/artifact/sqlite-artifact-store.js.map +1 -1
- package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.js.map +1 -1
- package/core/dist/runtime-v2/store/candidate/memory-candidate-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/candidate/sqlite-candidate-store.js.map +1 -1
- package/core/dist/runtime-v2/store/commit/diagnostician-committer.d.ts +15 -0
- package/core/dist/runtime-v2/store/commit/diagnostician-committer.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/commit/diagnostician-committer.js +32 -1
- package/core/dist/runtime-v2/store/commit/diagnostician-committer.js.map +1 -1
- package/core/dist/runtime-v2/store/commit/memory-commit-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/commit/sqlite-commit-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/commit/sqlite-commit-store.js.map +1 -1
- package/core/dist/runtime-v2/store/context/resilient-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/context/resilient-context-assembler.js.map +1 -1
- package/core/dist/runtime-v2/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime-v2/store/diagnostician-committer.test.js +36 -2
- package/core/dist/runtime-v2/store/diagnostician-committer.test.js.map +1 -1
- package/core/dist/runtime-v2/store/event-emitter.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/history/resilient-history-query.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/history/resilient-history-query.js.map +1 -1
- package/core/dist/runtime-v2/store/history/sqlite-history-query.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/history/sqlite-history-query.js.map +1 -1
- package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.js.map +1 -1
- package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.js.map +1 -1
- package/core/dist/runtime-v2/store/intent/sqlite-intent-doc-version-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/intent/sqlite-intent-doc-version-store.js.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/lease-manager.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/lease-manager.js.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/lease-manager.test.js.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/recovery-sweep.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/recovery-sweep.js.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/recovery-sweep.test.js.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/retry-policy.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/lifecycle/retry-policy.js.map +1 -1
- package/core/dist/runtime-v2/store/pain/__tests__/sqlite-dead-letter-store.test.d.ts +2 -0
- package/core/dist/runtime-v2/store/pain/__tests__/sqlite-dead-letter-store.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/store/pain/__tests__/sqlite-dead-letter-store.test.js +225 -0
- package/core/dist/runtime-v2/store/pain/__tests__/sqlite-dead-letter-store.test.js.map +1 -0
- package/core/dist/runtime-v2/store/pain/index.d.ts +3 -0
- package/core/dist/runtime-v2/store/pain/index.d.ts.map +1 -0
- package/core/dist/runtime-v2/store/pain/index.js +2 -0
- package/core/dist/runtime-v2/store/pain/index.js.map +1 -0
- package/core/dist/runtime-v2/store/pain/sqlite-dead-letter-store.d.ts +70 -0
- package/core/dist/runtime-v2/store/pain/sqlite-dead-letter-store.d.ts.map +1 -0
- package/core/dist/runtime-v2/store/pain/sqlite-dead-letter-store.js +154 -0
- package/core/dist/runtime-v2/store/pain/sqlite-dead-letter-store.js.map +1 -0
- package/core/dist/runtime-v2/store/run/memory-run-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/run/sqlite-run-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/run/sqlite-run-store.js.map +1 -1
- package/core/dist/runtime-v2/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/runtime-state-manager.integration.test.js.map +1 -1
- package/core/dist/runtime-v2/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/sqlite-connection.js +46 -1
- package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
- package/core/dist/runtime-v2/store/sqlite-task-store.test.js.map +1 -1
- package/core/dist/runtime-v2/store/task/__tests__/sqlite-task-store.failed-tasks.test.d.ts +2 -0
- package/core/dist/runtime-v2/store/task/__tests__/sqlite-task-store.failed-tasks.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/store/task/__tests__/sqlite-task-store.failed-tasks.test.js +442 -0
- package/core/dist/runtime-v2/store/task/__tests__/sqlite-task-store.failed-tasks.test.js.map +1 -0
- package/core/dist/runtime-v2/store/task/index.d.ts +1 -0
- package/core/dist/runtime-v2/store/task/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/task/index.js.map +1 -1
- package/core/dist/runtime-v2/store/task/memory-task-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts +45 -0
- package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/task/sqlite-task-store.js +205 -0
- package/core/dist/runtime-v2/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime-v2/store/task/task-types.d.ts +60 -0
- package/core/dist/runtime-v2/store/task/task-types.d.ts.map +1 -0
- package/core/dist/runtime-v2/store/task/task-types.js +2 -0
- package/core/dist/runtime-v2/store/task/task-types.js.map +1 -0
- package/core/dist/runtime-v2/store/task-migration.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/task-migration.js.map +1 -1
- package/core/dist/runtime-v2/store/trajectory/source-trace-locator.test.js.map +1 -1
- package/core/dist/runtime-v2/store/trajectory/sqlite-source-trace-locator.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/trajectory/sqlite-source-trace-locator.js.map +1 -1
- package/core/dist/runtime-v2/store/trajectory/sqlite-trajectory-locator.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/trajectory/sqlite-trajectory-locator.js.map +1 -1
- package/core/dist/runtime-v2/store/workspace-leak-guard.d.ts +23 -0
- package/core/dist/runtime-v2/store/workspace-leak-guard.d.ts.map +1 -0
- package/core/dist/runtime-v2/store/workspace-leak-guard.js +111 -0
- package/core/dist/runtime-v2/store/workspace-leak-guard.js.map +1 -0
- package/core/dist/runtime-v2/story-a-demo.d.ts +1 -1
- package/core/dist/runtime-v2/story-a-demo.d.ts.map +1 -1
- package/core/dist/runtime-v2/story-a-demo.js +8 -10
- package/core/dist/runtime-v2/story-a-demo.js.map +1 -1
- package/core/dist/runtime-v2/task-status.d.ts +2 -2
- package/core/dist/runtime-v2/tools/__tests__/agent-tool-contract.test.js.map +1 -1
- package/core/dist/runtime-v2/tools/__tests__/artificer-l2-tool-contract.test.js.map +1 -1
- package/core/dist/runtime-v2/tools/__tests__/dreamer-output-typebox.test.js.map +1 -1
- package/core/dist/runtime-v2/trace-refiner.d.ts +2 -2
- package/core/dist/runtime-v2/trace-refiner.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/evidence-chain-contract.js.map +1 -1
- package/core/dist/trajectory-store.js.map +1 -1
- package/core/dist/trajectory-store.test.d.ts +2 -0
- package/core/dist/trajectory-store.test.d.ts.map +1 -0
- package/core/dist/trajectory-store.test.js +251 -0
- package/core/dist/trajectory-store.test.js.map +1 -0
- package/core/dist/workflow-funnel-loader.d.ts.map +1 -1
- package/core/package.json +13 -7
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +56 -6
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +186 -27
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +11 -2
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +296 -145
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts +15 -0
- package/dist/installers/codex-host-installer.d.ts.map +1 -0
- package/dist/installers/codex-host-installer.js +445 -0
- package/dist/installers/codex-host-installer.js.map +1 -0
- package/dist/installers/index.d.ts +40 -0
- package/dist/installers/index.d.ts.map +1 -0
- package/dist/installers/index.js +35 -0
- package/dist/installers/index.js.map +1 -0
- package/dist/installers/openclaw-host-installer.d.ts +18 -0
- package/dist/installers/openclaw-host-installer.d.ts.map +1 -0
- package/dist/installers/openclaw-host-installer.js +404 -0
- package/dist/installers/openclaw-host-installer.js.map +1 -0
- package/dist/mvp-config.d.ts +23 -4
- package/dist/mvp-config.d.ts.map +1 -1
- package/dist/mvp-config.js +15 -7
- package/dist/mvp-config.js.map +1 -1
- package/dist/prompts.d.ts +17 -1
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +114 -0
- package/dist/prompts.js.map +1 -1
- package/dist/uninstaller.d.ts +18 -1
- package/dist/uninstaller.d.ts.map +1 -1
- package/dist/uninstaller.js +60 -75
- package/dist/uninstaller.js.map +1 -1
- package/dist/updater.d.ts +0 -6
- package/dist/updater.d.ts.map +1 -1
- package/dist/updater.js +0 -11
- package/dist/updater.js.map +1 -1
- package/dist/utils/env.d.ts +14 -0
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +35 -2
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/package.json +7 -7
- package/pd-cli/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +2 -0
- package/pd-cli/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +1 -0
- package/pd-cli/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +60 -0
- package/pd-cli/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +1 -0
- package/pd-cli/dist/commands/__tests__/rulecode-flag-wiring.test.js +11 -4
- package/pd-cli/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +1 -1
- package/pd-cli/dist/commands/__tests__/runtime-probe-config.test.js +2 -2
- package/pd-cli/dist/commands/__tests__/runtime-probe-config.test.js.map +1 -1
- package/pd-cli/dist/commands/admission-gate.d.ts +24 -0
- package/pd-cli/dist/commands/admission-gate.d.ts.map +1 -0
- package/pd-cli/dist/commands/admission-gate.js +29 -0
- package/pd-cli/dist/commands/admission-gate.js.map +1 -0
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +2 -21
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/console.d.ts.map +1 -1
- package/pd-cli/dist/commands/console.js +40 -0
- package/pd-cli/dist/commands/console.js.map +1 -1
- package/pd-cli/dist/commands/demo-story-a.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +88 -9
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/errors-list.d.ts +25 -0
- package/pd-cli/dist/commands/errors-list.d.ts.map +1 -0
- package/pd-cli/dist/commands/errors-list.js +368 -0
- package/pd-cli/dist/commands/errors-list.js.map +1 -0
- package/pd-cli/dist/commands/health.js.map +1 -1
- package/pd-cli/dist/commands/pain-evidence.d.ts +6 -0
- package/pd-cli/dist/commands/pain-evidence.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-evidence.js +6 -0
- package/pd-cli/dist/commands/pain-evidence.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts +1 -0
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +288 -19
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/proven-channel-baseline.js.map +1 -1
- package/pd-cli/dist/commands/runtime-canary.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-canary.js +28 -5
- package/pd-cli/dist/commands/runtime-canary.js.map +1 -1
- package/pd-cli/dist/commands/runtime-init.js +2 -2
- package/pd-cli/dist/commands/runtime-init.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-context-trace.d.ts +25 -0
- package/pd-cli/dist/commands/runtime-internalization-context-trace.d.ts.map +1 -0
- package/pd-cli/dist/commands/runtime-internalization-context-trace.js +374 -0
- package/pd-cli/dist/commands/runtime-internalization-context-trace.js.map +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 +20 -5
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.guard.test.js +13 -15
- package/pd-cli/dist/commands/runtime-uat.guard.test.js.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
- package/pd-cli/dist/index.js +21 -3
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/__tests__/evaluator-runner-deps.test.d.ts +2 -0
- package/pd-cli/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +1 -0
- package/pd-cli/dist/services/__tests__/evaluator-runner-deps.test.js +304 -0
- package/pd-cli/dist/services/__tests__/evaluator-runner-deps.test.js.map +1 -0
- package/pd-cli/dist/services/__tests__/rulehost-readiness.test.js.map +1 -1
- package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js.map +1 -1
- package/pd-cli/dist/services/config-doctor.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 +9 -0
- package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
- package/pd-cli/dist/services/proven-channel-baseline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/proven-channel-baseline-runner.js +10 -2
- package/pd-cli/dist/services/proven-channel-baseline-runner.js.map +1 -1
- package/pd-cli/dist/services/quality-scorecard/data-extractor.js.map +1 -1
- package/pd-cli/dist/services/resolve-runtime-from-pd-config.js.map +1 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts +73 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.js +107 -6
- package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/pd-cli/dist/services/rulehost-readiness.js.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts +1 -0
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.js +2 -0
- package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/pd-cli/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/synthetic-baseline-runner.js +11 -0
- package/pd-cli/dist/services/synthetic-baseline-runner.js.map +1 -1
- package/pd-cli/dist/utils/production-workspace-guard.d.ts +4 -4
- package/pd-cli/dist/utils/production-workspace-guard.d.ts.map +1 -1
- package/pd-cli/dist/utils/production-workspace-guard.js +19 -16
- package/pd-cli/dist/utils/production-workspace-guard.js.map +1 -1
- package/pd-cli/dist/utils/production-workspace-guard.test.js +54 -19
- package/pd-cli/dist/utils/production-workspace-guard.test.js.map +1 -1
- package/pd-cli/package.json +4 -4
- package/plugin/dist/assets/logo.svg +11 -0
- package/plugin/dist/bundle.js +3152 -0
- package/plugin/dist/commands/workflow-debug.d.ts +1 -3
- package/plugin/dist/config/defaults/runtime.d.ts +1 -1
- package/plugin/dist/constants/tools.d.ts +4 -4
- package/plugin/dist/core/config-health.d.ts +1 -11
- package/plugin/dist/core/dictionary.d.ts +1 -1
- package/plugin/dist/core/path-resolver.d.ts +3 -3
- package/plugin/dist/core/signal-collector-host.d.ts +9 -1
- package/plugin/dist/core/system-logger.d.ts +16 -0
- package/plugin/dist/index.d.ts +1 -1
- package/plugin/dist/index.js +1 -756
- package/plugin/dist/openclaw-sdk.d.ts +49 -8
- package/plugin/dist/openclaw.plugin.json +65 -0
- package/plugin/dist/service/evolution-worker.d.ts +27 -1
- package/plugin/dist/templates/langs/en/core/AGENTS.md +205 -0
- package/plugin/dist/templates/langs/en/core/BOOT.md +60 -0
- package/plugin/dist/templates/langs/en/core/BOOTSTRAP.md +259 -0
- package/plugin/dist/templates/langs/en/core/HEARTBEAT.md +74 -0
- package/plugin/dist/templates/langs/en/core/IDENTITY.md +8 -0
- package/plugin/dist/templates/langs/en/core/PRINCIPLES.md +10 -0
- package/plugin/dist/templates/langs/en/core/SOUL.md +46 -0
- package/plugin/dist/templates/langs/en/core/TOOLS.md +15 -0
- package/plugin/dist/templates/langs/en/core/USER.md +10 -0
- package/plugin/dist/templates/langs/en/pain/00_seed_samples.md +23 -0
- package/plugin/dist/templates/langs/en/pain_dictionary.json +22 -0
- package/plugin/dist/templates/langs/en/principles/THINKING_OS.md +77 -0
- package/plugin/dist/templates/langs/en/skills/admin/SKILL.md +39 -0
- package/plugin/dist/templates/langs/en/skills/ai-sprint-orchestration/runtime/.gitignore +2 -0
- package/plugin/dist/templates/langs/en/skills/bootstrap-tools/SKILL.md +53 -0
- package/plugin/dist/templates/langs/en/skills/deductive-audit/SKILL.md +36 -0
- package/plugin/dist/templates/langs/en/skills/evolution-framework-update/SKILL.md +31 -0
- package/plugin/dist/templates/langs/en/skills/evolve-task/SKILL.md +83 -0
- package/plugin/dist/templates/langs/en/skills/feedback/SKILL.md +51 -0
- package/plugin/dist/templates/langs/en/skills/init-strategy/SKILL.md +54 -0
- package/plugin/dist/templates/langs/en/skills/inject-rule/SKILL.md +19 -0
- package/plugin/dist/templates/langs/en/skills/pd-auditor/SKILL.md +61 -0
- package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +76 -0
- package/plugin/dist/templates/langs/en/skills/pd-explorer/SKILL.md +65 -0
- package/plugin/dist/templates/langs/en/skills/pd-implementer/SKILL.md +68 -0
- package/plugin/dist/templates/langs/en/skills/pd-mentor/SKILL.md +213 -0
- package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +30 -0
- package/plugin/dist/templates/langs/en/skills/pd-planner/SKILL.md +65 -0
- package/plugin/dist/templates/langs/en/skills/pd-runtime-v2/SKILL.md +71 -0
- package/plugin/dist/templates/langs/en/skills/profile/SKILL.md +24 -0
- package/plugin/dist/templates/langs/en/skills/reflection/SKILL.md +40 -0
- package/plugin/dist/templates/langs/en/skills/reflection-log/SKILL.md +37 -0
- package/plugin/dist/templates/langs/en/skills/report/SKILL.md +13 -0
- package/plugin/dist/templates/langs/en/skills/root-cause/SKILL.md +33 -0
- package/plugin/dist/templates/langs/en/skills/triage/SKILL.md +29 -0
- package/plugin/dist/templates/langs/en/skills/watch-evolution/SKILL.md +33 -0
- package/plugin/dist/templates/langs/zh/core/AGENTS.md +197 -0
- package/plugin/dist/templates/langs/zh/core/BOOT.md +60 -0
- package/plugin/dist/templates/langs/zh/core/BOOTSTRAP.md +260 -0
- package/plugin/dist/templates/langs/zh/core/HEARTBEAT.md +98 -0
- package/plugin/dist/templates/langs/zh/core/IDENTITY.md +8 -0
- package/plugin/dist/templates/langs/zh/core/PRINCIPLES.md +7 -0
- package/plugin/dist/templates/langs/zh/core/SOUL.md +46 -0
- package/plugin/dist/templates/langs/zh/core/TOOLS.md +15 -0
- package/plugin/dist/templates/langs/zh/core/USER.md +10 -0
- package/plugin/dist/templates/langs/zh/pain/00_seed_samples.md +24 -0
- package/plugin/dist/templates/langs/zh/pain_dictionary.json +18 -0
- package/plugin/dist/templates/langs/zh/principles/THINKING_OS.md +77 -0
- package/plugin/dist/templates/langs/zh/skills/admin/SKILL.md +41 -0
- package/plugin/dist/templates/langs/zh/skills/bootstrap-tools/SKILL.md +52 -0
- package/plugin/dist/templates/langs/zh/skills/deductive-audit/SKILL.md +36 -0
- package/plugin/dist/templates/langs/zh/skills/evolution-framework-update/SKILL.md +31 -0
- package/plugin/dist/templates/langs/zh/skills/evolve-task/SKILL.md +83 -0
- package/plugin/dist/templates/langs/zh/skills/feedback/SKILL.md +53 -0
- package/plugin/dist/templates/langs/zh/skills/init-strategy/SKILL.md +54 -0
- package/plugin/dist/templates/langs/zh/skills/inject-rule/SKILL.md +19 -0
- package/plugin/dist/templates/langs/zh/skills/pd-auditor/SKILL.md +61 -0
- package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +76 -0
- package/plugin/dist/templates/langs/zh/skills/pd-explorer/SKILL.md +65 -0
- package/plugin/dist/templates/langs/zh/skills/pd-implementer/SKILL.md +68 -0
- package/plugin/dist/templates/langs/zh/skills/pd-mentor/SKILL.md +213 -0
- package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +30 -0
- package/plugin/dist/templates/langs/zh/skills/pd-planner/SKILL.md +65 -0
- package/plugin/dist/templates/langs/zh/skills/pd-runtime-v2/SKILL.md +71 -0
- package/plugin/dist/templates/langs/zh/skills/profile/SKILL.md +24 -0
- package/plugin/dist/templates/langs/zh/skills/reflection/SKILL.md +40 -0
- package/plugin/dist/templates/langs/zh/skills/reflection-log/SKILL.md +37 -0
- package/plugin/dist/templates/langs/zh/skills/report/SKILL.md +13 -0
- package/plugin/dist/templates/langs/zh/skills/root-cause/SKILL.md +33 -0
- package/plugin/dist/templates/langs/zh/skills/triage/SKILL.md +29 -0
- package/plugin/dist/templates/langs/zh/skills/watch-evolution/SKILL.md +33 -0
- package/plugin/dist/templates/pain_dictionary.json +36 -0
- package/plugin/dist/templates/pain_settings.json +103 -0
- package/plugin/dist/templates/workspace/.principles/DECISION_POLICY.json +44 -0
- package/plugin/dist/templates/workspace/.principles/PRINCIPLES.md +20 -0
- package/plugin/dist/templates/workspace/.principles/PROFILE.json +54 -0
- package/plugin/dist/templates/workspace/.principles/PROFILE.schema.json +56 -0
- package/plugin/dist/templates/workspace/.principles/THINKING_OS.md +65 -0
- package/plugin/dist/templates/workspace/.principles/THINKING_OS_ARCHIVE.md +7 -0
- package/plugin/dist/templates/workspace/.principles/THINKING_OS_CANDIDATES.md +9 -0
- package/plugin/dist/templates/workspace/.principles/models/_INDEX.md +27 -0
- package/plugin/dist/templates/workspace/.principles/models/first_principles.md +62 -0
- package/plugin/dist/templates/workspace/.principles/models/marketing_4p.md +52 -0
- package/plugin/dist/templates/workspace/.principles/models/porter_five.md +63 -0
- package/plugin/dist/templates/workspace/.principles/models/swot.md +60 -0
- package/plugin/dist/templates/workspace/.principles/models/user_story_map.md +63 -0
- package/plugin/dist/templates/workspace/.state/WORKBOARD.json +4 -0
- package/plugin/dist/templates/workspace/AUDIT.md +15 -0
- package/plugin/dist/templates/workspace/okr/CURRENT_FOCUS.md +57 -0
- package/plugin/dist/templates/workspace/okr/RECOVERY_PROTOCOL.md +56 -0
- package/plugin/dist/templates/workspace/okr/TASK_CHANGES.jsonl +6 -0
- package/plugin/dist/templates/workspace/okr/WEEK_TASKS.json +6 -0
- package/plugin/docs/COMMAND_REFERENCE.md +0 -1
- package/plugin/docs/COMMAND_REFERENCE_EN.md +0 -2
- package/plugin/openclaw.plugin.json +5 -5
- package/plugin/package.json +22 -10
- package/plugin/scripts/bootstrap-rules.mjs +5 -1
- package/plugin/scripts/postinstall.cjs +177 -0
- package/plugin/scripts/sync-plugin.mjs +24 -1
- package/plugin/templates/langs/en/skills/pd-mentor/SKILL.md +2 -3
- package/plugin/templates/langs/zh/skills/pd-mentor/SKILL.md +2 -3
- package/templates/langs/en/core/BOOTSTRAP.md +4 -17
- package/templates/langs/en/skills/pd-mentor/SKILL.md +8 -26
- package/templates/langs/zh/core/BOOTSTRAP.md +4 -17
- package/templates/langs/zh/skills/pd-mentor/SKILL.md +8 -26
- package/plugin/dist/commands/archive-impl.js +0 -105
- package/plugin/dist/commands/capabilities.js +0 -77
- package/plugin/dist/commands/context.js +0 -299
- package/plugin/dist/commands/disable-impl.js +0 -118
- package/plugin/dist/commands/evolution-status.js +0 -185
- package/plugin/dist/commands/export.js +0 -53
- package/plugin/dist/commands/focus.js +0 -451
- package/plugin/dist/commands/pain.js +0 -336
- package/plugin/dist/commands/principle-rollback.js +0 -26
- package/plugin/dist/commands/promote-impl.js +0 -194
- package/plugin/dist/commands/rollback-impl.js +0 -180
- package/plugin/dist/commands/rollback.js +0 -126
- package/plugin/dist/commands/samples.js +0 -83
- package/plugin/dist/commands/strategy.js +0 -16
- package/plugin/dist/commands/thinking-os.js +0 -168
- package/plugin/dist/commands/workflow-debug.js +0 -111
- package/plugin/dist/config/defaults/runtime.js +0 -74
- package/plugin/dist/config/errors.js +0 -107
- package/plugin/dist/config/index.js +0 -7
- package/plugin/dist/constants/tools.js +0 -53
- package/plugin/dist/core/__tests__/focus-history.test.js +0 -160
- package/plugin/dist/core/behavior-example-pack-assembler.js +0 -207
- package/plugin/dist/core/bootstrap-rules.js +0 -187
- package/plugin/dist/core/code-implementation-storage.js +0 -139
- package/plugin/dist/core/config-health.js +0 -60
- package/plugin/dist/core/config-service.js +0 -26
- package/plugin/dist/core/config.js +0 -191
- package/plugin/dist/core/control-ui-db.js +0 -333
- package/plugin/dist/core/correction-cue-learner.js +0 -186
- package/plugin/dist/core/correction-types.js +0 -1
- package/plugin/dist/core/detection-funnel.js +0 -56
- package/plugin/dist/core/detection-service.js +0 -28
- package/plugin/dist/core/dictionary-service.js +0 -26
- package/plugin/dist/core/dictionary.js +0 -148
- package/plugin/dist/core/empathy-keyword-matcher.js +0 -40
- package/plugin/dist/core/empathy-types.js +0 -1
- package/plugin/dist/core/event-log.js +0 -706
- package/plugin/dist/core/evolution-engine.js +0 -460
- package/plugin/dist/core/evolution-logger.js +0 -261
- package/plugin/dist/core/evolution-reducer.js +0 -720
- package/plugin/dist/core/evolution-types.js +0 -11
- package/plugin/dist/core/file-store.js +0 -46
- package/plugin/dist/core/focus-history.js +0 -574
- package/plugin/dist/core/hygiene/tracker.js +0 -110
- package/plugin/dist/core/init.js +0 -254
- package/plugin/dist/core/intent-doc-reader-adapter.js +0 -76
- package/plugin/dist/core/intent-doc-reader.js +0 -210
- package/plugin/dist/core/migration.js +0 -86
- package/plugin/dist/core/pain-diagnostic-gate.js +0 -69
- package/plugin/dist/core/pain.js +0 -56
- package/plugin/dist/core/path-resolver.js +0 -358
- package/plugin/dist/core/paths.js +0 -77
- package/plugin/dist/core/pd-config-loader.js +0 -307
- package/plugin/dist/core/pd-task-reconciler.js +0 -262
- package/plugin/dist/core/pd-task-service.js +0 -32
- package/plugin/dist/core/pd-task-store.js +0 -62
- package/plugin/dist/core/pd-task-types.js +0 -2
- package/plugin/dist/core/principle-compiler/__tests__/compiler-replay-gate.test.js +0 -132
- package/plugin/dist/core/principle-compiler/code-validator.js +0 -86
- package/plugin/dist/core/principle-compiler/compiler.js +0 -289
- package/plugin/dist/core/principle-compiler/index.js +0 -10
- package/plugin/dist/core/principle-compiler/ledger-registrar.js +0 -95
- package/plugin/dist/core/principle-compiler/template-generator.js +0 -7
- package/plugin/dist/core/principle-injection.js +0 -10
- package/plugin/dist/core/principle-internalization/filesystem-lifecycle-datasource.js +0 -34
- package/plugin/dist/core/principle-internalization/lifecycle-read-model.js +0 -21
- package/plugin/dist/core/principle-internalization/lifecycle-refresh.js +0 -4
- package/plugin/dist/core/principle-internalization/principle-lifecycle-service.js +0 -89
- package/plugin/dist/core/principle-training-state.js +0 -113
- package/plugin/dist/core/principle-tree-ledger.js +0 -42
- package/plugin/dist/core/profile.js +0 -211
- package/plugin/dist/core/reflection/reflection-context.js +0 -91
- package/plugin/dist/core/replay-engine.js +0 -82
- package/plugin/dist/core/rule-context-assembler.js +0 -148
- package/plugin/dist/core/rule-host.js +0 -554
- package/plugin/dist/core/rule-implementation-runtime.js +0 -112
- package/plugin/dist/core/runtime-v2-prompt-activation-reader.js +0 -99
- package/plugin/dist/core/session-tracker.js +0 -462
- package/plugin/dist/core/signal-collector-host.js +0 -337
- package/plugin/dist/core/system-logger.js +0 -113
- package/plugin/dist/core/thinking-models.js +0 -94
- package/plugin/dist/core/thinking-os-parser.js +0 -132
- package/plugin/dist/core/trajectory-types.js +0 -8
- package/plugin/dist/core/trajectory.js +0 -1692
- package/plugin/dist/core/workflow-funnel-loader.js +0 -135
- package/plugin/dist/core/workspace-context.js +0 -260
- package/plugin/dist/core/workspace-dir-validation.js +0 -37
- package/plugin/dist/core/workspace-guidance-migrator.js +0 -141
- package/plugin/dist/hooks/after-tool-call-helpers.js +0 -535
- package/plugin/dist/hooks/after-tool-call-types.js +0 -13
- package/plugin/dist/hooks/gate-block-helper.js +0 -249
- package/plugin/dist/hooks/gate.js +0 -430
- package/plugin/dist/hooks/lifecycle.js +0 -284
- package/plugin/dist/hooks/llm.js +0 -452
- package/plugin/dist/hooks/message-sanitize.js +0 -77
- package/plugin/dist/hooks/pain.js +0 -369
- package/plugin/dist/hooks/prompt-helpers.js +0 -288
- package/plugin/dist/hooks/prompt-types.js +0 -12
- package/plugin/dist/hooks/prompt.js +0 -501
- package/plugin/dist/hooks/raw-observation-adapter.js +0 -15
- package/plugin/dist/hooks/raw-observation-types.js +0 -11
- package/plugin/dist/hooks/trajectory-collector.js +0 -164
- package/plugin/dist/hooks/trajectory-evidence.js +0 -92
- package/plugin/dist/hooks/triage-adapter.js +0 -72
- package/plugin/dist/hooks/trigger-cooldown-tracker.js +0 -80
- package/plugin/dist/i18n/commands.js +0 -96
- package/plugin/dist/openclaw-sdk.js +0 -4
- package/plugin/dist/rulehost-evidence.js +0 -3
- package/plugin/dist/service/correction-observer-service.js +0 -191
- package/plugin/dist/service/evolution-dedup.js +0 -54
- package/plugin/dist/service/evolution-worker.js +0 -578
- package/plugin/dist/service/internalization-auto-consumer-service.js +0 -323
- package/plugin/dist/service/keyword-optimization-service.js +0 -137
- package/plugin/dist/service/phase3-input-filter.js +0 -172
- package/plugin/dist/service/queue-io.js +0 -91
- package/plugin/dist/service/queue-migration.js +0 -113
- package/plugin/dist/service/runtime-summary-service.js +0 -639
- package/plugin/dist/service/subagent-workflow/subagent-error-utils.js +0 -23
- package/plugin/dist/service/subagent-workflow/types.js +0 -11
- package/plugin/dist/service/subagent-workflow/workflow-store.js +0 -298
- package/plugin/dist/service/trajectory-service.js +0 -16
- package/plugin/dist/service/workflow-watchdog.js +0 -104
- package/plugin/dist/types/event-types.js +0 -1
- package/plugin/dist/types/hygiene-types.js +0 -1
- package/plugin/dist/types/principle-tree-schema.js +0 -24
- package/plugin/dist/types/queue.js +0 -1
- package/plugin/dist/types/runtime-summary.js +0 -1
- package/plugin/dist/types.js +0 -11
- package/plugin/dist/utils/file-lock.js +0 -310
- package/plugin/dist/utils/hashing.js +0 -25
- package/plugin/dist/utils/io.js +0 -174
- package/plugin/dist/utils/node-vm-polyfill.js +0 -9
- package/plugin/dist/utils/retry.js +0 -380
- package/plugin/dist/utils/session-key.js +0 -21
- package/plugin/dist/utils/workspace-resolver.js +0 -288
- package/templates/langs/en/skills/pd-daily/SKILL.md +0 -199
- package/templates/langs/en/skills/pd-grooming/SKILL.md +0 -46
- package/templates/langs/zh/skills/pd-daily/SKILL.md +0 -283
- package/templates/langs/zh/skills/pd-grooming/SKILL.md +0 -46
|
@@ -1,1692 +0,0 @@
|
|
|
1
|
-
import Database from 'better-sqlite3';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import crypto from 'crypto';
|
|
5
|
-
import { withLock } from '../utils/file-lock.js';
|
|
6
|
-
import { atomicWriteFileSync } from '../utils/io.js';
|
|
7
|
-
import { resolvePdPath } from './paths.js';
|
|
8
|
-
import { SampleNotFoundError } from '../config/index.js';
|
|
9
|
-
/**
|
|
10
|
-
* Trajectory database stores HISTORICAL and ANALYTICS data.
|
|
11
|
-
*
|
|
12
|
-
* PURPOSE: Track task outcomes, trust changes, and evolution progress over time.
|
|
13
|
-
* USAGE: Insights, trends, and Phase 3 supporting evidence (where explicitly allowed).
|
|
14
|
-
* NOT FOR: Control decisions, Phase 3 eligibility, or real-time operations.
|
|
15
|
-
*
|
|
16
|
-
* Runtime truth comes from: queue state, workspace trust scorecard, active sessions
|
|
17
|
-
*/
|
|
18
|
-
const DEFAULT_INLINE_THRESHOLD = 16 * 1024;
|
|
19
|
-
const DEFAULT_BUSY_TIMEOUT_MS = 5000;
|
|
20
|
-
const DEFAULT_ORPHAN_BLOB_GRACE_DAYS = 7;
|
|
21
|
-
const SCHEMA_VERSION = 1;
|
|
22
|
-
/**
|
|
23
|
-
* Type guard: narrows `object` to `{ name: unknown }` without `as` casts.
|
|
24
|
-
* Used for PRAGMA table_info rows (rc-2-no-as-bypass).
|
|
25
|
-
*/
|
|
26
|
-
function hasNameField(row) {
|
|
27
|
-
return Object.hasOwn(row, 'name');
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Pure structural narrowing from `unknown` to `Record<string, unknown>` with
|
|
31
|
-
* no `as` cast (ERR-001 / rc-2). The returned type allows indexed access in
|
|
32
|
-
* subsequent code without further casts.
|
|
33
|
-
*/
|
|
34
|
-
function isStringRecord(value) {
|
|
35
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
36
|
-
}
|
|
37
|
-
function isPainEventRow(value) {
|
|
38
|
-
if (!isStringRecord(value))
|
|
39
|
-
return false;
|
|
40
|
-
if (typeof value.id !== 'number')
|
|
41
|
-
return false;
|
|
42
|
-
if (typeof value.session_id !== 'string')
|
|
43
|
-
return false;
|
|
44
|
-
// The remaining fields are accessed via String()/Number() which tolerate any
|
|
45
|
-
// primitive; presence check only (rc-5: Object.hasOwn over `in`).
|
|
46
|
-
return (Object.hasOwn(value, 'source')
|
|
47
|
-
&& Object.hasOwn(value, 'score')
|
|
48
|
-
&& Object.hasOwn(value, 'reason')
|
|
49
|
-
&& Object.hasOwn(value, 'severity')
|
|
50
|
-
&& Object.hasOwn(value, 'origin')
|
|
51
|
-
&& Object.hasOwn(value, 'confidence')
|
|
52
|
-
&& Object.hasOwn(value, 'text')
|
|
53
|
-
&& Object.hasOwn(value, 'canonical_pain_id')
|
|
54
|
-
&& Object.hasOwn(value, 'runtime_task_id')
|
|
55
|
-
&& Object.hasOwn(value, 'created_at'));
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Apply the full trajectory.db schema (tables + indexes + views + migrations) to an open
|
|
59
|
-
* Database handle. Used by TrajectoryDatabase.initSchema() and exported via
|
|
60
|
-
* initTrajectorySchema() for external callers (e.g. `pd runtime init`).
|
|
61
|
-
*
|
|
62
|
-
* DDL is the single source of truth for trajectory.db schema. pain-signal-observability.ts
|
|
63
|
-
* in principles-core also duplicates a subset of this DDL (acknowledged duplication); when
|
|
64
|
-
* updating this function, audit ensureTrajectorySchema() in core for parallel updates.
|
|
65
|
-
*
|
|
66
|
-
* Idempotent: all CREATE statements use IF NOT EXISTS; ALTER columns use try/catch on
|
|
67
|
-
* "duplicate column name" to skip existing columns.
|
|
68
|
-
*/
|
|
69
|
-
function applyTrajectorySchema(db) {
|
|
70
|
-
const warnings = [];
|
|
71
|
-
const tables = [
|
|
72
|
-
'schema_version', 'ingest_checkpoint', 'sessions', 'assistant_turns',
|
|
73
|
-
'user_turns', 'tool_calls', 'pain_events', 'gate_blocks', 'trust_changes',
|
|
74
|
-
'principle_events', 'task_outcomes', 'correction_samples', 'sample_reviews',
|
|
75
|
-
'exports_audit', 'evolution_tasks', 'evolution_events',
|
|
76
|
-
];
|
|
77
|
-
db.exec(`
|
|
78
|
-
CREATE TABLE IF NOT EXISTS schema_version (version INTEGER NOT NULL);
|
|
79
|
-
CREATE TABLE IF NOT EXISTS ingest_checkpoint (
|
|
80
|
-
source_key TEXT PRIMARY KEY,
|
|
81
|
-
imported_at TEXT NOT NULL
|
|
82
|
-
);
|
|
83
|
-
CREATE TABLE IF NOT EXISTS sessions (
|
|
84
|
-
session_id TEXT PRIMARY KEY,
|
|
85
|
-
started_at TEXT NOT NULL,
|
|
86
|
-
updated_at TEXT NOT NULL
|
|
87
|
-
);
|
|
88
|
-
CREATE TABLE IF NOT EXISTS assistant_turns (
|
|
89
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
90
|
-
session_id TEXT NOT NULL,
|
|
91
|
-
run_id TEXT NOT NULL,
|
|
92
|
-
provider TEXT NOT NULL,
|
|
93
|
-
model TEXT NOT NULL,
|
|
94
|
-
raw_text TEXT,
|
|
95
|
-
sanitized_text TEXT NOT NULL,
|
|
96
|
-
usage_json TEXT NOT NULL,
|
|
97
|
-
empathy_signal_json TEXT NOT NULL,
|
|
98
|
-
blob_ref TEXT,
|
|
99
|
-
raw_excerpt TEXT,
|
|
100
|
-
stop_reason TEXT,
|
|
101
|
-
thinking_blocks_count INTEGER,
|
|
102
|
-
created_at TEXT NOT NULL
|
|
103
|
-
);
|
|
104
|
-
CREATE TABLE IF NOT EXISTS user_turns (
|
|
105
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
106
|
-
session_id TEXT NOT NULL,
|
|
107
|
-
turn_index INTEGER NOT NULL,
|
|
108
|
-
raw_text TEXT,
|
|
109
|
-
blob_ref TEXT,
|
|
110
|
-
raw_excerpt TEXT,
|
|
111
|
-
correction_detected INTEGER NOT NULL DEFAULT 0,
|
|
112
|
-
correction_cue TEXT,
|
|
113
|
-
references_assistant_turn_id INTEGER,
|
|
114
|
-
created_at TEXT NOT NULL
|
|
115
|
-
);
|
|
116
|
-
CREATE TABLE IF NOT EXISTS tool_calls (
|
|
117
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
118
|
-
session_id TEXT NOT NULL,
|
|
119
|
-
tool_name TEXT NOT NULL,
|
|
120
|
-
outcome TEXT NOT NULL,
|
|
121
|
-
duration_ms INTEGER,
|
|
122
|
-
exit_code INTEGER,
|
|
123
|
-
error_type TEXT,
|
|
124
|
-
error_message TEXT,
|
|
125
|
-
gfi_before REAL,
|
|
126
|
-
gfi_after REAL,
|
|
127
|
-
params_json TEXT NOT NULL,
|
|
128
|
-
result_preview TEXT,
|
|
129
|
-
created_at TEXT NOT NULL
|
|
130
|
-
);
|
|
131
|
-
CREATE TABLE IF NOT EXISTS pain_events (
|
|
132
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
133
|
-
session_id TEXT NOT NULL,
|
|
134
|
-
source TEXT NOT NULL,
|
|
135
|
-
score REAL NOT NULL,
|
|
136
|
-
reason TEXT,
|
|
137
|
-
severity TEXT,
|
|
138
|
-
origin TEXT,
|
|
139
|
-
confidence REAL,
|
|
140
|
-
text TEXT,
|
|
141
|
-
canonical_pain_id TEXT,
|
|
142
|
-
runtime_task_id TEXT,
|
|
143
|
-
created_at TEXT NOT NULL
|
|
144
|
-
);
|
|
145
|
-
CREATE TABLE IF NOT EXISTS gate_blocks (
|
|
146
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
147
|
-
session_id TEXT,
|
|
148
|
-
tool_name TEXT NOT NULL,
|
|
149
|
-
file_path TEXT,
|
|
150
|
-
reason TEXT NOT NULL,
|
|
151
|
-
plan_status TEXT,
|
|
152
|
-
created_at TEXT NOT NULL
|
|
153
|
-
);
|
|
154
|
-
CREATE TABLE IF NOT EXISTS trust_changes (
|
|
155
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
156
|
-
session_id TEXT,
|
|
157
|
-
previous_score REAL NOT NULL,
|
|
158
|
-
new_score REAL NOT NULL,
|
|
159
|
-
delta REAL NOT NULL,
|
|
160
|
-
reason TEXT NOT NULL,
|
|
161
|
-
created_at TEXT NOT NULL
|
|
162
|
-
);
|
|
163
|
-
CREATE TABLE IF NOT EXISTS principle_events (
|
|
164
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
165
|
-
principle_id TEXT,
|
|
166
|
-
event_type TEXT NOT NULL,
|
|
167
|
-
payload_json TEXT NOT NULL,
|
|
168
|
-
created_at TEXT NOT NULL
|
|
169
|
-
);
|
|
170
|
-
CREATE TABLE IF NOT EXISTS task_outcomes (
|
|
171
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
172
|
-
session_id TEXT NOT NULL,
|
|
173
|
-
task_id TEXT,
|
|
174
|
-
outcome TEXT NOT NULL,
|
|
175
|
-
summary TEXT,
|
|
176
|
-
principle_ids_json TEXT NOT NULL,
|
|
177
|
-
created_at TEXT NOT NULL
|
|
178
|
-
);
|
|
179
|
-
CREATE TABLE IF NOT EXISTS correction_samples (
|
|
180
|
-
sample_id TEXT PRIMARY KEY,
|
|
181
|
-
session_id TEXT NOT NULL,
|
|
182
|
-
bad_assistant_turn_id INTEGER NOT NULL,
|
|
183
|
-
user_correction_turn_id INTEGER NOT NULL,
|
|
184
|
-
recovery_tool_span_json TEXT NOT NULL,
|
|
185
|
-
diff_excerpt TEXT NOT NULL,
|
|
186
|
-
principle_ids_json TEXT NOT NULL,
|
|
187
|
-
quality_score REAL NOT NULL,
|
|
188
|
-
review_status TEXT NOT NULL,
|
|
189
|
-
export_mode TEXT NOT NULL,
|
|
190
|
-
created_at TEXT NOT NULL,
|
|
191
|
-
updated_at TEXT NOT NULL
|
|
192
|
-
);
|
|
193
|
-
CREATE TABLE IF NOT EXISTS sample_reviews (
|
|
194
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
195
|
-
sample_id TEXT NOT NULL,
|
|
196
|
-
review_status TEXT NOT NULL,
|
|
197
|
-
note TEXT,
|
|
198
|
-
created_at TEXT NOT NULL
|
|
199
|
-
);
|
|
200
|
-
CREATE TABLE IF NOT EXISTS exports_audit (
|
|
201
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
202
|
-
export_kind TEXT NOT NULL,
|
|
203
|
-
mode TEXT NOT NULL,
|
|
204
|
-
approved_only INTEGER NOT NULL,
|
|
205
|
-
file_path TEXT NOT NULL,
|
|
206
|
-
row_count INTEGER NOT NULL,
|
|
207
|
-
created_at TEXT NOT NULL
|
|
208
|
-
);
|
|
209
|
-
CREATE TABLE IF NOT EXISTS evolution_tasks (
|
|
210
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
211
|
-
task_id TEXT UNIQUE NOT NULL,
|
|
212
|
-
trace_id TEXT NOT NULL,
|
|
213
|
-
source TEXT NOT NULL,
|
|
214
|
-
reason TEXT,
|
|
215
|
-
score INTEGER DEFAULT 0,
|
|
216
|
-
status TEXT DEFAULT 'pending',
|
|
217
|
-
enqueued_at TEXT,
|
|
218
|
-
started_at TEXT,
|
|
219
|
-
completed_at TEXT,
|
|
220
|
-
resolution TEXT,
|
|
221
|
-
task_kind TEXT,
|
|
222
|
-
priority TEXT,
|
|
223
|
-
retry_count INTEGER,
|
|
224
|
-
max_retries INTEGER,
|
|
225
|
-
last_error TEXT,
|
|
226
|
-
result_ref TEXT,
|
|
227
|
-
created_at TEXT NOT NULL,
|
|
228
|
-
updated_at TEXT NOT NULL
|
|
229
|
-
);
|
|
230
|
-
CREATE TABLE IF NOT EXISTS evolution_events (
|
|
231
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
232
|
-
trace_id TEXT NOT NULL,
|
|
233
|
-
task_id TEXT,
|
|
234
|
-
stage TEXT NOT NULL,
|
|
235
|
-
level TEXT DEFAULT 'info',
|
|
236
|
-
message TEXT NOT NULL,
|
|
237
|
-
summary TEXT,
|
|
238
|
-
metadata_json TEXT,
|
|
239
|
-
created_at TEXT NOT NULL
|
|
240
|
-
);
|
|
241
|
-
`);
|
|
242
|
-
// Migration: Add text column to pain_events if it doesn't exist (MEM-01)
|
|
243
|
-
// SQLite doesn't support IF NOT EXISTS for ADD COLUMN, so we use try/catch
|
|
244
|
-
try {
|
|
245
|
-
db.exec(`ALTER TABLE pain_events ADD COLUMN text TEXT`);
|
|
246
|
-
}
|
|
247
|
-
catch (err) {
|
|
248
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
249
|
-
if (!message.includes('duplicate column name') && !message.includes('no column named')) {
|
|
250
|
-
// Re-throw unexpected errors — silently swallowing migration failures is dangerous
|
|
251
|
-
throw err;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
// PRI-406: Add canonical_pain_id and runtime_task_id columns to pain_events
|
|
255
|
-
for (const col of [
|
|
256
|
-
{ name: 'canonical_pain_id', type: 'TEXT' },
|
|
257
|
-
{ name: 'runtime_task_id', type: 'TEXT' },
|
|
258
|
-
]) {
|
|
259
|
-
try {
|
|
260
|
-
db.exec(`ALTER TABLE pain_events ADD COLUMN ${col.name} ${col.type}`);
|
|
261
|
-
}
|
|
262
|
-
catch (err) {
|
|
263
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
264
|
-
if (!message.includes('duplicate column name') && !message.includes('no column named')) {
|
|
265
|
-
throw err;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
// Trajectory enhancement: add stop_reason, thinking_blocks_count, result_preview
|
|
270
|
-
const trajectoryEnhancementColumns = [
|
|
271
|
-
{ table: 'assistant_turns', name: 'stop_reason', type: 'TEXT' },
|
|
272
|
-
{ table: 'assistant_turns', name: 'thinking_blocks_count', type: 'INTEGER' },
|
|
273
|
-
{ table: 'tool_calls', name: 'result_preview', type: 'TEXT' },
|
|
274
|
-
];
|
|
275
|
-
for (const col of trajectoryEnhancementColumns) {
|
|
276
|
-
try {
|
|
277
|
-
db.exec(`ALTER TABLE ${col.table} ADD COLUMN ${col.name} ${col.type}`);
|
|
278
|
-
}
|
|
279
|
-
catch (err) {
|
|
280
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
281
|
-
if (!message.includes('duplicate column name') && !message.includes('no column named')) {
|
|
282
|
-
throw err;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
// PRI-406: Partial unique index on canonical_pain_id (non-null only) for dedup
|
|
287
|
-
db.exec(`
|
|
288
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_pain_events_canonical_pain_id
|
|
289
|
-
ON pain_events(canonical_pain_id)
|
|
290
|
-
WHERE canonical_pain_id IS NOT NULL
|
|
291
|
-
`);
|
|
292
|
-
// V2 migration: Add V2 columns to evolution_tasks if they don't exist
|
|
293
|
-
const v2Columns = [
|
|
294
|
-
{ name: 'task_kind', type: 'TEXT' },
|
|
295
|
-
{ name: 'priority', type: 'TEXT' },
|
|
296
|
-
{ name: 'retry_count', type: 'INTEGER' },
|
|
297
|
-
{ name: 'max_retries', type: 'INTEGER' },
|
|
298
|
-
{ name: 'last_error', type: 'TEXT' },
|
|
299
|
-
{ name: 'result_ref', type: 'TEXT' },
|
|
300
|
-
];
|
|
301
|
-
for (const col of v2Columns) {
|
|
302
|
-
const rows = db.prepare(`PRAGMA table_info(evolution_tasks)`).all();
|
|
303
|
-
const exists = rows.some((row) => {
|
|
304
|
-
if (typeof row !== 'object' || row === null)
|
|
305
|
-
return false;
|
|
306
|
-
// Use type guard predicate to narrow without `as` (rc-2-no-as-bypass)
|
|
307
|
-
return hasNameField(row) && row.name === col.name;
|
|
308
|
-
});
|
|
309
|
-
if (!exists) {
|
|
310
|
-
db.exec(`ALTER TABLE evolution_tasks ADD COLUMN ${col.name} ${col.type}`);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
db.exec(`
|
|
314
|
-
CREATE VIEW IF NOT EXISTS v_error_clusters AS
|
|
315
|
-
SELECT tool_name, COALESCE(error_type, 'unknown') AS error_type, COUNT(*) AS occurrences
|
|
316
|
-
FROM tool_calls
|
|
317
|
-
WHERE outcome = 'failure'
|
|
318
|
-
GROUP BY tool_name, COALESCE(error_type, 'unknown')
|
|
319
|
-
ORDER BY occurrences DESC;
|
|
320
|
-
CREATE VIEW IF NOT EXISTS v_principle_effectiveness AS
|
|
321
|
-
SELECT event_type, COUNT(*) AS total
|
|
322
|
-
FROM principle_events
|
|
323
|
-
GROUP BY event_type
|
|
324
|
-
ORDER BY total DESC;
|
|
325
|
-
CREATE VIEW IF NOT EXISTS v_sample_queue AS
|
|
326
|
-
SELECT review_status, COUNT(*) AS total
|
|
327
|
-
FROM correction_samples
|
|
328
|
-
GROUP BY review_status;
|
|
329
|
-
CREATE INDEX IF NOT EXISTS idx_assistant_turns_session_id ON assistant_turns(session_id);
|
|
330
|
-
CREATE INDEX IF NOT EXISTS idx_assistant_turns_created_at ON assistant_turns(created_at);
|
|
331
|
-
CREATE INDEX IF NOT EXISTS idx_assistant_turns_provider_model ON assistant_turns(provider, model);
|
|
332
|
-
CREATE INDEX IF NOT EXISTS idx_user_turns_session_id ON user_turns(session_id);
|
|
333
|
-
CREATE INDEX IF NOT EXISTS idx_tool_calls_session_id ON tool_calls(session_id);
|
|
334
|
-
CREATE INDEX IF NOT EXISTS idx_tool_calls_created_at ON tool_calls(created_at);
|
|
335
|
-
CREATE INDEX IF NOT EXISTS idx_pain_events_session_id ON pain_events(session_id);
|
|
336
|
-
CREATE INDEX IF NOT EXISTS idx_correction_samples_review_status ON correction_samples(review_status);
|
|
337
|
-
CREATE INDEX IF NOT EXISTS idx_evolution_tasks_trace_id ON evolution_tasks(trace_id);
|
|
338
|
-
CREATE INDEX IF NOT EXISTS idx_evolution_tasks_status ON evolution_tasks(status);
|
|
339
|
-
CREATE INDEX IF NOT EXISTS idx_evolution_tasks_created_at ON evolution_tasks(created_at);
|
|
340
|
-
CREATE INDEX IF NOT EXISTS idx_evolution_events_trace_id ON evolution_events(trace_id);
|
|
341
|
-
CREATE INDEX IF NOT EXISTS idx_evolution_events_created_at ON evolution_events(created_at);
|
|
342
|
-
`);
|
|
343
|
-
return { tables, warnings };
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Initialize trajectory.db schema at the given workspace directory.
|
|
347
|
-
*
|
|
348
|
-
* Opens trajectory.db in write mode, applies the full schema (tables + indexes + views +
|
|
349
|
-
* migrations), then closes the DB. Does NOT run importLegacyArtifacts() or
|
|
350
|
-
* pruneUnreferencedBlobs() — those are runtime side-effects of TrajectoryDatabase
|
|
351
|
-
* construction and are not needed for pure initialization.
|
|
352
|
-
*
|
|
353
|
-
* Idempotent: safe to call on an existing DB; all CREATE statements use IF NOT EXISTS.
|
|
354
|
-
*
|
|
355
|
-
* @returns list of created/verified table names and any warnings
|
|
356
|
-
*/
|
|
357
|
-
export function initTrajectorySchema(workspaceDir) {
|
|
358
|
-
const resolvedDir = path.resolve(workspaceDir);
|
|
359
|
-
const stateDir = resolvePdPath(resolvedDir, 'STATE_DIR');
|
|
360
|
-
const blobDir = resolvePdPath(resolvedDir, 'TRAJECTORY_BLOBS_DIR');
|
|
361
|
-
const exportDir = resolvePdPath(resolvedDir, 'EXPORTS_DIR');
|
|
362
|
-
const dbPath = resolvePdPath(resolvedDir, 'TRAJECTORY_DB');
|
|
363
|
-
fs.mkdirSync(stateDir, { recursive: true });
|
|
364
|
-
fs.mkdirSync(blobDir, { recursive: true });
|
|
365
|
-
fs.mkdirSync(exportDir, { recursive: true });
|
|
366
|
-
const db = new Database(dbPath);
|
|
367
|
-
try {
|
|
368
|
-
db.pragma('journal_mode = WAL');
|
|
369
|
-
db.pragma('foreign_keys = ON');
|
|
370
|
-
db.pragma('synchronous = NORMAL');
|
|
371
|
-
db.pragma(`busy_timeout = ${DEFAULT_BUSY_TIMEOUT_MS}`);
|
|
372
|
-
const result = applyTrajectorySchema(db);
|
|
373
|
-
// Record schema version (same logic as TrajectoryDatabase.initSchema)
|
|
374
|
-
const row = db.prepare('SELECT version FROM schema_version LIMIT 1').get();
|
|
375
|
-
if (!row) {
|
|
376
|
-
db.prepare('INSERT INTO schema_version (version) VALUES (?)').run(SCHEMA_VERSION);
|
|
377
|
-
}
|
|
378
|
-
else if (row.version !== SCHEMA_VERSION) {
|
|
379
|
-
db.prepare('UPDATE schema_version SET version = ?').run(SCHEMA_VERSION);
|
|
380
|
-
}
|
|
381
|
-
return result;
|
|
382
|
-
}
|
|
383
|
-
finally {
|
|
384
|
-
db.close();
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
function nowIso() {
|
|
388
|
-
return new Date().toISOString();
|
|
389
|
-
}
|
|
390
|
-
function safeJson(value) {
|
|
391
|
-
return JSON.stringify(value ?? {});
|
|
392
|
-
}
|
|
393
|
-
function fileSizeIfExists(filePath) {
|
|
394
|
-
try {
|
|
395
|
-
return fs.existsSync(filePath) ? fs.statSync(filePath).size : 0;
|
|
396
|
-
}
|
|
397
|
-
catch {
|
|
398
|
-
return 0;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
function summarizeForDiff(text) {
|
|
402
|
-
return text.length > 240 ? `${text.slice(0, 237)}...` : text;
|
|
403
|
-
}
|
|
404
|
-
function redactText(text) {
|
|
405
|
-
return text
|
|
406
|
-
.replace(/[A-Za-z]:\\[^\s"'`]+/g, '<WINDOWS_PATH>')
|
|
407
|
-
.replace(/\/[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+/g, '<PATH>')
|
|
408
|
-
.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, '<EMAIL>')
|
|
409
|
-
.replace(/\b(sk|rk|pk)_[A-Za-z0-9]+\b/g, '<TOKEN>');
|
|
410
|
-
}
|
|
411
|
-
export class TrajectoryDatabase {
|
|
412
|
-
workspaceDir;
|
|
413
|
-
stateDir;
|
|
414
|
-
dbPath;
|
|
415
|
-
blobDir;
|
|
416
|
-
exportDir;
|
|
417
|
-
blobInlineThresholdBytes;
|
|
418
|
-
orphanBlobGraceMs;
|
|
419
|
-
db;
|
|
420
|
-
constructor(opts) {
|
|
421
|
-
this.workspaceDir = path.resolve(opts.workspaceDir);
|
|
422
|
-
this.stateDir = resolvePdPath(this.workspaceDir, 'STATE_DIR');
|
|
423
|
-
this.dbPath = resolvePdPath(this.workspaceDir, 'TRAJECTORY_DB');
|
|
424
|
-
this.blobDir = resolvePdPath(this.workspaceDir, 'TRAJECTORY_BLOBS_DIR');
|
|
425
|
-
this.exportDir = resolvePdPath(this.workspaceDir, 'EXPORTS_DIR');
|
|
426
|
-
this.blobInlineThresholdBytes = opts.blobInlineThresholdBytes ?? DEFAULT_INLINE_THRESHOLD;
|
|
427
|
-
this.orphanBlobGraceMs = Math.max(0, (opts.orphanBlobGraceDays ?? DEFAULT_ORPHAN_BLOB_GRACE_DAYS) * 24 * 60 * 60 * 1000);
|
|
428
|
-
fs.mkdirSync(this.stateDir, { recursive: true });
|
|
429
|
-
fs.mkdirSync(this.blobDir, { recursive: true });
|
|
430
|
-
fs.mkdirSync(this.exportDir, { recursive: true });
|
|
431
|
-
this.db = new Database(this.dbPath);
|
|
432
|
-
this.db.pragma('journal_mode = WAL');
|
|
433
|
-
this.db.pragma('foreign_keys = ON');
|
|
434
|
-
this.db.pragma('synchronous = NORMAL');
|
|
435
|
-
this.db.pragma(`busy_timeout = ${Math.max(0, opts.busyTimeoutMs ?? DEFAULT_BUSY_TIMEOUT_MS)}`);
|
|
436
|
-
this.initSchema();
|
|
437
|
-
this.importLegacyArtifacts();
|
|
438
|
-
this.pruneUnreferencedBlobs();
|
|
439
|
-
}
|
|
440
|
-
dispose() {
|
|
441
|
-
this.db.close();
|
|
442
|
-
}
|
|
443
|
-
recordSession(input) {
|
|
444
|
-
const startedAt = input.startedAt ?? nowIso();
|
|
445
|
-
this.withWrite(() => {
|
|
446
|
-
this.db.prepare(`
|
|
447
|
-
INSERT INTO sessions (session_id, started_at, updated_at)
|
|
448
|
-
VALUES (?, ?, ?)
|
|
449
|
-
ON CONFLICT(session_id) DO UPDATE SET updated_at = excluded.updated_at
|
|
450
|
-
`).run(input.sessionId, startedAt, nowIso());
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
recordAssistantTurn(input) {
|
|
454
|
-
this.recordSession({ sessionId: input.sessionId, startedAt: input.createdAt });
|
|
455
|
-
const rawStorage = this.storeRawText('assistant', input.rawText);
|
|
456
|
-
const createdAt = input.createdAt ?? nowIso();
|
|
457
|
-
return this.withWrite(() => {
|
|
458
|
-
const result = this.db.prepare(`
|
|
459
|
-
INSERT INTO assistant_turns (
|
|
460
|
-
session_id, run_id, provider, model, raw_text, sanitized_text, usage_json,
|
|
461
|
-
empathy_signal_json, blob_ref, raw_excerpt, stop_reason, thinking_blocks_count, created_at
|
|
462
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
463
|
-
`).run(input.sessionId, input.runId, input.provider, input.model, rawStorage.inlineText, input.sanitizedText, safeJson(input.usageJson), safeJson(input.empathySignalJson), rawStorage.blobRef, rawStorage.excerpt, input.stopReason ?? null, input.thinkingBlocksCount ?? null, createdAt);
|
|
464
|
-
return Number(result.lastInsertRowid);
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
recordUserTurn(input) {
|
|
468
|
-
this.recordSession({ sessionId: input.sessionId, startedAt: input.createdAt });
|
|
469
|
-
const rawStorage = this.storeRawText('user', input.rawText);
|
|
470
|
-
const createdAt = input.createdAt ?? nowIso();
|
|
471
|
-
return this.withWrite(() => {
|
|
472
|
-
const result = this.db.prepare(`
|
|
473
|
-
INSERT INTO user_turns (
|
|
474
|
-
session_id, turn_index, raw_text, blob_ref, raw_excerpt,
|
|
475
|
-
correction_detected, correction_cue, references_assistant_turn_id, created_at
|
|
476
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
477
|
-
`).run(input.sessionId, input.turnIndex, rawStorage.inlineText, rawStorage.blobRef, rawStorage.excerpt, input.correctionDetected ? 1 : 0, input.correctionCue ?? null, input.referencesAssistantTurnId ?? null, createdAt);
|
|
478
|
-
return Number(result.lastInsertRowid);
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
recordToolCall(input) {
|
|
482
|
-
this.recordSession({ sessionId: input.sessionId, startedAt: input.createdAt });
|
|
483
|
-
const createdAt = input.createdAt ?? nowIso();
|
|
484
|
-
const rowId = this.withWrite(() => {
|
|
485
|
-
const result = this.db.prepare(`
|
|
486
|
-
INSERT INTO tool_calls (
|
|
487
|
-
session_id, tool_name, outcome, duration_ms, exit_code, error_type, error_message,
|
|
488
|
-
gfi_before, gfi_after, params_json, result_preview, created_at
|
|
489
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
490
|
-
`).run(input.sessionId, input.toolName, input.outcome, input.durationMs ?? null, input.exitCode ?? null, input.errorType ?? null, input.errorMessage ?? null, input.gfiBefore ?? null, input.gfiAfter ?? null, safeJson(input.paramsJson), input.resultPreview ?? null, createdAt);
|
|
491
|
-
return Number(result.lastInsertRowid);
|
|
492
|
-
});
|
|
493
|
-
if (input.outcome === 'success') {
|
|
494
|
-
this.maybeCreateCorrectionSample(input.sessionId);
|
|
495
|
-
}
|
|
496
|
-
return rowId;
|
|
497
|
-
}
|
|
498
|
-
recordPainEvent(input) {
|
|
499
|
-
this.recordSession({ sessionId: input.sessionId, startedAt: input.createdAt });
|
|
500
|
-
let insertedId = -1;
|
|
501
|
-
this.withWrite(() => {
|
|
502
|
-
// Try INSERT; on UNIQUE constraint violation for canonical_pain_id, do UPDATE instead.
|
|
503
|
-
// SQLite UPSERT (ON CONFLICT) does not support partial unique indexes, so we
|
|
504
|
-
// handle the conflict manually.
|
|
505
|
-
try {
|
|
506
|
-
const runResult = this.db.prepare(`
|
|
507
|
-
INSERT INTO pain_events (
|
|
508
|
-
session_id, source, score, reason, severity, origin, confidence, text, created_at,
|
|
509
|
-
canonical_pain_id, runtime_task_id
|
|
510
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
511
|
-
`).run(input.sessionId, input.source, input.score, input.reason ?? null, input.severity ?? null, input.origin ?? null, input.confidence ?? null, input.text ?? null, input.createdAt ?? nowIso(), input.canonicalPainId ?? null, input.runtimeTaskId ?? null);
|
|
512
|
-
insertedId = Number(runResult.lastInsertRowid);
|
|
513
|
-
}
|
|
514
|
-
catch (insertErr) {
|
|
515
|
-
if (input.canonicalPainId &&
|
|
516
|
-
insertErr instanceof Error &&
|
|
517
|
-
insertErr.message.includes('UNIQUE constraint failed') &&
|
|
518
|
-
insertErr.message.includes('canonical_pain_id')) {
|
|
519
|
-
this.db.prepare(`
|
|
520
|
-
UPDATE pain_events
|
|
521
|
-
SET runtime_task_id = COALESCE(?, runtime_task_id)
|
|
522
|
-
WHERE canonical_pain_id = ?
|
|
523
|
-
`).run(input.runtimeTaskId ?? null, input.canonicalPainId);
|
|
524
|
-
const rawRow = this.db.prepare('SELECT id FROM pain_events WHERE canonical_pain_id = ?').get(input.canonicalPainId);
|
|
525
|
-
// Runtime Contract #1/#2: validate DB row instead of `as` cast
|
|
526
|
-
if (rawRow && typeof rawRow === 'object' && Object.hasOwn(rawRow, 'id') && typeof rawRow.id === 'number') {
|
|
527
|
-
insertedId = rawRow.id;
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
insertedId = -1;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
throw insertErr;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
// FTS5 index write removed (PRI-451 Wave 1): the only reader (searchPainEvents)
|
|
539
|
-
// was dead code removed in Wave 1.1. The pain event row itself is committed
|
|
540
|
-
// above; nothing reads the FTS index anymore.
|
|
541
|
-
return insertedId;
|
|
542
|
-
}
|
|
543
|
-
// searchPainEvents removed (PRI-451 Wave 1): dead code. Its only caller was
|
|
544
|
-
// processDetectionQueue (also removed). The FTS5 index write it read is
|
|
545
|
-
// removed in Wave 1.2.
|
|
546
|
-
recordGateBlock(input) {
|
|
547
|
-
this.withWrite(() => {
|
|
548
|
-
this.db.prepare(`
|
|
549
|
-
INSERT INTO gate_blocks (session_id, tool_name, file_path, reason, plan_status, created_at)
|
|
550
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
551
|
-
`).run(input.sessionId ?? null, input.toolName, input.filePath ?? null, input.reason, input.planStatus ?? null, input.createdAt ?? nowIso());
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
recordTrustChange(input) {
|
|
555
|
-
this.withWrite(() => {
|
|
556
|
-
this.db.prepare(`
|
|
557
|
-
INSERT INTO trust_changes (session_id, previous_score, new_score, delta, reason, created_at)
|
|
558
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
559
|
-
`).run(input.sessionId ?? null, input.previousScore, input.newScore, input.delta, input.reason, input.createdAt ?? nowIso());
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
recordPrincipleEvent(input) {
|
|
563
|
-
this.withWrite(() => {
|
|
564
|
-
this.db.prepare(`
|
|
565
|
-
INSERT INTO principle_events (principle_id, event_type, payload_json, created_at)
|
|
566
|
-
VALUES (?, ?, ?, ?)
|
|
567
|
-
`).run(input.principleId ?? null, input.eventType, safeJson(input.payload), input.createdAt ?? nowIso());
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
recordTaskOutcome(input) {
|
|
571
|
-
this.withWrite(() => {
|
|
572
|
-
this.db.prepare(`
|
|
573
|
-
INSERT INTO task_outcomes (session_id, task_id, outcome, summary, principle_ids_json, created_at)
|
|
574
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
575
|
-
`).run(input.sessionId, input.taskId ?? null, input.outcome, input.summary ?? null, safeJson(input.principleIdsJson), input.createdAt ?? nowIso());
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
recordEvolutionTask(input) {
|
|
579
|
-
const now = nowIso();
|
|
580
|
-
// Cast to V2 to access new fields
|
|
581
|
-
const v2 = input;
|
|
582
|
-
this.withWrite(() => {
|
|
583
|
-
this.db.prepare(`
|
|
584
|
-
INSERT INTO evolution_tasks (
|
|
585
|
-
task_id, trace_id, source, reason, score, status,
|
|
586
|
-
enqueued_at, started_at, completed_at, resolution, created_at, updated_at,
|
|
587
|
-
task_kind, priority, retry_count, max_retries, last_error, result_ref
|
|
588
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
589
|
-
ON CONFLICT(task_id) DO UPDATE SET
|
|
590
|
-
status = excluded.status,
|
|
591
|
-
started_at = excluded.started_at,
|
|
592
|
-
completed_at = excluded.completed_at,
|
|
593
|
-
resolution = excluded.resolution,
|
|
594
|
-
updated_at = excluded.updated_at,
|
|
595
|
-
task_kind = excluded.task_kind,
|
|
596
|
-
priority = excluded.priority,
|
|
597
|
-
retry_count = excluded.retry_count,
|
|
598
|
-
max_retries = excluded.max_retries,
|
|
599
|
-
last_error = excluded.last_error,
|
|
600
|
-
result_ref = excluded.result_ref
|
|
601
|
-
`).run(input.taskId, input.traceId, input.source, input.reason ?? null, input.score ?? 0, input.status ?? 'pending', input.enqueuedAt ?? null, input.startedAt ?? null, input.completedAt ?? null, input.resolution ?? null, input.createdAt ?? now, input.updatedAt ?? now, v2.taskKind ?? null, v2.priority ?? null, v2.retryCount ?? null, v2.maxRetries ?? null, v2.lastError ?? null, v2.resultRef ?? null);
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
updateEvolutionTask(taskId, updates) {
|
|
605
|
-
const now = nowIso();
|
|
606
|
-
// Cast to V2 to access new fields
|
|
607
|
-
const v2Updates = updates;
|
|
608
|
-
this.withWrite(() => {
|
|
609
|
-
const setClauses = ['updated_at = ?'];
|
|
610
|
-
const values = [now];
|
|
611
|
-
if (updates.status !== undefined) {
|
|
612
|
-
setClauses.push('status = ?');
|
|
613
|
-
values.push(updates.status);
|
|
614
|
-
}
|
|
615
|
-
if (updates.startedAt !== undefined) {
|
|
616
|
-
setClauses.push('started_at = ?');
|
|
617
|
-
values.push(updates.startedAt);
|
|
618
|
-
}
|
|
619
|
-
if (updates.completedAt !== undefined) {
|
|
620
|
-
setClauses.push('completed_at = ?');
|
|
621
|
-
values.push(updates.completedAt);
|
|
622
|
-
}
|
|
623
|
-
if (updates.resolution !== undefined) {
|
|
624
|
-
setClauses.push('resolution = ?');
|
|
625
|
-
values.push(updates.resolution);
|
|
626
|
-
}
|
|
627
|
-
if (updates.score !== undefined) {
|
|
628
|
-
setClauses.push('score = ?');
|
|
629
|
-
values.push(updates.score);
|
|
630
|
-
}
|
|
631
|
-
// V2 fields
|
|
632
|
-
if (v2Updates.taskKind !== undefined) {
|
|
633
|
-
setClauses.push('task_kind = ?');
|
|
634
|
-
values.push(v2Updates.taskKind);
|
|
635
|
-
}
|
|
636
|
-
if (v2Updates.priority !== undefined) {
|
|
637
|
-
setClauses.push('priority = ?');
|
|
638
|
-
values.push(v2Updates.priority);
|
|
639
|
-
}
|
|
640
|
-
if (v2Updates.retryCount !== undefined) {
|
|
641
|
-
setClauses.push('retry_count = ?');
|
|
642
|
-
values.push(v2Updates.retryCount);
|
|
643
|
-
}
|
|
644
|
-
if (v2Updates.maxRetries !== undefined) {
|
|
645
|
-
setClauses.push('max_retries = ?');
|
|
646
|
-
values.push(v2Updates.maxRetries);
|
|
647
|
-
}
|
|
648
|
-
if (v2Updates.lastError !== undefined) {
|
|
649
|
-
setClauses.push('last_error = ?');
|
|
650
|
-
values.push(v2Updates.lastError);
|
|
651
|
-
}
|
|
652
|
-
if (v2Updates.resultRef !== undefined) {
|
|
653
|
-
setClauses.push('result_ref = ?');
|
|
654
|
-
values.push(v2Updates.resultRef);
|
|
655
|
-
}
|
|
656
|
-
values.push(taskId);
|
|
657
|
-
this.db.prepare(`
|
|
658
|
-
UPDATE evolution_tasks SET ${setClauses.join(', ')} WHERE task_id = ?
|
|
659
|
-
`).run(...values);
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
recordEvolutionEvent(input) {
|
|
663
|
-
this.withWrite(() => {
|
|
664
|
-
this.db.prepare(`
|
|
665
|
-
INSERT INTO evolution_events (trace_id, task_id, stage, level, message, summary, metadata_json, created_at)
|
|
666
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
667
|
-
`).run(input.traceId, input.taskId ?? null, input.stage, input.level ?? 'info', input.message, input.summary ?? null, safeJson(input.metadata), input.createdAt ?? nowIso());
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* List evolution tasks with optional filtering.
|
|
672
|
-
*
|
|
673
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
674
|
-
* Not: Runtime truth or real-time queue state.
|
|
675
|
-
*/
|
|
676
|
-
listEvolutionTasks(filters = {}) {
|
|
677
|
-
const conditions = [];
|
|
678
|
-
const values = [];
|
|
679
|
-
if (filters.status) {
|
|
680
|
-
conditions.push('status = ?');
|
|
681
|
-
values.push(filters.status);
|
|
682
|
-
}
|
|
683
|
-
if (filters.dateFrom) {
|
|
684
|
-
conditions.push('created_at >= ?');
|
|
685
|
-
values.push(filters.dateFrom);
|
|
686
|
-
}
|
|
687
|
-
if (filters.dateTo) {
|
|
688
|
-
conditions.push('created_at <= ?');
|
|
689
|
-
values.push(filters.dateTo);
|
|
690
|
-
}
|
|
691
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
692
|
-
const limit = filters.limit ?? 50;
|
|
693
|
-
const offset = filters.offset ?? 0;
|
|
694
|
-
const rows = this.db.prepare(`
|
|
695
|
-
SELECT id, task_id, trace_id, source, reason, score, status,
|
|
696
|
-
enqueued_at, started_at, completed_at, resolution, created_at, updated_at,
|
|
697
|
-
task_kind, priority, retry_count, max_retries, last_error, result_ref
|
|
698
|
-
FROM evolution_tasks
|
|
699
|
-
${whereClause}
|
|
700
|
-
ORDER BY created_at DESC
|
|
701
|
-
LIMIT ? OFFSET ?
|
|
702
|
-
`).all(...values, limit, offset);
|
|
703
|
-
return rows.map((row) => ({
|
|
704
|
-
id: Number(row.id),
|
|
705
|
-
taskId: String(row.task_id),
|
|
706
|
-
traceId: String(row.trace_id),
|
|
707
|
-
source: String(row.source),
|
|
708
|
-
reason: row.reason ? String(row.reason) : null,
|
|
709
|
-
score: Number(row.score ?? 0),
|
|
710
|
-
status: String(row.status),
|
|
711
|
-
enqueuedAt: row.enqueued_at ? String(row.enqueued_at) : null,
|
|
712
|
-
startedAt: row.started_at ? String(row.started_at) : null,
|
|
713
|
-
completedAt: row.completed_at ? String(row.completed_at) : null,
|
|
714
|
-
resolution: row.resolution ? String(row.resolution) : null,
|
|
715
|
-
createdAt: String(row.created_at),
|
|
716
|
-
updatedAt: String(row.updated_at),
|
|
717
|
-
taskKind: row.task_kind ? row.task_kind : null,
|
|
718
|
-
priority: row.priority ? row.priority : null,
|
|
719
|
-
retryCount: row.retry_count != null ? Number(row.retry_count) : null,
|
|
720
|
-
maxRetries: row.max_retries != null ? Number(row.max_retries) : null,
|
|
721
|
-
lastError: row.last_error ? String(row.last_error) : null,
|
|
722
|
-
resultRef: row.result_ref ? String(row.result_ref) : null,
|
|
723
|
-
}));
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* List evolution events for a trace or globally.
|
|
727
|
-
*
|
|
728
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
729
|
-
* Not: Runtime truth or real-time queue state.
|
|
730
|
-
*/
|
|
731
|
-
listEvolutionEvents(traceId, filters = {}) {
|
|
732
|
-
const limit = filters.limit ?? 100;
|
|
733
|
-
const offset = filters.offset ?? 0;
|
|
734
|
-
let rows;
|
|
735
|
-
if (traceId) {
|
|
736
|
-
rows = this.db.prepare(`
|
|
737
|
-
SELECT id, trace_id, task_id, stage, level, message, summary, metadata_json, created_at
|
|
738
|
-
FROM evolution_events
|
|
739
|
-
WHERE trace_id = ?
|
|
740
|
-
ORDER BY created_at ASC
|
|
741
|
-
LIMIT ? OFFSET ?
|
|
742
|
-
`).all(traceId, limit, offset);
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
rows = this.db.prepare(`
|
|
746
|
-
SELECT id, trace_id, task_id, stage, level, message, summary, metadata_json, created_at
|
|
747
|
-
FROM evolution_events
|
|
748
|
-
ORDER BY created_at DESC
|
|
749
|
-
LIMIT ? OFFSET ?
|
|
750
|
-
`).all(limit, offset);
|
|
751
|
-
}
|
|
752
|
-
return rows.map((row) => ({
|
|
753
|
-
id: Number(row.id),
|
|
754
|
-
traceId: String(row.trace_id),
|
|
755
|
-
taskId: row.task_id ? String(row.task_id) : null,
|
|
756
|
-
stage: String(row.stage),
|
|
757
|
-
level: String(row.level ?? 'info'),
|
|
758
|
-
message: String(row.message),
|
|
759
|
-
summary: row.summary ? String(row.summary) : null,
|
|
760
|
-
metadata: JSON.parse(String(row.metadata_json ?? '{}')),
|
|
761
|
-
createdAt: String(row.created_at),
|
|
762
|
-
}));
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* Get evolution task by trace ID.
|
|
766
|
-
*
|
|
767
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
768
|
-
* Not: Runtime truth or real-time queue state.
|
|
769
|
-
*/
|
|
770
|
-
getEvolutionTaskByTraceId(traceId) {
|
|
771
|
-
const row = this.db.prepare(`
|
|
772
|
-
SELECT id, task_id, trace_id, source, reason, score, status,
|
|
773
|
-
enqueued_at, started_at, completed_at, resolution, created_at, updated_at,
|
|
774
|
-
task_kind, priority, retry_count, max_retries, last_error, result_ref
|
|
775
|
-
FROM evolution_tasks
|
|
776
|
-
WHERE trace_id = ?
|
|
777
|
-
LIMIT 1
|
|
778
|
-
`).get(traceId);
|
|
779
|
-
if (!row)
|
|
780
|
-
return null;
|
|
781
|
-
return {
|
|
782
|
-
id: Number(row.id),
|
|
783
|
-
taskId: String(row.task_id),
|
|
784
|
-
traceId: String(row.trace_id),
|
|
785
|
-
source: String(row.source),
|
|
786
|
-
reason: row.reason ? String(row.reason) : null,
|
|
787
|
-
score: Number(row.score ?? 0),
|
|
788
|
-
status: String(row.status),
|
|
789
|
-
enqueuedAt: row.enqueued_at ? String(row.enqueued_at) : null,
|
|
790
|
-
startedAt: row.started_at ? String(row.started_at) : null,
|
|
791
|
-
completedAt: row.completed_at ? String(row.completed_at) : null,
|
|
792
|
-
resolution: row.resolution ? String(row.resolution) : null,
|
|
793
|
-
createdAt: String(row.created_at),
|
|
794
|
-
updatedAt: String(row.updated_at),
|
|
795
|
-
taskKind: row.task_kind ? row.task_kind : null,
|
|
796
|
-
priority: row.priority ? row.priority : null,
|
|
797
|
-
retryCount: row.retry_count != null ? Number(row.retry_count) : null,
|
|
798
|
-
maxRetries: row.max_retries != null ? Number(row.max_retries) : null,
|
|
799
|
-
lastError: row.last_error ? String(row.last_error) : null,
|
|
800
|
-
resultRef: row.result_ref ? String(row.result_ref) : null,
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Get evolution task statistics.
|
|
805
|
-
*
|
|
806
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
807
|
-
* Not: Runtime truth or real-time queue state.
|
|
808
|
-
*/
|
|
809
|
-
getEvolutionStats() {
|
|
810
|
-
const rows = this.db.prepare(`
|
|
811
|
-
SELECT status, COUNT(*) as count FROM evolution_tasks GROUP BY status
|
|
812
|
-
`).all();
|
|
813
|
-
const stats = { total: 0, pending: 0, inProgress: 0, completed: 0, failed: 0 };
|
|
814
|
-
for (const row of rows) {
|
|
815
|
-
stats.total += row.count;
|
|
816
|
-
if (row.status === 'pending')
|
|
817
|
-
stats.pending = row.count;
|
|
818
|
-
else if (row.status === 'in_progress')
|
|
819
|
-
stats.inProgress = row.count;
|
|
820
|
-
else if (row.status === 'completed')
|
|
821
|
-
stats.completed = row.count;
|
|
822
|
-
else if (row.status === 'failed')
|
|
823
|
-
stats.failed = row.count;
|
|
824
|
-
}
|
|
825
|
-
return stats;
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* List recent sessions from the trajectory database.
|
|
829
|
-
*
|
|
830
|
-
* Returns: Recent session records ordered by most recently updated.
|
|
831
|
-
*
|
|
832
|
-
* @param options.limit - Maximum number of sessions to return (default: 20)
|
|
833
|
-
* @param options.dateFrom - Only return sessions updated after this date
|
|
834
|
-
* @param options.dateTo - Only return sessions updated before this date
|
|
835
|
-
*/
|
|
836
|
-
listRecentSessions(options = {}) {
|
|
837
|
-
const conditions = [];
|
|
838
|
-
const values = [];
|
|
839
|
-
if (options.dateFrom) {
|
|
840
|
-
conditions.push('updated_at >= ?');
|
|
841
|
-
values.push(options.dateFrom);
|
|
842
|
-
}
|
|
843
|
-
if (options.dateTo) {
|
|
844
|
-
conditions.push('updated_at <= ?');
|
|
845
|
-
values.push(options.dateTo);
|
|
846
|
-
}
|
|
847
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
848
|
-
const limit = options.limit ?? 20;
|
|
849
|
-
const rows = this.db.prepare(`
|
|
850
|
-
SELECT session_id, started_at, updated_at
|
|
851
|
-
FROM sessions
|
|
852
|
-
${whereClause}
|
|
853
|
-
ORDER BY updated_at DESC
|
|
854
|
-
LIMIT ?
|
|
855
|
-
`).all(...values, limit);
|
|
856
|
-
return rows.map((row) => ({
|
|
857
|
-
sessionId: String(row.session_id),
|
|
858
|
-
startedAt: String(row.started_at),
|
|
859
|
-
updatedAt: String(row.updated_at),
|
|
860
|
-
}));
|
|
861
|
-
}
|
|
862
|
-
/**
|
|
863
|
-
* List assistant turns for a session.
|
|
864
|
-
*
|
|
865
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
866
|
-
* Not: Runtime truth or real-time queue state.
|
|
867
|
-
*/
|
|
868
|
-
listAssistantTurns(sessionId) {
|
|
869
|
-
const rows = this.db.prepare(`
|
|
870
|
-
SELECT id, session_id, run_id, provider, model, raw_text, sanitized_text, blob_ref,
|
|
871
|
-
stop_reason, thinking_blocks_count, created_at
|
|
872
|
-
FROM assistant_turns
|
|
873
|
-
WHERE session_id = ?
|
|
874
|
-
ORDER BY id ASC
|
|
875
|
-
`).all(sessionId);
|
|
876
|
-
return rows.map((row) => ({
|
|
877
|
-
id: Number(row.id),
|
|
878
|
-
sessionId: String(row.session_id),
|
|
879
|
-
runId: String(row.run_id),
|
|
880
|
-
provider: String(row.provider),
|
|
881
|
-
model: String(row.model),
|
|
882
|
-
rawText: this.restoreRawText(row.raw_text, row.blob_ref),
|
|
883
|
-
sanitizedText: String(row.sanitized_text ?? ''),
|
|
884
|
-
blobRef: row.blob_ref ? String(row.blob_ref) : null,
|
|
885
|
-
stopReason: row.stop_reason != null ? String(row.stop_reason) : null,
|
|
886
|
-
thinkingBlocksCount: row.thinking_blocks_count != null ? Number(row.thinking_blocks_count) : null,
|
|
887
|
-
createdAt: String(row.created_at),
|
|
888
|
-
}));
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* List tool calls for a session.
|
|
892
|
-
*
|
|
893
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
894
|
-
* Not: Runtime truth or real-time queue state.
|
|
895
|
-
*/
|
|
896
|
-
listToolCallsForSession(sessionId) {
|
|
897
|
-
const rows = this.db.prepare(`
|
|
898
|
-
SELECT id, tool_name, outcome, params_json, duration_ms, exit_code, error_type, error_message,
|
|
899
|
-
gfi_before, gfi_after, result_preview, created_at
|
|
900
|
-
FROM tool_calls
|
|
901
|
-
WHERE session_id = ?
|
|
902
|
-
ORDER BY id ASC
|
|
903
|
-
`).all(sessionId);
|
|
904
|
-
return rows.map((row) => {
|
|
905
|
-
// Extract filePath from params_json if present
|
|
906
|
-
let filePath = null;
|
|
907
|
-
if (row.params_json && typeof row.params_json === 'string') {
|
|
908
|
-
try {
|
|
909
|
-
const params = JSON.parse(row.params_json);
|
|
910
|
-
if (params && typeof params.filePath === 'string') {
|
|
911
|
-
filePath = params.filePath;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
catch {
|
|
915
|
-
// Ignore malformed JSON
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
return {
|
|
919
|
-
id: Number(row.id),
|
|
920
|
-
toolName: String(row.tool_name),
|
|
921
|
-
outcome: String(row.outcome),
|
|
922
|
-
filePath,
|
|
923
|
-
durationMs: row.duration_ms != null ? Number(row.duration_ms) : null,
|
|
924
|
-
exitCode: row.exit_code != null ? Number(row.exit_code) : null,
|
|
925
|
-
errorType: row.error_type ? String(row.error_type) : null,
|
|
926
|
-
errorMessage: row.error_message ? String(row.error_message) : null,
|
|
927
|
-
gfiBefore: row.gfi_before != null ? Number(row.gfi_before) : null,
|
|
928
|
-
gfiAfter: row.gfi_after != null ? Number(row.gfi_after) : null,
|
|
929
|
-
resultPreview: row.result_preview != null ? String(row.result_preview) : null,
|
|
930
|
-
createdAt: String(row.created_at),
|
|
931
|
-
};
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
/**
|
|
935
|
-
* PRI-482 Phase 3: Query tool_calls for RuleContext v2 history assembly.
|
|
936
|
-
*
|
|
937
|
-
* Reads limit+1 rows (DESC by id) to compute truncated, then reverses to FIFO.
|
|
938
|
-
* Returns raw rows — the assembler (rule-context-assembler.ts) validates them.
|
|
939
|
-
*
|
|
940
|
-
* Spec: §5.1, §5.2. ERR-026: reuses production schema (no hand-written DDL).
|
|
941
|
-
*/
|
|
942
|
-
getRuleHostContextRows(sessionId, limit = 20) {
|
|
943
|
-
const cappedLimit = Math.max(1, Math.floor(limit));
|
|
944
|
-
const rows = this.db.prepare(`
|
|
945
|
-
SELECT id, tool_name, outcome, params_json
|
|
946
|
-
FROM tool_calls
|
|
947
|
-
WHERE session_id = ?
|
|
948
|
-
ORDER BY id DESC
|
|
949
|
-
LIMIT ?
|
|
950
|
-
`).all(sessionId, cappedLimit + 1);
|
|
951
|
-
const truncated = rows.length > cappedLimit;
|
|
952
|
-
const output = truncated ? rows.slice(0, cappedLimit) : rows;
|
|
953
|
-
output.reverse(); // DESC → FIFO (oldest first)
|
|
954
|
-
return {
|
|
955
|
-
rows: output.map((row) => ({
|
|
956
|
-
id: Number(row.id),
|
|
957
|
-
toolName: String(row.tool_name),
|
|
958
|
-
outcome: String(row.outcome),
|
|
959
|
-
paramsJson: String(row.params_json),
|
|
960
|
-
})),
|
|
961
|
-
truncated,
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
/** Resolve one Owner-selected tool call without inferring its desired label. */
|
|
965
|
-
getRuleHostEvidenceRow(id) {
|
|
966
|
-
const row = this.db.prepare(`
|
|
967
|
-
SELECT id, session_id, tool_name, outcome, params_json
|
|
968
|
-
FROM tool_calls
|
|
969
|
-
WHERE id = ?
|
|
970
|
-
LIMIT 1
|
|
971
|
-
`).get(id);
|
|
972
|
-
if (!isStringRecord(row))
|
|
973
|
-
return null;
|
|
974
|
-
if (typeof row.id !== 'number' || typeof row.session_id !== 'string')
|
|
975
|
-
return null;
|
|
976
|
-
if (typeof row.tool_name !== 'string' || typeof row.outcome !== 'string' || typeof row.params_json !== 'string')
|
|
977
|
-
return null;
|
|
978
|
-
return {
|
|
979
|
-
id: row.id,
|
|
980
|
-
sessionId: row.session_id,
|
|
981
|
-
toolName: row.tool_name,
|
|
982
|
-
outcome: row.outcome,
|
|
983
|
-
paramsJson: row.params_json,
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
/** Return FIFO history strictly before an Owner-selected tool call. */
|
|
987
|
-
getRuleHostContextRowsBefore(sessionId, beforeId, limit = 20) {
|
|
988
|
-
const cappedLimit = Math.max(1, Math.floor(limit));
|
|
989
|
-
const rows = this.db.prepare(`
|
|
990
|
-
SELECT id, tool_name, outcome, params_json
|
|
991
|
-
FROM tool_calls
|
|
992
|
-
WHERE session_id = ? AND id < ?
|
|
993
|
-
ORDER BY id DESC
|
|
994
|
-
LIMIT ?
|
|
995
|
-
`).all(sessionId, beforeId, cappedLimit + 1);
|
|
996
|
-
const truncated = rows.length > cappedLimit;
|
|
997
|
-
const output = (truncated ? rows.slice(0, cappedLimit) : rows).reverse();
|
|
998
|
-
return {
|
|
999
|
-
rows: output.map((row) => ({
|
|
1000
|
-
id: Number(row.id), toolName: String(row.tool_name), outcome: String(row.outcome), paramsJson: String(row.params_json),
|
|
1001
|
-
})),
|
|
1002
|
-
truncated,
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* List pain events for a session.
|
|
1007
|
-
*
|
|
1008
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
1009
|
-
* Not: Runtime truth or real-time queue state.
|
|
1010
|
-
*/
|
|
1011
|
-
listPainEventsForSession(sessionId) {
|
|
1012
|
-
const rows = this.db.prepare(`
|
|
1013
|
-
SELECT id, source, score, reason, severity, origin, confidence, created_at
|
|
1014
|
-
FROM pain_events
|
|
1015
|
-
WHERE session_id = ?
|
|
1016
|
-
ORDER BY created_at ASC
|
|
1017
|
-
`).all(sessionId);
|
|
1018
|
-
return rows.map((row) => ({
|
|
1019
|
-
id: Number(row.id),
|
|
1020
|
-
source: String(row.source),
|
|
1021
|
-
score: Number(row.score),
|
|
1022
|
-
reason: row.reason ? String(row.reason) : null,
|
|
1023
|
-
severity: row.severity ? String(row.severity) : null,
|
|
1024
|
-
origin: row.origin ? String(row.origin) : null,
|
|
1025
|
-
confidence: row.confidence != null ? Number(row.confidence) : null,
|
|
1026
|
-
createdAt: String(row.created_at),
|
|
1027
|
-
}));
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* PRI-484 Phase 5 — Look up a single pain event by canonical_pain_id.
|
|
1031
|
-
*
|
|
1032
|
-
* Used by BehaviorExamplePackAssembler to anchor a pain lineage without
|
|
1033
|
-
* already knowing the session_id. Returns null when not found.
|
|
1034
|
-
*
|
|
1035
|
-
* ERR-001 (rc-1, rc-2): row fields validated as unknown — no `as` bypass.
|
|
1036
|
-
* Uses a type-guard predicate to narrow the DB row structurally.
|
|
1037
|
-
*/
|
|
1038
|
-
getPainEventByCanonicalId(canonicalPainId) {
|
|
1039
|
-
const rawRow = this.db.prepare(`
|
|
1040
|
-
SELECT id, session_id, source, score, reason, severity, origin, confidence,
|
|
1041
|
-
text, canonical_pain_id, runtime_task_id, created_at
|
|
1042
|
-
FROM pain_events
|
|
1043
|
-
WHERE canonical_pain_id = ?
|
|
1044
|
-
LIMIT 1
|
|
1045
|
-
`).get(canonicalPainId);
|
|
1046
|
-
if (!isPainEventRow(rawRow))
|
|
1047
|
-
return null;
|
|
1048
|
-
return {
|
|
1049
|
-
id: rawRow.id,
|
|
1050
|
-
sessionId: rawRow.session_id,
|
|
1051
|
-
source: String(rawRow.source),
|
|
1052
|
-
score: Number(rawRow.score),
|
|
1053
|
-
reason: rawRow.reason ? String(rawRow.reason) : null,
|
|
1054
|
-
severity: rawRow.severity ? String(rawRow.severity) : null,
|
|
1055
|
-
origin: rawRow.origin ? String(rawRow.origin) : null,
|
|
1056
|
-
confidence: rawRow.confidence != null ? Number(rawRow.confidence) : null,
|
|
1057
|
-
text: rawRow.text ? String(rawRow.text) : null,
|
|
1058
|
-
canonicalPainId: String(rawRow.canonical_pain_id),
|
|
1059
|
-
runtimeTaskId: rawRow.runtime_task_id ? String(rawRow.runtime_task_id) : null,
|
|
1060
|
-
createdAt: String(rawRow.created_at),
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* List user turns for a session.
|
|
1065
|
-
* Returns sanitized/reduced fields for nocturnal use — NO raw text.
|
|
1066
|
-
*/
|
|
1067
|
-
listUserTurnsForSession(sessionId) {
|
|
1068
|
-
const rows = this.db.prepare(`
|
|
1069
|
-
SELECT id, turn_index, raw_excerpt, correction_detected, correction_cue, created_at
|
|
1070
|
-
FROM user_turns
|
|
1071
|
-
WHERE session_id = ?
|
|
1072
|
-
ORDER BY turn_index ASC
|
|
1073
|
-
`).all(sessionId);
|
|
1074
|
-
return rows.map((row) => ({
|
|
1075
|
-
id: Number(row.id),
|
|
1076
|
-
turnIndex: Number(row.turn_index),
|
|
1077
|
-
rawExcerpt: String(row.raw_excerpt ?? ''),
|
|
1078
|
-
correctionDetected: Boolean(row.correction_detected),
|
|
1079
|
-
correctionCue: row.correction_cue ? String(row.correction_cue) : null,
|
|
1080
|
-
createdAt: String(row.created_at),
|
|
1081
|
-
}));
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* List correction samples with optional review status filter.
|
|
1085
|
-
*
|
|
1086
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
1087
|
-
* Not: Runtime truth or real-time queue state.
|
|
1088
|
-
*/
|
|
1089
|
-
listCorrectionSamples(status = 'pending') {
|
|
1090
|
-
const rows = this.db.prepare(`
|
|
1091
|
-
SELECT sample_id, session_id, bad_assistant_turn_id, user_correction_turn_id,
|
|
1092
|
-
recovery_tool_span_json, diff_excerpt, principle_ids_json, quality_score,
|
|
1093
|
-
review_status, export_mode, created_at, updated_at
|
|
1094
|
-
FROM correction_samples
|
|
1095
|
-
WHERE review_status = ?
|
|
1096
|
-
ORDER BY created_at DESC
|
|
1097
|
-
`).all(status);
|
|
1098
|
-
return rows.map((row) => ({
|
|
1099
|
-
sampleId: String(row.sample_id),
|
|
1100
|
-
sessionId: String(row.session_id),
|
|
1101
|
-
badAssistantTurnId: Number(row.bad_assistant_turn_id),
|
|
1102
|
-
userCorrectionTurnId: Number(row.user_correction_turn_id),
|
|
1103
|
-
recoveryToolSpanJson: String(row.recovery_tool_span_json),
|
|
1104
|
-
diffExcerpt: String(row.diff_excerpt ?? ''),
|
|
1105
|
-
principleIdsJson: String(row.principle_ids_json ?? '[]'),
|
|
1106
|
-
qualityScore: Number(row.quality_score),
|
|
1107
|
-
reviewStatus: row.review_status,
|
|
1108
|
-
exportMode: row.export_mode,
|
|
1109
|
-
createdAt: String(row.created_at),
|
|
1110
|
-
updatedAt: String(row.updated_at),
|
|
1111
|
-
}));
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* List gate blocks for a session.
|
|
1115
|
-
* Returns minimal fields for nocturnal use — no raw text.
|
|
1116
|
-
*/
|
|
1117
|
-
listGateBlocksForSession(sessionId) {
|
|
1118
|
-
const rows = this.db.prepare(`
|
|
1119
|
-
SELECT id, tool_name, file_path, reason, plan_status, created_at
|
|
1120
|
-
FROM gate_blocks
|
|
1121
|
-
WHERE session_id = ?
|
|
1122
|
-
ORDER BY id ASC
|
|
1123
|
-
`).all(sessionId);
|
|
1124
|
-
return rows.map((row) => ({
|
|
1125
|
-
id: Number(row.id),
|
|
1126
|
-
toolName: String(row.tool_name),
|
|
1127
|
-
filePath: row.file_path ? String(row.file_path) : null,
|
|
1128
|
-
reason: String(row.reason),
|
|
1129
|
-
planStatus: row.plan_status ? String(row.plan_status) : null,
|
|
1130
|
-
createdAt: String(row.created_at),
|
|
1131
|
-
}));
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* List correction samples for a specific session.
|
|
1135
|
-
* Returns minimal fields for nocturnal use — correction cue only.
|
|
1136
|
-
* #268: Wire correction_samples into nocturnal pipeline.
|
|
1137
|
-
*/
|
|
1138
|
-
listCorrectionSamplesForSession(sessionId) {
|
|
1139
|
-
const rows = this.db.prepare(`
|
|
1140
|
-
SELECT cs.sample_id, ut.correction_cue
|
|
1141
|
-
FROM correction_samples cs
|
|
1142
|
-
LEFT JOIN user_turns ut ON ut.id = cs.user_correction_turn_id
|
|
1143
|
-
WHERE cs.session_id = ?
|
|
1144
|
-
ORDER BY cs.created_at DESC
|
|
1145
|
-
`).all(sessionId);
|
|
1146
|
-
return rows.map((row) => ({
|
|
1147
|
-
correctionCue: row.correction_cue ? String(row.correction_cue) : null,
|
|
1148
|
-
}));
|
|
1149
|
-
}
|
|
1150
|
-
reviewCorrectionSample(sampleId, status, note) {
|
|
1151
|
-
const updatedAt = nowIso();
|
|
1152
|
-
const updated = this.withWrite(() => {
|
|
1153
|
-
const updateResult = this.db.prepare(`
|
|
1154
|
-
UPDATE correction_samples
|
|
1155
|
-
SET review_status = ?, updated_at = ?
|
|
1156
|
-
WHERE sample_id = ?
|
|
1157
|
-
`).run(status, updatedAt, sampleId);
|
|
1158
|
-
if (updateResult.changes === 0) {
|
|
1159
|
-
return false;
|
|
1160
|
-
}
|
|
1161
|
-
this.db.prepare(`
|
|
1162
|
-
INSERT INTO sample_reviews (sample_id, review_status, note, created_at)
|
|
1163
|
-
VALUES (?, ?, ?, ?)
|
|
1164
|
-
`).run(sampleId, status, note ?? null, updatedAt);
|
|
1165
|
-
return true;
|
|
1166
|
-
});
|
|
1167
|
-
if (!updated) {
|
|
1168
|
-
throw new SampleNotFoundError(sampleId);
|
|
1169
|
-
}
|
|
1170
|
-
const record = this.db.prepare(`
|
|
1171
|
-
SELECT sample_id, session_id, bad_assistant_turn_id, user_correction_turn_id,
|
|
1172
|
-
recovery_tool_span_json, diff_excerpt, principle_ids_json, quality_score,
|
|
1173
|
-
review_status, export_mode, created_at, updated_at
|
|
1174
|
-
FROM correction_samples
|
|
1175
|
-
WHERE sample_id = ?
|
|
1176
|
-
`).get(sampleId);
|
|
1177
|
-
if (!record) {
|
|
1178
|
-
throw new SampleNotFoundError(`${sampleId} (after update)`);
|
|
1179
|
-
}
|
|
1180
|
-
// #Phase2b: Emit pain event for rejected corrections
|
|
1181
|
-
if (status === 'rejected') {
|
|
1182
|
-
this.recordCorrectionRejectedPain({
|
|
1183
|
-
session_id: record.session_id,
|
|
1184
|
-
quality_score: record.quality_score,
|
|
1185
|
-
diff_excerpt: record.diff_excerpt,
|
|
1186
|
-
principle_ids_json: record.principle_ids_json,
|
|
1187
|
-
created_at: record.created_at,
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
|
-
return {
|
|
1191
|
-
sampleId: String(record.sample_id),
|
|
1192
|
-
sessionId: String(record.session_id),
|
|
1193
|
-
badAssistantTurnId: Number(record.bad_assistant_turn_id),
|
|
1194
|
-
userCorrectionTurnId: Number(record.user_correction_turn_id),
|
|
1195
|
-
recoveryToolSpanJson: String(record.recovery_tool_span_json),
|
|
1196
|
-
diffExcerpt: String(record.diff_excerpt ?? ''),
|
|
1197
|
-
principleIdsJson: String(record.principle_ids_json ?? '[]'),
|
|
1198
|
-
qualityScore: Number(record.quality_score),
|
|
1199
|
-
reviewStatus: record.review_status,
|
|
1200
|
-
exportMode: record.export_mode,
|
|
1201
|
-
createdAt: String(record.created_at),
|
|
1202
|
-
updatedAt: String(record.updated_at),
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
/**
|
|
1206
|
-
* When a correction sample is rejected, emit a pain event to the trajectory.
|
|
1207
|
-
* This feeds rejected corrections into the nocturnal pipeline as a high-fidelity
|
|
1208
|
-
* violation signal (human-verified, unlike heuristic pain detection).
|
|
1209
|
-
*/
|
|
1210
|
-
recordCorrectionRejectedPain(record) {
|
|
1211
|
-
const sessionId = String(record.session_id);
|
|
1212
|
-
const qualityScore = Number(record.quality_score);
|
|
1213
|
-
const diffExcerpt = String(record.diff_excerpt ?? '');
|
|
1214
|
-
const principleIds = String(record.principle_ids_json ?? '[]');
|
|
1215
|
-
// quality_score (0-100) from correction sample → pain score (0-100), clamped
|
|
1216
|
-
const painScore = Math.max(0, Math.min(100, Math.round(Number(qualityScore) || 0)));
|
|
1217
|
-
const reason = `Correction rejected (quality ${qualityScore.toFixed(2)}). Principles: ${principleIds}${diffExcerpt ? ` — ${diffExcerpt.slice(0, 120)}` : ''}`;
|
|
1218
|
-
try {
|
|
1219
|
-
this.recordPainEvent({
|
|
1220
|
-
sessionId,
|
|
1221
|
-
source: 'correction_rejected',
|
|
1222
|
-
score: painScore,
|
|
1223
|
-
reason,
|
|
1224
|
-
severity: painScore >= 70 ? 'severe' : painScore >= 40 ? 'moderate' : 'mild',
|
|
1225
|
-
origin: 'system_infer',
|
|
1226
|
-
text: diffExcerpt || undefined,
|
|
1227
|
-
createdAt: String(record.created_at),
|
|
1228
|
-
});
|
|
1229
|
-
}
|
|
1230
|
-
catch (err) {
|
|
1231
|
-
// Non-fatal: pain event recording should not break the review flow
|
|
1232
|
-
console.warn(`[Trajectory] Failed to record correction_rejected pain event: ${String(err)}`);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
/**
|
|
1236
|
-
* Export correction samples to JSONL file.
|
|
1237
|
-
*
|
|
1238
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
1239
|
-
* Not: Runtime truth or real-time queue state.
|
|
1240
|
-
*/
|
|
1241
|
-
exportCorrections(opts) {
|
|
1242
|
-
const rows = this.db.prepare(`
|
|
1243
|
-
SELECT cs.sample_id, cs.session_id, cs.recovery_tool_span_json, cs.diff_excerpt, cs.quality_score,
|
|
1244
|
-
at.raw_text AS assistant_raw_text, at.blob_ref AS assistant_blob_ref, at.sanitized_text,
|
|
1245
|
-
ut.raw_text AS user_raw_text, ut.blob_ref AS user_blob_ref, ut.correction_cue
|
|
1246
|
-
FROM correction_samples cs
|
|
1247
|
-
JOIN assistant_turns at ON at.id = cs.bad_assistant_turn_id
|
|
1248
|
-
JOIN user_turns ut ON ut.id = cs.user_correction_turn_id
|
|
1249
|
-
WHERE (? = 0 OR cs.review_status = 'approved')
|
|
1250
|
-
ORDER BY cs.created_at ASC
|
|
1251
|
-
`).all(opts.approvedOnly ? 1 : 0);
|
|
1252
|
-
const exportPath = path.join(this.exportDir, `corrections-${Date.now()}-${opts.mode}.jsonl`);
|
|
1253
|
-
const lines = rows.map((row) => {
|
|
1254
|
-
const assistantRaw = this.restoreRawText(row.assistant_raw_text, row.assistant_blob_ref);
|
|
1255
|
-
const userRaw = this.restoreRawText(row.user_raw_text, row.user_blob_ref);
|
|
1256
|
-
const assistantText = opts.mode === 'redacted' ? redactText(assistantRaw) : assistantRaw;
|
|
1257
|
-
const userText = opts.mode === 'redacted' ? redactText(userRaw) : userRaw;
|
|
1258
|
-
return JSON.stringify({
|
|
1259
|
-
sample_id: row.sample_id,
|
|
1260
|
-
session_id: row.session_id,
|
|
1261
|
-
instruction: userText,
|
|
1262
|
-
input_context: assistantText,
|
|
1263
|
-
bad_attempt_summary: String(row.diff_excerpt ?? ''),
|
|
1264
|
-
preferred_response: userText,
|
|
1265
|
-
labels: {
|
|
1266
|
-
correction_cue: row.correction_cue,
|
|
1267
|
-
quality_score: row.quality_score,
|
|
1268
|
-
},
|
|
1269
|
-
metadata: {
|
|
1270
|
-
mode: opts.mode,
|
|
1271
|
-
recovery_tool_span_json: row.recovery_tool_span_json,
|
|
1272
|
-
},
|
|
1273
|
-
});
|
|
1274
|
-
});
|
|
1275
|
-
atomicWriteFileSync(exportPath, `${lines.join('\n')}${lines.length > 0 ? '\n' : ''}`);
|
|
1276
|
-
this.recordExportAudit('corrections', opts.mode, opts.approvedOnly, exportPath, rows.length);
|
|
1277
|
-
return { filePath: exportPath, count: rows.length, mode: opts.mode };
|
|
1278
|
-
}
|
|
1279
|
-
/**
|
|
1280
|
-
* Export analytics data to JSON file.
|
|
1281
|
-
*
|
|
1282
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
1283
|
-
* Not: Runtime truth or real-time queue state.
|
|
1284
|
-
*/
|
|
1285
|
-
exportAnalytics() {
|
|
1286
|
-
const payload = {
|
|
1287
|
-
generatedAt: nowIso(),
|
|
1288
|
-
stats: this.getDataStats(),
|
|
1289
|
-
dailyMetrics: this.dailyMetrics(),
|
|
1290
|
-
errorClusters: this.db.prepare('SELECT * FROM v_error_clusters').all(),
|
|
1291
|
-
principleEffectiveness: this.db.prepare('SELECT * FROM v_principle_effectiveness').all(),
|
|
1292
|
-
sampleQueue: this.db.prepare('SELECT * FROM v_sample_queue').all(),
|
|
1293
|
-
};
|
|
1294
|
-
const exportPath = path.join(this.exportDir, `analytics-${Date.now()}.json`);
|
|
1295
|
-
atomicWriteFileSync(exportPath, JSON.stringify(payload, null, 2));
|
|
1296
|
-
this.recordExportAudit('analytics', 'raw', true, exportPath, Array.isArray(payload.dailyMetrics) ? payload.dailyMetrics.length : 0);
|
|
1297
|
-
return { filePath: exportPath, count: Array.isArray(payload.dailyMetrics) ? payload.dailyMetrics.length : 0 };
|
|
1298
|
-
}
|
|
1299
|
-
/**
|
|
1300
|
-
* Get trajectory database statistics.
|
|
1301
|
-
*
|
|
1302
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
1303
|
-
* Not: Runtime truth or real-time queue state.
|
|
1304
|
-
*/
|
|
1305
|
-
getDataStats() {
|
|
1306
|
-
const getCount = (table, where) => {
|
|
1307
|
-
const sql = where ? `SELECT COUNT(*) as count FROM ${table} WHERE ${where}` : `SELECT COUNT(*) as count FROM ${table}`;
|
|
1308
|
-
return Number(this.db.prepare(sql).get().count);
|
|
1309
|
-
};
|
|
1310
|
-
const lastIngest = this.db.prepare(`
|
|
1311
|
-
SELECT MAX(ts) AS ts FROM (
|
|
1312
|
-
SELECT MAX(created_at) AS ts FROM assistant_turns
|
|
1313
|
-
UNION ALL SELECT MAX(created_at) AS ts FROM user_turns
|
|
1314
|
-
UNION ALL SELECT MAX(created_at) AS ts FROM tool_calls
|
|
1315
|
-
UNION ALL SELECT MAX(created_at) AS ts FROM pain_events
|
|
1316
|
-
)
|
|
1317
|
-
`).get();
|
|
1318
|
-
return {
|
|
1319
|
-
dbPath: this.dbPath,
|
|
1320
|
-
dbSizeBytes: fileSizeIfExists(this.dbPath),
|
|
1321
|
-
assistantTurns: getCount('assistant_turns'),
|
|
1322
|
-
userTurns: getCount('user_turns'),
|
|
1323
|
-
toolCalls: getCount('tool_calls'),
|
|
1324
|
-
painEvents: getCount('pain_events'),
|
|
1325
|
-
pendingSamples: getCount('correction_samples', `review_status = 'pending'`),
|
|
1326
|
-
approvedSamples: getCount('correction_samples', `review_status = 'approved'`),
|
|
1327
|
-
blobBytes: this.computeBlobBytes(),
|
|
1328
|
-
lastIngestAt: lastIngest.ts ?? null,
|
|
1329
|
-
};
|
|
1330
|
-
}
|
|
1331
|
-
cleanupBlobStorage() {
|
|
1332
|
-
return this.pruneUnreferencedBlobs();
|
|
1333
|
-
}
|
|
1334
|
-
initSchema() {
|
|
1335
|
-
const result = applyTrajectorySchema(this.db);
|
|
1336
|
-
// Best-effort: surface any warnings from schema initialization (rc-9: no silent fallback).
|
|
1337
|
-
// Warnings include failed migrations or view creation issues; surfaced via console.info
|
|
1338
|
-
// because TrajectoryDatabase does not have a warnings buffer at this layer.
|
|
1339
|
-
for (const w of result.warnings) {
|
|
1340
|
-
console.info(`[PD:TrajectoryDatabase] schema init warning: ${w}`);
|
|
1341
|
-
}
|
|
1342
|
-
const row = this.db.prepare('SELECT version FROM schema_version LIMIT 1').get();
|
|
1343
|
-
this.migrateSchema(row?.version);
|
|
1344
|
-
if (!row) {
|
|
1345
|
-
this.db.prepare('INSERT INTO schema_version (version) VALUES (?)').run(SCHEMA_VERSION);
|
|
1346
|
-
}
|
|
1347
|
-
else if (row.version !== SCHEMA_VERSION) {
|
|
1348
|
-
this.db.prepare('UPDATE schema_version SET version = ?').run(SCHEMA_VERSION);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
importLegacyArtifacts() {
|
|
1352
|
-
this.importLegacySessions();
|
|
1353
|
-
this.importLegacyEvents();
|
|
1354
|
-
this.importLegacyEvolution();
|
|
1355
|
-
}
|
|
1356
|
-
migrateSchema(_fromVersion) {
|
|
1357
|
-
this.db.exec(`
|
|
1358
|
-
DROP VIEW IF EXISTS v_daily_metrics;
|
|
1359
|
-
CREATE VIEW IF NOT EXISTS v_daily_metrics AS
|
|
1360
|
-
WITH tool_daily AS (
|
|
1361
|
-
SELECT
|
|
1362
|
-
substr(created_at, 1, 10) AS day,
|
|
1363
|
-
COUNT(*) AS tool_calls,
|
|
1364
|
-
SUM(CASE WHEN outcome = 'failure' THEN 1 ELSE 0 END) AS failures
|
|
1365
|
-
FROM tool_calls
|
|
1366
|
-
GROUP BY substr(created_at, 1, 10)
|
|
1367
|
-
),
|
|
1368
|
-
correction_daily AS (
|
|
1369
|
-
SELECT
|
|
1370
|
-
substr(created_at, 1, 10) AS day,
|
|
1371
|
-
SUM(CASE WHEN correction_detected = 1 THEN 1 ELSE 0 END) AS user_corrections
|
|
1372
|
-
FROM user_turns
|
|
1373
|
-
GROUP BY substr(created_at, 1, 10)
|
|
1374
|
-
)
|
|
1375
|
-
SELECT
|
|
1376
|
-
tool_daily.day AS day,
|
|
1377
|
-
tool_daily.tool_calls AS tool_calls,
|
|
1378
|
-
tool_daily.failures AS failures,
|
|
1379
|
-
COALESCE(correction_daily.user_corrections, 0) AS user_corrections
|
|
1380
|
-
FROM tool_daily
|
|
1381
|
-
LEFT JOIN correction_daily ON correction_daily.day = tool_daily.day;
|
|
1382
|
-
`);
|
|
1383
|
-
}
|
|
1384
|
-
/**
|
|
1385
|
-
* Get daily metrics for analytics.
|
|
1386
|
-
*
|
|
1387
|
-
* Returns: Analytics data aggregated from trajectory database.
|
|
1388
|
-
* Not: Runtime truth or real-time queue state.
|
|
1389
|
-
*/
|
|
1390
|
-
dailyMetrics() {
|
|
1391
|
-
return this.db.prepare('SELECT * FROM v_daily_metrics ORDER BY day ASC').all();
|
|
1392
|
-
}
|
|
1393
|
-
importLegacySessions() {
|
|
1394
|
-
const key = 'legacy:sessions';
|
|
1395
|
-
if (this.isImported(key))
|
|
1396
|
-
return;
|
|
1397
|
-
const sessionDir = resolvePdPath(this.workspaceDir, 'SESSION_DIR');
|
|
1398
|
-
if (!fs.existsSync(sessionDir))
|
|
1399
|
-
return;
|
|
1400
|
-
for (const file of fs.readdirSync(sessionDir).filter((entry) => entry.endsWith('.json'))) {
|
|
1401
|
-
try {
|
|
1402
|
-
const content = JSON.parse(fs.readFileSync(path.join(sessionDir, file), 'utf8'));
|
|
1403
|
-
if (content.sessionId) {
|
|
1404
|
-
const startedAt = typeof content.lastActivityAt === 'number'
|
|
1405
|
-
? new Date(content.lastActivityAt).toISOString()
|
|
1406
|
-
: nowIso();
|
|
1407
|
-
this.recordSession({ sessionId: content.sessionId, startedAt });
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
catch {
|
|
1411
|
-
// Ignore malformed legacy sessions.
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
this.markImported(key);
|
|
1415
|
-
}
|
|
1416
|
-
importLegacyEvents() {
|
|
1417
|
-
const key = 'legacy:events';
|
|
1418
|
-
if (this.isImported(key))
|
|
1419
|
-
return;
|
|
1420
|
-
const eventsPath = path.join(this.stateDir, 'logs', 'events.jsonl');
|
|
1421
|
-
if (!fs.existsSync(eventsPath))
|
|
1422
|
-
return;
|
|
1423
|
-
const raw = fs.readFileSync(eventsPath, 'utf8').trim();
|
|
1424
|
-
if (!raw) {
|
|
1425
|
-
this.markImported(key);
|
|
1426
|
-
return;
|
|
1427
|
-
}
|
|
1428
|
-
for (const line of raw.split('\n')) {
|
|
1429
|
-
try {
|
|
1430
|
-
const event = JSON.parse(line);
|
|
1431
|
-
if (event.type === 'pain_signal' && event.sessionId) {
|
|
1432
|
-
this.recordPainEvent({
|
|
1433
|
-
sessionId: event.sessionId,
|
|
1434
|
-
source: String(event.data?.source ?? 'legacy'),
|
|
1435
|
-
score: Number(event.data?.score ?? 0),
|
|
1436
|
-
reason: typeof event.data?.reason === 'string' ? event.data.reason : null,
|
|
1437
|
-
severity: typeof event.data?.severity === 'string' ? event.data.severity : null,
|
|
1438
|
-
origin: typeof event.data?.origin === 'string' ? event.data.origin : null,
|
|
1439
|
-
confidence: typeof event.data?.confidence === 'number' ? event.data.confidence : null,
|
|
1440
|
-
createdAt: event.ts,
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
|
-
if (event.type === 'trust_change') {
|
|
1444
|
-
this.recordTrustChange({
|
|
1445
|
-
sessionId: event.sessionId,
|
|
1446
|
-
previousScore: Number(event.data?.previousScore ?? 0),
|
|
1447
|
-
newScore: Number(event.data?.newScore ?? 0),
|
|
1448
|
-
delta: Number(event.data?.delta ?? 0),
|
|
1449
|
-
reason: String(event.data?.reason ?? 'legacy'),
|
|
1450
|
-
createdAt: event.ts,
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
if (event.type === 'gate_block') {
|
|
1454
|
-
this.recordGateBlock({
|
|
1455
|
-
sessionId: event.sessionId,
|
|
1456
|
-
toolName: String(event.data?.toolName ?? 'unknown'),
|
|
1457
|
-
filePath: typeof event.data?.filePath === 'string' ? event.data.filePath : null,
|
|
1458
|
-
reason: String(event.data?.reason ?? 'legacy'),
|
|
1459
|
-
planStatus: typeof event.data?.planStatus === 'string' ? event.data.planStatus : null,
|
|
1460
|
-
createdAt: event.ts,
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
catch {
|
|
1465
|
-
// Ignore malformed legacy events.
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
this.markImported(key);
|
|
1469
|
-
}
|
|
1470
|
-
importLegacyEvolution() {
|
|
1471
|
-
const key = 'legacy:evolution';
|
|
1472
|
-
if (this.isImported(key))
|
|
1473
|
-
return;
|
|
1474
|
-
const evolutionPath = resolvePdPath(this.workspaceDir, 'EVOLUTION_STREAM');
|
|
1475
|
-
if (!fs.existsSync(evolutionPath))
|
|
1476
|
-
return;
|
|
1477
|
-
const raw = fs.readFileSync(evolutionPath, 'utf8').trim();
|
|
1478
|
-
if (!raw) {
|
|
1479
|
-
this.markImported(key);
|
|
1480
|
-
return;
|
|
1481
|
-
}
|
|
1482
|
-
for (const line of raw.split('\n')) {
|
|
1483
|
-
try {
|
|
1484
|
-
const event = JSON.parse(line);
|
|
1485
|
-
this.recordPrincipleEvent({
|
|
1486
|
-
principleId: typeof event.data?.principleId === 'string' ? event.data.principleId : null,
|
|
1487
|
-
eventType: String(event.type ?? 'legacy'),
|
|
1488
|
-
payload: event.data ?? {},
|
|
1489
|
-
createdAt: event.ts,
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
|
-
catch {
|
|
1493
|
-
// Ignore malformed legacy evolution events.
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
this.markImported(key);
|
|
1497
|
-
}
|
|
1498
|
-
markImported(sourceKey) {
|
|
1499
|
-
this.withWrite(() => {
|
|
1500
|
-
this.db.prepare(`
|
|
1501
|
-
INSERT INTO ingest_checkpoint (source_key, imported_at)
|
|
1502
|
-
VALUES (?, ?)
|
|
1503
|
-
ON CONFLICT(source_key) DO UPDATE SET imported_at = excluded.imported_at
|
|
1504
|
-
`).run(sourceKey, nowIso());
|
|
1505
|
-
});
|
|
1506
|
-
}
|
|
1507
|
-
isImported(sourceKey) {
|
|
1508
|
-
const row = this.db.prepare('SELECT source_key FROM ingest_checkpoint WHERE source_key = ?').get(sourceKey);
|
|
1509
|
-
return Boolean(row);
|
|
1510
|
-
}
|
|
1511
|
-
maybeCreateCorrectionSample(sessionId) {
|
|
1512
|
-
const pending = this.db.prepare(`
|
|
1513
|
-
SELECT sample_id FROM correction_samples
|
|
1514
|
-
WHERE session_id = ? AND review_status = 'pending'
|
|
1515
|
-
ORDER BY created_at DESC
|
|
1516
|
-
LIMIT 1
|
|
1517
|
-
`).get(sessionId);
|
|
1518
|
-
if (pending?.sample_id)
|
|
1519
|
-
return;
|
|
1520
|
-
const correctionTurn = this.db.prepare(`
|
|
1521
|
-
SELECT id, references_assistant_turn_id, correction_cue, raw_text, blob_ref
|
|
1522
|
-
FROM user_turns
|
|
1523
|
-
WHERE session_id = ? AND correction_detected = 1
|
|
1524
|
-
ORDER BY id DESC
|
|
1525
|
-
LIMIT 1
|
|
1526
|
-
`).get(sessionId);
|
|
1527
|
-
if (!correctionTurn || !correctionTurn.references_assistant_turn_id)
|
|
1528
|
-
return;
|
|
1529
|
-
// #Phase2b-fix: Tool failure is NOT required for correction samples.
|
|
1530
|
-
// User corrections are the highest-fidelity signal — they indicate the agent
|
|
1531
|
-
// said or did something wrong, regardless of whether tool calls succeeded.
|
|
1532
|
-
// Requiring tool failure excluded the most valuable cases: "agent did something
|
|
1533
|
-
// that technically worked but violated a principle or was logically wrong."
|
|
1534
|
-
const failedCall = this.db.prepare(`
|
|
1535
|
-
SELECT id, tool_name, error_type, error_message
|
|
1536
|
-
FROM tool_calls
|
|
1537
|
-
WHERE session_id = ? AND outcome = 'failure'
|
|
1538
|
-
ORDER BY id DESC
|
|
1539
|
-
LIMIT 1
|
|
1540
|
-
`).get(sessionId);
|
|
1541
|
-
const recentCalls = this.db.prepare(`
|
|
1542
|
-
SELECT id, tool_name, outcome
|
|
1543
|
-
FROM tool_calls
|
|
1544
|
-
WHERE session_id = ?
|
|
1545
|
-
ORDER BY id DESC
|
|
1546
|
-
LIMIT 5
|
|
1547
|
-
`).all(sessionId);
|
|
1548
|
-
const successfulCalls = recentCalls.filter(c => c.outcome === 'success');
|
|
1549
|
-
// Generate sample ID from correction turn + first recent call (or correction id if no calls)
|
|
1550
|
-
const refForHash = successfulCalls[0]?.id ?? correctionTurn.id;
|
|
1551
|
-
const sampleId = `sample_${crypto.createHash('md5').update(`${sessionId}:${correctionTurn.id}:${refForHash}`).digest('hex').slice(0, 12)}`;
|
|
1552
|
-
const userRawText = this.restoreRawText(correctionTurn.raw_text, correctionTurn.blob_ref);
|
|
1553
|
-
// Quality scoring: correction cue is always valuable
|
|
1554
|
-
// Tool failure adds context (20pts), successful calls add context (up to 15pts)
|
|
1555
|
-
// Pure conversation corrections still score 55-75 (high enough to review)
|
|
1556
|
-
const qualityScore = [
|
|
1557
|
-
correctionTurn.references_assistant_turn_id ? 35 : 0,
|
|
1558
|
-
correctionTurn.correction_cue ? 20 : 0,
|
|
1559
|
-
failedCall ? 20 : 0,
|
|
1560
|
-
Math.min(successfulCalls.length, 3) * 5,
|
|
1561
|
-
].reduce((sum, value) => sum + value, 0);
|
|
1562
|
-
// Diff excerpt: prefer user correction text, fallback to error info, fallback to cue
|
|
1563
|
-
const diffText = userRawText
|
|
1564
|
-
|| (failedCall ? String(failedCall.error_message ?? failedCall.error_type ?? failedCall.tool_name) : '')
|
|
1565
|
-
|| String(correctionTurn.correction_cue ?? 'user correction');
|
|
1566
|
-
this.withWrite(() => {
|
|
1567
|
-
this.db.prepare(`
|
|
1568
|
-
INSERT OR IGNORE INTO correction_samples (
|
|
1569
|
-
sample_id, session_id, bad_assistant_turn_id, user_correction_turn_id,
|
|
1570
|
-
recovery_tool_span_json, diff_excerpt, principle_ids_json, quality_score,
|
|
1571
|
-
review_status, export_mode, created_at, updated_at
|
|
1572
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'pending', 'raw', ?, ?)
|
|
1573
|
-
`).run(sampleId, sessionId, Number(correctionTurn.references_assistant_turn_id), Number(correctionTurn.id), safeJson(successfulCalls.map((call) => ({ id: call.id, toolName: call.tool_name, outcome: call.outcome }))), summarizeForDiff(diffText), '[]', qualityScore, nowIso(), nowIso());
|
|
1574
|
-
});
|
|
1575
|
-
}
|
|
1576
|
-
recordExportAudit(exportKind, mode, approvedOnly, filePath, rowCount) {
|
|
1577
|
-
this.withWrite(() => {
|
|
1578
|
-
this.db.prepare(`
|
|
1579
|
-
INSERT INTO exports_audit (export_kind, mode, approved_only, file_path, row_count, created_at)
|
|
1580
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
1581
|
-
`).run(exportKind, mode, approvedOnly ? 1 : 0, filePath, rowCount, nowIso());
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
storeRawText(kind, text) {
|
|
1585
|
-
const excerpt = text.length > 200 ? `${text.slice(0, 197)}...` : text;
|
|
1586
|
-
const bytes = Buffer.byteLength(text, 'utf8');
|
|
1587
|
-
if (bytes <= this.blobInlineThresholdBytes) {
|
|
1588
|
-
return { inlineText: text, blobRef: null, excerpt };
|
|
1589
|
-
}
|
|
1590
|
-
const hash = crypto.createHash('sha256').update(text).digest('hex');
|
|
1591
|
-
const relativePath = `${kind}-${hash}.txt`;
|
|
1592
|
-
const fullPath = path.join(this.blobDir, relativePath);
|
|
1593
|
-
if (!fs.existsSync(fullPath)) {
|
|
1594
|
-
atomicWriteFileSync(fullPath, text);
|
|
1595
|
-
}
|
|
1596
|
-
return { inlineText: null, blobRef: relativePath, excerpt };
|
|
1597
|
-
}
|
|
1598
|
-
restoreRawText(inlineText, blobRef) {
|
|
1599
|
-
if (inlineText)
|
|
1600
|
-
return inlineText;
|
|
1601
|
-
if (!blobRef)
|
|
1602
|
-
return '';
|
|
1603
|
-
const fullPath = path.join(this.blobDir, blobRef);
|
|
1604
|
-
return fs.existsSync(fullPath) ? fs.readFileSync(fullPath, 'utf8') : '';
|
|
1605
|
-
}
|
|
1606
|
-
computeBlobBytes() {
|
|
1607
|
-
if (!fs.existsSync(this.blobDir))
|
|
1608
|
-
return 0;
|
|
1609
|
-
return fs.readdirSync(this.blobDir).reduce((sum, file) => sum + fileSizeIfExists(path.join(this.blobDir, file)), 0);
|
|
1610
|
-
}
|
|
1611
|
-
pruneUnreferencedBlobs() {
|
|
1612
|
-
if (!fs.existsSync(this.blobDir)) {
|
|
1613
|
-
return { removedFiles: 0, reclaimedBytes: 0 };
|
|
1614
|
-
}
|
|
1615
|
-
const referenced = new Set();
|
|
1616
|
-
const rows = this.db.prepare(`
|
|
1617
|
-
SELECT blob_ref FROM assistant_turns WHERE blob_ref IS NOT NULL
|
|
1618
|
-
UNION
|
|
1619
|
-
SELECT blob_ref FROM user_turns WHERE blob_ref IS NOT NULL
|
|
1620
|
-
`).all();
|
|
1621
|
-
for (const row of rows) {
|
|
1622
|
-
if (row.blob_ref)
|
|
1623
|
-
referenced.add(String(row.blob_ref));
|
|
1624
|
-
}
|
|
1625
|
-
const now = Date.now();
|
|
1626
|
-
let removedFiles = 0;
|
|
1627
|
-
let reclaimedBytes = 0;
|
|
1628
|
-
for (const entry of fs.readdirSync(this.blobDir)) {
|
|
1629
|
-
if (referenced.has(entry))
|
|
1630
|
-
continue;
|
|
1631
|
-
const fullPath = path.join(this.blobDir, entry);
|
|
1632
|
-
let stat;
|
|
1633
|
-
try {
|
|
1634
|
-
stat = fs.statSync(fullPath);
|
|
1635
|
-
}
|
|
1636
|
-
catch {
|
|
1637
|
-
continue;
|
|
1638
|
-
}
|
|
1639
|
-
if (!stat.isFile())
|
|
1640
|
-
continue;
|
|
1641
|
-
if (this.orphanBlobGraceMs > 0 && now - stat.mtimeMs < this.orphanBlobGraceMs)
|
|
1642
|
-
continue;
|
|
1643
|
-
reclaimedBytes += stat.size;
|
|
1644
|
-
removedFiles += 1;
|
|
1645
|
-
fs.rmSync(fullPath, { force: true });
|
|
1646
|
-
}
|
|
1647
|
-
return { removedFiles, reclaimedBytes };
|
|
1648
|
-
}
|
|
1649
|
-
withWrite(fn) {
|
|
1650
|
-
return withLock(this.dbPath, fn, { lockSuffix: '.trajectory.lock', lockStaleMs: 30000 });
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
export class TrajectoryRegistry {
|
|
1654
|
-
static instances = new Map();
|
|
1655
|
-
static get(workspaceDir, opts = {}) {
|
|
1656
|
-
const normalized = path.resolve(workspaceDir);
|
|
1657
|
-
const existing = this.instances.get(normalized);
|
|
1658
|
-
if (existing)
|
|
1659
|
-
return existing;
|
|
1660
|
-
const created = new TrajectoryDatabase({ workspaceDir: normalized, ...opts });
|
|
1661
|
-
this.instances.set(normalized, created);
|
|
1662
|
-
return created;
|
|
1663
|
-
}
|
|
1664
|
-
static dispose(workspaceDir) {
|
|
1665
|
-
const normalized = path.resolve(workspaceDir);
|
|
1666
|
-
const instance = this.instances.get(normalized);
|
|
1667
|
-
if (instance) {
|
|
1668
|
-
instance.dispose();
|
|
1669
|
-
this.instances.delete(normalized);
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
static clear() {
|
|
1673
|
-
for (const instance of this.instances.values()) {
|
|
1674
|
-
instance.dispose();
|
|
1675
|
-
}
|
|
1676
|
-
this.instances.clear();
|
|
1677
|
-
}
|
|
1678
|
-
static use(workspaceDir, fn, opts = {}) {
|
|
1679
|
-
const normalized = path.resolve(workspaceDir);
|
|
1680
|
-
const existing = this.instances.get(normalized);
|
|
1681
|
-
if (existing) {
|
|
1682
|
-
return fn(existing);
|
|
1683
|
-
}
|
|
1684
|
-
const transient = new TrajectoryDatabase({ workspaceDir: normalized, ...opts });
|
|
1685
|
-
try {
|
|
1686
|
-
return fn(transient);
|
|
1687
|
-
}
|
|
1688
|
-
finally {
|
|
1689
|
-
transient.dispose();
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
}
|