principles-disciple 1.127.0 → 1.129.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/archive-impl.d.ts +18 -0
- package/dist/commands/archive-impl.js +105 -0
- package/dist/commands/capabilities.d.ts +3 -0
- package/dist/commands/capabilities.js +76 -0
- package/dist/commands/context.d.ts +5 -0
- package/{src/commands/context.ts → dist/commands/context.js} +34 -83
- package/dist/commands/disable-impl.d.ts +22 -0
- package/dist/commands/disable-impl.js +118 -0
- package/dist/commands/evolution-status.d.ts +4 -0
- package/dist/commands/evolution-status.js +187 -0
- package/dist/commands/export.d.ts +2 -0
- package/dist/commands/export.js +53 -0
- package/dist/commands/focus.d.ts +14 -0
- package/dist/commands/focus.js +443 -0
- package/dist/commands/pain.d.ts +6 -0
- package/{src/commands/pain.ts → dist/commands/pain.js} +137 -188
- package/dist/commands/principle-rollback.d.ts +4 -0
- package/dist/commands/principle-rollback.js +26 -0
- package/dist/commands/promote-impl.d.ts +22 -0
- package/dist/commands/promote-impl.js +194 -0
- package/dist/commands/rollback-impl.d.ts +32 -0
- package/dist/commands/rollback-impl.js +180 -0
- package/dist/commands/rollback.d.ts +19 -0
- package/{src/commands/rollback.ts → dist/commands/rollback.js} +10 -53
- package/dist/commands/samples.d.ts +2 -0
- package/dist/commands/samples.js +58 -0
- package/dist/commands/strategy.d.ts +2 -0
- package/dist/commands/strategy.js +16 -0
- package/dist/commands/thinking-os.d.ts +2 -0
- package/{src/commands/thinking-os.ts → dist/commands/thinking-os.js} +35 -58
- package/dist/commands/workflow-debug.d.ts +6 -0
- package/{src/commands/workflow-debug.ts → dist/commands/workflow-debug.js} +13 -33
- package/dist/config/defaults/runtime.d.ts +58 -0
- package/{src/config/defaults/runtime.ts → dist/config/defaults/runtime.js} +4 -41
- package/dist/config/errors.d.ts +86 -0
- package/dist/config/errors.js +107 -0
- package/{src/config/index.ts → dist/config/index.d.ts} +1 -2
- package/dist/config/index.js +7 -0
- package/dist/constants/diagnostician.d.ts +12 -0
- package/{src/constants/diagnostician.ts → dist/constants/diagnostician.js} +0 -1
- package/dist/constants/tools.d.ts +17 -0
- package/dist/constants/tools.js +53 -0
- package/dist/core/__tests__/focus-history.test.d.ts +1 -0
- package/dist/core/__tests__/focus-history.test.js +160 -0
- package/dist/core/bootstrap-rules.d.ts +50 -0
- package/dist/core/bootstrap-rules.js +187 -0
- package/dist/core/code-implementation-storage.d.ts +71 -0
- package/dist/core/code-implementation-storage.js +139 -0
- package/dist/core/config-health.d.ts +27 -0
- package/dist/core/config-health.js +60 -0
- package/dist/core/config-service.d.ts +15 -0
- package/{src/core/config-service.ts → dist/core/config-service.js} +4 -7
- package/dist/core/config.d.ts +111 -0
- package/{src/core/config.ts → dist/core/config.js} +46 -146
- package/dist/core/control-ui-db.d.ts +106 -0
- package/dist/core/control-ui-db.js +309 -0
- package/dist/core/correction-cue-learner.d.ts +33 -0
- package/dist/core/correction-cue-learner.js +184 -0
- package/dist/core/correction-types.d.ts +3 -0
- package/dist/core/correction-types.js +1 -0
- package/dist/core/detection-funnel.d.ts +33 -0
- package/{src/core/detection-funnel.ts → dist/core/detection-funnel.js} +17 -37
- package/dist/core/detection-service.d.ts +15 -0
- package/{src/core/detection-service.ts → dist/core/detection-service.js} +4 -7
- package/dist/core/dictionary-service.d.ts +15 -0
- package/{src/core/dictionary-service.ts → dist/core/dictionary-service.js} +4 -7
- package/dist/core/dictionary.d.ts +38 -0
- package/{src/core/dictionary.ts → dist/core/dictionary.js} +33 -59
- package/dist/core/empathy-keyword-matcher.d.ts +5 -0
- package/dist/core/empathy-keyword-matcher.js +40 -0
- package/dist/core/empathy-types.d.ts +2 -0
- package/dist/core/empathy-types.js +1 -0
- package/dist/core/event-log.d.ts +90 -0
- package/dist/core/event-log.js +702 -0
- package/dist/core/evolution-engine.d.ts +119 -0
- package/dist/core/evolution-engine.js +460 -0
- package/dist/core/evolution-logger.d.ts +137 -0
- package/dist/core/evolution-logger.js +261 -0
- package/dist/core/evolution-migration.d.ts +5 -0
- package/dist/core/evolution-migration.js +65 -0
- package/dist/core/evolution-reducer.d.ts +124 -0
- package/dist/core/evolution-reducer.js +730 -0
- package/dist/core/evolution-types.d.ts +50 -0
- package/dist/core/evolution-types.js +11 -0
- package/dist/core/external-training-contract.d.ts +276 -0
- package/dist/core/external-training-contract.js +269 -0
- package/dist/core/file-store.d.ts +41 -0
- package/dist/core/file-store.js +46 -0
- package/dist/core/focus-history.d.ts +50 -0
- package/dist/core/focus-history.js +574 -0
- package/dist/core/hygiene/tracker.d.ts +22 -0
- package/dist/core/hygiene/tracker.js +110 -0
- package/dist/core/init.d.ts +30 -0
- package/{src/core/init.ts → dist/core/init.js} +87 -118
- package/dist/core/local-worker-routing.d.ts +124 -0
- package/dist/core/local-worker-routing.js +216 -0
- package/dist/core/migration.d.ts +6 -0
- package/{src/core/migration.ts → dist/core/migration.js} +10 -18
- package/dist/core/model-deployment-registry.d.ts +218 -0
- package/dist/core/model-deployment-registry.js +502 -0
- package/dist/core/model-training-registry.d.ts +295 -0
- package/dist/core/model-training-registry.js +474 -0
- package/dist/core/observability.d.ts +40 -0
- package/dist/core/observability.js +164 -0
- package/dist/core/pain-diagnostic-gate.d.ts +36 -0
- package/dist/core/pain-diagnostic-gate.js +105 -0
- package/dist/core/pain.d.ts +87 -0
- package/dist/core/pain.js +223 -0
- package/dist/core/path-resolver.d.ts +60 -0
- package/{src/core/path-resolver.ts → dist/core/path-resolver.js} +41 -131
- package/dist/core/paths.d.ts +60 -0
- package/{src/core/paths.ts → dist/core/paths.js} +4 -13
- package/dist/core/pd-config-loader.d.ts +96 -0
- package/dist/core/pd-config-loader.js +307 -0
- package/dist/core/pd-task-reconciler.d.ts +89 -0
- package/dist/core/pd-task-reconciler.js +262 -0
- package/dist/core/pd-task-service.d.ts +2 -0
- package/dist/core/pd-task-service.js +32 -0
- package/dist/core/pd-task-store.d.ts +5 -0
- package/dist/core/pd-task-store.js +62 -0
- package/dist/core/pd-task-types.d.ts +8 -0
- package/dist/core/pd-task-types.js +2 -0
- package/dist/core/principle-compiler/__tests__/compiler-replay-gate.test.d.ts +1 -0
- package/dist/core/principle-compiler/__tests__/compiler-replay-gate.test.js +132 -0
- package/dist/core/principle-compiler/code-validator.d.ts +14 -0
- package/dist/core/principle-compiler/code-validator.js +86 -0
- package/dist/core/principle-compiler/compiler.d.ts +45 -0
- package/dist/core/principle-compiler/compiler.js +287 -0
- package/{src/core/principle-compiler/index.ts → dist/core/principle-compiler/index.d.ts} +0 -1
- package/dist/core/principle-compiler/index.js +10 -0
- package/dist/core/principle-compiler/ledger-registrar.d.ts +28 -0
- package/dist/core/principle-compiler/ledger-registrar.js +95 -0
- package/{src/core/principle-compiler/template-generator.ts → dist/core/principle-compiler/template-generator.d.ts} +0 -1
- package/dist/core/principle-compiler/template-generator.js +7 -0
- package/{src/core/principle-injection.ts → dist/core/principle-injection.d.ts} +1 -7
- package/dist/core/principle-injection.js +10 -0
- package/dist/core/principle-internalization/filesystem-lifecycle-datasource.d.ts +15 -0
- package/dist/core/principle-internalization/filesystem-lifecycle-datasource.js +34 -0
- package/dist/core/principle-internalization/lifecycle-read-model.d.ts +17 -0
- package/{src/core/principle-internalization/lifecycle-read-model.ts → dist/core/principle-internalization/lifecycle-read-model.js} +2 -21
- package/dist/core/principle-internalization/lifecycle-refresh.d.ts +2 -0
- package/dist/core/principle-internalization/lifecycle-refresh.js +4 -0
- package/dist/core/principle-internalization/principle-lifecycle-service.d.ts +28 -0
- package/dist/core/principle-internalization/principle-lifecycle-service.js +89 -0
- package/dist/core/principle-training-state.d.ts +47 -0
- package/dist/core/principle-training-state.js +113 -0
- package/dist/core/principle-tree-ledger-adapter.d.ts +32 -0
- package/dist/core/principle-tree-ledger-adapter.js +125 -0
- package/dist/core/principle-tree-ledger.d.ts +82 -0
- package/dist/core/principle-tree-ledger.js +527 -0
- package/dist/core/profile.d.ts +62 -0
- package/dist/core/profile.js +211 -0
- package/dist/core/promotion-gate.d.ts +243 -0
- package/dist/core/promotion-gate.js +554 -0
- package/dist/core/reflection/reflection-context.d.ts +31 -0
- package/dist/core/reflection/reflection-context.js +91 -0
- package/dist/core/replay-engine.d.ts +12 -0
- package/dist/core/replay-engine.js +82 -0
- package/dist/core/risk-calculator.d.ts +22 -0
- package/{src/core/risk-calculator.ts → dist/core/risk-calculator.js} +19 -49
- package/{src/core/rule-host-helpers.ts → dist/core/rule-host-helpers.d.ts} +0 -1
- package/dist/core/rule-host-helpers.js +7 -0
- package/{src/core/rule-host-types.ts → dist/core/rule-host-types.d.ts} +1 -8
- package/dist/core/rule-host-types.js +7 -0
- package/dist/core/rule-host.d.ts +86 -0
- package/dist/core/rule-host.js +311 -0
- package/dist/core/rule-implementation-runtime.d.ts +18 -0
- package/dist/core/rule-implementation-runtime.js +112 -0
- package/dist/core/runtime-v2-prompt-activation-reader.d.ts +22 -0
- package/dist/core/runtime-v2-prompt-activation-reader.js +99 -0
- package/{src/core/schema/db-types.ts → dist/core/schema/db-types.d.ts} +4 -9
- package/dist/core/schema/db-types.js +5 -0
- package/{src/core/schema/index.ts → dist/core/schema/index.d.ts} +1 -10
- package/dist/core/schema/index.js +15 -0
- package/dist/core/schema/migration-runner.d.ts +53 -0
- package/dist/core/schema/migration-runner.js +170 -0
- package/dist/core/schema/migrations/001-init-trajectory.d.ts +6 -0
- package/{src/core/schema/migrations/001-init-trajectory.ts → dist/core/schema/migrations/001-init-trajectory.js} +38 -56
- package/dist/core/schema/migrations/002-init-central.d.ts +5 -0
- package/{src/core/schema/migrations/002-init-central.ts → dist/core/schema/migrations/002-init-central.js} +27 -41
- package/dist/core/schema/migrations/003-init-workflow.d.ts +5 -0
- package/{src/core/schema/migrations/003-init-workflow.ts → dist/core/schema/migrations/003-init-workflow.js} +16 -21
- package/dist/core/schema/migrations/004-add-thinking-and-gfi.d.ts +8 -0
- package/{src/core/schema/migrations/004-add-thinking-and-gfi.ts → dist/core/schema/migrations/004-add-thinking-and-gfi.js} +19 -27
- package/{src/core/schema/migrations/index.ts → dist/core/schema/migrations/index.d.ts} +1 -16
- package/dist/core/schema/migrations/index.js +27 -0
- package/dist/core/schema/schema-definitions.d.ts +46 -0
- package/{src/core/schema/schema-definitions.ts → dist/core/schema/schema-definitions.js} +242 -291
- package/dist/core/session-tracker.d.ts +119 -0
- package/{src/core/session-tracker.ts → dist/core/session-tracker.js} +96 -239
- package/dist/core/shadow-observation-registry.d.ts +217 -0
- package/dist/core/shadow-observation-registry.js +280 -0
- package/dist/core/surface-guard.d.ts +31 -0
- package/dist/core/surface-guard.js +131 -0
- package/dist/core/system-logger.d.ts +8 -0
- package/{src/core/system-logger.ts → dist/core/system-logger.js} +20 -34
- package/dist/core/thinking-models.d.ts +70 -0
- package/dist/core/thinking-models.js +300 -0
- package/dist/core/thinking-os-parser.d.ts +35 -0
- package/dist/core/thinking-os-parser.js +123 -0
- package/dist/core/trajectory-types.d.ts +220 -0
- package/dist/core/trajectory-types.js +8 -0
- package/dist/core/trajectory.d.ts +242 -0
- package/dist/core/trajectory.js +1500 -0
- package/dist/core/workflow-funnel-loader.d.ts +72 -0
- package/dist/core/workflow-funnel-loader.js +135 -0
- package/dist/core/workspace-context.d.ts +111 -0
- package/{src/core/workspace-context.ts → dist/core/workspace-context.js} +50 -105
- package/dist/core/workspace-dir-validation.d.ts +11 -0
- package/dist/core/workspace-dir-validation.js +37 -0
- package/dist/core/workspace-guidance-migrator.d.ts +12 -0
- package/{src/core/workspace-guidance-migrator.ts → dist/core/workspace-guidance-migrator.js} +21 -59
- package/dist/hooks/after-tool-call-helpers.d.ts +89 -0
- package/dist/hooks/after-tool-call-helpers.js +475 -0
- package/dist/hooks/after-tool-call-types.d.ts +86 -0
- package/dist/hooks/after-tool-call-types.js +13 -0
- package/dist/hooks/gate-block-helper.d.ts +44 -0
- package/dist/hooks/gate-block-helper.js +209 -0
- package/dist/hooks/gate.d.ts +16 -0
- package/dist/hooks/gate.js +381 -0
- package/dist/hooks/lifecycle.d.ts +5 -0
- package/dist/hooks/lifecycle.js +287 -0
- package/dist/hooks/llm.d.ts +13 -0
- package/{src/hooks/llm.ts → dist/hooks/llm.js} +63 -117
- package/dist/hooks/message-sanitize.d.ts +24 -0
- package/dist/hooks/message-sanitize.js +77 -0
- package/dist/hooks/pain.d.ts +33 -0
- package/dist/hooks/pain.js +294 -0
- package/dist/hooks/prompt.d.ts +52 -0
- package/dist/hooks/prompt.js +930 -0
- package/dist/hooks/raw-observation-adapter.d.ts +57 -0
- package/dist/hooks/raw-observation-adapter.js +170 -0
- package/dist/hooks/raw-observation-types.d.ts +62 -0
- package/dist/hooks/raw-observation-types.js +15 -0
- package/dist/hooks/subagent.d.ts +9 -0
- package/{src/hooks/subagent.ts → dist/hooks/subagent.js} +20 -60
- package/dist/hooks/trajectory-collector.d.ts +25 -0
- package/dist/hooks/trajectory-collector.js +225 -0
- package/dist/hooks/trajectory-evidence.d.ts +11 -0
- package/dist/hooks/trajectory-evidence.js +88 -0
- package/dist/hooks/triage-adapter.d.ts +58 -0
- package/{src/hooks/triage-adapter.ts → dist/hooks/triage-adapter.js} +36 -68
- package/dist/hooks/trigger-cooldown-tracker.d.ts +30 -0
- package/dist/hooks/trigger-cooldown-tracker.js +55 -0
- package/dist/i18n/commands.d.ts +26 -0
- package/dist/i18n/commands.js +96 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +829 -0
- package/dist/openclaw-sdk.d.ts +293 -0
- package/dist/openclaw-sdk.js +4 -0
- package/dist/service/central-database.d.ts +138 -0
- package/dist/service/central-database.js +731 -0
- package/dist/service/central-sync-service.d.ts +8 -0
- package/dist/service/central-sync-service.js +71 -0
- package/dist/service/correction-observer-service.d.ts +19 -0
- package/{src/service/correction-observer-service.ts → dist/service/correction-observer-service.js} +36 -76
- package/dist/service/evolution-dedup.d.ts +27 -0
- package/{src/service/evolution-dedup.ts → dist/service/evolution-dedup.js} +11 -31
- package/{src/service/evolution-queue-migration.ts → dist/service/evolution-queue-migration.d.ts} +15 -62
- package/dist/service/evolution-queue-migration.js +53 -0
- package/dist/service/evolution-worker.d.ts +103 -0
- package/{src/service/evolution-worker.ts → dist/service/evolution-worker.js} +169 -331
- package/dist/service/internalization-auto-consumer-service.d.ts +8 -0
- package/dist/service/internalization-auto-consumer-service.js +322 -0
- package/dist/service/keyword-optimization-service.d.ts +44 -0
- package/dist/service/keyword-optimization-service.js +137 -0
- package/dist/service/phase3-input-filter.d.ts +73 -0
- package/dist/service/phase3-input-filter.js +172 -0
- package/dist/service/queue-io.d.ts +30 -0
- package/dist/service/queue-io.js +79 -0
- package/{src/service/queue-migration.ts → dist/service/queue-migration.d.ts} +6 -45
- package/dist/service/queue-migration.js +56 -0
- package/dist/service/runtime-summary-service.d.ts +158 -0
- package/dist/service/runtime-summary-service.js +636 -0
- package/dist/service/subagent-workflow/subagent-error-utils.d.ts +8 -0
- package/{src/service/subagent-workflow/subagent-error-utils.ts → dist/service/subagent-workflow/subagent-error-utils.js} +3 -6
- package/{src/service/subagent-workflow/types.ts → dist/service/subagent-workflow/types.d.ts} +17 -80
- package/dist/service/subagent-workflow/types.js +11 -0
- package/dist/service/subagent-workflow/workflow-store.d.ts +30 -0
- package/{src/service/subagent-workflow/workflow-store.ts → dist/service/subagent-workflow/workflow-store.js} +43 -108
- package/dist/service/trajectory-service.d.ts +2 -0
- package/dist/service/trajectory-service.js +16 -0
- package/dist/service/workflow-watchdog.d.ts +23 -0
- package/dist/service/workflow-watchdog.js +103 -0
- package/dist/types/event-types.d.ts +2 -0
- package/dist/types/event-types.js +1 -0
- package/dist/types/hygiene-types.d.ts +2 -0
- package/dist/types/hygiene-types.js +1 -0
- package/{src/types/principle-tree-schema.ts → dist/types/principle-tree-schema.d.ts} +2 -25
- package/dist/types/principle-tree-schema.js +24 -0
- package/dist/types/queue.d.ts +2 -0
- package/dist/types/queue.js +1 -0
- package/dist/types/runtime-summary.d.ts +1 -0
- package/dist/types/runtime-summary.js +1 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.js +16 -0
- package/dist/utils/file-lock.d.ts +68 -0
- package/dist/utils/file-lock.js +310 -0
- package/dist/utils/hashing.d.ts +9 -0
- package/{src/utils/hashing.ts → dist/utils/hashing.js} +4 -6
- package/dist/utils/io.d.ts +11 -0
- package/dist/utils/io.js +174 -0
- package/dist/utils/node-vm-polyfill.d.ts +9 -0
- package/{src/utils/node-vm-polyfill.ts → dist/utils/node-vm-polyfill.js} +0 -2
- package/dist/utils/retry.d.ts +210 -0
- package/dist/utils/retry.js +375 -0
- package/dist/utils/session-key.d.ts +10 -0
- package/{src/utils/session-key.ts → dist/utils/session-key.js} +5 -4
- package/dist/utils/shadow-fingerprint.d.ts +16 -0
- package/dist/utils/shadow-fingerprint.js +34 -0
- package/dist/utils/workspace-resolver.d.ts +82 -0
- package/dist/utils/workspace-resolver.js +288 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +8 -2
- package/templates/workspace/.principles/DECISION_POLICY.json +44 -0
- package/templates/workspace/.principles/PRINCIPLES.md +20 -0
- package/templates/workspace/.principles/PROFILE.json +54 -0
- package/templates/workspace/.principles/PROFILE.schema.json +56 -0
- package/templates/workspace/.principles/THINKING_OS.md +65 -0
- package/templates/workspace/.principles/THINKING_OS_ARCHIVE.md +7 -0
- package/templates/workspace/.principles/THINKING_OS_CANDIDATES.md +9 -0
- package/templates/workspace/.principles/models/_INDEX.md +27 -0
- package/templates/workspace/.principles/models/first_principles.md +62 -0
- package/templates/workspace/.principles/models/marketing_4p.md +52 -0
- package/templates/workspace/.principles/models/porter_five.md +63 -0
- package/templates/workspace/.principles/models/swot.md +60 -0
- package/templates/workspace/.principles/models/user_story_map.md +63 -0
- package/templates/workspace/.state/WORKBOARD.json +4 -0
- package/.dependency-cruiser.json +0 -19
- package/ADVANCED_CONFIG_ZH.md +0 -93
- package/AGENT_INSTALL.md +0 -173
- package/AGENT_INSTALL_EN.md +0 -173
- package/CHANGELOG.md +0 -26
- package/INSTALL.md +0 -254
- package/SKILL.md +0 -63
- package/esbuild.config.js +0 -104
- package/src/commands/archive-impl.ts +0 -147
- package/src/commands/capabilities.ts +0 -89
- package/src/commands/disable-impl.ts +0 -159
- package/src/commands/evolution-status.ts +0 -247
- package/src/commands/export.ts +0 -59
- package/src/commands/focus.ts +0 -523
- package/src/commands/principle-rollback.ts +0 -32
- package/src/commands/promote-impl.ts +0 -254
- package/src/commands/rollback-impl.ts +0 -246
- package/src/commands/samples.ts +0 -65
- package/src/commands/strategy.ts +0 -21
- package/src/config/errors.ts +0 -180
- package/src/constants/tools.ts +0 -62
- package/src/core/AGENTS.md +0 -34
- package/src/core/__tests__/focus-history.test.ts +0 -210
- package/src/core/bootstrap-rules.ts +0 -216
- package/src/core/code-implementation-storage.ts +0 -213
- package/src/core/config-health.ts +0 -72
- package/src/core/control-ui-db.ts +0 -454
- package/src/core/correction-cue-learner.ts +0 -239
- package/src/core/correction-types.ts +0 -16
- package/src/core/empathy-keyword-matcher.ts +0 -64
- package/src/core/empathy-types.ts +0 -18
- package/src/core/event-log.ts +0 -787
- package/src/core/evolution-engine.ts +0 -613
- package/src/core/evolution-logger.ts +0 -357
- package/src/core/evolution-migration.ts +0 -77
- package/src/core/evolution-reducer.ts +0 -891
- package/src/core/evolution-types.ts +0 -110
- package/src/core/external-training-contract.ts +0 -530
- package/src/core/file-store.ts +0 -80
- package/src/core/focus-history.ts +0 -763
- package/src/core/hygiene/tracker.ts +0 -122
- package/src/core/local-worker-routing.ts +0 -337
- package/src/core/model-deployment-registry.ts +0 -724
- package/src/core/model-training-registry.ts +0 -815
- package/src/core/observability.ts +0 -242
- package/src/core/pain-diagnostic-gate.ts +0 -169
- package/src/core/pain.ts +0 -309
- package/src/core/pd-config-loader.ts +0 -400
- package/src/core/pd-task-reconciler.ts +0 -380
- package/src/core/pd-task-service.ts +0 -43
- package/src/core/pd-task-store.ts +0 -78
- package/src/core/pd-task-types.ts +0 -24
- package/src/core/principle-compiler/__tests__/compiler-replay-gate.test.ts +0 -174
- package/src/core/principle-compiler/code-validator.ts +0 -96
- package/src/core/principle-compiler/compiler.ts +0 -327
- package/src/core/principle-compiler/ledger-registrar.ts +0 -116
- package/src/core/principle-internalization/filesystem-lifecycle-datasource.ts +0 -42
- package/src/core/principle-internalization/lifecycle-refresh.ts +0 -11
- package/src/core/principle-internalization/principle-lifecycle-service.ts +0 -170
- package/src/core/principle-training-state.ts +0 -177
- package/src/core/principle-tree-ledger-adapter.ts +0 -145
- package/src/core/principle-tree-ledger.ts +0 -725
- package/src/core/profile.ts +0 -228
- package/src/core/promotion-gate.ts +0 -854
- package/src/core/reflection/reflection-context.ts +0 -133
- package/src/core/replay-engine.ts +0 -106
- package/src/core/rule-host.ts +0 -386
- package/src/core/rule-implementation-runtime.ts +0 -145
- package/src/core/runtime-v2-prompt-activation-reader.ts +0 -114
- package/src/core/schema/migration-runner.ts +0 -207
- package/src/core/shadow-observation-registry.ts +0 -508
- package/src/core/surface-guard.ts +0 -188
- package/src/core/thinking-models.ts +0 -377
- package/src/core/thinking-os-parser.ts +0 -165
- package/src/core/trajectory-types.ts +0 -247
- package/src/core/trajectory.ts +0 -1831
- package/src/core/workflow-funnel-loader.ts +0 -195
- package/src/core/workspace-dir-validation.ts +0 -52
- package/src/hooks/AGENTS.md +0 -31
- package/src/hooks/after-tool-call-helpers.ts +0 -601
- package/src/hooks/after-tool-call-types.ts +0 -99
- package/src/hooks/gate-block-helper.ts +0 -265
- package/src/hooks/gate.ts +0 -394
- package/src/hooks/lifecycle.ts +0 -334
- package/src/hooks/message-sanitize.ts +0 -102
- package/src/hooks/pain.ts +0 -358
- package/src/hooks/prompt.ts +0 -1102
- package/src/hooks/raw-observation-adapter.ts +0 -215
- package/src/hooks/raw-observation-types.ts +0 -77
- package/src/hooks/trajectory-collector.ts +0 -253
- package/src/hooks/trajectory-evidence.ts +0 -97
- package/src/hooks/trigger-cooldown-tracker.ts +0 -82
- package/src/i18n/commands.ts +0 -101
- package/src/index.ts +0 -939
- package/src/openclaw-sdk.ts +0 -312
- package/src/service/central-database.ts +0 -936
- package/src/service/central-sync-service.ts +0 -85
- package/src/service/internalization-auto-consumer-service.ts +0 -397
- package/src/service/keyword-optimization-service.ts +0 -169
- package/src/service/phase3-input-filter.ts +0 -237
- package/src/service/queue-io.ts +0 -108
- package/src/service/runtime-summary-service.ts +0 -990
- package/src/service/trajectory-service.ts +0 -16
- package/src/service/workflow-watchdog.ts +0 -125
- package/src/types/event-types.ts +0 -39
- package/src/types/hygiene-types.ts +0 -8
- package/src/types/queue.ts +0 -15
- package/src/types/runtime-summary.ts +0 -5
- package/src/types.ts +0 -53
- package/src/utils/file-lock.ts +0 -394
- package/src/utils/io.ts +0 -176
- package/src/utils/retry.ts +0 -573
- package/src/utils/shadow-fingerprint.ts +0 -42
- package/src/utils/workspace-resolver.ts +0 -393
- package/tests/README.md +0 -120
- package/tests/build-artifacts.test.ts +0 -55
- package/tests/commands/evolution-status.test.ts +0 -511
- package/tests/commands/export.test.ts +0 -78
- package/tests/commands/pain.test.ts +0 -287
- package/tests/commands/samples.test.ts +0 -65
- package/tests/commands/strategy.test.ts +0 -19
- package/tests/commands/thinking-os.test.ts +0 -88
- package/tests/core/bootstrap-rules.test.ts +0 -596
- package/tests/core/code-implementation-storage.test.ts +0 -300
- package/tests/core/code-validator.test.ts +0 -197
- package/tests/core/config-service.test.ts +0 -89
- package/tests/core/config.test.ts +0 -90
- package/tests/core/control-ui-db.test.ts +0 -75
- package/tests/core/core-principle-registry-drift.test.ts +0 -39
- package/tests/core/core-template-guidance.test.ts +0 -21
- package/tests/core/correction-cue-learner.test.ts +0 -345
- package/tests/core/detection-service.test.ts +0 -50
- package/tests/core/dictionary-service.test.ts +0 -116
- package/tests/core/dictionary.test.ts +0 -171
- package/tests/core/empathy-keyword-matcher.test.ts +0 -209
- package/tests/core/event-log.test.ts +0 -484
- package/tests/core/evolution-engine.test.ts +0 -610
- package/tests/core/evolution-logger.test.ts +0 -148
- package/tests/core/evolution-migration.test.ts +0 -374
- package/tests/core/evolution-paths.test.ts +0 -21
- package/tests/core/evolution-reducer.compilation-retry.test.ts +0 -189
- package/tests/core/evolution-reducer.detector-metadata.test.ts +0 -602
- package/tests/core/evolution-types-loop.test.ts +0 -48
- package/tests/core/external-training-contract.test.ts +0 -463
- package/tests/core/file-store.test.ts +0 -102
- package/tests/core/focus-history.test.ts +0 -874
- package/tests/core/init-flatten.test.ts +0 -69
- package/tests/core/init-refactor.test.ts +0 -87
- package/tests/core/init-v1.3.test.ts +0 -46
- package/tests/core/init.test.ts +0 -190
- package/tests/core/ledger-registrar.test.ts +0 -235
- package/tests/core/migration.test.ts +0 -84
- package/tests/core/model-deployment-registry.test.ts +0 -858
- package/tests/core/model-training-registry.test.ts +0 -908
- package/tests/core/observability.test.ts +0 -382
- package/tests/core/pain-diagnostic-gate.test.ts +0 -614
- package/tests/core/pain-score.property.test.ts +0 -19
- package/tests/core/pain.test.ts +0 -132
- package/tests/core/path-resolver.test.ts +0 -57
- package/tests/core/paths-refactor.test.ts +0 -20
- package/tests/core/pd-config-loader.test.ts +0 -407
- package/tests/core/pd-task-store.test.ts +0 -126
- package/tests/core/phase7-rollout-integration.test.ts +0 -477
- package/tests/core/principle-compiler.test.ts +0 -350
- package/tests/core/principle-injection.test.ts +0 -223
- package/tests/core/principle-internalization/deprecated-readiness.test.ts +0 -193
- package/tests/core/principle-internalization/lifecycle-metrics.test.ts +0 -350
- package/tests/core/principle-internalization/lifecycle-routing-policy.test.ts +0 -212
- package/tests/core/principle-internalization/lineage-source-retired.test.ts +0 -56
- package/tests/core/principle-internalization/principle-lifecycle-service.test.ts +0 -189
- package/tests/core/principle-training-state.test.ts +0 -939
- package/tests/core/principle-tree-ledger-adapter.test.ts +0 -253
- package/tests/core/principle-tree-ledger.test.ts +0 -423
- package/tests/core/profile.test.ts +0 -56
- package/tests/core/promotion-gate.test.ts +0 -561
- package/tests/core/queue-purge.test.ts +0 -337
- package/tests/core/reflection-context.test.ts +0 -342
- package/tests/core/regression-v1-9-1.test.ts +0 -266
- package/tests/core/replay-engine.test.ts +0 -165
- package/tests/core/risk-calculator.test.ts +0 -168
- package/tests/core/rule-host-adversarial-output.test.ts +0 -242
- package/tests/core/rule-host-autocorrect-vm.test.ts +0 -163
- package/tests/core/rule-host-helpers.test.ts +0 -120
- package/tests/core/rule-host-resource-bounds.test.ts +0 -231
- package/tests/core/rule-host-sqlite-source.test.ts +0 -720
- package/tests/core/rule-host-unhealthy-visibility.test.ts +0 -261
- package/tests/core/rule-host-validation.test.ts +0 -315
- package/tests/core/rule-implementation-runtime.test.ts +0 -49
- package/tests/core/session-tracker.test.ts +0 -191
- package/tests/core/surface-guard.test.ts +0 -338
- package/tests/core/template-generator.test.ts +0 -101
- package/tests/core/trajectory.test.ts +0 -427
- package/tests/core/workflow-funnel-loader.test.ts +0 -1028
- package/tests/core/workspace-context-factory.test.ts +0 -18
- package/tests/core/workspace-context.test.ts +0 -187
- package/tests/core/workspace-guidance-migrator.test.ts +0 -248
- package/tests/core-anti-growth.test.ts +0 -182
- package/tests/evolution-worker-quarantine.test.ts +0 -400
- package/tests/evolution-worker-slimming.test.ts +0 -380
- package/tests/fixtures/legacy-queue-v1.json +0 -74
- package/tests/fixtures/production-compatibility.test.ts +0 -147
- package/tests/fixtures/production-mock-generator.ts +0 -282
- package/tests/globalSetup.ts +0 -38
- package/tests/hook-workspace-nextaction-contract.test.ts +0 -50
- package/tests/hooks/confirm-first-removal.test.ts +0 -188
- package/tests/hooks/gate-auto-correct-shadow.test.ts +0 -309
- package/tests/hooks/gate-auto-correct.test.ts +0 -664
- package/tests/hooks/gate-block-helper-profile.test.ts +0 -186
- package/tests/hooks/gate-no-path-write-tool.test.ts +0 -171
- package/tests/hooks/gate-rule-host-pipeline.test.ts +0 -230
- package/tests/hooks/gate-rule-host-real-pipeline.test.ts +0 -190
- package/tests/hooks/lifecycle.test.ts +0 -248
- package/tests/hooks/message-sanitize.test.ts +0 -244
- package/tests/hooks/pain-emission-characterization.test.ts +0 -420
- package/tests/hooks/pain.test.ts +0 -795
- package/tests/hooks/prompt-characterization.test.ts +0 -476
- package/tests/hooks/prompt-diet.test.ts +0 -335
- package/tests/hooks/prompt-size-guard.test.ts +0 -319
- package/tests/hooks/raw-observation-adapter.test.ts +0 -312
- package/tests/hooks/runtime-v2-prompt-activation.test.ts +0 -895
- package/tests/hooks/single-gate-pain-admission.test.ts +0 -258
- package/tests/hooks/subagent.test.ts +0 -469
- package/tests/hooks/trajectory-collector.test.ts +0 -269
- package/tests/hooks/trajectory-evidence.test.ts +0 -280
- package/tests/hooks/triage-adapter.test.ts +0 -331
- package/tests/hygiene-tracker.test.ts +0 -77
- package/tests/index.test.ts +0 -142
- package/tests/integration/auto-entry-gate.test.ts +0 -256
- package/tests/integration/gate-real-io.e2e.test.ts +0 -248
- package/tests/integration/m8-legacy-paths.test.ts +0 -63
- package/tests/integration/mvp-surface-registry-guard.test.ts +0 -536
- package/tests/integration/pain-id-chain-e2e.test.ts +0 -313
- package/tests/integration/principle-compiler-e2e.test.ts +0 -403
- package/tests/integration/principle-lifecycle.e2e.test.ts +0 -198
- package/tests/integration/runtime-v2-pain-guard.test.ts +0 -125
- package/tests/integration/trajectory-lifecycle.e2e.test.ts +0 -523
- package/tests/internalization-auto-consumer-gate.test.ts +0 -158
- package/tests/internalization-auto-consumer-service.test.ts +0 -219
- package/tests/plugin-config-resolution-cutover.test.ts +0 -359
- package/tests/queue/async-lock.test.ts +0 -200
- package/tests/runtime-v2-discovery-guard.test.ts +0 -153
- package/tests/scripts/validate-live-path.test.ts +0 -286
- package/tests/service/central-database.test.ts +0 -457
- package/tests/service/correction-observer-service.test.ts +0 -505
- package/tests/service/evolution-worker.compilation-backfill.test.ts +0 -203
- package/tests/service/evolution-worker.correction-observer.test.ts +0 -50
- package/tests/service/evolution-worker.queue.test.ts +0 -296
- package/tests/service/evolution-worker.timeout.test.ts +0 -233
- package/tests/service/keyword-optimization-service.test.ts +0 -121
- package/tests/service/phase3-input-filter.test.ts +0 -289
- package/tests/service/queue-io.test.ts +0 -168
- package/tests/service/queue-migration.test.ts +0 -147
- package/tests/service/runtime-summary-service.test.ts +0 -1100
- package/tests/service/workflow-watchdog.test.ts +0 -281
- package/tests/task-compliance.test.ts +0 -166
- package/tests/test-utils.ts +0 -48
- package/tests/utils/file-lock.test.ts +0 -409
- package/tests/utils/hashing.test.ts +0 -32
- package/tests/utils/hook-workspace-resolver.test.ts +0 -524
- package/tests/utils/io.test.ts +0 -39
- package/tests/utils/retry.test.ts +0 -327
- package/tests/utils/session-key.test.ts +0 -52
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -61
- package/vitest.unit.config.ts +0 -12
package/dist/index.js
ADDED
|
@@ -0,0 +1,829 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { loadFeatureFlagFromConfig } from './core/pd-config-loader.js';
|
|
3
|
+
import { checkConversationAccessConfig, getPluginEntry } from './core/config-health.js';
|
|
4
|
+
export { checkConversationAccessConfig, getPluginEntry } from './core/config-health.js';
|
|
5
|
+
import { classifyTask } from './core/local-worker-routing.js';
|
|
6
|
+
import { completeShadowObservation, recordShadowRouting } from './core/shadow-observation-registry.js';
|
|
7
|
+
import { getCommandDescription } from './i18n/commands.js';
|
|
8
|
+
import { WorkspaceContext } from './core/workspace-context.js';
|
|
9
|
+
import { handleBeforePromptBuild } from './hooks/prompt.js';
|
|
10
|
+
import { handleBeforeToolCall } from './hooks/gate.js';
|
|
11
|
+
import { handleAfterToolCall } from './hooks/pain.js';
|
|
12
|
+
import { handleBeforeReset, handleBeforeCompaction, handleAfterCompaction } from './hooks/lifecycle.js';
|
|
13
|
+
import { handleLlmOutput } from './hooks/llm.js';
|
|
14
|
+
import * as TrajectoryCollector from './hooks/trajectory-collector.js';
|
|
15
|
+
import { handleSubagentEnded } from './hooks/subagent.js';
|
|
16
|
+
import { handleInitStrategy } from './commands/strategy.js';
|
|
17
|
+
import { handleBootstrapTools, handleResearchTools } from './commands/capabilities.js';
|
|
18
|
+
import { handleThinkingOs } from './commands/thinking-os.js';
|
|
19
|
+
import { handlePainCommand, handlePainReportCommand } from './commands/pain.js';
|
|
20
|
+
import { handleContextCommand } from './commands/context.js';
|
|
21
|
+
import { handleFocusCommand } from './commands/focus.js';
|
|
22
|
+
import { handleRollbackCommand } from './commands/rollback.js';
|
|
23
|
+
import { handlePromoteImplCommand } from './commands/promote-impl.js';
|
|
24
|
+
import { handleDisableImplCommand } from './commands/disable-impl.js';
|
|
25
|
+
import { handleArchiveImplCommand } from './commands/archive-impl.js';
|
|
26
|
+
import { handleRollbackImplCommand } from './commands/rollback-impl.js';
|
|
27
|
+
import { handleEvolutionStatusCommand } from './commands/evolution-status.js';
|
|
28
|
+
import { handlePrincipleRollbackCommand } from './commands/principle-rollback.js';
|
|
29
|
+
import { handleExportCommand } from './commands/export.js';
|
|
30
|
+
import { handleSamplesCommand } from './commands/samples.js';
|
|
31
|
+
import { handleWorkflowDebugCommand } from './commands/workflow-debug.js';
|
|
32
|
+
import { EvolutionWorkerService } from './service/evolution-worker.js';
|
|
33
|
+
import { CorrectionObserverService } from './service/correction-observer-service.js';
|
|
34
|
+
import { InternalizationAutoConsumerService } from './service/internalization-auto-consumer-service.js';
|
|
35
|
+
import { TrajectoryService } from './service/trajectory-service.js';
|
|
36
|
+
import { PDTaskService } from './core/pd-task-service.js';
|
|
37
|
+
import { CentralSyncService } from './service/central-sync-service.js';
|
|
38
|
+
import { ensureWorkspaceTemplates } from './core/init.js';
|
|
39
|
+
import { migrateDirectoryStructure } from './core/migration.js';
|
|
40
|
+
import { migrateStaleWorkspaceGuidance } from './core/workspace-guidance-migrator.js';
|
|
41
|
+
import { SystemLogger } from './core/system-logger.js';
|
|
42
|
+
import { PathResolver } from './core/path-resolver.js';
|
|
43
|
+
import { resolveCommandWorkspaceDir, resolveToolHookWorkspaceDirSafe, resolveHookWorkspaceDir } from './utils/workspace-resolver.js';
|
|
44
|
+
import { computeRuntimeShadowTaskFingerprint, PD_LOCAL_PROFILES } from './utils/shadow-fingerprint.js';
|
|
45
|
+
import { validateWorkspaceDir } from './core/workspace-dir-validation.js';
|
|
46
|
+
import { resolveWorkspaceDirFromApi } from './core/path-resolver.js';
|
|
47
|
+
import { checkSurfaceGuard, guardHook, guardService } from './core/surface-guard.js';
|
|
48
|
+
// Track started workspaces — one-time init + evolution worker per workspace
|
|
49
|
+
const startedWorkspaces = new Set();
|
|
50
|
+
// Map from childSessionKey → shadowObservationId
|
|
51
|
+
// Used to complete shadow observations when subagent ends
|
|
52
|
+
const pendingShadowObservations = new Map();
|
|
53
|
+
// ── Conversation Access Health Check (PRI-343) ────────────────────────────
|
|
54
|
+
// Re-exported from core/config-health.ts for backward compatibility.
|
|
55
|
+
// Implementation moved to avoid circular imports with trajectory-collector.ts.
|
|
56
|
+
// ── Feature Flag Loader (plugin I/O boundary) ─────────────────────────────
|
|
57
|
+
// Reads workspace feature-flags.yaml and checks a specific flag.
|
|
58
|
+
// Returns the flag definition with effective enabled state.
|
|
59
|
+
function isRecord(value) {
|
|
60
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* PRI-305/PRI-307: Load feature flag from .pd/config.yaml instead of .pd/feature-flags.yaml.
|
|
64
|
+
* Delegates to the shared plugin config loader for consistency.
|
|
65
|
+
*/
|
|
66
|
+
function loadFeatureFlagFromWorkspace(workspaceDir, flagId, logger) {
|
|
67
|
+
return loadFeatureFlagFromConfig(workspaceDir, flagId, logger);
|
|
68
|
+
}
|
|
69
|
+
export function shouldStartEvolutionWorker(workspaceDir, logger) {
|
|
70
|
+
const flag = loadFeatureFlagFromWorkspace(workspaceDir, 'evolution_worker', logger);
|
|
71
|
+
if (flag.enabled) {
|
|
72
|
+
return { shouldStart: true, flagSource: flag.source, disabledInfo: null };
|
|
73
|
+
}
|
|
74
|
+
const disabledInfo = JSON.stringify({
|
|
75
|
+
reason: 'mvp_quiet_per_adr0014',
|
|
76
|
+
nextAction: 'set features.evolution_worker.enabled=true in .pd/config.yaml to enable',
|
|
77
|
+
featureFlag: 'evolution_worker',
|
|
78
|
+
boundedContext: 'legacy_evolution_worker',
|
|
79
|
+
flagSource: flag.source,
|
|
80
|
+
});
|
|
81
|
+
return { shouldStart: false, flagSource: flag.source, disabledInfo };
|
|
82
|
+
}
|
|
83
|
+
export function shouldStartCorrectionObserver(workspaceDir, logger) {
|
|
84
|
+
const flag = loadFeatureFlagFromWorkspace(workspaceDir, 'correction_observer', logger);
|
|
85
|
+
if (flag.enabled) {
|
|
86
|
+
return { shouldStart: true, flagSource: flag.source, disabledInfo: null };
|
|
87
|
+
}
|
|
88
|
+
const disabledInfo = JSON.stringify({
|
|
89
|
+
reason: 'correction_observer_disabled',
|
|
90
|
+
nextAction: 'set features.correction_observer.enabled=true in .pd/config.yaml to enable',
|
|
91
|
+
featureFlag: 'correction_observer',
|
|
92
|
+
boundedContext: 'correction_observer_service',
|
|
93
|
+
flagSource: flag.source,
|
|
94
|
+
});
|
|
95
|
+
return { shouldStart: false, flagSource: flag.source, disabledInfo };
|
|
96
|
+
}
|
|
97
|
+
export function shouldStartInternalizationAutoConsumer(workspaceDir, logger) {
|
|
98
|
+
const flag = loadFeatureFlagFromWorkspace(workspaceDir, 'internalization_auto_consumer', logger);
|
|
99
|
+
if (flag.enabled) {
|
|
100
|
+
return { shouldStart: true, flagSource: flag.source, disabledInfo: null };
|
|
101
|
+
}
|
|
102
|
+
const disabledInfo = JSON.stringify({
|
|
103
|
+
reason: 'internalization_auto_consumer_disabled',
|
|
104
|
+
nextAction: `pd runtime internalization run-once --workspace "${workspaceDir}" --runner dreamer --runtime config --json`,
|
|
105
|
+
featureFlag: 'internalization_auto_consumer',
|
|
106
|
+
boundedContext: 'internalization_auto_consumer',
|
|
107
|
+
flagSource: flag.source,
|
|
108
|
+
});
|
|
109
|
+
return { shouldStart: false, flagSource: flag.source, disabledInfo };
|
|
110
|
+
}
|
|
111
|
+
const plugin = {
|
|
112
|
+
name: "Principles Disciple",
|
|
113
|
+
description: "Evolutionary programming agent framework with strategic guardrails and reflection loops.",
|
|
114
|
+
register(api) {
|
|
115
|
+
api.logger.info(`Principles Disciple Plugin registered. (Path: ${api.rootDir ?? '(unknown)'})`);
|
|
116
|
+
PathResolver.setExtensionRoot(api.rootDir ?? '.');
|
|
117
|
+
// ── Startup Health Check: Verify workspaceDir resolution ──
|
|
118
|
+
// Catches OpenClaw context bugs early (e.g., missing workspaceDir in tool hooks)
|
|
119
|
+
const healthCheckTimer = setTimeout(() => {
|
|
120
|
+
const testCtx = { agentId: 'main' };
|
|
121
|
+
const toolWorkspaceDir = resolveToolHookWorkspaceDirSafe(testCtx, api, 'startup.health_check');
|
|
122
|
+
const toolIssue = validateWorkspaceDir(toolWorkspaceDir);
|
|
123
|
+
if (toolIssue) {
|
|
124
|
+
api.logger.error(`[PD:health] Tool hook workspaceDir is INVALID: "${toolWorkspaceDir}" - ${toolIssue}`);
|
|
125
|
+
api.logger.error(`[PD:health] Tool hook events will be written to the WRONG .state directory!`);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
api.logger.info(`[PD:health] Tool hook workspaceDir OK: "${toolWorkspaceDir}"`);
|
|
129
|
+
}
|
|
130
|
+
// PRI-343: Check allowConversationAccess — warn if llm_output/trajectory hooks blocked
|
|
131
|
+
const accessCheck = checkConversationAccessConfig(getPluginEntry(api.config, api.id));
|
|
132
|
+
if (!accessCheck.authorized) {
|
|
133
|
+
api.logger.error(`[PD:health] conversation hooks (llm_output / trajectory) will be BLOCKED by OpenClaw.\n` +
|
|
134
|
+
` reason: ${accessCheck.reason}\n` +
|
|
135
|
+
` nextAction: ${accessCheck.nextAction}`);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
api.logger.info(`[PD:health] conversation hooks (allowConversationAccess) OK`);
|
|
139
|
+
}
|
|
140
|
+
}, 1000);
|
|
141
|
+
healthCheckTimer.unref(); // Don't keep process alive for health check
|
|
142
|
+
// ── MVP Surface Guard (PRI-289): Verify surface classification ──
|
|
143
|
+
const surfaceGuard = checkSurfaceGuard();
|
|
144
|
+
if (!surfaceGuard.passed) {
|
|
145
|
+
for (const violation of surfaceGuard.violations) {
|
|
146
|
+
api.logger.error(`[PD:surface-guard] VIOLATION: ${violation}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
api.logger.info(`[PD:surface-guard] Core surfaces: ${surfaceGuard.enabledCoreSurfaces.join(', ')}`);
|
|
150
|
+
api.logger.info(`[PD:surface-guard] Disabled non-core surfaces: ${surfaceGuard.disabledNonCoreSurfaces.length}`);
|
|
151
|
+
for (const warning of surfaceGuard.warnings) {
|
|
152
|
+
api.logger.warn(`[PD:surface-guard] ${warning}`);
|
|
153
|
+
}
|
|
154
|
+
const language = api.pluginConfig?.language || 'en';
|
|
155
|
+
// ── Hook: Prompt Building ──
|
|
156
|
+
api.on('before_prompt_build', guardHook('hook:before_prompt_build', api.logger, async (event, ctx) => {
|
|
157
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'before_prompt_build');
|
|
158
|
+
if (!wsResult.ok) {
|
|
159
|
+
api.logger.error(`[PD:before_prompt_build] workspaceDir resolution failed. ` +
|
|
160
|
+
`reason=${wsResult.reason} agentId=${ctx.agentId ?? '(missing)'} sessionId=${ctx.sessionId ?? '(missing)'}. ` +
|
|
161
|
+
`Hook skipped — no mutation will occur. ` +
|
|
162
|
+
`NextAction: ${wsResult.nextAction}`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const workspaceDir = wsResult.workspaceDir;
|
|
166
|
+
if (wsResult.consistencyWarning) {
|
|
167
|
+
api.logger.warn(`[PD:before_prompt_build] ${wsResult.consistencyWarning}`);
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
if (!startedWorkspaces.has(workspaceDir)) {
|
|
171
|
+
startedWorkspaces.add(workspaceDir);
|
|
172
|
+
migrateDirectoryStructure(api, workspaceDir);
|
|
173
|
+
migrateStaleWorkspaceGuidance(api, workspaceDir);
|
|
174
|
+
ensureWorkspaceTemplates(api, workspaceDir, language);
|
|
175
|
+
SystemLogger.log(workspaceDir, 'SYSTEM_BOOT', `Principles Disciple online. Language: ${language}`);
|
|
176
|
+
// ── Start EvolutionWorker for THIS workspace ──
|
|
177
|
+
// Gated behind evolution_worker feature flag (MVP-Quiet, default OFF per ADR-0014).
|
|
178
|
+
const gate = shouldStartEvolutionWorker(workspaceDir, api.logger);
|
|
179
|
+
if (gate.shouldStart) {
|
|
180
|
+
EvolutionWorkerService.api = api;
|
|
181
|
+
EvolutionWorkerService.start({
|
|
182
|
+
config: api.config,
|
|
183
|
+
workspaceDir,
|
|
184
|
+
stateDir: path.join(workspaceDir, '.state'),
|
|
185
|
+
logger: api.logger,
|
|
186
|
+
});
|
|
187
|
+
api.logger.info(`[PD] EvolutionWorker started for workspace: ${workspaceDir} (flag source: ${gate.flagSource})`);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// Structured observability per ERR-002: no silent skip
|
|
191
|
+
api.logger.info(`[PD] EvolutionWorker NOT started for workspace: ${workspaceDir}. ${gate.disabledInfo}`);
|
|
192
|
+
SystemLogger.log(workspaceDir, 'EVOLUTION_WORKER_DISABLED', gate.disabledInfo ?? '');
|
|
193
|
+
}
|
|
194
|
+
// ── Start CorrectionObserver for THIS workspace ──
|
|
195
|
+
// MVP-Core per ADR-0014 amendment, independently owned (PRI-293).
|
|
196
|
+
const corrGate = shouldStartCorrectionObserver(workspaceDir, api.logger);
|
|
197
|
+
if (corrGate.shouldStart) {
|
|
198
|
+
CorrectionObserverService.start({
|
|
199
|
+
config: api.config,
|
|
200
|
+
workspaceDir,
|
|
201
|
+
stateDir: path.join(workspaceDir, '.state'),
|
|
202
|
+
logger: api.logger,
|
|
203
|
+
});
|
|
204
|
+
api.logger.info(`[PD] CorrectionObserver started for workspace: ${workspaceDir} (flag source: ${corrGate.flagSource})`);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
api.logger.info(`[PD] CorrectionObserver NOT started for workspace: ${workspaceDir}. ${corrGate.disabledInfo}`);
|
|
208
|
+
SystemLogger.log(workspaceDir, 'CORRECTION_OBSERVER_DISABLED', corrGate.disabledInfo ?? '');
|
|
209
|
+
}
|
|
210
|
+
// ── Start InternalizationAutoConsumer for THIS workspace ──
|
|
211
|
+
// PRI-381: Bounded auto-consumer for dreamer ready tasks.
|
|
212
|
+
// Default ON for dogfood; kill switch via features.internalization_auto_consumer.enabled=false.
|
|
213
|
+
const autoConsGate = shouldStartInternalizationAutoConsumer(workspaceDir, api.logger);
|
|
214
|
+
if (autoConsGate.shouldStart) {
|
|
215
|
+
InternalizationAutoConsumerService.start({
|
|
216
|
+
config: api.config,
|
|
217
|
+
workspaceDir,
|
|
218
|
+
stateDir: path.join(workspaceDir, '.state'),
|
|
219
|
+
logger: api.logger,
|
|
220
|
+
});
|
|
221
|
+
api.logger.info(`[PD] InternalizationAutoConsumer started for workspace: ${workspaceDir} (flag source: ${autoConsGate.flagSource})`);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
api.logger.info(`[PD] InternalizationAutoConsumer NOT started for workspace: ${workspaceDir}. ${autoConsGate.disabledInfo}`);
|
|
225
|
+
SystemLogger.log(workspaceDir, 'INTERNALIZATION_CONSUMER_DISABLED', autoConsGate.disabledInfo ?? '');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const result = await handleBeforePromptBuild(event, { ...ctx, api: api, workspaceDir });
|
|
229
|
+
// Record success
|
|
230
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
231
|
+
hook: 'before_prompt_build',
|
|
232
|
+
sessionId: ctx.sessionId
|
|
233
|
+
});
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
238
|
+
hook: 'before_prompt_build',
|
|
239
|
+
sessionId: ctx.sessionId,
|
|
240
|
+
error: String(err)
|
|
241
|
+
});
|
|
242
|
+
api.logger.error(`[PD] Error in before_prompt_build: ${String(err)}`);
|
|
243
|
+
}
|
|
244
|
+
}));
|
|
245
|
+
// ── Hook: Security Gate ──
|
|
246
|
+
api.on('before_tool_call', guardHook('hook:before_tool_call', api.logger, (event, ctx) => {
|
|
247
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'before_tool_call');
|
|
248
|
+
if (!wsResult.ok) {
|
|
249
|
+
api.logger.error(`[PD:before_tool_call] workspaceDir resolution failed. ` +
|
|
250
|
+
`reason=${wsResult.reason} agentId=${ctx.agentId ?? '(missing)'} sessionId=${ctx.sessionId ?? '(missing)'}. ` +
|
|
251
|
+
`Hook skipped — security gate bypassed. ` +
|
|
252
|
+
`NextAction: ${wsResult.nextAction}`);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const workspaceDir = wsResult.workspaceDir;
|
|
256
|
+
if (wsResult.consistencyWarning) {
|
|
257
|
+
api.logger.warn(`[PD:before_tool_call] ${wsResult.consistencyWarning}`);
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
const pluginConfig = api.pluginConfig ?? {};
|
|
261
|
+
const { logger } = api;
|
|
262
|
+
const result = handleBeforeToolCall(event, { ...ctx, workspaceDir, pluginConfig, logger });
|
|
263
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
264
|
+
hook: 'before_tool_call'
|
|
265
|
+
}, { flushImmediately: true });
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
270
|
+
hook: 'before_tool_call',
|
|
271
|
+
error: String(err)
|
|
272
|
+
}, { flushImmediately: true });
|
|
273
|
+
api.logger.error(`[PD] Error in before_tool_call: ${String(err)}`);
|
|
274
|
+
}
|
|
275
|
+
}));
|
|
276
|
+
// ── Hook: Pain & Trust ──
|
|
277
|
+
api.on('after_tool_call', guardHook('hook:after_tool_call', api.logger, (event, ctx) => {
|
|
278
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'after_tool_call');
|
|
279
|
+
if (!wsResult.ok) {
|
|
280
|
+
api.logger.error(`[PD:after_tool_call] workspaceDir resolution failed. ` +
|
|
281
|
+
`reason=${wsResult.reason} agentId=${ctx.agentId ?? '(missing)'} sessionId=${ctx.sessionId ?? '(missing)'}. ` +
|
|
282
|
+
`Hook skipped — pain detection bypassed. ` +
|
|
283
|
+
`NextAction: ${wsResult.nextAction}`);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const workspaceDir = wsResult.workspaceDir;
|
|
287
|
+
if (wsResult.consistencyWarning) {
|
|
288
|
+
api.logger.warn(`[PD:after_tool_call] ${wsResult.consistencyWarning}`);
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const pluginConfig = api.pluginConfig ?? {};
|
|
292
|
+
// Pass api separately to handleAfterToolCall to maintain type safety
|
|
293
|
+
handleAfterToolCall(event, { ...ctx, workspaceDir, pluginConfig }, api);
|
|
294
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
295
|
+
hook: 'after_tool_call'
|
|
296
|
+
}, { flushImmediately: true });
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
300
|
+
hook: 'after_tool_call',
|
|
301
|
+
error: String(err)
|
|
302
|
+
}, { flushImmediately: true });
|
|
303
|
+
api.logger.error(`[PD:EmpathyObserver] Error in after_tool_call: ${String(err)}`);
|
|
304
|
+
}
|
|
305
|
+
}));
|
|
306
|
+
// ── Hook: LLM Analysis ──
|
|
307
|
+
api.on('llm_output', guardHook('hook:llm_output', api.logger, (event, ctx) => {
|
|
308
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'llm_output');
|
|
309
|
+
if (!wsResult.ok) {
|
|
310
|
+
api.logger.error(`[PD:llm_output] workspaceDir resolution failed. ` +
|
|
311
|
+
`reason=${wsResult.reason} agentId=${ctx.agentId ?? '(missing)'} ` +
|
|
312
|
+
`sessionId=${ctx.sessionId ?? '(missing)'}. ` +
|
|
313
|
+
`Hook skipped — LLM analysis bypassed. ` +
|
|
314
|
+
`NextAction: ${wsResult.nextAction}`);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const workspaceDir = wsResult.workspaceDir;
|
|
318
|
+
if (wsResult.consistencyWarning) {
|
|
319
|
+
api.logger.warn(`[PD:llm_output] ${wsResult.consistencyWarning}`);
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
handleLlmOutput(event, { ...ctx, workspaceDir });
|
|
323
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
324
|
+
hook: 'llm_output',
|
|
325
|
+
sessionId: ctx.sessionId
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
catch (err) {
|
|
329
|
+
WorkspaceContext.fromHookContext({ workspaceDir }).eventLog.recordHookExecution({
|
|
330
|
+
hook: 'llm_output',
|
|
331
|
+
sessionId: ctx.sessionId,
|
|
332
|
+
error: String(err)
|
|
333
|
+
});
|
|
334
|
+
api.logger.error(`[PD] Error in llm_output: ${String(err)}`);
|
|
335
|
+
}
|
|
336
|
+
}));
|
|
337
|
+
// ── Hook: Subagent Loop Closure ──
|
|
338
|
+
api.on('subagent_spawning', guardHook('hook:subagent_spawning', api.logger, (event, _ctx) => {
|
|
339
|
+
try {
|
|
340
|
+
// FIX (B): Never fall back to '.' — fail-fast with ERROR log if workspaceDir cannot be resolved.
|
|
341
|
+
// For subagent hooks, we use event.agentId as the target agent for workspace resolution.
|
|
342
|
+
const workspaceDir = resolveWorkspaceDirFromApi(api, event.agentId);
|
|
343
|
+
if (!workspaceDir) {
|
|
344
|
+
api.logger.error(`[PD] subagent_spawning: cannot resolve workspaceDir for agent "${event.agentId}" — skipping shadow routing`);
|
|
345
|
+
return { status: 'ok' };
|
|
346
|
+
}
|
|
347
|
+
api.logger?.debug?.(`[PD] workspaceDir resolved for subagent_spawning: ${workspaceDir}`);
|
|
348
|
+
const { agentId, childSessionKey } = event;
|
|
349
|
+
// Only handle PD local worker profiles
|
|
350
|
+
if (!PD_LOCAL_PROFILES.has(agentId)) {
|
|
351
|
+
return { status: 'ok' };
|
|
352
|
+
}
|
|
353
|
+
// Use the real runtime hook to record shadow evidence. We still consult the
|
|
354
|
+
// routing/deployment state here, but the observation itself must originate
|
|
355
|
+
// from actual subagent execution rather than an operator command path.
|
|
356
|
+
const routingInput = { targetProfile: agentId };
|
|
357
|
+
const decision = classifyTask(routingInput, workspaceDir);
|
|
358
|
+
const shouldRecordShadow = decision.activeCheckpointState === 'shadow_ready' &&
|
|
359
|
+
!!decision.activeCheckpointId &&
|
|
360
|
+
decision.deploymentCheck.routingEnabled &&
|
|
361
|
+
decision.deploymentCheck.checkpointDeployable;
|
|
362
|
+
if (shouldRecordShadow) {
|
|
363
|
+
const observation = recordShadowRouting(workspaceDir, {
|
|
364
|
+
checkpointId: decision.activeCheckpointId,
|
|
365
|
+
workerProfile: agentId,
|
|
366
|
+
taskFingerprint: computeRuntimeShadowTaskFingerprint(event),
|
|
367
|
+
});
|
|
368
|
+
pendingShadowObservations.set(childSessionKey, observation.observationId);
|
|
369
|
+
}
|
|
370
|
+
return { status: 'ok' };
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
api.logger.error(`[PD] Error in subagent_spawning shadow routing: ${String(err)}`);
|
|
374
|
+
return { status: 'ok' }; // Don't block spawn on shadow observation errors
|
|
375
|
+
}
|
|
376
|
+
}));
|
|
377
|
+
api.on('subagent_ended', guardHook('hook:subagent_ended', api.logger, (event, ctx) => {
|
|
378
|
+
try {
|
|
379
|
+
// FIX (B): Never fall back to '.' — fail-fast with ERROR log if workspaceDir cannot be resolved.
|
|
380
|
+
const workspaceDir = resolveWorkspaceDirFromApi(api, undefined);
|
|
381
|
+
if (!workspaceDir) {
|
|
382
|
+
api.logger.error(`[PD] subagent_ended: cannot resolve workspaceDir — skipping shadow observation completion`);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
api.logger?.debug?.(`[PD] workspaceDir resolved for subagent_ended: ${workspaceDir}`);
|
|
386
|
+
// Complete any pending shadow observation for this subagent session
|
|
387
|
+
const shadowObsId = pendingShadowObservations.get(event.targetSessionKey);
|
|
388
|
+
if (shadowObsId && workspaceDir) {
|
|
389
|
+
try {
|
|
390
|
+
const outcome = event.outcome === 'ok'
|
|
391
|
+
? 'accepted'
|
|
392
|
+
: event.outcome === 'error'
|
|
393
|
+
? 'rejected'
|
|
394
|
+
: 'escalated';
|
|
395
|
+
completeShadowObservation(workspaceDir, {
|
|
396
|
+
observationId: shadowObsId,
|
|
397
|
+
outcome,
|
|
398
|
+
failureSignals: event.outcome === 'error' ? { threwException: true, timedOut: false, invalidOutput: false, profileRejected: false, extra: {} } : undefined,
|
|
399
|
+
});
|
|
400
|
+
pendingShadowObservations.delete(event.targetSessionKey);
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
api.logger.error(`[PD] Failed to complete shadow observation: ${String(err)}`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
handleSubagentEnded(event, { ...ctx, workspaceDir, api });
|
|
407
|
+
}
|
|
408
|
+
catch (err) {
|
|
409
|
+
api.logger.error(`[PD] Error in subagent_ended: ${String(err)}`);
|
|
410
|
+
}
|
|
411
|
+
}));
|
|
412
|
+
// ── Hook: Lifecycle ──
|
|
413
|
+
api.on('before_reset', guardHook('hook:before_reset', api.logger, (event, ctx) => {
|
|
414
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'before_reset');
|
|
415
|
+
if (!wsResult.ok) {
|
|
416
|
+
api.logger.error(`[PD:before_reset] workspaceDir resolution failed. ` +
|
|
417
|
+
`reason=${wsResult.reason} agentId=${ctx.agentId ?? '(missing)'} sessionId=${ctx.sessionId ?? '(missing)'}. ` +
|
|
418
|
+
`Hook skipped. NextAction: ${wsResult.nextAction}`);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (wsResult.consistencyWarning) {
|
|
422
|
+
api.logger.warn(`[PD:before_reset] ${wsResult.consistencyWarning}`);
|
|
423
|
+
}
|
|
424
|
+
return handleBeforeReset(event, { ...ctx, workspaceDir: wsResult.workspaceDir });
|
|
425
|
+
}));
|
|
426
|
+
api.on('before_compaction', guardHook('hook:before_compaction', api.logger, (event, ctx) => {
|
|
427
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'before_compaction');
|
|
428
|
+
if (!wsResult.ok) {
|
|
429
|
+
api.logger.error(`[PD:before_compaction] workspaceDir resolution failed. ` +
|
|
430
|
+
`reason=${wsResult.reason} agentId=${ctx.agentId ?? '(missing)'} sessionId=${ctx.sessionId ?? '(missing)'}. ` +
|
|
431
|
+
`Hook skipped. NextAction: ${wsResult.nextAction}`);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (wsResult.consistencyWarning) {
|
|
435
|
+
api.logger.warn(`[PD:before_compaction] ${wsResult.consistencyWarning}`);
|
|
436
|
+
}
|
|
437
|
+
return handleBeforeCompaction(event, { ...ctx, workspaceDir: wsResult.workspaceDir });
|
|
438
|
+
}));
|
|
439
|
+
api.on('after_compaction', guardHook('hook:after_compaction', api.logger, (event, ctx) => {
|
|
440
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'after_compaction');
|
|
441
|
+
if (!wsResult.ok) {
|
|
442
|
+
api.logger.error(`[PD:after_compaction] workspaceDir resolution failed. ` +
|
|
443
|
+
`reason=${wsResult.reason} agentId=${ctx.agentId ?? '(missing)'} sessionId=${ctx.sessionId ?? '(missing)'}. ` +
|
|
444
|
+
`Hook skipped. NextAction: ${wsResult.nextAction}`);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (wsResult.consistencyWarning) {
|
|
448
|
+
api.logger.warn(`[PD:after_compaction] ${wsResult.consistencyWarning}`);
|
|
449
|
+
}
|
|
450
|
+
return handleAfterCompaction(event, { ...ctx, workspaceDir: wsResult.workspaceDir });
|
|
451
|
+
}));
|
|
452
|
+
// ── Hook: Before Message Write (PRI-346) ──
|
|
453
|
+
// Fallback trajectory collection when llm_output is blocked by
|
|
454
|
+
// missing allowConversationAccess. Not in CONVERSATION_HOOK_NAMES
|
|
455
|
+
// so OpenClaw always delivers it.
|
|
456
|
+
api.on('before_message_write', guardHook('hook:before_message_write', api.logger, (event, ctx) => {
|
|
457
|
+
const wsResult = resolveHookWorkspaceDir(ctx, api, 'before_message_write');
|
|
458
|
+
if (!wsResult.ok) {
|
|
459
|
+
api.logger.warn(`[PD:before_message_write] workspaceDir resolution failed: ${wsResult.reason}`);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
try {
|
|
463
|
+
TrajectoryCollector.handleBeforeMessageWrite(event, {
|
|
464
|
+
...ctx,
|
|
465
|
+
workspaceDir: wsResult.workspaceDir,
|
|
466
|
+
pluginConfig: getPluginEntry(api.config, api.id),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
catch (err) {
|
|
470
|
+
// Non-critical: don't surface to user
|
|
471
|
+
api.logger.warn(`[PD:before_message_write] error: ${String(err)}`);
|
|
472
|
+
}
|
|
473
|
+
}));
|
|
474
|
+
// ── Service Registration (surface-guarded) ──
|
|
475
|
+
// PRI-294: EvolutionWorker service registration removed — it starts via
|
|
476
|
+
// before_prompt_build hook gate, not via api.registerService. The surface
|
|
477
|
+
// guard already prevents registration when disabled (enabledByDefault=false).
|
|
478
|
+
// Dead pre-assignment of EvolutionWorkerService.api removed.
|
|
479
|
+
try {
|
|
480
|
+
const guardedCorrectionObserver = guardService('service:correction-observer', CorrectionObserverService, api.logger);
|
|
481
|
+
if (guardedCorrectionObserver)
|
|
482
|
+
api.registerService(guardedCorrectionObserver);
|
|
483
|
+
const guardedTrajectory = guardService('service:trajectory', TrajectoryService, api.logger);
|
|
484
|
+
if (guardedTrajectory)
|
|
485
|
+
api.registerService(guardedTrajectory);
|
|
486
|
+
const guardedPdTask = guardService('service:pd-task', PDTaskService, api.logger);
|
|
487
|
+
if (guardedPdTask)
|
|
488
|
+
api.registerService(guardedPdTask);
|
|
489
|
+
const guardedCentralSync = guardService('service:central-sync', CentralSyncService, api.logger);
|
|
490
|
+
if (guardedCentralSync)
|
|
491
|
+
api.registerService(guardedCentralSync);
|
|
492
|
+
const guardedAutoConsumer = guardService('service:internalization-auto-consumer', InternalizationAutoConsumerService, api.logger);
|
|
493
|
+
if (guardedAutoConsumer)
|
|
494
|
+
api.registerService(guardedAutoConsumer);
|
|
495
|
+
}
|
|
496
|
+
catch (err) {
|
|
497
|
+
api.logger.error(`[PD] Failed to register services: ${String(err)}`);
|
|
498
|
+
}
|
|
499
|
+
// ── Slash Commands ──
|
|
500
|
+
// Register command with optional short alias
|
|
501
|
+
const registerCommandWithAlias = (name, alias, desc, handler, opts) => {
|
|
502
|
+
const base = {
|
|
503
|
+
name,
|
|
504
|
+
description: desc,
|
|
505
|
+
handler,
|
|
506
|
+
...(opts?.acceptsArgs ? { acceptsArgs: true } : {}),
|
|
507
|
+
};
|
|
508
|
+
api.registerCommand(base);
|
|
509
|
+
if (alias) {
|
|
510
|
+
api.registerCommand({
|
|
511
|
+
...base,
|
|
512
|
+
name: alias,
|
|
513
|
+
description: `${desc} (alias of /${name})`,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
registerCommandWithAlias('pd-init', 'pdi', getCommandDescription('pd-init', language), (ctx) => handleInitStrategy(ctx));
|
|
518
|
+
registerCommandWithAlias('pd-bootstrap', 'pdb', getCommandDescription('pd-bootstrap', language), (ctx) => handleBootstrapTools(ctx));
|
|
519
|
+
registerCommandWithAlias('pd-research', 'pdr', getCommandDescription('pd-research', language), (ctx) => handleResearchTools(ctx));
|
|
520
|
+
registerCommandWithAlias('pd-thinking', 'pdt', getCommandDescription('pd-thinking', language), (ctx) => handleThinkingOs(ctx), { acceptsArgs: true });
|
|
521
|
+
registerCommandWithAlias('pd-help', 'pdh', getCommandDescription('pd-help', language), () => {
|
|
522
|
+
if (language === 'zh') {
|
|
523
|
+
return { text: `
|
|
524
|
+
📖 **Principles Disciple 命令大全**
|
|
525
|
+
|
|
526
|
+
## 快速开始
|
|
527
|
+
| 短命令 | 长命令 | 用途 |
|
|
528
|
+
|--------|--------|------|
|
|
529
|
+
| \`/pdi\` | \`/pd-init\` | 初始化工作区 |
|
|
530
|
+
| \`/pdb\` | \`/pd-bootstrap\` | 环境工具扫描 |
|
|
531
|
+
| \`/pdr\` | \`/pd-research\` | 研究工具方案 |
|
|
532
|
+
|
|
533
|
+
## 状态查询
|
|
534
|
+
| 短命令 | 长命令 | 用途 |
|
|
535
|
+
|--------|--------|------|
|
|
536
|
+
| \`/pdt\` | \`/pd-thinking\` | 思维模型管理 |
|
|
537
|
+
|
|
538
|
+
## 其他命令
|
|
539
|
+
| 命令 | 用途 |
|
|
540
|
+
|------|------|
|
|
541
|
+
| \`/pd-status\` | 查看系统状态 |
|
|
542
|
+
| \`/pd-context\` | 控制上下文注入 |
|
|
543
|
+
| \`/pd-focus\` | 焦点文件管理 |
|
|
544
|
+
| \`/pd-export\` | 导出数据 |
|
|
545
|
+
| \`/pd-samples\` | 审核纠错样本 |
|
|
546
|
+
| \`/pd-rollback\` | 回滚情绪事件惩罚 |
|
|
547
|
+
| \`/pd-principle-rollback\` | 回滚原则 |
|
|
548
|
+
| \`/pd-help\` | 显示本帮助 |
|
|
549
|
+
`.trim() };
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
return { text: `
|
|
553
|
+
📖 **Principles Disciple Command Reference**
|
|
554
|
+
|
|
555
|
+
## Quick Start
|
|
556
|
+
| Short | Full | Purpose |
|
|
557
|
+
|-------|------|---------|
|
|
558
|
+
| \`/pdi\` | \`/pd-init\` | Initialize workspace |
|
|
559
|
+
| \`/pdb\` | \`/pd-bootstrap\` | Scan environment tools |
|
|
560
|
+
| \`/pdr\` | \`/pd-research\` | Research tool solutions |
|
|
561
|
+
|
|
562
|
+
## Status
|
|
563
|
+
| Short | Full | Purpose |
|
|
564
|
+
|-------|------|---------|
|
|
565
|
+
| \`/pdt\` | \`/pd-thinking\` | Mental model management |
|
|
566
|
+
|
|
567
|
+
## Other Commands
|
|
568
|
+
| Command | Purpose |
|
|
569
|
+
|---------|---------|
|
|
570
|
+
| \`/pd-status\` | View system status |
|
|
571
|
+
| \`/pd-context\` | Control context injection |
|
|
572
|
+
| \`/pd-focus\` | Focus file management |
|
|
573
|
+
| \`/pd-export\` | Export data |
|
|
574
|
+
| \`/pd-samples\` | Review correction samples |
|
|
575
|
+
| \`/pd-rollback\` | Rollback empathy penalty |
|
|
576
|
+
| \`/pd-principle-rollback\` | Rollback principle |
|
|
577
|
+
| \`/pd-help\` | Show this help |
|
|
578
|
+
`.trim() };
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
api.registerCommand({
|
|
582
|
+
name: "pd-status",
|
|
583
|
+
description: getCommandDescription('pd-status', language),
|
|
584
|
+
acceptsArgs: true,
|
|
585
|
+
handler: (ctx) => {
|
|
586
|
+
try {
|
|
587
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
588
|
+
// Ensure workspaceDir is in config for handlePainCommand
|
|
589
|
+
if (ctx.config)
|
|
590
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
591
|
+
return handlePainCommand(ctx);
|
|
592
|
+
}
|
|
593
|
+
catch (err) {
|
|
594
|
+
api.logger.error(`[PD] Command /pd-status failed: ${String(err)}`);
|
|
595
|
+
return { text: language === 'zh' ? "命令执行失败,请检查日志。" : "Command failed. Check logs." };
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
api.registerCommand({
|
|
600
|
+
name: "pd-pain",
|
|
601
|
+
description: language === 'zh'
|
|
602
|
+
? '从 OpenClaw 会话中报告 pain(context-bound provenance)'
|
|
603
|
+
: 'Report pain from OpenClaw session (context-bound provenance)',
|
|
604
|
+
acceptsArgs: true,
|
|
605
|
+
handler: async (ctx) => {
|
|
606
|
+
try {
|
|
607
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
608
|
+
ctx.workspaceDir = workspaceDir;
|
|
609
|
+
if (ctx.config)
|
|
610
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
611
|
+
return await handlePainReportCommand(ctx);
|
|
612
|
+
}
|
|
613
|
+
catch (err) {
|
|
614
|
+
api.logger.error(`[PD] Command /pd-pain failed: ${String(err)}`);
|
|
615
|
+
return { text: language === 'zh' ? "命令执行失败,请检查日志。" : "Command failed. Check logs." };
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
api.registerCommand({
|
|
620
|
+
name: "pd-context",
|
|
621
|
+
description: getCommandDescription('pd-context', language),
|
|
622
|
+
acceptsArgs: true,
|
|
623
|
+
handler: (ctx) => {
|
|
624
|
+
try {
|
|
625
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
626
|
+
if (ctx.config)
|
|
627
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
628
|
+
return handleContextCommand(ctx);
|
|
629
|
+
}
|
|
630
|
+
catch (err) {
|
|
631
|
+
api.logger.error(`[PD] Command /pd-context failed: ${String(err)}`);
|
|
632
|
+
return { text: language === 'zh' ? "命令执行失败,请检查日志。" : "Command failed. Check logs." };
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
api.registerCommand({
|
|
637
|
+
name: "pd-focus",
|
|
638
|
+
description: getCommandDescription('pd-focus', language),
|
|
639
|
+
acceptsArgs: true,
|
|
640
|
+
handler: (ctx) => {
|
|
641
|
+
try {
|
|
642
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
643
|
+
if (ctx.config)
|
|
644
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
645
|
+
return handleFocusCommand(ctx, api);
|
|
646
|
+
}
|
|
647
|
+
catch (err) {
|
|
648
|
+
api.logger.error(`[PD] Command /pd-focus failed: ${String(err)}`);
|
|
649
|
+
return { text: language === 'zh' ? "命令执行失败,请检查日志。" : "Command failed. Check logs." };
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
api.registerCommand({
|
|
654
|
+
name: "pd-evolution-status",
|
|
655
|
+
description: getCommandDescription('pd-evolution-status', language),
|
|
656
|
+
handler: (ctx) => {
|
|
657
|
+
try {
|
|
658
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
659
|
+
if (ctx.config)
|
|
660
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
661
|
+
return handleEvolutionStatusCommand(ctx);
|
|
662
|
+
}
|
|
663
|
+
catch (err) {
|
|
664
|
+
api.logger.error(`[PD] Command /pd-evolution-status failed: ${String(err)}`);
|
|
665
|
+
return { text: language === 'zh' ? "命令执行失败,请检查日志。" : "Command failed. Check logs." };
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
api.registerCommand({
|
|
670
|
+
name: "pd-principle-rollback",
|
|
671
|
+
description: getCommandDescription('pd-principle-rollback', language),
|
|
672
|
+
acceptsArgs: true,
|
|
673
|
+
handler: (ctx) => {
|
|
674
|
+
try {
|
|
675
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
676
|
+
if (ctx.config)
|
|
677
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
678
|
+
return handlePrincipleRollbackCommand(ctx);
|
|
679
|
+
}
|
|
680
|
+
catch (err) {
|
|
681
|
+
api.logger.error(`[PD] Command /pd-principle-rollback failed: ${String(err)}`);
|
|
682
|
+
return { text: language === 'zh' ? "命令执行失败,请检查日志。" : "Command failed. Check logs." };
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
api.registerCommand({
|
|
687
|
+
name: "pd-rollback",
|
|
688
|
+
description: getCommandDescription('pd-rollback', language),
|
|
689
|
+
acceptsArgs: true,
|
|
690
|
+
handler: (ctx) => {
|
|
691
|
+
try {
|
|
692
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
693
|
+
if (ctx.config)
|
|
694
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
695
|
+
return handleRollbackCommand(ctx);
|
|
696
|
+
}
|
|
697
|
+
catch (err) {
|
|
698
|
+
api.logger.error(`[PD] Command /pd-rollback failed: ${String(err)}`);
|
|
699
|
+
return { text: language === 'zh' ? "命令执行失败,请检查日志。" : "Command failed. Check logs." };
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
// ── Tools ──
|
|
704
|
+
api.registerCommand({
|
|
705
|
+
name: "pd-export",
|
|
706
|
+
description: getCommandDescription('pd-export', language),
|
|
707
|
+
acceptsArgs: true,
|
|
708
|
+
handler: (ctx) => {
|
|
709
|
+
try {
|
|
710
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
711
|
+
if (ctx.config)
|
|
712
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
713
|
+
return handleExportCommand(ctx);
|
|
714
|
+
}
|
|
715
|
+
catch (err) {
|
|
716
|
+
api.logger.error(`[PD] Command /pd-export failed: ${String(err)}`);
|
|
717
|
+
return { text: language === 'zh' ? "导出失败,请检查日志。" : "Export failed. Check logs." };
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
api.registerCommand({
|
|
722
|
+
name: "pd-samples",
|
|
723
|
+
description: getCommandDescription('pd-samples', language),
|
|
724
|
+
acceptsArgs: true,
|
|
725
|
+
handler: (ctx) => {
|
|
726
|
+
try {
|
|
727
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
728
|
+
if (ctx.config)
|
|
729
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
730
|
+
return handleSamplesCommand(ctx);
|
|
731
|
+
}
|
|
732
|
+
catch (err) {
|
|
733
|
+
api.logger.error(`[PD] Command /pd-samples failed: ${String(err)}`);
|
|
734
|
+
return { text: language === 'zh' ? "样本命令执行失败,请检查日志。" : "Samples command failed. Check logs." };
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
api.registerCommand({
|
|
739
|
+
name: "pd-workflow-debug",
|
|
740
|
+
description: 'Debug helper workflow state and events [workflowId]',
|
|
741
|
+
acceptsArgs: true,
|
|
742
|
+
handler: (ctx) => {
|
|
743
|
+
try {
|
|
744
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
745
|
+
if (ctx.config)
|
|
746
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
747
|
+
return handleWorkflowDebugCommand(ctx);
|
|
748
|
+
}
|
|
749
|
+
catch (err) {
|
|
750
|
+
api.logger.error(`[PD] Command /pd-workflow-debug failed: ${String(err)}`);
|
|
751
|
+
return { text: `Workflow debug command failed: ${String(err)}` };
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
// ── Implementation Lifecycle Commands (Phase 13) ──
|
|
756
|
+
api.registerCommand({
|
|
757
|
+
name: "pd-promote-impl",
|
|
758
|
+
description: 'Promote a candidate implementation to active [list|show <id>|<id>]',
|
|
759
|
+
acceptsArgs: true,
|
|
760
|
+
handler: (ctx) => {
|
|
761
|
+
try {
|
|
762
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
763
|
+
if (ctx.config)
|
|
764
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
765
|
+
return handlePromoteImplCommand(ctx);
|
|
766
|
+
}
|
|
767
|
+
catch (err) {
|
|
768
|
+
api.logger.error(`[PD] Command /pd-promote-impl failed: ${String(err)}`);
|
|
769
|
+
return { text: language === 'zh' ? '\u547d\u4ee4\u6267\u884c\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u65e5\u5fd7\u3002' : 'Command failed. Check logs.' };
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
api.registerCommand({
|
|
774
|
+
name: "pd-disable-impl",
|
|
775
|
+
description: 'Disable an active implementation [list|<id> --reason "..."]',
|
|
776
|
+
acceptsArgs: true,
|
|
777
|
+
handler: (ctx) => {
|
|
778
|
+
try {
|
|
779
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
780
|
+
if (ctx.config)
|
|
781
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
782
|
+
return handleDisableImplCommand(ctx);
|
|
783
|
+
}
|
|
784
|
+
catch (err) {
|
|
785
|
+
api.logger.error(`[PD] Command /pd-disable-impl failed: ${String(err)}`);
|
|
786
|
+
return { text: language === 'zh' ? '\u547d\u4ee4\u6267\u884c\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u65e5\u5fd7\u3002' : 'Command failed. Check logs.' };
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
api.registerCommand({
|
|
791
|
+
name: "pd-archive-impl",
|
|
792
|
+
description: 'Archive an implementation permanently [list|<id>]',
|
|
793
|
+
acceptsArgs: true,
|
|
794
|
+
handler: (ctx) => {
|
|
795
|
+
try {
|
|
796
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
797
|
+
if (ctx.config)
|
|
798
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
799
|
+
return handleArchiveImplCommand(ctx);
|
|
800
|
+
}
|
|
801
|
+
catch (err) {
|
|
802
|
+
api.logger.error(`[PD] Command /pd-archive-impl failed: ${String(err)}`);
|
|
803
|
+
return { text: language === 'zh' ? '\u547d\u4ee4\u6267\u884c\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u65e5\u5fd7\u3002' : 'Command failed. Check logs.' };
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
api.registerCommand({
|
|
808
|
+
name: "pd-rollback-impl",
|
|
809
|
+
description: 'Rollback current active implementation to previous active [list|<id> --reason "..."]',
|
|
810
|
+
acceptsArgs: true,
|
|
811
|
+
handler: (ctx) => {
|
|
812
|
+
try {
|
|
813
|
+
const workspaceDir = resolveCommandWorkspaceDir(api, ctx);
|
|
814
|
+
if (ctx.config)
|
|
815
|
+
ctx.config.workspaceDir = workspaceDir;
|
|
816
|
+
return handleRollbackImplCommand(ctx);
|
|
817
|
+
}
|
|
818
|
+
catch (err) {
|
|
819
|
+
api.logger.error(`[PD] Command /pd-rollback-impl failed: ${String(err)}`);
|
|
820
|
+
return { text: language === 'zh' ? '\u547d\u4ee4\u6267\u884c\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u65e5\u5fd7\u3002' : 'Command failed. Check logs.' };
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
export { PrincipleTreeLedgerAdapter } from './core/principle-tree-ledger-adapter.js';
|
|
827
|
+
/* istanbul ignore next — test exports for evolution worker gate */
|
|
828
|
+
export { loadFeatureFlagFromWorkspace, isRecord };
|
|
829
|
+
export default plugin;
|