principles-disciple 1.8.1 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADVANCED_CONFIG_ZH.md +97 -0
- package/AGENT_INSTALL.md +173 -0
- package/AGENT_INSTALL_EN.md +173 -0
- package/INSTALL.md +256 -0
- package/SKILL.md +63 -0
- package/docs/COMMAND_REFERENCE.md +76 -0
- package/docs/COMMAND_REFERENCE_EN.md +79 -0
- package/esbuild.config.js +75 -0
- package/openclaw.plugin.json +4 -4
- package/package.json +11 -13
- package/scripts/build-web.mjs +46 -0
- package/scripts/install-dependencies.cjs +47 -0
- package/scripts/sync-plugin.mjs +802 -0
- package/scripts/verify-build.mjs +109 -0
- package/src/agents/nocturnal-dreamer.md +152 -0
- package/src/agents/nocturnal-philosopher.md +138 -0
- package/src/agents/nocturnal-reflector.md +126 -0
- package/src/agents/nocturnal-scribe.md +164 -0
- package/src/commands/capabilities.ts +85 -0
- package/{dist/commands/context.js → src/commands/context.ts} +78 -38
- package/src/commands/evolution-status.ts +146 -0
- package/src/commands/export.ts +111 -0
- package/src/commands/focus.ts +533 -0
- package/src/commands/nocturnal-review.ts +311 -0
- package/src/commands/nocturnal-rollout.ts +763 -0
- package/src/commands/nocturnal-train.ts +1002 -0
- package/{dist/commands/pain.js → src/commands/pain.ts} +68 -49
- package/src/commands/principle-rollback.ts +27 -0
- package/{dist/commands/rollback.js → src/commands/rollback.ts} +44 -12
- package/src/commands/samples.ts +60 -0
- package/src/commands/strategy.ts +38 -0
- package/{dist/commands/thinking-os.js → src/commands/thinking-os.ts} +59 -36
- package/src/commands/workflow-debug.ts +128 -0
- package/{dist/config/defaults/runtime.js → src/config/defaults/runtime.ts} +12 -5
- package/src/config/errors.ts +163 -0
- package/{dist/config/index.d.ts → src/config/index.ts} +2 -1
- package/src/constants/diagnostician.ts +66 -0
- package/src/constants/tools.ts +62 -0
- package/src/core/adaptive-thresholds.ts +476 -0
- package/{dist/core/config-service.js → src/core/config-service.ts} +7 -4
- package/{dist/core/config.js → src/core/config.ts} +158 -46
- package/src/core/control-ui-db.ts +435 -0
- package/{dist/core/detection-funnel.js → src/core/detection-funnel.ts} +36 -21
- package/{dist/core/detection-service.js → src/core/detection-service.ts} +7 -4
- package/{dist/core/dictionary-service.js → src/core/dictionary-service.ts} +7 -4
- package/{dist/core/dictionary.js → src/core/dictionary.ts} +57 -34
- package/src/core/empathy-keyword-matcher.ts +327 -0
- package/src/core/empathy-types.ts +218 -0
- package/src/core/event-log.ts +544 -0
- package/src/core/evolution-engine.ts +612 -0
- package/src/core/evolution-logger.ts +353 -0
- package/src/core/evolution-migration.ts +77 -0
- package/src/core/evolution-reducer.ts +731 -0
- package/src/core/evolution-types.ts +456 -0
- package/src/core/external-training-contract.ts +527 -0
- package/src/core/focus-history.ts +1458 -0
- package/src/core/hygiene/tracker.ts +117 -0
- package/{dist/core/init.js → src/core/init.ts} +39 -26
- package/src/core/local-worker-routing.ts +617 -0
- package/{dist/core/migration.js → src/core/migration.ts} +18 -11
- package/src/core/model-deployment-registry.ts +722 -0
- package/src/core/model-training-registry.ts +813 -0
- package/src/core/nocturnal-arbiter.ts +706 -0
- package/src/core/nocturnal-candidate-scoring.ts +392 -0
- package/src/core/nocturnal-compliance.ts +1075 -0
- package/src/core/nocturnal-dataset.ts +668 -0
- package/src/core/nocturnal-executability.ts +428 -0
- package/src/core/nocturnal-export.ts +390 -0
- package/{dist/core/nocturnal-paths.js → src/core/nocturnal-paths.ts} +49 -23
- package/src/core/nocturnal-trajectory-extractor.ts +484 -0
- package/src/core/nocturnal-trinity.ts +1384 -0
- package/src/core/pain.ts +122 -0
- package/{dist/core/path-resolver.js → src/core/path-resolver.ts} +157 -36
- package/{dist/core/paths.js → src/core/paths.ts} +13 -4
- package/src/core/principle-training-state.ts +450 -0
- package/src/core/profile.ts +226 -0
- package/src/core/promotion-gate.ts +822 -0
- package/{dist/core/risk-calculator.js → src/core/risk-calculator.ts} +42 -16
- package/{dist/core/session-tracker.js → src/core/session-tracker.ts} +175 -62
- package/src/core/shadow-observation-registry.ts +534 -0
- package/{dist/core/system-logger.js → src/core/system-logger.ts} +9 -5
- package/src/core/thinking-models.ts +217 -0
- package/src/core/training-program.ts +630 -0
- package/src/core/trajectory-types.ts +243 -0
- package/src/core/trajectory.ts +1673 -0
- package/{dist/core/workspace-context.js → src/core/workspace-context.ts} +57 -32
- package/src/hooks/bash-risk.ts +171 -0
- package/src/hooks/edit-verification.ts +295 -0
- package/src/hooks/gate-block-helper.ts +160 -0
- package/src/hooks/gate.ts +210 -0
- package/src/hooks/gfi-gate.ts +177 -0
- package/src/hooks/lifecycle.ts +326 -0
- package/{dist/hooks/llm.js → src/hooks/llm.ts} +160 -80
- package/src/hooks/message-sanitize.ts +45 -0
- package/src/hooks/pain.ts +384 -0
- package/src/hooks/progressive-trust-gate.ts +174 -0
- package/src/hooks/prompt.ts +920 -0
- package/src/hooks/subagent.ts +207 -0
- package/src/hooks/thinking-checkpoint.ts +73 -0
- package/src/hooks/trajectory-collector.ts +290 -0
- package/src/http/principles-console-route.ts +716 -0
- package/src/i18n/commands.ts +117 -0
- package/src/index.ts +694 -0
- package/src/service/central-database.ts +831 -0
- package/src/service/control-ui-query-service.ts +888 -0
- package/src/service/evolution-query-service.ts +405 -0
- package/src/service/evolution-worker.ts +1646 -0
- package/src/service/health-query-service.ts +836 -0
- package/{dist/service/nocturnal-runtime.js → src/service/nocturnal-runtime.ts} +235 -79
- package/src/service/nocturnal-service.ts +1015 -0
- package/src/service/nocturnal-target-selector.ts +532 -0
- package/src/service/phase3-input-filter.ts +237 -0
- package/src/service/runtime-summary-service.ts +757 -0
- package/src/service/subagent-workflow/deep-reflect-workflow-manager.ts +513 -0
- package/{dist/service/subagent-workflow/empathy-observer-workflow-manager.js → src/service/subagent-workflow/empathy-observer-workflow-manager.ts} +240 -117
- package/src/service/subagent-workflow/index.ts +51 -0
- package/src/service/subagent-workflow/nocturnal-workflow-manager.ts +856 -0
- package/src/service/subagent-workflow/runtime-direct-driver.ts +166 -0
- package/{dist/service/subagent-workflow/types.d.ts → src/service/subagent-workflow/types.ts} +137 -18
- package/src/service/subagent-workflow/workflow-store.ts +328 -0
- package/src/service/trajectory-service.ts +15 -0
- package/{dist/tools/critique-prompt.js → src/tools/critique-prompt.ts} +25 -8
- package/src/tools/deep-reflect.ts +349 -0
- package/{dist/tools/model-index.js → src/tools/model-index.ts} +33 -17
- package/src/types/event-types.ts +453 -0
- package/src/types/hygiene-types.ts +31 -0
- package/src/types/principle-tree-schema.ts +244 -0
- package/src/types/runtime-summary.ts +49 -0
- package/src/types.ts +74 -0
- package/src/utils/file-lock.ts +391 -0
- package/{dist/utils/glob-match.js → src/utils/glob-match.ts} +21 -20
- package/{dist/utils/hashing.js → src/utils/hashing.ts} +6 -4
- package/src/utils/io.ts +110 -0
- package/{dist/utils/nlp.js → src/utils/nlp.ts} +19 -12
- package/{dist/utils/plugin-logger.js → src/utils/plugin-logger.ts} +33 -8
- package/src/utils/subagent-probe.ts +94 -0
- package/templates/langs/zh/skills/pd-diagnostician/SKILL.md +70 -1
- package/templates/pain_settings.json +2 -1
- package/tests/README.md +120 -0
- package/tests/build-artifacts.test.ts +111 -0
- package/tests/commands/evolution-status.test.ts +222 -0
- package/tests/commands/evolver.test.ts +22 -0
- package/tests/commands/export.test.ts +78 -0
- package/tests/commands/nocturnal-review.test.ts +448 -0
- package/tests/commands/nocturnal-train.test.ts +97 -0
- package/tests/commands/pain.test.ts +108 -0
- package/tests/commands/samples.test.ts +65 -0
- package/tests/commands/strategy.test.ts +34 -0
- package/tests/commands/thinking-os.test.ts +88 -0
- package/tests/core/adaptive-thresholds.test.ts +261 -0
- package/tests/core/config-service.test.ts +89 -0
- package/tests/core/config.test.ts +90 -0
- package/tests/core/control-ui-db.test.ts +75 -0
- package/tests/core/core-template-guidance.test.ts +21 -0
- package/tests/core/detection-funnel.test.ts +63 -0
- package/tests/core/detection-service.test.ts +50 -0
- package/tests/core/dictionary-service.test.ts +116 -0
- package/tests/core/dictionary.test.ts +168 -0
- package/tests/core/empathy-keyword-matcher.test.ts +209 -0
- package/tests/core/event-log.test.ts +181 -0
- package/tests/core/evolution-e2e.test.ts +58 -0
- package/tests/core/evolution-engine-gate-integration.test.ts +543 -0
- package/tests/core/evolution-engine.test.ts +562 -0
- package/tests/core/evolution-logger.test.ts +148 -0
- package/tests/core/evolution-migration.test.ts +50 -0
- package/tests/core/evolution-paths.test.ts +21 -0
- package/tests/core/evolution-reducer.detector-metadata.test.ts +602 -0
- package/tests/core/evolution-reducer.test.ts +180 -0
- package/tests/core/evolution-types-loop.test.ts +48 -0
- package/tests/core/evolution-user-stories.e2e.test.ts +249 -0
- package/tests/core/external-training-contract.test.ts +463 -0
- package/tests/core/focus-history.test.ts +682 -0
- package/tests/core/init-flatten.test.ts +69 -0
- package/tests/core/init-refactor.test.ts +87 -0
- package/tests/core/init-v1.3.test.ts +46 -0
- package/tests/core/init.test.ts +190 -0
- package/tests/core/local-worker-routing.test.ts +757 -0
- package/tests/core/migration.test.ts +84 -0
- package/tests/core/model-deployment-registry.test.ts +845 -0
- package/tests/core/model-training-registry.test.ts +889 -0
- package/tests/core/nocturnal-arbiter.test.ts +494 -0
- package/tests/core/nocturnal-candidate-scoring.test.ts +400 -0
- package/tests/core/nocturnal-compliance.test.ts +646 -0
- package/tests/core/nocturnal-dataset.test.ts +892 -0
- package/tests/core/nocturnal-executability.test.ts +357 -0
- package/tests/core/nocturnal-export.test.ts +462 -0
- package/tests/core/nocturnal-reviewed-subset-comparison.test.ts +428 -0
- package/tests/core/nocturnal-trajectory-extractor.test.ts +634 -0
- package/tests/core/nocturnal-trinity.test.ts +953 -0
- package/tests/core/pain.test.ts +33 -0
- package/tests/core/path-resolver.test.ts +57 -0
- package/tests/core/paths-refactor.test.ts +42 -0
- package/tests/core/phase7-rollout-integration.test.ts +477 -0
- package/tests/core/principle-training-state.test.ts +712 -0
- package/tests/core/profile.test.ts +56 -0
- package/tests/core/promotion-gate.test.ts +556 -0
- package/tests/core/risk-calculator.test.ts +168 -0
- package/tests/core/session-tracker.test.ts +191 -0
- package/tests/core/training-program.test.ts +472 -0
- package/tests/core/trajectory.test.ts +265 -0
- package/tests/core/workspace-context-factory.test.ts +18 -0
- package/tests/core/workspace-context.test.ts +134 -0
- package/tests/fixtures/nocturnal-reviewed-subset.json +183 -0
- package/tests/fixtures/production-compatibility.test.ts +147 -0
- package/tests/fixtures/production-mock-generator.ts +282 -0
- package/tests/hooks/bash-risk-integration.test.ts +137 -0
- package/tests/hooks/bash-risk.test.ts +81 -0
- package/tests/hooks/edit-verification.test.ts +678 -0
- package/tests/hooks/gate-edit-verification-p1.test.ts +632 -0
- package/tests/hooks/gate-edit-verification.test.ts +435 -0
- package/tests/hooks/gate-pipeline-integration.test.ts +404 -0
- package/tests/hooks/gate.test.ts +271 -0
- package/tests/hooks/gfi-gate-unit.test.ts +422 -0
- package/tests/hooks/gfi-gate.test.ts +669 -0
- package/tests/hooks/lifecycle.test.ts +248 -0
- package/tests/hooks/llm.test.ts +308 -0
- package/tests/hooks/message-sanitize.test.ts +36 -0
- package/tests/hooks/pain.test.ts +141 -0
- package/tests/hooks/progressive-trust-gate.test.ts +277 -0
- package/tests/hooks/prompt.test.ts +1411 -0
- package/tests/hooks/subagent.test.ts +467 -0
- package/tests/hooks/thinking-gate.test.ts +313 -0
- package/tests/http/principles-console-route.test.ts +140 -0
- package/tests/hygiene-tracker.test.ts +77 -0
- package/tests/index.integration.test.ts +179 -0
- package/tests/index.shadow-routing.integration.test.ts +140 -0
- package/tests/index.test.ts +9 -0
- package/tests/integration/empathy-workflow-integration.test.ts +627 -0
- package/tests/service/control-ui-query-service.test.ts +121 -0
- package/tests/service/empathy-observer-workflow-manager.test.ts +176 -0
- package/tests/service/evolution-worker.test.ts +585 -0
- package/tests/service/nocturnal-runtime.test.ts +470 -0
- package/tests/service/nocturnal-service.test.ts +577 -0
- package/tests/service/nocturnal-target-selector.test.ts +615 -0
- package/tests/service/nocturnal-workflow-manager.test.ts +439 -0
- package/tests/service/phase3-input-filter.test.ts +289 -0
- package/tests/service/runtime-summary-service.test.ts +919 -0
- package/tests/task-compliance.test.ts +166 -0
- package/tests/test-utils.ts +48 -0
- package/tests/tools/critique-prompt.test.ts +260 -0
- package/tests/tools/deep-reflect.test.ts +232 -0
- package/tests/tools/model-index.test.ts +246 -0
- package/tests/ui/app.test.tsx +114 -0
- package/tests/utils/file-lock.test.ts +407 -0
- package/tests/utils/hashing.test.ts +32 -0
- package/tests/utils/io.test.ts +39 -0
- package/tests/utils/nlp.test.ts +53 -0
- package/tests/utils/plugin-logger.test.ts +156 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/ui/src/App.tsx +45 -0
- package/ui/src/api.ts +216 -0
- package/ui/src/charts.tsx +586 -0
- package/ui/src/components/ErrorState.tsx +6 -0
- package/ui/src/components/Loading.tsx +13 -0
- package/ui/src/components/ProtectedRoute.tsx +12 -0
- package/ui/src/components/Shell.tsx +91 -0
- package/ui/src/components/WorkspaceConfig.tsx +146 -0
- package/ui/src/components/index.ts +5 -0
- package/ui/src/context/auth.tsx +80 -0
- package/ui/src/context/theme.tsx +66 -0
- package/ui/src/hooks/useAutoRefresh.ts +39 -0
- package/ui/src/i18n/ui.ts +363 -0
- package/ui/src/main.tsx +16 -0
- package/ui/src/pages/EvolutionPage.tsx +352 -0
- package/ui/src/pages/FeedbackPage.tsx +140 -0
- package/ui/src/pages/GateMonitorPage.tsx +136 -0
- package/ui/src/pages/LoginPage.tsx +88 -0
- package/ui/src/pages/OverviewPage.tsx +238 -0
- package/ui/src/pages/SamplesPage.tsx +174 -0
- package/ui/src/pages/ThinkingModelsPage.tsx +127 -0
- package/ui/src/styles.css +1661 -0
- package/ui/src/types.ts +368 -0
- package/ui/src/utils/format.ts +15 -0
- package/vitest.config.ts +23 -0
- package/dist/commands/capabilities.d.ts +0 -3
- package/dist/commands/capabilities.js +0 -73
- package/dist/commands/context.d.ts +0 -5
- package/dist/commands/evolution-status.d.ts +0 -4
- package/dist/commands/evolution-status.js +0 -117
- package/dist/commands/evolver.d.ts +0 -9
- package/dist/commands/evolver.js +0 -26
- package/dist/commands/export.d.ts +0 -2
- package/dist/commands/export.js +0 -98
- package/dist/commands/focus.d.ts +0 -14
- package/dist/commands/focus.js +0 -457
- package/dist/commands/nocturnal-review.d.ts +0 -24
- package/dist/commands/nocturnal-review.js +0 -265
- package/dist/commands/nocturnal-rollout.d.ts +0 -27
- package/dist/commands/nocturnal-rollout.js +0 -671
- package/dist/commands/nocturnal-train.d.ts +0 -25
- package/dist/commands/nocturnal-train.js +0 -919
- package/dist/commands/pain.d.ts +0 -5
- package/dist/commands/principle-rollback.d.ts +0 -4
- package/dist/commands/principle-rollback.js +0 -22
- package/dist/commands/rollback.d.ts +0 -19
- package/dist/commands/samples.d.ts +0 -2
- package/dist/commands/samples.js +0 -55
- package/dist/commands/strategy.d.ts +0 -3
- package/dist/commands/strategy.js +0 -29
- package/dist/commands/thinking-os.d.ts +0 -2
- package/dist/config/defaults/runtime.d.ts +0 -40
- package/dist/config/errors.d.ts +0 -84
- package/dist/config/errors.js +0 -94
- package/dist/config/index.js +0 -7
- package/dist/constants/diagnostician.d.ts +0 -12
- package/dist/constants/diagnostician.js +0 -56
- package/dist/constants/tools.d.ts +0 -17
- package/dist/constants/tools.js +0 -54
- package/dist/core/adaptive-thresholds.d.ts +0 -186
- package/dist/core/adaptive-thresholds.js +0 -300
- package/dist/core/config-service.d.ts +0 -15
- package/dist/core/config.d.ts +0 -129
- package/dist/core/control-ui-db.d.ts +0 -95
- package/dist/core/control-ui-db.js +0 -292
- package/dist/core/detection-funnel.d.ts +0 -33
- package/dist/core/detection-service.d.ts +0 -15
- package/dist/core/dictionary-service.d.ts +0 -15
- package/dist/core/dictionary.d.ts +0 -38
- package/dist/core/event-log.d.ts +0 -82
- package/dist/core/event-log.js +0 -463
- package/dist/core/evolution-engine.d.ts +0 -118
- package/dist/core/evolution-engine.js +0 -464
- package/dist/core/evolution-logger.d.ts +0 -137
- package/dist/core/evolution-logger.js +0 -256
- package/dist/core/evolution-migration.d.ts +0 -5
- package/dist/core/evolution-migration.js +0 -65
- package/dist/core/evolution-reducer.d.ts +0 -98
- package/dist/core/evolution-reducer.js +0 -465
- package/dist/core/evolution-types.d.ts +0 -287
- package/dist/core/evolution-types.js +0 -78
- package/dist/core/external-training-contract.d.ts +0 -276
- package/dist/core/external-training-contract.js +0 -269
- package/dist/core/focus-history.d.ts +0 -210
- package/dist/core/focus-history.js +0 -1185
- package/dist/core/hygiene/tracker.d.ts +0 -22
- package/dist/core/hygiene/tracker.js +0 -106
- package/dist/core/init.d.ts +0 -12
- package/dist/core/local-worker-routing.d.ts +0 -175
- package/dist/core/local-worker-routing.js +0 -525
- package/dist/core/migration.d.ts +0 -6
- package/dist/core/model-deployment-registry.d.ts +0 -218
- package/dist/core/model-deployment-registry.js +0 -503
- package/dist/core/model-training-registry.d.ts +0 -295
- package/dist/core/model-training-registry.js +0 -475
- package/dist/core/nocturnal-arbiter.d.ts +0 -159
- package/dist/core/nocturnal-arbiter.js +0 -534
- package/dist/core/nocturnal-candidate-scoring.d.ts +0 -137
- package/dist/core/nocturnal-candidate-scoring.js +0 -266
- package/dist/core/nocturnal-compliance.d.ts +0 -175
- package/dist/core/nocturnal-compliance.js +0 -824
- package/dist/core/nocturnal-dataset.d.ts +0 -224
- package/dist/core/nocturnal-dataset.js +0 -443
- package/dist/core/nocturnal-executability.d.ts +0 -85
- package/dist/core/nocturnal-executability.js +0 -331
- package/dist/core/nocturnal-export.d.ts +0 -124
- package/dist/core/nocturnal-export.js +0 -275
- package/dist/core/nocturnal-paths.d.ts +0 -124
- package/dist/core/nocturnal-trajectory-extractor.d.ts +0 -242
- package/dist/core/nocturnal-trajectory-extractor.js +0 -307
- package/dist/core/nocturnal-trinity.d.ts +0 -311
- package/dist/core/nocturnal-trinity.js +0 -880
- package/dist/core/pain.d.ts +0 -4
- package/dist/core/pain.js +0 -70
- package/dist/core/path-resolver.d.ts +0 -46
- package/dist/core/paths.d.ts +0 -65
- package/dist/core/principle-training-state.d.ts +0 -121
- package/dist/core/principle-training-state.js +0 -321
- package/dist/core/profile.d.ts +0 -62
- package/dist/core/profile.js +0 -210
- package/dist/core/promotion-gate.d.ts +0 -238
- package/dist/core/promotion-gate.js +0 -529
- package/dist/core/risk-calculator.d.ts +0 -22
- package/dist/core/session-tracker.d.ts +0 -101
- package/dist/core/shadow-observation-registry.d.ts +0 -217
- package/dist/core/shadow-observation-registry.js +0 -308
- package/dist/core/system-logger.d.ts +0 -8
- package/dist/core/thinking-models.d.ts +0 -38
- package/dist/core/thinking-models.js +0 -170
- package/dist/core/training-program.d.ts +0 -233
- package/dist/core/training-program.js +0 -433
- package/dist/core/trajectory.d.ts +0 -411
- package/dist/core/trajectory.js +0 -1307
- package/dist/core/workspace-context.d.ts +0 -71
- package/dist/hooks/bash-risk.d.ts +0 -57
- package/dist/hooks/bash-risk.js +0 -137
- package/dist/hooks/edit-verification.d.ts +0 -62
- package/dist/hooks/edit-verification.js +0 -256
- package/dist/hooks/gate-block-helper.d.ts +0 -44
- package/dist/hooks/gate-block-helper.js +0 -119
- package/dist/hooks/gate.d.ts +0 -24
- package/dist/hooks/gate.js +0 -173
- package/dist/hooks/gfi-gate.d.ts +0 -40
- package/dist/hooks/gfi-gate.js +0 -113
- package/dist/hooks/lifecycle.d.ts +0 -5
- package/dist/hooks/lifecycle.js +0 -284
- package/dist/hooks/llm.d.ts +0 -13
- package/dist/hooks/message-sanitize.d.ts +0 -3
- package/dist/hooks/message-sanitize.js +0 -37
- package/dist/hooks/pain.d.ts +0 -5
- package/dist/hooks/pain.js +0 -301
- package/dist/hooks/progressive-trust-gate.d.ts +0 -52
- package/dist/hooks/progressive-trust-gate.js +0 -134
- package/dist/hooks/prompt.d.ts +0 -49
- package/dist/hooks/prompt.js +0 -905
- package/dist/hooks/subagent.d.ts +0 -10
- package/dist/hooks/subagent.js +0 -387
- package/dist/hooks/thinking-checkpoint.d.ts +0 -37
- package/dist/hooks/thinking-checkpoint.js +0 -51
- package/dist/hooks/trajectory-collector.d.ts +0 -32
- package/dist/hooks/trajectory-collector.js +0 -256
- package/dist/http/principles-console-route.d.ts +0 -9
- package/dist/http/principles-console-route.js +0 -681
- package/dist/i18n/commands.d.ts +0 -26
- package/dist/i18n/commands.js +0 -116
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -581
- package/dist/service/central-database.d.ts +0 -104
- package/dist/service/central-database.js +0 -649
- package/dist/service/control-ui-query-service.d.ts +0 -221
- package/dist/service/control-ui-query-service.js +0 -543
- package/dist/service/empathy-observer-manager.d.ts +0 -88
- package/dist/service/empathy-observer-manager.js +0 -414
- package/dist/service/evolution-query-service.d.ts +0 -155
- package/dist/service/evolution-query-service.js +0 -258
- package/dist/service/evolution-worker.d.ts +0 -101
- package/dist/service/evolution-worker.js +0 -975
- package/dist/service/health-query-service.d.ts +0 -170
- package/dist/service/health-query-service.js +0 -662
- package/dist/service/nocturnal-runtime.d.ts +0 -183
- package/dist/service/nocturnal-service.d.ts +0 -163
- package/dist/service/nocturnal-service.js +0 -787
- package/dist/service/nocturnal-target-selector.d.ts +0 -145
- package/dist/service/nocturnal-target-selector.js +0 -315
- package/dist/service/phase3-input-filter.d.ts +0 -73
- package/dist/service/phase3-input-filter.js +0 -172
- package/dist/service/runtime-summary-service.d.ts +0 -122
- package/dist/service/runtime-summary-service.js +0 -485
- package/dist/service/subagent-workflow/empathy-observer-workflow-manager.d.ts +0 -48
- package/dist/service/subagent-workflow/index.d.ts +0 -4
- package/dist/service/subagent-workflow/index.js +0 -3
- package/dist/service/subagent-workflow/runtime-direct-driver.d.ts +0 -77
- package/dist/service/subagent-workflow/runtime-direct-driver.js +0 -75
- package/dist/service/subagent-workflow/types.js +0 -11
- package/dist/service/subagent-workflow/workflow-store.d.ts +0 -26
- package/dist/service/subagent-workflow/workflow-store.js +0 -165
- package/dist/service/trajectory-service.d.ts +0 -2
- package/dist/service/trajectory-service.js +0 -15
- package/dist/tools/critique-prompt.d.ts +0 -14
- package/dist/tools/deep-reflect.d.ts +0 -39
- package/dist/tools/deep-reflect.js +0 -350
- package/dist/tools/model-index.d.ts +0 -9
- package/dist/types/event-types.d.ts +0 -306
- package/dist/types/event-types.js +0 -106
- package/dist/types/hygiene-types.d.ts +0 -20
- package/dist/types/hygiene-types.js +0 -12
- package/dist/types/runtime-summary.d.ts +0 -47
- package/dist/types/runtime-summary.js +0 -1
- package/dist/types.d.ts +0 -50
- package/dist/types.js +0 -22
- package/dist/utils/file-lock.d.ts +0 -71
- package/dist/utils/file-lock.js +0 -309
- package/dist/utils/glob-match.d.ts +0 -28
- package/dist/utils/hashing.d.ts +0 -9
- package/dist/utils/io.d.ts +0 -6
- package/dist/utils/io.js +0 -106
- package/dist/utils/nlp.d.ts +0 -9
- package/dist/utils/plugin-logger.d.ts +0 -39
- package/dist/utils/subagent-probe.d.ts +0 -34
- package/dist/utils/subagent-probe.js +0 -81
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { readPainFlagData } from '../core/pain.js';
|
|
4
|
-
import { listSessions } from '../core/session-tracker.js';
|
|
5
|
-
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
6
|
-
import { evaluatePhase3Inputs } from './phase3-input-filter.js';
|
|
7
|
-
import { TrajectoryRegistry } from '../core/trajectory.js';
|
|
8
|
-
const MAX_SOURCE_EVENTS = 5;
|
|
9
|
-
const GFI_PARTIAL_WARNING = 'GFI source attribution remains partial in Phase 2b because only the empathy slice is source-attributed; most non-empathy friction still lacks full per-source attribution.';
|
|
10
|
-
const DAILY_GFI_WARNING = 'daily-stats.gfi is not authoritative in Phase 1 and is used only as a fallback reference.';
|
|
11
|
-
const EVENT_BUFFER_WARNING = 'Live event buffer is unavailable in this context, so status may lag until events.jsonl flushes.';
|
|
12
|
-
function pushWarning(warnings, message) {
|
|
13
|
-
if (!warnings.includes(message)) {
|
|
14
|
-
warnings.push(message);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export class RuntimeSummaryService {
|
|
18
|
-
static getSummary(workspaceDir, options) {
|
|
19
|
-
const generatedAt = new Date().toISOString();
|
|
20
|
-
const warnings = [];
|
|
21
|
-
const wctx = WorkspaceContext.fromHookContext({ workspaceDir });
|
|
22
|
-
const sessions = this.mergeSessionSnapshots(this.readSessions(wctx.resolve('SESSION_DIR'), warnings), workspaceDir);
|
|
23
|
-
const selectedSession = this.selectSession(sessions, options?.sessionId ?? null);
|
|
24
|
-
const selectedSessionId = selectedSession.session?.sessionId ?? null;
|
|
25
|
-
const persistedEvents = this.readEvents(path.join(wctx.stateDir, 'logs', 'events.jsonl'), warnings);
|
|
26
|
-
const hasBufferedEventAccess = typeof wctx.eventLog.getBufferedEvents === 'function';
|
|
27
|
-
const bufferedEvents = hasBufferedEventAccess
|
|
28
|
-
? wctx.eventLog.getBufferedEvents()
|
|
29
|
-
: [];
|
|
30
|
-
const events = this.mergeEvents(persistedEvents, bufferedEvents);
|
|
31
|
-
const dailyStats = this.readJsonFile(path.join(wctx.stateDir, 'logs', 'daily-stats.json'), warnings, false);
|
|
32
|
-
// Get most recent date from daily stats, fallback to today
|
|
33
|
-
const today = generatedAt.slice(0, 10);
|
|
34
|
-
const availableDates = Object.keys(dailyStats || {}).sort().reverse();
|
|
35
|
-
const statsDate = availableDates.length > 0 ? availableDates[0] : today;
|
|
36
|
-
const dailyGfiPeak = dailyStats?.[statsDate]?.gfi?.peak;
|
|
37
|
-
const gfiCurrent = selectedSession.session && Number.isFinite(selectedSession.session.currentGfi)
|
|
38
|
-
? Number(selectedSession.session.currentGfi)
|
|
39
|
-
: null;
|
|
40
|
-
const sessionPeak = selectedSession.session && Number.isFinite(selectedSession.session.dailyGfiPeak)
|
|
41
|
-
? Number(selectedSession.session.dailyGfiPeak)
|
|
42
|
-
: null;
|
|
43
|
-
const gfiPeak = sessionPeak ?? (Number.isFinite(dailyGfiPeak) ? Number(dailyGfiPeak) : null);
|
|
44
|
-
pushWarning(warnings, GFI_PARTIAL_WARNING);
|
|
45
|
-
if (sessionPeak === null && Number.isFinite(dailyGfiPeak)) {
|
|
46
|
-
pushWarning(warnings, DAILY_GFI_WARNING);
|
|
47
|
-
}
|
|
48
|
-
if (!hasBufferedEventAccess) {
|
|
49
|
-
pushWarning(warnings, EVENT_BUFFER_WARNING);
|
|
50
|
-
}
|
|
51
|
-
if (!selectedSession.session) {
|
|
52
|
-
pushWarning(warnings, 'No persisted session state was found; current session GFI is unavailable.');
|
|
53
|
-
}
|
|
54
|
-
const queue = this.readJsonFile(wctx.resolve('EVOLUTION_QUEUE'), warnings, false);
|
|
55
|
-
// compatibility-only display artifact - not a truth source for Phase 3 eligibility
|
|
56
|
-
// queue is the only authoritative execution truth source for Phase 3
|
|
57
|
-
const directive = this.readJsonFile(wctx.resolve('EVOLUTION_DIRECTIVE'), warnings, false);
|
|
58
|
-
const queueStats = this.buildQueueStats(queue);
|
|
59
|
-
const directiveSummary = this.buildDirectiveSummary(queue, directive, generatedAt, warnings);
|
|
60
|
-
const painFlag = readPainFlagData(workspaceDir);
|
|
61
|
-
const painCandidates = this.readJsonFile(wctx.resolve('PAIN_CANDIDATES'), warnings, false);
|
|
62
|
-
const phase3Inputs = evaluatePhase3Inputs(queue ?? []);
|
|
63
|
-
const lastPainSignal = this.findLastPainSignal(events, selectedSessionId);
|
|
64
|
-
const gfiSources = this.buildGfiSources(events, selectedSessionId);
|
|
65
|
-
const gateStats = this.buildGateStats(events, selectedSessionId, warnings);
|
|
66
|
-
// Read trajectory analytics data (historical data, NOT runtime truth)
|
|
67
|
-
const trajectoryStats = this.readTrajectoryStats(workspaceDir, warnings);
|
|
68
|
-
// Build runtime truth section (current state for control decisions)
|
|
69
|
-
const activeSessionIds = sessions.map(s => s.sessionId);
|
|
70
|
-
const runtimeTruth = {
|
|
71
|
-
queueState: {
|
|
72
|
-
total: queueStats.pending + queueStats.inProgress + queueStats.completed,
|
|
73
|
-
pending: queueStats.pending,
|
|
74
|
-
inProgress: queueStats.inProgress,
|
|
75
|
-
completed: queueStats.completed,
|
|
76
|
-
lastUpdated: generatedAt,
|
|
77
|
-
},
|
|
78
|
-
activeSessions: activeSessionIds,
|
|
79
|
-
};
|
|
80
|
-
// Build analytics truth section (historical data for insights)
|
|
81
|
-
const analyticsTruth = {
|
|
82
|
-
trajectoryData: {
|
|
83
|
-
totalTasks: trajectoryStats.assistantTurns + trajectoryStats.userTurns,
|
|
84
|
-
successRate: trajectoryStats.toolCalls > 0
|
|
85
|
-
? (trajectoryStats.toolCalls - trajectoryStats.failures) / trajectoryStats.toolCalls
|
|
86
|
-
: 0,
|
|
87
|
-
timeoutRate: trajectoryStats.failures > 0
|
|
88
|
-
? trajectoryStats.failures / (trajectoryStats.assistantTurns + trajectoryStats.userTurns || 1)
|
|
89
|
-
: 0,
|
|
90
|
-
lastUpdated: trajectoryStats.lastIngestAt ?? generatedAt,
|
|
91
|
-
},
|
|
92
|
-
dailyStats: {
|
|
93
|
-
toolCalls: dailyStats?.[statsDate]?.toolCalls ?? 0,
|
|
94
|
-
painSignals: dailyStats?.[statsDate]?.painSignals ?? 0,
|
|
95
|
-
evolutionTasks: dailyStats?.[statsDate]?.evolutionTasks ?? 0,
|
|
96
|
-
lastUpdated: statsDate,
|
|
97
|
-
},
|
|
98
|
-
trends: {
|
|
99
|
-
sevenDay: { successRateChange: 0, toolCallVolumeChange: 0, painSignalRateChange: 0 },
|
|
100
|
-
thirtyDay: { successRateChange: 0, toolCallVolumeChange: 0, painSignalRateChange: 0 },
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
return {
|
|
104
|
-
runtime: runtimeTruth,
|
|
105
|
-
analytics: analyticsTruth,
|
|
106
|
-
gfi: {
|
|
107
|
-
current: gfiCurrent,
|
|
108
|
-
peak: gfiPeak,
|
|
109
|
-
sources: gfiSources,
|
|
110
|
-
dataQuality: 'partial',
|
|
111
|
-
},
|
|
112
|
-
evolution: {
|
|
113
|
-
queue: queueStats,
|
|
114
|
-
directive: directiveSummary,
|
|
115
|
-
dataQuality: this.resolveEvolutionDataQuality(queue),
|
|
116
|
-
},
|
|
117
|
-
phase3: {
|
|
118
|
-
queueTruthReady: phase3Inputs.queueTruthReady,
|
|
119
|
-
phase3ShadowEligible: phase3Inputs.phase3ShadowEligible,
|
|
120
|
-
evolutionEligible: phase3Inputs.evolution.eligible.length,
|
|
121
|
-
evolutionReferenceOnly: phase3Inputs.evolution.referenceOnly.length,
|
|
122
|
-
evolutionReferenceOnlyReasons: [...new Set(phase3Inputs.evolution.referenceOnly.map((entry) => entry.classification))],
|
|
123
|
-
evolutionRejected: phase3Inputs.evolution.rejected.length,
|
|
124
|
-
evolutionRejectedReasons: phase3Inputs.evolution.rejected.flatMap((entry) => entry.reasons),
|
|
125
|
-
legacyDirectiveFilePresent: directive !== null,
|
|
126
|
-
directiveStatus: directive ? 'compatibility-only' : 'missing',
|
|
127
|
-
directiveIgnoredReason: 'queue is only truth source',
|
|
128
|
-
eligibilitySource: 'runtime_truth',
|
|
129
|
-
},
|
|
130
|
-
pain: {
|
|
131
|
-
activeFlag: Object.keys(painFlag).length > 0,
|
|
132
|
-
activeFlagSource: painFlag.source || null,
|
|
133
|
-
candidates: painCandidates?.candidates && typeof painCandidates.candidates === 'object'
|
|
134
|
-
? Object.keys(painCandidates.candidates).length
|
|
135
|
-
: null,
|
|
136
|
-
lastSignal: lastPainSignal,
|
|
137
|
-
},
|
|
138
|
-
gate: gateStats,
|
|
139
|
-
metadata: {
|
|
140
|
-
generatedAt,
|
|
141
|
-
workspaceDir,
|
|
142
|
-
sessionId: selectedSessionId,
|
|
143
|
-
selectedSessionReason: selectedSession.reason,
|
|
144
|
-
warnings,
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
static readSessions(sessionDir, warnings) {
|
|
149
|
-
if (!fs.existsSync(sessionDir)) {
|
|
150
|
-
pushWarning(warnings, 'No persisted session directory exists yet; session-scoped runtime state is unavailable.');
|
|
151
|
-
return [];
|
|
152
|
-
}
|
|
153
|
-
const sessions = [];
|
|
154
|
-
for (const file of fs.readdirSync(sessionDir)) {
|
|
155
|
-
if (!file.endsWith('.json'))
|
|
156
|
-
continue;
|
|
157
|
-
try {
|
|
158
|
-
const raw = fs.readFileSync(path.join(sessionDir, file), 'utf8');
|
|
159
|
-
const parsed = JSON.parse(raw);
|
|
160
|
-
if (parsed?.sessionId) {
|
|
161
|
-
sessions.push(parsed);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
pushWarning(warnings, `Failed to parse session snapshot: ${file}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return sessions.sort((a, b) => this.resolveSessionSortTime(b) - this.resolveSessionSortTime(a));
|
|
169
|
-
}
|
|
170
|
-
static selectSession(sessions, explicitSessionId) {
|
|
171
|
-
if (explicitSessionId) {
|
|
172
|
-
const explicit = sessions.find((session) => session.sessionId === explicitSessionId) ?? null;
|
|
173
|
-
return { session: explicit, reason: explicit ? 'explicit' : 'none' };
|
|
174
|
-
}
|
|
175
|
-
if (sessions.length === 0) {
|
|
176
|
-
return { session: null, reason: 'none' };
|
|
177
|
-
}
|
|
178
|
-
return { session: sessions[0], reason: 'latest_active' };
|
|
179
|
-
}
|
|
180
|
-
static mergeSessionSnapshots(persistedSessions, workspaceDir) {
|
|
181
|
-
const merged = new Map();
|
|
182
|
-
for (const session of persistedSessions) {
|
|
183
|
-
merged.set(session.sessionId, { ...session });
|
|
184
|
-
}
|
|
185
|
-
for (const live of listSessions(workspaceDir)) {
|
|
186
|
-
const persisted = merged.get(live.sessionId);
|
|
187
|
-
merged.set(live.sessionId, {
|
|
188
|
-
sessionId: live.sessionId,
|
|
189
|
-
currentGfi: Number.isFinite(live.currentGfi) ? Number(live.currentGfi) : persisted?.currentGfi,
|
|
190
|
-
dailyGfiPeak: Number.isFinite(live.dailyGfiPeak) ? Number(live.dailyGfiPeak) : persisted?.dailyGfiPeak,
|
|
191
|
-
lastActivityAt: Number.isFinite(live.lastActivityAt) ? Number(live.lastActivityAt) : persisted?.lastActivityAt,
|
|
192
|
-
lastControlActivityAt: Number.isFinite(live.lastControlActivityAt)
|
|
193
|
-
? Number(live.lastControlActivityAt)
|
|
194
|
-
: persisted?.lastControlActivityAt,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
return [...merged.values()].sort((a, b) => this.resolveSessionSortTime(b) - this.resolveSessionSortTime(a));
|
|
198
|
-
}
|
|
199
|
-
static buildQueueStats(queue) {
|
|
200
|
-
const stats = { pending: 0, inProgress: 0, completed: 0 };
|
|
201
|
-
if (!queue)
|
|
202
|
-
return stats;
|
|
203
|
-
for (const item of queue) {
|
|
204
|
-
if (item?.status === 'completed') {
|
|
205
|
-
stats.completed++;
|
|
206
|
-
}
|
|
207
|
-
else if (item?.status === 'in_progress') {
|
|
208
|
-
stats.inProgress++;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
stats.pending++;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return stats;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Builds directive summary for compatibility display only.
|
|
218
|
-
* NOT a truth source for Phase 3 eligibility or decisions.
|
|
219
|
-
* Queue is the only authoritative execution truth source.
|
|
220
|
-
*/
|
|
221
|
-
static buildDirectiveSummary(queue, directive, generatedAt, warnings) {
|
|
222
|
-
const inProgressTask = this.selectInProgressTask(queue);
|
|
223
|
-
if (!inProgressTask) {
|
|
224
|
-
if (directive) {
|
|
225
|
-
this.warnOnLegacyDirectiveMismatch(directive, null, warnings);
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
exists: false,
|
|
229
|
-
active: null,
|
|
230
|
-
ageSeconds: null,
|
|
231
|
-
taskPreview: null,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
const derivedTaskPreview = this.buildDirectiveTaskPreview(inProgressTask);
|
|
235
|
-
const timestampMs = this.resolveDirectiveTimestamp(inProgressTask);
|
|
236
|
-
const ageSeconds = Number.isFinite(timestampMs)
|
|
237
|
-
? Math.max(0, Math.floor((new Date(generatedAt).getTime() - timestampMs) / 1000))
|
|
238
|
-
: null;
|
|
239
|
-
if (directive) {
|
|
240
|
-
this.warnOnLegacyDirectiveMismatch(directive, {
|
|
241
|
-
active: true,
|
|
242
|
-
taskPreview: derivedTaskPreview,
|
|
243
|
-
taskId: inProgressTask.taskId ?? inProgressTask.id ?? null,
|
|
244
|
-
}, warnings);
|
|
245
|
-
}
|
|
246
|
-
return {
|
|
247
|
-
exists: true,
|
|
248
|
-
active: true,
|
|
249
|
-
ageSeconds,
|
|
250
|
-
taskPreview: derivedTaskPreview,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
static readEvents(eventsPath, warnings) {
|
|
254
|
-
if (!fs.existsSync(eventsPath)) {
|
|
255
|
-
warnings.push('No events.jsonl file exists yet; recent pain and gate summaries are partial.');
|
|
256
|
-
return [];
|
|
257
|
-
}
|
|
258
|
-
try {
|
|
259
|
-
const raw = fs.readFileSync(eventsPath, 'utf8').trim();
|
|
260
|
-
if (!raw)
|
|
261
|
-
return [];
|
|
262
|
-
let parseFailures = 0;
|
|
263
|
-
const entries = raw
|
|
264
|
-
.split('\n')
|
|
265
|
-
.map((line) => {
|
|
266
|
-
try {
|
|
267
|
-
return JSON.parse(line);
|
|
268
|
-
}
|
|
269
|
-
catch {
|
|
270
|
-
parseFailures += 1;
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
})
|
|
274
|
-
.filter((entry) => entry !== null);
|
|
275
|
-
if (parseFailures > 0) {
|
|
276
|
-
pushWarning(warnings, `Skipped ${parseFailures} malformed event line${parseFailures === 1 ? '' : 's'} while reading events.jsonl.`);
|
|
277
|
-
}
|
|
278
|
-
return entries;
|
|
279
|
-
}
|
|
280
|
-
catch {
|
|
281
|
-
pushWarning(warnings, 'Failed to read events.jsonl; recent pain and gate summaries are partial.');
|
|
282
|
-
return [];
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
static buildGfiSources(events, sessionId) {
|
|
286
|
-
const filtered = events
|
|
287
|
-
.filter((entry) => {
|
|
288
|
-
if (sessionId && entry.sessionId !== sessionId)
|
|
289
|
-
return false;
|
|
290
|
-
return (entry.type === 'pain_signal' ||
|
|
291
|
-
(entry.type === 'tool_call' && entry.category === 'failure'));
|
|
292
|
-
})
|
|
293
|
-
.slice(-MAX_SOURCE_EVENTS)
|
|
294
|
-
.reverse();
|
|
295
|
-
return filtered.map((entry) => {
|
|
296
|
-
if (entry.type === 'pain_signal') {
|
|
297
|
-
return {
|
|
298
|
-
source: String(entry.data?.source ?? 'pain_signal'),
|
|
299
|
-
score: this.asFiniteNumber(entry.data?.score),
|
|
300
|
-
ts: entry.ts,
|
|
301
|
-
confidence: this.asFiniteNumber(entry.data?.confidence),
|
|
302
|
-
origin: typeof entry.data?.origin === 'string' ? entry.data.origin : undefined,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
return {
|
|
306
|
-
source: `tool_failure:${String(entry.data?.toolName ?? 'unknown')}`,
|
|
307
|
-
score: this.asFiniteNumber(entry.data?.gfi),
|
|
308
|
-
ts: entry.ts,
|
|
309
|
-
};
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
static findLastPainSignal(events, sessionId) {
|
|
313
|
-
for (let i = events.length - 1; i >= 0; i--) {
|
|
314
|
-
const entry = events[i];
|
|
315
|
-
if (entry.type !== 'pain_signal')
|
|
316
|
-
continue;
|
|
317
|
-
if (sessionId && entry.sessionId !== sessionId)
|
|
318
|
-
continue;
|
|
319
|
-
return {
|
|
320
|
-
source: String(entry.data?.source ?? 'pain_signal'),
|
|
321
|
-
ts: entry.ts ?? null,
|
|
322
|
-
reason: typeof entry.data?.reason === 'string' ? entry.data.reason : null,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
static buildGateStats(events, sessionId, warnings) {
|
|
328
|
-
const scoped = events.filter((entry) => {
|
|
329
|
-
if (sessionId && entry.sessionId !== sessionId)
|
|
330
|
-
return false;
|
|
331
|
-
return entry.type === 'gate_block' || entry.type === 'gate_bypass';
|
|
332
|
-
});
|
|
333
|
-
if (scoped.length === 0) {
|
|
334
|
-
pushWarning(warnings, 'Gate block counts before Phase 1 may be incomplete because older block events were not recorded to event-log.');
|
|
335
|
-
}
|
|
336
|
-
return {
|
|
337
|
-
recentBlocks: scoped.filter((entry) => entry.type === 'gate_block').length,
|
|
338
|
-
recentBypasses: scoped.filter((entry) => entry.type === 'gate_bypass').length,
|
|
339
|
-
dataQuality: scoped.length > 0 ? 'authoritative' : 'partial',
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
static resolveSessionSortTime(session) {
|
|
343
|
-
return session.lastControlActivityAt ?? session.lastActivityAt ?? 0;
|
|
344
|
-
}
|
|
345
|
-
static mergeEvents(persistedEvents, bufferedEvents) {
|
|
346
|
-
const merged = new Map();
|
|
347
|
-
for (const entry of [...persistedEvents, ...bufferedEvents]) {
|
|
348
|
-
merged.set(this.getEventDedupKey(entry), entry);
|
|
349
|
-
}
|
|
350
|
-
return [...merged.values()].sort((a, b) => (a.ts || '').localeCompare(b.ts || ''));
|
|
351
|
-
}
|
|
352
|
-
static getEventDedupKey(entry) {
|
|
353
|
-
const eventId = typeof entry.data?.eventId === 'string' ? entry.data.eventId : null;
|
|
354
|
-
if (eventId) {
|
|
355
|
-
return `${entry.type}:${entry.sessionId ?? 'none'}:${eventId}`;
|
|
356
|
-
}
|
|
357
|
-
return [
|
|
358
|
-
entry.ts ?? 'no-ts',
|
|
359
|
-
entry.type ?? 'no-type',
|
|
360
|
-
entry.category ?? 'no-category',
|
|
361
|
-
entry.sessionId ?? 'no-session',
|
|
362
|
-
typeof entry.data?.source === 'string' ? entry.data.source : 'no-source',
|
|
363
|
-
typeof entry.data?.toolName === 'string' ? entry.data.toolName : 'no-tool',
|
|
364
|
-
typeof entry.data?.reason === 'string' ? entry.data.reason : 'no-reason',
|
|
365
|
-
].join('::');
|
|
366
|
-
}
|
|
367
|
-
static resolveEvolutionDataQuality(queue) {
|
|
368
|
-
return queue ? 'authoritative' : 'partial';
|
|
369
|
-
}
|
|
370
|
-
static selectInProgressTask(queue) {
|
|
371
|
-
if (!queue || queue.length === 0)
|
|
372
|
-
return null;
|
|
373
|
-
const inProgress = queue.filter((item) => item?.status === 'in_progress');
|
|
374
|
-
if (inProgress.length === 0)
|
|
375
|
-
return null;
|
|
376
|
-
for (const item of [...inProgress].sort((a, b) => this.getQueuePriority(b) - this.getQueuePriority(a))) {
|
|
377
|
-
if (this.isResolvableEvolutionTask(item)) {
|
|
378
|
-
return item;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
static getQueuePriority(item) {
|
|
384
|
-
return Number.isFinite(item.score) ? Number(item.score) : 0;
|
|
385
|
-
}
|
|
386
|
-
static isResolvableEvolutionTask(item) {
|
|
387
|
-
const rawTask = typeof item.task === 'string' ? item.task.trim() : '';
|
|
388
|
-
if (rawTask && rawTask.toLowerCase() !== 'undefined') {
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
return typeof item.id === 'string' && item.id.trim().length > 0;
|
|
392
|
-
}
|
|
393
|
-
static resolveDirectiveTimestamp(item) {
|
|
394
|
-
const candidate = item.started_at || item.enqueued_at || item.timestamp || null;
|
|
395
|
-
return candidate ? new Date(candidate).getTime() : NaN;
|
|
396
|
-
}
|
|
397
|
-
static buildDirectiveTaskPreview(item) {
|
|
398
|
-
const task = typeof item.task === 'string' ? item.task.trim() : '';
|
|
399
|
-
if (task && task.toLowerCase() !== 'undefined') {
|
|
400
|
-
return task.slice(0, 160);
|
|
401
|
-
}
|
|
402
|
-
const triggerTextPreview = typeof item.trigger_text_preview === 'string' ? item.trigger_text_preview.trim() : '';
|
|
403
|
-
const taskId = typeof item.taskId === 'string' && item.taskId.trim()
|
|
404
|
-
? item.taskId.trim()
|
|
405
|
-
: typeof item.id === 'string' && item.id.trim()
|
|
406
|
-
? item.id.trim()
|
|
407
|
-
: 'unknown';
|
|
408
|
-
const source = typeof item.source === 'string' && item.source.trim() ? item.source.trim() : 'unknown';
|
|
409
|
-
const reason = typeof item.reason === 'string' && item.reason.trim() ? item.reason.trim() : 'Systemic pain detected';
|
|
410
|
-
const preview = triggerTextPreview || 'N/A';
|
|
411
|
-
return `Diagnose systemic pain [ID: ${taskId}]. Source: ${source}. Reason: ${reason}. Trigger text: "${preview}"`.slice(0, 160);
|
|
412
|
-
}
|
|
413
|
-
static warnOnLegacyDirectiveMismatch(directive, derived, warnings) {
|
|
414
|
-
const legacyActive = typeof directive.active === 'boolean' ? directive.active : null;
|
|
415
|
-
const legacyTask = typeof directive.task === 'string' && directive.task.trim() ? directive.task.trim().slice(0, 160) : null;
|
|
416
|
-
const legacyTaskId = typeof directive.taskId === 'string' && directive.taskId.trim() ? directive.taskId.trim() : null;
|
|
417
|
-
const mismatchDetails = [];
|
|
418
|
-
if (derived === null) {
|
|
419
|
-
if (legacyActive === true || legacyTask || legacyTaskId) {
|
|
420
|
-
mismatchDetails.push('legacy directive exists but queue has no in_progress task');
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
if (legacyActive !== null && legacyActive !== derived.active) {
|
|
425
|
-
mismatchDetails.push(`active=${String(legacyActive)} vs queue=${String(derived.active)}`);
|
|
426
|
-
}
|
|
427
|
-
if (legacyTask && derived.taskPreview && legacyTask !== derived.taskPreview) {
|
|
428
|
-
mismatchDetails.push('task text differs');
|
|
429
|
-
}
|
|
430
|
-
if (legacyTaskId && derived.taskId && legacyTaskId !== derived.taskId) {
|
|
431
|
-
mismatchDetails.push('task id differs');
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
if (mismatchDetails.length > 0) {
|
|
435
|
-
pushWarning(warnings, `Legacy directive file disagrees with queue-derived evolution state; queue is authoritative (${mismatchDetails.join(', ')}).`);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
static readJsonFile(filePath, warnings, warnOnMissing) {
|
|
439
|
-
if (!fs.existsSync(filePath)) {
|
|
440
|
-
if (warnOnMissing) {
|
|
441
|
-
pushWarning(warnings, `Missing expected file: ${path.basename(filePath)}`);
|
|
442
|
-
}
|
|
443
|
-
return null;
|
|
444
|
-
}
|
|
445
|
-
try {
|
|
446
|
-
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
447
|
-
}
|
|
448
|
-
catch {
|
|
449
|
-
pushWarning(warnings, `Failed to parse ${path.basename(filePath)}.`);
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
static asFiniteNumber(value) {
|
|
454
|
-
return Number.isFinite(value) ? Number(value) : undefined;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Read trajectory analytics data from trajectory database.
|
|
458
|
-
*
|
|
459
|
-
* Returns: Analytics data (historical metrics) aggregated from trajectory database.
|
|
460
|
-
* Not: Runtime truth or real-time queue state.
|
|
461
|
-
*/
|
|
462
|
-
static readTrajectoryStats(workspaceDir, warnings) {
|
|
463
|
-
try {
|
|
464
|
-
// Use transient database instance to avoid locking issues
|
|
465
|
-
const stats = TrajectoryRegistry.use(workspaceDir, (db) => db.getDataStats());
|
|
466
|
-
return {
|
|
467
|
-
assistantTurns: stats.assistantTurns,
|
|
468
|
-
userTurns: stats.userTurns,
|
|
469
|
-
toolCalls: stats.toolCalls,
|
|
470
|
-
failures: stats.painEvents, // Approximate failures from pain events
|
|
471
|
-
lastIngestAt: stats.lastIngestAt,
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
catch (error) {
|
|
475
|
-
pushWarning(warnings, `Failed to read trajectory analytics: ${error instanceof Error ? error.message : String(error)}`);
|
|
476
|
-
return {
|
|
477
|
-
assistantTurns: 0,
|
|
478
|
-
userTurns: 0,
|
|
479
|
-
toolCalls: 0,
|
|
480
|
-
failures: 0,
|
|
481
|
-
lastIngestAt: null,
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { PluginLogger } from '../../openclaw-sdk.js';
|
|
2
|
-
import type { WorkflowManager, WorkflowHandle, SubagentWorkflowSpec, WorkflowDebugSummary, EmpathyObserverPayload, EmpathyResult } from './types.js';
|
|
3
|
-
import { RuntimeDirectDriver } from './runtime-direct-driver.js';
|
|
4
|
-
export interface EmpathyObserverWorkflowOptions {
|
|
5
|
-
workspaceDir: string;
|
|
6
|
-
logger: PluginLogger;
|
|
7
|
-
subagent: RuntimeDirectDriver['subagent'];
|
|
8
|
-
}
|
|
9
|
-
export declare class EmpathyObserverWorkflowManager implements WorkflowManager {
|
|
10
|
-
private readonly store;
|
|
11
|
-
private readonly driver;
|
|
12
|
-
private readonly logger;
|
|
13
|
-
private readonly workspaceDir;
|
|
14
|
-
private activeWorkflows;
|
|
15
|
-
private completedWorkflows;
|
|
16
|
-
private workflowSpecs;
|
|
17
|
-
constructor(opts: EmpathyObserverWorkflowOptions);
|
|
18
|
-
startWorkflow<TResult>(spec: SubagentWorkflowSpec<TResult>, options: {
|
|
19
|
-
parentSessionId: string;
|
|
20
|
-
workspaceDir?: string;
|
|
21
|
-
taskInput: unknown;
|
|
22
|
-
metadata?: Record<string, unknown>;
|
|
23
|
-
}): Promise<WorkflowHandle>;
|
|
24
|
-
private buildRunParams;
|
|
25
|
-
static buildEmpathyPrompt(userMessage: string): string;
|
|
26
|
-
private scheduleWaitPoll;
|
|
27
|
-
notifyWaitResult(workflowId: string, status: 'ok' | 'error' | 'timeout', error?: string): Promise<void>;
|
|
28
|
-
notifyLifecycleEvent(workflowId: string, event: 'subagent_spawned' | 'subagent_ended', data?: {
|
|
29
|
-
outcome?: 'ok' | 'error' | 'timeout' | 'killed' | 'reset' | 'deleted';
|
|
30
|
-
error?: string;
|
|
31
|
-
}): Promise<void>;
|
|
32
|
-
finalizeOnce(workflowId: string): Promise<void>;
|
|
33
|
-
sweepExpiredWorkflows(maxAgeMs?: number): Promise<number>;
|
|
34
|
-
getWorkflowDebugSummary(workflowId: string, eventLimit?: number): Promise<WorkflowDebugSummary | null>;
|
|
35
|
-
private generateWorkflowId;
|
|
36
|
-
private buildChildSessionKey;
|
|
37
|
-
private extractAssistantText;
|
|
38
|
-
parseEmpathyPayload(rawText: string): EmpathyObserverPayload | null;
|
|
39
|
-
private isCompleted;
|
|
40
|
-
private markCompleted;
|
|
41
|
-
dispose(): void;
|
|
42
|
-
}
|
|
43
|
-
export declare function createEmpathyObserverWorkflowManager(opts: EmpathyObserverWorkflowOptions): EmpathyObserverWorkflowManager;
|
|
44
|
-
/**
|
|
45
|
-
* EmpathyObserver workflow specification.
|
|
46
|
-
* This spec drives EmpathyObserverWorkflowManager for the empathy observer workflow.
|
|
47
|
-
*/
|
|
48
|
-
export declare const empathyObserverWorkflowSpec: SubagentWorkflowSpec<EmpathyResult>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { RuntimeDirectDriver, type TransportDriver, type RunParams, type RunResult, type WaitParams, type WaitResult, type GetResultParams, type GetResultResult, type CleanupParams, } from './runtime-direct-driver.js';
|
|
2
|
-
export { WorkflowStore, type WorkflowStoreOptions } from './workflow-store.js';
|
|
3
|
-
export { EmpathyObserverWorkflowManager, createEmpathyObserverWorkflowManager, empathyObserverWorkflowSpec, type EmpathyObserverWorkflowOptions, } from './empathy-observer-workflow-manager.js';
|
|
4
|
-
export type { WorkflowState, WorkflowTransport, WorkflowMetadata, WorkflowResultContext, WorkflowPersistContext, WorkflowHandle, SubagentWorkflowSpec, EmpathyObserverWorkflowSpec, EmpathyObserverPayload, EmpathyResult, WorkflowRow, WorkflowEventRow, WorkflowDebugSummary, } from './types.js';
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { RuntimeDirectDriver, } from './runtime-direct-driver.js';
|
|
2
|
-
export { WorkflowStore } from './workflow-store.js';
|
|
3
|
-
export { EmpathyObserverWorkflowManager, createEmpathyObserverWorkflowManager, empathyObserverWorkflowSpec, } from './empathy-observer-workflow-manager.js';
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { SubagentRunResult, SubagentWaitResult, SubagentGetSessionMessagesResult, PluginLogger } from '../../openclaw-sdk.js';
|
|
2
|
-
export interface TransportDriver {
|
|
3
|
-
run(params: RunParams): Promise<RunResult>;
|
|
4
|
-
wait(params: WaitParams): Promise<WaitResult>;
|
|
5
|
-
getResult(params: GetResultParams): Promise<GetResultResult>;
|
|
6
|
-
cleanup(params: CleanupParams): Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
export interface RunParams {
|
|
9
|
-
sessionKey: string;
|
|
10
|
-
message: string;
|
|
11
|
-
lane?: string;
|
|
12
|
-
deliver?: boolean;
|
|
13
|
-
idempotencyKey?: string;
|
|
14
|
-
expectsCompletionMessage?: boolean;
|
|
15
|
-
extraSystemPrompt?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface RunResult {
|
|
18
|
-
runId: string;
|
|
19
|
-
}
|
|
20
|
-
export interface WaitParams {
|
|
21
|
-
runId: string;
|
|
22
|
-
timeoutMs?: number;
|
|
23
|
-
}
|
|
24
|
-
export interface WaitResult {
|
|
25
|
-
status: 'ok' | 'error' | 'timeout';
|
|
26
|
-
error?: string;
|
|
27
|
-
}
|
|
28
|
-
export interface GetResultParams {
|
|
29
|
-
sessionKey: string;
|
|
30
|
-
limit?: number;
|
|
31
|
-
}
|
|
32
|
-
export interface GetResultResult {
|
|
33
|
-
messages: unknown[];
|
|
34
|
-
assistantTexts?: string[];
|
|
35
|
-
}
|
|
36
|
-
export interface CleanupParams {
|
|
37
|
-
sessionKey: string;
|
|
38
|
-
deleteTranscript?: boolean;
|
|
39
|
-
}
|
|
40
|
-
type PluginRuntimeSubagent = {
|
|
41
|
-
run: (params: {
|
|
42
|
-
sessionKey: string;
|
|
43
|
-
message: string;
|
|
44
|
-
lane?: string;
|
|
45
|
-
deliver?: boolean;
|
|
46
|
-
idempotencyKey?: string;
|
|
47
|
-
expectsCompletionMessage?: boolean;
|
|
48
|
-
extraSystemPrompt?: string;
|
|
49
|
-
}) => Promise<SubagentRunResult>;
|
|
50
|
-
waitForRun: (params: {
|
|
51
|
-
runId: string;
|
|
52
|
-
timeoutMs?: number;
|
|
53
|
-
}) => Promise<SubagentWaitResult>;
|
|
54
|
-
getSessionMessages: (params: {
|
|
55
|
-
sessionKey: string;
|
|
56
|
-
limit?: number;
|
|
57
|
-
}) => Promise<SubagentGetSessionMessagesResult>;
|
|
58
|
-
deleteSession: (params: {
|
|
59
|
-
sessionKey: string;
|
|
60
|
-
deleteTranscript?: boolean;
|
|
61
|
-
}) => Promise<void>;
|
|
62
|
-
};
|
|
63
|
-
export declare class RuntimeDirectDriver implements TransportDriver {
|
|
64
|
-
private readonly subagent;
|
|
65
|
-
private readonly logger;
|
|
66
|
-
constructor(options: {
|
|
67
|
-
subagent: PluginRuntimeSubagent;
|
|
68
|
-
logger: PluginLogger;
|
|
69
|
-
});
|
|
70
|
-
/** Expose subagent for availability checking (used by workflow manager for surface degrade) */
|
|
71
|
-
getSubagent(): PluginRuntimeSubagent;
|
|
72
|
-
run(params: RunParams): Promise<RunResult>;
|
|
73
|
-
wait(params: WaitParams): Promise<WaitResult>;
|
|
74
|
-
getResult(params: GetResultParams): Promise<GetResultResult>;
|
|
75
|
-
cleanup(params: CleanupParams): Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
export {};
|