gcf-aif-ext 0.32.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -6
- package/commands/gcf.js +344 -82
- package/extension.json +1 -1
- package/injections/plan-context.md +3 -0
- package/lib/agent-permissions.js +28 -4
- package/lib/audit-core.js +72 -127
- package/lib/board.js +22 -10
- package/lib/changes.js +7 -1
- package/lib/commit-files.js +1 -0
- package/lib/commit-move.js +56 -10
- package/lib/config-set.js +52 -14
- package/lib/context.js +29 -16
- package/lib/d2-states.js +208 -0
- package/lib/design-parts.js +37 -7
- package/lib/domain.js +144 -11
- package/lib/gcf-paths.js +13 -2
- package/lib/git.js +62 -17
- package/lib/inbox-categories.js +3 -0
- package/lib/inbox.js +69 -4
- package/lib/lessons.js +133 -4
- package/lib/main-lock.js +195 -3
- package/lib/plan-check.js +339 -37
- package/lib/play.js +21 -20
- package/lib/review.js +111 -2
- package/lib/rules.js +428 -0
- package/lib/session-mark.js +2 -1
- package/lib/systems-doc.js +60 -13
- package/lib/validate-item.js +9 -0
- package/lib/work-ops.js +109 -50
- package/package.json +1 -1
- package/profiles/plan.md +1 -1
- package/schemas/item.schema.json +4 -0
- package/skills/gcf-audit/SKILL.md +10 -5
- package/skills/gcf-card/SKILL.md +12 -10
- package/skills/gcf-chat/SKILL.md +14 -10
- package/skills/gcf-triage/SKILL.md +19 -1
- package/skills/gcf-verdict/SKILL.md +7 -5
- package/templates/agents-block.md +23 -2
- package/templates/config.yml +10 -6
package/lib/config-set.js
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
REVIEW_DEFAULTS,
|
|
26
26
|
reviewRowProblem,
|
|
27
27
|
RUN_MODES,
|
|
28
|
+
RUN_PHASES,
|
|
28
29
|
RUN_WORD,
|
|
29
30
|
} from './gcf-paths.js';
|
|
30
31
|
import { AIF_CONFIG, LANGUAGE_RE, languageIn, readAifConfig } from './aif-config.js';
|
|
@@ -100,8 +101,9 @@ export const SETTINGS = [
|
|
|
100
101
|
key: 'review.plan',
|
|
101
102
|
kind: 'passes',
|
|
102
103
|
label:
|
|
103
|
-
'the passes of a plan review, row k makes pass k: the
|
|
104
|
-
'
|
|
104
|
+
'the passes of a plan review, row k makes pass k: the first reviews the whole plan, the ' +
|
|
105
|
+
"rest check the author's fixes; the next goes only while the last found something " +
|
|
106
|
+
'blocking; the rows over, the card blocks for you (none: no review)',
|
|
105
107
|
},
|
|
106
108
|
{
|
|
107
109
|
key: 'review.code',
|
|
@@ -294,7 +296,33 @@ for (const s of SETTINGS) {
|
|
|
294
296
|
if (EXAMPLE[s.key]) Object.assign(s, { example: EXAMPLE[s.key] });
|
|
295
297
|
}
|
|
296
298
|
|
|
297
|
-
|
|
299
|
+
/**
|
|
300
|
+
* A phase's own model and effort (Plan-Review-Rework-Plan d10), set by `gcf config set` but no
|
|
301
|
+
* row of a settings screen yet: the screen's phase pair shows what a phase inherits and tells a
|
|
302
|
+
* pick from a reset (t4). GCF's own defaults are `PHASE_DEFAULTS`, under `agent.model|effort`.
|
|
303
|
+
* @type {typeof SETTINGS}
|
|
304
|
+
*/
|
|
305
|
+
const PHASE_SETTINGS = RUN_PHASES.flatMap((phase) =>
|
|
306
|
+
['model', 'effort'].map((k) => ({
|
|
307
|
+
key: `agent.${phase}.${k}`,
|
|
308
|
+
kind: /** @type {Kind} */ ('word'),
|
|
309
|
+
label: `the ${k} of the ${phase} phase of a run, over agent.${k}`,
|
|
310
|
+
})),
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* The phase keys the project sets, each with its value: `gcf config` lists them (d10).
|
|
315
|
+
* @public gcf.js imports lib modules by name at run time, out of knip's sight.
|
|
316
|
+
*/
|
|
317
|
+
export const phaseValues = (raw) =>
|
|
318
|
+
PHASE_SETTINGS.flatMap((s) => {
|
|
319
|
+
const [, phase, k] = s.key.split('.');
|
|
320
|
+
const v = raw?.agent?.[phase]?.[k];
|
|
321
|
+
|
|
322
|
+
return v === null || v === undefined ? [] : [{ ...s, value: v }];
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const BY_KEY = new Map([...SETTINGS, ...PHASE_SETTINGS].map((s) => [s.key, s]));
|
|
298
326
|
|
|
299
327
|
// What a settings screen groups the keys under, in its order.
|
|
300
328
|
/** @type {[string, string[]][]} */
|
|
@@ -466,6 +494,17 @@ function numberOf(setting, t) {
|
|
|
466
494
|
return n;
|
|
467
495
|
}
|
|
468
496
|
|
|
497
|
+
/**
|
|
498
|
+
* Write one key of two or three levels (`agent.plan.effort`), each level above it a map; null
|
|
499
|
+
* takes it off.
|
|
500
|
+
*/
|
|
501
|
+
function setKey(doc, keys, value, name) {
|
|
502
|
+
for (let n = 1; n < keys.length; n++)
|
|
503
|
+
ensureMap(doc, keys.slice(0, n), `${name}: ${keys.slice(0, n).join('.')} must map its keys`);
|
|
504
|
+
if (value === null) doc.deleteIn(keys);
|
|
505
|
+
else doc.setIn(keys, value);
|
|
506
|
+
}
|
|
507
|
+
|
|
469
508
|
/** `review.*` set: the keys it replaces go with it, in the same commit (t2 d1). */
|
|
470
509
|
function dropOldReview(doc, keys) {
|
|
471
510
|
if (keys[0] !== 'review') return;
|
|
@@ -491,7 +530,7 @@ const trackedByGit = (projectDir, file) =>
|
|
|
491
530
|
*/
|
|
492
531
|
export async function setConfig(projectDir, key, text, { commit = true } = {}) {
|
|
493
532
|
const setting = BY_KEY.get(key);
|
|
494
|
-
if (!setting) throw new Error(`no setting ${key}: ${
|
|
533
|
+
if (!setting) throw new Error(`no setting ${key}: ${[...BY_KEY.keys()].join(' | ')}`);
|
|
495
534
|
const value = valueOf(setting, text);
|
|
496
535
|
const name = setting.file ?? 'gcf/config.yml';
|
|
497
536
|
const file = setting.file
|
|
@@ -515,14 +554,12 @@ export async function setConfig(projectDir, key, text, { commit = true } = {}) {
|
|
|
515
554
|
const text = existsSync(file) ? await readFile(file, 'utf8') : '';
|
|
516
555
|
const doc = configDoc(text, name);
|
|
517
556
|
// A reset of a key whose parent is not there changes nothing: no empty map is written.
|
|
518
|
-
if (value === null && keys.length > 1 && !YAML.isMap(doc.getIn(
|
|
557
|
+
if (value === null && keys.length > 1 && !YAML.isMap(doc.getIn(keys.slice(0, -1), true))) {
|
|
519
558
|
unchanged = true;
|
|
520
559
|
throw NO_CHANGE;
|
|
521
560
|
}
|
|
522
561
|
|
|
523
|
-
|
|
524
|
-
if (value === null) doc.deleteIn(keys);
|
|
525
|
-
else doc.setIn(keys, value);
|
|
562
|
+
setKey(doc, keys, value, name);
|
|
526
563
|
dropOldReview(doc, keys);
|
|
527
564
|
const raw = doc.toJS();
|
|
528
565
|
// `agent:` is read by its own rules: a key set here must not leave a broken section.
|
|
@@ -560,7 +597,7 @@ export async function setConfigs(projectDir, pairs, { commit = true } = {}) {
|
|
|
560
597
|
if (!pairs.length) throw new Error('name a key=value to set');
|
|
561
598
|
const changes = pairs.map(([key, text]) => {
|
|
562
599
|
const setting = BY_KEY.get(key);
|
|
563
|
-
if (!setting) throw new Error(`no setting ${key}: ${
|
|
600
|
+
if (!setting) throw new Error(`no setting ${key}: ${[...BY_KEY.keys()].join(' | ')}`);
|
|
564
601
|
if (setting.file) throw new Error(`${key} lives in ${setting.file}: set it on its own`);
|
|
565
602
|
|
|
566
603
|
return { key, keys: key.split('.'), value: valueOf(setting, text) };
|
|
@@ -572,12 +609,13 @@ export async function setConfigs(projectDir, pairs, { commit = true } = {}) {
|
|
|
572
609
|
const doc = configDoc(text, 'gcf/config.yml');
|
|
573
610
|
for (const c of changes) {
|
|
574
611
|
// A reset of a key whose parent is not there changes nothing: no empty map is written.
|
|
575
|
-
if (
|
|
612
|
+
if (
|
|
613
|
+
c.value === null &&
|
|
614
|
+
c.keys.length > 1 &&
|
|
615
|
+
!YAML.isMap(doc.getIn(c.keys.slice(0, -1), true))
|
|
616
|
+
)
|
|
576
617
|
continue;
|
|
577
|
-
|
|
578
|
-
ensureMap(doc, [c.keys[0]], `gcf/config.yml: ${c.keys[0]} must map its keys`);
|
|
579
|
-
if (c.value === null) doc.deleteIn(c.keys);
|
|
580
|
-
else doc.setIn(c.keys, c.value);
|
|
618
|
+
setKey(doc, c.keys, c.value, 'gcf/config.yml');
|
|
581
619
|
dropOldReview(doc, c.keys);
|
|
582
620
|
}
|
|
583
621
|
|
package/lib/context.js
CHANGED
|
@@ -2,7 +2,9 @@ import { mkdir, readFile, readdir } from 'node:fs/promises';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { listItems, listSystems, readConfig, tokensEst } from './gcf-paths.js';
|
|
5
|
-
import {
|
|
5
|
+
import { buildLedger } from './ledger.js';
|
|
6
|
+
import { provenanceOf } from './design.js';
|
|
7
|
+
import { d2States, verdictMatchers } from './d2-states.js';
|
|
6
8
|
import { atomicWrite } from './safe-path.js';
|
|
7
9
|
import { ownerOf } from './session-mark.js';
|
|
8
10
|
|
|
@@ -20,7 +22,7 @@ export async function writeReadset(projectDir, ctx, env = process.env) {
|
|
|
20
22
|
/**
|
|
21
23
|
* Readset assembly — the whole command is deterministic (GCF-PRD §9.1, §10.1):
|
|
22
24
|
* PILLARS + LIVE.md + touched systems + the item + its parent + its depends + graveyard tag hits +
|
|
23
|
-
* D2 assumptions whose sys overlaps. Never over_budget-throws: the caller gates.
|
|
25
|
+
* D2 assumptions whose sys overlaps or the item cites. Never over_budget-throws: the caller gates.
|
|
24
26
|
*/
|
|
25
27
|
export async function buildContext(projectDir, itemId) {
|
|
26
28
|
const root = path.join(path.resolve(projectDir), 'gcf');
|
|
@@ -34,7 +36,7 @@ export async function buildContext(projectDir, itemId) {
|
|
|
34
36
|
const itemText =
|
|
35
37
|
`${item.data.id} ${item.data.title ?? ''} ${systems.join(' ')} ${item.body}`.toLowerCase();
|
|
36
38
|
const graveyard_hits = await graveyardHits(root, itemText);
|
|
37
|
-
const d2 = await d2Assumptions(
|
|
39
|
+
const { d2, fired } = await d2Assumptions(projectDir, config, item, systems);
|
|
38
40
|
|
|
39
41
|
const extraTokens = tokensEst(graveyard_hits.join('\n')) + tokensEst(d2.join('\n'));
|
|
40
42
|
const total_tokens_est = files.reduce((sum, f) => sum + f.tokens_est, 0) + extraTokens;
|
|
@@ -44,6 +46,8 @@ export async function buildContext(projectDir, itemId) {
|
|
|
44
46
|
files,
|
|
45
47
|
graveyard_hits,
|
|
46
48
|
d2,
|
|
49
|
+
// The ids in d2 whose trigger fired with no answer: the human's call now (GCF-PRD §7.3).
|
|
50
|
+
d2_fired: fired,
|
|
47
51
|
total_tokens_est,
|
|
48
52
|
budget: config.context_budget,
|
|
49
53
|
over_budget: total_tokens_est > config.context_budget,
|
|
@@ -111,18 +115,27 @@ async function graveyardHits(root, itemText) {
|
|
|
111
115
|
return hits;
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
/**
|
|
119
|
+
* D2 assumptions whose sys: overlaps the item's systems (GCF-PRD §9.1), and the ones the item
|
|
120
|
+
* cites as `assumed: q-NNN` whatever their sys:; `fired`, the unanswered ones whose until: fired.
|
|
121
|
+
*/
|
|
122
|
+
async function d2Assumptions(projectDir, config, item, systems) {
|
|
123
|
+
const file = path.join(path.resolve(projectDir), 'gcf', 'open-questions.md');
|
|
124
|
+
const text = existsSync(file) ? await readFile(file, 'utf8') : '';
|
|
125
|
+
// The ledger reads every design doc: built only when a D2 can fire by a verdict.
|
|
126
|
+
if (!/^\s*class:\s*D2\b/m.test(text)) return { d2: [], fired: [] };
|
|
127
|
+
const ledger = /verdict\(/.test(text) ? await buildLedger(projectDir) : null;
|
|
128
|
+
const states = await d2States(projectDir, {
|
|
129
|
+
fired: verdictMatchers(projectDir, ledger, ledger?.items ?? []),
|
|
130
|
+
limit: config.question_stale_after_commits,
|
|
131
|
+
});
|
|
132
|
+
const cited = new Set(provenanceOf(item.body).map((r) => r.assumed));
|
|
133
|
+
const picked = states.filter(
|
|
134
|
+
(q) => q.d2 && (cited.has(q.id) || systems.some((s) => (q.sys ?? '').includes(s))),
|
|
135
|
+
);
|
|
124
136
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
.
|
|
137
|
+
return {
|
|
138
|
+
d2: picked.map((q) => q.text),
|
|
139
|
+
fired: picked.filter((q) => q.status === 'stale').map((q) => q.id),
|
|
140
|
+
};
|
|
128
141
|
}
|
package/lib/d2-states.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// The state and age of each record of gcf/open-questions.md, and whether an until trigger fired
|
|
2
|
+
// (GCF-PRD §7.3, §7.4): the audit, the board and the readset read them alike. It imports no
|
|
3
|
+
// work-ops.js: context.js reads it, and audit-core → work-ops → plan-check → context is a cycle.
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
import { fieldOf } from './question-fields.js';
|
|
9
|
+
|
|
10
|
+
export function git(args, cwd) {
|
|
11
|
+
// A blame of a long file overflows the 1 MiB default, and an overflow reads as a git failure.
|
|
12
|
+
const res = spawnSync('git', args, {
|
|
13
|
+
windowsHide: true,
|
|
14
|
+
cwd,
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return res.status === 0 ? res.stdout.trim() : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const UNTIL_RE =
|
|
23
|
+
/\[until:\s*(verdict\([a-z0-9-]+\)|retune\([a-z0-9-]+\)|manual\([^)]*\))\]/g;
|
|
24
|
+
const D2_UNTIL_RE = /^(verdict\([a-z0-9-]+\)|retune\([a-z0-9-]+\)|manual\([^)]*\))/;
|
|
25
|
+
// The two markers GCF writes itself (systems-doc.js purposeLines, gcf-adopt): no human's manual().
|
|
26
|
+
export const PLACEHOLDER_RE = /\[until:\s*manual\((?:purpose of|first verdict touching) [^)]+\)\]/;
|
|
27
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
28
|
+
// An uncommitted line blames to the all-zero hash: it is new, not old.
|
|
29
|
+
const isUncommitted = (hash) => /^0+$/.test(hash);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Each line of `rel` with the commit that last changed it beyond whitespace (-w: a respaced or
|
|
33
|
+
* re-ended CRLF/LF line keeps the commit that wrote it), or null for an untracked file or
|
|
34
|
+
* outside a repository.
|
|
35
|
+
*/
|
|
36
|
+
export function blameLines(projectDir, rel) {
|
|
37
|
+
const blame = git(['blame', '-w', '--porcelain', '--', rel], projectDir);
|
|
38
|
+
if (blame === null) return null;
|
|
39
|
+
const lines = [];
|
|
40
|
+
let hash = '';
|
|
41
|
+
for (const line of blame.split('\n')) {
|
|
42
|
+
const head = line.match(/^([0-9a-f]{40,64}) \d+ \d+/);
|
|
43
|
+
if (head) hash = head[1];
|
|
44
|
+
else if (line.startsWith('\t')) lines.push({ hash, text: line.slice(1).replace(/\r$/, '') });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Commits since `hash`, memoized; null when the ref no longer resolves. */
|
|
51
|
+
function commitsSince(projectDir) {
|
|
52
|
+
const ages = new Map();
|
|
53
|
+
|
|
54
|
+
return (hash) => {
|
|
55
|
+
if (!ages.has(hash)) {
|
|
56
|
+
const raw = git(['rev-list', '--count', `${hash}..HEAD`], projectDir);
|
|
57
|
+
// Number(null) is 0, "fresh" — the one answer that must never be guessed.
|
|
58
|
+
ages.set(hash, raw === null ? null : Number(raw));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return ages.get(hash);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Whether a verdict fired. `verdict(id)` reads the files, as the ledger does (GCF-PRD §5.8): a
|
|
67
|
+
* keep or kill left a history or graveyard line, a tune left the item's tune_count. `retune(sys,
|
|
68
|
+
* birth)` reads the tune verdicts' subjects after `birth`, the commit that wrote the record: a
|
|
69
|
+
* tune before it is the one the record already knows. An uncommitted record is new, so open.
|
|
70
|
+
* With no birth (no blame: no repository, an untracked file) it guesses as before: an item of
|
|
71
|
+
* the subsystem with a tune_count, or any tune in the log.
|
|
72
|
+
*/
|
|
73
|
+
export function verdictMatchers(projectDir, ledger, items) {
|
|
74
|
+
const tuned = items.filter((c) => (c.data.tune_count ?? 0) > 0);
|
|
75
|
+
const logs = new Map();
|
|
76
|
+
const verdictLog = (birth) => {
|
|
77
|
+
if (!logs.has(birth)) {
|
|
78
|
+
const range = birth ? [`${birth}..HEAD`] : [];
|
|
79
|
+
const args = ['log', '--basic-regexp', '--grep', '^gcf(verdict):', '--format=%s', ...range];
|
|
80
|
+
logs.set(birth, git(args, projectDir) ?? '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return logs.get(birth);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// `tune <id> → <sys>,<sys>` and maybe ` (played on: …)` (work-ops.js verdictItemUnlocked).
|
|
87
|
+
const tuneOf = (system) =>
|
|
88
|
+
new RegExp(`^gcf\\(verdict\\): tune .*→ (?:\\S*,)?${escapeRe(system)}(?:,| \\(|$)`, 'm');
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
verdict: (id) =>
|
|
92
|
+
ledger.where(id).terminal.some((t) => t !== 'done') || tuned.some((c) => c.data.id === id),
|
|
93
|
+
/** @param {string} system @param {string} [birth] */
|
|
94
|
+
retune: (system, birth) => {
|
|
95
|
+
if (birth) return !isUncommitted(birth) && tuneOf(system).test(verdictLog(birth));
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
tuned.some((c) => (c.data.system ?? []).includes(system)) ||
|
|
99
|
+
tuneOf(system).test(verdictLog(birth))
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A question as the board and its Design screen show it: an unanswered D2 whose trigger fired
|
|
107
|
+
* (`fired`), or of `manual(...)` or no trigger past the age limit (`aged`, `commits` its age), is
|
|
108
|
+
* the Operator's decision now (Until-Records-Plan d3). An agent writes every question record:
|
|
109
|
+
* its origin is one.
|
|
110
|
+
*/
|
|
111
|
+
export function questionRow(q, state) {
|
|
112
|
+
const fired = state?.status === 'stale';
|
|
113
|
+
const aged = Boolean(state?.d2 && state.aged);
|
|
114
|
+
const decision = /^D1\b/.test(q.class ?? '') || fired || aged;
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...q,
|
|
118
|
+
category: decision ? 'decision' : 'assumption',
|
|
119
|
+
origin: 'agent',
|
|
120
|
+
fired,
|
|
121
|
+
aged,
|
|
122
|
+
...(aged && { commits: state.commits }),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `stale` (fired), `open` or `manual`; `birth` as for retune. */
|
|
127
|
+
export function untilStatus(trigger, fired, birth) {
|
|
128
|
+
if (trigger.startsWith('verdict(')) {
|
|
129
|
+
return fired.verdict(trigger.slice(8, -1)) ? 'stale' : 'open';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (trigger.startsWith('retune(')) {
|
|
133
|
+
return fired.retune(trigger.slice(7, -1), birth) ? 'stale' : 'open';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return 'manual';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Every record of open-questions.md with its state: `trigger` a D2's until (null for a D1 or
|
|
141
|
+
* none); `status` a D2's `answered`, `stale`, `open` or `manual` (null for a D1 or no trigger);
|
|
142
|
+
* `commits` since the commit that wrote its `- id:` line (undefined with no such commit: an
|
|
143
|
+
* uncommitted record, no blame; null when that commit no longer resolves); `aged` an unanswered
|
|
144
|
+
* record the human owes past `limit` commits — a D1, or a D2 with `manual(...)` or no trigger
|
|
145
|
+
* (GCF-PRD §7.4): an acting D2 waits for its trigger, a fired one is a stale until record.
|
|
146
|
+
* shortcut: a blame, a git log and a rev-list per call, the board's included; cache by HEAD
|
|
147
|
+
* when the board's refresh feels it.
|
|
148
|
+
*/
|
|
149
|
+
export async function d2States(projectDir, { fired, limit }) {
|
|
150
|
+
const file = path.join(path.resolve(projectDir), 'gcf', 'open-questions.md');
|
|
151
|
+
if (!existsSync(file)) return [];
|
|
152
|
+
const text = noBom(await readFile(file, 'utf8')).replace(/\r\n/g, '\n');
|
|
153
|
+
const at = { fired, limit, births: birthsOf(projectDir), since: commitsSince(projectDir) };
|
|
154
|
+
|
|
155
|
+
return text.split(/\n(?=- id:)/).flatMap((rec) => {
|
|
156
|
+
const id = rec.match(/^- id:\s*(\S+)/)?.[1];
|
|
157
|
+
|
|
158
|
+
return id ? [recordState(id, rec, at)] : [];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const BOM = String.fromCharCode(0xfeff);
|
|
163
|
+
const noBom = (s) => (s.startsWith(BOM) ? s.slice(1) : s);
|
|
164
|
+
|
|
165
|
+
/** The commit that wrote each record's `- id:` line, or null without a blame. */
|
|
166
|
+
function birthsOf(projectDir) {
|
|
167
|
+
const blamed = blameLines(projectDir, 'gcf/open-questions.md');
|
|
168
|
+
if (!blamed) return null;
|
|
169
|
+
const births = new Map();
|
|
170
|
+
for (const { hash, text } of blamed) {
|
|
171
|
+
const id = noBom(text).match(/^- id:\s*(\S+)/)?.[1];
|
|
172
|
+
if (id) births.set(id, hash);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return births;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function recordState(id, rec, { fired, limit, births, since }) {
|
|
179
|
+
const d2 = /^D2\b/.test(fieldOf(rec, 'class') ?? '');
|
|
180
|
+
const answered = Boolean(fieldOf(rec, 'answer'));
|
|
181
|
+
const trigger = d2 ? triggerOf(rec) : null;
|
|
182
|
+
// No blame: no birth, retune as before; a record the blame does not show is uncommitted.
|
|
183
|
+
const birth = births ? (births.get(id) ?? '0') : undefined;
|
|
184
|
+
const status = statusOf({ d2, answered, trigger }, fired, birth);
|
|
185
|
+
const commits = birth && !isUncommitted(birth) ? since(birth) : undefined;
|
|
186
|
+
const owed = !answered && (!trigger || status === 'manual');
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
id,
|
|
190
|
+
d2,
|
|
191
|
+
trigger,
|
|
192
|
+
status,
|
|
193
|
+
commits,
|
|
194
|
+
aged: owed && isOld(commits, limit),
|
|
195
|
+
sys: fieldOf(rec, 'sys'),
|
|
196
|
+
text: rec.trim(),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const triggerOf = (rec) => fieldOf(rec, 'until')?.match(D2_UNTIL_RE)?.[1] ?? null;
|
|
201
|
+
// No commit to age from is fresh; a commit that no longer resolves is never guessed fresh.
|
|
202
|
+
const isOld = (commits, limit) => commits !== undefined && (commits === null || commits > limit);
|
|
203
|
+
|
|
204
|
+
function statusOf({ d2, answered, trigger }, fired, birth) {
|
|
205
|
+
if (d2 && answered) return 'answered';
|
|
206
|
+
|
|
207
|
+
return trigger ? untilStatus(trigger, fired, birth) : null;
|
|
208
|
+
}
|
package/lib/design-parts.js
CHANGED
|
@@ -44,7 +44,7 @@ import { buildLedger } from './ledger.js';
|
|
|
44
44
|
import { deriveId } from './id.js';
|
|
45
45
|
import { renamePillar } from './pillars.js';
|
|
46
46
|
import { dirtyPaths, restoreFromHead } from './git.js';
|
|
47
|
-
import { blocksOf, putBlock } from './systems-doc.js';
|
|
47
|
+
import { blocksOf, fillPurpose, purposeTarget, putBlock } from './systems-doc.js';
|
|
48
48
|
|
|
49
49
|
// The work stage writes these blocks: a unit in design/ has not reached them.
|
|
50
50
|
const WORK_ONLY = ['contract', 'interactions', 'tuning', 'notes'];
|
|
@@ -556,6 +556,27 @@ const noteOf = (p) =>
|
|
|
556
556
|
// Nothing of the bundle applied: no commit to make.
|
|
557
557
|
class NothingApplied extends Error {}
|
|
558
558
|
|
|
559
|
+
/**
|
|
560
|
+
* The subsystems of the design/<s>.md among `files` whose systems doc still waits on its purpose
|
|
561
|
+
* and gets it from this move (fillPurpose), each with that doc. `parts`: a bundle's, whose system
|
|
562
|
+
* part is the purpose the move is about to write.
|
|
563
|
+
* @param {string} root
|
|
564
|
+
* @param {string[]} files
|
|
565
|
+
* @param {{kind: string, name: string, text: string}[]} [parts]
|
|
566
|
+
*/
|
|
567
|
+
async function purposeFills(root, files, parts = []) {
|
|
568
|
+
const fills = new Map();
|
|
569
|
+
for (const f of files) {
|
|
570
|
+
const s = path.basename(f, '.md');
|
|
571
|
+
if (path.dirname(f) !== path.join(root, 'design') || !SLUG_RE.test(s) || fills.has(s)) continue;
|
|
572
|
+
const part = parts.find((p) => p.kind === 'system' && p.name === s);
|
|
573
|
+
const doc = await purposeTarget(root, s, part?.text);
|
|
574
|
+
if (doc) fills.set(s, doc);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return fills;
|
|
578
|
+
}
|
|
579
|
+
|
|
559
580
|
/**
|
|
560
581
|
* Bring `text` in through the import and commit what it wrote. `strict`: a part the import
|
|
561
582
|
* reports refuses the whole move. Files with changes not recorded yet refuse it up front: the
|
|
@@ -573,8 +594,9 @@ async function bundleMove(
|
|
|
573
594
|
{ key, items = [], strict = false, draft = false, commit = true },
|
|
574
595
|
) {
|
|
575
596
|
const root = path.join(path.resolve(projectDir), 'gcf');
|
|
597
|
+
const { parts } = parseBundle(text);
|
|
576
598
|
// Only the names a write may take (bundle.js validName): no other path gets staged.
|
|
577
|
-
const files =
|
|
599
|
+
const files = parts.flatMap((p) => {
|
|
578
600
|
if (p.kind === 'doc')
|
|
579
601
|
return Object.hasOwn(DOC_FILES, p.name) ? [path.join(root, DOC_FILES[p.name])] : [];
|
|
580
602
|
const sys = p.kind === 'system' ? p.name : p.system;
|
|
@@ -583,7 +605,8 @@ async function bundleMove(
|
|
|
583
605
|
? [path.join(root, 'design', `${sys}.md`)]
|
|
584
606
|
: [];
|
|
585
607
|
});
|
|
586
|
-
const
|
|
608
|
+
const fills = await purposeFills(root, files, parts);
|
|
609
|
+
const touched = [...new Set([...files, path.join(root, 'backlog.md'), ...fills.values()])];
|
|
587
610
|
const rel = (f) => path.relative(path.resolve(projectDir), f).replaceAll('\\', '/');
|
|
588
611
|
// A form's save over an agent's draft of its own file takes the draft along (decision 35): the
|
|
589
612
|
// operator saw it in the form. Another file's changes would ride along unseen.
|
|
@@ -611,6 +634,7 @@ async function bundleMove(
|
|
|
611
634
|
if (strict && refused.length)
|
|
612
635
|
throw new Error(refused.map((p) => `${p.outcome} ${p.part}: ${noteOf(p)}`).join('\n'));
|
|
613
636
|
if (!result.applied.length) throw new NothingApplied();
|
|
637
|
+
for (const s of fills.keys()) await fillPurpose(root, s);
|
|
614
638
|
},
|
|
615
639
|
});
|
|
616
640
|
|
|
@@ -690,16 +714,21 @@ async function commitUnlocked(projectDir, { message = null, commit = true } = {}
|
|
|
690
714
|
}
|
|
691
715
|
|
|
692
716
|
const abs = files.map((f) => path.join(path.resolve(projectDir), f));
|
|
717
|
+
const root = path.join(path.resolve(projectDir), 'gcf');
|
|
718
|
+
const fills = await purposeFills(root, abs);
|
|
693
719
|
const why = oneLine(message) || 'record the design';
|
|
694
720
|
const hash = await commitMove(projectDir, `gcf(design): ${why}`, {
|
|
695
|
-
files: abs,
|
|
721
|
+
files: [...abs, ...fills.values()],
|
|
696
722
|
inputs: abs,
|
|
697
|
-
mutate: async () => {
|
|
723
|
+
mutate: async () => {
|
|
724
|
+
for (const s of fills.keys()) await fillPurpose(root, s);
|
|
725
|
+
},
|
|
698
726
|
commit,
|
|
699
727
|
key: 'design-commit',
|
|
700
728
|
});
|
|
729
|
+
const rel = (f) => path.relative(path.resolve(projectDir), f).replaceAll('\\', '/');
|
|
701
730
|
|
|
702
|
-
return { files, hash };
|
|
731
|
+
return { files: [...files, ...[...fills.values()].map(rel)], hash };
|
|
703
732
|
}
|
|
704
733
|
|
|
705
734
|
// What an agent's draft writes (decision 35), and so what `design discard` may take back: not an
|
|
@@ -760,7 +789,8 @@ export async function designState(projectDir, { report, questions, items }) {
|
|
|
760
789
|
const units = new Set(report.units.map((u) => u.id));
|
|
761
790
|
const sources = await sourcesOf(root);
|
|
762
791
|
const asked = questions.filter((q) => isDesignQuestion(q, units));
|
|
763
|
-
|
|
792
|
+
// The board's rows (d2-states.js questionRow): a fired or aged D2 waits on the Operator too.
|
|
793
|
+
const open = asked.filter((q) => q.category === 'decision' && !q.answer);
|
|
764
794
|
const pillars = recordsIn(pillarsText, 'pillars').map((p) => ({
|
|
765
795
|
id: p.id ?? null,
|
|
766
796
|
// The few words the operator knows it by (decision 34); an old file has none.
|