@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
@@ -11,16 +11,28 @@ import { dirname, resolve } from 'node:path';
11
11
  const HREF = /<a href="([^"#]*)(#[^"]*)?">([\s\S]*?)<\/a>/g;
12
12
  const ABSOLUTE = /^([a-z][a-z0-9+.-]*:|\/\/)/i;
13
13
 
14
+ // idByPath maps a document's absolute path to its id, and `<path>#<slug>` to the
15
+ // id that heading carries (prefixed by its document, D18). Authors write a
16
+ // fragment against the target's own headings (#q3) — or, with no path, against
17
+ // their own — so the fragment is looked up, never trusted.
14
18
  export function rewriteDocLinks(html, fromPath, idByPath) {
15
19
  const dir = dirname(fromPath);
16
20
  return html.replace(HREF, (whole, path, fragment, label) => {
17
- // No path means an in-page anchor; a scheme or // means it leaves the page.
18
- if (!path || ABSOLUTE.test(path)) return whole;
19
- // The fragment is dropped rather than resolved: heading slugs are deduped
20
- // across the whole set, so #context inside one ADR may have been minted as
21
- // context-7. The document anchor is the target we can honestly name.
22
- const id = idByPath.get(resolve(dir, path));
23
- if (id) return `<a href="#${id}">${label}</a>`;
21
+ // A scheme or // means it leaves the page.
22
+ if (ABSOLUTE.test(path)) return whole;
23
+ // No path: a heading in this same document; anything else keeps its id.
24
+ if (!path) return linkTo(idByPath.get(fromPath + fragment), label) ?? whole;
25
+ const target = resolve(dir, path);
26
+ const id = idByPath.get(target);
27
+ if (id) return linkTo(idByPath.get(target + (fragment ?? '')) || id, label);
24
28
  return `<span class="ext-ref" title="${path}${fragment ?? ''}">${label}</span>`;
25
29
  });
26
30
  }
31
+
32
+ function linkTo(id, label) {
33
+ return id ? `<a href="#${id}">${label}</a>` : null;
34
+ }
35
+
36
+ export function anchorIds({ path, headings }) {
37
+ return headings.map((h) => [`${path}#${h.local}`, h.slug]);
38
+ }
@@ -7,7 +7,7 @@ import { nextSlug } from './slug-registry.mjs';
7
7
  // reworded, a filename is the thing every other document already links to.
8
8
  // A section's index page takes the section slug instead, so #/decision-records
9
9
  // lands on the list rather than on a file called index.
10
- function fileSlug(path) {
10
+ export function fileSlug(path) {
11
11
  return slugOf(basename(path ?? '', extname(path ?? '')));
12
12
  }
13
13
 
@@ -1,26 +1,55 @@
1
1
  import { readFile } from 'node:fs/promises';
2
- import { relative } from 'node:path';
2
+ import { dirname, join, relative } from 'node:path';
3
3
  import { parseFrontmatter } from './frontmatter.mjs';
4
4
  import { parseTables } from './md-tables.mjs';
5
5
  import { extractLinks } from './md-links.mjs';
6
6
  import { erEntities } from './er-entities.mjs';
7
7
  import { extractModel } from './likec4-extract.mjs';
8
8
  import { nextSlug } from './slug-registry.mjs';
9
+ import { parseCitations } from './validate-quotes.mjs';
10
+ import { isPackage, baRows, statedText } from './ba-package.mjs';
9
11
 
10
- export async function buildInputs({ root, archPath, modelPath, docPaths = [] }) {
12
+ export async function buildInputs({ root, archPath, modelPath, docPaths = [], inputPaths = [] }) {
11
13
  const arch = await readFile(archPath, 'utf8');
12
14
  const docs = await readDocs(root, [archPath, ...docPaths]);
15
+ const sources = await readDocs(root, inputPaths);
16
+ const packages = packagesOf(sources);
13
17
  return {
18
+ archMd: arch,
14
19
  frontmatter: parseFrontmatter(arch).data ?? {},
15
20
  tables: parseTables(arch),
16
21
  erNames: erEntities(arch),
17
22
  model: extractModel(JSON.parse(await readFile(modelPath, 'utf8'))),
18
23
  links: docs.flatMap((d) => extractLinks(d.md).map((l) => ({ fromDoc: d.path, href: l.href }))),
19
- files: docs.map((d) => d.path),
24
+ files: [...docs, ...sources].map((d) => d.path),
20
25
  anchors: Object.fromEntries(docs.map((d) => [d.path, headingSlugs(d.md)])),
26
+ sources: new Map(sources.map((d) => [d.path, packages.has(d.path)
27
+ ? statedText(packages.get(d.path)) : d.md])),
28
+ packages,
29
+ citations: citationsOf(root, archPath, arch),
21
30
  };
22
31
  }
23
32
 
33
+ // Citations are written relative to ARCHITECTURE.md; sources are keyed
34
+ // relative to the root. Same frame as validate-links, or a nested set fails.
35
+ function citationsOf(root, archPath, md) {
36
+ return parseCitations(md).map((c) => ({ ...c, path: relative(root, join(dirname(archPath), c.path)) }));
37
+ }
38
+
39
+ // A requirements.json is cited by row id (ba-package.mjs). Its row texts stand
40
+ // in for its source text, so a quote or Brief says from a row still matches.
41
+ // A .json that is not a BA package stays plain text.
42
+ function packagesOf(docs) {
43
+ return new Map(docs.filter((d) => d.path.endsWith('.json'))
44
+ .map((d) => [d.path, parseJson(d.md)])
45
+ .filter(([, pkg]) => isPackage(pkg))
46
+ .map(([path, pkg]) => [path, baRows(pkg)]));
47
+ }
48
+
49
+ function parseJson(text) {
50
+ try { return JSON.parse(text); } catch { return null; }
51
+ }
52
+
24
53
  async function readDocs(root, paths) {
25
54
  return Promise.all(paths.map(async (p) => ({
26
55
  path: relative(root, p),
@@ -28,14 +57,16 @@ async function readDocs(root, paths) {
28
57
  })));
29
58
  }
30
59
 
31
- // Mirrors md-render.mjs exactly: only h2/h3 get an id in the viewer, deduped
32
- // with a shared -N suffix rule (see slug-registry.mjs). Dedupe scope is per doc
33
- // here, matching how this function is called once per doc; the renderer's
34
- // cross-doc dedupe is a viewer-side concern (D6, out of scope).
60
+ // Mirrors md-render.mjs: frontmatter stripped, fenced code skipped, only h2/h3,
61
+ // deduped per document with the shared -N rule (slug-registry.mjs). These are
62
+ // the `local` slugs the renderer keys its anchors on (doc-links.mjs anchorIds).
35
63
  function headingSlugs(md) {
36
64
  const registry = new Map();
37
- return md.split('\n')
38
- .map((l) => l.match(/^(#{2,3})\s+(.*)$/))
39
- .filter(Boolean)
40
- .map((m) => nextSlug(m[2].trim(), registry));
65
+ let fenced = false;
66
+ return md.replace(/^---\n[\s\S]*?\n---\n?/, '').split('\n').flatMap((l) => {
67
+ // Opens on any ``` line, closes only on a bare one — as md-render does.
68
+ if (fenced ? l.trim() === '```' : l.trim().startsWith('```')) fenced = !fenced;
69
+ const m = !fenced && l.match(/^(#{2,3})\s+(.*)$/);
70
+ return m ? [nextSlug(m[2].trim(), registry)] : [];
71
+ });
41
72
  }
@@ -9,10 +9,14 @@ import { readFlowGroup } from './md-flows.mjs';
9
9
 
10
10
  export { escapeHtml };
11
11
 
12
- export function renderMarkdown(md, slugs = new Map(), docSlugs = new Map()) {
12
+ // `slugs` dedupes h2/h3 within one document; `prefix` names that document, so an
13
+ // id is unique across the whole set by construction (0007-cache__context). The
14
+ // separator is `__` because slugify never emits `_`, so a prefixed id cannot
15
+ // collide with a bare one.
16
+ export function renderMarkdown(md, { slugs = new Map(), docSlugs = new Map(), prefix = '' } = {}) {
13
17
  const ctx = {
14
18
  lines: md.replace(/^---\n[\s\S]*?\n---\n?/, '').split('\n'),
15
- i: 0, html: [], headings: [], slugs, docSlugs, title: null, docId: null,
19
+ i: 0, html: [], headings: [], slugs, docSlugs, prefix, title: null, docId: null,
16
20
  };
17
21
  while (ctx.i < ctx.lines.length) dispatch(ctx);
18
22
  return {
@@ -56,9 +60,16 @@ function renderHeading(ctx) {
56
60
  ctx.html.push(`<h${level}>${inline(text)}</h${level}>`);
57
61
  return;
58
62
  }
59
- const slug = nextSlug(text, ctx.slugs);
63
+ const { slug, local } = headingId(ctx, text);
60
64
  ctx.html.push(`<h${level} id="${slug}">${inline(text)}</h${level}>`);
61
- ctx.headings.push({ level, text, slug });
65
+ ctx.headings.push({ level, text, slug, local });
66
+ }
67
+
68
+ // `local` is what an author writes after `#` inside the document and what the
69
+ // link validator knows; `slug` is the id the page carries.
70
+ function headingId(ctx, text) {
71
+ const local = nextSlug(text, ctx.slugs);
72
+ return { local, slug: ctx.prefix ? `${ctx.prefix}__${local}` : local };
62
73
  }
63
74
 
64
75
  function renderFence(ctx) {
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
2
2
 
3
3
  // The lookup keys on heading text rather than on a slug for two reasons: slugify
4
4
  // keeps both spaces around a stripped "&", so "Goals & Scope" becomes
5
- // goals--scope; and h2/h3 ids share one dedupe registry, so an h3 named Security
5
+ // goals--scope; and h2/h3 ids in one document share a dedupe registry, so an h3 named Security
6
6
  // under Crosscutting Concepts would take `security` and demote §12's h2 to
7
7
  // security-2.
8
8
  //
@@ -0,0 +1,30 @@
1
+ import { parseTables } from './md-tables.mjs';
2
+
3
+ // `^## ` never matches `### `, so a subheading stays inside its section.
4
+ export function sectionBody(md, title) {
5
+ const chunk = md.split(/^## /m).find((c) => title.test(c.split('\n')[0]));
6
+ return chunk ? chunk.slice(chunk.indexOf('\n') + 1) : '';
7
+ }
8
+
9
+ // Tables anywhere in the `## ` section, subheadings included. The table
10
+ // holding `column` wins; otherwise the first table, so a legacy shape is
11
+ // still seen.
12
+ export function sectionTable(md, title, column) {
13
+ const tables = parseTables(sectionBody(md, title));
14
+ const has = (t) => t.headers.some((h) => column.test(h));
15
+ return tables.find(has) ?? tables[0];
16
+ }
17
+
18
+ const GIVES_WAY = /\(gives way first\)/i;
19
+ const NOT_PROVIDED = /^Not provided/i;
20
+
21
+ // Cells compare without markdown emphasis, so **Speed** matches Speed.
22
+ const plain = (cell) => cell.replace(/[*_]/g, '');
23
+ export const isGivesWay = (cell) => GIVES_WAY.test(plain(cell));
24
+ export const isNotProvided = (cell) => NOT_PROVIDED.test(plain(cell));
25
+ export const nameOf = (cell) => plain(cell).replace(GIVES_WAY, '').trim().toLowerCase();
26
+
27
+ export function goalCells(t) {
28
+ const col = (t?.headers ?? []).findIndex((h) => /^goal$/i.test(h));
29
+ return col === -1 ? null : t.rows.map((r) => r[col] ?? '');
30
+ }
@@ -1,5 +1,6 @@
1
1
  const ALLOWED = ['observed', 'stated', 'researched', 'proposed'];
2
2
  const EXEMPT = ['Decisions', 'Glossary'];
3
+ const CITED = /\[[^\]]+\]\([^)\s]+\)/;
3
4
 
4
5
  export function validateProvenance({ tables }) {
5
6
  const findings = [];
@@ -15,6 +16,17 @@ function checkTable(t) {
15
16
  if (col === -1) {
16
17
  return [{ check: 'provenance', message: `table in "${t.section}" has no src column` }];
17
18
  }
18
- return t.rows.filter((r) => !ALLOWED.some((a) => (r[col] ?? '').startsWith(a)))
19
- .map((r) => ({ check: 'provenance', message: `"${t.section}" row "${r[0]}": bad src "${r[col]}"` }));
19
+ return t.rows.flatMap((r) => checkCell(t.section, r[0], r[col] ?? ''));
20
+ }
21
+
22
+ // Bare `stated` only warns: every set written before citations existed has it
23
+ // in every table, and failing them all would block every re-render at once.
24
+ function checkCell(section, name, cell) {
25
+ if (!ALLOWED.some((a) => cell.startsWith(a))) {
26
+ return [{ check: 'provenance', message: `"${section}" row "${name}": bad src "${cell}"` }];
27
+ }
28
+ if (cell.startsWith('stated') && !CITED.test(cell)) {
29
+ return [{ check: 'provenance', message: `"${section}" row "${name}": stated has no citation`, level: 'warn' }];
30
+ }
31
+ return [];
20
32
  }
@@ -0,0 +1,55 @@
1
+ // A `stated` fact that quotes a source must quote it word for word: a model
2
+ // that paraphrases and still says "the client said" is what citations exist
3
+ // to catch. Matching text is free and deterministic, so no agent checks it.
4
+ // Exact apart from whitespace and curly quotes — transcripts wrap lines and
5
+ // Word exports curl apostrophes; neither changes what was said.
6
+ const CITATION = /stated \[([^\]]+)\]\(([^)\s#]+)(?:#[^)\s]*)?\)(?: "([^"]+)")?/g;
7
+ const EMPTY = /^(—|-|Not provided.*)?$/;
8
+
9
+ export function normalize(text) {
10
+ return text.replace(/[“”]/g, '"').replace(/[‘’]/g, "'")
11
+ .replace(/\s+/g, ' ').trim();
12
+ }
13
+
14
+ export function parseCitations(md) {
15
+ return [...md.matchAll(CITATION)].map((m) => ({ label: m[1], path: m[2], quote: m[3] ?? null }));
16
+ }
17
+
18
+ export function closestSentence(text, quote) {
19
+ const words = new Set(normalize(quote).toLowerCase().split(' '));
20
+ const score = (s) => s.toLowerCase().split(' ').filter((w) => words.has(w)).length;
21
+ const sentences = normalize(text).split(/(?<=[.!?])\s+/);
22
+ return sentences.reduce((best, s) => (score(s) > score(best) ? s : best), sentences[0] ?? '');
23
+ }
24
+
25
+ export function briefQuotesOf(tables) {
26
+ const t = tables.find((x) => /Quality Requirements/i.test(x.section));
27
+ const col = (t?.headers ?? []).findIndex((h) => /^brief says$/i.test(h));
28
+ if (col === -1) return [];
29
+ return t.rows.map((r) => (r[col] ?? '').trim().replace(/^["“]|["”]$/g, ''))
30
+ .filter((q) => !EMPTY.test(q));
31
+ }
32
+
33
+ // sources maps root-relative path → text. A citation to a file not in the map
34
+ // is left to the links check, which already fails a missing target.
35
+ export function validateQuotes({ citations, briefQuotes, sources }) {
36
+ return [...citationFindings(citations, sources), ...briefFindings(briefQuotes, sources)];
37
+ }
38
+
39
+ function citationFindings(citations, sources) {
40
+ return citations.filter((c) => c.quote && sources.has(c.path))
41
+ .filter((c) => !normalize(sources.get(c.path)).includes(normalize(c.quote)))
42
+ .map((c) => ({
43
+ check: 'quotes',
44
+ message: `"${c.quote}" not found in ${c.path}; closest: "${closestSentence(sources.get(c.path), c.quote)}"`,
45
+ }));
46
+ }
47
+
48
+ // A Brief says quote names no file, so any input may hold it. With no inputs
49
+ // at all (the brief arrived in chat) there is nothing to check it against.
50
+ function briefFindings(quotes, sources) {
51
+ if (!sources.size) return [];
52
+ const all = [...sources.values()].map(normalize);
53
+ return quotes.filter((q) => !all.some((t) => t.includes(normalize(q))))
54
+ .map((q) => ({ check: 'quotes', message: `Brief says "${q}" is in no input file` }));
55
+ }
@@ -0,0 +1,65 @@
1
+ // Ties §4 Solution Strategy to §13's top-3 quality goals: every decision names
2
+ // a goal it serves, every goal is served by some decision. A set written before
3
+ // top-3 goals existed (§13 with no Goal column, §4 as bullets) warns instead of
4
+ // failing, so a rewrite the user declined never blocks the viewer.
5
+ import {
6
+ sectionBody, sectionTable, goalCells, isGivesWay, isNotProvided, nameOf,
7
+ } from './strategy-sections.mjs';
8
+
9
+ const fail = (message) => ({ check: 'strategy', message });
10
+
11
+ // `tables` is ignored: tables are read from archMd so a table under a ###
12
+ // subheading of §4 or §13 is found.
13
+ export function validateStrategy({ archMd }) {
14
+ const goals = sectionTable(archMd, /Quality Requirements/i, /^goal$/i);
15
+ const strategy = sectionTable(archMd, /Solution Strategy/i, /^serves$/i);
16
+ const cells = goalCells(goals);
17
+ const real = (cells ?? []).filter((c) => !isNotProvided(c));
18
+ return [
19
+ ...checkGoals(goals, cells),
20
+ ...checkStrategyShape(strategy, sectionBody(archMd, /Solution Strategy/i)),
21
+ ...(real.length && strategy ? checkServes(real, strategy) : []),
22
+ ];
23
+ }
24
+
25
+ function checkGoals(t, cells) {
26
+ if (!t) return [];
27
+ if (!cells) return [{ ...fail('§13 predates top-3 goals (no Goal column); rewrite as Goal · Target · Brief says · src'), level: 'warn' }];
28
+ const out = cells.length === 3 ? [] : [fail(`§13 has ${cells.length} goal rows, expected 3`)];
29
+ const marked = cells.filter(isGivesWay).length;
30
+ const needOne = cells.filter((c) => !isNotProvided(c)).length >= 2;
31
+ if (needOne ? marked !== 1 : marked > 1) {
32
+ out.push(fail(`§13 marks ${marked} goals "(gives way first)", expected ${needOne ? 'exactly 1' : 'at most 1'}`));
33
+ }
34
+ return out;
35
+ }
36
+
37
+ function checkStrategyShape(strategy, body) {
38
+ if (strategy || !/^\s*[-*] /m.test(body)) return [];
39
+ return [{ ...fail('§4 is a list; rewrite as a Decision · Serves · ADR · src table'), level: 'warn' }];
40
+ }
41
+
42
+ function checkServes(real, strategy) {
43
+ const col = strategy.headers.findIndex((h) => /^serves$/i.test(h));
44
+ if (col === -1) return [fail('§4 table has no Serves column')];
45
+ const goals = real.map(nameOf);
46
+ const rows = strategy.rows.map((r) => ({
47
+ decision: r[0],
48
+ serves: (r[col] ?? '').split(',').map(nameOf).filter(Boolean),
49
+ }));
50
+ return [...rowFindings(rows, goals), ...unservedFindings(rows, goals)];
51
+ }
52
+
53
+ function rowFindings(rows, goals) {
54
+ return rows.flatMap(({ decision, serves }) => {
55
+ if (!serves.length) return [fail(`§4 "${decision}" serves no goal`)];
56
+ return serves.filter((s) => !goals.includes(s))
57
+ .map((s) => fail(`§4 "${decision}" serves "${s}", not a §13 goal`));
58
+ });
59
+ }
60
+
61
+ function unservedFindings(rows, goals) {
62
+ const served = new Set(rows.flatMap((r) => r.serves));
63
+ return goals.filter((g) => !served.has(g))
64
+ .map((g) => fail(`§13 goal "${g}" is served by no §4 decision`));
65
+ }
@@ -2,9 +2,10 @@ import { readFileSync, mkdirSync, writeFileSync } from 'node:fs';
2
2
  import { basename, dirname, join, resolve } from 'node:path';
3
3
  import { renderMarkdown } from './lib/md-render.mjs';
4
4
  import { buildNav } from './lib/nav.mjs';
5
- import { rewriteDocLinks } from './lib/doc-links.mjs';
5
+ import { rewriteDocLinks, anchorIds } from './lib/doc-links.mjs';
6
6
  import { buildDoc } from './lib/doc-sections.mjs';
7
- import { routeMap } from './lib/doc-routes.mjs';
7
+ import { routeMap, fileSlug } from './lib/doc-routes.mjs';
8
+ import { nextSlug } from './lib/slug-registry.mjs';
8
9
  import { parseFrontmatter } from './lib/frontmatter.mjs';
9
10
  import { embed } from './lib/embed.mjs';
10
11
  import { kindOf } from './lib/doc-kinds.mjs';
@@ -70,10 +71,22 @@ function drawerOf(path, index) {
70
71
  const args = parseArgs(process.argv.slice(2));
71
72
  const archMd = readFileSync(args.arch, 'utf8');
72
73
  const docPaths = [args.arch, ...args.docs];
73
- const slugs = new Map();
74
+ const prefixes = new Map();
75
+ // The spine keeps bare ids: it is the document every other one links into, and
76
+ // its rail, section help and tests name `core-components`, not a prefixed id.
77
+ // A prefix is never reused or empty: `notes-2.md` beside two `notes.md` would
78
+ // otherwise repeat one, and a non-ASCII filename would collide with the spine.
79
+ const usedPrefixes = new Set();
80
+ function headingPrefix(path, index) {
81
+ if (index === 0) return '';
82
+ let prefix;
83
+ do prefix = nextSlug(fileSlug(path) || 'doc', prefixes); while (usedPrefixes.has(prefix));
84
+ usedPrefixes.add(prefix);
85
+ return prefix;
86
+ }
74
87
  const docSlugs = new Map();
75
88
  const pages = docPaths.map((p, i) => ({
76
- ...renderMarkdown(readFileSync(p, 'utf8'), slugs, docSlugs),
89
+ ...renderMarkdown(readFileSync(p, 'utf8'), { slugs: new Map(), docSlugs, prefix: headingPrefix(p, i) }),
77
90
  section: sectionOf(p, i, args.root),
78
91
  path: resolve(p),
79
92
  spine: i === 0,
@@ -83,7 +96,7 @@ const pages = docPaths.map((p, i) => ({
83
96
 
84
97
  // Second pass, because a link's target id is only known once every document has
85
98
  // been rendered: the id comes from the target's H1, not from its filename.
86
- const idByPath = new Map(pages.map((p) => [p.path, p.docId]));
99
+ const idByPath = new Map([...pages.map((p) => [p.path, p.docId]), ...pages.flatMap((p) => anchorIds(p))]);
87
100
  const linked = pages.map((p) => ({
88
101
  ...p,
89
102
  html: estimateLink(p, args.out) + rewriteDocLinks(p.html, p.path, idByPath),
@@ -0,0 +1,55 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { mkdtempSync, readFileSync, 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/ba-facts.mjs';
9
+ const PKG = {
10
+ schemaVersion: '1.0', updated: '2026-10-01',
11
+ requirements: [
12
+ { id: 'FR-001', text: 'Members book up to 4 courts per week.', label: 'confirmed', source: 'kickoff call 2026-09-20' },
13
+ { id: 'FR-002', text: 'Members pay a deposit online.', label: 'recommended' },
14
+ ],
15
+ };
16
+
17
+ function run(content) {
18
+ const dir = mkdtempSync(join(tmpdir(), 'ba-facts-'));
19
+ writeFileSync(join(dir, 'requirements.json'), content);
20
+ const out = join(dir, 'ba.json');
21
+ const r = spawnSync('node', [CLI, '--json', join(dir, 'requirements.json'), '--out', out], { encoding: 'utf8' });
22
+ return { r, out, dir };
23
+ }
24
+
25
+ test('splits confirmed facts from proposed rows', () => {
26
+ const { r, out, dir } = run(JSON.stringify(PKG));
27
+ assert.equal(r.status, 0, r.stdout);
28
+ assert.match(r.stdout, /^ok 1 confirmed facts, 1 not confirmed/m);
29
+ const { facts, proposed } = JSON.parse(readFileSync(out, 'utf8'));
30
+ assert.deepEqual(facts.map((f) => [f.id, f.cite, f.path]), [
31
+ ['FR-001', 'FR-001 · kickoff call 2026-09-20', join(dir, 'requirements.json')],
32
+ ]);
33
+ assert.deepEqual(proposed.map((f) => [f.id, f.label]), [['FR-002', 'recommended']]);
34
+ });
35
+
36
+ test('a file that is not a package fails', () => {
37
+ const { r } = run('{"port": 8080}');
38
+ assert.equal(r.status, 1);
39
+ assert.match(r.stdout, /^FAIL .* is not a requirements package/m);
40
+ });
41
+
42
+ test('invalid JSON fails the same way', () => {
43
+ const { r } = run('{"port": ');
44
+ assert.equal(r.status, 1);
45
+ assert.match(r.stdout, /is not a requirements package/);
46
+ });
47
+
48
+ test('a missing --json or --out prints usage and exits 1', () => {
49
+ const usage = 'FAIL usage: ba-facts.mjs --json <requirements.json> --out <file>';
50
+ for (const args of [[], ['--json', 'x.json'], ['--out', 'o.json']]) {
51
+ const r = spawnSync('node', [CLI, ...args], { encoding: 'utf8' });
52
+ assert.equal(r.status, 1);
53
+ assert.equal(r.stdout.trim(), usage);
54
+ }
55
+ });
@@ -0,0 +1,101 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { mkdirSync, 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 PKG = {
11
+ schemaVersion: '1.0', updated: '2026-10-01',
12
+ requirements: [{ id: 'FR-001', text: 'Members book up to 4 courts per week.', label: 'confirmed', source: 'kickoff call 2026-09-20' }],
13
+ nfrs: [{ id: 'NFR-001', area: 'availability', text: 'The booking page is up 99.95% of the time.', label: 'assumed' }],
14
+ };
15
+
16
+ function setUp(archRel, body, input = JSON.stringify(PKG)) {
17
+ const dir = mkdtempSync(join(tmpdir(), 'ba-cli-'));
18
+ mkdirSync(join(dir, 'docs'));
19
+ writeFileSync(join(dir, 'requirements.json'), input);
20
+ writeFileSync(join(dir, archRel), FRONT + body);
21
+ writeFileSync(join(dir, 'model.json'), JSON.stringify({ elements: {} }));
22
+ return dir;
23
+ }
24
+
25
+ const row = (cell) => `## 2 Constraints\n\n| Constraint | src |\n| --- | --- |\n| Courts | ${cell} |\n`;
26
+ const run = (dir, archRel) => spawnSync('node', [CLI, '--root', dir,
27
+ '--arch', join(dir, archRel), '--model', join(dir, 'model.json'),
28
+ '--inputs', join(dir, 'requirements.json')], { encoding: 'utf8' });
29
+
30
+ test('a citation to a confirmed row passes', () => {
31
+ const dir = setUp('ARCHITECTURE.md', row('stated [FR-001 · kickoff call 2026-09-20](requirements.json)'));
32
+ const r = run(dir, 'ARCHITECTURE.md');
33
+ assert.equal(r.status, 0, r.stdout);
34
+ });
35
+
36
+ test('a citation to an assumed row fails with its label', () => {
37
+ const dir = setUp('ARCHITECTURE.md', row('stated [NFR-001 · 2026-10-01](requirements.json)'));
38
+ const r = run(dir, 'ARCHITECTURE.md');
39
+ assert.equal(r.status, 1);
40
+ assert.match(r.stdout, /^FAIL \[quotes\] NFR-001 is assumed in requirements.json/m);
41
+ });
42
+
43
+ test('a reworded quote on a json citation fails once', () => {
44
+ const dir = setUp('ARCHITECTURE.md', row('stated [FR-001 · kickoff call 2026-09-20](requirements.json) "up to five courts"'));
45
+ const r = run(dir, 'ARCHITECTURE.md');
46
+ assert.equal(r.status, 1);
47
+ assert.equal(r.stdout.match(/^FAIL /gm).length, 1, r.stdout);
48
+ });
49
+
50
+ const Q = '"The page must show "open" 99.95% of the time."';
51
+ const q13 = (quote) => `## 13 Quality Requirements\n\n| Goal | Target | Brief says | src |\n| --- | --- | --- | --- |\n| Uptime | 99.95% | ${quote} | proposed |\n`;
52
+ const nfr = (label) => ({ ...PKG, nfrs: [{ ...PKG.nfrs[0], text: 'The page must show "open" 99.95% of the time.', label, source: 'kickoff call 2026-09-20' }] });
53
+
54
+ test('a Brief says quote from a confirmed row passes, even with a JSON-escaped quote', () => {
55
+ const dir = setUp('ARCHITECTURE.md', q13(Q), JSON.stringify(nfr('confirmed')));
56
+ assert.doesNotMatch(run(dir, 'ARCHITECTURE.md').stdout, /Brief says/);
57
+ });
58
+
59
+ test('a Brief says quote from an assumed row fails', () => {
60
+ const dir = setUp('ARCHITECTURE.md', q13(Q), JSON.stringify(nfr('assumed')));
61
+ assert.match(run(dir, 'ARCHITECTURE.md').stdout, /Brief says .* is in no input file/);
62
+ });
63
+
64
+ test('an inline quote on a confirmed citation cannot borrow a recommended row', () => {
65
+ const pkg = { ...PKG, requirements: [...PKG.requirements, { id: 'FR-003', text: 'Members pay a deposit', label: 'recommended' }] };
66
+ const dir = setUp('ARCHITECTURE.md', row('stated [FR-001 · kickoff call 2026-09-20](requirements.json) "Members pay a deposit"'), JSON.stringify(pkg));
67
+ const r = run(dir, 'ARCHITECTURE.md');
68
+ assert.equal(r.status, 1);
69
+ assert.match(r.stdout, /^FAIL \[quotes\]/m);
70
+ });
71
+
72
+ test('a citation label that is not the row cite fails', () => {
73
+ const dir = setUp('ARCHITECTURE.md', row('stated [FR-001 · made-up source](requirements.json)'));
74
+ assert.match(run(dir, 'ARCHITECTURE.md').stdout, /does not match requirements.json; cite it as FR-001 · kickoff call 2026-09-20/);
75
+ });
76
+
77
+ test('citation paths resolve from a nested ARCHITECTURE.md', () => {
78
+ const dir = setUp('docs/ARCHITECTURE.md', row('stated [NFR-001 · 2026-10-01](../requirements.json)'));
79
+ const r = run(dir, 'docs/ARCHITECTURE.md');
80
+ assert.match(r.stdout, /NFR-001 is assumed/);
81
+ });
82
+
83
+ test('a json input that is not a package is plain text, not a crash', () => {
84
+ const dir = setUp('ARCHITECTURE.md', row('stated [C9 · 2026-10-01](requirements.json) "port"'), '{"port": 8080');
85
+ const r = run(dir, 'ARCHITECTURE.md');
86
+ assert.equal(r.status, 0, r.stdout + r.stderr);
87
+ });
88
+
89
+ test('valid json that is not a package is plain text, not a crash', () => {
90
+ const dir = setUp('ARCHITECTURE.md', row('stated [C9 · 2026-10-01](requirements.json) "port"'), '{"port": 8080}');
91
+ const r = run(dir, 'ARCHITECTURE.md');
92
+ assert.equal(r.status, 0, r.stdout + r.stderr);
93
+ });
94
+
95
+ test('a citation to requirements.md fails when requirements.json is beside it', () => {
96
+ const dir = setUp('ARCHITECTURE.md', row('stated [FR-001 · kickoff call 2026-09-20](requirements.md)'));
97
+ writeFileSync(join(dir, 'requirements.md'), '# Requirements\n');
98
+ const r = run(dir, 'ARCHITECTURE.md');
99
+ assert.equal(r.status, 1);
100
+ assert.match(r.stdout, /^FAIL \[quotes\] requirements.md is the BA package for people; cite requirements.json by row id/m);
101
+ });