xdrs-core 0.34.2 → 0.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,7 +80,7 @@ Policies can be of different kinds, depending on the nature of the decision:
80
80
  - `apply-to` (required): Declares in which contexts — teams, systems, codebases, or environments — the decisions in this scope are relevant. Max 30 words.
81
81
  - `valid-from` (required): ISO date (YYYY-MM-DD) from which this scope became active.
82
82
  - `metadata` (optional): Arbitrary key-value map for additional scope metadata.
83
- - `follows` (optional): Core scope names whose Policies apply as mandatory conventions to this scope, beyond `_core`. Last-listed takes precedence on conflicts (e.g., `follows: [myarea-core, shared-standards]`).
83
+ - `follows` (optional): Core scope names whose Policies apply as mandatory conventions to this scope, beyond `_core`. Last-listed takes precedence on conflicts (e.g., `follows: myarea-core, shared-standards`).
84
84
  - `related-scopes` (optional): Scope names of parent, sibling, or child scopes. Use when structural links help verify policy correctness across related scopes.
85
85
  - **Subjects:** MUST be one of the following depending on the type of the Policy. Use the subject to indicate the main concern of the decision.
86
86
  - **ADR subjects**
@@ -57,7 +57,7 @@ Content that MUST NOT be placed in a `core`-type scope:
57
57
 
58
58
  #### 06-follows-required
59
59
 
60
- A scope that is governed by a `core` scope MUST declare this relationship explicitly using `follows: [{core-scope-name}]` in its `index.md` frontmatter.
60
+ A scope that is governed by a `core` scope MUST declare this relationship explicitly using `follows: {core-scope-name}` in its `index.md` frontmatter.
61
61
 
62
62
  #### 07-distribution
63
63
 
@@ -30,7 +30,7 @@ Performs a structured review of code changes or files against the Policies in th
30
30
  - Check `valid-from:` first. If a date is present and has not yet been reached, the decision SHOULD be adopted for new implementations but is not enforced during reviews.
31
31
  - Check `apply-to:` second. Keep only Policies whose stated scope fits the files, systems, or workflows under review.
32
32
  - Check the decision text itself last for additional boundaries or exceptions that metadata does not encode.
33
- 2. **Meta-policy scopes:** For each scope containing files under review, read its `index.md` frontmatter and check for a `follows` field. `_core` Policies always apply to all scopes. If a scope declares `follows:` with additional core scope names (e.g., `follows: [myarea-core, shared-standards]`), verify that each listed scope directory exists in the workspace (e.g., `.xdrs/[scope-name]/index.md`). If any listed scope is missing, STOP immediately — do not proceed with the review — and tell the user: "Scope `[scope-name]` is listed in `follows` but not found in the workspace. Install it before proceeding." Once all `follows` scopes are confirmed present, load their Policies and apply them as mandatory governance. Last-listed scope in `follows` takes precedence when the same topic is addressed by multiple scopes.
33
+ 2. **Meta-policy scopes:** For each scope containing files under review, read its `index.md` frontmatter and check for a `follows` field. `_core` Policies always apply to all scopes. If a scope declares `follows:` with additional core scope names (e.g., `follows: myarea-core, shared-standards`), verify that each listed scope directory exists in the workspace (e.g., `.xdrs/[scope-name]/index.md`). If any listed scope is missing, STOP immediately — do not proceed with the review — and tell the user: "Scope `[scope-name]` is listed in `follows` but not found in the workspace. Install it before proceeding." Once all `follows` scopes are confirmed present, load their Policies and apply them as mandatory governance. Last-listed scope in `follows` takes precedence when the same topic is addressed by multiple scopes.
34
34
  - **Scope-type standards:** Read the scope's `scope-type` from its `index.md`. Search the `[type]/principles/` directories of all `core`-type scopes in the workspace for a file whose name ends with `{scope-type}-scope-type.md`. If found, apply its rules as mandatory conventions. If the scope-type policy contains a rule titled `NN-parent-scope-type`, extract the parent type name (backtick-quoted identifier in the rule body) and repeat for the parent; continue until no more parents are declared. Detect and stop on cycles. See `_core-adr-policy-010` rules 15 and 17 for the full application model.
35
35
  - **Scope-local standards:** Search the scope's own `[type]/principles/` directories for a policy file whose name ends with `{scope-name}-core.md`. If found, apply its rules as mandatory conventions; scope-local standards take precedence over scope-type standards on any conflict. See `_core-adr-policy-010` rules 16 and 17.
36
36
  - **Scope-type standards:** Read the scope's `scope-type` from its `index.md`. Search the `[type]/principles/` directories of all `core`-type scopes in the workspace for a file whose name ends with `{scope-type}-scope-type.md`. If found, apply its rules as mandatory conventions. If the scope-type policy contains a rule titled `NN-parent-scope-type`, extract the parent type name (backtick-quoted identifier in the rule body) and repeat for the parent; continue until no more parents are declared. Detect and stop on cycles. See `_core-adr-policy-010` rules 15 and 17 for the full application model.
package/lib/lint.js CHANGED
@@ -99,23 +99,12 @@ function lintWorkspace(targetPath, options = {}) {
99
99
  const rootEntries = safeReadDir(xdrsRoot, errors, 'read XDRS root directory');
100
100
  const scopeEntries = rootEntries.filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'));
101
101
 
102
- // Pass 1: collect all core-type scopes by reading index.md directly (bypasses external-skip)
103
- const coreScopes = [];
104
- for (const scopeEntry of scopeEntries) {
105
- const scopeIndexPath = path.join(xdrsRoot, scopeEntry.name, 'index.md');
106
- if (!existsFile(scopeIndexPath)) continue;
107
- const content = fs.readFileSync(scopeIndexPath, 'utf8');
108
- const scopeTypeMatch = content.match(/^scope-type:\s*(.+)$/m);
109
- if (scopeTypeMatch && scopeTypeMatch[1].trim() === 'core') {
110
- coreScopes.push(path.join(xdrsRoot, scopeEntry.name));
111
- }
112
- }
113
-
114
- // Pass 2: collect known scope-type names from NNN-{scope-type}-scope-type.md files in core scopes
102
+ // Pass 1: collect known scope-type names from NNN-{scope-type}-scope-type.md files in any scope
115
103
  const knownScopeTypes = new Map(); // scopeTypeName -> filePath
116
- for (const coreScopePath of coreScopes) {
104
+ for (const scopeEntry of scopeEntries) {
105
+ const scopePath = path.join(xdrsRoot, scopeEntry.name);
117
106
  for (const typeName of Object.keys(TYPE_TO_ID)) {
118
- const principlesDir = path.join(coreScopePath, typeName, 'principles');
107
+ const principlesDir = path.join(scopePath, typeName, 'principles');
119
108
  if (!existsDirectory(principlesDir)) continue;
120
109
  let principlesEntries;
121
110
  try { principlesEntries = fs.readdirSync(principlesDir, { withFileTypes: true }); } catch { continue; }
@@ -256,8 +245,12 @@ function lintScopeIndexFrontmatter(scopeIndexPath, scopeName, errors, xdrsRoot,
256
245
  errors.push(`Scope index frontmatter must include a scope-type field: ${toDisplayPath(scopeIndexPath)}`);
257
246
  return;
258
247
  }
248
+ if (scopeType.startsWith('_') && scopeType !== '_local') {
249
+ errors.push(`Scope type "${scopeType}" uses a reserved "_" prefix; only "_local" is a valid underscore-prefixed scope type: ${toDisplayPath(scopeIndexPath)}`);
250
+ return;
251
+ }
259
252
  if (!knownScopeTypes.has(scopeType) && scopeType !== '_local') {
260
- errors.push(`Scope index scope-type "${scopeType}" has no corresponding ${scopeType}-scope-type policy in the principles subject of any core-type scope: ${toDisplayPath(scopeIndexPath)}`);
253
+ errors.push(`Scope index scope-type "${scopeType}" has no corresponding ${scopeType}-scope-type policy in the principles of any scope: ${toDisplayPath(scopeIndexPath)}`);
261
254
  return;
262
255
  }
263
256
  // Validate inheritance chain: ensure all ancestors exist in knownScopeTypes
@@ -269,9 +262,12 @@ function lintScopeIndexFrontmatter(scopeIndexPath, scopeName, errors, xdrsRoot,
269
262
  if (!policyPath) break;
270
263
  const parentType = extractParentScopeType(policyPath);
271
264
  if (!parentType) break;
272
- if (visited.has(parentType)) break; // cycle detected
265
+ if (visited.has(parentType)) {
266
+ errors.push(`Scope type "${currentType}" declares parent "${parentType}" which creates a cycle in the scope-type inheritance chain: ${toDisplayPath(scopeIndexPath)}`);
267
+ break;
268
+ }
273
269
  if (!knownScopeTypes.has(parentType)) {
274
- errors.push(`Scope type "${currentType}" declares parent "${parentType}" but no ${parentType}-scope-type policy exists in any core-type scope: ${toDisplayPath(scopeIndexPath)}`);
270
+ errors.push(`Scope type "${currentType}" declares parent "${parentType}" but no ${parentType}-scope-type policy exists in any scope: ${toDisplayPath(scopeIndexPath)}`);
275
271
  break;
276
272
  }
277
273
  visited.add(parentType);
@@ -326,12 +322,14 @@ function lintScopeIndexFrontmatter(scopeIndexPath, scopeName, errors, xdrsRoot,
326
322
  errors.push(`Scope index frontmatter valid-from must be a valid ISO date YYYY-MM-DD: ${toDisplayPath(scopeIndexPath)}`);
327
323
  }
328
324
 
325
+ let followsEntries = [];
329
326
  const followsLineMatch = block.match(/^follows:[ \t]*(.*)/m);
330
327
  if (followsLineMatch !== null) {
331
328
  const followsValue = followsLineMatch[1].trim();
332
329
  const scopeNamePattern = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
330
+ const commaSeparatedPattern = /^[a-zA-Z_][a-zA-Z0-9_-]*(\s*,\s*[a-zA-Z_][a-zA-Z0-9_-]*)+$/;
333
331
  if (followsValue) {
334
- if (!scopeNamePattern.test(followsValue)) {
332
+ if (!scopeNamePattern.test(followsValue) && !commaSeparatedPattern.test(followsValue)) {
335
333
  errors.push(`Scope index frontmatter follows must be a core scope name or list of core scope names: ${toDisplayPath(scopeIndexPath)}`);
336
334
  }
337
335
  } else {
@@ -357,18 +355,36 @@ function lintScopeIndexFrontmatter(scopeIndexPath, scopeName, errors, xdrsRoot,
357
355
  }
358
356
  }
359
357
  if (xdrsRoot) {
360
- const entries = followsValue ? [followsValue] : (() => {
361
- const items = [];
362
- const followsStart = block.indexOf(followsLineMatch[0]) + followsLineMatch[0].length;
363
- for (const line of block.slice(followsStart).split('\n')) {
364
- const itemMatch = line.match(/^\s+-\s*(\S.*)?$/);
365
- if (itemMatch && itemMatch[1]) items.push(itemMatch[1].trim());
366
- else if (line.trim() && !/^\s/.test(line)) break;
367
- }
368
- return items;
369
- })();
358
+ const entries = followsValue
359
+ ? (commaSeparatedPattern.test(followsValue)
360
+ ? followsValue.split(',').map((s) => s.trim())
361
+ : [followsValue])
362
+ : (() => {
363
+ const items = [];
364
+ const followsStart = block.indexOf(followsLineMatch[0]) + followsLineMatch[0].length;
365
+ for (const line of block.slice(followsStart).split('\n')) {
366
+ const itemMatch = line.match(/^\s+-\s*(\S.*)?$/);
367
+ if (itemMatch && itemMatch[1]) items.push(itemMatch[1].trim());
368
+ else if (line.trim() && !/^\s/.test(line)) break;
369
+ }
370
+ return items;
371
+ })();
372
+ followsEntries = entries;
373
+ const seenFollows = new Set();
370
374
  for (const entry of entries) {
375
+ if (seenFollows.has(entry)) {
376
+ errors.push(`Scope index frontmatter follows has duplicate entry "${entry}": ${toDisplayPath(scopeIndexPath)}`);
377
+ }
378
+ seenFollows.add(entry);
371
379
  if (/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(entry)) {
380
+ if (entry === scopeName) {
381
+ errors.push(`Scope index frontmatter follows must not reference the scope itself: ${toDisplayPath(scopeIndexPath)}`);
382
+ continue;
383
+ }
384
+ if (entry === '_core') {
385
+ errors.push(`Scope index frontmatter follows must not reference "_core" as it is always applied implicitly: ${toDisplayPath(scopeIndexPath)}`);
386
+ continue;
387
+ }
372
388
  const followedIndexPath = path.join(xdrsRoot, entry, 'index.md');
373
389
  if (!existsFile(followedIndexPath)) {
374
390
  errors.push(`Scope index frontmatter follows references scope "${entry}" which does not exist in the workspace: ${toDisplayPath(scopeIndexPath)}`);
@@ -425,9 +441,24 @@ function lintScopeIndexFrontmatter(scopeIndexPath, scopeName, errors, xdrsRoot,
425
441
  }
426
442
  return items;
427
443
  })();
444
+ const seenRelated = new Set();
428
445
  for (const entry of entries) {
429
- if (/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(entry) && !existsFile(path.join(xdrsRoot, entry, 'index.md'))) {
430
- errors.push(`Scope index frontmatter related-scopes references scope "${entry}" which does not exist in the workspace: ${toDisplayPath(scopeIndexPath)}`);
446
+ if (seenRelated.has(entry)) {
447
+ errors.push(`Scope index frontmatter related-scopes has duplicate entry "${entry}": ${toDisplayPath(scopeIndexPath)}`);
448
+ }
449
+ seenRelated.add(entry);
450
+ if (/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(entry)) {
451
+ if (entry === scopeName) {
452
+ errors.push(`Scope index frontmatter related-scopes must not reference the scope itself: ${toDisplayPath(scopeIndexPath)}`);
453
+ continue;
454
+ }
455
+ if (followsEntries.includes(entry)) {
456
+ errors.push(`Scope index frontmatter related-scopes must not repeat scope "${entry}" already declared in follows: ${toDisplayPath(scopeIndexPath)}`);
457
+ continue;
458
+ }
459
+ if (!existsFile(path.join(xdrsRoot, entry, 'index.md'))) {
460
+ errors.push(`Scope index frontmatter related-scopes references scope "${entry}" which does not exist in the workspace: ${toDisplayPath(scopeIndexPath)}`);
461
+ }
431
462
  }
432
463
  }
433
464
  }
@@ -476,6 +507,34 @@ function lintScopeDirectory(xdrsRoot, scopeName, errors, actualTypeIndexes, igno
476
507
  lintScopeIndex(scopeIndexPath, xdrsRoot, scopeName, typeIndexesInScope, errors, externalScopes);
477
508
  lintScopeIndexFrontmatter(scopeIndexPath, scopeName, errors, xdrsRoot, knownScopeTypes);
478
509
  }
510
+ lintScopeLocalStandards(xdrsRoot, scopeName, errors);
511
+ }
512
+
513
+ function lintScopeLocalStandards(xdrsRoot, scopeName, errors) {
514
+ const scopePath = path.join(xdrsRoot, scopeName);
515
+ const corePolicySuffix = `${scopeName}-core`;
516
+ const foundPolicies = [];
517
+ for (const typeName of Object.keys(TYPE_TO_ID)) {
518
+ const principlesDir = path.join(scopePath, typeName, 'principles');
519
+ if (!existsDirectory(principlesDir)) continue;
520
+ let principlesEntries;
521
+ try { principlesEntries = fs.readdirSync(principlesDir, { withFileTypes: true }); } catch { continue; }
522
+ for (const entry of principlesEntries) {
523
+ if (!entry.isFile()) continue;
524
+ if (!NUMBERED_FILE_RE.test(entry.name)) continue;
525
+ const filePath = path.join(principlesDir, entry.name);
526
+ let content;
527
+ try { content = fs.readFileSync(filePath, 'utf8'); } catch { continue; }
528
+ const fm = extractFrontmatter(content);
529
+ if (fm.name && (fm.name === corePolicySuffix || fm.name.endsWith(`-${corePolicySuffix}`))) {
530
+ foundPolicies.push(filePath);
531
+ }
532
+ }
533
+ }
534
+ if (foundPolicies.length > 1) {
535
+ const paths = foundPolicies.map((p) => toDisplayPath(p)).join(', ');
536
+ errors.push(`Scope "${scopeName}" has more than one scope-local standards policy (name ending with "${corePolicySuffix}"): ${paths}`);
537
+ }
479
538
  }
480
539
 
481
540
  function lintTypeDirectory(xdrsRoot, scopeName, typeName, errors, actualTypeIndexes, externalScopes = new Set()) {
package/lib/lint.test.js CHANGED
@@ -885,6 +885,34 @@ test('accepts custom scope-type when policy exists in core-type scope', () => {
885
885
  expect(result.errors.join('\n')).not.toContain('Scope index frontmatter');
886
886
  });
887
887
 
888
+ test('accepts custom scope-type when policy exists in a non-core scope', () => {
889
+ // domain-scope-type.md is in a platform-type scope (not a core scope), but lint should still find it
890
+ const workspaceRoot = createWorkspace('custom-scope-type-in-non-core-scope', {
891
+ '.xdrs/index.md': rootIndex(['[nnb-mt-domain](nnb-mt-domain/index.md)', '[my-platform](my-platform/index.md)']),
892
+ '.xdrs/nnb-mt-domain/index.md': '---\nscope-type: domain\nname: nnb-mt-domain\ndescription: Domain scope.\napply-to: All\nvalid-from: 2026-01-01\n---\n\n# nnb-mt-domain Scope Overview\n\nDomain scope.\n\n[ADRs](adrs/index.md)\n',
893
+ '.xdrs/nnb-mt-domain/adrs/index.md': teamAdrIndex([]),
894
+ // scope-type 'domain' defined in a non-core platform scope (not _core)
895
+ '.xdrs/my-platform/index.md': '---\nscope-type: platform\nname: my-platform\ndescription: Platform scope.\napply-to: All\nvalid-from: 2026-01-01\n---\n\n# my-platform Scope Overview\n\nPlatform scope.\n\n[ADRs](adrs/index.md)\n',
896
+ '.xdrs/my-platform/adrs/index.md': [
897
+ '# my-platform ADR Index', '', 'Platform ADRs.', '', '## principles', '',
898
+ '- [001-domain-scope-type](principles/001-domain-scope-type.md) - domain type', ''
899
+ ].join('\n'),
900
+ '.xdrs/my-platform/adrs/principles/001-domain-scope-type.md': [
901
+ '---', 'name: my-platform-adr-policy-001-domain-scope-type',
902
+ 'description: Defines the domain scope type.', 'apply-to: All', 'valid-from: 2026-01-01', '---', '',
903
+ '# my-platform-adr-policy-001: domain scope type', '', '## Context and Problem Statement', '',
904
+ 'Defines the domain scope type.', '', '## Decision Outcome', '', 'Use scope-type: domain.', ''
905
+ ].join('\n'),
906
+ // _core only defines 'core' and 'platform' — no 'domain' here
907
+ ...coreWithScopeTypes(['platform']),
908
+ });
909
+
910
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
911
+
912
+ expect(result.errors.join('\n')).not.toContain('has no corresponding');
913
+ expect(result.errors.join('\n')).not.toContain('Scope index frontmatter');
914
+ });
915
+
888
916
  test('reports custom scope-type when no policy exists', () => {
889
917
  const workspaceRoot = createWorkspace('custom-scope-type-missing-policy', {
890
918
  '.xdrs/index.md': rootIndex(['[my-scope](my-scope/index.md)']),
@@ -943,6 +971,205 @@ test('reports error when parent scope-type in chain does not exist', () => {
943
971
  expect(result.errors.join('\n')).toContain('declares parent "nonexistent-parent" but no nonexistent-parent-scope-type policy exists');
944
972
  });
945
973
 
974
+ test('reports cycle in scope-type inheritance chain', () => {
975
+ const workspaceRoot = createWorkspace('scope-type-inheritance-cycle', {
976
+ '.xdrs/index.md': rootIndex(['[my-custom](my-custom/index.md)', '[_core](_core/index.md)']),
977
+ '.xdrs/my-custom/index.md': '---\nscope-type: child\nname: my-custom\ndescription: Custom scope.\napply-to: All\nvalid-from: 2026-01-01\n---\n\n# my-custom Scope Overview\n\nCustom.\n\n[ADRs](adrs/index.md)\n',
978
+ '.xdrs/my-custom/adrs/index.md': teamAdrIndex([]),
979
+ '.xdrs/_core/index.md': '---\nscope-type: core\nname: _core\ndescription: Core scope.\napply-to: All\nvalid-from: 2026-01-01\n---\n\n# _core\n\n[ADRs](adrs/index.md)\n',
980
+ '.xdrs/_core/adrs/index.md': [
981
+ '# _core ADR Index', '', 'Core ADRs.', '', '## principles', '',
982
+ '- [001-core-scope-type](principles/001-core-scope-type.md) - core type',
983
+ '- [002-parent-scope-type](principles/002-parent-scope-type.md) - parent type',
984
+ '- [003-child-scope-type](principles/003-child-scope-type.md) - child type',
985
+ ''
986
+ ].join('\n'),
987
+ '.xdrs/_core/adrs/principles/001-core-scope-type.md': '---\nname: _core-adr-policy-001-core-scope-type\ndescription: core stub\napply-to: All\nvalid-from: 2026-01-01\n---\n\n## Context and Problem Statement\n\nStub.\n\n## Decision Outcome\n\nStub.\n',
988
+ '.xdrs/_core/adrs/principles/002-parent-scope-type.md': '---\nname: _core-adr-policy-002-parent-scope-type\ndescription: parent type that cycles back to child\napply-to: All\nvalid-from: 2026-01-01\n---\n\n## Context and Problem Statement\n\nParent.\n\n## Decision Outcome\n\nParent.\n\n#### 01-parent-scope-type\n\nInstances inherit from the `child` scope type.\n',
989
+ '.xdrs/_core/adrs/principles/003-child-scope-type.md': '---\nname: _core-adr-policy-003-child-scope-type\ndescription: child type that points to parent\napply-to: All\nvalid-from: 2026-01-01\n---\n\n## Context and Problem Statement\n\nChild.\n\n## Decision Outcome\n\nChild.\n\n#### 01-parent-scope-type\n\nInstances inherit from the `parent` scope type.\n',
990
+ });
991
+
992
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
993
+
994
+ expect(result.errors.join('\n')).toContain('creates a cycle in the scope-type inheritance chain');
995
+ expect(result.errors.join('\n')).toContain('my-custom/index.md');
996
+ });
997
+
998
+ test('reports scope-type with reserved underscore prefix', () => {
999
+ const workspaceRoot = createWorkspace('scope-type-underscore-prefix', {
1000
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)']),
1001
+ '.xdrs/myteam/index.md': '---\nscope-type: _custom\nname: myteam\ndescription: Team scope for tests.\napply-to: Test team only\nvalid-from: 2026-01-01\n---\n\n# myteam Scope Overview\n\nTeam scope for tests.\n\n[ADRs](adrs/index.md)\n',
1002
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex([
1003
+ '- [001-team](principles/001-team.md) - Team decision'
1004
+ ]),
1005
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1006
+ ...coreWithScopeTypes([]),
1007
+ });
1008
+
1009
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1010
+
1011
+ expect(result.errors.join('\n')).toContain('uses a reserved "_" prefix');
1012
+ expect(result.errors.join('\n')).toContain('myteam/index.md');
1013
+ });
1014
+
1015
+ test('does not report underscore prefix error for valid _local scope type', () => {
1016
+ const workspaceRoot = createWorkspace('scope-type-local-no-prefix-error', {
1017
+ '.xdrs/index.md': rootIndex(),
1018
+ '.xdrs/_local/index.md': localScopeIndex(),
1019
+ '.xdrs/_local/adrs/index.md': localAdrIndex([
1020
+ '- [001-main](principles/001-main.md) - Main decision'
1021
+ ]),
1022
+ '.xdrs/_local/adrs/principles/001-main.md': xdrDocument('Test body.'),
1023
+ });
1024
+
1025
+ const result = lintWorkspace(workspaceRoot);
1026
+
1027
+ expect(result.errors.join('\n')).not.toContain('uses a reserved "_" prefix');
1028
+ });
1029
+
1030
+ test('reports follows that references the scope itself', () => {
1031
+ const workspaceRoot = createWorkspace('follows-self-reference', {
1032
+ '.xdrs/index.md': rootIndex(['[myarea-core](myarea-core/index.md)']),
1033
+ '.xdrs/myarea-core/index.md': '---\nscope-type: core\nname: myarea-core\ndescription: Meta-governance for myarea.\napply-to: All myarea scopes\nvalid-from: 2026-01-01\nfollows: myarea-core\n---\n\n# myarea-core Scope Overview\n\n[ADRs](adrs/index.md)\n',
1034
+ '.xdrs/myarea-core/adrs/index.md': teamAdrIndex([
1035
+ '- [001-team](principles/001-team.md) - Team decision'
1036
+ ]),
1037
+ '.xdrs/myarea-core/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1038
+ });
1039
+
1040
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1041
+
1042
+ expect(result.errors.join('\n')).toContain('follows must not reference the scope itself');
1043
+ expect(result.errors.join('\n')).toContain('myarea-core/index.md');
1044
+ });
1045
+
1046
+ test('reports follows that references _core', () => {
1047
+ const workspaceRoot = createWorkspace('follows-core-reference', {
1048
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)']),
1049
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nfollows: _core\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1050
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex([
1051
+ '- [001-team](principles/001-team.md) - Team decision'
1052
+ ]),
1053
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1054
+ });
1055
+
1056
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1057
+
1058
+ expect(result.errors.join('\n')).toContain('follows must not reference "_core" as it is always applied implicitly');
1059
+ expect(result.errors.join('\n')).toContain('myteam/index.md');
1060
+ });
1061
+
1062
+ test('reports follows list that includes _core', () => {
1063
+ const workspaceRoot = createWorkspace('follows-list-includes-core', {
1064
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)', '[myarea-core](myarea-core/index.md)']),
1065
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nfollows:\n - myarea-core\n - _core\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1066
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex([
1067
+ '- [001-team](principles/001-team.md) - Team decision'
1068
+ ]),
1069
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1070
+ '.xdrs/myarea-core/index.md': '---\nscope-type: core\nname: myarea-core\ndescription: Meta-governance for myarea.\napply-to: All myarea scopes\nvalid-from: 2026-01-01\n---\n\n# myarea-core Scope Overview\n\n[ADRs](adrs/index.md)\n',
1071
+ '.xdrs/myarea-core/adrs/index.md': teamAdrIndex([
1072
+ '- [001-team](principles/001-team.md) - Team decision'
1073
+ ]),
1074
+ '.xdrs/myarea-core/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1075
+ });
1076
+
1077
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1078
+
1079
+ expect(result.errors.join('\n')).toContain('follows must not reference "_core" as it is always applied implicitly');
1080
+ });
1081
+
1082
+ test('reports duplicate scope-local standards policies in same scope', () => {
1083
+ const workspaceRoot = createWorkspace('duplicate-scope-local-standards', {
1084
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)']),
1085
+ '.xdrs/myteam/index.md': teamScopeIndex(),
1086
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex([
1087
+ '- [001-team](principles/001-team.md) - Team decision',
1088
+ '- [002-myteam-core](principles/002-myteam-core.md) - Local standards',
1089
+ '- [003-myteam-core-dup](principles/003-myteam-core-dup.md) - Duplicate local standards',
1090
+ ]),
1091
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1092
+ '.xdrs/myteam/adrs/principles/002-myteam-core.md': [
1093
+ '---',
1094
+ 'name: myteam-adr-policy-002-myteam-core',
1095
+ 'description: Local standards for myteam.',
1096
+ 'apply-to: myteam scope',
1097
+ 'valid-from: 2026-01-01',
1098
+ '---',
1099
+ '',
1100
+ '# myteam-adr-policy-002: myteam local standards',
1101
+ '',
1102
+ '## Context and Problem Statement',
1103
+ '',
1104
+ 'Defines local authoring standards.',
1105
+ '',
1106
+ '## Decision Outcome',
1107
+ '',
1108
+ 'Standard outcome.',
1109
+ ''
1110
+ ].join('\n'),
1111
+ '.xdrs/myteam/adrs/principles/003-myteam-core-dup.md': [
1112
+ '---',
1113
+ 'name: myteam-adr-policy-003-myteam-core',
1114
+ 'description: Duplicate local standards for myteam.',
1115
+ 'apply-to: myteam scope',
1116
+ 'valid-from: 2026-01-01',
1117
+ '---',
1118
+ '',
1119
+ '# myteam-adr-policy-003: myteam local standards duplicate',
1120
+ '',
1121
+ '## Context and Problem Statement',
1122
+ '',
1123
+ 'Duplicate defines local authoring standards.',
1124
+ '',
1125
+ '## Decision Outcome',
1126
+ '',
1127
+ 'Duplicate outcome.',
1128
+ ''
1129
+ ].join('\n'),
1130
+ });
1131
+
1132
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1133
+
1134
+ expect(result.errors.join('\n')).toContain('has more than one scope-local standards policy');
1135
+ expect(result.errors.join('\n')).toContain('myteam-core');
1136
+ });
1137
+
1138
+ test('accepts single scope-local standards policy in a scope', () => {
1139
+ const workspaceRoot = createWorkspace('single-scope-local-standards', {
1140
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)']),
1141
+ '.xdrs/myteam/index.md': teamScopeIndex(),
1142
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex([
1143
+ '- [001-team](principles/001-team.md) - Team decision',
1144
+ '- [002-myteam-core](principles/002-myteam-core.md) - Local standards',
1145
+ ]),
1146
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1147
+ '.xdrs/myteam/adrs/principles/002-myteam-core.md': [
1148
+ '---',
1149
+ 'name: myteam-adr-policy-002-myteam-core',
1150
+ 'description: Local standards for myteam.',
1151
+ 'apply-to: myteam scope',
1152
+ 'valid-from: 2026-01-01',
1153
+ '---',
1154
+ '',
1155
+ '# myteam-adr-policy-002: myteam local standards',
1156
+ '',
1157
+ '## Context and Problem Statement',
1158
+ '',
1159
+ 'Defines local authoring standards.',
1160
+ '',
1161
+ '## Decision Outcome',
1162
+ '',
1163
+ 'Standard outcome.',
1164
+ ''
1165
+ ].join('\n'),
1166
+ });
1167
+
1168
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1169
+
1170
+ expect(result.errors.join('\n')).not.toContain('has more than one scope-local standards policy');
1171
+ });
1172
+
946
1173
  test('reports missing name field in scope index frontmatter', () => {
947
1174
  const workspaceRoot = createWorkspace('scope-index-missing-name', {
948
1175
  '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)']),
@@ -1082,6 +1309,25 @@ test('accepts follows as a single core scope name string in scope index frontmat
1082
1309
  expect(result.errors.join('\n')).not.toContain('Scope index frontmatter follows');
1083
1310
  });
1084
1311
 
1312
+ test('accepts follows as a comma-separated list of core scope names in scope index frontmatter', () => {
1313
+ const workspaceRoot = createWorkspace('valid-scope-follows-comma', {
1314
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)', '[myarea-core](myarea-core/index.md)', '[shared-standards-core](shared-standards-core/index.md)']),
1315
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nfollows: myarea-core, shared-standards-core\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1316
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1317
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1318
+ '.xdrs/myarea-core/index.md': '---\nscope-type: core\nname: myarea-core\ndescription: Meta-governance for myarea.\napply-to: All myarea scopes\nvalid-from: 2026-01-01\n---\n\n# myarea-core Scope Overview\n\n[ADRs](adrs/index.md)\n',
1319
+ '.xdrs/myarea-core/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1320
+ '.xdrs/myarea-core/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1321
+ '.xdrs/shared-standards-core/index.md': '---\nscope-type: core\nname: shared-standards-core\ndescription: Shared standards for all areas.\napply-to: All scopes\nvalid-from: 2026-01-01\n---\n\n# shared-standards-core Scope Overview\n\n[ADRs](adrs/index.md)\n',
1322
+ '.xdrs/shared-standards-core/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1323
+ '.xdrs/shared-standards-core/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1324
+ });
1325
+
1326
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1327
+
1328
+ expect(result.errors.join('\n')).not.toContain('Scope index frontmatter follows');
1329
+ });
1330
+
1085
1331
  test('reports invalid follows value in scope index frontmatter', () => {
1086
1332
  const workspaceRoot = createWorkspace('invalid-scope-follows', {
1087
1333
  '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)']),
@@ -1243,6 +1489,83 @@ test('accepts related-scopes scope that exists in workspace', () => {
1243
1489
  expect(result.errors.join('\n')).not.toContain('related-scopes references scope "sibling-team"');
1244
1490
  });
1245
1491
 
1492
+ test('reports duplicate entries in follows list', () => {
1493
+ const workspaceRoot = createWorkspace('follows-duplicate-entries', {
1494
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)', '[myarea-core](myarea-core/index.md)']),
1495
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nfollows:\n - myarea-core\n - myarea-core\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1496
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1497
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1498
+ '.xdrs/myarea-core/index.md': '---\nscope-type: core\nname: myarea-core\ndescription: Meta-governance for myarea.\napply-to: All myarea scopes\nvalid-from: 2026-01-01\n---\n\n# myarea-core Scope Overview\n\n[ADRs](adrs/index.md)\n',
1499
+ '.xdrs/myarea-core/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1500
+ '.xdrs/myarea-core/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1501
+ });
1502
+
1503
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1504
+
1505
+ expect(result.errors.join('\n')).toContain('follows has duplicate entry "myarea-core"');
1506
+ });
1507
+
1508
+ test('reports duplicate entries in follows comma-separated list', () => {
1509
+ const workspaceRoot = createWorkspace('follows-comma-duplicate-entries', {
1510
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)', '[myarea-core](myarea-core/index.md)']),
1511
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nfollows: myarea-core, myarea-core\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1512
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1513
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1514
+ '.xdrs/myarea-core/index.md': '---\nscope-type: core\nname: myarea-core\ndescription: Meta-governance for myarea.\napply-to: All myarea scopes\nvalid-from: 2026-01-01\n---\n\n# myarea-core Scope Overview\n\n[ADRs](adrs/index.md)\n',
1515
+ '.xdrs/myarea-core/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1516
+ '.xdrs/myarea-core/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1517
+ });
1518
+
1519
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1520
+
1521
+ expect(result.errors.join('\n')).toContain('follows has duplicate entry "myarea-core"');
1522
+ });
1523
+
1524
+ test('reports related-scopes that references the scope itself', () => {
1525
+ const workspaceRoot = createWorkspace('related-scopes-self-reference', {
1526
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)']),
1527
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nrelated-scopes: myteam\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1528
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1529
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1530
+ });
1531
+
1532
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1533
+
1534
+ expect(result.errors.join('\n')).toContain('related-scopes must not reference the scope itself');
1535
+ });
1536
+
1537
+ test('reports duplicate entries in related-scopes list', () => {
1538
+ const workspaceRoot = createWorkspace('related-scopes-duplicate-entries', {
1539
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)', '[sibling-team](sibling-team/index.md)']),
1540
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nrelated-scopes:\n - sibling-team\n - sibling-team\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1541
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1542
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1543
+ '.xdrs/sibling-team/index.md': '---\nscope-type: standard\nname: sibling-team\ndescription: Sibling team.\napply-to: Sibling team\nvalid-from: 2026-01-01\n---\n\n# sibling-team Scope Overview\n\n[ADRs](adrs/index.md)\n',
1544
+ '.xdrs/sibling-team/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1545
+ '.xdrs/sibling-team/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1546
+ });
1547
+
1548
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1549
+
1550
+ expect(result.errors.join('\n')).toContain('related-scopes has duplicate entry "sibling-team"');
1551
+ });
1552
+
1553
+ test('reports related-scopes entry that is already declared in follows', () => {
1554
+ const workspaceRoot = createWorkspace('related-scopes-follows-overlap', {
1555
+ '.xdrs/index.md': rootIndex(['[myteam](myteam/index.md)', '[myarea-core](myarea-core/index.md)']),
1556
+ '.xdrs/myteam/index.md': '---\nscope-type: standard\nname: myteam\ndescription: Team.\napply-to: Test team\nvalid-from: 2026-01-01\nfollows: myarea-core\nrelated-scopes: myarea-core\n---\n\n# myteam Scope Overview\n\n[ADRs](adrs/index.md)\n',
1557
+ '.xdrs/myteam/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1558
+ '.xdrs/myteam/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1559
+ '.xdrs/myarea-core/index.md': '---\nscope-type: core\nname: myarea-core\ndescription: Meta-governance for myarea.\napply-to: All myarea scopes\nvalid-from: 2026-01-01\n---\n\n# myarea-core Scope Overview\n\n[ADRs](adrs/index.md)\n',
1560
+ '.xdrs/myarea-core/adrs/index.md': teamAdrIndex(['- [001-team](principles/001-team.md) - Team decision']),
1561
+ '.xdrs/myarea-core/adrs/principles/001-team.md': teamXdrDocument('Team decision.'),
1562
+ });
1563
+
1564
+ const result = lintWorkspace(workspaceRoot, { ignoreExternal: false });
1565
+
1566
+ expect(result.errors.join('\n')).toContain('related-scopes must not repeat scope "myarea-core" already declared in follows');
1567
+ });
1568
+
1246
1569
  test('reports orphan asset files not referenced by any document', () => {
1247
1570
  const workspaceRoot = createWorkspace('orphan-asset', {
1248
1571
  '.xdrs/index.md': rootIndex(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xdrs-core",
3
- "version": "0.34.2",
3
+ "version": "0.35.1",
4
4
  "description": "A framework to structure, compile and distribute Architectural (ADR), Business (BDR), and Engineering (EDR) decision records contents so that AI agents and humans can reliably find and use them with hierarchical scopes and controlled rollout in the format of distributable versioned packages.",
5
5
  "repository": {
6
6
  "type": "git",