@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,109 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/profile/delivered
4
+ *
5
+ * Loader for profile-delivered documents (ADR-030). Checks every delivered
6
+ * file's existence (PROFILE-DELIVERS-001/002), parses the `corpus: true`
7
+ * files, and stamps each parsed entry with its profile origin. Pure — all
8
+ * I/O via the injected {@linkcode ReadFile}.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.corpusOriginLabel = corpusOriginLabel;
12
+ exports.buildCorpusIndex = buildCorpusIndex;
13
+ exports.loadDeliveredCorpus = loadDeliveredCorpus;
14
+ exports.deliveredPathIsContained = deliveredPathIsContained;
15
+ const path_1 = require("@std/path");
16
+ const mod_js_1 = require("../parser/mod.js");
17
+ /** Human-facing label of a delivered document's providing tier. */
18
+ function corpusOriginLabel(doc) {
19
+ return `${doc.profileId}@${doc.profileVersion}`;
20
+ }
21
+ /** Index delivered documents by absolute path — used by CLI/LSP callers to
22
+ * recognise corpus locations when rendering diagnostics. */
23
+ function buildCorpusIndex(delivers) {
24
+ const out = new Map();
25
+ for (const d of delivers)
26
+ out.set(d.absPath, d);
27
+ return out;
28
+ }
29
+ /**
30
+ * Load the delivered corpus of an effective profile chain. Iterates
31
+ * `delivers` in order (parent-first + manifest order — the deterministic
32
+ * injection order), so the returned entry order is stable across runs.
33
+ */
34
+ async function loadDeliveredCorpus(delivers, readFile, realPath) {
35
+ const entries = [];
36
+ const diagnostics = [];
37
+ for (const doc of delivers) {
38
+ if (realPath && !(await deliveredPathIsContained(doc, realPath))) {
39
+ diagnostics.push({
40
+ code: "PROFILE-DELIVERS-005",
41
+ severity: "error",
42
+ message: `delivered ${doc.corpus ? "corpus" : "document"} file ` +
43
+ `'${doc.path}' declared by ${corpusOriginLabel(doc)} resolves ` +
44
+ `outside the profile package (symlink escape) and was not read`,
45
+ location: { file: doc.absPath, line: 1, column: 1 },
46
+ });
47
+ continue;
48
+ }
49
+ const content = await readFile(doc.absPath);
50
+ if (content === undefined) {
51
+ diagnostics.push({
52
+ code: doc.corpus ? "PROFILE-DELIVERS-001" : "PROFILE-DELIVERS-002",
53
+ severity: doc.corpus ? "error" : "warning",
54
+ message: `delivered ${doc.corpus ? "corpus" : "document"} file ` +
55
+ `'${doc.path}' declared by ${corpusOriginLabel(doc)} is missing ` +
56
+ `from the profile package`,
57
+ location: { file: doc.absPath, line: 1, column: 1 },
58
+ });
59
+ continue;
60
+ }
61
+ if (!doc.corpus)
62
+ continue; // docs-only: existence check only, never parsed
63
+ const parsed = await (0, mod_js_1.parseFile)(content, { file: doc.absPath });
64
+ for (const d of parsed.diagnostics) {
65
+ diagnostics.push({
66
+ ...d,
67
+ message: `delivered by ${corpusOriginLabel(doc)}: ${d.message}`,
68
+ });
69
+ }
70
+ const origin = {
71
+ kind: "profile",
72
+ profileId: doc.profileId,
73
+ profileVersion: doc.profileVersion,
74
+ };
75
+ entries.push(...parsed.entries.map((e) => ({ ...e, origin })));
76
+ }
77
+ return { entries, diagnostics };
78
+ }
79
+ /**
80
+ * True when `doc`'s real (symlink-resolved) path stays within its profile's
81
+ * `baseDir` — the delivered-path containment guard (#699). A malicious profile
82
+ * (pulled via `extends: git+…`, which preserves symlinks) can deliver a `.md`
83
+ * that is actually a symlink to an arbitrary local file (`~/.ssh/id_rsa`); the
84
+ * string-level path checks (PROFILE-DELIVERS-003/004) validate the declared
85
+ * path, not the symlink target, so a real-path containment check is the only
86
+ * thing that stops the read.
87
+ *
88
+ * Degrades to `true` (allow) when the doc carries no `baseDir` or when the
89
+ * paths cannot be canonicalised (e.g. the file is missing) — a missing file is
90
+ * left to the existing PROFILE-DELIVERS-001/002 checks. Shared by the MCP
91
+ * `readDeliveredDocument` read path, which faces the same vector.
92
+ */
93
+ async function deliveredPathIsContained(doc, realPath) {
94
+ if (doc.baseDir === undefined)
95
+ return true;
96
+ let realBase;
97
+ let realTarget;
98
+ try {
99
+ realBase = await realPath(doc.baseDir);
100
+ realTarget = await realPath(doc.absPath);
101
+ }
102
+ catch {
103
+ return true; // unresolvable (e.g. missing) — handled by 001/002 downstream
104
+ }
105
+ if (realTarget === realBase)
106
+ return true;
107
+ const prefix = realBase.endsWith(path_1.SEPARATOR) ? realBase : realBase + path_1.SEPARATOR;
108
+ return realTarget.startsWith(prefix);
109
+ }
@@ -11,6 +11,7 @@ export declare const ALLOWED_PROFILE_KEYS: Set<string>;
11
11
  export declare const ALLOWED_TYPE_KEYS: Set<string>;
12
12
  export declare const ALLOWED_DOC_TYPE_KEYS: Set<string>;
13
13
  export declare const ALLOWED_DOCUMENTS_KEYS: Set<string>;
14
+ export declare const ALLOWED_DELIVERS_KEYS: Set<string>;
14
15
  export declare const ALLOWED_ATTR_KEYS: Set<string>;
15
16
  export declare const ALLOWED_INVERSE_KEYS: Set<string>;
16
17
  export declare const ALLOWED_TRACE_RULE_KEYS: Set<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA6BnE,eAAO,MAAM,iBAAiB,aAS5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAU/B,CAAC;AAEH,eAAO,MAAM,iBAAiB,aAU5B,CAAC;AAEH,eAAO,MAAM,qBAAqB,aAA6C,CAAC;AAChF,eAAO,MAAM,sBAAsB,aAAoC,CAAC;AAExE,eAAO,MAAM,iBAAiB,aAQ5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAAgC,CAAC;AAElE,eAAO,MAAM,uBAAuB,aAKlC,CAAC;AAEH,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AA2tCD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CA+LrB"}
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA8BnE,eAAO,MAAM,iBAAiB,aAS5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAW/B,CAAC;AAEH,eAAO,MAAM,iBAAiB,aAU5B,CAAC;AAEH,eAAO,MAAM,qBAAqB,aAA6C,CAAC;AAChF,eAAO,MAAM,sBAAsB,aAAoC,CAAC;AACxE,eAAO,MAAM,qBAAqB,aAA6C,CAAC;AAEhF,eAAO,MAAM,iBAAiB,aAQ5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAAgC,CAAC;AAElE,eAAO,MAAM,uBAAuB,aAKlC,CAAC;AAEH,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAq0CD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CAyMrB"}
@@ -7,7 +7,7 @@
7
7
  * schema violations.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ALLOWED_TRACE_RULE_KEYS = exports.ALLOWED_INVERSE_KEYS = exports.ALLOWED_ATTR_KEYS = exports.ALLOWED_DOCUMENTS_KEYS = exports.ALLOWED_DOC_TYPE_KEYS = exports.ALLOWED_TYPE_KEYS = exports.ALLOWED_PROFILE_KEYS = exports.ALLOWED_ROOT_KEYS = void 0;
10
+ exports.ALLOWED_TRACE_RULE_KEYS = exports.ALLOWED_INVERSE_KEYS = exports.ALLOWED_ATTR_KEYS = exports.ALLOWED_DELIVERS_KEYS = exports.ALLOWED_DOCUMENTS_KEYS = exports.ALLOWED_DOC_TYPE_KEYS = exports.ALLOWED_TYPE_KEYS = exports.ALLOWED_PROFILE_KEYS = exports.ALLOWED_ROOT_KEYS = void 0;
11
11
  exports.parseManifest = parseManifest;
12
12
  const yaml_1 = require("@std/yaml");
13
13
  const mod_js_1 = require("../model/mod.js");
@@ -30,6 +30,7 @@ exports.ALLOWED_PROFILE_KEYS = new Set([
30
30
  "conventions",
31
31
  "types",
32
32
  "documents",
33
+ "delivers",
33
34
  "kinds",
34
35
  "prose",
35
36
  "discipline-mode",
@@ -47,6 +48,7 @@ exports.ALLOWED_TYPE_KEYS = new Set([
47
48
  ]);
48
49
  exports.ALLOWED_DOC_TYPE_KEYS = new Set(["id", "contains", "description"]);
49
50
  exports.ALLOWED_DOCUMENTS_KEYS = new Set(["types", "frontMatter"]);
51
+ exports.ALLOWED_DELIVERS_KEYS = new Set(["path", "corpus", "description"]);
50
52
  exports.ALLOWED_ATTR_KEYS = new Set([
51
53
  "name",
52
54
  "type",
@@ -1098,6 +1100,106 @@ function parseDocumentsSection(raw, sourcePath, diagnostics) {
1098
1100
  const frontMatter = parseAttrList(r.frontMatter, "profile.documents.frontMatter", sourcePath, diagnostics);
1099
1101
  return { types, frontMatter };
1100
1102
  }
1103
+ function parseDeliversSection(raw, sourcePath, diagnostics) {
1104
+ if (raw === undefined)
1105
+ return [];
1106
+ const loc = { file: sourcePath, line: 1, column: 1 };
1107
+ if (!Array.isArray(raw)) {
1108
+ diagnostics.push({
1109
+ code: "PROFILE-LOAD-003",
1110
+ severity: "error",
1111
+ message: `profile.delivers: must be a list`,
1112
+ location: loc,
1113
+ });
1114
+ return [];
1115
+ }
1116
+ const out = [];
1117
+ const seenPaths = new Set();
1118
+ for (const item of raw) {
1119
+ if (item == null || typeof item !== "object" || Array.isArray(item)) {
1120
+ diagnostics.push({
1121
+ code: "PROFILE-LOAD-003",
1122
+ severity: "error",
1123
+ message: `profile.delivers: each item must be a mapping`,
1124
+ location: loc,
1125
+ });
1126
+ continue;
1127
+ }
1128
+ const r = item;
1129
+ for (const key of Object.keys(r)) {
1130
+ if (!exports.ALLOWED_DELIVERS_KEYS.has(key)) {
1131
+ diagnostics.push({
1132
+ code: "PROFILE-LOAD-003",
1133
+ severity: "error",
1134
+ message: `profile.delivers: unknown key '${key}'`,
1135
+ location: loc,
1136
+ });
1137
+ }
1138
+ }
1139
+ const path = r.path;
1140
+ if (typeof path !== "string" || path.trim().length === 0) {
1141
+ diagnostics.push({
1142
+ code: "PROFILE-LOAD-003",
1143
+ severity: "error",
1144
+ message: `profile.delivers: item missing required 'path' (string)`,
1145
+ location: loc,
1146
+ });
1147
+ continue;
1148
+ }
1149
+ // PROFILE-DELIVERS-003 — the path must stay inside the profile
1150
+ // directory: no absolute paths (POSIX or drive-letter), no `..`.
1151
+ const normalized = path.replaceAll("\\", "/");
1152
+ if (normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) ||
1153
+ normalized.split("/").includes("..")) {
1154
+ diagnostics.push({
1155
+ code: "PROFILE-DELIVERS-003",
1156
+ severity: "error",
1157
+ message: `profile.delivers: path '${path}' escapes the profile ` +
1158
+ `directory (absolute paths and '..' segments are not allowed)`,
1159
+ location: loc,
1160
+ });
1161
+ continue;
1162
+ }
1163
+ if (r.corpus !== undefined && typeof r.corpus !== "boolean") {
1164
+ diagnostics.push({
1165
+ code: "PROFILE-LOAD-003",
1166
+ severity: "error",
1167
+ message: `profile.delivers: 'corpus' must be a boolean`,
1168
+ location: loc,
1169
+ });
1170
+ continue;
1171
+ }
1172
+ const corpus = r.corpus === true;
1173
+ if (corpus && !normalized.toLowerCase().endsWith(".md")) {
1174
+ diagnostics.push({
1175
+ code: "PROFILE-DELIVERS-004",
1176
+ severity: "error",
1177
+ message: `profile.delivers: 'corpus: true' requires a Markdown ` +
1178
+ `(.md) file, got '${path}'`,
1179
+ location: loc,
1180
+ });
1181
+ continue;
1182
+ }
1183
+ if (seenPaths.has(normalized)) {
1184
+ diagnostics.push({
1185
+ code: "PROFILE-LOAD-003",
1186
+ severity: "error",
1187
+ message: `profile.delivers: duplicate path '${path}'`,
1188
+ location: loc,
1189
+ });
1190
+ continue;
1191
+ }
1192
+ seenPaths.add(normalized);
1193
+ out.push({
1194
+ path: normalized,
1195
+ corpus,
1196
+ description: typeof r.description === "string"
1197
+ ? r.description
1198
+ : undefined,
1199
+ });
1200
+ }
1201
+ return out;
1202
+ }
1101
1203
  /**
1102
1204
  * Parse and validate a raw markspec.yaml string.
1103
1205
  *
@@ -1211,6 +1313,10 @@ function parseManifest(rawYaml, sourcePath = "<markspec.yaml>") {
1211
1313
  if (diagnostics.some((d) => d.severity === "error")) {
1212
1314
  return { manifest: null, diagnostics };
1213
1315
  }
1316
+ const delivers = parseDeliversSection(profileSection.delivers, sourcePath, diagnostics);
1317
+ if (diagnostics.some((d) => d.severity === "error")) {
1318
+ return { manifest: null, diagnostics };
1319
+ }
1214
1320
  const prose = parseProse(profileSection.prose, sourcePath, diagnostics);
1215
1321
  if (diagnostics.some((d) => d.severity === "error")) {
1216
1322
  return { manifest: null, diagnostics };
@@ -1240,6 +1346,7 @@ function parseManifest(rawYaml, sourcePath = "<markspec.yaml>") {
1240
1346
  colors,
1241
1347
  types: types,
1242
1348
  documents: documents,
1349
+ delivers,
1243
1350
  kinds,
1244
1351
  prose,
1245
1352
  disciplineMode,
@@ -1 +1 @@
1
- {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/profile/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAEV,UAAU,EAGV,gBAAgB,EAKhB,YAAY,EASb,MAAM,iBAAiB,CAAC;AAGzB,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAiF3D"}
1
+ {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/profile/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAGV,UAAU,EAGV,gBAAgB,EAKhB,YAAY,EASb,MAAM,iBAAiB,CAAC;AAGzB,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAiF3D"}
@@ -10,6 +10,7 @@
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.mergeChain = mergeChain;
13
+ const path_1 = require("@std/path");
13
14
  const mod_js_1 = require("../model/mod.js");
14
15
  const discipline_mode_js_1 = require("./discipline_mode.js");
15
16
  /**
@@ -143,6 +144,13 @@ function foldTier(base, tier, diagnostics) {
143
144
  // Overlap handling deferred.
144
145
  }
145
146
  const frontMatter = unionAttrMap(base.documents.frontMatter, m.documents.frontMatter, origin, diagnostics);
147
+ // Delivered documents — additive union keyed by (profileId, path).
148
+ const delivers = [...base.delivers];
149
+ for (const d of deliveredFromTier(tier)) {
150
+ if (!delivers.some((e) => e.profileId === d.profileId && e.path === d.path)) {
151
+ delivers.push(d);
152
+ }
153
+ }
146
154
  // Prose lexicons: list-additive across tiers (profile-schema §5.1).
147
155
  const capAllow = unionList(base.prose.lexicons["capitalized-allow"], m.prose.lexicons["capitalized-allow"], origin);
148
156
  const sentAbbrev = unionList(base.prose.lexicons["sentence-abbrev"], m.prose.lexicons["sentence-abbrev"], origin);
@@ -156,6 +164,7 @@ function foldTier(base, tier, diagnostics) {
156
164
  types: docTypes,
157
165
  frontMatter,
158
166
  },
167
+ delivers,
159
168
  kinds,
160
169
  prose: {
161
170
  lexicons: {
@@ -519,6 +528,18 @@ function stringifyMatcher(m) {
519
528
  // ---------------------------------------------------------------------------
520
529
  // Helpers: construct an EffectiveProfile from a single tier's manifest.
521
530
  // ---------------------------------------------------------------------------
531
+ /** Resolve a tier's `delivers:` declarations against its baseDir (ADR-030). */
532
+ function deliveredFromTier(tier) {
533
+ return tier.manifest.delivers.map((d) => ({
534
+ profileId: tier.id,
535
+ profileVersion: tier.version,
536
+ path: d.path,
537
+ absPath: (0, path_1.join)(tier.baseDir, d.path),
538
+ baseDir: tier.baseDir,
539
+ corpus: d.corpus,
540
+ description: d.description,
541
+ }));
542
+ }
522
543
  function seedFromTier(tier) {
523
544
  const origin = tier.id;
524
545
  const m = tier.manifest;
@@ -532,6 +553,7 @@ function seedFromTier(tier) {
532
553
  types: mapFromDocTypes(m.documents.types, origin),
533
554
  frontMatter: mapFromAttrList(m.documents.frontMatter, origin),
534
555
  },
556
+ delivers: deliveredFromTier(tier),
535
557
  kinds: mapFromKinds(m.kinds, origin),
536
558
  prose: {
537
559
  lexicons: {
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/refs/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,QAAQ,CAajE;AAcD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,SAAS,QAAQ,EAAE,GAC1B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CA4FtC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/refs/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,QAAQ,CAajE;AAcD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,SAAS,QAAQ,EAAE,GAC1B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAgHtC"}
@@ -17,6 +17,7 @@ exports.TRACE_ATTRIBUTE_KEYS = void 0;
17
17
  exports.buildRefIndex = buildRefIndex;
18
18
  exports.canonicalizeRefs = canonicalizeRefs;
19
19
  const mod_js_1 = require("../model/mod.js");
20
+ const fence_js_1 = require("../util/fence.js");
20
21
  /**
21
22
  * Trace-attribute keys whose values are canonicalised/healed: the core
22
23
  * relations plus `Verified-by`. Derived from {@linkcode CORE_RELATIONS} so new
@@ -89,12 +90,25 @@ function canonicalizeRefs(content, entries, index, ledger) {
89
90
  };
90
91
  const lines = content.split("\n");
91
92
  let changed = false;
93
+ // Track fenced-code regions so illustrative trailers inside ``` / ~~~
94
+ // blocks (e.g. `Realizes: 01HGW...` in a ```markdown example) are never
95
+ // "healed" against the real ref index — the same verbatim-region rule
96
+ // every other fmt pass honors (§5.1; cf. `collapseBlankLines`). Without
97
+ // this, `markspec fmt` rewrites example IDs in spec/ADR docs on every run
98
+ // (#668). The parser/validator already treat fenced content as inert.
99
+ let inFence = false;
92
100
  for (let i = 0; i < lines.length; i++) {
93
101
  // Strip a trailing CR before matching so CRLF files are handled (the
94
102
  // trailer regex ends in `$`, which `\r` would block) and re-append it on
95
103
  // rewrite so line endings stay byte-for-byte lossless.
96
104
  const cr = lines[i].endsWith("\r");
97
105
  const bare = cr ? lines[i].slice(0, -1) : lines[i];
106
+ if (fence_js_1.FENCE_RE.test(bare)) {
107
+ inFence = !inFence;
108
+ continue;
109
+ }
110
+ if (inFence)
111
+ continue;
98
112
  const m = TRACE_TRAILER_RE.exec(bare);
99
113
  if (!m)
100
114
  continue;
@@ -121,6 +135,14 @@ function canonicalizeRefs(content, entries, index, ledger) {
121
135
  j++;
122
136
  const crj = lines[j].endsWith("\r");
123
137
  const barej = crj ? lines[j].slice(0, -1) : lines[j];
138
+ // A fence marker is never continuation text. An indented one (e.g.
139
+ // ` ```md`) would otherwise match CONTINUATION_LINE_RE and be
140
+ // swallowed here without toggling `inFence`, desyncing fence tracking
141
+ // for the rest of the file. Back out and let the outer loop toggle it.
142
+ if (fence_js_1.FENCE_RE.test(barej)) {
143
+ j--;
144
+ break;
145
+ }
124
146
  const cm = CONTINUATION_LINE_RE.exec(barej);
125
147
  if (!cm) {
126
148
  j--; // not a continuation line — leave it for the outer loop
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/reporter/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,8BAA8B;AAC9B,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;AAErD,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,qBAAqB;IACrB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAO5E"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/reporter/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAIxD,8BAA8B;AAC9B,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;AAErD,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,qBAAqB;IACrB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAO5E"}
@@ -7,6 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.report = report;
10
+ const mod_js_1 = require("../model/mod.js");
10
11
  /**
11
12
  * Generate a report from compiled traceability graph.
12
13
  *
@@ -45,6 +46,15 @@ function filterEntries(result, scope, label) {
45
46
  }
46
47
  return entries;
47
48
  }
49
+ /**
50
+ * Render an entry's provenance cell (ADR-030): `<profileId>@<profileVersion>`
51
+ * for an entry injected from a profile-delivered corpus, `"project"` for a
52
+ * project-authored entry. Shared by the traceability matrix builder so CSV,
53
+ * Markdown, and JSON rows all agree on the same value.
54
+ */
55
+ function originCell(entry) {
56
+ return entry.origin ? (0, mod_js_1.formatEntryOrigin)(entry.origin) : "project";
57
+ }
48
58
  function buildTraceRows(result, entries) {
49
59
  return entries.map((entry) => {
50
60
  const fwd = result.forward.get(entry.displayId) ?? [];
@@ -53,6 +63,7 @@ function buildTraceRows(result, entries) {
53
63
  id: entry.displayId,
54
64
  title: entry.title,
55
65
  entryType: entry.type ?? "",
66
+ origin: originCell(entry),
56
67
  satisfies: fwd
57
68
  .filter((l) => l.kind === "satisfies")
58
69
  .map((l) => l.to)
@@ -70,20 +81,21 @@ function formatTraceability(result, entries, format) {
70
81
  return JSON.stringify(rows, null, 2);
71
82
  }
72
83
  if (format === "csv") {
73
- const header = "ID,Title,Type,Satisfies,Satisfied-by";
84
+ const header = "ID,Title,Type,Origin,Satisfies,Satisfied-by";
74
85
  const lines = rows.map((r) => [
75
86
  r.id,
76
87
  csvEscape(r.title),
77
88
  r.entryType,
89
+ csvEscape(r.origin),
78
90
  csvEscape(r.satisfies),
79
91
  csvEscape(r.satisfiedBy),
80
92
  ].join(","));
81
93
  return [header, ...lines].join("\n");
82
94
  }
83
95
  // Markdown table
84
- const header = "| ID | Title | Type | Satisfies | Satisfied-by |";
85
- const sep = "| -- | ----- | ---- | --------- | ------------ |";
86
- const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} |`);
96
+ const header = "| ID | Title | Type | Origin | Satisfies | Satisfied-by |";
97
+ const sep = "| -- | ----- | ---- | ------ | --------- | ------------ |";
98
+ const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.origin} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} |`);
87
99
  return [header, sep, ...lines].join("\n");
88
100
  }
89
101
  function computeCoverage(result, entries) {
@@ -27,4 +27,12 @@ export type ProseLineCallback = (line: string, index: number) => void;
27
27
  * skipped (they're structural, not prose).
28
28
  */
29
29
  export declare function walkProseLines(body: string, cb: ProseLineCallback): void;
30
+ /**
31
+ * Return whether `lineIndex` (0-based) is a line {@linkcode walkProseLines}
32
+ * would skip — either a fence-marker line itself, or content inside a
33
+ * fenced block. Single-line-membership counterpart to `walkProseLines`'s
34
+ * full-body callback walk, for callers that only need a yes/no answer for
35
+ * one position (e.g. an LSP request gating a cursor position, #680).
36
+ */
37
+ export declare function isLineFenced(body: string, lineIndex: number): boolean;
30
38
  //# sourceMappingURL=fence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/util/fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,gEAAgE;AAChE,eAAO,MAAM,QAAQ,QAAkB,CAAC;AAExC,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAYxE"}
1
+ {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/util/fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,gEAAgE;AAChE,eAAO,MAAM,QAAQ,QAAkB,CAAC;AAExC,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAYxE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAYrE"}
@@ -20,6 +20,7 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.FENCE_RE = void 0;
22
22
  exports.walkProseLines = walkProseLines;
23
+ exports.isLineFenced = isLineFenced;
23
24
  /** Three or more backticks or tildes at the start of a line. */
24
25
  exports.FENCE_RE = /^\s*(```|~~~)/;
25
26
  /**
@@ -42,3 +43,25 @@ function walkProseLines(body, cb) {
42
43
  cb(line, i);
43
44
  }
44
45
  }
46
+ /**
47
+ * Return whether `lineIndex` (0-based) is a line {@linkcode walkProseLines}
48
+ * would skip — either a fence-marker line itself, or content inside a
49
+ * fenced block. Single-line-membership counterpart to `walkProseLines`'s
50
+ * full-body callback walk, for callers that only need a yes/no answer for
51
+ * one position (e.g. an LSP request gating a cursor position, #680).
52
+ */
53
+ function isLineFenced(body, lineIndex) {
54
+ const lines = body.split("\n");
55
+ let inFence = false;
56
+ for (let i = 0; i <= lineIndex && i < lines.length; i++) {
57
+ if (exports.FENCE_RE.test(lines[i])) {
58
+ inFence = !inFence;
59
+ if (i === lineIndex)
60
+ return true;
61
+ continue;
62
+ }
63
+ if (i === lineIndex)
64
+ return inFence;
65
+ }
66
+ return false;
67
+ }
@@ -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"}