create-principles-disciple 1.152.5 → 1.153.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/agent-skill/pd-setup/SKILL.md +70 -0
  3. package/codex-adapter/dist/background-selection.d.ts +9 -0
  4. package/codex-adapter/dist/background-selection.js +142 -0
  5. package/codex-adapter/dist/ingestion/adaptive-append-state.d.ts +209 -0
  6. package/codex-adapter/dist/ingestion/adaptive-append-state.js +544 -0
  7. package/codex-adapter/dist/pd-hook.js +329 -5
  8. package/codex-adapter/package.json +1 -1
  9. package/console/dist/server/config/pd-config-store.d.ts +11 -15
  10. package/console/dist/server/config/pd-config-store.js +92 -17
  11. package/console/dist/server/models/ActivationsConsoleModel.d.ts +8 -0
  12. package/console/dist/server/models/ActivationsConsoleModel.js +3 -2
  13. package/console/dist/server/models/AdaptiveActivationConsoleModel.d.ts +43 -4
  14. package/console/dist/server/models/AdaptiveActivationConsoleModel.js +36 -7
  15. package/console/dist/server/models/ExaminerEvidenceModel.d.ts +6 -2
  16. package/console/dist/server/models/ExaminerEvidenceModel.js +13 -2
  17. package/console/dist/server/routes/config.js +34 -8
  18. package/console/dist/server/routes/examiner-executor.d.ts +33 -0
  19. package/console/dist/server/routes/examiner-executor.js +95 -0
  20. package/console/dist/server/routes/examiner.js +12 -9
  21. package/console/dist/web/assets/app.css +14 -10
  22. package/console/dist/web/assets/app.js +27 -27
  23. package/core/dist/ledger-file-lock.d.ts +38 -0
  24. package/core/dist/ledger-file-lock.d.ts.map +1 -0
  25. package/core/dist/ledger-file-lock.js +240 -0
  26. package/core/dist/ledger-file-lock.js.map +1 -0
  27. package/core/dist/principle-text-normalization.d.ts +32 -0
  28. package/core/dist/principle-text-normalization.d.ts.map +1 -0
  29. package/core/dist/principle-text-normalization.js +34 -0
  30. package/core/dist/principle-text-normalization.js.map +1 -0
  31. package/core/dist/principle-tree-ledger.d.ts +22 -21
  32. package/core/dist/principle-tree-ledger.d.ts.map +1 -1
  33. package/core/dist/principle-tree-ledger.js +77 -204
  34. package/core/dist/principle-tree-ledger.js.map +1 -1
  35. package/core/dist/runtime/activation/sqlite-approval-store.d.ts.map +1 -1
  36. package/core/dist/runtime/activation/sqlite-approval-store.js +7 -1
  37. package/core/dist/runtime/activation/sqlite-approval-store.js.map +1 -1
  38. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +13 -0
  39. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  40. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +90 -1
  41. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
  42. package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts.map +1 -1
  43. package/core/dist/runtime/adapter/schema-prompt-adapter.js +21 -30
  44. package/core/dist/runtime/adapter/schema-prompt-adapter.js.map +1 -1
  45. package/core/dist/runtime/candidate-intake-service.d.ts +40 -1
  46. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  47. package/core/dist/runtime/candidate-intake-service.js +548 -110
  48. package/core/dist/runtime/candidate-intake-service.js.map +1 -1
  49. package/core/dist/runtime/candidate-intake.d.ts +59 -2
  50. package/core/dist/runtime/candidate-intake.d.ts.map +1 -1
  51. package/core/dist/runtime/candidate-intake.js +23 -0
  52. package/core/dist/runtime/candidate-intake.js.map +1 -1
  53. package/core/dist/runtime/candidate-seed-suppression.d.ts +63 -0
  54. package/core/dist/runtime/candidate-seed-suppression.d.ts.map +1 -0
  55. package/core/dist/runtime/candidate-seed-suppression.js +29 -0
  56. package/core/dist/runtime/candidate-seed-suppression.js.map +1 -0
  57. package/core/dist/runtime/config/pd-config-agent-binding.d.ts +5 -5
  58. package/core/dist/runtime/config/pd-config-agent-binding.d.ts.map +1 -1
  59. package/core/dist/runtime/config/pd-config-agent-binding.js +22 -16
  60. package/core/dist/runtime/config/pd-config-agent-binding.js.map +1 -1
  61. package/core/dist/runtime/config/pd-config-feature-flags.d.ts +10 -0
  62. package/core/dist/runtime/config/pd-config-feature-flags.d.ts.map +1 -1
  63. package/core/dist/runtime/config/pd-config-feature-flags.js +14 -0
  64. package/core/dist/runtime/config/pd-config-feature-flags.js.map +1 -1
  65. package/core/dist/runtime/config/pd-config-types.d.ts +9 -0
  66. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  67. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  68. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  69. package/core/dist/runtime/config/pd-config-validate.js +10 -2
  70. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  71. package/core/dist/runtime/config/pd-credentials.d.ts.map +1 -1
  72. package/core/dist/runtime/config/pd-credentials.js +7 -1
  73. package/core/dist/runtime/config/pd-credentials.js.map +1 -1
  74. package/core/dist/runtime/diagnostician/distiller-prompt-builder.d.ts.map +1 -1
  75. package/core/dist/runtime/diagnostician/distiller-prompt-builder.js +30 -3
  76. package/core/dist/runtime/diagnostician/distiller-prompt-builder.js.map +1 -1
  77. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  78. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +16 -5
  79. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  80. package/core/dist/runtime/diagnostician/router-prompt-builder.d.ts.map +1 -1
  81. package/core/dist/runtime/diagnostician/router-prompt-builder.js +16 -4
  82. package/core/dist/runtime/diagnostician/router-prompt-builder.js.map +1 -1
  83. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  84. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +13 -2
  85. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  86. package/core/dist/runtime/index.d.ts +4 -2
  87. package/core/dist/runtime/index.d.ts.map +1 -1
  88. package/core/dist/runtime/index.js +3 -1
  89. package/core/dist/runtime/index.js.map +1 -1
  90. package/core/dist/runtime/intent/intent-doc.d.ts +22 -0
  91. package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
  92. package/core/dist/runtime/intent/intent-doc.js +79 -0
  93. package/core/dist/runtime/intent/intent-doc.js.map +1 -1
  94. package/core/dist/runtime/intent/intent-friction-block.d.ts +7 -0
  95. package/core/dist/runtime/intent/intent-friction-block.d.ts.map +1 -1
  96. package/core/dist/runtime/intent/intent-friction-block.js +34 -1
  97. package/core/dist/runtime/intent/intent-friction-block.js.map +1 -1
  98. package/core/dist/runtime/intent/intent-snapshot.d.ts +44 -5
  99. package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -1
  100. package/core/dist/runtime/intent/intent-snapshot.js +83 -15
  101. package/core/dist/runtime/intent/intent-snapshot.js.map +1 -1
  102. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts +19 -0
  103. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts.map +1 -1
  104. package/core/dist/runtime/intent/strategic-conflict-gate.js +94 -26
  105. package/core/dist/runtime/intent/strategic-conflict-gate.js.map +1 -1
  106. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +22 -11
  107. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  108. package/core/dist/runtime/internalization/diag-rootcause-runner.js +101 -28
  109. package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
  110. package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
  111. package/core/dist/runtime/internalization/dreamer-prompt-builder.js +177 -28
  112. package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
  113. package/core/dist/runtime/internalization/dreamer-runner.d.ts +9 -2
  114. package/core/dist/runtime/internalization/dreamer-runner.d.ts.map +1 -1
  115. package/core/dist/runtime/internalization/dreamer-runner.js +11 -1
  116. package/core/dist/runtime/internalization/dreamer-runner.js.map +1 -1
  117. package/core/dist/runtime/internalization/evaluator-runner.d.ts.map +1 -1
  118. package/core/dist/runtime/internalization/evaluator-runner.js +7 -0
  119. package/core/dist/runtime/internalization/evaluator-runner.js.map +1 -1
  120. package/core/dist/runtime/internalization/formation-context.d.ts +16 -0
  121. package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
  122. package/core/dist/runtime/internalization/formation-context.js +109 -8
  123. package/core/dist/runtime/internalization/formation-context.js.map +1 -1
  124. package/core/dist/runtime/internalization/index.d.ts +2 -2
  125. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  126. package/core/dist/runtime/internalization/index.js +1 -1
  127. package/core/dist/runtime/internalization/index.js.map +1 -1
  128. package/core/dist/runtime/internalization/intent-contract.d.ts +55 -4
  129. package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
  130. package/core/dist/runtime/internalization/intent-contract.js +111 -30
  131. package/core/dist/runtime/internalization/intent-contract.js.map +1 -1
  132. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +16 -2
  133. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  134. package/core/dist/runtime/internalization/internalization-orchestrator.js +48 -14
  135. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  136. package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
  137. package/core/dist/runtime/internalization/philosopher-prompt-builder.js +7 -6
  138. package/core/dist/runtime/internalization/philosopher-prompt-builder.js.map +1 -1
  139. package/core/dist/runtime/internalization/philosopher-runner.d.ts +9 -2
  140. package/core/dist/runtime/internalization/philosopher-runner.d.ts.map +1 -1
  141. package/core/dist/runtime/internalization/philosopher-runner.js +11 -1
  142. package/core/dist/runtime/internalization/philosopher-runner.js.map +1 -1
  143. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +13 -6
  144. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
  145. package/core/dist/runtime/internalization/scribe-prompt-builder.js +15 -10
  146. package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
  147. package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
  148. package/core/dist/runtime/internalization/scribe-runner.js +17 -7
  149. package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
  150. package/core/dist/runtime/pain-signal-bridge.d.ts +3 -0
  151. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  152. package/core/dist/runtime/pain-signal-bridge.js +224 -93
  153. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  154. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  155. package/core/dist/runtime/pain-submit-capability.js +3 -5
  156. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  157. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  158. package/core/dist/runtime/pain-to-principle-service.js +18 -21
  159. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  160. package/core/dist/runtime/store/candidate/admission-document.d.ts +129 -0
  161. package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
  162. package/core/dist/runtime/store/candidate/admission-document.js +196 -0
  163. package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
  164. package/core/dist/runtime/store/candidate/candidate-store.d.ts +54 -1
  165. package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
  166. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +32 -1
  167. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
  168. package/core/dist/runtime/store/candidate/memory-candidate-store.js +24 -1
  169. package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
  170. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +32 -1
  171. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
  172. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +76 -1
  173. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
  174. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts +10 -0
  175. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
  176. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js +15 -4
  177. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js.map +1 -1
  178. package/core/dist/runtime/store/runtime-state-manager.d.ts +34 -1
  179. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  180. package/core/dist/runtime/store/runtime-state-manager.js +10 -0
  181. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  182. package/core/dist/telemetry-event.d.ts +2 -2
  183. package/core/dist/telemetry-event.d.ts.map +1 -1
  184. package/core/dist/telemetry-event.js +6 -0
  185. package/core/dist/telemetry-event.js.map +1 -1
  186. package/core/package.json +1 -1
  187. package/dist/agent-skill.d.ts +59 -0
  188. package/dist/agent-skill.d.ts.map +1 -0
  189. package/dist/agent-skill.js +198 -0
  190. package/dist/agent-skill.js.map +1 -0
  191. package/dist/i18n.d.ts.map +1 -1
  192. package/dist/i18n.js +12 -0
  193. package/dist/i18n.js.map +1 -1
  194. package/dist/index.d.ts +3 -1
  195. package/dist/index.d.ts.map +1 -1
  196. package/dist/index.js +171 -3
  197. package/dist/index.js.map +1 -1
  198. package/dist/install-summary.d.ts +52 -0
  199. package/dist/install-summary.d.ts.map +1 -1
  200. package/dist/install-summary.js +104 -0
  201. package/dist/install-summary.js.map +1 -1
  202. package/host-runtime/dist/adaptive-background-append.d.ts +70 -0
  203. package/host-runtime/dist/adaptive-background-append.js +165 -0
  204. package/host-runtime/dist/governance-signal-admission.js +1 -5
  205. package/host-runtime/dist/index.d.ts +1 -0
  206. package/host-runtime/dist/index.js +5 -0
  207. package/host-runtime/package.json +1 -1
  208. package/package.json +3 -2
  209. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  210. package/pd-cli/dist/commands/candidate.js +243 -28
  211. package/pd-cli/dist/commands/candidate.js.map +1 -1
  212. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  213. package/pd-cli/dist/commands/diagnose.js +110 -7
  214. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  215. package/pd-cli/dist/commands/health-console.d.ts +21 -0
  216. package/pd-cli/dist/commands/health-console.d.ts.map +1 -0
  217. package/pd-cli/dist/commands/health-console.js +106 -0
  218. package/pd-cli/dist/commands/health-console.js.map +1 -0
  219. package/pd-cli/dist/commands/health.d.ts +159 -0
  220. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  221. package/pd-cli/dist/commands/health.js +162 -2
  222. package/pd-cli/dist/commands/health.js.map +1 -1
  223. package/pd-cli/dist/commands/mcp-probe.d.ts +48 -0
  224. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -0
  225. package/pd-cli/dist/commands/mcp-probe.js +479 -0
  226. package/pd-cli/dist/commands/mcp-probe.js.map +1 -0
  227. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  228. package/pd-cli/dist/commands/pain-retry.js +3 -0
  229. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  230. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  231. package/pd-cli/dist/commands/runtime-internalization-run-once.js +70 -4
  232. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  233. package/pd-cli/dist/program.d.ts.map +1 -1
  234. package/pd-cli/dist/program.js +68 -1
  235. package/pd-cli/dist/program.js.map +1 -1
  236. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  237. package/pd-cli/dist/services/admission-write-gate.js +18 -7
  238. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  239. package/pd-cli/dist/services/console-launcher.d.ts +3 -0
  240. package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
  241. package/pd-cli/dist/services/console-launcher.js +3 -2
  242. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  243. package/pd-cli/dist/services/demo-story-a-runner.d.ts.map +1 -1
  244. package/pd-cli/dist/services/demo-story-a-runner.js +8 -3
  245. package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
  246. package/pd-cli/dist/services/reuse-park-release.d.ts +142 -0
  247. package/pd-cli/dist/services/reuse-park-release.d.ts.map +1 -0
  248. package/pd-cli/dist/services/reuse-park-release.js +201 -0
  249. package/pd-cli/dist/services/reuse-park-release.js.map +1 -0
  250. package/pd-cli/package.json +1 -1
  251. package/plugin/dist/bundle.js +914 -640
  252. package/plugin/dist/openclaw.plugin.json +1 -1
  253. package/plugin/openclaw.plugin.json +1 -1
  254. package/plugin/package.json +1 -1
  255. package/release-manager/dist/i18n.js +12 -0
  256. package/release-manager/package.json +2 -1
  257. package/workbuddy-adapter/dist/pd-hook.js +37 -3
  258. package/workbuddy-adapter/package.json +1 -1
@@ -21,6 +21,7 @@
21
21
  * EP-03 / ERR-002: missing/invalid input returns empty string, never throws
22
22
  * EP-09: pure function — independently unit-testable without mocks
23
23
  */
24
+ import { type IntentLang } from './intent-doc.js';
24
25
  /**
25
26
  * Maximum number of characters of raw INTENT.md content injected into the
26
27
  * prompt. Oversized content is truncated with a visible marker so the Agent
@@ -37,6 +38,12 @@ export declare const INTENT_INJECT_MAX_CHARS = 4000;
37
38
  */
38
39
  export interface IntentFrictionBlockInput {
39
40
  rawIntentMd: string;
41
+ /**
42
+ * Language of the document, used to recognise the shipped template questions.
43
+ * Optional for backwards compatibility; defaults to 'zh-CN' (the same default
44
+ * `resolveIntentLang()` uses when no file exists).
45
+ */
46
+ lang?: IntentLang;
40
47
  }
41
48
  /**
42
49
  * Truncation marker appended when raw intent content exceeds the budget.
@@ -1 +1 @@
1
- {"version":3,"file":"intent-friction-block.d.ts","sourceRoot":"","sources":["../../../src/runtime/intent/intent-friction-block.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,wBAAwB,0DACoB,CAAC;AAE1D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,wBAAwB,GAAG,SAAS,GAC1C,MAAM,CA8ER"}
1
+ {"version":3,"file":"intent-friction-block.d.ts","sourceRoot":"","sources":["../../../src/runtime/intent/intent-friction-block.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAoBD;;;GAGG;AACH,eAAO,MAAM,wBAAwB,0DACoB,CAAC;AAE1D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,wBAAwB,GAAG,SAAS,GAC1C,MAAM,CA4FR"}
@@ -22,6 +22,7 @@
22
22
  * EP-09: pure function — independently unit-testable without mocks
23
23
  */
24
24
  import { escapeXml } from '../../prompt-builder/xml-escape.js';
25
+ import { analyzeIntentDocSections, assembleIntentDoc, parseIntentDocSections, } from './intent-doc.js';
25
26
  /**
26
27
  * Maximum number of characters of raw INTENT.md content injected into the
27
28
  * prompt. Oversized content is truncated with a visible marker so the Agent
@@ -32,6 +33,24 @@ import { escapeXml } from '../../prompt-builder/xml-escape.js';
32
33
  * leaves room for other appendSystemContext blocks.
33
34
  */
34
35
  export const INTENT_INJECT_MAX_CHARS = 4000;
36
+ /**
37
+ * Keep only OWNER-AUTHORED sections (SPEC §20.1).
38
+ *
39
+ * A template question is not a strategic instruction: injecting it makes the
40
+ * agent treat "What observable change should happen?" as Owner intent. Sections
41
+ * that are missing or still carry template / TODO text are dropped before the
42
+ * prompt block is built.
43
+ */
44
+ function authoredIntentDoc(sections, lang) {
45
+ const analyses = analyzeIntentDocSections(sections, lang);
46
+ const authored = {};
47
+ for (const analysis of analyses) {
48
+ if (analysis.state !== 'authored')
49
+ continue;
50
+ authored[analysis.key] = sections[analysis.key];
51
+ }
52
+ return authored;
53
+ }
35
54
  /**
36
55
  * Truncation marker appended when raw intent content exceeds the budget.
37
56
  * Kept as a constant so tests can match it exactly.
@@ -62,11 +81,25 @@ export function buildIntentFrictionBlock(input) {
62
81
  if (raw.trim().length === 0) {
63
82
  return '';
64
83
  }
84
+ // SPEC §20.1: template / blank sections are not Owner intent. Rebuild the
85
+ // document from authored sections only; when nothing is authored there is no
86
+ // strategic anchor to inject at all.
87
+ const lang = input.lang ?? 'zh-CN';
88
+ const parsed = parseIntentDocSections(raw);
89
+ const parsedAnySection = Object.keys(parsed).length > 0;
90
+ const authored = authoredIntentDoc(parsed, lang);
91
+ const hasAuthored = Object.keys(authored).length > 0;
92
+ // A document with no recognisable section headings is custom content, not a
93
+ // template (there is nothing to filter). Template documents always parse into
94
+ // the five sections, so they cannot reach this branch.
95
+ const scoped = parsedAnySection ? (hasAuthored ? assembleIntentDoc(authored) : '') : raw;
96
+ if (scoped.trim().length === 0)
97
+ return '';
65
98
  // SPEC §12.2 — escape XML/markdown boundaries so the content cannot
66
99
  // break out of the <intent_doc> block or inject live XML tags.
67
100
  // CodeRabbit P2 fix: escape FIRST, then bound the escaped content, so
68
101
  // entity expansion (& → &amp; = 5x) cannot blow the injection budget.
69
- let escaped = escapeXml(raw);
102
+ let escaped = escapeXml(scoped);
70
103
  // SPEC §12.2 — bound the ESCAPED content to INTENT_INJECT_MAX_CHARS.
71
104
  // The truncation marker is appended after the budget cut; it is short
72
105
  // (~60 chars), contains no XML special chars, and the prompt hook's
@@ -1 +1 @@
1
- {"version":3,"file":"intent-friction-block.js","sourceRoot":"","sources":["../../../src/runtime/intent/intent-friction-block.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AA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ED,6DAA6D;IAC7D,MAAM,WAAW,GAAG;;;;;;;;;;;;;iBAaL,CAAC;IAEhB,kDAAkD;IAClD,MAAM,QAAQ,GAAG;EACjB,OAAO;cACK,CAAC;IAEb,+DAA+D;IAC/D,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA4BL,CAAC;IAElB,OAAO,GAAG,WAAW,OAAO,QAAQ,OAAO,aAAa,EAAE,CAAC;AAC7D,CAAC"}
@@ -42,6 +42,16 @@ export interface IntentSnapshotSection {
42
42
  readonly truncated?: boolean;
43
43
  /** True when the section header/body was absent or empty in the document. */
44
44
  readonly missing?: boolean;
45
+ /**
46
+ * True when the body is the shipped template / TODO placeholder rather than
47
+ * Owner-authored content. Mutually exclusive with `missing`.
48
+ *
49
+ * Optional for backward compatibility: a snapshot written before this flag
50
+ * existed is re-classified deterministically by
51
+ * `deriveAuthoredSnapshotSectionKeys()` — historical template text is never
52
+ * trusted just because the flag is absent.
53
+ */
54
+ readonly placeholder?: boolean;
45
55
  }
46
56
  export interface IntentSnapshot {
47
57
  readonly schemaVersion: typeof INTENT_SNAPSHOT_SCHEMA_VERSION;
@@ -74,12 +84,35 @@ export interface BuildIntentSnapshotInput {
74
84
  * with an empty body — it is never back-filled from the model.
75
85
  */
76
86
  export declare function buildIntentSnapshot(input: BuildIntentSnapshotInput): IntentSnapshot;
87
+ /**
88
+ * The authoritative "this section is real Owner intent" set for a snapshot.
89
+ *
90
+ * Deterministic and snapshot-local: the explicit `missing` / `placeholder`
91
+ * flags are honoured, and every other section is RE-CLASSIFIED from its stored
92
+ * text with the same pure rules used at capture time. Re-classification is what
93
+ * makes a pre-flag (historical) snapshot safe: a template body is rejected even
94
+ * though it carries no `placeholder` marker.
95
+ */
96
+ export declare function deriveAuthoredSnapshotSectionKeys(snapshot: IntentSnapshot): ReadonlySet<IntentSnapshotSectionKey>;
97
+ /** True when the snapshot carries at least one Owner-authored section. */
98
+ export declare function hasAuthoredSnapshotSections(snapshot: IntentSnapshot): boolean;
99
+ /**
100
+ * Section-level variant used by tolerant projections (FormationContext), where
101
+ * the value is untrusted JSON rather than a validated `IntentSnapshot`.
102
+ *
103
+ * Returns false for an unknown key, a missing/placeholder entry, or a body that
104
+ * re-classifies as template / blank content.
105
+ */
106
+ export declare function isAuthoredSnapshotSection(section: unknown, lang: IntentLang): boolean;
77
107
  /**
78
108
  * Rebuild the document view used by the Stage A prompt.
79
109
  *
80
110
  * The prompt is always rebuilt from the snapshot (never from disk), so the
81
111
  * first attempt and every retry receive the SAME strategic bytes
82
112
  * (SPEC §6.6 / TECH §5.4 step 5).
113
+ *
114
+ * Only Owner-authored sections are rendered: a template body must never reach
115
+ * the model as a strategic instruction (SPEC §20.1).
83
116
  */
84
117
  export declare function intentSnapshotSectionsToDoc(snapshot: IntentSnapshot): IntentDocSections;
85
118
  /** The prompt-ready `intentDoc.raw`, rebuilt deterministically from sections. */
@@ -92,13 +125,19 @@ export declare function renderIntentSnapshotDoc(snapshot: IntentSnapshot): strin
92
125
  * BEFORE the call, so capture keeps all five bounded sections and the artifact
93
126
  * applies the declared filter here.
94
127
  *
95
- * When the model declared none (no `intentTension`, or an empty
96
- * `relatedIntentFields`), there is nothing to narrow by. Storing an empty
97
- * array would degrade the artifact to a hash-only record — exactly what
98
- * SPEC §6.2 rejects — so the bounded capture is kept as the traceable basis
99
- * that the diagnosis actually received.
128
+ * Non-authored sections (missing / template placeholder) are ALWAYS dropped —
129
+ * they are not strategic evidence and must never be persisted as if they were.
130
+ *
131
+ * Three cases, deliberately distinct (SPEC §20.1):
132
+ * - no declaration (`relatedKeys` empty) → keep every AUTHORED section;
133
+ * - partial declaration → keep `authored ∩ declared`;
134
+ * - declaration with NO valid entry → return an explicitly EMPTY section
135
+ * list. Falling back to the full capture here would let rejected sections
136
+ * re-enter the strategic basis, which is exactly the defect this guards.
100
137
  */
101
138
  export declare function filterIntentSnapshotSections(snapshot: IntentSnapshot, relatedKeys: readonly string[]): IntentSnapshot;
139
+ /** Explicit "no usable strategic sections" projection (never the full capture). */
140
+ export declare function emptyIntentSnapshotSections(snapshot: IntentSnapshot): IntentSnapshot;
102
141
  /** True when the value is a well-formed `IntentSnapshot` (rc-1 / rc-4). */
103
142
  export declare function isValidIntentSnapshot(value: unknown): value is IntentSnapshot;
104
143
  //# sourceMappingURL=intent-snapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"intent-snapshot.d.ts","sourceRoot":"","sources":["../../../src/runtime/intent/intent-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGrE,uDAAuD;AACvD,eAAO,MAAM,8BAA8B,EAAG,CAAU,CAAC;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,OAAO,CAAC;AAEtD,iDAAiD;AACjD,eAAO,MAAM,4BAA4B,YACvC,KAAK,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,CACjB,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC;AAErF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,GAAG,EAAE,wBAAwB,CAAC;IACvC,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,aAAa,EAAE,OAAO,8BAA8B,CAAC;IAC9D,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,8DAA8D;IA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AAU,CAAC;IAC1B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,cAAc,CA2BnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,cAAc,GACvB,WAAW,CAAC,wBAAwB,CAAC,CAYvC;AAED,0EAA0E;AAC1E,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,UAAU,GACf,OAAO,CAST;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,cAAc,GAAG,iBAAiB,CAQvF;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAExE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,cAAc,EACxB,WAAW,EAAE,SAAS,MAAM,EAAE,GAC7B,cAAc,CAOhB;AAED,mFAAmF;AACnF,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc,CAEpF;AAED,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAgC7E"}
@@ -21,7 +21,7 @@
21
21
  * (`{ ...output, intentSnapshot }`). It must not live inside `intentTension`,
22
22
  * whose schema is `additionalProperties: false`.
23
23
  */
24
- import { assembleIntentDoc, parseIntentDocSections } from './intent-doc.js';
24
+ import { assembleIntentDoc, classifyIntentSectionContent, parseIntentDocSections, } from './intent-doc.js';
25
25
  /** Version of the snapshot block shape (SPEC §6.3). */
26
26
  export const INTENT_SNAPSHOT_SCHEMA_VERSION = 1;
27
27
  /**
@@ -59,13 +59,18 @@ export function buildIntentSnapshot(input) {
59
59
  const parsed = parseIntentDocSections(input.raw);
60
60
  const sections = INTENT_SNAPSHOT_SECTION_KEYS.map((key) => {
61
61
  const body = parsed[KEY_TO_DOC_FIELD[key]];
62
- if (typeof body !== 'string' || body.trim() === '') {
62
+ const analysis = classifyIntentSectionContent(KEY_TO_DOC_FIELD[key], body, input.lang);
63
+ if (analysis.state === 'missing') {
63
64
  return { key, text: '', missing: true };
64
65
  }
65
- if (body.length > maxChars) {
66
- return { key, text: body.slice(0, maxChars), truncated: true };
67
- }
68
- return { key, text: body };
66
+ const text = typeof body === 'string' ? body : '';
67
+ const bounded = text.length > maxChars ? text.slice(0, maxChars) : text;
68
+ const truncated = text.length > maxChars ? { truncated: true } : {};
69
+ // A placeholder still stores its (bounded) text for audit, but is marked so
70
+ // no downstream stage can mistake a template question for Owner intent.
71
+ return analysis.state === 'placeholder'
72
+ ? { key, text: bounded, placeholder: true, ...truncated }
73
+ : { key, text: bounded, ...truncated };
69
74
  });
70
75
  return {
71
76
  schemaVersion: INTENT_SNAPSHOT_SCHEMA_VERSION,
@@ -76,17 +81,67 @@ export function buildIntentSnapshot(input) {
76
81
  ...(input.intentVersionId !== undefined ? { intentVersionId: input.intentVersionId } : {}),
77
82
  };
78
83
  }
84
+ /**
85
+ * The authoritative "this section is real Owner intent" set for a snapshot.
86
+ *
87
+ * Deterministic and snapshot-local: the explicit `missing` / `placeholder`
88
+ * flags are honoured, and every other section is RE-CLASSIFIED from its stored
89
+ * text with the same pure rules used at capture time. Re-classification is what
90
+ * makes a pre-flag (historical) snapshot safe: a template body is rejected even
91
+ * though it carries no `placeholder` marker.
92
+ */
93
+ export function deriveAuthoredSnapshotSectionKeys(snapshot) {
94
+ const authored = new Set();
95
+ for (const section of snapshot.sections) {
96
+ if (section.missing === true || section.placeholder === true)
97
+ continue;
98
+ const analysis = classifyIntentSectionContent(KEY_TO_DOC_FIELD[section.key], section.text, snapshot.lang);
99
+ if (analysis.state === 'authored')
100
+ authored.add(section.key);
101
+ }
102
+ return authored;
103
+ }
104
+ /** True when the snapshot carries at least one Owner-authored section. */
105
+ export function hasAuthoredSnapshotSections(snapshot) {
106
+ return deriveAuthoredSnapshotSectionKeys(snapshot).size > 0;
107
+ }
108
+ /**
109
+ * Section-level variant used by tolerant projections (FormationContext), where
110
+ * the value is untrusted JSON rather than a validated `IntentSnapshot`.
111
+ *
112
+ * Returns false for an unknown key, a missing/placeholder entry, or a body that
113
+ * re-classifies as template / blank content.
114
+ */
115
+ export function isAuthoredSnapshotSection(section, lang) {
116
+ if (typeof section !== 'object' || section === null || Array.isArray(section))
117
+ return false;
118
+ const entry = section;
119
+ if (typeof entry.key !== 'string')
120
+ return false;
121
+ if (!INTENT_SNAPSHOT_SECTION_KEYS.includes(entry.key))
122
+ return false;
123
+ if (entry.missing === true || entry.placeholder === true)
124
+ return false;
125
+ if (typeof entry.text !== 'string')
126
+ return false;
127
+ const key = entry.key;
128
+ return classifyIntentSectionContent(KEY_TO_DOC_FIELD[key], entry.text, lang).state === 'authored';
129
+ }
79
130
  /**
80
131
  * Rebuild the document view used by the Stage A prompt.
81
132
  *
82
133
  * The prompt is always rebuilt from the snapshot (never from disk), so the
83
134
  * first attempt and every retry receive the SAME strategic bytes
84
135
  * (SPEC §6.6 / TECH §5.4 step 5).
136
+ *
137
+ * Only Owner-authored sections are rendered: a template body must never reach
138
+ * the model as a strategic instruction (SPEC §20.1).
85
139
  */
86
140
  export function intentSnapshotSectionsToDoc(snapshot) {
141
+ const authored = deriveAuthoredSnapshotSectionKeys(snapshot);
87
142
  const doc = {};
88
143
  for (const section of snapshot.sections) {
89
- if (section.missing === true)
144
+ if (!authored.has(section.key))
90
145
  continue;
91
146
  doc[KEY_TO_DOC_FIELD[section.key]] = section.text;
92
147
  }
@@ -104,19 +159,26 @@ export function renderIntentSnapshotDoc(snapshot) {
104
159
  * BEFORE the call, so capture keeps all five bounded sections and the artifact
105
160
  * applies the declared filter here.
106
161
  *
107
- * When the model declared none (no `intentTension`, or an empty
108
- * `relatedIntentFields`), there is nothing to narrow by. Storing an empty
109
- * array would degrade the artifact to a hash-only record — exactly what
110
- * SPEC §6.2 rejects — so the bounded capture is kept as the traceable basis
111
- * that the diagnosis actually received.
162
+ * Non-authored sections (missing / template placeholder) are ALWAYS dropped —
163
+ * they are not strategic evidence and must never be persisted as if they were.
164
+ *
165
+ * Three cases, deliberately distinct (SPEC §20.1):
166
+ * - no declaration (`relatedKeys` empty) → keep every AUTHORED section;
167
+ * - partial declaration → keep `authored ∩ declared`;
168
+ * - declaration with NO valid entry → return an explicitly EMPTY section
169
+ * list. Falling back to the full capture here would let rejected sections
170
+ * re-enter the strategic basis, which is exactly the defect this guards.
112
171
  */
113
172
  export function filterIntentSnapshotSections(snapshot, relatedKeys) {
114
- if (relatedKeys.length === 0)
115
- return snapshot;
173
+ const authored = deriveAuthoredSnapshotSectionKeys(snapshot);
116
174
  const declared = new Set(relatedKeys);
117
- const sections = snapshot.sections.filter((section) => declared.has(section.key));
175
+ const sections = snapshot.sections.filter((section) => authored.has(section.key) && (declared.size === 0 || declared.has(section.key)));
118
176
  return { ...snapshot, sections };
119
177
  }
178
+ /** Explicit "no usable strategic sections" projection (never the full capture). */
179
+ export function emptyIntentSnapshotSections(snapshot) {
180
+ return { ...snapshot, sections: [] };
181
+ }
120
182
  /** True when the value is a well-formed `IntentSnapshot` (rc-1 / rc-4). */
121
183
  export function isValidIntentSnapshot(value) {
122
184
  if (typeof value !== 'object' || value === null || Array.isArray(value))
@@ -156,8 +218,14 @@ export function isValidIntentSnapshot(value) {
156
218
  return false;
157
219
  if (Object.hasOwn(entry, 'missing') && typeof entry.missing !== 'boolean')
158
220
  return false;
221
+ if (Object.hasOwn(entry, 'placeholder') && typeof entry.placeholder !== 'boolean')
222
+ return false;
159
223
  if (entry.truncated === true && entry.missing === true)
160
224
  return false;
225
+ // `missing` (nothing there) and `placeholder` (template text there) are
226
+ // mutually exclusive by definition.
227
+ if (entry.missing === true && entry.placeholder === true)
228
+ return false;
161
229
  }
162
230
  return true;
163
231
  }
@@ -1 +1 @@
1
- {"version":3,"file":"intent-snapshot.js","sourceRoot":"","sources":["../../../src/runtime/intent/intent-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE5E,uDAAuD;AACvD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAU,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,CAAC;AAEtD,iDAAiD;AACjD,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,KAAK;IACL,iBAAiB;IACjB,iBAAiB;IACjB,iBAAiB;IACjB,yBAAyB;CACjB,CAAC;AA0BX,4EAA4E;AAC5E,MAAM,gBAAgB,GAA8D;IAClF,GAAG,EAAE,KAAK;IACV,eAAe,EAAE,gBAAgB;IACjC,eAAe,EAAE,gBAAgB;IACjC,eAAe,EAAE,gBAAgB;IACjC,uBAAuB,EAAE,uBAAuB;CACjD,CAAC;AAeF;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,QAAQ,GAAG,KAAK,CAAC,eAAe,IAAI,iCAAiC,CAAC;IAC5E,MAAM,MAAM,GAAG,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,QAAQ,GAA4B,4BAA4B,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACjF,MAAM,IAAI,GAAG,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACnD,OAAO,EAAE,GAAG,EA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,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -8,9 +8,28 @@ export declare const STRATEGIC_CONFLICT_RESOLUTION_ACTION = "confirm_drift";
8
8
  export interface StrategicResolutionRecord {
9
9
  readonly ownerAction: string;
10
10
  readonly intentDocHash: string | null;
11
+ /**
12
+ * Bound to the FULL artifact digest (`computeArtifactDigest()` over the
13
+ * artifact snapshot under approval), NOT a contract-only digest. Such a
14
+ * digest does not exist in PD and must not be introduced: re-scribing or
15
+ * rewriting the artifact must invalidate the decision.
16
+ */
11
17
  readonly contractDigest: string | null;
12
18
  readonly resultingCandidateId: string | null;
19
+ /**
20
+ * P1-2: the INTENT sections this decision covered, resolved from the immutable
21
+ * `related_intent_fields_snapshot` (falling back to the mutable column for
22
+ * legacy rows). A decision only exempts the conflicts it actually names.
23
+ */
24
+ readonly relatedIntentFields?: readonly string[];
13
25
  }
26
+ /**
27
+ * SPEC §20.2: ONLY these three sections are ordinary strategic trade-offs an
28
+ * Owner may accept with `confirm_drift`. `non_negotiables` and
29
+ * `stop_escalation` are boundaries, not trade-offs — accepting a boundary
30
+ * violation is not a decision the drift acknowledgement can express.
31
+ */
32
+ export declare const STRATEGIC_TRADEOFF_SECTIONS: readonly ['why', 'desired_outcome', 'current_strategic_focus'];
14
33
  export interface StrategicConflictGateInput {
15
34
  /** Parsed artifact contentJson (untrusted). `undefined` = unparseable. */
16
35
  readonly artifactContent: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"strategic-conflict-gate.d.ts","sourceRoot":"","sources":["../../../src/runtime/intent/strategic-conflict-gate.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,8BAA8B,mCAAmC,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,kBAAkB,CAAC;AAEpE,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,cA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AQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC3G,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,0BAA0B,GAAG,qBAAqB,CAoBlG"}
@@ -6,19 +6,22 @@
6
6
  * read model (approval block) so the UI can never promise an approval the
7
7
  * server would refuse, and the server can never rely on the UI.
8
8
  *
9
- * Rules:
10
- * 1. Legacy / V1 artifacts are unaffected (no schemaVersion: 2 → allowed).
11
- * 2. A V2 that claims `schemaVersion: 2` but does not validate is a HARD block
12
- * (tampered / incomplete V2 must never be approvable).
13
- * 3. `conflictStatus !== 'confirmed'` → allowed.
14
- * 4. `confirmed` requires an effective resolution record bound to ALL of:
9
+ * Rules, IN THIS ORDER (P1, PR #2663 final):
10
+ * 1. Legacy / V1 artifacts are unaffected (no V2 claim → allowed).
11
+ * 2. A V2 that CLAIMS the schema but does not validate is a HARD block.
12
+ * 3. The contract's own facts must be trustworthy BEFORE its status is read:
13
+ * structure → `conflictStatus === maxConflictStatus(conflicts)` → every
14
+ * conflict target locatable. A status that contradicts its conflict list is
15
+ * never "good enough to be potential" and is never approvable.
16
+ * 4. `conflictStatus !== 'confirmed'` → allowed (only once step 3 passed).
17
+ * 5. `confirmed` requires an effective resolution record bound to ALL of:
15
18
  * the artifact's candidate, the contract's intent hash AND the artifact
16
19
  * digest. Any change to any of those invalidates the old record.
17
20
  *
18
21
  * `intentTension` is NOT consulted here; relevance/conflicts live in the V2
19
22
  * assessment, which is the only authority this gate reads.
20
23
  */
21
- import { extractIntentContractV2, } from '../internalization/intent-contract.js';
24
+ import { validateIntentContractV2, } from '../internalization/intent-contract.js';
22
25
  export const STRATEGIC_CONFLICT_UNCONFIRMED = 'strategic_conflict_unconfirmed';
23
26
  /**
24
27
  * The Owner action that acknowledges a confirmed conflict. Other actions
@@ -26,6 +29,21 @@ export const STRATEGIC_CONFLICT_UNCONFIRMED = 'strategic_conflict_unconfirmed';
26
29
  * change the anchor, `promote_to_*` = act on the candidate) do not resolve it.
27
30
  */
28
31
  export const STRATEGIC_CONFLICT_RESOLUTION_ACTION = 'confirm_drift';
32
+ /**
33
+ * SPEC §20.2: ONLY these three sections are ordinary strategic trade-offs an
34
+ * Owner may accept with `confirm_drift`. `non_negotiables` and
35
+ * `stop_escalation` are boundaries, not trade-offs — accepting a boundary
36
+ * violation is not a decision the drift acknowledgement can express.
37
+ */
38
+ export const STRATEGIC_TRADEOFF_SECTIONS = [
39
+ 'why',
40
+ 'desired_outcome',
41
+ 'current_strategic_focus',
42
+ ];
43
+ function isExemptableConflict(conflict) {
44
+ return conflict.against === 'owner_intent'
45
+ && STRATEGIC_TRADEOFF_SECTIONS.includes(conflict.ref);
46
+ }
29
47
  function isRecord(value) {
30
48
  return typeof value === 'object' && value !== null && !Array.isArray(value);
31
49
  }
@@ -33,21 +51,40 @@ function isRecord(value) {
33
51
  * TECH §8.3: the refusal reason must NAME the conflict target (`against` +
34
52
  * `ref`) so the Owner can act on it instead of reading an opaque code.
35
53
  */
36
- function describeTargets(contract) {
37
- const conflicts = contract?.strategicAssessment.conflicts ?? [];
54
+ function describeTargets(conflicts) {
38
55
  if (conflicts.length === 0)
39
56
  return '';
40
57
  return conflicts.map((conflict) => `${conflict.against}:${conflict.ref}`).join(', ');
41
58
  }
42
- function blocked(reason, contract) {
43
- const targets = describeTargets(contract);
59
+ function blocked(reason, conflicts, nextAction) {
60
+ const targets = describeTargets(conflicts);
44
61
  return {
45
62
  ok: false,
46
63
  code: STRATEGIC_CONFLICT_UNCONFIRMED,
47
64
  reason: targets === '' ? reason : `${reason} [${targets}]`,
48
- nextAction: 'Resolve the confirmed strategic conflict for THIS contract first: record an Owner decision bound to the current candidate, the intent hash and the current contract digest, then approve again.',
65
+ nextAction,
49
66
  };
50
67
  }
68
+ const HOW_TO_RESOLVE_TRADEOFF = 'Record an Owner decision with owner_action=confirm_drift that NAMES these sections in relatedIntentFields, bound to the current candidate, the intent hash and the current artifact digest, then approve again.';
69
+ const HOW_TO_RESOLVE_CORE_PRINCIPLE = 'A PD Core Principle cannot be exempted by an Owner Intent decision. Change the candidate so it satisfies BOTH anchors, then re-form the candidate and submit it for approval again.';
70
+ const HOW_TO_RESOLVE_BOUNDARY = 'confirm_drift cannot exempt a Non-negotiable / Stop-Escalation boundary. Either change the candidate so it respects the boundary, or update INTENT.md deliberately and re-form the candidate from the new intent version.';
71
+ /**
72
+ * P1 (PR #2663 final): a contract whose DECLARED status contradicts its own
73
+ * conflict list cannot be repaired by an Owner decision — `confirm_drift` would
74
+ * be accepting a status the server cannot trust.
75
+ */
76
+ const HOW_TO_FIX_STATUS_MISMATCH = 'The contract\'s conflictStatus contradicts its own conflicts[] list, so its status cannot be trusted and no Owner decision can repair it. Re-form the candidate so the server recomputes conflictStatus from the verified conflict list, then approve again. Already-completed historical approvals are not revoked; a pending one must be re-reviewed.';
77
+ /**
78
+ * P1: a conflict whose target does not resolve is a fabricated anchor. The
79
+ * decision layer can never match it, so it must be re-formed.
80
+ */
81
+ const HOW_TO_FIX_UNLOCATABLE = 'A conflict cites a target that cannot be resolved (owner_intent must be one of the five INTENT sections: why | desired_outcome | non_negotiables | stop_escalation | current_strategic_focus; core_principle must be a registered principle id), so no Owner decision can cover it. Re-form the candidate with a locatable against/ref, then approve again. Already-completed historical approvals are not revoked; a pending one must be re-reviewed.';
82
+ const NEXT_ACTION_BY_DEFECT = {
83
+ malformed_strategic_contract: 'Re-run the Scribe stage so the artifact carries a complete IntentContract V2, then approve again.',
84
+ conflict_status_mismatch: HOW_TO_FIX_STATUS_MISMATCH,
85
+ unlocatable_conflict: HOW_TO_FIX_UNLOCATABLE,
86
+ unreadable: 'Re-run the Scribe stage so the artifact body is readable and carries a complete IntentContract V2, then approve again.',
87
+ };
51
88
  /**
52
89
  * Rule 1 predicate: does this artifact CLAIM an IntentContract V2? The V2 lives
53
90
  * at `artifact.intentContract` (schemaVersion 2), never at the artifact root —
@@ -89,12 +126,16 @@ function readStrategicClaim(input) {
89
126
  return { kind: 'none' };
90
127
  const raw = content.intentContract;
91
128
  // A present-but-non-object contract is corruption, never "absent".
92
- if (!isRecord(raw))
93
- return { kind: 'invalid-v2' };
129
+ if (!isRecord(raw)) {
130
+ return { kind: 'invalid', defect: 'malformed_strategic_contract', errors: ['intentContract must be an object'] };
131
+ }
94
132
  if (!claimsIntentContractV2(content))
95
133
  return { kind: 'none' };
96
- const contract = extractIntentContractV2(content);
97
- return contract === null ? { kind: 'invalid-v2' } : { kind: 'v2', contract };
134
+ const validation = validateIntentContractV2(raw);
135
+ if (!validation.ok) {
136
+ return { kind: 'invalid', defect: validation.defect, errors: validation.errors };
137
+ }
138
+ return { kind: 'v2', contract: validation.contract };
98
139
  }
99
140
  export function evaluateStrategicConflictGate(input) {
100
141
  // Rule 1: artifacts without an intent-contract claim are outside SIA.
@@ -102,36 +143,63 @@ export function evaluateStrategicConflictGate(input) {
102
143
  if (claim.kind === 'none') {
103
144
  return { ok: true, conflictStatus: 'none' };
104
145
  }
105
- // Rule 2: an incomplete / corrupted claim is never approvable.
146
+ // Rule 2 + 3: an incomplete, self-contradictory or unlocatable V2 is never
147
+ // approvable — and the refusal names the failing integrity stage. This runs
148
+ // BEFORE any status read: `status !== 'confirmed'` must never short-circuit
149
+ // the integrity check (a `potential` contract with a confirmed conflict is a
150
+ // mismatch, not an approval).
106
151
  if (claim.kind !== 'v2') {
107
- return blocked(claim.kind === 'unreadable' ? 'unreadable_artifact_content' : 'malformed_strategic_contract', null);
152
+ if (claim.kind === 'unreadable') {
153
+ return blocked('unreadable_artifact_content', [], NEXT_ACTION_BY_DEFECT.unreadable);
154
+ }
155
+ const detail = claim.errors[0] ?? 'the contract is not internally consistent';
156
+ return blocked(`${claim.defect}: ${detail}`, [], NEXT_ACTION_BY_DEFECT[claim.defect]);
108
157
  }
109
158
  const { contract } = claim;
159
+ // Rule 4: the status is now known to agree with `conflicts[]`.
110
160
  const status = contract.strategicAssessment.conflictStatus;
111
- // Rule 3.
112
161
  if (status !== 'confirmed') {
113
162
  return { ok: true, conflictStatus: status };
114
163
  }
115
- // Rule 4: binding requires the server-captured intent hash.
164
+ // Rule 5: binding requires the server-captured intent hash.
116
165
  const intentDocHash = contract.strategicIntent?.contentHash;
117
166
  if (intentDocHash === undefined || intentDocHash === '') {
118
- return blocked('missing_intent_reference', contract);
167
+ return blocked('missing_intent_reference', [], HOW_TO_RESOLVE_TRADEOFF);
119
168
  }
120
- const resolved = input.resolutions.some((record) => record.ownerAction === STRATEGIC_CONFLICT_RESOLUTION_ACTION
169
+ const confirmed = (contract.strategicAssessment.conflicts ?? [])
170
+ .filter((conflict) => conflict.status === 'confirmed');
171
+ const effective = input.resolutions.filter((record) => record.ownerAction === STRATEGIC_CONFLICT_RESOLUTION_ACTION
121
172
  && record.intentDocHash === intentDocHash
122
173
  && record.contractDigest === input.artifactDigest
123
174
  && record.resultingCandidateId !== null
124
175
  && input.candidateIds.includes(record.resultingCandidateId));
125
- return resolved ? { ok: true, conflictStatus: 'confirmed' } : blocked('no_effective_resolution', contract);
176
+ // `confirmed` with no conflict element can no longer reach this point: the
177
+ // validator already refused it as `conflict_status_mismatch`. The invariant is
178
+ // asserted rather than silently reinterpreted.
179
+ if (confirmed.length === 0) {
180
+ return blocked('conflict_status_mismatch: conflictStatus is "confirmed" but the conflict list has no confirmed element', [], HOW_TO_FIX_STATUS_MISMATCH);
181
+ }
182
+ // Rule 5 (SPEC §20.2): boundaries and Core Principles are NEVER exemptable.
183
+ const unexemptable = confirmed.filter((conflict) => !isExemptableConflict(conflict));
184
+ if (unexemptable.length > 0) {
185
+ const hasCorePrinciple = unexemptable.some((conflict) => conflict.against === 'core_principle');
186
+ return blocked(hasCorePrinciple ? 'core_principle_conflict' : 'owner_boundary_conflict', unexemptable, hasCorePrinciple ? HOW_TO_RESOLVE_CORE_PRINCIPLE : HOW_TO_RESOLVE_BOUNDARY);
187
+ }
188
+ // Rule 6: EVERY ordinary trade-off must be covered by an effective decision.
189
+ // Exempting one conflict must not silently release the others.
190
+ const uncovered = confirmed.filter((conflict) => !effective.some((record) => (record.relatedIntentFields ?? []).includes(conflict.ref)));
191
+ return uncovered.length === 0
192
+ ? { ok: true, conflictStatus: 'confirmed' }
193
+ : blocked('no_effective_resolution', uncovered, HOW_TO_RESOLVE_TRADEOFF);
126
194
  }
127
195
  export function describeStrategicConflict(input) {
128
196
  const claim = readStrategicClaim(input);
129
197
  const contract = claim.kind === 'v2' ? claim.contract : null;
130
198
  const gate = evaluateStrategicConflictGate(input);
131
199
  return {
132
- // A malformed V2 is still a V2 artifact — the card must show it as a
133
- // blocked strategic contract, never as a plain non-SIA approval.
134
- isV2: claim.kind === 'v2' || claim.kind === 'invalid-v2',
200
+ // A malformed / self-contradictory V2 is still a V2 artifact — the card must
201
+ // show it as a blocked strategic contract, never as a plain non-SIA approval.
202
+ isV2: claim.kind === 'v2' || claim.kind === 'invalid',
135
203
  relevance: contract?.strategicAssessment.relevance ?? null,
136
204
  conflictStatus: contract?.strategicAssessment.conflictStatus ?? null,
137
205
  conflicts: (contract?.strategicAssessment.conflicts ?? []).map((conflict) => ({