gcf-aif-ext 0.18.9 → 0.20.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/audit-core.js CHANGED
@@ -5,7 +5,7 @@ import { spawnSync } from 'node:child_process';
5
5
  import { listItems, listSystems, readConfig, tokensEst, legacyCards } from './gcf-paths.js';
6
6
  import { lint } from './linter.js';
7
7
  import { drifted } from './index-gen.js';
8
- import { designCheck, recordsIn } from './design-check.js';
8
+ import { designCheck, gameMilestones, recordsIn } from './design-check.js';
9
9
  import { PILLARS_MAX } from './design.js';
10
10
  import { buildLedger } from './ledger.js';
11
11
  import { STORED } from './transitions.js';
@@ -15,6 +15,8 @@ import { markOwner, ownerOf, sessionActive } from './session-mark.js';
15
15
  import { fieldOf } from './question-fields.js';
16
16
  import { inboxProblems } from './inbox.js';
17
17
  import { inboxVocabulary } from './domain.js';
18
+ import { gatePolicy, verdictDeferred } from './gates.js';
19
+ import { milestoneState } from './milestone-state.js';
18
20
 
19
21
  function git(args, cwd) {
20
22
  // A blame of a long file overflows the 1 MiB default, and an overflow reads as a git failure.
@@ -86,7 +88,12 @@ export async function audit(projectDir) {
86
88
  const items = await listItems(root);
87
89
  const systems = await listSystems(root);
88
90
  const ledger = await buildLedger(projectDir);
89
- const unplayed = items.filter((c) => c.data.status === 'unplayed').length;
91
+ // An unplayed item of a milestone waits for that milestone's play by design: only the ones
92
+ // with none (or one game.md no longer has) pile up unasked (docs/Autonomy-Plan.md, C).
93
+ const named = new Set(((await gameMilestones(root)) ?? []).map((m) => m.name));
94
+ const unplayed = items.filter(
95
+ (c) => c.data.status === 'unplayed' && !named.has(c.data.milestone),
96
+ ).length;
90
97
  /** @type {AuditReport} */
91
98
  const report = {
92
99
  first_line: '',
@@ -116,6 +123,7 @@ export async function audit(projectDir) {
116
123
  };
117
124
  // The harness gate reads everything from this one report — it never parses gcf/ itself.
118
125
  report.schema = config.schema;
126
+ report.gates = config.gates;
119
127
  report.items = items.map((c) => ({
120
128
  id: c.data.id,
121
129
  type: c.data.type,
@@ -127,6 +135,12 @@ export async function audit(projectDir) {
127
135
  tune_count: c.data.tune_count ?? 0,
128
136
  parallel: c.data.parallel ?? 'serial',
129
137
  priority: c.data.priority ?? null,
138
+ milestone: c.data.milestone ?? null,
139
+ // Where its run goes: its own run_mode, else the project's (an autopilot batches by it).
140
+ run_mode: c.data.run_mode ?? config.run_mode,
141
+ // The gates in force (docs/Autonomy-Plan.md, B); `deferred`: its submit closes unplayed.
142
+ gates: gatePolicy(config, c.data),
143
+ deferred: verdictDeferred(config, c.data),
130
144
  ...runningOf(projectDir, String(c.data.id)),
131
145
  }));
132
146
  const design = await designCheck(projectDir);
@@ -136,6 +150,8 @@ export async function audit(projectDir) {
136
150
  units: design.units.length,
137
151
  ready: design.units.filter((u) => u.ready).length,
138
152
  };
153
+ // Where each milestone stands, and what the autopilot builds and stops to play (Plan, D).
154
+ Object.assign(report, await milestoneState(projectDir, ledger, design.units));
139
155
  lintSystems(report, systems);
140
156
  report.first_line = firstLine(report);
141
157
 
package/lib/board.js CHANGED
@@ -24,6 +24,8 @@ import { agentOf } from './agent-permissions.js';
24
24
  import { projectSettings } from './config-set.js';
25
25
  import { designCheck, designUnits } from './design-check.js';
26
26
  import { designState } from './design-parts.js';
27
+ import { gatePolicy } from './gates.js';
28
+ import { milestoneState } from './milestone-state.js';
27
29
 
28
30
  // The version of the JSON below (Methodology §11): a board refuses one it does not know. Bump it
29
31
  // when a field changes meaning or goes away; a new field does not bump it.
@@ -219,6 +221,8 @@ const SCALARS = [
219
221
  'model',
220
222
  'effort',
221
223
  'run_mode',
224
+ 'skip_gates',
225
+ 'gate_why',
222
226
  ];
223
227
 
224
228
  /**
@@ -243,7 +247,7 @@ function inRunOrder(items) {
243
247
  );
244
248
  }
245
249
 
246
- const LISTS = ['children', 'system', 'depends'];
250
+ const LISTS = ['children', 'system', 'depends', 'play_on'];
247
251
 
248
252
  /**
249
253
  * Its dependencies not ended in history (Board-PRD §5.2): items on the board, design units,
@@ -311,7 +315,7 @@ async function attachmentsOf(projectDir, id) {
311
315
  }
312
316
 
313
317
  /** One item of the board. */
314
- async function itemOf(projectDir, c, { verified, ledger, harness }) {
318
+ async function itemOf(projectDir, c, { verified, ledger, harness, config }) {
315
319
  const id = String(c.data.id);
316
320
  // A trailer counts only while the item waits on main for its integrate.
317
321
  const ready = c.data.status === 'ready' && verified.has(id);
@@ -337,6 +341,8 @@ async function itemOf(projectDir, c, { verified, ledger, harness }) {
337
341
  ...Object.fromEntries(LISTS.map((k) => [k, c.data[k] ?? []])),
338
342
  ...(c.data.severity ? { severity: c.data.severity } : {}),
339
343
  ...(c.data.blocked ? { blocked: c.data.blocked } : {}),
344
+ // The gates in force for it: the project's, or its card's (docs/Autonomy-Plan.md, B).
345
+ gates: gatePolicy(config, c.data),
340
346
  running,
341
347
  // `run`: a harness run's lock; `session`: an operator's or agent's session mark (`gcf claim`).
342
348
  running_kind: kind,
@@ -361,9 +367,10 @@ export async function board(projectDir) {
361
367
  const verified = verifiedOf(projectDir);
362
368
  const { extensions, error: extensionsError } = await extensionsOf(projectDir);
363
369
  const harness = hasHarness(extensions);
370
+ const config = await readConfig(root);
364
371
  const items = [];
365
372
  for (const c of ledger.items)
366
- items.push(await itemOf(projectDir, c, { verified, ledger, harness }));
373
+ items.push(await itemOf(projectDir, c, { verified, ledger, harness, config }));
367
374
  inRunOrder(items);
368
375
  // When the wait began: the time of the commit `since` names (Board-PRD §13).
369
376
  const times = commitTimes(
@@ -380,7 +387,6 @@ export async function board(projectDir) {
380
387
  for (const i of items)
381
388
  i.needed_by = items.filter((o) => o.depends.includes(i.id)).map((o) => o.id);
382
389
 
383
- const config = await readConfig(root);
384
390
  const live = await readLive(root);
385
391
  const questions = await listQuestions(root);
386
392
  const { units, design } = await designOf(projectDir, ledger, questions);
@@ -388,6 +394,9 @@ export async function board(projectDir) {
388
394
  return {
389
395
  schema: BOARD_SCHEMA,
390
396
  run_mode: config.run_mode,
397
+ // The project's gates: and where each milestone stands (docs/Autonomy-Plan.md, B and D).
398
+ gates: config.gates,
399
+ ...(await milestoneState(projectDir, ledger, units)),
391
400
  // What the harness hands its agent runs (Harness-PRD §7): deny rules and the context limits.
392
401
  agent: agentOf(config),
393
402
  // The human's settings of config.yml and the agents' language, each with its value and
package/lib/config-set.js CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  CHAT_DEFAULTS,
20
20
  configOf,
21
21
  DEFAULT_CONFIG,
22
+ GATE_POLICY,
22
23
  gcfRoot,
23
24
  readRawConfig,
24
25
  RUN_MODES,
@@ -120,6 +121,39 @@ export const SETTINGS = [
120
121
  'minutes a question waits for your answer before the agent takes its default (0: nobody ' +
121
122
  'watches, as for a night run; a main run waits with its whole queue)',
122
123
  },
124
+ {
125
+ key: 'gates.milestone',
126
+ kind: 'mode',
127
+ options: GATE_POLICY.milestone,
128
+ label:
129
+ 'when a milestone is built: wait (the autopilot stops for you to play it) or go (it ' +
130
+ 'builds the next one, the built one waits for your play)',
131
+ },
132
+ {
133
+ key: 'gates.verdict',
134
+ kind: 'mode',
135
+ options: GATE_POLICY.verdict,
136
+ label:
137
+ 'an item with its own verdict gate: wait (it waits for your play) or defer (a mechanic ' +
138
+ 'or a resource closes unplayed and is played with its milestone)',
139
+ },
140
+ {
141
+ key: 'gates.decision',
142
+ kind: 'mode',
143
+ options: GATE_POLICY.decision,
144
+ label:
145
+ 'a spike or decision item: wait (it waits for your decision) or agent (the agent decides ' +
146
+ 'go or no with its reason; a release always waits)',
147
+ },
148
+ {
149
+ key: 'gates.question',
150
+ kind: 'mode',
151
+ options: GATE_POLICY.question,
152
+ label:
153
+ 'a question for you: wait (the item blocks, or a run asks) or assume (the agent writes ' +
154
+ 'its assumption and goes on; never for a save format, a public API, a new dependency or ' +
155
+ 'a pillar conflict)',
156
+ },
123
157
  { key: 'dod.test', kind: 'command', label: "the project's test command for the DoD, or none" },
124
158
  { key: 'dod.build', kind: 'command', label: "the project's build command for the DoD, or none" },
125
159
  {
@@ -189,6 +223,7 @@ const GROUPS = [
189
223
  ],
190
224
  ],
191
225
  ['Checks (DoD)', ['dod.test', 'dod.build', 'dod_timeout_min']],
226
+ ['Autonomy', ['gates.milestone', 'gates.verdict', 'gates.decision', 'gates.question']],
192
227
  ['Chat', ['chat.ask', 'chat.answer_timeout_min']],
193
228
  ['Context', ['context_handoff_pct', 'context_window', 'auto_compact_pct']],
194
229
  [
@@ -211,6 +246,7 @@ function defaultOf(s, aif) {
211
246
  if (s.key === 'language.artifacts') return languageIn(aif, 'ui') ?? 'en';
212
247
  if (s.kind === 'language') return 'en';
213
248
  if (head === 'chat') return CHAT_DEFAULTS[sub];
249
+ if (head === 'gates') return 'wait';
214
250
  if (sub) return null;
215
251
 
216
252
  return head === 'run_mode' ? 'worktree' : (DEFAULT_CONFIG[head] ?? null);
@@ -360,3 +396,59 @@ export async function setConfig(projectDir, key, text, { commit = true } = {}) {
360
396
 
361
397
  return { key, value, unchanged, ignored, settings, hash };
362
398
  }
399
+
400
+ /**
401
+ * Set several keys of gcf/config.yml in one commit, `gcf(config): <key>, <key>`: a preset of
402
+ * the board (docs/Autonomy-Plan.md, E). Each value as `setConfig` takes it; a key of AI
403
+ * Factory's file is set alone. Nothing changed, nothing committed.
404
+ * @param {string} projectDir
405
+ * @param {[string, string][]} pairs
406
+ */
407
+ export async function setConfigs(projectDir, pairs, { commit = true } = {}) {
408
+ if (!pairs.length) throw new Error('name a key=value to set');
409
+ const changes = pairs.map(([key, text]) => {
410
+ const setting = BY_KEY.get(key);
411
+ if (!setting) throw new Error(`no setting ${key}: ${SETTINGS.map((s) => s.key).join(' | ')}`);
412
+ if (setting.file) throw new Error(`${key} lives in ${setting.file}: set it on its own`);
413
+
414
+ return { key, keys: key.split('.'), value: valueOf(setting, text) };
415
+ });
416
+ const file = path.join(gcfRoot(projectDir), 'config.yml');
417
+ let unchanged = false;
418
+ const mutate = async () => {
419
+ const text = existsSync(file) ? await readFile(file, 'utf8') : '';
420
+ const doc = configDoc(text, 'gcf/config.yml');
421
+ for (const c of changes) {
422
+ // A reset of a key whose parent is not there changes nothing: no empty map is written.
423
+ if (c.value === null && c.keys.length > 1 && !YAML.isMap(doc.getIn([c.keys[0]], true)))
424
+ continue;
425
+ if (c.keys.length > 1)
426
+ ensureMap(doc, [c.keys[0]], `gcf/config.yml: ${c.keys[0]} must map its keys`);
427
+ if (c.value === null) doc.deleteIn(c.keys);
428
+ else doc.setIn(c.keys, c.value);
429
+ }
430
+
431
+ const raw = doc.toJS();
432
+ agentOf(configOf(raw));
433
+ if (isDeepStrictEqual(YAML.parse(text) ?? {}, raw ?? {})) {
434
+ unchanged = true;
435
+ throw NO_CHANGE;
436
+ }
437
+
438
+ await atomicWrite(file, doc.toString());
439
+ };
440
+
441
+ const keys = changes.map((c) => c.key);
442
+ const hash = await commitMove(projectDir, `gcf(config): ${keys.join(', ')}`, {
443
+ files: [file],
444
+ mutate,
445
+ commit,
446
+ key: 'config',
447
+ }).catch((e) => {
448
+ if (e !== NO_CHANGE) throw e;
449
+
450
+ return null;
451
+ });
452
+
453
+ return { keys, unchanged, settings: await projectSettings(projectDir).catch(() => []), hash };
454
+ }
@@ -143,7 +143,7 @@ export async function gameMilestones(root) {
143
143
  ? null
144
144
  : recordsIn(game, 'milestones')
145
145
  .filter((m) => SLUG_RE.test(m.name ?? ''))
146
- .map((m) => ({ name: m.name, goal: m.goal ?? null }));
146
+ .map((m) => ({ name: m.name, goal: m.goal ?? null, play: m.play ?? null }));
147
147
  }
148
148
 
149
149
  /** A D1 record nobody answered yet: only such a question holds its units. */
@@ -425,6 +425,16 @@ async function checkUnit(u, ctx, ledger) {
425
425
  const atBody = (line) => (line ? u.bodyLine + line - 1 : u.line);
426
426
  for (const [c, line, m] of headerIssues(u, ctx, ledger)) add(c, line, m);
427
427
  if (!UNIT_TYPES.includes(u.header.type)) return { issues, values: [] };
428
+ // A soft unit is played with its milestone (docs/Autonomy-Plan.md, C): a reading, not a block.
429
+ const own = u.header.milestone;
430
+ const none = own === undefined || own === 'TBD' || own === 'later';
431
+ if (ctx.milestones?.length && CARD_TYPES.includes(u.header.type) && none)
432
+ add(
433
+ 'M2',
434
+ u.line,
435
+ `no milestone: give it the milestone it is played with (${ctx.milestones.join(', ')})`,
436
+ 'report',
437
+ );
428
438
 
429
439
  const { profile, issues: shape } = await bodyProblems(u.body, u.header.type, 'design');
430
440
  for (const i of shape) add('M1', atBody(i.line), i.message);
@@ -3,7 +3,7 @@
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.
6
- import { readFile, readdir, rm } from 'node:fs/promises';
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';
@@ -34,7 +34,7 @@ import { locked } from './main-lock.js';
34
34
  import { buildLedger } from './ledger.js';
35
35
  import { deriveId } from './id.js';
36
36
  import { renamePillar } from './pillars.js';
37
- import { dirtyPaths } from './git.js';
37
+ import { dirtyPaths, restoreFromHead } from './git.js';
38
38
  import { blocksOf, putBlock } from './systems-doc.js';
39
39
 
40
40
  const PROFILES_DIR = fileURLToPath(new URL('../profiles/', import.meta.url));
@@ -656,19 +656,7 @@ export const discardDesign = (projectDir, only = []) =>
656
656
  if (off.length)
657
657
  throw new Error(`${off.join(', ')}: no draft to discard (${drafts.join(', ') || 'none'})`);
658
658
  const files = only.length ? only : drafts;
659
- const git = (...args) => spawnSync('git', args, { cwd: projectDir, encoding: 'utf8' });
660
- const must = (...args) => {
661
- const r = git(...args);
662
- if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr.trim()}`);
663
- };
664
- for (const f of files) {
665
- if (git('cat-file', '-e', `HEAD:./${f}`).status === 0) {
666
- must('checkout', 'HEAD', '--', f);
667
- continue;
668
- }
669
- must('rm', '--cached', '-q', '--ignore-unmatch', '--', f);
670
- await rm(path.join(projectDir, f), { force: true });
671
- }
659
+ restoreFromHead(projectDir, files);
672
660
 
673
661
  return { files };
674
662
  });
package/lib/domain.js CHANGED
@@ -28,7 +28,9 @@ const HUMAN = new Set(['blocked', 'awaiting-verdict', 'awaiting-decision', 'unpl
28
28
 
29
29
  const GATE_HELP = {
30
30
  verdict: 'Closed by a playtest: keep, tune or kill',
31
- auto: 'Closed by the run itself when its checks are green; no playtest',
31
+ auto:
32
+ 'Closed by the run itself when its checks are green; a mechanic or a resource goes ' +
33
+ 'unplayed and is played with its milestone',
32
34
  decision: 'Closed by the operator: go, no, close or continue',
33
35
  };
34
36
 
@@ -38,10 +40,12 @@ const GATE_HELP = {
38
40
  // `remove` is `--remove` / `--no-remove`, or the command's own rule when left empty; `slug` is
39
41
  // the target id the operator types (`{id}`); a field with `when` goes only while another field
40
42
  // holds one of those values.
43
+ // The graveyard keeps a reason (work-ops endToGraveyard): every move into it needs one.
41
44
  const REASON = { key: 'reason', label: 'Reason', kind: 'longtext', required: true };
42
- const OPTIONAL_REASON = { ...REASON, required: false };
43
45
  const REMOVE = { key: 'remove', label: 'Removal item for its code', kind: 'remove' };
44
46
  const CONSTRAINT = { key: 'constraint', label: 'Constraint lines', kind: 'list' };
47
+ // Where the operator played it: lines of game.md's platforms, a note for the history (Plan, C).
48
+ const PLAYED_ON = { key: 'played_on', flag: 'played-on', label: 'Played on', kind: 'list' };
45
49
  // close and submit need a green gcf verify of the code as it is now; the operator may say why
46
50
  // they go without one, and the reason goes into the move's commit.
47
51
  const UNVERIFIED = {
@@ -57,12 +61,16 @@ const UNTICKED = {
57
61
  excuses: 'plan',
58
62
  };
59
63
 
64
+ // A project chat agent proposes a verdict only after the operator said in its talk that they
65
+ // played it and how it felt, the note in their words (the gcf-chat skill holds it); the click
66
+ // that makes it is the operator's "I played it" (Board-PRD decision 42, AD-53).
60
67
  const verdict = (v, help, fields, danger) => ({
61
68
  label: v,
62
69
  help,
63
70
  args: ['gcf', 'verdict', '{id}', v],
64
71
  fields,
65
72
  ...(danger && { danger }),
73
+ propose: true,
66
74
  });
67
75
  const decide = (choice, help, fields = [], danger) => ({
68
76
  label: choice,
@@ -70,6 +78,7 @@ const decide = (choice, help, fields = [], danger) => ({
70
78
  args: ['gcf', 'decide', '{id}', choice],
71
79
  fields,
72
80
  ...(danger && { danger }),
81
+ propose: true,
73
82
  });
74
83
  const text = (key, label, extra = {}) => ({ key, label, kind: 'text', ...extra });
75
84
  // How an item's run goes (decision 36): a board offers Default (`default`), which leaves the
@@ -103,7 +112,7 @@ const ITEM_SPECS = {
103
112
  rare: true,
104
113
  },
105
114
  // A keep stores no note (`gcf verdict --note` is a tune's remark, a kill's reason).
106
- 'verdict:keep': verdict('keep', 'Played and kept: it goes to history', [CONSTRAINT]),
115
+ 'verdict:keep': verdict('keep', 'Played and kept: it goes to history', [CONSTRAINT, PLAYED_ON]),
107
116
  'verdict:tune': verdict('tune', 'Played; needs a change: back to ready with the note', [
108
117
  { key: 'note', label: 'What to change', kind: 'longtext', required: true },
109
118
  ]),
@@ -111,7 +120,7 @@ const ITEM_SPECS = {
111
120
  'kill',
112
121
  'Played and rejected: it goes to the graveyard',
113
122
  [
114
- { key: 'note', label: 'Why', kind: 'longtext' },
123
+ { key: 'note', label: 'Why', kind: 'longtext', required: true },
115
124
  {
116
125
  key: 'tags',
117
126
  label: 'Graveyard tags',
@@ -123,16 +132,11 @@ const ITEM_SPECS = {
123
132
  true,
124
133
  ),
125
134
  'decide:go': decide('go', 'Approved: it goes to history as decided'),
126
- 'decide:no': decide(
127
- 'no',
128
- 'Not doing it: it goes to the graveyard',
129
- [OPTIONAL_REASON, REMOVE],
130
- true,
131
- ),
135
+ 'decide:no': decide('no', 'Not doing it: it goes to the graveyard', [REASON, REMOVE], true),
132
136
  'decide:wontfix': decide(
133
137
  'wontfix',
134
138
  'A bug left as it is: it goes to the graveyard',
135
- [OPTIONAL_REASON, REMOVE],
139
+ [REASON, REMOVE],
136
140
  true,
137
141
  ),
138
142
  'decide:known': decide('known', 'A bug kept as a known issue: it goes to parked'),
@@ -141,7 +145,7 @@ const ITEM_SPECS = {
141
145
  'decide:kill': decide(
142
146
  'kill',
143
147
  'The feature is dropped: it goes to the graveyard with its live children',
144
- [OPTIONAL_REASON],
148
+ [REASON],
145
149
  true,
146
150
  ),
147
151
  block: {
@@ -157,6 +161,7 @@ const ITEM_SPECS = {
157
161
  args: ['gcf', 'unblock', '{id}'],
158
162
  fields: [{ key: 'note', label: 'Answer or "file: <path>"', kind: 'longtext' }],
159
163
  drag: RUNS_FROM,
164
+ propose: true,
160
165
  },
161
166
  drop: {
162
167
  label: 'drop',
@@ -186,6 +191,27 @@ const ITEM_SPECS = {
186
191
  fields: [MODEL, EFFORT],
187
192
  rare: true,
188
193
  },
194
+ gates: {
195
+ label: 'gates',
196
+ help:
197
+ "Its stops: skip (a verdict defers to its milestone's play, the agent decides a spike and " +
198
+ "assumes instead of asking), wait, or the project's gates",
199
+ args: ['gcf', 'item', 'gates', '{id}'],
200
+ fields: [
201
+ {
202
+ key: 'skip_gates',
203
+ flag: 'to',
204
+ label: 'Its gates',
205
+ kind: 'choice',
206
+ required: true,
207
+ options: [
208
+ { value: 'project', label: "the project's gates" },
209
+ { value: 'skip', label: 'skip: the agent goes on' },
210
+ { value: 'wait', label: 'wait: they wait for you' },
211
+ ],
212
+ },
213
+ ],
214
+ },
189
215
  mode: {
190
216
  label: 'run mode',
191
217
  help: 'Where its runs go: the project folder or a worktree of their own; the next run takes it',
@@ -577,6 +603,9 @@ const DETAIL = {
577
603
  help: 'One lowercase word after the category: asset, static-analysis, framework',
578
604
  };
579
605
 
606
+ // The paths of a `dirty` refusal: `--path=<path>` each.
607
+ const EDIT_PATHS = { key: 'paths', flag: 'path', label: 'Paths', kind: 'list', hidden: true };
608
+
580
609
  // The moves of the domain's blocks: the phase, the inbox, the questions, the run order.
581
610
  const BLOCK_SPECS = {
582
611
  'item-new': NEW_ITEM,
@@ -639,6 +668,22 @@ const BLOCK_SPECS = {
639
668
  help: 'The answer goes into the record; the next agent on its units puts it in place',
640
669
  args: ['gcf', 'question', 'answer', '{id}'],
641
670
  fields: [{ key: 'text', label: 'Answer', kind: 'text', required: true }],
671
+ propose: true,
672
+ },
673
+ // Hand edits under gcf/ that a move's `dirty` refusal names (Rich-Chat-Plan §5): the board
674
+ // fills the paths from the refusal; the operator's moves, never proposed.
675
+ 'edits-commit': {
676
+ label: 'commit',
677
+ help: 'Commit the hand edits under gcf/ as they are, then try the move again',
678
+ args: ['gcf', 'edits', 'commit'],
679
+ fields: [EDIT_PATHS],
680
+ },
681
+ 'edits-discard': {
682
+ label: 'discard',
683
+ help: 'Put the edited files back as the last commit has them; a new file goes. No undo',
684
+ args: ['gcf', 'edits', 'discard'],
685
+ fields: [EDIT_PATHS],
686
+ danger: true,
642
687
  },
643
688
  prioritize: {
644
689
  label: 'prioritize',
@@ -670,6 +715,9 @@ const FIELDS = [
670
715
  { key: 'model', label: 'model', kind: 'text', card: true, edit: 'agent' },
671
716
  { key: 'effort', label: 'effort', kind: 'text', edit: 'agent' },
672
717
  { key: 'run_mode', label: 'run mode', kind: 'text', edit: 'mode' },
718
+ { key: 'skip_gates', label: 'gates', kind: 'text', help: "Its card's gates", edit: 'gates' },
719
+ { key: 'gate_why', label: 'why its own stop', kind: 'text' },
720
+ { key: 'play_on', label: 'play on', kind: 'list', help: 'Where to play it: lines of platforms' },
673
721
  { key: 'tune_count', label: 'tune', kind: 'text', help: 'Tune verdicts so far', card: true },
674
722
  {
675
723
  key: 'waits_for',
@@ -749,6 +797,8 @@ const SECTIONS = {
749
797
  ...inboxVocabulary(),
750
798
  },
751
799
  questions: { answer: 'question-answer' },
800
+ // A move's `dirty` refusal: the board reads `gcf edits diff` and offers these.
801
+ edits: { commit: 'edits-commit', discard: 'edits-discard' },
752
802
  lessons: {},
753
803
  playtest: {
754
804
  // The inbox category a note from the playtest screen goes with.
@@ -792,6 +842,8 @@ const CHANGES = [
792
842
  'design save',
793
843
  'design commit',
794
844
  'design discard',
845
+ 'edits commit',
846
+ 'edits discard',
795
847
  'take',
796
848
  'done',
797
849
  'drop',
package/lib/edits.js ADDED
@@ -0,0 +1,115 @@
1
+ // Hand edits under gcf/ (Rich-Chat-Plan §5): what a move's `dirty` refusal names, shown, committed
2
+ // or put back. Reading is anyone's; commit and discard are the operator's (the CLI holds them,
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
+ import { spawnSync } from 'node:child_process';
6
+ import path from 'node:path';
7
+ import { dirtyGcf, literal, restoreFromHead } from './git.js';
8
+ import { locked } from './main-lock.js';
9
+ import { commitMove } from './unit-ops.js';
10
+
11
+ /** A path from the project with `/`: the form dirtyGcf gives and a refusal names. */
12
+ const norm = (projectDir, p) =>
13
+ path.relative(path.resolve(projectDir), path.resolve(projectDir, p)).replaceAll('\\', '/');
14
+
15
+ /**
16
+ * `paths` as dirtyGcf names them; one with no change under the gate's scope is refused (a
17
+ * clean path, one outside gcf/, a typo): the command acts only on what a refusal can name.
18
+ * @param {string} projectDir
19
+ * @param {string[]} paths
20
+ * @param {string} verb
21
+ */
22
+ function changed(projectDir, paths, verb) {
23
+ if (!paths.length)
24
+ throw new Error(`edits ${verb}: name the paths (--path), as a refusal lists them`);
25
+ const dirty = new Set(dirtyGcf(projectDir));
26
+ const files = [...new Set(paths.map((p) => norm(projectDir, p)))];
27
+ const off = files.filter((f) => !dirty.has(f));
28
+ if (off.length)
29
+ throw new Error(`edits ${verb}: no change under gcf/ to ${verb} in ${off.join(', ')}`);
30
+
31
+ return files;
32
+ }
33
+
34
+ const git = (projectDir, ...args) =>
35
+ spawnSync('git', ['-c', 'core.quotePath=false', ...args], { cwd: projectDir, encoding: 'utf8' })
36
+ .stdout ?? '';
37
+
38
+ /** A file git does not know yet as a diff of its own: each line added. */
39
+ function newFileDiff(projectDir, f) {
40
+ const file = path.join(projectDir, f);
41
+ if (!existsSync(file)) return '';
42
+ const text = readFileSync(file, 'utf8');
43
+ if (text.includes('\0')) return `new file ${f}: binary\n`;
44
+ const lines = text.replace(/\n$/, '').split('\n');
45
+
46
+ return `new file ${f}\n--- /dev/null\n+++ b/${f}\n${lines.map((l) => `+${l}`).join('\n')}\n`;
47
+ }
48
+
49
+ /** Literal pathspecs: a `[` in a name is no glob that takes its siblings along. */
50
+ const lits = (projectDir, files) => files.map((f) => literal(projectDir, f));
51
+
52
+ const tracked = (projectDir, f) =>
53
+ spawnSync('git', ['ls-files', '--error-unmatch', '--', literal(projectDir, f)], {
54
+ cwd: projectDir,
55
+ stdio: 'ignore',
56
+ }).status === 0;
57
+
58
+ /**
59
+ * The edits of `paths` in two parts: `staged` (the index against HEAD) and `unstaged` (the
60
+ * working file against the index), a new file's lines in the second. One diff against HEAD
61
+ * would hide an edit held only in the index when the file on disk equals HEAD; discard resets
62
+ * the index too, and that edit would go unseen.
63
+ * @param {string} projectDir
64
+ * @param {string[]} paths
65
+ */
66
+ export function editsDiff(projectDir, paths) {
67
+ const files = changed(projectDir, paths, 'diff');
68
+ const staged = git(projectDir, 'diff', '--cached', '--', ...lits(projectDir, files));
69
+ const known = files.filter((f) => tracked(projectDir, f));
70
+ const fresh = files.filter((f) => !known.includes(f));
71
+ const unstaged =
72
+ (known.length ? git(projectDir, 'diff', '--', ...lits(projectDir, known)) : '') +
73
+ fresh.map((f) => newFileDiff(projectDir, f)).join('');
74
+
75
+ return { files, staged, unstaged };
76
+ }
77
+
78
+ // The ids an edit touches: gcf/work/<id>.md and anything in gcf/work/<id>/ (item history finds
79
+ // the commit by them).
80
+ const ITEM_PATH = /^gcf\/work\/([^/]+?)(?:\.md$|\/)/;
81
+
82
+ /**
83
+ * Commit the hand edits of `paths` as they are, `gcf(edit): <n> files`, the move
84
+ * `edits-commit`. Through the gate like any move: its refusal comes up as it is.
85
+ * @param {string} projectDir
86
+ * @param {string[]} paths
87
+ */
88
+ export const editsCommit = (projectDir, paths) =>
89
+ locked(projectDir, true, async () => {
90
+ const files = changed(projectDir, paths, 'commit');
91
+ const abs = files.map((f) => path.join(projectDir, f));
92
+ const items = files.flatMap((f) => ITEM_PATH.exec(f)?.[1] ?? []);
93
+ const hash = await commitMove(
94
+ projectDir,
95
+ `gcf(edit): ${files.length} file${files.length === 1 ? '' : 's'}`,
96
+ // The files are the edits themselves: none is "dirty" to its own commit.
97
+ { files: abs, inputs: abs, mutate: async () => {}, commit: true, key: 'edits-commit', items },
98
+ );
99
+
100
+ return { files, hash };
101
+ });
102
+
103
+ /**
104
+ * Put the files of `paths` back as the last commit has them, the index too: a new one goes.
105
+ * It cannot be undone; a board shows the diff first.
106
+ * @param {string} projectDir
107
+ * @param {string[]} paths
108
+ */
109
+ export const editsDiscard = (projectDir, paths) =>
110
+ locked(projectDir, true, async () => {
111
+ const files = changed(projectDir, paths, 'discard');
112
+ restoreFromHead(projectDir, files);
113
+
114
+ return { files };
115
+ });