gcf-aif-ext 0.20.1 → 0.20.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.
package/README.md CHANGED
@@ -50,6 +50,10 @@ Updating preserves `gcf/`, `cnlp.config.json` and the pre-commit hook. Run `ai-f
50
50
 
51
51
  On Windows, run `extension add` and `extension update` from PowerShell or cmd, not Git Bash: the installer unpacks with `tar`, and Git Bash's GNU tar reads `C:\…` as a remote host (`Cannot connect to C: resolve failed`). The Windows `tar.exe` handles it.
52
52
 
53
+ ### 0.20.2
54
+
55
+ - `edits diff|commit|discard` also take the paths from `--path-file <file|->`, one a line: a board sends a refusal's paths on stdin. Hundreds of them no longer run past Windows' 32K command line, neither in the command nor in the git calls of a move's commit: `git diff` and `git ls-files` go in parts, `git commit` takes a long list from `--pathspec-from-file` (git 2.25+; a move's few paths stay arguments).
56
+
53
57
  ### 0.20.1
54
58
 
55
59
  - `edits diff|commit|discard` on a path with no change left ends its error with `gcf-refusal: {"code":"clean","paths":[…],"left":[…]}`: the clean paths, and the named ones still edited. A board whose refusal list went stale (another card's Commit took the files) knows nothing is left to fix.
package/commands/gcf.js CHANGED
@@ -753,13 +753,17 @@ function registerEdits(gcf) {
753
753
  "(the human's)",
754
754
  );
755
755
  const PATH = 'a path from the project, as the refusal lists it (repeatable)';
756
+ const PATH_FILE = 'the paths from a file, one a line, - for stdin: past the command line';
757
+ // A refusal of many paths runs past Windows' 32K command line: a board sends them on stdin.
758
+ const pathsOf = (o) => [...o.path, ...(o.pathFile === undefined ? [] : linesOf(o.pathFile))];
756
759
  group
757
760
  .command('diff')
758
761
  .description('The edits of these paths: the staged part and the part not staged')
759
- .requiredOption('--path <path>', PATH, repeated, [])
762
+ .option('--path <path>', PATH, repeated, [])
763
+ .option('--path-file <path>', PATH_FILE)
760
764
  .option('--json', '{files, staged, unstaged}')
761
765
  .action(async (o) => {
762
- const r = (await edits()).editsDiff(process.cwd(), o.path);
766
+ const r = (await edits()).editsDiff(process.cwd(), pathsOf(o));
763
767
  if (o.json) return out(true, r);
764
768
  if (r.staged) console.log(`staged:\n${r.staged}`);
765
769
  if (r.unstaged) console.log(`not staged:\n${r.unstaged}`);
@@ -767,10 +771,11 @@ function registerEdits(gcf) {
767
771
  group
768
772
  .command('commit')
769
773
  .description('Commit the hand edits of these paths as they are: gcf(edit), through the gate')
770
- .requiredOption('--path <path>', PATH, repeated, [])
774
+ .option('--path <path>', PATH, repeated, [])
775
+ .option('--path-file <path>', PATH_FILE)
771
776
  .action(async (o) => {
772
777
  await operatorOnly('edits commit');
773
- const r = await (await edits()).editsCommit(process.cwd(), o.path);
778
+ const r = await (await edits()).editsCommit(process.cwd(), pathsOf(o));
774
779
  console.log(`committed ${r.files.join(', ')}${shortHash(r.hash)}`);
775
780
  });
776
781
  group
@@ -779,10 +784,11 @@ function registerEdits(gcf) {
779
784
  'Put these paths back as the last commit has them, the index too; a new file goes. ' +
780
785
  'It cannot be undone: look at edits diff first',
781
786
  )
782
- .requiredOption('--path <path>', PATH, repeated, [])
787
+ .option('--path <path>', PATH, repeated, [])
788
+ .option('--path-file <path>', PATH_FILE)
783
789
  .action(async (o) => {
784
790
  await operatorOnly('edits discard');
785
- const r = await (await edits()).editsDiscard(process.cwd(), o.path);
791
+ const r = await (await edits()).editsDiscard(process.cwd(), pathsOf(o));
786
792
  console.log(`discarded ${r.files.join(', ')}`);
787
793
  });
788
794
  }
@@ -1354,6 +1360,12 @@ function entryText(arg, o) {
1354
1360
  return readTextFile(o.textFile);
1355
1361
  }
1356
1362
 
1363
+ /** A file's lines, `-` for stdin: none empty, a CRLF's CR gone. */
1364
+ const linesOf = (file) =>
1365
+ readTextFile(file)
1366
+ .split(/\r?\n/)
1367
+ .filter((l) => l !== '');
1368
+
1357
1369
  /** A text file's text, `-` for stdin. */
1358
1370
  function readTextFile(file) {
1359
1371
  const text = readFileSync(file === '-' ? 0 : file, 'utf8');
package/extension.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/lee-to/ai-factory/2.x/schemas/extension.schema.json",
3
3
  "name": "gcf-aif-ext",
4
- "version": "0.20.1",
4
+ "version": "0.20.2",
5
5
  "description": "Game Context Framework for AI Factory",
6
6
  "skills": [
7
7
  "skills/gcf-init",
package/lib/domain.js CHANGED
@@ -603,8 +603,16 @@ const DETAIL = {
603
603
  help: 'One lowercase word after the category: asset, static-analysis, framework',
604
604
  };
605
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 };
606
+ // The paths of a `dirty` refusal: `--path=<path>` each, or one a line on stdin (`lines`:
607
+ // `--path-file -`, core 0.20.2), past Windows' 32K command line.
608
+ const EDIT_PATHS = {
609
+ key: 'paths',
610
+ flag: 'path',
611
+ label: 'Paths',
612
+ kind: 'list',
613
+ hidden: true,
614
+ lines: true,
615
+ };
608
616
 
609
617
  // The moves of the domain's blocks: the phase, the inbox, the questions, the run order.
610
618
  const BLOCK_SPECS = {
package/lib/edits.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { readFileSync, existsSync } from 'node:fs';
5
5
  import { spawnSync } from 'node:child_process';
6
6
  import path from 'node:path';
7
- import { dirtyGcf, literal, restoreFromHead } from './git.js';
7
+ import { dirtyGcf, inParts, literal, restoreFromHead } from './git.js';
8
8
  import { locked } from './main-lock.js';
9
9
  import { refusal } from './refusal.js';
10
10
  import { commitMove } from './unit-ops.js';
@@ -56,6 +56,40 @@ function newFileDiff(projectDir, f) {
56
56
  /** Literal pathspecs: a `[` in a name is no glob that takes its siblings along. */
57
57
  const lits = (projectDir, files) => files.map((f) => literal(projectDir, f));
58
58
 
59
+ // The form a board cuts the diff by, whatever the user's git config says (diff.noprefix,
60
+ // diff.mnemonicPrefix, color.ui=always, an external diff): heads `a/<path> b/<path>` from the
61
+ // project, as dirtyGcf names the paths, not from the repository a project may sit in.
62
+ const DIFF_FORM = [
63
+ '--no-color',
64
+ '--no-ext-diff',
65
+ '--no-textconv',
66
+ '--relative',
67
+ '--src-prefix=a/',
68
+ '--dst-prefix=b/',
69
+ ];
70
+
71
+ /**
72
+ * `git diff <opts>` of `files`; it takes no pathspec file: a long list in parts (inParts). A
73
+ * working-tree diff refreshes the index under index.lock even with GIT_OPTIONAL_LOCKS=0 (a
74
+ * file with a new time and the index's content): autoRefreshIndex off, a run's commit beside
75
+ * the open dialog finds no lock.
76
+ */
77
+ const diffOf = (projectDir, opts, files) =>
78
+ inParts(lits(projectDir, files))
79
+ .map((part) =>
80
+ git(
81
+ projectDir,
82
+ '-c',
83
+ 'diff.autoRefreshIndex=false',
84
+ 'diff',
85
+ ...DIFF_FORM,
86
+ ...opts,
87
+ '--',
88
+ ...part,
89
+ ),
90
+ )
91
+ .join('');
92
+
59
93
  const tracked = (projectDir, f) =>
60
94
  spawnSync('git', ['ls-files', '--error-unmatch', '--', literal(projectDir, f)], {
61
95
  cwd: projectDir,
@@ -72,12 +106,11 @@ const tracked = (projectDir, f) =>
72
106
  */
73
107
  export function editsDiff(projectDir, paths) {
74
108
  const files = changed(projectDir, paths, 'diff');
75
- const staged = git(projectDir, 'diff', '--cached', '--', ...lits(projectDir, files));
109
+ const staged = diffOf(projectDir, ['--cached'], files);
76
110
  const known = files.filter((f) => tracked(projectDir, f));
77
111
  const fresh = files.filter((f) => !known.includes(f));
78
112
  const unstaged =
79
- (known.length ? git(projectDir, 'diff', '--', ...lits(projectDir, known)) : '') +
80
- fresh.map((f) => newFileDiff(projectDir, f)).join('');
113
+ diffOf(projectDir, [], known) + fresh.map((f) => newFileDiff(projectDir, f)).join('');
81
114
 
82
115
  return { files, staged, unstaged };
83
116
  }
package/lib/git.js CHANGED
@@ -3,6 +3,34 @@ import { existsSync, rmSync } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { refusal } from './refusal.js';
5
5
 
6
+ // A read (`git status`, `git diff`) refreshes the index under index.lock when it can: a board's
7
+ // read then failed a run's integrate commit in main ("index.lock: File exists"). Every git of
8
+ // this process reads without that lock; a write takes its own lock as ever.
9
+ process.env.GIT_OPTIONAL_LOCKS ??= '0';
10
+
11
+ // Windows' command line holds 32K characters: a longer list of paths (a refusal's hundreds of
12
+ // hand edits) goes in parts, or to `git commit` from a file.
13
+ const ARGS_MAX = 8000;
14
+
15
+ /** `specs` in parts, each short enough for one command line. */
16
+ export function inParts(specs) {
17
+ const parts = [];
18
+ let part = [];
19
+ let n = 0;
20
+ for (const s of specs) {
21
+ if (part.length && n + s.length + 1 > ARGS_MAX) {
22
+ parts.push(part);
23
+ part = [];
24
+ n = 0;
25
+ }
26
+ part.push(s);
27
+ n += s.length + 1;
28
+ }
29
+ if (part.length) parts.push(part);
30
+
31
+ return parts;
32
+ }
33
+
6
34
  // `git commit --only <paths>` is a partial commit, which git refuses outright while a merge
7
35
  // or a sequencer operation is in progress. Detect it up front so the failure has a reason.
8
36
  const IN_PROGRESS = [
@@ -226,10 +254,22 @@ export function commitPaths(projectDir, message, paths, move = {}) {
226
254
  const real = paths.filter((p) => existsSync(p) || inHead(projectDir, p));
227
255
  const msg = ['-m', message, ...moveTrailers(move)];
228
256
  const only = real.map((p) => literal(projectDir, p));
229
- const res = spawnSync('git', ['commit', ...msg, '--only', '--', ...only], {
230
- cwd: projectDir,
231
- encoding: 'utf8',
232
- });
257
+ // A list past one command line goes on stdin (git 2.25+); a move's few paths as arguments.
258
+ const long = inParts(only).length > 1;
259
+ const res = spawnSync(
260
+ 'git',
261
+ [
262
+ 'commit',
263
+ ...msg,
264
+ '--only',
265
+ ...(long ? ['--pathspec-from-file=-', '--pathspec-file-nul'] : ['--', ...only]),
266
+ ],
267
+ {
268
+ cwd: projectDir,
269
+ encoding: 'utf8',
270
+ ...(long && { input: only.map((p) => `${p}\0`).join('') }),
271
+ },
272
+ );
233
273
  const out = res.stderr || res.stdout;
234
274
  // The gate reads the whole gcf/ tree: another file's edit stops the move, in the Operator's
235
275
  // words. Its paths from git: the move's own staged files ride along and stop nothing.
@@ -259,15 +299,23 @@ export function commitPaths(projectDir, message, paths, move = {}) {
259
299
  export function snapshotIndex(cwd, files) {
260
300
  const rels = files.map((f) => path.relative(cwd, f).replaceAll('\\', '/'));
261
301
  // -z: no C-quoting of non-ASCII paths, so the output is the path itself.
262
- const res = spawnSync('git', ['ls-files', '-s', '-z', '--', ...rels], { cwd, encoding: 'utf8' });
263
- if (res.status !== 0) return null;
302
+ // ls-files takes no pathspec file: a long list in parts.
303
+ let stdout = '';
304
+ for (const part of inParts(rels)) {
305
+ const res = spawnSync('git', ['ls-files', '-s', '-z', '--', ...part], {
306
+ cwd,
307
+ encoding: 'utf8',
308
+ });
309
+ if (res.status !== 0) return null;
310
+ stdout += res.stdout;
311
+ }
264
312
  const prefix = spawnSync('git', ['rev-parse', '--show-prefix'], {
265
313
  cwd,
266
314
  encoding: 'utf8',
267
315
  }).stdout.trim();
268
316
  const entries = new Map();
269
317
  const conflicted = new Set();
270
- for (const rec of res.stdout.split('\0').filter(Boolean)) {
318
+ for (const rec of stdout.split('\0').filter(Boolean)) {
271
319
  const m = rec.match(/^(\d+) ([0-9a-f]+) (\d)\t(.+)$/s);
272
320
  if (!m) continue;
273
321
  if (m[3] === '0') entries.set(m[4], { mode: m[1], blob: m[2] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-aif-ext",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "description": "Game Context Framework for AI Factory",
5
5
  "type": "module",
6
6
  "license": "MIT",