@sun-asterisk/sungen 2.7.0-beta.0 → 3.0.0-beta.71

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 (256) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/commands/add.js +3 -3
  3. package/dist/cli/commands/add.js.map +1 -1
  4. package/dist/cli/commands/audit.d.ts +3 -0
  5. package/dist/cli/commands/audit.d.ts.map +1 -0
  6. package/dist/cli/commands/audit.js +134 -0
  7. package/dist/cli/commands/audit.js.map +1 -0
  8. package/dist/cli/commands/blindspot.d.ts +3 -0
  9. package/dist/cli/commands/blindspot.d.ts.map +1 -0
  10. package/dist/cli/commands/blindspot.js +58 -0
  11. package/dist/cli/commands/blindspot.js.map +1 -0
  12. package/dist/cli/commands/challenge.d.ts +3 -0
  13. package/dist/cli/commands/challenge.d.ts.map +1 -0
  14. package/dist/cli/commands/challenge.js +102 -0
  15. package/dist/cli/commands/challenge.js.map +1 -0
  16. package/dist/cli/commands/feedback.d.ts +3 -0
  17. package/dist/cli/commands/feedback.d.ts.map +1 -0
  18. package/dist/cli/commands/feedback.js +72 -0
  19. package/dist/cli/commands/feedback.js.map +1 -0
  20. package/dist/cli/commands/generate.d.ts.map +1 -1
  21. package/dist/cli/commands/generate.js +22 -0
  22. package/dist/cli/commands/generate.js.map +1 -1
  23. package/dist/cli/commands/ledger.d.ts +3 -0
  24. package/dist/cli/commands/ledger.d.ts.map +1 -0
  25. package/dist/cli/commands/ledger.js +71 -0
  26. package/dist/cli/commands/ledger.js.map +1 -0
  27. package/dist/cli/commands/manifest.d.ts +3 -0
  28. package/dist/cli/commands/manifest.d.ts.map +1 -0
  29. package/dist/cli/commands/manifest.js +101 -0
  30. package/dist/cli/commands/manifest.js.map +1 -0
  31. package/dist/cli/commands/script-check.d.ts +3 -0
  32. package/dist/cli/commands/script-check.d.ts.map +1 -0
  33. package/dist/cli/commands/script-check.js +97 -0
  34. package/dist/cli/commands/script-check.js.map +1 -0
  35. package/dist/cli/commands/trace.d.ts +3 -0
  36. package/dist/cli/commands/trace.d.ts.map +1 -0
  37. package/dist/cli/commands/trace.js +110 -0
  38. package/dist/cli/commands/trace.js.map +1 -0
  39. package/dist/cli/commands/update.d.ts.map +1 -1
  40. package/dist/cli/commands/update.js +22 -9
  41. package/dist/cli/commands/update.js.map +1 -1
  42. package/dist/cli/index.js +16 -0
  43. package/dist/cli/index.js.map +1 -1
  44. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/capture-variable.hbs +1 -0
  45. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/all-contain-assertion.hbs +7 -0
  46. package/dist/generators/test-generator/patterns/capture-patterns.d.ts +16 -0
  47. package/dist/generators/test-generator/patterns/capture-patterns.d.ts.map +1 -0
  48. package/dist/generators/test-generator/patterns/capture-patterns.js +54 -0
  49. package/dist/generators/test-generator/patterns/capture-patterns.js.map +1 -0
  50. package/dist/generators/test-generator/patterns/index.d.ts.map +1 -1
  51. package/dist/generators/test-generator/patterns/index.js +2 -0
  52. package/dist/generators/test-generator/patterns/index.js.map +1 -1
  53. package/dist/generators/test-generator/step-mapper.d.ts.map +1 -1
  54. package/dist/generators/test-generator/step-mapper.js +1 -0
  55. package/dist/generators/test-generator/step-mapper.js.map +1 -1
  56. package/dist/generators/test-generator/utils/data-resolver.d.ts +5 -0
  57. package/dist/generators/test-generator/utils/data-resolver.d.ts.map +1 -1
  58. package/dist/generators/test-generator/utils/data-resolver.js +17 -0
  59. package/dist/generators/test-generator/utils/data-resolver.js.map +1 -1
  60. package/dist/harness/audit.d.ts +24 -0
  61. package/dist/harness/audit.d.ts.map +1 -0
  62. package/dist/harness/audit.js +115 -0
  63. package/dist/harness/audit.js.map +1 -0
  64. package/dist/harness/blindspot.d.ts +15 -0
  65. package/dist/harness/blindspot.d.ts.map +1 -0
  66. package/dist/harness/blindspot.js +85 -0
  67. package/dist/harness/blindspot.js.map +1 -0
  68. package/dist/harness/catalog/universal-viewpoints.yaml +114 -0
  69. package/dist/harness/challenge.d.ts +21 -0
  70. package/dist/harness/challenge.d.ts.map +1 -0
  71. package/dist/harness/challenge.js +151 -0
  72. package/dist/harness/challenge.js.map +1 -0
  73. package/dist/harness/feedback.d.ts +29 -0
  74. package/dist/harness/feedback.d.ts.map +1 -0
  75. package/dist/harness/feedback.js +106 -0
  76. package/dist/harness/feedback.js.map +1 -0
  77. package/dist/harness/intent.d.ts +11 -0
  78. package/dist/harness/intent.d.ts.map +1 -0
  79. package/dist/harness/intent.js +86 -0
  80. package/dist/harness/intent.js.map +1 -0
  81. package/dist/harness/ledger.d.ts +42 -0
  82. package/dist/harness/ledger.d.ts.map +1 -0
  83. package/dist/harness/ledger.js +171 -0
  84. package/dist/harness/ledger.js.map +1 -0
  85. package/dist/harness/manifest.d.ts +42 -0
  86. package/dist/harness/manifest.d.ts.map +1 -0
  87. package/dist/harness/manifest.js +209 -0
  88. package/dist/harness/manifest.js.map +1 -0
  89. package/dist/harness/parse.d.ts +22 -0
  90. package/dist/harness/parse.d.ts.map +1 -0
  91. package/dist/harness/parse.js +163 -0
  92. package/dist/harness/parse.js.map +1 -0
  93. package/dist/harness/script-check.d.ts +16 -0
  94. package/dist/harness/script-check.d.ts.map +1 -0
  95. package/dist/harness/script-check.js +169 -0
  96. package/dist/harness/script-check.js.map +1 -0
  97. package/dist/harness/secret-scan.d.ts +8 -0
  98. package/dist/harness/secret-scan.d.ts.map +1 -0
  99. package/dist/harness/secret-scan.js +88 -0
  100. package/dist/harness/secret-scan.js.map +1 -0
  101. package/dist/harness/sensors.d.ts +88 -0
  102. package/dist/harness/sensors.d.ts.map +1 -0
  103. package/dist/harness/sensors.js +232 -0
  104. package/dist/harness/sensors.js.map +1 -0
  105. package/dist/harness/trace.d.ts +31 -0
  106. package/dist/harness/trace.d.ts.map +1 -0
  107. package/dist/harness/trace.js +173 -0
  108. package/dist/harness/trace.js.map +1 -0
  109. package/dist/orchestrator/ai-rules-updater.d.ts +1 -0
  110. package/dist/orchestrator/ai-rules-updater.d.ts.map +1 -1
  111. package/dist/orchestrator/ai-rules-updater.js +55 -11
  112. package/dist/orchestrator/ai-rules-updater.js.map +1 -1
  113. package/dist/orchestrator/figma/spec-figma-renderer.d.ts +2 -2
  114. package/dist/orchestrator/figma/spec-figma-renderer.js +2 -2
  115. package/dist/orchestrator/figma/spec-figma-section-renderers.d.ts +1 -1
  116. package/dist/orchestrator/figma/spec-figma-section-renderers.js +1 -1
  117. package/dist/orchestrator/project-initializer.d.ts +5 -0
  118. package/dist/orchestrator/project-initializer.d.ts.map +1 -1
  119. package/dist/orchestrator/project-initializer.js +26 -6
  120. package/dist/orchestrator/project-initializer.js.map +1 -1
  121. package/dist/orchestrator/templates/ai-instructions/claude-agent-challenge.md +46 -0
  122. package/dist/orchestrator/templates/ai-instructions/claude-agent-discovery.md +32 -0
  123. package/dist/orchestrator/templates/ai-instructions/claude-agent-reviewer.md +37 -0
  124. package/dist/orchestrator/templates/ai-instructions/claude-cmd-add-flow.md +3 -3
  125. package/dist/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +5 -5
  126. package/dist/orchestrator/templates/ai-instructions/claude-cmd-create-test.md +45 -13
  127. package/dist/orchestrator/templates/ai-instructions/claude-cmd-design.md +12 -0
  128. package/dist/orchestrator/templates/ai-instructions/claude-cmd-feedback.md +36 -0
  129. package/dist/orchestrator/templates/ai-instructions/claude-cmd-review.md +27 -30
  130. package/dist/orchestrator/templates/ai-instructions/claude-cmd-run-test.md +8 -3
  131. package/dist/orchestrator/templates/ai-instructions/claude-config.md +1 -4
  132. package/dist/orchestrator/templates/ai-instructions/claude-skill-capture-mode-figma-mcp.md +82 -0
  133. package/dist/orchestrator/templates/ai-instructions/{github-skill-sungen-figma-source.md → claude-skill-capture-mode-figma-pat.md} +14 -48
  134. package/dist/orchestrator/templates/ai-instructions/claude-skill-capture-mode-live.md +60 -0
  135. package/dist/orchestrator/templates/ai-instructions/claude-skill-capture-mode-local.md +38 -0
  136. package/dist/orchestrator/templates/ai-instructions/claude-skill-capture.md +35 -0
  137. package/dist/orchestrator/templates/ai-instructions/claude-skill-harness-audit.md +84 -0
  138. package/dist/orchestrator/templates/ai-instructions/claude-skill-selector-fix.md +57 -11
  139. package/dist/orchestrator/templates/ai-instructions/claude-skill-selector-keys.md +41 -31
  140. package/dist/orchestrator/templates/ai-instructions/claude-skill-tc-generation.md +53 -1
  141. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-add-flow.md +3 -3
  142. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +4 -4
  143. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-create-test.md +27 -11
  144. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-design.md +13 -0
  145. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-feedback.md +24 -0
  146. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-review.md +20 -30
  147. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-run-test.md +6 -3
  148. package/dist/orchestrator/templates/ai-instructions/copilot-config.md +1 -4
  149. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-figma-mcp.md +82 -0
  150. package/{src/orchestrator/templates/ai-instructions/claude-skill-figma-source.md → dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-figma-pat.md} +14 -48
  151. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-live.md +60 -0
  152. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-local.md +38 -0
  153. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture.md +35 -0
  154. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-harness-audit.md +84 -0
  155. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-selector-fix.md +62 -16
  156. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-selector-keys.md +41 -31
  157. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-tc-generation.md +40 -1
  158. package/dist/orchestrator/templates/qa-context.md +90 -0
  159. package/dist/orchestrator/templates/readme.md +16 -13
  160. package/dist/orchestrator/templates/specs-test-data.ts +9 -0
  161. package/dist/tools/figma/figma-auth.d.ts +5 -2
  162. package/dist/tools/figma/figma-auth.d.ts.map +1 -1
  163. package/dist/tools/figma/figma-auth.js +19 -9
  164. package/dist/tools/figma/figma-auth.js.map +1 -1
  165. package/docs/orchestration-spec.md +267 -0
  166. package/package.json +10 -6
  167. package/src/cli/commands/add.ts +3 -3
  168. package/src/cli/commands/audit.ts +92 -0
  169. package/src/cli/commands/blindspot.ts +48 -0
  170. package/src/cli/commands/challenge.ts +55 -0
  171. package/src/cli/commands/feedback.ts +65 -0
  172. package/src/cli/commands/generate.ts +19 -0
  173. package/src/cli/commands/ledger.ts +61 -0
  174. package/src/cli/commands/manifest.ts +55 -0
  175. package/src/cli/commands/script-check.ts +50 -0
  176. package/src/cli/commands/trace.ts +60 -0
  177. package/src/cli/commands/update.ts +30 -10
  178. package/src/cli/index.ts +16 -0
  179. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/capture-variable.hbs +1 -0
  180. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/all-contain-assertion.hbs +7 -0
  181. package/src/generators/test-generator/patterns/capture-patterns.ts +59 -0
  182. package/src/generators/test-generator/patterns/index.ts +2 -0
  183. package/src/generators/test-generator/step-mapper.ts +1 -0
  184. package/src/generators/test-generator/utils/data-resolver.ts +20 -0
  185. package/src/harness/audit.ts +112 -0
  186. package/src/harness/blindspot.ts +51 -0
  187. package/src/harness/catalog/universal-viewpoints.yaml +114 -0
  188. package/src/harness/challenge.ts +131 -0
  189. package/src/harness/feedback.ts +84 -0
  190. package/src/harness/intent.ts +58 -0
  191. package/src/harness/ledger.ts +155 -0
  192. package/src/harness/manifest.ts +173 -0
  193. package/src/harness/parse.ts +145 -0
  194. package/src/harness/script-check.ts +149 -0
  195. package/src/harness/secret-scan.ts +51 -0
  196. package/src/harness/sensors.ts +279 -0
  197. package/src/harness/trace.ts +138 -0
  198. package/src/orchestrator/ai-rules-updater.ts +57 -10
  199. package/src/orchestrator/figma/spec-figma-renderer.ts +2 -2
  200. package/src/orchestrator/figma/spec-figma-section-renderers.ts +1 -1
  201. package/src/orchestrator/project-initializer.ts +30 -7
  202. package/src/orchestrator/templates/ai-instructions/claude-agent-challenge.md +46 -0
  203. package/src/orchestrator/templates/ai-instructions/claude-agent-discovery.md +32 -0
  204. package/src/orchestrator/templates/ai-instructions/claude-agent-reviewer.md +37 -0
  205. package/src/orchestrator/templates/ai-instructions/claude-cmd-add-flow.md +3 -3
  206. package/src/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +5 -5
  207. package/src/orchestrator/templates/ai-instructions/claude-cmd-create-test.md +45 -13
  208. package/src/orchestrator/templates/ai-instructions/claude-cmd-design.md +12 -0
  209. package/src/orchestrator/templates/ai-instructions/claude-cmd-feedback.md +36 -0
  210. package/src/orchestrator/templates/ai-instructions/claude-cmd-review.md +27 -30
  211. package/src/orchestrator/templates/ai-instructions/claude-cmd-run-test.md +8 -3
  212. package/src/orchestrator/templates/ai-instructions/claude-config.md +1 -4
  213. package/src/orchestrator/templates/ai-instructions/claude-skill-capture-mode-figma-mcp.md +82 -0
  214. package/{dist/orchestrator/templates/ai-instructions/copilot-skill-figma-source.md → src/orchestrator/templates/ai-instructions/claude-skill-capture-mode-figma-pat.md} +14 -48
  215. package/src/orchestrator/templates/ai-instructions/claude-skill-capture-mode-live.md +60 -0
  216. package/src/orchestrator/templates/ai-instructions/claude-skill-capture-mode-local.md +38 -0
  217. package/src/orchestrator/templates/ai-instructions/claude-skill-capture.md +35 -0
  218. package/src/orchestrator/templates/ai-instructions/claude-skill-harness-audit.md +84 -0
  219. package/src/orchestrator/templates/ai-instructions/claude-skill-selector-fix.md +57 -11
  220. package/src/orchestrator/templates/ai-instructions/claude-skill-selector-keys.md +41 -31
  221. package/src/orchestrator/templates/ai-instructions/claude-skill-tc-generation.md +53 -1
  222. package/src/orchestrator/templates/ai-instructions/copilot-cmd-add-flow.md +3 -3
  223. package/src/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +4 -4
  224. package/src/orchestrator/templates/ai-instructions/copilot-cmd-create-test.md +27 -11
  225. package/src/orchestrator/templates/ai-instructions/copilot-cmd-design.md +13 -0
  226. package/src/orchestrator/templates/ai-instructions/copilot-cmd-feedback.md +24 -0
  227. package/src/orchestrator/templates/ai-instructions/copilot-cmd-review.md +20 -30
  228. package/src/orchestrator/templates/ai-instructions/copilot-cmd-run-test.md +6 -3
  229. package/src/orchestrator/templates/ai-instructions/copilot-config.md +1 -4
  230. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-figma-mcp.md +82 -0
  231. package/{dist/orchestrator/templates/ai-instructions/claude-skill-figma-source.md → src/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-figma-pat.md} +14 -48
  232. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-live.md +60 -0
  233. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-capture-mode-local.md +38 -0
  234. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-capture.md +35 -0
  235. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-harness-audit.md +84 -0
  236. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-selector-fix.md +62 -16
  237. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-selector-keys.md +41 -31
  238. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-tc-generation.md +40 -1
  239. package/src/orchestrator/templates/qa-context.md +90 -0
  240. package/src/orchestrator/templates/readme.md +16 -13
  241. package/src/orchestrator/templates/specs-test-data.ts +9 -0
  242. package/src/tools/figma/figma-auth.ts +20 -9
  243. package/dist/orchestrator/templates/ai-instructions/claude-skill-capture-figma.md +0 -142
  244. package/dist/orchestrator/templates/ai-instructions/claude-skill-capture-live.md +0 -112
  245. package/dist/orchestrator/templates/ai-instructions/claude-skill-capture-local.md +0 -73
  246. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture-figma.md +0 -142
  247. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture-live.md +0 -112
  248. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-capture-local.md +0 -73
  249. package/src/orchestrator/templates/ai-instructions/claude-skill-capture-figma.md +0 -142
  250. package/src/orchestrator/templates/ai-instructions/claude-skill-capture-live.md +0 -112
  251. package/src/orchestrator/templates/ai-instructions/claude-skill-capture-local.md +0 -73
  252. package/src/orchestrator/templates/ai-instructions/copilot-skill-figma-source.md +0 -151
  253. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-capture-figma.md +0 -142
  254. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-capture-live.md +0 -112
  255. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-capture-local.md +0 -73
  256. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-figma-source.md +0 -151
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Harness Audit — runs all sensors over a screen's test-design artifacts and
3
+ * produces a structured report + a business-weighted quality score.
4
+ *
5
+ * The score is INTENTIONALLY weighted toward business-critical coverage/depth
6
+ * (not breadth), so it surfaces the gaps a count-based view hides. See
7
+ * docs/orchestration-spec.md §5 and reports/sungen_home_gherkin_viewpoint_coverage_review.md.
8
+ */
9
+ import * as path from 'path';
10
+ import { loadScenarios, parseViewpointOverview, ScenarioInfo, ViewpointEntry } from './parse';
11
+ import {
12
+ loadCatalog, viewpointGate, assertionDepth, dataThemesFor, coverageBalance, duplicateClusters, traceability,
13
+ GateResult, DepthResult, BalanceResult, DuplicateResult, TraceResult,
14
+ } from './sensors';
15
+ import { readIntent, projectRootFromScreenDir, IntentProfile } from './intent';
16
+
17
+ export interface AuditReport {
18
+ screen: string;
19
+ scenarioCount: number;
20
+ gate: GateResult;
21
+ depth: DepthResult;
22
+ balance: BalanceResult;
23
+ duplicates: DuplicateResult;
24
+ trace: TraceResult;
25
+ score: {
26
+ overall: number; // 0..10, business-weighted
27
+ coverage: number; // 0..1
28
+ businessDepth: number; // 0..1
29
+ balance: number; // 0..1
30
+ traceability: number; // 0..1
31
+ formula: string;
32
+ };
33
+ gateStatus: 'PASS' | 'FAIL';
34
+ findings: string[]; // human-actionable, what the Repair loop would target
35
+ intent: IntentProfile; // P3 — the intent profile that drove the thresholds
36
+ }
37
+
38
+ export function runAudit(screenDir: string, screenName: string): AuditReport {
39
+ const featurePath = path.join(screenDir, 'features', `${screenName}.feature`);
40
+ const viewpointPath = path.join(screenDir, 'requirements', 'test-viewpoint.md');
41
+
42
+ const scenarios: ScenarioInfo[] = loadScenarios(featurePath);
43
+ const viewpoints: ViewpointEntry[] = parseViewpointOverview(viewpointPath);
44
+ const catalog = loadCatalog();
45
+
46
+ const gate = viewpointGate(scenarios, viewpoints, catalog);
47
+ // P3 — intent profile from qa/context.md drives the depth threshold (focus).
48
+ const intent = readIntent(projectRootFromScreenDir(screenDir));
49
+ const depth = assertionDepth(scenarios, dataThemesFor(catalog, gate.pageType), intent.focus);
50
+ const balance = coverageBalance(scenarios);
51
+ const duplicates = duplicateClusters(scenarios);
52
+ const trace = traceability(scenarios, viewpoints);
53
+
54
+ // Sub-scores
55
+ const coverage = gate.coverageRatio;
56
+ const businessDepth = depth.bcDepthRatio;
57
+ const balanceScore = balance.coreCount + balance.secondaryCount > 0
58
+ ? Math.min(1, balance.coreCount / Math.max(1, balance.secondaryCount))
59
+ : 1;
60
+ const traceScore = 0.5 * trace.withVpCodeRatio + 0.5 * trace.mappedRatio;
61
+
62
+ // Business-weighted overall (coverage + depth dominate)
63
+ const overall = (0.4 * coverage + 0.3 * businessDepth + 0.15 * balanceScore + 0.15 * traceScore) * 10;
64
+
65
+ const findings: string[] = [];
66
+ for (const g of gate.gaps) {
67
+ if (g.status === 'shallow') {
68
+ findings.push(`GATE: critical theme "${g.theme}" is covered only by SHALLOW scenarios (no data assertion) → deepen with \`... with {{value}}\` / \`table ... with {{value}}\` (count @manual cross-screen too).`);
69
+ } else {
70
+ findings.push(`GATE: critical theme "${g.theme}" for page-type "${gate.pageType}" has NO covering scenario → generate it (often cross-screen → consider add-flow).`);
71
+ }
72
+ }
73
+ if (depth.businessCriticalShallow > 0) {
74
+ const tag = depth.verdict === 'fail' ? 'DEPTH-FAIL' : depth.verdict === 'warn' ? 'DEPTH-WARN' : 'DEPTH';
75
+ findings.push(
76
+ `${tag}: ${depth.businessCriticalShallow}/${depth.businessCriticalTotal} data-correctness scenarios assert only visibility ` +
77
+ `(ratio ${depth.bcDepthRatio.toFixed(2)} < threshold ${depth.threshold.toFixed(2)} for focus "${depth.focus}") → ` +
78
+ `add data assertions (\`... with {{value}}\`, \`see all ... contain {{v}}\`) or, if cross-screen, defer to a flow with @manual + reason.`,
79
+ );
80
+ }
81
+ if (balance.imbalanced) {
82
+ findings.push(`BALANCE: ${balance.note} Stop expanding secondary viewpoints until business-core gaps are filled.`);
83
+ }
84
+ if (trace.mappedRatio < 0.5) {
85
+ findings.push(`TRACE: ${trace.note}`);
86
+ }
87
+ if (gate.universalGaps.length) {
88
+ findings.push(`UNIVERSAL: missing theme(s): ${gate.universalGaps.join(', ')} (low priority reminder).`);
89
+ }
90
+
91
+ // Gate now spans coverage (viewpoint themes) AND depth (data-correctness).
92
+ // A depth 'fail' (below the intent threshold) fails the gate; 'warn' does not.
93
+ const gateStatus: 'PASS' | 'FAIL' =
94
+ gate.gaps.length === 0 && depth.verdict !== 'fail' ? 'PASS' : 'FAIL';
95
+
96
+ return {
97
+ screen: screenName,
98
+ scenarioCount: scenarios.length,
99
+ gate, depth, balance, duplicates, trace,
100
+ score: {
101
+ overall: Math.round(overall * 10) / 10,
102
+ coverage: Math.round(coverage * 100) / 100,
103
+ businessDepth: Math.round(businessDepth * 100) / 100,
104
+ balance: Math.round(balanceScore * 100) / 100,
105
+ traceability: Math.round(traceScore * 100) / 100,
106
+ formula: 'overall = (0.4*coverage + 0.3*businessDepth + 0.15*balance + 0.15*traceability) * 10',
107
+ },
108
+ gateStatus,
109
+ findings,
110
+ intent,
111
+ };
112
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Blind-Spot Memory (harness-roadmap P5).
3
+ *
4
+ * A deterministic harness reliably repeats whatever its rules/viewpoints miss. When
5
+ * a QA (or the challenge critic) finds a recurring gap, don't just patch one test —
6
+ * promote it to a reusable PATTERN here. Loop 1 (generation pre-gate) and Loop 2
7
+ * (challenge critic) read these so the same blind spot doesn't come back.
8
+ *
9
+ * Store: .sungen/blindspots/blindspots.jsonl (append-only, project-local).
10
+ */
11
+ import * as fs from 'fs';
12
+ import * as path from 'path';
13
+
14
+ export interface Blindspot {
15
+ ts: string;
16
+ pattern: string; // short name, e.g. "add-action-no-duplicate-check"
17
+ rule: string; // the generalised rule to apply next time
18
+ example?: string; // a concrete instance that motivated it
19
+ screen?: string; // where it was first noticed
20
+ source?: string; // 'qa' | 'challenge' | 'feedback'
21
+ }
22
+
23
+ function storePath(): string {
24
+ return path.join(process.cwd(), '.sungen', 'blindspots', 'blindspots.jsonl');
25
+ }
26
+
27
+ export function addBlindspot(entry: Omit<Blindspot, 'ts'> & { ts?: string }): string {
28
+ const p = storePath();
29
+ fs.mkdirSync(path.dirname(p), { recursive: true });
30
+ const full: Blindspot = { ts: entry.ts ?? new Date().toISOString(), ...entry };
31
+ fs.appendFileSync(p, JSON.stringify(full) + '\n', 'utf-8');
32
+ return p;
33
+ }
34
+
35
+ export function listBlindspots(): Blindspot[] {
36
+ const p = storePath();
37
+ if (!fs.existsSync(p)) return [];
38
+ return fs.readFileSync(p, 'utf-8').split('\n').filter(Boolean).map((l) => {
39
+ try { return JSON.parse(l) as Blindspot; } catch { return null; }
40
+ }).filter(Boolean) as Blindspot[];
41
+ }
42
+
43
+ /** Compact bullet list for injecting into generator / critic prompts. */
44
+ export function blindspotsForPrompt(): string {
45
+ const all = listBlindspots();
46
+ if (!all.length) return '';
47
+ // De-dupe by pattern (latest rule wins).
48
+ const byPattern = new Map<string, Blindspot>();
49
+ for (const b of all) byPattern.set(b.pattern, b);
50
+ return [...byPattern.values()].map((b) => `- [${b.pattern}] ${b.rule}`).join('\n');
51
+ }
@@ -0,0 +1,114 @@
1
+ # Seed Universal Viewpoint Catalog (bundled, local — NOT a server).
2
+ # Role: REFERENCE for the Harness Coverage Gate (the "answer key" sensors check
3
+ # against). The AI still GENERATES the viewpoint-overview; this catalog only
4
+ # verifies that critical themes for a page-type were not missed.
5
+ #
6
+ # Each page-type lists must-cover themes. A theme is "covered" when the project's
7
+ # viewpoint-overview (or generated scenarios) contains one of its keywords.
8
+ # See docs/orchestration-spec.md §5.2 and reports/sungen_refactor_spec.md §9.
9
+ #
10
+ # `depth:` (optional, harness-roadmap P1) marks a theme as DATA-correctness:
11
+ # requires: data-assertion → scenarios on this theme must assert DATA (not just
12
+ # visibility) to count as "deep". Drives the depth gate.
13
+ # cross_screen: true → genuine depth needs another screen → use a flow
14
+ # (P5 `remember` / `see all … contain`); on one screen
15
+ # it should be @manual + deferred-to-flow, not shallow.
16
+ # keywords: → PRECISE data-noun keywords for depth matching (kept
17
+ # separate from coverage keywords to avoid matching
18
+ # navigation scenarios like "API list page").
19
+ # template: → the deep step the generator should emit by default.
20
+ # Themes with no `depth:` are visibility/navigation — landing/seeing IS the assertion.
21
+
22
+ page_types:
23
+ ecommerce-list:
24
+ detect_keywords: [cart, product, checkout, catalog, brand, category, "add to cart"]
25
+ must_cover:
26
+ - theme: list-data
27
+ keywords: [list, displayed, card, "product card", grid]
28
+ depth:
29
+ requires: data-assertion
30
+ cross_screen: false
31
+ keywords: ["product price", "product card", "every card", "all product", "product name", "displays a price", "card displays"]
32
+ template: "User see all [Product Price] contain {{currency}} (and name/image per card)"
33
+ - theme: product-detail-consistency
34
+ keywords: [consistent, consistency, match, "same product", "correct product"]
35
+ depth:
36
+ requires: data-assertion
37
+ cross_screen: true
38
+ keywords: ["product detail", "detail page", "same product name", "matching name", "consistency", "same price"]
39
+ template: "User remember [Product Name] text as {{v}} … User see [Detail Product Name] header with {{v}}"
40
+ - theme: cart-correctness
41
+ keywords: ["cart contains", quantity, "price", subtotal, "in cart", "cart content", "cart product"]
42
+ depth:
43
+ requires: data-assertion
44
+ cross_screen: true
45
+ keywords: ["cart product", "cart contains", "in cart", "cart item", "appears in the cart", "cart line", "subtotal", "quantity"]
46
+ template: "User remember [Product Name] text as {{v}} … User see all [Cart Product Name] contain {{v}}"
47
+ - theme: category-filter-correctness
48
+ keywords: ["belong to the selected category", "category result", "matching the selected category", "products belong to", "only products that belong to the selected category"]
49
+ depth:
50
+ requires: data-assertion
51
+ cross_screen: true
52
+ keywords: ["belong to the selected category", "category result", "products that belong", "matching the selected category"]
53
+ template: "User see all [Result Product Name] contain {{selected_category}}"
54
+ - theme: brand-filter-correctness
55
+ keywords: ["belong to the selected brand", "brand result", "only products ... brand", "products that belong to the selected brand", "all displayed products belong to"]
56
+ depth:
57
+ requires: data-assertion
58
+ cross_screen: true
59
+ keywords: ["belong to the selected brand", "brand result", "products that belong to the selected brand"]
60
+ template: "User see all [Result Product Name] contain {{selected_brand}}"
61
+ - theme: add-to-cart
62
+ keywords: ["add to cart", added, "added to cart"]
63
+ depth:
64
+ requires: data-assertion
65
+ cross_screen: false
66
+ keywords: ["add to cart", "added to cart", "added confirmation", "added message"]
67
+ template: "User see [Added Message] text contains {{added_message}} (not just the modal)"
68
+
69
+ form:
70
+ detect_keywords: [form, submit, field, input, validation]
71
+ must_cover:
72
+ - theme: required-validation
73
+ keywords: [required, empty, "must be", validation]
74
+ depth:
75
+ requires: data-assertion
76
+ cross_screen: false
77
+ keywords: ["required", "must be", "error message", "validation message"]
78
+ template: "User see [Field Error] message with {{error_text}}"
79
+ - theme: format-boundary
80
+ keywords: [format, invalid, boundary, length, range]
81
+ depth:
82
+ requires: data-assertion
83
+ cross_screen: false
84
+ keywords: ["invalid format", "boundary", "max length", "min length", "out of range"]
85
+ template: "User see [Field Error] message with {{error_text}}"
86
+ - theme: submit-success
87
+ keywords: [submit, success, saved, created]
88
+ depth:
89
+ requires: data-assertion
90
+ cross_screen: false
91
+ keywords: ["success message", "saved", "created", "confirmation"]
92
+ template: "User see [Success] message with {{success_text}}"
93
+
94
+ auth:
95
+ detect_keywords: [login, logout, password, signin, "sign in", credential]
96
+ must_cover:
97
+ - theme: valid-login
98
+ keywords: ["valid", login, success]
99
+ - theme: invalid-credential
100
+ keywords: ["invalid", "wrong password", error, incorrect]
101
+ depth:
102
+ requires: data-assertion
103
+ cross_screen: false
104
+ keywords: ["wrong password", "incorrect", "invalid credential", "error message"]
105
+ template: "User see [Login Error] message with {{error_text}}"
106
+ - theme: access-control
107
+ keywords: ["unauthorized", "redirect", "not logged in", permission]
108
+
109
+ # Universal themes worth checking on ANY page-type (low-weight reminders).
110
+ universal:
111
+ - theme: error-empty-state
112
+ keywords: ["empty", "no data", "no result", "failed", "error state"]
113
+ - theme: accessibility
114
+ keywords: ["keyboard", "tab order", "accessible", "aria", "focus"]
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Challenge / Exploration Harness (harness-roadmap P4) — Loop 2.
3
+ *
4
+ * Production mode (Loop 1: create-test → audit gate → repair) is deterministic by
5
+ * design: same spec + viewpoint → same official suite. That is the *feature* for
6
+ * delivery/CI, but it can feel like "a machine that always outputs the same thing".
7
+ *
8
+ * The Challenge Harness is the antidote: it does NOT regenerate the suite — it
9
+ * ATTACKS the existing one to surface what production missed. It is advisory
10
+ * (never auto-merges) and read-only.
11
+ *
12
+ * This module is the DETERMINISTIC spine — three structural critics:
13
+ * 1. Coverage — over-covered (low-value) areas + shallow gate themes.
14
+ * 2. Depth — titles that claim a collection but assert a single element.
15
+ * 3. Novelty — risk-based prompts the AI `sungen-challenge` agent expands into
16
+ * concrete novelty candidates (semantic — not deterministic here).
17
+ *
18
+ * The AI agent layer adds the semantic + novelty judgement on top of this spine.
19
+ */
20
+ import * as path from 'path';
21
+ import { loadScenarios, ScenarioInfo } from './parse';
22
+ import { runAudit } from './audit';
23
+
24
+ export interface ChallengeFinding {
25
+ scenario?: string;
26
+ issue: string;
27
+ suggestion: string;
28
+ }
29
+
30
+ export interface ChallengeReport {
31
+ screen: string;
32
+ // Coverage critic
33
+ overCovered: { bucket: string; count: number; note: string }[];
34
+ shallowThemes: string[];
35
+ // Depth critic
36
+ collectionClaimSingular: ChallengeFinding[];
37
+ // Novelty critic (deterministic prompts → AI agent fills candidates)
38
+ noveltyPrompts: string[];
39
+ // Roll-up
40
+ explorationReadiness: string[];
41
+ }
42
+
43
+ // A collection claim = a PLURAL set noun (or an explicit quantifier) used with a
44
+ // DISPLAY verb. Plural-only avoids false-positives on single-item actions like
45
+ // "Adding A product ... shows the dialog" (which correctly asserts one item).
46
+ const PLURAL_NOUN = /\b(cards|items|products|rows|results|prices|entries|records)\b/i;
47
+ const QUANTIFIER = /\b(all|every|each)\b/i;
48
+ const DISPLAY_VERB = /\b(displays?|shows?|lists?|grid|contains?)\b/i;
49
+
50
+ /** Risk lenses the Novelty critic prompts the AI to explore (beyond the catalog). */
51
+ const NOVELTY_LENSES = [
52
+ 'double-submit / rapid repeat of the primary action (duplicate side-effects?)',
53
+ 'state after partial / slow load (assert against a not-yet-ready page)',
54
+ 'boundary & unusual data (very long text, 0 / max quantity, special chars)',
55
+ 'concurrency / back-button / refresh mid-flow',
56
+ 'historical-incident mindset — what has broken on similar screens before?',
57
+ ];
58
+
59
+ export function buildChallenge(screenDir: string, screenName: string): ChallengeReport {
60
+ const featurePath = path.join(screenDir, 'features', `${screenName}.feature`);
61
+ const scenarios: ScenarioInfo[] = loadScenarios(featurePath);
62
+ const audit = runAudit(screenDir, screenName);
63
+
64
+ // 1. Coverage critic — over-covered buckets (secondary >> business-core) + shallow themes.
65
+ const buckets = audit.balance.byBucket;
66
+ const core = buckets['business-core'] || 0;
67
+ const overCovered: ChallengeReport['overCovered'] = [];
68
+ for (const [bucket, count] of Object.entries(buckets)) {
69
+ if (['business-core', 'other'].includes(bucket)) continue;
70
+ if (core > 0 && count > core * 1.5) {
71
+ overCovered.push({ bucket, count, note: `${count} scenarios vs ${core} business-core — likely low-value expansion; trim toward correctness.` });
72
+ }
73
+ }
74
+ const shallowThemes = audit.gate.gaps.filter((g) => g.status === 'shallow').map((g) => g.theme);
75
+
76
+ // 2. Depth critic — title claims a collection but the assertion is singular (no "see all").
77
+ const collectionClaimSingular: ChallengeFinding[] = [];
78
+ for (const s of scenarios) {
79
+ if (s.manual || s.category === 'NAV') continue;
80
+ const claimsCollection = (PLURAL_NOUN.test(s.name) || QUANTIFIER.test(s.name)) && DISPLAY_VERB.test(s.name);
81
+ const assertsAll = /\bsee all\b/.test(s.haystack);
82
+ if (claimsCollection && !assertsAll) {
83
+ collectionClaimSingular.push({
84
+ scenario: s.name,
85
+ issue: 'Title implies a set (cards/items/all) but the assertion targets a single element.',
86
+ suggestion: 'Prove EVERY member: `Then User see all [<Card/Row>] contain {{...}}` instead of a single `see [X]`.',
87
+ });
88
+ }
89
+ }
90
+
91
+ // 3. Novelty critic — deterministic prompts; the AI agent expands these into candidates.
92
+ const noveltyPrompts = NOVELTY_LENSES.map((l) => `Find 1 non-obvious, valuable scenario via: ${l}`);
93
+
94
+ // Roll-up — exploration readiness signals (not a fake score).
95
+ const explorationReadiness: string[] = [];
96
+ if (collectionClaimSingular.length) explorationReadiness.push(`${collectionClaimSingular.length} title↔assertion gap(s) — deterministic depth critic flagged these; an AI Business-Depth critic should confirm + fix.`);
97
+ if (overCovered.length) explorationReadiness.push(`${overCovered.length} possibly over-covered area(s) — rebalance toward correctness.`);
98
+ if (shallowThemes.length) explorationReadiness.push(`Shallow themes: ${shallowThemes.join(', ')}.`);
99
+ explorationReadiness.push('Novelty candidates are NOT generated deterministically — run the `sungen-challenge` agent (Claude) or its inline criteria (Copilot) to propose them, then QA accept/reject (≤20% of official, no auto-merge).');
100
+
101
+ return { screen: screenName, overCovered, shallowThemes, collectionClaimSingular, noveltyPrompts, explorationReadiness };
102
+ }
103
+
104
+ /** Render the Challenge Report as Markdown (advisory — not part of the official suite). */
105
+ export function renderChallengeMarkdown(r: ChallengeReport): string {
106
+ const lines: string[] = [];
107
+ lines.push(`# Challenge Report — ${r.screen}`, '');
108
+ lines.push('> Advisory (Loop 2 / exploration mode). Does NOT change the official suite — it attacks it to surface blind spots. QA decides what to adopt.', '');
109
+
110
+ lines.push('## Depth — title claims a collection but asserts a single element');
111
+ if (r.collectionClaimSingular.length) {
112
+ lines.push('| Scenario | Issue | Suggested |', '|---|---|---|');
113
+ for (const f of r.collectionClaimSingular) lines.push(`| ${f.scenario} | ${f.issue} | ${f.suggestion} |`);
114
+ } else lines.push('_none_');
115
+ lines.push('');
116
+
117
+ lines.push('## Coverage — possibly over-covered / shallow');
118
+ if (r.overCovered.length) for (const o of r.overCovered) lines.push(`- **${o.bucket}** — ${o.note}`);
119
+ if (r.shallowThemes.length) lines.push(`- Shallow themes: ${r.shallowThemes.join(', ')}`);
120
+ if (!r.overCovered.length && !r.shallowThemes.length) lines.push('_balanced_');
121
+ lines.push('');
122
+
123
+ lines.push('## Novelty — prompts for the AI critic (expand into candidates, ≤20% of official, no auto-merge)');
124
+ for (const p of r.noveltyPrompts) lines.push(`- ${p}`);
125
+ lines.push('');
126
+
127
+ lines.push('## Exploration readiness');
128
+ for (const e of r.explorationReadiness) lines.push(`- ${e}`);
129
+ lines.push('');
130
+ return lines.join('\n');
131
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Feedback — local-first capture of QA feedback. The most valuable use of
3
+ * feedback is closing the learning loop WITHIN a project (feed reuse/regenerate
4
+ * + improve the Guide), which needs no server. A future opt-in `feedback sync`
5
+ * can push anonymized metadata to a central API (Nấc 2) — not implemented here.
6
+ *
7
+ * Two purposes are kept distinct:
8
+ * - test-design: a viewpoint/scenario is wrong / missing / duplicate → knowledge
9
+ * - product: Sungen itself did X wrong → telemetry/issue
10
+ *
11
+ * Storage: .sungen/feedback/feedback.jsonl (append-only)
12
+ */
13
+ import * as fs from 'fs';
14
+ import * as path from 'path';
15
+
16
+ export type FeedbackType = 'test-design' | 'product' | 'other';
17
+ export type FeedbackDecision = 'accept' | 'reject' | 'edit' | 'add' | 'none';
18
+
19
+ export interface FeedbackEntry {
20
+ ts: string;
21
+ type: FeedbackType;
22
+ screen?: string;
23
+ target?: string; // viewpoint id / scenario / command / artifact the feedback is about
24
+ decision?: FeedbackDecision;
25
+ message: string;
26
+ reason?: string;
27
+ source: string; // who (default: qa)
28
+ auditScore?: number; // snapshot of current audit score if available
29
+ }
30
+
31
+ function feedbackPath(): string {
32
+ return path.join(process.cwd(), '.sungen', 'feedback', 'feedback.jsonl');
33
+ }
34
+
35
+ function currentAuditScore(screen?: string): number | undefined {
36
+ if (!screen) return undefined;
37
+ const p = path.join(process.cwd(), '.sungen', 'reports', `${screen}-audit.json`);
38
+ if (!fs.existsSync(p)) return undefined;
39
+ try { return JSON.parse(fs.readFileSync(p, 'utf-8'))?.score?.overall; } catch { return undefined; }
40
+ }
41
+
42
+ export function recordFeedback(entry: Omit<FeedbackEntry, 'ts' | 'source' | 'auditScore'> & { ts?: string; source?: string }): string {
43
+ const p = feedbackPath();
44
+ fs.mkdirSync(path.dirname(p), { recursive: true });
45
+ const full: FeedbackEntry = {
46
+ ts: entry.ts ?? new Date().toISOString(),
47
+ type: entry.type,
48
+ screen: entry.screen,
49
+ target: entry.target,
50
+ decision: entry.decision ?? 'none',
51
+ message: entry.message,
52
+ reason: entry.reason,
53
+ source: entry.source ?? 'qa',
54
+ auditScore: currentAuditScore(entry.screen),
55
+ };
56
+ fs.appendFileSync(p, JSON.stringify(full) + '\n', 'utf-8');
57
+ return p;
58
+ }
59
+
60
+ export function readFeedback(): FeedbackEntry[] {
61
+ const p = feedbackPath();
62
+ if (!fs.existsSync(p)) return [];
63
+ return fs.readFileSync(p, 'utf-8').split('\n').filter(Boolean).map((l) => JSON.parse(l));
64
+ }
65
+
66
+ export interface FeedbackSummary {
67
+ total: number;
68
+ byType: Record<string, number>;
69
+ byDecision: Record<string, number>;
70
+ entries: FeedbackEntry[];
71
+ }
72
+
73
+ export function summarize(filter?: { screen?: string; type?: FeedbackType }): FeedbackSummary {
74
+ let entries = readFeedback();
75
+ if (filter?.screen) entries = entries.filter((e) => e.screen === filter.screen);
76
+ if (filter?.type) entries = entries.filter((e) => e.type === filter.type);
77
+ const byType: Record<string, number> = {};
78
+ const byDecision: Record<string, number> = {};
79
+ for (const e of entries) {
80
+ byType[e.type] = (byType[e.type] || 0) + 1;
81
+ byDecision[e.decision || 'none'] = (byDecision[e.decision || 'none'] || 0) + 1;
82
+ }
83
+ return { total: entries.length, byType, byDecision, entries };
84
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Intent Profile (harness-roadmap P3) — lets the gate flex to project intent.
3
+ *
4
+ * Read from qa/context.md so a project can declare what it cares about:
5
+ *
6
+ * ## Intent
7
+ * focus: security # functional | e-commerce | security | smoke
8
+ * risk_tier: high # high | normal | low (reserved — future weighting)
9
+ * tier_scope: full # tier-1 | full (reserved)
10
+ *
11
+ * Keys may appear anywhere in context.md (a heading is optional). Unknown / missing
12
+ * values fall back to the safe default (functional), so behaviour is unchanged for
13
+ * projects that haven't declared an intent.
14
+ */
15
+ import * as fs from 'fs';
16
+ import * as path from 'path';
17
+
18
+ export type IntentFocus = 'functional' | 'e-commerce' | 'security' | 'smoke';
19
+
20
+ export interface IntentProfile {
21
+ focus: IntentFocus;
22
+ riskTier: 'high' | 'normal' | 'low';
23
+ tierScope: 'tier-1' | 'full';
24
+ source: 'context.md' | 'default';
25
+ }
26
+
27
+ const DEFAULT_INTENT: IntentProfile = {
28
+ focus: 'functional', riskTier: 'normal', tierScope: 'full', source: 'default',
29
+ };
30
+
31
+ const FOCI: IntentFocus[] = ['functional', 'e-commerce', 'security', 'smoke'];
32
+
33
+ /** Resolve project root from a screen/flow dir (…/qa/screens/<name>). */
34
+ export function projectRootFromScreenDir(screenDir: string): string {
35
+ return path.resolve(screenDir, '..', '..', '..');
36
+ }
37
+
38
+ export function readIntent(projectRoot: string): IntentProfile {
39
+ const ctx = path.join(projectRoot, 'qa', 'context.md');
40
+ if (!fs.existsSync(ctx)) return DEFAULT_INTENT;
41
+ let text: string;
42
+ try { text = fs.readFileSync(ctx, 'utf-8').toLowerCase(); } catch { return DEFAULT_INTENT; }
43
+
44
+ const grab = (key: string): string | undefined => {
45
+ const m = text.match(new RegExp(`(?:^|\\n)\\s*${key}\\s*:\\s*([a-z0-9-]+)`));
46
+ return m?.[1];
47
+ };
48
+
49
+ const focusRaw = grab('focus');
50
+ const focus = (FOCI.includes(focusRaw as IntentFocus) ? focusRaw : DEFAULT_INTENT.focus) as IntentFocus;
51
+ const risk = grab('risk_tier');
52
+ const riskTier = (['high', 'normal', 'low'].includes(risk as string) ? risk : DEFAULT_INTENT.riskTier) as IntentProfile['riskTier'];
53
+ const scope = grab('tier_scope');
54
+ const tierScope = (['tier-1', 'full'].includes(scope as string) ? scope : DEFAULT_INTENT.tierScope) as IntentProfile['tierScope'];
55
+
56
+ const found = focusRaw || risk || scope;
57
+ return { focus, riskTier, tierScope, source: found ? 'context.md' : 'default' };
58
+ }