@driftsys/markspec 0.10.1 → 0.10.2

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 (77) hide show
  1. package/esm/collect/mod.d.ts +34 -0
  2. package/esm/collect/mod.d.ts.map +1 -0
  3. package/esm/collect/mod.js +37 -0
  4. package/esm/formatter/mod.d.ts.map +1 -1
  5. package/esm/formatter/mod.js +29 -1
  6. package/esm/gates/mod.d.ts +82 -0
  7. package/esm/gates/mod.d.ts.map +1 -0
  8. package/esm/gates/mod.js +139 -0
  9. package/esm/lint/runner.d.ts +26 -3
  10. package/esm/lint/runner.d.ts.map +1 -1
  11. package/esm/lint/runner.js +39 -9
  12. package/esm/lock/edge_drift.d.ts +31 -0
  13. package/esm/lock/edge_drift.d.ts.map +1 -0
  14. package/esm/lock/edge_drift.js +29 -0
  15. package/esm/lock/mod.d.ts +2 -0
  16. package/esm/lock/mod.d.ts.map +1 -1
  17. package/esm/lock/mod.js +1 -0
  18. package/esm/mod.d.ts +11 -6
  19. package/esm/mod.d.ts.map +1 -1
  20. package/esm/mod.js +10 -4
  21. package/esm/model/mod.d.ts +8 -0
  22. package/esm/model/mod.d.ts.map +1 -1
  23. package/esm/model/mod.js +10 -0
  24. package/esm/model/profile.d.ts +8 -0
  25. package/esm/model/profile.d.ts.map +1 -1
  26. package/esm/parser/markdown.d.ts.map +1 -1
  27. package/esm/parser/markdown.js +38 -11
  28. package/esm/profile/delivered.d.ts +22 -1
  29. package/esm/profile/delivered.d.ts.map +1 -1
  30. package/esm/profile/delivered.js +44 -1
  31. package/esm/profile/merge.js +1 -0
  32. package/esm/reporter/mod.d.ts.map +1 -1
  33. package/esm/reporter/mod.js +2 -3
  34. package/esm/util/fence.d.ts +8 -0
  35. package/esm/util/fence.d.ts.map +1 -1
  36. package/esm/util/fence.js +22 -0
  37. package/esm/validator/corpus.d.ts.map +1 -1
  38. package/esm/validator/corpus.js +14 -12
  39. package/package.json +1 -1
  40. package/script/collect/mod.d.ts +34 -0
  41. package/script/collect/mod.d.ts.map +1 -0
  42. package/script/collect/mod.js +40 -0
  43. package/script/formatter/mod.d.ts.map +1 -1
  44. package/script/formatter/mod.js +29 -1
  45. package/script/gates/mod.d.ts +82 -0
  46. package/script/gates/mod.d.ts.map +1 -0
  47. package/script/gates/mod.js +144 -0
  48. package/script/lint/runner.d.ts +26 -3
  49. package/script/lint/runner.d.ts.map +1 -1
  50. package/script/lint/runner.js +39 -9
  51. package/script/lock/edge_drift.d.ts +31 -0
  52. package/script/lock/edge_drift.d.ts.map +1 -0
  53. package/script/lock/edge_drift.js +32 -0
  54. package/script/lock/mod.d.ts +2 -0
  55. package/script/lock/mod.d.ts.map +1 -1
  56. package/script/lock/mod.js +3 -1
  57. package/script/mod.d.ts +11 -6
  58. package/script/mod.d.ts.map +1 -1
  59. package/script/mod.js +45 -29
  60. package/script/model/mod.d.ts +8 -0
  61. package/script/model/mod.d.ts.map +1 -1
  62. package/script/model/mod.js +11 -0
  63. package/script/model/profile.d.ts +8 -0
  64. package/script/model/profile.d.ts.map +1 -1
  65. package/script/parser/markdown.d.ts.map +1 -1
  66. package/script/parser/markdown.js +38 -11
  67. package/script/profile/delivered.d.ts +22 -1
  68. package/script/profile/delivered.d.ts.map +1 -1
  69. package/script/profile/delivered.js +45 -1
  70. package/script/profile/merge.js +1 -0
  71. package/script/reporter/mod.d.ts.map +1 -1
  72. package/script/reporter/mod.js +2 -3
  73. package/script/util/fence.d.ts +8 -0
  74. package/script/util/fence.d.ts.map +1 -1
  75. package/script/util/fence.js +23 -0
  76. package/script/validator/corpus.d.ts.map +1 -1
  77. package/script/validator/corpus.js +14 -12
@@ -13,6 +13,7 @@
13
13
  * delivering profile; generic duplicate codes are suppressed for
14
14
  * collided tokens (MSL-R014 replaces them).
15
15
  */
16
+ import { formatEntryOrigin } from "../model/mod.js";
16
17
  /** Generic duplicate detectors superseded by MSL-R014 for corpus collisions. */
17
18
  const GENERIC_DUP_CODES = new Set([
18
19
  "MSL-R005",
@@ -46,8 +47,7 @@ export function detectCorpusCollisions(allEntries) {
46
47
  code: "MSL-R014",
47
48
  severity: "error",
48
49
  message: `display ID '${e.displayId}' is already delivered by ` +
49
- `${displayOwner.origin.profileId}@` +
50
- `${displayOwner.origin.profileVersion}; rename this entry — ` +
50
+ `${formatEntryOrigin(displayOwner.origin)}; rename this entry — ` +
51
51
  `delivered corpus entries are read-only`,
52
52
  location: e.location,
53
53
  });
@@ -60,8 +60,7 @@ export function detectCorpusCollisions(allEntries) {
60
60
  code: "MSL-R014",
61
61
  severity: "error",
62
62
  message: `Id '${e.id}' is already delivered by ` +
63
- `${idOwner.origin.profileId}@` +
64
- `${idOwner.origin.profileVersion}; rename this entry — ` +
63
+ `${formatEntryOrigin(idOwner.origin)}; rename this entry — ` +
65
64
  `delivered corpus entries are read-only`,
66
65
  location: e.location,
67
66
  });
@@ -82,8 +81,7 @@ export function detectCorpusCollisions(allEntries) {
82
81
  code: "MSL-R014",
83
82
  severity: "error",
84
83
  message: `display ID '${e.displayId}' is already delivered by ` +
85
- `${displayOwner.origin.profileId}@` +
86
- `${displayOwner.origin.profileVersion}; delivered corpus ` +
84
+ `${formatEntryOrigin(displayOwner.origin)}; delivered corpus ` +
87
85
  `entries are read-only`,
88
86
  location: e.location,
89
87
  });
@@ -97,8 +95,7 @@ export function detectCorpusCollisions(allEntries) {
97
95
  code: "MSL-R014",
98
96
  severity: "error",
99
97
  message: `Id '${e.id}' is already delivered by ` +
100
- `${idOwner.origin.profileId}@` +
101
- `${idOwner.origin.profileVersion}; delivered corpus entries ` +
98
+ `${formatEntryOrigin(idOwner.origin)}; delivered corpus entries ` +
102
99
  `are read-only`,
103
100
  location: e.location,
104
101
  });
@@ -111,14 +108,19 @@ export function attributeCorpusDiagnostics(diagnostics, allEntries, collidedToke
111
108
  const corpusFiles = new Map();
112
109
  for (const e of allEntries) {
113
110
  if (e.origin) {
114
- corpusFiles.set(e.location.file, `${e.origin.profileId}@${e.origin.profileVersion}`);
111
+ corpusFiles.set(e.location.file, formatEntryOrigin(e.origin));
115
112
  }
116
113
  }
117
114
  const out = [];
118
115
  for (const d of diagnostics) {
119
- // Suppress the generic duplicate codes for corpus collisions; the
120
- // validator embeds the offending token in single quotes, which is what
121
- // this containment check keys on.
116
+ // Suppress the generic duplicate codes for a corpus collision (MSL-R014
117
+ // has already replaced them). This is a load-bearing coupling with the
118
+ // duplicate validators' message format: MSL-R005/R006/I007/I008 all embed
119
+ // the offending token wrapped in single quotes (`'<token>'`), and the
120
+ // containment check below keys on that exact `'${t}'` shape. If any of
121
+ // those producers stops single-quoting the token, the generic duplicate
122
+ // would leak through alongside the MSL-R014 — `corpus_test.ts` pins all
123
+ // four codes to this contract.
122
124
  if (GENERIC_DUP_CODES.has(d.code) &&
123
125
  [...collidedTokens].some((t) => d.message.includes(`'${t}'`))) {
124
126
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftsys/markspec",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Markdown flavor and toolchain for traceable industrial documentation",
5
5
  "keywords": [
6
6
  "markdown",
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @module core/collect
3
+ *
4
+ * Project-entry collection: discover every MarkSpec-relevant file under a
5
+ * root and parse it into a flat `Entry[]`. The single source of truth for
6
+ * "the set of entries whose trace edges the lockfile pins" — shared by
7
+ * `markspec lock` (the pinner) and its checkers (`compile`, `fmt`, `doctor`)
8
+ * so they cannot disagree on which files count. Previously each of those
9
+ * commands hand-rolled the same discover→parse loop (a `cli/commands/lock.ts`
10
+ * private helper the others reached into), which had to stay byte-identical
11
+ * by hand or the lockfile edge-hash comparison would drift spuriously.
12
+ */
13
+ import type { Entry } from "../model/mod.js";
14
+ import { type DiscoveryIO } from "../discovery/mod.js";
15
+ /** Options for {@linkcode collectProjectEntries}. */
16
+ export interface CollectOptions {
17
+ /** Gitignore-syntax patterns (e.g. `project.yaml` `exclude:`), anchored at
18
+ * `root`. Applied after `.gitignore` rules. Defaults to none. */
19
+ readonly exclude?: readonly string[];
20
+ }
21
+ /**
22
+ * Walk `root` via {@linkcode discoverFiles} — relying on its default
23
+ * extension set (`RELEVANT_EXTENSIONS`), the parity point every caller
24
+ * depends on — and parse each discovered file, returning the flattened
25
+ * entry list. Unreadable files are skipped. Parse diagnostics are not
26
+ * surfaced here: this collector exists to give the lockfile pinner and its
27
+ * checkers one definition of the file set; callers that need diagnostics
28
+ * re-parse.
29
+ *
30
+ * @param io Injected filesystem surface (keeps `core/` Node-compatible; CLI
31
+ * entry points pass a Deno-backed implementation).
32
+ */
33
+ export declare function collectProjectEntries(root: string, io: DiscoveryIO, opts?: CollectOptions): Promise<Entry[]>;
34
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/collect/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtE,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC7B;qEACiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,WAAW,EACf,IAAI,GAAE,cAAmB,GACxB,OAAO,CAAC,KAAK,EAAE,CAAC,CASlB"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/collect
4
+ *
5
+ * Project-entry collection: discover every MarkSpec-relevant file under a
6
+ * root and parse it into a flat `Entry[]`. The single source of truth for
7
+ * "the set of entries whose trace edges the lockfile pins" — shared by
8
+ * `markspec lock` (the pinner) and its checkers (`compile`, `fmt`, `doctor`)
9
+ * so they cannot disagree on which files count. Previously each of those
10
+ * commands hand-rolled the same discover→parse loop (a `cli/commands/lock.ts`
11
+ * private helper the others reached into), which had to stay byte-identical
12
+ * by hand or the lockfile edge-hash comparison would drift spuriously.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.collectProjectEntries = collectProjectEntries;
16
+ const mod_js_1 = require("../discovery/mod.js");
17
+ const mod_js_2 = require("../parser/mod.js");
18
+ /**
19
+ * Walk `root` via {@linkcode discoverFiles} — relying on its default
20
+ * extension set (`RELEVANT_EXTENSIONS`), the parity point every caller
21
+ * depends on — and parse each discovered file, returning the flattened
22
+ * entry list. Unreadable files are skipped. Parse diagnostics are not
23
+ * surfaced here: this collector exists to give the lockfile pinner and its
24
+ * checkers one definition of the file set; callers that need diagnostics
25
+ * re-parse.
26
+ *
27
+ * @param io Injected filesystem surface (keeps `core/` Node-compatible; CLI
28
+ * entry points pass a Deno-backed implementation).
29
+ */
30
+ async function collectProjectEntries(root, io, opts = {}) {
31
+ const out = [];
32
+ for await (const file of (0, mod_js_1.discoverFiles)(root, io, { exclude: opts.exclude })) {
33
+ const content = await io.readFile(file);
34
+ if (content === undefined)
35
+ continue;
36
+ const result = await (0, mod_js_2.parseFile)(content, { file });
37
+ out.push(...result.entries);
38
+ }
39
+ return out;
40
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGX,MAAM,iBAAiB,CAAC;AA2BzB,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAGrB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAc/D;AAmSD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,cAAc,CAAC;CAC/C;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AA2BD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,CA8Nd;AA4DD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAmB/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,EAAE,GACtB,SAAS,EAAE,CA2Bb;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,MAAM,GACb,MAAM,CAKR;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAcR;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA2B5C"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGX,MAAM,iBAAiB,CAAC;AA2BzB,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAGrB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAc/D;AAmSD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,cAAc,CAAC;CAC/C;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AA2BD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,CAgQd;AA4DD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAmB/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,EAAE,GACtB,SAAS,EAAE,CA2Bb;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,MAAM,GACb,MAAM,CAKR;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAcR;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA2B5C"}
@@ -423,11 +423,39 @@ function format(markdown, options) {
423
423
  for (const entry of sorted) {
424
424
  const indent = (entry.location.column - 1) + 2;
425
425
  let attrs = [...entry.rawAttributes];
426
+ const titleLineIdx = entry.location.line - 1;
427
+ // #686: a title that soft-wraps onto extra physical lines is a single
428
+ // Markdown paragraph, but the line-based passes here and in
429
+ // `emitBodyViaAst` (which takes `titleLineIdx + 1` as the body start)
430
+ // assume the title occupies one physical line. Collapse the wrapped
431
+ // title onto a single line so Id stamping and body splicing land on the
432
+ // right lines and the continuation is not clobbered or dropped. The
433
+ // parser already folded the title text on the model side; this repairs
434
+ // the raw buffer to match. The scan runs from the title line to the
435
+ // first blank line (the title/body separator), bounded above by the
436
+ // attribute block so a malformed entry with no blank line before its
437
+ // trailer cannot swallow it.
438
+ if (titleLineIdx >= 0 && titleLineIdx < lines.length) {
439
+ const attrRange = findAttributeBlockRange(lines, entry.location.line, indent);
440
+ const limit = attrRange ? attrRange.start : lines.length;
441
+ let titleEnd = titleLineIdx;
442
+ while (titleEnd + 1 < limit && lines[titleEnd + 1].trim() !== "") {
443
+ titleEnd++;
444
+ }
445
+ if (titleEnd > titleLineIdx) {
446
+ const collapsed = lines[titleLineIdx].replace(/\s+$/, "") + " " +
447
+ lines
448
+ .slice(titleLineIdx + 1, titleEnd + 1)
449
+ .map((l) => l.trim())
450
+ .join(" ");
451
+ lines.splice(titleLineIdx, titleEnd - titleLineIdx + 1, collapsed);
452
+ changed = true;
453
+ }
454
+ }
426
455
  // Title-line bullet canonicalisation per spec §3.2: rewrite `*`
427
456
  // or `+` to `-`. The list-item position from the parser is the
428
457
  // line carrying the bullet marker; we only touch the marker
429
458
  // character itself, leaving the rest of the title alone.
430
- const titleLineIdx = entry.location.line - 1;
431
459
  if (titleLineIdx >= 0 && titleLineIdx < lines.length) {
432
460
  const titleLine = lines[titleLineIdx];
433
461
  const markerCol = entry.location.column - 1;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @module core/gates
3
+ *
4
+ * Composite-`check` gate stages (ADR-027). Each function is a pure,
5
+ * independently-testable transformation from already-gathered inputs to a
6
+ * `Diagnostic[]`; the CLI `check` command orchestrates them (gather inputs →
7
+ * call stages → merge diagnostics → render) and owns the scope policy that
8
+ * decides whether they run at all (project-wide only).
9
+ *
10
+ * Extracted from `cli/commands/check.ts` (#659) so the diagnostic-producing
11
+ * logic lives in `core` — composable, unit-testable in isolation, and reusable
12
+ * by future surfaces — rather than inline in the command body. The command
13
+ * keeps the I/O it must do (loading the Markdown prose formatter, reading
14
+ * `markspec.lock`) and feeds the results in.
15
+ *
16
+ * `gates` is a top-level composition layer: it depends on `formatter`,
17
+ * `parser`, `refs`, `lock`, and `lint`, and nothing in those depends back on
18
+ * it — no cycle.
19
+ */
20
+ import type { Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
21
+ import type { ProseFormatter } from "../formatter/dprint.js";
22
+ import { type LockEdge, type ParseLockfileResult } from "../lock/mod.js";
23
+ /**
24
+ * Format-drift gate — the `MSL-F010` (formatter drift) and `MSL-F011`
25
+ * (reference-canonicalization drift) findings.
26
+ *
27
+ * Runs the SAME `format() → parse → canonicalizeRefs` sequence `markspec fmt`
28
+ * performs, from the same exclude-aware corpus, so bare `check` and
29
+ * `fmt --check` never disagree on what "formatted" means. `MSL-F010` is pure
30
+ * formatter drift; `MSL-F011` is reference-canonicalization drift (a ULID or
31
+ * stale display ID `fmt` would rewrite) — kept distinct so the author knows
32
+ * which fmt concern fired. Markdown only — `markspec fmt` never rewrites source
33
+ * files, so the caller passes only Markdown file contents.
34
+ *
35
+ * @param mdContents Markdown file path → current on-disk content.
36
+ * @param entries The full parsed entry set (project + corpus). Only
37
+ * project-owned entries (`!e.origin`) build the reference index
38
+ * `canonicalizeRefs` heals against — `markspec fmt` is corpus-blind (ADR-030).
39
+ * @param ledger The lockfile's `[[edge]]` ULID ledger (`lockfile.edges`, or
40
+ * `[]` when there is no lockfile), threaded into `canonicalizeRefs`.
41
+ * @param formatMarkdownProse The loaded ADR-029 whole-document Markdown
42
+ * formatter, or `undefined` to degrade to entry-only formatting.
43
+ */
44
+ export declare function fmtDriftGate(mdContents: ReadonlyMap<string, string>, entries: readonly Entry[], ledger: readonly LockEdge[], formatMarkdownProse: ProseFormatter | undefined): Promise<Diagnostic[]>;
45
+ /**
46
+ * Lockfile-drift gate — the `MSL-L212` offline traceability-edge drift finding.
47
+ *
48
+ * A malformed lockfile surfaces the parser's own diagnostics unchanged. An
49
+ * intact lockfile is compared against the current graph's canonical edge hash.
50
+ * Offline by design — upstream resolution (network) stays in
51
+ * `markspec lock --check`.
52
+ *
53
+ * Corpus-blind by design: the lockfile is not corpus-aware yet (ADR-030 defers
54
+ * lockfile integration), so `markspec lock` never counts corpus edges. Counting
55
+ * them here would raise an `MSL-L212` drift error that `markspec lock` can never
56
+ * fix — a consumer gate must not fail on upstream content the consumer cannot
57
+ * re-lock. The gate therefore filters to project-owned entries (`!e.origin`),
58
+ * mirroring `markspec lock`.
59
+ *
60
+ * @param lockParse The parsed `markspec.lock` (already read from disk).
61
+ * @param lockPath Absolute path to `markspec.lock`, used as the diagnostic
62
+ * location so JSON consumers that group by `location.file` keep the finding.
63
+ * @param entries The full parsed entry set; corpus entries are filtered out.
64
+ */
65
+ export declare function lockfileDriftGate(lockParse: ParseLockfileResult, lockPath: string, entries: readonly Entry[]): Promise<Diagnostic[]>;
66
+ /**
67
+ * Prose-lint gate — the advisory `MSL-Q` prose-analysis findings, projected to
68
+ * plain {@linkcode Diagnostic}s.
69
+ *
70
+ * Pass the FULL entry set (project + corpus) and the active profile.
71
+ * {@linkcode runLint} excludes corpus entries from its output but keeps them in
72
+ * the glossary / `$Identifier` indexes, so a corpus-defined term still silences
73
+ * Q500 in project prose (ADR-030 §D4). The profile threads into `isProseScope`
74
+ * so profile-typed entries are scoped (#675).
75
+ *
76
+ * `runLint`'s {@linkcode LintDiagnostic} carries `slug`/`group`/`score` fields
77
+ * that must not leak into `check`'s stable JSON schema — the result is projected
78
+ * to plain {@linkcode Diagnostic}. `runLint`'s `readFile` option (for glossary
79
+ * file indexing) is not needed here: `check` passes no `glossaryFilePaths`.
80
+ */
81
+ export declare function proseLintGate(entries: readonly Entry[], profile: EffectiveProfile | undefined): Promise<Diagnostic[]>;
82
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/gates/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACzB,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,mBAAmB,EAAE,cAAc,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAuCvB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,KAAK,EAAE,GACxB,OAAO,CAAC,UAAU,EAAE,CAAC,CAiBvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvB"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/gates
4
+ *
5
+ * Composite-`check` gate stages (ADR-027). Each function is a pure,
6
+ * independently-testable transformation from already-gathered inputs to a
7
+ * `Diagnostic[]`; the CLI `check` command orchestrates them (gather inputs →
8
+ * call stages → merge diagnostics → render) and owns the scope policy that
9
+ * decides whether they run at all (project-wide only).
10
+ *
11
+ * Extracted from `cli/commands/check.ts` (#659) so the diagnostic-producing
12
+ * logic lives in `core` — composable, unit-testable in isolation, and reusable
13
+ * by future surfaces — rather than inline in the command body. The command
14
+ * keeps the I/O it must do (loading the Markdown prose formatter, reading
15
+ * `markspec.lock`) and feeds the results in.
16
+ *
17
+ * `gates` is a top-level composition layer: it depends on `formatter`,
18
+ * `parser`, `refs`, `lock`, and `lint`, and nothing in those depends back on
19
+ * it — no cycle.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.fmtDriftGate = fmtDriftGate;
23
+ exports.lockfileDriftGate = lockfileDriftGate;
24
+ exports.proseLintGate = proseLintGate;
25
+ const mod_js_1 = require("../formatter/mod.js");
26
+ const mod_js_2 = require("../parser/mod.js");
27
+ const mod_js_3 = require("../refs/mod.js");
28
+ const mod_js_4 = require("../lock/mod.js");
29
+ const mod_js_5 = require("../lint/mod.js");
30
+ /**
31
+ * Format-drift gate — the `MSL-F010` (formatter drift) and `MSL-F011`
32
+ * (reference-canonicalization drift) findings.
33
+ *
34
+ * Runs the SAME `format() → parse → canonicalizeRefs` sequence `markspec fmt`
35
+ * performs, from the same exclude-aware corpus, so bare `check` and
36
+ * `fmt --check` never disagree on what "formatted" means. `MSL-F010` is pure
37
+ * formatter drift; `MSL-F011` is reference-canonicalization drift (a ULID or
38
+ * stale display ID `fmt` would rewrite) — kept distinct so the author knows
39
+ * which fmt concern fired. Markdown only — `markspec fmt` never rewrites source
40
+ * files, so the caller passes only Markdown file contents.
41
+ *
42
+ * @param mdContents Markdown file path → current on-disk content.
43
+ * @param entries The full parsed entry set (project + corpus). Only
44
+ * project-owned entries (`!e.origin`) build the reference index
45
+ * `canonicalizeRefs` heals against — `markspec fmt` is corpus-blind (ADR-030).
46
+ * @param ledger The lockfile's `[[edge]]` ULID ledger (`lockfile.edges`, or
47
+ * `[]` when there is no lockfile), threaded into `canonicalizeRefs`.
48
+ * @param formatMarkdownProse The loaded ADR-029 whole-document Markdown
49
+ * formatter, or `undefined` to degrade to entry-only formatting.
50
+ */
51
+ async function fmtDriftGate(mdContents, entries, ledger, formatMarkdownProse) {
52
+ const diagnostics = [];
53
+ // Corpus-blind by design (ADR-030): `markspec fmt` never loads the delivered
54
+ // corpus, so it can only canonicalize references into project-owned entries.
55
+ // Building the heal index over the full set (including corpus) would flag an
56
+ // MSL-F011 drift that `fmt` can never fix — a permanently red gate for any
57
+ // consumer using a delivered corpus. Filter to `!e.origin`, mirroring
58
+ // lockfileDriftGate.
59
+ const refIndex = (0, mod_js_3.buildRefIndex)(entries.filter((e) => !e.origin));
60
+ for (const [filePath, content] of mdContents) {
61
+ const formatted = (0, mod_js_1.format)(content, {
62
+ file: filePath,
63
+ formatMarkdownProse,
64
+ });
65
+ if (formatted.changed) {
66
+ diagnostics.push({
67
+ code: "MSL-F010",
68
+ severity: "error",
69
+ message: "file is not formatted (run `markspec fmt`)",
70
+ location: { file: filePath, line: 1, column: 1 },
71
+ });
72
+ }
73
+ const parsed = await (0, mod_js_2.parseFile)(formatted.output, { file: filePath });
74
+ const refResult = (0, mod_js_3.canonicalizeRefs)(formatted.output, parsed.entries, refIndex, ledger);
75
+ if (refResult.changed) {
76
+ diagnostics.push({
77
+ code: "MSL-F011",
78
+ severity: "error",
79
+ message: "references are not canonical (run `markspec fmt`)",
80
+ location: { file: filePath, line: 1, column: 1 },
81
+ });
82
+ }
83
+ }
84
+ return diagnostics;
85
+ }
86
+ /**
87
+ * Lockfile-drift gate — the `MSL-L212` offline traceability-edge drift finding.
88
+ *
89
+ * A malformed lockfile surfaces the parser's own diagnostics unchanged. An
90
+ * intact lockfile is compared against the current graph's canonical edge hash.
91
+ * Offline by design — upstream resolution (network) stays in
92
+ * `markspec lock --check`.
93
+ *
94
+ * Corpus-blind by design: the lockfile is not corpus-aware yet (ADR-030 defers
95
+ * lockfile integration), so `markspec lock` never counts corpus edges. Counting
96
+ * them here would raise an `MSL-L212` drift error that `markspec lock` can never
97
+ * fix — a consumer gate must not fail on upstream content the consumer cannot
98
+ * re-lock. The gate therefore filters to project-owned entries (`!e.origin`),
99
+ * mirroring `markspec lock`.
100
+ *
101
+ * @param lockParse The parsed `markspec.lock` (already read from disk).
102
+ * @param lockPath Absolute path to `markspec.lock`, used as the diagnostic
103
+ * location so JSON consumers that group by `location.file` keep the finding.
104
+ * @param entries The full parsed entry set; corpus entries are filtered out.
105
+ */
106
+ async function lockfileDriftGate(lockParse, lockPath, entries) {
107
+ if (!lockParse.lockfile) {
108
+ return [...lockParse.diagnostics];
109
+ }
110
+ const projectEntries = entries.filter((e) => !e.origin);
111
+ const drift = await (0, mod_js_4.detectOfflineEdgeDrift)(projectEntries, lockParse.lockfile.generatedCache);
112
+ if (!drift.drifted)
113
+ return [];
114
+ return [{
115
+ code: "MSL-L212",
116
+ severity: "error",
117
+ message: `traceability edges drifted from markspec.lock: locked ${drift.lockedCount} edge(s), current ${drift.currentCount} — run \`markspec lock\` to refresh. (After upgrading MarkSpec this can also fire once because traceability inputs now include source-file doc comments; re-running \`markspec lock\` clears it.)`,
118
+ location: { file: lockPath, line: 1, column: 1 },
119
+ }];
120
+ }
121
+ /**
122
+ * Prose-lint gate — the advisory `MSL-Q` prose-analysis findings, projected to
123
+ * plain {@linkcode Diagnostic}s.
124
+ *
125
+ * Pass the FULL entry set (project + corpus) and the active profile.
126
+ * {@linkcode runLint} excludes corpus entries from its output but keeps them in
127
+ * the glossary / `$Identifier` indexes, so a corpus-defined term still silences
128
+ * Q500 in project prose (ADR-030 §D4). The profile threads into `isProseScope`
129
+ * so profile-typed entries are scoped (#675).
130
+ *
131
+ * `runLint`'s {@linkcode LintDiagnostic} carries `slug`/`group`/`score` fields
132
+ * that must not leak into `check`'s stable JSON schema — the result is projected
133
+ * to plain {@linkcode Diagnostic}. `runLint`'s `readFile` option (for glossary
134
+ * file indexing) is not needed here: `check` passes no `glossaryFilePaths`.
135
+ */
136
+ async function proseLintGate(entries, profile) {
137
+ const lintResult = await (0, mod_js_5.runLint)({ entries, profile });
138
+ return lintResult.diagnostics.map((d) => ({
139
+ code: d.code,
140
+ severity: d.severity,
141
+ message: d.message,
142
+ location: d.location,
143
+ }));
144
+ }
@@ -6,7 +6,7 @@
6
6
  * suppression hygiene on all Authored entries, applies suppression, and
7
7
  * returns the final diagnostics.
8
8
  */
9
- import type { Entry } from "../model/mod.js";
9
+ import type { EffectiveProfile, Entry } from "../model/mod.js";
10
10
  import type { LintDiagnostic } from "./types.js";
11
11
  import type { FileReader } from "./glossary.js";
12
12
  import type { ScoreRollup } from "./score.js";
@@ -16,10 +16,23 @@ import type { ScoreRollup } from "./score.js";
16
16
  * In-scope: Authored shape AND resolved core type is Specification or
17
17
  * a direct subtype (Requirement, Test, Contract, Record, Risk).
18
18
  * Reference-shape entries are always excluded.
19
+ *
20
+ * `profile` is threaded into {@linkcode resolvedCoreType} so an entry
21
+ * classified purely by a profile type (via `Type:` or a profile
22
+ * display-id pattern, e.g. `platform-component`) resolves to its core
23
+ * ancestor through the profile's `extends:` chain. Without it (#675),
24
+ * such entries never enter prose scope and are silently skipped.
19
25
  */
20
- export declare function isProseScope(entry: Entry): boolean;
26
+ export declare function isProseScope(entry: Entry, profile?: EffectiveProfile): boolean;
21
27
  export interface LintOptions {
22
28
  readonly entries: readonly Entry[];
29
+ /**
30
+ * Active profile, threaded into {@linkcode isProseScope} so entries
31
+ * classified purely by a profile type enter prose scope (#675). Optional:
32
+ * callers with no profile (e.g. file-local prose scoring) pass nothing and
33
+ * only core-resolvable types are scoped.
34
+ */
35
+ readonly profile?: EffectiveProfile;
23
36
  /** Profile-extended capitalized-allow lexicon. Defaults to core baseline. */
24
37
  readonly capitalizedAllow?: ReadonlySet<string>;
25
38
  /** Glossary file paths discovered by the listing-directive validator. */
@@ -34,8 +47,18 @@ export interface LintResult {
34
47
  /**
35
48
  * Run the lint pipeline on a set of entries.
36
49
  *
50
+ * Corpus handling (ADR-030 §D4): the glossary and `$Identifier` indexes are
51
+ * built from the FULL `entries` set — including delivered-corpus entries — so a
52
+ * term or `$Identifier` defined only in a corpus document still silences Q500
53
+ * in project prose (the additive-enrichment invariant). Prose *diagnostics*,
54
+ * suppression hygiene, and the score roll-up run only on project entries
55
+ * (`entry.origin === undefined`): a consumer cannot fix an upstream profile's
56
+ * prose, so corpus findings are never emitted and never skew the score. Callers
57
+ * therefore pass the merged project + corpus set, not a pre-filtered one.
58
+ *
37
59
  * Pipeline:
38
- * 1. Filter to in-scope entries (Specification subtypes, Authored shape).
60
+ * 1. Filter to in-scope entries (Specification subtypes, Authored shape,
61
+ * non-corpus).
39
62
  * 2. Build glossary index from DefinitionList nodes and glossary files.
40
63
  * 3. Run lexicon rules on each in-scope entry's prose blocks.
41
64
  * 4. Run structural rules on each in-scope entry.
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/lint/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAUjD,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,eAAe,CAAC;AAY/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAgB9C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAKlD;AAMD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAChD,yEAAyE;IACzE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAoBD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CA8EvE"}
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/lint/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAUjD,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,eAAe,CAAC;AAY/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAgB9C;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAKT;AAMD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,6EAA6E;IAC7E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAChD,yEAAyE;IACzE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAoBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CA0FvE"}
@@ -42,11 +42,17 @@ function isSpecificationDescendant(typeName) {
42
42
  * In-scope: Authored shape AND resolved core type is Specification or
43
43
  * a direct subtype (Requirement, Test, Contract, Record, Risk).
44
44
  * Reference-shape entries are always excluded.
45
+ *
46
+ * `profile` is threaded into {@linkcode resolvedCoreType} so an entry
47
+ * classified purely by a profile type (via `Type:` or a profile
48
+ * display-id pattern, e.g. `platform-component`) resolves to its core
49
+ * ancestor through the profile's `extends:` chain. Without it (#675),
50
+ * such entries never enter prose scope and are silently skipped.
45
51
  */
46
- function isProseScope(entry) {
52
+ function isProseScope(entry, profile) {
47
53
  if (entry.shape === "Reference")
48
54
  return false;
49
- const coreType = (0, type_resolution_js_1.resolvedCoreType)(entry);
55
+ const coreType = (0, type_resolution_js_1.resolvedCoreType)(entry, profile);
50
56
  if (!coreType)
51
57
  return false;
52
58
  return isSpecificationDescendant(coreType);
@@ -69,8 +75,18 @@ function disabledCodes(entry) {
69
75
  /**
70
76
  * Run the lint pipeline on a set of entries.
71
77
  *
78
+ * Corpus handling (ADR-030 §D4): the glossary and `$Identifier` indexes are
79
+ * built from the FULL `entries` set — including delivered-corpus entries — so a
80
+ * term or `$Identifier` defined only in a corpus document still silences Q500
81
+ * in project prose (the additive-enrichment invariant). Prose *diagnostics*,
82
+ * suppression hygiene, and the score roll-up run only on project entries
83
+ * (`entry.origin === undefined`): a consumer cannot fix an upstream profile's
84
+ * prose, so corpus findings are never emitted and never skew the score. Callers
85
+ * therefore pass the merged project + corpus set, not a pre-filtered one.
86
+ *
72
87
  * Pipeline:
73
- * 1. Filter to in-scope entries (Specification subtypes, Authored shape).
88
+ * 1. Filter to in-scope entries (Specification subtypes, Authored shape,
89
+ * non-corpus).
74
90
  * 2. Build glossary index from DefinitionList nodes and glossary files.
75
91
  * 3. Run lexicon rules on each in-scope entry's prose blocks.
76
92
  * 4. Run structural rules on each in-scope entry.
@@ -91,18 +107,25 @@ function disabledCodes(entry) {
91
107
  * 14. Return diagnostics and score.
92
108
  */
93
109
  async function runLint(options) {
94
- const { entries } = options;
110
+ const { entries, profile } = options;
95
111
  const allow = options.capitalizedAllow ?? (0, mod_js_2.loadLexicon)("capitalized-allow");
112
+ // Glossary + $Identifier indexes see the FULL entry set (corpus included) so
113
+ // corpus-defined terms/identifiers silence Q500 additively (ADR-030 §D4).
96
114
  const glossary = await (0, glossary_js_1.buildGlossaryIndex)(entries, options.readFile ?? (() => Promise.resolve(undefined)), options.glossaryFilePaths ?? []);
97
115
  // Corpus-scan resolver leg (issue #502, ADR-021 Decision 1). Built once
98
116
  // per invocation; reused across every in-scope entry. Honors the
99
117
  // additive-enrichment invariant — Q500 fires *less* as the resolver
100
118
  // grows, never *more*.
101
119
  const isIdHook = (0, xref_js_1.buildIsIdentifierHook)((0, xref_js_1.buildIdentifierIndex)(entries));
102
- // Steps 1–9: collect diagnostics keyed by entry
120
+ // Steps 1–9: collect diagnostics keyed by entry. Delivered-corpus entries
121
+ // (`entry.origin`) are excluded from rule execution — a consumer cannot fix
122
+ // upstream prose (ADR-030 §D4) — even though they contribute to the indexes
123
+ // above.
103
124
  const inScopeDiags = new Map();
104
125
  for (const entry of entries) {
105
- if (!isProseScope(entry))
126
+ if (entry.origin)
127
+ continue;
128
+ if (!isProseScope(entry, profile))
106
129
  continue;
107
130
  const diags = [];
108
131
  // Step 3: lexicon rules
@@ -121,11 +144,15 @@ async function runLint(options) {
121
144
  diags.push(...(0, passive_js_1.runPassiveRules)(entry));
122
145
  inScopeDiags.set(entry, diags);
123
146
  }
124
- // Step 10: suppression hygiene on all Authored entries
147
+ // Step 10: suppression hygiene on all Authored project entries. Corpus
148
+ // entries are skipped for the same reason as rule execution — hygiene
149
+ // findings located in a corpus file are unfixable by the consumer.
125
150
  const hygieneDiags = [];
126
151
  for (const entry of entries) {
127
152
  if (entry.shape !== "Authored")
128
153
  continue;
154
+ if (entry.origin)
155
+ continue;
129
156
  hygieneDiags.push(...(0, suppression_js_1.runSuppressionRules)(entry));
130
157
  }
131
158
  // Step 11: apply suppression to in-scope diagnostics; track matched codes
@@ -155,7 +182,10 @@ async function runLint(options) {
155
182
  }
156
183
  // Append hygiene diagnostics (Q900/Q901 — never suppressed)
157
184
  out.push(...hygieneDiags);
158
- // Step 13: compute score roll-up across all entries (including 0-score ones).
159
- const score = (0, score_js_1.computeScoreRollup)(out, entries);
185
+ // Step 13: compute score roll-up across project entries (including 0-score
186
+ // ones). Corpus entries are excluded — counting them would skew band-counts
187
+ // and the mean on prose a consumer cannot act on (ADR-030 §D4). A no-op when
188
+ // no corpus is present.
189
+ const score = (0, score_js_1.computeScoreRollup)(out, entries.filter((e) => !e.origin));
160
190
  return { diagnostics: out, score };
161
191
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @module core/lock/edge_drift
3
+ *
4
+ * Offline traceability edge-drift detection: compare the current project
5
+ * graph's canonical edge hash against a lockfile's generated-cache. Pure,
6
+ * offline (no upstream resolution) — the single source of truth shared by
7
+ * `check`'s MSL-L212 gate and `doctor`'s lock-drift health check so the two
8
+ * can never disagree on what "drift" means.
9
+ */
10
+ import type { Entry } from "../model/mod.js";
11
+ import type { GeneratedCache } from "./model.js";
12
+ /** Result of the offline (no-network) edge-hash drift comparison. */
13
+ export interface OfflineEdgeDrift {
14
+ /** True when the current canonical edge hash differs from the lockfile. */
15
+ readonly drifted: boolean;
16
+ /** Edge count recorded in the lockfile's generated-cache. */
17
+ readonly lockedCount: number;
18
+ /** Edge count in the current project graph. */
19
+ readonly currentCount: number;
20
+ }
21
+ /**
22
+ * Compare the current project graph's canonical edge hash against a
23
+ * lockfile's generated-cache. Offline by design — no upstream resolution.
24
+ *
25
+ * `projectEntries` MUST already exclude delivered-corpus entries (ADR-030
26
+ * corpus-blindness); the caller filters `!e.origin`, mirroring how
27
+ * `markspec lock` and `check`'s MSL-L212 gate count only project-owned
28
+ * edges.
29
+ */
30
+ export declare function detectOfflineEdgeDrift(projectEntries: readonly Entry[], cache: GeneratedCache): Promise<OfflineEdgeDrift>;
31
+ //# sourceMappingURL=edge_drift.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge_drift.d.ts","sourceRoot":"","sources":["../../src/lock/edge_drift.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,qEAAqE;AACrE,MAAM,WAAW,gBAAgB;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,cAAc,EAAE,SAAS,KAAK,EAAE,EAChC,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,gBAAgB,CAAC,CAQ3B"}