create-principles-disciple 1.112.3 → 1.114.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.
Files changed (220) hide show
  1. package/console/dist/server/routes/update.js +43 -0
  2. package/core/dist/runtime-v2/__tests__/activation-compatibility-read-model.test.d.ts +2 -0
  3. package/core/dist/runtime-v2/__tests__/activation-compatibility-read-model.test.d.ts.map +1 -0
  4. package/core/dist/runtime-v2/__tests__/activation-compatibility-read-model.test.js +148 -0
  5. package/core/dist/runtime-v2/__tests__/activation-compatibility-read-model.test.js.map +1 -0
  6. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +6 -5
  7. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  8. package/core/dist/runtime-v2/__tests__/golden-trace.test.js +2 -2
  9. package/core/dist/runtime-v2/__tests__/golden-trace.test.js.map +1 -1
  10. package/core/dist/runtime-v2/__tests__/internalization-contracts.test.js +4 -6
  11. package/core/dist/runtime-v2/__tests__/internalization-contracts.test.js.map +1 -1
  12. package/core/dist/runtime-v2/__tests__/rule-host-evaluator.test.js +4 -4
  13. package/core/dist/runtime-v2/__tests__/rule-host-evaluator.test.js.map +1 -1
  14. package/core/dist/runtime-v2/__tests__/story-a-demo.test.js +8 -8
  15. package/core/dist/runtime-v2/__tests__/story-a-demo.test.js.map +1 -1
  16. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js +31 -0
  17. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
  18. package/core/dist/runtime-v2/activation-compatibility-read-model.d.ts +24 -0
  19. package/core/dist/runtime-v2/activation-compatibility-read-model.d.ts.map +1 -0
  20. package/core/dist/runtime-v2/activation-compatibility-read-model.js +132 -0
  21. package/core/dist/runtime-v2/activation-compatibility-read-model.js.map +1 -0
  22. package/core/dist/runtime-v2/config/__tests__/pd-validate-profile-legacy-keys.test.d.ts +13 -0
  23. package/core/dist/runtime-v2/config/__tests__/pd-validate-profile-legacy-keys.test.d.ts.map +1 -0
  24. package/core/dist/runtime-v2/config/__tests__/pd-validate-profile-legacy-keys.test.js +73 -0
  25. package/core/dist/runtime-v2/config/__tests__/pd-validate-profile-legacy-keys.test.js.map +1 -0
  26. package/core/dist/runtime-v2/config/pd-config-types.d.ts +0 -23
  27. package/core/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
  28. package/core/dist/runtime-v2/config/pd-config-types.js.map +1 -1
  29. package/core/dist/runtime-v2/config/pd-profile-constants.d.ts +11 -5
  30. package/core/dist/runtime-v2/config/pd-profile-constants.d.ts.map +1 -1
  31. package/core/dist/runtime-v2/config/pd-profile-constants.js +10 -45
  32. package/core/dist/runtime-v2/config/pd-profile-constants.js.map +1 -1
  33. package/core/dist/runtime-v2/config/pd-validate-profile.d.ts.map +1 -1
  34. package/core/dist/runtime-v2/config/pd-validate-profile.js +27 -135
  35. package/core/dist/runtime-v2/config/pd-validate-profile.js.map +1 -1
  36. package/core/dist/runtime-v2/core-principles/core-principle-registry.d.ts +4 -4
  37. package/core/dist/runtime-v2/core-principles/core-principle-registry.d.ts.map +1 -1
  38. package/core/dist/runtime-v2/core-principles/core-principle-registry.js +2 -2
  39. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  40. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +8 -0
  41. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  42. package/core/dist/runtime-v2/golden-trace-replay-validator.d.ts.map +1 -1
  43. package/core/dist/runtime-v2/golden-trace-replay-validator.js +0 -2
  44. package/core/dist/runtime-v2/golden-trace-replay-validator.js.map +1 -1
  45. package/core/dist/runtime-v2/golden-trace.d.ts.map +1 -1
  46. package/core/dist/runtime-v2/golden-trace.js +0 -3
  47. package/core/dist/runtime-v2/golden-trace.js.map +1 -1
  48. package/core/dist/runtime-v2/index.d.ts +7 -5
  49. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  50. package/core/dist/runtime-v2/index.js +6 -5
  51. package/core/dist/runtime-v2/index.js.map +1 -1
  52. package/core/dist/runtime-v2/internalization/__tests__/artificer-output-retry-flag.test.d.ts +2 -0
  53. package/core/dist/runtime-v2/internalization/__tests__/artificer-output-retry-flag.test.d.ts.map +1 -0
  54. package/core/dist/runtime-v2/internalization/__tests__/artificer-output-retry-flag.test.js +95 -0
  55. package/core/dist/runtime-v2/internalization/__tests__/artificer-output-retry-flag.test.js.map +1 -0
  56. package/core/dist/runtime-v2/internalization/__tests__/external-review-p0-regressions.test.js +2 -2
  57. package/core/dist/runtime-v2/internalization/__tests__/external-review-p0-regressions.test.js.map +1 -1
  58. package/core/dist/runtime-v2/internalization/__tests__/internalization-transition-decision.test.js.map +1 -1
  59. package/core/dist/runtime-v2/internalization/__tests__/legacy-rule-contract-scanner.test.d.ts +2 -0
  60. package/core/dist/runtime-v2/internalization/__tests__/legacy-rule-contract-scanner.test.d.ts.map +1 -0
  61. package/core/dist/runtime-v2/internalization/__tests__/legacy-rule-contract-scanner.test.js +101 -0
  62. package/core/dist/runtime-v2/internalization/__tests__/legacy-rule-contract-scanner.test.js.map +1 -0
  63. package/core/dist/runtime-v2/internalization/__tests__/mvp-core-loop-journeys.test.js +28 -28
  64. package/core/dist/runtime-v2/internalization/__tests__/mvp-core-loop-journeys.test.js.map +1 -1
  65. package/core/dist/runtime-v2/internalization/artificer-runner.d.ts +25 -1
  66. package/core/dist/runtime-v2/internalization/artificer-runner.d.ts.map +1 -1
  67. package/core/dist/runtime-v2/internalization/artificer-runner.js +37 -3
  68. package/core/dist/runtime-v2/internalization/artificer-runner.js.map +1 -1
  69. package/core/dist/runtime-v2/internalization/index.d.ts +2 -0
  70. package/core/dist/runtime-v2/internalization/index.d.ts.map +1 -1
  71. package/core/dist/runtime-v2/internalization/index.js +1 -0
  72. package/core/dist/runtime-v2/internalization/index.js.map +1 -1
  73. package/core/dist/runtime-v2/internalization/legacy-rule-contract-scanner.d.ts +51 -0
  74. package/core/dist/runtime-v2/internalization/legacy-rule-contract-scanner.d.ts.map +1 -0
  75. package/core/dist/runtime-v2/internalization/legacy-rule-contract-scanner.js +81 -0
  76. package/core/dist/runtime-v2/internalization/legacy-rule-contract-scanner.js.map +1 -0
  77. package/core/dist/runtime-v2/internalization/refiner-sandbox-wrapper.d.ts.map +1 -1
  78. package/core/dist/runtime-v2/internalization/refiner-sandbox-wrapper.js +0 -2
  79. package/core/dist/runtime-v2/internalization/refiner-sandbox-wrapper.js.map +1 -1
  80. package/core/dist/runtime-v2/internalization/rule-host-contracts.d.ts +0 -3
  81. package/core/dist/runtime-v2/internalization/rule-host-contracts.d.ts.map +1 -1
  82. package/core/dist/runtime-v2/internalization/rule-host-helpers.d.ts +4 -2
  83. package/core/dist/runtime-v2/internalization/rule-host-helpers.d.ts.map +1 -1
  84. package/core/dist/runtime-v2/internalization/rule-host-helpers.js +4 -2
  85. package/core/dist/runtime-v2/internalization/rule-host-helpers.js.map +1 -1
  86. package/core/dist/runtime-v2/pain-signal-observability.js +3 -3
  87. package/core/dist/runtime-v2/pain-signal-observability.js.map +1 -1
  88. package/core/dist/runtime-v2/story-a-demo.d.ts.map +1 -1
  89. package/core/dist/runtime-v2/story-a-demo.js +2 -0
  90. package/core/dist/runtime-v2/story-a-demo.js.map +1 -1
  91. package/core/dist/runtime-v2/tools/artificer-l2-tool-contract.d.ts.map +1 -1
  92. package/core/dist/runtime-v2/tools/artificer-l2-tool-contract.js +0 -4
  93. package/core/dist/runtime-v2/tools/artificer-l2-tool-contract.js.map +1 -1
  94. package/core/dist/runtime-v2/types/event-payload.d.ts +1 -20
  95. package/core/dist/runtime-v2/types/event-payload.d.ts.map +1 -1
  96. package/core/dist/runtime-v2/types/event-payload.js +0 -12
  97. package/core/dist/runtime-v2/types/event-payload.js.map +1 -1
  98. package/core/dist/runtime-v2/types/event-types.d.ts +3 -18
  99. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  100. package/core/dist/runtime-v2/types/event-types.js +0 -8
  101. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  102. package/core/dist/runtime-v2/types/index.d.ts +3 -3
  103. package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
  104. package/core/dist/runtime-v2/types/index.js +2 -2
  105. package/core/dist/runtime-v2/types/index.js.map +1 -1
  106. package/dist/installer.d.ts +49 -0
  107. package/dist/installer.d.ts.map +1 -1
  108. package/dist/installer.js +215 -3
  109. package/dist/installer.js.map +1 -1
  110. package/host-runtime/dist/legacy-rule-contract-symbols.d.ts +20 -0
  111. package/host-runtime/dist/legacy-rule-contract-symbols.js +37 -0
  112. package/host-runtime/dist/production-rulehost-gate.d.ts +0 -1
  113. package/host-runtime/dist/production-rulehost-gate.js +29 -5
  114. package/host-runtime/dist/rule-implementation-runtime.js +0 -2
  115. package/package.json +2 -2
  116. package/pd-cli/dist/commands/demo-story-a.d.ts +2 -0
  117. package/pd-cli/dist/commands/demo-story-a.d.ts.map +1 -1
  118. package/pd-cli/dist/commands/demo-story-a.js +41 -0
  119. package/pd-cli/dist/commands/demo-story-a.js.map +1 -1
  120. package/pd-cli/dist/commands/runtime-compatibility-scan.d.ts +32 -0
  121. package/pd-cli/dist/commands/runtime-compatibility-scan.d.ts.map +1 -0
  122. package/pd-cli/dist/commands/runtime-compatibility-scan.js +94 -0
  123. package/pd-cli/dist/commands/runtime-compatibility-scan.js.map +1 -0
  124. package/pd-cli/dist/commands/runtime-init.d.ts +6 -0
  125. package/pd-cli/dist/commands/runtime-init.d.ts.map +1 -1
  126. package/pd-cli/dist/commands/runtime-init.js +127 -2
  127. package/pd-cli/dist/commands/runtime-init.js.map +1 -1
  128. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  129. package/pd-cli/dist/commands/runtime-internalization-run-once.js +6 -1
  130. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  131. package/pd-cli/dist/index.js +4 -0
  132. package/pd-cli/dist/index.js.map +1 -1
  133. package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  134. package/pd-cli/dist/services/rulehost-pipeline-runner.js +6 -1
  135. package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
  136. package/plugin/dist/bundle.js +529 -750
  137. package/plugin/dist/core/event-log.d.ts +1 -2
  138. package/plugin/dist/core/paths.d.ts +0 -2
  139. package/plugin/dist/core/profile.d.ts +0 -19
  140. package/plugin/dist/core/rule-host.d.ts +19 -0
  141. package/plugin/dist/core/session-tracker.d.ts +0 -13
  142. package/plugin/dist/core/thinking-os-parser.d.ts +0 -5
  143. package/plugin/dist/core/trajectory-types.d.ts +0 -1
  144. package/plugin/dist/core/trajectory.d.ts +0 -12
  145. package/plugin/dist/hooks/gate.d.ts +0 -1
  146. package/plugin/dist/templates/langs/en/skills/pd-mentor/SKILL.md +3 -4
  147. package/plugin/dist/templates/langs/zh/skills/pd-mentor/SKILL.md +3 -4
  148. package/plugin/dist/templates/workspace/.principles/PROFILE.json +0 -29
  149. package/plugin/dist/templates/workspace/.principles/PROFILE.schema.json +16 -25
  150. package/plugin/dist/templates/workspace/okr/CURRENT_FOCUS.md +0 -1
  151. package/plugin/dist/types/event-types.d.ts +1 -1
  152. package/plugin/openclaw.plugin.json +1 -1
  153. package/plugin/package.json +1 -1
  154. package/plugin/templates/langs/en/skills/pd-mentor/SKILL.md +3 -4
  155. package/plugin/templates/langs/zh/skills/pd-mentor/SKILL.md +3 -4
  156. package/plugin/templates/workspace/.principles/PROFILE.json +0 -29
  157. package/plugin/templates/workspace/.principles/PROFILE.schema.json +16 -25
  158. package/plugin/templates/workspace/okr/CURRENT_FOCUS.md +0 -1
  159. package/templates/workspace/okr/CURRENT_FOCUS.md +0 -1
  160. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.d.ts +0 -2
  161. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.d.ts.map +0 -1
  162. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.js +0 -149
  163. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.js.map +0 -1
  164. package/core/dist/runtime-v2/thinking-models/index.d.ts +0 -3
  165. package/core/dist/runtime-v2/thinking-models/index.d.ts.map +0 -1
  166. package/core/dist/runtime-v2/thinking-models/index.js +0 -3
  167. package/core/dist/runtime-v2/thinking-models/index.js.map +0 -1
  168. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.d.ts +0 -73
  169. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.d.ts.map +0 -1
  170. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.js +0 -227
  171. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.js.map +0 -1
  172. package/plugin/dist/commands/thinking-os.d.ts +0 -2
  173. package/plugin/dist/core/control-ui-db.d.ts +0 -117
  174. package/plugin/dist/core/thinking-models.d.ts +0 -25
  175. package/plugin/dist/templates/workspace/.principles/THINKING_OS_CANDIDATES.md +0 -9
  176. package/plugin/templates/workspace/.principles/THINKING_OS_CANDIDATES.md +0 -9
  177. package/templates/langs/en/skills/admin/SKILL.md +0 -39
  178. package/templates/langs/en/skills/bootstrap-tools/SKILL.md +0 -53
  179. package/templates/langs/en/skills/deductive-audit/SKILL.md +0 -36
  180. package/templates/langs/en/skills/evolution-framework-update/SKILL.md +0 -31
  181. package/templates/langs/en/skills/evolve-system/SKILL.md +0 -46
  182. package/templates/langs/en/skills/evolve-task/SKILL.md +0 -83
  183. package/templates/langs/en/skills/feedback/SKILL.md +0 -51
  184. package/templates/langs/en/skills/init-strategy/SKILL.md +0 -54
  185. package/templates/langs/en/skills/inject-rule/SKILL.md +0 -19
  186. package/templates/langs/en/skills/manage-okr/SKILL.md +0 -96
  187. package/templates/langs/en/skills/pain/SKILL.md +0 -19
  188. package/templates/langs/en/skills/pd-mentor/SKILL.md +0 -211
  189. package/templates/langs/en/skills/profile/SKILL.md +0 -24
  190. package/templates/langs/en/skills/reflection/SKILL.md +0 -40
  191. package/templates/langs/en/skills/reflection-log/SKILL.md +0 -37
  192. package/templates/langs/en/skills/report/SKILL.md +0 -13
  193. package/templates/langs/en/skills/root-cause/SKILL.md +0 -33
  194. package/templates/langs/en/skills/triage/SKILL.md +0 -29
  195. package/templates/langs/en/skills/watch-evolution/SKILL.md +0 -33
  196. package/templates/langs/zh/skills/admin/SKILL.md +0 -41
  197. package/templates/langs/zh/skills/bootstrap-tools/SKILL.md +0 -52
  198. package/templates/langs/zh/skills/deductive-audit/SKILL.md +0 -36
  199. package/templates/langs/zh/skills/evolution-framework-update/SKILL.md +0 -31
  200. package/templates/langs/zh/skills/evolve-system/SKILL.md +0 -46
  201. package/templates/langs/zh/skills/evolve-task/SKILL.md +0 -83
  202. package/templates/langs/zh/skills/feedback/SKILL.md +0 -53
  203. package/templates/langs/zh/skills/init-strategy/SKILL.md +0 -54
  204. package/templates/langs/zh/skills/inject-rule/SKILL.md +0 -19
  205. package/templates/langs/zh/skills/manage-okr/SKILL.md +0 -109
  206. package/templates/langs/zh/skills/pain/SKILL.md +0 -30
  207. package/templates/langs/zh/skills/pd-auditor/SKILL.md +0 -61
  208. package/templates/langs/zh/skills/pd-explorer/SKILL.md +0 -65
  209. package/templates/langs/zh/skills/pd-implementer/SKILL.md +0 -68
  210. package/templates/langs/zh/skills/pd-mentor/SKILL.md +0 -211
  211. package/templates/langs/zh/skills/pd-planner/SKILL.md +0 -65
  212. package/templates/langs/zh/skills/pd-reporter/SKILL.md +0 -78
  213. package/templates/langs/zh/skills/pd-reviewer/SKILL.md +0 -66
  214. package/templates/langs/zh/skills/profile/SKILL.md +0 -24
  215. package/templates/langs/zh/skills/reflection/SKILL.md +0 -40
  216. package/templates/langs/zh/skills/reflection-log/SKILL.md +0 -37
  217. package/templates/langs/zh/skills/report/SKILL.md +0 -13
  218. package/templates/langs/zh/skills/root-cause/SKILL.md +0 -33
  219. package/templates/langs/zh/skills/triage/SKILL.md +0 -29
  220. package/templates/langs/zh/skills/watch-evolution/SKILL.md +0 -33
@@ -7,6 +7,24 @@ import { sendSuccess, sendError, sendMethodNotAllowed, sendBadRequest, sendNotFo
7
7
  import { appendUpdateHistory } from './update-history.js';
8
8
  import { checkOpenClawGateway, stopOpenClawGateway, restartOpenClawGateway, } from '../utils/gateway.js';
9
9
  import { migrateLegacyExtensionBackups, reservePdBackupDestination, resolvePdBackupsRoot, } from '../utils/pd-backups.js';
10
+ import { ActivationCompatibilityReadModel } from '@principles/core/runtime-v2';
11
+ /**
12
+ * Legacy rule contract preflight (2026-08-19): refuse to swap the runtime
13
+ * while an ACTIVE owner-approved rule still depends on a RuleHost contract
14
+ * symbol the new runtime removed (recentThinking, planStatus, hasPlanFile,
15
+ * ...). Executing such a rule against the new contract silently changes its
16
+ * semantics; refusing before any mutation leaves the installation untouched.
17
+ */
18
+ function runLegacyRuleContractPreflight(workspaceDir) {
19
+ const scan = new ActivationCompatibilityReadModel({ workspaceDir }).scan();
20
+ if (scan.ok)
21
+ return { ok: true };
22
+ return {
23
+ ok: false,
24
+ reason: scan.reason ?? 'legacy_rule_contract_dependency',
25
+ nextAction: scan.nextAction ?? 'Migrate or deactivate the listed rules before updating.',
26
+ };
27
+ }
10
28
  // ---------------------------------------------------------------------------
11
29
  // Constants
12
30
  // ---------------------------------------------------------------------------
@@ -418,6 +436,18 @@ async function doApplyUpdate(options, workspaceDir) {
418
436
  let appliedChanges = false;
419
437
  let gatewayWasStopped = false;
420
438
  const codexInstalled = detectCodexInstall();
439
+ // Legacy-contract preflight BEFORE the gateway stop and any file mutation:
440
+ // an active rule depending on a removed RuleHost contract symbol must
441
+ // block the update while the installation is still untouched.
442
+ const compat = runLegacyRuleContractPreflight(workspaceDir);
443
+ if (!compat.ok) {
444
+ return {
445
+ success: false,
446
+ message: compat.reason,
447
+ reason: 'legacy_rule_contract_dependency',
448
+ nextAction: compat.nextAction,
449
+ };
450
+ }
421
451
  // Fix 5: stop the OpenClaw gateway before file mutations to release file
422
452
  // locks on native modules. Best-effort — if `openclaw` is not in PATH or
423
453
  // the gateway isn't running, we proceed (dist/*.js files are not locked).
@@ -630,6 +660,19 @@ function depsMeaningfullyChanged(oldDeps, newDeps) {
630
660
  }
631
661
  async function doInlineFullUpdate(workspaceDir) {
632
662
  const extDir = resolvePluginDir(workspaceDir);
663
+ // Legacy-contract preflight BEFORE stopping the gateway or touching files:
664
+ // refuse while an active rule still uses a removed RuleHost contract
665
+ // symbol — the running installation stays exactly as it was.
666
+ const compat = runLegacyRuleContractPreflight(workspaceDir);
667
+ if (!compat.ok) {
668
+ return {
669
+ success: false,
670
+ message: compat.reason,
671
+ reason: 'legacy_rule_contract_dependency',
672
+ nextAction: compat.nextAction,
673
+ requiresRestart: false,
674
+ };
675
+ }
633
676
  // 1. Stop gateway (releases native module locks held by the gateway process)
634
677
  const gatewayStatus = await checkOpenClawGateway();
635
678
  let gatewayWasStopped = false;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=activation-compatibility-read-model.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activation-compatibility-read-model.test.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/__tests__/activation-compatibility-read-model.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,148 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import * as os from 'node:os';
5
+ import { SqliteConnection } from '../store/sqlite-connection.js';
6
+ import { ActivationCompatibilityReadModel } from '../activation-compatibility-read-model.js';
7
+ import { createRuleArtifact, seedArtifactToDb } from '../activation/__tests__/helpers.js';
8
+ /**
9
+ * Persisted-workspace regression fixture (P1-3): a workspace upgraded from an
10
+ * older PD may hold an ACTIVE owner-approved rule whose RuleCode reads
11
+ * `input.session.recentThinking` — a contract symbol the current runtime
12
+ * removed. The compatibility read model must detect it; it must NOT silently
13
+ * report clean (which would let an upgrade change the rule's semantics), and
14
+ * it must never mutate the workspace.
15
+ */
16
+ function createBareWorkspace() {
17
+ // Local variant of the shared helper (avoids pulling the dispatcher deps
18
+ // we do not need here) — same real-SQLite production stores.
19
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-compat-scan-'));
20
+ fs.mkdirSync(path.join(tmpDir, '.pd'), { recursive: true });
21
+ const connection = new SqliteConnection({ workspaceDir: tmpDir });
22
+ connection.getDb();
23
+ return {
24
+ workspaceDir: tmpDir,
25
+ connection,
26
+ approvalStore: null,
27
+ stateStore: null,
28
+ artifactStore: null,
29
+ cleanup: () => {
30
+ connection.close();
31
+ fs.rmSync(tmpDir, { recursive: true, force: true });
32
+ },
33
+ };
34
+ }
35
+ const LEGACY_RECENT_THINKING_CODE = `function evaluate(input, helpers) {
36
+ var hasRecentDiagnosis = false;
37
+ if (input.session && input.session.recentThinking === true) { hasRecentDiagnosis = true; }
38
+ if (!hasRecentDiagnosis) {
39
+ return { decision: 'requireApproval', matched: true, reason: 'no recent diagnosis evidence' };
40
+ }
41
+ return { decision: 'allow', matched: false };
42
+ }`;
43
+ const CLEAN_V2_CODE = `function evaluate(input, helpers) {
44
+ var h = input.context && input.context.history;
45
+ if (h && h.status === 'available' && h.recentCalls.length > 0) {
46
+ return { decision: 'requireApproval', matched: true, reason: 'diagnosis evidence present' };
47
+ }
48
+ return { decision: 'allow', matched: false, reason: 'cannot verify: history unavailable' };
49
+ }`;
50
+ function seedActiveCodeToolHookRule(ws, spec) {
51
+ const { artifactId, ruleId, implementationCode, activationId } = spec;
52
+ const artifact = createRuleArtifact({
53
+ artifactId,
54
+ sourceRuleId: ruleId,
55
+ contentJson: JSON.stringify({
56
+ ruleId,
57
+ implementationCode,
58
+ ruleHostGateDecision: 'accepted_shadow',
59
+ affectedTools: ['write_file'],
60
+ }),
61
+ });
62
+ seedArtifactToDb(ws, artifact);
63
+ const db = ws.connection.getDb();
64
+ db.prepare(`
65
+ INSERT INTO activations (activation_id, idempotency_key, artifact_id, channel, action, target_ref, activated_at, promoted_at, deactivated_at)
66
+ VALUES (?, ?, ?, 'code_tool_hook', 'code_tool_hook_shadow_activate', ?, ?, NULL, NULL)
67
+ `).run(activationId, `idem-${activationId}`, artifactId, ruleId, new Date().toISOString());
68
+ }
69
+ describe('ActivationCompatibilityReadModel', () => {
70
+ it('detects an active rule that reads the retired recentThinking contract', () => {
71
+ const ws = createBareWorkspace();
72
+ try {
73
+ seedActiveCodeToolHookRule(ws, { artifactId: 'art-legacy-1', ruleId: 'rule-real-diagnosis-first', implementationCode: LEGACY_RECENT_THINKING_CODE, activationId: 'act-legacy-1' });
74
+ const result = new ActivationCompatibilityReadModel({ workspaceDir: ws.workspaceDir }).scan();
75
+ expect(result.ok).toBe(false);
76
+ expect(result.status).toBe('legacy_dependency');
77
+ expect(result.scannedActivations).toBe(1);
78
+ expect(result.findings).toHaveLength(1);
79
+ expect(result.findings[0]).toMatchObject({
80
+ symbol: 'recentThinking',
81
+ ruleId: 'rule-real-diagnosis-first',
82
+ activationId: 'act-legacy-1',
83
+ channel: 'code_tool_hook',
84
+ });
85
+ expect(result.reason).toBe('legacy_rule_contract_dependency');
86
+ expect(result.nextAction).toContain('Migrate or deactivate');
87
+ }
88
+ finally {
89
+ ws.cleanup();
90
+ }
91
+ });
92
+ it('passes a clean RuleContextV2-only active rule', () => {
93
+ const ws = createBareWorkspace();
94
+ try {
95
+ seedActiveCodeToolHookRule(ws, { artifactId: 'art-clean-1', ruleId: 'rule-clean-v2', implementationCode: CLEAN_V2_CODE, activationId: 'act-clean-1' });
96
+ const result = new ActivationCompatibilityReadModel({ workspaceDir: ws.workspaceDir }).scan();
97
+ expect(result.ok).toBe(true);
98
+ expect(result.status).toBe('clean');
99
+ expect(result.findings).toEqual([]);
100
+ }
101
+ finally {
102
+ ws.cleanup();
103
+ }
104
+ });
105
+ it('ignores deactivated rules (only active activations block upgrades)', () => {
106
+ const ws = createBareWorkspace();
107
+ try {
108
+ seedActiveCodeToolHookRule(ws, { artifactId: 'art-legacy-2', ruleId: 'rule-retired-old', implementationCode: LEGACY_RECENT_THINKING_CODE, activationId: 'act-legacy-2' });
109
+ ws.connection.getDb().prepare('UPDATE activations SET deactivated_at = ? WHERE activation_id = ?').run(new Date().toISOString(), 'act-legacy-2');
110
+ const result = new ActivationCompatibilityReadModel({ workspaceDir: ws.workspaceDir }).scan();
111
+ expect(result.status).toBe('clean');
112
+ expect(result.scannedActivations).toBe(0);
113
+ }
114
+ finally {
115
+ ws.cleanup();
116
+ }
117
+ });
118
+ it('treats a workspace without state.db as a clean pass (fresh install)', () => {
119
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-compat-empty-'));
120
+ try {
121
+ const result = new ActivationCompatibilityReadModel({ workspaceDir: tmpDir }).scan();
122
+ expect(result.ok).toBe(true);
123
+ expect(result.status).toBe('no_state_db');
124
+ // Side-effect-free: no state.db was created by the scan (EP-02).
125
+ expect(fs.existsSync(path.join(tmpDir, '.pd', 'state.db'))).toBe(false);
126
+ }
127
+ finally {
128
+ fs.rmSync(tmpDir, { recursive: true, force: true });
129
+ }
130
+ });
131
+ it('never mutates the scanned workspace (activations and artifacts intact)', () => {
132
+ const ws = createBareWorkspace();
133
+ try {
134
+ seedActiveCodeToolHookRule(ws, { artifactId: 'art-legacy-3', ruleId: 'rule-kept-3', implementationCode: LEGACY_RECENT_THINKING_CODE, activationId: 'act-legacy-3' });
135
+ const result = new ActivationCompatibilityReadModel({ workspaceDir: ws.workspaceDir }).scan();
136
+ expect(result.ok).toBe(false);
137
+ const db = ws.connection.getDb();
138
+ const activations = db.prepare('SELECT COUNT(*) AS n FROM activations').get();
139
+ const artifacts = db.prepare('SELECT COUNT(*) AS n FROM pi_artifacts').get();
140
+ expect(activations.n).toBe(1);
141
+ expect(artifacts.n).toBeGreaterThanOrEqual(1);
142
+ }
143
+ finally {
144
+ ws.cleanup();
145
+ }
146
+ });
147
+ });
148
+ //# sourceMappingURL=activation-compatibility-read-model.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activation-compatibility-read-model.test.js","sourceRoot":"","sources":["../../../src/runtime-v2/__tests__/activation-compatibility-read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AAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC9B,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,OAAO,EAAE,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -303,8 +303,6 @@ const KNOWN_PLUGIN_CORE_FILES = new Set([
303
303
  'training-program.ts',
304
304
  'replay-engine.ts',
305
305
  'merge-gate-audit.ts',
306
- 'control-ui-db.ts',
307
- 'thinking-models.ts',
308
306
  'pd-task-reconciler.ts',
309
307
  'correction-cue-learner.ts',
310
308
  // MVP core-loop closure (P0-B/P0-D/E/F): live correction-cue store projection
@@ -406,7 +404,7 @@ describe('PRI-212 plugin core anti-growth guard', () => {
406
404
  expect.fail(msg);
407
405
  }
408
406
  });
409
- it('known baseline count is self-consistent (98 files)', async () => {
407
+ it('known baseline count is self-consistent (96 files)', async () => {
410
408
  // Sanity check: if the baseline grows, update this number.
411
409
  // Prevents accidental baseline bloat from going unnoticed.
412
410
  // See docs/archive/reviews/plugin-core-inventory-2026-05.md §7
@@ -446,10 +444,13 @@ describe('PRI-212 plugin core anti-growth guard', () => {
446
444
  // PRI-530: Added principle-receipt-metadata.ts (94 → 95) — plugin I/O boundary
447
445
  // for principle receipt attribution reads (readonly state.db joins).
448
446
  // PRI-531: Added principle-application-ledger.ts (95 → 96) — receipt ledger writer.
447
+ // 2026-08-19 retirement: Removed control-ui-db.ts and thinking-models.ts
448
+ // (96 → 94) — zero production consumers after the Thinking Activity
449
+ // writer retirement (census in the PR description).
449
450
  // MVP core-loop closure (P0-B/P0-D): Added signal-keyword-store.ts +
450
- // auto-consumer-governance-wiring.ts (9698) — live correction-cue store
451
+ // auto-consumer-governance-wiring.ts (9496) — live correction-cue store
451
452
  // projection + auto-consumer governance dispatcher/repair wiring (I/O boundary).
452
- expect(KNOWN_PLUGIN_CORE_FILES.size).toBe(98);
453
+ expect(KNOWN_PLUGIN_CORE_FILES.size).toBe(96);
453
454
  });
454
455
  });
455
456
  const REQUIRED_TEST_FILES = [