copilot-operator 0.1.66 → 0.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/src/api/operator.controller.js +8 -1
  2. package/dist/src/api/operator.service.js +3 -1
  3. package/dist/src/cli.js +1 -0
  4. package/dist/src/config/schema.js +7 -0
  5. package/dist/src/exec/authorizer.js +26 -6
  6. package/dist/src/exec/commandHeads.js +30 -6
  7. package/dist/src/exec/platforms.js +13 -2
  8. package/dist/src/exec/policy.js +31 -4
  9. package/dist/src/exec/policyManifest.js +9 -0
  10. package/dist/src/exec/readOnly.js +158 -0
  11. package/dist/src/orchestrator/taskRunner.js +4 -2
  12. package/dist/src/plan/kerrigan.js +3 -1
  13. package/dist/src/plan/systemGuide.js +63 -0
  14. package/dist/web/404.html +2 -2
  15. package/dist/web/_next/static/chunks/1024-5f630cbb54e7346f.js +1 -0
  16. package/dist/web/_next/static/chunks/{1077.b88b069535f7008e.js → 1077.3b82a837cf810f8b.js} +1 -1
  17. package/dist/web/_next/static/chunks/{1548.9e01803e48173ea9.js → 1548.52bfcd01c16aaafe.js} +1 -1
  18. package/dist/web/_next/static/chunks/{2163.018cd5f719ae4b3d.js → 2163.e60d3be9bb3f8b3f.js} +1 -1
  19. package/dist/web/_next/static/chunks/{714.281f68f85df26013.js → 714.b452ef814760b5a5.js} +1 -1
  20. package/dist/web/_next/static/chunks/{7220.3bd10a3e4e053e0c.js → 7220.96b18052ed9c06c7.js} +1 -1
  21. package/dist/web/_next/static/chunks/{7921-1c173d00d23b3589.js → 7921-dd201ce7aa02c12d.js} +1 -1
  22. package/dist/web/_next/static/chunks/{8124-bb544c96a7c0e7e3.js → 8124-c27ce7bd781f4c56.js} +1 -1
  23. package/dist/web/_next/static/chunks/{8584.c7cd52c2e7075bcb.js → 8584.ab8d406781cdd45c.js} +1 -1
  24. package/dist/web/_next/static/chunks/{9067.feaf894390db1a88.js → 9067.5b8abc40104d51d9.js} +1 -1
  25. package/dist/web/_next/static/chunks/9747.cf0353e7ffec2ee4.js +1 -0
  26. package/dist/web/_next/static/chunks/app/{page-95379244849623fc.js → page-ab73d1b3ba9181c2.js} +1 -1
  27. package/dist/web/_next/static/chunks/app/settings/page-7d120feb5af0ace9.js +1 -0
  28. package/dist/web/_next/static/chunks/{webpack-5ea108bc2e386c55.js → webpack-23ace264f775d98a.js} +1 -1
  29. package/dist/web/_next/static/css/{a112074f3d1a8a07.css → 532df8667473c4fc.css} +1 -1
  30. package/dist/web/defaults.html +2 -2
  31. package/dist/web/defaults.txt +8 -8
  32. package/dist/web/index.html +3 -3
  33. package/dist/web/index.txt +9 -9
  34. package/dist/web/queue.html +2 -2
  35. package/dist/web/queue.txt +9 -9
  36. package/dist/web/settings.html +2 -2
  37. package/dist/web/settings.txt +9 -9
  38. package/dist/web/system.html +2 -2
  39. package/dist/web/system.txt +9 -9
  40. package/package.json +3 -2
  41. package/dist/web/_next/static/chunks/1024-444e9060299d04ba.js +0 -1
  42. package/dist/web/_next/static/chunks/9747.7cee8a2d8301f25c.js +0 -1
  43. package/dist/web/_next/static/chunks/app/settings/page-9a83381087178f80.js +0 -1
  44. /package/dist/web/_next/static/{BbWvNQTsh3pH7ZN_RKR60 → JpBxrjYpw2xowWbFoiPjO}/_buildManifest.js +0 -0
  45. /package/dist/web/_next/static/{BbWvNQTsh3pH7ZN_RKR60 → JpBxrjYpw2xowWbFoiPjO}/_ssgManifest.js +0 -0
@@ -26,6 +26,8 @@ import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
26
26
  import { CHANGED_ON_DISK } from '../session/workspace.js';
27
27
  import { join } from 'node:path';
28
28
  import { DefaultPickerLocators } from '../transport/locators.js';
29
+ import { platformTools } from '../exec/platforms.js';
30
+ import { readOnlyCapable } from '../exec/readOnly.js';
29
31
  function fail(e) {
30
32
  // A settings file or a policy lock that cannot be used is not the request's fault, and every route
31
33
  // that reads the settings meets it, wrapped here or not: it is passed on as it is, for the server
@@ -83,7 +85,12 @@ let OperatorController = class OperatorController {
83
85
  * pictures of a choice are kept — a run's beside its browser's other files, a reading of the list in its own.
84
86
  */
85
87
  const picker = { defaults: DefaultPickerLocators, dirs: { run: join(resolved.resolved.runsDir, '_browser'), read: join(resolved.resolved.runsDir, '_models') } };
86
- return { raw, defaults, resolved: resolved.resolved, picker };
88
+ /*
89
+ * The programs the bot may start (2026-10-26): which of them reach a platform with the operator's access, which can
90
+ * be set to read only, and the list in force, which a policy lock may have narrowed.
91
+ */
92
+ const programs = { platforms: platformTools(), readOnly: readOnlyCapable(), inForce: resolved.execution.allowedPrograms };
93
+ return { raw, defaults, resolved: resolved.resolved, picker, programs };
87
94
  }
88
95
  async saveSettings(body) {
89
96
  await this.ops.settings.save(body).catch(fail);
@@ -847,6 +847,7 @@ let OperatorService = class OperatorService {
847
847
  // Read once per run like the rest of the policy: a change in Settings applies from the next start.
848
848
  networkFetch: cfg.execution.networkFetch,
849
849
  platformAccess: cfg.execution.questions === 'agree' ? 'allow' : 'ask',
850
+ readOnlyPrograms: cfg.execution.readOnlyPrograms,
850
851
  };
851
852
  /*
852
853
  * An unattended run that cannot legally execute anything is stopped here, where the operator
@@ -2340,12 +2341,13 @@ let OperatorService = class OperatorService {
2340
2341
  ...(ctx.actor ? { actor: ctx.actor } : {}),
2341
2342
  ...(held?.network ? { network: held.network } : {}),
2342
2343
  ...(held?.platform ? { platform: held.platform } : {}),
2344
+ ...(held?.readOnly ? { readOnly: held.readOnly } : {}),
2343
2345
  };
2344
2346
  this.waiting.set(approval.id, { approval, resolve: resolvePromise });
2345
2347
  this.parkLater(approval);
2346
2348
  this.bus.publish({ sessionId: approval.sessionId, taskId: approval.taskId, type: 'approval-requested', level: 'warn',
2347
2349
  message: held
2348
- ? `held for the operator — ${[held.platform ? `it reaches ${held.platform} with the operator's access` : '', held.network ?? ''].filter(Boolean).join('; ')}: ${approval.description}`
2350
+ ? `held for the operator — ${[held.platform ? `it reaches ${held.platform} with the operator's access` : '', held.readOnly ? `set to read only, and ${held.readOnly}` : '', held.network ?? ''].filter(Boolean).join('; ')}: ${approval.description}`
2349
2351
  : `waiting for approval: ${approval.description}`,
2350
2352
  data: { ...approval } });
2351
2353
  }), signal);
package/dist/src/cli.js CHANGED
@@ -501,6 +501,7 @@ program
501
501
  lockedToConfirm: cfg.policyLock?.maxMode === 'confirm',
502
502
  networkFetch: cfg.execution.networkFetch,
503
503
  platformAccess: cfg.execution.questions === 'agree' ? 'allow' : 'ask',
504
+ readOnlyPrograms: cfg.execution.readOnlyPrograms,
504
505
  };
505
506
  const authorizer = cfg.execution.mode === 'unattended'
506
507
  ? unattendedAuthorizer(policy)
@@ -297,6 +297,13 @@ export const RunConfigSchema = z.object({
297
297
  // ordinary Windows inspection and housekeeping a build or test reaches for
298
298
  'where', 'findstr', 'tasklist', 'taskkill', 'netstat', 'robocopy', 'xcopy', 'tar', 'curl', 'docker', 'docker-compose',
299
299
  ]),
300
+ /**
301
+ * Programs on the list above set to read only, "for reference" (operator, 2026-10-26): a command of theirs that only
302
+ * reads runs without a card, one that changes something, signs in or out or shows a secret is refused, one that
303
+ * cannot be read is asked about in every mode. Only programs with a rule (`exec/readOnly.ts`: az) can be; others
304
+ * named here are ignored.
305
+ */
306
+ readOnlyPrograms: z.array(z.string()).default([]),
300
307
  denyPatterns: z
301
308
  .array(z.string())
302
309
  .default([
@@ -1,7 +1,8 @@
1
1
  import { staticCheck, describeStep } from './policy.js';
2
2
  import { networkFetchReason, networkFetchRefusal } from './network.js';
3
3
  import { scriptNetworkReason } from './policy.js';
4
- import { platformReason } from './platforms.js';
4
+ import { platformOf, platformReason } from './platforms.js';
5
+ import { readOnlyUnclearRefusal, readOnlyVerdict } from './readOnly.js';
5
6
  import { createInterface } from 'node:readline/promises';
6
7
  import { stdin, stdout } from 'node:process';
7
8
  /**
@@ -32,17 +33,28 @@ export function makeAuthorizer(cfg, ask, signal) {
32
33
  return blocked;
33
34
  const cwd = ctx.confinement?.cwd;
34
35
  const network = networkFetchReason(step.cmd, cwd) ?? (cwd ? scriptNetworkReason(step.cmd, cwd) : null);
35
- // A platform reached with the operator's access (2026-10-23): asked in every mode, unless Settings agree to it.
36
- const platform = cfg.platformAccess === 'allow' ? null : platformReason(step.cmd, step.shell);
36
+ /*
37
+ * A platform reached with the operator's access (2026-10-23): asked in every mode, unless Settings agree to it. A
38
+ * program set to read only (2026-10-26) is not asked about when the line only reads with it; when it cannot be
39
+ * read as reading, it is asked about in every mode, Settings' agreement or not — the operator said it must not write.
40
+ */
41
+ const reading = readOnlyVerdict(step.cmd, step.shell, cfg.readOnlyPrograms);
42
+ const unclear = reading?.kind === 'unclear' ? reading : null;
43
+ const platform = unclear
44
+ ? (platformReason(step.cmd, step.shell) ?? platformOf(unclear.program) ?? unclear.program)
45
+ : cfg.platformAccess === 'allow'
46
+ ? null
47
+ : platformReason(step.cmd, step.shell, reading?.kind === 'reads' ? new Set(reading.programs) : undefined);
48
+ const held = { ...(platform ? { platform } : {}), ...(unclear ? { readOnly: unclear.why, readOnlyProgram: unclear.program } : {}) };
37
49
  if (network) {
38
50
  if (cfg.mode === 'unattended' && cfg.networkFetch === 'refuse')
39
51
  return { action: 'skip', reason: networkFetchRefusal(network) };
40
52
  if (!platform && cfg.mode === 'unattended' && cfg.networkFetch === 'run')
41
53
  return { action: 'run' };
42
- return await ask(step, ctx, { network, ...(platform ? { platform } : {}) });
54
+ return await ask(step, ctx, { network, ...held });
43
55
  }
44
56
  if (platform)
45
- return await ask(step, ctx, { platform });
57
+ return await ask(step, ctx, held);
46
58
  if (cfg.mode === 'unattended')
47
59
  return { action: 'run' };
48
60
  return await ask(step, ctx);
@@ -63,6 +75,8 @@ export function terminalAuthorizer(cfg, print) {
63
75
  print(` held: ${held.network}`);
64
76
  if (held?.platform)
65
77
  print(` held: it reaches ${held.platform} with your access`);
78
+ if (held?.readOnly)
79
+ print(` held: ${held.readOnlyProgram ?? 'the program'} is set to read only, and this could not be read as only reading (${held.readOnly})`);
66
80
  const rl = createInterface({ input: stdin, output: stdout });
67
81
  try {
68
82
  const answer = (await rl.question(' [Enter] run [s] skip [q] abort > ')).trim().toLowerCase();
@@ -87,5 +101,11 @@ export function terminalAuthorizer(cfg, print) {
87
101
  * those steps.
88
102
  */
89
103
  export function unattendedAuthorizer(cfg) {
90
- return makeAuthorizer({ ...cfg, mode: 'unattended' }, async (_step, _ctx, held) => held?.network ? { action: 'skip', reason: networkFetchRefusal(held.network) } : held?.platform ? { action: 'skip', reason: platformRefusal(held.platform) } : { action: 'run' });
104
+ return makeAuthorizer({ ...cfg, mode: 'unattended' }, async (_step, _ctx, held) => held?.network
105
+ ? { action: 'skip', reason: networkFetchRefusal(held.network) }
106
+ : held?.readOnly
107
+ ? { action: 'skip', reason: readOnlyUnclearRefusal(held.readOnlyProgram ?? 'the program', held.readOnly) }
108
+ : held?.platform
109
+ ? { action: 'skip', reason: platformRefusal(held.platform) }
110
+ : { action: 'run' });
91
111
  }
@@ -74,6 +74,7 @@ const isTerminator = (c) => c === '' || c === ';' || c === '\n' || c === '|' ||
74
74
  class PowerShellScan {
75
75
  s;
76
76
  heads = [];
77
+ calls = [];
77
78
  uncertain;
78
79
  depth = 0;
79
80
  constructor(s) {
@@ -81,7 +82,14 @@ class PowerShellScan {
81
82
  }
82
83
  run() {
83
84
  this.statements(0, null);
84
- return this.uncertain ? { heads: this.heads, uncertain: this.uncertain } : { heads: this.heads };
85
+ return this.uncertain ? { heads: this.heads, calls: this.calls, uncertain: this.uncertain } : { heads: this.heads, calls: this.calls };
86
+ }
87
+ /** A literal head: recorded, with the invocation its arguments are read into. */
88
+ record(head) {
89
+ this.heads.push(head);
90
+ const call = { head, args: [] };
91
+ this.calls.push(call);
92
+ return call;
85
93
  }
86
94
  fail(why) {
87
95
  this.uncertain ??= why;
@@ -229,7 +237,7 @@ class PowerShellScan {
229
237
  if (word.dynamic)
230
238
  this.fail(`the command "${word.literal}" is built from a variable, so which program it starts is known only when it runs`);
231
239
  else if (word.literal)
232
- this.heads.push(word.literal);
240
+ return this.commandArgs(word.end, this.record(word.literal));
233
241
  return this.commandArgs(word.end);
234
242
  }
235
243
  /**
@@ -272,11 +280,14 @@ class PowerShellScan {
272
280
  if (word.dynamic)
273
281
  this.fail(`the program "${word.literal}" is built from a variable, so which program it starts is known only when it runs`);
274
282
  else if (word.literal)
275
- this.heads.push(word.literal);
283
+ return this.commandArgs(word.end, this.record(word.literal));
276
284
  return this.commandArgs(word.end);
277
285
  }
278
- /** A command's arguments, up to the end of its pipeline element. Nested statements are read. */
279
- commandArgs(i) {
286
+ /**
287
+ * A command's arguments, up to the end of its pipeline element. Nested statements are read. With `call`, each
288
+ * argument is recorded on it: a word or a quoted string as it reads, anything else as known only when it runs.
289
+ */
290
+ commandArgs(i, call) {
280
291
  for (;;) {
281
292
  i = this.skip(i);
282
293
  const c = this.at(i);
@@ -285,6 +296,7 @@ class PowerShellScan {
285
296
  return i;
286
297
  // `--%` hands the rest of the line to the program untouched, up to a pipe or a newline.
287
298
  if (c === '-' && n === '-' && this.at(i + 2) === '%') {
299
+ call?.args.push({ literal: '--%', dynamic: true });
288
300
  while (i < this.s.length && this.at(i) !== '\n' && this.at(i) !== '|')
289
301
  i += 1;
290
302
  continue;
@@ -298,12 +310,22 @@ class PowerShellScan {
298
310
  i += 1;
299
311
  continue;
300
312
  }
313
+ // A quoted argument is read as a word is, so the program gets the text it will get: `'vm' 'list'` is `vm list`.
314
+ if (isSingleQuote(c) || isDoubleQuote(c)) {
315
+ const word = this.readWord(i);
316
+ call?.args.push({ literal: word.literal, dynamic: word.dynamic });
317
+ i = word.end > i ? word.end : i + 1;
318
+ continue;
319
+ }
301
320
  const nested = this.nested(i, 'statements');
302
321
  if (nested !== null) {
322
+ call?.args.push({ literal: this.s.slice(i, nested), dynamic: true });
303
323
  i = nested;
304
324
  continue;
305
325
  }
306
326
  const word = this.readWord(i);
327
+ if (word.end > i)
328
+ call?.args.push({ literal: word.literal, dynamic: word.dynamic });
307
329
  i = word.end > i ? word.end : i + 1;
308
330
  }
309
331
  }
@@ -698,6 +720,7 @@ class PowerShellScan {
698
720
  */
699
721
  function scanCmd(src) {
700
722
  const heads = [];
723
+ const calls = [];
701
724
  let uncertain;
702
725
  const fail = (why) => {
703
726
  uncertain ??= why;
@@ -794,6 +817,7 @@ function scanCmd(src) {
794
817
  continue;
795
818
  }
796
819
  heads.push(literal);
820
+ calls.push({ head: literal, args: tokens.slice(k + 1).map((t) => ({ literal: t.replace(/"/g, ''), dynamic: /%[^%\s]+%|![^!\s]+!/.test(t) })) });
797
821
  }
798
- return uncertain ? { heads, uncertain } : { heads };
822
+ return uncertain ? { heads, calls, uncertain } : { heads, calls };
799
823
  }
@@ -64,13 +64,24 @@ const REGISTRIES = [
64
64
  [/(?:^|[\s;|&(])gem\s+(?:push|yank|signin)\b/i, 'RubyGems'],
65
65
  [/(?:^|[\s;|&(])cargo(?:\.exe)?\s+(?:publish|yank|login)\b/i, 'crates.io'],
66
66
  ];
67
+ /** The platform tools, by program, as the card names each (for Settings' list of programs, 2026-10-26). */
68
+ export function platformTools() {
69
+ return { ...TOOLS };
70
+ }
71
+ /** The platform a program reaches, as the card names it, or null. */
72
+ export function platformOf(program) {
73
+ return TOOLS[program.toLowerCase()] ?? null;
74
+ }
67
75
  /**
68
76
  * The platform a command reaches with the operator's access, as the card names it, or null. `Connect-AzAccount` is
69
- * Azure; `npm publish` the npm registry; `az login; gh repo list` the first one met.
77
+ * Azure; `npm publish` the npm registry; `az login; gh repo list` the first one met. `reading`: programs set to read
78
+ * only whose every command on this line only reads (`readOnly.ts`), which are not asked about.
70
79
  */
71
- export function platformReason(command, shell) {
80
+ export function platformReason(command, shell, reading) {
72
81
  for (const head of commandHeads(command, shell)) {
73
82
  const program = externalProgram(head);
83
+ if (program && reading?.has(program.toLowerCase()))
84
+ continue;
74
85
  if (program && TOOLS[program.toLowerCase()])
75
86
  return TOOLS[program.toLowerCase()];
76
87
  const bare = head.replace(/^.*[\\/]/, '').replace(/^['"]|['"]$/g, '');
@@ -6,6 +6,8 @@ import { unattendedIsolationRefusal } from './isolation.js';
6
6
  import { confinementRefusal } from './confinement.js';
7
7
  import { botSelfRefusal, networkFetchReason, networkFetchRefusal } from './network.js';
8
8
  import { ownScriptRefusal, scriptFileRefusal } from './scriptFiles.js';
9
+ import { readOnlyRefusal, readOnlyUnaskedRefusal, readOnlyUnclearRefusal, readOnlyVerdict } from './readOnly.js';
10
+ import { platformReason } from './platforms.js';
9
11
  export function describeStep(step) {
10
12
  // The shell it will really be read by, not the one this file used to assume: a line in the
11
13
  // log that names an interpreter the machine has not got explains the wrong failure.
@@ -64,7 +66,9 @@ export function commandRefusal(command, shell, denyPatterns, allowedPrograms = [
64
66
  * speak of — a check run by hand, a test of some other rule. Every path that runs a command for a
65
67
  * task passes it: the implementer's steps and checks, and the reviewer's steps and derived checks.
66
68
  */
67
- confinement) {
69
+ confinement,
70
+ /** Programs set to read only: a command of theirs that changes something is refused. See `readOnly.ts`. */
71
+ readOnlyPrograms = []) {
68
72
  // The built-in refusals first, because the operator's list can add to them and must not be
69
73
  // able to stand in for them: a config written before they existed, or edited since, still gets
70
74
  // them. See `dangerous.ts` for what is on the list and why each one is.
@@ -95,6 +99,10 @@ confinement) {
95
99
  const offlist = programRefusal(command, allowedPrograms, shell);
96
100
  if (offlist)
97
101
  return offlist;
102
+ // A program on the list but set to read only, asked to change something (2026-10-26).
103
+ const writes = readOnlyRefusal(command, shell, readOnlyPrograms);
104
+ if (writes)
105
+ return writes;
98
106
  const trap = findShellExecuteTrap(command, shell, env);
99
107
  if (trap)
100
108
  return trap;
@@ -108,7 +116,9 @@ confinement) {
108
116
  repositoryInternalsRefusal(text) ??
109
117
  (matchDenyPattern(text, denyPatterns) ? `matches deny pattern /${matchDenyPattern(text, denyPatterns)}/` : null) ??
110
118
  confinementRefusal(text, confinement) ??
111
- programRefusal(text, allowedPrograms));
119
+ programRefusal(text, allowedPrograms) ??
120
+ // Inside a script nothing is put to the operator command by command: one that cannot be read as reading is refused.
121
+ readOnlyUnaskedRefusal(text, undefined, readOnlyPrograms));
112
122
  }
113
123
  return null;
114
124
  }
@@ -119,12 +129,29 @@ confinement) {
119
129
  * reviewer's checks refused downloads, the plan's did not).
120
130
  */
121
131
  export function checkCommandRefusal(command, shell, cfg, confinement, env = process.env) {
122
- const refusal = commandRefusal(command, shell, cfg.denyPatterns, cfg.allowedPrograms, env, confinement);
132
+ const refusal = commandRefusal(command, shell, cfg.denyPatterns, cfg.allowedPrograms, env, confinement, cfg.readOnlyPrograms ?? []);
123
133
  if (refusal)
124
134
  return refusal;
135
+ const access = checkAccessRefusal(command, shell, cfg);
136
+ if (access)
137
+ return access;
125
138
  const network = networkFetchReason(command, confinement.cwd) ?? scriptNetworkReason(command, confinement.cwd);
126
139
  return network ? networkFetchRefusal(network) : null;
127
140
  }
141
+ /**
142
+ * A check reaching a platform with the operator's access, which a step puts to the operator every time (2026-10-26):
143
+ * a check has nobody to put it to, so it is refused unless Settings agree with what the bot proposes. A program set to
144
+ * read only passes with a command that only reads; one that cannot be read as reading is refused.
145
+ */
146
+ export function checkAccessRefusal(command, shell, cfg) {
147
+ const reading = readOnlyVerdict(command, shell, cfg.readOnlyPrograms);
148
+ if (reading?.kind === 'unclear')
149
+ return readOnlyUnclearRefusal(reading.program, reading.why);
150
+ const platform = cfg.questions === 'agree' ? null : platformReason(command, shell, reading?.kind === 'reads' ? new Set(reading.programs) : undefined);
151
+ if (!platform)
152
+ return null;
153
+ return `refused: this check reaches ${platform} with the operator's access, which only the operator may allow, and a check runs with nobody asked. Check it another way, or do it in a step, where it is put to the operator.`;
154
+ }
128
155
  /** A fetch inside a script the line runs — held or refused exactly as one on the line would be. */
129
156
  export function scriptNetworkReason(command, cwd) {
130
157
  let found = null;
@@ -185,7 +212,7 @@ export function staticCheck(step, cfg, env = process.env, confinement) {
185
212
  }
186
213
  // Screened against the shell that will actually read it: the traps in `shellExecuteTrap.ts`
187
214
  // are shell-specific, so screening for one interpreter and running in another finds nothing.
188
- const reason = commandRefusal(step.cmd, effectiveShell(step.shell), cfg.denyPatterns, cfg.allowedPrograms, env, confinement);
215
+ const reason = commandRefusal(step.cmd, effectiveShell(step.shell), cfg.denyPatterns, cfg.allowedPrograms, env, confinement, cfg.readOnlyPrograms ?? []);
189
216
  if (reason)
190
217
  return { action: 'skip', reason };
191
218
  /*
@@ -23,6 +23,7 @@
23
23
  import { createHash } from 'node:crypto';
24
24
  import { DANGEROUS_TECHNIQUES } from './dangerous.js';
25
25
  import { describeIsolation } from './isolation.js';
26
+ import { readOnlyCapable } from './readOnly.js';
26
27
  /** A short, stable digest of a list, order-independent so a reordered config is not a changed one. */
27
28
  export function digestOf(values) {
28
29
  // JSON rather than a separator character: unambiguous for any entry, and free of the control
@@ -46,6 +47,12 @@ export function networkFetchStatement(mode, choice = 'ask') {
46
47
  return `${FETCHES} RUNS WITHOUT ANYONE READING IT — the operator chose this (execution.networkFetch: run). Only the deny list and the built-in refusals applied`;
47
48
  return `${FETCHES} is held for the operator even in this unattended run (execution.networkFetch: ask); with nobody to ask it is refused. ${NOT_HELD}`;
48
49
  }
50
+ /** The programs set to read only that a rule reads and, with the gate on, the list names: the ones in force. */
51
+ function readOnlyInForce(readOnly, allowed) {
52
+ const capable = new Set(readOnlyCapable());
53
+ const listed = new Set(allowed.map((p) => p.trim().toLowerCase()));
54
+ return [...new Set(readOnly.map((p) => p.trim().toLowerCase()))].filter((p) => capable.has(p) && (listed.size === 0 || listed.has(p)));
55
+ }
49
56
  export function collectPolicyManifest(input, env = process.env) {
50
57
  const names = DANGEROUS_TECHNIQUES.map((t) => t.name);
51
58
  return {
@@ -59,6 +66,7 @@ export function collectPolicyManifest(input, env = process.env) {
59
66
  digest: digestOf(input.allowedPrograms),
60
67
  programs: [...input.allowedPrograms],
61
68
  },
69
+ readOnly: readOnlyInForce(input.readOnlyPrograms ?? [], input.allowedPrograms),
62
70
  chatFiles: 'the chat cannot supply a file: this runner has no file step and executes nothing it did not receive as a command',
63
71
  networkFetch: networkFetchStatement(input.mode, input.networkFetch),
64
72
  denyPatterns: { count: input.denyPatterns.length, digest: digestOf(input.denyPatterns) },
@@ -79,6 +87,7 @@ export function describePolicyManifest(m) {
79
87
  return [
80
88
  `mode : ${m.mode}${m.mode === 'unattended' ? ' (no person saw the steps as they ran)' : ' (a person approved each step)'}`,
81
89
  `allowlist : ${m.allowlist.enforced ? `${m.allowlist.count} programs, digest ${m.allowlist.digest}` : 'NOT ENFORCED — any program could be started'}`,
90
+ `read only : ${m.readOnly.length ? `${m.readOnly.join(', ')} — a command that changes something, signs in or out or shows a secret is refused` : 'none'}`,
82
91
  `chat files : ${m.chatFiles}`,
83
92
  `downloads : ${m.networkFetch}`,
84
93
  `deny list : ${m.denyPatterns.count} patterns, digest ${m.denyPatterns.digest}`,
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Programs set to read only (operator, 2026-10-26: "give the bot az, with me signing in myself and the bot never
3
+ * learning my credentials; but it is important that it runs without writing, for reference only"). A program on the
4
+ * allowlist that reaches a platform with the operator's access is put to the operator on every command
5
+ * (`platforms.ts`). Set to read only, its commands are read by their own words instead:
6
+ *
7
+ * reads `az vm list`, `az group show`, `az graph query`: run without a card, as any other command does
8
+ * refused a change (create, delete, update, start, deploy…), a sign-in or sign-out, a secret shown (keys, tokens,
9
+ * connection strings, app settings), `az rest`, a download: sent back to the chat with why
10
+ * unclear a verb known neither way, a word known only when it runs, or the program named where it is not run
11
+ * directly (a string, `cmd /c`, `Start-Process`): held on a card in every mode, even when Settings agree
12
+ * with what the bot proposes, since the operator said this program must not write
13
+ *
14
+ * The sign-in is the operator's own: `az login` in their terminal. The bot's commands use it as it is and never see a
15
+ * password, which Microsoft's own window takes. The bot never signs in or out, and az's token cache is outside the
16
+ * project, where no command may reach (`confinement.ts`).
17
+ *
18
+ * The honest limit, the same as everywhere in this folder: this reads the command line. A program the project contains,
19
+ * such as a script that calls Azure's API, is not seen. What makes "read only" true is the account: one with only the
20
+ * Reader role has Azure itself refuse every change.
21
+ */
22
+ import { scanCommandHeads } from './commandHeads.js';
23
+ import { externalProgram } from './programs.js';
24
+ /** The programs whose commands can be told apart, reading from changing, each by its own rule. */
25
+ const RULES = { az: azReading };
26
+ /** The programs that may be set to read only: the ones with a rule. */
27
+ export function readOnlyCapable() {
28
+ return Object.keys(RULES);
29
+ }
30
+ const normalise = (p) => p.trim().toLowerCase().replace(/\.(exe|cmd|bat|com)$/i, '');
31
+ /**
32
+ * What a line does with the programs set to read only, or null when it starts none of them. Refused at the first
33
+ * invocation that changes something; unclear when one cannot be read, or when a program is named more often than the
34
+ * line runs it directly — the rest of its mentions are where its words cannot be read.
35
+ */
36
+ export function readOnlyVerdict(command, shell, readOnlyPrograms) {
37
+ const set = new Set((readOnlyPrograms ?? []).map(normalise).filter((p) => p in RULES));
38
+ if (set.size === 0)
39
+ return null;
40
+ const scan = scanCommandHeads(command, shell ?? 'pwsh');
41
+ const runs = new Map();
42
+ const programs = [];
43
+ let unclear = null;
44
+ for (const call of scan.calls) {
45
+ const program = externalProgram(call.head);
46
+ if (!program || !set.has(program))
47
+ continue;
48
+ runs.set(program, (runs.get(program) ?? 0) + 1);
49
+ const r = RULES[program](call.args);
50
+ if (r.kind === 'refused')
51
+ return r;
52
+ if (r.kind === 'unclear')
53
+ unclear ??= { program, why: r.why };
54
+ else if (!programs.includes(program))
55
+ programs.push(program);
56
+ }
57
+ for (const program of set) {
58
+ if (mentions(command, program) > (runs.get(program) ?? 0)) {
59
+ unclear ??= { program, why: `${program} is named where its words cannot be read (in a string, a nested shell, Start-Process or a name built at run time)` };
60
+ }
61
+ }
62
+ if (unclear)
63
+ return { kind: 'unclear', ...unclear };
64
+ return programs.length > 0 ? { kind: 'reads', programs } : null;
65
+ }
66
+ /** Why a line must not run because a program set to read only would change something, or null. */
67
+ export function readOnlyRefusal(command, shell, readOnlyPrograms) {
68
+ const v = readOnlyVerdict(command, shell, readOnlyPrograms);
69
+ return v?.kind === 'refused' ? v.reason : null;
70
+ }
71
+ /**
72
+ * The same for the text of a script the line runs, and for a check, which run with nobody asked: a command that cannot
73
+ * be read as only reading has nobody to put it to, so it is refused as well.
74
+ */
75
+ export function readOnlyUnaskedRefusal(command, shell, readOnlyPrograms) {
76
+ const v = readOnlyVerdict(command, shell, readOnlyPrograms);
77
+ if (v?.kind === 'refused')
78
+ return v.reason;
79
+ if (v?.kind === 'unclear')
80
+ return readOnlyUnclearRefusal(v.program, v.why);
81
+ return null;
82
+ }
83
+ /** What the chat is told of a command that could not be read as only reading and had nobody to ask. */
84
+ export function readOnlyUnclearRefusal(program, why) {
85
+ return (`refused: ${program} is set to read only here, and this could not be read as only reading (${why}); ` +
86
+ `nobody is there to judge it. Call ${program} directly on the step's own line, with a command that only reads — list, show or query.`);
87
+ }
88
+ /** How many times the line names the program as a word of its own: `az`, `az.cmd`, `'az'`; not `az.txt` or `lazy`. */
89
+ function mentions(command, program) {
90
+ const name = program.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
91
+ return command.match(new RegExp(`(?<![\\w.\\\\/$@-])${name}(?:\\.(?:cmd|exe|bat))?(?![\\w.\\\\/-])`, 'gi'))?.length ?? 0;
92
+ }
93
+ // ------------------------------------------------------------------------------------------
94
+ // az
95
+ // ------------------------------------------------------------------------------------------
96
+ /** A word of the command that shows a secret: keys, tokens, passwords, connection strings, app settings. */
97
+ const AZ_SECRET = /(?:^|-)(?:keys?|credentials?|secrets?|passwords?|tokens?|sas|connection-strings?|appsettings|publishing-profiles?|kubeconfig)(?:$|-)/;
98
+ /** The verbs that only read. `get-…`, `list-…` and `show-…` after the secrets are taken out. */
99
+ const AZ_READ = /^(?:list|show|query|exists|wait|version|what-if|(?:list|show|get)-[a-z0-9-]+|check-name(?:-availability)?)$/;
100
+ /** The verbs that change something, in Azure or in az's own setup; and the ones named after them (`create-for-rbac`). */
101
+ const AZ_WRITE = /^(?:create|delete|update|set|unset|add|remove|start|stop|restart|reboot|deploy|redeploy|reimage|deallocate|generalize|capture|resize|scale|swap|assign|unassign|purge|recover|restore|backup|renew|regenerate|rotate|reset|import|upload|sync|move|lock|unlock|enable|disable|approve|reject|attach|detach|connect|disconnect|apply|cancel|abort|run|invoke|execute|install|uninstall|register|unregister|grant|revoke|push|tag|untag|migrate|upgrade|failover|promote|convert|link|unlink|clear|flush|cordon|drain|retry|rerun|trigger|publish|release|merge|close|reopen|accept|archive|unarchive|schedule|power-off|rollback|repair|refresh|replace|rename|copy|patch|put|post|send|mount|unmount|activate|deactivate|pause|resume|suspend|terminate|kill)(?:-[a-z0-9-]+)?$/;
102
+ /**
103
+ * One `az` invocation. Its command is the group path and the verb at its end, the words before the first option:
104
+ * `az storage account list --query ...` is `storage account list`, read by `list`. `--help` anywhere only prints help.
105
+ */
106
+ function azReading(args) {
107
+ if (args.some((a) => !a.dynamic && /^(?:--help|-h)$/i.test(a.literal)))
108
+ return { kind: 'reads' };
109
+ const path = [];
110
+ for (const a of args) {
111
+ if (a.dynamic)
112
+ return { kind: 'unclear', why: 'a word of the az command is known only when it runs' };
113
+ if (a.literal.startsWith('-'))
114
+ break;
115
+ path.push(a.literal.toLowerCase());
116
+ }
117
+ // `az`, `az --version`: nothing but the version or the help.
118
+ if (path.length === 0)
119
+ return { kind: 'reads' };
120
+ const p = path.join(' ');
121
+ if (path[0] === 'rest') {
122
+ return { kind: 'refused', reason: 'refused: "az rest" sends any request to Azure, one that changes something too, and az is set to read only here. Use the resource\'s own list, show or query command.' };
123
+ }
124
+ if (path.some((w) => w === 'login' || w === 'logout')) {
125
+ return {
126
+ kind: 'refused',
127
+ reason: `refused: "az ${p}" signs in or out. The operator signs in with az login themselves; the bot uses that sign-in as it is and never signs in, out or as anyone else. If az says nobody is signed in, end blocked and say so in notes.`,
128
+ };
129
+ }
130
+ if (path[0] === 'account' && (path[1] === 'set' || path[1] === 'clear')) {
131
+ return { kind: 'refused', reason: `refused: "az account ${path[1]}" changes the subscription the operator's own az uses. Name it on the command instead: --subscription <name or id>.` };
132
+ }
133
+ if (path[0] === 'interactive' || path[0] === 'init') {
134
+ return { kind: 'refused', reason: `refused: "az ${p}" waits for a person to type, and nobody types into a step. Run the command itself.` };
135
+ }
136
+ if (path.some((w) => AZ_SECRET.test(w))) {
137
+ return {
138
+ kind: 'refused',
139
+ reason: `refused: "az ${p}" shows a secret (a key, a token, a password, a connection string or app settings), and az is set to read only here: what a step prints goes to the chat. Read the resource with show or list, which leave the secrets out.`,
140
+ };
141
+ }
142
+ // `az find "<words>"` takes what it looks for after it; every other command ends at its verb.
143
+ if (path[0] === 'find')
144
+ return { kind: 'reads' };
145
+ const verb = path.at(-1);
146
+ if (/^download(?:-|$)/.test(verb)) {
147
+ return { kind: 'refused', reason: `refused: "az ${p}" downloads a file, and the bot does not download files; az is set to read only here. Read with list, show or query.` };
148
+ }
149
+ if (AZ_WRITE.test(verb)) {
150
+ return {
151
+ kind: 'refused',
152
+ reason: `refused: "az ${p}" changes something, and az is set to read only here (for reference): its commands may look, never change. Read with list, show or query; if something has to change, say in notes what and leave it to the operator.`,
153
+ };
154
+ }
155
+ if (AZ_READ.test(verb))
156
+ return { kind: 'reads' };
157
+ return { kind: 'unclear', why: `"az ${p}" is not known as only reading` };
158
+ }
@@ -35,7 +35,7 @@ import { describeCrash } from '../transport/edgeCrash.js';
35
35
  import { runReview, findingsMessage, deliverableFor } from './review.js';
36
36
  import { allAboutTheTask, isRepeat, findingId } from '../protocol/reviewSchema.js';
37
37
  import { repoState, workingTreePaths } from '../vcs/git.js';
38
- import { describeStep, checkCommandRefusal, commandRefusal, staticCheck } from '../exec/policy.js';
38
+ import { describeStep, checkAccessRefusal, checkCommandRefusal, commandRefusal, staticCheck } from '../exec/policy.js';
39
39
  import { networkFetchReason } from '../exec/network.js';
40
40
  import { collectPolicyManifest, describePolicyManifest } from '../exec/policyManifest.js';
41
41
  import { assessIsolation, readIsolationSignals } from '../exec/isolation.js';
@@ -129,8 +129,9 @@ export function checkRefusalForOperator(why) {
129
129
  return text;
130
130
  }
131
131
  export function lineRefusal(command, shell, cwd, cfg, roots) {
132
- return (commandRefusal(command, shell, cfg.denyPatterns, cfg.allowedPrograms) ??
132
+ return (commandRefusal(command, shell, cfg.denyPatterns, cfg.allowedPrograms, process.env, undefined, cfg.readOnlyPrograms ?? []) ??
133
133
  confinementRefusal(command, { roots, cwd }) ??
134
+ checkAccessRefusal(command, shell, cfg) ??
134
135
  (PACKAGE_RUNNER.test(command) ? null : networkFetchReason(command, cwd)));
135
136
  }
136
137
  /**
@@ -1551,6 +1552,7 @@ export async function runTask(transport, session, task, deps) {
1551
1552
  mode: deps.currentMode?.() ?? cfg.execution.mode,
1552
1553
  networkFetch: cfg.execution.networkFetch,
1553
1554
  allowedPrograms: cfg.execution.allowedPrograms,
1555
+ readOnlyPrograms: cfg.execution.readOnlyPrograms,
1554
1556
  denyPatterns: cfg.execution.denyPatterns,
1555
1557
  cwd: work.cwd,
1556
1558
  lock: cfg.policyLock,
@@ -165,6 +165,7 @@ You are **Kerrigan**. You help the person talking to you get their work done wit
165
165
  - copilot-operator **runs those commands on the machine, in the project folder**, and sends back what they printed. Round after round, until Copilot says the task is **done** (with a summary of what it did), or **blocked** (with what it tried and what it needs), or a limit is reached.
166
166
  - Copilot learns the project only through those commands: it lists files, reads them, runs the build and the tests. It is not sent the files themselves, and it knows nothing about the project that the task does not say and the commands cannot find.
167
167
  - The person chooses how commands run in Settings, under ${Q('exec.startMode')} (not in the chat): ${Q('exec.startModeAsk')} (they press ${Q('chat.askRun')}, ${Q('chat.askRunAll')} or ${Q('chat.askSkip')} on a card that says who asks) or ${Q('exec.startModeAuto')}. A list of forbidden commands applies either way; pushing to a remote is refused; nothing needs administrator rights. A command that reaches a platform with the person's own access — Azure, AWS, GitHub, Jira, publishing a package and the like — waits on a card even in a run without asking, unless ${Q('exec.questions')} in Settings is set to agree with what the bot proposes; so do the questions the chat or the lead asks, with their answers to click. Once one answer on a card is pressed, the card's other answers and its text box turn off and the one pressed stays marked until the card goes; only when the answer did not reach the program do they come back on, with the reason on the card.
168
+ - The programs a command may start are listed in Settings, under "Programs the bot may start": the person adds one by its name (${Q('prog.add')}, ${Q('prog.addButton')}) and takes one off with its ✕; a command that starts a program not on the list is refused, and the chat is told why. A program that reaches a platform with their access is set to ${Q('prog.modeAsk')}, or, for az, to ${Q('prog.modeReadOnly')}: az's commands that only look (list, show, query) then run without a card, the ones that create, change, delete, sign in or out, or show a secret are refused, and one the program cannot read waits on a card. The person signs in themselves, with az login in their own terminal; the program uses that sign-in and never sees the password. The program reads the command line and a script could go round it, so for a guarantee they sign in with an account that has only the Reader role in Azure, and Azure itself refuses every change.
168
169
  - The model: ${Q('chat.model')} under the chat's box. When it is to be chosen by hand (the default), a card asks the person to choose the model in the Copilot window and press ${Q('approval.manualReady')}.
169
170
  - ${Q('chat.planMode')} (a choice under the chat's box): Copilot first looks at the project with read-only commands and proposes a plan — what is there, how it means to do it, the stages, the files, how it will show it works — and nothing is changed until the person approves the plan (${Q('pm.approve')}), asks for another (${Q('pm.revise')}), or stops.
170
171
  - ${Q('chat.review')} (under the chat's box, on unless unticked): when Copilot says the work is done, a conversation of its own reviews it — reads the changes, runs the checks — and sends back what it finds, up to ${n(rounds)} round(s) of fixing. When the model is chosen by hand, the card for the review's model says it is the review's: a different, stronger model than the one that did the work catches more mistakes.
@@ -246,7 +247,8 @@ function bgText(f) {
246
247
  - Човекът пише задание в чата, за **папката на проекта**, отворена там. Програмата го изпраща на **Microsoft 365 Copilot** (служебен акаунт) в прозорец на Edge, който отваря и държи отворен между съобщенията; когато работата по съобщение свърши, карта в този прозорец го казва, с бутон „ОК“. Copilot не може сам да пипа машината: отговаря с **команди на PowerShell**, в определен вид JSON.
247
248
  - copilot-operator **изпълнява тези команди на машината, в папката на проекта**, и връща какво са изписали. Кръг след кръг, докато Copilot каже, че заданието е **готово** (с обобщение на направеното), или **блокирано** (с какво е опитал и какво му трябва), или се стигне ограничение.
248
249
  - Copilot опознава проекта само чрез тези команди: изброява файлове, чете ги, пуска компилацията и тестовете. Самите файлове не му се изпращат и той не знае за проекта нищо, което заданието не казва и командите не могат да намерят.
249
- - Човекът избира как се изпълняват командите в Настройки, при ${Q('exec.startMode')} (не в чата): ${Q('exec.startModeAsk')} (натиска ${Q('chat.askRun')}, ${Q('chat.askRunAll')} или ${Q('chat.askSkip')} на карта, на която пише кой иска) или ${Q('exec.startModeAuto')}. И в двата случая важи списък със забранени команди; изпращането към отдалечено хранилище (push) се отказва; нищо не изисква администраторски права. Команда, която достъпва платформа със собствения достъп на човека — Azure, AWS, GitHub, Jira, публикуване на пакет и подобни, — чака на карта дори при пускане без питане, освен ако ${Q('exec.questions')} в Настройки не е настроено да се съгласява с това, което предлага ботът; същото важи за въпросите на чата или на ръководителя, с отговори за избор.
250
+ - Човекът избира как се изпълняват командите в Настройки, при ${Q('exec.startMode')} (не в чата): ${Q('exec.startModeAsk')} (натиска ${Q('chat.askRun')}, ${Q('chat.askRunAll')} или ${Q('chat.askSkip')} на карта, на която пише кой иска) или ${Q('exec.startModeAuto')}. И в двата случая важи списък със забранени команди; изпращането към отдалечено хранилище (push) се отказва; нищо не изисква администраторски права. Команда, която достъпва платформа със собствения достъп на човека — Azure, AWS, GitHub, Jira, публикуване на пакет и подобни, — чака на карта дори при пускане без питане, освен ако ${Q('exec.questions')} в Настройки не е настроено да се съгласява с това, което предлага ботът; същото важи за въпросите на чата или на ръководителя, с отговори за избор. Щом се натисне един отговор на карта, другите отговори и полето за текст на картата се изключват, а натиснатият остава отбелязан, докато картата изчезне; включват се отново само ако отговорът не е стигнал до програмата, с причината на картата.
251
+ - Програмите, които командата може да пуска, са изброени в Настройки, при „Програми, които ботът може да пуска“: човекът добавя програма по името ѝ (${Q('prog.add')}, ${Q('prog.addButton')}) и маха програма с нейното ✕; команда, която пуска програма извън списъка, се отказва и на чата се казва защо. Програма, която достъпва платформа с неговия достъп, е на ${Q('prog.modeAsk')} или, за az, на ${Q('prog.modeReadOnly')}: тогава командите на az, които само гледат (list, show, query), се изпълняват без карта, тези, които създават, променят, трият, влизат или излизат, или показват тайна, се отказват, а такава, която програмата не може да разчете, чака на карта. Човекът влиза сам, с az login в собствения си терминал; програмата ползва този вход и никога не вижда паролата. Програмата чете командния ред и скрипт би могъл да го заобиколи, затова за гаранция той влиза с акаунт, който има само ролята Reader в Azure, и тогава самият Azure отказва всяка промяна.
250
252
  - Моделът: ${Q('chat.model')} под полето на чата. Когато се избира ръчно (по подразбиране), карта моли човека да избере модела в прозореца на Copilot и да натисне ${Q('approval.manualReady')}.
251
253
  - ${Q('chat.planMode')} (избор под полето на чата): Copilot първо разглежда проекта само с команди, които четат, и предлага план — какво има, как смята да го направи, етапите, файловете, как ще покаже, че работи, — и нищо не се променя, докато човекът не одобри плана (${Q('pm.approve')}), не поиска друг (${Q('pm.revise')}) или не спре.
252
254
  - ${Q('chat.review')} (под полето на чата, включена, освен ако не я изключат): когато Copilot каже, че работата е готова, отделен разговор я преглежда — чете промените, пуска проверките — и връща каквото открие, до ${n(rounds)} кръга поправка. Когато моделът се избира ръчно, картата за модела на рецензията казва, че е за нея: модел, различен и по-силен от този, с който е работено, хваща повече грешки.