gcf-harness-aif-ext 0.28.1 → 0.31.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 +6 -3
- package/commands/codex-review.js +132 -0
- package/commands/harness.js +119 -20
- package/commands/milestones.js +23 -2
- package/commands/run.js +124 -28
- package/extension.json +1 -1
- package/node_modules/gcf-session/lib/activity.js +6 -2
- package/node_modules/gcf-session/lib/adapter/claude.js +1 -1
- package/node_modules/gcf-session/lib/adapter/codex.js +137 -0
- package/node_modules/gcf-session/lib/chat-input.js +14 -1
- package/node_modules/gcf-session/lib/chat.js +14 -2
- package/node_modules/gcf-session/lib/cli.js +7 -2
- package/node_modules/gcf-session/lib/index.js +10 -0
- package/node_modules/gcf-session/lib/job.js +93 -15
- package/node_modules/gcf-session/lib/limit.js +9 -5
- package/node_modules/gcf-session/lib/thread.js +5 -4
- package/node_modules/gcf-session/lib/usage.js +19 -4
- package/node_modules/gcf-session/lib/wake.js +141 -0
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +52 -2
- package/package.json +3 -3
- package/skills/gcf-run/SKILL.md +30 -10
- package/commands/plan-review.js +0 -95
- /package/commands/{plan-review.schema.json → codex-review.schema.json} +0 -0
package/README.md
CHANGED
|
@@ -43,6 +43,8 @@ ai-factory extension update gcf-harness-aif-ext
|
|
|
43
43
|
|
|
44
44
|
Updating keeps the hook entry valid — it points into the extension's install directory, which an update refreshes in place.
|
|
45
45
|
|
|
46
|
+
0.31.0 needs gcf-aif-ext 0.32 (docs/Fallback-Fidelity-Plan.md): update both together with gcf-board 0.32.0 (`gcf board --json` is `schema: 6`), then run `ai-factory gcf init`. `run_mode` is `main` by default now; set `run_mode: worktree` to keep parallel runs. Without `--mode` an item runs where the core says (`runs_in`): its own `run_mode`, else where its kept session ran (the record `<id>.agent.json` now carries `mode`; `--fresh` drops the session, not that place), else `worktree` while its worktree copy or `work/<id>` branch lives, else the project's. A review row that cannot make its pass (codex-review `failed`, `skipped` for no Codex, the Agent tool's refusal, a subagent with no answer or at its usage limit) gives way to the next of its `fallback`, then to the session's own model; the pass records `--by <who> --for <the row>`. A subagent's usage limit no longer stops the session (bundled gcf-session).
|
|
47
|
+
|
|
46
48
|
0.25.1 changes nothing but the peer range: it runs with `gcf-aif-ext` 0.26 and 0.27.
|
|
47
49
|
|
|
48
50
|
0.23.0 needs `gcf-aif-ext` 0.24: a main batch goes on past a card that left code, the next claim moving it to `work/<id>`. It still stops with `left` when no baseline stands or the shelve is refused. A returning card's first message says what came back and which conflicts to resolve first; `gate --each`'s `dirty` leaves out the paths of the card in the folder; a run's report names `shelved`, `returned` and `conflicts`.
|
|
@@ -131,7 +133,7 @@ Updating keeps the hook entry valid — it points into the extension's install d
|
|
|
131
133
|
- `/gcf-run` writes a plan task's code through aif-implement, so the plan ticks show the item's progress, and answers aif-implement's questions itself: no commit, stash or merge.
|
|
132
134
|
|
|
133
135
|
0.8.0, to update together with core 0.7.0:
|
|
134
|
-
- `run_mode: main` in `gcf/config.yml` (or `run --mode main
|
|
136
|
+
- `run_mode: main` in `gcf/config.yml` (or `run --mode main`; the default since 0.31.0): items run one after another in the main checkout, for an agent that works through an editor bound to the project folder. The item carries the core's session mark (`gcf claim`), not a run lock, so the agent records its own move; one run works the checkout at a time (`.gcf-session/runs/.main-run.lock`).
|
|
135
137
|
- `gcf-harness next [N] --json`: the ready items that can run together now, by priority; each is taken while the batch with it passes the gate.
|
|
136
138
|
- `gcf-harness stop <id>`: stops the session that works the item (its run lock names it); the run records no result for it and goes on with the rest. The item stays ready and its work is kept. Known limit: the session is killed at once, so a `gcf` move it was in the middle of may leave `.gcf-session/main.lock` behind (taken over once its pid is gone).
|
|
137
139
|
- A run on main refreshes its item's mark every 5 minutes while the mark is its own, and the readset-guard hook refreshes live marks on each read: a long build without a gcf command does not expire it.
|
|
@@ -160,7 +162,7 @@ Removal does not touch `.claude/settings.json`: delete the entries whose command
|
|
|
160
162
|
|
|
161
163
|
**`ai-factory gcf-harness gate <item-id…>`** — the `/gcf-run` gate as code (`--each`: each item alone, see 0.14.0 above). It reads one `gcf audit --json` report and exits 1 with a one-line reason when the items may not go: a core older than 0.4.0, a `schema:` other than 1 in `gcf/config.yml`, an id with no work item, a feature (run its children; the feature closes when they are finished), an item that is not `ready`, an unplayed dependency, no WIP room for the batch (items awaiting a verdict + the batch's `gate: verdict` items over `wip_built_limit`), or two items of the batch touching the same system unless both say `parallel: ok`. The tune limit is not a gate rule: `verdict tune` itself refuses at the limit, and an item tuned up to it still gets its last build. The skill runs it and stops on a non-zero exit — no model compares the numbers.
|
|
162
164
|
|
|
163
|
-
**`ai-factory gcf-harness run <item-id…> [--agent "<cmd>"]`** — runs a batch at once, each item in its own worktree (`gcf worktree <id>`) with its own agent session: `claude -p --output-format stream-json --verbose "/gcf-run <id> --worktree"` by default, or the command in `--agent` / `GCF_RUN_AGENT`. The sessions run unattended, so set the agent's permissions for print mode first. A session ends with a commit and `gcf verify <id> --mark` (the `GCF-Verified` trailer); a question for the human goes into `.gcf-session/outcome.json` in its worktree, and `run` records the block on main. Then `gcf integrate` merges the verified branches and records each move, and `run` prints the playtest session. Its first step, like `/gcf-run`'s, integrates the verified branches a dead run left. A session that ended with no result leaves its item `ready`; the next `run` resumes its worktree and the agent's own session (`--resume <session_id>`, kept in `.gcf-session/runs/<id>.agent.json`), in either run mode; `--fresh` starts a new session instead. A session cut off by Claude's usage limit reports `paused (usage limit, resets 3am (…))` and `limit_resets`. Logs: `.gcf-session/runs/<id>.log`, written as the session works: a `start:` line, then one stamped line per agent message, tool call (`tool: Edit <file>`, `tool: Bash <command>`) and failed tool result, and at the end the agent's final text and `done in 34m, 212 turns, $3.41 (…tokens)`; stderr goes in as it is, and a non-Claude `--agent` keeps its own lines. With `--json`, each item carries the session's `cost_usd`, `tokens`, `turns` and `duration_ms` when the agent reported them, what it ran on (`model`, `effort`; null: the agent's own) and `log: {from, to}`, the bytes of its log this run wrote. `--model <m>` and `--effort <e>` set the model and effort of every item for this run only, over the item's own `model:` and `effort:` (`default` or none: the item's); the item file is not changed. A run sets `GCF_MOVE_BY=run` for its core calls and every agent it starts, in either mode, so the core's moves name the run as their maker. One run drives an item at a time (`.gcf-session/runs/<id>.lock`), and a resumed worktree first gets main merged in, so the answer from an `unblock` reaches the session. A worktree sees only what is committed: keep `.ai-factory.json`, the installed extensions with their `node_modules` (a `node_modules/` line in `.gitignore` drops the core's `yaml` and `cnlp-kit`, and `ai-factory gcf` fails in the worktree) and `.claude/` (skills, the readset-guard hook) in git, or the session has no `/gcf-run` and no `ai-factory gcf`. On Windows a project in a deep folder needs `git config core.longpaths true`, or `git worktree add` fails on `Filename too long`.
|
|
165
|
+
**`ai-factory gcf-harness run <item-id…> [--agent "<cmd>"]`** — runs a batch; under `run_mode: worktree` (or `--mode worktree`, or for a card whose worktree copy lives) at once, each item in its own worktree (`gcf worktree <id>`) with its own agent session: `claude -p --output-format stream-json --verbose "/gcf-run <id> --worktree"` by default, or the command in `--agent` / `GCF_RUN_AGENT`. The sessions run unattended, so set the agent's permissions for print mode first. A session ends with a commit and `gcf verify <id> --mark` (the `GCF-Verified` trailer); a question for the human goes into `.gcf-session/outcome.json` in its worktree, and `run` records the block on main. Then `gcf integrate` merges the verified branches and records each move, and `run` prints the playtest session. Its first step, like `/gcf-run`'s, integrates the verified branches a dead run left. A session that ended with no result leaves its item `ready`; the next `run` resumes its worktree and the agent's own session (`--resume <session_id>`, kept in `.gcf-session/runs/<id>.agent.json`), in either run mode; `--fresh` starts a new session instead. A session cut off by Claude's usage limit reports `paused (usage limit, resets 3am (…))` and `limit_resets`. Logs: `.gcf-session/runs/<id>.log`, written as the session works: a `start:` line, then one stamped line per agent message, tool call (`tool: Edit <file>`, `tool: Bash <command>`) and failed tool result, and at the end the agent's final text and `done in 34m, 212 turns, $3.41 (…tokens)`; stderr goes in as it is, and a non-Claude `--agent` keeps its own lines. With `--json`, each item carries the session's `cost_usd`, `tokens`, `turns` and `duration_ms` when the agent reported them, what it ran on (`model`, `effort`; null: the agent's own) and `log: {from, to}`, the bytes of its log this run wrote. `--model <m>` and `--effort <e>` set the model and effort of every item for this run only, over the item's own `model:` and `effort:` (`default` or none: the item's); the item file is not changed. A run sets `GCF_MOVE_BY=run` for its core calls and every agent it starts, in either mode, so the core's moves name the run as their maker. One run drives an item at a time (`.gcf-session/runs/<id>.lock`), and a resumed worktree first gets main merged in, so the answer from an `unblock` reaches the session. A worktree sees only what is committed: keep `.ai-factory.json`, the installed extensions with their `node_modules` (a `node_modules/` line in `.gitignore` drops the core's `yaml` and `cnlp-kit`, and `ai-factory gcf` fails in the worktree) and `.claude/` (skills, the readset-guard hook) in git, or the session has no `/gcf-run` and no `ai-factory gcf`. On Windows a project in a deep folder needs `git config core.longpaths true`, or `git worktree add` fails on `Filename too long`.
|
|
164
166
|
|
|
165
167
|
**`ai-factory gcf-harness metrics [--since <date>] [--json]`** — the run metrics of Harness-PRD §11 from `gcf/.metrics`: how many item runs reached `submit` or `close` (a run the usage limit paused or a session cut short does not count as finished), the block reasons, what the runs cost (dollars, minutes, turns, handoffs, code written outside aif-implement), the plan checks per item (the improve passes), the DoD attempts per item and the checks that failed them, and the guard firings by hook and by item. The logs: `run-log.csv` (one line per item of each `run`: `at, item, mode, result, reason, cost_usd, input, output, cache_read, turns, duration_ms, handoffs, process, run_id, started, model, effort, log_from, log_to`; `result` is `submit`, `close`, `block`, `error`, `conflict`, `skipped`, `paused` for the usage limit, `no-result` for a session cut short, `not-started`; `run_id` is `<started>-<pid>` of the run; `model` and `effort` what the item ran on, empty for the agent's own; `log_from`, `log_to` the bytes of `.gcf-session/runs/<id>.log` this run wrote; older lines end at `process`), `guard-log.csv` (each denial of readset-guard and implement-guard, by hook: `readset`, `implement`, or `verify` for a move past the verify gate), and the core's `plan-log.csv` and `verify-log.csv`. A worktree session's lines go to the main checkout's logs; the next `gcf integrate` commits them.
|
|
166
168
|
|
|
@@ -176,7 +178,8 @@ Removal does not touch `.claude/settings.json`: delete the entries whose command
|
|
|
176
178
|
|
|
177
179
|
- `gcf-harness hold <id>` holds an item: its session hands over at its next call, its work waits `ready`, and your Run goes on from the plan. `hold --project` holds the queue and the autopilot (your own Run still goes); `hold --release [<id>]` lets go.
|
|
178
180
|
- Automation (`--wait-limit`, the autopilot's card sessions) keeps `quota_reserve_pct` of each usage window (`~/.gcf/settings.json`, 10): it waits for the 5-hour reset, and stops at the week's.
|
|
179
|
-
-
|
|
181
|
+
- `gcf-harness wake <id>` (or `--thread <t>`, or `--all`): the usage limit was reset early, so a live limit or reserve wait goes on now; it marks only a wait that lives. A fresh `/usage` reading under the limit wakes a wait too (automation reads it every 5 minutes; your own Run and a chat thread ask it themselves). A wake before the reset spends no try; the operator's wake lets the reserve go till that reset. The wait's chat says `limit {until, reserve?, pct?}` and, at its end, `limit_end {by}`. `gcf-harness chat say --json` prints `{id}` of the line it wrote.
|
|
182
|
+
- Planning and implementation are two sessions: `GCF_RUN_PHASE` comes from `gcf plan check`; `aif-implement` goes only on a converged plan. `gcf-harness codex-review <id> --kind plan|code --pass <k> --json` is a review pass by the Codex CLI, read-only, when row k of `review.plan|code` is Codex's: a family (`sol`, `astra`) is the newest listed slug of `codex debug models` (kept 6 h in `.gcf-session/codex-models.json`, `--bundled` when the live read fails); Claude rows are the session's subagents with the row's model and effort. A code review's rows over with a blocking finding: the code is committed and the card blocks (`stall.code`); under `--worktree` the trailer comes off first, so nothing merges until the human answers. Each session gets `GCF_RUN_BASE`, the commit its card's work started from.
|
|
180
183
|
|
|
181
184
|
## Docs
|
|
182
185
|
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// `gcf-harness codex-review <id> --kind plan|code --pass <k>` (Operator-Tasks-Plan t2 d2): a review
|
|
2
|
+
// pass by the Codex CLI, read-only, when row k of `review.plan|code` is Codex's. Codex runs in its
|
|
3
|
+
// read-only sandbox: the audit holds by the sandbox, not by trust. The row's model is a family
|
|
4
|
+
// (`sol`), made the newest listed slug of the catalog, or a full slug as it is. Its answer is
|
|
5
|
+
// findings as JSON. With no Codex, or when it fails (its usage limit comes as a non-zero exit),
|
|
6
|
+
// the answer carries the row's `fallback` from `gcf review row` (Fallback-Fidelity-Plan d2): a
|
|
7
|
+
// subagent of a model of its size makes the pass, the list over, the session's own (`by self`).
|
|
8
|
+
// A row that is not Codex's is skipped with no fallback: its subagent makes it (SKILL.md).
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
11
|
+
import os from 'node:os';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
import { codexInstalled, codexModels, slugOf } from 'gcf-session';
|
|
15
|
+
|
|
16
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
export const FINDINGS_SCHEMA = path.join(HERE, 'codex-review.schema.json');
|
|
18
|
+
export const REVIEW_TIMEOUT_MS = 25 * 60_000;
|
|
19
|
+
|
|
20
|
+
const ANSWER = [
|
|
21
|
+
'A finding is blocking when the work, as it stands, would be wrong, miss what the item asks,',
|
|
22
|
+
'break what the code already does or a pillar; polish when it only reads better.',
|
|
23
|
+
'Answer with the findings only, as the schema says.',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The review's prompt: what to read and how to answer; the reviewer reads the files itself. The
|
|
28
|
+
* plan's carries aif-improve's criteria and the pillars' invariants; the code's the diff file and
|
|
29
|
+
* the pillars' review questions (SKILL.md steps 9, 15).
|
|
30
|
+
* @param {{id: string, kind: string, plan: string, diff?: string | null}} o
|
|
31
|
+
*/
|
|
32
|
+
export function reviewPrompt({ id, kind, plan, diff }) {
|
|
33
|
+
if (kind === 'code')
|
|
34
|
+
return [
|
|
35
|
+
`Review the code change of work item ${id} before its commit. The diff is in ${diff};`,
|
|
36
|
+
`read it, the item gcf/work/${id}.md, its plan ${plan} and the code around the change.`,
|
|
37
|
+
'Change nothing. Check that the change does what the item and the plan ask, breaks nothing,',
|
|
38
|
+
'and is tested. Answer the review_question of each pillar in gcf/PILLARS.md over the diff:',
|
|
39
|
+
'an answer that breaks a pillar is a blocking finding.',
|
|
40
|
+
...ANSWER,
|
|
41
|
+
].join('\n');
|
|
42
|
+
|
|
43
|
+
return [
|
|
44
|
+
`Audit the implementation plan of work item ${id}: ${plan}.`,
|
|
45
|
+
`Read the item gcf/work/${id}.md, the plan, and the code the plan names. Change nothing.`,
|
|
46
|
+
'Apply the criteria of an improve pass: every task provable by a check, nothing the item asks',
|
|
47
|
+
'missing, no wrong behavior, no conflict with a project rule. Check every task against the',
|
|
48
|
+
'invariant of each pillar in gcf/PILLARS.md, and against the graveyard_hits lines of',
|
|
49
|
+
`\`ai-factory gcf context ${id} --json\`. Check each claim of the plan against the code.`,
|
|
50
|
+
...ANSWER,
|
|
51
|
+
].join('\n');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Run the pass: `{findings, by}`, `{skipped: why}` (the row is not Codex's, no Codex) or
|
|
56
|
+
* `{failed: why}`; no Codex and a failure add the row's `fallback`. `row` is `gcf review row`'s
|
|
57
|
+
* answer; `codex` the command (a test's fake).
|
|
58
|
+
* @param {string} projectDir
|
|
59
|
+
* @param {{row: any, codex?: string[], timeoutMs?: number}} o
|
|
60
|
+
*/
|
|
61
|
+
export function codexReview(projectDir, o) {
|
|
62
|
+
const { row } = o;
|
|
63
|
+
if (row.row?.agent !== 'codex')
|
|
64
|
+
return { skipped: `pass ${row.pass} is ${row.by ?? 'no row'}'s: a subagent makes it` };
|
|
65
|
+
// From here the row cannot make its pass but by a stand-in: the core's `fallback`, in order
|
|
66
|
+
// (Fallback-Fidelity-Plan d2); an older core gives none, and the session's own subagent goes.
|
|
67
|
+
const standIns = Array.isArray(row.fallback) ? { fallback: row.fallback } : {};
|
|
68
|
+
const cmd = o.codex
|
|
69
|
+
? { exe: o.codex[0], pre: o.codex.slice(1), shell: false }
|
|
70
|
+
: { exe: 'codex', pre: [], shell: process.platform === 'win32' };
|
|
71
|
+
if (!codexInstalled(cmd)) return { skipped: 'no codex in PATH', ...standIns };
|
|
72
|
+
// The catalog is read once a while for the project's runs (t2 d4).
|
|
73
|
+
const cache = path.join(projectDir, '.gcf-session', 'codex-models.json');
|
|
74
|
+
const slug = slugOf(codexModels({ cache, cmd }), row.row.model);
|
|
75
|
+
if (!slug) return { failed: `Codex lists no model of ${row.row.model}`, ...standIns };
|
|
76
|
+
const { effort } = row.row;
|
|
77
|
+
const done = run(projectDir, cmd, { ...o, slug, effort });
|
|
78
|
+
|
|
79
|
+
return { ...done, by: `codex:${slug}:${effort}`, ...(done.failed ? standIns : {}) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* `codex exec` in its read-only sandbox, the findings to a file.
|
|
84
|
+
* @param {string} projectDir
|
|
85
|
+
* @param {any} cmd
|
|
86
|
+
* @param {any} o
|
|
87
|
+
*/
|
|
88
|
+
function run(projectDir, cmd, { row, slug, effort, timeoutMs }) {
|
|
89
|
+
const dir = mkdtempSync(path.join(os.tmpdir(), 'gcf-review-'));
|
|
90
|
+
const out = path.join(dir, 'findings.json');
|
|
91
|
+
try {
|
|
92
|
+
const args = [
|
|
93
|
+
...['exec', '-', '-s', 'read-only', '-m', slug],
|
|
94
|
+
...['-c', `model_reasoning_effort=${effort}`, '--ephemeral'],
|
|
95
|
+
...['--output-schema', FINDINGS_SCHEMA, '-o', out],
|
|
96
|
+
];
|
|
97
|
+
const res = spawnSync(cmd.exe, [...cmd.pre, ...args], {
|
|
98
|
+
windowsHide: true,
|
|
99
|
+
cwd: projectDir,
|
|
100
|
+
input: reviewPrompt({ ...row, diff: row.diff?.file ?? null }),
|
|
101
|
+
encoding: 'utf8',
|
|
102
|
+
timeout: timeoutMs ?? REVIEW_TIMEOUT_MS,
|
|
103
|
+
shell: cmd.shell,
|
|
104
|
+
});
|
|
105
|
+
if (/** @type {NodeJS.ErrnoException | undefined} */ (res.error)?.code === 'ETIMEDOUT')
|
|
106
|
+
return { failed: 'the review timed out' };
|
|
107
|
+
// A flag or a model the CLI does not take is named as it said it (Hold-Plan risk 11).
|
|
108
|
+
if (res.status !== 0)
|
|
109
|
+
return { failed: `codex exit ${res.status}: ${firstLine(res.stderr || res.stdout)}` };
|
|
110
|
+
|
|
111
|
+
return findingsOf(out);
|
|
112
|
+
} finally {
|
|
113
|
+
rmSync(dir, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const firstLine = (text) =>
|
|
118
|
+
String(text ?? '')
|
|
119
|
+
.trim()
|
|
120
|
+
.split(/\r?\n/)[0] || 'no output';
|
|
121
|
+
|
|
122
|
+
/** The findings the reviewer wrote, or why they cannot be read. */
|
|
123
|
+
function findingsOf(file) {
|
|
124
|
+
try {
|
|
125
|
+
const x = JSON.parse(readFileSync(file, 'utf8'));
|
|
126
|
+
if (!Array.isArray(x?.findings)) return { failed: 'the answer has no findings list' };
|
|
127
|
+
|
|
128
|
+
return { findings: x.findings };
|
|
129
|
+
} catch (e) {
|
|
130
|
+
return { failed: `the answer is not JSON: ${e.message}` };
|
|
131
|
+
}
|
|
132
|
+
}
|
package/commands/harness.js
CHANGED
|
@@ -17,7 +17,7 @@ import { spawnSync } from 'node:child_process';
|
|
|
17
17
|
import path from 'node:path';
|
|
18
18
|
import { fileURLToPath } from 'node:url';
|
|
19
19
|
import { metricsCommand, runsCommand } from './metrics.js';
|
|
20
|
-
import {
|
|
20
|
+
import { codexReview } from './codex-review.js';
|
|
21
21
|
import {
|
|
22
22
|
run,
|
|
23
23
|
card,
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
loosePaths,
|
|
33
33
|
queueOf,
|
|
34
34
|
stopOf,
|
|
35
|
+
wakeOf,
|
|
35
36
|
} from './run.js';
|
|
36
37
|
import {
|
|
37
38
|
CHAT_TIMEOUT_MIN,
|
|
@@ -41,6 +42,9 @@ import {
|
|
|
41
42
|
chatOut,
|
|
42
43
|
killTree,
|
|
43
44
|
readText,
|
|
45
|
+
THREAD_ID,
|
|
46
|
+
threadWaits,
|
|
47
|
+
wakeThread,
|
|
44
48
|
} from 'gcf-session';
|
|
45
49
|
|
|
46
50
|
const EXT_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
@@ -585,8 +589,24 @@ export function register(program) {
|
|
|
585
589
|
.command('stop <id>')
|
|
586
590
|
.description('Stop the session that works an item; the run goes on, the item stays ready')
|
|
587
591
|
.action((id) => console.log(stopRun(process.cwd(), id)));
|
|
592
|
+
harness
|
|
593
|
+
.command('wake [id]')
|
|
594
|
+
.description(
|
|
595
|
+
"The usage limit was reset early: an item's limit wait goes on now (--thread: a chat " +
|
|
596
|
+
"thread's; --all: every wait of the project)",
|
|
597
|
+
)
|
|
598
|
+
.option('--thread <t>', "a project chat thread's wait")
|
|
599
|
+
.option('--all', 'every live wait of the project: the limit is one for the account')
|
|
600
|
+
.action((id, o) => {
|
|
601
|
+
try {
|
|
602
|
+
console.log(wakeCommand(process.cwd(), id, o));
|
|
603
|
+
} catch (e) {
|
|
604
|
+
console.error(`gcf-harness wake: ${e.message}`);
|
|
605
|
+
process.exitCode = 1;
|
|
606
|
+
}
|
|
607
|
+
});
|
|
588
608
|
registerHold(harness);
|
|
589
|
-
|
|
609
|
+
registerCodexReview(harness);
|
|
590
610
|
registerChat(harness);
|
|
591
611
|
}
|
|
592
612
|
|
|
@@ -655,17 +675,22 @@ function registerCard(harness) {
|
|
|
655
675
|
});
|
|
656
676
|
}
|
|
657
677
|
|
|
658
|
-
/** `gcf-harness
|
|
659
|
-
function
|
|
678
|
+
/** `gcf-harness codex-review`: a review pass by the Codex CLI (Operator-Tasks-Plan t2 d2). */
|
|
679
|
+
function registerCodexReview(harness) {
|
|
660
680
|
harness
|
|
661
|
-
.command('
|
|
681
|
+
.command('codex-review <id>')
|
|
662
682
|
.description(
|
|
663
|
-
"
|
|
664
|
-
'
|
|
683
|
+
"Pass k of the item's plan or code review by the Codex CLI, read-only, when row k of " +
|
|
684
|
+
'review.plan|code is Codex: its findings, or skipped or failed with why',
|
|
685
|
+
)
|
|
686
|
+
.requiredOption('--kind <kind>', 'plan or code')
|
|
687
|
+
.requiredOption('--pass <k>', 'the pass number, 1 or more')
|
|
688
|
+
.option(
|
|
689
|
+
'--json',
|
|
690
|
+
'machine output: {findings, by} | {skipped, fallback?} | {failed, by?, fallback?}',
|
|
665
691
|
)
|
|
666
|
-
.option('--json', 'machine output: {findings} | {skipped} | {failed}')
|
|
667
692
|
.action((id, o) => {
|
|
668
|
-
const r =
|
|
693
|
+
const r = /** @type {any} */ (codexReviewOf(process.cwd(), id, o));
|
|
669
694
|
if (o.json) return console.log(JSON.stringify(r));
|
|
670
695
|
if (r.findings)
|
|
671
696
|
for (const f of r.findings) console.log(`${f.severity}: ${f.where}: ${f.text}`);
|
|
@@ -708,7 +733,12 @@ function registerRun(harness) {
|
|
|
708
733
|
'stop a session that runs longer; its item stays ready (default: session_timeout_min of ' +
|
|
709
734
|
`gcf/config.yml, else ${DEFAULT_TIMEOUT_MIN})`,
|
|
710
735
|
)
|
|
711
|
-
.option(
|
|
736
|
+
.option(
|
|
737
|
+
'--mode <mode>',
|
|
738
|
+
"worktree | main (default: the core's runs_in: the item's own run_mode, else where its " +
|
|
739
|
+
'kept session ran, else worktree while its live copy lives, else run_mode of ' +
|
|
740
|
+
'gcf/config.yml)',
|
|
741
|
+
)
|
|
712
742
|
.option('--fresh', 'start new agent sessions: an interrupted one is not resumed')
|
|
713
743
|
.option(
|
|
714
744
|
'--allow <rule>',
|
|
@@ -749,6 +779,7 @@ function registerChat(harness) {
|
|
|
749
779
|
.option('--text-file <path>', 'say: the message from a file, - for stdin')
|
|
750
780
|
.option('--image <path>', 'say: a picture with it (png, jpg, gif, webp; repeat)', collect, [])
|
|
751
781
|
.option('--answers-file <path>', 'answer: {"<question>": "<answer>"} from a file, - for stdin')
|
|
782
|
+
.option('--json', 'machine output: {id} of the line written (a message is known by it)')
|
|
752
783
|
.action(chatAction);
|
|
753
784
|
}
|
|
754
785
|
|
|
@@ -760,7 +791,7 @@ function collect(v, list) {
|
|
|
760
791
|
function chatAction(id, action, words, opts) {
|
|
761
792
|
try {
|
|
762
793
|
const runs = path.join(process.cwd(), '.gcf-session', 'runs');
|
|
763
|
-
chatInput(
|
|
794
|
+
const line = chatInput(
|
|
764
795
|
process.cwd(),
|
|
765
796
|
id,
|
|
766
797
|
{ action, words, ...opts },
|
|
@@ -769,7 +800,9 @@ function chatAction(id, action, words, opts) {
|
|
|
769
800
|
read: readText,
|
|
770
801
|
},
|
|
771
802
|
);
|
|
772
|
-
|
|
803
|
+
// A message's line has its id (AD-35); an answer or an interrupt has none.
|
|
804
|
+
const sent = line && 'id' in line ? line.id : null;
|
|
805
|
+
console.log(opts.json ? JSON.stringify({ id: sent }) : 'sent');
|
|
773
806
|
} catch (e) {
|
|
774
807
|
console.error(`gcf-harness chat: ${e.message}`);
|
|
775
808
|
// 4: the input was good, writing it failed (a disk, a permission): the board answers 500.
|
|
@@ -829,17 +862,27 @@ export function itemLock(runs, id) {
|
|
|
829
862
|
}
|
|
830
863
|
|
|
831
864
|
/**
|
|
832
|
-
*
|
|
833
|
-
*
|
|
865
|
+
* Pass k of item `id`'s review of `kind` by Codex: the row from the core (`gcf review row`, the
|
|
866
|
+
* code's diff written with it), then the pass. GCF_CODEX (a JSON list: the command and its first
|
|
867
|
+
* arguments) names another Codex, a test's fake.
|
|
834
868
|
*/
|
|
835
|
-
function
|
|
836
|
-
const
|
|
837
|
-
const
|
|
838
|
-
|
|
869
|
+
function codexReviewOf(projectDir, id, { kind, pass }) {
|
|
870
|
+
const diff = kind === 'code' ? ['--diff'] : [];
|
|
871
|
+
const r = cliCore(projectDir)([
|
|
872
|
+
'review',
|
|
873
|
+
'row',
|
|
874
|
+
id,
|
|
875
|
+
'--kind',
|
|
876
|
+
kind,
|
|
877
|
+
'--pass',
|
|
878
|
+
pass,
|
|
879
|
+
...diff,
|
|
880
|
+
'--json',
|
|
881
|
+
]);
|
|
882
|
+
if (!r.ok) return { failed: (r.err || r.out).trim() };
|
|
839
883
|
const codex = process.env.GCF_CODEX ? JSON.parse(process.env.GCF_CODEX) : undefined;
|
|
840
|
-
const plan = item.plan_file ?? `.ai-factory/plans/${id}.md`;
|
|
841
884
|
|
|
842
|
-
return
|
|
885
|
+
return codexReview(projectDir, { row: json(r, 'review row'), codex });
|
|
843
886
|
}
|
|
844
887
|
|
|
845
888
|
/** The autopilot's stop while the project is held (Hold-Plan d9). */
|
|
@@ -890,6 +933,62 @@ export function holdCommand(projectDir, id, { project = false, release = false }
|
|
|
890
933
|
: 'held the project: its sessions hand over, nothing queued or autopiloted starts';
|
|
891
934
|
}
|
|
892
935
|
|
|
936
|
+
/**
|
|
937
|
+
* Whether item `id`'s run waits for the limit's reset now (t1 d1): its record names a reset and
|
|
938
|
+
* a live run holds its lock. A stopped or killed wait keeps its reset: the record alone is not.
|
|
939
|
+
*/
|
|
940
|
+
function itemWaits(runs, id) {
|
|
941
|
+
try {
|
|
942
|
+
const rec = JSON.parse(readFileSync(path.join(runs, `${id}.agent.json`), 'utf8'));
|
|
943
|
+
|
|
944
|
+
return Boolean(rec.resets) && Boolean(itemLock(runs, id));
|
|
945
|
+
} catch {
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* `gcf-harness wake`: the mark that ends a limit wait early (Operator-Tasks-Plan t1 d4), only
|
|
952
|
+
* while one lives: an item's, a thread's (`thread`), or every one of the project (`all`).
|
|
953
|
+
* @param {string} projectDir
|
|
954
|
+
* @param {string | undefined} id
|
|
955
|
+
* @param {{thread?: string, all?: boolean}} [o]
|
|
956
|
+
*/
|
|
957
|
+
export function wakeCommand(projectDir, id, { thread, all = false } = {}) {
|
|
958
|
+
if ([id, thread, all || undefined].filter(Boolean).length !== 1)
|
|
959
|
+
throw new Error('name one item, --thread <t> or --all');
|
|
960
|
+
const dir = path.resolve(projectDir);
|
|
961
|
+
if (thread) return wakeThread(dir, thread);
|
|
962
|
+
const runs = runsDir(dir);
|
|
963
|
+
if (id) {
|
|
964
|
+
if (!itemWaits(runs, id)) return `nothing waits for ${id}`;
|
|
965
|
+
writeFileSync(wakeOf(runs, id), `${new Date().toISOString()}\n`);
|
|
966
|
+
|
|
967
|
+
return `woke ${id}: its session goes on now`;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
const items = safeList(runs)
|
|
971
|
+
.filter((n) => n.endsWith('.agent.json'))
|
|
972
|
+
.map((n) => n.slice(0, -'.agent.json'.length))
|
|
973
|
+
.filter((x) => itemWaits(runs, x));
|
|
974
|
+
for (const x of items) writeFileSync(wakeOf(runs, x), `${new Date().toISOString()}\n`);
|
|
975
|
+
const threads = safeList(path.join(dir, '.gcf-session', 'chats')).filter(
|
|
976
|
+
(t) => THREAD_ID.test(t) && threadWaits(dir, t),
|
|
977
|
+
);
|
|
978
|
+
for (const t of threads) wakeThread(dir, t);
|
|
979
|
+
const woke = [...items, ...threads.map((t) => `thread ${t}`)];
|
|
980
|
+
|
|
981
|
+
return woke.length ? `woke ${woke.join(', ')}` : 'nothing waits';
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
const safeList = (d) => {
|
|
985
|
+
try {
|
|
986
|
+
return readdirSync(d);
|
|
987
|
+
} catch {
|
|
988
|
+
return [];
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
|
|
893
992
|
export function stopRun(projectDir, id, core = cliCore(projectDir)) {
|
|
894
993
|
const runs = path.join(path.resolve(projectDir), '.gcf-session', 'runs');
|
|
895
994
|
const lockFor = () => itemLock(runs, id);
|
package/commands/milestones.js
CHANGED
|
@@ -13,6 +13,8 @@ export const REVIEW = 'gcf review';
|
|
|
13
13
|
/** @type {[RegExp, string][]} */
|
|
14
14
|
const BASH = [
|
|
15
15
|
[/\bai-factory\s+gcf\s+plan\s+check\b/, 'plan-check'],
|
|
16
|
+
// The code's review by Codex (Operator-Tasks-Plan t2 d2); the plan's is no step of the chat.
|
|
17
|
+
[/\bai-factory\s+gcf-harness\s+codex-review\b[^|&;]*--kind[\s=]+code\b/, 'review'],
|
|
16
18
|
[/\bai-factory\s+gcf\s+verify\b/, 'dod'],
|
|
17
19
|
[/\bgit\s+commit\b/, 'commit'],
|
|
18
20
|
[/\bai-factory\s+gcf\s+(submit|close|block|decide)\b/, 'move'],
|
|
@@ -96,7 +98,13 @@ export function milestones({ verifyLog, item, head = () => null, worktree = fals
|
|
|
96
98
|
const step = stepOf(e);
|
|
97
99
|
if (step?.step === 'move' && worktree) return [];
|
|
98
100
|
if (step && step.step !== 'plan')
|
|
99
|
-
calls.set(e.id, {
|
|
101
|
+
calls.set(e.id, {
|
|
102
|
+
...step,
|
|
103
|
+
at: Date.now(),
|
|
104
|
+
head: step.step === 'commit' ? head() : null,
|
|
105
|
+
// A shell in the background answers at once: its step ends with its task (t2 d2).
|
|
106
|
+
background: e.kind === 'shell' && e.input?.run_in_background === true,
|
|
107
|
+
});
|
|
100
108
|
|
|
101
109
|
return [];
|
|
102
110
|
};
|
|
@@ -114,6 +122,7 @@ export function milestones({ verifyLog, item, head = () => null, worktree = fals
|
|
|
114
122
|
|
|
115
123
|
const ended = (e) => {
|
|
116
124
|
const call = calls.get(e.id);
|
|
125
|
+
if (call?.background) return [];
|
|
117
126
|
calls.delete(e.id);
|
|
118
127
|
if (!call || call.step === 'plan-check') {
|
|
119
128
|
if (call) w.checks++;
|
|
@@ -121,12 +130,23 @@ export function milestones({ verifyLog, item, head = () => null, worktree = fals
|
|
|
121
130
|
return [];
|
|
122
131
|
}
|
|
123
132
|
|
|
124
|
-
const { at: _, head: __, ...step } = call;
|
|
133
|
+
const { at: _, head: __, background: ___, ...step } = call;
|
|
125
134
|
const ok = okOf(call, e);
|
|
126
135
|
|
|
127
136
|
return [{ type: 'step', ...step, ok, ...(ok === false ? { text: firstLine(e.text) } : {}) }];
|
|
128
137
|
};
|
|
129
138
|
|
|
139
|
+
/** A background shell's step at its task's end: `completed` is ok, else its summary says why. */
|
|
140
|
+
const backgroundEnded = (e) => {
|
|
141
|
+
const call = e.call ? calls.get(e.call) : null;
|
|
142
|
+
if (!call?.background) return [];
|
|
143
|
+
calls.delete(/** @type {string} */ (e.call));
|
|
144
|
+
const { at: _, head: __, background: ___, ...step } = call;
|
|
145
|
+
const ok = e.status === 'completed';
|
|
146
|
+
|
|
147
|
+
return [{ type: 'step', ...step, ok, ...(ok ? {} : { text: firstLine(e.summary ?? '') }) }];
|
|
148
|
+
};
|
|
149
|
+
|
|
130
150
|
return {
|
|
131
151
|
// Kept for its callers: the plan's step comes from the phase's end now, not from a call.
|
|
132
152
|
skipPlan: () => {},
|
|
@@ -144,6 +164,7 @@ export function milestones({ verifyLog, item, head = () => null, worktree = fals
|
|
|
144
164
|
// A subagent's calls (a reviewer running the tests) are its own, not the item's steps.
|
|
145
165
|
if (!e || e.sub) return [];
|
|
146
166
|
if (e.type === 'tool_call') return called(e);
|
|
167
|
+
if (e.type === 'task' && e.phase === 'end') return backgroundEnded(e);
|
|
147
168
|
|
|
148
169
|
return e.type === 'tool_result' ? ended(e) : [];
|
|
149
170
|
},
|