copilot-operator 0.1.51 → 0.1.53
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 +24 -3
- package/dist/src/api/operator.controller.js +55 -71
- package/dist/src/api/operator.service.js +243 -109
- package/dist/src/config/schema.js +45 -0
- package/dist/src/exec/policy.js +11 -1
- package/dist/src/exec/scriptFiles.js +108 -2
- package/dist/src/orchestrator/leadRunner.js +605 -0
- package/dist/src/orchestrator/review.js +9 -3
- package/dist/src/orchestrator/taskRunner.js +110 -20
- package/dist/src/plan/kerrigan.js +203 -47
- package/dist/src/plan/systemGuide.js +555 -499
- package/dist/src/protocol/leadSchema.js +156 -0
- package/dist/src/protocol/parser.js +1 -1
- package/dist/src/session/chatNotice.js +115 -0
- package/dist/src/session/checkpoint.js +19 -0
- package/dist/src/session/compose.js +17 -5
- package/dist/src/session/store.js +21 -72
- package/dist/src/transport/copilotTransport.js +2 -0
- package/dist/src/util/pacing.js +33 -2
- package/dist/src/vcs/git.js +11 -1
- package/dist/src/vcs/referenceGuard.js +299 -0
- package/dist/web/404.html +14 -18
- package/dist/web/_next/static/FGzV3mVZpXRCVjiw1diNu/_buildManifest.js +1 -0
- package/dist/web/_next/static/chunks/163.980c5145848efbdf.js +1 -0
- package/dist/web/_next/static/chunks/220.447d1d8624d4644c.js +1 -0
- package/dist/web/_next/static/chunks/500-34d01f8d8d73eb2c.js +1 -0
- package/dist/web/_next/static/chunks/548.c6dfd1cb270f3c93.js +1 -0
- package/dist/web/_next/static/chunks/584.fc9e061dd4069406.js +1 -0
- package/dist/web/_next/static/chunks/67.1a3ca07919abce27.js +1 -0
- package/dist/web/_next/static/chunks/714.5b2e291a430adc9c.js +1 -0
- package/dist/web/_next/static/chunks/747.157732b5b3f3c435.js +1 -0
- package/dist/web/_next/static/chunks/77.d478a6f2eafe31e3.js +1 -0
- package/dist/web/_next/static/chunks/921-b2219533c5a6e38f.js +1 -0
- package/dist/web/_next/static/chunks/app/defaults/page-b7e4e94a55e65806.js +1 -0
- package/dist/web/_next/static/chunks/app/layout-2b3718748721c1ac.js +1 -0
- package/dist/web/_next/static/chunks/app/page-59b9867b52914a6c.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-1cf9e75e76da59ed.js +1 -0
- package/dist/web/_next/static/chunks/webpack-0c3cad1f3181d857.js +1 -0
- package/dist/web/_next/static/css/06f314fa5fccd68d.css +1 -0
- package/dist/web/defaults.html +14 -18
- package/dist/web/defaults.txt +9 -9
- package/dist/web/index.html +14 -18
- package/dist/web/index.txt +9 -9
- package/dist/web/system.html +14 -18
- package/dist/web/system.txt +9 -9
- package/package.json +8 -5
- package/prompts/lead1.md +116 -0
- package/prompts/level1.md +32 -12
- package/prompts/review1.md +287 -286
- package/dist/src/vcs/prepareFromRemote.js +0 -288
- package/dist/src/vcs/remoteAuth.js +0 -117
- package/dist/src/vcs/syncCommand.js +0 -97
- package/dist/web/_next/static/chunks/190-70555f20dd0da19b.js +0 -1
- package/dist/web/_next/static/chunks/643-e85d221d57900ed7.js +0 -1
- package/dist/web/_next/static/chunks/867-869900ec999e6345.js +0 -1
- package/dist/web/_next/static/chunks/app/appearance/page-cdef33c421397cbe.js +0 -1
- package/dist/web/_next/static/chunks/app/defaults/page-e0a2b8f9a41a94c4.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-b4fc21e26e1bad95.js +0 -1
- package/dist/web/_next/static/chunks/app/level1/page-31b74cae86d960d8.js +0 -1
- package/dist/web/_next/static/chunks/app/page-1075921d44db3e4d.js +0 -1
- package/dist/web/_next/static/chunks/app/presets/page-f8abdd83cdf468f7.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-2a270bb885885821.js +0 -1
- package/dist/web/_next/static/chunks/webpack-0f31b926d9a9c5a4.js +0 -1
- package/dist/web/_next/static/css/8b14cb3cf0051138.css +0 -1
- package/dist/web/_next/static/eqTUTH_SJtBgNgq8Zzy3n/_buildManifest.js +0 -1
- package/dist/web/appearance.html +0 -18
- package/dist/web/appearance.txt +0 -25
- package/dist/web/level1.html +0 -18
- package/dist/web/level1.txt +0 -25
- package/dist/web/presets.html +0 -21
- package/dist/web/presets.txt +0 -25
- /package/dist/web/_next/static/{eqTUTH_SJtBgNgq8Zzy3n → FGzV3mVZpXRCVjiw1diNu}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two-chat mode (operator, 2026-10-20): "chat A takes the whole, complex task — it breaks it into steps, checks
|
|
3
|
+
* that it understands it, plans, and directs; chat B carries out the small technical tasks — reads files, runs tests,
|
|
4
|
+
* debugs, whatever it takes — and reports back to A. One LLM controls the process at a high level and knows what is to
|
|
5
|
+
* be achieved; the other does the separate technical tasks. The browser is not closed between the two chats."
|
|
6
|
+
*
|
|
7
|
+
* So a message of such a conversation is run here, not by `runTask`. The conversation of the chat's session is the
|
|
8
|
+
* lead's (A): it is given the lead's contract (`prompts/lead1.md`) and the assignment, and every reply of it is one
|
|
9
|
+
* decision in the shape `protocol/leadSchema.ts` holds it to — a subtask for the worker, the plan, a question for the
|
|
10
|
+
* operator, the result, or a stop. The worker (B) is a session of its own (`Session.workerOf`), made at the first
|
|
11
|
+
* subtask, with a conversation of its own in the same Copilot window; each subtask is a task of it, run by `runTask`
|
|
12
|
+
* as any chat message is, with everything that comes with that — commands asked about or not, Pause, Stop, the
|
|
13
|
+
* checkpoint of the folder, the limits. The window goes from one conversation to the other and back (as the review's
|
|
14
|
+
* does); it is never closed between them. The worker keeps its conversation across subtasks, so what it learnt of
|
|
15
|
+
* the project stays with it, unless the lead asks for a fresh one.
|
|
16
|
+
*
|
|
17
|
+
* What the operator sees is the lead's record on the message (`Task.lead`): its understanding of the assignment, its
|
|
18
|
+
* notes, its plan, the subtasks with the worker's commands under each, its questions with their answers, and the
|
|
19
|
+
* result, which is the message's summary. The folder is photographed before the message and after it, so its changes
|
|
20
|
+
* are shown and "go back" works for the whole of it.
|
|
21
|
+
*/
|
|
22
|
+
import { appendFile, mkdir, writeFile } from 'node:fs/promises';
|
|
23
|
+
import { isReplyTimeout, WindowClosed } from '../transport/chatTransport.js';
|
|
24
|
+
import { buildChatName, chatCode, savePointer } from '../transport/chatSession.js';
|
|
25
|
+
import { RunLog } from '../log/runLog.js';
|
|
26
|
+
import { gapFrom, Pacer } from '../util/pacing.js';
|
|
27
|
+
import { takeAfter, takeCheckpoint } from '../session/checkpoint.js';
|
|
28
|
+
import { commitFiles } from '../vcs/git.js';
|
|
29
|
+
import { buildStory } from '../session/story.js';
|
|
30
|
+
import { operatorNotesSection, whyItStopped } from '../session/compose.js';
|
|
31
|
+
import { describeDeviations } from '../protocol/replySchema.js';
|
|
32
|
+
import { leadFormatErrorMessage, parseLeadReply, UNDERSTANDING_FIRST } from '../protocol/leadSchema.js';
|
|
33
|
+
import { describePlan, planFrom } from './planMode.js';
|
|
34
|
+
import { applySessionModel, enterSessionConversation, holdsWhilePaused, runTask, Sink, speakFor, StoppedSend } from './taskRunner.js';
|
|
35
|
+
import { DEFAULT_VCS } from '../session/store.js';
|
|
36
|
+
/** The assignment as the lead is given it: the operator's message, and what the runner tells it about the work. */
|
|
37
|
+
export function assignmentMessage(task, n, facts, again) {
|
|
38
|
+
return [
|
|
39
|
+
again
|
|
40
|
+
? 'New assignment in this same conversation. The lead\'s contract you were given at the start still applies unchanged: the same format, the same rules. Restate this assignment in "understanding" in your first reply to it.'
|
|
41
|
+
: '',
|
|
42
|
+
`## Assignment ${n}: ${task.title.trim() || 'untitled'}`,
|
|
43
|
+
'',
|
|
44
|
+
task.prompt.trim(),
|
|
45
|
+
'',
|
|
46
|
+
// The operator's skill for this kind of work (2026-10-21): the lead plans by it, and every subtask carries it to the worker.
|
|
47
|
+
...(task.skill?.text.trim()
|
|
48
|
+
? [
|
|
49
|
+
`## Skill: ${task.skill.name}`,
|
|
50
|
+
'',
|
|
51
|
+
...(task.skill.description.trim() ? [`For: ${task.skill.description.trim()}`, ''] : []),
|
|
52
|
+
'The operator\'s instructions for this kind of work. Plan and judge the work by them; the worker is given them with every subtask.',
|
|
53
|
+
'',
|
|
54
|
+
task.skill.text.trim(),
|
|
55
|
+
'',
|
|
56
|
+
]
|
|
57
|
+
: []),
|
|
58
|
+
'## What the runner tells you',
|
|
59
|
+
'',
|
|
60
|
+
`- The project folder, where the worker's commands run: ${facts.workDir || '(none is open)'}.`,
|
|
61
|
+
`- You may give the worker at most ${facts.maxSubtasks} subtask(s) for this assignment. Each subtask may take the worker up to ${facts.maxIterations} messages and ${facts.maxRunMinutes} minutes.`,
|
|
62
|
+
facts.planApproval
|
|
63
|
+
? '- The operator approves plans: when you send "plan", the work waits for their answer.'
|
|
64
|
+
: '- Plans are not put to the operator here: send "plan" all the same, so it is on record; the work goes on at once.',
|
|
65
|
+
...((facts.reference?.length ?? 0) > 0
|
|
66
|
+
? [
|
|
67
|
+
`- For reference only, changed by nothing: ${facts.reference.map((p) => `${p.name} (${p.dir})`).join(', ')}. The worker may read them and run what only reads; whatever it changes there is put back. Plan no change in them; if the result needs one, say so to the operator.`,
|
|
68
|
+
]
|
|
69
|
+
: []),
|
|
70
|
+
'- Reply in the lead\'s format.',
|
|
71
|
+
]
|
|
72
|
+
.filter((l, i) => l !== '' || i > 0)
|
|
73
|
+
.join('\n')
|
|
74
|
+
.trim();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* "Continue" on a message of the lead's that stopped before its result (a limit, Stop, the bot closed): in the same
|
|
78
|
+
* conversation, told why it stopped, to carry on from where the work got to — the subtasks and their reports are above
|
|
79
|
+
* it — rather than to start the assignment again.
|
|
80
|
+
*/
|
|
81
|
+
export function continuationMessage(task, n, facts) {
|
|
82
|
+
const instruction = task.continuing?.instruction?.trim();
|
|
83
|
+
return [
|
|
84
|
+
`Continue assignment ${n}: ${task.title.trim() || 'untitled'}, in this same conversation. ${task.continuing ? whyItStopped(task.continuing) : ''}`.trim(),
|
|
85
|
+
'',
|
|
86
|
+
'Do not start over: the subtasks so far and the worker\'s reports are above in this conversation. Say in "notes" where the work got to, and carry on from there in the lead\'s format.',
|
|
87
|
+
...(instruction ? ['', 'The operator adds this, which wins where it and the assignment disagree:', '', instruction] : []),
|
|
88
|
+
'',
|
|
89
|
+
`You may give the worker up to ${facts.maxSubtasks} more subtask(s) for it.`,
|
|
90
|
+
].join('\n');
|
|
91
|
+
}
|
|
92
|
+
/** A subtask, as the worker is given it: a task of its own, written so that someone who knows nothing else can do it. */
|
|
93
|
+
export function subtaskPrompt(sub, n) {
|
|
94
|
+
return [
|
|
95
|
+
`This task comes from the lead of the work, not straight from the operator: it is subtask ${n} of a larger assignment. Your closing summary is your report to the lead — put in it exactly what the lead asks for under "Report back", with the evidence (commands, their output, files and lines), not only your conclusions.`,
|
|
96
|
+
'',
|
|
97
|
+
`## Goal`,
|
|
98
|
+
sub.goal.trim(),
|
|
99
|
+
...(sub.context.trim() ? ['', '## What you need to know', sub.context.trim()] : []),
|
|
100
|
+
...(sub.steps.length > 0 ? ['', '## How to go about it', ...sub.steps.map((s, i) => `${i + 1}. ${s}`)] : []),
|
|
101
|
+
'',
|
|
102
|
+
'## Report back',
|
|
103
|
+
sub.report.trim(),
|
|
104
|
+
...(sub.doneWhen.trim() ? ['', '## Done when', sub.doneWhen.trim()] : []),
|
|
105
|
+
...(sub.readOnly ? ['', 'This subtask changes nothing: read, run and diagnose, but do not create, change or delete a file.'] : []),
|
|
106
|
+
].join('\n');
|
|
107
|
+
}
|
|
108
|
+
/** How a subtask ended, in the report's words. */
|
|
109
|
+
function endedAs(status) {
|
|
110
|
+
switch (status) {
|
|
111
|
+
case 'done':
|
|
112
|
+
return 'done';
|
|
113
|
+
case 'blocked':
|
|
114
|
+
return 'blocked — the worker could not finish it';
|
|
115
|
+
case 'limit-reached':
|
|
116
|
+
return 'stopped at a limit of the settings, unfinished';
|
|
117
|
+
case 'aborted':
|
|
118
|
+
return 'stopped';
|
|
119
|
+
default:
|
|
120
|
+
return 'failed';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** What the lead is told when it has no subtask left. */
|
|
124
|
+
export function noSubtasksLeft(max) {
|
|
125
|
+
return [
|
|
126
|
+
`No subtask is left: all ${max} of this assignment have been used. Do not send "delegate" again.`,
|
|
127
|
+
'Deliver what the work has found (status "done", with what is missing said plainly in "answer"), or stop (status "blocked", with what would let it go on in "needed").',
|
|
128
|
+
].join('\n');
|
|
129
|
+
}
|
|
130
|
+
/** The plan, as the lead is told it was approved. */
|
|
131
|
+
export function leadPlanApproved(approval, left) {
|
|
132
|
+
return [
|
|
133
|
+
approval.by === 'operator' ? 'The operator approved your plan.' : 'Your plan is on record; the operator is not asked about plans in this conversation.',
|
|
134
|
+
...(approval.note?.trim() ? ['', 'With this from the operator, which wins where it and the plan disagree:', '', approval.note.trim()] : []),
|
|
135
|
+
'',
|
|
136
|
+
`Carry it out now: give the worker the first subtask of it (status "delegate"). Subtasks left: ${left}.`,
|
|
137
|
+
].join('\n');
|
|
138
|
+
}
|
|
139
|
+
/** The operator asked the lead for another plan. */
|
|
140
|
+
export function leadPlanRevise(comment, version) {
|
|
141
|
+
return [
|
|
142
|
+
`The operator read version ${version} of your plan and asks for another. What to change:`,
|
|
143
|
+
'',
|
|
144
|
+
comment.trim(),
|
|
145
|
+
'',
|
|
146
|
+
'Send the whole revised plan (status "plan"), not only what changed. You may give the worker a subtask first if you need to find something out for it.',
|
|
147
|
+
].join('\n');
|
|
148
|
+
}
|
|
149
|
+
/** The operator's answer to the lead's question. */
|
|
150
|
+
export function operatorAnswerMessage(answer, left) {
|
|
151
|
+
return ['The operator answers your question:', '', answer.trim(), '', `Go on in the lead's format. Subtasks left: ${left}.`].join('\n');
|
|
152
|
+
}
|
|
153
|
+
/** Nobody can answer the lead's question (a run with no page to ask on). */
|
|
154
|
+
export const NOBODY_TO_ASK = 'Nobody can answer a question in this run: decide it yourself, the way that keeps the most options open, say the assumption in "notes", and go on.';
|
|
155
|
+
export async function runLeadTask(transport, session, task, deps) {
|
|
156
|
+
const { cfg, store, bus, signal } = deps;
|
|
157
|
+
const attempt = task.attempt ?? 1;
|
|
158
|
+
const runId = task.runId ?? `${session.id}-${task.id}${attempt > 1 ? `-a${attempt}` : ''}`;
|
|
159
|
+
const log = new RunLog(runId, cfg.resolved.runsDir);
|
|
160
|
+
const sink = new Sink(log, bus, session.id, task.id);
|
|
161
|
+
const taskLogPath = log.path('task-log.txt');
|
|
162
|
+
await mkdir(log.path('replies'), { recursive: true });
|
|
163
|
+
await mkdir(log.path('messages'), { recursive: true });
|
|
164
|
+
const record = async (heading, body) => {
|
|
165
|
+
await appendFile(taskLogPath, `\n${'='.repeat(78)}\n${heading}\n${'='.repeat(78)}\n${body.trimEnd()}\n`, 'utf8').catch(() => undefined);
|
|
166
|
+
};
|
|
167
|
+
const setTask = async (mutate) => {
|
|
168
|
+
await store.updateTask(session.id, task.id, mutate);
|
|
169
|
+
};
|
|
170
|
+
const max = Math.max(1, cfg.limits.maxSubtasks ?? 20);
|
|
171
|
+
const lead = { rounds: [], subtasks: 0, maxSubtasks: max };
|
|
172
|
+
const saveLead = async () => {
|
|
173
|
+
const copy = JSON.parse(JSON.stringify(lead));
|
|
174
|
+
await setTask((t) => {
|
|
175
|
+
t.lead = copy;
|
|
176
|
+
t.iterations = copy.rounds.length;
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
await setTask((t) => {
|
|
180
|
+
t.status = 'running';
|
|
181
|
+
t.runId = runId;
|
|
182
|
+
t.runGroup = deps.runGroup;
|
|
183
|
+
t.startedAt = new Date().toISOString();
|
|
184
|
+
t.lead = { rounds: [], subtasks: 0, maxSubtasks: max };
|
|
185
|
+
});
|
|
186
|
+
await writeFile(taskLogPath, `TASK: ${task.title}\nSESSION: ${session.name} (${session.id})\nRUN: ${runId}\nSTARTED: ${new Date().toISOString()}\nMODE: lead and worker\n`, 'utf8');
|
|
187
|
+
sink.event('task-started', { runId, title: task.title, lead: true }, `task "${task.title}" starting with a lead and a worker (run ${runId})`);
|
|
188
|
+
// The folder before the message, for "go back" and for what the whole of it changed.
|
|
189
|
+
const chatDir = session.projectDir?.trim() ?? '';
|
|
190
|
+
let checkpoint = task.checkpoint;
|
|
191
|
+
if (!checkpoint && chatDir) {
|
|
192
|
+
const cp = await takeCheckpoint(chatDir, task.id).catch((e) => ({ problem: e.message }));
|
|
193
|
+
if ('problem' in cp)
|
|
194
|
+
sink.event('chat-checkpoint-missing', { problem: cp.problem }, `no way back to before this message: ${cp.problem}`, 'warn');
|
|
195
|
+
else {
|
|
196
|
+
checkpoint = cp;
|
|
197
|
+
await setTask((t) => {
|
|
198
|
+
t.checkpoint = cp;
|
|
199
|
+
});
|
|
200
|
+
sink.event('chat-checkpoint', { commit: cp.commit, branch: cp.branch, head: cp.head }, `the folder before this message is kept as ${cp.commit.slice(0, 8)} (on ${cp.branch || cp.head.slice(0, 8)})`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const pacer = new Pacer({
|
|
204
|
+
enabled: cfg.pacing.enabled,
|
|
205
|
+
settleMs: cfg.pacing.settleMs,
|
|
206
|
+
maxMessagesPerHour: cfg.pacing.maxMessagesPerHour,
|
|
207
|
+
gapMs: gapFrom(cfg.pacing),
|
|
208
|
+
signal,
|
|
209
|
+
onGap: (ms) => sink.event('pacing-gap', { ms, lead: true }, `the next message to the lead waits ${Math.ceil(ms / 1000)} s: Settings ask for a pause between messages`),
|
|
210
|
+
});
|
|
211
|
+
let limitHit;
|
|
212
|
+
/*
|
|
213
|
+
* Paused (see `Hold`): the lead's next message waits, as the worker's do in `runTask`. True when the run was stopped
|
|
214
|
+
* while it was held.
|
|
215
|
+
*/
|
|
216
|
+
const holdHere = async () => {
|
|
217
|
+
const hold = deps.hold;
|
|
218
|
+
if (!hold?.held || signal?.aborted)
|
|
219
|
+
return false;
|
|
220
|
+
const from = Date.now();
|
|
221
|
+
sink.event('task-paused', { before: 'message', lead: true }, 'paused by the operator: nothing more is sent to the lead until Continue');
|
|
222
|
+
await hold.until(signal);
|
|
223
|
+
const stopped = !!signal?.aborted;
|
|
224
|
+
sink.event('task-resumed', { heldMs: Date.now() - from, stopped }, stopped ? 'stopped while paused' : 'continued by the operator');
|
|
225
|
+
return stopped;
|
|
226
|
+
};
|
|
227
|
+
const leadChat = holdsWhilePaused(transport, holdHere);
|
|
228
|
+
let sent = 0;
|
|
229
|
+
let replies = 0;
|
|
230
|
+
/** One message to the lead, and its reply. */
|
|
231
|
+
const tell = async (text) => {
|
|
232
|
+
await pacer.throttleSend();
|
|
233
|
+
// The operator's notes written while the work goes on ("Add to it") go to the lead with its next message.
|
|
234
|
+
const notes = await store.takeUnsentNotes(session.id, task.id).catch(() => []);
|
|
235
|
+
const message = notes.length > 0 ? `${text}\n\n${operatorNotesSection(notes, true)}` : text;
|
|
236
|
+
if (notes.length > 0)
|
|
237
|
+
sink.event('operator-note-sent', { notes: notes.length, with: 'lead' }, `${notes.length} note(s) from the operator go to the lead`);
|
|
238
|
+
const before = await leadChat.sendAndConfirm(message);
|
|
239
|
+
sent += 1;
|
|
240
|
+
// Counted for the operator, with the worker's (2026-10-21): shown under the message and in the status bar.
|
|
241
|
+
lead.messages = { lead: sent, worker: lead.messages?.worker ?? 0 };
|
|
242
|
+
await saveLead();
|
|
243
|
+
await writeFile(log.path('messages', `${String(sent).padStart(2, '0')}.md`), message, 'utf8').catch(() => undefined);
|
|
244
|
+
sink.event('message-sent', { n: sent, chars: message.length, lead: true, chatId: session.chat?.chatId ?? null }, `message ${sent} sent to the lead (${message.length} chars)`);
|
|
245
|
+
await record(`TO THE LEAD (${sent})`, message);
|
|
246
|
+
const reply = await leadChat.waitForReply(before);
|
|
247
|
+
replies += 1;
|
|
248
|
+
await writeFile(log.path('replies', `${String(replies).padStart(2, '0')}-lead.md`), reply.markdown, 'utf8').catch(() => undefined);
|
|
249
|
+
await record(`FROM THE LEAD (${replies})`, reply.markdown);
|
|
250
|
+
await pacer.settle();
|
|
251
|
+
await registerLeadChat();
|
|
252
|
+
return reply.markdown;
|
|
253
|
+
};
|
|
254
|
+
/** The lead's conversation, put on record and named once it exists. */
|
|
255
|
+
const registerLeadChat = async () => {
|
|
256
|
+
if (session.chat)
|
|
257
|
+
return;
|
|
258
|
+
const chatId = await transport.currentChatId().catch(() => null);
|
|
259
|
+
if (!chatId)
|
|
260
|
+
return;
|
|
261
|
+
const asked = buildChatName(chatCode(session.id), session.name);
|
|
262
|
+
const saved = await transport.nameChat(chatId, asked).catch(() => false);
|
|
263
|
+
const chat = {
|
|
264
|
+
chatId,
|
|
265
|
+
url: `${cfg.copilot.url.replace(/\/chat.*$/, '')}/chat/conversation/${chatId}?es=SSR`,
|
|
266
|
+
name: saved || asked,
|
|
267
|
+
...(saved !== false ? {} : { named: false }),
|
|
268
|
+
runId,
|
|
269
|
+
createdAt: new Date().toISOString(),
|
|
270
|
+
};
|
|
271
|
+
session.chat = chat;
|
|
272
|
+
await store.updateSession(session.id, (s) => {
|
|
273
|
+
s.chat = chat;
|
|
274
|
+
});
|
|
275
|
+
await savePointer(log.path('chat.json'), chat).catch(() => undefined);
|
|
276
|
+
sink.event('chat-registered', { ...chat, lead: true }, `the lead's chat: ${chat.name}`);
|
|
277
|
+
};
|
|
278
|
+
const finish = async (status, reason, summary) => {
|
|
279
|
+
// What the whole of the message changed: the folder against its photograph from before it.
|
|
280
|
+
let vcs;
|
|
281
|
+
if (checkpoint && chatDir) {
|
|
282
|
+
const after = await takeAfter(chatDir, task.id, checkpoint).catch((e) => ({ problem: e.message }));
|
|
283
|
+
if (!('problem' in after))
|
|
284
|
+
vcs = { baseCommit: checkpoint.commit, commit: after.commit, files: await commitFiles(chatDir, after.commit).catch(() => []) };
|
|
285
|
+
}
|
|
286
|
+
await saveLead();
|
|
287
|
+
await setTask((t) => {
|
|
288
|
+
if (vcs)
|
|
289
|
+
t.vcs = vcs;
|
|
290
|
+
t.status = status;
|
|
291
|
+
t.finishedAt = new Date().toISOString();
|
|
292
|
+
t.summary = summary;
|
|
293
|
+
t.reason = reason;
|
|
294
|
+
t.logFile = 'task-log.txt';
|
|
295
|
+
if (limitHit)
|
|
296
|
+
t.limit = limitHit;
|
|
297
|
+
});
|
|
298
|
+
await record(`TASK ${status.toUpperCase()}`, [summary ?? '', reason ? `Reason: ${reason}` : ''].filter(Boolean).join('\n\n') || '(no details)');
|
|
299
|
+
sink.event('task-finished', { status, reason, iterations: lead.rounds.length, subtasks: lead.subtasks, lead: true }, `task "${task.title}" ${status}${reason ? `: ${reason}` : ''}`);
|
|
300
|
+
await log.close();
|
|
301
|
+
return { status, iterations: lead.rounds.length, summary, reason };
|
|
302
|
+
};
|
|
303
|
+
/** The worker's session: made at the first subtask, with the chat's folder and the worker's model. */
|
|
304
|
+
const workerSession = async () => {
|
|
305
|
+
const now = await store.getSession(session.id);
|
|
306
|
+
const id = now?.lead?.workerSessionId;
|
|
307
|
+
const existing = id ? await store.getSession(id) : null;
|
|
308
|
+
if (existing) {
|
|
309
|
+
deps.onWorker?.(existing.id);
|
|
310
|
+
lead.workerSessionId = existing.id;
|
|
311
|
+
return existing;
|
|
312
|
+
}
|
|
313
|
+
const made = await store.createSession(`worker: ${session.name.replace(/^chat: /, '')}`, session.projectDir ?? '');
|
|
314
|
+
const lead2 = now?.lead ?? {};
|
|
315
|
+
const worker = await store.updateSession(made.id, (s) => {
|
|
316
|
+
s.kind = 'chat';
|
|
317
|
+
s.workerOf = session.id;
|
|
318
|
+
s.onFailure = 'continue';
|
|
319
|
+
/*
|
|
320
|
+
* No version control of its own, as the chat has none (2026-10-17): the worker works on the branch the folder is
|
|
321
|
+
* on, and each subtask is photographed instead. A session is made with it on, and the first worker made a branch
|
|
322
|
+
* of the operator's repository and committed on it (found by the check, 2026-10-20).
|
|
323
|
+
*/
|
|
324
|
+
s.vcs = { ...(s.vcs ?? DEFAULT_VCS), enabled: false, repoDir: '' };
|
|
325
|
+
s.projectDir = session.projectDir ?? '';
|
|
326
|
+
// The lead judges the worker's reports; there is no review of its own.
|
|
327
|
+
s.review = { enabled: false, model: '' };
|
|
328
|
+
s.planMode = 'off';
|
|
329
|
+
/*
|
|
330
|
+
* The worker's model as chosen under the chat's box; with none chosen, the lead's — by hand when the lead's is.
|
|
331
|
+
* A worker with no model of its own would be asked about by hand on every conversation that named one.
|
|
332
|
+
*/
|
|
333
|
+
const own = lead2.workerModel?.trim();
|
|
334
|
+
if (lead2.workerManualModel || (!own && now?.manualModel))
|
|
335
|
+
s.manualModel = true;
|
|
336
|
+
else if (own || now?.model?.trim()) {
|
|
337
|
+
s.model = own || now?.model?.trim();
|
|
338
|
+
s.modelSource = 'operator';
|
|
339
|
+
}
|
|
340
|
+
if (session.lang)
|
|
341
|
+
s.lang = session.lang;
|
|
342
|
+
});
|
|
343
|
+
await store.updateSession(session.id, (s) => {
|
|
344
|
+
s.lead = { ...(s.lead ?? {}), workerSessionId: worker.id };
|
|
345
|
+
});
|
|
346
|
+
lead.workerSessionId = worker.id;
|
|
347
|
+
deps.onWorker?.(worker.id);
|
|
348
|
+
sink.event('worker-made', { workerSessionId: worker.id }, 'a worker for the lead\'s subtasks');
|
|
349
|
+
return worker;
|
|
350
|
+
};
|
|
351
|
+
/** The worker's report of a subtask, as the lead is given it. */
|
|
352
|
+
const reportOf = async (workerId, taskId, out, n, title) => {
|
|
353
|
+
const w = await store.getSession(workerId);
|
|
354
|
+
const t = w?.tasks.find((x) => x.id === taskId);
|
|
355
|
+
const story = t?.runId ? await buildStory(cfg.resolved.runsDir, t.runId, t, false).catch(() => null) : null;
|
|
356
|
+
const steps = (story?.entries ?? []).flatMap((e) => (e.kind === 'step' ? [e] : e.kind === 'review' ? e.entries.filter((x) => x.kind === 'step') : []));
|
|
357
|
+
const commands = steps.slice(-25).map((s) => `- \`${s.command.replace(/\s+/g, ' ').slice(0, 160)}\` → ${s.exitCode ?? s.outcome ?? '?'}`);
|
|
358
|
+
const files = (t?.vcs?.files ?? []).map((f) => f.path);
|
|
359
|
+
return [
|
|
360
|
+
`Report of subtask ${n} (${title}): ${endedAs(out.status)}.`,
|
|
361
|
+
'',
|
|
362
|
+
'### The worker\'s report',
|
|
363
|
+
(t?.summary ?? out.summary ?? '').trim() || '(the worker gave no summary)',
|
|
364
|
+
...(out.status !== 'done' && (t?.reason ?? out.reason) ? ['', `### Why it ended so`, (t?.reason ?? out.reason ?? '').trim()] : []),
|
|
365
|
+
...(commands.length > 0 ? ['', `### The commands it ran, and their exit codes${steps.length > 25 ? ` (the last 25 of ${steps.length})` : ''}`, ...commands] : ['', 'It ran no command.']),
|
|
366
|
+
'',
|
|
367
|
+
files.length > 0 ? `Files it changed: ${files.join(', ')}.` : 'It changed no file.',
|
|
368
|
+
...((t?.deviations?.length ?? 0) > 0 ? ['', describeDeviations(t.deviations)] : []),
|
|
369
|
+
'',
|
|
370
|
+
`Subtasks left: ${max - lead.subtasks} of ${max}.`,
|
|
371
|
+
'Reply in the lead\'s format: the next subtask, the plan, a question for the operator, or the result.',
|
|
372
|
+
].join('\n');
|
|
373
|
+
};
|
|
374
|
+
/** One subtask: to the worker's conversation, carried out there as a task, and back to the lead with its report. */
|
|
375
|
+
const runSubtask = async (sub, round) => {
|
|
376
|
+
lead.subtasks += 1;
|
|
377
|
+
const n = lead.subtasks;
|
|
378
|
+
let worker = await workerSession();
|
|
379
|
+
if (sub.freshWorker && worker.chat) {
|
|
380
|
+
worker = await store.updateSession(worker.id, (s) => {
|
|
381
|
+
s.chat = undefined;
|
|
382
|
+
s.contractSent = false;
|
|
383
|
+
s.modelByHand = undefined;
|
|
384
|
+
});
|
|
385
|
+
sink.event('worker-fresh', { n }, `subtask ${n} goes to a fresh worker conversation`);
|
|
386
|
+
}
|
|
387
|
+
const made = await store.addTask(worker.id, { title: `${n}. ${sub.title}`, level2: '', prompt: subtaskPrompt(sub, n), reviewEnabled: false, readOnly: sub.readOnly, ...(task.skill ? { skill: task.skill } : {}) });
|
|
388
|
+
await store.updateTask(worker.id, made.id, (t) => {
|
|
389
|
+
t.fromLead = { sessionId: session.id, taskId: task.id, n };
|
|
390
|
+
});
|
|
391
|
+
round.subtask = { n, taskId: made.id, title: sub.title, ...(sub.readOnly ? { readOnly: true } : {}), ...(sub.freshWorker ? { fresh: true } : {}) };
|
|
392
|
+
await saveLead();
|
|
393
|
+
sink.event('subtask-given', { n, taskId: made.id, title: sub.title, readOnly: sub.readOnly, fresh: sub.freshWorker }, `subtask ${n} to the worker: ${sub.title}`);
|
|
394
|
+
// To the worker's conversation, in the same window.
|
|
395
|
+
speakFor(transport, worker.id);
|
|
396
|
+
const fresh = !worker.chat;
|
|
397
|
+
await enterSessionConversation(transport, worker, { closeOnFailure: false });
|
|
398
|
+
const model = await applySessionModel(transport, worker, bus, cfg, store, deps.models, fresh, signal);
|
|
399
|
+
if (model.refused) {
|
|
400
|
+
speakFor(transport, session.id);
|
|
401
|
+
if (signal?.aborted)
|
|
402
|
+
return 'stopped';
|
|
403
|
+
throw new Error(`The worker's conversation could not be put on its model: ${model.refused}`);
|
|
404
|
+
}
|
|
405
|
+
const current = (await store.getSession(worker.id));
|
|
406
|
+
const subtask = current.tasks.find((x) => x.id === made.id);
|
|
407
|
+
// Every message the worker's task sends is counted as the worker's, as it goes.
|
|
408
|
+
const counted = new Proxy(transport, {
|
|
409
|
+
get(target, key) {
|
|
410
|
+
if (key === 'sendAndConfirm') {
|
|
411
|
+
return async (...args) => {
|
|
412
|
+
const r = await target.sendAndConfirm(...args);
|
|
413
|
+
lead.messages = { lead: lead.messages?.lead ?? sent, worker: (lead.messages?.worker ?? 0) + 1 };
|
|
414
|
+
await saveLead();
|
|
415
|
+
return r;
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
const value = Reflect.get(target, key, target);
|
|
419
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
const out = await runTask(counted, current, subtask, { ...deps, approvePlan: undefined });
|
|
423
|
+
speakFor(transport, session.id);
|
|
424
|
+
if (transport.closedOutside())
|
|
425
|
+
throw new WindowClosed();
|
|
426
|
+
if (signal?.aborted)
|
|
427
|
+
return 'stopped';
|
|
428
|
+
sink.event('subtask-ended', { n, status: out.status }, `subtask ${n} ${out.status}`);
|
|
429
|
+
// Back to the lead's conversation.
|
|
430
|
+
const leadNow = (await store.getSession(session.id));
|
|
431
|
+
await enterSessionConversation(transport, leadNow, { closeOnFailure: false });
|
|
432
|
+
const back = await applySessionModel(transport, leadNow, bus, cfg, store, deps.models, false, signal);
|
|
433
|
+
if (back.refused) {
|
|
434
|
+
if (signal?.aborted)
|
|
435
|
+
return 'stopped';
|
|
436
|
+
throw new Error(`The lead's conversation could not be put on its model again: ${back.refused}`);
|
|
437
|
+
}
|
|
438
|
+
return { report: await reportOf(worker.id, made.id, out, n, sub.title) };
|
|
439
|
+
};
|
|
440
|
+
try {
|
|
441
|
+
const facts = {
|
|
442
|
+
workDir: chatDir,
|
|
443
|
+
maxSubtasks: max,
|
|
444
|
+
maxIterations: cfg.limits.maxIterations,
|
|
445
|
+
maxRunMinutes: cfg.limits.maxRunMinutes,
|
|
446
|
+
planApproval: session.planMode === 'approve' && !!deps.approvePlan,
|
|
447
|
+
reference: [
|
|
448
|
+
...(cfg.project.readOnly && cfg.project.rootDir ? [{ name: cfg.project.name || cfg.project.rootDir, dir: cfg.project.rootDir }] : []),
|
|
449
|
+
...cfg.project.others.filter((o) => o.readOnly).map((o) => ({ name: o.name, dir: o.rootDir })),
|
|
450
|
+
],
|
|
451
|
+
};
|
|
452
|
+
const n = session.tasks.findIndex((x) => x.id === task.id) + 1;
|
|
453
|
+
const contract = (await store.getLead1()).content.trim();
|
|
454
|
+
// Carried on in its own conversation: told why it stopped, and to go on from there (see `continuationMessage`).
|
|
455
|
+
const carryingOn = !!task.continuing && !!session.contractSent;
|
|
456
|
+
const assignment = carryingOn ? continuationMessage(task, n || 1, facts) : assignmentMessage(task, n || 1, facts, !!session.contractSent);
|
|
457
|
+
await setTask((t) => {
|
|
458
|
+
t.firstMessage = session.contractSent ? assignment : `${contract}\n\n---\n\n${assignment}`;
|
|
459
|
+
});
|
|
460
|
+
await record('OPENING MESSAGE', session.contractSent ? assignment : `${contract}\n\n---\n\n${assignment}`);
|
|
461
|
+
if (signal?.aborted)
|
|
462
|
+
return await finish('aborted', 'stopped before the assignment was sent');
|
|
463
|
+
let markdown;
|
|
464
|
+
if (!session.contractSent) {
|
|
465
|
+
await tell(contract);
|
|
466
|
+
session.contractSent = true;
|
|
467
|
+
await store.updateSession(session.id, (s) => {
|
|
468
|
+
s.contractSent = true;
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
markdown = await tell(assignment);
|
|
472
|
+
const maxFormat = Math.max(0, cfg.limits.maxFormatRetries ?? 2);
|
|
473
|
+
let formatRetries = 0;
|
|
474
|
+
// A message carried on was restated when it began: its first reply now need not do it again.
|
|
475
|
+
let understood = carryingOn;
|
|
476
|
+
let planVersion = 0;
|
|
477
|
+
let revisions = [];
|
|
478
|
+
const maxRounds = Math.max(1, cfg.limits.maxIterations);
|
|
479
|
+
for (;;) {
|
|
480
|
+
if (signal?.aborted)
|
|
481
|
+
return await finish('aborted', 'stopped by the operator');
|
|
482
|
+
if (lead.rounds.length >= maxRounds) {
|
|
483
|
+
limitHit = { setting: 'maxIterations', value: maxRounds };
|
|
484
|
+
return await finish('limit-reached', `maxIterations (${maxRounds}) reached: the lead's replies`);
|
|
485
|
+
}
|
|
486
|
+
const parsed = parseLeadReply(markdown);
|
|
487
|
+
if (!parsed.ok) {
|
|
488
|
+
formatRetries += 1;
|
|
489
|
+
if (formatRetries > maxFormat) {
|
|
490
|
+
limitHit = { setting: 'maxFormatRetries', value: maxFormat };
|
|
491
|
+
return await finish('limit-reached', `maxFormatRetries (${maxFormat}) reached: the lead's replies did not match its format (${parsed.detail})`);
|
|
492
|
+
}
|
|
493
|
+
sink.event('lead-format-retry', { reason: parsed.reason, detail: parsed.detail, retry: formatRetries }, `the lead's reply did not match its format, asked again (${formatRetries} of ${maxFormat})`, 'warn');
|
|
494
|
+
markdown = await tell(leadFormatErrorMessage(parsed, formatRetries, maxFormat));
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
const r = parsed.reply;
|
|
498
|
+
if (!understood && !r.understanding) {
|
|
499
|
+
formatRetries += 1;
|
|
500
|
+
if (formatRetries > maxFormat) {
|
|
501
|
+
limitHit = { setting: 'maxFormatRetries', value: maxFormat };
|
|
502
|
+
return await finish('limit-reached', `maxFormatRetries (${maxFormat}) reached: the lead did not restate the assignment`);
|
|
503
|
+
}
|
|
504
|
+
markdown = await tell(UNDERSTANDING_FIRST);
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
formatRetries = 0;
|
|
508
|
+
understood = true;
|
|
509
|
+
const round = {
|
|
510
|
+
n: lead.rounds.length + 1,
|
|
511
|
+
at: new Date().toISOString(),
|
|
512
|
+
status: r.status,
|
|
513
|
+
...(r.understanding ? { understanding: r.understanding } : {}),
|
|
514
|
+
...(r.notes ? { notes: r.notes } : {}),
|
|
515
|
+
};
|
|
516
|
+
lead.rounds.push(round);
|
|
517
|
+
await saveLead();
|
|
518
|
+
sink.event('lead-reply', { round: round.n, status: r.status }, `the lead: ${r.status}${r.subtask ? ` — ${r.subtask.title}` : ''}`);
|
|
519
|
+
switch (r.status) {
|
|
520
|
+
case 'delegate': {
|
|
521
|
+
if (lead.subtasks >= max) {
|
|
522
|
+
markdown = await tell(noSubtasksLeft(max));
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
const ran = await runSubtask(r.subtask, round);
|
|
526
|
+
if (ran === 'stopped')
|
|
527
|
+
return await finish('aborted', 'stopped by the operator');
|
|
528
|
+
markdown = await tell(ran.report);
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
case 'plan': {
|
|
532
|
+
planVersion += 1;
|
|
533
|
+
const plan = planFrom(r.plan, planVersion, revisions);
|
|
534
|
+
await setTask((t) => {
|
|
535
|
+
t.plan = plan;
|
|
536
|
+
});
|
|
537
|
+
await record(`THE LEAD'S PLAN (version ${planVersion})`, describePlan(plan));
|
|
538
|
+
let approved;
|
|
539
|
+
if (facts.planApproval && deps.approvePlan) {
|
|
540
|
+
const answer = await deps.approvePlan({ sessionId: session.id, taskId: task.id, title: task.title, plan });
|
|
541
|
+
if (answer.decision === 'stop' || signal?.aborted)
|
|
542
|
+
return await finish('aborted', 'the operator stopped the task at the lead\'s plan');
|
|
543
|
+
if (answer.decision === 'revise') {
|
|
544
|
+
revisions = [...(revisions ?? []), { version: planVersion, comment: answer.note ?? '', at: new Date().toISOString() }];
|
|
545
|
+
await setTask((t) => {
|
|
546
|
+
if (t.plan)
|
|
547
|
+
t.plan.revisions = revisions;
|
|
548
|
+
});
|
|
549
|
+
markdown = await tell(leadPlanRevise(answer.note ?? '', planVersion));
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
approved = { by: 'operator', at: new Date().toISOString(), ...(answer.note?.trim() ? { note: answer.note.trim() } : {}) };
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
approved = { by: 'auto', at: new Date().toISOString(), why: 'plans are not put to the operator in this conversation' };
|
|
556
|
+
}
|
|
557
|
+
await setTask((t) => {
|
|
558
|
+
if (t.plan)
|
|
559
|
+
t.plan.approved = approved;
|
|
560
|
+
});
|
|
561
|
+
markdown = await tell(leadPlanApproved(approved, max - lead.subtasks));
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case 'ask': {
|
|
565
|
+
round.question = { text: r.question, ...(r.why ? { why: r.why } : {}), ...(r.options.length > 0 ? { options: r.options } : {}) };
|
|
566
|
+
await saveLead();
|
|
567
|
+
if (!deps.askQuestion) {
|
|
568
|
+
markdown = await tell(NOBODY_TO_ASK);
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
sink.event('lead-question', { round: round.n, question: r.question }, `the lead asks the operator: ${r.question}`, 'warn');
|
|
572
|
+
const got = await deps.askQuestion({ sessionId: session.id, taskId: task.id, question: r.question, ...(r.why ? { why: r.why } : {}), options: r.options });
|
|
573
|
+
if (got === 'stop' || signal?.aborted)
|
|
574
|
+
return await finish('aborted', 'the operator stopped the task at the lead\'s question');
|
|
575
|
+
round.question.answer = got.answer;
|
|
576
|
+
round.question.at = new Date().toISOString();
|
|
577
|
+
await saveLead();
|
|
578
|
+
sink.event('lead-question-answered', { round: round.n }, 'the operator answered the lead');
|
|
579
|
+
markdown = await tell(operatorAnswerMessage(got.answer, max - lead.subtasks));
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case 'done': {
|
|
583
|
+
lead.evidence = r.evidence;
|
|
584
|
+
return await finish('done', undefined, r.answer);
|
|
585
|
+
}
|
|
586
|
+
case 'blocked': {
|
|
587
|
+
return await finish('blocked', `the lead could not take it further: ${r.needed ?? ''}`.trim(), r.summary);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
catch (e) {
|
|
593
|
+
const message = e.message;
|
|
594
|
+
if (e instanceof StoppedSend || signal?.aborted)
|
|
595
|
+
return await finish('aborted', 'stopped by the operator; nothing more was sent');
|
|
596
|
+
if (isReplyTimeout(e)) {
|
|
597
|
+
limitHit = { setting: 'replyTimeoutSec', value: e.seconds };
|
|
598
|
+
return await finish('limit-reached', `replyTimeoutSec (${e.seconds}) reached: ${message}`);
|
|
599
|
+
}
|
|
600
|
+
if (e instanceof WindowClosed || transport.closedOutside())
|
|
601
|
+
return await finish('aborted', 'the browser window was closed; nothing more was sent');
|
|
602
|
+
sink.event('task-error', { error: message, stack: e.stack }, message, 'error');
|
|
603
|
+
return await finish('failed', message);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
@@ -261,8 +261,8 @@ export async function runReview(transport, session, task, deps) {
|
|
|
261
261
|
// The machine's shells, when they are not what the contract's example assumes — the same note
|
|
262
262
|
// the implementer's conversation opens with, for a conversation working to the same example.
|
|
263
263
|
const machineNote = shellNote(undefined, defaultShell);
|
|
264
|
-
let before = await transport.sendAndConfirm(machineNote ? `${contract}
|
|
265
|
-
|
|
264
|
+
let before = await transport.sendAndConfirm(machineNote ? `${contract}
|
|
265
|
+
|
|
266
266
|
${machineNote}` : contract);
|
|
267
267
|
await transport.waitForReply(before);
|
|
268
268
|
await pacer.throttleSend();
|
|
@@ -471,7 +471,7 @@ ${machineNote}` : contract);
|
|
|
471
471
|
sessionId: session.id,
|
|
472
472
|
taskId: task.id,
|
|
473
473
|
iteration: iterations,
|
|
474
|
-
confinement: { roots: deps.roots, cwd: deps.cwd },
|
|
474
|
+
confinement: { roots: deps.roots, cwd: deps.cwd, workStartedAt: deps.workStartedAt },
|
|
475
475
|
});
|
|
476
476
|
if (decision.action !== 'run') {
|
|
477
477
|
results.push(refused(step.id, decision.reason, step.cmd, step.shell, decision.by === 'operator' ? 'operator' : 'runner'));
|
|
@@ -510,10 +510,16 @@ ${machineNote}` : contract);
|
|
|
510
510
|
}, { signal, tracker: deps.tracker });
|
|
511
511
|
stepsRun += 1;
|
|
512
512
|
results.push(result);
|
|
513
|
+
const touched = deps.afterStep ? await deps.afterStep().catch(() => null) : null;
|
|
514
|
+
if (touched)
|
|
515
|
+
result.stderr = `${result.stderr}${result.stderr && !result.stderr.endsWith('\n') ? '\n' : ''}[runner] ${touched}\n`;
|
|
513
516
|
deps.event('review-step-finished', { round, id: step.id, outcome: result.outcome, exitCode: result.exitCode, shell: result.shell, requestedShell: result.requestedShell ?? null, shellPath: result.shellPath ?? '' }, `review step ${step.id}: ${result.outcome}, exit ${result.exitCode}, ${(result.durationMs / 1000).toFixed(1)}s`);
|
|
514
517
|
// Stopped while it ran: no step after it is started, and the report waits below.
|
|
515
518
|
if (signal?.aborted)
|
|
516
519
|
break;
|
|
520
|
+
// A project for reference only was changed and put back: the rest of the round is not run.
|
|
521
|
+
if (touched)
|
|
522
|
+
break;
|
|
517
523
|
await pacer.settle();
|
|
518
524
|
}
|
|
519
525
|
const report = await writeReport(results, {
|