@gate-forge/cli 0.10.4 → 0.11.0

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 (89) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -0
  3. package/dist/commands/check.d.ts.map +1 -1
  4. package/dist/commands/check.js +44 -14
  5. package/dist/commands/check.js.map +1 -1
  6. package/dist/commands/classify.d.ts.map +1 -1
  7. package/dist/commands/classify.js +24 -11
  8. package/dist/commands/classify.js.map +1 -1
  9. package/dist/commands/init.d.ts +14 -14
  10. package/dist/commands/init.d.ts.map +1 -1
  11. package/dist/commands/init.js +120 -80
  12. package/dist/commands/init.js.map +1 -1
  13. package/dist/commands/migrate-moved-documents.d.ts +44 -0
  14. package/dist/commands/migrate-moved-documents.d.ts.map +1 -0
  15. package/dist/commands/migrate-moved-documents.js +333 -0
  16. package/dist/commands/migrate-moved-documents.js.map +1 -0
  17. package/dist/commands/migrate.d.ts.map +1 -1
  18. package/dist/commands/migrate.js +98 -75
  19. package/dist/commands/migrate.js.map +1 -1
  20. package/dist/commands/next.d.ts.map +1 -1
  21. package/dist/commands/next.js +50 -17
  22. package/dist/commands/next.js.map +1 -1
  23. package/dist/docs-exclusions.js +1 -2
  24. package/dist/docs-exclusions.js.map +1 -1
  25. package/dist/endpoint-compiler.d.ts +82 -9
  26. package/dist/endpoint-compiler.d.ts.map +1 -1
  27. package/dist/endpoint-compiler.js +86 -41
  28. package/dist/endpoint-compiler.js.map +1 -1
  29. package/dist/endpoint-config.d.ts +32 -13
  30. package/dist/endpoint-config.d.ts.map +1 -1
  31. package/dist/endpoint-config.js +37 -27
  32. package/dist/endpoint-config.js.map +1 -1
  33. package/dist/execution.d.ts.map +1 -1
  34. package/dist/execution.js +6 -8
  35. package/dist/execution.js.map +1 -1
  36. package/dist/gateforge-owned.d.ts.map +1 -1
  37. package/dist/gateforge-owned.js +2 -6
  38. package/dist/gateforge-owned.js.map +1 -1
  39. package/dist/index.d.ts +2 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +2 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/input-snapshot.d.ts +0 -2
  44. package/dist/input-snapshot.d.ts.map +1 -1
  45. package/dist/input-snapshot.js +9 -6
  46. package/dist/input-snapshot.js.map +1 -1
  47. package/dist/moved-owner-documents.d.ts +51 -0
  48. package/dist/moved-owner-documents.d.ts.map +1 -0
  49. package/dist/moved-owner-documents.js +92 -0
  50. package/dist/moved-owner-documents.js.map +1 -0
  51. package/dist/owner-answers.d.ts +31 -0
  52. package/dist/owner-answers.d.ts.map +1 -0
  53. package/dist/owner-answers.js +56 -0
  54. package/dist/owner-answers.js.map +1 -0
  55. package/dist/pipeline.d.ts +0 -2
  56. package/dist/pipeline.d.ts.map +1 -1
  57. package/dist/pipeline.js +34 -41
  58. package/dist/pipeline.js.map +1 -1
  59. package/dist/planes-inference.d.ts +3 -2
  60. package/dist/planes-inference.d.ts.map +1 -1
  61. package/dist/planes-inference.js +3 -2
  62. package/dist/planes-inference.js.map +1 -1
  63. package/dist/plugins.d.ts +25 -3
  64. package/dist/plugins.d.ts.map +1 -1
  65. package/dist/plugins.js +23 -7
  66. package/dist/plugins.js.map +1 -1
  67. package/dist/route-plane-proposals.d.ts +6 -3
  68. package/dist/route-plane-proposals.d.ts.map +1 -1
  69. package/dist/route-plane-proposals.js +26 -7
  70. package/dist/route-plane-proposals.js.map +1 -1
  71. package/dist/run-cache.d.ts +8 -2
  72. package/dist/run-cache.d.ts.map +1 -1
  73. package/dist/run-cache.js +9 -3
  74. package/dist/run-cache.js.map +1 -1
  75. package/dist/scope.d.ts.map +1 -1
  76. package/dist/scope.js +1 -3
  77. package/dist/scope.js.map +1 -1
  78. package/dist/yaml-section.d.ts +49 -0
  79. package/dist/yaml-section.d.ts.map +1 -0
  80. package/dist/yaml-section.js +443 -0
  81. package/dist/yaml-section.js.map +1 -0
  82. package/dist/yaml.d.ts +10 -0
  83. package/dist/yaml.d.ts.map +1 -0
  84. package/dist/yaml.js +35 -0
  85. package/dist/yaml.js.map +1 -0
  86. package/guides/CONNECT-YOUR-PROJECT.md +1 -1
  87. package/guides/QUICKSTART.md +8 -8
  88. package/guides/REFERENCE.md +100 -23
  89. package/package.json +10 -10
@@ -0,0 +1,443 @@
1
+ /**
2
+ * TEXT-LEVEL writing of ONE section of a YAML document, for the documents
3
+ * the CLI owns and the owner reviews: `gateforge migrate`, `gateforge
4
+ * classify plane`, `gateforge init --planes` and `gateforge init --rules`.
5
+ *
6
+ * Why text and not re-serialization: `.gateforge/classification-policy.yml`
7
+ * is an owner-authored review artifact. A `parse` → `stringify` round trip
8
+ * destroys every comment, key order and quoting choice the owner made, and
9
+ * the reasons next to each rule ARE the review record. So this writer
10
+ * splices a rendered block into the existing TEXT and touches nothing else.
11
+ *
12
+ * The span it replaces comes from the PARSER, not from line scanning: the
13
+ * `yaml` document node knows exactly where a key's value ends, so a comment
14
+ * at column zero inside the section, a `#` on the key's own line and a
15
+ * trailing comment block after the section are all left where the owner put
16
+ * them. Line scanning gets those wrong, and a wrong span silently eats the
17
+ * owner's notes.
18
+ *
19
+ * Sections are addressed by PATH (`['scan', 'httpClients']`), not by a bare
20
+ * key: `gateforge migrate` writes a nested section into `.gateforge.yml`
21
+ * while leaving every sibling key of `scan:` exactly as the owner wrote it.
22
+ *
23
+ * Fail-closed four ways:
24
+ *
25
+ * 1. the input must parse as a YAML mapping (an existing section the writer
26
+ * cannot read as a mapping is REFUSED BY NAME, never overwritten);
27
+ * 2. the rendered block is re-parsed and the section compared to what was
28
+ * asked for, so a rendering the parser reads differently fails before
29
+ * anything reaches disk;
30
+ * 3. a document with the same key twice is refused outright — the strict
31
+ * readers behind it reject it too, and guessing which one to replace
32
+ * would pick an answer nobody wrote;
33
+ * 4. {@link removeTopLevelSection} hands back the comment block that stood
34
+ * directly above the key it removed, so a caller that MOVES a key can
35
+ * carry the owner's note to its new home instead of dropping it.
36
+ */
37
+ import { isCollection, isMap, isScalar, parseDocument, stringify as stringifyYaml, } from 'yaml';
38
+ import { UsageError } from './errors.js';
39
+ /** One `key:` whose value the writer cannot read as a mapping. */
40
+ class UnreadableSection extends Error {
41
+ }
42
+ /**
43
+ * The mapping entries of the document at `prefix`, in document order.
44
+ *
45
+ * @param text - the document's exact current text ('' for a new file).
46
+ * @param prefix - the key path of the mapping to list (empty = top level).
47
+ * @param key - the key the caller intends to write, named in refusals.
48
+ * @param path - repo-relative document path, named in refusals.
49
+ * @returns the entries, or null when the prefix does not exist.
50
+ * @throws UsageError when the document or a prefix step is not a mapping.
51
+ */
52
+ function pairsAt(text, prefix, key, path) {
53
+ const document = parseDocument(text === '' ? '{}\n' : text);
54
+ if (document.errors.length > 0) {
55
+ throw new UsageError(`${path} is not valid YAML, so nothing can be written into it: ` +
56
+ `${document.errors[0]?.message.split('\n')[0] ?? 'parse error'}`);
57
+ }
58
+ let contents = document.contents;
59
+ if (contents === null || !isMap(contents)) {
60
+ throw new UsageError(`${path} is not a YAML mapping, so ${key}: cannot be written into it`);
61
+ }
62
+ // Every prefix step must be a mapping the writer can read into: a scalar
63
+ // or sequence there means the owner wrote something this writer has no
64
+ // business reshaping, so it refuses by name.
65
+ for (const step of prefix) {
66
+ const pairs = mapPairs(contents, step, path);
67
+ const found = pairs.find((pair) => pair.name === step);
68
+ if (found === undefined)
69
+ return null;
70
+ if (!isCollection(found.valueNode) || !isMap(found.valueNode)) {
71
+ throw new UnreadableSection(`${path}: '${step}' is not a mapping, so ${[...prefix, key].join('.')} cannot be written into it`);
72
+ }
73
+ contents = found.valueNode;
74
+ }
75
+ return mapPairs(contents, key, path);
76
+ }
77
+ /**
78
+ * The entries of one YAML mapping, refusing a duplicated key.
79
+ *
80
+ * @param contents - the mapping node to list.
81
+ * @param key - the key the caller intends to write, named in refusals.
82
+ * @param path - repo-relative document path, named in refusals.
83
+ * @returns every entry, in document order.
84
+ */
85
+ function mapPairs(contents, key, path) {
86
+ if (!isMap(contents)) {
87
+ throw new UsageError(`${path} is not a YAML mapping, so ${key}: cannot be written into it`);
88
+ }
89
+ const seen = new Set();
90
+ const pairs = [];
91
+ for (const pair of contents.items) {
92
+ if (pair === null || pair === undefined || !isScalar(pair.key))
93
+ continue;
94
+ const name = String(pair.key.value);
95
+ if (seen.has(name)) {
96
+ throw new UsageError(`${path} declares the key '${name}' more than once; fix the document by hand ` +
97
+ 'before a command rewrites one of them');
98
+ }
99
+ seen.add(name);
100
+ pairs.push({ name, keyStart: pair.key.range?.[0], valueNode: pair.value });
101
+ }
102
+ return pairs;
103
+ }
104
+ /**
105
+ * The end offset of a `key:` line that declares NO value — the one case a
106
+ * scalar node cannot describe, because the parser gives an empty value a
107
+ * zero-width range right after the colon.
108
+ *
109
+ * Text after the colon is consumed only up to a trailing comment, so an
110
+ * owner's `# note` on the key's own line survives the write instead of
111
+ * being deleted with the line it annotated.
112
+ *
113
+ * @param text - the document's exact text.
114
+ * @param keyStart - offset of the `key` token.
115
+ * @param key - the key being written, named in refusals.
116
+ * @param path - repo-relative document path, named in refusals.
117
+ * @returns the offset one past the consumed text.
118
+ */
119
+ function emptyValueEnd(text, keyStart, key, path) {
120
+ const newline = text.indexOf('\n', keyStart);
121
+ const line = text.slice(keyStart, newline === -1 ? text.length : newline);
122
+ const colon = line.indexOf(':');
123
+ if (colon === -1) {
124
+ throw new UnreadableSection(`${path}: '${line}' is not a \`key:\` line`);
125
+ }
126
+ const after = line.slice(colon + 1);
127
+ const comment = after.search(/(^|\s)#/);
128
+ const declared = (comment === -1 ? after : after.slice(0, comment)).trim();
129
+ if (declared !== '') {
130
+ throw new UnreadableSection(`${path} declares ${key} inline as \`${key}: ${declared}\`; this command only writes ` +
131
+ `${key} as a mapping — edit the file by hand`);
132
+ }
133
+ return keyStart + colon + 1 + (comment === -1 ? after.length : comment);
134
+ }
135
+ /**
136
+ * Locates the exact span of one section.
137
+ *
138
+ * @param text - the document's exact current text.
139
+ * @param keyPath - the section's key path; its LAST element is the key.
140
+ * @param path - repo-relative document path, named in refusals.
141
+ * @returns the span, or null when the document does not declare the key.
142
+ * @throws UnreadableSection when the existing section is not a mapping.
143
+ */
144
+ function sectionSpan(text, keyPath, path) {
145
+ const key = keyPath[keyPath.length - 1];
146
+ if (key === undefined) {
147
+ throw new UsageError(`${path}: a section needs at least one key`);
148
+ }
149
+ const pairs = pairsAt(text, keyPath.slice(0, -1), key, path);
150
+ for (const pair of pairs ?? []) {
151
+ if (pair.name !== key)
152
+ continue;
153
+ const start = pair.keyStart;
154
+ if (start === undefined) {
155
+ throw new UnreadableSection(`${path}: the parser located no source text for ${key}:`);
156
+ }
157
+ // A scalar here is an INLINE declaration (`planes: 5`, a block string).
158
+ // The writer never guesses what a scalar meant; the owner edits it.
159
+ if (isScalar(pair.valueNode)) {
160
+ if (pair.valueNode.value !== null) {
161
+ throw new UnreadableSection(`${path} declares ${key} inline as \`${key}: ${String(pair.valueNode.value).split('\n')[0]}\`; ` +
162
+ `this command only writes ${key} as a mapping — edit the file by hand`);
163
+ }
164
+ return { start, end: emptyValueEnd(text, start, key, path) };
165
+ }
166
+ if (!isCollection(pair.valueNode)) {
167
+ throw new UnreadableSection(`${path}: the parser located no source text for ${key}:`);
168
+ }
169
+ const end = pair.valueNode.range?.[1];
170
+ if (end === undefined) {
171
+ throw new UnreadableSection(`${path}: the parser located no source text for ${key}:`);
172
+ }
173
+ return { start, end };
174
+ }
175
+ return null;
176
+ }
177
+ /**
178
+ * Recursively orders object keys and drops undefined members, so two
179
+ * structurally equal values compare equal as text.
180
+ *
181
+ * @param value - any parsed YAML value.
182
+ * @returns a canonical text form.
183
+ */
184
+ function canonical(value) {
185
+ if (value === null || typeof value !== 'object')
186
+ return JSON.stringify(value) ?? 'null';
187
+ if (Array.isArray(value))
188
+ return `[${value.map(canonical).join(',')}]`;
189
+ const entries = Object.entries(value)
190
+ .filter(([, item]) => item !== undefined)
191
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));
192
+ return `{${entries.map(([name, item]) => `${JSON.stringify(name)}:${canonical(item)}`).join(',')}}`;
193
+ }
194
+ /** Indentation of a key at `depth`, counting the document root as 0. */
195
+ function indentOf(depth) {
196
+ return ' '.repeat(depth);
197
+ }
198
+ /**
199
+ * Renders one section and every MISSING level above it: `key:` plus a body
200
+ * indented one level deeper. An empty mapping renders inline
201
+ * (`key: {}`), so a written section never leaves a dangling key behind.
202
+ *
203
+ * A level the document already declares is NOT rendered: writing
204
+ * `scan.httpClients` into a config that already has a `scan:` block must
205
+ * append the leaf inside it, and rendering the whole chain there would
206
+ * nest `scan:` inside `scan:` — a document that parses as the wrong shape
207
+ * and that the writer's own read-back check then refuses.
208
+ *
209
+ * @param keyPath - the section's key path.
210
+ * @param value - the plain-data section body.
211
+ * @param comments - per-key comment lines carried along by a move.
212
+ * @param declaredDepth - how many leading levels the document already has.
213
+ * @returns the rendered lines, without a trailing newline.
214
+ */
215
+ function renderSection(keyPath, value, comments, declaredDepth = 0) {
216
+ const key = keyPath[keyPath.length - 1];
217
+ if (key === undefined) {
218
+ throw new UsageError('a section needs at least one key');
219
+ }
220
+ const isEmptyMapping = value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0;
221
+ const leaf = isEmptyMapping
222
+ ? [`${key}: {}`]
223
+ : [
224
+ `${key}:`,
225
+ ...stringifyYaml(value, { indent: 2, lineWidth: 0 })
226
+ .replace(/\n$/, '')
227
+ .split('\n')
228
+ .map((line) => (line === '' ? '' : ` ${line}`)),
229
+ ];
230
+ // The body of a nested section is indented twice: once for the parent key
231
+ // it sits under, once for its own body.
232
+ let lines = leaf;
233
+ for (let depth = keyPath.length - 1; depth >= declaredDepth + 1; depth -= 1) {
234
+ const parent = keyPath[depth - 1];
235
+ if (parent === undefined)
236
+ continue;
237
+ lines = [`${parent}:`, ...lines.map((line) => (line === '' ? '' : ` ${line}`))];
238
+ }
239
+ // Comments ride above their own key, at that key's indentation.
240
+ const withComments = lines.flatMap((line) => {
241
+ const depth = (line.length - line.trimStart().length) / 2;
242
+ const name = line.trimStart().replace(/:.*$/, '');
243
+ const note = comments.get(name);
244
+ if (note === undefined || note.length === 0)
245
+ return [line];
246
+ return [...note.map((comment) => `${indentOf(depth)}${comment}`), line];
247
+ });
248
+ return withComments;
249
+ }
250
+ /**
251
+ * {@link sectionSpan} with its internal refusal type turned into the
252
+ * `UsageError` every caller of this module surfaces.
253
+ *
254
+ * @param text - the document's exact current text.
255
+ * @param keyPath - the section's key path.
256
+ * @param path - repo-relative document path, named in refusals.
257
+ * @returns the span, or null when the document does not declare the key.
258
+ * @throws UsageError naming the key the writer refuses to reshape.
259
+ */
260
+ function sectionSpanOrRefuse(text, keyPath, path) {
261
+ try {
262
+ return sectionSpan(text, keyPath, path);
263
+ }
264
+ catch (error) {
265
+ if (error instanceof UnreadableSection)
266
+ throw new UsageError(error.message);
267
+ throw error;
268
+ }
269
+ }
270
+ /**
271
+ * Replaces (or appends) one section of a YAML document, preserving every
272
+ * other byte — comments included.
273
+ *
274
+ * @param text - the document's exact current text ('' for a new file).
275
+ * @param keyPath - the section's key path (`['scan', 'httpClients']`).
276
+ * @param value - the exact plain-data body to declare.
277
+ * @param path - repo-relative document path, named in refusals.
278
+ * @param comments - comment lines to place above their own key, for a
279
+ * caller moving a key and carrying the owner's note with it.
280
+ * @returns the document text with the section written.
281
+ * @throws UsageError on unparsable input, a duplicated or unreadable
282
+ * existing section, or a result that does not parse back to what was
283
+ * asked for.
284
+ */
285
+ export function setSection(text, keyPath, value, path, comments = new Map()) {
286
+ const key = keyPath[keyPath.length - 1];
287
+ if (key === undefined) {
288
+ throw new UsageError(`${path}: a section needs at least one key`);
289
+ }
290
+ const span = sectionSpanOrRefuse(text, keyPath, path);
291
+ // The longest existing prefix of the path: where a missing section is
292
+ // appended, how deep its body must be indented, and how much of the
293
+ // chain is already in the document (so it is not rendered twice).
294
+ const existing = longestExistingPrefix(text, keyPath, path);
295
+ const depth = existing?.length ?? 0;
296
+ const rendered = renderSection(keyPath, value, comments, depth);
297
+ const indented = rendered.map((line) => (line === '' ? '' : `${indentOf(depth)}${line}`));
298
+ let next;
299
+ if (span !== null) {
300
+ // The section exists: replace exactly its span, so every other byte of
301
+ // the document — including a trailing comment block — is untouched.
302
+ let before = text.slice(0, span.start);
303
+ let after = text.slice(span.end);
304
+ if (before !== '' && !before.endsWith('\n'))
305
+ before += '\n';
306
+ if (after !== '' && !after.startsWith('\n'))
307
+ after = `\n${after}`;
308
+ next = `${before}${rendered.join('\n')}${after}`;
309
+ }
310
+ else if (existing !== null) {
311
+ // The parent exists but the leaf does not: append the new leaf INSIDE
312
+ // the parent, at the parent's own indentation.
313
+ const at = sectionSpanOrRefuse(text, existing, path)?.end ?? text.length;
314
+ let before = text.slice(0, at);
315
+ let after = text.slice(at);
316
+ if (before !== '' && !before.endsWith('\n'))
317
+ before += '\n';
318
+ if (after !== '' && !after.startsWith('\n'))
319
+ after = `\n${after}`;
320
+ next = `${before}${indented.join('\n')}${after}`;
321
+ }
322
+ else {
323
+ // Nothing of the path exists: append the whole rendered chain at the
324
+ // end of the document, separated by one blank line.
325
+ const head = text.replace(/\n+$/, '');
326
+ next = head === '' ? `${indented.join('\n')}\n` : `${head}\n\n${indented.join('\n')}\n`;
327
+ }
328
+ // Fail closed: the block this writer produced must parse back to exactly
329
+ // what was asked for, so no later reader ever sees a section that differs
330
+ // from the one the command reported.
331
+ const document = parseDocument(next);
332
+ if (document.errors.length > 0) {
333
+ throw new UsageError(`writing ${keyPath.join('.')} into ${path} produced invalid YAML and was refused: ` +
334
+ `${document.errors[0]?.message.split('\n')[0] ?? 'parse error'}`);
335
+ }
336
+ let read = document.toJS();
337
+ for (const step of keyPath) {
338
+ if (read === null || typeof read !== 'object' || !(step in read)) {
339
+ throw new UsageError(`writing ${keyPath.join('.')} into ${path} would not read back as the declared value; ` +
340
+ 'nothing was written — edit the file by hand');
341
+ }
342
+ read = read[step];
343
+ }
344
+ if (canonical(read) !== canonical(value)) {
345
+ throw new UsageError(`writing ${keyPath.join('.')} into ${path} would not read back as the declared value; nothing was ` +
346
+ 'written — edit the file by hand');
347
+ }
348
+ return next;
349
+ }
350
+ /**
351
+ * The longest prefix of `keyPath` the document already declares as a
352
+ * mapping, or null when the document declares none of it.
353
+ *
354
+ * @param text - the document's exact current text.
355
+ * @param keyPath - the section's key path.
356
+ * @param path - repo-relative document path, named in refusals.
357
+ * @returns the declared prefix length, as a path.
358
+ */
359
+ function longestExistingPrefix(text, keyPath, path) {
360
+ for (let length = keyPath.length - 1; length >= 1; length -= 1) {
361
+ const candidate = keyPath.slice(0, length);
362
+ if (sectionSpanOrRefuse(text, candidate, path) !== null)
363
+ return candidate;
364
+ }
365
+ return null;
366
+ }
367
+ /**
368
+ * Reports whether a YAML document declares a section.
369
+ *
370
+ * @param text - the document's exact text.
371
+ * @param keyPath - the section's key path.
372
+ * @param path - repo-relative document path, named in refusals.
373
+ * @returns true when the key is present at every level of the path.
374
+ * @throws UsageError when the document does not parse or is not a mapping.
375
+ */
376
+ export function declaresSection(text, keyPath, path) {
377
+ // An UNREADABLE existing section is still a declared section: the caller
378
+ // only asks "does the owner have this answer?", and the answer is yes.
379
+ // The writer that follows is the one that refuses by name.
380
+ try {
381
+ return sectionSpan(text, keyPath, path) !== null;
382
+ }
383
+ catch (error) {
384
+ if (error instanceof UnreadableSection)
385
+ return true;
386
+ throw error;
387
+ }
388
+ }
389
+ /**
390
+ * Cuts one TOP-LEVEL key out of a document, handing back the comment block
391
+ * that stood directly above it.
392
+ *
393
+ * The block above a key is that key's documentation by YAML convention, so
394
+ * a caller that moves the key elsewhere can carry the note to its new home
395
+ * instead of leaving it to be read as the next key's.
396
+ *
397
+ * @param text - the document's exact current text.
398
+ * @param key - the top-level key to remove.
399
+ * @param path - repo-relative document path, named in refusals.
400
+ * @returns the removal, or null when the document declares no such key.
401
+ * @throws UsageError when the document does not parse or is not a mapping.
402
+ */
403
+ export function removeTopLevelSection(text, key, path) {
404
+ const span = sectionSpan(text, [key], path);
405
+ if (span === null)
406
+ return null;
407
+ // Walk back from the key's own line over the contiguous comment lines
408
+ // above it (and the blank line that separates them from the rest), so the
409
+ // note travels with its key instead of being left to annotate the next.
410
+ let start = text.lastIndexOf('\n', span.start - 1);
411
+ start = start === -1 ? 0 : start + 1;
412
+ const lines = text.slice(0, start).split('\n');
413
+ // `slice` stops right after the previous newline, so the split ends on an
414
+ // empty element that is not a line of the document — drop it before
415
+ // walking back, or the walk stops on it instead of on a comment.
416
+ if (lines[lines.length - 1] === '')
417
+ lines.pop();
418
+ const notes = [];
419
+ while (lines.length > 0) {
420
+ const last = lines[lines.length - 1];
421
+ if (last === undefined || !/^\s*#/.test(last))
422
+ break;
423
+ notes.unshift(last.trim());
424
+ lines.pop();
425
+ }
426
+ if (notes.length > 0) {
427
+ // One blank line above the comment block belongs to it, not to whatever
428
+ // precedes it.
429
+ const blank = lines.pop();
430
+ if (blank !== undefined && blank.trim() === '')
431
+ start -= blank.length + 1;
432
+ start -= notes.reduce((total, note) => total + note.length + 1, 0);
433
+ }
434
+ // Swallow exactly one blank line AFTER the removed block, so the removal
435
+ // does not leave a double gap; every other blank line is the owner's.
436
+ let end = span.end;
437
+ const after = text.slice(end);
438
+ const trailing = /^\n[ \t]*\n/.exec(after);
439
+ if (trailing !== null)
440
+ end += trailing[0].length - 1;
441
+ return { text: `${text.slice(0, start)}${text.slice(end)}`, comments: notes };
442
+ }
443
+ //# sourceMappingURL=yaml-section.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml-section.js","sourceRoot":"","sources":["../src/yaml-section.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,EACL,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,aAAa,EACb,SAAS,IAAI,aAAa,GAC3B,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoBzC,kEAAkE;AAClE,MAAM,iBAAkB,SAAQ,KAAK;CAAG;AAUxC;;;;;;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;IACrE,CAAC;IACD,yEAAyE;IACzE,sEAAsE;IACtE,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACnB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,QAAQ,KAAK,IAAI;QAAE,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACrD,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAChF,CAAC"}
package/dist/yaml.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /** Reads a YAML document fail-closed (missing/unparsable → UsageError). */
2
+ export declare function loadYaml(path: string, label: string): unknown;
3
+ /** First zod issue as one actionable `path: message` line. */
4
+ export declare function firstIssueText(error: {
5
+ issues?: Array<{
6
+ path: PropertyKey[];
7
+ message: string;
8
+ }>;
9
+ }, fallback: string): string;
10
+ //# sourceMappingURL=yaml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAaA,2EAA2E;AAC3E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAe7D;AAED,8DAA8D;AAC9D,wBAAgB,cAAc,CAC5B,KAAK,EAAE;IAAE,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,WAAW,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,EACnE,QAAQ,EAAE,MAAM,GACf,MAAM,CAGR"}
package/dist/yaml.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The shared fail-closed YAML reader and zod-issue formatter.
3
+ *
4
+ * Both live in their own module (not in `pipeline.ts`) so the modules
5
+ * that read ONE owner document — `owner-answers.ts`, reached from
6
+ * `route-plane-proposals.ts` for the `init` plane proposals — can reuse
7
+ * them without importing the whole pipeline and closing an import cycle.
8
+ */
9
+ import { readFileSync } from 'node:fs';
10
+ import { parse as parseYaml } from 'yaml';
11
+ import { jsonPathFor } from '@gate-forge/core';
12
+ import { UsageError } from './errors.js';
13
+ /** Reads a YAML document fail-closed (missing/unparsable → UsageError). */
14
+ export function loadYaml(path, label) {
15
+ let raw;
16
+ try {
17
+ raw = readFileSync(path, 'utf8');
18
+ }
19
+ catch (error) {
20
+ const code = error.code ?? 'UNKNOWN';
21
+ throw new UsageError(`cannot read ${label} file '${path}' (${code})`);
22
+ }
23
+ try {
24
+ return parseYaml(raw);
25
+ }
26
+ catch (error) {
27
+ throw new UsageError(`${label} file '${path}' is not valid YAML: ${error.message.split('\n')[0] ?? 'parse error'}`);
28
+ }
29
+ }
30
+ /** First zod issue as one actionable `path: message` line. */
31
+ export function firstIssueText(error, fallback) {
32
+ const issue = error.issues?.[0];
33
+ return issue === undefined ? fallback : `${jsonPathFor(issue.path)}: ${issue.message}`;
34
+ }
35
+ //# sourceMappingURL=yaml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.js","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAa;IAClD,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,GAAI,KAA+B,CAAC,IAAI,IAAI,SAAS,CAAC;QAChE,MAAM,IAAI,UAAU,CAAC,eAAe,KAAK,UAAU,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,UAAU,CAClB,GAAG,KAAK,UAAU,IAAI,wBAAyB,KAAe,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa,EAAE,CACzG,CAAC;IACJ,CAAC;AACH,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,cAAc,CAC5B,KAAmE,EACnE,QAAgB;IAEhB,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;AACzF,CAAC"}
@@ -15,7 +15,7 @@ ONE next action.
15
15
  `gateforge init` → answer the plane questions → `gateforge adopt` (only when the repository already has code) → adapters and runtime → pin the owner-approved policy digest → commit. Each step assumes the previous one ran.
16
16
  - Install the CLI and packs, then commit the install (package.json + lockfile) on its own before `gateforge init` — no gate is wired yet. The setup commit must contain only Gateforge's own files (plus the `.gitignore` block init writes) to count as product-behavior-neutral; mixing in dependency or product changes makes it a normal gated change, which under strictE2E re-grades the adopted E2E debt as blocking. Commit product changes (for example a Playwright config rename) separately, after the setup commit.
17
17
 
18
- - **Answer the plane questions** with `gateforge classify plane <folder> <tenant|master|global> --reason "<why>" --confirm` (run `gateforge init --planes` once first to create the owner-reviewed `.gateforge/planes.json`). The three planes:
18
+ - **Answer the plane questions** with `gateforge classify plane <folder> <tenant|master|global> --reason "<why>" --confirm` (run `gateforge init --planes` once first to create the owner-reviewed `planes:` section of `.gateforge/classification-policy.yml`). The three planes:
19
19
  - **tenant** — the data of one customer or organisation, e.g. a per-customer database or rows scoped by a customer id.
20
20
  - **master** — the platform's own administrative data, shared by the operator, e.g. the admin platform's database of customers and plans.
21
21
  - **global** — reference data that is the same for everyone, e.g. currencies.
@@ -11,7 +11,7 @@ You need Node.js 20 or newer and an existing Playwright suite that can run again
11
11
  `gateforge init` → answer the plane questions → `gateforge adopt` (only when the repository already has code) → adapters and runtime → pin the owner-approved policy digest → commit.
12
12
 
13
13
  - Install the CLI and packs, then commit the install (package.json + lockfile) on its own before `gateforge init` — no gate is wired yet. The setup commit must contain only Gateforge's own files (plus the `.gitignore` block init writes) to count as product-behavior-neutral; mixing in dependency or product changes makes it a normal gated change, which under strictE2E re-grades the adopted E2E debt as blocking. Commit product changes (for example a Playwright config rename) separately, after the setup commit.
14
- - Answer the plane questions with `gateforge classify plane <folder> <tenant|master|global> --reason "<why>" --confirm` (run `gateforge init --planes` once first to create the owner-reviewed `.gateforge/planes.json`).
14
+ - Answer the plane questions with `gateforge classify plane <folder> <tenant|master|global> --reason "<why>" --confirm` (run `gateforge init --planes` once first to create the owner-reviewed `planes:` section of `.gateforge/classification-policy.yml`).
15
15
  - Adopt comes after the plane answers because a plane answer changes a resource's identity, so the debt set `adopt` records would not match the repository if it were captured before the answer.
16
16
  - Declare the dependency directories the staged commit gate may link (`prepare: { reuse: [node_modules] }` in `.gateforge/runtime.yml`): the gate runs on a checkout of the staged files only.
17
17
  - Pin the owner-approved policy digest LAST, right before the first strict commit: `git add -A .gateforge .gateforge.yml && gateforge enforcement pin --pin-file ~/.config/<repo>.gateforge.env --confirm`. The flag is `--pin-file`, not `--env-file`: node itself consumes `--env-file <path>` anywhere in argv and would read the file instead of running the command. Without `--confirm` the command only prints the line it would write. The pin file must live OUTSIDE the repository — a file the candidate controls cannot approve its own policy revision — and the command refuses any path inside the repo, plus a policy input that is not fully staged (it names the file). The digest changes whenever a policy input changes — `.gateforge.yml`, the policies, the classification policy, `.gateforge/test-map.yml`, `planes.json`, adapters, `runtime.yml`, waivers, hooks — so re-pin after every such edit. `gateforge enforcement doctor` names the inputs that changed since HEAD (`policy-inputs-vs-HEAD`) and whether the provisioned pin still matches the staged bytes (`approved-digest`).
@@ -24,11 +24,11 @@ Example for a React frontend, FastAPI backend, and SQLAlchemy data layer:
24
24
 
25
25
  ```sh
26
26
  npm i -D \
27
- @gate-forge/cli@0.10.4 \
28
- @gate-forge/pack-playwright@0.10.4 \
29
- @gate-forge/pack-http@0.10.4 \
30
- @gate-forge/pack-fastapi@0.10.4 \
31
- @gate-forge/pack-sqlalchemy@0.10.4
27
+ @gate-forge/cli@0.11.0 \
28
+ @gate-forge/pack-playwright@0.11.0 \
29
+ @gate-forge/pack-http@0.11.0 \
30
+ @gate-forge/pack-fastapi@0.11.0 \
31
+ @gate-forge/pack-sqlalchemy@0.11.0
32
32
  ```
33
33
 
34
34
  Use the project-local `gateforge` binary from your npm script or add `node_modules/.bin` to your shell `PATH`. If the scan recommends other packs, add only the ones your code uses, at the same version. A mismatched Gateforge package contract can stop the CLI with exit code 2 and `GATEFORGE_PACKAGE_INCOMPATIBLE`.
@@ -49,7 +49,7 @@ This installs every pack of the release; the scan still recommends the ones your
49
49
 
50
50
  **You should see:** npm installs the packages without a Gateforge compatibility error.
51
51
 
52
- **If not:** align every direct `@gate-forge/*` package to `0.10.4`, then install again. Do not work around the compatibility error.
52
+ **If not:** align every direct `@gate-forge/*` package to `0.11.0`, then install again. Do not work around the compatibility error.
53
53
 
54
54
  ## 2. Pick a goal
55
55
 
@@ -445,7 +445,7 @@ the registry. To gate a release that is not on the registry yet (a local
445
445
  regenerate:
446
446
 
447
447
  ```sh
448
- GATEFORGE_CI_ENGINE_SOURCE=vendor/gate-forge-cli-0.10.4.tgz \
448
+ GATEFORGE_CI_ENGINE_SOURCE=vendor/gate-forge-cli-0.11.0.tgz \
449
449
  gateforge enforce --ci github
450
450
  ```
451
451