copilot-operator 0.1.96 → 0.1.99
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/dist/src/api/apiLock.js +82 -0
- package/dist/src/api/folderPicker.js +22 -22
- package/dist/src/api/main.js +5 -0
- package/dist/src/api/operator.controller.js +37 -11
- package/dist/src/api/operator.service.js +493 -86
- package/dist/src/api/server.js +10 -0
- package/dist/src/config/exportHome.js +52 -10
- package/dist/src/config/home.js +27 -11
- package/dist/src/config/schema.js +13 -0
- package/dist/src/exec/authorizer.js +11 -4
- package/dist/src/exec/commandHeads.js +25 -0
- package/dist/src/exec/confinement.js +50 -4
- package/dist/src/exec/network.js +11 -1
- package/dist/src/exec/npmScripts.js +33 -0
- package/dist/src/exec/policy.js +79 -24
- package/dist/src/exec/processes.js +24 -5
- package/dist/src/exec/programs.js +21 -0
- package/dist/src/exec/reportFile.js +2 -1
- package/dist/src/exec/runner.js +31 -9
- package/dist/src/exec/scriptFiles.js +133 -6
- package/dist/src/orchestrator/handoff.js +3 -3
- package/dist/src/orchestrator/kerriganRunner.js +14 -6
- package/dist/src/orchestrator/leadRunner.js +43 -23
- package/dist/src/orchestrator/review.js +66 -10
- package/dist/src/orchestrator/taskRunner.js +73 -14
- package/dist/src/plan/kerrigan.js +253 -253
- package/dist/src/plan/schema.js +3 -13
- package/dist/src/plan/systemGuide.js +28 -28
- package/dist/src/protocol/kerriganSchema.js +5 -1
- package/dist/src/protocol/replySchema.js +2 -2
- package/dist/src/queue/queue.js +93 -0
- package/dist/src/session/compose.js +14 -10
- package/dist/src/session/locatorFailures.js +32 -12
- package/dist/src/session/model.js +23 -0
- package/dist/src/session/store.js +47 -0
- package/dist/src/session/workspace.js +20 -5
- package/dist/src/transport/copilotTransport.js +82 -62
- package/dist/src/util/zip.js +147 -44
- package/dist/src/vcs/newBranch.js +24 -2
- package/dist/src/vcs/operatorGit.js +9 -10
- package/dist/src/vcs/referenceGuard.js +9 -4
- package/dist/web/404.html +2 -2
- package/dist/web/_next/static/chunks/1024-c0eee3ec374816d1.js +1 -0
- package/dist/web/_next/static/chunks/1077.a4fe6ae48f3d3ff9.js +1 -0
- package/dist/web/_next/static/chunks/1548.765d6eed5325bd01.js +1 -0
- package/dist/web/_next/static/chunks/2163.e8d6c85412d5d411.js +1 -0
- package/dist/web/_next/static/chunks/6240-8ba644c53ffab87d.js +1 -0
- package/dist/web/_next/static/chunks/714.f2dcd6b41b58d1a7.js +1 -0
- package/dist/web/_next/static/chunks/7220.652a8a339c1e7401.js +1 -0
- package/dist/web/_next/static/chunks/7921-9cf1ece94fc89bb3.js +1 -0
- package/dist/web/_next/static/chunks/8584.7c438425140f1d8d.js +1 -0
- package/dist/web/_next/static/chunks/9067.8c4e6a64620a45d9.js +1 -0
- package/dist/web/_next/static/chunks/9747.43d25bdff8737d09.js +1 -0
- package/dist/web/_next/static/chunks/app/{layout-2364903896c2c175.js → layout-97259931ed97e20d.js} +1 -1
- package/dist/web/_next/static/chunks/app/page-26e4ea30eb076e6b.js +1 -0
- package/dist/web/_next/static/chunks/app/queue/page-7228e045f8ea10c4.js +1 -0
- package/dist/web/_next/static/chunks/app/settings/page-c915d61553e1025b.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-4d24f44eb9077fb7.js +1 -0
- package/dist/web/_next/static/chunks/{webpack-3f144d13be3516c2.js → webpack-31db88c3d5781520.js} +1 -1
- package/dist/web/_next/static/css/{523d11041085f836.css → 87999096d96266fd.css} +1 -1
- package/dist/web/defaults.html +2 -2
- package/dist/web/defaults.txt +26 -25
- package/dist/web/index.html +3 -3
- package/dist/web/index.txt +26 -25
- package/dist/web/queue.html +2 -2
- package/dist/web/queue.txt +26 -25
- package/dist/web/settings.html +2 -2
- package/dist/web/settings.txt +26 -25
- package/dist/web/system.html +2 -2
- package/dist/web/system.txt +26 -25
- package/package.json +3 -2
- package/prompts/kerrigan1.md +2 -1
- package/prompts/lead1.md +2 -1
- package/prompts/level1.md +6 -1
- package/prompts/review1.md +7 -4
- package/dist/web/_next/static/chunks/1024-214ded25b9048526.js +0 -1
- package/dist/web/_next/static/chunks/1077.161de82f740d47f0.js +0 -1
- package/dist/web/_next/static/chunks/1548.f2688468bf946e13.js +0 -1
- package/dist/web/_next/static/chunks/2163.b8ada3b7bde69f03.js +0 -1
- package/dist/web/_next/static/chunks/714.d1489788e598833b.js +0 -1
- package/dist/web/_next/static/chunks/7220.b85c8d105f394389.js +0 -1
- package/dist/web/_next/static/chunks/7921-00ebbcc6f65fbe35.js +0 -1
- package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +0 -1
- package/dist/web/_next/static/chunks/8584.a678bfced1cea938.js +0 -1
- package/dist/web/_next/static/chunks/9067.6da03ae052877b19.js +0 -1
- package/dist/web/_next/static/chunks/9747.ba29e64e97e8a15b.js +0 -1
- package/dist/web/_next/static/chunks/app/page-d031bf326e401246.js +0 -1
- package/dist/web/_next/static/chunks/app/queue/page-9cfc8f78d536cfb6.js +0 -1
- package/dist/web/_next/static/chunks/app/settings/page-9c2b961beb8b3dce.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-3466496814a70b62.js +0 -1
- /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → n8n-2FmbL8PhXulu4hTV5}/_buildManifest.js +0 -0
- /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → n8n-2FmbL8PhXulu4hTV5}/_ssgManifest.js +0 -0
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { createHash } from 'node:crypto';
|
|
8
8
|
import { existsSync, statSync } from 'node:fs';
|
|
9
|
-
import { readdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
10
|
-
import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
|
+
import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
11
11
|
import { git, looksLikeRepo, repoState } from '../vcs/git.js';
|
|
12
12
|
import { moveOver } from './store.js';
|
|
13
13
|
export async function workspaceInfo(dir, name = '') {
|
|
@@ -71,12 +71,18 @@ function insideFolder(dir, path) {
|
|
|
71
71
|
function versionOf(bytes) {
|
|
72
72
|
return createHash('sha256').update(bytes).digest('hex').slice(0, 20);
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Said when the file is not on disk (any more): deleted or renamed under the editor (second bug hunt, 2026-11-19), which
|
|
76
|
+
* the page says, keeping the edit and offering to save it there again.
|
|
77
|
+
*/
|
|
78
|
+
export const GONE_FROM_DISK = 'gone-from-disk';
|
|
79
|
+
const gone = (clean) => Object.assign(new Error(`There is no file ${clean} in the project folder.`), { code: GONE_FROM_DISK });
|
|
74
80
|
/** One file of the folder as it is on disk, as text; a binary or very large one is said to be one. */
|
|
75
81
|
export async function workspaceFile(dir, path, maxBytes = MAX_EDIT_BYTES) {
|
|
76
82
|
const { clean, full } = insideFolder(dir, path);
|
|
77
83
|
const st = await stat(full).catch(() => null);
|
|
78
84
|
if (!st?.isFile())
|
|
79
|
-
throw
|
|
85
|
+
throw gone(clean);
|
|
80
86
|
if (st.size > maxBytes)
|
|
81
87
|
return { path: clean, text: null, binary: false, tooLarge: true, size: st.size };
|
|
82
88
|
const bytes = await readFile(full);
|
|
@@ -112,12 +118,21 @@ export const CHANGED_ON_DISK = 'changed-on-disk';
|
|
|
112
118
|
* is there already and is text; and only over the version the edit was made on (`base`), so a change the chat made to
|
|
113
119
|
* it meanwhile is not overwritten without the operator knowing — without `base` it is saved whatever is there. The
|
|
114
120
|
* file keeps its own line endings and its byte-order mark: the editor works in LF, and a CRLF file stays CRLF.
|
|
121
|
+
* `again`: a file deleted or renamed under the editor, saved where it was with the editor's text (2026-11-19).
|
|
115
122
|
*/
|
|
116
|
-
export async function saveWorkspaceFile(dir, path, text, base) {
|
|
123
|
+
export async function saveWorkspaceFile(dir, path, text, base, again = false) {
|
|
117
124
|
const { clean, full } = insideFolder(dir, path);
|
|
118
125
|
const st = await stat(full).catch(() => null);
|
|
126
|
+
if (!st && again) {
|
|
127
|
+
const bytes = Buffer.from(text.replace(/\r\n/g, '\n'), 'utf8');
|
|
128
|
+
if (bytes.length > MAX_EDIT_BYTES)
|
|
129
|
+
throw new Error(`The text is too large to save (${bytes.length} bytes).`);
|
|
130
|
+
await mkdir(dirname(full), { recursive: true });
|
|
131
|
+
await writeFile(full, bytes, { flag: 'wx' });
|
|
132
|
+
return { path: clean, version: versionOf(bytes), size: bytes.length };
|
|
133
|
+
}
|
|
119
134
|
if (!st?.isFile())
|
|
120
|
-
throw
|
|
135
|
+
throw gone(clean);
|
|
121
136
|
if (st.size > MAX_EDIT_BYTES)
|
|
122
137
|
throw new Error(`${clean} is too large to edit here.`);
|
|
123
138
|
const before = await readFile(full);
|
|
@@ -218,65 +218,65 @@ const NOTICE_ID = 'copilot-operator-notice';
|
|
|
218
218
|
* impossible — the runner notes it before the click and waits for it to move, so a copy that
|
|
219
219
|
* did not happen reads as a failure rather than as the previous answer.
|
|
220
220
|
*/
|
|
221
|
-
export const CLIPBOARD_GUARD = `(() => {
|
|
222
|
-
const state = { text: '', seq: 0 };
|
|
223
|
-
try {
|
|
224
|
-
Object.defineProperty(window, '__copClipboard', { value: state, enumerable: false });
|
|
225
|
-
} catch (e) {
|
|
226
|
-
window.__copClipboard = state;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const remember = (text) => {
|
|
230
|
-
if (typeof text !== 'string' || text.length === 0) return;
|
|
231
|
-
state.text = text;
|
|
232
|
-
state.seq += 1;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const clip = navigator.clipboard;
|
|
236
|
-
if (clip) {
|
|
237
|
-
try {
|
|
238
|
-
Object.defineProperty(clip, 'writeText', {
|
|
239
|
-
configurable: true,
|
|
240
|
-
writable: true,
|
|
241
|
-
value: (text) => {
|
|
242
|
-
remember(String(text));
|
|
243
|
-
return Promise.resolve();
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
} catch (e) { /* a frame that will not let its clipboard be replaced reads as a failure later */ }
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
Object.defineProperty(clip, 'write', {
|
|
250
|
-
configurable: true,
|
|
251
|
-
writable: true,
|
|
252
|
-
value: async (items) => {
|
|
253
|
-
for (const item of items || []) {
|
|
254
|
-
try {
|
|
255
|
-
if (item && item.types && item.types.indexOf('text/plain') >= 0) {
|
|
256
|
-
remember(await (await item.getType('text/plain')).text());
|
|
257
|
-
}
|
|
258
|
-
} catch (e) { /* one unreadable item is not a reason to drop the rest */ }
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
} catch (e) { /* as above */ }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// The old way: select text in a hidden field, then execCommand('copy'). The selection is
|
|
266
|
-
// exactly the text being copied, so it is taken and the command is never run.
|
|
267
|
-
try {
|
|
268
|
-
const realExec = document.execCommand.bind(document);
|
|
269
|
-
document.execCommand = (command, ...rest) => {
|
|
270
|
-
if (String(command).toLowerCase() === 'copy') {
|
|
271
|
-
const selected = String(window.getSelection() || '');
|
|
272
|
-
if (selected.length > 0) {
|
|
273
|
-
remember(selected);
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return realExec(command, ...rest);
|
|
278
|
-
};
|
|
279
|
-
} catch (e) { /* as above */ }
|
|
221
|
+
export const CLIPBOARD_GUARD = `(() => {
|
|
222
|
+
const state = { text: '', seq: 0 };
|
|
223
|
+
try {
|
|
224
|
+
Object.defineProperty(window, '__copClipboard', { value: state, enumerable: false });
|
|
225
|
+
} catch (e) {
|
|
226
|
+
window.__copClipboard = state;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const remember = (text) => {
|
|
230
|
+
if (typeof text !== 'string' || text.length === 0) return;
|
|
231
|
+
state.text = text;
|
|
232
|
+
state.seq += 1;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const clip = navigator.clipboard;
|
|
236
|
+
if (clip) {
|
|
237
|
+
try {
|
|
238
|
+
Object.defineProperty(clip, 'writeText', {
|
|
239
|
+
configurable: true,
|
|
240
|
+
writable: true,
|
|
241
|
+
value: (text) => {
|
|
242
|
+
remember(String(text));
|
|
243
|
+
return Promise.resolve();
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
} catch (e) { /* a frame that will not let its clipboard be replaced reads as a failure later */ }
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
Object.defineProperty(clip, 'write', {
|
|
250
|
+
configurable: true,
|
|
251
|
+
writable: true,
|
|
252
|
+
value: async (items) => {
|
|
253
|
+
for (const item of items || []) {
|
|
254
|
+
try {
|
|
255
|
+
if (item && item.types && item.types.indexOf('text/plain') >= 0) {
|
|
256
|
+
remember(await (await item.getType('text/plain')).text());
|
|
257
|
+
}
|
|
258
|
+
} catch (e) { /* one unreadable item is not a reason to drop the rest */ }
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
} catch (e) { /* as above */ }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// The old way: select text in a hidden field, then execCommand('copy'). The selection is
|
|
266
|
+
// exactly the text being copied, so it is taken and the command is never run.
|
|
267
|
+
try {
|
|
268
|
+
const realExec = document.execCommand.bind(document);
|
|
269
|
+
document.execCommand = (command, ...rest) => {
|
|
270
|
+
if (String(command).toLowerCase() === 'copy') {
|
|
271
|
+
const selected = String(window.getSelection() || '');
|
|
272
|
+
if (selected.length > 0) {
|
|
273
|
+
remember(selected);
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return realExec(command, ...rest);
|
|
278
|
+
};
|
|
279
|
+
} catch (e) { /* as above */ }
|
|
280
280
|
})();`;
|
|
281
281
|
/**
|
|
282
282
|
* A locator of the chat that found nothing where the bot needed it (operator, 2026-11-17: "a mechanism that detects
|
|
@@ -1064,7 +1064,7 @@ export class CopilotTransport {
|
|
|
1064
1064
|
// Most likely the box itself (2026-11-17: Copilot's chat was at /home, its box changed): said as the box's locator.
|
|
1065
1065
|
return await this.locatorMissing('composer', `on ${whereIs(url)}, which did not turn into the chat`, {
|
|
1066
1066
|
message: (files) => `Copilot showed its page ${whereIs(url)} instead of the chat, and the chat did not open from there ` +
|
|
1067
|
-
`(by its address on that host, nor by a link to it on the page). Nothing was sent. ${files} ${this.composerHint()}
|
|
1067
|
+
`(by its address on that host, nor by a link to it on the page). Nothing was sent. ${files} ${this.composerHint()}
|
|
1068
1068
|
Current URL: ${url}`,
|
|
1069
1069
|
});
|
|
1070
1070
|
}
|
|
@@ -1160,10 +1160,10 @@ Current URL: ${url}`,
|
|
|
1160
1160
|
unknown: 'The page is not the Microsoft 365 Copilot chat.',
|
|
1161
1161
|
};
|
|
1162
1162
|
if (where === 'unknown') {
|
|
1163
|
-
throw await this.locatorMissing('composer', `on ${whereIs(url)}`, { message: (files) => `${explain.unknown} ${files} ${this.composerHint()}
|
|
1163
|
+
throw await this.locatorMissing('composer', `on ${whereIs(url)}`, { message: (files) => `${explain.unknown} ${files} ${this.composerHint()}
|
|
1164
1164
|
Current URL: ${url}` });
|
|
1165
1165
|
}
|
|
1166
|
-
throw new Error(`${explain[where] ?? explain.unknown}
|
|
1166
|
+
throw new Error(`${explain[where] ?? explain.unknown}
|
|
1167
1167
|
Current URL: ${url}`);
|
|
1168
1168
|
}
|
|
1169
1169
|
/**
|
|
@@ -1256,6 +1256,12 @@ Current URL: ${url}`);
|
|
|
1256
1256
|
* Opens the chat and, if the tenant has signed us out, waits for the human. The bot never
|
|
1257
1257
|
* types credentials; it only waits for the composer to appear.
|
|
1258
1258
|
*/
|
|
1259
|
+
/**
|
|
1260
|
+
* `boxNotWaited`: for a reading that only looks — the models, "Check the locators" — a box not found on Copilot's own
|
|
1261
|
+
* chat page, no sign-in page in sight, is said at once as the box's locator, not waited on for the whole sign-in time
|
|
1262
|
+
* (second bug hunt, 2026-11-19: the operator, at Settings, waited fifteen minutes with nothing said). A sign-in page is
|
|
1263
|
+
* still waited on.
|
|
1264
|
+
*/
|
|
1259
1265
|
async ensureSignedIn(url = this.opts.chatUrl, opts = {}) {
|
|
1260
1266
|
// A box locator saved in Settings that cannot be used: said once, before the box is looked for with the default.
|
|
1261
1267
|
for (const problem of this.chatLocatorProblems.splice(0))
|
|
@@ -1284,8 +1290,14 @@ Current URL: ${url}`);
|
|
|
1284
1290
|
*/
|
|
1285
1291
|
const firstLook = Math.min(this.boxSuspectMs, this.opts.signInTimeoutMs);
|
|
1286
1292
|
const soon = await this.composerWithin(firstLook, opts.signal, stoppedHere);
|
|
1293
|
+
if (!soon && opts.boxNotWaited && isWorkChatAddress(this.p.url())) {
|
|
1294
|
+
this.warned.add('composer');
|
|
1295
|
+
throw await this.locatorMissing('composer', `on ${whereIs(this.p.url())}, Copilot's own chat page and not a sign-in page, for ${Math.round(firstLook / 1000)} s`);
|
|
1296
|
+
}
|
|
1297
|
+
let suspected = false;
|
|
1287
1298
|
if (!soon && isWorkChatAddress(this.p.url()) && !this.warned.has('composer')) {
|
|
1288
1299
|
this.warned.add('composer');
|
|
1300
|
+
suspected = true;
|
|
1289
1301
|
await this.locatorMissing('composer', `on ${whereIs(this.p.url())}, Copilot's own chat page and not a sign-in page, for ${Math.round(firstLook / 1000)} s: if you are signed in, the box's locator is the one to fix (the bot goes on waiting for a sign-in meanwhile)`, { stopped: false }).catch(() => undefined);
|
|
1290
1302
|
}
|
|
1291
1303
|
if (!soon && !(await this.composerWithin(Math.max(1, this.opts.signInTimeoutMs - firstLook), opts.signal, stoppedHere))) {
|
|
@@ -1295,6 +1307,14 @@ Current URL: ${url}`);
|
|
|
1295
1307
|
? ` If you were signed in, the box to write in was not found on Copilot's chat page: fix "Box to write in" in Settings → "The chat's locators" (its notice has the file for a chatbot). In force: ${this.chatLocators.composer}`
|
|
1296
1308
|
: ''));
|
|
1297
1309
|
}
|
|
1310
|
+
/*
|
|
1311
|
+
* Found after all, once the sign-in was done (second bug hunt, 2026-11-19): the box's locator was not at fault, and
|
|
1312
|
+
* the red field and the banner it had been given stayed, saying so.
|
|
1313
|
+
*/
|
|
1314
|
+
if (suspected) {
|
|
1315
|
+
this.warned.delete('composer');
|
|
1316
|
+
this.emit('locator-found', { key: 'composer', locator: this.chatLocators.composer });
|
|
1317
|
+
}
|
|
1298
1318
|
this.emit('signed-in');
|
|
1299
1319
|
// A sign-in may come back to Copilot's home page rather than to its chat.
|
|
1300
1320
|
at = await this.arrive(Url.newChatPath, opts.signal, stoppedHere);
|
package/dist/src/util/zip.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A .zip archive, written with what Node has (2026-10-23, the bot's folder exported from the System page): each file
|
|
3
3
|
* deflated with `zlib`, its CRC-32, a local header, and the central directory at the end. No package to install, and
|
|
4
|
-
* Windows opens it as it opens any .zip.
|
|
4
|
+
* Windows opens it as it opens any .zip.
|
|
5
|
+
*
|
|
6
|
+
* Written as it goes (second bug hunt, 2026-11-19): `ZipWriter` sends each file to the download as it is packed, one
|
|
7
|
+
* file in memory at a time, deflated off the API's thread — the whole archive was built in memory first, with every
|
|
8
|
+
* run's records a few gigabytes, and the API answered nothing while it was. And ZIP64 where the plain format runs out
|
|
9
|
+
* (more than 65,535 files, or past 4 GB), where it failed or wrote an archive no tool could open.
|
|
5
10
|
*/
|
|
6
|
-
import { deflateRawSync } from 'node:zlib';
|
|
11
|
+
import { deflateRaw, deflateRawSync } from 'node:zlib';
|
|
12
|
+
import { promisify } from 'node:util';
|
|
13
|
+
const deflateLater = promisify(deflateRaw);
|
|
14
|
+
const MAX16 = 0xffff;
|
|
15
|
+
const MAX32 = 0xffffffff;
|
|
7
16
|
const CRC_TABLE = (() => {
|
|
8
17
|
const table = new Uint32Array(256);
|
|
9
18
|
for (let n = 0; n < 256; n += 1) {
|
|
@@ -28,53 +37,147 @@ function dosTime(d) {
|
|
|
28
37
|
date: ((year - 1980) << 9) | ((d.getMonth() + 1) << 5) | d.getDate(),
|
|
29
38
|
};
|
|
30
39
|
}
|
|
40
|
+
function packed(entry, deflated) {
|
|
41
|
+
// Forward slashes, no leading one, UTF-8 names (flag 0x0800).
|
|
42
|
+
const name = Buffer.from(entry.name.replace(/\\/g, '/').replace(/^\/+/, ''), 'utf8');
|
|
43
|
+
const stored = deflated.length >= entry.data.length;
|
|
44
|
+
const { time, date } = dosTime(entry.mtime ?? new Date());
|
|
45
|
+
return { name, method: stored ? 0 : 8, body: stored ? entry.data : deflated, crc: crc32(entry.data), size: entry.data.length, time, date };
|
|
46
|
+
}
|
|
47
|
+
/** ZIP64's extra field: the values the plain fields could not hold, in the order the format gives them. */
|
|
48
|
+
function zip64Extra(values) {
|
|
49
|
+
if (values.length === 0)
|
|
50
|
+
return Buffer.alloc(0);
|
|
51
|
+
const extra = Buffer.alloc(4 + 8 * values.length);
|
|
52
|
+
extra.writeUInt16LE(0x0001, 0);
|
|
53
|
+
extra.writeUInt16LE(8 * values.length, 2);
|
|
54
|
+
values.forEach((v, i) => extra.writeBigUInt64LE(BigInt(v), 4 + 8 * i));
|
|
55
|
+
return extra;
|
|
56
|
+
}
|
|
57
|
+
function localHeader(p) {
|
|
58
|
+
const big = p.size >= MAX32 || p.body.length >= MAX32;
|
|
59
|
+
// In a local header, ZIP64 carries both sizes when either needs it.
|
|
60
|
+
const extra = big ? zip64Extra([p.size, p.body.length]) : Buffer.alloc(0);
|
|
61
|
+
const head = Buffer.alloc(30);
|
|
62
|
+
head.writeUInt32LE(0x04034b50, 0);
|
|
63
|
+
head.writeUInt16LE(big ? 45 : 20, 4);
|
|
64
|
+
head.writeUInt16LE(0x0800, 6);
|
|
65
|
+
head.writeUInt16LE(p.method, 8);
|
|
66
|
+
head.writeUInt16LE(p.time, 10);
|
|
67
|
+
head.writeUInt16LE(p.date, 12);
|
|
68
|
+
head.writeUInt32LE(p.crc, 14);
|
|
69
|
+
head.writeUInt32LE(big ? MAX32 : p.body.length, 18);
|
|
70
|
+
head.writeUInt32LE(big ? MAX32 : p.size, 22);
|
|
71
|
+
head.writeUInt16LE(p.name.length, 26);
|
|
72
|
+
head.writeUInt16LE(extra.length, 28);
|
|
73
|
+
return Buffer.concat([head, p.name, extra]);
|
|
74
|
+
}
|
|
75
|
+
function centralHeader(p, offset) {
|
|
76
|
+
const sizeBig = p.size >= MAX32;
|
|
77
|
+
const bodyBig = p.body.length >= MAX32;
|
|
78
|
+
const offsetBig = offset >= MAX32;
|
|
79
|
+
const extra = zip64Extra([...(sizeBig ? [p.size] : []), ...(bodyBig ? [p.body.length] : []), ...(offsetBig ? [offset] : [])]);
|
|
80
|
+
const needs = sizeBig || bodyBig || offsetBig ? 45 : 20;
|
|
81
|
+
const head = Buffer.alloc(46);
|
|
82
|
+
head.writeUInt32LE(0x02014b50, 0);
|
|
83
|
+
head.writeUInt16LE(needs, 4);
|
|
84
|
+
head.writeUInt16LE(needs, 6);
|
|
85
|
+
head.writeUInt16LE(0x0800, 8);
|
|
86
|
+
head.writeUInt16LE(p.method, 10);
|
|
87
|
+
head.writeUInt16LE(p.time, 12);
|
|
88
|
+
head.writeUInt16LE(p.date, 14);
|
|
89
|
+
head.writeUInt32LE(p.crc, 16);
|
|
90
|
+
head.writeUInt32LE(bodyBig ? MAX32 : p.body.length, 20);
|
|
91
|
+
head.writeUInt32LE(sizeBig ? MAX32 : p.size, 24);
|
|
92
|
+
head.writeUInt16LE(p.name.length, 28);
|
|
93
|
+
head.writeUInt16LE(extra.length, 30);
|
|
94
|
+
head.writeUInt32LE(offsetBig ? MAX32 : offset, 42);
|
|
95
|
+
return Buffer.concat([head, p.name, extra]);
|
|
96
|
+
}
|
|
97
|
+
/** The end of the archive: with ZIP64's record and its locator first when the plain end cannot hold the counts. */
|
|
98
|
+
function endRecords(count, dirOffset, dirSize) {
|
|
99
|
+
const big = count >= MAX16 || dirOffset >= MAX32 || dirSize >= MAX32;
|
|
100
|
+
const end = Buffer.alloc(22);
|
|
101
|
+
end.writeUInt32LE(0x06054b50, 0);
|
|
102
|
+
end.writeUInt16LE(big ? MAX16 : count, 8);
|
|
103
|
+
end.writeUInt16LE(big ? MAX16 : count, 10);
|
|
104
|
+
end.writeUInt32LE(big ? MAX32 : dirSize, 12);
|
|
105
|
+
end.writeUInt32LE(big ? MAX32 : dirOffset, 16);
|
|
106
|
+
if (!big)
|
|
107
|
+
return end;
|
|
108
|
+
const record = Buffer.alloc(56);
|
|
109
|
+
record.writeUInt32LE(0x06064b50, 0);
|
|
110
|
+
record.writeBigUInt64LE(44n, 4);
|
|
111
|
+
record.writeUInt16LE(45, 12);
|
|
112
|
+
record.writeUInt16LE(45, 14);
|
|
113
|
+
record.writeBigUInt64LE(BigInt(count), 24);
|
|
114
|
+
record.writeBigUInt64LE(BigInt(count), 32);
|
|
115
|
+
record.writeBigUInt64LE(BigInt(dirSize), 40);
|
|
116
|
+
record.writeBigUInt64LE(BigInt(dirOffset), 48);
|
|
117
|
+
const locator = Buffer.alloc(20);
|
|
118
|
+
locator.writeUInt32LE(0x07064b50, 0);
|
|
119
|
+
locator.writeBigUInt64LE(BigInt(dirOffset + dirSize), 8);
|
|
120
|
+
locator.writeUInt32LE(1, 16);
|
|
121
|
+
return Buffer.concat([record, locator, end]);
|
|
122
|
+
}
|
|
123
|
+
/** A whole archive in memory: for a few small files. An export goes through `ZipWriter`. */
|
|
31
124
|
export function createZip(entries) {
|
|
32
125
|
const parts = [];
|
|
33
126
|
const central = [];
|
|
34
127
|
let offset = 0;
|
|
35
128
|
for (const entry of entries) {
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const crc = crc32(entry.data);
|
|
42
|
-
const { time, date } = dosTime(entry.mtime ?? new Date());
|
|
43
|
-
const local = Buffer.alloc(30);
|
|
44
|
-
local.writeUInt32LE(0x04034b50, 0);
|
|
45
|
-
local.writeUInt16LE(20, 4);
|
|
46
|
-
local.writeUInt16LE(0x0800, 6);
|
|
47
|
-
local.writeUInt16LE(stored ? 0 : 8, 8);
|
|
48
|
-
local.writeUInt16LE(time, 10);
|
|
49
|
-
local.writeUInt16LE(date, 12);
|
|
50
|
-
local.writeUInt32LE(crc, 14);
|
|
51
|
-
local.writeUInt32LE(body.length, 18);
|
|
52
|
-
local.writeUInt32LE(entry.data.length, 22);
|
|
53
|
-
local.writeUInt16LE(name.length, 26);
|
|
54
|
-
local.writeUInt16LE(0, 28);
|
|
55
|
-
parts.push(local, name, body);
|
|
56
|
-
const head = Buffer.alloc(46);
|
|
57
|
-
head.writeUInt32LE(0x02014b50, 0);
|
|
58
|
-
head.writeUInt16LE(20, 4);
|
|
59
|
-
head.writeUInt16LE(20, 6);
|
|
60
|
-
head.writeUInt16LE(0x0800, 8);
|
|
61
|
-
head.writeUInt16LE(stored ? 0 : 8, 10);
|
|
62
|
-
head.writeUInt16LE(time, 12);
|
|
63
|
-
head.writeUInt16LE(date, 14);
|
|
64
|
-
head.writeUInt32LE(crc, 16);
|
|
65
|
-
head.writeUInt32LE(body.length, 20);
|
|
66
|
-
head.writeUInt32LE(entry.data.length, 24);
|
|
67
|
-
head.writeUInt16LE(name.length, 28);
|
|
68
|
-
head.writeUInt32LE(offset, 42);
|
|
69
|
-
central.push(head, name);
|
|
70
|
-
offset += local.length + name.length + body.length;
|
|
129
|
+
const p = packed(entry, deflateRawSync(entry.data));
|
|
130
|
+
const local = localHeader(p);
|
|
131
|
+
parts.push(local, p.body);
|
|
132
|
+
central.push(centralHeader(p, offset));
|
|
133
|
+
offset += local.length + p.body.length;
|
|
71
134
|
}
|
|
72
135
|
const directory = Buffer.concat(central);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
136
|
+
return Buffer.concat([...parts, directory, endRecords(entries.length, offset, directory.length)]);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* An archive written to `out` as it goes: each file deflated off the API's thread and sent, then the next, waiting
|
|
140
|
+
* while the reader has not taken what was sent. Only the central directory is kept until the end. A download the
|
|
141
|
+
* reader gave up on stops it.
|
|
142
|
+
*/
|
|
143
|
+
export class ZipWriter {
|
|
144
|
+
out;
|
|
145
|
+
offset = 0;
|
|
146
|
+
count = 0;
|
|
147
|
+
central = [];
|
|
148
|
+
constructor(out) {
|
|
149
|
+
this.out = out;
|
|
150
|
+
}
|
|
151
|
+
async add(entry) {
|
|
152
|
+
const p = packed(entry, await deflateLater(entry.data));
|
|
153
|
+
const at = this.offset;
|
|
154
|
+
await this.send(localHeader(p));
|
|
155
|
+
await this.send(p.body);
|
|
156
|
+
this.central.push(centralHeader(p, at));
|
|
157
|
+
this.count += 1;
|
|
158
|
+
}
|
|
159
|
+
async finish() {
|
|
160
|
+
const directory = Buffer.concat(this.central);
|
|
161
|
+
const at = this.offset;
|
|
162
|
+
await this.send(directory);
|
|
163
|
+
await this.send(endRecords(this.count, at, directory.length));
|
|
164
|
+
}
|
|
165
|
+
async send(b) {
|
|
166
|
+
if (this.out.destroyed)
|
|
167
|
+
throw new Error('the download was given up on');
|
|
168
|
+
this.offset += b.length;
|
|
169
|
+
if (this.out.write(b))
|
|
170
|
+
return;
|
|
171
|
+
await new Promise((resolve) => {
|
|
172
|
+
const go = () => {
|
|
173
|
+
this.out.off('drain', go);
|
|
174
|
+
this.out.off('close', go);
|
|
175
|
+
resolve();
|
|
176
|
+
};
|
|
177
|
+
this.out.on('drain', go);
|
|
178
|
+
this.out.on('close', go);
|
|
179
|
+
});
|
|
180
|
+
if (this.out.destroyed)
|
|
181
|
+
throw new Error('the download was given up on');
|
|
182
|
+
}
|
|
80
183
|
}
|
|
@@ -237,10 +237,32 @@ export async function putBackAside(folder, saved) {
|
|
|
237
237
|
if (!commit)
|
|
238
238
|
return { problem: `there is no branch ${saved} any more` };
|
|
239
239
|
const files = lines((await git(repoDir, ['diff', '--name-only', `${commit}^`, commit])).stdout).length;
|
|
240
|
+
/*
|
|
241
|
+
* Something staged in the folder (third hunt, 2026-11-20): a pick that clashed was taken back with `reset --merge`,
|
|
242
|
+
* which sets a staged change back to the last commit — the operator's `git add` lost — or, with the same file changed
|
|
243
|
+
* after it was staged, refuses, and the conflict markers stayed while the task was told the folder was as it was.
|
|
244
|
+
* Nothing is laid on a folder with something staged; said, with the work kept on its branch.
|
|
245
|
+
*/
|
|
246
|
+
const staged = await git(repoDir, ['diff', '--cached', '--quiet']);
|
|
247
|
+
if (staged.code === 1) {
|
|
248
|
+
return { problem: `the folder has changes staged in it (git add), which laying the work on could not keep apart, so nothing was put back; commit or unstage them and it can be. The work is kept on ${saved}` };
|
|
249
|
+
}
|
|
250
|
+
if (!staged.ok)
|
|
251
|
+
return { problem: `git could not tell whether anything is staged in the folder (${staged.stderr.split(/\r?\n/)[0]}); nothing was put back. The work is kept on ${saved}` };
|
|
240
252
|
const laid = await git(repoDir, [...BOT_AUTHOR, 'cherry-pick', '--no-commit', commit], 300_000);
|
|
241
253
|
if (!laid.ok) {
|
|
242
|
-
|
|
243
|
-
|
|
254
|
+
/*
|
|
255
|
+
* Taken back as a merge is (2026-11-19): a pick with --no-commit leaves no cherry-pick for "--abort" to end, and the
|
|
256
|
+
* folder was left half merged, conflict markers in it. `reset --merge` takes back what the pick laid — the clash, the
|
|
257
|
+
* new files — and keeps an edit of the folder's own elsewhere, which a pick never touches (it refuses first). Its own
|
|
258
|
+
* result is said when it fails (third hunt, 2026-11-20): the folder is then not as it was.
|
|
259
|
+
*/
|
|
260
|
+
const undone = await git(repoDir, ['reset', '--merge']);
|
|
261
|
+
const why = (laid.stderr || laid.stdout).split(/\r?\n/)[0];
|
|
262
|
+
if (!undone.ok) {
|
|
263
|
+
return { problem: `its changes could not be laid on what the folder holds now (${why}), and taking them back out failed too (${undone.stderr.split(/\r?\n/)[0]}): the folder may hold conflict markers — look at it in the Git view. The work is kept on ${saved}` };
|
|
264
|
+
}
|
|
265
|
+
return { problem: `its changes could not be laid on what the folder holds now (${why}); they are kept on ${saved}` };
|
|
244
266
|
}
|
|
245
267
|
// Not staged, as they were: the new files new again, the changed ones changed.
|
|
246
268
|
await git(repoDir, ['reset', '--quiet']);
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { createHash } from 'node:crypto';
|
|
24
24
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
25
|
-
import { mkdir
|
|
25
|
+
import { mkdir } from 'node:fs/promises';
|
|
26
26
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
27
27
|
import { git, gitLive, RUNNER_EMAIL } from './git.js';
|
|
28
28
|
import { askpassProgram, closePasswordWindows, operatorFetchEnv, passwordWindowOpen } from './remoteAuth.js';
|
|
29
29
|
import { workspaceGit } from '../session/workspaceGit.js';
|
|
30
|
+
import { readStoreJson, writeFileAtomically } from '../session/store.js';
|
|
30
31
|
const MINUTES = 60_000;
|
|
31
32
|
/** Long enough for a project's pre-commit checks or a big push; the view shows every line meanwhile. */
|
|
32
33
|
const OP_TIMEOUT_MS = 15 * MINUTES;
|
|
@@ -67,17 +68,14 @@ export class TrustedHooks {
|
|
|
67
68
|
constructor(file) {
|
|
68
69
|
this.file = file;
|
|
69
70
|
}
|
|
71
|
+
/** As kept; one there but not readable is refused (2026-11-19), so an addition never writes the others over. */
|
|
70
72
|
async read() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return data && typeof data === 'object' ? data : {};
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
73
|
+
const data = await readStoreJson(this.file);
|
|
74
|
+
return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
78
75
|
}
|
|
76
|
+
/** Not readable: not trusted, so the hook is asked about again. */
|
|
79
77
|
async has(top, path, sha) {
|
|
80
|
-
return !!sha && (await this.read())[repoKey(top)]?.[path] === sha;
|
|
78
|
+
return !!sha && (await this.read().catch(() => ({})))[repoKey(top)]?.[path] === sha;
|
|
81
79
|
}
|
|
82
80
|
async add(top, hooks) {
|
|
83
81
|
if (hooks.length === 0)
|
|
@@ -88,7 +86,8 @@ export class TrustedHooks {
|
|
|
88
86
|
mine[h.path] = h.sha;
|
|
89
87
|
all[repoKey(top)] = mine;
|
|
90
88
|
await mkdir(dirname(this.file), { recursive: true });
|
|
91
|
-
|
|
89
|
+
// Through a temporary file and a rename, retried as Windows needs (2026-11-19): written in place, a crash left it cut.
|
|
90
|
+
await writeFileAtomically(this.file, `${JSON.stringify(all, null, 2)}\n`);
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
/** The repository's top folder, or null when the folder is not in one. */
|
|
@@ -303,11 +303,16 @@ export function referenceNote(projects, workDir) {
|
|
|
303
303
|
...projects.map((p) => `- ${p.name}: ${p.dir}`),
|
|
304
304
|
].join('\n');
|
|
305
305
|
}
|
|
306
|
-
/**
|
|
307
|
-
|
|
306
|
+
/**
|
|
307
|
+
* What the chat is told after a step changed a project for reference. `by`: what changed it, when not the last step — the
|
|
308
|
+
* task's checks (third hunt, 2026-11-20), which leave no rest of the round to skip.
|
|
309
|
+
*/
|
|
310
|
+
export function referenceMessage(changes, by) {
|
|
311
|
+
const who = by === 'checks' ? 'The checks just run' : 'The last step';
|
|
312
|
+
const rest = by === 'checks' ? '' : ' and did not run the rest of the round';
|
|
308
313
|
return changes
|
|
309
314
|
.map((c) => c.putBack
|
|
310
|
-
?
|
|
311
|
-
:
|
|
315
|
+
? `${who} changed ${c.name} (${c.dir}), which is for reference only: ${describeChange(c)}. The runner put it back as it was${rest}. Change nothing there; if the work needs a change in it, say so in "notes".`
|
|
316
|
+
: `${who} changed ${c.name} (${c.dir}), which is for reference only: ${describeChange(c)}. The runner could not put all of it back (${c.problem ?? 'no reason given'}); the operator has been told. Change nothing there.`)
|
|
312
317
|
.join('\n\n');
|
|
313
318
|
}
|