@v11g/agents-rock 1.0.10 → 1.0.12

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 (122) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/plugins/business-analyst/.claude-plugin/plugin.json +2 -2
  4. package/plugins/business-analyst/evals/draft-scope-rich/case.yaml +4 -0
  5. package/plugins/business-analyst/evals/draft-scope-rich/fixture.sh +5 -0
  6. package/plugins/business-analyst/evals/draft-scope-rich/graders/conflict-question.md +11 -0
  7. package/plugins/business-analyst/evals/draft-scope-rich/graders/keep-and-exclude.md +14 -0
  8. package/plugins/business-analyst/evals/draft-scope-rich/graders/noise-and-shape.md +13 -0
  9. package/plugins/business-analyst/evals/draft-scope-rich/graders/problem-not-solution.md +13 -0
  10. package/plugins/business-analyst/evals/draft-scope-rich/graders/share-kept.md +11 -0
  11. package/plugins/business-analyst/evals/draft-scope-rich/graders/skill-fired.md +7 -0
  12. package/plugins/business-analyst/evals/draft-scope-rich/graders/vague-word.md +13 -0
  13. package/plugins/business-analyst/evals/draft-scope-rich/inputs/C1.txt +10 -0
  14. package/plugins/business-analyst/evals/draft-scope-rich/inputs/E1.txt +5 -0
  15. package/plugins/business-analyst/evals/draft-scope-rich/inputs/E2.txt +5 -0
  16. package/plugins/business-analyst/evals/draft-scope-rich/inputs/E3.txt +5 -0
  17. package/plugins/business-analyst/evals/draft-scope-rich/prompt.md +9 -0
  18. package/plugins/business-analyst/evals/draft-scope-thin/case.yaml +4 -0
  19. package/plugins/business-analyst/evals/draft-scope-thin/fixture.sh +4 -0
  20. package/plugins/business-analyst/evals/draft-scope-thin/graders/no-invention.md +18 -0
  21. package/plugins/business-analyst/evals/draft-scope-thin/graders/skill-fired.md +7 -0
  22. package/plugins/business-analyst/evals/draft-scope-thin/inputs/E1.txt +5 -0
  23. package/plugins/business-analyst/evals/draft-scope-thin/prompt.md +8 -0
  24. package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/review_data.cpython-312.pyc +0 -0
  25. package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/review_layout.cpython-312.pyc +0 -0
  26. package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/review_page.cpython-312.pyc +0 -0
  27. package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/scope_checks.cpython-312.pyc +0 -0
  28. package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/scope_render.cpython-312.pyc +0 -0
  29. package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/validate.cpython-312.pyc +0 -0
  30. package/plugins/business-analyst/skills/draft-scope/SKILL.md +46 -0
  31. package/plugins/business-analyst/skills/draft-scope/references/credits.md +12 -0
  32. package/plugins/business-analyst/skills/draft-scope/references/draft-schema.md +44 -0
  33. package/plugins/business-analyst/skills/draft-scope/references/rules.md +24 -0
  34. package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_body.cpython-312.pyc +0 -0
  35. package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_flow.cpython-312.pyc +0 -0
  36. package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_package.cpython-312.pyc +0 -0
  37. package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_xml.cpython-312.pyc +0 -0
  38. package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/draft_quotes.cpython-312.pyc +0 -0
  39. package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/draft_rules.cpython-312.pyc +0 -0
  40. package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/draft_schema.cpython-312.pyc +0 -0
  41. package/plugins/business-analyst/skills/draft-scope/scripts/build_docx.py +36 -0
  42. package/plugins/business-analyst/skills/draft-scope/scripts/check.py +53 -0
  43. package/plugins/business-analyst/skills/draft-scope/scripts/docx_body.py +58 -0
  44. package/plugins/business-analyst/skills/draft-scope/scripts/docx_flow.py +52 -0
  45. package/plugins/business-analyst/skills/draft-scope/scripts/docx_package.py +62 -0
  46. package/plugins/business-analyst/skills/draft-scope/scripts/docx_xml.py +44 -0
  47. package/plugins/business-analyst/skills/draft-scope/scripts/draft_quotes.py +49 -0
  48. package/plugins/business-analyst/skills/draft-scope/scripts/draft_rules.py +106 -0
  49. package/plugins/business-analyst/skills/draft-scope/scripts/draft_schema.py +87 -0
  50. package/plugins/business-analyst/skills/draft-scope/scripts/test/build-docx.test.mjs +76 -0
  51. package/plugins/business-analyst/skills/draft-scope/scripts/test/check-rules.test.mjs +131 -0
  52. package/plugins/business-analyst/skills/draft-scope/scripts/test/check-shape.test.mjs +70 -0
  53. package/plugins/business-analyst/skills/draft-scope/scripts/test/fixtures/draft-pass.json +40 -0
  54. package/plugins/business-analyst/skills/draft-scope/scripts/test/fixtures/sources/C1.txt +7 -0
  55. package/plugins/business-analyst/skills/draft-scope/scripts/test/fixtures/sources/E1.txt +5 -0
  56. package/plugins/business-analyst/skills/draft-scope/scripts/test/gates.test.mjs +39 -0
  57. package/plugins/business-analyst/skills/draft-scope/scripts/test/helpers.mjs +30 -0
  58. package/plugins/business-analyst/skills/draft-scope/scripts/test/skill-files.test.mjs +59 -0
  59. package/plugins/business-analyst/skills/draft-scope/steps/assumptions.md +24 -0
  60. package/plugins/business-analyst/skills/draft-scope/steps/check.md +24 -0
  61. package/plugins/business-analyst/skills/draft-scope/steps/discover.md +53 -0
  62. package/plugins/business-analyst/skills/draft-scope/steps/draft.md +64 -0
  63. package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
  64. package/plugins/solution-architect/skills/analyze-requirements/SKILL.md +8 -7
  65. package/plugins/solution-architect/skills/analyze-requirements/assets/section-help.json +5 -5
  66. package/plugins/solution-architect/skills/analyze-requirements/assets/viewer-template.html +15 -3
  67. package/plugins/solution-architect/skills/analyze-requirements/evals/evals.json +50 -6
  68. package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/ba-package-citations/requirements.json +31 -0
  69. package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/ba-package-citations/requirements.md +17 -0
  70. package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/transcript-citations/C1-kickoff-call.txt +16 -0
  71. package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/transcript-citations/E1-intro-email.md +9 -0
  72. package/plugins/solution-architect/skills/analyze-requirements/references/extract.md +108 -0
  73. package/plugins/solution-architect/skills/analyze-requirements/references/interview.md +39 -5
  74. package/plugins/solution-architect/skills/analyze-requirements/references/project-types.md +1 -1
  75. package/plugins/solution-architect/skills/analyze-requirements/references/quality-goals.md +84 -0
  76. package/plugins/solution-architect/skills/analyze-requirements/references/research.md +1 -1
  77. package/plugins/solution-architect/skills/analyze-requirements/references/rewriting.md +7 -2
  78. package/plugins/solution-architect/skills/analyze-requirements/references/viewer.md +10 -6
  79. package/plugins/solution-architect/skills/analyze-requirements/references/writing.md +45 -3
  80. package/plugins/solution-architect/skills/analyze-requirements/scripts/ba-facts.mjs +32 -0
  81. package/plugins/solution-architect/skills/analyze-requirements/scripts/check-quotes.mjs +39 -0
  82. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/ba-package.mjs +75 -0
  83. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-links.mjs +19 -7
  84. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-routes.mjs +1 -1
  85. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/inputs.mjs +42 -11
  86. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-render.mjs +15 -4
  87. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/section-help.mjs +1 -1
  88. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/strategy-sections.mjs +30 -0
  89. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-provenance.mjs +14 -2
  90. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-quotes.mjs +55 -0
  91. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-strategy.mjs +65 -0
  92. package/plugins/solution-architect/skills/analyze-requirements/scripts/render.mjs +18 -5
  93. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/ba-facts-cli.test.mjs +55 -0
  94. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/ba-package-cli.test.mjs +101 -0
  95. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/ba-package.test.mjs +115 -0
  96. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/browser.test.mjs +50 -2
  97. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/check-quotes-cli.test.mjs +49 -0
  98. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-links.test.mjs +49 -4
  99. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/extract-workflow.test.mjs +69 -0
  100. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/inputs.test.mjs +14 -0
  101. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-render.test.mjs +19 -5
  102. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/record-cli.test.mjs +1 -1
  103. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/render.test.mjs +69 -2
  104. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/rewriting.test.mjs +1 -1
  105. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/section-help.test.mjs +6 -0
  106. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-provenance.test.mjs +19 -0
  107. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-quotes-cli.test.mjs +58 -0
  108. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-quotes.test.mjs +81 -0
  109. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-strategy-cli.test.mjs +32 -0
  110. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-strategy.test.mjs +118 -0
  111. package/plugins/solution-architect/skills/analyze-requirements/scripts/validate.mjs +17 -6
  112. package/plugins/solution-architect/skills/analyze-requirements/workflows/extract.js +51 -0
  113. package/plugins/solution-architect/skills/estimate/workflow-based/assets/estimate-components.html +73 -9
  114. package/plugins/solution-architect/skills/estimate/workflow-based/assets/score-review.html +73 -9
  115. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/build-template.mjs +14 -1
  116. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/also-builds.css +3 -0
  117. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/also-builds.js +16 -0
  118. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/link-picker.css +8 -0
  119. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/link-picker.js +43 -0
  120. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/test/also-builds-browser.test.mjs +59 -0
  121. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/test/link-picker-browser.test.mjs +83 -0
  122. package/plugins/solution-architect/skills/estimate/workflow-based/scripts/test/stage.mjs +19 -1
@@ -0,0 +1,81 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {
4
+ normalize, parseCitations, closestSentence, briefQuotesOf, validateQuotes,
5
+ } from '../lib/validate-quotes.mjs';
6
+
7
+ const C1 = 'Maya: We open sales at 10am sharp. For a headline act we get ten times the orders\nin the first five minutes.\nMaya: We don’t want to touch card data.';
8
+ const sources = new Map([['inputs/C1-kickoff-call.txt', C1]]);
9
+ const cite = (quote) => ({ label: 'C1 · 2026-09-10', path: 'inputs/C1-kickoff-call.txt', quote });
10
+
11
+ test('normalize folds curly quotes and whitespace', () => {
12
+ assert.equal(normalize(' don’t “x”\n y '), 'don\'t "x" y');
13
+ });
14
+
15
+ test('parseCitations reads label, path without fragment, and quote', () => {
16
+ const md = '| a | stated [C1 · 2026-09-10](inputs/C1.txt) "ten times" |\n| b | stated [Q3 · 2026-10-14](interview-log.md#q3) |';
17
+ assert.deepEqual(parseCitations(md), [
18
+ { label: 'C1 · 2026-09-10', path: 'inputs/C1.txt', quote: 'ten times' },
19
+ { label: 'Q3 · 2026-10-14', path: 'interview-log.md', quote: null },
20
+ ]);
21
+ });
22
+
23
+ test('passes an exact quote, a wrapped quote, and a straight-quoted apostrophe', () => {
24
+ const citations = [
25
+ cite('We open sales at 10am sharp.'),
26
+ cite('ten times the orders in the first five minutes'),
27
+ cite("We don't want to touch card data."),
28
+ ];
29
+ assert.deepEqual(validateQuotes({ citations, briefQuotes: [], sources }), []);
30
+ });
31
+
32
+ test('fails a reworded quote and names the closest sentence', () => {
33
+ const out = validateQuotes({ citations: [cite('ten times more orders in five minutes')], briefQuotes: [], sources });
34
+ assert.equal(out.length, 1);
35
+ assert.equal(out[0].check, 'quotes');
36
+ assert.match(out[0].message, /not found in inputs\/C1-kickoff-call\.txt; closest: "For a headline act/);
37
+ });
38
+
39
+ test('is case-sensitive', () => {
40
+ assert.equal(validateQuotes({ citations: [cite('we open sales at 10am sharp.')], briefQuotes: [], sources }).length, 1);
41
+ });
42
+
43
+ test('skips interview citations and citations to files not loaded', () => {
44
+ const citations = [
45
+ { label: 'Q3', path: 'interview-log.md', quote: null },
46
+ { label: 'E9', path: 'inputs/E9.md', quote: 'anything' },
47
+ ];
48
+ assert.deepEqual(validateQuotes({ citations, briefQuotes: [], sources }), []);
49
+ });
50
+
51
+ test('Brief says quotes must appear in some input, and are skipped with no inputs', () => {
52
+ assert.deepEqual(validateQuotes({ citations: [], briefQuotes: ['10am sharp'], sources }), []);
53
+ const out = validateQuotes({ citations: [], briefQuotes: ['sold out in seconds'], sources });
54
+ assert.match(out[0].message, /Brief says "sold out in seconds" is in no input file/);
55
+ assert.deepEqual(validateQuotes({ citations: [], briefQuotes: ['anything'], sources: new Map() }), []);
56
+ });
57
+
58
+ test('briefQuotesOf reads the §13 Brief says column', () => {
59
+ const t = {
60
+ section: '13 Quality Requirements and SLOs',
61
+ headers: ['Goal', 'Target', 'Brief says', 'src'],
62
+ rows: [['Speed', 't', '"10am sharp"', 'stated'], ['Uptime', 't', '—', 'stated'], ['Not provided — x', '', '', 'stated']],
63
+ };
64
+ assert.deepEqual(briefQuotesOf([t]), ['10am sharp']);
65
+ assert.deepEqual(briefQuotesOf([]), []);
66
+ });
67
+
68
+ test('closestSentence picks the sentence sharing most words', () => {
69
+ assert.match(closestSentence(C1, 'orders in five minutes'), /^For a headline act/);
70
+ });
71
+
72
+ test('briefQuotesOf strips curly surrounding quotes', () => {
73
+ const t = {
74
+ section: '13 Quality Requirements and SLOs',
75
+ headers: ['Goal', 'Target', 'Brief says', 'src'],
76
+ rows: [['Speed', 't', '“10am sharp”', 'stated']],
77
+ };
78
+ const briefQuotes = briefQuotesOf([t]);
79
+ assert.deepEqual(briefQuotes, ['10am sharp']);
80
+ assert.deepEqual(validateQuotes({ citations: [], briefQuotes, sources }), []);
81
+ });
@@ -0,0 +1,32 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { mkdtempSync, writeFileSync } from 'node:fs';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
+
8
+ const CLI = 'plugins/solution-architect/skills/analyze-requirements/scripts/validate.mjs';
9
+ const FRONT = '---\nelectedDocs: [{"name":"threat-model","elected":false,"reason":"r"},{"name":"interface-contract","elected":false,"reason":"r"},{"name":"estimation","elected":false,"reason":"r"},{"name":"domain-overview","elected":false,"reason":"r"}]\n---\n\n';
10
+ const GOALS = '## 13 Quality Requirements and SLOs\n\n| Goal | Target | Brief says | src |\n| --- | --- | --- | --- |\n| Uptime | 99.9% | "q" | stated |\n| Integration | 5 min | "q" | stated |\n| Speed (gives way first) | 2s | "q" | stated |\n';
11
+
12
+ function validate(body) {
13
+ const dir = mkdtempSync(join(tmpdir(), 'strategy-cli-'));
14
+ writeFileSync(join(dir, 'ARCHITECTURE.md'), FRONT + body);
15
+ writeFileSync(join(dir, 'model.json'), JSON.stringify({ elements: {} }));
16
+ return spawnSync('node', [CLI, '--root', dir,
17
+ '--arch', join(dir, 'ARCHITECTURE.md'), '--model', join(dir, 'model.json')], { encoding: 'utf8' });
18
+ }
19
+
20
+ test('§4 bullets: WARN printed, exit 0', () => {
21
+ const r = validate('## 4 Solution Strategy\n\n- Single app → ADR-001\n\n' + GOALS);
22
+ assert.equal(r.status, 0, r.stdout);
23
+ assert.match(r.stdout, /^WARN \[strategy\] §4 is a list/m);
24
+ assert.match(r.stdout, /all checks passed/);
25
+ });
26
+
27
+ test('unserved goal: FAIL printed, exit 1', () => {
28
+ const strategy = '## 4 Solution Strategy\n\n| Decision | Serves | ADR | src |\n| --- | --- | --- | --- |\n| Single app | Uptime, Integration | ADR-001 | proposed |\n\n';
29
+ const r = validate(strategy + GOALS);
30
+ assert.equal(r.status, 1);
31
+ assert.match(r.stdout, /^FAIL \[strategy\] §13 goal "speed"/m);
32
+ });
@@ -0,0 +1,118 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { validateStrategy } from '../lib/validate-strategy.mjs';
4
+
5
+ const GOALS = '13 Quality Requirements and SLOs';
6
+ const STRATEGY = '4 Solution Strategy';
7
+ const goals = (...cells) => ({
8
+ section: GOALS, headers: ['Goal', 'Target', 'Brief says', 'src'],
9
+ rows: cells.map((c) => [c, 't', 'q', 'stated']),
10
+ });
11
+ const strategy = (...serves) => ({
12
+ section: STRATEGY, headers: ['Decision', 'Serves', 'ADR', 'src'],
13
+ rows: serves.map((s, i) => [`decision ${i}`, s, 'ADR-001', 'proposed']),
14
+ });
15
+ const THREE = goals('Uptime', 'Integration', 'Speed (gives way first)');
16
+ const render = (t) => [
17
+ `## ${t.section}`, '', `| ${t.headers.join(' | ')} |`, `|${t.headers.map(() => '---').join('|')}|`,
18
+ ...t.rows.map((r) => `| ${r.join(' | ')} |`), '',
19
+ ].join('\n');
20
+ const run = (tables, archMd = '') => validateStrategy({ tables: [], archMd: tables.map(render).join('\n') + archMd });
21
+ const fails = (fs) => fs.filter((f) => f.level !== 'warn');
22
+
23
+ test('passes three goals, one giving way, every goal served', () => {
24
+ assert.deepEqual(run([THREE, strategy('Uptime, Integration', 'Speed')]), []);
25
+ });
26
+
27
+ test('fails when §13 does not have exactly three rows', () => {
28
+ const out = run([goals('Uptime', 'Speed (gives way first)'), strategy('Uptime, Speed')]);
29
+ assert.match(out[0].message, /2 goal rows, expected 3/);
30
+ });
31
+
32
+ test('fails when no goal or two goals give way first', () => {
33
+ assert.equal(run([goals('A', 'B', 'C'), strategy('A, B, C')]).length, 1);
34
+ const two = goals('A (gives way first)', 'B (gives way first)', 'C');
35
+ assert.match(run([two, strategy('A, B, C')])[0].message, /marks 2 goals/);
36
+ });
37
+
38
+ test('Not provided rows count as rows but not as goals', () => {
39
+ const t = goals('Reliability', 'Simplicity (gives way first)', 'Not provided — user declined');
40
+ assert.deepEqual(run([t, strategy('Reliability', 'Simplicity')]), []);
41
+ const one = goals('Reliability', 'Not provided — a', 'Not provided — b');
42
+ assert.deepEqual(run([one, strategy('Reliability')]), []);
43
+ });
44
+
45
+ test('fails a decision serving a non-goal, and one serving nothing', () => {
46
+ const out = run([THREE, strategy('Uptime, Integration, Speed', 'Growth', '')]);
47
+ assert.equal(out.length, 2);
48
+ assert.match(out[0].message, /"growth", not a §13 goal/);
49
+ assert.match(out[1].message, /serves no goal/);
50
+ });
51
+
52
+ test('fails a goal no decision serves', () => {
53
+ const out = run([THREE, strategy('Uptime, Integration')]);
54
+ assert.match(out[0].message, /goal "speed" is served by no §4 decision/);
55
+ });
56
+
57
+ test('matches serves names case-insensitively and with the gives-way label', () => {
58
+ assert.deepEqual(run([THREE, strategy('uptime, INTEGRATION', 'Speed (gives way first)')]), []);
59
+ });
60
+
61
+ test('fails a §4 table with no Serves column', () => {
62
+ const t = { section: STRATEGY, headers: ['Decision', 'ADR', 'src'], rows: [['d', 'a', 'proposed']] };
63
+ assert.match(run([THREE, t])[0].message, /no Serves column/);
64
+ });
65
+
66
+ test('legacy §13 (no Goal column) warns once and skips serves checks', () => {
67
+ const legacy = { section: GOALS, headers: ['Requirement', 'Target', 'src'], rows: [['r', 't', 'stated']] };
68
+ const out = run([legacy, strategy('anything')]);
69
+ assert.equal(out.length, 1);
70
+ assert.equal(out[0].level, 'warn');
71
+ assert.match(out[0].message, /predates top-3 goals/);
72
+ });
73
+
74
+ test('§4 written as bullets warns, even under a ### subheading', () => {
75
+ const md = '## 4 Solution Strategy\n\n### Notes\n\n- Single app → ADR-001\n\n## 5 Architecture Model\n';
76
+ const out = run([THREE], md);
77
+ assert.equal(out.length, 1);
78
+ assert.equal(out[0].level, 'warn');
79
+ assert.match(out[0].message, /§4 is a list/);
80
+ });
81
+
82
+ test('no findings when §4 and §13 are absent or Not applicable', () => {
83
+ assert.deepEqual(run([], '## Core Components\n'), []);
84
+ const md = '## 4 Solution Strategy\n\nNot applicable — single script\n\n## 13 Quality Requirements\n\nNot applicable — x\n';
85
+ assert.deepEqual(run([], md), []);
86
+ });
87
+
88
+ test('fails never carry the warn level', () => {
89
+ assert.equal(fails(run([THREE, strategy('Uptime')])).length, 2);
90
+ });
91
+
92
+ const GOAL_TABLE = '| Goal | Target | Brief says | src |\n|---|---|---|---|\n| A | t | q | stated |\n| B | t | q | stated |\n| C (gives way first) | t | q | stated |\n';
93
+ const SERVES = (rows) => `| Decision | Serves | ADR | src |\n|---|---|---|---|\n${rows}\n`;
94
+
95
+ test('checks a §4 table under a ### subheading', () => {
96
+ const md = `## 4 Solution Strategy\n\n### Key decisions\n\n${SERVES('| d | A | ADR-1 | proposed |')}\n## 13 Quality Requirements\n\n${GOAL_TABLE}`;
97
+ const out = validateStrategy({ tables: [], archMd: md });
98
+ assert.equal(fails(out).length, 2);
99
+ assert.match(out[0].message, /goal "b" is served by no §4 decision/);
100
+ });
101
+
102
+ test('finds the Goal table when another table comes first in §13', () => {
103
+ const slo = '| SLO | Target | src |\n|---|---|---|\n| p95 | 1s | stated |\n\n';
104
+ const md = `## 4 Solution Strategy\n\n${SERVES('| d | A | ADR-1 | proposed |')}\n## 13 Quality Requirements\n\n${slo}${GOAL_TABLE}`;
105
+ const out = validateStrategy({ tables: [], archMd: md });
106
+ assert.ok(out.every((f) => f.level !== 'warn'));
107
+ assert.equal(out.length, 2);
108
+ });
109
+
110
+ test('skips serves checks when every §13 goal is Not provided', () => {
111
+ const t = goals('Not provided — a', 'Not provided — b', 'Not provided — c');
112
+ assert.deepEqual(run([t, strategy('Growth', '')]), []);
113
+ });
114
+
115
+ test('ignores markdown emphasis in goal and serves cells', () => {
116
+ const t = goals('**Uptime**', '_Integration_', 'Speed *(gives way first)*');
117
+ assert.deepEqual(run([t, strategy('Uptime, **Integration**', 'Speed')]), []);
118
+ });
@@ -8,6 +8,9 @@ import { validateDeployment } from './lib/validate-deployment.mjs';
8
8
  import { validateLinks } from './lib/validate-links.mjs';
9
9
  import { validateTree } from './lib/validate-tree.mjs';
10
10
  import { validateClusters } from './lib/validate-clusters.mjs';
11
+ import { validateStrategy } from './lib/validate-strategy.mjs';
12
+ import { validateQuotes, briefQuotesOf } from './lib/validate-quotes.mjs';
13
+ import { validateBaCitations } from './lib/ba-package.mjs';
11
14
 
12
15
  function consumeDocs(argv, i, docs) {
13
16
  while (argv[i + 1] && !argv[i + 1].startsWith('--')) docs.push(argv[++i]);
@@ -15,11 +18,11 @@ function consumeDocs(argv, i, docs) {
15
18
  }
16
19
 
17
20
  function parseArgs(argv) {
18
- const args = { root: process.cwd(), docs: [] };
21
+ const args = { root: process.cwd(), docs: [], inputs: [] };
19
22
  for (let i = 0; i < argv.length; i += 1) {
20
23
  const flag = argv[i];
21
- if (flag === '--docs') {
22
- i = consumeDocs(argv, i, args.docs);
24
+ if (flag === '--docs' || flag === '--inputs') {
25
+ i = consumeDocs(argv, i, args[flag.slice(2)]);
23
26
  } else if (flag.startsWith('--')) {
24
27
  args[flag.slice(2)] = argv[++i];
25
28
  }
@@ -72,10 +75,14 @@ const inputs = await buildInputs({
72
75
  archPath: args.arch,
73
76
  modelPath: args.model,
74
77
  docPaths: args.docs,
78
+ inputPaths: args.inputs,
75
79
  });
76
80
 
77
81
  const findings = [
78
82
  ...validateProvenance({ tables: inputs.tables }),
83
+ ...validateStrategy({ tables: inputs.tables, archMd: inputs.archMd }),
84
+ ...validateQuotes({ citations: inputs.citations, briefQuotes: briefQuotesOf(inputs.tables), sources: inputs.sources }),
85
+ ...validateBaCitations({ citations: inputs.citations, packages: inputs.packages }),
79
86
  ...validateElections({ frontmatter: inputs.frontmatter }),
80
87
  ...validateModelTables({ model: inputs.model, tables: inputs.tables, erNames: inputs.erNames }),
81
88
  ...validateDeployment({ model: inputs.model }),
@@ -83,6 +90,10 @@ const findings = [
83
90
  ...(args.mode === 'brownfield' ? brownfieldFindings({ inputs, args, root }) : []),
84
91
  ];
85
92
 
86
- for (const f of findings) console.log(`FAIL [${f.check}] ${f.message}`);
87
- if (!findings.length) console.log('ok all checks passed');
88
- process.exit(findings.length ? 1 : 0);
93
+ // A warn finding marks a set written before a rule existed: printed so the
94
+ // next rewrite fixes it, never blocking — rule 4 makes validation gate rendering.
95
+ const fails = findings.filter((f) => f.level !== 'warn');
96
+ for (const f of findings.filter((x) => x.level === 'warn')) console.log(`WARN [${f.check}] ${f.message}`);
97
+ for (const f of fails) console.log(`FAIL [${f.check}] ${f.message}`);
98
+ if (!fails.length) console.log('ok all checks passed');
99
+ process.exit(fails.length ? 1 : 0);
@@ -0,0 +1,51 @@
1
+ export const meta = {
2
+ name: 'arch-docs-extract',
3
+ description: 'One agent per client input file: facts backed by exact quotes',
4
+ phases: [{ title: 'Extract', detail: 'one agent per input file' }],
5
+ }
6
+
7
+ const FACTS = { type: 'object', required: ['facts'], properties: { facts: { type: 'array', items: {
8
+ type: 'object', required: ['fact', 'quote', 'section'],
9
+ properties: { fact: { type: 'string' }, quote: { type: 'string' }, section: { type: 'string' } },
10
+ } } } }
11
+
12
+ // The spine sections a client input can speak to; the agent hunts each one so
13
+ // a fact is missed by omission less often (references/extract.md).
14
+ const CHECKLIST = [
15
+ 'goals and scope',
16
+ 'users and actors',
17
+ 'constraints: budget, deadline, mandated tech, compliance',
18
+ 'quality: speed, load spikes, uptime, data loss, reliability, security, running cost',
19
+ 'external systems and integrations',
20
+ 'data and its sensitivity',
21
+ 'deployment and hosting',
22
+ ]
23
+
24
+ const RULES = 'Read the file with the Read tool. Every fact carries a quote copied character for character from the file: no rewording, no joining separate sentences, no fixing typos. A fact you cannot quote is left out. Small talk is left out.'
25
+
26
+ // requirements.md read without its json (references/extract.md §2.2): the BA
27
+ // already labelled every row, and only a confirmed one is the client's word.
28
+ const BA = 'This file is a business-analyst requirements package. Take only rows labelled confirmed, plus constraints and business rules that name a source. Skip rows labelled assumed or recommended, the assumptions register and open questions: the client did not confirm them.'
29
+
30
+ function promptFor(file) {
31
+ const head = `${RULES}${file.ba ? `\n${BA}` : ''}\nFile: ${file.path}\n`
32
+ if (file.fix) return `${head}These quotes were not found in the file. For each, return the fact again with a quote copied exactly from the file, or leave it out:\n${JSON.stringify(file.fix)}`
33
+ if (args.question) return `${head}Answer only this: ${args.question}`
34
+ return `${head}Work through each topic and return every fact the file states about it, with section set to the topic:\n- ${CHECKLIST.join('\n- ')}`
35
+ }
36
+
37
+ const dropped = []
38
+ const tag = (file) => (r) => {
39
+ if (r) return r.facts.map((f) => ({ ...f, src: file.id, date: file.date, path: file.path }))
40
+ dropped.push({ item: file.id, reason: 'agent returned nothing' })
41
+ log(`DROPPED ${file.id}: agent returned nothing`)
42
+ return []
43
+ }
44
+
45
+ phase('Extract')
46
+ const facts = (await parallel(args.files.map((file) => () =>
47
+ agent(promptFor(file), { label: `extract-${file.id}`, phase: 'Extract', schema: FACTS }).then(tag(file))
48
+ ))).flat()
49
+
50
+ log(`extract done: ${facts.length} facts from ${args.files.length} files, ${dropped.length} dropped`)
51
+ return { facts, dropped }
@@ -308,6 +308,17 @@ textarea, input, select { font-size:.92rem; }
308
308
  @media (prefers-color-scheme:dark) { :root:not([data-theme="light"]) { color-scheme:dark; } }
309
309
  :root[data-theme="dark"] { color-scheme:dark; }
310
310
  select option, select optgroup { background:var(--sheet); color:var(--ink); }
311
+ .crow .calso:not(.open) .cmini.more { display:none; }
312
+ .alsomore { font:inherit; font-size:.74rem; color:var(--ink-dim); background:none; border:0; padding:0 .2rem; cursor:pointer; text-decoration:underline dotted; }
313
+ .alsomore:hover, .alsomore:focus-visible { color:var(--ink); }
314
+ .lpick { position:relative; width:100%; max-width:28rem; margin-top:.4rem; }
315
+ .lpick input { width:100%; box-sizing:border-box; font:inherit; font-size:.85rem; padding:.35rem .6rem; color:var(--ink); background:var(--sheet); border:1px dashed var(--ink-dim); border-radius:.3rem; }
316
+ .lpick input:focus { border-style:solid; border-color:var(--ink); outline:none; }
317
+ .lpick-list { position:absolute; z-index:20; left:0; right:0; top:calc(100% + .2rem); max-height:20rem; overflow:auto; background:var(--sheet); border:1px solid var(--grid); border-radius:.3rem; box-shadow:0 6px 18px rgba(0,0,0,.25); padding:.25rem 0; }
318
+ .lpick-g { font-size:.7rem; font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:var(--ink-dim); padding:.35rem .7rem .15rem; }
319
+ .lpick-o { font-size:.88rem; padding:.3rem .7rem .3rem 1.3rem; cursor:pointer; }
320
+ .lpick-o.lpick-cur { background:var(--hi); }
321
+ .lpick-none { padding:.4rem .7rem; font-size:.85rem; }
311
322
 
312
323
  :root { --c1:#44586a; --c2:#7d96ab; }
313
324
  @media (prefers-color-scheme:dark) { :root:not([data-theme="light"]) { --c1:#bacdda; --c2:#8fa8bb; } }
@@ -579,10 +590,69 @@ const archLink = (containers) => {
579
590
  return [...c3.map((c) => `<a class="archlink" href="${ARCH}#panel-components-${PAGE.c3[c]}" target="_blank" rel="noopener">C3 ${esc(c)} ↗</a>`),
580
591
  c2 && `<a class="archlink" href="${ARCH}#panel-containers" target="_blank" rel="noopener">C2 containers ↗</a>`].filter(Boolean).join(' · ');
581
592
  };
593
+ // the other features a component builds: 3 or more fold to one chip and "…N more"
594
+ const ALSO_SHOWN = 1; const ALSO_FOLD = 3;
595
+ const alsoChip = (c, fold) => `<span class="cmini${fold ? ' more' : ''}" style="--sc:var(--s${sysNo(c)})" data-cap-chip="${c}" title="${esc(capById[c].name)}">${c}</span>`;
596
+ function alsoHtml(others) {
597
+ if (!others.length) return '<span class="dim">only this feature</span>';
598
+ const fold = others.length >= ALSO_FOLD;
599
+ const chips = others.map((c, i) => alsoChip(c, fold && i >= ALSO_SHOWN)).join('');
600
+ const more = fold ? `<button type="button" class="alsomore" data-also-more aria-expanded="false">…${others.length - ALSO_SHOWN} more</button>` : '';
601
+ return `also builds ${chips}${more}`;
602
+ }
603
+ function toggleAlso(b) {
604
+ const box = b.closest('.calso'); const open = box.classList.toggle('open');
605
+ b.setAttribute('aria-expanded', String(open));
606
+ b.textContent = open ? 'show less' : `…${box.querySelectorAll('.cmini.more').length} more`;
607
+ }
608
+ document.addEventListener('click', (e) => { const b = e.target.closest('[data-also-more]'); if (b) toggleAlso(b); });
609
+ // "+ Link a component": a wide search box; typing filters by component or container name
610
+ const pickerHtml = (capId) => `<div class="lpick" data-lpick="${capId}"><input type="search" data-lpick-q placeholder="+ Link a component… type to filter" aria-label="Link a component" autocomplete="off"><div class="lpick-list hide" role="listbox"></div></div>`;
611
+ const pickOpt = (b) => `<div class="lpick-o" role="option" data-lpick-id="${b.id}">${esc(b.name)}${notAsked(b.id) ? '<span class="dim"> · builds nothing yet</span>' : ''}</div>`;
612
+ function pickList(capId, q) {
613
+ const by = buildersOf(capId); const t = q.trim().toLowerCase();
614
+ const hit = (b) => !by.includes(b.id) && `${b.name} ${b.container}`.toLowerCase().includes(t);
615
+ const groups = [...new Set(COMPS.map((b) => b.container))].map((g) => [g, COMPS.filter((b) => b.container === g && hit(b))]).filter(([, bs]) => bs.length);
616
+ if (!groups.length) return '<div class="lpick-none dim">No component matches</div>';
617
+ return groups.map(([g, bs]) => `<div class="lpick-g">${esc(g)}</div>${bs.map(pickOpt).join('')}`).join('');
618
+ }
619
+ function openPick(inp) {
620
+ const box = inp.closest('.lpick'); const list = $('.lpick-list', box);
621
+ list.innerHTML = pickList(box.dataset.lpick, inp.value); list.classList.remove('hide');
622
+ $('.lpick-o', list)?.classList.add('lpick-cur');
623
+ }
624
+ function movePick(list, d) {
625
+ const os = [...list.querySelectorAll('.lpick-o')]; if (!os.length) return;
626
+ const i = os.findIndex((o) => o.classList.contains('lpick-cur'));
627
+ os.forEach((o) => o.classList.remove('lpick-cur'));
628
+ const n = os[(i + d + os.length) % os.length]; n.classList.add('lpick-cur'); n.scrollIntoView({ block: 'nearest' });
629
+ }
630
+ function pickComp(capId, bid) { links[bid] = [...links[bid], capId]; relink(); }
631
+ function onPickKey(e) {
632
+ const inp = e.target.closest?.('[data-lpick-q]'); if (!inp) return;
633
+ const box = inp.closest('.lpick'); const list = $('.lpick-list', box); const cur = $('.lpick-o.lpick-cur', list);
634
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); if (list.classList.contains('hide')) openPick(inp); else movePick(list, e.key === 'ArrowDown' ? 1 : -1); }
635
+ if (e.key === 'Enter') { e.preventDefault(); if (cur && !list.classList.contains('hide')) pickComp(box.dataset.lpick, cur.dataset.lpickId); }
636
+ if (e.key === 'Escape') { inp.value = ''; list.classList.add('hide'); }
637
+ }
638
+ const pickInput = (e) => e.target.closest?.('[data-lpick-q]');
639
+ document.addEventListener('focusin', (e) => { const q = pickInput(e); if (q) openPick(q); });
640
+ document.addEventListener('input', (e) => { const q = pickInput(e); if (q) openPick(q); });
641
+ document.addEventListener('focusout', (e) => { const q = pickInput(e); if (q) $('.lpick-list', q.closest('.lpick')).classList.add('hide'); });
642
+ document.addEventListener('keydown', onPickKey);
643
+ // mousedown would blur the box and close the list before the click lands
644
+ document.addEventListener('mousedown', (e) => { if (e.target.closest('.lpick-list')) e.preventDefault(); });
645
+ document.addEventListener('click', (e) => { const o = e.target.closest('.lpick-o'); if (o) pickComp(o.closest('.lpick').dataset.lpick, o.dataset.lpickId); });
646
+ // hovering a row moves the highlight, so mouse and keyboard never show two
647
+ document.addEventListener('mouseover', (e) => {
648
+ const o = e.target.closest?.('.lpick-o'); if (!o) return;
649
+ o.parentNode.querySelectorAll('.lpick-cur').forEach((x) => x.classList.remove('lpick-cur'));
650
+ o.classList.add('lpick-cur');
651
+ });
582
652
  // one row per component: its container, its name, and the other features it builds
583
653
  function compRow(bid, capId, cls = '') {
584
654
  const b = compById[bid]; const others = links[bid].filter((c) => c !== capId);
585
- const also = others.length ? `also builds ${others.map((c) => `<span class="cmini" style="--sc:var(--s${sysNo(c)})" data-cap-chip="${c}" title="${esc(capById[c].name)}">${c}</span>`).join('')}` : '<span class="dim">only this feature</span>';
655
+ const also = alsoHtml(others);
586
656
  const x = !FINAL && !cls.includes('removed') ? `<button type="button" data-unlink="${bid}:${capId}" title="This component does not build it">×</button>` : '';
587
657
  return `<div class="crow${cls}" data-comp-chip="${bid}"><span class="ccont">${esc(b.container)}</span><b class="cname">${esc(b.name)}</b><span class="calso">${also}</span>${FINAL ? `<span class="chrs">${hoursOf(bid)}h</span>` : ''}${x}</div>`;
588
658
  }
@@ -596,9 +666,7 @@ function paintBuilt(capId) {
596
666
  if (FINAL) { const h = by.reduce((n, b) => n + hoursOf(b), 0); $(`[data-hrs="${capId}"]`).textContent = `${h.toLocaleString('en-US')}h`;
597
667
  box.innerHTML = `<div class="bhead">${head}<span class="arch">${archLink(conts)}</span></div><div class="crows">${by.map((b) => compRow(b, capId)).join('')}</div>${by.map((b) => tasksHtml(compById[b])).join('')}`; return; }
598
668
  const rows = by.map((b) => compRow(b, capId, was.includes(b) ? '' : ' added')).join('') + was.filter((b) => !by.includes(b)).map((b) => compRow(b, capId, ' removed')).join('');
599
- const conts2 = [...new Set(COMPS.map((b) => b.container))];
600
- const pick = `<select data-link="${capId}" aria-label="Link a component"><option value="">+ Link a component</option>${conts2.map((g) => `<optgroup label="${esc(g)}">${COMPS.filter((b) => b.container === g && !by.includes(b.id)).map((b) =>
601
- `<option value="${b.id}">${esc(b.name)}${notAsked(b.id) ? ' · builds nothing yet' : ''}</option>`).join('')}</optgroup>`).join('')}</select>`;
669
+ const pick = pickerHtml(capId);
602
670
  const gap = by.length ? '' : asks[capId] !== undefined
603
671
  ? `<div class="ask"><b>Asked the agent to add a component</b> <button type="button" class="btn" data-unask="${capId}">undo</button><textarea data-ask="${capId}" rows="1" placeholder="What should it cover? e.g. parse emails/faxes into a draft order">${esc(asks[capId])}</textarea></div>`
604
672
  : `<div class="ask"><span class="gapnote">⚠ No component builds this, so nobody would build it.</span> <button type="button" class="btn" data-ask-btn="${capId}">Ask the agent to add one</button> <span class="dim">or link one</span></div>`;
@@ -783,10 +851,6 @@ $('#systems').addEventListener('toggle', (e) => {
783
851
  else if (openSys === d.dataset.sys) openSystem(null);
784
852
  refresh();
785
853
  }, true);
786
- document.addEventListener('change', (e) => {
787
- const capId = e.target.dataset.link;
788
- if (capId && e.target.value) { links[e.target.value] = [...links[e.target.value], capId]; relink(); }
789
- });
790
854
  document.addEventListener('input', (e) => {
791
855
  const n = e.target.dataset.note; if (n) { notes[n] = e.target.value; save(); }
792
856
  const a = e.target.dataset.ask; if (a) { asks[a] = e.target.value; save(); }
@@ -812,7 +876,7 @@ function highlight(refs, caps, comps) {
812
876
  }
813
877
  const clearHl = () => document.querySelectorAll('.hl, .cur').forEach((x) => x.classList.remove('hl', 'cur'));
814
878
  function hitAt(t) {
815
- if (t.closest('button:not(.dot), input, textarea, select, .factors, nav, .bar, dialog, details.tasks, a')) return null;
879
+ if (t.closest('button:not(.dot), input, textarea, select, .lpick, .factors, nav, .bar, dialog, details.tasks, a')) return null;
816
880
  const node = t.closest('.flow g.node');
817
881
  if (node) { const ref = JSON.parse(node.closest('.flow').dataset.map)[(node.id.match(/flowchart-(n\d+)-/) || [])[1]];
818
882
  return ref ? { hit: fromStep(ref), label: `Step “${stepName(ref)}”` } : null; }
@@ -308,6 +308,17 @@ textarea, input, select { font-size:.92rem; }
308
308
  @media (prefers-color-scheme:dark) { :root:not([data-theme="light"]) { color-scheme:dark; } }
309
309
  :root[data-theme="dark"] { color-scheme:dark; }
310
310
  select option, select optgroup { background:var(--sheet); color:var(--ink); }
311
+ .crow .calso:not(.open) .cmini.more { display:none; }
312
+ .alsomore { font:inherit; font-size:.74rem; color:var(--ink-dim); background:none; border:0; padding:0 .2rem; cursor:pointer; text-decoration:underline dotted; }
313
+ .alsomore:hover, .alsomore:focus-visible { color:var(--ink); }
314
+ .lpick { position:relative; width:100%; max-width:28rem; margin-top:.4rem; }
315
+ .lpick input { width:100%; box-sizing:border-box; font:inherit; font-size:.85rem; padding:.35rem .6rem; color:var(--ink); background:var(--sheet); border:1px dashed var(--ink-dim); border-radius:.3rem; }
316
+ .lpick input:focus { border-style:solid; border-color:var(--ink); outline:none; }
317
+ .lpick-list { position:absolute; z-index:20; left:0; right:0; top:calc(100% + .2rem); max-height:20rem; overflow:auto; background:var(--sheet); border:1px solid var(--grid); border-radius:.3rem; box-shadow:0 6px 18px rgba(0,0,0,.25); padding:.25rem 0; }
318
+ .lpick-g { font-size:.7rem; font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:var(--ink-dim); padding:.35rem .7rem .15rem; }
319
+ .lpick-o { font-size:.88rem; padding:.3rem .7rem .3rem 1.3rem; cursor:pointer; }
320
+ .lpick-o.lpick-cur { background:var(--hi); }
321
+ .lpick-none { padding:.4rem .7rem; font-size:.85rem; }
311
322
  </style>
312
323
  </head>
313
324
  <body>
@@ -497,10 +508,69 @@ const archLink = (containers) => {
497
508
  return [...c3.map((c) => `<a class="archlink" href="${ARCH}#panel-components-${PAGE.c3[c]}" target="_blank" rel="noopener">C3 ${esc(c)} ↗</a>`),
498
509
  c2 && `<a class="archlink" href="${ARCH}#panel-containers" target="_blank" rel="noopener">C2 containers ↗</a>`].filter(Boolean).join(' · ');
499
510
  };
511
+ // the other features a component builds: 3 or more fold to one chip and "…N more"
512
+ const ALSO_SHOWN = 1; const ALSO_FOLD = 3;
513
+ const alsoChip = (c, fold) => `<span class="cmini${fold ? ' more' : ''}" style="--sc:var(--s${sysNo(c)})" data-cap-chip="${c}" title="${esc(capById[c].name)}">${c}</span>`;
514
+ function alsoHtml(others) {
515
+ if (!others.length) return '<span class="dim">only this feature</span>';
516
+ const fold = others.length >= ALSO_FOLD;
517
+ const chips = others.map((c, i) => alsoChip(c, fold && i >= ALSO_SHOWN)).join('');
518
+ const more = fold ? `<button type="button" class="alsomore" data-also-more aria-expanded="false">…${others.length - ALSO_SHOWN} more</button>` : '';
519
+ return `also builds ${chips}${more}`;
520
+ }
521
+ function toggleAlso(b) {
522
+ const box = b.closest('.calso'); const open = box.classList.toggle('open');
523
+ b.setAttribute('aria-expanded', String(open));
524
+ b.textContent = open ? 'show less' : `…${box.querySelectorAll('.cmini.more').length} more`;
525
+ }
526
+ document.addEventListener('click', (e) => { const b = e.target.closest('[data-also-more]'); if (b) toggleAlso(b); });
527
+ // "+ Link a component": a wide search box; typing filters by component or container name
528
+ const pickerHtml = (capId) => `<div class="lpick" data-lpick="${capId}"><input type="search" data-lpick-q placeholder="+ Link a component… type to filter" aria-label="Link a component" autocomplete="off"><div class="lpick-list hide" role="listbox"></div></div>`;
529
+ const pickOpt = (b) => `<div class="lpick-o" role="option" data-lpick-id="${b.id}">${esc(b.name)}${notAsked(b.id) ? '<span class="dim"> · builds nothing yet</span>' : ''}</div>`;
530
+ function pickList(capId, q) {
531
+ const by = buildersOf(capId); const t = q.trim().toLowerCase();
532
+ const hit = (b) => !by.includes(b.id) && `${b.name} ${b.container}`.toLowerCase().includes(t);
533
+ const groups = [...new Set(COMPS.map((b) => b.container))].map((g) => [g, COMPS.filter((b) => b.container === g && hit(b))]).filter(([, bs]) => bs.length);
534
+ if (!groups.length) return '<div class="lpick-none dim">No component matches</div>';
535
+ return groups.map(([g, bs]) => `<div class="lpick-g">${esc(g)}</div>${bs.map(pickOpt).join('')}`).join('');
536
+ }
537
+ function openPick(inp) {
538
+ const box = inp.closest('.lpick'); const list = $('.lpick-list', box);
539
+ list.innerHTML = pickList(box.dataset.lpick, inp.value); list.classList.remove('hide');
540
+ $('.lpick-o', list)?.classList.add('lpick-cur');
541
+ }
542
+ function movePick(list, d) {
543
+ const os = [...list.querySelectorAll('.lpick-o')]; if (!os.length) return;
544
+ const i = os.findIndex((o) => o.classList.contains('lpick-cur'));
545
+ os.forEach((o) => o.classList.remove('lpick-cur'));
546
+ const n = os[(i + d + os.length) % os.length]; n.classList.add('lpick-cur'); n.scrollIntoView({ block: 'nearest' });
547
+ }
548
+ function pickComp(capId, bid) { links[bid] = [...links[bid], capId]; relink(); }
549
+ function onPickKey(e) {
550
+ const inp = e.target.closest?.('[data-lpick-q]'); if (!inp) return;
551
+ const box = inp.closest('.lpick'); const list = $('.lpick-list', box); const cur = $('.lpick-o.lpick-cur', list);
552
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); if (list.classList.contains('hide')) openPick(inp); else movePick(list, e.key === 'ArrowDown' ? 1 : -1); }
553
+ if (e.key === 'Enter') { e.preventDefault(); if (cur && !list.classList.contains('hide')) pickComp(box.dataset.lpick, cur.dataset.lpickId); }
554
+ if (e.key === 'Escape') { inp.value = ''; list.classList.add('hide'); }
555
+ }
556
+ const pickInput = (e) => e.target.closest?.('[data-lpick-q]');
557
+ document.addEventListener('focusin', (e) => { const q = pickInput(e); if (q) openPick(q); });
558
+ document.addEventListener('input', (e) => { const q = pickInput(e); if (q) openPick(q); });
559
+ document.addEventListener('focusout', (e) => { const q = pickInput(e); if (q) $('.lpick-list', q.closest('.lpick')).classList.add('hide'); });
560
+ document.addEventListener('keydown', onPickKey);
561
+ // mousedown would blur the box and close the list before the click lands
562
+ document.addEventListener('mousedown', (e) => { if (e.target.closest('.lpick-list')) e.preventDefault(); });
563
+ document.addEventListener('click', (e) => { const o = e.target.closest('.lpick-o'); if (o) pickComp(o.closest('.lpick').dataset.lpick, o.dataset.lpickId); });
564
+ // hovering a row moves the highlight, so mouse and keyboard never show two
565
+ document.addEventListener('mouseover', (e) => {
566
+ const o = e.target.closest?.('.lpick-o'); if (!o) return;
567
+ o.parentNode.querySelectorAll('.lpick-cur').forEach((x) => x.classList.remove('lpick-cur'));
568
+ o.classList.add('lpick-cur');
569
+ });
500
570
  // one row per component: its container, its name, and the other features it builds
501
571
  function compRow(bid, capId, cls = '') {
502
572
  const b = compById[bid]; const others = links[bid].filter((c) => c !== capId);
503
- const also = others.length ? `also builds ${others.map((c) => `<span class="cmini" style="--sc:var(--s${sysNo(c)})" data-cap-chip="${c}" title="${esc(capById[c].name)}">${c}</span>`).join('')}` : '<span class="dim">only this feature</span>';
573
+ const also = alsoHtml(others);
504
574
  const x = !FINAL && !cls.includes('removed') ? `<button type="button" data-unlink="${bid}:${capId}" title="This component does not build it">×</button>` : '';
505
575
  return `<div class="crow${cls}" data-comp-chip="${bid}"><span class="ccont">${esc(b.container)}</span><b class="cname">${esc(b.name)}</b><span class="calso">${also}</span>${FINAL ? `<span class="chrs">${hoursOf(bid)}h</span>` : ''}${x}</div>`;
506
576
  }
@@ -514,9 +584,7 @@ function paintBuilt(capId) {
514
584
  if (FINAL) { const h = by.reduce((n, b) => n + hoursOf(b), 0); $(`[data-hrs="${capId}"]`).textContent = `${h.toLocaleString('en-US')}h`;
515
585
  box.innerHTML = `<div class="bhead">${head}<span class="arch">${archLink(conts)}</span></div><div class="crows">${by.map((b) => compRow(b, capId)).join('')}</div>${by.map((b) => tasksHtml(compById[b])).join('')}`; return; }
516
586
  const rows = by.map((b) => compRow(b, capId, was.includes(b) ? '' : ' added')).join('') + was.filter((b) => !by.includes(b)).map((b) => compRow(b, capId, ' removed')).join('');
517
- const conts2 = [...new Set(COMPS.map((b) => b.container))];
518
- const pick = `<select data-link="${capId}" aria-label="Link a component"><option value="">+ Link a component</option>${conts2.map((g) => `<optgroup label="${esc(g)}">${COMPS.filter((b) => b.container === g && !by.includes(b.id)).map((b) =>
519
- `<option value="${b.id}">${esc(b.name)}${notAsked(b.id) ? ' · builds nothing yet' : ''}</option>`).join('')}</optgroup>`).join('')}</select>`;
587
+ const pick = pickerHtml(capId);
520
588
  const gap = by.length ? '' : asks[capId] !== undefined
521
589
  ? `<div class="ask"><b>Asked the agent to add a component</b> <button type="button" class="btn" data-unask="${capId}">undo</button><textarea data-ask="${capId}" rows="1" placeholder="What should it cover? e.g. parse emails/faxes into a draft order">${esc(asks[capId])}</textarea></div>`
522
590
  : `<div class="ask"><span class="gapnote">⚠ No component builds this, so nobody would build it.</span> <button type="button" class="btn" data-ask-btn="${capId}">Ask the agent to add one</button> <span class="dim">or link one</span></div>`;
@@ -701,10 +769,6 @@ $('#systems').addEventListener('toggle', (e) => {
701
769
  else if (openSys === d.dataset.sys) openSystem(null);
702
770
  refresh();
703
771
  }, true);
704
- document.addEventListener('change', (e) => {
705
- const capId = e.target.dataset.link;
706
- if (capId && e.target.value) { links[e.target.value] = [...links[e.target.value], capId]; relink(); }
707
- });
708
772
  document.addEventListener('input', (e) => {
709
773
  const n = e.target.dataset.note; if (n) { notes[n] = e.target.value; save(); }
710
774
  const a = e.target.dataset.ask; if (a) { asks[a] = e.target.value; save(); }
@@ -730,7 +794,7 @@ function highlight(refs, caps, comps) {
730
794
  }
731
795
  const clearHl = () => document.querySelectorAll('.hl, .cur').forEach((x) => x.classList.remove('hl', 'cur'));
732
796
  function hitAt(t) {
733
- if (t.closest('button:not(.dot), input, textarea, select, .factors, nav, .bar, dialog, details.tasks, a')) return null;
797
+ if (t.closest('button:not(.dot), input, textarea, select, .lpick, .factors, nav, .bar, dialog, details.tasks, a')) return null;
734
798
  const node = t.closest('.flow g.node');
735
799
  if (node) { const ref = JSON.parse(node.closest('.flow').dataset.map)[(node.id.match(/flowchart-(n\d+)-/) || [])[1]];
736
800
  return ref ? { hit: fromStep(ref), label: `Step “${stepName(ref)}”` } : null; }
@@ -46,6 +46,19 @@ rep(/function price\(s\) \{\n[\s\S]*?\n\}\n/, 'const price = (s) => featurePrice
46
46
  rep(/\/\/ the architecture document holds the C4 views[^\n]*\n\/\/ \(C3 is the Backend API[^\n]*\nconst ARCH = 'architecture\.html';\nconst archLink = [\s\S]*?\.join\(' · '\); \};\n/,
47
47
  readFileSync(at('./template/arch-link.js'), 'utf8'));
48
48
 
49
+ // ---- "also builds": 3 or more other features fold to one chip and "…N more" ----
50
+ rep(/ const also = others\.length \? `also builds [^\n]*\n/, ' const also = alsoHtml(others);\n');
51
+ rep('// one row per component: its container', `${readFileSync(at('./template/also-builds.js'), 'utf8')}// one row per component: its container`);
52
+
53
+ // ---- "+ Link a component": a search box that filters as you type, not a <select> ----
54
+ rep(/ const pick = `<select data-link=[\s\S]*?<\/select>`;\n/, ' const pick = pickerHtml(capId);\n');
55
+ rep('// one row per component: its container', `${readFileSync(at('./template/link-picker.js'), 'utf8')}// one row per component: its container`);
56
+ // the Task 2 select is gone: its unused container list and change listener go too
57
+ rep(" const conts2 = [...new Set(COMPS.map((b) => b.container))];\n", '');
58
+ rep(/document\.addEventListener\('change', \(e\) => \{\n const capId = e\.target\.dataset\.link;[\s\S]*?\n\}\);\n/, '');
59
+ // a click inside the picker is a pick, not a pin
60
+ rep("t.closest('button:not(.dot), input, textarea, select, ", "t.closest('button:not(.dot), input, textarea, select, .lpick, ");
61
+
49
62
  // ---- the 22-line function gate (quality-gates.test.mjs) ----
50
63
  // An apostrophe inside a template literal reads as a string quote to the gate.
51
64
  rep("data-tip=\"Each feature's scores", 'data-tip="Each feature&#39;s scores');
@@ -56,5 +69,5 @@ rep(" const count = { edits: CAPS.filter((c) => isChanged(c.id)).length,", " r
56
69
  rep('diagrams need a connection in this mockup', 'diagrams need a connection');
57
70
 
58
71
  const head = base.slice(0, base.indexOf('</style>')).replace('<title>Sin Kowa — score review</title>', '<title><!-- slot:TITLE --> — score review</title>');
59
- writeFileSync(OUT, `${head}${css}${readFileSync(`${M}reading.css`, 'utf8')}</style>\n</head>\n<body>\n${body}`);
72
+ writeFileSync(OUT, `${head}${css}${readFileSync(`${M}reading.css`, 'utf8')}${readFileSync(at('./template/also-builds.css'), 'utf8')}${readFileSync(at('./template/link-picker.css'), 'utf8')}</style>\n</head>\n<body>\n${body}`);
60
73
  console.log(OUT);
@@ -0,0 +1,3 @@
1
+ .crow .calso:not(.open) .cmini.more { display:none; }
2
+ .alsomore { font:inherit; font-size:.74rem; color:var(--ink-dim); background:none; border:0; padding:0 .2rem; cursor:pointer; text-decoration:underline dotted; }
3
+ .alsomore:hover, .alsomore:focus-visible { color:var(--ink); }