gcf-harness-aif-ext 0.12.0 → 0.12.2
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 +2 -0
- package/commands/run.js +40 -27
- package/extension.json +1 -1
- package/node_modules/gcf-session/lib/adapter/claude.js +13 -0
- package/node_modules/gcf-session/lib/adapter/index.js +6 -0
- package/node_modules/gcf-session/lib/chat.js +10 -3
- package/node_modules/gcf-session/lib/index.js +4 -1
- package/node_modules/gcf-session/lib/job.js +23 -3
- package/node_modules/gcf-session/lib/thread.js +68 -6
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +28 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ 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.2 reads an item as it starts it: in a main-mode batch, an item the run has yet to reach takes a model or effort set meanwhile (`ai-factory gcf item agent`, core 0.12.3; a worktree run locks its items first). A stored `default` gives no `--model` or `--effort` flag.
|
|
51
|
+
|
|
50
52
|
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
53
|
- **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
54
|
- **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.
|
package/commands/run.js
CHANGED
|
@@ -108,13 +108,13 @@ const RUN_WORD = /^[A-Za-z0-9][\w.-]*$/;
|
|
|
108
108
|
/**
|
|
109
109
|
* The agent command of one item: its `model:` and `effort:` become `--model` and `--effort`,
|
|
110
110
|
* the flags of `claude`. The command goes through a shell, and an item file can be edited by
|
|
111
|
-
* hand: a value that is not one plain word is refused.
|
|
111
|
+
* hand: a value that is not one plain word is refused; `default` leaves it to the agent.
|
|
112
112
|
*/
|
|
113
113
|
export function agentFor(agent, item) {
|
|
114
114
|
const flags = [];
|
|
115
115
|
for (const k of ['model', 'effort']) {
|
|
116
116
|
const v = item?.[k];
|
|
117
|
-
if (v === null || v === undefined) continue;
|
|
117
|
+
if (v === null || v === undefined || v === 'default') continue;
|
|
118
118
|
if (!RUN_WORD.test(String(v))) throw new Error(`${k}: ${v} is not one plain word`);
|
|
119
119
|
flags.push(`--${k} ${v}`);
|
|
120
120
|
}
|
|
@@ -322,7 +322,9 @@ function recordFor(r) {
|
|
|
322
322
|
|
|
323
323
|
/**
|
|
324
324
|
* The line of a session that ended with its item still ready: why, and what a rerun does. A
|
|
325
|
-
* usage limit pauses the item; `limit_resets` tells a board when it may go on.
|
|
325
|
+
* usage limit pauses the item; `limit_resets` tells a board when it may go on. A stop during
|
|
326
|
+
* the limit's wait pauses the item the same way, but it is the operator's: no `limit_resets`,
|
|
327
|
+
* so a board's queue goes on (PRD §3.2).
|
|
326
328
|
*/
|
|
327
329
|
function noResult(r, rerun) {
|
|
328
330
|
if (r.lost)
|
|
@@ -332,39 +334,36 @@ function noResult(r, rerun) {
|
|
|
332
334
|
`no result (its session could not be resumed, agent exit ${r.code}): ` +
|
|
333
335
|
`${r.id} stays ready, a rerun starts fresh`,
|
|
334
336
|
};
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
337
|
+
// The operator's stop during the wait leaves the item paused, with no reset for a board.
|
|
338
|
+
const resets = r.limit && !r.stopped ? { limit_resets: r.limit.resets } : {};
|
|
339
|
+
const limit = r.limit ? `usage limit${r.limit.resets ? `, resets ${r.limit.resets}` : ''}` : '';
|
|
340
|
+
if (r.handoffPending)
|
|
340
341
|
return {
|
|
341
342
|
id: r.id,
|
|
342
343
|
result:
|
|
343
|
-
`paused (${limit}context handoff): ${r.id} stays ready, ` +
|
|
344
|
-
|
|
344
|
+
`paused (${limit ? `${limit}; ` : ''}context handoff): ${r.id} stays ready, ` +
|
|
345
|
+
'a rerun goes on from the plan',
|
|
346
|
+
...resets,
|
|
345
347
|
};
|
|
346
|
-
}
|
|
347
348
|
|
|
348
349
|
const again = r.session_id ? 'a rerun resumes its session' : rerun;
|
|
349
350
|
if (r.limit) {
|
|
350
|
-
const
|
|
351
|
+
const stop = r.stopped ? ', stopped during the wait' : '';
|
|
351
352
|
|
|
352
353
|
return {
|
|
353
354
|
id: r.id,
|
|
354
|
-
result: `paused (
|
|
355
|
-
|
|
355
|
+
result: `paused (${limit}${stop}): ${r.id} stays ready, ${again}`,
|
|
356
|
+
...resets,
|
|
356
357
|
};
|
|
357
358
|
}
|
|
358
359
|
|
|
359
|
-
|
|
360
|
-
? 'stopped'
|
|
361
|
-
: r.code === 'timeout'
|
|
362
|
-
? 'the session timed out'
|
|
363
|
-
: `agent exit ${r.code}`;
|
|
364
|
-
|
|
365
|
-
return { id: r.id, result: `no result (${why}): ${r.id} stays ready, ${again}` };
|
|
360
|
+
return { id: r.id, result: `no result (${endWhy(r)}): ${r.id} stays ready, ${again}` };
|
|
366
361
|
}
|
|
367
362
|
|
|
363
|
+
/** Why a session with no result ended: stopped, timed out, or its agent's exit. */
|
|
364
|
+
const endWhy = (r) =>
|
|
365
|
+
r.stopped ? 'stopped' : r.code === 'timeout' ? 'the session timed out' : `agent exit ${r.code}`;
|
|
366
|
+
|
|
368
367
|
const STAYED = / stays ready, a rerun /;
|
|
369
368
|
|
|
370
369
|
// `--no-lessons`: the run asks the lessons itself, after the session (see `lessonsTurn`).
|
|
@@ -883,7 +882,7 @@ async function mainItem(projectDir, id, ctx) {
|
|
|
883
882
|
const s = {
|
|
884
883
|
id,
|
|
885
884
|
dir: projectDir,
|
|
886
|
-
agent: agentOf(id),
|
|
885
|
+
agent: await agentOf(id),
|
|
887
886
|
release: none,
|
|
888
887
|
main: true,
|
|
889
888
|
done,
|
|
@@ -985,8 +984,9 @@ const extras = (r, note = null) => {
|
|
|
985
984
|
|
|
986
985
|
/** Every claimed item in its worktree at once; blocks recorded on main, verified ones merged. */
|
|
987
986
|
async function runWorktrees(claims, ctx) {
|
|
988
|
-
const { core, logs
|
|
989
|
-
|
|
987
|
+
const { core, logs } = ctx;
|
|
988
|
+
// Its items are locked already: no move changes them after the run's first read.
|
|
989
|
+
const { ready, failed } = await prepare(claims, core, ctx.agentFirst);
|
|
990
990
|
// A session that verified its branch, or left an outcome, is done: no fresh one follows.
|
|
991
991
|
const done = (r) => () =>
|
|
992
992
|
verified(r.dir, r.id) || existsSync(path.join(r.dir, '.gcf-session', 'outcome.json'));
|
|
@@ -1077,9 +1077,22 @@ export async function run(
|
|
|
1077
1077
|
});
|
|
1078
1078
|
if (!passed.pass) return { orphans, gate: passed.reason, items: [] };
|
|
1079
1079
|
|
|
1080
|
-
const itemOf = (id) => (
|
|
1081
|
-
|
|
1082
|
-
|
|
1080
|
+
const itemOf = (items, id) => (items ?? []).find((i) => i.id === id);
|
|
1081
|
+
// Read as the item starts: a main run's later items take a model or effort set meanwhile
|
|
1082
|
+
// (`gcf item agent`); a board that cannot be read leaves the run's first read.
|
|
1083
|
+
const agentOf = async (id) => {
|
|
1084
|
+
let now = null;
|
|
1085
|
+
try {
|
|
1086
|
+
now = itemOf(json(await core(['board', '--json']), 'board').items, id);
|
|
1087
|
+
} catch {
|
|
1088
|
+
// The first read below.
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
return agentFor(agent, now ?? itemOf(board.items, id));
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
const agentFirst = (id) => agentFor(agent, itemOf(board.items, id));
|
|
1095
|
+
const ctx = { core, logs, agentOf, agentFirst, timeoutMs, fresh, launch, waitLimit, limitClock };
|
|
1083
1096
|
const unhook = stopWithSessions();
|
|
1084
1097
|
try {
|
|
1085
1098
|
const items = await (runMode === 'main'
|
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.12.
|
|
4
|
+
"version": "0.12.2",
|
|
5
5
|
"description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
|
|
6
6
|
"skills": [
|
|
7
7
|
"skills/gcf-run",
|
|
@@ -14,6 +14,9 @@ export const CHAT_FLAGS =
|
|
|
14
14
|
// What `claude --resume` prints on stderr for a session it does not have.
|
|
15
15
|
export const NO_SESSION = /No conversation found with session ID/;
|
|
16
16
|
|
|
17
|
+
/** What an operator may pick for a session (a thread's `agent.json`). */
|
|
18
|
+
export const PICKS = ['model', 'effort'];
|
|
19
|
+
|
|
17
20
|
/** One line of stream-json input. */
|
|
18
21
|
const line = (e) => `${JSON.stringify(e)}\n`;
|
|
19
22
|
|
|
@@ -214,6 +217,16 @@ export const claude = {
|
|
|
214
217
|
[agent, resume && `--resume ${resume}`, flags, chat ? CHAT_FLAGS : `"${prompt}"`]
|
|
215
218
|
.filter(Boolean)
|
|
216
219
|
.join(' '),
|
|
220
|
+
/**
|
|
221
|
+
* What an operator picks a session's model and effort from (Board-PRD decision 24); another
|
|
222
|
+
* plain word goes too, and none leaves the choice to claude.
|
|
223
|
+
*/
|
|
224
|
+
presets: {
|
|
225
|
+
model: ['opus', 'sonnet', 'haiku'],
|
|
226
|
+
effort: ['low', 'medium', 'high', 'xhigh', 'max'],
|
|
227
|
+
},
|
|
228
|
+
/** The flags of a picked model and effort (`{model?, effort?}`, plain words). */
|
|
229
|
+
pickFlags: (pick) => PICKS.flatMap((k) => (pick?.[k] ? [`--${k} ${pick[k]}`] : [])).join(' '),
|
|
217
230
|
/** The env a session adds: the guards read the session's own checkout. */
|
|
218
231
|
env: (dir) => ({ CLAUDE_PROJECT_DIR: dir }),
|
|
219
232
|
parse: activity,
|
|
@@ -20,6 +20,9 @@ export const raw = {
|
|
|
20
20
|
},
|
|
21
21
|
command: ({ agent, flags = '', chat = false, prompt }) =>
|
|
22
22
|
claude.command({ agent, flags, chat, prompt }),
|
|
23
|
+
// An unknown command takes no claude flags of a model or effort.
|
|
24
|
+
presets: { model: [], effort: [] },
|
|
25
|
+
pickFlags: () => '',
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
/**
|
|
@@ -31,3 +34,6 @@ export const adapterFor = (command) =>
|
|
|
31
34
|
(process.env.GCF_SESSION_AGENT && command === process.env.GCF_SESSION_AGENT)
|
|
32
35
|
? claude
|
|
33
36
|
: raw;
|
|
37
|
+
|
|
38
|
+
/** What an operator picks the model and effort of `command`'s sessions from. */
|
|
39
|
+
export const presetsOf = (command) => adapterFor(command).presets;
|
|
@@ -453,12 +453,14 @@ async function decided(c, requestId, { allow, by = 'operator', always = false })
|
|
|
453
453
|
return post(c, { type: 'denied', request_id: requestId, tool: card.tool, by, title });
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
-
|
|
456
|
+
let rule = always ? card.always : null;
|
|
457
457
|
if (rule) {
|
|
458
458
|
try {
|
|
459
459
|
await c.saveAlways(rule);
|
|
460
460
|
} catch (e) {
|
|
461
461
|
post(c, { type: 'error', text: `the rule ${rule} was not saved: ${e.message}` });
|
|
462
|
+
// "Saved" is the event's word (chat-events.md): a rule not saved is an allow once.
|
|
463
|
+
rule = null;
|
|
462
464
|
}
|
|
463
465
|
}
|
|
464
466
|
|
|
@@ -706,7 +708,8 @@ function see(c, events) {
|
|
|
706
708
|
* (`{flagged}`): a flagged session closes at its turn's end; `context()` the context it holds
|
|
707
709
|
* (`{context, context_pct}`); `pause(on)` stops the session's timeout while it waits for the
|
|
708
710
|
* operator; `prompt` is the first message; `kind` how the session started (`start`, `resume`,
|
|
709
|
-
* `handoff`); `
|
|
711
|
+
* `handoff`); `pick` the model and effort a project chat's session was started with;
|
|
712
|
+
* `steps.see(e)` the steps an event ends; `defaultAnswer` what silence says.
|
|
710
713
|
* `see(events)` takes the neutral events of each line the agent prints; `event(e)` posts one
|
|
711
714
|
* the run saw; `encode` writes its input as the agent reads it;
|
|
712
715
|
* `close(code, seen)` stops reading and posts the session's end.
|
|
@@ -724,7 +727,11 @@ export function openChat(opts) {
|
|
|
724
727
|
// A session that ended under a write to its stdin breaks the pipe: the end is its close.
|
|
725
728
|
c.stdin.on('error', () => {});
|
|
726
729
|
const from = opts.summary ? { summary: opts.summary } : {};
|
|
727
|
-
|
|
730
|
+
// A project chat's session says the model and effort it was started with (null: the agent's).
|
|
731
|
+
const picked = opts.pick
|
|
732
|
+
? { model: opts.pick.model ?? null, effort: opts.pick.effort ?? null }
|
|
733
|
+
: {};
|
|
734
|
+
post(c, { type: 'session', kind: c.kind, v: EVENTS_V, ...from, ...picked });
|
|
728
735
|
// A project chat starts on the operator's message, not on a prompt of its own.
|
|
729
736
|
// A run's prompt is the run's; a project chat's (after the limit's reset) the engine's.
|
|
730
737
|
if (opts.prompt) say(c, opts.prompt, c.handover ? 'engine' : 'run');
|
|
@@ -31,9 +31,10 @@ export {
|
|
|
31
31
|
export { addCost, beyond } from './cost.js';
|
|
32
32
|
export { claim, clearDead, create, dead } from './lock.js';
|
|
33
33
|
export { WIN, alive, byLine, killTree, sessions, spawnAgent, stopWithSessions } from './proc.js';
|
|
34
|
-
export { adapterFor, raw } from './adapter/index.js';
|
|
34
|
+
export { adapterFor, presetsOf, raw } from './adapter/index.js';
|
|
35
35
|
export {
|
|
36
36
|
NO_SESSION,
|
|
37
|
+
PICKS,
|
|
37
38
|
claude,
|
|
38
39
|
encode,
|
|
39
40
|
hookCall,
|
|
@@ -52,6 +53,8 @@ export {
|
|
|
52
53
|
listThreads,
|
|
53
54
|
readThread,
|
|
54
55
|
runThread,
|
|
56
|
+
setThreadAgent,
|
|
57
|
+
threadAgent,
|
|
55
58
|
threadDir,
|
|
56
59
|
threadOf,
|
|
57
60
|
} from './thread.js';
|
|
@@ -305,6 +305,7 @@ export async function runJob(p) {
|
|
|
305
305
|
// A record whose handoff its own run already counted (`counted`) owes none.
|
|
306
306
|
if (kind === 'handoff' && !rec.counted && (await capped(j)))
|
|
307
307
|
return { code: 0, handoffs: j.handoffs, handoffLimit: true, handoffPending: false };
|
|
308
|
+
await noReset(j, kind, rec);
|
|
308
309
|
try {
|
|
309
310
|
return await chain(j, kind, rec);
|
|
310
311
|
} finally {
|
|
@@ -314,18 +315,37 @@ export async function runJob(p) {
|
|
|
314
315
|
}
|
|
315
316
|
}
|
|
316
317
|
|
|
318
|
+
/**
|
|
319
|
+
* A record a stopped wait left paused: limit names its reset: a run started on it (the
|
|
320
|
+
* operator's Run, before the reset or after) names none while it works (AD-32), so no board
|
|
321
|
+
* reads it as waiting for the limit.
|
|
322
|
+
*/
|
|
323
|
+
async function noReset(j, kind, rec) {
|
|
324
|
+
if (!rec?.resets) return;
|
|
325
|
+
// As the gate's: a session the run does not resume is named by none, so a handoff stays one.
|
|
326
|
+
const resumes = kind === 'resume';
|
|
327
|
+
await j.p.persist?.({
|
|
328
|
+
session_id: resumes ? rec.session_id : undefined,
|
|
329
|
+
handoffs: j.handoffs,
|
|
330
|
+
handoffPending: false,
|
|
331
|
+
total: resumes ? Number(rec.cost_usd) || undefined : undefined,
|
|
332
|
+
limit: { resets: null },
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
317
336
|
/**
|
|
318
337
|
* A session the usage limit cut (`s.ran`): the job waits for the reset, then goes on with it
|
|
319
338
|
* resumed; with a fresh one when it was told to hand over (a handoff, counted), or when it has
|
|
320
|
-
* no session to resume. No wait leaves it as it ended: paused. A stop during the wait
|
|
321
|
-
* the
|
|
339
|
+
* no session to resume. No wait leaves it as it ended: paused. A stop during the wait keeps
|
|
340
|
+
* the limit and its reset (PRD §3.2): the item is paused: limit, and a rerun resumes the
|
|
341
|
+
* session; the stop is the operator's, so it pauses no queue.
|
|
322
342
|
*/
|
|
323
343
|
async function overLimit(j, s) {
|
|
324
344
|
while (s.ran.limit && !s.ran.stopped && !(await j.p.done?.())) {
|
|
325
345
|
const { reset, handover, state } = limitState(j, s);
|
|
326
346
|
if (handover && (await pastCap(j))) return;
|
|
327
347
|
const waited = await limitWait(j, reset, state);
|
|
328
|
-
if (waited === 'stopped') s.ran = { ...s.ran,
|
|
348
|
+
if (waited === 'stopped') s.ran = { ...s.ran, stopped: true };
|
|
329
349
|
if (waited !== 'reset' || (handover && (await capped(j)))) return;
|
|
330
350
|
await afterReset(j, s, handover);
|
|
331
351
|
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// project's folder, run as a job with a chat policy. Its files live in `.gcf-session/chats/<t>/`:
|
|
3
3
|
// `thread.json` (its sessions), `chat.jsonl` (what the operator reads), `chat-in.jsonl` (what
|
|
4
4
|
// the operator writes), `att/` (pictures), `context.md` (what the center gives it to read),
|
|
5
|
-
// `handoff-<n>.md` (the summaries its sessions handed over by), `spec.json` (how it runs)
|
|
5
|
+
// `handoff-<n>.md` (the summaries its sessions handed over by), `spec.json` (how it runs),
|
|
6
|
+
// `agent.json` (the model and effort the operator picked).
|
|
6
7
|
import { randomBytes } from 'node:crypto';
|
|
7
8
|
import {
|
|
8
9
|
closeSync,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
} from 'node:fs';
|
|
17
18
|
import path from 'node:path';
|
|
18
19
|
import { createHash } from 'node:crypto';
|
|
20
|
+
import { PICKS } from './adapter/claude.js';
|
|
19
21
|
import { adapterFor } from './adapter/index.js';
|
|
20
22
|
import { runJob } from './job.js';
|
|
21
23
|
import { alive, killTree } from './proc.js';
|
|
@@ -82,6 +84,56 @@ function keepTrying(dir, t, rec) {
|
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
// A picked model or effort goes into the agent's shell command: one plain word, no flag.
|
|
88
|
+
const PICK_WORD = /^[A-Za-z0-9][\w.-]*$/;
|
|
89
|
+
|
|
90
|
+
// The pick that leaves the choice to the agent.
|
|
91
|
+
const AGENT_DEFAULT = 'default';
|
|
92
|
+
|
|
93
|
+
const pickFile = (td) => path.join(td, 'agent.json');
|
|
94
|
+
|
|
95
|
+
/** A pick's word, or null for the agent's own: none, `default`, or a word that is not plain. */
|
|
96
|
+
const wordOf = (v) =>
|
|
97
|
+
typeof v === 'string' && v !== AGENT_DEFAULT && PICK_WORD.test(v) ? v : null;
|
|
98
|
+
|
|
99
|
+
/** What `agent.json` of folder `td` picks, `{model?, effort?}`; a hand edit's bad word left out. */
|
|
100
|
+
function pickIn(td) {
|
|
101
|
+
try {
|
|
102
|
+
const v = JSON.parse(readFileSync(pickFile(td), 'utf8'));
|
|
103
|
+
|
|
104
|
+
return Object.fromEntries(PICKS.flatMap((k) => (wordOf(v?.[k]) ? [[k, v[k]]] : [])));
|
|
105
|
+
} catch {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The model and effort thread `t`'s sessions run on, `{model?, effort?}`; none: the agent's. */
|
|
111
|
+
export const threadAgent = (dir, t) => pickIn(threadDir(dir, t));
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Pick the model and effort of thread `t` (Board-PRD decision 24): each a plain word, `default`
|
|
115
|
+
* or null the agent's own choice, one left out kept as it is. Its next session takes them (a
|
|
116
|
+
* resume or a fresh agent); the live one keeps its own. Returns the pick kept. A word that is not
|
|
117
|
+
* plain is a RangeError.
|
|
118
|
+
* @param {{model?: string | null, effort?: string | null}} pick
|
|
119
|
+
*/
|
|
120
|
+
export function setThreadAgent(dir, t, pick) {
|
|
121
|
+
for (const k of PICKS)
|
|
122
|
+
if (pick[k] && !PICK_WORD.test(pick[k]))
|
|
123
|
+
throw new RangeError(`${k} is one plain word, e.g. opus`);
|
|
124
|
+
const was = threadAgent(dir, t);
|
|
125
|
+
const kept = Object.fromEntries(
|
|
126
|
+
PICKS.flatMap((k) => {
|
|
127
|
+
const v = pick[k] === undefined ? was[k] : wordOf(pick[k]);
|
|
128
|
+
|
|
129
|
+
return v ? [[k, v]] : [];
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
writeAtomic(pickFile(threadDir(dir, t)), `${JSON.stringify(kept)}\n`);
|
|
133
|
+
|
|
134
|
+
return kept;
|
|
135
|
+
}
|
|
136
|
+
|
|
85
137
|
/** The thread bound to `item`, or null (AD-46). */
|
|
86
138
|
export function threadOf(dir, item) {
|
|
87
139
|
try {
|
|
@@ -205,18 +257,20 @@ function promptFile(td, spec, summary) {
|
|
|
205
257
|
|
|
206
258
|
/**
|
|
207
259
|
* The flags of a thread's session: ask mode with the spec's rules (AD-5), the project's settings,
|
|
208
|
-
* the MCP servers (the project's and the center's),
|
|
260
|
+
* the MCP servers (the project's and the center's), the prompt file at a start or a handoff, and
|
|
261
|
+
* the model and effort picked (`pick`).
|
|
209
262
|
* shortcut: claude's flags written out here; move them into the adapter with a second provider.
|
|
210
263
|
*/
|
|
211
|
-
function flagsOf(dir, td, spec, settings) {
|
|
264
|
+
function flagsOf({ dir, td, spec, adapter }, settings) {
|
|
212
265
|
const mcp = [
|
|
213
266
|
...(existsSync(path.join(dir, '.mcp.json')) ? ['.mcp.json'] : []),
|
|
214
267
|
...(spec.mcp ?? []),
|
|
215
268
|
];
|
|
216
269
|
|
|
217
|
-
return (kind, summary) =>
|
|
270
|
+
return (kind, summary, pick) =>
|
|
218
271
|
[
|
|
219
272
|
'--permission-mode default --setting-sources project,local',
|
|
273
|
+
adapter.pickFlags(pick),
|
|
220
274
|
`--settings "${settings}"`,
|
|
221
275
|
...(mcp.length ? ['--strict-mcp-config', ...mcp.map((f) => `--mcp-config "${f}"`)] : []),
|
|
222
276
|
kind === 'resume' ? '' : `--append-system-prompt-file "${promptFile(td, spec, summary)}"`,
|
|
@@ -241,7 +295,9 @@ export async function runThread(dir, t, spec, opts = {}) {
|
|
|
241
295
|
const last = rec.sessions.at(-1) ?? null;
|
|
242
296
|
const s = {
|
|
243
297
|
...{ dir, t, td, rec, spec, adapter, stopped },
|
|
244
|
-
flags: flagsOf(dir, td, spec, settingsOf(td, adapter, spec.rules)),
|
|
298
|
+
flags: flagsOf({ dir, td, spec, adapter }, settingsOf(td, adapter, spec.rules)),
|
|
299
|
+
// The model and effort of the session starting now: read afresh for each (agent.json).
|
|
300
|
+
pick: {},
|
|
245
301
|
learned: readWindows(runsDir(dir)),
|
|
246
302
|
input: inputOf(dir, t, rec),
|
|
247
303
|
// The newest summary: a fresh start after a lost resume goes on from it too.
|
|
@@ -374,6 +430,7 @@ function chatOf(s, kind, prev) {
|
|
|
374
430
|
saveAlways: (rule) => s.adapter.saveAlways(dir, rule),
|
|
375
431
|
handover: handoverOf(s),
|
|
376
432
|
summary: kind === 'handoff' ? s.summary : null,
|
|
433
|
+
pick: s.pick,
|
|
377
434
|
fresh: kind === 'handoff' || Boolean(rec.unheard),
|
|
378
435
|
onHeard: () => {
|
|
379
436
|
rec.unheard = false;
|
|
@@ -401,7 +458,12 @@ function jobOf(s, record) {
|
|
|
401
458
|
record,
|
|
402
459
|
// A thread starts on the operator's message; after the usage limit's wait, on this.
|
|
403
460
|
prompt: (kind, _caps, rec) => (rec?.ended === 'limit' ? AFTER_LIMIT : null),
|
|
404
|
-
flags
|
|
461
|
+
// The flags come before the chat of each session (job.js): the chat says what they picked.
|
|
462
|
+
flags: (kind) => {
|
|
463
|
+
s.pick = pickIn(s.td);
|
|
464
|
+
|
|
465
|
+
return s.flags(kind, s.summary, s.pick);
|
|
466
|
+
},
|
|
405
467
|
onSpawn: (p) => {
|
|
406
468
|
s.pid = p;
|
|
407
469
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
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",
|
|
@@ -10,7 +10,15 @@ interface At {
|
|
|
10
10
|
|
|
11
11
|
export type ChatEvent = At &
|
|
12
12
|
(
|
|
13
|
-
| {
|
|
13
|
+
| {
|
|
14
|
+
type: 'session';
|
|
15
|
+
kind: 'start' | 'resume' | 'handoff';
|
|
16
|
+
v?: number;
|
|
17
|
+
summary?: string;
|
|
18
|
+
/** A project chat's: the model and effort it started with; null, the agent's own. */
|
|
19
|
+
model?: string | null;
|
|
20
|
+
effort?: string | null;
|
|
21
|
+
}
|
|
14
22
|
| {
|
|
15
23
|
type: 'session_end';
|
|
16
24
|
code: number | 'timeout' | 'handoff' | 'idle' | string;
|
|
@@ -139,6 +147,25 @@ export interface ThreadSpec {
|
|
|
139
147
|
timeoutMin?: number;
|
|
140
148
|
}
|
|
141
149
|
|
|
150
|
+
/** The model and effort an operator picked, `chats/<t>/agent.json`: none, the agent's own. */
|
|
151
|
+
export interface AgentPick {
|
|
152
|
+
model?: string;
|
|
153
|
+
effort?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** What an agent command offers to pick from (Board-PRD decision 24). */
|
|
157
|
+
export interface AgentPresets {
|
|
158
|
+
model: string[];
|
|
159
|
+
effort: string[];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export declare function threadAgent(dir: string, t: string): AgentPick;
|
|
163
|
+
export declare function setThreadAgent(
|
|
164
|
+
dir: string,
|
|
165
|
+
t: string,
|
|
166
|
+
pick: { model?: string | null; effort?: string | null },
|
|
167
|
+
): AgentPick;
|
|
168
|
+
export declare function presetsOf(agent: string): AgentPresets;
|
|
142
169
|
export declare function createThread(dir: string, opts?: { item?: string | null }): string;
|
|
143
170
|
export declare function threadOf(dir: string, item: string): string | null;
|
|
144
171
|
export declare function threadDir(dir: string, t: string): string;
|