gcf-aif-ext 0.18.4 → 0.18.6

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.
package/README.md CHANGED
@@ -50,6 +50,15 @@ Updating preserves `gcf/`, `cnlp.config.json` and the pre-commit hook. Run `ai-f
50
50
 
51
51
  On Windows, run `extension add` and `extension update` from PowerShell or cmd, not Git Bash: the installer unpacks with `tar`, and Git Bash's GNU tar reads `C:\…` as a remote host (`Cannot connect to C: resolve failed`). The Windows `tar.exe` handles it.
52
52
 
53
+ ### 0.18.6
54
+
55
+ - A multi-line note of `gcf verdict tune` or `gcf unblock --note` (the board's What to change box) is written as one bullet per line. Before, the second line went in without `- ` and the pre-commit gate refused the move with `M1: "tuning:" is a bullet-list — every item opens with "- "`.
56
+
57
+ ### 0.18.5
58
+
59
+ - `gcf verdict tune` and `gcf unblock --note` put a new `tuning:` / `notes:` block where the unit's profile orders it, before `notes:` and `provenance:`; a verdict merge does the same with `feel:` and `open:` in `systems/`. Before, the block went to the end of the body and the pre-commit gate refused the move with `M1: blocks out of order`. A block a hand left out of order moves to its place on the next write, so a `tuning:` inserted by hand as a workaround needs no cleanup.
60
+ - A move refused because another file in `gcf/` holds uncommitted changes says so in plain words: `cannot record <move> while gcf/ holds uncommitted changes: <files> — commit or discard them, then try again`. gcf-board 0.16.5 shows a refused proposal's message without node's stack.
61
+
53
62
  ### 0.18.4
54
63
 
55
64
  - The `attach` move's field is of the new kind `file` (Board-PRD §5.4): gcf-board 0.16.3 picks it in the system's file dialog instead of a text box for a path. A board before 0.16.3 shows it as a text box, as before. The command itself is unchanged.
package/extension.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/lee-to/ai-factory/2.x/schemas/extension.schema.json",
3
3
  "name": "gcf-aif-ext",
4
- "version": "0.18.4",
4
+ "version": "0.18.6",
5
5
  "description": "Game Context Framework for AI Factory",
6
6
  "skills": [
7
7
  "skills/gcf-init",
@@ -35,6 +35,7 @@ import { buildLedger } from './ledger.js';
35
35
  import { deriveId } from './id.js';
36
36
  import { renamePillar } from './pillars.js';
37
37
  import { dirtyPaths } from './git.js';
38
+ import { blocksOf, putBlock } from './systems-doc.js';
38
39
 
39
40
  const PROFILES_DIR = fileURLToPath(new URL('../profiles/', import.meta.url));
40
41
  // The work stage writes these blocks: a unit in design/ has not reached them.
@@ -93,23 +94,6 @@ async function specsOf(kind, name, type) {
93
94
  return [...header, ...blocks];
94
95
  }
95
96
 
96
- /**
97
- * The top-level blocks of a text: key, value on its line, and its lines (1-based, `end`
98
- * inclusive) up to the next block or `##` heading, trailing blank lines left out.
99
- */
100
- function blocksOf(text) {
101
- const { lines, sections } = parseBlocks(text);
102
-
103
- return sections.map((s, i) => {
104
- let end = (sections[i + 1]?.line ?? lines.length + 1) - 1;
105
- const heading = lines.slice(s.line, end).findIndex((l) => /^##\s/.test(l));
106
- if (heading >= 0) end = s.line + heading;
107
- while (end > s.line && !lines[end - 1].trim()) end--;
108
-
109
- return { key: s.key, value: s.value, start: s.line, end };
110
- });
111
- }
112
-
113
97
  const oneLine = (v) =>
114
98
  String(v ?? '')
115
99
  .replace(/\s+/g, ' ')
@@ -265,32 +249,6 @@ export async function designPart(projectDir, kind, name, { type = null } = {}) {
265
249
  };
266
250
  }
267
251
 
268
- /** `lines` with block `spec` set to `rendered`: in place, or where the field order puts it. */
269
- function putBlock(lines, specs, spec, rendered) {
270
- const blocks = blocksOf(lines.join('\n'));
271
- const at = blocks.find((b) => b.key === spec.key);
272
- if (at) {
273
- // A dropped block takes one of the blank lines around it along.
274
- const drop = !rendered.length && !lines[at.start - 2]?.trim() && !lines[at.end]?.trim();
275
-
276
- return [...lines.slice(0, at.start - 1), ...rendered, ...lines.slice(at.end + (drop ? 1 : 0))];
277
- }
278
-
279
- if (!rendered.length) return lines;
280
- const order = specs.map((s) => s.key);
281
- const header = (b) => Boolean(specs.find((s) => s.key === b?.key)?.header);
282
- // Header fields stand line under line; a block stands apart from its neighbours.
283
- const tight = (b) => Boolean(spec.header && header(b));
284
- const prev = blocks.filter((b) => order.indexOf(b.key) < order.indexOf(spec.key)).at(-1);
285
- if (!prev)
286
- return blocks.length ? [...rendered, ...(tight(blocks[0]) ? [] : ['']), ...lines] : rendered;
287
- const tail = lines.slice(prev.end);
288
- const gap = tight(prev) ? [] : [''];
289
- const after = !tight(prev) && tail[0]?.trim() ? [''] : [];
290
-
291
- return [...lines.slice(0, prev.end), ...gap, ...rendered, ...after, ...tail];
292
- }
293
-
294
252
  /** A unit nobody wrote yet: its header, every block it owes as TBD. */
295
253
  function skeleton(specs, { id, type, system, title }) {
296
254
  const soft = CARD_TYPES.includes(type);
package/lib/design.js CHANGED
@@ -33,6 +33,9 @@ const PROFILES_DIR = fileURLToPath(new URL('../profiles/', import.meta.url));
33
33
  /** The CNL-P profile of a document kind shipped in profiles/ (`unit-mechanic`, `game`, …). */
34
34
  export const loadDocProfile = (name) => loadProfileAt(path.join(PROFILES_DIR, `${name}.md`));
35
35
 
36
+ /** A doc profile's block keys in the order M1 holds a body to. */
37
+ export const blockOrder = async (name) => (await loadDocProfile(name)).sections.map((s) => s.key);
38
+
36
39
  /** `[a, b]`, `a, b` → ['a', 'b']; `none` and `[]` → []; `TBD` stays the string 'TBD'. */
37
40
  export function listOf(value) {
38
41
  const v = String(value ?? '').trim();
package/lib/git.js CHANGED
@@ -109,7 +109,15 @@ export function commitPaths(projectDir, message, paths, move = {}) {
109
109
  cwd: projectDir,
110
110
  encoding: 'utf8',
111
111
  });
112
- if (res.status !== 0) throw new Error(`commit failed: ${res.stderr || res.stdout}`);
112
+ const out = res.stderr || res.stdout;
113
+ // The gate reads the whole gcf/ tree: another file's edit stops the move, in the Operator's words.
114
+ const loose = /gcf\/ has changes outside the index \((.*)\) — stage them/.exec(out)?.[1];
115
+ if (res.status !== 0 && loose)
116
+ throw new Error(
117
+ `cannot record ${message} while gcf/ holds uncommitted changes: ${loose} — ` +
118
+ 'commit or discard them, then try again',
119
+ );
120
+ if (res.status !== 0) throw new Error(`commit failed: ${out}`);
113
121
 
114
122
  return spawnSync('git', ['rev-parse', 'HEAD'], {
115
123
  cwd: projectDir,
@@ -20,11 +20,61 @@ export function blockLines(body, key) {
20
20
  return at ? itemsOf(prose, at.line).map((i) => i.text) : [];
21
21
  }
22
22
 
23
+ /**
24
+ * The top-level blocks of a text: key, value on its line, and its lines (1-based, `end`
25
+ * inclusive) up to the next block or `##` heading, trailing blank lines left out. A comment or
26
+ * a code fence reads as blank there, unless `raw`: then a trailing one stays in its block.
27
+ */
28
+ export function blocksOf(text, { raw = false } = {}) {
29
+ const { lines, sections } = parseBlocks(text);
30
+ const ends = raw ? text.split('\n') : lines;
31
+
32
+ return sections.map((s, i) => {
33
+ let end = (sections[i + 1]?.line ?? lines.length + 1) - 1;
34
+ const heading = lines.slice(s.line, end).findIndex((l) => /^##\s/.test(l));
35
+ if (heading >= 0) end = s.line + heading;
36
+ while (end > s.line && !ends[end - 1].trim()) end--;
37
+
38
+ return { key: s.key, value: s.value, start: s.line, end };
39
+ });
40
+ }
41
+
42
+ /**
43
+ * `lines` with block `spec` set to `rendered`: in place, or where the field order puts it.
44
+ * `raw`: as blocksOf's, a comment or fence closing the block before stays above the new one.
45
+ */
46
+ export function putBlock(lines, specs, spec, rendered, { raw = false } = {}) {
47
+ const blocks = blocksOf(lines.join('\n'), { raw });
48
+ const at = blocks.find((b) => b.key === spec.key);
49
+ if (at) {
50
+ // A dropped block takes one of the blank lines around it along.
51
+ const drop = !rendered.length && !lines[at.start - 2]?.trim() && !lines[at.end]?.trim();
52
+
53
+ return [...lines.slice(0, at.start - 1), ...rendered, ...lines.slice(at.end + (drop ? 1 : 0))];
54
+ }
55
+
56
+ if (!rendered.length) return lines;
57
+ const order = specs.map((s) => s.key);
58
+ const header = (b) => Boolean(specs.find((s) => s.key === b?.key)?.header);
59
+ // Header fields stand line under line; a block stands apart from its neighbours.
60
+ const tight = (b) => Boolean(spec.header && header(b));
61
+ const prev = blocks.filter((b) => order.indexOf(b.key) < order.indexOf(spec.key)).at(-1);
62
+ if (!prev)
63
+ return blocks.length ? [...rendered, ...(tight(blocks[0]) ? [] : ['']), ...lines] : rendered;
64
+ const tail = lines.slice(prev.end);
65
+ const gap = tight(prev) ? [] : [''];
66
+ const after = !tight(prev) && tail[0]?.trim() ? [''] : [];
67
+
68
+ return [...lines.slice(0, prev.end), ...gap, ...rendered, ...after, ...tail];
69
+ }
70
+
23
71
  /**
24
72
  * Append `addLines` to the `key:` bullet block of a body, skipping lines already there. A
25
- * `- none: …` placeholder gives way: CNL-P reads it as the whole content or not at all.
73
+ * `- none: …` placeholder gives way: CNL-P reads it as the whole content or not at all. The
74
+ * block stands where `order` (the profile's block keys, see blockOrder) puts it: M1 refuses
75
+ * any other place.
26
76
  */
27
- export function upsertBlock(rawBody, key, addLines) {
77
+ export function upsertBlock(rawBody, key, addLines, order) {
28
78
  // A CRLF checkout: `\r` before each `\n` would stop the block match at its first line and
29
79
  // duplicate every line after it.
30
80
  const body = lf(rawBody);
@@ -32,12 +82,24 @@ export function upsertBlock(rawBody, key, addLines) {
32
82
  const fresh = addLines.filter((l) => !existing.includes(l));
33
83
  if (!fresh.length) return body;
34
84
  const kept = existing.filter((l) => !/^- none\b/.test(l));
35
- const block = `${key}:\n${[...kept, ...fresh].join('\n')}\n`;
36
- const re = new RegExp(`^${key}:[^\\n]*\\n(?:(?!\\S+:).*\\n?)*`, 'm');
37
- // A replacer function: a string replacement would expand `$&` or `$'` inside a line.
38
- if (re.test(body)) return body.replace(re, () => `${block}\n`).replace(/\n{3,}/g, '\n\n');
85
+ // A key the profile does not know goes last, after every block it does.
86
+ const specs = (order.includes(key) ? order : [...order, key]).map((k) => ({ key: k }));
87
+ const lead = body.match(/^\n*/)[0];
88
+ const text = body.slice(lead.length);
89
+ let lines = text.split('\n');
90
+ // Out and back in: a block a hand left out of the profile's order moves to its place.
91
+ const at = blocksOf(text).find((b) => b.key === key);
92
+ if (at) {
93
+ // Up to its last item: a closing pragma is one, though the range reads it as blank.
94
+ const { prose } = parseBlocks(text);
95
+ const end = Math.max(at.end, ...itemsOf(prose, at.start).map((i) => i.line));
96
+ lines = [...lines.slice(0, at.start - 1), ...lines.slice(end)];
97
+ while (lines.length > 1 && !lines[0].trim()) lines.shift();
98
+ while (lines.length > 1 && !lines.at(-1).trim() && !lines.at(-2).trim()) lines.pop();
99
+ }
100
+ const put = putBlock(lines, specs, { key }, [`${key}:`, ...kept, ...fresh], { raw: true });
39
101
 
40
- return `${body.trimEnd()}\n\n${block}`;
102
+ return `${lead}${put.join('\n')}`.replace(/\n{3,}/g, '\n\n');
41
103
  }
42
104
 
43
105
  /**
package/lib/unit-ops.js CHANGED
@@ -6,7 +6,7 @@ import { existsSync, readFileSync } from 'node:fs';
6
6
  import { spawnSync } from 'node:child_process';
7
7
  import path from 'node:path';
8
8
  import { serialize } from './frontmatter.js';
9
- import { CARD_TYPES, SLUG_RE, listOf } from './design.js';
9
+ import { CARD_TYPES, SLUG_RE, blockOrder, listOf } from './design.js';
10
10
  import { buildLedger } from './ledger.js';
11
11
  import { cycleMessage, designCheck, dependsGraph, pathTo } from './design-check.js';
12
12
  import { atomicWrite, withFileRollback } from './safe-path.js';
@@ -334,6 +334,7 @@ export async function addConstraints(doc, id, constraints) {
334
334
  doc.body,
335
335
  'constraints',
336
336
  constraints.map((c) => `- ${c}`),
337
+ await blockOrder('system'),
337
338
  );
338
339
  await atomicWrite(doc.file, serialize({ ...doc.data, updated_by: id }, body));
339
340
  }
package/lib/verdict-fs.js CHANGED
@@ -9,6 +9,7 @@ import { parseBlocks, itemsOf, readRecords } from 'cnlp-kit';
9
9
  import { serialize } from './frontmatter.js';
10
10
  import { atomicWrite, resolveInside } from './safe-path.js';
11
11
  import { blockLines, upsertBlock, removeLines, openSystemDoc } from './systems-doc.js';
12
+ import { blockOrder } from './design.js';
12
13
 
13
14
  const ENVELOPE = /^\S+\.\.\S+ /;
14
15
  const real = (lines) => lines.filter((l) => !/^- none\b/.test(l));
@@ -75,9 +76,10 @@ export const systemFiles = (root, systems) =>
75
76
  /** Merge the item's lines into one systems doc; a new doc starts from design/'s purpose. */
76
77
  export async function mergeIntoSystem(root, system, item) {
77
78
  const doc = await openSystemDoc(root, system);
79
+ const order = await blockOrder('system');
78
80
  let body = doc.body;
79
81
  for (const [section, lines] of Object.entries(collapseLines(item.body))) {
80
- body = upsertBlock(body, section, lines);
82
+ body = upsertBlock(body, section, lines, order);
81
83
  }
82
84
 
83
85
  await atomicWrite(doc.file, serialize({ ...doc.data, updated_by: item.data.id }, body));
package/lib/work-ops.js CHANGED
@@ -17,6 +17,7 @@ import { ITEM_TYPES, DEFAULT_GATE, GATES, SEVERITIES, UNIT_ITEM_TYPES } from './
17
17
  import { deriveId, isValidId } from './id.js';
18
18
  import { commitMove, addConstraints, onWorkBranch } from './unit-ops.js';
19
19
  import { openSystemDoc, upsertBlock } from './systems-doc.js';
20
+ import { blockOrder } from './design.js';
20
21
  import {
21
22
  collapseLines,
22
23
  mergeIntoSystem,
@@ -295,6 +296,21 @@ const unverifiedTail = (opts) =>
295
296
  (opts.unticked ? ` (unticked: ${opts.unticked})` : '');
296
297
 
297
298
  const writeItem = (item, data, body = item.body) => atomicWrite(item.file, serialize(data, body));
299
+ /**
300
+ * A note into an item's `key:` block, where its unit profile orders it (M1). A note from a
301
+ * multi-line box gives a bullet per line: a line without `- ` breaks the bullet-list (M1).
302
+ */
303
+ const upsertItemNote = async (item, key, note) =>
304
+ upsertBlock(
305
+ item.body,
306
+ key,
307
+ String(note)
308
+ .split(/\r?\n/)
309
+ .map((l) => l.trim().replace(/^[-*]\s+/, ''))
310
+ .filter(Boolean)
311
+ .map((l) => `- ${l}`),
312
+ UNIT_ITEM_TYPES.includes(item.data.type) ? await blockOrder(`unit-${item.data.type}`) : [],
313
+ );
298
314
 
299
315
  /** `data` without the keys named — a field that no longer applies leaves the frontmatter. */
300
316
  const without = (data, ...keys) =>
@@ -674,7 +690,7 @@ async function tune(m, note) {
674
690
  'redesigned envelope is a new item with reopens: <this id>',
675
691
  );
676
692
  if (item.data.status === 'unplayed') unplay(m, item);
677
- const body = note ? upsertBlock(item.body, 'tuning', [`- ${note}`]) : item.body;
693
+ const body = note ? await upsertItemNote(item, 'tuning', note) : item.body;
678
694
  const data = {
679
695
  ...without(item.data, 'frozen'),
680
696
  status: 'ready',
@@ -798,7 +814,7 @@ async function unblockItemUnlocked(projectDir, id, opts = {}) {
798
814
  const { note = '', commit = true } = opts;
799
815
  const m = await begin(projectDir, id, 'unblock');
800
816
  if (m.item.data.status === 'parked') dropKnownIssue(m, id);
801
- const body = note ? upsertBlock(m.item.body, 'notes', [`- ${note}`]) : m.item.body;
817
+ const body = note ? await upsertItemNote(m.item, 'notes', note) : m.item.body;
802
818
  // A feature whose child died while it was blocked owes the operator that decision first; the
803
819
  // death is the one parentWaits wrote into `blocked:`, not any death of the feature's past.
804
820
  const childDied = / child \S+ died/.test(String(m.item.data.blocked ?? ''));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-aif-ext",
3
- "version": "0.18.4",
3
+ "version": "0.18.6",
4
4
  "description": "Game Context Framework for AI Factory",
5
5
  "type": "module",
6
6
  "license": "MIT",