copilot-operator 0.1.50 → 0.1.51

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.
Files changed (81) hide show
  1. package/README.md +582 -574
  2. package/dist/src/api/operator.controller.js +77 -932
  3. package/dist/src/api/operator.service.js +197 -2461
  4. package/dist/src/orchestrator/hold.js +49 -0
  5. package/dist/src/orchestrator/taskRunner.js +157 -23
  6. package/dist/src/plan/kerrigan.js +107 -0
  7. package/dist/src/plan/systemGuide.js +438 -3374
  8. package/dist/src/session/chatNotice.js +76 -0
  9. package/dist/src/session/store.js +2 -57
  10. package/dist/src/session/workspace.js +52 -5
  11. package/dist/src/transport/chatTransport.js +1 -1
  12. package/dist/src/transport/copilotTransport.js +133 -1
  13. package/dist/web/404.html +5 -3
  14. package/dist/web/_next/static/chunks/134-ddd50a7fbb536ec8.js +1 -0
  15. package/dist/web/_next/static/chunks/190-70555f20dd0da19b.js +1 -0
  16. package/dist/web/_next/static/chunks/643-e85d221d57900ed7.js +1 -0
  17. package/dist/web/_next/static/chunks/867-869900ec999e6345.js +1 -0
  18. package/dist/web/_next/static/chunks/app/appearance/page-cdef33c421397cbe.js +1 -0
  19. package/dist/web/_next/static/chunks/app/defaults/page-e0a2b8f9a41a94c4.js +1 -0
  20. package/dist/web/_next/static/chunks/app/layout-b4fc21e26e1bad95.js +1 -0
  21. package/dist/web/_next/static/chunks/app/level1/page-31b74cae86d960d8.js +1 -0
  22. package/dist/web/_next/static/chunks/app/page-1075921d44db3e4d.js +1 -0
  23. package/dist/web/_next/static/chunks/app/presets/page-f8abdd83cdf468f7.js +1 -0
  24. package/dist/web/_next/static/chunks/app/system/page-2a270bb885885821.js +1 -0
  25. package/dist/web/_next/static/css/8b14cb3cf0051138.css +1 -0
  26. package/dist/web/_next/static/eqTUTH_SJtBgNgq8Zzy3n/_buildManifest.js +1 -0
  27. package/dist/web/appearance.html +5 -3
  28. package/dist/web/appearance.txt +22 -23
  29. package/dist/web/defaults.html +5 -3
  30. package/dist/web/defaults.txt +22 -23
  31. package/dist/web/index.html +5 -3
  32. package/dist/web/index.txt +22 -23
  33. package/dist/web/level1.html +5 -3
  34. package/dist/web/level1.txt +22 -23
  35. package/dist/web/presets.html +6 -4
  36. package/dist/web/presets.txt +22 -23
  37. package/dist/web/system.html +5 -3
  38. package/dist/web/system.txt +22 -23
  39. package/package.json +3 -20
  40. package/dist/src/api/saveToDesktop.js +0 -157
  41. package/dist/src/plan/brief.js +0 -2003
  42. package/dist/src/plan/changes.js +0 -217
  43. package/dist/src/plan/script.js +0 -1014
  44. package/dist/src/session/debugExport.js +0 -165
  45. package/dist/src/session/exportRecord.js +0 -277
  46. package/dist/src/session/metrics.js +0 -95
  47. package/dist/src/vcs/startChoice.js +0 -367
  48. package/dist/web/_next/static/chunks/197-f7c33a0114fc3db3.js +0 -1
  49. package/dist/web/_next/static/chunks/499-751e0be9d4f86e2d.js +0 -1
  50. package/dist/web/_next/static/chunks/534-56c68930a1a3c10f.js +0 -1
  51. package/dist/web/_next/static/chunks/549-c32dd718a1809d4d.js +0 -1
  52. package/dist/web/_next/static/chunks/699-9d031f8c145a0465.js +0 -1
  53. package/dist/web/_next/static/chunks/867-0e5d0d5472bf185f.js +0 -1
  54. package/dist/web/_next/static/chunks/app/appearance/page-a18019cdc395de3d.js +0 -1
  55. package/dist/web/_next/static/chunks/app/defaults/page-614be29d185a2947.js +0 -1
  56. package/dist/web/_next/static/chunks/app/history/page-95bab4c1b1ff9339.js +0 -1
  57. package/dist/web/_next/static/chunks/app/import/page-8ef75fc08638e75f.js +0 -1
  58. package/dist/web/_next/static/chunks/app/layout-a1314921eeba8ad5.js +0 -1
  59. package/dist/web/_next/static/chunks/app/level1/page-dd3ebf37d29dce4f.js +0 -1
  60. package/dist/web/_next/static/chunks/app/page-4d8f0851fe672925.js +0 -1
  61. package/dist/web/_next/static/chunks/app/presets/page-93ab518db67e52a2.js +0 -1
  62. package/dist/web/_next/static/chunks/app/sessions/page-28376d2e4a9b4738.js +0 -1
  63. package/dist/web/_next/static/chunks/app/sessions/view/page-adb64f8ba3d8c06e.js +0 -1
  64. package/dist/web/_next/static/chunks/app/system/page-227a259e383ca2a0.js +0 -1
  65. package/dist/web/_next/static/css/4335e4ce269ba1ea.css +0 -1
  66. package/dist/web/_next/static/z74_FBfnnXW5IJCHTgTH2/_buildManifest.js +0 -1
  67. package/dist/web/history.html +0 -16
  68. package/dist/web/history.txt +0 -26
  69. package/dist/web/import.html +0 -16
  70. package/dist/web/import.txt +0 -26
  71. package/dist/web/sessions/view.html +0 -16
  72. package/dist/web/sessions/view.txt +0 -26
  73. package/dist/web/sessions.html +0 -16
  74. package/dist/web/sessions.txt +0 -26
  75. package/prompts/organisation.bg.md +0 -43
  76. package/prompts/organisation.en.md +0 -43
  77. package/prompts/persona.bg.md +0 -17
  78. package/prompts/persona.en.md +0 -17
  79. package/prompts/work.bg.md +0 -19
  80. package/prompts/work.en.md +0 -19
  81. /package/dist/web/_next/static/{z74_FBfnnXW5IJCHTgTH2 → eqTUTH_SJtBgNgq8Zzy3n}/_ssgManifest.js +0 -0
@@ -1,165 +0,0 @@
1
- /**
2
- * Everything that happened across a set of sessions, as one JSON document.
3
- *
4
- * The audience is somebody who was not there and has to work out why a run went the way it
5
- * did — very often that means handing it to another model, which is why this is JSON rather
6
- * than the prose export next door. `exportRecord.ts` answers "what was asked and what came
7
- * back" for a person to read; this answers "what actually ran, in what order, with what exit
8
- * codes, and what did the repository end up with" for someone to analyse.
9
- *
10
- * It is assembled from two places. The sessions carry the durable record — the text, the
11
- * outcome, the checks, what version control did. The run folders carry the sequence: every
12
- * step the model proposed, whether it ran, and what it exited with. Neither alone is enough to
13
- * explain a failure, and a run folder that has been cleaned away is not an error here: the
14
- * task still appears, with its own record and an empty step list.
15
- */
16
- import { readFile } from 'node:fs/promises';
17
- import { join } from 'node:path';
18
- /** How long a command line travels into the report. Enough to recognise, not enough to drown. */
19
- const MAX_COMMAND_CHARS = 600;
20
- function clip(text, max = MAX_COMMAND_CHARS) {
21
- const t = text.trim();
22
- return t.length > max ? `${t.slice(0, max)}… (${t.length - max} more characters)` : t;
23
- }
24
- /**
25
- * The sequence of what ran, read back out of the transcript.
26
- *
27
- * A step appears twice in the transcript — proposed, then finished — so the two are joined on
28
- * the step id. A step that was proposed and never finished is left with no outcome, which is
29
- * itself the answer when a run was stopped or the process died in the middle of one.
30
- */
31
- async function readTranscript(runsDir, runId) {
32
- const empty = { steps: [], chatRounds: [], problems: [] };
33
- const raw = await readFile(join(runsDir, runId, 'transcript.jsonl'), 'utf8').catch(() => null);
34
- if (raw === null)
35
- return empty;
36
- const byId = new Map();
37
- const chatRounds = [];
38
- const problems = [];
39
- for (const line of raw.split('\n')) {
40
- if (!line.trim())
41
- continue;
42
- let event;
43
- try {
44
- event = JSON.parse(line);
45
- }
46
- catch {
47
- continue;
48
- }
49
- const type = String(event.type ?? '');
50
- if (type === 'step-proposed') {
51
- const id = Number(event.id);
52
- byId.set(id, { ...(byId.get(id) ?? { id }), id, description: clip(String(event.description ?? '')) });
53
- }
54
- else if (type === 'step-finished') {
55
- const id = Number(event.id);
56
- byId.set(id, {
57
- ...(byId.get(id) ?? { id }),
58
- id,
59
- outcome: String(event.outcome ?? ''),
60
- exitCode: typeof event.exitCode === 'number' ? event.exitCode : undefined,
61
- durationMs: typeof event.durationMs === 'number' ? event.durationMs : undefined,
62
- });
63
- }
64
- else if (type === 'reply-parsed') {
65
- chatRounds.push({
66
- iteration: Number(event.iteration) || chatRounds.length + 1,
67
- status: String(event.status ?? ''),
68
- steps: Number(event.steps) || 0,
69
- notes: event.notes ? clip(String(event.notes), 300) : undefined,
70
- });
71
- }
72
- else if (type === 'task-error' || type === 'report-send-failed' || type === 'format-error' || type === 'vcs-problem') {
73
- problems.push(`${type}: ${clip(String(event.error ?? event.message ?? event.detail ?? ''), 400)}`);
74
- }
75
- }
76
- return { steps: [...byId.values()].sort((a, b) => a.id - b.id), chatRounds, problems };
77
- }
78
- async function taskOf(task, runsDir) {
79
- const transcript = task.runId ? await readTranscript(runsDir, task.runId) : { steps: [], chatRounds: [], problems: [] };
80
- const started = task.startedAt ? Date.parse(task.startedAt) : undefined;
81
- const finished = task.finishedAt ? Date.parse(task.finishedAt) : undefined;
82
- return {
83
- id: task.id,
84
- title: task.title,
85
- status: task.status,
86
- attempt: task.attempt ?? 1,
87
- createdAt: task.createdAt,
88
- startedAt: task.startedAt,
89
- finishedAt: task.finishedAt,
90
- durationMs: started && finished ? finished - started : undefined,
91
- iterations: task.iterations,
92
- runId: task.runId,
93
- prompt: task.prompt,
94
- level2: task.level2,
95
- summary: task.summary,
96
- reason: task.reason,
97
- deviations: task.deviations,
98
- disputes: task.disputes,
99
- reviewChecks: task.reviewChecks,
100
- environment: task.environment,
101
- vcsPlan: task.vcsPlan,
102
- vcs: task.vcs,
103
- checks: task.checks,
104
- checkResults: task.checkResults,
105
- steps: transcript.steps,
106
- chatRounds: transcript.chatRounds,
107
- problems: transcript.problems,
108
- earlierAttempts: (task.attempts ?? []).map((a) => ({
109
- status: a.status,
110
- iterations: a.iterations,
111
- runId: a.runId,
112
- reason: a.reason,
113
- summary: a.summary,
114
- deviations: a.deviations,
115
- disputes: a.disputes,
116
- checkResults: a.checkResults,
117
- vcs: a.vcs,
118
- })),
119
- };
120
- }
121
- /** The whole thing, plus a file name that says what it is without being opened. */
122
- export async function buildDebugExport(input) {
123
- const sessions = [];
124
- const totals = { sessions: input.sessions.length, tasks: 0, done: 0, failed: 0, queued: 0 };
125
- for (const session of input.sessions) {
126
- const tasks = [];
127
- for (const task of session.tasks) {
128
- totals.tasks += 1;
129
- if (task.status === 'done')
130
- totals.done += 1;
131
- else if (task.status === 'queued')
132
- totals.queued += 1;
133
- else
134
- totals.failed += 1;
135
- tasks.push(await taskOf(task, input.runsDir));
136
- }
137
- sessions.push({
138
- id: session.id,
139
- name: session.name,
140
- createdAt: session.createdAt,
141
- status: session.status,
142
- model: session.model,
143
- modelInUse: session.modelInUse,
144
- onFailure: session.onFailure,
145
- chat: session.chat ? { name: session.chat.name, url: session.chat.url } : undefined,
146
- vcs: session.vcs,
147
- vcsBaseCommit: session.vcsBaseCommit,
148
- projectDir: session.projectDir,
149
- tasks,
150
- });
151
- }
152
- const report = {
153
- exportedAt: new Date().toISOString(),
154
- about: 'copilot-operator: what ran and what happened, across the selected sessions. Everything here is ' +
155
- 'either the session record on disk or the run transcript; nothing is inferred.',
156
- machine: { node: process.versions.node, platform: process.platform, cwd: input.cwd, runsDir: input.runsDir },
157
- totals,
158
- sessions,
159
- };
160
- const stamp = new Date().toISOString().slice(0, 16).replace(/[:T]/g, '').replace(/-/g, '');
161
- const name = input.sessions.length === 1
162
- ? (input.sessions[0].name.replace(/[^\p{L}\p{N}._ -]/gu, '').trim().replace(/\s+/g, '-') || 'session')
163
- : `${input.sessions.length}-sessions`;
164
- return { fileName: `copilot-operator-debug-${name}-${stamp}.json`, content: JSON.stringify(report, null, 2), totals };
165
- }
@@ -1,277 +0,0 @@
1
- /**
2
- * Turns what a task did into one document the operator can keep.
3
- *
4
- * Everything here already exists on disk: the opening message is on the task, every reply is
5
- * under `replies/`, every report that was sent back is under `reports/`. What was missing was
6
- * a way to hand someone the record without explaining the folder layout first.
7
- *
8
- * Two shapes, because two questions get asked about a finished task:
9
- *
10
- * `full` the whole conversation, in order, both sides. For reading what actually
11
- * happened, step by step, or for attaching to a bug report.
12
- * `outcome` only the first message and the last one. The first says what the task was
13
- * asked to do, the last says what was done: expected and actual, side by side,
14
- * with nothing in between to wade through.
15
- *
16
- * A task whose run folder is gone still exports: the opening message, the summary and the
17
- * final reply are kept on the session itself, so the record survives a cleaned `runs/`.
18
- */
19
- import { readFile, readdir } from 'node:fs/promises';
20
- import { join } from 'node:path';
21
- import { describeDeviations, describeDisputes } from '../protocol/replySchema.js';
22
- import { SHELL_ORDER, availableShells } from '../exec/shells.js';
23
- const RULE = '='.repeat(78);
24
- const THIN = '-'.repeat(78);
25
- function heading(text) {
26
- return `\n${RULE}\n${text}\n${RULE}\n`;
27
- }
28
- function when(iso) {
29
- return iso ? new Date(iso).toISOString().replace('T', ' ').slice(0, 19) : '—';
30
- }
31
- /**
32
- * The conversation of one task, reconstructed from the run folder.
33
- *
34
- * Replies are numbered by the transport as `NN-<label>.md`, so their names sort into the
35
- * order they arrived. A reply labelled `iteration-K` was the answer to report K, which is why
36
- * the report is emitted just before it: that pairing is what makes the document read like a
37
- * conversation rather than two separate piles of text.
38
- */
39
- async function conversationOf(task, runsDir) {
40
- const out = [];
41
- if (!task.runId)
42
- return out;
43
- const base = join(runsDir, task.runId);
44
- const replies = (await readdir(join(base, 'replies')).catch(() => []))
45
- .filter((n) => n.endsWith('.md'))
46
- .sort();
47
- let openingWritten = false;
48
- for (const name of replies) {
49
- const label = name.replace(/^\d+-/, '').replace(/\.md$/, '');
50
- if (label.startsWith('opening')) {
51
- if (!openingWritten && task.firstMessage) {
52
- out.push(`${heading('SENT — the message that opened the task')}${task.firstMessage.trimEnd()}`);
53
- openingWritten = true;
54
- }
55
- }
56
- else if (label.startsWith('iteration')) {
57
- const n = label.split('-')[1];
58
- const report = await readFile(join(base, 'reports', `iteration-${n}.txt`), 'utf8').catch(() => null);
59
- out.push(`${heading(`SENT — the report after iteration ${n}`)}${report ? report.trimEnd() : '(the report file is no longer in the run folder)'}`);
60
- }
61
- else if (label.startsWith('format-retry')) {
62
- out.push(heading('SENT — a request to keep the agreed format').trimEnd());
63
- }
64
- const body = await readFile(join(base, 'replies', name), 'utf8').catch(() => '');
65
- out.push(`${heading(`RECEIVED — ${label}`)}${body.trimEnd()}`);
66
- }
67
- if (!openingWritten && task.firstMessage) {
68
- out.unshift(`${heading('SENT — the message that opened the task')}${task.firstMessage.trimEnd()}`);
69
- }
70
- return out;
71
- }
72
- /**
73
- * What version control did for one task, as lines in the record.
74
- *
75
- * This belongs in the document rather than only on screen. The question someone asks weeks
76
- * later is "where did this change go", and the answer — the branch, the commit it started
77
- * from, the commits it produced — is not reconstructable from a summary. `commits` is the
78
- * list the runner read back from the repository after committing, so the count is what is
79
- * actually on that branch since it was cut, not what anybody assumed.
80
- */
81
- export function versionControlLines(task, session) {
82
- const vcs = task.vcs;
83
- const loose = task.treeChanged?.length ? [`changed, not committed: ${task.treeChanged.length} file(s) — ${task.treeChanged.slice(0, 10).join(', ')}${task.treeChanged.length > 10 ? ', …' : ''}`] : [];
84
- if (!session.vcs?.enabled)
85
- return ['version control : off for this session', ...loose];
86
- if (!vcs || (!vcs.branch && !vcs.problem))
87
- return ['version control : nothing was recorded for this task'];
88
- if (!vcs.branch)
89
- return [`version control : did not run — ${vcs.problem}`];
90
- const commits = vcs.commits ?? [];
91
- // In the order it happened: the tree before the runner's commit, the commit, the tree after it.
92
- const before = vcs.beforeCommit;
93
- const after = vcs.afterCommit;
94
- const lines = [
95
- `branch : ${vcs.branch}`,
96
- `started at : ${vcs.baseCommit ? vcs.baseCommit.slice(0, 8) : '—'} (the commit this task branched from)`,
97
- ...(before ? [`before commit: ${before.changed.length} path(s) changed or new in the working tree${before.changed.length ? ` — ${before.changed.slice(0, 10).join(', ')}` : ''}`] : []),
98
- `commit : ${vcs.commit
99
- ? vcs.commit.slice(0, 8)
100
- : vcs.problem
101
- ? 'none — see the note below'
102
- : session.vcs?.commitOnFinish === false
103
- ? `none — commits are off for this session${after && !after.clean ? ', so the changes stay in the working tree' : ''}`
104
- : 'none — the task changed no files'}`,
105
- ...(after
106
- ? [`after commit: on ${after.branch ?? '?'} at ${after.head ? after.head.slice(0, 8) : '?'}, ${after.clean ? 'working tree clean' : `still uncommitted: ${after.changed.slice(0, 10).join(', ')}`}`]
107
- : []),
108
- `commits : ${commits.length} on this branch since it was cut`,
109
- ];
110
- for (const line of commits)
111
- lines.push(` ${line}`);
112
- if (!vcs.commit)
113
- lines.push(...loose);
114
- const files = vcs.files ?? [];
115
- if (files.length > 0) {
116
- lines.push(`files : ${files.length} changed by this task's commit`);
117
- for (const f of files) {
118
- const counts = f.added < 0 || f.removed < 0 ? 'binary' : `+${f.added} -${f.removed}`;
119
- lines.push(` ${counts.padEnd(12)} ${f.path}`);
120
- }
121
- }
122
- else if (vcs.commit) {
123
- lines.push('files : none recorded for this commit');
124
- }
125
- lines.push('pushed : no — this runner never pushes');
126
- if (vcs.problem)
127
- lines.push(`note : ${vcs.problem}`);
128
- const earlier = (task.attempts ?? []).map((a) => a.vcs?.branch).filter(Boolean);
129
- if (earlier.length > 0) {
130
- lines.push(`earlier : ${earlier.join(', ')} (branches of the previous attempts, untouched)`);
131
- }
132
- return lines;
133
- }
134
- /**
135
- * Which shells the machine had when the task ran, as lines in the record.
136
- *
137
- * Worth the four lines because of the failure it explains. A task whose commands were written
138
- * for PowerShell 7 on a machine that has not got it fails in a way that reads like bad work —
139
- * every command dead, nothing accomplished — and the only thing that says otherwise is what was
140
- * installed at the time. Read weeks later, on a different machine, that is not recoverable from
141
- * anywhere else.
142
- */
143
- function shellLines(task) {
144
- const shells = task.environment?.shells;
145
- if (!shells)
146
- return [];
147
- const lines = SHELL_ORDER.map((shell) => `${shell.padEnd(11)}: ${shells.found[shell] ?? '(not installed)'}`);
148
- const fallback = task.environment?.defaultShell ?? availableShells(shells)[0];
149
- lines.push(`default : ${fallback ?? '(none — this machine could run nothing)'} for a step or check that named no shell`);
150
- return lines;
151
- }
152
- /** One task's section of the document. */
153
- async function sectionFor(task, index, input) {
154
- const parts = [];
155
- parts.push(heading(`TASK ${index}: ${task.title}`).trimStart());
156
- parts.push([
157
- `status : ${task.status}`,
158
- `attempt : ${task.attempt ?? 1}${(task.attempts?.length ?? 0) > 0 ? ` (earlier attempts: ${task.attempts?.length})` : ''}`,
159
- `started : ${when(task.startedAt)}`,
160
- `finished : ${when(task.finishedAt)}`,
161
- `iterations : ${task.iterations}`,
162
- `run folder : ${task.runId ?? '(never started)'}`,
163
- ].join('\n'));
164
- parts.push(`\n${THIN}\nVERSION CONTROL\n${THIN}`);
165
- parts.push(versionControlLines(task, input.session).join('\n'));
166
- const shells = shellLines(task);
167
- if (shells.length > 0) {
168
- parts.push(`\n${THIN}\nSHELLS ON THE MACHINE\n${THIN}`);
169
- parts.push(shells.join('\n'));
170
- }
171
- /*
172
- * What the second opinion concluded, kept in the record because it is the part a reader
173
- * cannot reconstruct. A summary says what the implementer believes about its own work; this
174
- * says what somebody who had no part in it found when they ran the thing.
175
- */
176
- if (task.review && task.review.verdict !== 'skipped') {
177
- const r = task.review;
178
- parts.push(`\n${THIN}\nINDEPENDENT REVIEW\n${THIN}`);
179
- parts.push([
180
- `verdict : ${r.verdict}`,
181
- `rounds : ${r.rounds}`,
182
- `commands : ${r.stepsRun} run by the reviewer`,
183
- r.model ? `model : ${r.model}` : '',
184
- r.problem ? `problem : ${r.problem}` : '',
185
- r.summary ? `\n${r.summary}` : '',
186
- (r.findings ?? []).length > 0
187
- ? '\n' +
188
- (r.findings ?? [])
189
- .map((f, i) => `${i + 1}. ${f.what}${f.where ? ` (${f.where})` : ''}\n Evidence: ${f.evidence}`)
190
- .join('\n\n')
191
- : '',
192
- ]
193
- .filter(Boolean)
194
- .join('\n'));
195
- }
196
- /*
197
- * The expectation is the task as it was written, not the whole first message.
198
- *
199
- * The first message of a session carries the level-1 contract in front of the task, which
200
- * runs to several pages. Putting that under "EXPECTED" buries the one paragraph the reader
201
- * is comparing against the outcome. The exact first message is not lost: the full variant
202
- * prints it verbatim as the first thing in the conversation.
203
- */
204
- parts.push(`\n${THIN}\nEXPECTED — the task as it was written\n${THIN}`);
205
- parts.push(task.prompt.trimEnd() || '(the task had no text)');
206
- if (task.level2.trim()) {
207
- parts.push(`\n${THIN}\nEXPECTED — the project instructions sent with it (level 2)\n${THIN}`);
208
- parts.push(task.level2.trimEnd());
209
- }
210
- if (task.firstMessage && task.firstMessage.includes('Level 1')) {
211
- parts.push('\n(The level 1 contract was sent in front of this task. It is in the full variant.)');
212
- }
213
- parts.push(`\n${THIN}\nACTUAL — what came back\n${THIN}`);
214
- if (task.summary)
215
- parts.push(task.summary.trimEnd());
216
- else if (task.reason)
217
- parts.push(`The task did not finish with a summary. Reason: ${task.reason}`);
218
- else
219
- parts.push('(no closing summary)');
220
- // Right under the outcome, because this is the part of it the reader is least likely to
221
- // expect: the task said one thing, and the model — with a reason — did another.
222
- if ((task.deviations ?? []).length > 0) {
223
- parts.push(`\n${THIN}\nNOT AS THE TASK SAID — instructions the model could not follow as written\n${THIN}`);
224
- parts.push(describeDeviations(task.deviations ?? []));
225
- }
226
- if ((task.disputes ?? []).length > 0) {
227
- parts.push(`\n${THIN}\nDISPUTED — review findings the model said were wrong\n${THIN}`);
228
- parts.push(describeDisputes(task.disputes ?? []));
229
- }
230
- if (task.finalReply && task.finalReply.trim() !== (task.summary ?? '').trim()) {
231
- parts.push(`\n${THIN}\nACTUAL — the last message in full\n${THIN}`);
232
- parts.push(task.finalReply.trimEnd());
233
- }
234
- if (input.variant === 'full') {
235
- const conversation = await conversationOf(task, input.runsDir);
236
- if (conversation.length > 0) {
237
- parts.push(`\n${THIN}\nTHE WHOLE CONVERSATION, IN ORDER\n${THIN}`);
238
- parts.push(conversation.join('\n'));
239
- }
240
- else {
241
- parts.push(`\n${THIN}\nTHE WHOLE CONVERSATION, IN ORDER\n${THIN}`);
242
- parts.push('(the run folder is not on this machine any more, so only the record above is left)');
243
- }
244
- }
245
- return `${parts.join('\n')}\n`;
246
- }
247
- /** The whole document, plus a file name that says what it is without being opened. */
248
- export async function buildExport(input) {
249
- const { session, tasks, variant } = input;
250
- const header = [
251
- `copilot-operator — ${variant === 'full' ? 'the whole conversation' : 'expected and actual'}`,
252
- '',
253
- `session : ${session.name} (${session.id})`,
254
- `chat : ${session.chat?.url ?? '(no conversation was opened)'}`,
255
- `model : ${session.model || 'whatever the chat was set to'}${session.modelInUse ? ` (ran on ${session.modelInUse})` : ''}`,
256
- `repository : ${session.vcs?.enabled
257
- ? `${session.vcs.repoDir || session.projectDir || '(none set)'} — ${session.vcs.branchMode === 'per-session' ? 'one branch for the whole session' : 'a branch of its own for every task'}, prefix ${session.vcs.branchPrefix}${session.vcs.commitOnFinish ? '' : ', commits off'}`
258
- : 'version control is off for this session'}`,
259
- `tasks : ${tasks.length} of ${session.tasks.length}`,
260
- `exported : ${when(new Date().toISOString())}`,
261
- '',
262
- variant === 'full'
263
- ? 'Every message of every selected task, in the order it was sent or received.'
264
- : 'For each selected task: the message that opened it, and what came back at the end.',
265
- ].join('\n');
266
- const sections = [];
267
- for (const [i, task] of tasks.entries()) {
268
- sections.push(await sectionFor(task, i + 1, input));
269
- }
270
- const safeName = session.name.replace(/[^\p{L}\p{N}._ -]/gu, '').trim().replace(/\s+/g, '-') || 'session';
271
- const stamp = new Date().toISOString().slice(0, 16).replace(/[:T]/g, '').replace(/-/g, '');
272
- const kind = variant === 'full' ? 'full' : 'expected-actual';
273
- return {
274
- fileName: `${safeName}-${kind}-${stamp}.txt`,
275
- content: `${header}\n${sections.join('\n')}`,
276
- };
277
- }
@@ -1,95 +0,0 @@
1
- const ENDED = ['done', 'failed', 'blocked', 'aborted', 'limit-reached'];
2
- function attemptsOf(task) {
3
- const all = [...(task.attempts ?? [])];
4
- if (ENDED.includes(task.status))
5
- all.push(task);
6
- return all.filter((a) => ENDED.includes(a.status));
7
- }
8
- function modelOf(session) {
9
- return (session.modelInUse ?? '').trim() || (session.model ?? '').trim() || '(the chat default)';
10
- }
11
- function row(group, tasks) {
12
- const r = {
13
- group,
14
- tasks: 0,
15
- attempts: 0,
16
- firstPass: { n: 0, of: 0 },
17
- doneInTheEnd: { n: 0, of: 0 },
18
- ended: {},
19
- freshRetries: 0,
20
- manualInterventions: 0,
21
- falseCompletion: { n: 0, of: 0 },
22
- reviewRejection: { n: 0, of: 0 },
23
- repeatedCommands: { n: 0, of: 0 },
24
- scopeViolation: { n: 0, of: 0 },
25
- noProgress: { n: 0, of: 0 },
26
- unrelatedDiff: { n: 0, of: 0 },
27
- resumed: { n: 0, of: 0 },
28
- withStats: 0,
29
- };
30
- for (const task of tasks) {
31
- const list = attemptsOf(task);
32
- if (list.length === 0)
33
- continue;
34
- r.tasks += 1;
35
- r.attempts += list.length;
36
- r.firstPass.of += 1;
37
- if (list[0].status === 'done')
38
- r.firstPass.n += 1;
39
- const last = list[list.length - 1];
40
- r.doneInTheEnd.of += 1;
41
- if (last.status === 'done')
42
- r.doneInTheEnd.n += 1;
43
- r.ended[last.status] = (r.ended[last.status] ?? 0) + 1;
44
- list.forEach((a, i) => {
45
- if (a.freshRetry)
46
- r.freshRetries += 1;
47
- else if (i > 0)
48
- r.manualInterventions += 1;
49
- r.unrelatedDiff.of += 1;
50
- if ((a.vcs?.suspicious?.length ?? 0) > 0 || (a.vcs?.foreignCommits?.length ?? 0) > 0)
51
- r.unrelatedDiff.n += 1;
52
- if ((a.scope?.length ?? 0) > 0) {
53
- r.scopeViolation.of += 1;
54
- if ((a.scopeReverted?.length ?? 0) > 0)
55
- r.scopeViolation.n += 1;
56
- }
57
- if (a.continuing) {
58
- r.resumed.of += 1;
59
- if (a.status === 'done')
60
- r.resumed.n += 1;
61
- }
62
- if (a.review && a.review.verdict !== 'skipped') {
63
- r.reviewRejection.of += 1;
64
- if ((a.stats?.reviewRejections ?? 0) > 0 || a.review.verdict === 'fail' || (a.review.rounds ?? 0) > 1)
65
- r.reviewRejection.n += 1;
66
- }
67
- if (!a.stats)
68
- return;
69
- r.withStats += 1;
70
- r.manualInterventions += a.stats.operatorStops;
71
- r.falseCompletion.of += 1;
72
- if (a.stats.doneRejected > 0)
73
- r.falseCompletion.n += 1;
74
- r.repeatedCommands.of += 1;
75
- if (a.stats.repeatsRefused > 0)
76
- r.repeatedCommands.n += 1;
77
- r.noProgress.of += 1;
78
- if (a.stats.stoppedFor === 'no-progress')
79
- r.noProgress.n += 1;
80
- });
81
- }
82
- return r;
83
- }
84
- /** All tasks, then one row per model the sessions ran on, busiest first. */
85
- export function computeMetrics(sessions, now = new Date()) {
86
- const all = sessions.flatMap((s) => s.tasks);
87
- const byModel = new Map();
88
- for (const s of sessions)
89
- byModel.set(modelOf(s), [...(byModel.get(modelOf(s)) ?? []), ...s.tasks]);
90
- const models = [...byModel.entries()]
91
- .map(([group, tasks]) => row(group, tasks))
92
- .filter((r) => r.tasks > 0)
93
- .sort((a, b) => b.tasks - a.tasks);
94
- return { rows: [row('all', all), ...(models.length > 1 ? models : [])], computedAt: now.toISOString() };
95
- }