gcf-harness-aif-ext 0.9.10 → 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 +15 -0
- package/commands/harness.js +86 -42
- package/commands/implement-steps.js +45 -0
- package/commands/milestones.js +149 -0
- package/commands/run.js +299 -645
- package/extension.json +1 -1
- package/hooks/handoff-guard.js +19 -10
- package/hooks/implement-guard.js +50 -49
- package/hooks/owner.js +27 -0
- package/hooks/readset-guard.js +35 -21
- package/{commands → node_modules/gcf-session/lib}/activity.js +155 -28
- package/node_modules/gcf-session/lib/adapter/claude.js +226 -0
- package/node_modules/gcf-session/lib/adapter/index.js +33 -0
- package/node_modules/gcf-session/lib/chat-input.js +260 -0
- package/node_modules/gcf-session/lib/chat.js +832 -0
- package/node_modules/gcf-session/lib/cli.js +52 -0
- package/node_modules/gcf-session/lib/cost.js +29 -0
- package/node_modules/gcf-session/lib/index.js +58 -0
- package/node_modules/gcf-session/lib/job.js +417 -0
- package/node_modules/gcf-session/lib/limit.js +132 -0
- package/node_modules/gcf-session/lib/lock.js +81 -0
- package/node_modules/gcf-session/lib/proc.js +93 -0
- package/node_modules/gcf-session/lib/session.js +320 -0
- package/node_modules/gcf-session/lib/store.js +28 -0
- package/node_modules/gcf-session/lib/thread.js +423 -0
- package/node_modules/gcf-session/lib/windows.js +46 -0
- package/node_modules/gcf-session/package.json +23 -0
- package/node_modules/gcf-session/types/index.d.ts +152 -0
- package/package.json +9 -3
- package/skills/gcf-run/SKILL.md +95 -86
package/README.md
CHANGED
|
@@ -47,6 +47,21 @@ Updating keeps the hook entry valid — it points into the extension's install d
|
|
|
47
47
|
|
|
48
48
|
0.5.1 is a fix release. During a run, `gcf/config.yml` is always readable, and a Grep inside `gcf/` reads only readset files. An import breaks a `depends:` cycle the pair checks closed and asks a D1 about it. It cuts a section longer than a segment at paragraphs, and lens and pair prompts carry a window around the quote. `/gcf-run` checks the plan against each pillar's invariant and asks each pillar's review question over the diff. Use it with core 0.4.1, which brings the parent feature into the readset.
|
|
49
49
|
|
|
50
|
+
0.12.0 moves the session mechanics into the bundled session engine `gcf-session` (docs/Session-Engine.md) and needs gcf-aif-ext 0.12.0: a core without neutral rules (`agent.rules`) is refused before any item is claimed. The hooks keep their files and matchers: no new `init` is needed.
|
|
51
|
+
- **The usage limit waits.** A session cut by the limit with a known reset waits for it (plus 60 s) and goes on in the same session. Before the wait its record is written (`<id>.agent.json`, `ended: limit`, `resets` as ISO), so a run killed meanwhile resumes the same session; the chat gets `limit {until}`; the wait does not count against `--timeout`; `gcf-harness stop` ends it. It does not wait for the week's limit, an unknown reset, a reset over 6 h away, an item's third limit in a run, or a lessons turn: those end `paused` as before. `--wait-limit` (a queued start from the board) also holds each session while a known reset is ahead. `--json` says `limit_wait: true`.
|
|
52
|
+
- **Owners.** The handoff flag and the readset manifest name their owner and item: the guards act only on that session, so a project chat or an interactive claude in the same folder goes on. The guards are each a neutral decision and a claude shim, with the same files and input as before.
|
|
53
|
+
- **Milestones from what the work left:** the DoD's `ok` comes from the item's row of main's `gcf/.metrics/verify-log.csv` between the call and its result (`null` with none or two), a commit's from the new HEAD; a worktree's move is main's to record.
|
|
54
|
+
- A background subagent keeps the session open with no timer and no default answer (`background`, then `working`); the context window is known from the first turn (the live `modelUsage`), and the chat shows the share during a turn (`context`).
|
|
55
|
+
- `GCF_SESSION_AGENT` puts another agent in place of `claude` (tests); `GCF_RUN_AGENT` still works.
|
|
56
|
+
|
|
57
|
+
0.11.1 reworks the chat (docs/Chat-Plan.md) and needs gcf-aif-ext 0.11.1 for its settings (an older core gives the defaults):
|
|
58
|
+
- `chat:` of `gcf/config.yml` decides who waits for whom: `ask` (`d1` by default: only the human's decisions by a question card; `all`; `none`: each card is denied, the agent decides) goes to the skill as `/gcf-run <id> --ask d1|all`; `answer_timeout_min` (15) is how long a question waits, 0 when nobody watches (then `ask` is `none`). `--chat-timeout` has no default any more: it overrides the setting for one run, 0 allowed.
|
|
59
|
+
- `ai-factory gcf-harness chat <id> say [text] [--text-file <path|->] [--image <path>]…`, `answer <request_id> [text] [--answers-file <path|->]`, `interrupt` writes the operator's input: checked (text up to 64 000 characters, up to 10 png/jpg/gif/webp pictures of 5 MB each, an answer to an open card only), never through a link, and only while a live session reads it. Exit 1: bad input; 3: no live chat session; 4: the write failed. A picture is copied into `.gcf-session/runs/<id>.att/`, not git; `chat-in.jsonl` names it by path.
|
|
60
|
+
- `<id>.chat.jsonl` adds the run's milestones from the main agent's tool calls (`step`: the plan converged with its passes, the DoD, the review subagent the skill names `gcf review`, a commit, the item's move; in a worktree the move main recorded), each session's start and end, the handoff flag, the context share at each turn's end, and an `error` for input that reached no one (a dropped card, a missing picture, a message after the item's last session).
|
|
61
|
+
- A turn whose messages the agent never echoed as read frees the session after 10 s with no new turn. After the operator's interrupt the session waits for them with no default answer, while the session's timeout runs on. A session flagged for a handoff closes at its turn's end, as without the chat: no more reminder to hand over. A card a session took with it at its end is dropped.
|
|
62
|
+
|
|
63
|
+
0.10.0 adds the chat (docs/Chat-Plan.md, stage 1): `run --chat` keeps each agent session open to the operator. The prompt goes in as the session's first stream-json message on stdin. The operator writes into `.gcf-session/runs/<id>.chat-in.jsonl`, one JSON a line: `{"type":"say","text":…,"images":[{media_type,data}]}`, `{"type":"interrupt"}` (stops the agent's step, the session stays), `{"type":"answer","request_id":…,"answers":{…}}` (a question card). What the operator reads goes to `<id>.chat.jsonl`: the agent's text, each message sent and when the agent read it, question cards and their answers, the end of each turn. A question waits `--chat-timeout` minutes (15 by default), and the session's own timeout stands still meanwhile; then the run answers: the card's recommended option, or `take your safe default, or block the item`. A turn that ends without the item's move waits the same way, once. Without `--chat` nothing changes. A session flagged for a handoff closes once it went on past its flag, and the fresh one takes the chat on; flagged on its turn's last message, it is first told to hand over. A message sent while a question card is open leaves the card its timeout. `--chat` adds `claude`'s stream-json flags to the agent's command: another `--agent` must take them. Any other tool approval the agent asks for is denied: the run's permissions decide. Checked live with `claude` (Haiku): the prompt on stdin, an interrupt, the operator's message, the item blocked, the session closed.
|
|
64
|
+
|
|
50
65
|
0.9.10 makes a main run's session marks its own (with core 0.10.2): the run sets `GCF_RUN_OWNER=run:<pid>`, its core calls and every agent session it starts (a fresh one after a handoff too) inherit it, and the core refuses the mark to anyone else. An item another session has claimed is refused with `worked by another agent session`. `/gcf-run` reports a refused claim and goes on with the next item; it never releases another session's mark, and neither does the run (`gcf-harness stop` still does: that is the human's). The readset-guard hook keeps only its own session's marks fresh (and marks that name nobody), so another session's mark expires when that session stops.
|
|
51
66
|
|
|
52
67
|
0.9.9 changes no code: its peer range adds core 0.10.0, whose board read is schema 3 and names this harness as the domain's runner (the harness reads neither).
|
package/commands/harness.js
CHANGED
|
@@ -10,6 +10,7 @@ import path from 'node:path';
|
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import { metricsCommand } from './metrics.js';
|
|
12
12
|
import { run, cliCore, DEFAULT_AGENT, DEFAULT_TIMEOUT_MIN, MAIN_RUN, stopOf } from './run.js';
|
|
13
|
+
import { CHAT_TIMEOUT_MIN, ChatRefusal, alive, chatInput, killTree, readText } from 'gcf-session';
|
|
13
14
|
|
|
14
15
|
const EXT_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
15
16
|
const SCHEMA = 1; // the only gcf/config.yml schema this harness drives
|
|
@@ -349,23 +350,7 @@ export function register(program) {
|
|
|
349
350
|
.option('--json', 'machine output: {pass, reason}')
|
|
350
351
|
.action(runGate);
|
|
351
352
|
|
|
352
|
-
harness
|
|
353
|
-
.command('run <ids...>')
|
|
354
|
-
.description('Run items at once, each in its worktree with its own agent, then integrate')
|
|
355
|
-
.option(
|
|
356
|
-
'--agent <command>',
|
|
357
|
-
'the agent command; it gets "/gcf-run <id> --worktree", or --resume <session> to go on',
|
|
358
|
-
process.env.GCF_RUN_AGENT ?? DEFAULT_AGENT,
|
|
359
|
-
)
|
|
360
|
-
.option(
|
|
361
|
-
'--timeout <minutes>',
|
|
362
|
-
'stop a session that runs longer; its item stays ready',
|
|
363
|
-
String(DEFAULT_TIMEOUT_MIN),
|
|
364
|
-
)
|
|
365
|
-
.option('--mode <mode>', 'worktree | main (default: run_mode of gcf/config.yml)')
|
|
366
|
-
.option('--fresh', 'start new agent sessions: an interrupted one is not resumed')
|
|
367
|
-
.option('--json', 'machine output')
|
|
368
|
-
.action(runItems);
|
|
353
|
+
registerRun(harness);
|
|
369
354
|
|
|
370
355
|
harness
|
|
371
356
|
.command('next [count]')
|
|
@@ -385,19 +370,79 @@ export function register(program) {
|
|
|
385
370
|
.command('stop <id>')
|
|
386
371
|
.description('Stop the session that works an item; the run goes on, the item stays ready')
|
|
387
372
|
.action((id) => console.log(stopRun(process.cwd(), id)));
|
|
373
|
+
registerChat(harness);
|
|
388
374
|
}
|
|
389
375
|
|
|
390
|
-
|
|
376
|
+
/** `gcf-harness run`: the items' agent sessions, each in its checkout. */
|
|
377
|
+
function registerRun(harness) {
|
|
378
|
+
harness
|
|
379
|
+
.command('run <ids...>')
|
|
380
|
+
.description('Run items at once, each in its worktree with its own agent, then integrate')
|
|
381
|
+
.option(
|
|
382
|
+
'--agent <command>',
|
|
383
|
+
'the agent command; it gets "/gcf-run <id> --worktree", or --resume <session> to go on',
|
|
384
|
+
process.env.GCF_SESSION_AGENT ?? process.env.GCF_RUN_AGENT ?? DEFAULT_AGENT,
|
|
385
|
+
)
|
|
386
|
+
.option(
|
|
387
|
+
'--timeout <minutes>',
|
|
388
|
+
'stop a session that runs longer; its item stays ready',
|
|
389
|
+
String(DEFAULT_TIMEOUT_MIN),
|
|
390
|
+
)
|
|
391
|
+
.option('--mode <mode>', 'worktree | main (default: run_mode of gcf/config.yml)')
|
|
392
|
+
.option('--fresh', 'start new agent sessions: an interrupted one is not resumed')
|
|
393
|
+
.option(
|
|
394
|
+
'--wait-limit',
|
|
395
|
+
'a queued start: each session first waits while the usage limit is known to reset ahead',
|
|
396
|
+
)
|
|
397
|
+
.option(
|
|
398
|
+
'--chat',
|
|
399
|
+
'keep each session open to the operator: .gcf-session/runs/<id>.chat-in.jsonl',
|
|
400
|
+
)
|
|
401
|
+
.option(
|
|
402
|
+
'--chat-timeout <minutes>',
|
|
403
|
+
'how long a chat question waits for the operator (default: chat.answer_timeout_min of ' +
|
|
404
|
+
`gcf/config.yml, else ${CHAT_TIMEOUT_MIN}; 0: nobody watches)`,
|
|
405
|
+
)
|
|
406
|
+
.option('--json', 'machine output')
|
|
407
|
+
.action(runItems);
|
|
408
|
+
}
|
|
391
409
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
410
|
+
function registerChat(harness) {
|
|
411
|
+
harness
|
|
412
|
+
.command('chat <id> <action> [words...]')
|
|
413
|
+
.description(
|
|
414
|
+
"Write into an item's live chat session: say <text>, answer <request_id> [text], interrupt",
|
|
415
|
+
)
|
|
416
|
+
.option('--text-file <path>', 'say: the message from a file, - for stdin')
|
|
417
|
+
.option('--image <path>', 'say: a picture with it (png, jpg, gif, webp; repeat)', collect, [])
|
|
418
|
+
.option('--answers-file <path>', 'answer: {"<question>": "<answer>"} from a file, - for stdin')
|
|
419
|
+
.action(chatAction);
|
|
420
|
+
}
|
|
395
421
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
422
|
+
function collect(v, list) {
|
|
423
|
+
return [...list, v];
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Exit 1 on bad input, 3 when no live session takes it, 4 when the write fails: 400, 409, 500. */
|
|
427
|
+
function chatAction(id, action, words, opts) {
|
|
428
|
+
try {
|
|
429
|
+
const runs = path.join(process.cwd(), '.gcf-session', 'runs');
|
|
430
|
+
chatInput(
|
|
431
|
+
process.cwd(),
|
|
432
|
+
id,
|
|
433
|
+
{ action, words, ...opts },
|
|
434
|
+
{
|
|
435
|
+
lockFor: (x) => itemLock(runs, x),
|
|
436
|
+
read: readText,
|
|
437
|
+
},
|
|
438
|
+
);
|
|
439
|
+
console.log('sent');
|
|
440
|
+
} catch (e) {
|
|
441
|
+
console.error(`gcf-harness chat: ${e.message}`);
|
|
442
|
+
// 4: the input was good, writing it failed (a disk, a permission): the board answers 500.
|
|
443
|
+
process.exitCode = e instanceof ChatRefusal ? e.code : 4;
|
|
399
444
|
}
|
|
400
|
-
}
|
|
445
|
+
}
|
|
401
446
|
|
|
402
447
|
/**
|
|
403
448
|
* A run lock: `<run pid>\n<item>\n<session pid>\n` once the session started, the run pid alone
|
|
@@ -414,31 +459,25 @@ function lockOf(file) {
|
|
|
414
459
|
}
|
|
415
460
|
}
|
|
416
461
|
|
|
417
|
-
/** Kill a session and everything under it: a tree on Windows, its own group elsewhere. */
|
|
418
|
-
function killTree(pid) {
|
|
419
|
-
if (WIN) spawnSync('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore' });
|
|
420
|
-
else {
|
|
421
|
-
try {
|
|
422
|
-
process.kill(-pid, 'SIGKILL');
|
|
423
|
-
} catch {
|
|
424
|
-
// Gone already.
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
462
|
/**
|
|
430
463
|
* Stop the session that works `id`: the one its own lock names (worktree mode), or the main
|
|
431
464
|
* checkout's run when that run works this very item (main mode). Only that session goes: the
|
|
432
465
|
* run records it as stopped and goes on with the rest. The item stays ready and its work in
|
|
433
466
|
* progress is kept.
|
|
434
467
|
*/
|
|
468
|
+
/**
|
|
469
|
+
* The live run lock that drives item `id`: its own (worktree mode), or the main checkout's when
|
|
470
|
+
* that run works this very item (main mode). Null when no live run drives it.
|
|
471
|
+
*/
|
|
472
|
+
export function itemLock(runs, id) {
|
|
473
|
+
const main = lockOf(path.join(runs, `${MAIN_RUN}.lock`));
|
|
474
|
+
|
|
475
|
+
return lockOf(path.join(runs, `${id}.lock`)) ?? (main?.item === id ? main : null);
|
|
476
|
+
}
|
|
477
|
+
|
|
435
478
|
export function stopRun(projectDir, id, core = cliCore(projectDir)) {
|
|
436
479
|
const runs = path.join(path.resolve(projectDir), '.gcf-session', 'runs');
|
|
437
|
-
const lockFor = () =>
|
|
438
|
-
const main = lockOf(path.join(runs, `${MAIN_RUN}.lock`));
|
|
439
|
-
|
|
440
|
-
return lockOf(path.join(runs, `${id}.lock`)) ?? (main?.item === id ? main : null);
|
|
441
|
-
};
|
|
480
|
+
const lockFor = () => itemLock(runs, id);
|
|
442
481
|
|
|
443
482
|
// The mark says the session ended by a stop, and stops the next one as it starts: the lock
|
|
444
483
|
// names none before the item's first session, or between two of a handoff. Read again after
|
|
@@ -482,6 +521,9 @@ async function runItems(ids, opts) {
|
|
|
482
521
|
if (!(minutes > 0)) throw new Error('--timeout is a number of minutes above 0');
|
|
483
522
|
if (opts.mode && !['worktree', 'main'].includes(opts.mode))
|
|
484
523
|
throw new Error('--mode is worktree or main');
|
|
524
|
+
const answer = opts.chatTimeout === undefined ? null : Number(opts.chatTimeout);
|
|
525
|
+
if (answer !== null && !(answer >= 0))
|
|
526
|
+
throw new Error('--chat-timeout is a number of minutes, 0 or more');
|
|
485
527
|
// The true-case path: Claude Code trusts a folder by its exact path, and a shell or a board
|
|
486
528
|
// may hand over c: for C:, which turns off every allow rule of the project.
|
|
487
529
|
const r = await run(realpathSync.native(process.cwd()), [...new Set(ids)], {
|
|
@@ -490,6 +532,8 @@ async function runItems(ids, opts) {
|
|
|
490
532
|
timeoutMs: minutes * 60_000,
|
|
491
533
|
mode: opts.mode,
|
|
492
534
|
fresh: Boolean(opts.fresh),
|
|
535
|
+
waitLimit: Boolean(opts.waitLimit),
|
|
536
|
+
chat: opts.chat ? { answerMin: answer } : null,
|
|
493
537
|
});
|
|
494
538
|
if (opts.json) console.log(JSON.stringify(r, null, 2));
|
|
495
539
|
else printRun(r);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// gcf-run step 13 in a session's neutral events (gcf-session `Neutral`): whether it invoked
|
|
2
|
+
// aif-implement, and the code it wrote. A session that wrote code with no aif-implement before it
|
|
3
|
+
// skipped the step (`OUTSIDE_IMPLEMENT`).
|
|
4
|
+
import { planning } from '../hooks/implement-guard.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What one tool call tells of step 13: `implement` when it invokes the aif-implement skill,
|
|
8
|
+
* `write` the file an edit names. A subagent's calls count too.
|
|
9
|
+
* @returns {{implement?: boolean, write?: {id: string, file: string}}}
|
|
10
|
+
*/
|
|
11
|
+
export function stepOf(e) {
|
|
12
|
+
if (e?.type !== 'tool_call') return {};
|
|
13
|
+
// A plugin's skill comes as <plugin>:aif-implement.
|
|
14
|
+
if (e.kind === 'skill' && /(^|:)aif-implement$/.test(String(e.input?.skill ?? '')))
|
|
15
|
+
return { implement: true };
|
|
16
|
+
const file = e.input?.file_path ?? e.input?.notebook_path;
|
|
17
|
+
|
|
18
|
+
return e.kind === 'edit' && typeof file === 'string' ? { write: { id: e.id, file } } : {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One session's step-13 watch in `dir`: `see(events)` takes each line's neutral events;
|
|
23
|
+
* `implement` and `wrote` are what it found. The code writes are kept by call id until a failed
|
|
24
|
+
* result drops one; `dir`'s planning files are no code.
|
|
25
|
+
*/
|
|
26
|
+
export function implementWatch(dir) {
|
|
27
|
+
const writes = new Map();
|
|
28
|
+
const w = {
|
|
29
|
+
implement: false,
|
|
30
|
+
wrote: false,
|
|
31
|
+
see(events) {
|
|
32
|
+
for (const e of events) {
|
|
33
|
+
const s = stepOf(e);
|
|
34
|
+
w.implement ||= Boolean(s.implement);
|
|
35
|
+
if (s.write && !planning(dir, s.write.file)) writes.set(s.write.id, s.write.file);
|
|
36
|
+
// A refused or failed call wrote nothing: its write does not count.
|
|
37
|
+
if (e.type === 'tool_result' && e.error) writes.delete(e.id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
w.wrote = writes.size > 0;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return w;
|
|
45
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// The steps of an item's session the operator's chat shows (Board-PRD §5.13): read from the main
|
|
2
|
+
// agent's tool calls and their results, never from what it says. A plan converged (the first
|
|
3
|
+
// aif-implement, with the plan checks before it), the DoD (`gcf verify`), the review (a subagent
|
|
4
|
+
// the gcf-run skill names `gcf review`), a commit, the item's move. A step's `ok` is what the
|
|
5
|
+
// work left, not the tool's exit (fix A, AD-37): an agent pipes `gcf verify | tail`, whose exit
|
|
6
|
+
// is tail's. `null`: unknown.
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
|
|
9
|
+
/** The description gcf-run gives its reviewer subagent: how the review is told from the rest. */
|
|
10
|
+
export const REVIEW = 'gcf review';
|
|
11
|
+
|
|
12
|
+
// The first that matches a Bash command names its step.
|
|
13
|
+
/** @type {[RegExp, string][]} */
|
|
14
|
+
const BASH = [
|
|
15
|
+
[/\bai-factory\s+gcf\s+plan\s+check\b/, 'plan-check'],
|
|
16
|
+
[/\bai-factory\s+gcf\s+verify\b/, 'dod'],
|
|
17
|
+
[/\bgit\s+commit\b/, 'commit'],
|
|
18
|
+
[/\bai-factory\s+gcf\s+(submit|close|block)\b/, 'move'],
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
/** The step a shell command is, or null. */
|
|
22
|
+
function bashStep(command) {
|
|
23
|
+
// `verify --mark` stamps a worktree's branch after the DoD: no DoD of its own; the rest of
|
|
24
|
+
// the command still counts.
|
|
25
|
+
const rest = command.replace(/\bai-factory\s+gcf\s+verify\b[^|&;]*\s--mark\b[^|&;]*/g, '');
|
|
26
|
+
for (const [re, step] of BASH) {
|
|
27
|
+
const m = re.exec(rest);
|
|
28
|
+
if (m) return step === 'move' ? { step, move: m[1] } : { step };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The step a tool call (a neutral `tool_call`) is, or null. */
|
|
35
|
+
function stepOf(c) {
|
|
36
|
+
const input = c.input ?? {};
|
|
37
|
+
if (c.kind === 'shell') return bashStep(String(input.command ?? ''));
|
|
38
|
+
if (c.kind === 'subagent' && input.description === REVIEW) return { step: 'review' };
|
|
39
|
+
// A plugin's skill comes as <plugin>:aif-implement.
|
|
40
|
+
const implement = /(^|:)aif-implement$/.test(String(input.skill ?? ''));
|
|
41
|
+
|
|
42
|
+
return c.kind === 'skill' && implement ? { step: 'plan' } : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Whether the item's `gcf verify` between `from` and `to` (ms) was green: its one row of
|
|
47
|
+
* verify-log.csv (`at,item,ok,failed,mark`, a `--mark` run aside); null with none or several.
|
|
48
|
+
*/
|
|
49
|
+
function verified(file, item, from, to) {
|
|
50
|
+
let text;
|
|
51
|
+
try {
|
|
52
|
+
text = readFileSync(file, 'utf8');
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const rows = text
|
|
58
|
+
.split('\n')
|
|
59
|
+
.map((l) => l.split(','))
|
|
60
|
+
.filter(([at, id, , , mark]) => {
|
|
61
|
+
const t = Date.parse(at);
|
|
62
|
+
|
|
63
|
+
return id === item && mark !== '1' && t >= from && t <= to;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return rows.length === 1 ? rows[0][2] === '1' : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The first line of a tool's result, for a step that failed. */
|
|
70
|
+
const firstLine = (text) =>
|
|
71
|
+
(
|
|
72
|
+
String(text)
|
|
73
|
+
.split('\n')
|
|
74
|
+
.find((l) => l.trim()) ?? ''
|
|
75
|
+
)
|
|
76
|
+
.trim()
|
|
77
|
+
.slice(0, 200);
|
|
78
|
+
|
|
79
|
+
// A row's time and the watch's may part by this much: the same machine, two processes.
|
|
80
|
+
const SKEW_MS = 2000;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* An item's watch, across its sessions: `see(e)` takes each neutral event of a session (gcf-session
|
|
84
|
+
* `Neutral`) and gives the steps it ends. The plan converges once per item, whatever session
|
|
85
|
+
* reaches it. `verifyLog` is main's verify-log.csv and `item` the item, which the DoD's `ok`
|
|
86
|
+
* is read from; `head()` the session checkout's HEAD, which a commit's is; `worktree`: its
|
|
87
|
+
* moves are recorded on main, not here.
|
|
88
|
+
* @param {{verifyLog?: string, item?: string, head?: () => string | null, worktree?: boolean}} [o]
|
|
89
|
+
*/
|
|
90
|
+
export function milestones({ verifyLog, item, head = () => null, worktree = false } = {}) {
|
|
91
|
+
const calls = new Map();
|
|
92
|
+
const w = { checks: 0, planned: false };
|
|
93
|
+
// A call the watch knows waits for its result; the first aif-implement is the plan's step.
|
|
94
|
+
const called = (e) => {
|
|
95
|
+
const step = stepOf(e);
|
|
96
|
+
if (step?.step === 'move' && worktree) return [];
|
|
97
|
+
if (step?.step !== 'plan') {
|
|
98
|
+
if (step)
|
|
99
|
+
calls.set(e.id, { ...step, at: Date.now(), head: step.step === 'commit' ? head() : null });
|
|
100
|
+
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const first = !w.planned;
|
|
105
|
+
w.planned = true;
|
|
106
|
+
|
|
107
|
+
return first ? [{ type: 'step', step: 'plan', passes: w.checks }] : [];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** A step's `ok`: the DoD's row, a commit's new HEAD, else the tool's own result. */
|
|
111
|
+
const okOf = (step, e) => {
|
|
112
|
+
if (step.step === 'dod')
|
|
113
|
+
return verifyLog && item
|
|
114
|
+
? verified(verifyLog, item, step.at - SKEW_MS, Date.now() + SKEW_MS)
|
|
115
|
+
: null;
|
|
116
|
+
if (step.step === 'commit' && step.head) return head() !== step.head;
|
|
117
|
+
|
|
118
|
+
return !e.error;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const ended = (e) => {
|
|
122
|
+
const call = calls.get(e.id);
|
|
123
|
+
calls.delete(e.id);
|
|
124
|
+
if (!call || call.step === 'plan-check') {
|
|
125
|
+
if (call) w.checks++;
|
|
126
|
+
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const { at: _, head: __, ...step } = call;
|
|
131
|
+
const ok = okOf(call, e);
|
|
132
|
+
|
|
133
|
+
return [{ type: 'step', ...step, ok, ...(ok === false ? { text: firstLine(e.text) } : {}) }];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
// A session after an earlier run's handoff goes on from a plan that converged before it.
|
|
138
|
+
skipPlan: () => {
|
|
139
|
+
w.planned = true;
|
|
140
|
+
},
|
|
141
|
+
see(e) {
|
|
142
|
+
// A subagent's calls (a reviewer running the tests) are its own, not the item's steps.
|
|
143
|
+
if (!e || e.sub) return [];
|
|
144
|
+
if (e.type === 'tool_call') return called(e);
|
|
145
|
+
|
|
146
|
+
return e.type === 'tool_result' ? ended(e) : [];
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|