gcf-aif-ext 0.7.5 → 0.7.7
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 +11 -0
- package/commands/gcf.js +56 -0
- package/extension.json +1 -1
- package/lib/agent-permissions.js +244 -0
- package/lib/board.js +15 -2
- package/lib/config-set.js +167 -0
- package/lib/gcf-paths.js +35 -10
- package/lib/questions.js +14 -1
- package/package.json +1 -1
- package/templates/agents-block.md +2 -0
- package/templates/config.yml +8 -0
package/README.md
CHANGED
|
@@ -50,6 +50,17 @@ Updating preserves `gcf/`, `cnlp.config.json` and the pre-commit hook. Run `ai-f
|
|
|
50
50
|
|
|
51
51
|
On Windows, run `extension add` and `extension update` from PowerShell or cmd, not Git Bash: the installer unpacks with `tar`, and Git Bash's GNU tar reads `C:\…` as a remote host (`Cannot connect to C: resolve failed`). The Windows `tar.exe` handles it.
|
|
52
52
|
|
|
53
|
+
### 0.7.7
|
|
54
|
+
|
|
55
|
+
- `ai-factory gcf config [--json]` lists the human's settings of `gcf/config.yml` with what each means; `gcf config set <key> --value=<v>` sets one, checked by the rules a read applies, the comments kept, one `gcf(config)` commit. An empty number goes back to its default. `gcf board --json` carries them as `settings`.
|
|
56
|
+
- `gcf board --json` questions also carry `assumed`, `until`, `sys`, `lens` and `sections`: a D2 shows what it assumed and when it comes back, and every record where it came from.
|
|
57
|
+
|
|
58
|
+
### 0.7.6
|
|
59
|
+
|
|
60
|
+
- `ai-factory gcf permissions [--on <group>] [--off <group>] [--deny <rule>] [--undeny <rule>]` — what agent runs may not do: deny groups and the human's own rules in the `agent:` section of `gcf/config.yml`, one `gcf(permissions)` commit; with no change it lists them. On by default: `git-destroy`, `mass-delete`, `publish`, `human-moves`, `guards`; off: `secrets`, `outside`, `processes`. `agent.groups` keeps only the human's choices (`secrets: true`): a group it does not name keeps its default, so one a later version adds comes on. `git push` is in none. `gcf board --json` carries `agent` (`groups`, `deny_extra`, the resolved `deny`, `allow`).
|
|
61
|
+
- New `config.yml` keys for harness runs: `context_handoff_pct` (60; 0 turns the handoff off), `context_window` (0: the model's) and `auto_compact_pct` (0: the agent's default; at least the handoff share + 15). `gcf board --json` carries them as `context`; a kept session that handed over reads `resume: {ended: 'handoff', handoffs}`.
|
|
62
|
+
- The AGENTS.md block tells the agent that the permissions are the human's.
|
|
63
|
+
|
|
53
64
|
### 0.7.1
|
|
54
65
|
|
|
55
66
|
- `gcf board --json`: a ready item's worktree with no run lock and no session mark is a run that stopped (a timeout, a stop, a crash), not a run: the item reads `running: false`, `resumable: true`, and keeps its moves; its next run resumes the worktree. An agent session the harness kept (`.gcf-session/runs/<id>.agent.json`) makes a ready item `resumable` too, in either run mode, and shows as `resume: {ended, resets?}` (null without one).
|
package/commands/gcf.js
CHANGED
|
@@ -977,6 +977,62 @@ function registerBoard(gcf) {
|
|
|
977
977
|
].join('\n'),
|
|
978
978
|
);
|
|
979
979
|
});
|
|
980
|
+
const config = gcf
|
|
981
|
+
.command('config')
|
|
982
|
+
.description("The human's settings of gcf/config.yml: list them, or set one (commit)")
|
|
983
|
+
// A misspelt subcommand would read as a stray word and list the settings, as if set.
|
|
984
|
+
.allowExcessArguments(false)
|
|
985
|
+
.option('--json', 'machine output')
|
|
986
|
+
.action(async (o) => {
|
|
987
|
+
const { gcfRoot, readConfig, readRawConfig } = await lib('gcf-paths');
|
|
988
|
+
await readConfig(gcfRoot()); // a config the rules refuse says so here
|
|
989
|
+
const list = (await lib('config-set')).settingsOf(await readRawConfig(gcfRoot()));
|
|
990
|
+
out(o.json, list, (x) =>
|
|
991
|
+
x.map((s) => `${s.key}: ${s.value ?? '-'} # ${s.label}`).join('\n'),
|
|
992
|
+
);
|
|
993
|
+
});
|
|
994
|
+
config
|
|
995
|
+
.command('set <key>')
|
|
996
|
+
.description('Set one key; an empty --value= takes a number back to its default')
|
|
997
|
+
// The value only through --value: `set plan_passes 7` must not read as a reset. A value
|
|
998
|
+
// may start with a hyphen (a command's flag); as `--value=<text>` it stays one value.
|
|
999
|
+
.allowExcessArguments(false)
|
|
1000
|
+
.requiredOption('--value <value>', 'the new value; empty (--value=) for the default')
|
|
1001
|
+
.option('--no-commit', 'skip the commit (tests only)')
|
|
1002
|
+
.action(async (key, o) => {
|
|
1003
|
+
const r = await (
|
|
1004
|
+
await lib('config-set')
|
|
1005
|
+
).setConfig(process.cwd(), key, o.value, {
|
|
1006
|
+
commit: o.commit,
|
|
1007
|
+
});
|
|
1008
|
+
const now = `${r.key}: ${r.value ?? 'default'}`;
|
|
1009
|
+
console.log(r.unchanged ? `${now} (unchanged)` : `${now}${shortHash(r.hash)}`);
|
|
1010
|
+
});
|
|
1011
|
+
const many = (v, prev = []) => [...prev, v];
|
|
1012
|
+
gcf
|
|
1013
|
+
.command('permissions')
|
|
1014
|
+
.description("What agent runs may not do: deny groups and custom rules (the human's; commit)")
|
|
1015
|
+
.option('--on <group>', 'turn a deny group on (repeatable)', many)
|
|
1016
|
+
.option('--off <group>', 'turn a deny group off (repeatable)', many)
|
|
1017
|
+
.option('--deny <rule>', 'add a custom deny rule, like Bash(cmd*) (repeatable)', many)
|
|
1018
|
+
.option('--undeny <rule>', 'remove a custom deny rule (repeatable)', many)
|
|
1019
|
+
.option('--json', 'machine output')
|
|
1020
|
+
.option('--no-commit', 'skip the commit (tests only)')
|
|
1021
|
+
.action(async (o) => {
|
|
1022
|
+
const perms = await lib('agent-permissions');
|
|
1023
|
+
const { gcfRoot, readConfig } = await lib('gcf-paths');
|
|
1024
|
+
const change = [o.on, o.off, o.deny, o.undeny].some(Boolean);
|
|
1025
|
+
const r = change
|
|
1026
|
+
? await perms.setPermissions(process.cwd(), o, { commit: o.commit })
|
|
1027
|
+
: perms.agentOf(await readConfig(gcfRoot()));
|
|
1028
|
+
out(o.json, r, (x) =>
|
|
1029
|
+
[
|
|
1030
|
+
...x.groups.map((g) => `${g.on ? '[x]' : '[ ]'} ${g.id}: ${g.label}`),
|
|
1031
|
+
...x.deny_extra.map((d) => `deny: ${d}`),
|
|
1032
|
+
...(x.hash ? [`committed${shortHash(x.hash)}`] : []),
|
|
1033
|
+
].join('\n'),
|
|
1034
|
+
);
|
|
1035
|
+
});
|
|
980
1036
|
}
|
|
981
1037
|
|
|
982
1038
|
function registerIntegrate(gcf) {
|
package/extension.json
CHANGED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// What a headless agent run may not do (Harness-PRD §7). The run allows everything else
|
|
2
|
+
// (`--permission-mode bypassPermissions`): a deny rule holds in every mode. The groups guard
|
|
3
|
+
// the edge cases only — what git cannot undo, what leaves the machine, the human's own moves
|
|
4
|
+
// and the guards themselves. `git push` is not one of them: a feature ends tested and pushed.
|
|
5
|
+
// Deny rules match the command as written, so they catch accidents, not a determined
|
|
6
|
+
// rewording; the gcf-run skill makes a refusal a stop.
|
|
7
|
+
import { readFile } from 'node:fs/promises';
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import YAML from 'yaml';
|
|
11
|
+
import { commitMove } from './unit-ops.js';
|
|
12
|
+
import { atomicWrite } from './safe-path.js';
|
|
13
|
+
import { gcfRoot } from './gcf-paths.js';
|
|
14
|
+
|
|
15
|
+
// A shell command pattern turns into a rule for both shell tools: on Windows the agent runs
|
|
16
|
+
// commands through PowerShell, which Bash rules do not cover.
|
|
17
|
+
const shell = (...patterns) => patterns.flatMap((p) => [`Bash(${p})`, `PowerShell(${p})`]);
|
|
18
|
+
const files = (tools, ...globs) => globs.flatMap((g) => tools.map((t) => `${t}(${g})`));
|
|
19
|
+
|
|
20
|
+
/** @type {{ id: string, label: string, on: boolean, rules: string[] }[]} */
|
|
21
|
+
export const DENY_GROUPS = [
|
|
22
|
+
{
|
|
23
|
+
id: 'git-destroy',
|
|
24
|
+
label: 'git history and uncommitted work: reset --hard, clean, stash, force push',
|
|
25
|
+
on: true,
|
|
26
|
+
rules: shell(
|
|
27
|
+
'git reset --hard*',
|
|
28
|
+
'git clean*',
|
|
29
|
+
'git stash*',
|
|
30
|
+
'git branch -D*',
|
|
31
|
+
'git filter-branch*',
|
|
32
|
+
'git update-ref -d*',
|
|
33
|
+
'git push*--force*',
|
|
34
|
+
'git push -f*',
|
|
35
|
+
'git push -uf*',
|
|
36
|
+
'git push * -f',
|
|
37
|
+
'git push * -f *',
|
|
38
|
+
'git push *+*',
|
|
39
|
+
'git push*--mirror*',
|
|
40
|
+
'git push*--delete*',
|
|
41
|
+
'git checkout .',
|
|
42
|
+
'git checkout -- .',
|
|
43
|
+
'git restore .',
|
|
44
|
+
'git restore -- .',
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'mass-delete',
|
|
49
|
+
label: 'recursive delete: rm -r, Remove-Item -Recurse, rd /s',
|
|
50
|
+
on: true,
|
|
51
|
+
rules: shell(
|
|
52
|
+
'rm -r*',
|
|
53
|
+
'rm -R*',
|
|
54
|
+
'rm -fr*',
|
|
55
|
+
'rm -fR*',
|
|
56
|
+
'rm -f -r*',
|
|
57
|
+
'rm --recursive*',
|
|
58
|
+
'Remove-Item*-Recurse*',
|
|
59
|
+
'Remove-Item* -r',
|
|
60
|
+
'Remove-Item* -r *',
|
|
61
|
+
'rmdir /s*',
|
|
62
|
+
'rd /s*',
|
|
63
|
+
'del /s*',
|
|
64
|
+
'cmd /c rd /s*',
|
|
65
|
+
'cmd /c rmdir /s*',
|
|
66
|
+
'cmd /c del /s*',
|
|
67
|
+
),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'publish',
|
|
71
|
+
label: 'publishing: npm publish, stage, unpublish, deprecate; docker push',
|
|
72
|
+
on: true,
|
|
73
|
+
rules: shell('npm publish*', 'npm stage*', 'npm unpublish*', 'npm deprecate*', 'docker push*'),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'human-moves',
|
|
77
|
+
label:
|
|
78
|
+
"the human's GCF moves: verdict, decide, answer, unblock, phase, pillars, settings, permissions, setup",
|
|
79
|
+
on: true,
|
|
80
|
+
rules: shell(
|
|
81
|
+
'ai-factory gcf verdict*',
|
|
82
|
+
'ai-factory gcf decide*',
|
|
83
|
+
'ai-factory gcf question answer*',
|
|
84
|
+
'ai-factory gcf unblock*',
|
|
85
|
+
'ai-factory gcf phase next*',
|
|
86
|
+
'ai-factory gcf pillar*',
|
|
87
|
+
'ai-factory gcf permissions*',
|
|
88
|
+
'ai-factory gcf config set*',
|
|
89
|
+
'ai-factory gcf hooks-install*',
|
|
90
|
+
'ai-factory gcf-harness init*',
|
|
91
|
+
'ai-factory gcf-harness run*',
|
|
92
|
+
'ai-factory gcf-harness stop*',
|
|
93
|
+
'ai-factory extension*',
|
|
94
|
+
),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'guards',
|
|
98
|
+
label: 'the guards: .claude/, extension code, gcf/LIVE.md, gcf/.metrics/, the run files',
|
|
99
|
+
on: true,
|
|
100
|
+
rules: files(
|
|
101
|
+
['Edit', 'Write'],
|
|
102
|
+
'.claude/**',
|
|
103
|
+
'.ai-factory/extensions/**',
|
|
104
|
+
'gcf/LIVE.md',
|
|
105
|
+
'gcf/.metrics/**',
|
|
106
|
+
'.gcf-session/runs/**',
|
|
107
|
+
'.gcf-session/handoff.json',
|
|
108
|
+
),
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: 'secrets',
|
|
112
|
+
label: 'reading secrets: ~/.npmrc, ~/.ssh, ~/.claude.json, .env',
|
|
113
|
+
on: false,
|
|
114
|
+
rules: files(['Read'], '~/.npmrc', '~/.ssh/**', '~/.claude.json', '**/.env'),
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'outside',
|
|
118
|
+
label:
|
|
119
|
+
'changes outside the project: global installs, git config --global, setx, registry, shutdown',
|
|
120
|
+
on: false,
|
|
121
|
+
rules: shell(
|
|
122
|
+
'npm i -g*',
|
|
123
|
+
'npm install -g*',
|
|
124
|
+
'npm install --global*',
|
|
125
|
+
'git config --global*',
|
|
126
|
+
'setx*',
|
|
127
|
+
'reg add*',
|
|
128
|
+
'reg delete*',
|
|
129
|
+
'shutdown*',
|
|
130
|
+
'Restart-Computer*',
|
|
131
|
+
'Stop-Computer*',
|
|
132
|
+
),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: 'processes',
|
|
136
|
+
label: 'killing processes: taskkill, Stop-Process, kill',
|
|
137
|
+
on: false,
|
|
138
|
+
rules: shell('taskkill*', 'Stop-Process*', 'kill *', 'pkill*'),
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
const GROUP_IDS = DENY_GROUPS.map((g) => g.id);
|
|
143
|
+
// A permission rule: a tool name, optionally with a specifier — `Bash(npm test*)`, `Read`.
|
|
144
|
+
const RULE_RE = /^[A-Za-z_][\w-]*(\(.+\))?$/;
|
|
145
|
+
const known = (x) => GROUP_IDS.includes(x);
|
|
146
|
+
const rule = (x) => typeof x === 'string' && RULE_RE.test(x);
|
|
147
|
+
|
|
148
|
+
function rules(agent, key) {
|
|
149
|
+
const v = agent[key] ?? [];
|
|
150
|
+
if (!Array.isArray(v) || !v.every(rule))
|
|
151
|
+
throw new Error(`gcf/config.yml: agent.${key} must be a list of rules like Bash(cmd*) or Read`);
|
|
152
|
+
|
|
153
|
+
return v;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The groups the human chose: `agent.groups` maps a group id to true or false. A group it does
|
|
158
|
+
* not name keeps its default, so a group a later version adds on comes on in every project.
|
|
159
|
+
*/
|
|
160
|
+
function choices(agent) {
|
|
161
|
+
const g = agent.groups ?? {};
|
|
162
|
+
if (typeof g !== 'object' || Array.isArray(g))
|
|
163
|
+
throw new Error('gcf/config.yml: agent.groups must map a group id to true or false');
|
|
164
|
+
for (const [id, on] of Object.entries(g))
|
|
165
|
+
if (!known(id) || typeof on !== 'boolean')
|
|
166
|
+
throw new Error(
|
|
167
|
+
`gcf/config.yml: agent.groups.${id} must be true or false, for one of ${GROUP_IDS.join(' | ')}`,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
return g;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The `agent:` section resolved: each group on or off, the deny rules the run gets, the extra
|
|
175
|
+
* allow rules (for an agent run without bypass). No section: the default groups.
|
|
176
|
+
*/
|
|
177
|
+
export function agentOf(config) {
|
|
178
|
+
const agent = config.agent ?? {};
|
|
179
|
+
if (typeof agent !== 'object' || Array.isArray(agent))
|
|
180
|
+
throw new Error('gcf/config.yml: agent must be a mapping');
|
|
181
|
+
const chosen = choices(agent);
|
|
182
|
+
const extra = rules(agent, 'deny');
|
|
183
|
+
const allow = rules(agent, 'allow');
|
|
184
|
+
const groups = DENY_GROUPS.map((g) => ({ id: g.id, label: g.label, on: chosen[g.id] ?? g.on }));
|
|
185
|
+
const deny = [
|
|
186
|
+
...new Set([...DENY_GROUPS.filter((g, i) => groups[i].on).flatMap((g) => g.rules), ...extra]),
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
return { groups, deny_extra: extra, deny, allow };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Refuse a change that names no group, a group twice, a bad rule, or a rule it cannot remove. */
|
|
193
|
+
function checkChange(change, current) {
|
|
194
|
+
const on = change.on ?? [];
|
|
195
|
+
const off = change.off ?? [];
|
|
196
|
+
for (const id of [...on, ...off])
|
|
197
|
+
if (!known(id)) throw new Error(`no permission group ${id}: ${GROUP_IDS.join(' | ')}`);
|
|
198
|
+
const both = on.find((id) => off.includes(id));
|
|
199
|
+
if (both) throw new Error(`${both} is turned on and off at once`);
|
|
200
|
+
for (const r of [...(change.deny ?? []), ...(change.undeny ?? [])])
|
|
201
|
+
if (!rule(r)) throw new Error(`not a permission rule: ${r}`);
|
|
202
|
+
const missing = (change.undeny ?? []).find((r) => !current.deny_extra.includes(r));
|
|
203
|
+
if (missing) throw new Error(`${missing} is not one of your own deny rules: turn its group off`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Turn groups on or off, add or remove a custom rule; commit gcf(permissions). Only the
|
|
208
|
+
* `agent:` section changes: the rest of config.yml keeps its keys and comments. The file is
|
|
209
|
+
* read under the move's lock, so two changes at once both land.
|
|
210
|
+
*/
|
|
211
|
+
export async function setPermissions(projectDir, change, { commit = true } = {}) {
|
|
212
|
+
const file = path.join(gcfRoot(projectDir), 'config.yml');
|
|
213
|
+
let result;
|
|
214
|
+
const hash = await commitMove(projectDir, 'gcf(permissions): agent deny rules', {
|
|
215
|
+
files: [file],
|
|
216
|
+
mutate: async () => {
|
|
217
|
+
const doc = YAML.parseDocument(existsSync(file) ? await readFile(file, 'utf8') : '');
|
|
218
|
+
if (doc.errors.length) throw new Error(`gcf/config.yml: ${doc.errors[0].message}`);
|
|
219
|
+
if (!YAML.isMap(doc.contents)) doc.contents = doc.createNode({});
|
|
220
|
+
// A blank `agent:` (or one holding only comments) is no map yet.
|
|
221
|
+
const agent = doc.get('agent', true);
|
|
222
|
+
if (agent != null && !YAML.isMap(agent) && !(YAML.isScalar(agent) && agent.value == null))
|
|
223
|
+
throw new Error('gcf/config.yml: agent must be a mapping');
|
|
224
|
+
if (!YAML.isMap(agent)) doc.set('agent', doc.createNode({}));
|
|
225
|
+
const groups = doc.getIn(['agent', 'groups'], true);
|
|
226
|
+
if (groups != null && !YAML.isMap(groups) && !(YAML.isScalar(groups) && groups.value == null))
|
|
227
|
+
throw new Error('gcf/config.yml: agent.groups must map a group id to true or false');
|
|
228
|
+
if (!YAML.isMap(groups)) doc.setIn(['agent', 'groups'], doc.createNode({}));
|
|
229
|
+
const current = agentOf({ agent: doc.toJS().agent });
|
|
230
|
+
checkChange(change, current);
|
|
231
|
+
for (const id of change.on ?? []) doc.setIn(['agent', 'groups', id], true);
|
|
232
|
+
for (const id of change.off ?? []) doc.setIn(['agent', 'groups', id], false);
|
|
233
|
+
const deny = [...new Set([...current.deny_extra, ...(change.deny ?? [])])].filter(
|
|
234
|
+
(r) => !change.undeny?.includes(r),
|
|
235
|
+
);
|
|
236
|
+
doc.setIn(['agent', 'deny'], doc.createNode(deny, { flow: true }));
|
|
237
|
+
result = agentOf({ agent: doc.toJS().agent });
|
|
238
|
+
await atomicWrite(file, doc.toString());
|
|
239
|
+
},
|
|
240
|
+
commit,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
return { ...result, hash };
|
|
244
|
+
}
|
package/lib/board.js
CHANGED
|
@@ -4,7 +4,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { buildLedger } from './ledger.js';
|
|
7
|
-
import { readConfig } from './gcf-paths.js';
|
|
7
|
+
import { readConfig, readRawConfig } from './gcf-paths.js';
|
|
8
8
|
import { readLive } from './live.js';
|
|
9
9
|
import { listInbox } from './inbox.js';
|
|
10
10
|
import { phaseStatus } from './phase.js';
|
|
@@ -16,6 +16,8 @@ import { ITEM_TYPES } from './validate-item.js';
|
|
|
16
16
|
import { movesOf } from './transitions.js';
|
|
17
17
|
import { listQuestions } from './questions.js';
|
|
18
18
|
import { sessionActive } from './session-mark.js';
|
|
19
|
+
import { agentOf } from './agent-permissions.js';
|
|
20
|
+
import { settingsOf } from './config-set.js';
|
|
19
21
|
|
|
20
22
|
// The version of the JSON below (Methodology §11): a board refuses one it does not know. Bump it
|
|
21
23
|
// when a field changes meaning or goes away; a new field does not bump it.
|
|
@@ -128,11 +130,13 @@ async function resumeOf(projectDir, id) {
|
|
|
128
130
|
try {
|
|
129
131
|
const file = path.join(projectDir, '.gcf-session', 'runs', `${id}.agent.json`);
|
|
130
132
|
const rec = JSON.parse(await readFile(file, 'utf8'));
|
|
131
|
-
|
|
133
|
+
// A handoff needs no session: the next run starts a fresh one from the plan.
|
|
134
|
+
if (typeof rec?.session_id !== 'string' && rec?.ended !== 'handoff') return null;
|
|
132
135
|
|
|
133
136
|
return {
|
|
134
137
|
ended: String(rec.ended ?? ''),
|
|
135
138
|
...(rec.resets ? { resets: String(rec.resets) } : {}),
|
|
139
|
+
...(rec.handoffs ? { handoffs: Number(rec.handoffs) } : {}),
|
|
136
140
|
};
|
|
137
141
|
} catch {
|
|
138
142
|
return null;
|
|
@@ -227,6 +231,15 @@ export async function board(projectDir) {
|
|
|
227
231
|
return {
|
|
228
232
|
schema: BOARD_SCHEMA,
|
|
229
233
|
run_mode: config.run_mode,
|
|
234
|
+
// What the harness hands its agent runs (Harness-PRD §7): the deny rules and the context limits.
|
|
235
|
+
agent: agentOf(config),
|
|
236
|
+
// The human's settings of config.yml, each with its value and default (`gcf config set`).
|
|
237
|
+
settings: settingsOf(await readRawConfig(root)),
|
|
238
|
+
context: {
|
|
239
|
+
handoff_pct: config.context_handoff_pct,
|
|
240
|
+
window: config.context_window,
|
|
241
|
+
compact_pct: config.auto_compact_pct,
|
|
242
|
+
},
|
|
230
243
|
phase: await phaseOf(projectDir),
|
|
231
244
|
// A malformed block reads with fields missing (live check names it): null, not absent.
|
|
232
245
|
release: releaseOf(live.release),
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// `gcf config set` (GCF-PRD §12.4): the human's settings of gcf/config.yml, one key at a time,
|
|
2
|
+
// so a board edits them through the core and never writes the file itself. A change is checked
|
|
3
|
+
// by the same rules a read applies before it is written; the rest of the file keeps its keys
|
|
4
|
+
// and comments. `phases:` and `agent:` have their own commands and are not set here.
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
9
|
+
import YAML from 'yaml';
|
|
10
|
+
import { commitMove } from './unit-ops.js';
|
|
11
|
+
import { atomicWrite } from './safe-path.js';
|
|
12
|
+
import { configOf, DEFAULT_CONFIG, gcfRoot, RUN_MODES } from './gcf-paths.js';
|
|
13
|
+
|
|
14
|
+
/** @typedef {'number' | 'share' | 'mode' | 'command'} Kind */
|
|
15
|
+
|
|
16
|
+
// Thrown inside the move to leave without a write or a commit.
|
|
17
|
+
const NO_CHANGE = new Error('no change');
|
|
18
|
+
|
|
19
|
+
/** @type {{ key: string, kind: Kind, label: string }[]} */
|
|
20
|
+
export const SETTINGS = [
|
|
21
|
+
{
|
|
22
|
+
key: 'run_mode',
|
|
23
|
+
kind: 'mode',
|
|
24
|
+
label:
|
|
25
|
+
'how a run drives an item: worktree (several at once) or main (one at a time in the project folder)',
|
|
26
|
+
},
|
|
27
|
+
{ key: 'dod.test', kind: 'command', label: "the project's test command for the DoD, or none" },
|
|
28
|
+
{ key: 'dod.build', kind: 'command', label: "the project's build command for the DoD, or none" },
|
|
29
|
+
{
|
|
30
|
+
key: 'plan_passes',
|
|
31
|
+
kind: 'number',
|
|
32
|
+
label: 'improve passes a plan may take before the item blocks',
|
|
33
|
+
},
|
|
34
|
+
{ key: 'dod_attempts', kind: 'number', label: 'DoD attempts before the item blocks' },
|
|
35
|
+
{
|
|
36
|
+
key: 'wip_built_limit',
|
|
37
|
+
kind: 'number',
|
|
38
|
+
label: 'items waiting for a verdict before new verdict work stops',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: 'context_handoff_pct',
|
|
42
|
+
kind: 'share',
|
|
43
|
+
label:
|
|
44
|
+
'share of the context window at which a session hands its item to a fresh one (0: never)',
|
|
45
|
+
},
|
|
46
|
+
{ key: 'context_window', kind: 'number', label: "context window in tokens (0: the model's)" },
|
|
47
|
+
{
|
|
48
|
+
key: 'auto_compact_pct',
|
|
49
|
+
kind: 'share',
|
|
50
|
+
label: 'share at which the agent compacts (0: its default; at least the handoff share + 15)',
|
|
51
|
+
},
|
|
52
|
+
{ key: 'tune_limit', kind: 'number', label: 'tune verdicts an item may take' },
|
|
53
|
+
{ key: 'unplayed_warn_after', kind: 'number', label: 'unplayed items before the audit warns' },
|
|
54
|
+
{
|
|
55
|
+
key: 'built_stale_after_commits',
|
|
56
|
+
kind: 'number',
|
|
57
|
+
label: 'commits after which a waiting or blocked item is stale',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: 'question_stale_after_commits',
|
|
61
|
+
kind: 'number',
|
|
62
|
+
label: 'commits after which an open question is stale',
|
|
63
|
+
},
|
|
64
|
+
{ key: 'context_budget', kind: 'number', label: "token budget of an item's readset" },
|
|
65
|
+
{ key: 'pillars_budget', kind: 'number', label: 'token budget of PILLARS.md' },
|
|
66
|
+
{
|
|
67
|
+
key: 'envelope_default_spread',
|
|
68
|
+
kind: 'number',
|
|
69
|
+
label: 'default spread of a feel envelope around a GDD number (0.3: ±30%)',
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
const BY_KEY = new Map(SETTINGS.map((s) => [s.key, s]));
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Each setting with what the file sets (null: not set, the default holds) and its default:
|
|
77
|
+
* what a settings screen shows. `raw` is the parsed config.yml, before the defaults.
|
|
78
|
+
*/
|
|
79
|
+
export function settingsOf(raw) {
|
|
80
|
+
return SETTINGS.map((s) => {
|
|
81
|
+
const [head, sub] = s.key.split('.');
|
|
82
|
+
const parent = raw?.[head];
|
|
83
|
+
const value = sub
|
|
84
|
+
? parent && typeof parent === 'object'
|
|
85
|
+
? (parent[sub] ?? null)
|
|
86
|
+
: null
|
|
87
|
+
: (parent ?? null);
|
|
88
|
+
const def = sub ? null : head === 'run_mode' ? 'worktree' : (DEFAULT_CONFIG[head] ?? null);
|
|
89
|
+
|
|
90
|
+
return { ...s, value, default: def };
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The value of `text` for a setting of `kind`; an empty number goes back to its default. */
|
|
95
|
+
function valueOf(setting, text) {
|
|
96
|
+
const t = String(text ?? '').trim();
|
|
97
|
+
if (setting.kind === 'command') {
|
|
98
|
+
if (!t) throw new Error(`${setting.key}: name the command, or none`);
|
|
99
|
+
|
|
100
|
+
return t;
|
|
101
|
+
}
|
|
102
|
+
if (setting.kind === 'mode') {
|
|
103
|
+
if (!RUN_MODES.includes(t)) throw new Error(`run_mode must be ${RUN_MODES.join(' | ')}`);
|
|
104
|
+
|
|
105
|
+
return t;
|
|
106
|
+
}
|
|
107
|
+
if (!t) return null;
|
|
108
|
+
// Plain decimals only: Number() would also take 0x10, 1e3 and 0b1.
|
|
109
|
+
if (!/^\d+(\.\d+)?$/.test(t)) throw new Error(`${setting.key} must be a number, got ${t}`);
|
|
110
|
+
const n = Number(t);
|
|
111
|
+
if (!Number.isFinite(n)) throw new Error(`${setting.key} must be a number, got ${t}`);
|
|
112
|
+
|
|
113
|
+
return n;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Set one key of gcf/config.yml and commit gcf(config); a number set to nothing goes back to
|
|
118
|
+
* its default. The file is read and checked under the move's lock.
|
|
119
|
+
*/
|
|
120
|
+
export async function setConfig(projectDir, key, text, { commit = true } = {}) {
|
|
121
|
+
const setting = BY_KEY.get(key);
|
|
122
|
+
if (!setting) throw new Error(`no setting ${key}: ${SETTINGS.map((s) => s.key).join(' | ')}`);
|
|
123
|
+
const value = valueOf(setting, text);
|
|
124
|
+
const file = path.join(gcfRoot(projectDir), 'config.yml');
|
|
125
|
+
const keys = key.split('.');
|
|
126
|
+
let raw;
|
|
127
|
+
// A change that changes nothing (the same value, a reset of a key not set) commits nothing.
|
|
128
|
+
let unchanged = false;
|
|
129
|
+
const hash = await commitMove(projectDir, `gcf(config): ${key}`, {
|
|
130
|
+
files: [file],
|
|
131
|
+
mutate: async () => {
|
|
132
|
+
const text = existsSync(file) ? await readFile(file, 'utf8') : '';
|
|
133
|
+
const doc = YAML.parseDocument(text);
|
|
134
|
+
if (doc.errors.length) throw new Error(`gcf/config.yml: ${doc.errors[0].message}`);
|
|
135
|
+
if (!YAML.isMap(doc.contents)) doc.contents = doc.createNode({});
|
|
136
|
+
// A blank parent (`dod:` with nothing under it) is no map yet.
|
|
137
|
+
if (keys.length > 1) {
|
|
138
|
+
const parent = doc.get(keys[0], true);
|
|
139
|
+
if (
|
|
140
|
+
parent != null &&
|
|
141
|
+
!YAML.isMap(parent) &&
|
|
142
|
+
!(YAML.isScalar(parent) && parent.value == null)
|
|
143
|
+
)
|
|
144
|
+
throw new Error(`gcf/config.yml: ${keys[0]} must map its keys`);
|
|
145
|
+
if (!YAML.isMap(parent)) doc.set(keys[0], doc.createNode({}));
|
|
146
|
+
}
|
|
147
|
+
if (value === null) doc.deleteIn(keys);
|
|
148
|
+
else doc.setIn(keys, value);
|
|
149
|
+
raw = doc.toJS();
|
|
150
|
+
configOf(raw);
|
|
151
|
+
const out = doc.toString();
|
|
152
|
+
// The values, not the text: YAML's output may differ in form (a final newline, `{}`).
|
|
153
|
+
if (isDeepStrictEqual(YAML.parse(text) ?? {}, raw ?? {})) {
|
|
154
|
+
unchanged = true;
|
|
155
|
+
throw NO_CHANGE;
|
|
156
|
+
}
|
|
157
|
+
await atomicWrite(file, out);
|
|
158
|
+
},
|
|
159
|
+
commit,
|
|
160
|
+
}).catch((e) => {
|
|
161
|
+
if (e !== NO_CHANGE) throw e;
|
|
162
|
+
|
|
163
|
+
return null;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return { key, value, unchanged, settings: settingsOf(raw), hash };
|
|
167
|
+
}
|
package/lib/gcf-paths.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import YAML from 'yaml';
|
|
5
5
|
import { parse } from './frontmatter.js';
|
|
6
6
|
|
|
7
|
-
const DEFAULT_CONFIG = {
|
|
7
|
+
export const DEFAULT_CONFIG = {
|
|
8
8
|
schema: 1,
|
|
9
9
|
built_stale_after_commits: 5,
|
|
10
10
|
tune_limit: 3,
|
|
@@ -16,8 +16,16 @@ const DEFAULT_CONFIG = {
|
|
|
16
16
|
unplayed_warn_after: 5,
|
|
17
17
|
plan_passes: 5,
|
|
18
18
|
dod_attempts: 2,
|
|
19
|
+
// A run hands its item to a fresh session at this share of the context window (0: never);
|
|
20
|
+
// the window comes from the model unless context_window sets it (Harness-PRD §7).
|
|
21
|
+
context_handoff_pct: 60,
|
|
22
|
+
context_window: 0,
|
|
23
|
+
// CLAUDE_AUTOCOMPACT_PCT_OVERRIDE for the run (0: the agent's own default).
|
|
24
|
+
auto_compact_pct: 0,
|
|
19
25
|
};
|
|
20
26
|
|
|
27
|
+
const PCT_KEYS = ['context_handoff_pct', 'auto_compact_pct'];
|
|
28
|
+
|
|
21
29
|
/** `gcf/` lives at the repository root (GCF-PRD §5.1). Throws when absent. */
|
|
22
30
|
export function gcfRoot(projectDir = process.cwd()) {
|
|
23
31
|
const root = path.join(path.resolve(projectDir), 'gcf');
|
|
@@ -40,17 +48,24 @@ function runModeOf(v = 'worktree') {
|
|
|
40
48
|
|
|
41
49
|
/** @returns {Promise<Record<string, any>>} */
|
|
42
50
|
export async function readConfig(root) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return { ...config, run_mode: runModeOf(config.run_mode) };
|
|
51
|
+
return configOf(await readRawConfig(root));
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
/**
|
|
49
|
-
async function
|
|
54
|
+
/** config.yml as the file has it, before the defaults: `{}` when there is none. */
|
|
55
|
+
export async function readRawConfig(root) {
|
|
50
56
|
const file = path.join(root, 'config.yml');
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
|
|
58
|
+
return existsSync(file) ? (YAML.parse(await readFile(file, 'utf8')) ?? {}) : {};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The config a parsed config.yml gives, checked: defaults for what it does not set, every limit
|
|
63
|
+
* a non-negative number, the shares 0-100, the run mode one of RUN_MODES. Throws on the first
|
|
64
|
+
* key that breaks a rule. `gcf config set` checks a change with it before it writes.
|
|
65
|
+
* @returns {Record<string, any>}
|
|
66
|
+
*/
|
|
67
|
+
export function configOf(parsed) {
|
|
68
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
54
69
|
throw new Error('gcf/config.yml must be a key: value mapping');
|
|
55
70
|
// A blank `key:` parses as null and means "not set", like an absent key.
|
|
56
71
|
const config = {
|
|
@@ -66,8 +81,18 @@ async function readNumbers(root) {
|
|
|
66
81
|
);
|
|
67
82
|
}
|
|
68
83
|
}
|
|
84
|
+
for (const key of PCT_KEYS)
|
|
85
|
+
if (config[key] > 100)
|
|
86
|
+
throw new Error(`gcf/config.yml: ${key} is a share of the window, 0-100, got ${config[key]}`);
|
|
87
|
+
// A compaction before the handoff threshold shrinks the context the handoff waits for.
|
|
88
|
+
const { auto_compact_pct: compact, context_handoff_pct: handoff } = config;
|
|
89
|
+
if (compact && handoff && compact < handoff + 15)
|
|
90
|
+
throw new Error(
|
|
91
|
+
`gcf/config.yml: auto_compact_pct ${compact} must be at least context_handoff_pct + 15 ` +
|
|
92
|
+
`(${handoff + 15}), or the compaction comes before the handoff`,
|
|
93
|
+
);
|
|
69
94
|
|
|
70
|
-
return config;
|
|
95
|
+
return { ...config, run_mode: runModeOf(config.run_mode) };
|
|
71
96
|
}
|
|
72
97
|
|
|
73
98
|
/** Token estimate: ceil(chars/4). Stability over accuracy (GCF-PRD §9.1). */
|
package/lib/questions.js
CHANGED
|
@@ -8,7 +8,20 @@ import path from 'node:path';
|
|
|
8
8
|
import { atomicWrite } from './safe-path.js';
|
|
9
9
|
import { commitMove } from './unit-ops.js';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// A D2 carries its assumption and the trigger that brings it back; `lens`, `sections` and `sys`
|
|
12
|
+
// say where a record came from: an import names its lens and the GDD sections.
|
|
13
|
+
const FIELDS = [
|
|
14
|
+
'class',
|
|
15
|
+
'question',
|
|
16
|
+
'proposed',
|
|
17
|
+
'blocks',
|
|
18
|
+
'answer',
|
|
19
|
+
'assumed',
|
|
20
|
+
'until',
|
|
21
|
+
'sys',
|
|
22
|
+
'lens',
|
|
23
|
+
'sections',
|
|
24
|
+
];
|
|
12
25
|
|
|
13
26
|
const fileOf = (root) => path.join(root, 'open-questions.md');
|
|
14
27
|
|
package/package.json
CHANGED
|
@@ -28,6 +28,8 @@ gcf_forbidden:
|
|
|
28
28
|
- do not give a verdict or a decision: `verdict` and `decide` belong to the human, through the gcf-verdict skill
|
|
29
29
|
- do not answer a `TBD` of a design unit yourself: ask the human and offer your draft as the proposed answer
|
|
30
30
|
- do not run `ai-factory gcf phase next`: the phase moves on the human's word only
|
|
31
|
+
- do not change what agent runs may do: `ai-factory gcf permissions` and its deny groups belong to the human
|
|
32
|
+
- do not change a setting of `gcf/config.yml`: `ai-factory gcf config set` belongs to the human
|
|
31
33
|
- do not reuse an ended id: rework gets a new id with `reopens: <old id>`
|
|
32
34
|
- do not commit past the gate with `--no-verify`: a refused commit names what to fix
|
|
33
35
|
|
package/templates/config.yml
CHANGED
|
@@ -9,6 +9,14 @@ envelope_default_spread: 0.3
|
|
|
9
9
|
unplayed_warn_after: 5
|
|
10
10
|
plan_passes: 5
|
|
11
11
|
dod_attempts: 2
|
|
12
|
+
# Agent runs (Harness-PRD §7): the share of the context window at which a run hands its item
|
|
13
|
+
# to a fresh session (0: never), the window when the model's is unknown (0: the model's), and
|
|
14
|
+
# the agent's auto-compaction share (0: its default; at least the handoff share + 15).
|
|
15
|
+
context_handoff_pct: 60
|
|
16
|
+
context_window: 0
|
|
17
|
+
auto_compact_pct: 0
|
|
18
|
+
# What agent runs may not do lives in an `agent:` section that `ai-factory gcf permissions`
|
|
19
|
+
# and the board write; without it the default deny groups hold.
|
|
12
20
|
# The project's own commands for the auto DoD (Methodology §6); the engine does not matter.
|
|
13
21
|
# gcf verify fails on an empty one; `none` says the project has no such step.
|
|
14
22
|
# Phases (Methodology §10) come from code; a `phases:` list here replaces the whole set.
|