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.
- package/commands/gcf.js +114 -57
- package/extension.json +1 -1
- package/hooks/pre-commit.js +2 -0
- package/lib/agent-permissions.js +6 -3
- package/lib/audit-core.js +28 -18
- package/lib/board.js +1 -1
- package/lib/changes.js +1 -0
- package/lib/commit-files.js +2 -1
- package/lib/commit-move.js +114 -0
- package/lib/config-doc.js +22 -0
- package/lib/config-set.js +34 -39
- package/lib/design-check.js +8 -3
- package/lib/design-parts.js +111 -80
- package/lib/devices.js +3 -8
- package/lib/edits.js +7 -3
- package/lib/frozen.js +24 -0
- package/lib/gate.js +1 -1
- package/lib/gcf-paths.js +13 -10
- package/lib/git.js +18 -4
- package/lib/handoff.js +1 -1
- package/lib/history.js +1 -1
- package/lib/inbox-categories.js +32 -39
- package/lib/inbox.js +46 -34
- package/lib/integrate.js +3 -12
- package/lib/ledger.js +1 -1
- package/lib/lessons.js +4 -1
- package/lib/metrics.js +1 -0
- package/lib/migrate.js +1 -1
- package/lib/milestone-state.js +1 -1
- package/lib/phase.js +1 -1
- package/lib/pillars.js +1 -1
- package/lib/play.js +31 -5
- package/lib/playtest-list.js +1 -1
- package/lib/push.js +2 -1
- package/lib/questions.js +1 -1
- package/lib/session-mark.js +21 -2
- package/lib/shelf.js +1 -0
- package/lib/systems-doc.js +27 -17
- package/lib/unit-ops.js +31 -109
- package/lib/verdict-fs.js +2 -1
- package/lib/verify-stamp.js +6 -1
- package/lib/verify.js +6 -2
- package/lib/work-ops.js +117 -83
- package/package.json +1 -1
- package/templates/agents-block.md +1 -0
package/lib/config-set.js
CHANGED
|
@@ -11,7 +11,7 @@ import { spawnSync } from 'node:child_process';
|
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import { isDeepStrictEqual } from 'node:util';
|
|
13
13
|
import YAML from 'yaml';
|
|
14
|
-
import { commitMove } from './
|
|
14
|
+
import { commitMove } from './commit-move.js';
|
|
15
15
|
import { withMainLock } from './main-lock.js';
|
|
16
16
|
import { atomicWrite } from './safe-path.js';
|
|
17
17
|
import {
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from './gcf-paths.js';
|
|
28
28
|
import { AIF_CONFIG, LANGUAGE_RE, languageIn, readAifConfig } from './aif-config.js';
|
|
29
29
|
import { agentOf } from './agent-permissions.js';
|
|
30
|
+
import { configDoc, ensureMap } from './config-doc.js';
|
|
30
31
|
|
|
31
32
|
/** @typedef {'number' | 'share' | 'mode' | 'command' | 'language' | 'word' | 'list'} Kind */
|
|
32
33
|
|
|
@@ -36,26 +37,6 @@ const NO_CHANGE = new Error('no change');
|
|
|
36
37
|
// The languages AI Factory's own setup offers; any other name or code is taken too.
|
|
37
38
|
const LANGUAGES = ['en', 'ru', 'de', 'fr', 'es', 'zh', 'ja', 'ko', 'pt', 'it'];
|
|
38
39
|
|
|
39
|
-
/** A YAML file as a document with a map on top: an edit keeps its comments. */
|
|
40
|
-
export function configDoc(text, name = 'gcf/config.yml') {
|
|
41
|
-
const doc = YAML.parseDocument(text);
|
|
42
|
-
if (doc.errors.length) throw new Error(`${name}: ${doc.errors[0].message}`);
|
|
43
|
-
// A file of a list or a word on top is not a settings file: replacing it would lose it.
|
|
44
|
-
if (doc.contents != null && !YAML.isMap(doc.contents) && doc.contents.toJSON() != null)
|
|
45
|
-
throw new Error(`${name} must map its keys`);
|
|
46
|
-
if (!YAML.isMap(doc.contents)) doc.contents = /** @type {any} */ (doc.createNode({}));
|
|
47
|
-
|
|
48
|
-
return doc;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Make `keys` a map. A blank key (`dod:` with nothing or only comments under it) is none yet. */
|
|
52
|
-
export function ensureMap(doc, keys, error) {
|
|
53
|
-
const node = doc.getIn(keys, true);
|
|
54
|
-
if (YAML.isMap(node)) return;
|
|
55
|
-
if (node != null && !(YAML.isScalar(node) && node.value == null)) throw new Error(error);
|
|
56
|
-
doc.setIn(keys, doc.createNode({}));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
40
|
/**
|
|
60
41
|
* `presets`: a word whose suggestions are the agent's own (`presets` of the board read), not the
|
|
61
42
|
* framework's.
|
|
@@ -342,28 +323,38 @@ function valueOf(setting, text) {
|
|
|
342
323
|
|
|
343
324
|
if (setting.kind === 'list') return linesOf(t);
|
|
344
325
|
|
|
345
|
-
if (setting.kind === 'command')
|
|
346
|
-
if (!t) throw new Error(`${setting.key}: name the command, or none`);
|
|
326
|
+
if (setting.kind === 'command') return commandOf(setting, t);
|
|
347
327
|
|
|
348
|
-
|
|
349
|
-
}
|
|
328
|
+
if (setting.kind === 'word') return wordOf(setting, t);
|
|
350
329
|
|
|
351
|
-
|
|
352
|
-
if (setting.kind === 'word') {
|
|
353
|
-
if (!t || t.toLowerCase() === 'default') return null;
|
|
354
|
-
if (!RUN_WORD.test(t))
|
|
355
|
-
throw new Error(`${setting.key} must be one plain word (letters, digits, . - _), e.g. opus`);
|
|
330
|
+
if (setting.kind === 'mode') return modeOf(setting, t);
|
|
356
331
|
|
|
357
|
-
|
|
358
|
-
|
|
332
|
+
return numberOf(setting, t);
|
|
333
|
+
}
|
|
359
334
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (!options.includes(t)) throw new Error(`${setting.key} must be ${options.join(' | ')}`);
|
|
335
|
+
function commandOf(setting, t) {
|
|
336
|
+
if (!t) throw new Error(`${setting.key}: name the command, or none`);
|
|
363
337
|
|
|
364
|
-
|
|
365
|
-
|
|
338
|
+
return t;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// `default`, as an item's, leaves the choice to the agent.
|
|
342
|
+
function wordOf(setting, t) {
|
|
343
|
+
if (!t || t.toLowerCase() === 'default') return null;
|
|
344
|
+
if (!RUN_WORD.test(t))
|
|
345
|
+
throw new Error(`${setting.key} must be one plain word (letters, digits, . - _), e.g. opus`);
|
|
346
|
+
|
|
347
|
+
return t;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function modeOf(setting, t) {
|
|
351
|
+
const options = setting.options ?? [];
|
|
352
|
+
if (!options.includes(t)) throw new Error(`${setting.key} must be ${options.join(' | ')}`);
|
|
353
|
+
|
|
354
|
+
return t;
|
|
355
|
+
}
|
|
366
356
|
|
|
357
|
+
function numberOf(setting, t) {
|
|
367
358
|
if (!t) return null;
|
|
368
359
|
// Plain decimals only: Number() would also take 0x10, 1e3 and 0b1.
|
|
369
360
|
if (!/^\d+(\.\d+)?$/.test(t)) throw new Error(`${setting.key} must be a number, got ${t}`);
|
|
@@ -375,10 +366,14 @@ function valueOf(setting, text) {
|
|
|
375
366
|
|
|
376
367
|
/** Whether git ignores `file`: a commit cannot carry it, and a worktree does not have it. */
|
|
377
368
|
const ignoredByGit = (projectDir, file) =>
|
|
378
|
-
spawnSync('git', ['check-ignore', '-q', '--', file], { cwd: projectDir })
|
|
369
|
+
spawnSync('git', ['check-ignore', '-q', '--', file], { windowsHide: true, cwd: projectDir })
|
|
370
|
+
.status === 0;
|
|
379
371
|
|
|
380
372
|
const trackedByGit = (projectDir, file) =>
|
|
381
|
-
spawnSync('git', ['ls-files', '--error-unmatch', '--', file], {
|
|
373
|
+
spawnSync('git', ['ls-files', '--error-unmatch', '--', file], {
|
|
374
|
+
windowsHide: true,
|
|
375
|
+
cwd: projectDir,
|
|
376
|
+
}).status === 0;
|
|
382
377
|
|
|
383
378
|
/**
|
|
384
379
|
* Set one key of gcf/config.yml, or the language of `.ai-factory/config.yaml`, and commit
|
package/lib/design-check.js
CHANGED
|
@@ -517,6 +517,13 @@ function preambleIssues(design) {
|
|
|
517
517
|
}));
|
|
518
518
|
}
|
|
519
519
|
|
|
520
|
+
function parentKnown(id, ledger) {
|
|
521
|
+
// A parent that already ended is fine: a parked bug may outlive its feature.
|
|
522
|
+
const parent = ledger.item(id);
|
|
523
|
+
|
|
524
|
+
return parent ? parent.data.type === 'feature' : ledger.known(id);
|
|
525
|
+
}
|
|
526
|
+
|
|
520
527
|
/** M2 over a work item's references: depends, parent, children, reopens, milestone. */
|
|
521
528
|
function itemRefIssues(item, ctx, ledger, add) {
|
|
522
529
|
const d = item.data;
|
|
@@ -526,9 +533,7 @@ function itemRefIssues(item, ctx, ledger, add) {
|
|
|
526
533
|
add('M2', 1, `milestone ${d.milestone} is not a milestone of game.md`, 'report');
|
|
527
534
|
const unknown = (d.depends ?? []).filter((x) => x === d.id || !ledger.known(x));
|
|
528
535
|
if (unknown.length) add('M2', 1, `depends on unknown ${unknown.join(', ')}`);
|
|
529
|
-
|
|
530
|
-
const parent = d.parent ? ledger.item(d.parent) : null;
|
|
531
|
-
if (d.parent && !(parent ? parent.data.type === 'feature' : ledger.known(d.parent)))
|
|
536
|
+
if (d.parent && !parentKnown(d.parent, ledger))
|
|
532
537
|
add('M2', 1, `parent ${d.parent} is neither a feature item nor an ended id`);
|
|
533
538
|
const lost = (d.children ?? []).filter((c) => !ledger.known(c));
|
|
534
539
|
if (lost.length) add('M2', 1, `children unknown: ${lost.join(', ')}`);
|
package/lib/design-parts.js
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
recordsIn,
|
|
39
39
|
uncovered,
|
|
40
40
|
} from './design-check.js';
|
|
41
|
-
import { commitMove } from './
|
|
41
|
+
import { commitMove } from './commit-move.js';
|
|
42
42
|
import { locked } from './main-lock.js';
|
|
43
43
|
import { buildLedger } from './ledger.js';
|
|
44
44
|
import { deriveId } from './id.js';
|
|
@@ -406,83 +406,89 @@ async function newUnitId(projectDir, kind, title, type) {
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
/**
|
|
409
|
-
*
|
|
410
|
-
* @
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
409
|
+
* saveUnlocked's options with their defaults.
|
|
410
|
+
* @typedef {{fields?: Record<string, any> | null, text?: string | null, base?: string | null,
|
|
411
|
+
* system?: string | null, type?: string | null, title?: string | null,
|
|
412
|
+
* commit?: boolean}} SaveOpts
|
|
413
|
+
* @type {(opts: SaveOpts) => Required<SaveOpts>}
|
|
414
414
|
*/
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
},
|
|
428
|
-
) {
|
|
429
|
-
if ((fields === null) === (text === null))
|
|
430
|
-
throw new Error('give the part once: its fields or its text');
|
|
431
|
-
const name = given || (await newUnitId(projectDir, kind, title, type));
|
|
432
|
-
let part = await designPart(projectDir, kind, name, { type });
|
|
433
|
-
if (part.exists && !base)
|
|
434
|
-
throw new Error(
|
|
435
|
-
`${kind} ${name} exists: pass --base from gcf design part, so an edit made since is ` +
|
|
436
|
-
`not overwritten`,
|
|
437
|
-
);
|
|
415
|
+
const saveOpts = ({
|
|
416
|
+
fields = null,
|
|
417
|
+
text = null,
|
|
418
|
+
base = null,
|
|
419
|
+
system = null,
|
|
420
|
+
type = null,
|
|
421
|
+
title = null,
|
|
422
|
+
commit = true,
|
|
423
|
+
}) => ({ fields, text, base, system, type, title, commit });
|
|
424
|
+
|
|
425
|
+
/** The subsystem a part goes into; a new unit must name one. */
|
|
426
|
+
function ownerOf(kind, part, system) {
|
|
438
427
|
const owner = part.system ?? system;
|
|
439
428
|
if (kind === 'unit' && !part.exists && !SLUG_RE.test(String(owner ?? '')))
|
|
440
429
|
throw new Error('a new unit needs --system: the subsystem file it goes into');
|
|
441
|
-
|
|
430
|
+
|
|
431
|
+
return owner;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The pillars doc's form save renames the pillars whose names changed before it saves: the
|
|
436
|
+
* part read again after, its base the new one. Any other save goes on as it was given.
|
|
437
|
+
*/
|
|
438
|
+
async function renameFirst(projectDir, kind, name, { part, base, fields, type, commit }) {
|
|
442
439
|
const pillars = kind === 'doc' && name === 'pillars' && Array.isArray(fields?.pillars);
|
|
443
440
|
const { records, renames } = pillars ? pillarIds(part, fields.pillars) : {};
|
|
444
|
-
|
|
441
|
+
const edits = pillars ? { ...fields, pillars: records } : fields;
|
|
442
|
+
if (!renames?.length) return { part, base, edits, hash: null, renames };
|
|
443
|
+
// The rename goes first, on the part the operator read: changed since, nothing moves.
|
|
444
|
+
if (part.base !== base)
|
|
445
|
+
throw new Error(`conflict doc:pillars: ${noteOf({ outcome: 'conflict' })}`);
|
|
446
|
+
if (commit) await refuseLooseForRename(projectDir, renames);
|
|
447
|
+
/** @type {string | null} */
|
|
445
448
|
let hash = null;
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
edits
|
|
449
|
+
for (const [from, to] of renames)
|
|
450
|
+
hash = (await renamePillar(projectDir, from, to, { commit })).hash;
|
|
451
|
+
const moved = new Map(renames);
|
|
452
|
+
const read = await designPart(projectDir, kind, name, { type });
|
|
453
|
+
|
|
454
|
+
return {
|
|
455
|
+
part: read,
|
|
456
|
+
base: read.base,
|
|
457
|
+
edits: {
|
|
455
458
|
...edits,
|
|
456
459
|
pillars: records.map((p) => (moved.has(p?.id) ? { ...p, id: moved.get(p.id) } : p)),
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
let next = text === null ? null : lf(text).trim();
|
|
463
|
-
if (next === null) {
|
|
464
|
-
const start = part.exists
|
|
465
|
-
? part.text
|
|
466
|
-
: kind === 'unit'
|
|
467
|
-
? skeleton(specs, { id: name, type: part.type, system: owner, title })
|
|
468
|
-
: '';
|
|
469
|
-
let lines = start ? start.split('\n') : [];
|
|
470
|
-
// `fields` is given when `text` is not (checked above).
|
|
471
|
-
for (const [key, value] of Object.entries(/** @type {Record<string, any>} */ (edits))) {
|
|
472
|
-
const spec = specs.find((s) => s.key === key);
|
|
473
|
-
if (!spec) throw new Error(`${key} is not a field of ${kind} ${name}`);
|
|
474
|
-
const field = part.fields.find((f) => f.key === key);
|
|
475
|
-
if (part.exists && field && !field.exact)
|
|
476
|
-
throw new Error(`${key} holds text a form cannot keep: edit the part as text`);
|
|
477
|
-
lines = putBlock(lines, specs, spec, renderField(spec, value));
|
|
478
|
-
}
|
|
460
|
+
},
|
|
461
|
+
hash,
|
|
462
|
+
renames,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
479
465
|
|
|
480
|
-
|
|
466
|
+
/** The part's text with the form's fields put in: over what it holds, a new unit's skeleton. */
|
|
467
|
+
function formText(kind, name, part, { specs, owner, title, edits }) {
|
|
468
|
+
const start = part.exists
|
|
469
|
+
? part.text
|
|
470
|
+
: kind === 'unit'
|
|
471
|
+
? skeleton(specs, { id: name, type: part.type, system: owner, title })
|
|
472
|
+
: '';
|
|
473
|
+
let lines = start ? start.split('\n') : [];
|
|
474
|
+
// `fields` is given when `text` is not (checked above).
|
|
475
|
+
for (const [key, value] of Object.entries(/** @type {Record<string, any>} */ (edits))) {
|
|
476
|
+
const spec = specs.find((s) => s.key === key);
|
|
477
|
+
if (!spec) throw new Error(`${key} is not a field of ${kind} ${name}`);
|
|
478
|
+
const field = part.fields.find((f) => f.key === key);
|
|
479
|
+
if (part.exists && field && !field.exact)
|
|
480
|
+
throw new Error(`${key} holds text a form cannot keep: edit the part as text`);
|
|
481
|
+
lines = putBlock(lines, specs, spec, { rendered: renderField(spec, value) });
|
|
481
482
|
}
|
|
482
483
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
484
|
+
return lines.join('\n').trim();
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** The part's new text through the import, under its marker line; nothing when it is the same. */
|
|
488
|
+
async function savePart(projectDir, kind, name, { part, base, owner, next, commit }) {
|
|
489
|
+
const text =
|
|
490
|
+
kind === 'unit' ? await withManualAnswers(next, changedKeys(part.text, next), part.type) : next;
|
|
491
|
+
if (part.exists && hashOf(text) === part.base) return null;
|
|
486
492
|
// The base goes into the marker line: anything but a hash would break the bundle's shape.
|
|
487
493
|
if (part.exists && !/^[0-9a-f]{8}$/.test(/** @type {string} */ (base)))
|
|
488
494
|
throw new Error(`--base is the 8-hex hash gcf design part gave: ${base}`);
|
|
@@ -491,18 +497,41 @@ async function saveUnlocked(
|
|
|
491
497
|
...(kind === 'unit' ? [`system=${owner}`] : []),
|
|
492
498
|
...(part.exists ? [`base=${base}`] : []),
|
|
493
499
|
].join(' ');
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
500
|
+
|
|
501
|
+
return bundleMove(projectDir, `gcf(design): ${kind} ${name}`, `${marker} -->\n${text}\n`, {
|
|
502
|
+
key: 'design-save',
|
|
503
|
+
items: kind === 'unit' ? [name] : [],
|
|
504
|
+
strict: true,
|
|
505
|
+
draft: true,
|
|
506
|
+
commit,
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @param {string} projectDir
|
|
512
|
+
* @param {string} kind
|
|
513
|
+
* @param {string | null | undefined} given
|
|
514
|
+
* @param {SaveOpts} opts
|
|
515
|
+
*/
|
|
516
|
+
async function saveUnlocked(projectDir, kind, given, opts) {
|
|
517
|
+
const { fields, text, base, system, type, title, commit } = saveOpts(opts);
|
|
518
|
+
if ((fields === null) === (text === null))
|
|
519
|
+
throw new Error('give the part once: its fields or its text');
|
|
520
|
+
const name = given || (await newUnitId(projectDir, kind, title, type));
|
|
521
|
+
const read = await designPart(projectDir, kind, name, { type });
|
|
522
|
+
if (read.exists && !base)
|
|
523
|
+
throw new Error(
|
|
524
|
+
`${kind} ${name} exists: pass --base from gcf design part, so an edit made since is ` +
|
|
525
|
+
`not overwritten`,
|
|
526
|
+
);
|
|
527
|
+
const owner = ownerOf(kind, read, system);
|
|
528
|
+
const specs = await specsOf(kind, name, read.type);
|
|
529
|
+
const now = await renameFirst(projectDir, kind, name, { part: read, base, fields, type, commit });
|
|
530
|
+
const { part, edits, hash, renames } = now;
|
|
531
|
+
const next =
|
|
532
|
+
text === null ? formText(kind, name, part, { specs, owner, title, edits }) : lf(text).trim();
|
|
533
|
+
const r = await savePart(projectDir, kind, name, { part, base: now.base, owner, next, commit });
|
|
534
|
+
if (!r) return { applied: [], hash: null };
|
|
506
535
|
|
|
507
536
|
return { id: name, applied: r.applied, hash: r.hash ?? hash, renamed: renames ?? [] };
|
|
508
537
|
}
|
|
@@ -534,7 +563,8 @@ class NothingApplied extends Error {}
|
|
|
534
563
|
* @param {string} projectDir
|
|
535
564
|
* @param {string} message
|
|
536
565
|
* @param {string} text
|
|
537
|
-
* @param {{key: string, items?: string[], strict?: boolean, draft?: boolean,
|
|
566
|
+
* @param {{key: string, items?: string[], strict?: boolean, draft?: boolean,
|
|
567
|
+
* commit?: boolean}} opts
|
|
538
568
|
*/
|
|
539
569
|
async function bundleMove(
|
|
540
570
|
projectDir,
|
|
@@ -609,11 +639,12 @@ export function unrecordedDesign(projectDir, { renamed = false } = {}) {
|
|
|
609
639
|
const res = spawnSync(
|
|
610
640
|
'git',
|
|
611
641
|
['status', '--porcelain', '-z', '--untracked-files=all', '--', ...DESIGN_PATHS],
|
|
612
|
-
{ cwd: projectDir, encoding: 'utf8' },
|
|
642
|
+
{ windowsHide: true, cwd: projectDir, encoding: 'utf8' },
|
|
613
643
|
);
|
|
614
644
|
if (res.status !== 0) return [];
|
|
615
645
|
// git prints paths from the repository's root: a project in a subfolder strips its prefix.
|
|
616
646
|
const prefix = spawnSync('git', ['rev-parse', '--show-prefix'], {
|
|
647
|
+
windowsHide: true,
|
|
617
648
|
cwd: projectDir,
|
|
618
649
|
encoding: 'utf8',
|
|
619
650
|
}).stdout.trim();
|
package/lib/devices.js
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
// would hold an inherited pipe open on Windows.
|
|
6
6
|
import { mkdir, open, readFile } from 'node:fs/promises';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import { readConfig } from './gcf-paths.js';
|
|
9
|
-
import { NOT_SET_UP, playOf } from './play.js';
|
|
10
8
|
import { runCommand } from './verify.js';
|
|
11
9
|
|
|
12
10
|
const DEVICES_MS = 30000;
|
|
@@ -82,16 +80,13 @@ function deviceOf(v, rows) {
|
|
|
82
80
|
const tailOf = (text) => text.trimEnd().split(/\r?\n/).slice(-20).join('\n');
|
|
83
81
|
|
|
84
82
|
/**
|
|
85
|
-
*
|
|
86
|
-
* of `plays_on` it fits, or why not.
|
|
83
|
+
* What target `targetName` of the project's `play` (playOf) finds with its script, each device
|
|
84
|
+
* placed under a row of `plays_on` it fits, or why not. `devicesOf` of play.js reads the config.
|
|
87
85
|
* @returns {Promise<{target: string, rows: object[], devices: Array<Record<string, any>>,
|
|
88
86
|
* unavailable?: string,
|
|
89
87
|
* problem?: string, tail?: string}>}
|
|
90
88
|
*/
|
|
91
|
-
export async function
|
|
92
|
-
const dir = path.resolve(projectDir);
|
|
93
|
-
const play = playOf(await readConfig(path.join(dir, 'gcf')));
|
|
94
|
-
if (!play) throw new Error(NOT_SET_UP);
|
|
89
|
+
export async function targetDevices(dir, play, targetName, { ms = DEVICES_MS } = {}) {
|
|
95
90
|
const t = Object.hasOwn(play.targets, targetName) ? play.targets[targetName] : null;
|
|
96
91
|
if (!t) throw new Error(`no target ${targetName}: ${Object.keys(play.targets).join(', ')}`);
|
|
97
92
|
const rows = play.builds[t.build].plays_on.filter((r) => serves(t, t.build, r));
|
package/lib/edits.js
CHANGED
|
@@ -7,7 +7,7 @@ import { dirtyGcf, inParts, literal, restoreFromHead } from './git.js';
|
|
|
7
7
|
import { locked } from './main-lock.js';
|
|
8
8
|
import { refusal } from './refusal.js';
|
|
9
9
|
import { newFileDiff } from './tree-file.js';
|
|
10
|
-
import { commitMove } from './
|
|
10
|
+
import { commitMove } from './commit-move.js';
|
|
11
11
|
|
|
12
12
|
/** A path from the project with `/`: the form dirtyGcf gives and a refusal names. */
|
|
13
13
|
const norm = (projectDir, p) =>
|
|
@@ -39,8 +39,11 @@ function changed(projectDir, paths, verb) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const git = (projectDir, ...args) =>
|
|
42
|
-
spawnSync('git', ['-c', 'core.quotePath=false', ...args], {
|
|
43
|
-
|
|
42
|
+
spawnSync('git', ['-c', 'core.quotePath=false', ...args], {
|
|
43
|
+
windowsHide: true,
|
|
44
|
+
cwd: projectDir,
|
|
45
|
+
encoding: 'utf8',
|
|
46
|
+
}).stdout ?? '';
|
|
44
47
|
|
|
45
48
|
/** Literal pathspecs: a `[` in a name is no glob that takes its siblings along. */
|
|
46
49
|
const lits = (projectDir, files) => files.map((f) => literal(projectDir, f));
|
|
@@ -81,6 +84,7 @@ const diffOf = (projectDir, opts, files) =>
|
|
|
81
84
|
|
|
82
85
|
const tracked = (projectDir, f) =>
|
|
83
86
|
spawnSync('git', ['ls-files', '--error-unmatch', '--', literal(projectDir, f)], {
|
|
87
|
+
windowsHide: true,
|
|
84
88
|
cwd: projectDir,
|
|
85
89
|
stdio: 'ignore',
|
|
86
90
|
}).status === 0;
|
package/lib/frozen.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The `frozen:` stamp of an unplayed item (Methodology §5.4): the hash a tune or a kill checks
|
|
2
|
+
// before it takes the item's lines back out of systems/ and LIVE.md.
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The hash an unplayed item is frozen at (Methodology §5.4): its body and its `live:` delta —
|
|
7
|
+
* the two things a tune or a kill takes back out of systems/ and LIVE.md.
|
|
8
|
+
*/
|
|
9
|
+
export const frozenHash = (item) =>
|
|
10
|
+
createHash('sha1')
|
|
11
|
+
.update(String(item.body).replace(/\r\n/g, '\n').trim())
|
|
12
|
+
.update(`\nlive: ${JSON.stringify(item.data.live ?? null)}`)
|
|
13
|
+
.digest('hex');
|
|
14
|
+
|
|
15
|
+
/** The 0.4.0 `frozen:`: the sha1 of the body alone, without the `live:` delta. */
|
|
16
|
+
export const legacyFrozen = (item) =>
|
|
17
|
+
createHash('sha1').update(String(item.body).replace(/\r\n/g, '\n').trim()).digest('hex');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Whether an unplayed item still matches its `frozen:`. An item closed by 0.4.0 holds the
|
|
21
|
+
* legacy form, which guards the body only, until `gcf init` restamps it (restampFrozen).
|
|
22
|
+
*/
|
|
23
|
+
export const matchesFrozen = (item) =>
|
|
24
|
+
item.data.frozen === frozenHash(item) || item.data.frozen === legacyFrozen(item);
|
package/lib/gate.js
CHANGED
|
@@ -9,7 +9,7 @@ import { stemMatches } from './id.js';
|
|
|
9
9
|
import { lint } from './linter.js';
|
|
10
10
|
import { buildLedger } from './ledger.js';
|
|
11
11
|
import { designCheck } from './design-check.js';
|
|
12
|
-
import { matchesFrozen } from './
|
|
12
|
+
import { matchesFrozen } from './frozen.js';
|
|
13
13
|
import { checkLive } from './live.js';
|
|
14
14
|
|
|
15
15
|
/** Problems of form: legacy cards, item frontmatter and filenames, `until` grammar. */
|
package/lib/gcf-paths.js
CHANGED
|
@@ -131,6 +131,18 @@ export async function readRawConfig(root) {
|
|
|
131
131
|
return existsSync(file) ? (YAML.parse(await readFile(file, 'utf8')) ?? {}) : {};
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
function checkLimits(config) {
|
|
135
|
+
// A limit that is not a number compares false against everything, which silently
|
|
136
|
+
// switches its gate off — the one failure a gate must not have.
|
|
137
|
+
for (const key of Object.keys(DEFAULT_CONFIG)) {
|
|
138
|
+
if (!Number.isFinite(config[key]) || config[key] < 0) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
`gcf/config.yml: ${key} must be a non-negative number, got ${JSON.stringify(config[key])}`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
134
146
|
/**
|
|
135
147
|
* The config a parsed config.yml gives, checked: defaults for what it does not set, every limit
|
|
136
148
|
* a non-negative number, the shares 0-100, the run mode one of RUN_MODES, the chat as chatOf
|
|
@@ -147,16 +159,7 @@ export function configOf(parsed) {
|
|
|
147
159
|
...DEFAULT_CONFIG,
|
|
148
160
|
...Object.fromEntries(Object.entries(parsed).filter(([, v]) => v !== null)),
|
|
149
161
|
};
|
|
150
|
-
|
|
151
|
-
// switches its gate off — the one failure a gate must not have.
|
|
152
|
-
for (const key of Object.keys(DEFAULT_CONFIG)) {
|
|
153
|
-
if (!Number.isFinite(config[key]) || config[key] < 0) {
|
|
154
|
-
throw new Error(
|
|
155
|
-
`gcf/config.yml: ${key} must be a non-negative number, got ${JSON.stringify(config[key])}`,
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
162
|
+
checkLimits(config);
|
|
160
163
|
if (config.session_timeout_min === 0)
|
|
161
164
|
throw new Error('gcf/config.yml: session_timeout_min must be above 0: a session needs a limit');
|
|
162
165
|
for (const key of PCT_KEYS)
|
package/lib/git.js
CHANGED
|
@@ -46,6 +46,7 @@ const IN_PROGRESS = [
|
|
|
46
46
|
/** The name of the merge or sequencer operation in progress, or null. */
|
|
47
47
|
export function operationInProgress(projectDir) {
|
|
48
48
|
const gitDir = spawnSync('git', ['rev-parse', '--git-dir'], {
|
|
49
|
+
windowsHide: true,
|
|
49
50
|
cwd: projectDir,
|
|
50
51
|
encoding: 'utf8',
|
|
51
52
|
});
|
|
@@ -63,6 +64,7 @@ export const literal = (projectDir, p) => `:(literal)${relOf(projectDir, p)}`;
|
|
|
63
64
|
|
|
64
65
|
const tracked = (projectDir, p) =>
|
|
65
66
|
spawnSync('git', ['ls-files', '--error-unmatch', '--', literal(projectDir, p)], {
|
|
67
|
+
windowsHide: true,
|
|
66
68
|
cwd: projectDir,
|
|
67
69
|
stdio: 'ignore',
|
|
68
70
|
}).status === 0;
|
|
@@ -70,6 +72,7 @@ const tracked = (projectDir, p) =>
|
|
|
70
72
|
/** Whether the last commit holds `p`: a file only staged is not in it. */
|
|
71
73
|
export const inHead = (projectDir, p) =>
|
|
72
74
|
spawnSync('git', ['ls-tree', '--name-only', 'HEAD', '--', p], {
|
|
75
|
+
windowsHide: true,
|
|
73
76
|
cwd: projectDir,
|
|
74
77
|
encoding: 'utf8',
|
|
75
78
|
}).stdout?.trim() !== '';
|
|
@@ -83,6 +86,7 @@ export function dirtyPaths(projectDir, paths) {
|
|
|
83
86
|
// writing that file anew would commit away every line the deleted file held.
|
|
84
87
|
if (!paths.length) return [];
|
|
85
88
|
const res = spawnSync('git', ['status', '--porcelain', '--', ...paths], {
|
|
89
|
+
windowsHide: true,
|
|
86
90
|
cwd: projectDir,
|
|
87
91
|
encoding: 'utf8',
|
|
88
92
|
});
|
|
@@ -116,11 +120,12 @@ export function dirtyGcf(projectDir, skip = []) {
|
|
|
116
120
|
const res = spawnSync(
|
|
117
121
|
'git',
|
|
118
122
|
['-c', 'core.quotePath=false', 'status', '--porcelain', '-z', '-uall', '--', ...GATE_SCOPE],
|
|
119
|
-
{ cwd: projectDir, encoding: 'utf8' },
|
|
123
|
+
{ windowsHide: true, cwd: projectDir, encoding: 'utf8' },
|
|
120
124
|
);
|
|
121
125
|
if (res.status !== 0) return [];
|
|
122
126
|
// Porcelain paths are the repository's: a project inside a bigger repository is a prefix in.
|
|
123
127
|
const prefix = spawnSync('git', ['rev-parse', '--show-prefix'], {
|
|
128
|
+
windowsHide: true,
|
|
124
129
|
cwd: projectDir,
|
|
125
130
|
encoding: 'utf8',
|
|
126
131
|
}).stdout.trim();
|
|
@@ -166,7 +171,8 @@ const relOf = (projectDir, p) =>
|
|
|
166
171
|
* @param {string[]} files
|
|
167
172
|
*/
|
|
168
173
|
export function restoreFromHead(projectDir, files) {
|
|
169
|
-
const git = (...args) =>
|
|
174
|
+
const git = (...args) =>
|
|
175
|
+
spawnSync('git', args, { windowsHide: true, cwd: projectDir, encoding: 'utf8' });
|
|
170
176
|
const must = (...args) => {
|
|
171
177
|
const r = git(...args);
|
|
172
178
|
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr.trim()}`);
|
|
@@ -272,7 +278,11 @@ function commitRefusal(message, out) {
|
|
|
272
278
|
export function commitPaths(projectDir, message, paths, move = {}) {
|
|
273
279
|
const staged = paths.filter((p) => existsSync(p) || tracked(projectDir, p));
|
|
274
280
|
for (const p of staged)
|
|
275
|
-
spawnSync('git', ['add', '--', literal(projectDir, p)], {
|
|
281
|
+
spawnSync('git', ['add', '--', literal(projectDir, p)], {
|
|
282
|
+
windowsHide: true,
|
|
283
|
+
cwd: projectDir,
|
|
284
|
+
stdio: 'ignore',
|
|
285
|
+
});
|
|
276
286
|
// A staged deletion (`git rm`) is off the disk and out of the index, but HEAD holds it: its
|
|
277
287
|
// path commits the deletion. A file staged but never committed and now deleted matches
|
|
278
288
|
// nothing: no pathspec.
|
|
@@ -302,6 +312,7 @@ export function commitOnly(projectDir, message, paths, msg) {
|
|
|
302
312
|
...(long ? ['--pathspec-from-file=-', '--pathspec-file-nul'] : ['--', ...only]),
|
|
303
313
|
],
|
|
304
314
|
{
|
|
315
|
+
windowsHide: true,
|
|
305
316
|
cwd: projectDir,
|
|
306
317
|
encoding: 'utf8',
|
|
307
318
|
...(long && { input: only.map((p) => `${p}\0`).join('') }),
|
|
@@ -322,6 +333,7 @@ export function commitOnly(projectDir, message, paths, msg) {
|
|
|
322
333
|
if (res.status !== 0) throw commitRefusal(message, out);
|
|
323
334
|
|
|
324
335
|
return spawnSync('git', ['rev-parse', 'HEAD'], {
|
|
336
|
+
windowsHide: true,
|
|
325
337
|
cwd: projectDir,
|
|
326
338
|
encoding: 'utf8',
|
|
327
339
|
}).stdout.trim();
|
|
@@ -341,6 +353,7 @@ export function snapshotIndex(cwd, files) {
|
|
|
341
353
|
let stdout = '';
|
|
342
354
|
for (const part of inParts(rels)) {
|
|
343
355
|
const res = spawnSync('git', ['ls-files', '-s', '-z', '--', ...part], {
|
|
356
|
+
windowsHide: true,
|
|
344
357
|
cwd,
|
|
345
358
|
encoding: 'utf8',
|
|
346
359
|
});
|
|
@@ -349,6 +362,7 @@ export function snapshotIndex(cwd, files) {
|
|
|
349
362
|
}
|
|
350
363
|
|
|
351
364
|
const prefix = spawnSync('git', ['rev-parse', '--show-prefix'], {
|
|
365
|
+
windowsHide: true,
|
|
352
366
|
cwd,
|
|
353
367
|
encoding: 'utf8',
|
|
354
368
|
}).stdout.trim();
|
|
@@ -385,7 +399,7 @@ export function restoreIndex(snapshot) {
|
|
|
385
399
|
`${entry.mode},${entry.blob},${snapshot.prefix}${rel}`,
|
|
386
400
|
]
|
|
387
401
|
: ['update-index', '--force-remove', '--', rel];
|
|
388
|
-
const res = spawnSync('git', args, { cwd: snapshot.cwd, encoding: 'utf8' });
|
|
402
|
+
const res = spawnSync('git', args, { windowsHide: true, cwd: snapshot.cwd, encoding: 'utf8' });
|
|
389
403
|
const reason = (res.stderr || '').trim() || res.error?.message;
|
|
390
404
|
if (res.status !== 0)
|
|
391
405
|
errors.push(new Error(`could not restore the index entry of ${rel}: ${reason}`));
|
package/lib/handoff.js
CHANGED
|
@@ -134,7 +134,7 @@ function saidOf(projectDir, id) {
|
|
|
134
134
|
const res = spawnSync(
|
|
135
135
|
'git',
|
|
136
136
|
['log', '-1', '--format=%s', '--fixed-strings', `--grep=gcf(submit): ${id}`],
|
|
137
|
-
{ cwd: projectDir, encoding: 'utf8' },
|
|
137
|
+
{ windowsHide: true, cwd: projectDir, encoding: 'utf8' },
|
|
138
138
|
);
|
|
139
139
|
const m = /\((agent: [^)]*)\)\s*$/.exec(res.stdout?.trim() ?? '');
|
|
140
140
|
|
package/lib/history.js
CHANGED
|
@@ -90,7 +90,7 @@ export function itemHistory(projectDir, id, { limit = HISTORY_MAX } = {}) {
|
|
|
90
90
|
const res = spawnSync(
|
|
91
91
|
'git',
|
|
92
92
|
['log', `--format=%h${FS}%cI${FS}%s${FS}%b${RS}`, '--fixed-strings', '--grep=gcf(', '--'],
|
|
93
|
-
{ cwd: projectDir, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 },
|
|
93
|
+
{ windowsHide: true, cwd: projectDir, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 },
|
|
94
94
|
);
|
|
95
95
|
if (res.status !== 0) return [];
|
|
96
96
|
const moves = [];
|