@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
@@ -11,6 +11,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.corpusOriginLabel = corpusOriginLabel;
12
12
  exports.buildCorpusIndex = buildCorpusIndex;
13
13
  exports.loadDeliveredCorpus = loadDeliveredCorpus;
14
+ exports.deliveredPathIsContained = deliveredPathIsContained;
15
+ const path_1 = require("@std/path");
14
16
  const mod_js_1 = require("../parser/mod.js");
15
17
  /** Human-facing label of a delivered document's providing tier. */
16
18
  function corpusOriginLabel(doc) {
@@ -29,10 +31,21 @@ function buildCorpusIndex(delivers) {
29
31
  * `delivers` in order (parent-first + manifest order — the deterministic
30
32
  * injection order), so the returned entry order is stable across runs.
31
33
  */
32
- async function loadDeliveredCorpus(delivers, readFile) {
34
+ async function loadDeliveredCorpus(delivers, readFile, realPath) {
33
35
  const entries = [];
34
36
  const diagnostics = [];
35
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
+ }
36
49
  const content = await readFile(doc.absPath);
37
50
  if (content === undefined) {
38
51
  diagnostics.push({
@@ -63,3 +76,34 @@ async function loadDeliveredCorpus(delivers, readFile) {
63
76
  }
64
77
  return { entries, diagnostics };
65
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
+ }
@@ -535,6 +535,7 @@ function deliveredFromTier(tier) {
535
535
  profileVersion: tier.version,
536
536
  path: d.path,
537
537
  absPath: (0, path_1.join)(tier.baseDir, d.path),
538
+ baseDir: tier.baseDir,
538
539
  corpus: d.corpus,
539
540
  description: d.description,
540
541
  }));
@@ -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
  *
@@ -52,9 +53,7 @@ function filterEntries(result, scope, label) {
52
53
  * Markdown, and JSON rows all agree on the same value.
53
54
  */
54
55
  function originCell(entry) {
55
- return entry.origin
56
- ? `${entry.origin.profileId}@${entry.origin.profileVersion}`
57
- : "project";
56
+ return entry.origin ? (0, mod_js_1.formatEntryOrigin)(entry.origin) : "project";
58
57
  }
59
58
  function buildTraceRows(result, entries) {
60
59
  return entries.map((entry) => {
@@ -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
+ }
@@ -1 +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;AAUzD,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,CAwFvB;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,CAiCd"}
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"}
@@ -17,6 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.detectCorpusCollisions = detectCorpusCollisions;
19
19
  exports.attributeCorpusDiagnostics = attributeCorpusDiagnostics;
20
+ const mod_js_1 = require("../model/mod.js");
20
21
  /** Generic duplicate detectors superseded by MSL-R014 for corpus collisions. */
21
22
  const GENERIC_DUP_CODES = new Set([
22
23
  "MSL-R005",
@@ -50,8 +51,7 @@ function detectCorpusCollisions(allEntries) {
50
51
  code: "MSL-R014",
51
52
  severity: "error",
52
53
  message: `display ID '${e.displayId}' is already delivered by ` +
53
- `${displayOwner.origin.profileId}@` +
54
- `${displayOwner.origin.profileVersion}; rename this entry — ` +
54
+ `${(0, mod_js_1.formatEntryOrigin)(displayOwner.origin)}; rename this entry — ` +
55
55
  `delivered corpus entries are read-only`,
56
56
  location: e.location,
57
57
  });
@@ -64,8 +64,7 @@ function detectCorpusCollisions(allEntries) {
64
64
  code: "MSL-R014",
65
65
  severity: "error",
66
66
  message: `Id '${e.id}' is already delivered by ` +
67
- `${idOwner.origin.profileId}@` +
68
- `${idOwner.origin.profileVersion}; rename this entry — ` +
67
+ `${(0, mod_js_1.formatEntryOrigin)(idOwner.origin)}; rename this entry — ` +
69
68
  `delivered corpus entries are read-only`,
70
69
  location: e.location,
71
70
  });
@@ -86,8 +85,7 @@ function detectCorpusCollisions(allEntries) {
86
85
  code: "MSL-R014",
87
86
  severity: "error",
88
87
  message: `display ID '${e.displayId}' is already delivered by ` +
89
- `${displayOwner.origin.profileId}@` +
90
- `${displayOwner.origin.profileVersion}; delivered corpus ` +
88
+ `${(0, mod_js_1.formatEntryOrigin)(displayOwner.origin)}; delivered corpus ` +
91
89
  `entries are read-only`,
92
90
  location: e.location,
93
91
  });
@@ -101,8 +99,7 @@ function detectCorpusCollisions(allEntries) {
101
99
  code: "MSL-R014",
102
100
  severity: "error",
103
101
  message: `Id '${e.id}' is already delivered by ` +
104
- `${idOwner.origin.profileId}@` +
105
- `${idOwner.origin.profileVersion}; delivered corpus entries ` +
102
+ `${(0, mod_js_1.formatEntryOrigin)(idOwner.origin)}; delivered corpus entries ` +
106
103
  `are read-only`,
107
104
  location: e.location,
108
105
  });
@@ -115,14 +112,19 @@ function attributeCorpusDiagnostics(diagnostics, allEntries, collidedTokens) {
115
112
  const corpusFiles = new Map();
116
113
  for (const e of allEntries) {
117
114
  if (e.origin) {
118
- corpusFiles.set(e.location.file, `${e.origin.profileId}@${e.origin.profileVersion}`);
115
+ corpusFiles.set(e.location.file, (0, mod_js_1.formatEntryOrigin)(e.origin));
119
116
  }
120
117
  }
121
118
  const out = [];
122
119
  for (const d of diagnostics) {
123
- // Suppress the generic duplicate codes for corpus collisions; the
124
- // validator embeds the offending token in single quotes, which is what
125
- // this containment check keys on.
120
+ // Suppress the generic duplicate codes for a corpus collision (MSL-R014
121
+ // has already replaced them). This is a load-bearing coupling with the
122
+ // duplicate validators' message format: MSL-R005/R006/I007/I008 all embed
123
+ // the offending token wrapped in single quotes (`'<token>'`), and the
124
+ // containment check below keys on that exact `'${t}'` shape. If any of
125
+ // those producers stops single-quoting the token, the generic duplicate
126
+ // would leak through alongside the MSL-R014 — `corpus_test.ts` pins all
127
+ // four codes to this contract.
126
128
  if (GENERIC_DUP_CODES.has(d.code) &&
127
129
  [...collidedTokens].some((t) => d.message.includes(`'${t}'`))) {
128
130
  continue;