gcf-aif-ext 0.29.1 → 0.29.2

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.
@@ -68,12 +68,10 @@ export const DETAIL = /^[a-z0-9][a-z0-9-]{0,29}$/;
68
68
  * @param {string} id
69
69
  * @param {string} label
70
70
  * @param {string} help
71
- * @param {number} rank
72
- * @param {string} group
73
- * @param {string[]} setBy
74
- * @param {{details?: string[] | null, later?: boolean}} [opts]
71
+ * @param {{rank: number, group: string, setBy: string[], details?: string[] | null,
72
+ * later?: boolean}} opts
75
73
  */
76
- const row = (id, label, help, rank, group, setBy, { details = null, later = true } = {}) => ({
74
+ const row = (id, label, help, { rank, group, setBy, details = null, later = true }) => ({
77
75
  id,
78
76
  label,
79
77
  help,
@@ -90,50 +88,40 @@ export const BASE_CATEGORIES = [
90
88
  'decision',
91
89
  'Decision needed',
92
90
  'A question only you can answer; the work it holds waits for your answer',
93
- 1,
94
- 'needs-you',
95
- ['question'],
96
- { later: false },
91
+ { rank: 1, group: 'needs-you', setBy: ['question'], later: false },
97
92
  ),
98
93
  row(
99
94
  'failure',
100
95
  'Check failed',
101
96
  'An automatic check broke on the main line: a CI job, a build, a scheduled test',
102
- 2,
103
- 'needs-you',
104
- ['automation'],
105
- { later: false },
97
+ { rank: 2, group: 'needs-you', setBy: ['automation'], later: false },
106
98
  ),
107
99
  row(
108
100
  'request',
109
101
  'Agent request',
110
102
  'What only a person can give: a file, an asset, an account, an access',
111
- 3,
112
- 'needs-you',
113
- ['agent'],
103
+ { rank: 3, group: 'needs-you', setBy: ['agent'] },
114
104
  ),
115
- row('bug', 'Bug', 'The product does what a rule or a test says it must not', 4, 'to-sort', [
116
- 'you',
117
- 'agent',
118
- 'automation',
119
- ]),
105
+ row('bug', 'Bug', 'The product does what a rule or a test says it must not', {
106
+ rank: 4,
107
+ group: 'to-sort',
108
+ setBy: ['you', 'agent', 'automation'],
109
+ }),
120
110
  row(
121
111
  'finding',
122
112
  'Finding',
123
113
  "A remark about the code or the project: a risk, debt, an analyzer's warning, a slow path",
124
- 6,
125
- 'to-sort',
126
- ['agent', 'automation'],
127
- ),
128
- row(
129
- 'unsorted',
130
- 'Not sorted',
131
- 'An entry from before the categories: give it one',
132
- 7,
133
- 'to-sort',
134
- [],
114
+ { rank: 6, group: 'to-sort', setBy: ['agent', 'automation'] },
135
115
  ),
136
- row('lesson', 'Lesson', "What got in an agent's way in its run", 8, 'agent-feedback', ['agent'], {
116
+ row('unsorted', 'Not sorted', 'An entry from before the categories: give it one', {
117
+ rank: 7,
118
+ group: 'to-sort',
119
+ setBy: [],
120
+ }),
121
+ row('lesson', 'Lesson', "What got in an agent's way in its run", {
122
+ rank: 8,
123
+ group: 'agent-feedback',
124
+ setBy: ['agent'],
137
125
  details: LESSON_KINDS,
138
126
  }),
139
127
  // No Later either (the operator, 2026-10-22): it waits folded already, an answer moves it.
@@ -141,13 +129,18 @@ export const BASE_CATEGORIES = [
141
129
  'assumption',
142
130
  'Assumption to check',
143
131
  'A decision an agent took and works with; overrule it if it is wrong',
144
- 9,
145
- 'agent-feedback',
146
- ['question'],
147
- { later: false },
132
+ { rank: 9, group: 'agent-feedback', setBy: ['question'], later: false },
148
133
  ),
149
- row('idea', 'Idea', 'A change someone proposes, not decided', 10, 'ideas', ['you', 'agent']),
150
- row('note', 'Note', 'A reminder, a plan, a reference', 11, 'ideas', ['you']),
134
+ row('idea', 'Idea', 'A change someone proposes, not decided', {
135
+ rank: 10,
136
+ group: 'ideas',
137
+ setBy: ['you', 'agent'],
138
+ }),
139
+ row('note', 'Note', 'A reminder, a plan, a reference', {
140
+ rank: 11,
141
+ group: 'ideas',
142
+ setBy: ['you'],
143
+ }),
151
144
  ];
152
145
 
153
146
  /**
package/lib/inbox.js CHANGED
@@ -65,6 +65,19 @@ const OLD_SOURCES = {
65
65
  operator: ['note', 'you'],
66
66
  };
67
67
 
68
+ const laterOf = (category) => BASE_CATEGORIES.find((c) => c.id === category)?.later ?? true;
69
+
70
+ /** An old entry's detail: a lesson's kind, else its first tag when it reads as one (taken off). */
71
+ function oldDetail(lesson, kind, rest) {
72
+ if (lesson) return LESSON_KINDS.includes(String(kind)) ? String(kind) : 'other';
73
+ if (!rest.length) return null;
74
+ const word = rest[0].replaceAll(':', '-').slice(0, 30).replace(/-+$/, '');
75
+ if (!DETAIL.test(word)) return null;
76
+ rest.shift();
77
+
78
+ return word;
79
+ }
80
+
68
81
  /**
69
82
  * The frontmatter of an entry from before the categories (`source`, `tags`, a lesson's `kind`
70
83
  * and `item`) as the categories have it, with what did not fit (Board-PRD §2.6 Migration): the
@@ -79,20 +92,10 @@ export function fromOld({ source, tags = [], kind, item }) {
79
92
  if (!category || !Array.isArray(tags)) return null;
80
93
  const words = tags.map(String);
81
94
  // Later only where its category may go there: an old CI failure never did.
82
- const laterOk = BASE_CATEGORIES.find((c) => c.id === category)?.later ?? true;
95
+ const laterOk = laterOf(category);
83
96
  const later = words.includes('later') && laterOk;
84
97
  const rest = words.filter((t) => t !== 'later');
85
- /** @type {string | null} */
86
- let detail = null;
87
- if (lesson) detail = LESSON_KINDS.includes(String(kind)) ? String(kind) : 'other';
88
- else if (rest.length) {
89
- const word = rest[0].replaceAll(':', '-').slice(0, 30).replace(/-+$/, '');
90
- if (DETAIL.test(word)) {
91
- detail = word;
92
- rest.shift();
93
- }
94
- }
95
-
98
+ const detail = oldDetail(lesson, kind, rest);
96
99
  const lostLater = words.includes('later') && !laterOk ? ['later (never on its category)'] : [];
97
100
 
98
101
  return {
@@ -261,6 +264,17 @@ function originOf(origin, by) {
261
264
  return origin;
262
265
  }
263
266
 
267
+ /** Refuse filing an entry into category `c` from `from`: a question's, or one it may not file. */
268
+ function refuseFiling(vocab, c, from) {
269
+ if (questionOnly(c))
270
+ throw new Error(`a ${c.id} is an open question, not an entry: ai-factory gcf question add`);
271
+ if (!c.set_by.includes(from))
272
+ throw new Error(
273
+ `${from} files no ${c.id}: ${fileableBy(vocab, from).join(' | ') || 'none'} ` +
274
+ '(ai-factory gcf inbox categories)',
275
+ );
276
+ }
277
+
264
278
  /**
265
279
  * A new entry's plan: its file and how to write it. Its id hashes the text and the moment
266
280
  * (`now`), so two branches never collide; a clash in this folder hashes again. The category
@@ -292,13 +306,7 @@ export function planAdd(
292
306
  );
293
307
  const c = categoryOf(vocab, category);
294
308
  const from = originOf(origin, by);
295
- if (questionOnly(c))
296
- throw new Error(`a ${c.id} is an open question, not an entry: ai-factory gcf question add`);
297
- if (!c.set_by.includes(from))
298
- throw new Error(
299
- `${from} files no ${c.id}: ${fileableBy(vocab, from).join(' | ') || 'none'} ` +
300
- '(ai-factory gcf inbox categories)',
301
- );
309
+ refuseFiling(vocab, c, from);
302
310
  checkDetail(c, detail);
303
311
  if (item !== null && !isValidId(item)) throw new Error(`${item} is not an item id`);
304
312
  const id = freeId(root, `${now}\n${clean}`, taken);
@@ -334,6 +342,21 @@ async function planChange(root, id, change) {
334
342
  return plan;
335
343
  }
336
344
 
345
+ /** Refuse moving an entry into category `c`: a question's, an old one's, or one `actor` may not. */
346
+ function refuseMoveInto(vocab, c, actor) {
347
+ if (questionOnly(c) || !c.set_by.length)
348
+ throw new Error(
349
+ `no entry moves into ${c.id}: ` +
350
+ (c.set_by.length
351
+ ? 'it is an open question'
352
+ : 'it is for entries from before the categories'),
353
+ );
354
+ if (actor === 'agent' && !c.set_by.includes('agent'))
355
+ throw new Error(
356
+ `an agent moves no entry into ${c.id}: ${fileableBy(vocab, 'agent').join(' | ')}`,
357
+ );
358
+ }
359
+
337
360
  /**
338
361
  * Entry `id` moved to `category` (its own when none) with `detail` (none when the category
339
362
  * changes and no detail is given). The operator moves it to any category but a question's and
@@ -353,18 +376,7 @@ export async function planCategory(
353
376
 
354
377
  return planChange(root, id, (e) => {
355
378
  const c = categoryOf(vocab, category ?? e.category);
356
- const actor = actorOrigin(by);
357
- if (questionOnly(c) || !c.set_by.length)
358
- throw new Error(
359
- `no entry moves into ${c.id}: ` +
360
- (c.set_by.length
361
- ? 'it is an open question'
362
- : 'it is for entries from before the categories'),
363
- );
364
- if (actor === 'agent' && !c.set_by.includes('agent'))
365
- throw new Error(
366
- `an agent moves no entry into ${c.id}: ${fileableBy(vocab, 'agent').join(' | ')}`,
367
- );
379
+ refuseMoveInto(vocab, c, actorOrigin(by));
368
380
  const next = detail === undefined ? (c.id === e.category ? e.detail : null) : detail || null;
369
381
  checkDetail(c, next);
370
382
  if (c.id === e.category && next === e.detail)
@@ -471,9 +483,9 @@ export async function dropInbox(root, id) {
471
483
  */
472
484
  export function untrackedEntries(projectDir) {
473
485
  const list = (args) =>
474
- (spawnSync('git', args, { cwd: projectDir, encoding: 'utf8' }).stdout ?? '').split(
475
- String.fromCharCode(0),
476
- );
486
+ (
487
+ spawnSync('git', args, { windowsHide: true, cwd: projectDir, encoding: 'utf8' }).stdout ?? ''
488
+ ).split(String.fromCharCode(0));
477
489
  // Never committed: not tracked at all, or only staged.
478
490
  const names = [
479
491
  ...list(['ls-files', '--others', '--exclude-standard', '-z', '--', 'gcf/inbox']),
package/lib/integrate.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // branch is ready once its tip carries the trailer `GCF-Verified: <id>` — readiness lives in git,
3
3
  // not in memory. `integrate` merges such a branch into main and records the item's move there,
4
4
  // under the main lock; without an id it picks up every verified branch a dead run left behind.
5
- import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
5
+ import { readFile, writeFile } from 'node:fs/promises';
6
6
  import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
7
7
  import { spawnSync } from 'node:child_process';
8
8
  import path from 'node:path';
@@ -17,6 +17,7 @@ import { agentDecideProblem } from './gates.js';
17
17
  import { isValidId } from './id.js';
18
18
  import { writeIndex } from './index-gen.js';
19
19
  import { moveTrailers, restoreIndex, snapshotIndex } from './git.js';
20
+ import { excludeSession } from './session-mark.js';
20
21
 
21
22
  const TRAILER = 'GCF-Verified';
22
23
  export const branchOf = (id) => `work/${id}`;
@@ -24,23 +25,13 @@ export const worktreeOf = (projectDir, id) =>
24
25
  path.join(path.resolve(projectDir), '.gcf-session', 'worktrees', id);
25
26
 
26
27
  function git(cwd, args, { check = true } = {}) {
27
- const res = spawnSync('git', args, { cwd, encoding: 'utf8' });
28
+ const res = spawnSync('git', args, { windowsHide: true, cwd, encoding: 'utf8' });
28
29
  const err = (res.stderr || res.stdout || '').trim();
29
30
  if (check && res.status !== 0) throw new Error(`git ${args.join(' ')} failed: ${err}`);
30
31
 
31
32
  return { ok: res.status === 0, out: (res.stdout ?? '').trim(), err };
32
33
  }
33
34
 
34
- /** `.gcf-session/` stays out of `git status` without a tracked .gitignore change. */
35
- export async function excludeSession(projectDir) {
36
- const common = path.resolve(projectDir, git(projectDir, ['rev-parse', '--git-common-dir']).out);
37
- const file = path.join(common, 'info', 'exclude');
38
- const text = existsSync(file) ? await readFile(file, 'utf8') : '';
39
- if (text.split(/\r?\n/).includes('/.gcf-session/')) return;
40
- await mkdir(path.dirname(file), { recursive: true });
41
- await appendFile(file, `${text && !text.endsWith('\n') ? '\n' : ''}/.gcf-session/\n`);
42
- }
43
-
44
35
  const METRICS = ':(exclude)gcf/.metrics';
45
36
 
46
37
  /** A worktree's own audit and context lines in gcf/.metrics are no work to keep: dropped. */
package/lib/ledger.js CHANGED
@@ -25,7 +25,7 @@ async function recordLines(root, name) {
25
25
  }
26
26
 
27
27
  const gitOut = (args, cwd) => {
28
- const res = spawnSync('git', args, { cwd, encoding: 'utf8' });
28
+ const res = spawnSync('git', args, { windowsHide: true, cwd, encoding: 'utf8' });
29
29
 
30
30
  return res.status === 0 ? res.stdout : null;
31
31
  };
package/lib/lessons.js CHANGED
@@ -155,7 +155,10 @@ export async function addLessons(root, id, lessons) {
155
155
  return plan.entries;
156
156
  }
157
157
 
158
- /** The lessons of a JSON file: an array, as the harness writes it. */
158
+ /**
159
+ * The lessons of a JSON file: an array, as the harness writes it.
160
+ * @public gcf.js imports lib modules by name at run time, out of knip's sight.
161
+ */
159
162
  export async function lessonsFile(file) {
160
163
  try {
161
164
  return JSON.parse(await readFile(file, 'utf8'));
package/lib/metrics.js CHANGED
@@ -9,6 +9,7 @@ import path from 'node:path';
9
9
  /** gcf/.metrics of the main checkout of `projectDir`; its own outside a repository. */
10
10
  export function metricsDir(projectDir) {
11
11
  const res = spawnSync('git', ['rev-parse', '--git-common-dir'], {
12
+ windowsHide: true,
12
13
  cwd: projectDir,
13
14
  encoding: 'utf8',
14
15
  });
package/lib/migrate.js CHANGED
@@ -61,7 +61,7 @@ async function historySeed(projectDir, root) {
61
61
  const res = spawnSync(
62
62
  'git',
63
63
  ['log', '-E', '--grep', '^((Revert|Reapply) ")*gcf\\((verdict|done)\\):', '--format=%as %s'],
64
- { cwd: projectDir, encoding: 'utf8' },
64
+ { windowsHide: true, cwd: projectDir, encoding: 'utf8' },
65
65
  );
66
66
  const log = res.status === 0 ? res.stdout.split('\n').filter(Boolean) : [];
67
67
  const file = path.join(root, 'history.md');
@@ -22,7 +22,7 @@ function carriedOnce(projectDir, name) {
22
22
  '--',
23
23
  'gcf/work',
24
24
  ],
25
- { cwd: projectDir, encoding: 'utf8' },
25
+ { windowsHide: true, cwd: projectDir, encoding: 'utf8' },
26
26
  );
27
27
 
28
28
  return res.status === 0 && Boolean(res.stdout.trim());
package/lib/phase.js CHANGED
@@ -7,7 +7,7 @@ import { readConfig } from './gcf-paths.js';
7
7
  import { readLiveStrict, writeLive, liveFile } from './live.js';
8
8
  import { buildLedger } from './ledger.js';
9
9
  import { ITEM_TYPES } from './validate-item.js';
10
- import { commitMove } from './unit-ops.js';
10
+ import { commitMove } from './commit-move.js';
11
11
  import { locked } from './main-lock.js';
12
12
  import { gameMilestones } from './design-check.js';
13
13
 
package/lib/pillars.js CHANGED
@@ -9,7 +9,7 @@ import { SLUG_RE, listOf, parseDesign } from './design.js';
9
9
  import { recordsIn } from './design-check.js';
10
10
  import { buildLedger } from './ledger.js';
11
11
  import { atomicWrite } from './safe-path.js';
12
- import { commitMove } from './unit-ops.js';
12
+ import { commitMove } from './commit-move.js';
13
13
  import { locked } from './main-lock.js';
14
14
 
15
15
  const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
package/lib/play.js CHANGED
@@ -13,20 +13,20 @@ import net from 'node:net';
13
13
  import os from 'node:os';
14
14
  import path from 'node:path';
15
15
  import YAML from 'yaml';
16
- import { configDoc } from './config-set.js';
16
+ import { configDoc } from './config-doc.js';
17
17
  import { readConfig } from './gcf-paths.js';
18
18
  import { isValidId } from './id.js';
19
19
  import { buildLedger } from './ledger.js';
20
20
  import { alive, claimMainRun, MAIN_RUN, runHolder, withMainLock } from './main-lock.js';
21
21
  import { atomicWrite, renameRetrying } from './safe-path.js';
22
- import { commitMove } from './unit-ops.js';
22
+ import { commitMove } from './commit-move.js';
23
23
  import { commandEnv } from './shell-env.js';
24
24
  import { failureOf, killTree, runCommand } from './verify.js';
25
25
  import { unplayedCloseCommit } from './verdict-fs.js';
26
26
  import { CANCELLED, cancelled, sweepTickets, ticketClose, ticketOpen } from './build-queue.js';
27
27
  import { readTicket, ticketSet, ticketsOf, waitTurn } from './build-queue.js';
28
28
  import { fileURLToPath } from 'node:url';
29
- import { DEVICE_ID_RE, devicesOf } from './devices.js';
29
+ import { DEVICE_ID_RE, targetDevices } from './devices.js';
30
30
 
31
31
  export const NOT_SET_UP =
32
32
  'how to play is not set up: ai-factory gcf playtest setup --build <cmd> --output <folder> ' +
@@ -381,7 +381,12 @@ const refreshed = (before, after) => [...after].some(([p, f]) => before.get(p)?.
381
381
 
382
382
  const gitOut = (cwd, args) => {
383
383
  // A big project lists far past the 1 MB a spawn holds by default; past it git's answer is lost.
384
- const res = spawnSync('git', args, { cwd, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
384
+ const res = spawnSync('git', args, {
385
+ windowsHide: true,
386
+ cwd,
387
+ encoding: 'utf8',
388
+ maxBuffer: 256 * 1024 * 1024,
389
+ });
385
390
 
386
391
  return res.status === 0 ? res.stdout : null;
387
392
  };
@@ -959,7 +964,13 @@ async function claimTree(dir, ticket = null) {
959
964
  function gitMust(cwd, args) {
960
965
  // A caller's GIT_DIR or GIT_WORK_TREE (a hook) would point a clean at its own folder.
961
966
  const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => !/^GIT_/.test(k)));
962
- const res = spawnSync('git', args, { cwd, env, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
967
+ const res = spawnSync('git', args, {
968
+ windowsHide: true,
969
+ cwd,
970
+ env,
971
+ encoding: 'utf8',
972
+ maxBuffer: 64 * 1024 * 1024,
973
+ });
963
974
  if (res.status !== 0)
964
975
  throw new Error(`git ${args[0]} in the build folder failed: ${(res.stderr || '').trim()}`);
965
976
  }
@@ -1331,6 +1342,21 @@ async function buildThenStart(dir, id, how, n) {
1331
1342
  return startNow(dir, id, how);
1332
1343
  }
1333
1344
 
1345
+ /**
1346
+ * `gcf playtest devices <target>`: what the target's script finds, each device placed under a row
1347
+ * of `plays_on` it fits, or why not (targetDevices).
1348
+ * @param {string} projectDir
1349
+ * @param {string} targetName
1350
+ * @param {{ ms?: number }} [opts]
1351
+ */
1352
+ export async function devicesOf(projectDir, targetName, opts) {
1353
+ const dir = path.resolve(projectDir);
1354
+ const play = playOf(await readConfig(path.join(dir, 'gcf')));
1355
+ if (!play) throw new Error(NOT_SET_UP);
1356
+
1357
+ return targetDevices(dir, play, targetName, opts);
1358
+ }
1359
+
1334
1360
  /**
1335
1361
  * The device a start plays on (docs/Handoff-Plan.md t8): an id of the target's `devices` answer
1336
1362
  * that fits a row and is ready. A target whose commands name `{device}` plays on none without one.
@@ -105,7 +105,7 @@ async function decisionList(root) {
105
105
  }
106
106
 
107
107
  const git = (projectDir, args) => {
108
- const res = spawnSync('git', args, { cwd: projectDir, encoding: 'utf8' });
108
+ const res = spawnSync('git', args, { windowsHide: true, cwd: projectDir, encoding: 'utf8' });
109
109
 
110
110
  return res.status === 0 ? res.stdout.trim() : null;
111
111
  };
package/lib/push.js CHANGED
@@ -5,7 +5,7 @@ import { spawn, spawnSync } from 'node:child_process';
5
5
  import { operationInProgress } from './git.js';
6
6
  import { claimMainRun, MAIN_RUN, runHolder, withMainLock } from './main-lock.js';
7
7
  import { refusal } from './refusal.js';
8
- import { onWorkBranch } from './unit-ops.js';
8
+ import { onWorkBranch } from './commit-move.js';
9
9
  import { killTree } from './verify.js';
10
10
 
11
11
  export const NET_TIMEOUT_MS = 90_000;
@@ -16,6 +16,7 @@ const RS = '\x1e';
16
16
 
17
17
  const git = (dir, args, opts = {}) =>
18
18
  spawnSync('git', ['-c', 'core.quotePath=false', ...args], {
19
+ windowsHide: true,
19
20
  cwd: dir,
20
21
  encoding: 'utf8',
21
22
  ...opts,
package/lib/questions.js CHANGED
@@ -6,7 +6,7 @@ import { readFile } from 'node:fs/promises';
6
6
  import { existsSync } from 'node:fs';
7
7
  import path from 'node:path';
8
8
  import { atomicWrite } from './safe-path.js';
9
- import { commitMove } from './unit-ops.js';
9
+ import { commitMove } from './commit-move.js';
10
10
  import { locked } from './main-lock.js';
11
11
  import { blockEnd, fieldOf, indentOf } from './question-fields.js';
12
12
 
@@ -6,9 +6,9 @@
6
6
  // session that stopped: the item reads as not running again. The mark names its owner, so a
7
7
  // second session cannot take an item the first one works.
8
8
  import { existsSync, readdirSync, readFileSync, rmSync, statSync, utimesSync } from 'node:fs';
9
- import { mkdir, writeFile } from 'node:fs/promises';
9
+ import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
10
+ import { spawnSync } from 'node:child_process';
10
11
  import path from 'node:path';
11
- import { excludeSession } from './integrate.js';
12
12
  import { alive, withMainLock } from './main-lock.js';
13
13
  import { enterFolder } from './shelf.js';
14
14
 
@@ -19,6 +19,25 @@ export const SESSION_TTL_MS = 120 * 60_000;
19
19
  const markOf = (projectDir, id) =>
20
20
  path.join(path.resolve(projectDir), '.gcf-session', 'runs', `${id}.session`);
21
21
 
22
+ /** `.gcf-session/` stays out of `git status` without a tracked .gitignore change. */
23
+ export async function excludeSession(projectDir) {
24
+ const res = spawnSync('git', ['rev-parse', '--git-common-dir'], {
25
+ windowsHide: true,
26
+ cwd: projectDir,
27
+ encoding: 'utf8',
28
+ });
29
+ if (res.status !== 0)
30
+ throw new Error(
31
+ `git rev-parse --git-common-dir failed: ${(res.stderr || res.stdout || '').trim()}`,
32
+ );
33
+ const common = path.resolve(projectDir, res.stdout.trim());
34
+ const file = path.join(common, 'info', 'exclude');
35
+ const text = existsSync(file) ? await readFile(file, 'utf8') : '';
36
+ if (text.split(/\r?\n/).includes('/.gcf-session/')) return;
37
+ await mkdir(path.dirname(file), { recursive: true });
38
+ await appendFile(file, `${text && !text.endsWith('\n') ? '\n' : ''}/.gcf-session/\n`);
39
+ }
40
+
22
41
  /**
23
42
  * Who works an item: a harness run (`GCF_RUN_OWNER`, which its agent sessions inherit, a fresh
24
43
  * one after a handoff included), else the Claude Code session; null when neither is known.
package/lib/shelf.js CHANGED
@@ -41,6 +41,7 @@ const IDENT = { name: 'gcf', email: 'gcf@localhost' };
41
41
  */
42
42
  function git(dir, args, { env = {}, input } = {}) {
43
43
  const r = spawnSync('git', args, {
44
+ windowsHide: true,
44
45
  cwd: dir,
45
46
  encoding: 'utf8',
46
47
  input,
@@ -39,33 +39,38 @@ export function blocksOf(text, { raw = false } = {}) {
39
39
  });
40
40
  }
41
41
 
42
+ /** Block `at` of `lines` set to `rendered` in place. */
43
+ function setBlockAt(lines, at, rendered) {
44
+ // A dropped block takes one of the blank lines around it along.
45
+ const drop = !rendered.length && !lines[at.start - 2]?.trim() && !lines[at.end]?.trim();
46
+
47
+ return [...lines.slice(0, at.start - 1), ...rendered, ...lines.slice(at.end + (drop ? 1 : 0))];
48
+ }
49
+
50
+ /** `rendered` as the first block of `lines`, the blocks there after it. */
51
+ function firstBlock(lines, blocks, rendered, tight) {
52
+ if (blocks.length) return [...rendered, ...(tight(blocks[0]) ? [] : ['']), ...lines];
53
+ // A body of words with no block keeps them, over the new one.
54
+ const last = lines.findLastIndex((l) => l.trim());
55
+
56
+ return last < 0 ? rendered : [...lines.slice(0, last + 1), '', ...rendered, ''];
57
+ }
58
+
42
59
  /**
43
60
  * `lines` with block `spec` set to `rendered`: in place, or where the field order puts it.
44
61
  * `raw`: as blocksOf's, a comment or fence closing the block before stays above the new one.
45
62
  */
46
- export function putBlock(lines, specs, spec, rendered, { raw = false } = {}) {
63
+ export function putBlock(lines, specs, spec, { rendered, raw = false }) {
47
64
  const blocks = blocksOf(lines.join('\n'), { raw });
48
65
  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
-
66
+ if (at) return setBlockAt(lines, at, rendered);
56
67
  if (!rendered.length) return lines;
57
68
  const order = specs.map((s) => s.key);
58
69
  const header = (b) => Boolean(specs.find((s) => s.key === b?.key)?.header);
59
70
  // Header fields stand line under line; a block stands apart from its neighbours.
60
71
  const tight = (b) => Boolean(spec.header && header(b));
61
72
  const prev = blocks.filter((b) => order.indexOf(b.key) < order.indexOf(spec.key)).at(-1);
62
- if (!prev && blocks.length) return [...rendered, ...(tight(blocks[0]) ? [] : ['']), ...lines];
63
- if (!prev) {
64
- // A body of words with no block keeps them, over the new one.
65
- const last = lines.findLastIndex((l) => l.trim());
66
-
67
- return last < 0 ? rendered : [...lines.slice(0, last + 1), '', ...rendered, ''];
68
- }
73
+ if (!prev) return firstBlock(lines, blocks, rendered, tight);
69
74
 
70
75
  const tail = lines.slice(prev.end);
71
76
  const gap = tight(prev) ? [] : [''];
@@ -105,7 +110,12 @@ export function upsertBlock(rawBody, key, addLines, order) {
105
110
  lines.pop();
106
111
  }
107
112
 
108
- const put = putBlock(lines, specs, { key }, [`${key}:`, ...kept, ...fresh], { raw: true });
113
+ const put = putBlock(
114
+ lines,
115
+ specs,
116
+ { key },
117
+ { rendered: [`${key}:`, ...kept, ...fresh], raw: true },
118
+ );
109
119
 
110
120
  return `${lead}${put.join('\n')}`.replace(/\n{3,}/g, '\n\n');
111
121
  }
@@ -146,7 +156,7 @@ export function replaceBlock(rawBody, key, rendered, order) {
146
156
  const specs = (order.includes(key) ? order : [...order, key]).map((k) => ({ key: k }));
147
157
  const lead = /** @type {RegExpMatchArray} */ (body.match(/^\n*/))[0];
148
158
  const lines = body.slice(lead.length).split('\n');
149
- const put = putBlock(lines, specs, { key }, rendered, { raw: true });
159
+ const put = putBlock(lines, specs, { key }, { rendered, raw: true });
150
160
 
151
161
  return `${lead}${put.join('\n')}`.replace(/\n{3,}/g, '\n\n');
152
162
  }