copilot-operator 0.1.88 → 0.1.90
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/operator.controller.js +66 -3
- package/dist/src/api/operator.service.js +141 -0
- package/dist/src/api/server.js +5 -1
- package/dist/src/cli.js +6 -0
- package/dist/src/config/live.js +1 -1
- package/dist/src/config/schema.js +12 -0
- package/dist/src/orchestrator/taskRunner.js +9 -2
- package/dist/src/plan/systemGuide.js +158 -0
- package/dist/src/session/locatorFailures.js +55 -0
- package/dist/src/transport/copilotTransport.js +310 -65
- package/dist/src/transport/keptWindow.js +3 -0
- package/dist/src/transport/locators.js +126 -5
- package/dist/src/transport/pageHtml.js +62 -0
- package/dist/web/404.html +2 -2
- package/dist/web/_next/static/chunks/{1077.26ca37faa3726fff.js → 1077.1cc6d439e3dd0fa9.js} +1 -1
- package/dist/web/_next/static/chunks/{1548.f5790cd11a91309f.js → 1548.3de9dc874e47558e.js} +1 -1
- package/dist/web/_next/static/chunks/{2163.aa9d9b82fcde6caa.js → 2163.66458fb9c54fb52d.js} +1 -1
- package/dist/web/_next/static/chunks/{714.b7dbce98ba0b59a8.js → 714.cffed2b87154be0f.js} +1 -1
- package/dist/web/_next/static/chunks/{7220.0ca53eefec5d01ea.js → 7220.30b6a3e1bd41e51a.js} +1 -1
- package/dist/web/_next/static/chunks/7921-d3a4a261e08950e0.js +1 -0
- package/dist/web/_next/static/chunks/{8584.9f3b058a8f67d3d7.js → 8584.36422ed19d6c43e9.js} +1 -1
- package/dist/web/_next/static/chunks/{9067.107f6164157e0aa1.js → 9067.e579f97591576de2.js} +1 -1
- package/dist/web/_next/static/chunks/{9747.984a86f70f9cd973.js → 9747.11247f0e21542f6d.js} +1 -1
- package/dist/web/_next/static/chunks/app/layout-7b5fa7c74ecd6939.js +1 -0
- package/dist/web/_next/static/chunks/app/queue/{page-317151444eda8115.js → page-7909ba7c9e3d4c2d.js} +1 -1
- package/dist/web/_next/static/chunks/app/settings/page-7651920337bbb580.js +1 -0
- package/dist/web/_next/static/chunks/{webpack-c015bbeb103c0856.js → webpack-78ec62098b09e4a0.js} +1 -1
- package/dist/web/_next/static/css/{0c5d6d5914aa3824.css → d74aa18c98dacdb4.css} +1 -1
- package/dist/web/defaults.html +2 -2
- package/dist/web/defaults.txt +8 -8
- package/dist/web/index.html +3 -3
- package/dist/web/index.txt +9 -9
- package/dist/web/queue.html +2 -2
- package/dist/web/queue.txt +9 -9
- package/dist/web/settings.html +2 -2
- package/dist/web/settings.txt +9 -9
- package/dist/web/system.html +2 -2
- package/dist/web/system.txt +9 -9
- package/package.json +3 -2
- package/dist/web/_next/static/chunks/7921-8f6503aba840928a.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-127e5af1ebf21876.js +0 -1
- package/dist/web/_next/static/chunks/app/settings/page-95069cb94d79e909.js +0 -1
- /package/dist/web/_next/static/{hLBBsG7Kn4vd0p_J-47BJ → 3VkK1sxEugkae88HSFR-i}/_buildManifest.js +0 -0
- /package/dist/web/_next/static/{hLBBsG7Kn4vd0p_J-47BJ → 3VkK1sxEugkae88HSFR-i}/_ssgManifest.js +0 -0
|
@@ -19,13 +19,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
19
19
|
* What is here is what the chat and its workbench use, with Settings and Kerrigan (2026-10-20: the sessions, the task
|
|
20
20
|
* register and the plan from JSON were removed, and their routes with them).
|
|
21
21
|
*/
|
|
22
|
-
import { Body, Controller, Get, Inject, Param, Post, Put, Query, Res, NotFoundException, BadRequestException, ConflictException } from '@nestjs/common';
|
|
22
|
+
import { Body, Controller, Delete, Get, Inject, Param, Post, Put, Query, Res, NotFoundException, BadRequestException, ConflictException } from '@nestjs/common';
|
|
23
23
|
import { OperatorService } from './operator.service.js';
|
|
24
24
|
import { SettingsUnusableError } from './settings.js';
|
|
25
25
|
import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
|
|
26
26
|
import { CHANGED_ON_DISK } from '../session/workspace.js';
|
|
27
27
|
import { join } from 'node:path';
|
|
28
|
-
import { DefaultPickerLocators } from '../transport/locators.js';
|
|
28
|
+
import { DefaultChatLocators, DefaultPickerLocators } from '../transport/locators.js';
|
|
29
29
|
import { platformTools } from '../exec/platforms.js';
|
|
30
30
|
import { readOnlyCapable } from '../exec/readOnly.js';
|
|
31
31
|
function fail(e) {
|
|
@@ -101,7 +101,9 @@ let OperatorController = class OperatorController {
|
|
|
101
101
|
const programs = { platforms: platformTools(), readOnly: readOnlyCapable(), inForce: resolved.execution.allowedPrograms };
|
|
102
102
|
// The scripts the bot may run, as in force (2026-10-27): a lock may have emptied the boxes for its own.
|
|
103
103
|
const scripts = { inForce: resolved.execution.scripts, writtenScripts: resolved.execution.writtenScripts };
|
|
104
|
-
|
|
104
|
+
// The chat page's own locators (2026-11-17): their defaults, which Settings shows and puts back.
|
|
105
|
+
const chat = { defaults: DefaultChatLocators };
|
|
106
|
+
return { raw, defaults, resolved: resolved.resolved, picker, chat, programs, scripts };
|
|
105
107
|
}
|
|
106
108
|
/** Saved, and taken at once by the work going on where it can be (2026-11-03): the answer says what was, and what waits. */
|
|
107
109
|
async saveSettings(body) {
|
|
@@ -177,6 +179,40 @@ let OperatorController = class OperatorController {
|
|
|
177
179
|
startFailures(unanswered) {
|
|
178
180
|
return this.ops.recentStartFailures(unanswered === '1' || unanswered === 'true');
|
|
179
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* The chat's locators that found nothing where the bot needed them (2026-11-17): the last time for each, whether it
|
|
184
|
+
* has been changed in Settings since, and the text for a chatbot. Read by the banner on every page and by Settings.
|
|
185
|
+
*/
|
|
186
|
+
locatorFailures() {
|
|
187
|
+
return this.ops.listLocatorFailures();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The page's HTML kept with one, to hand to a chatbot. Always a download, never a page of this origin: what the page
|
|
191
|
+
* held is not this program's, however much of it was taken out.
|
|
192
|
+
*/
|
|
193
|
+
async locatorFailureHtml(key, res) {
|
|
194
|
+
try {
|
|
195
|
+
const { fileName, content } = await this.ops.locatorFailureHtml(key);
|
|
196
|
+
res.type('application/octet-stream');
|
|
197
|
+
res.setHeader('content-disposition', contentDisposition(fileName));
|
|
198
|
+
res.setHeader('x-content-type-options', 'nosniff');
|
|
199
|
+
res.send(Buffer.from(content, 'utf8'));
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
failText(res, e);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* "Check the locators" (2026-11-17): the Copilot window opened, each of the chat's locators looked for, and what each
|
|
207
|
+
* found. Takes as long as the window takes to open, a sign-in included.
|
|
208
|
+
*/
|
|
209
|
+
checkLocators() {
|
|
210
|
+
return this.ops.checkLocators().catch(fail);
|
|
211
|
+
}
|
|
212
|
+
/** Closed by the operator: its banner and its red go. */
|
|
213
|
+
async dismissLocatorFailure(key) {
|
|
214
|
+
return { dismissed: await this.ops.locatorFailures.dismiss(key) };
|
|
215
|
+
}
|
|
180
216
|
/** One of them as a text file: the error, where it stopped, the run's record, the events and the console. */
|
|
181
217
|
async startFailureReport(id, res) {
|
|
182
218
|
try {
|
|
@@ -667,6 +703,33 @@ __decorate([
|
|
|
667
703
|
__metadata("design:paramtypes", [String]),
|
|
668
704
|
__metadata("design:returntype", Object)
|
|
669
705
|
], OperatorController.prototype, "startFailures", null);
|
|
706
|
+
__decorate([
|
|
707
|
+
Get('locators/failures'),
|
|
708
|
+
__metadata("design:type", Function),
|
|
709
|
+
__metadata("design:paramtypes", []),
|
|
710
|
+
__metadata("design:returntype", Promise)
|
|
711
|
+
], OperatorController.prototype, "locatorFailures", null);
|
|
712
|
+
__decorate([
|
|
713
|
+
Get('locators/failures/:key/html'),
|
|
714
|
+
__param(0, Param('key')),
|
|
715
|
+
__param(1, Res()),
|
|
716
|
+
__metadata("design:type", Function),
|
|
717
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
718
|
+
__metadata("design:returntype", Promise)
|
|
719
|
+
], OperatorController.prototype, "locatorFailureHtml", null);
|
|
720
|
+
__decorate([
|
|
721
|
+
Post('locators/check'),
|
|
722
|
+
__metadata("design:type", Function),
|
|
723
|
+
__metadata("design:paramtypes", []),
|
|
724
|
+
__metadata("design:returntype", Promise)
|
|
725
|
+
], OperatorController.prototype, "checkLocators", null);
|
|
726
|
+
__decorate([
|
|
727
|
+
Delete('locators/failures/:key'),
|
|
728
|
+
__param(0, Param('key')),
|
|
729
|
+
__metadata("design:type", Function),
|
|
730
|
+
__metadata("design:paramtypes", [String]),
|
|
731
|
+
__metadata("design:returntype", Promise)
|
|
732
|
+
], OperatorController.prototype, "dismissLocatorFailure", null);
|
|
670
733
|
__decorate([
|
|
671
734
|
Get('start/failures/:id/report'),
|
|
672
735
|
__param(0, Param('id')),
|
|
@@ -15,6 +15,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
15
15
|
import { pageModelFor, sameModel } from '../transport/modelMatch.js';
|
|
16
16
|
import { Injectable } from '@nestjs/common';
|
|
17
17
|
import { existsSync } from 'node:fs';
|
|
18
|
+
import { isAbsolute, relative } from 'node:path';
|
|
19
|
+
import { readFile as readFileText } from 'node:fs/promises';
|
|
20
|
+
import { LocatorFailures } from '../session/locatorFailures.js';
|
|
21
|
+
import { CHAT_LOCATOR_KEYS, locatorPrompt, resolveChatLocators } from '../transport/locators.js';
|
|
22
|
+
import { LocatorMissing } from '../transport/copilotTransport.js';
|
|
18
23
|
import { readFile } from 'node:fs/promises';
|
|
19
24
|
import { join, resolve } from 'node:path';
|
|
20
25
|
import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
|
|
@@ -150,6 +155,14 @@ function browserRefusal(held, ask) {
|
|
|
150
155
|
}
|
|
151
156
|
if (ask.kind === 'login')
|
|
152
157
|
return loginWhileBusy;
|
|
158
|
+
// "Check the locators" (2026-11-17) holds the browser for the moment it looks.
|
|
159
|
+
if (held.kind === 'locators') {
|
|
160
|
+
return ask.kind === 'locators'
|
|
161
|
+
? 'The locators are already being checked.'
|
|
162
|
+
: "the chat's locators are being checked in the browser; start this once that has finished";
|
|
163
|
+
}
|
|
164
|
+
if (ask.kind === 'locators')
|
|
165
|
+
return 'The browser profile is in use right now (a run, or a reading of the models). Check the locators once it has finished.';
|
|
153
166
|
if (held.kind === 'models') {
|
|
154
167
|
return ask.kind === 'models'
|
|
155
168
|
? 'The model list is already being read.'
|
|
@@ -187,6 +200,8 @@ let OperatorService = class OperatorService {
|
|
|
187
200
|
layout = installLayout();
|
|
188
201
|
projectRoot = this.layout.projectRoot;
|
|
189
202
|
dataDir = this.layout.dataDir;
|
|
203
|
+
/** The chat's locators that found nothing, the last time for each (2026-11-17): the banner's and Settings' red fields. */
|
|
204
|
+
locatorFailures = new LocatorFailures(join(this.layout.dataDir, 'locator-failures.json'));
|
|
190
205
|
settings = settingsOf(this.layout);
|
|
191
206
|
store = new SessionStore(this.dataDir, join(this.layout.promptsDir, 'level1.md'));
|
|
192
207
|
bus = new EventBus();
|
|
@@ -208,6 +223,9 @@ let OperatorService = class OperatorService {
|
|
|
208
223
|
followsActing = this.bus.subscribe('*', (e) => {
|
|
209
224
|
if (e.type === 'acting' && e.data)
|
|
210
225
|
this.acting.set(e.sessionId, e.data);
|
|
226
|
+
// A chat locator that found nothing (2026-11-17): kept for the banner and Settings.
|
|
227
|
+
else if (e.type === 'browser:locator-missing' && e.data)
|
|
228
|
+
this.recordLocatorFailure(e.data);
|
|
211
229
|
else if (e.type === 'browser:sign-in-required' || e.type === 'browser:verification-required') {
|
|
212
230
|
// The Copilot window waits for the operator to sign in, or to show a person is there: not counted (2026-10-29).
|
|
213
231
|
this.holdOf(e.sessionId)?.waitFor(`${e.type}:${e.sessionId}`);
|
|
@@ -866,6 +884,65 @@ let OperatorService = class OperatorService {
|
|
|
866
884
|
* One of them as a file: what failed and where, the run's record, the sessions' events from the press,
|
|
867
885
|
* and the console lines from the press to a few seconds after — secret-shaped text taken out.
|
|
868
886
|
*/
|
|
887
|
+
/**
|
|
888
|
+
* A chat locator that found nothing where the bot needed it (the transport's `locator-missing`, operator 2026-11-17:
|
|
889
|
+
* "a mechanism that detects which locator exactly the bot failed on"): kept as the last one for that locator, for the
|
|
890
|
+
* banner on every page and the field in red in Settings.
|
|
891
|
+
*/
|
|
892
|
+
recordLocatorFailure(detail) {
|
|
893
|
+
const key = detail.key;
|
|
894
|
+
if (typeof key !== 'string' || !CHAT_LOCATOR_KEYS.includes(key) || typeof detail.locator !== 'string')
|
|
895
|
+
return;
|
|
896
|
+
const str = (v) => (typeof v === 'string' && v ? v : undefined);
|
|
897
|
+
const html = str(detail.html);
|
|
898
|
+
const picture = str(detail.picture);
|
|
899
|
+
const url = str(detail.url);
|
|
900
|
+
void this.locatorFailures
|
|
901
|
+
.record({
|
|
902
|
+
key: key,
|
|
903
|
+
locator: detail.locator,
|
|
904
|
+
at: new Date().toISOString(),
|
|
905
|
+
why: str(detail.why) ?? '',
|
|
906
|
+
stopped: detail.stopped !== false,
|
|
907
|
+
...(html ? { html } : {}),
|
|
908
|
+
...(picture ? { picture } : {}),
|
|
909
|
+
...(url ? { url } : {}),
|
|
910
|
+
})
|
|
911
|
+
.catch(() => undefined);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* The failures kept, each with whether its locator has been changed in Settings since (then it is no longer the one
|
|
915
|
+
* that found nothing, and the banner and the red go), whether its HTML is there to download, and the text for a
|
|
916
|
+
* chatbot. The files' places are not given out: the HTML is downloaded through the API.
|
|
917
|
+
*/
|
|
918
|
+
async listLocatorFailures() {
|
|
919
|
+
const cfg = await this.settings.load();
|
|
920
|
+
const inForce = resolveChatLocators(cfg.copilot.chatLocators).locators;
|
|
921
|
+
return (await this.locatorFailures.list()).map(({ html, picture: _picture, ...f }) => ({
|
|
922
|
+
...f,
|
|
923
|
+
html: !!html && existsSync(html),
|
|
924
|
+
changed: inForce[f.key] !== f.locator,
|
|
925
|
+
prompt: locatorPrompt(f.key, f.locator),
|
|
926
|
+
}));
|
|
927
|
+
}
|
|
928
|
+
/** The page's HTML kept with a failure, to download: only a file in the bot's runs folder. */
|
|
929
|
+
async locatorFailureHtml(key) {
|
|
930
|
+
const f = await this.locatorFailures.get(key);
|
|
931
|
+
if (!f?.html)
|
|
932
|
+
throw new Error(`No HTML is kept for the "${key}" locator.`);
|
|
933
|
+
const cfg = await this.settings.load();
|
|
934
|
+
const runs = resolve(cfg.resolved.runsDir);
|
|
935
|
+
const file = resolve(f.html);
|
|
936
|
+
const inside = relative(runs, file);
|
|
937
|
+
if (!inside || inside.startsWith('..') || isAbsolute(inside)) {
|
|
938
|
+
throw new Error(`The HTML kept for the "${key}" locator is not in the bot's runs folder.`);
|
|
939
|
+
}
|
|
940
|
+
const content = await readFileText(file, 'utf8').catch(() => {
|
|
941
|
+
throw new Error(`The HTML kept for the "${key}" locator is gone (${file}).`);
|
|
942
|
+
});
|
|
943
|
+
const stamp = f.at.replace(/[-:]/g, '').replace('T', '-').slice(0, 15);
|
|
944
|
+
return { fileName: `copilot-page-${key}-${stamp}.html`, content };
|
|
945
|
+
}
|
|
869
946
|
async startFailureReport(id) {
|
|
870
947
|
await this.init();
|
|
871
948
|
const f = this.startFailures.get(id);
|
|
@@ -3214,6 +3291,12 @@ let OperatorService = class OperatorService {
|
|
|
3214
3291
|
await this.init();
|
|
3215
3292
|
const cfg = await this.settings.load();
|
|
3216
3293
|
transport = createTransport({
|
|
3294
|
+
// The box to write in by Settings' locator (2026-11-17): the sign-in ends when it shows; one that finds nothing is kept.
|
|
3295
|
+
...(cfg.copilot.chatLocators ? { chatLocators: cfg.copilot.chatLocators } : {}),
|
|
3296
|
+
onEvent: (event, detail) => {
|
|
3297
|
+
if (event === 'locator-missing' && detail)
|
|
3298
|
+
this.recordLocatorFailure(detail);
|
|
3299
|
+
},
|
|
3217
3300
|
profileDir: cfg.resolved.profileDir,
|
|
3218
3301
|
transportDir: join(cfg.resolved.runsDir, '_login'),
|
|
3219
3302
|
chatUrl: cfg.copilot.url,
|
|
@@ -3283,6 +3366,10 @@ let OperatorService = class OperatorService {
|
|
|
3283
3366
|
keepFailurePage: cfg.copilot.keepFailurePage,
|
|
3284
3367
|
// The rows' locator reads the names (Settings' own, 2026-10-24).
|
|
3285
3368
|
...pickerOptions(cfg),
|
|
3369
|
+
onEvent: (event, detail) => {
|
|
3370
|
+
if (event === 'locator-missing' && detail)
|
|
3371
|
+
this.recordLocatorFailure(detail);
|
|
3372
|
+
},
|
|
3286
3373
|
});
|
|
3287
3374
|
await this.closeChatWindow('reading the models needs the browser');
|
|
3288
3375
|
await transport.open();
|
|
@@ -3315,6 +3402,60 @@ let OperatorService = class OperatorService {
|
|
|
3315
3402
|
this.releaseBrowser(claim.holder);
|
|
3316
3403
|
}
|
|
3317
3404
|
}
|
|
3405
|
+
/**
|
|
3406
|
+
* "Check the locators" (operator, 2026-11-17): the Copilot window opened as for reading the models, each of the chat's
|
|
3407
|
+
* locators looked for (`checkLocators`, which only reads and looks), and the window closed. One that found nothing is
|
|
3408
|
+
* kept as a failure (its field red, its HTML kept); one found whose failure is still kept has it taken away: it works
|
|
3409
|
+
* again. The box itself not found: the chat did not open, said for the box, the others not looked for.
|
|
3410
|
+
*/
|
|
3411
|
+
async checkLocators() {
|
|
3412
|
+
const claim = this.claimBrowser({ kind: 'locators' });
|
|
3413
|
+
if ('refused' in claim)
|
|
3414
|
+
throw new Error(claim.refused);
|
|
3415
|
+
let transport = null;
|
|
3416
|
+
try {
|
|
3417
|
+
await this.init();
|
|
3418
|
+
const cfg = await this.settings.load();
|
|
3419
|
+
transport = createTransport({
|
|
3420
|
+
profileDir: cfg.resolved.profileDir,
|
|
3421
|
+
transportDir: join(cfg.resolved.runsDir, '_locators'),
|
|
3422
|
+
chatUrl: cfg.copilot.url,
|
|
3423
|
+
channel: cfg.copilot.channel,
|
|
3424
|
+
headless: cfg.copilot.headless,
|
|
3425
|
+
replyTimeoutMs: cfg.copilot.replyTimeoutSec * 1000,
|
|
3426
|
+
signInTimeoutMs: cfg.copilot.signInTimeoutSec * 1000,
|
|
3427
|
+
humanWaitMs: cfg.copilot.humanWaitSec * 1000,
|
|
3428
|
+
keepFailurePage: cfg.copilot.keepFailurePage,
|
|
3429
|
+
...pickerOptions(cfg),
|
|
3430
|
+
onEvent: (event, detail) => {
|
|
3431
|
+
if (event === 'locator-missing' && detail)
|
|
3432
|
+
this.recordLocatorFailure(detail);
|
|
3433
|
+
},
|
|
3434
|
+
});
|
|
3435
|
+
await this.closeChatWindow('checking the locators needs the browser');
|
|
3436
|
+
await transport.open();
|
|
3437
|
+
let results;
|
|
3438
|
+
try {
|
|
3439
|
+
await transport.ensureSignedIn();
|
|
3440
|
+
results = await transport.checkLocators();
|
|
3441
|
+
}
|
|
3442
|
+
catch (e) {
|
|
3443
|
+
if (!(e instanceof LocatorMissing) || e.key !== 'composer')
|
|
3444
|
+
throw e;
|
|
3445
|
+
results = CHAT_LOCATOR_KEYS.map((key) => (key === 'composer' ? { key, status: 'none', count: 0 } : { key, status: 'not-here', count: 0, note: 'noChat' }));
|
|
3446
|
+
}
|
|
3447
|
+
// Found now: no longer a failure, whatever was kept.
|
|
3448
|
+
const kept = await this.locatorFailures.list();
|
|
3449
|
+
for (const r of results)
|
|
3450
|
+
if (r.status === 'found' && kept.some((f) => f.key === r.key))
|
|
3451
|
+
await this.locatorFailures.dismiss(r.key);
|
|
3452
|
+
return { checkedAt: new Date().toISOString(), results };
|
|
3453
|
+
}
|
|
3454
|
+
finally {
|
|
3455
|
+
await transport?.close().catch(() => undefined);
|
|
3456
|
+
this.releaseBrowser(claim.holder);
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3318
3459
|
// --- the registry ---------------------------------------------------------------------
|
|
3319
3460
|
// --- environment ----------------------------------------------------------------------
|
|
3320
3461
|
/** Opens the machine's own folder dialog and reports what was picked. */
|
package/dist/src/api/server.js
CHANGED
|
@@ -149,7 +149,11 @@ export async function startApi(opts = {}) {
|
|
|
149
149
|
await app.close();
|
|
150
150
|
throw e;
|
|
151
151
|
});
|
|
152
|
-
|
|
152
|
+
// A port that cannot be taken (in use, or reserved by Windows: EACCES) closes what was opened, so a caller can try another.
|
|
153
|
+
await app.listen(PORT, '127.0.0.1').catch(async (e) => {
|
|
154
|
+
await app.close().catch(() => undefined);
|
|
155
|
+
throw e;
|
|
156
|
+
});
|
|
153
157
|
// Close whatever the previous process left open before anyone can look at it, rather than
|
|
154
158
|
// waiting for the first request to trigger it.
|
|
155
159
|
await ops.bootstrap();
|
package/dist/src/cli.js
CHANGED
|
@@ -126,7 +126,10 @@ program
|
|
|
126
126
|
console.log('No existing profile to delete.');
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
// The box to write in by Settings' locator (2026-11-17): the sign-in ends when it shows.
|
|
130
|
+
const saved = await settingsOf(installLayout()).load().catch(() => null);
|
|
129
131
|
const transport = new CopilotTransport({
|
|
132
|
+
...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
|
|
130
133
|
profileDir: opts.profile,
|
|
131
134
|
transportDir: join(opts.profile, '_transport'),
|
|
132
135
|
chatUrl: opts.url,
|
|
@@ -187,7 +190,9 @@ program
|
|
|
187
190
|
.option('-p, --profile <dir>', 'profile directory', DEFAULT_PROFILE)
|
|
188
191
|
.option('--url <url>', 'chat url', Url.chat)
|
|
189
192
|
.action(async (opts) => {
|
|
193
|
+
const saved = await settingsOf(installLayout()).load().catch(() => null);
|
|
190
194
|
const transport = new CopilotTransport({
|
|
195
|
+
...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
|
|
191
196
|
profileDir: opts.profile,
|
|
192
197
|
transportDir: join(opts.profile, '_transport'),
|
|
193
198
|
chatUrl: opts.url,
|
|
@@ -392,6 +397,7 @@ program
|
|
|
392
397
|
const saved = await settingsOf(installLayout()).load().catch(() => null);
|
|
393
398
|
const transport = new CopilotTransport({
|
|
394
399
|
...(saved?.copilot.pickerLocators ? { pickerLocators: saved.copilot.pickerLocators } : {}),
|
|
400
|
+
...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
|
|
395
401
|
profileDir: opts.profile,
|
|
396
402
|
transportDir: join(installLayout().runsDir, '_models'),
|
|
397
403
|
chatUrl: opts.url,
|
package/dist/src/config/live.js
CHANGED
|
@@ -36,7 +36,7 @@ const NOT_NOW = {
|
|
|
36
36
|
};
|
|
37
37
|
/** What the chat window was opened with. */
|
|
38
38
|
const WINDOW = {
|
|
39
|
-
copilot: ['url', 'profileDir', 'channel', 'headless', 'replyTimeoutSec', 'signInTimeoutSec', 'humanWaitSec', 'keepFailurePage', 'pickerLocators', 'pickerSteps'],
|
|
39
|
+
copilot: ['url', 'profileDir', 'channel', 'headless', 'replyTimeoutSec', 'signInTimeoutSec', 'humanWaitSec', 'keepFailurePage', 'pickerLocators', 'chatLocators', 'pickerSteps'],
|
|
40
40
|
};
|
|
41
41
|
/** The sections a run compares; the rest (where the bot keeps its records) is read when the bot starts. */
|
|
42
42
|
const SECTIONS = ['copilot', 'task', 'execution', 'report', 'project', 'skills', 'pacing', 'limits'];
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { SCRIPT_KINDS } from '../exec/scriptKinds.js';
|
|
10
|
+
import { CHAT_LOCATOR_KEYS } from '../transport/locators.js';
|
|
10
11
|
import { parse as parseYaml } from 'yaml';
|
|
11
12
|
import { readHandWritten } from './handWritten.js';
|
|
12
13
|
import { applyPolicyLock, readPolicyLocks } from './lockedPolicy.js';
|
|
@@ -169,6 +170,17 @@ export const RunConfigSchema = z.object({
|
|
|
169
170
|
providerModel: z.string().optional(),
|
|
170
171
|
})
|
|
171
172
|
.optional(),
|
|
173
|
+
/**
|
|
174
|
+
* The chat page's locators (operator, 2026-11-17: "a field in Settings to set it by hand", after the work page's
|
|
175
|
+
* box to write in changed and the start was refused as "not the Microsoft 365 Copilot chat"; then "each of the
|
|
176
|
+
* locators"): every one the bot finds the chat by. Left out, or empty, the default in `transport/locators.ts`
|
|
177
|
+
* (`DefaultChatLocators`); one that cannot be used is not, and the run says why. Taken by the next Copilot window.
|
|
178
|
+
* Made from the keys themselves: written out by hand, it kept only the box's, and a locator saved for Send was
|
|
179
|
+
* dropped when the settings were read.
|
|
180
|
+
*/
|
|
181
|
+
chatLocators: z
|
|
182
|
+
.object(Object.fromEntries(CHAT_LOCATOR_KEYS.map((k) => [k, z.string().optional()])))
|
|
183
|
+
.optional(),
|
|
172
184
|
/**
|
|
173
185
|
* A picture and the menu's HTML at every step of choosing a model, with what each locator found (operator,
|
|
174
186
|
* 2026-10-24: "an option in Settings to keep this information"), beside the run's other browser files. Off: only
|
|
@@ -457,8 +457,13 @@ export function speakFor(transport, sessionId, opts = {}) {
|
|
|
457
457
|
speaker.alone = true;
|
|
458
458
|
}
|
|
459
459
|
/** The model menu's locators and its step pictures, as Settings have them (2026-10-24), for every window that picks a model. */
|
|
460
|
+
/** The locators Settings hold for the Copilot window: the model menu's, and the chat page's own (the box to write in, 2026-11-17). */
|
|
460
461
|
export function pickerOptions(cfg) {
|
|
461
|
-
return {
|
|
462
|
+
return {
|
|
463
|
+
...(cfg.copilot.pickerLocators ? { pickerLocators: cfg.copilot.pickerLocators } : {}),
|
|
464
|
+
...(cfg.copilot.chatLocators ? { chatLocators: cfg.copilot.chatLocators } : {}),
|
|
465
|
+
...(cfg.copilot.pickerSteps ? { modelStepShots: true } : {}),
|
|
466
|
+
};
|
|
462
467
|
}
|
|
463
468
|
export async function openBrowser(cfg, bus, transportDir, sessionId,
|
|
464
469
|
/** The run's Stop: a sign-in still awaited ends with it. */
|
|
@@ -496,6 +501,8 @@ signal) {
|
|
|
496
501
|
'chat-left': `The Copilot window is no longer on this conversation (it shows ${String(detail?.found ?? 'another page')}). Going back to it before anything is sent.`,
|
|
497
502
|
'chat-returned': `Back on this conversation${detail?.signedIn ? ', after the sign-in' : ''}${detail?.by === 'name' ? ', found by its name in the sidebar' : ''}. The work goes on there.`,
|
|
498
503
|
'chat-lost': 'The conversation could not be opened again, by its address or by its name. Nothing was sent, and nothing went into another chat.',
|
|
504
|
+
// A locator of the chat that found nothing (2026-11-17): which, and where Settings has it; the API keeps it for the red field.
|
|
505
|
+
'locator-missing': `Not found on Copilot's page: the "${String(detail?.key ?? '')}" locator (${String(detail?.locator ?? '')}) found nothing ${String(detail?.why ?? '')}. ${detail?.stopped === false ? 'The work goes on without it. ' : ''}Settings → "The chat's locators" shows it in red, with the page's HTML for a chatbot to find the right one in.`,
|
|
499
506
|
// Copilot showed another of its pages, its home page, instead of the chat (2026-11-17): the chat opened from it.
|
|
500
507
|
'chat-page-elsewhere': `Copilot showed its page ${String(detail?.found ?? '')} instead of the chat; opening the chat ${detail?.by === 'link' ? "by the page's own link to it" : `at ${String(detail?.to ?? '')}`}.`,
|
|
501
508
|
};
|
|
@@ -503,7 +510,7 @@ signal) {
|
|
|
503
510
|
bus.publish({
|
|
504
511
|
sessionId: id,
|
|
505
512
|
type: `browser:${event}`,
|
|
506
|
-
level: event === 'chat-lost' ? 'error' : ['verification-required', 'reply-files-ignored', 'model-menu-stuck', 'chat-left', 'window-closed', 'window-not-reopened', 'reply-asked-again', 'message-sent-again'].includes(event) ? 'warn' : 'info',
|
|
513
|
+
level: event === 'chat-lost' || (event === 'locator-missing' && detail?.stopped !== false) ? 'error' : event === 'locator-missing' ? 'warn' : ['verification-required', 'reply-files-ignored', 'model-menu-stuck', 'chat-left', 'window-closed', 'window-not-reopened', 'reply-asked-again', 'message-sent-again'].includes(event) ? 'warn' : 'info',
|
|
507
514
|
// An event with no sentence of its own is named, not said as "undefined".
|
|
508
515
|
message: spoken[event] ?? event.replace(/-/g, ' '),
|
|
509
516
|
data: detail,
|
|
@@ -192,6 +192,45 @@ export const SYSTEM_GUIDE = [
|
|
|
192
192
|
},
|
|
193
193
|
],
|
|
194
194
|
},
|
|
195
|
+
{
|
|
196
|
+
headingKey: 'chatloc.failTitle',
|
|
197
|
+
en: 'The bot could not find "{name}" on Copilot\'s page; the work stopped',
|
|
198
|
+
bg: 'Ботът не намери „{name}“ в страницата на Copilot; работата спря',
|
|
199
|
+
controls: [
|
|
200
|
+
{
|
|
201
|
+
key: 'chatloc.fix',
|
|
202
|
+
kind: 'link',
|
|
203
|
+
en: 'Fix in Settings',
|
|
204
|
+
bg: 'Поправи в Settings',
|
|
205
|
+
doesEn: 'On every page, when a locator of the chat found nothing (2026-11-17): opens Settings → "The chat\'s locators" at that locator\'s field, in red, the cursor in it. A failure that stopped the work opens it once by itself.',
|
|
206
|
+
doesBg: 'На всяка страница, когато локатор на чата не е намерил нищо (2026-11-17): отваря Settings → „Локатори на чата“ на полето на този локатор, в червено, с курсора в него. Провал, спрял работата, го отваря веднъж сам.',
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
key: 'chatloc.html',
|
|
210
|
+
kind: 'link',
|
|
211
|
+
en: 'Download the HTML',
|
|
212
|
+
bg: 'Изтегли HTML',
|
|
213
|
+
doesEn: 'The page\'s HTML at the moment the locator found nothing, scripts, styles and the sidebar\'s conversation names taken out: the file to give a chatbot with "Copy for a chatbot", which answers with the right locator.',
|
|
214
|
+
doesBg: 'HTML-ът на страницата в момента, в който локаторът не е намерил нищо, без скриптове, стилове и имената на разговорите от страничната лента: файлът, който се дава на чатбот заедно с „Копирай за чатбот“, и той отговаря с правилния локатор.',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
key: 'chatloc.prompt',
|
|
218
|
+
kind: 'button',
|
|
219
|
+
en: 'Copy for a chatbot',
|
|
220
|
+
bg: 'Копирай за чатбот',
|
|
221
|
+
doesEn: 'Copies the text that asks a chatbot, given the HTML file, for the locator of this element: what it is, the locator that stopped finding it, and what a good locator uses.',
|
|
222
|
+
doesBg: 'Копира текста, който пита чатбот, получил HTML файла, за локатора на този елемент: какъв е, локаторът, който е спрял да го намира, и какво ползва добрият локатор.',
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
key: 'chatloc.dismiss',
|
|
226
|
+
kind: 'button',
|
|
227
|
+
en: 'Close',
|
|
228
|
+
bg: 'Затвори',
|
|
229
|
+
doesEn: 'Closes the notice of this locator, on every page and in Settings; changing the locator in Settings takes it away too.',
|
|
230
|
+
doesBg: 'Затваря съобщението за този локатор, на всяка страница и в Settings; смяната на локатора в Settings също го маха.',
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
},
|
|
195
234
|
{
|
|
196
235
|
headingKey: 'approval.waitingHere',
|
|
197
236
|
en: 'A step is waiting for your decision',
|
|
@@ -2502,6 +2541,125 @@ export const SYSTEM_GUIDE = [
|
|
|
2502
2541
|
},
|
|
2503
2542
|
],
|
|
2504
2543
|
},
|
|
2544
|
+
{
|
|
2545
|
+
headingKey: 'chatloc.title',
|
|
2546
|
+
en: "The chat's locators",
|
|
2547
|
+
bg: 'Локатори на чата',
|
|
2548
|
+
controls: [
|
|
2549
|
+
{
|
|
2550
|
+
key: 'chatloc.check',
|
|
2551
|
+
kind: 'button',
|
|
2552
|
+
en: 'Check the locators',
|
|
2553
|
+
bg: 'Провери локаторите',
|
|
2554
|
+
doesEn: 'Opens the Copilot window, as reading the models does, and looks for each locator: the box and Send, the sidebar, the newest conversation (opened by its address) and its "More" menu (opened and closed again). It only reads; nothing is sent or renamed. Under each field: found, not found (then in red, with the page\'s HTML), or not on the page then and why.',
|
|
2555
|
+
doesBg: 'Отваря прозореца на Copilot, както при четенето на моделите, и търси всеки локатор: полето и Send, страничната лента, най-новия разговор (отворен по адреса му) и менюто му „More“ (отворено и затворено отново). Само чете; нищо не се изпраща и не се преименува. Под всяко поле: намерен, ненамерен (тогава в червено, с HTML-а на страницата) или не беше на страницата тогава и защо.',
|
|
2556
|
+
},
|
|
2557
|
+
{
|
|
2558
|
+
key: 'chatloc.composer',
|
|
2559
|
+
kind: 'field',
|
|
2560
|
+
en: 'Box to write in',
|
|
2561
|
+
bg: 'Поле за писане',
|
|
2562
|
+
doesEn: 'How the bot finds the box it writes its messages in (2026-11-17): a CSS selector, or an XPath starting with /; empty is the default, which finds the box of before November 2026 and the one of 17 November 2026. A locator of an element around the box works too. When a start is refused as "not the Microsoft 365 Copilot chat" and its picture shows the chat, this is the one to change. The next Copilot window takes it.',
|
|
2563
|
+
doesBg: 'Как ботът намира полето, в което пише съобщенията си (2026-11-17): CSS селектор или XPath, започващ с /; празно е стойността по подразбиране, която намира полето отпреди ноември 2026 и това от 17 ноември 2026. Става и локатор на елемент около полето. Когато стартът е отказан с „not the Microsoft 365 Copilot chat“, а снимката му показва чата, сменя се този. Важи от следващия прозорец на Copilot.',
|
|
2564
|
+
},
|
|
2565
|
+
{
|
|
2566
|
+
key: 'chatloc.howTitle',
|
|
2567
|
+
kind: 'disclosure',
|
|
2568
|
+
en: 'How to find the right locator',
|
|
2569
|
+
bg: 'Как да намерите правилния локатор',
|
|
2570
|
+
doesEn: 'Opens the steps: download the page\'s HTML, give it to a chatbot with the text "Copy for a chatbot", put the locator it answers in the field in red; or by hand, with Inspect and Ctrl+F.',
|
|
2571
|
+
doesBg: 'Отваря стъпките: изтеглете HTML-а на страницата, дайте го на чатбот с текста от „Копирай за чатбот“, сложете локатора, който върне, в полето в червено; или на ръка, с Inspect и Ctrl+F.',
|
|
2572
|
+
},
|
|
2573
|
+
{
|
|
2574
|
+
key: 'chatloc.send',
|
|
2575
|
+
kind: 'field',
|
|
2576
|
+
en: 'Send button',
|
|
2577
|
+
bg: 'Бутон Send',
|
|
2578
|
+
doesEn: 'How the bot finds the button that sends the message; empty is the default, the button named "Send" in the box\'s wrapper.',
|
|
2579
|
+
doesBg: 'Как ботът намира бутона, който изпраща съобщението; празно е стойността по подразбиране — бутонът с име „Send“ в обвивката на полето.',
|
|
2580
|
+
},
|
|
2581
|
+
{
|
|
2582
|
+
key: 'chatloc.userMessage',
|
|
2583
|
+
kind: 'field',
|
|
2584
|
+
en: 'Your message in the conversation',
|
|
2585
|
+
bg: 'Вашето съобщение в разговора',
|
|
2586
|
+
doesEn: 'How the bot finds the messages it sent in the conversation, to know one arrived; empty is the default, [id^="user-message-"].',
|
|
2587
|
+
doesBg: 'Как ботът намира изпратените от него съобщения в разговора, за да разбере, че са пристигнали; празно е стойността по подразбиране, [id^="user-message-"].',
|
|
2588
|
+
},
|
|
2589
|
+
{
|
|
2590
|
+
key: 'chatloc.turn',
|
|
2591
|
+
kind: 'field',
|
|
2592
|
+
en: 'Messages of the conversation',
|
|
2593
|
+
bg: 'Съобщенията в разговора',
|
|
2594
|
+
doesEn: 'How the bot finds each message of the conversation, to count them; empty is the default.',
|
|
2595
|
+
doesBg: 'Как ботът намира всяко съобщение в разговора, за да ги брои; празно е стойността по подразбиране.',
|
|
2596
|
+
},
|
|
2597
|
+
{
|
|
2598
|
+
key: 'chatloc.answer',
|
|
2599
|
+
kind: 'field',
|
|
2600
|
+
en: 'Copilot\'s answer',
|
|
2601
|
+
bg: 'Отговорът на Copilot',
|
|
2602
|
+
doesEn: 'How the bot finds each of Copilot\'s answers, with its toolbar; empty is the default.',
|
|
2603
|
+
doesBg: 'Как ботът намира всеки отговор на Copilot, с лентата му; празно е стойността по подразбиране.',
|
|
2604
|
+
},
|
|
2605
|
+
{
|
|
2606
|
+
key: 'chatloc.copy',
|
|
2607
|
+
kind: 'field',
|
|
2608
|
+
en: 'Copy button of the answer',
|
|
2609
|
+
bg: 'Бутон Copy на отговора',
|
|
2610
|
+
doesEn: 'How the bot finds the Copy button inside the answer, through which it takes the answer; empty is the default.',
|
|
2611
|
+
doesBg: 'Как ботът намира бутона Copy в отговора, през който взема отговора; празно е стойността по подразбиране.',
|
|
2612
|
+
},
|
|
2613
|
+
{
|
|
2614
|
+
key: 'chatloc.stop',
|
|
2615
|
+
kind: 'field',
|
|
2616
|
+
en: 'Stop button',
|
|
2617
|
+
bg: 'Бутон Stop',
|
|
2618
|
+
doesEn: 'How the bot finds the button shown while Copilot is still writing; empty is the default.',
|
|
2619
|
+
doesBg: 'Как ботът намира бутона, който се вижда, докато Copilot още пише; празно е стойността по подразбиране.',
|
|
2620
|
+
},
|
|
2621
|
+
{
|
|
2622
|
+
key: 'chatloc.conversationLink',
|
|
2623
|
+
kind: 'field',
|
|
2624
|
+
en: 'A conversation in the sidebar',
|
|
2625
|
+
bg: 'Разговор в страничната лента',
|
|
2626
|
+
doesEn: 'How the bot finds a conversation\'s link in the sidebar, to name it or open it again by its name; empty is the default.',
|
|
2627
|
+
doesBg: 'Как ботът намира връзката към разговор в страничната лента, за да го кръсти или отвори отново по името му; празно е стойността по подразбиране.',
|
|
2628
|
+
},
|
|
2629
|
+
{
|
|
2630
|
+
key: 'chatloc.chatMore',
|
|
2631
|
+
kind: 'field',
|
|
2632
|
+
en: '"More" button of a conversation',
|
|
2633
|
+
bg: 'Бутон „More“ на разговор',
|
|
2634
|
+
doesEn: 'How the bot finds a conversation\'s "More" button in the sidebar; {$chat_id} is where the conversation\'s id goes; empty is the default.',
|
|
2635
|
+
doesBg: 'Как ботът намира бутона „More“ на разговор в страничната лента; {$chat_id} е мястото на id-то на разговора; празно е стойността по подразбиране.',
|
|
2636
|
+
},
|
|
2637
|
+
{
|
|
2638
|
+
key: 'chatloc.renameItem',
|
|
2639
|
+
kind: 'field',
|
|
2640
|
+
en: '"Rename" in that menu',
|
|
2641
|
+
bg: '„Rename“ в това меню',
|
|
2642
|
+
doesEn: 'How the bot finds "Rename" in a conversation\'s menu; empty is the default.',
|
|
2643
|
+
doesBg: 'Как ботът намира „Rename“ в менюто на разговор; празно е стойността по подразбиране.',
|
|
2644
|
+
},
|
|
2645
|
+
{
|
|
2646
|
+
key: 'chatloc.renameInput',
|
|
2647
|
+
kind: 'field',
|
|
2648
|
+
en: 'The name field of the rename dialog',
|
|
2649
|
+
bg: 'Полето за име в прозореца за преименуване',
|
|
2650
|
+
doesEn: 'How the bot finds the field the new name is written in; empty is the default.',
|
|
2651
|
+
doesBg: 'Как ботът намира полето, в което се пише новото име; празно е стойността по подразбиране.',
|
|
2652
|
+
},
|
|
2653
|
+
{
|
|
2654
|
+
key: 'chatloc.renameSave',
|
|
2655
|
+
kind: 'field',
|
|
2656
|
+
en: '"Save" of the rename dialog',
|
|
2657
|
+
bg: '„Save“ в прозореца за преименуване',
|
|
2658
|
+
doesEn: 'How the bot finds the button that saves the new name; empty is the default.',
|
|
2659
|
+
doesBg: 'Как ботът намира бутона, който записва новото име; празно е стойността по подразбиране.',
|
|
2660
|
+
},
|
|
2661
|
+
],
|
|
2662
|
+
},
|
|
2505
2663
|
{
|
|
2506
2664
|
headingKey: 'loc.title',
|
|
2507
2665
|
en: "The model menu's locators",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat's locators that found nothing where the bot needed them (operator, 2026-11-17: "a mechanism that detects
|
|
3
|
+
* which locator exactly the bot failed on, so we can easily see which locator has to be updated"), the last time for
|
|
4
|
+
* each. Kept in the data folder, so a failure seen before a restart is still shown; read by the banner on every page
|
|
5
|
+
* and by Settings, where the locator's field is in red, until the locator is changed there or the operator closes it.
|
|
6
|
+
*/
|
|
7
|
+
import { readFile, rename, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { CHAT_LOCATOR_KEYS } from '../transport/locators.js';
|
|
9
|
+
const isKey = (k) => typeof k === 'string' && CHAT_LOCATOR_KEYS.includes(k);
|
|
10
|
+
export class LocatorFailures {
|
|
11
|
+
file;
|
|
12
|
+
/** One write at a time: two failures in the same second are both kept. */
|
|
13
|
+
queue = Promise.resolve();
|
|
14
|
+
constructor(file) {
|
|
15
|
+
this.file = file;
|
|
16
|
+
}
|
|
17
|
+
async list() {
|
|
18
|
+
try {
|
|
19
|
+
const raw = JSON.parse(await readFile(this.file, 'utf8'));
|
|
20
|
+
if (!Array.isArray(raw))
|
|
21
|
+
return [];
|
|
22
|
+
return raw.filter((f) => !!f && typeof f === 'object' && isKey(f.key) && typeof f.locator === 'string' && typeof f.at === 'string');
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async get(key) {
|
|
29
|
+
return (await this.list()).find((f) => f.key === key) ?? null;
|
|
30
|
+
}
|
|
31
|
+
/** Kept as the one for its locator: the newest replaces the one before. */
|
|
32
|
+
async record(failure) {
|
|
33
|
+
await this.change((all) => [failure, ...all.filter((f) => f.key !== failure.key)]);
|
|
34
|
+
}
|
|
35
|
+
/** Closed by the operator. True when there was one. */
|
|
36
|
+
async dismiss(key) {
|
|
37
|
+
let had = false;
|
|
38
|
+
await this.change((all) => {
|
|
39
|
+
had = all.some((f) => f.key === key);
|
|
40
|
+
return all.filter((f) => f.key !== key);
|
|
41
|
+
});
|
|
42
|
+
return had;
|
|
43
|
+
}
|
|
44
|
+
async change(edit) {
|
|
45
|
+
const run = async () => {
|
|
46
|
+
const next = edit(await this.list());
|
|
47
|
+
const tmp = `${this.file}.tmp`;
|
|
48
|
+
await writeFile(tmp, JSON.stringify(next, null, 2), 'utf8');
|
|
49
|
+
await rename(tmp, this.file);
|
|
50
|
+
};
|
|
51
|
+
const done = this.queue.then(run, run);
|
|
52
|
+
this.queue = done.catch(() => undefined);
|
|
53
|
+
await done;
|
|
54
|
+
}
|
|
55
|
+
}
|