@driftsys/markspec 0.7.2 → 0.7.3

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 (95) hide show
  1. package/esm/config/markspec.d.ts +17 -0
  2. package/esm/config/markspec.d.ts.map +1 -1
  3. package/esm/config/markspec.js +30 -1
  4. package/esm/lock/mod.d.ts +2 -2
  5. package/esm/lock/mod.d.ts.map +1 -1
  6. package/esm/lock/mod.js +1 -1
  7. package/esm/lock/model.d.ts +25 -0
  8. package/esm/lock/model.d.ts.map +1 -1
  9. package/esm/lock/parser.d.ts.map +1 -1
  10. package/esm/lock/parser.js +20 -0
  11. package/esm/lock/resolve.d.ts +19 -1
  12. package/esm/lock/resolve.d.ts.map +1 -1
  13. package/esm/lock/resolve.js +47 -1
  14. package/esm/lock/serializer.d.ts.map +1 -1
  15. package/esm/lock/serializer.js +31 -0
  16. package/esm/mod.d.ts +9 -7
  17. package/esm/mod.d.ts.map +1 -1
  18. package/esm/mod.js +6 -4
  19. package/esm/model/mod.d.ts +16 -0
  20. package/esm/model/mod.d.ts.map +1 -1
  21. package/esm/model/mod.js +16 -0
  22. package/esm/profile/display_id.d.ts +78 -25
  23. package/esm/profile/display_id.d.ts.map +1 -1
  24. package/esm/profile/display_id.js +164 -26
  25. package/esm/profile/manifest.d.ts.map +1 -1
  26. package/esm/profile/manifest.js +19 -0
  27. package/esm/profile/mod.d.ts +2 -2
  28. package/esm/profile/mod.d.ts.map +1 -1
  29. package/esm/profile/mod.js +1 -1
  30. package/esm/refs/mod.d.ts +43 -0
  31. package/esm/refs/mod.d.ts.map +1 -0
  32. package/esm/refs/mod.js +128 -0
  33. package/esm/validator/mod.d.ts +1 -1
  34. package/esm/validator/mod.d.ts.map +1 -1
  35. package/esm/validator/pattern.d.ts +47 -13
  36. package/esm/validator/pattern.d.ts.map +1 -1
  37. package/esm/validator/pattern.js +91 -41
  38. package/esm/validator/pipeline.d.ts +15 -1
  39. package/esm/validator/pipeline.d.ts.map +1 -1
  40. package/esm/validator/pipeline.js +16 -7
  41. package/esm/validator/traceability.d.ts +6 -3
  42. package/esm/validator/traceability.d.ts.map +1 -1
  43. package/esm/validator/traceability.js +23 -5
  44. package/esm/validator/types.d.ts.map +1 -1
  45. package/esm/validator/types.js +10 -4
  46. package/esm/validator/value_types.d.ts.map +1 -1
  47. package/esm/validator/value_types.js +4 -2
  48. package/package.json +1 -1
  49. package/script/config/markspec.d.ts +17 -0
  50. package/script/config/markspec.d.ts.map +1 -1
  51. package/script/config/markspec.js +30 -0
  52. package/script/lock/mod.d.ts +2 -2
  53. package/script/lock/mod.d.ts.map +1 -1
  54. package/script/lock/mod.js +2 -1
  55. package/script/lock/model.d.ts +25 -0
  56. package/script/lock/model.d.ts.map +1 -1
  57. package/script/lock/parser.d.ts.map +1 -1
  58. package/script/lock/parser.js +20 -0
  59. package/script/lock/resolve.d.ts +19 -1
  60. package/script/lock/resolve.d.ts.map +1 -1
  61. package/script/lock/resolve.js +47 -0
  62. package/script/lock/serializer.d.ts.map +1 -1
  63. package/script/lock/serializer.js +31 -0
  64. package/script/mod.d.ts +9 -7
  65. package/script/mod.d.ts.map +1 -1
  66. package/script/mod.js +30 -22
  67. package/script/model/mod.d.ts +16 -0
  68. package/script/model/mod.d.ts.map +1 -1
  69. package/script/model/mod.js +17 -1
  70. package/script/profile/display_id.d.ts +78 -25
  71. package/script/profile/display_id.d.ts.map +1 -1
  72. package/script/profile/display_id.js +166 -26
  73. package/script/profile/manifest.d.ts.map +1 -1
  74. package/script/profile/manifest.js +19 -0
  75. package/script/profile/mod.d.ts +2 -2
  76. package/script/profile/mod.d.ts.map +1 -1
  77. package/script/profile/mod.js +2 -1
  78. package/script/refs/mod.d.ts +43 -0
  79. package/script/refs/mod.d.ts.map +1 -0
  80. package/script/refs/mod.js +133 -0
  81. package/script/validator/mod.d.ts +1 -1
  82. package/script/validator/mod.d.ts.map +1 -1
  83. package/script/validator/pattern.d.ts +47 -13
  84. package/script/validator/pattern.d.ts.map +1 -1
  85. package/script/validator/pattern.js +92 -41
  86. package/script/validator/pipeline.d.ts +15 -1
  87. package/script/validator/pipeline.d.ts.map +1 -1
  88. package/script/validator/pipeline.js +16 -7
  89. package/script/validator/traceability.d.ts +6 -3
  90. package/script/validator/traceability.d.ts.map +1 -1
  91. package/script/validator/traceability.js +23 -5
  92. package/script/validator/types.d.ts.map +1 -1
  93. package/script/validator/types.js +9 -3
  94. package/script/validator/value_types.d.ts.map +1 -1
  95. package/script/validator/value_types.js +3 -1
@@ -1,38 +1,91 @@
1
1
  /**
2
2
  * @module core/profile/display_id
3
3
  *
4
- * Shared parser for the `display-id-pattern` template used by profile
5
- * type declarations. Patterns look like:
6
- *
7
- * STK_{n:4d}
8
- * STK_AEB_{n:04d}
9
- * REQ-{n:03d}-draft
10
- *
11
- * The `{n:Nd}` placeholder (with optional leading zero in the Nd
12
- * form) names the sequential number slot. The text before the
13
- * placeholder becomes the literal prefix; the text after becomes the
14
- * literal suffix.
15
- *
16
- * Note: the `{scope}` placeholder documented in the profile schema
17
- * is NOT substituted here — callers handle that separately. For
18
- * patterns containing `{scope}`, the literal text `{scope}` ends up
19
- * in `prefix` (or `suffix`) and must be replaced upstream before the
20
- * pattern is fed to scaffolding.
4
+ * Single source of truth for the `display-id-pattern` template grammar.
5
+ *
6
+ * One tokenizer ({@linkcode tokenizePattern}) and one well-formedness
7
+ * oracle ({@linkcode validateDisplayIdPattern}) back both consumers of the
8
+ * grammar: classification (`compileDisplayIdPattern` in `core/validator`,
9
+ * which builds the recognizer regex) and minting/scaffolding
10
+ * ({@linkcode parseDisplayIdPattern}, which decomposes the numeric slot).
11
+ * Keeping a single grammar here prevents the two from drifting — see #596.
12
+ *
13
+ * A pattern is one of two kinds, selected by whether it contains a counter:
14
+ *
15
+ * numbered := segment+ (exactly one `{n}` counter) — mintable + classifying
16
+ * named := segment+ (literal anchor, ≥1 named, no counter) — classifying
17
+ *
18
+ * counter := "{n}" | "{n:" digits "d}" (e.g. {n}, {n:4d}, {n:04d})
19
+ * named := "{" identifier "}" (e.g. {scope}, {name})
20
+ *
21
+ * The padding digit count is a minimum width; `{n:4d}` and `{n:04d}` are
22
+ * equivalent. A bare `{n}` mints with no zero-padding (width 1).
23
+ *
24
+ * Patterns:
25
+ *
26
+ * STK_{n:4d} → numbered, width 4
27
+ * STK_AEB_{n:04d} → numbered, width 4
28
+ * REQ-{n:03d}-draft → numbered, width 3, suffix "-draft"
29
+ * REQ-{n} → numbered, width 1
30
+ * SWC_{name} → named (classifying only — not mintable)
31
+ *
32
+ * Note: the `{scope}` placeholder documented in the profile schema is NOT
33
+ * substituted here. For a numbered pattern like `XREQ_{scope}_{n:04d}`,
34
+ * the literal `{scope}` text ends up in `prefix` and must be replaced
35
+ * upstream before the pattern is fed to scaffolding.
21
36
  */
22
- /** Width-and-position decomposition of a display-id-pattern. */
37
+ /** Width-and-position decomposition of a *numbered* display-id-pattern. */
23
38
  export interface DisplayIdPatternShape {
24
- /** Literal text before the `{n:Nd}` placeholder. */
39
+ /** Literal text before the counter placeholder. */
25
40
  readonly prefix: string;
26
- /** Width of the zero-padded numeric segment. */
41
+ /** Minimum width of the numeric segment (1 for a bare `{n}`). */
27
42
  readonly width: number;
28
- /** Literal text after the `{n:Nd}` placeholder (often empty). */
43
+ /** Literal text after the counter placeholder (often empty). */
29
44
  readonly suffix: string;
30
45
  }
46
+ /** A tokenized fragment of a display-id-pattern template. */
47
+ export type PatternToken = {
48
+ readonly kind: "literal";
49
+ readonly text: string;
50
+ } | {
51
+ readonly kind: "counter";
52
+ readonly padding?: string;
53
+ } | {
54
+ readonly kind: "named";
55
+ readonly name: string;
56
+ };
57
+ /** Split a template into its literal / counter / named tokens. */
58
+ export declare function tokenizePattern(template: string): PatternToken[];
59
+ /** Outcome of {@linkcode validateDisplayIdPattern}. */
60
+ export type DisplayIdPatternValidation = {
61
+ readonly ok: true;
62
+ } | {
63
+ readonly ok: false;
64
+ readonly message: string;
65
+ };
66
+ /**
67
+ * Decide whether a `display-id-pattern` template is well-formed, returning
68
+ * a MarkSpec-authored reason when it is not. This is the single oracle
69
+ * shared by classification (which throws this message) and profile-load
70
+ * validation (which emits it as a diagnostic), so a malformed pattern is
71
+ * reported identically everywhere and never reaches `new RegExp`.
72
+ *
73
+ * Rejects: more than one counter; a malformed/zero-width padding
74
+ * specifier; an all-literal template (no variable part); a counter-less
75
+ * pattern with no literal anchor (a bare `{name}` matches every ID); and
76
+ * a duplicate named placeholder (which would build an invalid RegExp).
77
+ */
78
+ export declare function validateDisplayIdPattern(template: string): DisplayIdPatternValidation;
31
79
  /**
32
- * Parse a `display-id-pattern` template. Returns `undefined` when
33
- * the pattern does not contain a recognised `{n:Nd}` placeholder so
34
- * callers can decide how to surface the error (CLI exits, LSP
35
- * silently skips the type).
80
+ * Decompose a *numbered* `display-id-pattern` into its mint shape.
81
+ *
82
+ * Returns `undefined` for any template that is not mintable — a named
83
+ * (counter-less) pattern, an all-literal template, or a malformed one —
84
+ * so callers can decide how to surface it (the CLI distinguishes a valid
85
+ * named type from a malformed pattern via {@linkcode validateDisplayIdPattern};
86
+ * the LSP skips non-mintable types). Shares the {@linkcode tokenizePattern}
87
+ * grammar with `compileDisplayIdPattern`, so the two never disagree about
88
+ * which counter forms are valid (#596).
36
89
  */
37
90
  export declare function parseDisplayIdPattern(pattern: string): DisplayIdPatternShape | undefined;
38
91
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"display_id.d.ts","sourceRoot":"","sources":["../../src/profile/display_id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,gEAAgE;AAChE,MAAM,WAAW,qBAAqB;IACpC,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAKD;;;;;GAKG;AACH,wBAAgB,q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ACvD,MAAM,MAAM,0BAA0B,GAClC;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,GACf,0BAA0B,CAsE5B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GACd,qBAAqB,GAAG,SAAS,CAcnC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,qBAAqB,EAC5B,CAAC,EAAE,MAAM,GACR,MAAM,CAER;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,qBAAqB,EAC5B,OAAO,EAAE,QAAQ,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,GACvC,MAAM,CAcR"}
@@ -2,48 +2,188 @@
2
2
  /**
3
3
  * @module core/profile/display_id
4
4
  *
5
- * Shared parser for the `display-id-pattern` template used by profile
6
- * type declarations. Patterns look like:
5
+ * Single source of truth for the `display-id-pattern` template grammar.
7
6
  *
8
- * STK_{n:4d}
9
- * STK_AEB_{n:04d}
10
- * REQ-{n:03d}-draft
7
+ * One tokenizer ({@linkcode tokenizePattern}) and one well-formedness
8
+ * oracle ({@linkcode validateDisplayIdPattern}) back both consumers of the
9
+ * grammar: classification (`compileDisplayIdPattern` in `core/validator`,
10
+ * which builds the recognizer regex) and minting/scaffolding
11
+ * ({@linkcode parseDisplayIdPattern}, which decomposes the numeric slot).
12
+ * Keeping a single grammar here prevents the two from drifting — see #596.
11
13
  *
12
- * The `{n:Nd}` placeholder (with optional leading zero in the Nd
13
- * form) names the sequential number slot. The text before the
14
- * placeholder becomes the literal prefix; the text after becomes the
15
- * literal suffix.
14
+ * A pattern is one of two kinds, selected by whether it contains a counter:
16
15
  *
17
- * Note: the `{scope}` placeholder documented in the profile schema
18
- * is NOT substituted here — callers handle that separately. For
19
- * patterns containing `{scope}`, the literal text `{scope}` ends up
20
- * in `prefix` (or `suffix`) and must be replaced upstream before the
21
- * pattern is fed to scaffolding.
16
+ * numbered := segment+ (exactly one `{n}` counter) — mintable + classifying
17
+ * named := segment+ (literal anchor, ≥1 named, no counter) — classifying
18
+ *
19
+ * counter := "{n}" | "{n:" digits "d}" (e.g. {n}, {n:4d}, {n:04d})
20
+ * named := "{" identifier "}" (e.g. {scope}, {name})
21
+ *
22
+ * The padding digit count is a minimum width; `{n:4d}` and `{n:04d}` are
23
+ * equivalent. A bare `{n}` mints with no zero-padding (width 1).
24
+ *
25
+ * Patterns:
26
+ *
27
+ * STK_{n:4d} → numbered, width 4
28
+ * STK_AEB_{n:04d} → numbered, width 4
29
+ * REQ-{n:03d}-draft → numbered, width 3, suffix "-draft"
30
+ * REQ-{n} → numbered, width 1
31
+ * SWC_{name} → named (classifying only — not mintable)
32
+ *
33
+ * Note: the `{scope}` placeholder documented in the profile schema is NOT
34
+ * substituted here. For a numbered pattern like `XREQ_{scope}_{n:04d}`,
35
+ * the literal `{scope}` text ends up in `prefix` and must be replaced
36
+ * upstream before the pattern is fed to scaffolding.
22
37
  */
23
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.tokenizePattern = tokenizePattern;
40
+ exports.validateDisplayIdPattern = validateDisplayIdPattern;
24
41
  exports.parseDisplayIdPattern = parseDisplayIdPattern;
25
42
  exports.padDisplayIdNumber = padDisplayIdNumber;
26
43
  exports.formatDisplayId = formatDisplayId;
27
44
  exports.highestDisplayIdNumber = highestDisplayIdNumber;
28
- /** Regex capturing the `{n:Nd}` placeholder; `0` and the digit count are both captured. */
29
- const PLACEHOLDER_RE = /\{n:(\d+)d\}/;
30
45
  /**
31
- * Parse a `display-id-pattern` template. Returns `undefined` when
32
- * the pattern does not contain a recognised `{n:Nd}` placeholder so
33
- * callers can decide how to surface the error (CLI exits, LSP
34
- * silently skips the type).
46
+ * One template token: the `{n}` counter (optionally padded) OR a `{named}`
47
+ * segment. The padding capture accepts any positive digit count — `{n:4d}`
48
+ * and `{n:04d}` both tokenize to a counter (`Number()` collapses the
49
+ * leading zero downstream).
50
+ */
51
+ const TOKEN_RE = /\{n(?::(\d+)d)?\}|\{([A-Za-z][A-Za-z0-9_]*)\}/g;
52
+ /** Split a template into its literal / counter / named tokens. */
53
+ function tokenizePattern(template) {
54
+ const tokens = [];
55
+ let lastIndex = 0;
56
+ const re = new RegExp(TOKEN_RE);
57
+ let match;
58
+ while ((match = re.exec(template)) !== null) {
59
+ if (match.index > lastIndex) {
60
+ tokens.push({
61
+ kind: "literal",
62
+ text: template.slice(lastIndex, match.index),
63
+ });
64
+ }
65
+ const named = match[2];
66
+ if (named === undefined) {
67
+ tokens.push({ kind: "counter", padding: match[1] });
68
+ }
69
+ else {
70
+ tokens.push({ kind: "named", name: named });
71
+ }
72
+ lastIndex = match.index + match[0].length;
73
+ }
74
+ if (lastIndex < template.length) {
75
+ tokens.push({ kind: "literal", text: template.slice(lastIndex) });
76
+ }
77
+ return tokens;
78
+ }
79
+ /** Re-emit the literal source a non-counter token contributes to a
80
+ * numbered pattern's prefix/suffix. A named placeholder is rendered in
81
+ * its `{name}` form (callers substitute it upstream). */
82
+ function reconstructLiteral(token) {
83
+ switch (token.kind) {
84
+ case "literal":
85
+ return token.text;
86
+ case "named":
87
+ return `{${token.name}}`;
88
+ case "counter":
89
+ return token.padding ? `{n:${token.padding}d}` : "{n}";
90
+ }
91
+ }
92
+ /**
93
+ * Decide whether a `display-id-pattern` template is well-formed, returning
94
+ * a MarkSpec-authored reason when it is not. This is the single oracle
95
+ * shared by classification (which throws this message) and profile-load
96
+ * validation (which emits it as a diagnostic), so a malformed pattern is
97
+ * reported identically everywhere and never reaches `new RegExp`.
98
+ *
99
+ * Rejects: more than one counter; a malformed/zero-width padding
100
+ * specifier; an all-literal template (no variable part); a counter-less
101
+ * pattern with no literal anchor (a bare `{name}` matches every ID); and
102
+ * a duplicate named placeholder (which would build an invalid RegExp).
103
+ */
104
+ function validateDisplayIdPattern(template) {
105
+ const tokens = tokenizePattern(template);
106
+ const counters = tokens.filter((t) => t.kind === "counter");
107
+ const named = tokens.filter((t) => t.kind === "named");
108
+ const hasLiteralAnchor = tokens.some((t) => t.kind === "literal" && t.text.length > 0);
109
+ if (counters.length > 1) {
110
+ return {
111
+ ok: false,
112
+ message: `display-id-pattern '${template}': multiple {n} counters (expected one)`,
113
+ };
114
+ }
115
+ if (counters.length === 1) {
116
+ const padding = counters[0].padding;
117
+ if (padding !== undefined && parseInt(padding, 10) < 1) {
118
+ return {
119
+ ok: false,
120
+ message: `display-id-pattern '${template}': invalid padding specifier ` +
121
+ `(expected {n} or {n:NNd})`,
122
+ };
123
+ }
124
+ }
125
+ if (counters.length === 0) {
126
+ // A malformed counter (`{n:abc}`, `{n:4}`) is not tokenized as a
127
+ // counter — it lands in literal text. Surface it as an invalid padding
128
+ // error before the missing-counter / named-pattern checks.
129
+ if (/\{n:[^}]*\}/.test(template)) {
130
+ return {
131
+ ok: false,
132
+ message: `display-id-pattern '${template}': invalid padding specifier ` +
133
+ `(expected {n} or {n:NNd})`,
134
+ };
135
+ }
136
+ if (named.length === 0) {
137
+ return {
138
+ ok: false,
139
+ message: `display-id-pattern '${template}': missing {n} placeholder`,
140
+ };
141
+ }
142
+ if (!hasLiteralAnchor) {
143
+ return {
144
+ ok: false,
145
+ message: `display-id-pattern '${template}': named pattern needs a literal ` +
146
+ `prefix (a bare {name} would match every display ID)`,
147
+ };
148
+ }
149
+ }
150
+ const seen = new Set();
151
+ for (const t of named) {
152
+ const name = t.name;
153
+ if (seen.has(name)) {
154
+ return {
155
+ ok: false,
156
+ message: `display-id-pattern '${template}': duplicate named placeholder '{${name}}'`,
157
+ };
158
+ }
159
+ seen.add(name);
160
+ }
161
+ return { ok: true };
162
+ }
163
+ /**
164
+ * Decompose a *numbered* `display-id-pattern` into its mint shape.
165
+ *
166
+ * Returns `undefined` for any template that is not mintable — a named
167
+ * (counter-less) pattern, an all-literal template, or a malformed one —
168
+ * so callers can decide how to surface it (the CLI distinguishes a valid
169
+ * named type from a malformed pattern via {@linkcode validateDisplayIdPattern};
170
+ * the LSP skips non-mintable types). Shares the {@linkcode tokenizePattern}
171
+ * grammar with `compileDisplayIdPattern`, so the two never disagree about
172
+ * which counter forms are valid (#596).
35
173
  */
36
174
  function parseDisplayIdPattern(pattern) {
37
- const match = PLACEHOLDER_RE.exec(pattern);
38
- if (!match)
39
- return undefined;
40
- const width = parseInt(match[1], 10);
175
+ const tokens = tokenizePattern(pattern);
176
+ const counters = tokens.filter((t) => t.kind === "counter");
177
+ if (counters.length !== 1)
178
+ return undefined; // named/none, or multi-counter
179
+ const counterIndex = tokens.indexOf(counters[0]);
180
+ const width = counters[0].padding ? parseInt(counters[0].padding, 10) : 1;
41
181
  if (!Number.isFinite(width) || width < 1)
42
182
  return undefined;
43
183
  return {
44
- prefix: pattern.slice(0, match.index),
184
+ prefix: tokens.slice(0, counterIndex).map(reconstructLiteral).join(""),
45
185
  width,
46
- suffix: pattern.slice(match.index + match[0].length),
186
+ suffix: tokens.slice(counterIndex + 1).map(reconstructLiteral).join(""),
47
187
  };
48
188
  }
49
189
  /**
@@ -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;AA4BnE,eAAO,MAAM,iBAAiB,aAS5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAU/B,CAAC;AAEH,eAAO,MAAM,iBAAiB,aAU5B,CAAC;AAEH,eAAO,MAAM,qBAAq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ACE_RULE_KEYS = exports.ALLOWED_INVERSE_KEYS = exports.ALLOWED
11
11
  exports.parseManifest = parseManifest;
12
12
  const yaml_1 = require("@std/yaml");
13
13
  const mod_js_1 = require("../model/mod.js");
14
+ const display_id_js_1 = require("./display_id.js");
14
15
  const VALUE_TYPE_SET = new Set(mod_js_1.VALUE_TYPES);
15
16
  exports.ALLOWED_ROOT_KEYS = new Set([
16
17
  "$schema",
@@ -918,6 +919,24 @@ function parseTypeDef(name, raw, sourcePath, diagnostics) {
918
919
  return undefined;
919
920
  }
920
921
  displayIdPattern = r["display-id-pattern"];
922
+ // Compile-check the pattern here, at profile-load, against the same grammar
923
+ // oracle classification uses. A malformed pattern (duplicate named
924
+ // placeholder, bad padding, no anchor, …) is reported as a clean
925
+ // PROFILE-TYPE-008 diagnostic instead of throwing an uncaught exception
926
+ // later inside classifyEntry / checkEnforcement. Like the sibling field
927
+ // checks above, an error here drops the type so the bad pattern never
928
+ // reaches compileDisplayIdPattern (and, per parseManifest's all-or-nothing
929
+ // error contract, the manifest is rejected). (#597)
930
+ const patternValidation = (0, display_id_js_1.validateDisplayIdPattern)(displayIdPattern);
931
+ if (!patternValidation.ok) {
932
+ diagnostics.push({
933
+ code: "PROFILE-TYPE-008",
934
+ severity: "error",
935
+ message: `${ctx}: ${patternValidation.message}`,
936
+ location: { file: sourcePath, line: 1, column: 1 },
937
+ });
938
+ return undefined;
939
+ }
921
940
  }
922
941
  let enforcement = "off";
923
942
  const rawEnf = r["display-id-pattern-enforcement"];
@@ -19,8 +19,8 @@ export type { MergeResult } from "./merge.js";
19
19
  export { resolveEntryColor } from "./colors.js";
20
20
  export { buildEffectiveDisciplineRegistry } from "./discipline_registry.js";
21
21
  export { inferDisciplineMode, resolveDisciplineMode, } from "./discipline_mode.js";
22
- export { formatDisplayId, highestDisplayIdNumber, padDisplayIdNumber, parseDisplayIdPattern, } from "./display_id.js";
23
- export type { DisplayIdPatternShape } from "./display_id.js";
22
+ export { formatDisplayId, highestDisplayIdNumber, padDisplayIdNumber, parseDisplayIdPattern, validateDisplayIdPattern, } from "./display_id.js";
23
+ export type { DisplayIdPatternShape, DisplayIdPatternValidation, } from "./display_id.js";
24
24
  export { entryMatchesTargets, filterEntriesByTraceTargets, targetsForRelation, } from "./trace_targets.js";
25
25
  export { buildProfileIntrospection } from "./introspect.js";
26
26
  export type { AttributeDetail, ConventionDetail, LabelConcernDetail, ProfileElementDetail, ProfileElementKind, ProfileElementRef, ProfileIntrospection, ProfileOverview, ProvenancedDescription, RelationDetail, TypeDetail, } from "./introspect.js";
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/profile/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3E,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,MAAM,EACN,YAAY,GACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aA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EpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,UAAU,GACX,MAAM,iBAAiB,CAAC"}
@@ -6,7 +6,7 @@
6
6
  * resolution, and merging. Consumed by the validator pipeline and the CLI.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.buildProfileIntrospection = exports.targetsForRelation = exports.filterEntriesByTraceTargets = exports.entryMatchesTargets = exports.parseDisplayIdPattern = exports.padDisplayIdNumber = exports.highestDisplayIdNumber = exports.formatDisplayId = exports.resolveDisciplineMode = exports.inferDisciplineMode = exports.buildEffectiveDisciplineRegistry = exports.resolveEntryColor = exports.mergeChain = exports.loadProfileForCommand = exports.loadChain = exports.ensureCacheGitignored = exports.defaultRunGit = exports.defaultAppendFile = exports.computeCacheLocation = exports.computeCacheKey = exports.resolveLocalSpecifier = exports.resolveGitSpecifier = exports.parseManifest = void 0;
9
+ exports.buildProfileIntrospection = exports.targetsForRelation = exports.filterEntriesByTraceTargets = exports.entryMatchesTargets = exports.validateDisplayIdPattern = exports.parseDisplayIdPattern = exports.padDisplayIdNumber = exports.highestDisplayIdNumber = exports.formatDisplayId = exports.resolveDisciplineMode = exports.inferDisciplineMode = exports.buildEffectiveDisciplineRegistry = exports.resolveEntryColor = exports.mergeChain = exports.loadProfileForCommand = exports.loadChain = exports.ensureCacheGitignored = exports.defaultRunGit = exports.defaultAppendFile = exports.computeCacheLocation = exports.computeCacheKey = exports.resolveLocalSpecifier = exports.resolveGitSpecifier = exports.parseManifest = void 0;
10
10
  var manifest_js_1 = require("./manifest.js");
11
11
  Object.defineProperty(exports, "parseManifest", { enumerable: true, get: function () { return manifest_js_1.parseManifest; } });
12
12
  var resolver_js_1 = require("./resolver.js");
@@ -40,6 +40,7 @@ Object.defineProperty(exports, "formatDisplayId", { enumerable: true, get: funct
40
40
  Object.defineProperty(exports, "highestDisplayIdNumber", { enumerable: true, get: function () { return display_id_js_1.highestDisplayIdNumber; } });
41
41
  Object.defineProperty(exports, "padDisplayIdNumber", { enumerable: true, get: function () { return display_id_js_1.padDisplayIdNumber; } });
42
42
  Object.defineProperty(exports, "parseDisplayIdPattern", { enumerable: true, get: function () { return display_id_js_1.parseDisplayIdPattern; } });
43
+ Object.defineProperty(exports, "validateDisplayIdPattern", { enumerable: true, get: function () { return display_id_js_1.validateDisplayIdPattern; } });
43
44
  var trace_targets_js_1 = require("./trace_targets.js");
44
45
  Object.defineProperty(exports, "entryMatchesTargets", { enumerable: true, get: function () { return trace_targets_js_1.entryMatchesTargets; } });
45
46
  Object.defineProperty(exports, "filterEntriesByTraceTargets", { enumerable: true, get: function () { return trace_targets_js_1.filterEntriesByTraceTargets; } });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @module core/refs
3
+ *
4
+ * Project-aware trace-reference canonicalisation + rename-healing (issue #593,
5
+ * Slice 4). Pure module: given a project-wide display-ID ↔ ULID index and the
6
+ * lockfile's edge ledger, rewrite a file's trace-attribute values losslessly —
7
+ * ULID → current display ID (canonicalise), and a stale display ID → the
8
+ * ledger's stable target ULID → the target's current display ID (heal).
9
+ *
10
+ * Architecture: composed AROUND the pure `core/formatter` by the `markspec fmt`
11
+ * CLI. It MUST NOT import `core/formatter`, and `core/formatter` MUST NOT import
12
+ * it (WASM-migration purity guard, AGENTS.md).
13
+ */
14
+ import type { Entry } from "../model/mod.js";
15
+ import type { LockEdge } from "../lock/mod.js";
16
+ /**
17
+ * Trace-attribute keys whose values are canonicalised/healed: the core
18
+ * relations plus `Verified-by`. Derived from {@linkcode CORE_RELATIONS} so new
19
+ * relations are covered automatically.
20
+ */
21
+ export declare const TRACE_ATTRIBUTE_KEYS: ReadonlySet<string>;
22
+ /** Bidirectional display-ID ↔ ULID resolution index over a project's entries. */
23
+ export interface RefIndex {
24
+ readonly displayIdToUlid: ReadonlyMap<string, string>;
25
+ readonly ulidToDisplayId: ReadonlyMap<string, string>;
26
+ }
27
+ /**
28
+ * Build a {@linkcode RefIndex} from a project's entries. First-entry-wins on
29
+ * duplicate keys (validator/workspace convention). Entries without a ULID are
30
+ * skipped.
31
+ */
32
+ export declare function buildRefIndex(entries: readonly Entry[]): RefIndex;
33
+ /**
34
+ * Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
35
+ * `entries` MUST be the parse of `content` (used to map each trailer line to its
36
+ * source entry's stable ULID). Returns the rewritten text and whether anything
37
+ * changed. Lossless: only resolvable value tokens are replaced.
38
+ */
39
+ export declare function canonicalizeRefs(content: string, entries: readonly Entry[], index: RefIndex, ledger: readonly LockEdge[]): {
40
+ output: string;
41
+ changed: boolean;
42
+ };
43
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +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;AAQD;;;;;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,CAuDtC"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/refs
4
+ *
5
+ * Project-aware trace-reference canonicalisation + rename-healing (issue #593,
6
+ * Slice 4). Pure module: given a project-wide display-ID ↔ ULID index and the
7
+ * lockfile's edge ledger, rewrite a file's trace-attribute values losslessly —
8
+ * ULID → current display ID (canonicalise), and a stale display ID → the
9
+ * ledger's stable target ULID → the target's current display ID (heal).
10
+ *
11
+ * Architecture: composed AROUND the pure `core/formatter` by the `markspec fmt`
12
+ * CLI. It MUST NOT import `core/formatter`, and `core/formatter` MUST NOT import
13
+ * it (WASM-migration purity guard, AGENTS.md).
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.TRACE_ATTRIBUTE_KEYS = void 0;
17
+ exports.buildRefIndex = buildRefIndex;
18
+ exports.canonicalizeRefs = canonicalizeRefs;
19
+ const mod_js_1 = require("../model/mod.js");
20
+ /**
21
+ * Trace-attribute keys whose values are canonicalised/healed: the core
22
+ * relations plus `Verified-by`. Derived from {@linkcode CORE_RELATIONS} so new
23
+ * relations are covered automatically.
24
+ */
25
+ exports.TRACE_ATTRIBUTE_KEYS = new Set([
26
+ ...mod_js_1.CORE_RELATIONS.map((r) => r.attr),
27
+ ...mod_js_1.LOCK_EXTRA_INVERSE_KEYS,
28
+ ]);
29
+ /**
30
+ * Build a {@linkcode RefIndex} from a project's entries. First-entry-wins on
31
+ * duplicate keys (validator/workspace convention). Entries without a ULID are
32
+ * skipped.
33
+ */
34
+ function buildRefIndex(entries) {
35
+ const displayIdToUlid = new Map();
36
+ const ulidToDisplayId = new Map();
37
+ for (const e of entries) {
38
+ if (e.id === undefined)
39
+ continue;
40
+ if (!displayIdToUlid.has(e.displayId)) {
41
+ displayIdToUlid.set(e.displayId, e.id);
42
+ }
43
+ if (!ulidToDisplayId.has(e.id)) {
44
+ ulidToDisplayId.set(e.id, e.displayId);
45
+ }
46
+ }
47
+ return { displayIdToUlid, ulidToDisplayId };
48
+ }
49
+ /** Trailer trace line: indent, key, `:` + spaces, value-rest. */
50
+ const TRACE_TRAILER_RE = /^(\s{4,})([A-Z][A-Za-z-]*)(\s*:\s*)(.*)$/;
51
+ /** Token splitter that preserves separators between value tokens. */
52
+ const VALUE_TOKEN_RE = /[^\s,]+/g;
53
+ /**
54
+ * Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
55
+ * `entries` MUST be the parse of `content` (used to map each trailer line to its
56
+ * source entry's stable ULID). Returns the rewritten text and whether anything
57
+ * changed. Lossless: only resolvable value tokens are replaced.
58
+ */
59
+ function canonicalizeRefs(content, entries, index, ledger) {
60
+ const ledgerByKey = new Map();
61
+ for (const e of ledger) {
62
+ if (e.targetUlid === undefined)
63
+ continue;
64
+ ledgerByKey.set(`${e.sourceUlid} ${e.relation} ${e.authoredTarget}`, e.targetUlid);
65
+ }
66
+ // Sort entries by start line so binary-search for source ULID is correct.
67
+ const sorted = [...entries].sort((a, b) => a.location.line - b.location.line);
68
+ /** Return the ULID of the entry whose block contains the given 1-based line. */
69
+ const sourceUlidForLine = (line1) => {
70
+ let lo = 0;
71
+ let hi = sorted.length - 1;
72
+ let ans = -1;
73
+ while (lo <= hi) {
74
+ const mid = (lo + hi) >> 1;
75
+ if (sorted[mid].location.line <= line1) {
76
+ ans = mid;
77
+ lo = mid + 1;
78
+ }
79
+ else {
80
+ hi = mid - 1;
81
+ }
82
+ }
83
+ return ans >= 0 ? sorted[ans].id : undefined;
84
+ };
85
+ const lines = content.split("\n");
86
+ let changed = false;
87
+ for (let i = 0; i < lines.length; i++) {
88
+ // Strip a trailing CR before matching so CRLF files are handled (the
89
+ // trailer regex ends in `$`, which `\r` would block) and re-append it on
90
+ // rewrite so line endings stay byte-for-byte lossless.
91
+ const cr = lines[i].endsWith("\r");
92
+ const bare = cr ? lines[i].slice(0, -1) : lines[i];
93
+ const m = TRACE_TRAILER_RE.exec(bare);
94
+ if (!m)
95
+ continue;
96
+ const [, indent, key, sep, rest] = m;
97
+ if (!exports.TRACE_ATTRIBUTE_KEYS.has(key))
98
+ continue;
99
+ // Multi-line continuation — leave untouched (debt: full multi-line support).
100
+ if (rest.endsWith("\\"))
101
+ continue;
102
+ const sourceUlid = sourceUlidForLine(i + 1);
103
+ const rewritten = rest.replace(VALUE_TOKEN_RE, (token) => rewriteToken(token, sourceUlid, key, index, ledgerByKey));
104
+ if (rewritten !== rest) {
105
+ lines[i] = `${indent}${key}${sep}${rewritten}${cr ? "\r" : ""}`;
106
+ changed = true;
107
+ }
108
+ }
109
+ return { output: lines.join("\n"), changed };
110
+ }
111
+ function rewriteToken(token, sourceUlid, relation, index, ledgerByKey) {
112
+ if (mod_js_1.ULID_RE.test(token)) {
113
+ // Rule 1: ULID → current display ID (canonicalise).
114
+ return index.ulidToDisplayId.get(token) ?? token;
115
+ }
116
+ if (!mod_js_1.DISPLAY_ID_RE.test(token))
117
+ return token;
118
+ if (index.displayIdToUlid.has(token)) {
119
+ // Rule 2: current display ID — leave unchanged.
120
+ return token;
121
+ }
122
+ if (sourceUlid !== undefined) {
123
+ // Rule 3: stale display ID — try to heal via ledger.
124
+ const targetUlid = ledgerByKey.get(`${sourceUlid} ${relation} ${token}`);
125
+ if (targetUlid !== undefined) {
126
+ const healed = index.ulidToDisplayId.get(targetUlid);
127
+ if (healed !== undefined)
128
+ return healed;
129
+ }
130
+ }
131
+ // Rule 4: leave untouched (URI/broken/unknown).
132
+ return token;
133
+ }
@@ -31,7 +31,7 @@ export declare function validate(entries: readonly Entry[]): ValidateResult;
31
31
  export declare function indexByDisplayId(entries: readonly Entry[]): ReadonlyMap<string, Entry>;
32
32
  export declare function findAttr(attrs: readonly Attribute[], key: string): Attribute | undefined;
33
33
  export { runPipeline, suppressDeclaredAttrR010 } from "./pipeline.js";
34
- export type { PipelineResult } from "./pipeline.js";
34
+ export type { PipelineOptions, PipelineResult } from "./pipeline.js";
35
35
  export { validateListingDocuments } from "./listing.js";
36
36
  export type { ListingFileContext, ListingKind } from "./listing.js";
37
37
  export { classifyEntriesStage, classifyEntry } from "./types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/validator/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAqCpE,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,E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