gcf-harness-aif-ext 0.20.0 → 0.21.1
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 +5 -1
- package/commands/harness.js +8 -4
- package/commands/metrics.js +2 -1
- package/commands/run.js +102 -11
- package/extension.json +1 -1
- package/node_modules/gcf-session/lib/activity.js +45 -1
- package/node_modules/gcf-session/lib/chat.js +88 -3
- package/node_modules/gcf-session/lib/session.js +22 -5
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +16 -0
- package/package.json +2 -2
- package/skills/gcf-run/SKILL.md +1 -0
package/README.md
CHANGED
|
@@ -47,6 +47,10 @@ 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.21.1: `/gcf-run` treats a `format:` line of `gcf plan check` (core 0.21: the plan's form against the plan profile) as polish its improve passes apply, never a block. It takes core 0.20 or 0.21 (the peer range of 0.21.0 left 0.21 out).
|
|
51
|
+
|
|
52
|
+
0.21.0 (bundled gcf-session 0.18.0): `run_end` also names the run's last DoD (`green`, `red`, `unknown`) and review, and the files a worktree run left uncommitted (`left`: the worktree, how many files; a rerun goes on there). A run's chat carries its subagents' and background shells' `task` events: the board shows what each does.
|
|
53
|
+
|
|
50
54
|
0.20.0 (bundled gcf-session 0.17.4): each item's run chat ends with `run_end`: the outcome, the reason word for word, cost, duration, main's commit, plan tasks left unticked, lessons, a broken step. The board draws it as the run's end card.
|
|
51
55
|
|
|
52
56
|
0.19.1: `next --plan` first closes the features whose children are all finished: a keep by the operator, with no run after it, finishes them too. `card` reports a unit that left design without its item as `drop` (a `gcf(drop)` commit) or `none`, not `card`.
|
|
@@ -113,7 +117,7 @@ Updating keeps the hook entry valid — it points into the extension's install d
|
|
|
113
117
|
0.9.0, to update together with core 0.7.6:
|
|
114
118
|
- The harness's own agent runs with `--permission-mode bypassPermissions`: it may do everything but the project's deny rules, which hold in every mode. The rules come from the deny groups of `gcf/config.yml` (`ai-factory gcf permissions`, or the board): git history and uncommitted work, recursive delete, publishing, the human's GCF moves and the guards are on by default; secrets, changes outside the project and killing processes are off. `git push` is allowed. Deny rules match the command as written: they catch accidents, not a rewording, and `/gcf-run` makes a refused command a stop with `needs permission: <command>`.
|
|
115
119
|
- A run loads the project's settings and MCP servers only (`--setting-sources project,local --strict-mcp-config --mcp-config .mcp.json`): the operator's plugins, hooks and claude.ai connectors stay out. So does `env` or `apiKeyHelper` in `~/.claude/settings.json`: an operator who logs in through them, not `claude login`, names the agent with `--agent`. The deny rules and the handoff guard come in `.gcf-session/runs/agent-settings.json` (`--settings`), so a worktree gets them without a commit.
|
|
116
|
-
- Context handoff: past `context_handoff_pct` (60 by default) of the window, or at a compaction, the run flags the session; the handoff guard then denies every call of the main agent but the plan's read and edit with the instruction to write `## Handoff` into the plan and end. The run starts a fresh session with `/gcf-run <id> --handoff`, which goes on from the plan: the ticked tasks stay done. A session that works on past its flag is stopped; after 3 handoffs in a row the item is blocked with `context handoff limit`. The window is `context_window`, else the one a result of the same model reported (`.gcf-session/runs/windows.json`); with neither, the first session of a model runs without a handoff and says so. The sessions of an item share one timeout, and their costs add up; `--json` gives `handoffs`.
|
|
120
|
+
- Context handoff: past `context_handoff_pct` (60 by default) of the window, or at a compaction, the run flags the session; the handoff guard then denies every call of the main agent but the plan's read and edit with the instruction to write `## Handoff` into the plan and end. The run starts a fresh session with `/gcf-run <id> --handoff`, which goes on from the plan: the ticked tasks stay done. A session that works on past its flag is stopped; after 3 handoffs in a row the item is blocked with `context handoff limit`. The window is `context_window`, else the one a result of the same model reported (`.gcf-session/runs/windows.json`); with neither, the first session of a model runs without a handoff and says so. A fresh session already over the share at its first turn (claude's own prompt and the skills hold about 40k tokens) is not handed over by the share, for a fresh one would start there too: its log says `handoff: off, the session starts at N% of the window, over context_handoff_pct P`; a compaction still hands it over (0.21.0). The sessions of an item share one timeout, and their costs add up; `--json` gives `handoffs`.
|
|
117
121
|
- `auto_compact_pct` sets the agent's `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE`, at least 15 points above the handoff share.
|
|
118
122
|
- The readset-guard reads the manifest of the directory the session started in (`CLAUDE_PROJECT_DIR`): an agent's `cd` no longer lifts the readset.
|
|
119
123
|
- `/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.
|
package/commands/harness.js
CHANGED
|
@@ -447,13 +447,17 @@ export function gateEach(report, ids) {
|
|
|
447
447
|
}
|
|
448
448
|
|
|
449
449
|
/**
|
|
450
|
-
* The checkout's uncommitted paths outside `gcf
|
|
451
|
-
* main run's code lands among them, so the board warns before its click (Tails
|
|
452
|
-
* moves' own refusals guard `gcf
|
|
450
|
+
* The checkout's uncommitted paths outside `gcf/` and `GLOSSARY.md`, untracked ones too (a new
|
|
451
|
+
* folder as one): a main run's code lands among them, so the board warns before its click (Tails
|
|
452
|
+
* "Первым" 6). The moves' own refusals guard `gcf/` and the glossary (core 0.21's gate scope).
|
|
453
|
+
* Null outside a git checkout.
|
|
453
454
|
*/
|
|
454
455
|
export function loosePaths(dir) {
|
|
455
456
|
// No optional locks: a main run's agent may be committing in the same checkout.
|
|
456
|
-
const args = [
|
|
457
|
+
const args = [
|
|
458
|
+
...['--no-optional-locks', 'status', '--porcelain', '-z', '--', '.'],
|
|
459
|
+
...[':(exclude)gcf', ':(exclude)GLOSSARY.md'],
|
|
460
|
+
];
|
|
457
461
|
const res = spawnSync('git', args, { cwd: dir, encoding: 'utf8' });
|
|
458
462
|
if (res.status !== 0) return null;
|
|
459
463
|
const parts = res.stdout.split('\0').filter(Boolean);
|
package/commands/metrics.js
CHANGED
|
@@ -88,7 +88,8 @@ export function summarize(dir, since = '') {
|
|
|
88
88
|
const finished = runs.filter((r) => !UNFINISHED.includes(r[3]));
|
|
89
89
|
const reached = finished.filter((r) => ['submit', 'close', 'decide', 'deferred'].includes(r[3]));
|
|
90
90
|
const spent = runs.map((r) => num(r[5])).filter((v) => v !== null);
|
|
91
|
-
// plan-log: at, item, ok, problems; verify-log: at, item, ok,
|
|
91
|
+
// plan-log: at, item, ok, problems, format lines (core 0.21); verify-log: at, item, ok,
|
|
92
|
+
// failed checks, mark
|
|
92
93
|
const plans = rows(dir, 'plan-log.csv', since);
|
|
93
94
|
const verifies = rows(dir, 'verify-log.csv', since).filter((r) => r[4] !== '1');
|
|
94
95
|
// guard-log: at, item, hook, tool
|
package/commands/run.js
CHANGED
|
@@ -1254,7 +1254,8 @@ async function runWorktrees(claims, ctx) {
|
|
|
1254
1254
|
|
|
1255
1255
|
return { ...i, ...r?.cost, ...extras(r) };
|
|
1256
1256
|
});
|
|
1257
|
-
for (const i of lines)
|
|
1257
|
+
for (const i of lines)
|
|
1258
|
+
if (i.result !== 'verified') await postEnd(ctx, i, runs.find((x) => x.id === i.id)?.dir);
|
|
1258
1259
|
|
|
1259
1260
|
return lines;
|
|
1260
1261
|
}
|
|
@@ -1331,10 +1332,57 @@ const OUTCOME = {
|
|
|
1331
1332
|
// The words that are a move of the core: the card names them beside the outcome.
|
|
1332
1333
|
const MOVES = ['submit', 'close', 'block', 'decide', 'deferred'];
|
|
1333
1334
|
|
|
1335
|
+
/** Where the core keeps item `id`'s worktree (`gcf worktree`, `worktreeOf` of the core). */
|
|
1336
|
+
const worktreeAt = (projectDir, id) =>
|
|
1337
|
+
path.join(path.resolve(projectDir), '.gcf-session', 'worktrees', id);
|
|
1338
|
+
|
|
1339
|
+
// What a run leaves in its worktree that is not its work: the gate's metrics, the session's files.
|
|
1340
|
+
const NOT_WORK = /^(gcf\/\.metrics\/|\.gcf-session\/)/;
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* The paths of `git status --porcelain -z`, a rename or copy at where it went: each entry is
|
|
1344
|
+
* `XY path`, NUL-ended, and a rename's source follows as one more. Not ` -> ` in a line: a
|
|
1345
|
+
* POSIX name may hold it (the audit of 2026-11-03).
|
|
1346
|
+
*/
|
|
1347
|
+
export function statusPaths(out) {
|
|
1348
|
+
const parts = out.split('\0');
|
|
1349
|
+
const paths = [];
|
|
1350
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1351
|
+
const entry = parts[i];
|
|
1352
|
+
if (entry.length < 4) continue;
|
|
1353
|
+
paths.push(entry.slice(3));
|
|
1354
|
+
if (/[RC]/.test(entry.slice(0, 2))) i++;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
return paths;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* The work a run left uncommitted in its worktree (`{worktree, files}`, the path from the
|
|
1362
|
+
* project), or null: none, or no worktree. A rerun goes on in that worktree.
|
|
1363
|
+
*/
|
|
1364
|
+
export function leftIn(dir, projectDir) {
|
|
1365
|
+
if (!dir || !existsSync(dir)) return null;
|
|
1366
|
+
const res = spawnSync('git', ['status', '--porcelain', '-z', '--untracked-files=all'], {
|
|
1367
|
+
cwd: dir,
|
|
1368
|
+
encoding: 'utf8',
|
|
1369
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' },
|
|
1370
|
+
});
|
|
1371
|
+
if (res.status !== 0) return null;
|
|
1372
|
+
const files = statusPaths(res.stdout).filter((p) => !NOT_WORK.test(p)).length;
|
|
1373
|
+
|
|
1374
|
+
return files ? { worktree: path.relative(projectDir, dir).replaceAll('\\', '/'), files } : null;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
/** A step's `ok` (`step` events, milestones.js) as the run's end names it. */
|
|
1378
|
+
const DOD = (ok) => (ok === true ? 'green' : ok === false ? 'red' : 'unknown');
|
|
1379
|
+
|
|
1334
1380
|
/**
|
|
1335
1381
|
* How an item's run ended, for its chat (`run_end`): the outcome (submitted, blocked, failed,
|
|
1336
1382
|
* paused, stopped, no-result, skipped), the move, the reason word for word, what it cost and
|
|
1337
|
-
* took, main's commit, the plan's tasks left unticked, the lessons it filed, a broken step
|
|
1383
|
+
* took, main's commit, the plan's tasks left unticked, the lessons it filed, a broken step, the
|
|
1384
|
+
* run's last DoD and review (from `launch.events`, its chat's events since the last run's end),
|
|
1385
|
+
* the work it left uncommitted in its worktree (`launch.worktree`).
|
|
1338
1386
|
*/
|
|
1339
1387
|
export function runEndOf(i, projectDir, launch = null) {
|
|
1340
1388
|
const result = String(i.result ?? 'merged');
|
|
@@ -1356,6 +1404,9 @@ export function runEndOf(i, projectDir, launch = null) {
|
|
|
1356
1404
|
} catch {
|
|
1357
1405
|
// Archived with its item: nothing left.
|
|
1358
1406
|
}
|
|
1407
|
+
const steps = (launch?.events ?? []).filter((e) => e.type === 'step');
|
|
1408
|
+
const dod = steps.findLast((e) => e.step === 'dod');
|
|
1409
|
+
const review = steps.findLast((e) => e.step === 'review');
|
|
1359
1410
|
|
|
1360
1411
|
return {
|
|
1361
1412
|
type: 'run_end',
|
|
@@ -1372,15 +1423,45 @@ export function runEndOf(i, projectDir, launch = null) {
|
|
|
1372
1423
|
unticked,
|
|
1373
1424
|
lessons: i.lessons ?? 0,
|
|
1374
1425
|
process: i.process ?? null,
|
|
1426
|
+
// null: the run reached no DoD, no review.
|
|
1427
|
+
dod: dod ? DOD(dod.ok) : null,
|
|
1428
|
+
review: review ? (review.ok === false ? 'failed' : 'done') : null,
|
|
1429
|
+
// A branch that went in took its work along.
|
|
1430
|
+
left: outcome === 'submitted' ? null : leftIn(launch?.worktree, projectDir),
|
|
1375
1431
|
};
|
|
1376
1432
|
}
|
|
1377
1433
|
|
|
1434
|
+
/** The events of an item's chat file that are this run's. */
|
|
1435
|
+
export function runEvents(file) {
|
|
1436
|
+
let lines;
|
|
1437
|
+
try {
|
|
1438
|
+
lines = readFileSync(file, 'utf8').split('\n');
|
|
1439
|
+
} catch {
|
|
1440
|
+
return [];
|
|
1441
|
+
}
|
|
1442
|
+
const events = lines.flatMap((l) => {
|
|
1443
|
+
try {
|
|
1444
|
+
return l.trim() ? [JSON.parse(l)] : [];
|
|
1445
|
+
} catch {
|
|
1446
|
+
return [];
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
// A run begins after the last one's end, or at its own first session (a run killed with no
|
|
1451
|
+
// end left none): a handoff's session goes on in the same run.
|
|
1452
|
+
const from = events.findLastIndex(
|
|
1453
|
+
(e) => e.type === 'run_end' || (e.type === 'session' && e.kind !== 'handoff'),
|
|
1454
|
+
);
|
|
1455
|
+
|
|
1456
|
+
return events.slice(from < 0 ? 0 : events[from].type === 'run_end' ? from + 1 : from);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1378
1459
|
/**
|
|
1379
1460
|
* Post an item's run end to its chat (Tails «Первым» 2), when the run has one: not for an item
|
|
1380
1461
|
* that never started (another run's lock), whose chat is that run's. The plan is the board's now:
|
|
1381
1462
|
* a first run made it.
|
|
1382
1463
|
*/
|
|
1383
|
-
async function postEnd(ctx, item) {
|
|
1464
|
+
async function postEnd(ctx, item, worktree = null) {
|
|
1384
1465
|
if (!ctx.launch?.chat || item.started === false) return;
|
|
1385
1466
|
let plans = {};
|
|
1386
1467
|
try {
|
|
@@ -1390,8 +1471,13 @@ async function postEnd(ctx, item) {
|
|
|
1390
1471
|
// No board: no plan count.
|
|
1391
1472
|
}
|
|
1392
1473
|
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1474
|
+
const file = chatOut(ctx.logs, item.id);
|
|
1475
|
+
const end = runEndOf(item, ctx.projectDir, {
|
|
1476
|
+
planOf: (id) => plans[id] ?? null,
|
|
1477
|
+
events: runEvents(file),
|
|
1478
|
+
worktree,
|
|
1479
|
+
});
|
|
1480
|
+
postTo(file, end);
|
|
1395
1481
|
}
|
|
1396
1482
|
|
|
1397
1483
|
/** Whether a commit dropped unit `id` (`gcf(drop): <id>`). */
|
|
@@ -1586,7 +1672,12 @@ async function runBatch(
|
|
|
1586
1672
|
const error = String(failed.reason?.message ?? failed.reason);
|
|
1587
1673
|
for (const [n, d] of driven.entries())
|
|
1588
1674
|
if (d.status === 'rejected')
|
|
1589
|
-
for (const id of parts[n][1])
|
|
1675
|
+
for (const id of parts[n][1])
|
|
1676
|
+
await postEnd(
|
|
1677
|
+
ctx,
|
|
1678
|
+
{ id, result: 'error', error },
|
|
1679
|
+
parts[n][0] === 'main' ? null : worktreeAt(projectDir, id),
|
|
1680
|
+
);
|
|
1590
1681
|
throw failed.reason;
|
|
1591
1682
|
}
|
|
1592
1683
|
|
|
@@ -1602,11 +1693,11 @@ async function runBatch(
|
|
|
1602
1693
|
for (const i of d.value.filter((x) => x.result === 'verified')) {
|
|
1603
1694
|
const merged = after.find((r) => r.id === i.id);
|
|
1604
1695
|
const result = merged?.move ?? (merged?.conflict ? 'conflict' : i.result);
|
|
1605
|
-
await postEnd(
|
|
1606
|
-
|
|
1607
|
-
result,
|
|
1608
|
-
|
|
1609
|
-
|
|
1696
|
+
await postEnd(
|
|
1697
|
+
ctx,
|
|
1698
|
+
{ ...i, result, ...(merged?.conflict && { conflict: merged.conflict }) },
|
|
1699
|
+
worktreeAt(projectDir, i.id),
|
|
1700
|
+
);
|
|
1610
1701
|
}
|
|
1611
1702
|
|
|
1612
1703
|
// `limit_wait`: this harness waits for a usage limit's reset itself (AD-19); a board reads it.
|
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-harness-aif-ext",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.21.1",
|
|
5
5
|
"description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
|
|
6
6
|
"skills": [
|
|
7
7
|
"skills/gcf-run",
|
|
@@ -201,10 +201,15 @@ export const kindOf = (tool) => KINDS[tool] ?? (/^mcp__/.test(tool) ? 'mcp' : 'o
|
|
|
201
201
|
* | {type: 'cancel', request_id: string}
|
|
202
202
|
* | {type: 'result', subtype?: string, total_cost_usd: number | null}
|
|
203
203
|
* | {type: 'background', tasks: {id: string, description: string}[]}
|
|
204
|
+
* | {type: 'task', phase: 'start' | 'progress' | 'end', id: string, kind: string | null,
|
|
205
|
+
* agent: string | null, description: string | null, doing: string | null,
|
|
206
|
+
* prompt: string | null, calls: number | null, ms: number | null, status: string | null,
|
|
207
|
+
* summary: string | null, call: string | null, background: boolean}
|
|
204
208
|
* | {type: 'compacted'}} Neutral
|
|
205
209
|
* The events a session's work is read by, the same from any agent: what the main agent (or a
|
|
206
210
|
* subagent, `sub`) said and called, the results, the operator's messages it took in, the
|
|
207
|
-
* question and permission requests, a turn's end, the background tasks,
|
|
211
|
+
* question and permission requests, a turn's end, the background tasks, each task's start,
|
|
212
|
+
* progress and end, a compaction.
|
|
208
213
|
*/
|
|
209
214
|
|
|
210
215
|
/** @returns {Neutral[]} */
|
|
@@ -319,6 +324,9 @@ function systemEvents(e) {
|
|
|
319
324
|
reason: String(e.message ?? ''),
|
|
320
325
|
},
|
|
321
326
|
];
|
|
327
|
+
// An ambient task (claude's own, e.g. a memory pass) is none of the agent's work.
|
|
328
|
+
if (Object.hasOwn(TASK_PHASE, e.subtype))
|
|
329
|
+
return e.ambient === true ? [] : [taskOf(e, TASK_PHASE[e.subtype])];
|
|
322
330
|
if (e.subtype !== 'background_tasks_changed') return [];
|
|
323
331
|
const tasks = (Array.isArray(e.tasks) ? e.tasks : []).map((t) => ({
|
|
324
332
|
id: String(t.task_id ?? t.id ?? ''),
|
|
@@ -328,6 +336,42 @@ function systemEvents(e) {
|
|
|
328
336
|
return [{ type: 'background', tasks }];
|
|
329
337
|
}
|
|
330
338
|
|
|
339
|
+
// A task of the session (a subagent, a background shell), claude 2.1.317: its start, its
|
|
340
|
+
// progress after each call it makes, its end.
|
|
341
|
+
const TASK_PHASE = { task_started: 'start', task_progress: 'progress', task_notification: 'end' };
|
|
342
|
+
// claude's task types, as the operator reads them.
|
|
343
|
+
const TASK_KIND = { local_agent: 'agent', local_bash: 'shell' };
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* One phase of a task: what it is (`kind`, the subagent's type `agent`), what it was started
|
|
347
|
+
* for (`description`, a subagent's `prompt`), what it does now (`doing`, from a progress), the
|
|
348
|
+
* calls it made and how long it took so far (`calls`, `ms`), how it ended (`status`, `summary`),
|
|
349
|
+
* the main agent's call that started it (`call`) and whether it runs in the background.
|
|
350
|
+
* @returns {Neutral}
|
|
351
|
+
*/
|
|
352
|
+
function taskOf(e, phase) {
|
|
353
|
+
const str = (v) => (typeof v === 'string' && v ? v : null);
|
|
354
|
+
const num = (v) => (typeof v === 'number' ? v : null);
|
|
355
|
+
|
|
356
|
+
return {
|
|
357
|
+
type: 'task',
|
|
358
|
+
phase,
|
|
359
|
+
id: String(e.task_id ?? ''),
|
|
360
|
+
kind: TASK_KIND[e.task_type] ?? str(e.task_type),
|
|
361
|
+
agent: str(e.subagent_type),
|
|
362
|
+
// A progress's description says what the task does now, not what it was started for.
|
|
363
|
+
description: phase === 'progress' ? null : str(e.description),
|
|
364
|
+
doing: phase === 'progress' ? str(e.description) : null,
|
|
365
|
+
prompt: str(e.prompt),
|
|
366
|
+
calls: num(e.usage?.tool_uses),
|
|
367
|
+
ms: num(e.usage?.duration_ms),
|
|
368
|
+
status: str(e.status),
|
|
369
|
+
summary: str(e.summary),
|
|
370
|
+
call: str(e.tool_use_id),
|
|
371
|
+
background: e.is_backgrounded === true,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
331
375
|
/**
|
|
332
376
|
* The account's usage-limit state as the stream gives it, raw: kept to learn its fields before
|
|
333
377
|
* the board shows the quota (Board-PRD decision 17). Any other event gives nothing.
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
17
|
import path from 'node:path';
|
|
18
18
|
import { CHAT_FLAGS, encode as claudeInput } from './adapter/claude.js';
|
|
19
|
+
import { kindOf } from './activity.js';
|
|
19
20
|
|
|
20
21
|
export { CHAT_FLAGS };
|
|
21
22
|
|
|
@@ -62,6 +63,11 @@ const PATH_GLOB = { '**/': '(?:.*/)?', '**': '.*', '*': '[^/]*' };
|
|
|
62
63
|
// How much of a refused call the chat keeps: its command or file, and what it was for.
|
|
63
64
|
const TITLE_MAX = 2000;
|
|
64
65
|
const WHY_MAX = 500;
|
|
66
|
+
// A task's start keeps the head of what it was told, its end the head of its report; one
|
|
67
|
+
// progress in TASK_EVERY_MS per task reaches the chat (one comes after each call it makes).
|
|
68
|
+
const TASK_PROMPT_MAX = 1000;
|
|
69
|
+
const TASK_SUMMARY_MAX = 4000;
|
|
70
|
+
const TASK_EVERY_MS = 2000;
|
|
65
71
|
const cut = (s, max) => (s.length > max ? `${s.slice(0, max)}…` : s);
|
|
66
72
|
|
|
67
73
|
// A shell line's pieces: a quoted string whole (an unclosed one to the end), a separator, a run
|
|
@@ -414,7 +420,8 @@ function say(c, text, by, m = {}) {
|
|
|
414
420
|
if (entry) entry.echo = true;
|
|
415
421
|
const shown = paths.length ? { images: paths } : {};
|
|
416
422
|
const again = retry ? { retry: true } : {};
|
|
417
|
-
|
|
423
|
+
// The chat shows what the operator wrote: the context that went before it is the agent's.
|
|
424
|
+
post(c, { type: 'say', by, text: own, ...shown, n: c.sent, ...(id ? { id } : {}), ...again });
|
|
418
425
|
|
|
419
426
|
return true;
|
|
420
427
|
}
|
|
@@ -531,7 +538,14 @@ async function decided(c, requestId, { allow, by = 'operator', always = false })
|
|
|
531
538
|
if (!allow) {
|
|
532
539
|
send(c, c.encode.deny(requestId, `the operator refused: ${title}`));
|
|
533
540
|
|
|
534
|
-
return post(c, {
|
|
541
|
+
return post(c, {
|
|
542
|
+
type: 'denied',
|
|
543
|
+
request_id: requestId,
|
|
544
|
+
tool: card.tool,
|
|
545
|
+
kind: kindOf(card.tool),
|
|
546
|
+
by,
|
|
547
|
+
title,
|
|
548
|
+
});
|
|
535
549
|
}
|
|
536
550
|
|
|
537
551
|
let rule = always ? card.always : null;
|
|
@@ -721,10 +735,51 @@ function permit(c, e) {
|
|
|
721
735
|
waitCards(c);
|
|
722
736
|
}
|
|
723
737
|
|
|
738
|
+
/**
|
|
739
|
+
* Whether a task's event (`{phase, id}`) reaches the chat at `now`: one progress per
|
|
740
|
+
* TASK_EVERY_MS per task. Within the gap the last one waits, and `later` posts it as the gap
|
|
741
|
+
* ends: a long step after it keeps its words. Any event that goes now drops the one held, which
|
|
742
|
+
* is older: a late timer would post it over the newer (the audit of 2026-11-03).
|
|
743
|
+
* `c` holds `taskAt` and `taskHeld` (maps by task id).
|
|
744
|
+
*/
|
|
745
|
+
export function taskGate(c, e, now, later) {
|
|
746
|
+
const held = c.taskHeld.get(e.id);
|
|
747
|
+
if (e.phase === 'progress') {
|
|
748
|
+
const left = (c.taskAt.get(e.id) ?? 0) + TASK_EVERY_MS - now;
|
|
749
|
+
if (left > 0) {
|
|
750
|
+
if (held) held.e = e;
|
|
751
|
+
else {
|
|
752
|
+
const h = { e, timer: setTimeout(later, left) };
|
|
753
|
+
h.timer.unref?.();
|
|
754
|
+
c.taskHeld.set(e.id, h);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
759
|
+
c.taskAt.set(e.id, now);
|
|
760
|
+
}
|
|
761
|
+
if (held) {
|
|
762
|
+
clearTimeout(held.timer);
|
|
763
|
+
c.taskHeld.delete(e.id);
|
|
764
|
+
}
|
|
765
|
+
if (e.phase === 'end') c.taskAt.delete(e.id);
|
|
766
|
+
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/** The progress a task held back, taken out once its gap is over: it is posted now. */
|
|
771
|
+
function flushed(c, id) {
|
|
772
|
+
const { e } = c.taskHeld.get(id);
|
|
773
|
+
c.taskHeld.delete(id);
|
|
774
|
+
c.taskAt.set(id, 0);
|
|
775
|
+
|
|
776
|
+
return e;
|
|
777
|
+
}
|
|
778
|
+
|
|
724
779
|
/** Refuse a tool call (`{request_id, tool}`) by the engine's own word, with no card before it. */
|
|
725
780
|
function refuse(c, { request_id: requestId, tool }, message, more = {}) {
|
|
726
781
|
send(c, c.encode.deny(requestId, message));
|
|
727
|
-
post(c, { type: 'denied', tool, by: 'engine', ...more });
|
|
782
|
+
post(c, { type: 'denied', tool, kind: kindOf(tool), by: 'engine', ...more });
|
|
728
783
|
}
|
|
729
784
|
|
|
730
785
|
// What the operator reads of each neutral event of the session, by its type.
|
|
@@ -759,6 +814,8 @@ const SEEN = {
|
|
|
759
814
|
post(c, {
|
|
760
815
|
type: 'denied',
|
|
761
816
|
tool: e.tool,
|
|
817
|
+
// The kind a card names (shell, edit…): the board folds the refusal into a line under it.
|
|
818
|
+
kind: kindOf(e.tool),
|
|
762
819
|
by: 'rule',
|
|
763
820
|
...(call ? { title: cut(call.title, TITLE_MAX), ...refusedBy(c.deny, call) } : {}),
|
|
764
821
|
...(why ? { description: cut(why, WHY_MAX) } : {}),
|
|
@@ -781,6 +838,31 @@ const SEEN = {
|
|
|
781
838
|
},
|
|
782
839
|
cancel: (c, e) => dropCard(c, e.request_id),
|
|
783
840
|
result: (c, e) => turnEnd(c, e),
|
|
841
|
+
// A subagent or a background shell: what it was started for, what it does, how it ended. A
|
|
842
|
+
// progress comes after each call it makes: one in TASK_EVERY_MS reaches the chat.
|
|
843
|
+
task: (c, e) => {
|
|
844
|
+
const later = () => {
|
|
845
|
+
const last = flushed(c, e.id);
|
|
846
|
+
if (!c.closed) SEEN.task(c, last);
|
|
847
|
+
};
|
|
848
|
+
if (!taskGate(c, e, Date.now(), later)) return;
|
|
849
|
+
const prompt = e.phase === 'start' ? e.prompt : null;
|
|
850
|
+
post(c, {
|
|
851
|
+
type: 'task',
|
|
852
|
+
phase: e.phase,
|
|
853
|
+
id: e.id,
|
|
854
|
+
...(e.kind ? { kind: e.kind } : {}),
|
|
855
|
+
...(e.agent ? { agent: e.agent } : {}),
|
|
856
|
+
...(e.description ? { description: cut(e.description, WHY_MAX) } : {}),
|
|
857
|
+
...(e.doing ? { doing: cut(e.doing, WHY_MAX) } : {}),
|
|
858
|
+
...(prompt ? { prompt: cut(prompt, TASK_PROMPT_MAX) } : {}),
|
|
859
|
+
...(e.calls !== null ? { calls: e.calls } : {}),
|
|
860
|
+
...(e.ms !== null ? { ms: e.ms } : {}),
|
|
861
|
+
...(e.status ? { status: e.status } : {}),
|
|
862
|
+
...(e.summary ? { summary: cut(e.summary, TASK_SUMMARY_MAX) } : {}),
|
|
863
|
+
...(e.background ? { background: true } : {}),
|
|
864
|
+
});
|
|
865
|
+
},
|
|
784
866
|
// While they run, no answer is waited for; claude starts a turn itself as they end. Their end
|
|
785
867
|
// with no new turn after the grace settles the session, so it is not held for good.
|
|
786
868
|
background: (c, e) => {
|
|
@@ -900,6 +982,9 @@ function chatState(opts) {
|
|
|
900
982
|
...{ sent: 0, read: 0, cards: new Map(), wait: null, defaulted: false, closed: false },
|
|
901
983
|
...{ stopped: false, grace: null, idle: false, inTurn: true, tasks: [] },
|
|
902
984
|
...{ proposals: new Map(), calls: new Map(), heard: false, summary: null, wanted: null },
|
|
985
|
+
// When each task's last progress reached the chat; the last one it held back since.
|
|
986
|
+
taskAt: new Map(),
|
|
987
|
+
taskHeld: new Map(),
|
|
903
988
|
why: null,
|
|
904
989
|
...{ hold: false, late: false, pending: [], echoes: [] },
|
|
905
990
|
};
|
|
@@ -39,12 +39,18 @@ function absorb(seen, a) {
|
|
|
39
39
|
/**
|
|
40
40
|
* The handoff watch of one session (see `runSession`): `see(a, model)` takes each activity,
|
|
41
41
|
* flags the session past its share or at a compaction (`handoff.flag`), and calls `stop` once it
|
|
42
|
-
* works on past more. `windowOf(model)` is the window the share is taken of.
|
|
42
|
+
* works on past more. `windowOf(model)` is the window the share is taken of. A run's `fresh`
|
|
43
|
+
* session (no resume) over the share at its first reading starts there: a fresh one after it,
|
|
44
|
+
* on the same prompt, would too, so the share does not hand it over (a live run at 10%, 2026-11-03: three sessions of 19% each
|
|
45
|
+
* handed over before any work, and the item blocked); a compaction still does.
|
|
43
46
|
*/
|
|
44
|
-
function handoffWatch(handoff, windowOf, write, { stop, onFlag }) {
|
|
47
|
+
function handoffWatch(handoff, windowOf, write, { stop, onFlag, fresh = false }) {
|
|
45
48
|
/** @type {{flagged: boolean, after: number, context: number, turn?: string, unknown: boolean,
|
|
46
|
-
* info?: object}} */
|
|
47
|
-
const w = {
|
|
49
|
+
* info?: object, readings: number, under: boolean}} */
|
|
50
|
+
const w = {
|
|
51
|
+
...{ flagged: false, after: 0, context: 0, turn: undefined, unknown: false },
|
|
52
|
+
...{ readings: 0, under: false },
|
|
53
|
+
};
|
|
48
54
|
const unknownOnce = (model) => {
|
|
49
55
|
if (w.unknown) return;
|
|
50
56
|
w.unknown = true;
|
|
@@ -69,7 +75,16 @@ function handoffWatch(handoff, windowOf, write, { stop, onFlag }) {
|
|
|
69
75
|
// No share is under every threshold: a session of an unknown window hands over at a compaction.
|
|
70
76
|
const share = pct ?? 0;
|
|
71
77
|
if (pct === null && !compacted) unknownOnce(model);
|
|
72
|
-
|
|
78
|
+
// A run's fresh session starts from the same prompt; a project chat's, from a summary.
|
|
79
|
+
const under = fresh && !handoff.soft && w.readings === 1 && share >= handoff.pct;
|
|
80
|
+
if (under && !compacted && !w.under) {
|
|
81
|
+
w.under = true;
|
|
82
|
+
write([
|
|
83
|
+
`[${clock()}] handoff: off, the session starts at ${pct}% of the window, over ` +
|
|
84
|
+
`context_handoff_pct ${handoff.pct}: a fresh session would start there too; raise it`,
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
if (!w.flagged && (compacted || (share >= handoff.pct && !w.under))) flag(win, pct, compacted);
|
|
73
88
|
// A project chat hands over by its summary turn, which goes on past the flag (AD-42).
|
|
74
89
|
if (handoff.soft) return;
|
|
75
90
|
if (w.flagged && (w.after > HARD_TURNS || share >= handoff.pct + HARD_OVER)) {
|
|
@@ -83,6 +98,7 @@ function handoffWatch(handoff, windowOf, write, { stop, onFlag }) {
|
|
|
83
98
|
see(a, model) {
|
|
84
99
|
if (a.context !== undefined) {
|
|
85
100
|
w.context = a.context;
|
|
101
|
+
w.readings++;
|
|
86
102
|
if (w.flagged && a.turn !== w.turn) w.after++;
|
|
87
103
|
w.turn = a.turn;
|
|
88
104
|
}
|
|
@@ -292,6 +308,7 @@ export function runSession(s) {
|
|
|
292
308
|
const watch = handoffWatch(handoff, windowOf, write, {
|
|
293
309
|
stop: stop('handoff'),
|
|
294
310
|
onFlag: flagged,
|
|
311
|
+
fresh: !s.resume,
|
|
295
312
|
});
|
|
296
313
|
const limit = sessionTimeout(timeoutMs, stop('timeout'), { halt, stop: stop('stopped') });
|
|
297
314
|
/** @type {((tokens: number, model?: string) => void) | null} */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "The session engine of GCF: one agent session and a run as a chain of them, the chat protocol, the provider adapters. Bundled by gcf-harness-aif-ext and gcf-board, never published.",
|
|
6
6
|
"type": "module",
|
|
@@ -46,6 +46,22 @@ export type ChatEvent = At &
|
|
|
46
46
|
/** `id`: the input line of the operator's message it did not send, when it has one. */
|
|
47
47
|
| { type: 'error'; text: string; id?: string }
|
|
48
48
|
| { type: 'background'; tasks: { id: string; description: string }[] }
|
|
49
|
+
/** A subagent's or a background shell's start, progress (one in 2 s) or end. */
|
|
50
|
+
| {
|
|
51
|
+
type: 'task';
|
|
52
|
+
phase: 'start' | 'progress' | 'end';
|
|
53
|
+
id: string;
|
|
54
|
+
kind?: string;
|
|
55
|
+
agent?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
doing?: string;
|
|
58
|
+
prompt?: string;
|
|
59
|
+
calls?: number;
|
|
60
|
+
ms?: number;
|
|
61
|
+
status?: string;
|
|
62
|
+
summary?: string;
|
|
63
|
+
background?: boolean;
|
|
64
|
+
}
|
|
49
65
|
| {
|
|
50
66
|
type: 'question';
|
|
51
67
|
request_id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-harness-aif-ext",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.1",
|
|
4
4
|
"description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"prepack": "node -e \"const p=require('./package.json'),e=require('./extension.json');if(p.version!==e.version)throw new Error('version mismatch: package.json '+p.version+' vs extension.json '+e.version);require('node:fs').statSync('node_modules/gcf-session/lib/index.js')\""
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"gcf-aif-ext": "
|
|
31
|
+
"gcf-aif-ext": ">=0.20.0 <0.22.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"gcf-session": "file:../gcf-session"
|
package/skills/gcf-run/SKILL.md
CHANGED
|
@@ -48,6 +48,7 @@ forbidden_behaviors:
|
|
|
48
48
|
- a plan pass sorts each finding as blocking or polish, and reports how many of each it found
|
|
49
49
|
- blocking: a wrong or missing behavior, a missing or wrong task, a broken pillar invariant, a conflict with a project rule, a task no check can prove
|
|
50
50
|
- polish: wording, splitting or merging tasks, their order, more detail - the pass applies it, and it does not keep the plan from converging
|
|
51
|
+
- a `format:` line of `ai-factory gcf plan check` is polish: the pass brings the plan into the plan form it names, and it never blocks
|
|
51
52
|
- do not edit `status:` or `gcf/LIVE.md` by hand: `submit`, `close` and `block` own them
|
|
52
53
|
- do not write a plan task's first implementation outside the aif-implement skill: it ticks the task done in the plan, and the board shows the item's progress from those ticks
|
|
53
54
|
- a fix for a red DoD or a review finding goes in directly, without aif-implement
|