create-principles-disciple 1.95.0 → 1.97.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 (263) hide show
  1. package/console/dist/server/config/pd-config-store.js +49 -12
  2. package/console/dist/server/index.js +4 -3
  3. package/console/dist/server/models/IntentPageModel.d.ts +36 -2
  4. package/console/dist/server/models/IntentPageModel.js +213 -11
  5. package/console/dist/server/routes/intent.d.ts +5 -1
  6. package/console/dist/server/routes/intent.js +200 -12
  7. package/console/dist/types.d.ts +1 -0
  8. package/console/dist/ui/App.js +0 -53
  9. package/console/dist/ui/api.d.ts +18 -4
  10. package/console/dist/ui/api.js +38 -5
  11. package/console/dist/ui/components/layout/app-sidebar.js +12 -12
  12. package/console/dist/ui/components/ui/badge.d.ts +1 -1
  13. package/console/dist/ui/i18n/en.json +142 -3
  14. package/console/dist/ui/i18n/zh-CN.json +142 -3
  15. package/console/dist/ui/pages/control-center/AgentCard.d.ts +31 -0
  16. package/console/dist/ui/pages/control-center/AgentCard.js +156 -0
  17. package/console/dist/ui/pages/control-center/AgentGroup.d.ts +26 -0
  18. package/console/dist/ui/pages/control-center/AgentGroup.js +38 -0
  19. package/console/dist/ui/pages/control-center/ControlCenterPage.js +77 -41
  20. package/console/dist/ui/pages/control-center/WorkflowDiagram.d.ts +17 -0
  21. package/console/dist/ui/pages/control-center/WorkflowDiagram.js +55 -0
  22. package/console/dist/ui/pages/intent/IntentOnboarding.d.ts +67 -0
  23. package/console/dist/ui/pages/intent/IntentOnboarding.js +289 -0
  24. package/console/dist/ui/pages/intent/IntentPage.js +117 -6
  25. package/console/dist/ui/utils/agent-metadata.d.ts +58 -0
  26. package/console/dist/ui/utils/agent-metadata.js +275 -0
  27. package/console/dist/ui/utils/control-center-helpers.d.ts +19 -0
  28. package/console/dist/ui/utils/control-center-helpers.js +37 -0
  29. package/console/dist/ui/utils/validators.d.ts +37 -0
  30. package/console/dist/ui/utils/validators.js +130 -0
  31. package/console/dist/web/assets/app.css +360 -3
  32. package/console/dist/web/assets/app.js +2952 -1143
  33. package/console/package.json +1 -1
  34. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +27 -35
  35. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  36. package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js +85 -7
  37. package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js.map +1 -1
  38. package/core/dist/runtime-v2/__tests__/golden-trace-replay-validator.test.js +70 -0
  39. package/core/dist/runtime-v2/__tests__/golden-trace-replay-validator.test.js.map +1 -1
  40. package/core/dist/runtime-v2/__tests__/golden-trace.test.js +136 -1
  41. package/core/dist/runtime-v2/__tests__/golden-trace.test.js.map +1 -1
  42. package/core/dist/runtime-v2/__tests__/v2-adversarial-cases.test.d.ts +2 -0
  43. package/core/dist/runtime-v2/__tests__/v2-adversarial-cases.test.d.ts.map +1 -0
  44. package/core/dist/runtime-v2/__tests__/v2-adversarial-cases.test.js +211 -0
  45. package/core/dist/runtime-v2/__tests__/v2-adversarial-cases.test.js.map +1 -0
  46. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js +93 -0
  47. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
  48. package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts +11 -0
  49. package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts.map +1 -1
  50. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js +22 -0
  51. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js.map +1 -1
  52. package/core/dist/runtime-v2/feature-flags/__tests__/rulecode-context-v2-flag.test.d.ts +2 -0
  53. package/core/dist/runtime-v2/feature-flags/__tests__/rulecode-context-v2-flag.test.d.ts.map +1 -0
  54. package/core/dist/runtime-v2/feature-flags/__tests__/rulecode-context-v2-flag.test.js +74 -0
  55. package/core/dist/runtime-v2/feature-flags/__tests__/rulecode-context-v2-flag.test.js.map +1 -0
  56. package/core/dist/runtime-v2/feature-flags/__tests__/surface-guard-policy.test.d.ts +2 -0
  57. package/core/dist/runtime-v2/feature-flags/__tests__/surface-guard-policy.test.d.ts.map +1 -0
  58. package/core/dist/runtime-v2/feature-flags/__tests__/surface-guard-policy.test.js +246 -0
  59. package/core/dist/runtime-v2/feature-flags/__tests__/surface-guard-policy.test.js.map +1 -0
  60. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  61. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +7 -0
  62. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  63. package/core/dist/runtime-v2/feature-flags/index.d.ts +2 -0
  64. package/core/dist/runtime-v2/feature-flags/index.d.ts.map +1 -1
  65. package/core/dist/runtime-v2/feature-flags/index.js +2 -0
  66. package/core/dist/runtime-v2/feature-flags/index.js.map +1 -1
  67. package/{plugin/dist/core/surface-guard.d.ts → core/dist/runtime-v2/feature-flags/surface-guard-policy.d.ts} +15 -5
  68. package/core/dist/runtime-v2/feature-flags/surface-guard-policy.d.ts.map +1 -0
  69. package/{plugin/dist/core/surface-guard.js → core/dist/runtime-v2/feature-flags/surface-guard-policy.js} +14 -2
  70. package/core/dist/runtime-v2/feature-flags/surface-guard-policy.js.map +1 -0
  71. package/core/dist/runtime-v2/golden-trace-replay-validator.js +1 -1
  72. package/core/dist/runtime-v2/golden-trace-replay-validator.js.map +1 -1
  73. package/core/dist/runtime-v2/golden-trace.d.ts +19 -3
  74. package/core/dist/runtime-v2/golden-trace.d.ts.map +1 -1
  75. package/core/dist/runtime-v2/golden-trace.js +2 -0
  76. package/core/dist/runtime-v2/golden-trace.js.map +1 -1
  77. package/core/dist/runtime-v2/index.d.ts +15 -3
  78. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  79. package/core/dist/runtime-v2/index.js +11 -2
  80. package/core/dist/runtime-v2/index.js.map +1 -1
  81. package/core/dist/runtime-v2/intent/__tests__/intent-doc-version.test.d.ts +2 -0
  82. package/core/dist/runtime-v2/intent/__tests__/intent-doc-version.test.d.ts.map +1 -0
  83. package/core/dist/runtime-v2/intent/__tests__/intent-doc-version.test.js +88 -0
  84. package/core/dist/runtime-v2/intent/__tests__/intent-doc-version.test.js.map +1 -0
  85. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.js +91 -1
  86. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.js.map +1 -1
  87. package/core/dist/runtime-v2/intent/index.d.ts +2 -0
  88. package/core/dist/runtime-v2/intent/index.d.ts.map +1 -1
  89. package/core/dist/runtime-v2/intent/index.js +2 -0
  90. package/core/dist/runtime-v2/intent/index.js.map +1 -1
  91. package/core/dist/runtime-v2/intent/intent-browser.d.ts +23 -0
  92. package/core/dist/runtime-v2/intent/intent-browser.d.ts.map +1 -0
  93. package/core/dist/runtime-v2/intent/intent-browser.js +21 -0
  94. package/core/dist/runtime-v2/intent/intent-browser.js.map +1 -0
  95. package/core/dist/runtime-v2/intent/intent-doc-version.d.ts +28 -0
  96. package/core/dist/runtime-v2/intent/intent-doc-version.d.ts.map +1 -0
  97. package/core/dist/runtime-v2/intent/intent-doc-version.js +21 -0
  98. package/core/dist/runtime-v2/intent/intent-doc-version.js.map +1 -0
  99. package/core/dist/runtime-v2/intent/intent-doc.d.ts +17 -1
  100. package/core/dist/runtime-v2/intent/intent-doc.d.ts.map +1 -1
  101. package/core/dist/runtime-v2/intent/intent-doc.js +95 -7
  102. package/core/dist/runtime-v2/intent/intent-doc.js.map +1 -1
  103. package/core/dist/runtime-v2/intent/intent-hash.d.ts +2 -0
  104. package/core/dist/runtime-v2/intent/intent-hash.d.ts.map +1 -0
  105. package/core/dist/runtime-v2/intent/intent-hash.js +10 -0
  106. package/core/dist/runtime-v2/intent/intent-hash.js.map +1 -0
  107. package/core/dist/runtime-v2/internalization/__tests__/artificer-prompt-builder.test.js +41 -1
  108. package/core/dist/runtime-v2/internalization/__tests__/artificer-prompt-builder.test.js.map +1 -1
  109. package/core/dist/runtime-v2/internalization/__tests__/artificer-rule-output.test.js +130 -2
  110. package/core/dist/runtime-v2/internalization/__tests__/artificer-rule-output.test.js.map +1 -1
  111. package/core/dist/runtime-v2/internalization/__tests__/behavior-example-pack.test.d.ts +2 -0
  112. package/core/dist/runtime-v2/internalization/__tests__/behavior-example-pack.test.d.ts.map +1 -0
  113. package/core/dist/runtime-v2/internalization/__tests__/behavior-example-pack.test.js +228 -0
  114. package/core/dist/runtime-v2/internalization/__tests__/behavior-example-pack.test.js.map +1 -0
  115. package/core/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js +41 -11
  116. package/core/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js.map +1 -1
  117. package/core/dist/runtime-v2/internalization/__tests__/refiner-sandbox-wrapper.test.js +135 -0
  118. package/core/dist/runtime-v2/internalization/__tests__/refiner-sandbox-wrapper.test.js.map +1 -1
  119. package/core/dist/runtime-v2/internalization/__tests__/rule-context-v2.test.d.ts +2 -0
  120. package/core/dist/runtime-v2/internalization/__tests__/rule-context-v2.test.d.ts.map +1 -0
  121. package/core/dist/runtime-v2/internalization/__tests__/rule-context-v2.test.js +449 -0
  122. package/core/dist/runtime-v2/internalization/__tests__/rule-context-v2.test.js.map +1 -0
  123. package/core/dist/runtime-v2/internalization/adversarial-case.d.ts.map +1 -1
  124. package/core/dist/runtime-v2/internalization/adversarial-case.js +24 -0
  125. package/core/dist/runtime-v2/internalization/adversarial-case.js.map +1 -1
  126. package/core/dist/runtime-v2/internalization/artificer-output.d.ts +10 -0
  127. package/core/dist/runtime-v2/internalization/artificer-output.d.ts.map +1 -1
  128. package/core/dist/runtime-v2/internalization/artificer-output.js +45 -0
  129. package/core/dist/runtime-v2/internalization/artificer-output.js.map +1 -1
  130. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts +2 -2
  131. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts.map +1 -1
  132. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js +7 -2
  133. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js.map +1 -1
  134. package/core/dist/runtime-v2/internalization/behavior-example-pack.d.ts +66 -0
  135. package/core/dist/runtime-v2/internalization/behavior-example-pack.d.ts.map +1 -0
  136. package/core/dist/runtime-v2/internalization/behavior-example-pack.js +183 -0
  137. package/core/dist/runtime-v2/internalization/behavior-example-pack.js.map +1 -0
  138. package/core/dist/runtime-v2/internalization/evaluator-output.d.ts +8 -0
  139. package/core/dist/runtime-v2/internalization/evaluator-output.d.ts.map +1 -1
  140. package/core/dist/runtime-v2/internalization/evaluator-output.js +10 -0
  141. package/core/dist/runtime-v2/internalization/evaluator-output.js.map +1 -1
  142. package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts +17 -0
  143. package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
  144. package/core/dist/runtime-v2/internalization/evaluator-runner.js +118 -24
  145. package/core/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
  146. package/core/dist/runtime-v2/internalization/refiner-sandbox-wrapper.d.ts.map +1 -1
  147. package/core/dist/runtime-v2/internalization/refiner-sandbox-wrapper.js +1 -1
  148. package/core/dist/runtime-v2/internalization/refiner-sandbox-wrapper.js.map +1 -1
  149. package/core/dist/runtime-v2/internalization/rule-context-v2.d.ts +61 -0
  150. package/core/dist/runtime-v2/internalization/rule-context-v2.d.ts.map +1 -0
  151. package/core/dist/runtime-v2/internalization/rule-context-v2.js +301 -0
  152. package/core/dist/runtime-v2/internalization/rule-context-v2.js.map +1 -0
  153. package/core/dist/runtime-v2/internalization/rule-host-contracts.d.ts +9 -0
  154. package/core/dist/runtime-v2/internalization/rule-host-contracts.d.ts.map +1 -1
  155. package/core/dist/runtime-v2/internalization/v2-adversarial-cases.d.ts +55 -0
  156. package/core/dist/runtime-v2/internalization/v2-adversarial-cases.d.ts.map +1 -0
  157. package/core/dist/runtime-v2/internalization/v2-adversarial-cases.js +131 -0
  158. package/core/dist/runtime-v2/internalization/v2-adversarial-cases.js.map +1 -0
  159. package/core/dist/runtime-v2/pain-signal-observability.d.ts.map +1 -1
  160. package/core/dist/runtime-v2/pain-signal-observability.js +24 -1
  161. package/core/dist/runtime-v2/pain-signal-observability.js.map +1 -1
  162. package/core/dist/runtime-v2/risk/__tests__/risk-calculator-policy.test.d.ts +2 -0
  163. package/core/dist/runtime-v2/risk/__tests__/risk-calculator-policy.test.d.ts.map +1 -0
  164. package/core/dist/runtime-v2/risk/__tests__/risk-calculator-policy.test.js +95 -0
  165. package/core/dist/runtime-v2/risk/__tests__/risk-calculator-policy.test.js.map +1 -0
  166. package/core/dist/runtime-v2/risk/index.d.ts +7 -0
  167. package/core/dist/runtime-v2/risk/index.d.ts.map +1 -0
  168. package/core/dist/runtime-v2/risk/index.js +6 -0
  169. package/core/dist/runtime-v2/risk/index.js.map +1 -0
  170. package/core/dist/runtime-v2/risk/risk-calculator-policy.d.ts +18 -0
  171. package/core/dist/runtime-v2/risk/risk-calculator-policy.d.ts.map +1 -0
  172. package/core/dist/runtime-v2/risk/risk-calculator-policy.js +47 -0
  173. package/core/dist/runtime-v2/risk/risk-calculator-policy.js.map +1 -0
  174. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-doc-version-store.test.d.ts +2 -0
  175. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-doc-version-store.test.d.ts.map +1 -0
  176. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-doc-version-store.test.js +83 -0
  177. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-doc-version-store.test.js.map +1 -0
  178. package/core/dist/runtime-v2/store/intent/index.d.ts +2 -1
  179. package/core/dist/runtime-v2/store/intent/index.d.ts.map +1 -1
  180. package/core/dist/runtime-v2/store/intent/index.js +2 -1
  181. package/core/dist/runtime-v2/store/intent/index.js.map +1 -1
  182. package/core/dist/runtime-v2/store/intent/sqlite-intent-doc-version-store.d.ts +28 -0
  183. package/core/dist/runtime-v2/store/intent/sqlite-intent-doc-version-store.d.ts.map +1 -0
  184. package/core/dist/runtime-v2/store/intent/sqlite-intent-doc-version-store.js +88 -0
  185. package/core/dist/runtime-v2/store/intent/sqlite-intent-doc-version-store.js.map +1 -0
  186. package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
  187. package/core/dist/runtime-v2/store/sqlite-connection.js +14 -0
  188. package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
  189. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.d.ts +2 -0
  190. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.d.ts.map +1 -0
  191. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.js +149 -0
  192. package/core/dist/runtime-v2/thinking-models/__tests__/thinking-models-policy.test.js.map +1 -0
  193. package/core/dist/runtime-v2/thinking-models/index.d.ts +3 -0
  194. package/core/dist/runtime-v2/thinking-models/index.d.ts.map +1 -0
  195. package/core/dist/runtime-v2/thinking-models/index.js +3 -0
  196. package/core/dist/runtime-v2/thinking-models/index.js.map +1 -0
  197. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.d.ts +73 -0
  198. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.d.ts.map +1 -0
  199. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.js +227 -0
  200. package/core/dist/runtime-v2/thinking-models/thinking-models-policy.js.map +1 -0
  201. package/core/dist/runtime-v2/tools/__tests__/artificer-l2-tool-contract.test.js +40 -1
  202. package/core/dist/runtime-v2/tools/__tests__/artificer-l2-tool-contract.test.js.map +1 -1
  203. package/core/dist/runtime-v2/tools/artificer-l2-tool-contract.d.ts.map +1 -1
  204. package/core/dist/runtime-v2/tools/artificer-l2-tool-contract.js +28 -1
  205. package/core/dist/runtime-v2/tools/artificer-l2-tool-contract.js.map +1 -1
  206. package/core/dist/runtime-v2/tools/artificer-output-typebox.d.ts +3 -0
  207. package/core/dist/runtime-v2/tools/artificer-output-typebox.d.ts.map +1 -1
  208. package/core/dist/runtime-v2/tools/artificer-output-typebox.js +3 -0
  209. package/core/dist/runtime-v2/tools/artificer-output-typebox.js.map +1 -1
  210. package/core/package.json +4 -0
  211. package/package.json +1 -1
  212. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.js +74 -3
  213. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.js.map +1 -1
  214. package/pd-cli/dist/commands/intent.d.ts +21 -4
  215. package/pd-cli/dist/commands/intent.d.ts.map +1 -1
  216. package/pd-cli/dist/commands/intent.js +88 -27
  217. package/pd-cli/dist/commands/intent.js.map +1 -1
  218. package/plugin/dist/commands/pain.js +2 -2
  219. package/plugin/dist/core/behavior-example-pack-assembler.d.ts +43 -0
  220. package/plugin/dist/core/behavior-example-pack-assembler.js +247 -0
  221. package/plugin/dist/core/intent-doc-reader-adapter.d.ts +13 -5
  222. package/plugin/dist/core/intent-doc-reader-adapter.js +25 -5
  223. package/plugin/dist/core/intent-doc-reader.d.ts +13 -4
  224. package/plugin/dist/core/intent-doc-reader.js +45 -24
  225. package/plugin/dist/core/rule-context-assembler.d.ts +45 -0
  226. package/plugin/dist/core/rule-context-assembler.js +148 -0
  227. package/plugin/dist/core/thinking-models.d.ts +12 -57
  228. package/plugin/dist/core/thinking-models.js +18 -224
  229. package/plugin/dist/core/trajectory-types.d.ts +18 -0
  230. package/plugin/dist/core/trajectory.d.ts +34 -2
  231. package/plugin/dist/core/trajectory.js +103 -0
  232. package/plugin/dist/hooks/gate.js +59 -2
  233. package/plugin/dist/hooks/pain.js +2 -2
  234. package/plugin/dist/hooks/prompt.js +2 -1
  235. package/plugin/dist/index.js +1 -1
  236. package/plugin/package.json +1 -1
  237. package/plugin/dist/core/evolution-migration.d.ts +0 -5
  238. package/plugin/dist/core/evolution-migration.js +0 -65
  239. package/plugin/dist/core/risk-calculator.d.ts +0 -22
  240. package/plugin/dist/core/risk-calculator.js +0 -88
  241. package/plugin/dist/core/rule-host-helpers.d.ts +0 -8
  242. package/plugin/dist/core/rule-host-helpers.js +0 -7
  243. package/plugin/dist/core/rule-host-types.d.ts +0 -7
  244. package/plugin/dist/core/rule-host-types.js +0 -7
  245. package/plugin/dist/core/schema/db-types.d.ts +0 -11
  246. package/plugin/dist/core/schema/db-types.js +0 -5
  247. package/plugin/dist/core/schema/index.d.ts +0 -17
  248. package/plugin/dist/core/schema/index.js +0 -15
  249. package/plugin/dist/core/schema/migration-runner.d.ts +0 -53
  250. package/plugin/dist/core/schema/migration-runner.js +0 -170
  251. package/plugin/dist/core/schema/migrations/001-init-trajectory.d.ts +0 -6
  252. package/plugin/dist/core/schema/migrations/001-init-trajectory.js +0 -190
  253. package/plugin/dist/core/schema/migrations/002-init-central.d.ts +0 -5
  254. package/plugin/dist/core/schema/migrations/002-init-central.js +0 -108
  255. package/plugin/dist/core/schema/migrations/003-init-workflow.d.ts +0 -5
  256. package/plugin/dist/core/schema/migrations/003-init-workflow.js +0 -50
  257. package/plugin/dist/core/schema/migrations/004-add-thinking-and-gfi.d.ts +0 -8
  258. package/plugin/dist/core/schema/migrations/004-add-thinking-and-gfi.js +0 -66
  259. package/plugin/dist/core/schema/migrations/index.d.ts +0 -16
  260. package/plugin/dist/core/schema/migrations/index.js +0 -27
  261. package/plugin/dist/core/schema/schema-definitions.d.ts +0 -46
  262. package/plugin/dist/core/schema/schema-definitions.js +0 -599
  263. package/plugin/scripts/db-migrate.mjs +0 -170
@@ -17,12 +17,20 @@
17
17
  * Architecture: this file is I/O (delegates to fs-reading safeReadIntentDoc).
18
18
  * It will be added to KNOWN_PLUGIN_CORE_FILES in architecture-regression.test.ts.
19
19
  */
20
- import type { IntentDocReader } from '@principles/core/runtime-v2';
20
+ import type { IntentDocReader, IntentLang } from '@principles/core/runtime-v2';
21
21
  /**
22
- * Create an IntentDocReader bound to a specific workspace.
22
+ * Detect which language's INTENT file exists on disk.
23
+ * Priority: zh-CN first, then en. Defaults to zh-CN if neither exists.
23
24
  *
24
- * The returned reader is stateless beyond the workspace binding — each
25
+ * This lets hooks avoid hardcoding a single language — the Owner may have
26
+ * created either INTENT.zh-CN.md or INTENT.en.md.
27
+ */
28
+ export declare function resolveIntentLang(workspaceDir: string): IntentLang;
29
+ /**
30
+ * Create an IntentDocReader bound to a specific workspace and language.
31
+ *
32
+ * The returned reader is stateless beyond the (workspace, lang) binding — each
25
33
  * `readIntentDoc()` call delegates to `safeReadIntentDoc()`, which owns
26
- * the TTL+mtime cache.
34
+ * the TTL+mtime cache keyed by `${workspaceDir}:${lang}`.
27
35
  */
28
- export declare function createIntentDocReader(workspaceDir: string): IntentDocReader;
36
+ export declare function createIntentDocReader(workspaceDir: string, lang: IntentLang): IntentDocReader;
@@ -17,18 +17,38 @@
17
17
  * Architecture: this file is I/O (delegates to fs-reading safeReadIntentDoc).
18
18
  * It will be added to KNOWN_PLUGIN_CORE_FILES in architecture-regression.test.ts.
19
19
  */
20
+ import * as fs from 'node:fs';
21
+ import * as path from 'node:path';
20
22
  import { safeReadIntentDoc } from './intent-doc-reader.js';
23
+ import { getIntentFilename, } from '@principles/core/runtime-v2';
24
+ const INTENT_DIR = '.principles';
21
25
  /**
22
- * Create an IntentDocReader bound to a specific workspace.
26
+ * Detect which language's INTENT file exists on disk.
27
+ * Priority: zh-CN first, then en. Defaults to zh-CN if neither exists.
23
28
  *
24
- * The returned reader is stateless beyond the workspace binding — each
29
+ * This lets hooks avoid hardcoding a single language — the Owner may have
30
+ * created either INTENT.zh-CN.md or INTENT.en.md.
31
+ */
32
+ export function resolveIntentLang(workspaceDir) {
33
+ const zhPath = path.join(workspaceDir, INTENT_DIR, getIntentFilename('zh-CN'));
34
+ if (fs.existsSync(zhPath))
35
+ return 'zh-CN';
36
+ const enPath = path.join(workspaceDir, INTENT_DIR, getIntentFilename('en'));
37
+ if (fs.existsSync(enPath))
38
+ return 'en';
39
+ return 'zh-CN';
40
+ }
41
+ /**
42
+ * Create an IntentDocReader bound to a specific workspace and language.
43
+ *
44
+ * The returned reader is stateless beyond the (workspace, lang) binding — each
25
45
  * `readIntentDoc()` call delegates to `safeReadIntentDoc()`, which owns
26
- * the TTL+mtime cache.
46
+ * the TTL+mtime cache keyed by `${workspaceDir}:${lang}`.
27
47
  */
28
- export function createIntentDocReader(workspaceDir) {
48
+ export function createIntentDocReader(workspaceDir, lang) {
29
49
  return {
30
50
  readIntentDoc() {
31
- const result = safeReadIntentDoc(workspaceDir);
51
+ const result = safeReadIntentDoc(workspaceDir, lang);
32
52
  if (result.ok && result.doc) {
33
53
  const doc = result.doc;
34
54
  const reference = {
@@ -21,7 +21,7 @@
21
21
  * Architecture: this file is I/O (fs, path). It is whitelisted in
22
22
  * architecture-regression.test.ts KNOWN_PLUGIN_CORE_FILES.
23
23
  */
24
- import { type IntentDocSections, type IntentDocWarning } from '@principles/core/runtime-v2';
24
+ import { type IntentDocSections, type IntentDocWarning, type IntentLang } from '@principles/core/runtime-v2';
25
25
  export type SafeReadIntentDocReason = 'flag_disabled' | 'not_found' | 'oversized' | 'read_error';
26
26
  export interface IntentDoc {
27
27
  /** Raw INTENT.md content (unescaped — caller escapes for prompt injection). */
@@ -55,9 +55,17 @@ export interface SafeReadIntentDocResult {
55
55
  }
56
56
  /**
57
57
  * Reset the intent doc cache for test isolation.
58
- * Call in beforeEach() to ensure tests don't pollute each other.
58
+ *
59
+ * - No args: clear the whole cache.
60
+ * - workspaceDir only: delete all entries for that workspace (any lang).
61
+ * Keys are formatted as `${workspaceDir}:${lang}`, so we match by prefix.
62
+ * - workspaceDir + lang: delete the single `${workspaceDir}:${lang}` entry.
63
+ *
64
+ * Note: prompt.ts resetPromptStateForTest passes workspaceDir only — the
65
+ * previous signature treated it as a literal cache key, which never matched
66
+ * the `${workspaceDir}:${lang}` format and silently left entries behind.
59
67
  */
60
- export declare function resetIntentDocCacheForTest(workspaceDir?: string): void;
68
+ export declare function resetIntentDocCacheForTest(workspaceDir?: string, lang?: IntentLang): void;
61
69
  /**
62
70
  * Safely read INTENT.md for prompt injection.
63
71
  *
@@ -69,10 +77,11 @@ export declare function resetIntentDocCacheForTest(workspaceDir?: string): void;
69
77
  * 4. Never throws — all errors return structured reason + nextAction.
70
78
  *
71
79
  * @param workspaceDir - Absolute path to the workspace root
80
+ * @param lang - Mandatory language code ('zh-CN' | 'en'); selects INTENT.${lang}.md
72
81
  * @param options - Optional logger for debug-level diagnostics
73
82
  * @returns SafeReadIntentDocResult (never throws)
74
83
  */
75
- export declare function safeReadIntentDoc(workspaceDir: string, options?: {
84
+ export declare function safeReadIntentDoc(workspaceDir: string, lang: IntentLang, options?: {
76
85
  logger?: {
77
86
  debug?: (msg: string) => void;
78
87
  warn?: (msg: string) => void;
@@ -23,29 +23,48 @@
23
23
  */
24
24
  import * as fs from 'node:fs';
25
25
  import * as path from 'node:path';
26
- import { INTENT_MAX_BYTES, parseIntentDocSections, computeIntentContentHash, validateIntentDocSections, } from '@principles/core/runtime-v2';
26
+ import { INTENT_MAX_BYTES, getIntentFilename, parseIntentDocSections, computeIntentContentHash, validateIntentDocSections, } from '@principles/core/runtime-v2';
27
27
  import { loadFeatureFlagFromConfig } from './pd-config-loader.js';
28
28
  // ── Constants ────────────────────────────────────────────────────────────────
29
- const INTENT_FILENAME = 'INTENT.md';
30
29
  const INTENT_DIR = '.principles';
31
30
  const INTENT_CACHE_TTL_MS = 60_000; // 1 minute (SPEC §12.1)
32
31
  // ── Module-level cache (per-workspace) ───────────────────────────────────────
33
32
  const _intentDocCache = new Map();
34
33
  /**
35
34
  * Reset the intent doc cache for test isolation.
36
- * Call in beforeEach() to ensure tests don't pollute each other.
35
+ *
36
+ * - No args: clear the whole cache.
37
+ * - workspaceDir only: delete all entries for that workspace (any lang).
38
+ * Keys are formatted as `${workspaceDir}:${lang}`, so we match by prefix.
39
+ * - workspaceDir + lang: delete the single `${workspaceDir}:${lang}` entry.
40
+ *
41
+ * Note: prompt.ts resetPromptStateForTest passes workspaceDir only — the
42
+ * previous signature treated it as a literal cache key, which never matched
43
+ * the `${workspaceDir}:${lang}` format and silently left entries behind.
37
44
  */
38
- export function resetIntentDocCacheForTest(workspaceDir) {
39
- if (workspaceDir) {
40
- _intentDocCache.delete(workspaceDir);
41
- }
42
- else {
45
+ export function resetIntentDocCacheForTest(workspaceDir, lang) {
46
+ if (workspaceDir === undefined) {
43
47
  _intentDocCache.clear();
48
+ return;
49
+ }
50
+ if (lang !== undefined) {
51
+ _intentDocCache.delete(`${workspaceDir}:${lang}`);
52
+ return;
53
+ }
54
+ // workspaceDir only — clear all langs for this workspace by prefix.
55
+ const prefix = `${workspaceDir}:`;
56
+ for (const key of _intentDocCache.keys()) {
57
+ if (key.startsWith(prefix)) {
58
+ _intentDocCache.delete(key);
59
+ }
44
60
  }
45
61
  }
46
62
  // ── Helpers ──────────────────────────────────────────────────────────────────
47
- function getIntentFilePath(workspaceDir) {
48
- return path.join(workspaceDir, INTENT_DIR, INTENT_FILENAME);
63
+ function getIntentFilePath(workspaceDir, lang) {
64
+ return path.join(workspaceDir, INTENT_DIR, getIntentFilename(lang));
65
+ }
66
+ function getCacheKey(workspaceDir, lang) {
67
+ return `${workspaceDir}:${lang}`;
49
68
  }
50
69
  function buildDocFromRaw(raw, filePath, readAt) {
51
70
  const sections = parseIntentDocSections(raw);
@@ -72,10 +91,11 @@ function buildDocFromRaw(raw, filePath, readAt) {
72
91
  * 4. Never throws — all errors return structured reason + nextAction.
73
92
  *
74
93
  * @param workspaceDir - Absolute path to the workspace root
94
+ * @param lang - Mandatory language code ('zh-CN' | 'en'); selects INTENT.${lang}.md
75
95
  * @param options - Optional logger for debug-level diagnostics
76
96
  * @returns SafeReadIntentDocResult (never throws)
77
97
  */
78
- export function safeReadIntentDoc(workspaceDir, options) {
98
+ export function safeReadIntentDoc(workspaceDir, lang, options) {
79
99
  // SPEC §12 — Flag check FIRST. Flag off → no fs access, no cache access.
80
100
  const flagResult = loadFeatureFlagFromConfig(workspaceDir, 'intent_engineering', options?.logger);
81
101
  if (!flagResult.enabled) {
@@ -84,14 +104,15 @@ export function safeReadIntentDoc(workspaceDir, options) {
84
104
  found: false,
85
105
  flagEnabled: false,
86
106
  reason: 'flag_disabled',
87
- nextAction: 'Enable the intent_engineering feature flag in .pd/config.yaml to read INTENT.md.',
107
+ nextAction: `Enable the intent_engineering feature flag in .pd/config.yaml to read ${getIntentFilename(lang)}.`,
88
108
  warnings: [],
89
109
  };
90
110
  }
91
- const filePath = getIntentFilePath(workspaceDir);
111
+ const cacheKey = getCacheKey(workspaceDir, lang);
112
+ const filePath = getIntentFilePath(workspaceDir, lang);
92
113
  const now = Date.now();
93
114
  // Check cache freshness (TTL + mtime)
94
- const cached = _intentDocCache.get(workspaceDir);
115
+ const cached = _intentDocCache.get(cacheKey);
95
116
  if (cached && (now - cached.loadedAt) < INTENT_CACHE_TTL_MS) {
96
117
  // Cache is within TTL. Verify mtime hasn't changed.
97
118
  try {
@@ -117,26 +138,26 @@ export function safeReadIntentDoc(workspaceDir, options) {
117
138
  // Check existence first
118
139
  if (!fs.existsSync(filePath)) {
119
140
  // Invalidate stale cache entry if any
120
- _intentDocCache.delete(workspaceDir);
141
+ _intentDocCache.delete(cacheKey);
121
142
  return {
122
143
  ok: false,
123
144
  found: false,
124
145
  flagEnabled: true,
125
146
  reason: 'not_found',
126
- nextAction: 'Create .principles/INTENT.md using "pd intent init".',
147
+ nextAction: `Create .principles/${getIntentFilename(lang)} using "pd intent init".`,
127
148
  warnings: [],
128
149
  };
129
150
  }
130
151
  const stat = fs.statSync(filePath);
131
152
  // SPEC §12 — 32KB size cap
132
153
  if (stat.size > INTENT_MAX_BYTES) {
133
- _intentDocCache.delete(workspaceDir);
154
+ _intentDocCache.delete(cacheKey);
134
155
  return {
135
156
  ok: false,
136
157
  found: true,
137
158
  flagEnabled: true,
138
159
  reason: 'oversized',
139
- nextAction: `INTENT.md exceeds ${INTENT_MAX_BYTES} bytes (${stat.size} bytes). Reduce content.`,
160
+ nextAction: `${getIntentFilename(lang)} exceeds ${INTENT_MAX_BYTES} bytes (${stat.size} bytes). Reduce content.`,
140
161
  warnings: [],
141
162
  };
142
163
  }
@@ -147,19 +168,19 @@ export function safeReadIntentDoc(workspaceDir, options) {
147
168
  // an oversized file would enter parse/hash/cache as ok:true.
148
169
  const actualBytes = Buffer.byteLength(raw, 'utf8');
149
170
  if (actualBytes > INTENT_MAX_BYTES) {
150
- _intentDocCache.delete(workspaceDir);
171
+ _intentDocCache.delete(cacheKey);
151
172
  return {
152
173
  ok: false,
153
174
  found: true,
154
175
  flagEnabled: true,
155
176
  reason: 'oversized',
156
- nextAction: `INTENT.md exceeds ${INTENT_MAX_BYTES} bytes (${actualBytes} bytes after read). Reduce content.`,
177
+ nextAction: `${getIntentFilename(lang)} exceeds ${INTENT_MAX_BYTES} bytes (${actualBytes} bytes after read). Reduce content.`,
157
178
  warnings: [],
158
179
  };
159
180
  }
160
181
  const doc = buildDocFromRaw(raw, filePath, new Date(now).toISOString());
161
182
  // Update cache
162
- _intentDocCache.set(workspaceDir, {
183
+ _intentDocCache.set(cacheKey, {
163
184
  doc,
164
185
  mtime: stat.mtimeMs,
165
186
  loadedAt: now,
@@ -174,15 +195,15 @@ export function safeReadIntentDoc(workspaceDir, options) {
174
195
  }
175
196
  catch (err) {
176
197
  // ERR-002 — graceful degradation with reason + nextAction
177
- _intentDocCache.delete(workspaceDir);
198
+ _intentDocCache.delete(cacheKey);
178
199
  const message = err instanceof Error ? err.message : String(err);
179
- options?.logger?.warn?.(`[PD:Intent] safeReadIntentDoc failed: workspace=${workspaceDir}, error=${message}`);
200
+ options?.logger?.warn?.(`[PD:Intent] safeReadIntentDoc failed: workspace=${workspaceDir}, lang=${lang}, error=${message}`);
180
201
  return {
181
202
  ok: false,
182
203
  found: false,
183
204
  flagEnabled: true,
184
205
  reason: 'read_error',
185
- nextAction: 'Check filesystem permissions for .principles/INTENT.md.',
206
+ nextAction: `Check filesystem permissions for .principles/${getIntentFilename(lang)}.`,
186
207
  warnings: [],
187
208
  };
188
209
  }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * PRI-482 Phase 3 — Production RuleContext v2 assembler
3
+ *
4
+ * Converts raw TrajectoryDatabase rows into a validated RuleHistoryWindow,
5
+ * and provides buildProductionRuleContext for gate integration.
6
+ *
7
+ * ERR prevention:
8
+ * - ERR-001: every row field is validated as unknown. No `as` bypass on
9
+ * parsed params_json or outcome.
10
+ * - ERR-024: buildProductionRuleContext fail-soft — query failure returns
11
+ * unavailable, never throws.
12
+ * - ERR-025: callers use recordToolCall → getRuleHostContextRows → this
13
+ * assembler, covering the full production chain.
14
+ *
15
+ * Spec: docs/superpowers/specs/2026-06-27-rulecode-context-vision-design.md §5.
16
+ */
17
+ import type { RuleContextV2, RuleHistoryWindow } from '@principles/core/runtime-v2';
18
+ import type { RuleHostContextResult, RuleHostContextRow } from './trajectory-types.js';
19
+ /**
20
+ * Minimal interface for the data source that TrajectoryDatabase satisfies.
21
+ * Allows testing buildProductionRuleContext without a real DB.
22
+ */
23
+ export interface RuleContextDataSource {
24
+ getRuleHostContextRows(sessionId: string, limit: number): RuleHostContextResult;
25
+ }
26
+ /**
27
+ * Convert raw DB rows into a validated RuleHistoryWindow.
28
+ *
29
+ * If ANY row is malformed (bad params_json, invalid outcome, empty tool_name),
30
+ * the entire window is marked unavailable (fail loud, spec §5.2).
31
+ *
32
+ * ERR-001: row fields are validated as unknown. params_json is JSON.parsed
33
+ * then structurally checked (must be a non-array object). No `as` bypass.
34
+ */
35
+ export declare function assembleHistoryFromRows(rows: readonly RuleHostContextRow[], truncated: boolean, projectDir: string): RuleHistoryWindow;
36
+ /**
37
+ * Build a RuleContextV2 from the production data source (TrajectoryDatabase).
38
+ *
39
+ * ERR-024: if the query or assembly fails, returns an unavailable context
40
+ * (fail-soft). Never throws.
41
+ *
42
+ * sameActionBlockCount is always null in this version (spec §5.4:
43
+ * session-tracker.blockedAttempts is a session total, not per-action).
44
+ */
45
+ export declare function buildProductionRuleContext(sessionId: string | null | undefined, targetPath: string | null, source: RuleContextDataSource, projectDir: string, limit?: number): RuleContextV2;
@@ -0,0 +1,148 @@
1
+ /**
2
+ * PRI-482 Phase 3 — Production RuleContext v2 assembler
3
+ *
4
+ * Converts raw TrajectoryDatabase rows into a validated RuleHistoryWindow,
5
+ * and provides buildProductionRuleContext for gate integration.
6
+ *
7
+ * ERR prevention:
8
+ * - ERR-001: every row field is validated as unknown. No `as` bypass on
9
+ * parsed params_json or outcome.
10
+ * - ERR-024: buildProductionRuleContext fail-soft — query failure returns
11
+ * unavailable, never throws.
12
+ * - ERR-025: callers use recordToolCall → getRuleHostContextRows → this
13
+ * assembler, covering the full production chain.
14
+ *
15
+ * Spec: docs/superpowers/specs/2026-06-27-rulecode-context-vision-design.md §5.
16
+ */
17
+ import { canonicalizeToolKind, computeBehaviorFacts, extractFilePathFromParams, normalizePathPure, UNAVAILABLE_RULE_CONTEXT, } from '@principles/core/runtime-v2';
18
+ // ── internal constants ─────────────────────────────────────────────────────
19
+ const VALID_OUTCOMES = new Set([
20
+ 'success',
21
+ 'failure',
22
+ 'blocked',
23
+ ]);
24
+ const DEFAULT_HISTORY_LIMIT = 20;
25
+ // ── type guards (rc-2: no `as` bypass) ─────────────────────────────────────
26
+ function isPlainObject(value) {
27
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
28
+ }
29
+ function isRuleToolOutcome(value) {
30
+ return typeof value === 'string' && VALID_OUTCOMES.has(value);
31
+ }
32
+ // ── assembleHistoryFromRows ────────────────────────────────────────────────
33
+ /**
34
+ * Convert raw DB rows into a validated RuleHistoryWindow.
35
+ *
36
+ * If ANY row is malformed (bad params_json, invalid outcome, empty tool_name),
37
+ * the entire window is marked unavailable (fail loud, spec §5.2).
38
+ *
39
+ * ERR-001: row fields are validated as unknown. params_json is JSON.parsed
40
+ * then structurally checked (must be a non-array object). No `as` bypass.
41
+ */
42
+ export function assembleHistoryFromRows(rows, truncated, projectDir) {
43
+ const records = [];
44
+ for (const row of rows) {
45
+ // ── validate tool_name (ERR-001: unknown) ──
46
+ const toolName = row.toolName;
47
+ if (typeof toolName !== 'string' || toolName.length === 0) {
48
+ return unavailable(`row id=${row.id}: tool_name must be a non-empty string`);
49
+ }
50
+ // ── validate outcome (ERR-001: unknown, enum check) ──
51
+ const outcome = row.outcome;
52
+ if (!isRuleToolOutcome(outcome)) {
53
+ return unavailable(`row id=${row.id}: outcome "${row.outcome}" is not a valid RuleToolOutcome`);
54
+ }
55
+ // ── validate & parse params_json (ERR-001: unknown) ──
56
+ const paramsJsonStr = row.paramsJson;
57
+ if (typeof paramsJsonStr !== 'string') {
58
+ return unavailable(`row id=${row.id}: params_json must be a string`);
59
+ }
60
+ let parsedParams;
61
+ try {
62
+ parsedParams = JSON.parse(paramsJsonStr);
63
+ }
64
+ catch {
65
+ return unavailable(`row id=${row.id}: params_json is not valid JSON`);
66
+ }
67
+ // Must be a non-array object (spec §5.2)
68
+ if (!isPlainObject(parsedParams)) {
69
+ return unavailable(`row id=${row.id}: params_json must parse to a non-array object`);
70
+ }
71
+ // ── build RuleToolCallRecord ──
72
+ const canonicalKind = canonicalizeToolKind(toolName);
73
+ // Extract normalized path using the same pure logic as buildRuleHostAction
74
+ // (avoids production/replay drift, spec §4.4)
75
+ const rawPath = extractFilePathFromParams(parsedParams, {
76
+ isBashTool: canonicalKind === 'execute',
77
+ isWriteTool: canonicalKind === 'write',
78
+ toolName,
79
+ });
80
+ const normalizedPath = normalizePathPure(rawPath, projectDir);
81
+ records.push({
82
+ sequenceId: row.id,
83
+ toolName,
84
+ canonicalKind,
85
+ normalizedPath: normalizedPath === '' ? null : normalizedPath,
86
+ paramsSummary: parsedParams,
87
+ outcome,
88
+ });
89
+ }
90
+ return {
91
+ status: 'available',
92
+ truncated,
93
+ calls: records,
94
+ };
95
+ }
96
+ // ── buildProductionRuleContext ─────────────────────────────────────────────
97
+ /**
98
+ * Build a RuleContextV2 from the production data source (TrajectoryDatabase).
99
+ *
100
+ * ERR-024: if the query or assembly fails, returns an unavailable context
101
+ * (fail-soft). Never throws.
102
+ *
103
+ * sameActionBlockCount is always null in this version (spec §5.4:
104
+ * session-tracker.blockedAttempts is a session total, not per-action).
105
+ */
106
+ export function buildProductionRuleContext(sessionId, targetPath, source, projectDir, limit = DEFAULT_HISTORY_LIMIT) {
107
+ // Guard: no session → no context
108
+ if (!sessionId || typeof sessionId !== 'string' || sessionId.length === 0) {
109
+ return UNAVAILABLE_RULE_CONTEXT;
110
+ }
111
+ try {
112
+ const result = source.getRuleHostContextRows(sessionId, limit);
113
+ const history = assembleHistoryFromRows(result.rows, result.truncated, projectDir);
114
+ // sameActionBlockCount = null (spec §5.4 — no reliable per-action source)
115
+ const facts = computeBehaviorFacts(history, targetPath, null);
116
+ return {
117
+ version: 2,
118
+ history,
119
+ facts,
120
+ };
121
+ }
122
+ catch {
123
+ // ERR-024: fail-soft — never let a DB error propagate to the rule host
124
+ return unavailableContext('query or assembly failed');
125
+ }
126
+ }
127
+ // ── internal helpers ───────────────────────────────────────────────────────
128
+ function unavailable(reason) {
129
+ return {
130
+ status: 'unavailable',
131
+ unavailableReason: reason,
132
+ truncated: false,
133
+ calls: [],
134
+ };
135
+ }
136
+ function unavailableContext(reason) {
137
+ return {
138
+ version: 2,
139
+ history: unavailable(reason),
140
+ facts: {
141
+ priorReadOfTarget: 'unknown',
142
+ readCount: null,
143
+ writeCount: null,
144
+ uniqueWritePathCount: null,
145
+ sameActionBlockCount: null,
146
+ },
147
+ };
148
+ }
@@ -1,49 +1,19 @@
1
1
  /**
2
- * Thinking Models — Detection Engine
2
+ * Thinking Models — Plugin I/O Adapter (Stage 3 slim)
3
3
  *
4
- * Core principle metadata (id, name, description) comes from the
5
- * Core Principle Registry in @principles/core/runtime-v2.
6
- * Detection patterns are carefully tuned regexes that match AI output text.
4
+ * Pure logic (BUILTIN_PATTERNS, BUILTIN_PATTERN_MAP, getFallbackName,
5
+ * getFallbackDescription, deriveThinkingScenarios, types) lives in
6
+ * @principles/core/runtime-v2/thinking-models.
7
7
  *
8
- * Flow:
9
- * Core Principle Registry (authority) id, name, description
10
- * BUILTIN_PATTERNS (engine) detection regexes per model id
11
- * THINKING_MODELS (merged) full definitions with patterns
8
+ * This file owns only the I/O boundary: reading THINKING_OS.md from a
9
+ * workspace dir and merging it with the builtin patterns. It re-exports
10
+ * the pure functions and types so existing relative imports
11
+ * (../core/thinking-models.js) continue to resolve.
12
12
  */
13
- export interface ThinkingModelDefinition {
14
- id: string;
15
- name: string;
16
- description: string;
17
- antiPattern?: string;
18
- patterns: RegExp[];
19
- baselineScenarios: string[];
20
- }
21
- export interface ThinkingModelMatch {
22
- modelId: string;
23
- matchedPattern: string;
24
- }
25
- export interface ThinkingScenarioContext {
26
- recentToolCalls?: {
27
- toolName: string;
28
- outcome: 'success' | 'failure' | 'blocked';
29
- errorType?: string | null;
30
- }[];
31
- recentPainEvents?: {
32
- source: string;
33
- score: number;
34
- }[];
35
- recentGateBlocks?: {
36
- toolName: string;
37
- reason: string;
38
- }[];
39
- recentUserCorrections?: {
40
- correctionCue?: string | null;
41
- }[];
42
- recentPrincipleEvents?: {
43
- eventType: string;
44
- principleId?: string | null;
45
- }[];
46
- }
13
+ import { type ThinkingModelDefinition, type ThinkingModelMatch } from '@principles/core/runtime-v2';
14
+ export { BUILTIN_PATTERN_MAP, getFallbackName, getFallbackDescription, } from '@principles/core/runtime-v2';
15
+ export { deriveThinkingScenarios } from '@principles/core/runtime-v2';
16
+ export type { ThinkingModelDefinition, ThinkingModelMatch, ThinkingScenarioContext, } from '@principles/core/runtime-v2';
47
17
  /**
48
18
  * Load thinking model definitions dynamically from THINKING_OS.md.
49
19
  * Falls back to built-in definitions if parsing fails.
@@ -51,20 +21,5 @@ export interface ThinkingScenarioContext {
51
21
  * @param workspaceDir Optional. If provided, loads from that workspace's THINKING_OS.md.
52
22
  */
53
23
  export declare function listThinkingModels(workspaceDir?: string): ThinkingModelDefinition[];
54
- /**
55
- * Clear the cached model definitions.
56
- * Call this when THINKING_OS.md changes.
57
- */
58
- export declare function clearThinkingModelCache(): void;
59
24
  export declare function getThinkingModel(modelId: string, workspaceDir?: string): ThinkingModelDefinition | undefined;
60
25
  export declare function detectThinkingModelMatches(text: string, workspaceDir?: string): ThinkingModelMatch[];
61
- /**
62
- * Get all model definitions for display purposes (no patterns).
63
- */
64
- export declare function getThinkingModelDefinitions(workspaceDir?: string): {
65
- modelId: string;
66
- name: string;
67
- description: string;
68
- antiPattern?: string;
69
- }[];
70
- export declare function deriveThinkingScenarios(modelId: string, context: ThinkingScenarioContext): string[];