gcf-aif-ext 0.12.3 → 0.13.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.
package/lib/unit-ops.js CHANGED
@@ -230,7 +230,9 @@ function uncommitted(projectDir, file) {
230
230
  * their own uncommitted edits (an answer, a live: delta) ride along on purpose.
231
231
  * @param {string} projectDir
232
232
  * @param {string} message
233
- * @param {{files: string[], mutate: () => Promise<void>, commit: boolean, inputs?: string[]}} move
233
+ * `key` is the domain's move key and `items` the ids it touched: the commit's trailers.
234
+ * @param {{files: string[], mutate: () => Promise<void>, commit: boolean, inputs?: string[],
235
+ * key?: string, items?: string[]}} move
234
236
  */
235
237
  /** A worktree of the integrator (Methodology §7): its gcf/ state is main's to move. */
236
238
  export const onWorkBranch = (projectDir) =>
@@ -248,7 +250,7 @@ export async function commitMove(projectDir, message, move) {
248
250
  : record(projectDir, message, move);
249
251
  }
250
252
 
251
- async function record(projectDir, message, { files, mutate, commit, inputs = [] }) {
253
+ async function record(projectDir, message, { files, mutate, commit, inputs = [], key, items }) {
252
254
  if (commit && onWorkBranch(projectDir))
253
255
  throw new Error(
254
256
  `cannot record ${message} on a work/ branch: a worktree records no move — the run ` +
@@ -276,7 +278,7 @@ async function record(projectDir, message, { files, mutate, commit, inputs = []
276
278
  async () => {
277
279
  await mutate();
278
280
  await writeIndex(root);
279
- if (commit) hash = commitPaths(projectDir, message, touched);
281
+ if (commit) hash = commitPaths(projectDir, message, touched, { key, items });
280
282
  },
281
283
  { gitCwd: commit ? path.resolve(projectDir) : null },
282
284
  );
@@ -312,7 +314,13 @@ async function doneUnitUnlocked(projectDir, id, { constraints = [], commit = tru
312
314
 
313
315
  return {
314
316
  id,
315
- hash: await commitMove(projectDir, `gcf(done): ${id}`, { files, mutate, commit }),
317
+ hash: await commitMove(projectDir, `gcf(done): ${id}`, {
318
+ files,
319
+ mutate,
320
+ commit,
321
+ key: 'done',
322
+ items: [id],
323
+ }),
316
324
  };
317
325
  }
318
326
 
@@ -350,6 +358,12 @@ async function dropUnitUnlocked(projectDir, id, { reason, tags = [], commit = tr
350
358
 
351
359
  return {
352
360
  id,
353
- hash: await commitMove(projectDir, `gcf(drop): ${id}`, { files, mutate, commit }),
361
+ hash: await commitMove(projectDir, `gcf(drop): ${id}`, {
362
+ files,
363
+ mutate,
364
+ commit,
365
+ key: 'drop',
366
+ items: [id],
367
+ }),
354
368
  };
355
369
  }
package/lib/work-ops.js CHANGED
@@ -206,6 +206,8 @@ async function begin(projectDir, id, move) {
206
206
  item,
207
207
  /** @type {Set<string>} ids leaving systems/ in this move */
208
208
  leaving: new Set(),
209
+ /** @type {Set<string>} every item the move touches, for its commit's GCF-Items */
210
+ items: new Set([id]),
209
211
  files,
210
212
  touch: (...f) => files.push(...f.filter((x) => !files.includes(x))),
211
213
  step: (fn) => steps.push(fn),
@@ -223,13 +225,19 @@ async function begin(projectDir, id, move) {
223
225
  };
224
226
  }
225
227
 
226
- /** Commit the move as `gcf(<move>): <tail>` with every file it touched (item edits included). */
227
- async function finish(m, move, tail, commit) {
228
+ /**
229
+ * Commit the move as `gcf(<move>): <tail>` with every file it touched (item edits included);
230
+ * `key` is the domain's move key its trailer carries (`verdict:keep`), its head the move.
231
+ */
232
+ async function finish(m, key, tail, commit) {
233
+ const move = key.split(':')[0];
228
234
  const hash = await commitMove(m.projectDir, `gcf(${move}): ${tail}`, {
229
235
  files: m.files,
230
236
  mutate: m.run,
231
237
  commit,
232
238
  inputs: [m.item.file],
239
+ key,
240
+ items: [...m.items],
233
241
  });
234
242
  // A move on the item ends the session that worked it: the board stops showing it running,
235
243
  // and no rerun resumes it.
@@ -429,6 +437,7 @@ function freshId(ledger, base) {
429
437
  function removalItem(m, item, reason) {
430
438
  const id = freshId(m.ledger, `remove-${item.data.id}`);
431
439
  const file = path.join(m.root, 'work', `${id}.md`);
440
+ m.items.add(id);
432
441
  const data = {
433
442
  schema: 3,
434
443
  id,
@@ -455,6 +464,7 @@ function parentWaits(m, item) {
455
464
  const { status } = parent.data;
456
465
  if (status !== 'ready' && status !== 'blocked') return;
457
466
  m.touch(parent.file);
467
+ m.items.add(String(parent.data.id));
458
468
  // A blocked feature keeps its reason: the dead child is added to it, unblock decides later.
459
469
  const data =
460
470
  status === 'blocked'
@@ -477,6 +487,8 @@ function endToGraveyard(
477
487
  const why = String(reason ?? '').trim();
478
488
  if (!why) throw new Error(`${id}: the graveyard keeps a reason — give one`);
479
489
  m.touch(path.join(m.root, 'graveyard.md'), item.file);
490
+ // A feature's kill takes its live children down in the same commit.
491
+ m.items.add(id);
480
492
  const lineTags = tags.length ? tags : (item.data.system ?? []);
481
493
  m.step(() => buryLine(m.root, id, { type: item.data.type, reason: why, tags: lineTags }));
482
494
  if (item.data.status === 'unplayed') unplay(m, item);
@@ -684,7 +696,8 @@ async function verdictItemUnlocked(projectDir, id, verdict, opts = {}) {
684
696
  if (verdict === 'keep') await keep(m, constraints);
685
697
  else if (verdict === 'tune') await tune(m, note);
686
698
  else removal = endToGraveyard(m, m.item, { reason: note, tags, removal: remove ?? true });
687
- const hash = await finish(m, 'verdict', `${verdict} ${id} → ${systems.join(',')}`, commit);
699
+ const tail = `${verdict} ${id} → ${systems.join(',')}`;
700
+ const hash = await finish(m, `verdict:${verdict}`, tail, commit);
688
701
 
689
702
  return { verdict, id, systems, hash, removal };
690
703
  }
@@ -759,7 +772,7 @@ async function decideItemUnlocked(projectDir, id, choice, opts = {}) {
759
772
  const m = await begin(projectDir, id, `decide:${choice}`);
760
773
  fitDecision(choice, m.item);
761
774
  const removal = DECIDE[choice](m, { reason, remove }) ?? null;
762
- const hash = await finish(m, 'decide', `${choice} ${id}`, commit);
775
+ const hash = await finish(m, `decide:${choice}`, `${choice} ${id}`, commit);
763
776
 
764
777
  return { id, choice, hash, removal };
765
778
  }
@@ -1013,6 +1026,8 @@ async function prioritizeItemsUnlocked(projectDir, ids, { commit = true } = {})
1013
1026
  await atomicWrite(i.file, serialize({ ...i.data, priority: ranks[n] }, i.body));
1014
1027
  },
1015
1028
  commit,
1029
+ key: 'prioritize',
1030
+ items: ids,
1016
1031
  });
1017
1032
 
1018
1033
  return { ids, hash };
@@ -1049,6 +1064,8 @@ async function setDependsUnlocked(projectDir, id, { add = [], remove = [], commi
1049
1064
  inputs: [item.file],
1050
1065
  mutate: () => atomicWrite(item.file, serialize({ ...item.data, depends }, item.body)),
1051
1066
  commit,
1067
+ key: 'depends',
1068
+ items: [id],
1052
1069
  });
1053
1070
 
1054
1071
  return { id, depends, hash };
@@ -1085,6 +1102,8 @@ async function setAgentUnlocked(projectDir, id, { model, effort, commit = true }
1085
1102
  inputs: [item.file],
1086
1103
  mutate: () => atomicWrite(item.file, serialize(data, item.body)),
1087
1104
  commit,
1105
+ key: 'agent',
1106
+ items: [id],
1088
1107
  },
1089
1108
  );
1090
1109
 
@@ -1118,6 +1137,8 @@ async function attachItemUnlocked(projectDir, id, file, { commit = true } = {})
1118
1137
  await copyFile(file, to);
1119
1138
  },
1120
1139
  commit,
1140
+ key: 'attach',
1141
+ items: [id],
1121
1142
  });
1122
1143
 
1123
1144
  return { id, file: path.relative(projectDir, to).replaceAll('\\', '/'), hash };
@@ -1142,6 +1163,16 @@ export const attachItem = (projectDir, id, file, opts = {}) =>
1142
1163
  /** The longest note a new item takes (AD-39): a proposal's, or the operator's. */
1143
1164
  export const NOTE_MAX = 4000;
1144
1165
 
1166
+ /** The parent feature's file with the new child in its `children`; none without a parent. */
1167
+ function parentWrite(ledger, spec) {
1168
+ if (!spec.parent) return [];
1169
+ const p = ledger.item(spec.parent);
1170
+ if (!p || p.data.type !== 'feature') throw new Error(`${spec.parent} is not a live feature item`);
1171
+ const children = [...new Set([...(p.data.children ?? []), spec.id])];
1172
+
1173
+ return [[p.file, serialize({ ...p.data, children }, p.body)]];
1174
+ }
1175
+
1145
1176
  async function newItemUnlocked(projectDir, spec) {
1146
1177
  const root = gcfOf(projectDir);
1147
1178
  const ledger = await buildLedger(projectDir);
@@ -1158,14 +1189,10 @@ async function newItemUnlocked(projectDir, spec) {
1158
1189
  const note = [spec.note, take.note].filter((x) => x?.trim()).join('\n\n') || undefined;
1159
1190
  const item = { ...spec, title: take.title, note };
1160
1191
 
1161
- const writes = [[file, newItemText(item, gate, headHash(projectDir))]];
1162
- if (spec.parent) {
1163
- const p = ledger.item(spec.parent);
1164
- if (!p || p.data.type !== 'feature')
1165
- throw new Error(`${spec.parent} is not a live feature item`);
1166
- const children = [...new Set([...(p.data.children ?? []), spec.id])];
1167
- writes.push([p.file, serialize({ ...p.data, children }, p.body)]);
1168
- }
1192
+ const writes = [
1193
+ [file, newItemText(item, gate, headHash(projectDir))],
1194
+ ...parentWrite(ledger, spec),
1195
+ ];
1169
1196
 
1170
1197
  // `commit` is for a caller with no console to commit from, a board: a run starts from HEAD.
1171
1198
  const hash = await commitMove(projectDir, `gcf(item): ${spec.id}`, {
@@ -1176,6 +1203,8 @@ async function newItemUnlocked(projectDir, spec) {
1176
1203
  await take.apply();
1177
1204
  },
1178
1205
  commit: spec.commit ?? false,
1206
+ key: 'item-new',
1207
+ items: [spec.id, ...(spec.parent ? [spec.parent] : [])],
1179
1208
  });
1180
1209
 
1181
1210
  return { item: `gcf/work/${spec.id}.md`, hash };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-aif-ext",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
4
4
  "description": "Game Context Framework for AI Factory",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,6 +11,7 @@ gcf_work:
11
11
  - before planning an item, run `ai-factory gcf context <id>` and read only the files it lists under `gcf/`
12
12
  - drive a ready item with the gcf-run skill when the project has gcf-harness-aif-ext and the agent is Claude Code (a batch at once: `ai-factory gcf-harness run <ids...>`), otherwise with aif-plan and aif-implement
13
13
  - a question about how the runs go (the share that reached their move, cost, plan checks, DoD attempts, guard firings) is answered by `ai-factory gcf-harness metrics`
14
+ - a question about past runs (an item's results, what it ran on, its cost, the part of its log a run wrote) is answered by `ai-factory gcf-harness runs [--item <id>] --json`; `ai-factory gcf-harness run <ids...> --model <m> --effort <e>` runs items on another model for that run only, the item unchanged
14
15
  - after the code, write the item's `live:` delta and run `ai-factory gcf verify <id>`: fix what it reports and run it again until every check is green, at most `dod_attempts` of `gcf/config.yml` red runs; still red: block the item with the diagnosis
15
16
  - the `live:` delta is YAML in the item's frontmatter, one of two forms: `live: {none: "<why it changes no capability>"}`, or `live:` with `changes:`, a list of `{id: <capability slug>, change: added | modified | removed, summary: "<at most two sentences>"}` (a removed one needs no summary)
16
17
  - before `submit` or `close`, tick every task of the item's plan that is done, the verify and the review included: both refuse a plan with unticked tasks; `--unticked "<why>"` is the human's call, never the agent's
@@ -25,6 +26,7 @@ gcf_work:
25
26
  - `item new` and `take` refuse a type the current phase does not take: run `ai-factory gcf phase` and bring the refusal to the human
26
27
  - an item the human wants run on a given model or effort gets `item new <id> --model <m> --effort <e>`: the harness run passes both to the agent; an existing item changes with `ai-factory gcf item agent <id> --model <m> --effort <e>` (`default` takes one off: the agent picks), never a hand edit; its next run takes them
27
28
  - ready items run in `priority:` order, lower first: rank a set of items with `ai-factory gcf prioritize <id> <id> …`, and put an id in `depends` only when the item uses that one's data or code: `ai-factory gcf depends <id> --add <ids>` or `--remove <ids>`, never a hand edit
29
+ - what happened to an item before (who submitted, blocked, tuned or reranked it, and when) is `ai-factory gcf item history <id>`: its moves from git, an ended item's too
28
30
  - a picture or file the human gives an item goes to `ai-factory gcf item attach <id> --file <path>` (its `gcf/work/<id>/attachments/`, committed); read an item's attachments before you plan it
29
31
  - write what the human reads (a question, an assumption, a block reason, an inbox entry, a lesson, a report, an item's `title:`) in `language.ui` of `.ai-factory/config.yaml`, and the body of an item that is not a design unit in its `language.artifacts`
30
32
  - write in English whatever lands in a checked document: `gcf/design/`, `gcf/systems/`, `gcf/glossary.md`, `gcf/PILLARS.md`, `gcf/LIVE.md`, the body of a design unit's item but its `tuning:` and `notes:`, an item's `live:` summary; an answer that moves into a unit's slot goes there in English