copilot-operator 0.1.52 → 0.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -1
- package/dist/src/api/operator.controller.js +71 -2
- package/dist/src/api/operator.service.js +99 -7
- package/dist/src/config/schema.js +32 -0
- package/dist/src/exec/policy.js +11 -1
- package/dist/src/exec/scriptFiles.js +108 -2
- package/dist/src/orchestrator/leadRunner.js +50 -4
- package/dist/src/orchestrator/review.js +9 -3
- package/dist/src/orchestrator/taskRunner.js +55 -3
- package/dist/src/plan/kerrigan.js +35 -4
- package/dist/src/plan/systemGuide.js +234 -4
- package/dist/src/session/compose.js +16 -4
- package/dist/src/session/store.js +3 -0
- package/dist/src/session/workspace.js +22 -0
- package/dist/src/session/workspaceSearch.js +162 -0
- package/dist/src/util/pacing.js +33 -2
- package/dist/src/vcs/git.js +12 -2
- package/dist/src/vcs/referenceGuard.js +299 -0
- package/dist/web/404.html +3 -2
- package/dist/web/_next/static/{_1zhoDsMOPAH2xW702E5A → WuIGWiKKh_ESR3KwzsLZF}/_buildManifest.js +1 -1
- package/dist/web/_next/static/chunks/1017.ce926873b598fb89.js +1 -0
- package/dist/web/_next/static/chunks/1077.ae2fd686ef05572e.js +1 -0
- package/dist/web/_next/static/chunks/12.06a7f14bd6716249.js +1 -0
- package/dist/web/_next/static/chunks/1350.a5dc706c8110fd34.js +24 -0
- package/dist/web/_next/static/chunks/1548.bd558d3f2c8df4af.js +1 -0
- package/dist/web/_next/static/chunks/1706.db51b57351297898.js +309 -0
- package/dist/web/_next/static/chunks/1707.7d64ffc060c697a0.js +193 -0
- package/dist/web/_next/static/chunks/1880.87829ecb91209eda.js +24 -0
- package/dist/web/_next/static/chunks/20154aaa.28032c3aa5bcd84d.js +1 -0
- package/dist/web/_next/static/chunks/2037.d1bb5e37c7fe85ae.js +104 -0
- package/dist/web/_next/static/chunks/2163.b41334711ddcceff.js +1 -0
- package/dist/web/_next/static/chunks/2398d077.79ae940919b9695e.js +1 -0
- package/dist/web/_next/static/chunks/2435.9b433b38d34b4b2e.js +1 -0
- package/dist/web/_next/static/chunks/2506.bc8515842e225d2a.js +1 -0
- package/dist/web/_next/static/chunks/2529.c88688b437d71d68.js +41 -0
- package/dist/web/_next/static/chunks/2908.4e0e875d2d471932.js +1 -0
- package/dist/web/_next/static/chunks/3117.a4e1c3348e8bead9.js +1 -0
- package/dist/web/_next/static/chunks/3131-8ec8b632ebf0450d.js +1 -0
- package/dist/web/_next/static/chunks/3134-b6a7bc1f267c39aa.js +1 -0
- package/dist/web/_next/static/chunks/3233.1dcc2798f7f5efa0.js +149 -0
- package/dist/web/_next/static/chunks/344.41cc997c8c8deeed.js +115 -0
- package/dist/web/_next/static/chunks/3690.f691d3fcbd70073d.js +1 -0
- package/dist/web/_next/static/chunks/3804.593b14643e74a2a1.js +1 -0
- package/dist/web/_next/static/chunks/3816.9f5568918e35e4ef.js +77 -0
- package/dist/web/_next/static/chunks/3859.f56f3c6ac4b74cf1.js +94 -0
- package/dist/web/_next/static/chunks/3976.11b159e82e0aa974.js +1 -0
- package/dist/web/_next/static/chunks/3986.d47ed4855773e6dd.js +1 -0
- package/dist/web/_next/static/chunks/441.172f3f581f0030d1.js +226 -0
- package/dist/web/_next/static/chunks/442.2e236a6c5c413bd9.js +1 -0
- package/dist/web/_next/static/chunks/4459.d6df347eb58fccd7.js +1 -0
- package/dist/web/_next/static/chunks/4619.ae3628373decf74f.js +34 -0
- package/dist/web/_next/static/chunks/4623.d5711a8d967e49f4.js +1 -0
- package/dist/web/_next/static/chunks/4670.6b811cc3f67a851c.js +62 -0
- package/dist/web/_next/static/chunks/4812.0af1380aa478f6d3.js +93 -0
- package/dist/web/_next/static/chunks/4969.4f7aff472cf938bf.js +1 -0
- package/dist/web/_next/static/chunks/5790.fe114d1a18741d62.js +86 -0
- package/dist/web/_next/static/chunks/603.4055460889ea24d8.js +1 -0
- package/dist/web/_next/static/chunks/6072.b4b359b24b1738d4.js +286 -0
- package/dist/web/_next/static/chunks/6230.8645bbed143793da.js +1 -0
- package/dist/web/_next/static/chunks/6260.6b5b5c9713d7133f.js +1 -0
- package/dist/web/_next/static/chunks/63b9f8e2.218fd437b256a7e4.js +1 -0
- package/dist/web/_next/static/chunks/6421.3ace3aefc3e7350e.js +1 -0
- package/dist/web/_next/static/chunks/6542.963ec591b5c2bc5a.js +1 -0
- package/dist/web/_next/static/chunks/6885.8fb8eeb9e792b515.js +1 -0
- package/dist/web/_next/static/chunks/6891.dd910309748ad46b.js +1 -0
- package/dist/web/_next/static/chunks/714.cb77983f9be215c9.js +1 -0
- package/dist/web/_next/static/chunks/7220.072a60cd9d60220a.js +1 -0
- package/dist/web/_next/static/chunks/7307.39c27470a879fd0a.js +1 -0
- package/dist/web/_next/static/chunks/7333.04d0e45b223dadd4.js +32 -0
- package/dist/web/_next/static/chunks/7489.395193bf37b80884.js +1 -0
- package/dist/web/_next/static/chunks/7496.17282033df0e8794.js +148 -0
- package/dist/web/_next/static/chunks/7500-f90e2ae7061e351d.js +1 -0
- package/dist/web/_next/static/chunks/7507.9fd648884587a7f3.js +287 -0
- package/dist/web/_next/static/chunks/76.f9c2aea58a61692f.js +1 -0
- package/dist/web/_next/static/chunks/7664.bd6265e6e94e1ecd.js +79 -0
- package/dist/web/_next/static/chunks/7872.9b08a88b7289949f.js +64 -0
- package/dist/web/_next/static/chunks/7921-54dae769aa8bae96.js +1 -0
- package/dist/web/_next/static/chunks/795.710d39b80c9ae80c.js +1 -0
- package/dist/web/_next/static/chunks/8173.b82aa1855e641605.js +1 -0
- package/dist/web/_next/static/chunks/8216.b248ebe0af447347.js +8 -0
- package/dist/web/_next/static/chunks/82d3f3cb.23be11b749288234.js +62 -0
- package/dist/web/_next/static/chunks/8381.2d6783c030f8a913.js +27 -0
- package/dist/web/_next/static/chunks/85120a0e.ac16dccf0b8d73d3.js +66 -0
- package/dist/web/_next/static/chunks/8547.0a9997b67008c706.js +1 -0
- package/dist/web/_next/static/chunks/8584.9d5d6c09b0375015.js +1 -0
- package/dist/web/_next/static/chunks/8662.f2663643214caed1.js +38 -0
- package/dist/web/_next/static/chunks/8689.e564346c6e0d16be.js +1 -0
- package/dist/web/_next/static/chunks/9067.832c4761a991f2c2.js +1 -0
- package/dist/web/_next/static/chunks/9125.8589db5ba200cbf1.js +1 -0
- package/dist/web/_next/static/chunks/9202.8dcf7e6a85cc3d36.js +1 -0
- package/dist/web/_next/static/chunks/9249.916a423ac8a07e76.js +1 -0
- package/dist/web/_next/static/chunks/9313.e4f6405d96375c40.js +92 -0
- package/dist/web/_next/static/chunks/937.6d8406b06135134f.js +1 -0
- package/dist/web/_next/static/chunks/9418.1e8f8e14bb5fe3ae.js +217 -0
- package/dist/web/_next/static/chunks/9591.fabd60bd0d10341c.js +1 -0
- package/dist/web/_next/static/chunks/972.db753db904050e48.js +23 -0
- package/dist/web/_next/static/chunks/9747.c8d4ba56c9eef95f.js +1 -0
- package/dist/web/_next/static/chunks/9763.da9015d4a1b533b9.js +36 -0
- package/dist/web/_next/static/chunks/9884.8712c5ed7b044ff2.js +1 -0
- package/dist/web/_next/static/chunks/9891.91a2c59fd073fd48.js +74 -0
- package/dist/web/_next/static/chunks/9984.cdabea5a592e42a1.js +1 -0
- package/dist/web/_next/static/chunks/a9ddb983.8bbb677720017a57.js +122 -0
- package/dist/web/_next/static/chunks/app/_not-found/page-1264c0db9665169c.js +1 -0
- package/dist/web/_next/static/chunks/app/defaults/page-a1f90fe37e302928.js +1 -0
- package/dist/web/_next/static/chunks/app/layout-46efb208d7c88648.js +1 -0
- package/dist/web/_next/static/chunks/app/page-57787f15774d76b8.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-825f53f14d16033d.js +1 -0
- package/dist/web/_next/static/chunks/c7879cf7-fabe25011515220e.js +1 -0
- package/dist/web/_next/static/chunks/c7ea4e13.9b71b5f026a1d6d4.js +1 -0
- package/dist/web/_next/static/chunks/f99cb6a2.3f570aeba3860608.js +160 -0
- package/dist/web/_next/static/chunks/framework-a8bf4d38dd23845f.js +1 -0
- package/dist/web/_next/static/chunks/main-app-f747f0f5ddb4213b.js +1 -0
- package/dist/web/_next/static/chunks/main-d3bbfb91b54fbcc3.js +1 -0
- package/dist/web/_next/static/chunks/pages/_app-5b348989bba3d570.js +1 -0
- package/dist/web/_next/static/chunks/pages/_error-cf88c6d2cc5868d7.js +1 -0
- package/dist/web/_next/static/chunks/webpack-cb74fa884b8af278.js +1 -0
- package/dist/web/_next/static/css/d3398f485b2a9075.css +1 -0
- package/dist/web/defaults.html +3 -2
- package/dist/web/defaults.txt +16 -16
- package/dist/web/index.html +4 -2
- package/dist/web/index.txt +16 -16
- package/dist/web/system.html +3 -2
- package/dist/web/system.txt +16 -16
- package/package.json +8 -2
- package/prompts/level1.md +32 -12
- package/prompts/review1.md +287 -286
- package/dist/web/_next/static/chunks/12.f1f4d35b52633e8d.js +0 -1
- package/dist/web/_next/static/chunks/131-bae98f790a541679.js +0 -1
- package/dist/web/_next/static/chunks/134-ddd50a7fbb536ec8.js +0 -1
- package/dist/web/_next/static/chunks/163.dbd7d36584d0bb37.js +0 -1
- package/dist/web/_next/static/chunks/220.35531b39410e1a9f.js +0 -1
- package/dist/web/_next/static/chunks/489.158bbe303a595fba.js +0 -1
- package/dist/web/_next/static/chunks/548.71ac96c94136659b.js +0 -1
- package/dist/web/_next/static/chunks/584.6df695c5b86a75aa.js +0 -1
- package/dist/web/_next/static/chunks/67.9ed79e2fbfb56f26.js +0 -1
- package/dist/web/_next/static/chunks/714.1e2338736a70b9c7.js +0 -1
- package/dist/web/_next/static/chunks/747.d2c1249d736dc03b.js +0 -1
- package/dist/web/_next/static/chunks/77.a200abef0f5b4a7f.js +0 -1
- package/dist/web/_next/static/chunks/808-bc7d7eac6d823291.js +0 -1
- package/dist/web/_next/static/chunks/921-dc5538cd779c6432.js +0 -1
- package/dist/web/_next/static/chunks/app/_not-found/page-0d0d8e7e62efca12.js +0 -1
- package/dist/web/_next/static/chunks/app/defaults/page-edd7534ca9ecf366.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-8f99a164d76897a0.js +0 -1
- package/dist/web/_next/static/chunks/app/page-4bed816eda370d0c.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-1cf9e75e76da59ed.js +0 -1
- package/dist/web/_next/static/chunks/c7879cf7-b5ab1053c1d9a2e7.js +0 -1
- package/dist/web/_next/static/chunks/framework-9ac6a346bd42cedd.js +0 -1
- package/dist/web/_next/static/chunks/main-6be4444e2d667e41.js +0 -1
- package/dist/web/_next/static/chunks/main-app-e3a5f713ba31557e.js +0 -1
- package/dist/web/_next/static/chunks/pages/_app-32d20d5a04949d29.js +0 -1
- package/dist/web/_next/static/chunks/pages/_error-abbab53f25ea29b0.js +0 -1
- package/dist/web/_next/static/chunks/webpack-77147e31d2125631.js +0 -1
- package/dist/web/_next/static/css/3bea264adc472bc8.css +0 -1
- /package/dist/web/_next/static/{_1zhoDsMOPAH2xW702E5A → WuIGWiKKh_ESR3KwzsLZF}/_ssgManifest.js +0 -0
package/README.md
CHANGED
|
@@ -395,6 +395,10 @@ npx tsx src/cli.ts login --account you@tenant.org # sign in once; the Edge pr
|
|
|
395
395
|
npx tsx src/cli.ts doctor # check the machine
|
|
396
396
|
```
|
|
397
397
|
|
|
398
|
+
A pull, a merge or a switch of branch leaves `node_modules` as it was; when what it brought in
|
|
399
|
+
names a package that is not installed, or another version of one, `npm start` and the package build
|
|
400
|
+
(`npm pack`, `npm publish`) say which and stop before building anything: `npm install` again.
|
|
401
|
+
|
|
398
402
|
The bot never types credentials. `login` opens Edge, waits for the chat to appear, checks
|
|
399
403
|
that the right account is signed in, and stores nothing but the browser profile.
|
|
400
404
|
|
|
@@ -419,10 +423,28 @@ same Copilot window, the lead asking you only what nobody else can decide. "Paus
|
|
|
419
423
|
"Continue". The interface speaks nine languages (English, Bulgarian, German, Spanish, French,
|
|
420
424
|
Portuguese, Japanese, Korean, Arabic), chosen from "Language". "Kerrigan" on the home screen hands out a persona to
|
|
421
425
|
give another chat, which then helps you write tasks for this one (optional); she knows your projects,
|
|
422
|
-
with the level 2 you write for each in Settings.
|
|
426
|
+
with the level 2 you write for each in Settings. A project in Settings can be marked "For
|
|
427
|
+
reference only": the bot reads it and runs what only reads it, and whatever a command changes there
|
|
428
|
+
— files, branches, what is staged — is put back after that command, and the chat is told. See
|
|
423
429
|
[`docs/ui.md`](docs/ui.md); the Sessions page, the task register and plans from JSON were removed
|
|
424
430
|
on 2026-10-20.
|
|
425
431
|
|
|
432
|
+
As in VS Code, Ctrl+P finds a file by name and Ctrl+Shift+F searches the code (match case, whole word,
|
|
433
|
+
regular expressions, files to include or exclude); a Markdown file opens as it reads, its mermaid diagrams drawn.
|
|
434
|
+
Skills keep your instructions for a kind of task that comes back — a new test, a new entity, a migration — in
|
|
435
|
+
Settings; a message starting with `/its-name` (or with the skill chosen under the chat's box) carries them to the
|
|
436
|
+
chat. The three panels move as in VS Code: drag the grip ⠿ in a panel's head onto another. Settings can also make
|
|
437
|
+
the bot pause between messages to Copilot, by a fixed or a random time.
|
|
438
|
+
|
|
439
|
+
**What runs, and how.** Every command the chat sends is given to PowerShell as text
|
|
440
|
+
(`pwsh -NoProfile -NonInteractive -Command "…"`); the bot writes no script to run it. A script file
|
|
441
|
+
— `.ps1`, `.cmd`, `.bat`, `.sh`, `.vbs` — runs only when it is the project's own: committed in its
|
|
442
|
+
repository, unchanged since, and committed before the work began. One the chat wrote, changed or
|
|
443
|
+
downloaded is refused however it is called, and nothing in `.cop-tmp` is run. The project's tools
|
|
444
|
+
go on as usual — `npm test`, `npm run build`, `dotnet test`, `node` starting the application.
|
|
445
|
+
Downloads wait for you even in an unattended run, `npm install` runs no install scripts, and the
|
|
446
|
+
package itself has none.
|
|
447
|
+
|
|
426
448
|
### Removing it from a machine
|
|
427
449
|
|
|
428
450
|
Nothing is installed system-wide, nothing runs at start-up, no service and no scheduled task
|
|
@@ -199,6 +199,22 @@ let OperatorController = class OperatorController {
|
|
|
199
199
|
workspaceFiles() {
|
|
200
200
|
return this.ops.workspaceFiles().catch(fail);
|
|
201
201
|
}
|
|
202
|
+
/** The folder's code searched, as VS Code's Search view (2026-10-21): the text, and its options as 1 or nothing. */
|
|
203
|
+
workspaceSearch(q, matchCase, wholeWord, regex, include, exclude) {
|
|
204
|
+
const on = (v) => v === '1' || v === 'true';
|
|
205
|
+
return this.ops.workspaceSearch(q ?? '', { matchCase: on(matchCase), wholeWord: on(wholeWord), regex: on(regex), include: include ?? '', exclude: exclude ?? '' }).catch(fail);
|
|
206
|
+
}
|
|
207
|
+
/** A picture of the folder, for a Markdown preview (2026-10-21). Served so it can only be shown, never run. */
|
|
208
|
+
async workspaceRaw(path, res) {
|
|
209
|
+
if (!path)
|
|
210
|
+
throw new BadRequestException('path is required');
|
|
211
|
+
const r = await this.ops.workspaceRaw(path).catch(fail);
|
|
212
|
+
res.setHeader('Content-Type', r.type);
|
|
213
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
214
|
+
res.setHeader('Content-Security-Policy', "default-src 'none'; style-src 'unsafe-inline'; sandbox");
|
|
215
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
216
|
+
res.end(r.bytes);
|
|
217
|
+
}
|
|
202
218
|
workspaceFile(path) {
|
|
203
219
|
if (!path)
|
|
204
220
|
throw new BadRequestException('path is required');
|
|
@@ -263,6 +279,8 @@ let OperatorController = class OperatorController {
|
|
|
263
279
|
...(body.lead === true ? { lead: true } : {}),
|
|
264
280
|
...(typeof body.workerModel === 'string' && body.workerModel.trim() ? { workerModel: body.workerModel } : {}),
|
|
265
281
|
...(body.workerManualModel === true ? { workerManualModel: true } : {}),
|
|
282
|
+
// The skill chosen for this message (2026-10-21), by its name.
|
|
283
|
+
...(typeof body.skill === 'string' && body.skill.trim() ? { skill: body.skill } : {}),
|
|
266
284
|
})
|
|
267
285
|
.catch(fail);
|
|
268
286
|
}
|
|
@@ -315,10 +333,28 @@ let OperatorController = class OperatorController {
|
|
|
315
333
|
/** Stores it. A field left out is kept; an empty `rootDir` clears the default. */
|
|
316
334
|
setProject(body) {
|
|
317
335
|
const text = (v) => (typeof v === 'string' ? v : undefined);
|
|
336
|
+
const flag = (v) => (typeof v === 'boolean' ? v : undefined);
|
|
318
337
|
const others = Array.isArray(body?.others)
|
|
319
|
-
? body.others.map((o) => ({
|
|
338
|
+
? body.others.map((o) => ({
|
|
339
|
+
name: String(o?.name ?? ''),
|
|
340
|
+
rootDir: String(o?.rootDir ?? ''),
|
|
341
|
+
...(typeof o?.level2 === 'string' ? { level2: o.level2 } : {}),
|
|
342
|
+
...(typeof o?.readOnly === 'boolean' ? { readOnly: o.readOnly } : {}),
|
|
343
|
+
}))
|
|
320
344
|
: undefined;
|
|
321
|
-
return this.ops
|
|
345
|
+
return this.ops
|
|
346
|
+
.setProject({ rootDir: text(body?.rootDir), name: text(body?.name), level2: text(body?.level2), readOnly: flag(body?.readOnly), ...(others ? { others } : {}) })
|
|
347
|
+
.catch(fail);
|
|
348
|
+
}
|
|
349
|
+
// --- skills (2026-10-21) ---------------------------------------------------------------------
|
|
350
|
+
skills() {
|
|
351
|
+
return this.ops.skills();
|
|
352
|
+
}
|
|
353
|
+
/** The whole list, as Settings show it: each skill's name, what it is for, its instructions and its project. */
|
|
354
|
+
setSkills(body = {}) {
|
|
355
|
+
if (!Array.isArray(body?.skills))
|
|
356
|
+
throw new BadRequestException('skills must be a list');
|
|
357
|
+
return this.ops.setSkills(body.skills).catch(fail);
|
|
322
358
|
}
|
|
323
359
|
// --- the model picker ---------------------------------------------------------------------
|
|
324
360
|
/** The cached list. Returns null when the picker has never been read on this machine. */
|
|
@@ -519,6 +555,26 @@ __decorate([
|
|
|
519
555
|
__metadata("design:paramtypes", []),
|
|
520
556
|
__metadata("design:returntype", Promise)
|
|
521
557
|
], OperatorController.prototype, "workspaceFiles", null);
|
|
558
|
+
__decorate([
|
|
559
|
+
Get('workspace/search'),
|
|
560
|
+
__param(0, Query('q')),
|
|
561
|
+
__param(1, Query('case')),
|
|
562
|
+
__param(2, Query('word')),
|
|
563
|
+
__param(3, Query('regex')),
|
|
564
|
+
__param(4, Query('include')),
|
|
565
|
+
__param(5, Query('exclude')),
|
|
566
|
+
__metadata("design:type", Function),
|
|
567
|
+
__metadata("design:paramtypes", [String, String, String, String, String, String]),
|
|
568
|
+
__metadata("design:returntype", Promise)
|
|
569
|
+
], OperatorController.prototype, "workspaceSearch", null);
|
|
570
|
+
__decorate([
|
|
571
|
+
Get('workspace/raw'),
|
|
572
|
+
__param(0, Query('path')),
|
|
573
|
+
__param(1, Res()),
|
|
574
|
+
__metadata("design:type", Function),
|
|
575
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
576
|
+
__metadata("design:returntype", Promise)
|
|
577
|
+
], OperatorController.prototype, "workspaceRaw", null);
|
|
522
578
|
__decorate([
|
|
523
579
|
Get('workspace/file'),
|
|
524
580
|
__param(0, Query('path')),
|
|
@@ -626,6 +682,19 @@ __decorate([
|
|
|
626
682
|
__metadata("design:paramtypes", [Object]),
|
|
627
683
|
__metadata("design:returntype", Promise)
|
|
628
684
|
], OperatorController.prototype, "setProject", null);
|
|
685
|
+
__decorate([
|
|
686
|
+
Get('skills'),
|
|
687
|
+
__metadata("design:type", Function),
|
|
688
|
+
__metadata("design:paramtypes", []),
|
|
689
|
+
__metadata("design:returntype", Promise)
|
|
690
|
+
], OperatorController.prototype, "skills", null);
|
|
691
|
+
__decorate([
|
|
692
|
+
Put('skills'),
|
|
693
|
+
__param(0, Body()),
|
|
694
|
+
__metadata("design:type", Function),
|
|
695
|
+
__metadata("design:paramtypes", [Object]),
|
|
696
|
+
__metadata("design:returntype", Promise)
|
|
697
|
+
], OperatorController.prototype, "setSkills", null);
|
|
629
698
|
__decorate([
|
|
630
699
|
Get('models'),
|
|
631
700
|
__metadata("design:type", Function),
|
|
@@ -33,6 +33,12 @@ import { chatCode } from '../transport/chatSession.js';
|
|
|
33
33
|
/** The folders the operator works in: the default new sessions start on, and the rest by name. */
|
|
34
34
|
/** The longest level 2 a project may have: Kerrigan carries each one whole. */
|
|
35
35
|
export const MAX_PROJECT_LEVEL2 = 8000;
|
|
36
|
+
/** Its instructions: as long as a project's level 2, the longest text the opening carries besides the task. */
|
|
37
|
+
export const MAX_SKILL_TEXT = 8000;
|
|
38
|
+
export const MAX_SKILL_DESCRIPTION = 300;
|
|
39
|
+
export const MAX_SKILLS = 50;
|
|
40
|
+
/** What follows `/` at the start of a message: lowercase letters, digits and hyphens, 2 to 40 of them. */
|
|
41
|
+
export const SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,38}[a-z0-9]$/;
|
|
36
42
|
/**
|
|
37
43
|
* A settings file or a policy lock that cannot be used: answered 409 with its own message on every route
|
|
38
44
|
* (see `server.ts`), so a start passes it on rather than answering it as a start that did not happen.
|
|
@@ -49,7 +55,8 @@ function sameFolder(a, b) {
|
|
|
49
55
|
const norm = (p) => p.trim().replace(/[\\/]+$/, '').replace(/\//g, '\\').toLowerCase();
|
|
50
56
|
return a.trim() !== '' && norm(a) === norm(b);
|
|
51
57
|
}
|
|
52
|
-
import { saveWorkspaceFile, workspaceFile, workspaceFiles, workspaceInfo } from '../session/workspace.js';
|
|
58
|
+
import { saveWorkspaceFile, workspaceFile, workspaceFiles, workspaceInfo, workspaceRaw } from '../session/workspace.js';
|
|
59
|
+
import { searchWorkspace } from '../session/workspaceSearch.js';
|
|
53
60
|
import { restoreCheckpoint } from '../session/checkpoint.js';
|
|
54
61
|
import { readInterruption } from '../session/interruption.js';
|
|
55
62
|
import { baseRefOf, commitInterrupted, nextAttemptBranch, repoDirOf, trackedRepoOf, sessionBranchName } from '../vcs/taskVcs.js';
|
|
@@ -1023,6 +1030,20 @@ let OperatorService = class OperatorService {
|
|
|
1023
1030
|
const cfg = await this.settings.load();
|
|
1024
1031
|
return await workspaceInfo(cfg.project?.rootDir ?? '', cfg.project?.name ?? '');
|
|
1025
1032
|
}
|
|
1033
|
+
/** The open folder's code, searched as VS Code's Search view does (2026-10-21, see `workspaceSearch.ts`). */
|
|
1034
|
+
async workspaceSearch(query, opts) {
|
|
1035
|
+
const ws = await this.workspace();
|
|
1036
|
+
if (!ws.ok)
|
|
1037
|
+
throw new Error(ws.problem ?? 'No project folder is open.');
|
|
1038
|
+
return await searchWorkspace(ws.dir, query, opts);
|
|
1039
|
+
}
|
|
1040
|
+
/** A file of the open folder as its bytes, with its type: an image a Markdown preview shows (2026-10-21). */
|
|
1041
|
+
async workspaceRaw(path) {
|
|
1042
|
+
const ws = await this.workspace();
|
|
1043
|
+
if (!ws.ok)
|
|
1044
|
+
throw new Error(ws.problem ?? 'No project folder is open.');
|
|
1045
|
+
return await workspaceRaw(ws.dir, path);
|
|
1046
|
+
}
|
|
1026
1047
|
async workspaceFiles() {
|
|
1027
1048
|
const ws = await this.workspace();
|
|
1028
1049
|
if (!ws.ok)
|
|
@@ -1073,11 +1094,15 @@ let OperatorService = class OperatorService {
|
|
|
1073
1094
|
const cfg = await this.settings.load();
|
|
1074
1095
|
const p = await this.project();
|
|
1075
1096
|
const projects = [
|
|
1076
|
-
...(p.rootDir ? [{ name: p.name, rootDir: p.rootDir, ...(p.branch ? { branch: p.branch } : {}), level2: p.level2, chat: true }] : []),
|
|
1077
|
-
...p.others.map((o) => ({ name: o.name, rootDir: o.rootDir, ...(o.branch ? { branch: o.branch } : {}), level2: o.level2 })),
|
|
1097
|
+
...(p.rootDir ? [{ name: p.name, rootDir: p.rootDir, ...(p.branch ? { branch: p.branch } : {}), level2: p.level2, chat: true, ...(p.readOnly ? { readOnly: true } : {}) }] : []),
|
|
1098
|
+
...p.others.map((o) => ({ name: o.name, rootDir: o.rootDir, ...(o.branch ? { branch: o.branch } : {}), level2: o.level2, ...(o.readOnly ? { readOnly: true } : {}) })),
|
|
1078
1099
|
];
|
|
1100
|
+
// The skills, each with the name of the project it is for.
|
|
1101
|
+
const nameOf = (dir) => [{ name: p.name || p.rootDir, rootDir: p.rootDir }, ...p.others].find((x) => x.rootDir && sameFolder(x.rootDir, dir))?.name ?? dir;
|
|
1102
|
+
const skills = (await this.skills()).skills.map((k) => ({ name: k.name, description: k.description, ...(k.projectDir ? { project: nameOf(k.projectDir) } : {}) }));
|
|
1079
1103
|
const text = kerriganPersona(lang, {
|
|
1080
1104
|
version: botVersion(),
|
|
1105
|
+
skills,
|
|
1081
1106
|
maxIterations: cfg.limits.maxIterations,
|
|
1082
1107
|
maxRunMinutes: cfg.limits.maxRunMinutes,
|
|
1083
1108
|
autoContinue: cfg.limits.autoContinue ?? 0,
|
|
@@ -1113,9 +1138,13 @@ let OperatorService = class OperatorService {
|
|
|
1113
1138
|
let session = input.threadId ? await this.store.getSession(input.threadId) : null;
|
|
1114
1139
|
if (input.threadId && (!session || session.kind !== 'chat'))
|
|
1115
1140
|
throw new Error('That conversation is not there any more. Start a new one.');
|
|
1141
|
+
// The skill chosen for this message, as it reads now: the task keeps this copy whatever is edited later.
|
|
1142
|
+
const skill = input.skill?.trim() ? await this.skillFor(input.skill, session?.projectDir ?? (await this.workspace()).dir) : undefined;
|
|
1116
1143
|
if (session) {
|
|
1117
1144
|
const inFlight = session.tasks.find((t) => t.status === 'running' || t.status === 'waiting-approval');
|
|
1118
1145
|
if (inFlight && this.running.has(session.id)) {
|
|
1146
|
+
if (skill)
|
|
1147
|
+
throw new Error(`A skill goes with a new message, and this one would be a note to the message at work. Send /${skill.name} when it has finished.`);
|
|
1119
1148
|
await this.addTaskNote(session.id, inFlight.id, text);
|
|
1120
1149
|
return { threadId: session.id, taskId: inFlight.id, noted: true, needsStart: false };
|
|
1121
1150
|
}
|
|
@@ -1169,6 +1198,7 @@ let OperatorService = class OperatorService {
|
|
|
1169
1198
|
title: text.split(/\r?\n/)[0].trim().slice(0, 80) || 'message',
|
|
1170
1199
|
level2: '',
|
|
1171
1200
|
prompt: text,
|
|
1201
|
+
...(skill ? { skill: { name: skill.name, description: skill.description, text: skill.text } } : {}),
|
|
1172
1202
|
});
|
|
1173
1203
|
// The language the workbench is in, for what the chat's window says when the work has ended (`chatWindowNotice`).
|
|
1174
1204
|
if (input.lang && session.lang !== input.lang) {
|
|
@@ -1186,6 +1216,64 @@ let OperatorService = class OperatorService {
|
|
|
1186
1216
|
}
|
|
1187
1217
|
return { threadId: session.id, taskId: task.id, needsStart: false };
|
|
1188
1218
|
}
|
|
1219
|
+
// --- skills (2026-10-21) ----------------------------------------------------------------------------
|
|
1220
|
+
/** The skills in Settings, and how long their instructions may be. */
|
|
1221
|
+
async skills() {
|
|
1222
|
+
const cfg = await this.settings.load();
|
|
1223
|
+
return {
|
|
1224
|
+
skills: (cfg.skills ?? []).map((k) => ({ name: k.name, description: k.description ?? '', text: k.text ?? '', projectDir: k.projectDir ?? '' })),
|
|
1225
|
+
maxText: MAX_SKILL_TEXT,
|
|
1226
|
+
maxDescription: MAX_SKILL_DESCRIPTION,
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Stores the list as given, held to the rules: a name to type after `/` — lowercase, digits and hyphens, each used
|
|
1231
|
+
* once — instructions that are there and not too long, a project that is one of Settings' or every project.
|
|
1232
|
+
*/
|
|
1233
|
+
async setSkills(list) {
|
|
1234
|
+
if (!Array.isArray(list))
|
|
1235
|
+
throw new Error('The skills come as a list.');
|
|
1236
|
+
if (list.length > MAX_SKILLS)
|
|
1237
|
+
throw new Error(`There can be at most ${MAX_SKILLS} skills.`);
|
|
1238
|
+
const cfg = await this.settings.load();
|
|
1239
|
+
const folders = [cfg.project.rootDir, ...cfg.project.others.map((o) => o.rootDir)].filter((d) => d?.trim());
|
|
1240
|
+
const seen = new Set();
|
|
1241
|
+
const skills = list.map((k) => {
|
|
1242
|
+
const name = String(k?.name ?? '').trim().toLowerCase();
|
|
1243
|
+
if (!SKILL_NAME.test(name))
|
|
1244
|
+
throw new Error(`"${name || '(no name)'}" cannot be a skill's name: 2 to 40 lowercase letters, digits and hyphens, as typed after / — new-test, new-entity, db-migration.`);
|
|
1245
|
+
if (seen.has(name))
|
|
1246
|
+
throw new Error(`Two skills are named "${name}". The name is how a message calls one, so each needs its own.`);
|
|
1247
|
+
seen.add(name);
|
|
1248
|
+
const description = String(k?.description ?? '').trim();
|
|
1249
|
+
if (description.length > MAX_SKILL_DESCRIPTION)
|
|
1250
|
+
throw new Error(`What "${name}" is for is longer than ${MAX_SKILL_DESCRIPTION} characters; one line is enough.`);
|
|
1251
|
+
const text = String(k?.text ?? '');
|
|
1252
|
+
if (!text.trim())
|
|
1253
|
+
throw new Error(`The skill "${name}" has no instructions: write what the chat should know and do for this kind of task.`);
|
|
1254
|
+
if (text.length > MAX_SKILL_TEXT)
|
|
1255
|
+
throw new Error(`The instructions of "${name}" are longer than ${MAX_SKILL_TEXT.toLocaleString('en')} characters.`);
|
|
1256
|
+
const projectDir = String(k?.projectDir ?? '').trim();
|
|
1257
|
+
if (projectDir && !folders.some((f) => sameFolder(f, projectDir)))
|
|
1258
|
+
throw new Error(`The skill "${name}" is for ${projectDir}, which is not one of the projects in Settings.`);
|
|
1259
|
+
return { name, description, text, projectDir };
|
|
1260
|
+
});
|
|
1261
|
+
await this.settings.update((raw) => ({ ...raw, skills }));
|
|
1262
|
+
return await this.skills();
|
|
1263
|
+
}
|
|
1264
|
+
/** The skill a message calls, for the folder it works in: one for every project, or one for this one. */
|
|
1265
|
+
async skillFor(asked, dir) {
|
|
1266
|
+
const name = asked.trim().replace(/^\//, '').toLowerCase();
|
|
1267
|
+
const { skills } = await this.skills();
|
|
1268
|
+
const fits = skills.filter((k) => !k.projectDir || (dir && sameFolder(k.projectDir, dir)));
|
|
1269
|
+
const found = fits.find((k) => k.name === name);
|
|
1270
|
+
if (found)
|
|
1271
|
+
return found;
|
|
1272
|
+
const other = skills.find((k) => k.name === name);
|
|
1273
|
+
if (other)
|
|
1274
|
+
throw new Error(`The skill "${name}" is for ${other.projectDir}, not for the folder this chat works in.`);
|
|
1275
|
+
throw new Error(`There is no skill called "${name}"${fits.length > 0 ? `; there are ${fits.map((k) => k.name).join(', ')}` : ''}. Skills are written in Settings → Skills.`);
|
|
1276
|
+
}
|
|
1189
1277
|
/**
|
|
1190
1278
|
* Back to before a message of the chat (2026-10-17): the folder put back exactly as it was just before that
|
|
1191
1279
|
* message ran — branch, commit, uncommitted changes — and that message and every one after it taken out of the
|
|
@@ -1751,7 +1839,7 @@ let OperatorService = class OperatorService {
|
|
|
1751
1839
|
* The branch each folder is on now (operator, 2026-10-20: "show which branch is chosen"), read from git each
|
|
1752
1840
|
* time, since the operator switches it by hand and the chat works on whatever is checked out.
|
|
1753
1841
|
*/
|
|
1754
|
-
const entry = async (name, dir, level2) => {
|
|
1842
|
+
const entry = async (name, dir, level2, readOnly) => {
|
|
1755
1843
|
const problem = dir ? repoUnusableReason(dir) : 'no folder';
|
|
1756
1844
|
const branch = dir && problem === null ? await git(dir, ['rev-parse', '--abbrev-ref', 'HEAD']).catch(() => null) : null;
|
|
1757
1845
|
return {
|
|
@@ -1761,10 +1849,11 @@ let OperatorService = class OperatorService {
|
|
|
1761
1849
|
...(dir && problem ? { repoProblem: problem } : {}),
|
|
1762
1850
|
...(branch?.ok && branch.stdout ? { branch: branch.stdout } : {}),
|
|
1763
1851
|
level2,
|
|
1852
|
+
readOnly,
|
|
1764
1853
|
};
|
|
1765
1854
|
};
|
|
1766
|
-
const main = await entry((cfg.project?.name ?? '').trim(), rootDir, cfg.project?.level2 ?? '');
|
|
1767
|
-
const others = await Promise.all((cfg.project?.others ?? []).map((o) => entry(o.name, o.rootDir, o.level2 ?? '')));
|
|
1855
|
+
const main = await entry((cfg.project?.name ?? '').trim(), rootDir, cfg.project?.level2 ?? '', cfg.project?.readOnly === true);
|
|
1856
|
+
const others = await Promise.all((cfg.project?.others ?? []).map((o) => entry(o.name, o.rootDir, o.level2 ?? '', o.readOnly === true)));
|
|
1768
1857
|
return { ...main, others };
|
|
1769
1858
|
}
|
|
1770
1859
|
/**
|
|
@@ -1784,6 +1873,7 @@ let OperatorService = class OperatorService {
|
|
|
1784
1873
|
await this.settings.update((raw) => {
|
|
1785
1874
|
const current = (raw.project ?? {});
|
|
1786
1875
|
const rootDir = patch.rootDir !== undefined ? patch.rootDir.trim() : (current.rootDir ?? '').trim();
|
|
1876
|
+
const readOnly = patch.readOnly !== undefined ? patch.readOnly === true : current.readOnly === true;
|
|
1787
1877
|
const name = patch.name !== undefined ? patch.name.trim() : (current.name ?? '').trim();
|
|
1788
1878
|
const level2 = patch.level2 !== undefined ? patch.level2 : (current.level2 ?? '');
|
|
1789
1879
|
// Each goes into Kerrigan whole, and she is pasted into a chat: bounded, so one project cannot crowd out the rest.
|
|
@@ -1803,6 +1893,8 @@ let OperatorService = class OperatorService {
|
|
|
1803
1893
|
name: (o.name ?? '').trim(),
|
|
1804
1894
|
rootDir: (o.rootDir ?? '').trim(),
|
|
1805
1895
|
level2: o.level2 !== undefined ? o.level2 : (was?.level2 ?? ''),
|
|
1896
|
+
// Kept like the level 2 when the list comes without it: a page that does not know the box must not clear it.
|
|
1897
|
+
readOnly: o.readOnly !== undefined ? o.readOnly === true : was?.readOnly === true,
|
|
1806
1898
|
};
|
|
1807
1899
|
});
|
|
1808
1900
|
const seen = new Set();
|
|
@@ -1822,7 +1914,7 @@ let OperatorService = class OperatorService {
|
|
|
1822
1914
|
}
|
|
1823
1915
|
// What the removed Desktop copies left in the stored project is dropped with the next save.
|
|
1824
1916
|
const { mirror: _m, desktop: _d, mirrorToDesktop: _t, ...rest } = current;
|
|
1825
|
-
return { ...raw, project: { ...rest, rootDir, name, level2, others } };
|
|
1917
|
+
return { ...raw, project: { ...rest, rootDir, name, level2, readOnly, others } };
|
|
1826
1918
|
});
|
|
1827
1919
|
return await this.project();
|
|
1828
1920
|
}
|
|
@@ -314,6 +314,11 @@ export const RunConfigSchema = z.object({
|
|
|
314
314
|
* saved or copied, so the chat she helps in knows the project; the bot sends it nowhere by itself.
|
|
315
315
|
*/
|
|
316
316
|
level2: z.string().default(''),
|
|
317
|
+
/**
|
|
318
|
+
* For reference only (operator, 2026-10-21): the bot may read it and run what only reads, and nothing in it
|
|
319
|
+
* may change while it works. Whatever a step changes there is put back (see `vcs/referenceGuard.ts`).
|
|
320
|
+
*/
|
|
321
|
+
readOnly: z.boolean().default(false),
|
|
317
322
|
/**
|
|
318
323
|
* The other folders this operator works in, each with a short name: a front end, a back
|
|
319
324
|
* end, the test suite. They are not defaults — a new session still starts on `rootDir` —
|
|
@@ -328,15 +333,42 @@ export const RunConfigSchema = z.object({
|
|
|
328
333
|
rootDir: z.string().trim().min(1),
|
|
329
334
|
/** Its level 2, as the default project's `level2`. */
|
|
330
335
|
level2: z.string().default(''),
|
|
336
|
+
/** For reference only, as the default project's `readOnly`. */
|
|
337
|
+
readOnly: z.boolean().default(false),
|
|
331
338
|
}))
|
|
332
339
|
.default([]),
|
|
333
340
|
})
|
|
334
341
|
.prefault({}),
|
|
342
|
+
/**
|
|
343
|
+
* Skills (operator, 2026-10-21: "a skill I can set and call for a certain task — information that belongs only to
|
|
344
|
+
* one task that comes back: adding a new automated test, a new entity, migrations of the database"): instructions
|
|
345
|
+
* for a kind of task, chosen under the chat's box or with `/its-name` at the start of a message, and sent to the
|
|
346
|
+
* chat with that message. `projectDir` is the project a skill is for; empty, every project. Kept loose here, so a
|
|
347
|
+
* hand-edited file still loads; the API holds what it saves to the rules (see `setSkills` in operator.service.ts).
|
|
348
|
+
*/
|
|
349
|
+
skills: z
|
|
350
|
+
.array(z.object({
|
|
351
|
+
name: z.string().trim().min(1),
|
|
352
|
+
description: z.string().default(''),
|
|
353
|
+
text: z.string().default(''),
|
|
354
|
+
projectDir: z.string().default(''),
|
|
355
|
+
}))
|
|
356
|
+
.default([]),
|
|
335
357
|
pacing: z
|
|
336
358
|
.object({
|
|
337
359
|
enabled: z.boolean().default(true),
|
|
338
360
|
settleMs: z.number().int().nonnegative().default(1000),
|
|
339
361
|
maxMessagesPerHour: z.number().int().positive().default(60),
|
|
362
|
+
/**
|
|
363
|
+
* A pause between two messages to Copilot (operator, 2026-10-21: "how often a message may be sent — one a minute,
|
|
364
|
+
* say: a message sent, the next no sooner than 60 seconds after"), and with `gapRandom` a time drawn anew each
|
|
365
|
+
* time between `gapSec` and `gapMaxSec` ("between 60 and 90"). Held across every conversation of the window,
|
|
366
|
+
* the lead's and the worker's alike (see `util/pacing.ts`).
|
|
367
|
+
*/
|
|
368
|
+
gapEnabled: z.boolean().default(false),
|
|
369
|
+
gapSec: z.number().int().min(1).max(3600).default(60),
|
|
370
|
+
gapRandom: z.boolean().default(false),
|
|
371
|
+
gapMaxSec: z.number().int().min(1).max(3600).default(90),
|
|
340
372
|
})
|
|
341
373
|
.prefault({}),
|
|
342
374
|
limits: z
|
package/dist/src/exec/policy.js
CHANGED
|
@@ -5,7 +5,7 @@ import { inlineCodeRefusal, programRefusal } from './programs.js';
|
|
|
5
5
|
import { unattendedIsolationRefusal } from './isolation.js';
|
|
6
6
|
import { confinementRefusal } from './confinement.js';
|
|
7
7
|
import { botSelfRefusal, networkFetchReason, networkFetchRefusal } from './network.js';
|
|
8
|
-
import { scriptFileRefusal } from './scriptFiles.js';
|
|
8
|
+
import { ownScriptRefusal, scriptFileRefusal } from './scriptFiles.js';
|
|
9
9
|
export function describeStep(step) {
|
|
10
10
|
// The shell it will really be read by, not the one this file used to assume: a line in the
|
|
11
11
|
// log that names an interpreter the machine has not got explains the wrong failure.
|
|
@@ -173,6 +173,16 @@ export function unattendedPrecondition(cfg) {
|
|
|
173
173
|
* decision when it is refused without asking anyone.
|
|
174
174
|
*/
|
|
175
175
|
export function staticCheck(step, cfg, env = process.env, confinement) {
|
|
176
|
+
/*
|
|
177
|
+
* Only the project's own scripts, and nothing from .cop-tmp (operator, 2026-10-21): a script the chat wrote is not
|
|
178
|
+
* run, however it is called. First, so the chat is told that, and not the older advice of the shared gate to write
|
|
179
|
+
* a script in one step and run it in the next. See `scriptFiles.ts`.
|
|
180
|
+
*/
|
|
181
|
+
if (confinement) {
|
|
182
|
+
const own = ownScriptRefusal(step.cmd, confinement.cwd, confinement.workStartedAt);
|
|
183
|
+
if (own)
|
|
184
|
+
return { action: 'skip', reason: own };
|
|
185
|
+
}
|
|
176
186
|
// Screened against the shell that will actually read it: the traps in `shellExecuteTrap.ts`
|
|
177
187
|
// are shell-specific, so screening for one interpreter and running in another finds nothing.
|
|
178
188
|
const reason = commandRefusal(step.cmd, effectiveShell(step.shell), cfg.denyPatterns, cfg.allowedPrograms, env, confinement);
|
|
@@ -18,9 +18,19 @@
|
|
|
18
18
|
* Covered: PowerShell scripts given to `-File`, dot-sourced, or called with `&` or by path. Not
|
|
19
19
|
* covered, and stated so: a `.js`, `.py` or `.cs` file a project's own tools run. Those are the
|
|
20
20
|
* project's code, and this runner has never claimed to read it; the boundary there is isolation.
|
|
21
|
+
*
|
|
22
|
+
* And since 2026-10-21, for the chat's steps, a third rule (`ownScriptRefusal`): only the project's own scripts run
|
|
23
|
+
* at all. The operator: "I do not want the project to run scripts downloaded from the internet, or ones it created
|
|
24
|
+
* itself — everything is dynamic, not from files", then "that is for scripts from the internet; the ones that are
|
|
25
|
+
* part of it and needed stay", and "npm and the like of course; I mean only scripts from files, not whether the bot
|
|
26
|
+
* runs the tests or the back end". What the chat writes comes from Copilot, a service on the internet, so a script
|
|
27
|
+
* it wrote is a script from the internet. A script file a step runs must therefore be the project's own: committed
|
|
28
|
+
* in its repository, unchanged since, last committed by someone other than the runner and before the work began;
|
|
29
|
+
* nothing is run from `.cop-tmp`. What a step does it says in the step itself, which may be several lines.
|
|
21
30
|
*/
|
|
22
|
-
import { readFileSync, statSync } from 'node:fs';
|
|
23
|
-
import { isAbsolute, resolve } from 'node:path';
|
|
31
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
32
|
+
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
33
|
+
import { gitSync, RUNNER_EMAIL } from '../vcs/git.js';
|
|
24
34
|
/** Larger than this is not a step's script; it is not read, and running it is refused. */
|
|
25
35
|
const MAX_SCRIPT_BYTES = 256 * 1024;
|
|
26
36
|
/** Paths of PowerShell scripts this command line runs, as written. */
|
|
@@ -79,3 +89,99 @@ export function scriptFileRefusal(command, cwd, screen) {
|
|
|
79
89
|
}
|
|
80
90
|
return null;
|
|
81
91
|
}
|
|
92
|
+
/** The folder for scratch files (`vcs/artifacts.ts` keeps it out of every commit); nothing in it is run. */
|
|
93
|
+
const SCRATCH = '.cop-tmp';
|
|
94
|
+
/** A program that runs a file it is given: the shells, the scripting runtimes, the TypeScript runners. */
|
|
95
|
+
const RUNS_A_FILE = String.raw `(?:node|nodejs|python3?|py|pwsh|powershell|cmd|tsx|ts-node|deno|bun|ruby|perl|php|cscript|wscript|bash|sh|java|dotnet|npx|vitest|jest|mocha)`;
|
|
96
|
+
/**
|
|
97
|
+
* The script files a command line runs — PowerShell's `.ps1` and `.psm1`, cmd's `.cmd` and `.bat`, bash's `.sh`,
|
|
98
|
+
* Windows Script Host's `.vbs`, `.wsf` and the rest — as full paths:
|
|
99
|
+
* given to `-File`, dot-sourced, called with `&` or by a path, passed to `cmd /c`, started with Start-Process, or
|
|
100
|
+
* imported as a module. A bare name counts only when that file is in the folder, where cmd and Start-Process look
|
|
101
|
+
* first; otherwise it is a program found on PATH — `npm.cmd`, `npx.cmd` — and not one of the project's files.
|
|
102
|
+
*/
|
|
103
|
+
export function shellScriptsRun(command, cwd) {
|
|
104
|
+
const named = new Set(scriptPathsRun(command));
|
|
105
|
+
const patterns = [
|
|
106
|
+
/(?:^|[|;&(\n{]\s*)(?:[.&]\s+)?(?:"([^"]+\.(?:ps1|psm1|cmd|bat))"|'([^']+\.(?:ps1|psm1|cmd|bat))'|(\S+\.(?:ps1|psm1|cmd|bat)))(?=\s|$)/gi,
|
|
107
|
+
/\bcmd(?:\.exe)?\b[^|;\n]*?\s\/[ck]\s+(?:"([^"]+\.(?:cmd|bat))"|'([^']+\.(?:cmd|bat))'|(\S+\.(?:cmd|bat)))/gi,
|
|
108
|
+
/\b(?:Start-Process|saps)\b[^|;\n]*?(?:"([^"]+\.(?:ps1|cmd|bat))"|'([^']+\.(?:ps1|cmd|bat))'|([^\s'",]+\.(?:ps1|cmd|bat)))/gi,
|
|
109
|
+
/\b(?:Import-Module|ipmo)\b[^|;\n]*?(?:"([^"]+\.psm1)"|'([^']+\.psm1)'|(\S+\.psm1))/gi,
|
|
110
|
+
// A shell script for bash and its kin (Git Bash, WSL), by a path or given to the shell.
|
|
111
|
+
/(?:^|[|;&(\n{]\s*)(?:"([^"]+\.(?:sh|bash|zsh))"|'([^']+\.(?:sh|bash|zsh))'|(\S+\.(?:sh|bash|zsh)))(?=\s|$)/gi,
|
|
112
|
+
/\b(?:bash|sh|zsh|ksh|dash|wsl)(?:\.exe)?\b[^|;\n]*?\s(?:"([^"]+\.(?:sh|bash|zsh))"|'([^']+\.(?:sh|bash|zsh))'|(\S+\.(?:sh|bash|zsh)))/gi,
|
|
113
|
+
// Windows Script Host's scripts.
|
|
114
|
+
/\b(?:wscript|cscript)(?:\.exe)?\b[^|;\n]*?\s(?:"([^"]+\.(?:vbs|vbe|js|jse|wsf|wsh))"|'([^']+\.(?:vbs|vbe|js|jse|wsf|wsh))'|(\S+\.(?:vbs|vbe|js|jse|wsf|wsh)))/gi,
|
|
115
|
+
/(?:^|[|;&(\n{]\s*)(?:[.&]\s+)?(?:"([^"]+\.(?:vbs|vbe|wsf|wsh|hta))"|'([^']+\.(?:vbs|vbe|wsf|wsh|hta))'|(\S+\.(?:vbs|vbe|wsf|wsh|hta)))(?=\s|$)/gi,
|
|
116
|
+
];
|
|
117
|
+
for (const re of patterns) {
|
|
118
|
+
for (const m of command.matchAll(re)) {
|
|
119
|
+
const p = (m[1] ?? m[2] ?? m[3] ?? '').trim();
|
|
120
|
+
if (p)
|
|
121
|
+
named.add(p);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const files = new Set();
|
|
125
|
+
for (const p of named) {
|
|
126
|
+
const full = isAbsolute(p) ? p : resolve(cwd, p);
|
|
127
|
+
if (!/[\\/]/.test(p) && !existsSync(full))
|
|
128
|
+
continue;
|
|
129
|
+
files.add(full);
|
|
130
|
+
}
|
|
131
|
+
return [...files];
|
|
132
|
+
}
|
|
133
|
+
/** Whether a path lies in the scratch folder, at any depth. */
|
|
134
|
+
const inScratch = (path) => path.split(/[\\/]+/).some((part) => part.toLowerCase() === SCRATCH);
|
|
135
|
+
/**
|
|
136
|
+
* Why a script is not one of the project's own, or null when it is: in its repository, committed, unchanged since,
|
|
137
|
+
* last committed by someone other than the runner and, when `since` is known, before the work began.
|
|
138
|
+
*/
|
|
139
|
+
export function notTheProjects(file, since) {
|
|
140
|
+
if (inScratch(file))
|
|
141
|
+
return `it is in ${SCRATCH}, the folder for scratch files, and nothing there is run`;
|
|
142
|
+
if (!existsSync(file))
|
|
143
|
+
return 'it does not exist';
|
|
144
|
+
const top = gitSync(dirname(file), ['rev-parse', '--show-toplevel']);
|
|
145
|
+
if (!top.ok || !top.stdout)
|
|
146
|
+
return 'it is not in a git repository, so nothing tells it apart from a script written during the work';
|
|
147
|
+
const rel = relative(top.stdout, file);
|
|
148
|
+
const path = rel && !rel.startsWith('..') && !isAbsolute(rel) ? rel.replace(/\\/g, '/') : file;
|
|
149
|
+
if (!gitSync(top.stdout, ['ls-files', '--error-unmatch', '--', path]).ok)
|
|
150
|
+
return 'it is not committed in its repository';
|
|
151
|
+
const diff = gitSync(top.stdout, ['diff', '--quiet', 'HEAD', '--', path]);
|
|
152
|
+
if (diff.code === 1)
|
|
153
|
+
return 'it was changed since it was last committed';
|
|
154
|
+
if (!diff.ok)
|
|
155
|
+
return `git could not compare it with its last commit${diff.stderr ? ` (${diff.stderr.split('\n')[0]})` : ''}`;
|
|
156
|
+
const last = gitSync(top.stdout, ['log', '-1', '--format=%ae%x09%ct', '--', path]);
|
|
157
|
+
const [email = '', time = ''] = last.stdout.split('\t');
|
|
158
|
+
if (email.trim().toLowerCase() === RUNNER_EMAIL)
|
|
159
|
+
return 'its last commit was made by copilot-operator, so it was written during the work';
|
|
160
|
+
const began = since ? Date.parse(since) : NaN;
|
|
161
|
+
if (Number.isFinite(began) && Number(time) * 1000 >= began - 1000)
|
|
162
|
+
return 'it was committed after this work began, so it was written during the work';
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Why a chat's step must not run a script, or null: a shell script that is not one of the project's own (see
|
|
167
|
+
* `notTheProjects`), or any file in `.cop-tmp` given to a program that runs it. Only for the chat's steps, the
|
|
168
|
+
* implementer's and the reviewer's: the operator's own checks are theirs to point at whatever they choose.
|
|
169
|
+
*/
|
|
170
|
+
export function ownScriptRefusal(command, cwd, since) {
|
|
171
|
+
// A file of code in it, given to a program that runs files — not its output written there (`node x.js > .cop-tmp\out.txt`).
|
|
172
|
+
const scratch = new RegExp(String.raw `\b${RUNS_A_FILE}(?:\.exe|\.cmd)?\b[^|;\n]*?(?:^|[\s'"=(,:])(?:\.[\\/])?(?:[^\s'"|;]*[\\/])?\.cop-tmp[\\/][^\s'"|;]*\.(?:ps1|psm1|cmd|bat|js|mjs|cjs|jsx|ts|mts|cts|tsx|py|rb|pl|php|vbs|vbe|wsf|sh|jar|dll|exe|csx)\b`, 'i');
|
|
173
|
+
const why = (file, reason) => `refused: ${relative(cwd, file) || file} is not one of the project's own scripts — ${reason}. A script written or ` +
|
|
174
|
+
'changed during the work is not run, nor anything in .cop-tmp (the operator\'s rule). Put what it does in the ' +
|
|
175
|
+
'step itself: a command may be several lines. If the script is meant to be part of the project, say so in "notes", ' +
|
|
176
|
+
'and the operator can commit it.';
|
|
177
|
+
for (const file of shellScriptsRun(command, cwd)) {
|
|
178
|
+
const reason = notTheProjects(file, since);
|
|
179
|
+
if (reason)
|
|
180
|
+
return why(file, reason);
|
|
181
|
+
}
|
|
182
|
+
if (scratch.test(command)) {
|
|
183
|
+
return ('refused: this runs a file in .cop-tmp, the folder for scratch files — nothing there is run (the operator\'s rule). ' +
|
|
184
|
+
'Put what it does in the step itself: a command may be several lines.');
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|