gcf-aif-ext 0.10.2 → 0.12.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 +23 -4
- package/commands/gcf.js +140 -60
- package/extension.json +3 -2
- package/lib/agent-permissions.js +125 -20
- package/lib/audit-core.js +46 -6
- package/lib/board.js +6 -2
- package/lib/config-set.js +28 -2
- package/lib/context.js +24 -1
- package/lib/domain.js +81 -5
- package/lib/gcf-paths.js +26 -2
- package/lib/git.js +11 -2
- package/lib/inbox.js +265 -108
- package/lib/index-gen.js +7 -4
- package/lib/integrate.js +45 -8
- package/lib/lessons.js +31 -15
- package/lib/plan-check.js +22 -13
- package/lib/safe-path.js +2 -1
- package/lib/transitions.js +2 -0
- package/lib/unit-ops.js +1 -1
- package/lib/validate-item.js +7 -1
- package/lib/work-ops.js +141 -14
- package/package.json +1 -1
- package/skills/gcf-chat/SKILL.md +40 -0
- package/skills/gcf-triage/SKILL.md +10 -8
- package/templates/agents-block.md +12 -4
- package/templates/config.yml +7 -0
package/lib/agent-permissions.js
CHANGED
|
@@ -14,12 +14,95 @@ import { configDoc, ensureMap } from './config-set.js';
|
|
|
14
14
|
|
|
15
15
|
const GROUPS_SHAPE = 'gcf/config.yml: agent.groups must map a group id to true or false';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
// commands through PowerShell, which Bash rules do not cover.
|
|
19
|
-
const shell = (...patterns) => patterns.flatMap((p) => [`Bash(${p})`, `PowerShell(${p})`]);
|
|
20
|
-
const files = (tools, ...globs) => globs.flatMap((g) => tools.map((t) => `${t}(${g})`));
|
|
17
|
+
/** @typedef {{ kind: string, pattern: string }} Rule a neutral rule (Session-Engine.md AD-4) */
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
// The claude tools of each neutral kind: a rule of the kind holds for each. A shell rule covers
|
|
20
|
+
// PowerShell too: on Windows the agent runs commands through it, which Bash rules do not cover.
|
|
21
|
+
const CLAUDE = {
|
|
22
|
+
read: ['Read'],
|
|
23
|
+
search: ['Grep', 'Glob'],
|
|
24
|
+
edit: ['Edit', 'Write', 'MultiEdit', 'NotebookEdit'],
|
|
25
|
+
shell: ['Bash', 'PowerShell'],
|
|
26
|
+
web: ['WebFetch'],
|
|
27
|
+
subagent: ['Task', 'Agent'],
|
|
28
|
+
skill: ['Skill'],
|
|
29
|
+
question: ['AskUserQuestion'],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The kinds of tool a rule names: `mcp` (`server__tool`) and `other` (a claude rule as is). */
|
|
33
|
+
export const KINDS = [...Object.keys(CLAUDE), 'mcp', 'other'];
|
|
34
|
+
|
|
35
|
+
const NEUTRAL_RE = new RegExp(`^(${KINDS.join('|')}):\\s*(.*)$`);
|
|
36
|
+
// The kinds whose pattern is a path glob.
|
|
37
|
+
const PATHS = ['read', 'search', 'edit'];
|
|
38
|
+
// A claude rule: a tool name, optionally with a specifier — `Bash(npm test*)`, `Read`.
|
|
39
|
+
const CLAUDE_RE = /^([A-Za-z_][\w-]*)(?:\((.+)\))?$/;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A rule line in either form, neutral (`shell: git push --force*`) or claude's (`Bash(...)`,
|
|
43
|
+
* `mcp__server__tool`), as a neutral rule; null when it is neither.
|
|
44
|
+
* @param {unknown} line
|
|
45
|
+
* @returns {Rule | null}
|
|
46
|
+
*/
|
|
47
|
+
export function parseRule(line) {
|
|
48
|
+
if (typeof line !== 'string') return null;
|
|
49
|
+
const n = NEUTRAL_RE.exec(line.trim());
|
|
50
|
+
if (n) return n[1] === 'other' && !CLAUDE_RE.test(n[2]) ? null : { kind: n[1], pattern: n[2] };
|
|
51
|
+
const c = CLAUDE_RE.exec(line);
|
|
52
|
+
if (!c) return null;
|
|
53
|
+
if (c[1].startsWith('mcp__') && !c[2]) return { kind: 'mcp', pattern: c[1].slice(5) };
|
|
54
|
+
const kind = Object.keys(CLAUDE).find((k) => CLAUDE[k].includes(c[1]));
|
|
55
|
+
if (!kind) return { kind: 'other', pattern: line };
|
|
56
|
+
|
|
57
|
+
return { kind, pattern: neutralSpec(kind, c[2] ?? '') };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A claude rule's specifier in the neutral form: a domain without `domain:`; a path `/x`, which
|
|
62
|
+
* claude reads from the project, as `x`, and `//x`, from the root, as `/x` (the engine's adapter
|
|
63
|
+
* writes them back so).
|
|
64
|
+
*/
|
|
65
|
+
function neutralSpec(kind, spec) {
|
|
66
|
+
if (kind === 'web') return spec.replace(/^domain:/, '');
|
|
67
|
+
|
|
68
|
+
return PATHS.includes(kind) && spec.startsWith('/') ? spec.slice(1) : spec;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The claude rules of a neutral one: one per tool of its kind, `WebFetch(domain:…)` for `web`,
|
|
73
|
+
* `mcp__…` for `mcp`, an `other` as it is.
|
|
74
|
+
* @param {Rule} r
|
|
75
|
+
*/
|
|
76
|
+
export function claudeRules(r) {
|
|
77
|
+
if (r.kind === 'other') return [r.pattern];
|
|
78
|
+
if (r.kind === 'mcp') return [`mcp__${r.pattern}`];
|
|
79
|
+
const web = r.kind === 'web' && r.pattern ? `domain:${r.pattern}` : r.pattern;
|
|
80
|
+
const spec = PATHS.includes(r.kind) ? claudePath(r.pattern) : web;
|
|
81
|
+
|
|
82
|
+
return CLAUDE[r.kind].map((t) => (spec ? `${t}(${spec})` : t));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A neutral path glob as claude reads it, as the engine's adapter writes it
|
|
87
|
+
* (gcf-session/lib/adapter/claude.js `pathRule`: change both): a project path as it is, an
|
|
88
|
+
* absolute one from the root (`//x`), a Windows drive as `//c/x`.
|
|
89
|
+
*/
|
|
90
|
+
function claudePath(pattern) {
|
|
91
|
+
const drive = /^([A-Za-z]):[\\/](.*)$/.exec(pattern);
|
|
92
|
+
if (drive) return `//${drive[1].toLowerCase()}/${drive[2].replaceAll('\\', '/')}`;
|
|
93
|
+
|
|
94
|
+
return pattern.startsWith('/') && !pattern.startsWith('//') ? `/${pattern}` : pattern;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A rule as the operator reads it: `shell: git push --force*`. */
|
|
98
|
+
export const ruleText = (r) => `${r.kind}: ${r.pattern}`;
|
|
99
|
+
|
|
100
|
+
const sameRule = (a, b) => a?.kind === b?.kind && a?.pattern === b?.pattern;
|
|
101
|
+
|
|
102
|
+
const shell = (...patterns) => patterns.map((pattern) => ({ kind: 'shell', pattern }));
|
|
103
|
+
const files = (kind, ...globs) => globs.map((pattern) => ({ kind, pattern }));
|
|
104
|
+
|
|
105
|
+
/** @type {{ id: string, label: string, on: boolean, rules: Rule[] }[]} */
|
|
23
106
|
export const DENY_GROUPS = [
|
|
24
107
|
{
|
|
25
108
|
id: 'git-destroy',
|
|
@@ -93,20 +176,25 @@ export const DENY_GROUPS = [
|
|
|
93
176
|
'ai-factory gcf-harness init*',
|
|
94
177
|
'ai-factory gcf-harness run*',
|
|
95
178
|
'ai-factory gcf-harness stop*',
|
|
179
|
+
// The operator's chat input: an agent answering its own question would be no answer.
|
|
180
|
+
'ai-factory gcf-harness chat*',
|
|
96
181
|
'ai-factory extension*',
|
|
97
182
|
),
|
|
98
183
|
},
|
|
99
184
|
{
|
|
100
185
|
id: 'guards',
|
|
101
|
-
label:
|
|
186
|
+
label:
|
|
187
|
+
'the guards: .claude/, extension code, gcf/LIVE.md, gcf/.metrics/, the run and chat files',
|
|
102
188
|
on: true,
|
|
103
189
|
rules: files(
|
|
104
|
-
|
|
190
|
+
'edit',
|
|
105
191
|
'.claude/**',
|
|
106
192
|
'.ai-factory/extensions/**',
|
|
107
193
|
'gcf/LIVE.md',
|
|
108
194
|
'gcf/.metrics/**',
|
|
109
195
|
'.gcf-session/runs/**',
|
|
196
|
+
// The project chat's threads: their records, input and settings are the center's.
|
|
197
|
+
'.gcf-session/chats/**',
|
|
110
198
|
'.gcf-session/handoff.json',
|
|
111
199
|
),
|
|
112
200
|
},
|
|
@@ -114,7 +202,7 @@ export const DENY_GROUPS = [
|
|
|
114
202
|
id: 'secrets',
|
|
115
203
|
label: 'reading secrets: ~/.npmrc, ~/.ssh, ~/.claude.json, .env',
|
|
116
204
|
on: false,
|
|
117
|
-
rules: files(
|
|
205
|
+
rules: files('read', '~/.npmrc', '~/.ssh/**', '~/.claude.json', '**/.env'),
|
|
118
206
|
},
|
|
119
207
|
{
|
|
120
208
|
id: 'outside',
|
|
@@ -143,19 +231,22 @@ export const DENY_GROUPS = [
|
|
|
143
231
|
];
|
|
144
232
|
|
|
145
233
|
const GROUP_IDS = DENY_GROUPS.map((g) => g.id);
|
|
146
|
-
// A permission rule: a tool name, optionally with a specifier — `Bash(npm test*)`, `Read`.
|
|
147
|
-
const RULE_RE = /^[A-Za-z_][\w-]*(\(.+\))?$/;
|
|
148
234
|
const known = (x) => GROUP_IDS.includes(x);
|
|
149
|
-
const rule = (x) =>
|
|
235
|
+
const rule = (x) => parseRule(x) !== null;
|
|
150
236
|
|
|
151
237
|
function rules(agent, key) {
|
|
152
238
|
const v = agent[key] ?? [];
|
|
153
239
|
if (!Array.isArray(v) || !v.every(rule))
|
|
154
|
-
throw new Error(
|
|
240
|
+
throw new Error(
|
|
241
|
+
`gcf/config.yml: agent.${key} must be a list of rules like shell: cmd*, Bash(cmd*) or Read`,
|
|
242
|
+
);
|
|
155
243
|
|
|
156
244
|
return v;
|
|
157
245
|
}
|
|
158
246
|
|
|
247
|
+
/** The claude rules of neutral ones, each once. */
|
|
248
|
+
const claudeOf = (list) => [...new Set(list.flatMap(claudeRules))];
|
|
249
|
+
|
|
159
250
|
/**
|
|
160
251
|
* The groups the human chose: `agent.groups` maps a group id to true or false. A group it does
|
|
161
252
|
* not name keeps its default, so a group a later version adds on comes on in every project.
|
|
@@ -175,7 +266,9 @@ function choices(agent) {
|
|
|
175
266
|
|
|
176
267
|
/**
|
|
177
268
|
* The `agent:` section resolved: each group on or off, the deny rules the run gets, the extra
|
|
178
|
-
* allow rules (for an agent run without bypass). No section: the default groups.
|
|
269
|
+
* allow rules (for an agent run without bypass). No section: the default groups. `rules` holds
|
|
270
|
+
* them neutral (AD-4), `deny` and `allow` as claude rules for a harness before 0.12;
|
|
271
|
+
* `deny_extra` is the operator's own deny lines as written, `extra` the same neutral.
|
|
179
272
|
*/
|
|
180
273
|
export function agentOf(config) {
|
|
181
274
|
const agent = config.agent ?? {};
|
|
@@ -183,13 +276,22 @@ export function agentOf(config) {
|
|
|
183
276
|
throw new Error('gcf/config.yml: agent must be a mapping');
|
|
184
277
|
const chosen = choices(agent);
|
|
185
278
|
const extra = rules(agent, 'deny');
|
|
186
|
-
const
|
|
279
|
+
const allowed = rules(agent, 'allow').map(parseRule);
|
|
187
280
|
const groups = DENY_GROUPS.map((g) => ({ id: g.id, label: g.label, on: chosen[g.id] ?? g.on }));
|
|
188
|
-
const
|
|
189
|
-
...
|
|
190
|
-
|
|
281
|
+
const denied = [
|
|
282
|
+
...DENY_GROUPS.filter((g, i) => groups[i].on).flatMap((g) => g.rules),
|
|
283
|
+
...extra.map(parseRule),
|
|
284
|
+
].filter((r, i, all) => all.findIndex((x) => sameRule(x, r)) === i);
|
|
191
285
|
|
|
192
|
-
return {
|
|
286
|
+
return {
|
|
287
|
+
groups,
|
|
288
|
+
deny_extra: extra,
|
|
289
|
+
deny: claudeOf(denied),
|
|
290
|
+
allow: claudeOf(allowed),
|
|
291
|
+
rules: { deny: denied, allow: allowed },
|
|
292
|
+
// The operator's own deny lines neutral, in `deny_extra`'s order: what the board shows.
|
|
293
|
+
extra: extra.map(parseRule),
|
|
294
|
+
};
|
|
193
295
|
}
|
|
194
296
|
|
|
195
297
|
/** Refuse a change that names no group, a group twice, a bad rule, or a rule it cannot remove. */
|
|
@@ -202,7 +304,10 @@ function checkChange(change, current) {
|
|
|
202
304
|
if (both) throw new Error(`${both} is turned on and off at once`);
|
|
203
305
|
for (const r of [...(change.deny ?? []), ...(change.undeny ?? [])])
|
|
204
306
|
if (!rule(r)) throw new Error(`not a permission rule: ${r}`);
|
|
205
|
-
|
|
307
|
+
// A line goes by its meaning: `shell: curl *` removes a written `Bash(curl *)`.
|
|
308
|
+
const missing = (change.undeny ?? []).find(
|
|
309
|
+
(r) => !current.deny_extra.some((d) => sameRule(parseRule(d), parseRule(r))),
|
|
310
|
+
);
|
|
206
311
|
if (missing) throw new Error(`${missing} is not one of your own deny rules: turn its group off`);
|
|
207
312
|
}
|
|
208
313
|
|
|
@@ -225,7 +330,7 @@ export async function setPermissions(projectDir, change, { commit = true } = {})
|
|
|
225
330
|
for (const id of change.on ?? []) doc.setIn(['agent', 'groups', id], true);
|
|
226
331
|
for (const id of change.off ?? []) doc.setIn(['agent', 'groups', id], false);
|
|
227
332
|
const deny = [...new Set([...current.deny_extra, ...(change.deny ?? [])])].filter(
|
|
228
|
-
(r) => !change.undeny?.
|
|
333
|
+
(r) => !change.undeny?.some((u) => sameRule(parseRule(u), parseRule(r))),
|
|
229
334
|
);
|
|
230
335
|
doc.setIn(['agent', 'deny'], doc.createNode(deny, { flow: true }));
|
|
231
336
|
result = agentOf({ agent: doc.toJS().agent });
|
package/lib/audit-core.js
CHANGED
|
@@ -10,8 +10,9 @@ import { buildLedger } from './ledger.js';
|
|
|
10
10
|
import { STORED } from './transitions.js';
|
|
11
11
|
import { openDepends } from './work-ops.js';
|
|
12
12
|
import { runHolder } from './main-lock.js';
|
|
13
|
-
import { sessionActive } from './session-mark.js';
|
|
13
|
+
import { markOwner, ownerOf, sessionActive } from './session-mark.js';
|
|
14
14
|
import { fieldOf } from './question-fields.js';
|
|
15
|
+
import { inboxProblems } from './inbox.js';
|
|
15
16
|
|
|
16
17
|
function git(args, cwd) {
|
|
17
18
|
// A blame of a long file overflows the 1 MiB default, and an overflow reads as a git failure.
|
|
@@ -23,6 +24,27 @@ function git(args, cwd) {
|
|
|
23
24
|
const UNTIL_RE = /\[until:\s*(verdict\([a-z0-9-]+\)|retune\([a-z0-9-]+\)|manual\([^)]*\))\]/g;
|
|
24
25
|
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Whether an item runs, and who works it (`running_by`): `run`, a harness run's live lock; `you`,
|
|
29
|
+
* a fresh session mark this session or its run owns (`GCF_RUN_OWNER`, else
|
|
30
|
+
* `CLAUDE_CODE_SESSION_ID`); `unowned`, a mark that names nobody (a claim takes it); `session`,
|
|
31
|
+
* another session's mark. Null when nobody does.
|
|
32
|
+
*/
|
|
33
|
+
function runningOf(projectDir, id) {
|
|
34
|
+
const held = () => {
|
|
35
|
+
if (runHolder(projectDir, id) !== null) return 'run';
|
|
36
|
+
if (!sessionActive(projectDir, id)) return null;
|
|
37
|
+
const mark = markOwner(projectDir, id);
|
|
38
|
+
if (!mark) return 'unowned';
|
|
39
|
+
|
|
40
|
+
return mark === ownerOf() ? 'you' : 'session';
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const by = held();
|
|
44
|
+
|
|
45
|
+
return { running: by !== null, running_by: by };
|
|
46
|
+
}
|
|
47
|
+
|
|
26
48
|
/**
|
|
27
49
|
* @typedef {object} AuditReport
|
|
28
50
|
* @property {string} first_line
|
|
@@ -44,8 +66,10 @@ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
44
66
|
* @property {number} [schema]
|
|
45
67
|
* @property {Array<{id: string, type: string, gate: string, status: string, system: string[],
|
|
46
68
|
* depends: string[], parent: string | null, tune_count: number, parallel: string,
|
|
47
|
-
* priority: number | null, running: boolean}>} [items]
|
|
69
|
+
* priority: number | null, running: boolean, running_by: string | null}>} [items]
|
|
48
70
|
* @property {{blocking: number, units: number, ready: number}} [design]
|
|
71
|
+
* @property {{legacy: boolean, bad_names: string[], untitled: string[], broken_links: string[],
|
|
72
|
+
* orphan_dirs: string[]}} inbox
|
|
49
73
|
*/
|
|
50
74
|
|
|
51
75
|
/**
|
|
@@ -85,6 +109,7 @@ export async function audit(projectDir) {
|
|
|
85
109
|
index_drift: await drifted(root),
|
|
86
110
|
illegal_status: [],
|
|
87
111
|
stale_questions: staleQuestions(projectDir, root, config),
|
|
112
|
+
inbox: await inboxProblems(root),
|
|
88
113
|
};
|
|
89
114
|
// The harness gate reads everything from this one report — it never parses gcf/ itself.
|
|
90
115
|
report.schema = config.schema;
|
|
@@ -99,9 +124,7 @@ export async function audit(projectDir) {
|
|
|
99
124
|
tune_count: c.data.tune_count ?? 0,
|
|
100
125
|
parallel: c.data.parallel ?? 'serial',
|
|
101
126
|
priority: c.data.priority ?? null,
|
|
102
|
-
|
|
103
|
-
running:
|
|
104
|
-
runHolder(projectDir, c.data.id) !== null || sessionActive(projectDir, String(c.data.id)),
|
|
127
|
+
...runningOf(projectDir, String(c.data.id)),
|
|
105
128
|
}));
|
|
106
129
|
const design = await designCheck(projectDir);
|
|
107
130
|
checkItems(report, items, config, { projectDir, ledger });
|
|
@@ -290,7 +313,12 @@ function untilRecords(items, systems, fired, questions) {
|
|
|
290
313
|
];
|
|
291
314
|
const until = [];
|
|
292
315
|
for (const doc of docs) {
|
|
293
|
-
|
|
316
|
+
// A quoted line (an inbox entry's text in a note:) holds no annotation, as for the gate.
|
|
317
|
+
const own = doc.body
|
|
318
|
+
.split('\n')
|
|
319
|
+
.filter((l) => !l.startsWith('>'))
|
|
320
|
+
.join('\n');
|
|
321
|
+
for (const m of own.matchAll(UNTIL_RE)) {
|
|
294
322
|
until.push({ file: `gcf/${doc.rel}`, trigger: m[1], status: untilStatus(m[1], fired) });
|
|
295
323
|
}
|
|
296
324
|
}
|
|
@@ -345,6 +373,18 @@ const docAlerts = (report) => [
|
|
|
345
373
|
Object.keys(report.linter).length && 'П2 linter findings in systems docs',
|
|
346
374
|
report.index_drift && 'INDEX drift (regenerate)',
|
|
347
375
|
report.design?.blocking && `${report.design.blocking} blocking design finding(s)`,
|
|
376
|
+
...inboxAlerts(report.inbox),
|
|
377
|
+
];
|
|
378
|
+
|
|
379
|
+
/** Alerts about gcf/inbox/: the old one-line file, files that are no entry, broken pictures. */
|
|
380
|
+
const inboxAlerts = (i) => [
|
|
381
|
+
i.legacy &&
|
|
382
|
+
'gcf/inbox.md is the old one-line inbox: the core reads gcf/inbox/ only — move its lines ' +
|
|
383
|
+
"with ai-factory gcf inbox add (the operator's call), then delete it",
|
|
384
|
+
i.bad_names.length && `${i.bad_names.length} file(s) in gcf/inbox/ are no entry`,
|
|
385
|
+
i.untitled.length && `${i.untitled.length} inbox entr(ies) without a title line`,
|
|
386
|
+
i.broken_links.length && `${i.broken_links.length} inbox picture link(s) lead nowhere`,
|
|
387
|
+
i.orphan_dirs.length && `${i.orphan_dirs.length} inbox picture folder(s) without their entry`,
|
|
348
388
|
];
|
|
349
389
|
|
|
350
390
|
/** @param {AuditReport} report */
|
package/lib/board.js
CHANGED
|
@@ -190,8 +190,10 @@ async function resumeOf(projectDir, id) {
|
|
|
190
190
|
try {
|
|
191
191
|
const file = path.join(projectDir, '.gcf-session', 'runs', `${id}.agent.json`);
|
|
192
192
|
const rec = JSON.parse(await readFile(file, 'utf8'));
|
|
193
|
-
// A handoff needs no session: the next run starts a fresh one from the plan.
|
|
194
|
-
|
|
193
|
+
// A handoff needs no session: the next run starts a fresh one from the plan. Nor does a
|
|
194
|
+
// run that waits for the usage limit before its first session (AD-19).
|
|
195
|
+
const sessionless = rec?.ended === 'handoff' || rec?.ended === 'limit';
|
|
196
|
+
if (typeof rec?.session_id !== 'string' && !sessionless) return null;
|
|
195
197
|
|
|
196
198
|
return {
|
|
197
199
|
ended: String(rec.ended ?? ''),
|
|
@@ -344,6 +346,8 @@ export async function board(projectDir) {
|
|
|
344
346
|
window: config.context_window,
|
|
345
347
|
compact_pct: config.auto_compact_pct,
|
|
346
348
|
},
|
|
349
|
+
// A run's chat with the operator (`chat:` in config.yml): what it asks, how long it waits.
|
|
350
|
+
chat: config.chat,
|
|
347
351
|
phase: await phaseOf(projectDir),
|
|
348
352
|
extensions,
|
|
349
353
|
extensions_error: extensionsError,
|
package/lib/config-set.js
CHANGED
|
@@ -13,7 +13,15 @@ import YAML from 'yaml';
|
|
|
13
13
|
import { commitMove } from './unit-ops.js';
|
|
14
14
|
import { withMainLock } from './main-lock.js';
|
|
15
15
|
import { atomicWrite } from './safe-path.js';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
CHAT_ASK,
|
|
18
|
+
CHAT_DEFAULTS,
|
|
19
|
+
configOf,
|
|
20
|
+
DEFAULT_CONFIG,
|
|
21
|
+
gcfRoot,
|
|
22
|
+
readRawConfig,
|
|
23
|
+
RUN_MODES,
|
|
24
|
+
} from './gcf-paths.js';
|
|
17
25
|
import { AIF_CONFIG, LANGUAGE_RE, languageIn, readAifConfig } from './aif-config.js';
|
|
18
26
|
|
|
19
27
|
/** @typedef {'number' | 'share' | 'mode' | 'command' | 'language'} Kind */
|
|
@@ -65,10 +73,26 @@ export const SETTINGS = [
|
|
|
65
73
|
{
|
|
66
74
|
key: 'run_mode',
|
|
67
75
|
kind: 'mode',
|
|
76
|
+
options: RUN_MODES,
|
|
68
77
|
label:
|
|
69
78
|
'how a run drives an item: worktree (several at once) or main (one at a time in the ' +
|
|
70
79
|
'project folder)',
|
|
71
80
|
},
|
|
81
|
+
{
|
|
82
|
+
key: 'chat.ask',
|
|
83
|
+
kind: 'mode',
|
|
84
|
+
options: CHAT_ASK,
|
|
85
|
+
label:
|
|
86
|
+
'what an agent run asks you by a question card: d1 (only your decisions), all (every ' +
|
|
87
|
+
'question of substance), none (nothing, it decides)',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
key: 'chat.answer_timeout_min',
|
|
91
|
+
kind: 'number',
|
|
92
|
+
label:
|
|
93
|
+
'minutes a question waits for your answer before the agent takes its default (0: nobody ' +
|
|
94
|
+
'watches, as for a night run; a main run waits with its whole queue)',
|
|
95
|
+
},
|
|
72
96
|
{ key: 'dod.test', kind: 'command', label: "the project's test command for the DoD, or none" },
|
|
73
97
|
{ key: 'dod.build', kind: 'command', label: "the project's build command for the DoD, or none" },
|
|
74
98
|
{
|
|
@@ -127,6 +151,7 @@ function defaultOf(s, aif) {
|
|
|
127
151
|
const [head, sub] = s.key.split('.');
|
|
128
152
|
if (s.key === 'language.artifacts') return languageIn(aif, 'ui') ?? 'en';
|
|
129
153
|
if (s.kind === 'language') return 'en';
|
|
154
|
+
if (head === 'chat') return CHAT_DEFAULTS[sub];
|
|
130
155
|
if (sub) return null;
|
|
131
156
|
|
|
132
157
|
return head === 'run_mode' ? 'worktree' : (DEFAULT_CONFIG[head] ?? null);
|
|
@@ -177,7 +202,8 @@ function valueOf(setting, text) {
|
|
|
177
202
|
}
|
|
178
203
|
|
|
179
204
|
if (setting.kind === 'mode') {
|
|
180
|
-
|
|
205
|
+
const options = setting.options ?? [];
|
|
206
|
+
if (!options.includes(t)) throw new Error(`${setting.key} must be ${options.join(' | ')}`);
|
|
181
207
|
|
|
182
208
|
return t;
|
|
183
209
|
}
|
package/lib/context.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
1
|
+
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
5
|
import { fieldOf } from './question-fields.js';
|
|
6
|
+
import { atomicWrite } from './safe-path.js';
|
|
7
|
+
import { ownerOf } from './session-mark.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The readset guard's manifest, `.gcf-session/readset.json`: the item, its readset's paths, and
|
|
11
|
+
* the session that owns it (`ownerOf`), so the guard holds for that session only.
|
|
12
|
+
*/
|
|
13
|
+
export async function writeReadset(projectDir, ctx, env = process.env) {
|
|
14
|
+
const dir = path.join(path.resolve(projectDir), '.gcf-session');
|
|
15
|
+
await mkdir(dir, { recursive: true });
|
|
16
|
+
const manifest = { item: ctx.item, owner: ownerOf(env), files: ctx.files.map((f) => f.path) };
|
|
17
|
+
await atomicWrite(path.join(dir, 'readset.json'), `${JSON.stringify(manifest)}\n`);
|
|
18
|
+
}
|
|
6
19
|
|
|
7
20
|
/**
|
|
8
21
|
* Readset assembly — the whole command is deterministic (GCF-PRD §9.1, §10.1):
|
|
@@ -60,6 +73,16 @@ async function readsetFiles(root, item, items) {
|
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
await push(`work/${item.name}`);
|
|
76
|
+
// The files the human gave the item (`gcf item attach`): read, not counted against the budget,
|
|
77
|
+
// which measures text.
|
|
78
|
+
const attached = path.join(root, 'work', String(item.data.id), 'attachments');
|
|
79
|
+
if (existsSync(attached))
|
|
80
|
+
for (const e of await readdir(attached, { recursive: true, withFileTypes: true })) {
|
|
81
|
+
if (!e.isFile()) continue;
|
|
82
|
+
const rel = path.relative(root, path.join(e.parentPath, e.name)).replaceAll('\\', '/');
|
|
83
|
+
files.push({ path: `gcf/${rel}`, tokens_est: 0 });
|
|
84
|
+
}
|
|
85
|
+
|
|
63
86
|
const parent = items.find((c) => c.data.id === item.data.parent);
|
|
64
87
|
if (parent) await push(`work/${parent.name}`);
|
|
65
88
|
for (const depId of item.data.depends ?? []) {
|
package/lib/domain.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { ITEM_MOVES, STORED } from './transitions.js';
|
|
6
6
|
import { DEFAULT_GATE, GATES, ITEM_TYPES, SEVERITIES, UNIT_ITEM_TYPES } from './validate-item.js';
|
|
7
7
|
import { SOURCES } from './inbox.js';
|
|
8
|
+
import { NOTE_MAX } from './work-ops.js';
|
|
8
9
|
|
|
9
10
|
// The status a run starts from; the order of its column is the run order.
|
|
10
11
|
export const RUNS_FROM = 'ready';
|
|
@@ -42,6 +43,12 @@ const UNVERIFIED = {
|
|
|
42
43
|
label: 'No green gcf verify? Why it goes anyway',
|
|
43
44
|
kind: 'text',
|
|
44
45
|
};
|
|
46
|
+
// And a plan with tasks left unticked (AD-50).
|
|
47
|
+
const UNTICKED = {
|
|
48
|
+
key: 'unticked',
|
|
49
|
+
label: 'Plan tasks unticked? Why it goes anyway',
|
|
50
|
+
kind: 'text',
|
|
51
|
+
};
|
|
45
52
|
|
|
46
53
|
const verdict = (v, help, fields, danger) => ({
|
|
47
54
|
label: v,
|
|
@@ -65,14 +72,14 @@ const ITEM_SPECS = {
|
|
|
65
72
|
label: 'submit',
|
|
66
73
|
help: 'Built: on to awaiting verdict or awaiting decision, by its gate',
|
|
67
74
|
args: ['gcf', 'submit', '{id}'],
|
|
68
|
-
fields: [UNVERIFIED],
|
|
75
|
+
fields: [UNVERIFIED, UNTICKED],
|
|
69
76
|
rare: true,
|
|
70
77
|
},
|
|
71
78
|
close: {
|
|
72
79
|
label: 'close',
|
|
73
80
|
help: 'Done, gate auto: to history; a mechanic or a resource waits unplayed',
|
|
74
81
|
args: ['gcf', 'close', '{id}'],
|
|
75
|
-
fields: [CONSTRAINT, UNVERIFIED],
|
|
82
|
+
fields: [CONSTRAINT, UNVERIFIED, UNTICKED],
|
|
76
83
|
rare: true,
|
|
77
84
|
},
|
|
78
85
|
'verdict:keep': verdict('keep', 'Played and kept: it goes to history', [
|
|
@@ -142,6 +149,13 @@ const ITEM_SPECS = {
|
|
|
142
149
|
],
|
|
143
150
|
rare: true,
|
|
144
151
|
},
|
|
152
|
+
attach: {
|
|
153
|
+
label: 'attach',
|
|
154
|
+
help: 'Give the item a file (a chat image, a reference): committed in its attachments',
|
|
155
|
+
args: ['gcf', 'item', 'attach', '{id}'],
|
|
156
|
+
fields: [{ key: 'file', label: 'File path', kind: 'text', required: true }],
|
|
157
|
+
rare: true,
|
|
158
|
+
},
|
|
145
159
|
};
|
|
146
160
|
|
|
147
161
|
// The agent's move: a session of the gcf-run skill builds the item, driven by the harness.
|
|
@@ -155,11 +169,13 @@ const RUN = {
|
|
|
155
169
|
};
|
|
156
170
|
|
|
157
171
|
// The new item form (`gcf item new`): work that is not a design unit; a design unit enters work
|
|
158
|
-
// through the gcf-card skill and take.
|
|
172
|
+
// through the gcf-card skill and take. A project chat agent may propose it (AD-12): the board
|
|
173
|
+
// shows the proposal, the operator's click makes it.
|
|
159
174
|
const NEW_ITEM = {
|
|
160
175
|
label: 'create',
|
|
161
176
|
help: 'A new work item, committed; the core refuses a type the phase does not take',
|
|
162
177
|
args: ['gcf', 'item', 'new', '{id}', '--commit'],
|
|
178
|
+
propose: true,
|
|
163
179
|
fields: [
|
|
164
180
|
{ key: 'id', label: 'Id (lowercase-hyphen slug)', kind: 'slug', required: true },
|
|
165
181
|
{
|
|
@@ -201,6 +217,14 @@ const NEW_ITEM = {
|
|
|
201
217
|
text('blocked', 'Start blocked: why (e.g. "file needed")'),
|
|
202
218
|
text('model', 'Model of its run (e.g. opus)'),
|
|
203
219
|
text('effort', 'Effort of its run (e.g. high)'),
|
|
220
|
+
// A board passes it on stdin (`stdin`: `--note-file -`, AD-39).
|
|
221
|
+
{
|
|
222
|
+
key: 'note',
|
|
223
|
+
label: 'Note: what its run should know',
|
|
224
|
+
kind: 'longtext',
|
|
225
|
+
max: NOTE_MAX,
|
|
226
|
+
stdin: true,
|
|
227
|
+
},
|
|
204
228
|
// The inbox entry it comes from: the form fills it, the operator does not.
|
|
205
229
|
text('from', 'From inbox entry', { hidden: true }),
|
|
206
230
|
],
|
|
@@ -219,10 +243,10 @@ const BLOCK_SPECS = {
|
|
|
219
243
|
},
|
|
220
244
|
'inbox-add': {
|
|
221
245
|
label: 'add',
|
|
222
|
-
help: 'A raw note for triage
|
|
246
|
+
help: 'A raw note for triage (an idea, a playtest note, a CI finding); line 1 is its title',
|
|
223
247
|
args: ['gcf', 'inbox', 'add', '--commit'],
|
|
224
248
|
fields: [
|
|
225
|
-
{ key: 'text', label: 'Text', kind: '
|
|
249
|
+
{ key: 'text', label: 'Text', kind: 'longtext', required: true },
|
|
226
250
|
{
|
|
227
251
|
key: 'source',
|
|
228
252
|
label: 'Source',
|
|
@@ -334,6 +358,57 @@ const SECTIONS = {
|
|
|
334
358
|
graveyard: { label: 'Graveyard' },
|
|
335
359
|
};
|
|
336
360
|
|
|
361
|
+
// The gcf commands that change the project: a project chat asks the operator before each one
|
|
362
|
+
// (AD-5). The read-only ones (audit, board, context, verify, where, plan check…) go unasked.
|
|
363
|
+
// shortcut: the rules match `ai-factory gcf …` as written, as the deny groups do; `npx` or a
|
|
364
|
+
// path to the CLI slips past them.
|
|
365
|
+
const CHANGES = [
|
|
366
|
+
'claim',
|
|
367
|
+
'release',
|
|
368
|
+
'init',
|
|
369
|
+
'index',
|
|
370
|
+
'anchor',
|
|
371
|
+
'design export',
|
|
372
|
+
'design import',
|
|
373
|
+
'design migrate',
|
|
374
|
+
'take',
|
|
375
|
+
'done',
|
|
376
|
+
'drop',
|
|
377
|
+
'item',
|
|
378
|
+
'depends',
|
|
379
|
+
'prioritize',
|
|
380
|
+
'question',
|
|
381
|
+
'submit',
|
|
382
|
+
'close',
|
|
383
|
+
'verdict',
|
|
384
|
+
'decide',
|
|
385
|
+
'block',
|
|
386
|
+
'unblock',
|
|
387
|
+
'inbox add',
|
|
388
|
+
'inbox tag',
|
|
389
|
+
'inbox drop',
|
|
390
|
+
'lessons add',
|
|
391
|
+
'config set',
|
|
392
|
+
'permissions',
|
|
393
|
+
'worktree',
|
|
394
|
+
'integrate',
|
|
395
|
+
'phase next',
|
|
396
|
+
'hooks-install',
|
|
397
|
+
'pillar',
|
|
398
|
+
];
|
|
399
|
+
|
|
400
|
+
// The project chat of a GCF project (AD-5, AD-6): its skill, and the commands it asks for.
|
|
401
|
+
const CHAT = {
|
|
402
|
+
skill: 'gcf-chat',
|
|
403
|
+
confirm: [
|
|
404
|
+
...CHANGES.map((c) => ({ kind: 'shell', pattern: `ai-factory gcf ${c}*` })),
|
|
405
|
+
// `context` reads, but with `--readset` it takes the guard's manifest over (AD-30).
|
|
406
|
+
{ kind: 'shell', pattern: 'ai-factory gcf context*--readset*' },
|
|
407
|
+
// `verify` reads, but with `--mark` it commits a branch's readiness to merge.
|
|
408
|
+
{ kind: 'shell', pattern: 'ai-factory gcf verify*--mark*' },
|
|
409
|
+
],
|
|
410
|
+
};
|
|
411
|
+
|
|
337
412
|
// The extension whose CLI drives agent runs (run, next, stop, metrics with --json).
|
|
338
413
|
const HARNESS = { extension: 'gcf-harness-aif-ext', cli: 'gcf-harness' };
|
|
339
414
|
|
|
@@ -366,5 +441,6 @@ export function domainOf(extensions = {}) {
|
|
|
366
441
|
sections: SECTIONS,
|
|
367
442
|
new_item: 'item-new',
|
|
368
443
|
rank: 'prioritize',
|
|
444
|
+
chat: CHAT,
|
|
369
445
|
};
|
|
370
446
|
}
|
package/lib/gcf-paths.js
CHANGED
|
@@ -48,6 +48,29 @@ function runModeOf(v = 'worktree') {
|
|
|
48
48
|
return v;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// A run's chat with the operator (Harness-PRD §10 "чат"): what the agent asks by a question card
|
|
52
|
+
// (`d1`: only the human's decisions; `all`: every question of substance; `none`: nothing) and
|
|
53
|
+
// how long a question waits for an answer (0: nobody watches, the default answer goes at once).
|
|
54
|
+
export const CHAT_ASK = ['d1', 'all', 'none'];
|
|
55
|
+
export const CHAT_DEFAULTS = { ask: 'd1', answer_timeout_min: 15 };
|
|
56
|
+
|
|
57
|
+
function chatOf(v = {}) {
|
|
58
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v))
|
|
59
|
+
throw new Error('gcf/config.yml: chat must be a key: value mapping');
|
|
60
|
+
const set = Object.fromEntries(Object.entries(v).filter(([, x]) => x !== null));
|
|
61
|
+
const chat = { ...CHAT_DEFAULTS, ...set };
|
|
62
|
+
if (!CHAT_ASK.includes(chat.ask))
|
|
63
|
+
throw new Error(`gcf/config.yml: chat.ask must be ${CHAT_ASK.join(' | ')}, got ${chat.ask}`);
|
|
64
|
+
const min = chat.answer_timeout_min;
|
|
65
|
+
if (!Number.isFinite(min) || min < 0)
|
|
66
|
+
throw new Error(
|
|
67
|
+
'gcf/config.yml: chat.answer_timeout_min must be a non-negative number, ' +
|
|
68
|
+
`got ${JSON.stringify(min)}`,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return chat;
|
|
72
|
+
}
|
|
73
|
+
|
|
51
74
|
/** @returns {Promise<Record<string, any>>} */
|
|
52
75
|
export async function readConfig(root) {
|
|
53
76
|
return configOf(await readRawConfig(root));
|
|
@@ -62,7 +85,8 @@ export async function readRawConfig(root) {
|
|
|
62
85
|
|
|
63
86
|
/**
|
|
64
87
|
* The config a parsed config.yml gives, checked: defaults for what it does not set, every limit
|
|
65
|
-
* a non-negative number, the shares 0-100, the run mode one of RUN_MODES
|
|
88
|
+
* a non-negative number, the shares 0-100, the run mode one of RUN_MODES, the chat as chatOf
|
|
89
|
+
* checks it. Throws on the first
|
|
66
90
|
* key that breaks a rule. `gcf config set` checks a change with it before it writes.
|
|
67
91
|
* @returns {Record<string, any>}
|
|
68
92
|
*/
|
|
@@ -96,7 +120,7 @@ export function configOf(parsed) {
|
|
|
96
120
|
`(${handoff + 15}), or the compaction comes before the handoff`,
|
|
97
121
|
);
|
|
98
122
|
|
|
99
|
-
return { ...config, run_mode: runModeOf(config.run_mode) };
|
|
123
|
+
return { ...config, run_mode: runModeOf(config.run_mode), chat: chatOf(config.chat) };
|
|
100
124
|
}
|
|
101
125
|
|
|
102
126
|
/** Token estimate: ceil(chars/4). Stability over accuracy (GCF-PRD §9.1). */
|