gcf-aif-ext 0.20.2 → 0.22.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 (42) hide show
  1. package/GLOSSARY.md +26 -0
  2. package/README.md +19 -0
  3. package/commands/gcf.js +92 -6
  4. package/extension.json +6 -1
  5. package/injections/improve-plan.md +7 -0
  6. package/injections/plan-context.md +10 -1
  7. package/lib/bundle.js +4 -5
  8. package/lib/changes.js +643 -0
  9. package/lib/config-set.js +19 -1
  10. package/lib/design-check.js +47 -18
  11. package/lib/design-parts.js +27 -17
  12. package/lib/design.js +24 -3
  13. package/lib/domain.js +4 -2
  14. package/lib/edits.js +2 -13
  15. package/lib/gate.js +13 -1
  16. package/lib/gcf-paths.js +10 -0
  17. package/lib/git.js +22 -2
  18. package/lib/index-gen.js +5 -4
  19. package/lib/linter.js +5 -3
  20. package/lib/plan-check.js +52 -2
  21. package/lib/tree-file.js +107 -0
  22. package/node_modules/cnlp-kit/CHANGELOG.md +23 -0
  23. package/node_modules/cnlp-kit/README.md +27 -1
  24. package/node_modules/cnlp-kit/bin/cnlp.js +1 -1
  25. package/node_modules/cnlp-kit/cnlp-format.md +13 -0
  26. package/node_modules/cnlp-kit/package.json +1 -1
  27. package/node_modules/cnlp-kit/profiles/glossary.md +38 -0
  28. package/node_modules/cnlp-kit/skills/cnlp-glossary/SKILL.md +50 -0
  29. package/node_modules/cnlp-kit/src/cnlp.js +10 -5
  30. package/node_modules/cnlp-kit/src/config.js +40 -3
  31. package/package.json +3 -2
  32. package/profiles/game.md +6 -0
  33. package/profiles/glossary.md +15 -14
  34. package/profiles/plan.md +52 -0
  35. package/skills/gcf-adopt/SKILL.md +1 -1
  36. package/skills/gcf-ingest/SKILL.md +4 -4
  37. package/skills/gcf-init/SKILL.md +1 -1
  38. package/skills/gcf-vision/SKILL.md +1 -1
  39. package/templates/agents-block.md +7 -2
  40. package/templates/config.yml +4 -0
  41. package/templates/game.md +3 -0
  42. package/templates/glossary.md +5 -5
@@ -5,6 +5,7 @@ import { readFile } from 'node:fs/promises';
5
5
  import { existsSync } from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { bodyIssues, lexiconIssues, parseBlocks, itemsOf, readRecords } from 'cnlp-kit';
8
+ import { glossaryAvoids } from 'cnlp-kit/config';
8
9
  import {
9
10
  SLUG_RE,
10
11
  UNIT_TYPES,
@@ -12,6 +13,8 @@ import {
12
13
  AGENT_SLOTS,
13
14
  listOf,
14
15
  loadDocProfile,
16
+ DOC_FILES,
17
+ docPath,
15
18
  slotValues,
16
19
  provenanceOf,
17
20
  isTbd,
@@ -22,7 +25,7 @@ import { collapseLines } from './verdict-fs.js';
22
25
  import { fieldOf } from './question-fields.js';
23
26
  import { blocksOf } from './systems-doc.js';
24
27
 
25
- // Units a number may carry. A project adds its own in the `units:` block of glossary.md.
28
+ // Units a number may carry. A project adds its own in the `units:` block of game.md.
26
29
  // Bare `px` is absent on purpose: its size depends on the screen density.
27
30
  export const UNITS = [
28
31
  ...['s', 'ms', 'min', 'h', '%', 'fps', 'KB', 'MB', 'GB', 'deg', 'm'],
@@ -49,7 +52,6 @@ export const REQUIRED_HEADER = [
49
52
  'source',
50
53
  ];
51
54
  const ws = (t) => String(t).replace(/\s+/g, ' ').trim();
52
- const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
53
55
 
54
56
  /**
55
57
  * @typedef {object} Issue
@@ -112,9 +114,6 @@ export const closingComparison = (line) => {
112
114
  return Boolean(cmp) && !/\d/.test(namesOut(v.slice(0, cmp?.index ?? 0)));
113
115
  };
114
116
 
115
- /** A whole-word, case-insensitive match that also works for Cyrillic (`\b` is ASCII-only). */
116
- const wordRe = (w) => new RegExp(`(?<![\\p{L}\\p{N}_])${escapeRe(w)}(?![\\p{L}\\p{N}_])`, 'iu');
117
-
118
117
  async function readIf(file) {
119
118
  return existsSync(file) ? readFile(file, 'utf8') : null;
120
119
  }
@@ -173,24 +172,26 @@ export function questionBlocks(text) {
173
172
 
174
173
  /** Everything outside a unit that its references resolve against. */
175
174
  async function loadContext(root) {
176
- const glossary = await readIf(path.join(root, 'glossary.md'));
175
+ const glossary = await readIf(path.join(root, DOC_FILES.glossary));
176
+ const game = await readIf(path.join(root, 'game.md'));
177
+ // A glossary not moved yet (before core 0.21) still lends its units: M5 does not block a
178
+ // number its project counted in them while the move waits (the review).
179
+ const old = await readIf(path.join(root, 'glossary.md'));
177
180
  const milestones = await gameMilestones(root);
178
181
  const pillars = await readIf(path.join(root, 'PILLARS.md'));
179
- const forbidden = recordsIn(glossary, 'terms').flatMap((t) => {
180
- const not = listOf(t.not ?? '');
181
-
182
- return not === 'TBD' ? [] : not;
183
- });
184
182
 
185
183
  return {
186
184
  milestones: milestones?.map((m) => m.name) ?? null,
187
185
  pillarIds: recordsIn(pillars, 'pillars')
188
186
  .map((p) => p.id)
189
187
  .filter(Boolean),
190
- forbidden: forbidden.map((w) => ({ word: w, re: wordRe(w) })),
188
+ // The words GLOSSARY.md avoids (cnlp's own reading); a draft's `avoid: TBD` bans no word.
189
+ forbidden: glossary === null ? [] : glossaryAvoids(glossary).filter((f) => f.word !== 'TBD'),
191
190
  units: [
192
191
  ...UNITS,
193
- ...itemsIn(glossary, 'units').map((i) => i.text.replace(/^- /, '').split(':')[0].trim()),
192
+ ...[...itemsIn(game, 'units'), ...itemsIn(old, 'units')].map((i) =>
193
+ i.text.replace(/^- /, '').split(':')[0].trim(),
194
+ ),
194
195
  ],
195
196
  questions: questionBlocks(await readIf(path.join(root, 'open-questions.md'))),
196
197
  sources: await sourceBodies(path.join(root, 'source')),
@@ -333,7 +334,8 @@ function valueIssues(values, ctx) {
333
334
  for (const v of values) {
334
335
  const text = judged(v.value, true);
335
336
  const hit = ctx.forbidden.find((f) => f.re.test(text));
336
- if (hit) out.push(['M4', v.line, `"${hit.word}" is a forbidden synonym in glossary.md`]);
337
+ if (hit)
338
+ out.push(['M4', v.line, `"${hit.word}" is a word GLOSSARY.md avoids — write "${hit.term}"`]);
337
339
  // `contract` names code — paths and types like Rigidbody2D — not quantities.
338
340
  const num = v.block === 'contract' ? null : numberProblem(v.block, v.value, ctx.units);
339
341
  if (num) out.push(['M5', v.line, `${num}: ${v.value}`]);
@@ -446,9 +448,9 @@ async function checkUnit(u, ctx, ledger) {
446
448
  return { issues, values };
447
449
  }
448
450
 
449
- /** M1 and M5 over a singleton document (game.md, glossary.md), `key: TBD` accepted. */
451
+ /** M1 and M5 over a singleton document (game.md, GLOSSARY.md), `key: TBD` accepted. */
450
452
  async function checkDoc(root, name, ctx) {
451
- const text = await readIf(path.join(root, `${name}.md`));
453
+ const text = await readIf(path.join(root, DOC_FILES[name]));
452
454
  if (text === null) return [];
453
455
  const profile = await loadDocProfile(name);
454
456
  const tbdLines = new Set(
@@ -459,7 +461,10 @@ async function checkDoc(root, name, ctx) {
459
461
  const shape = bodyIssues(text, profile).filter(
460
462
  (i) => !(tbdLines.has(i.line) && i.message.includes('carries a value on the key line')),
461
463
  );
462
- const nums = slotValues(text, profile).flatMap((v) => {
464
+ // The glossary is cnlp's document: a number in a term's meaning ("one of the 3 rows") is no
465
+ // quantity a design slot holds, and cnlp's own check passes it (the review).
466
+ const values = name === 'glossary' ? [] : slotValues(text, profile);
467
+ const nums = values.flatMap((v) => {
463
468
  const p = numberProblem(v.block, v.value, ctx.units);
464
469
 
465
470
  return p ? [{ line: v.line, message: `${p}: ${v.value}`, check: 'M5' }] : [];
@@ -468,13 +473,36 @@ async function checkDoc(root, name, ctx) {
468
473
  return [...shape.map((i) => ({ ...i, check: 'M1' })), ...nums].map((i) => ({
469
474
  check: i.check,
470
475
  severity: 'block',
471
- file: `${name}.md`,
476
+ // From gcf/, as the other findings are; the glossary by its own name, at the root.
477
+ file: DOC_FILES[name].replace(/^\.\.\//, ''),
472
478
  line: i.line,
473
479
  id: null,
474
480
  message: i.message,
475
481
  }));
476
482
  }
477
483
 
484
+ /**
485
+ * A glossary left at gcf/glossary.md, where GCF kept it before core 0.21: nothing reads it any
486
+ * more, so its avoided words hold nowhere until it moves (a report, not a block).
487
+ */
488
+ async function oldGlossary(root) {
489
+ if (!existsSync(path.join(root, 'glossary.md'))) return [];
490
+
491
+ return [
492
+ {
493
+ check: 'M1',
494
+ severity: 'report',
495
+ file: 'glossary.md',
496
+ line: 1,
497
+ id: null,
498
+ message:
499
+ `gcf/glossary.md is read no more: move it to ${docPath('glossary')} (git mv), give it a ` +
500
+ '`purpose:` block, turn each `not:` into `avoid:` (a word wrong in every document), and ' +
501
+ 'move `units:` into gcf/game.md',
502
+ },
503
+ ];
504
+ }
505
+
478
506
  /** Each design file opens with the subsystem's `purpose:` (`TBD` until someone writes it). */
479
507
  function preambleIssues(design) {
480
508
  return design
@@ -822,6 +850,7 @@ export async function designCheck(projectDir, { ledger: built = null } = {}) {
822
850
  for (const c of ledger.items) issues.push(...(await checkItem(c, ctx, ledger)));
823
851
  issues.push(...(await unplayedIssues(root, ledger)));
824
852
  for (const doc of ['game', 'glossary']) issues.push(...(await checkDoc(root, doc, ctx)));
853
+ issues.push(...(await oldGlossary(root)));
825
854
  issues.push(...preambleIssues(ledger.design));
826
855
  issues.push(...ledgerIssues(ledger), ...dependsCycles(ledger), ...questionIssues(ctx, ledger));
827
856
  if (ledger.design.length) {
@@ -1,5 +1,5 @@
1
1
  // The design as parts a board edits field by field (Board-PRD §5.24): PILLARS.md, game.md,
2
- // glossary.md, a subsystem's purpose, a unit. A part reads as the fields its CNL-P profile
2
+ // the project's GLOSSARY.md, a subsystem's purpose, a unit. A part reads as the fields its CNL-P profile
3
3
  // declares; a save writes the edited fields back into the part's text and brings it in as a
4
4
  // one-part bundle (lib/bundle.js), so a form edit passes the same three-way check and the same
5
5
  // design check a designer's import does. The board writes no file of gcf/ itself.
@@ -7,7 +7,6 @@ import { readFile, readdir } from 'node:fs/promises';
7
7
  import { existsSync } from 'node:fs';
8
8
  import { spawnSync } from 'node:child_process';
9
9
  import path from 'node:path';
10
- import { fileURLToPath } from 'node:url';
11
10
  import { parseBlocks, itemsOf, readRecords } from 'cnlp-kit';
12
11
  import {
13
12
  HEADER_KEYS,
@@ -15,13 +14,22 @@ import {
15
14
  UNIT_TYPES,
16
15
  CARD_TYPES,
17
16
  loadDocProfile,
17
+ profileFile,
18
18
  parseDesign,
19
19
  provenanceOf,
20
20
  readDesign,
21
21
  slotValues,
22
22
  listOf,
23
23
  } from './design.js';
24
- import { DOC_FILES, hashOf, importBundle, parseBundle, purposeOf, unitText } from './bundle.js';
24
+ import {
25
+ DOC_FILES,
26
+ docPath,
27
+ hashOf,
28
+ importBundle,
29
+ parseBundle,
30
+ purposeOf,
31
+ unitText,
32
+ } from './bundle.js';
25
33
  import {
26
34
  REQUIRED_HEADER,
27
35
  designCheck,
@@ -37,7 +45,6 @@ import { renamePillar } from './pillars.js';
37
45
  import { dirtyPaths, restoreFromHead } from './git.js';
38
46
  import { blocksOf, putBlock } from './systems-doc.js';
39
47
 
40
- const PROFILES_DIR = fileURLToPath(new URL('../profiles/', import.meta.url));
41
48
  // The work stage writes these blocks: a unit in design/ has not reached them.
42
49
  const WORK_ONLY = ['contract', 'interactions', 'tuning', 'notes'];
43
50
  // What a unit's header field takes, for the form's help.
@@ -67,7 +74,7 @@ const lf = (t) => String(t ?? '').replace(/\r\n/g, '\n');
67
74
 
68
75
  /** The `note:` of each section a profile declares: the help a form shows beside its field. */
69
76
  async function notesOf(name) {
70
- const raw = await readFile(path.join(PROFILES_DIR, `${name}.md`), 'utf8');
77
+ const raw = await readFile(profileFile(name), 'utf8');
71
78
 
72
79
  return new Map(recordsIn(raw, 'sections').map((r) => [r.key, r.note ?? null]));
73
80
  }
@@ -187,7 +194,7 @@ async function locate(root, kind, name, type) {
187
194
  throw new Error(`${name} is not a design doc: ${Object.keys(DOC_FILES).join(', ')}`);
188
195
  const text = await readIf(path.join(root, DOC_FILES[name]));
189
196
 
190
- return { file: `gcf/${DOC_FILES[name]}`, text: text === null ? null : text.trim() };
197
+ return { file: docPath(name), text: text === null ? null : text.trim() };
191
198
  }
192
199
 
193
200
  const design = await readDesign(root);
@@ -561,14 +568,13 @@ async function bundleMove(
561
568
 
562
569
  // What the design is made of: what `design commit` records and the board counts as unrecorded.
563
570
  const DESIGN_PATHS = [
564
- 'PILLARS.md',
565
- 'game.md',
566
- 'glossary.md',
567
- 'backlog.md',
568
- 'open-questions.md',
569
- 'design',
570
- 'source',
571
- ].map((p) => `gcf/${p}`);
571
+ ...['PILLARS.md', 'game.md', 'backlog.md', 'open-questions.md', 'design', 'source'].map(
572
+ (p) => `gcf/${p}`,
573
+ ),
574
+ docPath('glossary'),
575
+ // Where the glossary lived before core 0.21: its move to the root is design too (the review).
576
+ 'gcf/glossary.md',
577
+ ];
572
578
 
573
579
  /**
574
580
  * The design files with changes git has not recorded, project-relative. An import's held map
@@ -614,7 +620,9 @@ export const commitDesign = (projectDir, opts = {}) =>
614
620
  locked(projectDir, opts.commit ?? true, () => commitUnlocked(projectDir, opts));
615
621
 
616
622
  async function commitUnlocked(projectDir, { message = null, commit = true } = {}) {
617
- const files = unrecordedDesign(projectDir);
623
+ // A rename takes its old path along (`git mv gcf/glossary.md GLOSSARY.md`): left out, the
624
+ // hook saw the deletion outside the commit and refused it.
625
+ const files = unrecordedDesign(projectDir, { renamed: true });
618
626
  if (!files.length) return { files, hash: null };
619
627
  const blocking = (await designCheck(projectDir)).issues.filter((i) => i.severity === 'block');
620
628
  if (blocking.length) {
@@ -639,7 +647,7 @@ async function commitUnlocked(projectDir, { message = null, commit = true } = {}
639
647
 
640
648
  // What an agent's draft writes (decision 35), and so what `design discard` may take back: not an
641
649
  // uploaded GDD, the backlog or the questions, which an import writes.
642
- const DRAFT_PATHS = ['gcf/PILLARS.md', 'gcf/game.md', 'gcf/glossary.md'];
650
+ const DRAFT_PATHS = ['gcf/PILLARS.md', 'gcf/game.md', docPath('glossary')];
643
651
  const isDraftPath = (f) => DRAFT_PATHS.includes(f) || f.startsWith('gcf/design/');
644
652
 
645
653
  /**
@@ -690,7 +698,7 @@ const isDesignQuestion = (q, units) =>
690
698
  export async function designState(projectDir, { report, questions, items }) {
691
699
  const root = path.join(path.resolve(projectDir), 'gcf');
692
700
  const pillarsText = await readIf(path.join(root, 'PILLARS.md'));
693
- const glossaryText = await readIf(path.join(root, 'glossary.md'));
701
+ const glossaryText = await readIf(path.join(root, DOC_FILES.glossary));
694
702
  const game = existsSync(path.join(root, 'game.md'));
695
703
  const units = new Set(report.units.map((u) => u.id));
696
704
  const sources = await sourcesOf(root);
@@ -710,6 +718,8 @@ export async function designState(projectDir, { report, questions, items }) {
710
718
  // The new item form's milestone choices; null without game.md (a free field then).
711
719
  milestones: await gameMilestones(root),
712
720
  glossary: glossaryText === null ? null : recordsIn(glossaryText, 'terms').length,
721
+ // A glossary left where a core before 0.21 kept it: read no more until it moves.
722
+ glossary_old: existsSync(path.join(root, 'glossary.md')),
713
723
  systems: report.systems,
714
724
  sources,
715
725
  questions: asked.map((q) => q.id),
package/lib/design.js CHANGED
@@ -5,7 +5,8 @@ import { readFile, readdir } from 'node:fs/promises';
5
5
  import { existsSync } from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { fileURLToPath } from 'node:url';
8
- import { parseBlocks, itemsOf, readRecords, loadProfileAt } from 'cnlp-kit';
8
+ import { parseBlocks, itemsOf, readRecords } from 'cnlp-kit';
9
+ import { profileFor } from 'cnlp-kit/config';
9
10
 
10
11
  export const SLUG_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
11
12
  export const UNIT_TYPES = ['mechanic', 'resource', 'rule', 'constraint', 'entity'];
@@ -30,8 +31,28 @@ export const AGENT_SLOTS = ['check', 'measure', 'contract', 'interactions'];
30
31
 
31
32
  const PROFILES_DIR = fileURLToPath(new URL('../profiles/', import.meta.url));
32
33
 
33
- /** The CNL-P profile of a document kind shipped in profiles/ (`unit-mechanic`, `game`, …). */
34
- export const loadDocProfile = (name) => loadProfileAt(path.join(PROFILES_DIR, `${name}.md`));
34
+ // The singleton design documents, each with its file from gcf/: the glossary is the project's
35
+ // GLOSSARY.md beside cnlp.config.json, where cnlp finds it (cnlp-kit 3.10).
36
+ export const DOC_FILES = { game: 'game.md', glossary: '../GLOSSARY.md', pillars: 'PILLARS.md' };
37
+
38
+ /** A doc's file from the project, with `/`: `gcf/game.md`, `GLOSSARY.md`. */
39
+ export const docPath = (name) => path.posix.normalize(`gcf/${DOC_FILES[name]}`);
40
+
41
+ /**
42
+ * The CNL-P profile of a document kind: GCF's own in profiles/ (`unit-mechanic`, `game`, …),
43
+ * else cnlp-kit's (`glossary`: the project glossary is cnlp's document, not GCF's).
44
+ */
45
+ export const loadDocProfile = (name) => profileFor(name, PROFILES_DIR);
46
+
47
+ // cnlp-kit's own profiles, beside its src/.
48
+ const CNLP_PROFILES = fileURLToPath(new URL('../profiles/', import.meta.resolve('cnlp-kit')));
49
+
50
+ /** The file of the profile loadDocProfile loads: GCF's own, else cnlp-kit's. */
51
+ export function profileFile(name) {
52
+ const own = path.join(PROFILES_DIR, `${name}.md`);
53
+
54
+ return existsSync(own) ? own : path.join(CNLP_PROFILES, `${name}.md`);
55
+ }
35
56
 
36
57
  /** A doc profile's block keys in the order M1 holds a body to. */
37
58
  export const blockOrder = async (name) => (await loadDocProfile(name)).sections.map((s) => s.key);
package/lib/domain.js CHANGED
@@ -420,7 +420,7 @@ const DESIGN_SPECS = {
420
420
  // files its agent writes without a permission card; everything else still asks.
421
421
  const DESIGN_EDITS = [
422
422
  'gcf/game.md',
423
- 'gcf/glossary.md',
423
+ 'GLOSSARY.md',
424
424
  'gcf/backlog.md',
425
425
  'gcf/open-questions.md',
426
426
  'gcf/INDEX.md',
@@ -496,7 +496,7 @@ const STARTS = {
496
496
  label: 'Draft with agent',
497
497
  help: 'A draft of the glossary from the vision and the units: you record it, edit or discard it',
498
498
  skill: 'gcf-vision',
499
- say: 'Draft gcf/glossary.md from the vision and the design units. Write it, do not record it.',
499
+ say: 'Draft GLOSSARY.md from the vision and the design units. Write it, do not record it.',
500
500
  edits: DESIGN_EDITS,
501
501
  },
502
502
  'draft-system': {
@@ -807,6 +807,8 @@ const SECTIONS = {
807
807
  questions: { answer: 'question-answer' },
808
808
  // A move's `dirty` refusal: the board reads `gcf edits diff` and offers these.
809
809
  edits: { commit: 'edits-commit', discard: 'edits-discard' },
810
+ // `gcf changes` reads what is uncommitted: the board's Changes screen and its header's marker.
811
+ changes: {},
810
812
  lessons: {},
811
813
  playtest: {
812
814
  // The inbox category a note from the playtest screen goes with.
package/lib/edits.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // Hand edits under gcf/ (Rich-Chat-Plan §5): what a move's `dirty` refusal names, shown, committed
2
2
  // or put back. Reading is anyone's; commit and discard are the operator's (the CLI holds them,
3
3
  // and the deny group human-moves): an agent does not decide over a human's unfinished work.
4
- import { readFileSync, existsSync } from 'node:fs';
5
4
  import { spawnSync } from 'node:child_process';
6
5
  import path from 'node:path';
7
6
  import { dirtyGcf, inParts, literal, restoreFromHead } from './git.js';
8
7
  import { locked } from './main-lock.js';
9
8
  import { refusal } from './refusal.js';
9
+ import { newFileDiff } from './tree-file.js';
10
10
  import { commitMove } from './unit-ops.js';
11
11
 
12
12
  /** A path from the project with `/`: the form dirtyGcf gives and a refusal names. */
@@ -42,24 +42,13 @@ const git = (projectDir, ...args) =>
42
42
  spawnSync('git', ['-c', 'core.quotePath=false', ...args], { cwd: projectDir, encoding: 'utf8' })
43
43
  .stdout ?? '';
44
44
 
45
- /** A file git does not know yet as a diff of its own: each line added. */
46
- function newFileDiff(projectDir, f) {
47
- const file = path.join(projectDir, f);
48
- if (!existsSync(file)) return '';
49
- const text = readFileSync(file, 'utf8');
50
- if (text.includes('\0')) return `new file ${f}: binary\n`;
51
- const lines = text.replace(/\n$/, '').split('\n');
52
-
53
- return `new file ${f}\n--- /dev/null\n+++ b/${f}\n${lines.map((l) => `+${l}`).join('\n')}\n`;
54
- }
55
-
56
45
  /** Literal pathspecs: a `[` in a name is no glob that takes its siblings along. */
57
46
  const lits = (projectDir, files) => files.map((f) => literal(projectDir, f));
58
47
 
59
48
  // The form a board cuts the diff by, whatever the user's git config says (diff.noprefix,
60
49
  // diff.mnemonicPrefix, color.ui=always, an external diff): heads `a/<path> b/<path>` from the
61
50
  // project, as dirtyGcf names the paths, not from the repository a project may sit in.
62
- const DIFF_FORM = [
51
+ export const DIFF_FORM = [
63
52
  '--no-color',
64
53
  '--no-ext-diff',
65
54
  '--no-textconv',
package/lib/gate.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // The GCF checks of the pre-commit gate (GCF-PRD §13.1) over the working tree, cheap ones first.
2
2
  // The gate refuses on the first problem; `gcf verify` reports them all as the GCF part of the DoD.
3
+ import { readFile } from 'node:fs/promises';
3
4
  import path from 'node:path';
4
5
  import { listSystems, legacyCards, readConfig } from './gcf-paths.js';
5
6
  import { phasesOf } from './phase.js';
@@ -57,6 +58,14 @@ async function phaseProblems(root, phase) {
57
58
  }
58
59
 
59
60
  /** Every problem the gate refuses a commit for, one line each, and the ledger it read. */
61
+ /** A line of a doc's body as its file numbers it: past the frontmatter the body is read without. */
62
+ async function fileLine(doc, line) {
63
+ const text = await readFile(doc.file, 'utf8');
64
+ const at = text.indexOf(doc.body);
65
+
66
+ return at < 0 ? line : text.slice(0, at).split('\n').length - 1 + line;
67
+ }
68
+
60
69
  export async function gateProblems(projectDir) {
61
70
  const root = path.join(path.resolve(projectDir), 'gcf');
62
71
  const ledger = await buildLedger(projectDir);
@@ -99,7 +108,10 @@ export async function gateProblems(projectDir) {
99
108
  for (const s of systems) {
100
109
  const { issues } = lint(s.body);
101
110
  if (issues.length)
102
- problems.push(`systems/${s.name}:${issues[0].line}: ${issues[0].rule}: ${issues[0].text}`);
111
+ problems.push(
112
+ `gcf/systems/${s.name}:${await fileLine(s, issues[0].line)}: ` +
113
+ `${issues[0].rule}: ${issues[0].text}`,
114
+ );
103
115
  }
104
116
 
105
117
  return { problems, ledger };
package/lib/gcf-paths.js CHANGED
@@ -110,6 +110,15 @@ function gatesOf(v = {}) {
110
110
  );
111
111
  }
112
112
 
113
+ // Files listed and never opened on the board's Changes screen (Board-PRD §5.25): the project's
114
+ // call, GCF names no stack's files.
115
+ function noDiffOf(v = []) {
116
+ if (!Array.isArray(v) || !v.every((g) => typeof g === 'string' && g.trim()))
117
+ throw new Error('gcf/config.yml: no_diff must be a list of globs, one per entry');
118
+
119
+ return v;
120
+ }
121
+
113
122
  /** @returns {Promise<Record<string, any>>} */
114
123
  export async function readConfig(root) {
115
124
  return configOf(await readRawConfig(root));
@@ -166,6 +175,7 @@ export function configOf(parsed) {
166
175
  run_mode: runModeOf(config.run_mode),
167
176
  chat: chatOf(config.chat),
168
177
  gates: gatesOf(config.gates),
178
+ no_diff: noDiffOf(config.no_diff),
169
179
  };
170
180
  }
171
181
 
package/lib/git.js CHANGED
@@ -95,6 +95,9 @@ export function dirtyPaths(projectDir, paths) {
95
95
  */
96
96
  export const GATE_SCOPE = [
97
97
  'gcf',
98
+ // The project's glossary sits beside cnlp.config.json, where cnlp finds it (cnlp-kit 3.10):
99
+ // its avoided words hold over gcf/, so a change to it is checked with gcf/.
100
+ 'GLOSSARY.md',
98
101
  ':(exclude)gcf/.metrics',
99
102
  ':(exclude,glob)gcf/source/*.import.json',
100
103
  ];
@@ -132,7 +135,7 @@ export function dirtyGcf(projectDir, skip = []) {
132
135
  if (!/[RC]/.test(xy)) continue;
133
136
  i++;
134
137
  const old = ours(recs[i] ?? '');
135
- if (xy.includes('R') && old.startsWith('gcf/')) paths.push(old);
138
+ if (xy.includes('R') && (old.startsWith('gcf/') || old === 'GLOSSARY.md')) paths.push(old);
136
139
  }
137
140
 
138
141
  const off = new Set([...skip].map((p) => relOf(projectDir, p)));
@@ -234,6 +237,23 @@ export function moveTrailers({ key, items = [], proposal } = {}) {
234
237
  return ['-m', lines.join('\n')];
235
238
  }
236
239
 
240
+ /**
241
+ * Why a commit did not land. The gate's refusal in the words of whoever made the move, with no
242
+ * git around it; anything else as git said it, past its line-ending warnings, which stop nothing.
243
+ */
244
+ function commitRefusal(message, out) {
245
+ const problems = [...out.matchAll(/^gcf pre-commit: (?!warning: )(.+?)\r?$/gm)].map((m) => m[1]);
246
+ if (!problems.length)
247
+ return new Error(`commit failed: ${out.replace(/^warning: .*\r?\n?/gm, '')}`);
248
+
249
+ return refusal(
250
+ 'gate',
251
+ { problems },
252
+ `cannot record ${message}: the gate refuses ${problems.join('; ')}\n` +
253
+ 'Nothing was committed. What it names has to change first (the agent can do it), then try again.',
254
+ );
255
+ }
256
+
237
257
  /**
238
258
  * Stage and commit exactly `paths`: `git add -- gcf/` would stage a user's unrelated edits
239
259
  * under gcf/, and a rollback only restores what it snapshotted. A path that neither exists nor
@@ -281,7 +301,7 @@ export function commitPaths(projectDir, message, paths, move = {}) {
281
301
  'commit or discard them, then try again',
282
302
  );
283
303
  }
284
- if (res.status !== 0) throw new Error(`commit failed: ${out}`);
304
+ if (res.status !== 0) throw commitRefusal(message, out);
285
305
 
286
306
  return spawnSync('git', ['rev-parse', 'HEAD'], {
287
307
  cwd: projectDir,
package/lib/index-gen.js CHANGED
@@ -11,10 +11,11 @@ import { readDesign, slotValues, loadDocProfile, isTbd, UNIT_TYPES } from './des
11
11
  * INDEX.md is a deterministic function of gcf/ contents (GCF-PRD §5.1): generated,
12
12
  * never hand-written. The pre-commit hook regenerates it and stages the result.
13
13
  */
14
+ // Each with its file from the project: the glossary is the project's, beside cnlp.config.json.
14
15
  const SINGLETONS = [
15
- ['pillars', 'PILLARS.md', 'pillars and negative invariants'],
16
- ['game', 'game.md', 'vision, scope and milestones'],
17
- ['glossary', 'glossary.md', 'terms and forbidden synonyms'],
16
+ ['pillars', 'gcf/PILLARS.md', 'pillars and negative invariants'],
17
+ ['game', 'gcf/game.md', 'vision, scope, milestones and units of measure'],
18
+ ['glossary', 'GLOSSARY.md', 'terms and the words they avoid'],
18
19
  ];
19
20
 
20
21
  export async function generate(root) {
@@ -23,7 +24,7 @@ export async function generate(root) {
23
24
  lines.push(`${type} | gcf/${file} | ${status} | ${system} | ${descr}`);
24
25
 
25
26
  for (const [type, file, descr] of SINGLETONS) {
26
- if (existsSync(path.join(root, file))) row([type, file, '-', '-', descr]);
27
+ if (existsSync(path.join(root, '..', file))) lines.push(`${type} | ${file} | - | - | ${descr}`);
27
28
  }
28
29
 
29
30
  const backlog = await readIfExists(root, 'backlog.md');
package/lib/linter.js CHANGED
@@ -10,7 +10,9 @@ const UNIT_WORDS = [...UNITS, 'мс', 'с', 'сек', 'dmg', 'hp', 'px'].map(esc
10
10
  const UNIT_NUM = new RegExp(`\\d+(?:[.,]\\d+)?\\s?(?:${UNIT_WORDS})(?![\\p{L}\\p{N}_-])`, 'u');
11
11
  // No space before the paren: "respawn the player (out of the arena)" is prose, not a call.
12
12
  const SIGNATURE = /\w+\([^)]*\b(?:int|float|bool|string|void|var|ref|out)\b[^)]*\)/;
13
- const CAMEL = /\b[A-Z][a-z0-9]+(?:[A-Z][a-z0-9]+)+\b/;
13
+ // A bullet headed by a CamelCase name: "HealthComponent holds the pool". One that only mentions a
14
+ // name is a sentence, and a path or a file name is what `code:` is there for.
15
+ const MEMBER_BULLET = /^- `?[A-Z][a-z0-9]+(?:[A-Z][a-z0-9]+)+\b(?!\.[a-z0-9]+\b|\/)/;
14
16
  const ENVELOPE_FIELD = /^\s*(?:- )?(?:question|assumed|proposed):/;
15
17
 
16
18
  /**
@@ -84,7 +86,7 @@ function toggleFence(st, i) {
84
86
  st.fenceStart = -1;
85
87
  }
86
88
 
87
- const memberBullet = (line) => /^- /.test(line) && CAMEL.test(line);
89
+ const memberBullet = (line) => MEMBER_BULLET.test(line);
88
90
 
89
91
  /** Pattern rules for one prose line (outside fences, not pragma-allowed). */
90
92
  function checkLine(st, i) {
@@ -103,7 +105,7 @@ function checkLine(st, i) {
103
105
 
104
106
  if (SIGNATURE.test(line)) flag('signature');
105
107
 
106
- // Three or more consecutive bullets each naming CamelCase identifiers = a member list.
108
+ // Three or more consecutive bullets each headed by a CamelCase identifier = a member list.
107
109
  const prev = st.lines[i - 1] ?? '';
108
110
  if (memberBullet(line) && memberBullet(prev) && memberBullet(st.lines[i - 2] ?? '')) {
109
111
  flag('camelcase-member-list');
package/lib/plan-check.js CHANGED
@@ -1,10 +1,15 @@
1
1
  // `gcf plan check <id>` (Methodology §5.2.1): the deterministic check after each improve pass —
2
2
  // the plan exists, it holds task checkboxes, and the item's readset fits the context budget.
3
- // Whether the plan is any good is the improve passes' job; this only says it is usable.
3
+ // Whether the plan is any good is the improve passes' job; this only says it is usable. Its
4
+ // form against the `plan` profile (CNL-P: blocks, one idea a line, no fact twice) is reported
5
+ // as `format` lines, never a problem: a long line must not cost the item its paid passes.
4
6
  import { existsSync, readFileSync } from 'node:fs';
5
7
  import path from 'node:path';
8
+ import { bodyIssues } from 'cnlp-kit';
9
+ import { glossaryAvoids, GLOSSARY_NAME } from 'cnlp-kit/config';
6
10
  import { buildLedger } from './ledger.js';
7
11
  import { buildContext } from './context.js';
12
+ import { loadDocProfile } from './design.js';
8
13
 
9
14
  /**
10
15
  * An item's plan and its task checkboxes: `{plan, tasks, done}`, `tasks` null when there is no
@@ -23,6 +28,47 @@ export function planTicks(projectDir, data) {
23
28
  };
24
29
  }
25
30
 
31
+ /**
32
+ * The plan as the profile reads it, line numbers kept: a `##` section aif-plan or GCF adds
33
+ * (Settings, Original Request, Handoff, Outcome) is blanked to the next block of the profile,
34
+ * and a `### Phase` line is blank (a bullet-list takes only `- ` items; a blank line is fine).
35
+ */
36
+ export function profiledText(text, keys) {
37
+ const block = new RegExp(`^(${keys.join('|')}):`);
38
+ let section = false;
39
+
40
+ return text
41
+ .split(/\r?\n/)
42
+ .map((l) => {
43
+ if (/^## /.test(l)) section = true;
44
+ else if (block.test(l)) section = false;
45
+ if (section || /^### /.test(l)) return '';
46
+
47
+ // A subtask is a task: aif-plan nests them, the form does not refuse them.
48
+ return /^\s+- \[[ xX]\] /.test(l) ? l.trimStart() : l;
49
+ })
50
+ .join('\n');
51
+ }
52
+
53
+ /**
54
+ * The plan's form against the `plan` profile, as `<line>: <message>` lines; the project
55
+ * glossary's avoided words count. None once a task is ticked: work in flight is not asked to
56
+ * change its form. A plan in no block of the profile (aif-plan's own layout) gets one line.
57
+ */
58
+ export async function planFormat(projectDir, text) {
59
+ if (/^\s*- \[[xX]\] /m.test(text)) return [];
60
+ const profile = await loadDocProfile('plan');
61
+ const keys = profile.sections.map((s) => s.key);
62
+ if (!new RegExp(`^(${keys.join('|')}):`, 'm').test(text))
63
+ return [`the plan is not in the plan profile: blocks ${keys.join(', ')}`];
64
+ const glossary = path.join(path.resolve(projectDir), GLOSSARY_NAME);
65
+ const avoid = existsSync(glossary) ? glossaryAvoids(readFileSync(glossary, 'utf8')) : [];
66
+
67
+ return bodyIssues(profiledText(text, keys), profile, { avoid }).map(
68
+ (i) => `${i.line}: ${i.message}`,
69
+ );
70
+ }
71
+
26
72
  export async function planCheck(projectDir, id) {
27
73
  const item = (await buildLedger(projectDir)).item(id);
28
74
  if (!item) throw new Error(`${id} is not a work item of gcf/work/`);
@@ -35,6 +81,10 @@ export async function planCheck(projectDir, id) {
35
81
  const ctx = await buildContext(projectDir, id);
36
82
  if (ctx.over_budget)
37
83
  problems.push(`readset ~${ctx.total_tokens_est} tokens is over the budget ${ctx.budget}`);
84
+ const format =
85
+ found === null
86
+ ? []
87
+ : await planFormat(projectDir, readFileSync(path.resolve(projectDir, plan), 'utf8'));
38
88
 
39
- return { id, plan, tasks, done, problems, ok: problems.length === 0 };
89
+ return { id, plan, tasks, done, problems, format, ok: problems.length === 0 };
40
90
  }