gcf-aif-ext 0.7.6 → 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 CHANGED
@@ -50,6 +50,11 @@ 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
+
53
58
  ### 0.7.6
54
59
 
55
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`).
package/commands/gcf.js CHANGED
@@ -977,6 +977,37 @@ 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
+ });
980
1011
  const many = (v, prev = []) => [...prev, v];
981
1012
  gcf
982
1013
  .command('permissions')
package/extension.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/lee-to/ai-factory/2.x/schemas/extension.schema.json",
3
3
  "name": "gcf-aif-ext",
4
- "version": "0.7.6",
4
+ "version": "0.7.7",
5
5
  "description": "Game Context Framework for AI Factory",
6
6
  "skills": [
7
7
  "skills/gcf-init",
@@ -75,7 +75,7 @@ export const DENY_GROUPS = [
75
75
  {
76
76
  id: 'human-moves',
77
77
  label:
78
- "the human's GCF moves: verdict, decide, answer, unblock, phase, pillars, permissions, setup",
78
+ "the human's GCF moves: verdict, decide, answer, unblock, phase, pillars, settings, permissions, setup",
79
79
  on: true,
80
80
  rules: shell(
81
81
  'ai-factory gcf verdict*',
@@ -85,6 +85,7 @@ export const DENY_GROUPS = [
85
85
  'ai-factory gcf phase next*',
86
86
  'ai-factory gcf pillar*',
87
87
  'ai-factory gcf permissions*',
88
+ 'ai-factory gcf config set*',
88
89
  'ai-factory gcf hooks-install*',
89
90
  'ai-factory gcf-harness init*',
90
91
  'ai-factory gcf-harness run*',
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';
@@ -17,6 +17,7 @@ import { movesOf } from './transitions.js';
17
17
  import { listQuestions } from './questions.js';
18
18
  import { sessionActive } from './session-mark.js';
19
19
  import { agentOf } from './agent-permissions.js';
20
+ import { settingsOf } from './config-set.js';
20
21
 
21
22
  // The version of the JSON below (Methodology §11): a board refuses one it does not know. Bump it
22
23
  // when a field changes meaning or goes away; a new field does not bump it.
@@ -232,6 +233,8 @@ export async function board(projectDir) {
232
233
  run_mode: config.run_mode,
233
234
  // What the harness hands its agent runs (Harness-PRD §7): the deny rules and the context limits.
234
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)),
235
238
  context: {
236
239
  handoff_pct: config.context_handoff_pct,
237
240
  window: config.context_window,
@@ -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,
@@ -48,27 +48,24 @@ function runModeOf(v = 'worktree') {
48
48
 
49
49
  /** @returns {Promise<Record<string, any>>} */
50
50
  export async function readConfig(root) {
51
- const config = await readNumbers(root);
52
- for (const key of PCT_KEYS)
53
- if (config[key] > 100)
54
- throw new Error(`gcf/config.yml: ${key} is a share of the window, 0-100, got ${config[key]}`);
55
- // A compaction before the handoff threshold shrinks the context the handoff waits for.
56
- const { auto_compact_pct: compact, context_handoff_pct: handoff } = config;
57
- if (compact && handoff && compact < handoff + 15)
58
- throw new Error(
59
- `gcf/config.yml: auto_compact_pct ${compact} must be at least context_handoff_pct + 15 ` +
60
- `(${handoff + 15}), or the compaction comes before the handoff`,
61
- );
62
-
63
- return { ...config, run_mode: runModeOf(config.run_mode) };
51
+ return configOf(await readRawConfig(root));
64
52
  }
65
53
 
66
- /** @returns {Promise<Record<string, any>>} */
67
- async function readNumbers(root) {
54
+ /** config.yml as the file has it, before the defaults: `{}` when there is none. */
55
+ export async function readRawConfig(root) {
68
56
  const file = path.join(root, 'config.yml');
69
- if (!existsSync(file)) return { ...DEFAULT_CONFIG };
70
- const parsed = YAML.parse(await readFile(file, 'utf8')) ?? {};
71
- if (typeof parsed !== 'object' || Array.isArray(parsed))
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))
72
69
  throw new Error('gcf/config.yml must be a key: value mapping');
73
70
  // A blank `key:` parses as null and means "not set", like an absent key.
74
71
  const config = {
@@ -84,8 +81,18 @@ async function readNumbers(root) {
84
81
  );
85
82
  }
86
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
+ );
87
94
 
88
- return config;
95
+ return { ...config, run_mode: runModeOf(config.run_mode) };
89
96
  }
90
97
 
91
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
- const FIELDS = ['class', 'question', 'proposed', 'blocks', 'answer'];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-aif-ext",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "description": "Game Context Framework for AI Factory",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,6 +29,7 @@ gcf_forbidden:
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
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
32
33
  - do not reuse an ended id: rework gets a new id with `reopens: <old id>`
33
34
  - do not commit past the gate with `--no-verify`: a refused commit names what to fix
34
35