gcf-aif-ext 0.29.0 → 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 +7 -4
- package/lib/audit-core.js +28 -18
- package/lib/board.js +1 -1
- package/lib/build-queue.js +5 -2
- 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 +123 -74
- package/lib/devices.js +5 -9
- package/lib/edits.js +7 -3
- package/lib/frozen.js +24 -0
- package/lib/gate.js +1 -1
- package/lib/gates.js +2 -1
- package/lib/gcf-paths.js +13 -10
- package/lib/git.js +19 -5
- package/lib/handoff.js +6 -1
- package/lib/history.js +1 -1
- package/lib/inbox-categories.js +37 -35
- package/lib/inbox.js +65 -34
- package/lib/integrate.js +7 -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-notes.js +4 -0
- package/lib/play-on.js +2 -1
- package/lib/play.js +36 -9
- package/lib/playtest-list.js +1 -1
- package/lib/push.js +9 -5
- package/lib/questions.js +4 -2
- package/lib/session-mark.js +21 -2
- package/lib/shelf.js +1 -0
- package/lib/systems-doc.js +31 -20
- package/lib/unit-ops.js +31 -109
- package/lib/validate-item.js +1 -2
- 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 +126 -86
- package/package.json +1 -1
- package/templates/agents-block.md +3 -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';
|
|
@@ -219,6 +219,10 @@ async function locate(root, kind, name, type) {
|
|
|
219
219
|
* `gcf design part <kind> <name>`: one part as a form shows it. `base` is the hash a save sends
|
|
220
220
|
* back, so an edit made meanwhile is reported, not overwritten. `type` gives the fields of a
|
|
221
221
|
* unit not written yet.
|
|
222
|
+
* @param {string} projectDir
|
|
223
|
+
* @param {string} kind
|
|
224
|
+
* @param {string} name
|
|
225
|
+
* @param {{type?: string | null}} [opts]
|
|
222
226
|
*/
|
|
223
227
|
export async function designPart(projectDir, kind, name, { type = null } = {}) {
|
|
224
228
|
const root = path.join(path.resolve(projectDir), 'gcf');
|
|
@@ -340,6 +344,7 @@ function pillarIds(part, given) {
|
|
|
340
344
|
const now = part.fields.find((f) => f.key === 'pillars')?.value ?? [];
|
|
341
345
|
const before = Array.isArray(now) ? now : [];
|
|
342
346
|
const taken = new Set([...before, ...given].map((p) => p?.id).filter(Boolean));
|
|
347
|
+
/** @type {[string, string][]} */
|
|
343
348
|
const renames = [];
|
|
344
349
|
const records = given.map((p) => {
|
|
345
350
|
if (!p || typeof p !== 'object') return p;
|
|
@@ -400,96 +405,133 @@ async function newUnitId(projectDir, kind, title, type) {
|
|
|
400
405
|
return deriveId(oneLine(title), (await buildLedger(projectDir)).known, type);
|
|
401
406
|
}
|
|
402
407
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
throw new Error(
|
|
423
|
-
`${kind} ${name} exists: pass --base from gcf design part, so an edit made since is ` +
|
|
424
|
-
`not overwritten`,
|
|
425
|
-
);
|
|
408
|
+
/**
|
|
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
|
+
*/
|
|
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) {
|
|
426
427
|
const owner = part.system ?? system;
|
|
427
428
|
if (kind === 'unit' && !part.exists && !SLUG_RE.test(String(owner ?? '')))
|
|
428
429
|
throw new Error('a new unit needs --system: the subsystem file it goes into');
|
|
429
|
-
|
|
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 }) {
|
|
430
439
|
const pillars = kind === 'doc' && name === 'pillars' && Array.isArray(fields?.pillars);
|
|
431
440
|
const { records, renames } = pillars ? pillarIds(part, fields.pillars) : {};
|
|
432
|
-
|
|
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} */
|
|
433
448
|
let hash = null;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
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: {
|
|
443
458
|
...edits,
|
|
444
459
|
pillars: records.map((p) => (moved.has(p?.id) ? { ...p, id: moved.get(p.id) } : p)),
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
let next = text === null ? null : lf(text).trim();
|
|
451
|
-
if (next === null) {
|
|
452
|
-
const start = part.exists
|
|
453
|
-
? part.text
|
|
454
|
-
: kind === 'unit'
|
|
455
|
-
? skeleton(specs, { id: name, type: part.type, system: owner, title })
|
|
456
|
-
: '';
|
|
457
|
-
let lines = start ? start.split('\n') : [];
|
|
458
|
-
for (const [key, value] of Object.entries(edits)) {
|
|
459
|
-
const spec = specs.find((s) => s.key === key);
|
|
460
|
-
if (!spec) throw new Error(`${key} is not a field of ${kind} ${name}`);
|
|
461
|
-
const field = part.fields.find((f) => f.key === key);
|
|
462
|
-
if (part.exists && field && !field.exact)
|
|
463
|
-
throw new Error(`${key} holds text a form cannot keep: edit the part as text`);
|
|
464
|
-
lines = putBlock(lines, specs, spec, renderField(spec, value));
|
|
465
|
-
}
|
|
460
|
+
},
|
|
461
|
+
hash,
|
|
462
|
+
renames,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
466
465
|
|
|
467
|
-
|
|
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) });
|
|
468
482
|
}
|
|
469
483
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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;
|
|
473
492
|
// The base goes into the marker line: anything but a hash would break the bundle's shape.
|
|
474
|
-
if (part.exists && !/^[0-9a-f]{8}$/.test(base))
|
|
493
|
+
if (part.exists && !/^[0-9a-f]{8}$/.test(/** @type {string} */ (base)))
|
|
475
494
|
throw new Error(`--base is the 8-hex hash gcf design part gave: ${base}`);
|
|
476
495
|
const marker = [
|
|
477
496
|
`<!-- gcf:part ${kind} ${name}`,
|
|
478
497
|
...(kind === 'unit' ? [`system=${owner}`] : []),
|
|
479
498
|
...(part.exists ? [`base=${base}`] : []),
|
|
480
499
|
].join(' ');
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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 };
|
|
493
535
|
|
|
494
536
|
return { id: name, applied: r.applied, hash: r.hash ?? hash, renamed: renames ?? [] };
|
|
495
537
|
}
|
|
@@ -518,6 +560,11 @@ class NothingApplied extends Error {}
|
|
|
518
560
|
* Bring `text` in through the import and commit what it wrote. `strict`: a part the import
|
|
519
561
|
* reports refuses the whole move. Files with changes not recorded yet refuse it up front: the
|
|
520
562
|
* commit would carry them under the edit's name.
|
|
563
|
+
* @param {string} projectDir
|
|
564
|
+
* @param {string} message
|
|
565
|
+
* @param {string} text
|
|
566
|
+
* @param {{key: string, items?: string[], strict?: boolean, draft?: boolean,
|
|
567
|
+
* commit?: boolean}} opts
|
|
521
568
|
*/
|
|
522
569
|
async function bundleMove(
|
|
523
570
|
projectDir,
|
|
@@ -549,6 +596,7 @@ async function bundleMove(
|
|
|
549
596
|
`${loose.join(', ')} holds changes not recorded yet: record the design first (gcf ` +
|
|
550
597
|
`design commit)`,
|
|
551
598
|
);
|
|
599
|
+
/** @type {Awaited<ReturnType<typeof importBundle>>} */
|
|
552
600
|
let result = { applied: [], report: [] };
|
|
553
601
|
try {
|
|
554
602
|
const hash = await commitMove(projectDir, message, {
|
|
@@ -591,11 +639,12 @@ export function unrecordedDesign(projectDir, { renamed = false } = {}) {
|
|
|
591
639
|
const res = spawnSync(
|
|
592
640
|
'git',
|
|
593
641
|
['status', '--porcelain', '-z', '--untracked-files=all', '--', ...DESIGN_PATHS],
|
|
594
|
-
{ cwd: projectDir, encoding: 'utf8' },
|
|
642
|
+
{ windowsHide: true, cwd: projectDir, encoding: 'utf8' },
|
|
595
643
|
);
|
|
596
644
|
if (res.status !== 0) return [];
|
|
597
645
|
// git prints paths from the repository's root: a project in a subfolder strips its prefix.
|
|
598
646
|
const prefix = spawnSync('git', ['rev-parse', '--show-prefix'], {
|
|
647
|
+
windowsHide: true,
|
|
599
648
|
cwd: projectDir,
|
|
600
649
|
encoding: 'utf8',
|
|
601
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,15 +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.
|
|
87
|
-
* @returns {Promise<{target: string, rows: object[], devices:
|
|
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.
|
|
85
|
+
* @returns {Promise<{target: string, rows: object[], devices: Array<Record<string, any>>,
|
|
86
|
+
* unavailable?: string,
|
|
88
87
|
* problem?: string, tail?: string}>}
|
|
89
88
|
*/
|
|
90
|
-
export async function
|
|
91
|
-
const dir = path.resolve(projectDir);
|
|
92
|
-
const play = playOf(await readConfig(path.join(dir, 'gcf')));
|
|
93
|
-
if (!play) throw new Error(NOT_SET_UP);
|
|
89
|
+
export async function targetDevices(dir, play, targetName, { ms = DEVICES_MS } = {}) {
|
|
94
90
|
const t = Object.hasOwn(play.targets, targetName) ? play.targets[targetName] : null;
|
|
95
91
|
if (!t) throw new Error(`no target ${targetName}: ${Object.keys(play.targets).join(', ')}`);
|
|
96
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/gates.js
CHANGED
|
@@ -12,8 +12,9 @@ const AGENT_DECIDES = ['spike', 'decision'];
|
|
|
12
12
|
/**
|
|
13
13
|
* The gates in force for `item` (its frontmatter): the project's, or every item gate on its
|
|
14
14
|
* second value (`skip_gates: true`) or on `wait` (`false`). `milestone` is the project's only.
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {Record<string, any>} config readConfig's (its `gates`)
|
|
16
16
|
* @param {Record<string, any> | null} [item]
|
|
17
|
+
* @returns {Record<string, string>}
|
|
17
18
|
*/
|
|
18
19
|
export function gatePolicy(config, item = null) {
|
|
19
20
|
const skip = item?.skip_gates;
|
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)
|