@driftsys/markspec 0.9.0 → 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 (131) 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/compiler/mod.d.ts +7 -0
  5. package/esm/compiler/mod.d.ts.map +1 -1
  6. package/esm/compiler/mod.js +17 -3
  7. package/esm/compiler/schema.d.ts +8 -1
  8. package/esm/compiler/schema.d.ts.map +1 -1
  9. package/esm/compiler/schema.js +8 -1
  10. package/esm/formatter/dprint.d.ts +62 -0
  11. package/esm/formatter/dprint.d.ts.map +1 -0
  12. package/esm/formatter/dprint.js +83 -0
  13. package/esm/formatter/md_equiv.d.ts +24 -0
  14. package/esm/formatter/md_equiv.d.ts.map +1 -0
  15. package/esm/formatter/md_equiv.js +81 -0
  16. package/esm/formatter/mod.d.ts +25 -0
  17. package/esm/formatter/mod.d.ts.map +1 -1
  18. package/esm/formatter/mod.js +135 -7
  19. package/esm/formatter/prose.d.ts +48 -0
  20. package/esm/formatter/prose.d.ts.map +1 -0
  21. package/esm/formatter/prose.js +85 -0
  22. package/esm/gates/mod.d.ts +82 -0
  23. package/esm/gates/mod.d.ts.map +1 -0
  24. package/esm/gates/mod.js +139 -0
  25. package/esm/lint/runner.d.ts +26 -3
  26. package/esm/lint/runner.d.ts.map +1 -1
  27. package/esm/lint/runner.js +39 -9
  28. package/esm/lock/edge_drift.d.ts +31 -0
  29. package/esm/lock/edge_drift.d.ts.map +1 -0
  30. package/esm/lock/edge_drift.js +29 -0
  31. package/esm/lock/mod.d.ts +2 -0
  32. package/esm/lock/mod.d.ts.map +1 -1
  33. package/esm/lock/mod.js +1 -0
  34. package/esm/mod.d.ts +16 -7
  35. package/esm/mod.d.ts.map +1 -1
  36. package/esm/mod.js +13 -4
  37. package/esm/model/mod.d.ts +27 -1
  38. package/esm/model/mod.d.ts.map +1 -1
  39. package/esm/model/mod.js +10 -0
  40. package/esm/model/profile.d.ts +42 -0
  41. package/esm/model/profile.d.ts.map +1 -1
  42. package/esm/parser/markdown.d.ts.map +1 -1
  43. package/esm/parser/markdown.js +38 -11
  44. package/esm/profile/chain.js +1 -0
  45. package/esm/profile/delivered.d.ts +48 -0
  46. package/esm/profile/delivered.d.ts.map +1 -0
  47. package/esm/profile/delivered.js +103 -0
  48. package/esm/profile/manifest.d.ts +1 -0
  49. package/esm/profile/manifest.d.ts.map +1 -1
  50. package/esm/profile/manifest.js +107 -0
  51. package/esm/profile/merge.d.ts.map +1 -1
  52. package/esm/profile/merge.js +22 -0
  53. package/esm/refs/mod.d.ts.map +1 -1
  54. package/esm/refs/mod.js +22 -0
  55. package/esm/reporter/mod.d.ts.map +1 -1
  56. package/esm/reporter/mod.js +16 -4
  57. package/esm/util/fence.d.ts +8 -0
  58. package/esm/util/fence.d.ts.map +1 -1
  59. package/esm/util/fence.js +22 -0
  60. package/esm/validator/corpus.d.ts +25 -0
  61. package/esm/validator/corpus.d.ts.map +1 -0
  62. package/esm/validator/corpus.js +140 -0
  63. package/esm/validator/mod.d.ts +2 -0
  64. package/esm/validator/mod.d.ts.map +1 -1
  65. package/esm/validator/mod.js +1 -0
  66. package/package.json +3 -1
  67. package/script/collect/mod.d.ts +34 -0
  68. package/script/collect/mod.d.ts.map +1 -0
  69. package/script/collect/mod.js +40 -0
  70. package/script/compiler/mod.d.ts +7 -0
  71. package/script/compiler/mod.d.ts.map +1 -1
  72. package/script/compiler/mod.js +16 -2
  73. package/script/compiler/schema.d.ts +8 -1
  74. package/script/compiler/schema.d.ts.map +1 -1
  75. package/script/compiler/schema.js +8 -1
  76. package/script/formatter/dprint.d.ts +62 -0
  77. package/script/formatter/dprint.d.ts.map +1 -0
  78. package/script/formatter/dprint.js +120 -0
  79. package/script/formatter/md_equiv.d.ts +24 -0
  80. package/script/formatter/md_equiv.d.ts.map +1 -0
  81. package/script/formatter/md_equiv.js +87 -0
  82. package/script/formatter/mod.d.ts +25 -0
  83. package/script/formatter/mod.d.ts.map +1 -1
  84. package/script/formatter/mod.js +135 -6
  85. package/script/formatter/prose.d.ts +48 -0
  86. package/script/formatter/prose.d.ts.map +1 -0
  87. package/script/formatter/prose.js +88 -0
  88. package/script/gates/mod.d.ts +82 -0
  89. package/script/gates/mod.d.ts.map +1 -0
  90. package/script/gates/mod.js +144 -0
  91. package/script/lint/runner.d.ts +26 -3
  92. package/script/lint/runner.d.ts.map +1 -1
  93. package/script/lint/runner.js +39 -9
  94. package/script/lock/edge_drift.d.ts +31 -0
  95. package/script/lock/edge_drift.d.ts.map +1 -0
  96. package/script/lock/edge_drift.js +32 -0
  97. package/script/lock/mod.d.ts +2 -0
  98. package/script/lock/mod.d.ts.map +1 -1
  99. package/script/lock/mod.js +3 -1
  100. package/script/mod.d.ts +16 -7
  101. package/script/mod.d.ts.map +1 -1
  102. package/script/mod.js +56 -29
  103. package/script/model/mod.d.ts +27 -1
  104. package/script/model/mod.d.ts.map +1 -1
  105. package/script/model/mod.js +11 -0
  106. package/script/model/profile.d.ts +42 -0
  107. package/script/model/profile.d.ts.map +1 -1
  108. package/script/parser/markdown.d.ts.map +1 -1
  109. package/script/parser/markdown.js +38 -11
  110. package/script/profile/chain.js +1 -0
  111. package/script/profile/delivered.d.ts +48 -0
  112. package/script/profile/delivered.d.ts.map +1 -0
  113. package/script/profile/delivered.js +109 -0
  114. package/script/profile/manifest.d.ts +1 -0
  115. package/script/profile/manifest.d.ts.map +1 -1
  116. package/script/profile/manifest.js +108 -1
  117. package/script/profile/merge.d.ts.map +1 -1
  118. package/script/profile/merge.js +22 -0
  119. package/script/refs/mod.d.ts.map +1 -1
  120. package/script/refs/mod.js +22 -0
  121. package/script/reporter/mod.d.ts.map +1 -1
  122. package/script/reporter/mod.js +16 -4
  123. package/script/util/fence.d.ts +8 -0
  124. package/script/util/fence.d.ts.map +1 -1
  125. package/script/util/fence.js +23 -0
  126. package/script/validator/corpus.d.ts +25 -0
  127. package/script/validator/corpus.d.ts.map +1 -0
  128. package/script/validator/corpus.js +144 -0
  129. package/script/validator/mod.d.ts +2 -0
  130. package/script/validator/mod.d.ts.map +1 -1
  131. package/script/validator/mod.js +4 -1
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @module core/validator/corpus
3
+ *
4
+ * Corpus-aware diagnostic post-pass (ADR-030). Two responsibilities:
5
+ *
6
+ * 1. {@linkcode detectCorpusCollisions} — a project entry re-declaring a
7
+ * display ID (or Id) owned by a delivered corpus entry is MSL-R014, a
8
+ * distinct code from MSL-R006 because the fix is different: rename the
9
+ * project entry; the corpus entry is not yours to change.
10
+ * 2. {@linkcode attributeCorpusDiagnostics} — consumer builds must not go
11
+ * red from upstream bugs they cannot fix: findings located inside a
12
+ * corpus file are downgraded to warnings and attributed to the
13
+ * delivering profile; generic duplicate codes are suppressed for
14
+ * collided tokens (MSL-R014 replaces them).
15
+ */
16
+ import type { Diagnostic, Entry } from "../model/mod.js";
17
+ /** Result of {@linkcode detectCorpusCollisions}. */
18
+ export interface CorpusCollisionResult {
19
+ readonly diagnostics: readonly Diagnostic[];
20
+ /** Display-ID / Id tokens involved in a project↔corpus collision. */
21
+ readonly collidedTokens: ReadonlySet<string>;
22
+ }
23
+ export declare function detectCorpusCollisions(allEntries: readonly Entry[]): CorpusCollisionResult;
24
+ export declare function attributeCorpusDiagnostics(diagnostics: readonly Diagnostic[], allEntries: readonly Entry[], collidedTokens: ReadonlySet<string>): Diagnostic[];
25
+ //# sourceMappingURL=corpus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"corpus.d.ts","sourceRoot":"","sources":["../../src/validator/corpus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAWzD,oDAAoD;AACpD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,KAAK,EAAE,GAC3B,qBAAqB,CAoFvB;AAED,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,UAAU,EAAE,SAAS,KAAK,EAAE,EAC5B,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,UAAU,EAAE,CAmCd"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @module core/validator/corpus
3
+ *
4
+ * Corpus-aware diagnostic post-pass (ADR-030). Two responsibilities:
5
+ *
6
+ * 1. {@linkcode detectCorpusCollisions} — a project entry re-declaring a
7
+ * display ID (or Id) owned by a delivered corpus entry is MSL-R014, a
8
+ * distinct code from MSL-R006 because the fix is different: rename the
9
+ * project entry; the corpus entry is not yours to change.
10
+ * 2. {@linkcode attributeCorpusDiagnostics} — consumer builds must not go
11
+ * red from upstream bugs they cannot fix: findings located inside a
12
+ * corpus file are downgraded to warnings and attributed to the
13
+ * delivering profile; generic duplicate codes are suppressed for
14
+ * collided tokens (MSL-R014 replaces them).
15
+ */
16
+ import { formatEntryOrigin } from "../model/mod.js";
17
+ /** Generic duplicate detectors superseded by MSL-R014 for corpus collisions. */
18
+ const GENERIC_DUP_CODES = new Set([
19
+ "MSL-R005",
20
+ "MSL-R006",
21
+ "MSL-I007",
22
+ "MSL-I008",
23
+ ]);
24
+ export function detectCorpusCollisions(allEntries) {
25
+ const corpusByDisplayId = new Map();
26
+ const corpusById = new Map();
27
+ for (const e of allEntries) {
28
+ if (!e.origin)
29
+ continue;
30
+ if (!corpusByDisplayId.has(e.displayId)) {
31
+ corpusByDisplayId.set(e.displayId, e);
32
+ }
33
+ if (e.id && !corpusById.has(e.id))
34
+ corpusById.set(e.id, e);
35
+ }
36
+ if (corpusByDisplayId.size === 0 && corpusById.size === 0) {
37
+ return { diagnostics: [], collidedTokens: new Set() };
38
+ }
39
+ const diagnostics = [];
40
+ const collided = new Set();
41
+ for (const e of allEntries) {
42
+ if (!e.origin) {
43
+ const displayOwner = corpusByDisplayId.get(e.displayId);
44
+ if (displayOwner) {
45
+ collided.add(e.displayId);
46
+ diagnostics.push({
47
+ code: "MSL-R014",
48
+ severity: "error",
49
+ message: `display ID '${e.displayId}' is already delivered by ` +
50
+ `${formatEntryOrigin(displayOwner.origin)}; rename this entry — ` +
51
+ `delivered corpus entries are read-only`,
52
+ location: e.location,
53
+ });
54
+ }
55
+ if (e.id) {
56
+ const idOwner = corpusById.get(e.id);
57
+ if (idOwner) {
58
+ collided.add(e.id);
59
+ diagnostics.push({
60
+ code: "MSL-R014",
61
+ severity: "error",
62
+ message: `Id '${e.id}' is already delivered by ` +
63
+ `${formatEntryOrigin(idOwner.origin)}; rename this entry — ` +
64
+ `delivered corpus entries are read-only`,
65
+ location: e.location,
66
+ });
67
+ }
68
+ }
69
+ continue;
70
+ }
71
+ // Corpus↔corpus inter-tier collision: a later delivered entry from a
72
+ // DIFFERENT profile claims a display ID (or Id) the first-registered
73
+ // profile already owns. Same-profile duplicates are excluded — that's
74
+ // the delivering profile's own authoring bug, not a read-only-boundary
75
+ // violation, and stays on the generic duplicate codes.
76
+ const displayOwner = corpusByDisplayId.get(e.displayId);
77
+ if (displayOwner !== e && displayOwner &&
78
+ displayOwner.origin.profileId !== e.origin.profileId) {
79
+ collided.add(e.displayId);
80
+ diagnostics.push({
81
+ code: "MSL-R014",
82
+ severity: "error",
83
+ message: `display ID '${e.displayId}' is already delivered by ` +
84
+ `${formatEntryOrigin(displayOwner.origin)}; delivered corpus ` +
85
+ `entries are read-only`,
86
+ location: e.location,
87
+ });
88
+ }
89
+ if (e.id) {
90
+ const idOwner = corpusById.get(e.id);
91
+ if (idOwner !== e && idOwner &&
92
+ idOwner.origin.profileId !== e.origin.profileId) {
93
+ collided.add(e.id);
94
+ diagnostics.push({
95
+ code: "MSL-R014",
96
+ severity: "error",
97
+ message: `Id '${e.id}' is already delivered by ` +
98
+ `${formatEntryOrigin(idOwner.origin)}; delivered corpus entries ` +
99
+ `are read-only`,
100
+ location: e.location,
101
+ });
102
+ }
103
+ }
104
+ }
105
+ return { diagnostics, collidedTokens: collided };
106
+ }
107
+ export function attributeCorpusDiagnostics(diagnostics, allEntries, collidedTokens) {
108
+ const corpusFiles = new Map();
109
+ for (const e of allEntries) {
110
+ if (e.origin) {
111
+ corpusFiles.set(e.location.file, formatEntryOrigin(e.origin));
112
+ }
113
+ }
114
+ const out = [];
115
+ for (const d of diagnostics) {
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.
124
+ if (GENERIC_DUP_CODES.has(d.code) &&
125
+ [...collidedTokens].some((t) => d.message.includes(`'${t}'`))) {
126
+ continue;
127
+ }
128
+ const label = d.location ? corpusFiles.get(d.location.file) : undefined;
129
+ if (label !== undefined) {
130
+ out.push({
131
+ ...d,
132
+ severity: d.severity === "error" ? "warning" : d.severity,
133
+ message: `delivered by ${label}: ${d.message}`,
134
+ });
135
+ continue;
136
+ }
137
+ out.push(d);
138
+ }
139
+ return out;
140
+ }
@@ -43,4 +43,6 @@ export { validateValue } from "./value_types.js";
43
43
  export type { ValueValidator } from "./value_types.js";
44
44
  export { normalizeListValues } from "./normalize.js";
45
45
  export { effectiveTraceRules, matchesAnyTarget, validateTraceabilityForEntry, } from "./traceability.js";
46
+ export { attributeCorpusDiagnostics, detectCorpusCollisions, } from "./corpus.js";
47
+ export type { CorpusCollisionResult } from "./corpus.js";
46
48
  //# sourceMappingURL=mod.d.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,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
@@ -474,3 +474,4 @@ export { effectiveScope, validateAttributesForEntry } from "./attributes.js";
474
474
  export { validateValue } from "./value_types.js";
475
475
  export { normalizeListValues } from "./normalize.js";
476
476
  export { effectiveTraceRules, matchesAnyTarget, validateTraceabilityForEntry, } from "./traceability.js";
477
+ export { attributeCorpusDiagnostics, detectCorpusCollisions, } from "./corpus.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftsys/markspec",
3
- "version": "0.9.0",
3
+ "version": "0.10.2",
4
4
  "description": "Markdown flavor and toolchain for traceable industrial documentation",
5
5
  "keywords": [
6
6
  "markdown",
@@ -29,6 +29,8 @@
29
29
  },
30
30
  "scripts": {},
31
31
  "dependencies": {
32
+ "@dprint/formatter": "0.5.1",
33
+ "@dprint/markdown": "0.20.0",
32
34
  "@types/mdast": "^4",
33
35
  "remark-gfm": "^4",
34
36
  "remark-parse": "^11",
@@ -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
+ }
@@ -43,6 +43,13 @@ export interface CompileOptions {
43
43
  * list is deduplicated and sorted for deterministic output.
44
44
  */
45
45
  readonly withContributors?: boolean;
46
+ /**
47
+ * Profile-delivered corpus entries (ADR-030), pre-loaded and
48
+ * origin-stamped by `loadDeliveredCorpus`. Injected AHEAD of project
49
+ * entries so first-entry-wins graph slots resolve to the corpus
50
+ * deterministically. Optional — absent means no corpus.
51
+ */
52
+ readonly corpusEntries?: readonly Entry[];
46
53
  }
47
54
  /** Compiled project output with resolved traceability graph. */
48
55
  export interface CompileResult {
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,KAAK,EAEL,IAAI,EAEL,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAOjE,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,qGAAqG;IACrG,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAClB,IAAI,EAAE,MAAM,KACT,OAAO,CAAC;QAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACjD;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CACjB,IAAI,EAAE,MAAM,KACT,OAAO,CACV;QACE,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;QACjC,QAAQ,CAAC,EAAE,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AI,EAAE,CAAC,CAAC;IAC1D,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAC1D,4GAA4G;IAC5G,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClD,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC;AA4BD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CAgMxB;AA+ED,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EACV,uBAAuB,EACvB,eAAe,EACf,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC"}
@@ -114,7 +114,7 @@ class Semaphore {
114
114
  */
115
115
  async function compile(paths, options) {
116
116
  const read = options.readFile;
117
- const allEntries = [];
117
+ const allEntries = [...(options.corpusEntries ?? [])];
118
118
  const parseDiagnostics = [];
119
119
  const documents = new Map();
120
120
  // Phase 1: Read and parse all files with bounded concurrency (16 slots).
@@ -242,11 +242,25 @@ async function compile(paths, options) {
242
242
  // diagnostics are already included in validationDiagnostics, so we discard
243
243
  // them to avoid duplicates in the output.
244
244
  const { registry: typeRegistry } = (0, mod_js_4.validateTypl)([...entries.values()]);
245
- const diagnostics = [
245
+ let diagnostics = [
246
246
  ...parseDiagnostics,
247
247
  ...validationDiagnostics,
248
248
  ...linkTargetDiags,
249
249
  ];
250
+ // Phase 5: Corpus-aware diagnostic post-pass (ADR-030). A project entry
251
+ // that reuses a display ID or Id already delivered by a corpus is
252
+ // MSL-R014, not the generic MSL-R005/R006/I007/I008 duplicate codes —
253
+ // and findings located inside a corpus file are downgraded to
254
+ // attributed warnings so consumer builds don't go red over upstream
255
+ // bugs they cannot fix. No-op (and zero allocation beyond the spread
256
+ // above) when no corpus was injected.
257
+ if (options.corpusEntries && options.corpusEntries.length > 0) {
258
+ const collisions = (0, mod_js_3.detectCorpusCollisions)(allEntries);
259
+ diagnostics = [
260
+ ...(0, mod_js_3.attributeCorpusDiagnostics)(diagnostics, allEntries, collisions.collidedTokens),
261
+ ...collisions.diagnostics,
262
+ ];
263
+ }
250
264
  return {
251
265
  entries,
252
266
  links,
@@ -6,7 +6,7 @@
6
6
  * interchange.
7
7
  */
8
8
  import type { CompileResult } from "./mod.js";
9
- import type { Diagnostic, Entry, Link } from "../model/mod.js";
9
+ import type { Diagnostic, Entry, EntryOrigin, Link } from "../model/mod.js";
10
10
  import type { RegistryBinding, RegistryTypedef } from "../typl/mod.js";
11
11
  /**
12
12
  * JSON-serializable form of {@linkcode Entry}.
@@ -14,9 +14,16 @@ import type { RegistryBinding, RegistryTypedef } from "../typl/mod.js";
14
14
  * Identical to `Entry` except `typedAttributes` is a plain
15
15
  * `Record<string, readonly string[]>` instead of a `ReadonlyMap` — Maps are
16
16
  * not JSON-serializable. All other fields are passed through unchanged.
17
+ *
18
+ * `origin` (ADR-030) is restated explicitly here — rather than relying on
19
+ * the `Omit<Entry, ...>` passthrough — so the field-presence contract is
20
+ * documented at the serialization boundary: present verbatim on entries
21
+ * injected from a profile-delivered corpus, absent (not `null`) on
22
+ * project-authored entries.
17
23
  */
18
24
  export type SerializedEntry = Omit<Entry, "typedAttributes"> & {
19
25
  readonly typedAttributes?: Record<string, readonly string[]>;
26
+ readonly origin?: EntryOrigin;
20
27
  };
21
28
  /**
22
29
  * Serialized form of the {@linkcode TypeRegistry}.
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/compiler/schema.ts"],"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AM,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAClD,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAClD,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,sCAAsC;IACtC,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAC;CAC/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,aAAa,GACpB,uBAAuB,CAazB;AAgBD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CA4B5D"}
@@ -61,9 +61,16 @@ function serializeEntry(entry) {
61
61
  const { sync: _sync, ...rest } = properties;
62
62
  properties = Object.keys(rest).length > 0 ? rest : undefined;
63
63
  }
64
+ // Pull `origin` (ADR-030) out of the spread so the key is entirely
65
+ // absent — not `origin: undefined` — on entries that did not come
66
+ // from a delivered corpus, matching the serialized-field-presence
67
+ // contract. Object rest destructuring drops the named key regardless
68
+ // of its value, unlike `...entry` alone.
69
+ const { origin, ...rest } = entry;
64
70
  return {
65
- ...entry,
71
+ ...rest,
66
72
  typedAttributes,
67
73
  properties,
74
+ ...(origin ? { origin } : {}),
68
75
  };
69
76
  }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @module formatter/dprint
3
+ *
4
+ * Loader for the embedded dprint-markdown WASM plugin (ADR-029).
5
+ * `markspec fmt` formats whole Markdown documents with one canonical,
6
+ * zero-config style; this module owns that style and the (cached)
7
+ * WASM instantiation. Dynamic imports keep the plugin off every code
8
+ * path except formatting (`fmt`, the `check` MSL-F010 drift gate, LSP
9
+ * documentFormatting).
10
+ *
11
+ * Node-compatible: `node:fs/promises` + WebAssembly only, no `Deno.*`.
12
+ *
13
+ * Packaging note: `@dprint/formatter` and `@dprint/markdown` are dynamically
14
+ * imported bare npm specifiers, and their `plugin.wasm` ships inside the npm
15
+ * package — no vendored copy in this repo. `deno compile` only embeds the
16
+ * resolved npm tree (and thus the wasm) when the compile entry point itself
17
+ * lives inside this workspace member (`packages/markspec/`); an entry point
18
+ * outside that tree can't resolve the import map at runtime. The project's
19
+ * one real compile target (`packages/markspec/main.ts`) already satisfies
20
+ * this, so it's a non-issue in production — it only bites a from-scratch
21
+ * smoke test placed elsewhere.
22
+ */
23
+ /** Per-call options for a {@linkcode ProseFormatter}. */
24
+ export interface ProseFormatOptions {
25
+ /** Override the effective line width for this fragment. Used by the
26
+ * entry-body polish: bodies are formatted dedented and re-indented
27
+ * afterwards, so the budget must shrink by the indent width to stay
28
+ * in agreement with a whole-file dprint view of the same content. */
29
+ readonly lineWidth?: number;
30
+ }
31
+ /** Formats a Markdown fragment to the canonical MarkSpec style. */
32
+ export type ProseFormatter = (markdown: string, options?: ProseFormatOptions) => string;
33
+ /**
34
+ * The fixed MarkSpec Markdown style (ADR-029). Zero configuration by
35
+ * design — one canonical form across every project. `newLineKind` is
36
+ * "lf" because `format()` operates on a pure-LF buffer and re-applies
37
+ * the file's detected line ending on output.
38
+ */
39
+ export declare const MARKSPEC_MARKDOWN_GLOBAL_CONFIG: Readonly<{
40
+ lineWidth: number;
41
+ newLineKind: "lf";
42
+ }>;
43
+ /** Plugin-level style knobs. See ADR-029 for the rationale per value.
44
+ *
45
+ * Frozen: this is the single canonical MarkSpec style, exported through the
46
+ * public barrel. Freezing stops a consumer from mutating the shared object
47
+ * after the formatter has already baked these values in at `instantiate()`
48
+ * (which would drift the entry-body width budget from the whole-document
49
+ * formatter — see `emitBodyViaAst`). */
50
+ export declare const MARKSPEC_MARKDOWN_PLUGIN_CONFIG: Readonly<Record<string, unknown>>;
51
+ /**
52
+ * Load the dprint-markdown WASM plugin (once — subsequent calls return
53
+ * the cached instance) and return a synchronous prose formatter.
54
+ *
55
+ * A failed instantiation is NOT cached: the rejected promise is cleared
56
+ * before it propagates, so the next call retries from scratch instead of
57
+ * replaying the same failure forever. This matters for the long-lived LSP
58
+ * session, where a transient WASM-load failure must not permanently
59
+ * disable formatting for the rest of the process.
60
+ */
61
+ export declare function loadMarkdownFormatter(): Promise<ProseFormatter>;
62
+ //# sourceMappingURL=dprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dprint.d.ts","sourceRoot":"","sources":["../../src/formatter/dprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yDAAyD;AACzD,MAAM,WAAW,kBAAkB;IACjC;;;yEAGqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,mEAAmE;AACnE,MAAM,MAAM,cAAc,GAAG,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,kBAAkB,KACzB,MAAM,CAAC;AAEZ;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;CACnB,CAGC,CAAC;AAEH;;;;;;wCAMwC;AACxC,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMvB,CAAC;AAIH;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAAC,cAAc,CAAC,CAM/D"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ /**
3
+ * @module formatter/dprint
4
+ *
5
+ * Loader for the embedded dprint-markdown WASM plugin (ADR-029).
6
+ * `markspec fmt` formats whole Markdown documents with one canonical,
7
+ * zero-config style; this module owns that style and the (cached)
8
+ * WASM instantiation. Dynamic imports keep the plugin off every code
9
+ * path except formatting (`fmt`, the `check` MSL-F010 drift gate, LSP
10
+ * documentFormatting).
11
+ *
12
+ * Node-compatible: `node:fs/promises` + WebAssembly only, no `Deno.*`.
13
+ *
14
+ * Packaging note: `@dprint/formatter` and `@dprint/markdown` are dynamically
15
+ * imported bare npm specifiers, and their `plugin.wasm` ships inside the npm
16
+ * package — no vendored copy in this repo. `deno compile` only embeds the
17
+ * resolved npm tree (and thus the wasm) when the compile entry point itself
18
+ * lives inside this workspace member (`packages/markspec/`); an entry point
19
+ * outside that tree can't resolve the import map at runtime. The project's
20
+ * one real compile target (`packages/markspec/main.ts`) already satisfies
21
+ * this, so it's a non-issue in production — it only bites a from-scratch
22
+ * smoke test placed elsewhere.
23
+ */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || (function () {
41
+ var ownKeys = function(o) {
42
+ ownKeys = Object.getOwnPropertyNames || function (o) {
43
+ var ar = [];
44
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
45
+ return ar;
46
+ };
47
+ return ownKeys(o);
48
+ };
49
+ return function (mod) {
50
+ if (mod && mod.__esModule) return mod;
51
+ var result = {};
52
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
53
+ __setModuleDefault(result, mod);
54
+ return result;
55
+ };
56
+ })();
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.MARKSPEC_MARKDOWN_PLUGIN_CONFIG = exports.MARKSPEC_MARKDOWN_GLOBAL_CONFIG = void 0;
59
+ exports.loadMarkdownFormatter = loadMarkdownFormatter;
60
+ /**
61
+ * The fixed MarkSpec Markdown style (ADR-029). Zero configuration by
62
+ * design — one canonical form across every project. `newLineKind` is
63
+ * "lf" because `format()` operates on a pure-LF buffer and re-applies
64
+ * the file's detected line ending on output.
65
+ */
66
+ exports.MARKSPEC_MARKDOWN_GLOBAL_CONFIG = Object.freeze({
67
+ lineWidth: 80,
68
+ newLineKind: "lf",
69
+ });
70
+ /** Plugin-level style knobs. See ADR-029 for the rationale per value.
71
+ *
72
+ * Frozen: this is the single canonical MarkSpec style, exported through the
73
+ * public barrel. Freezing stops a consumer from mutating the shared object
74
+ * after the formatter has already baked these values in at `instantiate()`
75
+ * (which would drift the entry-body width budget from the whole-document
76
+ * formatter — see `emitBodyViaAst`). */
77
+ exports.MARKSPEC_MARKDOWN_PLUGIN_CONFIG = Object.freeze({
78
+ textWrap: "always",
79
+ emphasisKind: "underscores",
80
+ strongKind: "asterisks",
81
+ unorderedListKind: "dashes",
82
+ });
83
+ let cached;
84
+ /**
85
+ * Load the dprint-markdown WASM plugin (once — subsequent calls return
86
+ * the cached instance) and return a synchronous prose formatter.
87
+ *
88
+ * A failed instantiation is NOT cached: the rejected promise is cleared
89
+ * before it propagates, so the next call retries from scratch instead of
90
+ * replaying the same failure forever. This matters for the long-lived LSP
91
+ * session, where a transient WASM-load failure must not permanently
92
+ * disable formatting for the rest of the process.
93
+ */
94
+ function loadMarkdownFormatter() {
95
+ cached ??= instantiate().catch((err) => {
96
+ cached = undefined;
97
+ throw err;
98
+ });
99
+ return cached;
100
+ }
101
+ async function instantiate() {
102
+ const { createFromBuffer } = await Promise.resolve().then(() => __importStar(require("@dprint/formatter")));
103
+ const { getPath } = await Promise.resolve().then(() => __importStar(require("@dprint/markdown")));
104
+ const { readFile } = await Promise.resolve().then(() => __importStar(require("node:fs/promises")));
105
+ const wasm = await readFile(getPath());
106
+ // `readFile` returns a Node `Buffer`, whose `buffer` property is typed
107
+ // `ArrayBufferLike` (may be a `SharedArrayBuffer`) — not assignable to
108
+ // `BufferSource`'s `ArrayBuffer`-backed view. Copy into a plain
109
+ // `Uint8Array` so the type is unambiguous; this runs once per process
110
+ // (the result is cached by `loadMarkdownFormatter`).
111
+ const formatter = createFromBuffer(Uint8Array.from(wasm));
112
+ formatter.setConfig(exports.MARKSPEC_MARKDOWN_GLOBAL_CONFIG, exports.MARKSPEC_MARKDOWN_PLUGIN_CONFIG);
113
+ return (markdown, options) => formatter.formatText({
114
+ filePath: "fragment.md",
115
+ fileText: markdown,
116
+ overrideConfig: options?.lineWidth !== undefined
117
+ ? { lineWidth: options.lineWidth }
118
+ : undefined,
119
+ });
120
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module formatter/md_equiv
3
+ *
4
+ * CommonMark-semantic Markdown equivalence — the gate for the ADR-029
5
+ * dprint pass. Two fragments are equivalent when they parse to the
6
+ * same mdast structure after eliding source `position`s and collapsing
7
+ * ASCII whitespace runs inside `text` node values. Only ASCII
8
+ * whitespace is collapsed — NBSP (U+00A0) and Unicode spaces are
9
+ * content, not wrap artifacts, and must not compare equal to a plain
10
+ * space. Soft-wrap positions,
11
+ * emphasis delimiter style (`*x*` vs `_x_`), table cell padding, and
12
+ * list marker style are presentation, not content — they compare
13
+ * equal. Hard breaks are `break` nodes in mdast, so wrap-collapsing
14
+ * cannot erase or fabricate one. Code (`code`, `inlineCode`), `html`,
15
+ * and definition `url`s stay byte-exact.
16
+ *
17
+ * DELIBERATELY weaker than ADR-015's `astEquivalent` (byte-verbatim on
18
+ * inline markup). Used ONLY to accept/reject dprint output; the
19
+ * ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
20
+ * not be modified.
21
+ */
22
+ /** True when `a` and `b` are the same Markdown, modulo presentation. */
23
+ export declare function markdownSemanticallyEquivalent(a: string, b: string): boolean;
24
+ //# sourceMappingURL=md_equiv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"md_equiv.d.ts","sourceRoot":"","sources":["../../src/formatter/md_equiv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAQH,wEAAwE;AACxE,wBAAgB,8BAA8B,CAC5C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAMT"}