copilot-operator 0.1.66 → 0.1.68

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 (61) hide show
  1. package/dist/src/api/operator.controller.js +9 -2
  2. package/dist/src/api/operator.service.js +23 -7
  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 +32 -5
  9. package/dist/src/exec/policyManifest.js +9 -0
  10. package/dist/src/exec/readOnly.js +158 -0
  11. package/dist/src/exec/scriptFiles.js +91 -9
  12. package/dist/src/orchestrator/handoff.js +79 -0
  13. package/dist/src/orchestrator/taskRunner.js +43 -2
  14. package/dist/src/plan/kerrigan.js +5 -1
  15. package/dist/src/plan/systemGuide.js +95 -0
  16. package/dist/src/protocol/parser.js +2 -2
  17. package/dist/src/protocol/replySchema.js +23 -2
  18. package/dist/src/queue/queue.js +6 -0
  19. package/dist/web/404.html +2 -2
  20. package/dist/web/_next/static/chunks/1024-e4e596b184e05e91.js +1 -0
  21. package/dist/web/_next/static/chunks/1077.61be1f7b74828a4c.js +1 -0
  22. package/dist/web/_next/static/chunks/1548.a112748131a396ed.js +1 -0
  23. package/dist/web/_next/static/chunks/2163.581b2e067fe95eb3.js +1 -0
  24. package/dist/web/_next/static/chunks/714.5cc35e9440591fd9.js +1 -0
  25. package/dist/web/_next/static/chunks/7220.9313ff4ad7480f12.js +1 -0
  26. package/dist/web/_next/static/chunks/7921-19f36659bdea8d09.js +1 -0
  27. package/dist/web/_next/static/chunks/8124-1952612d3a681879.js +1 -0
  28. package/dist/web/_next/static/chunks/8584.5ff9e8c49bf9b259.js +1 -0
  29. package/dist/web/_next/static/chunks/9067.f0db4983b81a2df6.js +1 -0
  30. package/dist/web/_next/static/chunks/9747.0e0c54e5f8fab6c4.js +1 -0
  31. package/dist/web/_next/static/chunks/app/page-18954867735bf8c0.js +1 -0
  32. package/dist/web/_next/static/chunks/app/settings/page-7d120feb5af0ace9.js +1 -0
  33. package/dist/web/_next/static/chunks/{webpack-5ea108bc2e386c55.js → webpack-a3dd4e873378e9ae.js} +1 -1
  34. package/dist/web/_next/static/css/{a112074f3d1a8a07.css → 45da8a97dbf20586.css} +1 -1
  35. package/dist/web/defaults.html +2 -2
  36. package/dist/web/defaults.txt +8 -8
  37. package/dist/web/index.html +3 -3
  38. package/dist/web/index.txt +9 -9
  39. package/dist/web/queue.html +2 -2
  40. package/dist/web/queue.txt +9 -9
  41. package/dist/web/settings.html +2 -2
  42. package/dist/web/settings.txt +9 -9
  43. package/dist/web/system.html +2 -2
  44. package/dist/web/system.txt +9 -9
  45. package/package.json +4 -2
  46. package/prompts/level1.md +53 -14
  47. package/dist/web/_next/static/chunks/1024-444e9060299d04ba.js +0 -1
  48. package/dist/web/_next/static/chunks/1077.b88b069535f7008e.js +0 -1
  49. package/dist/web/_next/static/chunks/1548.9e01803e48173ea9.js +0 -1
  50. package/dist/web/_next/static/chunks/2163.018cd5f719ae4b3d.js +0 -1
  51. package/dist/web/_next/static/chunks/714.281f68f85df26013.js +0 -1
  52. package/dist/web/_next/static/chunks/7220.3bd10a3e4e053e0c.js +0 -1
  53. package/dist/web/_next/static/chunks/7921-1c173d00d23b3589.js +0 -1
  54. package/dist/web/_next/static/chunks/8124-bb544c96a7c0e7e3.js +0 -1
  55. package/dist/web/_next/static/chunks/8584.c7cd52c2e7075bcb.js +0 -1
  56. package/dist/web/_next/static/chunks/9067.feaf894390db1a88.js +0 -1
  57. package/dist/web/_next/static/chunks/9747.7cee8a2d8301f25c.js +0 -1
  58. package/dist/web/_next/static/chunks/app/page-95379244849623fc.js +0 -1
  59. package/dist/web/_next/static/chunks/app/settings/page-9a83381087178f80.js +0 -1
  60. /package/dist/web/_next/static/{BbWvNQTsh3pH7ZN_RKR60 → 52rfiQXdaggycbuMIIw4K}/_buildManifest.js +0 -0
  61. /package/dist/web/_next/static/{BbWvNQTsh3pH7ZN_RKR60 → 52rfiQXdaggycbuMIIw4K}/_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);
@@ -392,7 +399,7 @@ let OperatorController = class OperatorController {
392
399
  }
393
400
  /** The lead's question (two chats): the operator's answer, as text. Stopping the task is `approvals/:id` with abort. */
394
401
  answerQuestion(id, body) {
395
- const result = this.ops.answerQuestion(id, typeof body?.text === 'string' ? body.text : '');
402
+ const result = this.ops.answerQuestion(id, typeof body?.text === 'string' ? body.text : '', body?.ran === false ? false : undefined);
396
403
  if (!result.ok)
397
404
  throw new BadRequestException(result.problem);
398
405
  return result;
@@ -24,6 +24,7 @@ import { checkItems, emptyQueue, itemTitle, mergeItems, nextStep, parkAfterMs, p
24
24
  import { branchStart, makeQueueBranch, refreshQueueBranch } from '../queue/queueBranch.js';
25
25
  import { EventBus } from '../session/events.js';
26
26
  import { MAX_INSTRUCTION_CHARS, newId } from '../session/model.js';
27
+ import { handoffResultMessage } from '../orchestrator/handoff.js';
27
28
  import { runSession, queuedToRun, failedWhileOpening, pickerOptions } from '../orchestrator/taskRunner.js';
28
29
  import { Hold } from '../orchestrator/hold.js';
29
30
  import { exportFileName, exportMachine, writeAttemptRecord } from '../session/exports.js';
@@ -847,6 +848,7 @@ let OperatorService = class OperatorService {
847
848
  // Read once per run like the rest of the policy: a change in Settings applies from the next start.
848
849
  networkFetch: cfg.execution.networkFetch,
849
850
  platformAccess: cfg.execution.questions === 'agree' ? 'allow' : 'ask',
851
+ readOnlyPrograms: cfg.execution.readOnlyPrograms,
850
852
  };
851
853
  /*
852
854
  * An unattended run that cannot legally execute anything is stopped here, where the operator
@@ -1874,7 +1876,8 @@ let OperatorService = class OperatorService {
1874
1876
  }
1875
1877
  }
1876
1878
  else if (a.kind === 'question') {
1877
- note = `You asked: ${p.approval.question?.text ?? ''}\n\nThe operator answers: ${a.answer}`;
1879
+ const handed = p.approval.question?.handoff;
1880
+ note = handed ? handoffResultMessage(handed, a.ran !== false, a.answer) : `You asked: ${p.approval.question?.text ?? ''}\n\nThe operator answers: ${a.answer}`;
1878
1881
  }
1879
1882
  else if (a.kind === 'retry' && p.approval.retry) {
1880
1883
  const r = p.approval.retry;
@@ -2070,11 +2073,19 @@ let OperatorService = class OperatorService {
2070
2073
  sessionId: ask.sessionId,
2071
2074
  taskId: ask.taskId,
2072
2075
  stepId: 0,
2073
- description: `${(ask.actor ?? 'lead') === 'lead' ? 'The lead asks' : 'The chat asks'}: ${ask.question}`,
2076
+ description: ask.handoff
2077
+ ? `The chat hands over commands to run yourself: ${ask.handoff.commands.join(' ; ')}`
2078
+ : `${(ask.actor ?? 'lead') === 'lead' ? 'The lead asks' : 'The chat asks'}: ${ask.question}`,
2074
2079
  createdAt: new Date().toISOString(),
2075
2080
  // The lead's, or since 2026-10-23 the chat's own (plan mode's or the worker's).
2076
2081
  actor: ask.actor ?? 'lead',
2077
- question: { text: ask.question, ...(ask.why ? { why: ask.why } : {}), options: ask.options, ...(ask.commands?.some(Boolean) ? { commands: ask.commands } : {}) },
2082
+ question: {
2083
+ text: ask.question,
2084
+ ...(ask.why ? { why: ask.why } : {}),
2085
+ options: ask.options,
2086
+ ...(ask.commands?.some(Boolean) ? { commands: ask.commands } : {}),
2087
+ ...(ask.handoff ? { handoff: ask.handoff } : {}),
2088
+ },
2078
2089
  };
2079
2090
  this.waiting.set(approval.id, {
2080
2091
  approval,
@@ -2156,14 +2167,18 @@ let OperatorService = class OperatorService {
2156
2167
  const cfg = await this.settings.load();
2157
2168
  return await this.start(threadId, cfg.execution.mode);
2158
2169
  }
2159
- answerQuestion(approvalId, text) {
2170
+ answerQuestion(approvalId, text, ran) {
2160
2171
  const w = this.waiting.get(approvalId);
2161
2172
  if (!w?.resolveAnswer)
2162
2173
  return { ok: false, problem: 'No question of the lead is waiting under that id.' };
2163
- if (!text.trim())
2174
+ // Commands handed over (2026-10-26): what they printed, or that the operator did not run them, with a word or none.
2175
+ const handed = !!w.approval.question?.handoff;
2176
+ if (handed && ran !== false && !text.trim())
2177
+ return { ok: false, problem: 'Paste what the commands printed first.' };
2178
+ if (!handed && !text.trim())
2164
2179
  return { ok: false, problem: 'Write the answer first.' };
2165
2180
  this.waiting.delete(approvalId);
2166
- w.resolveAnswer({ answer: text.trim() });
2181
+ w.resolveAnswer(handed ? { answer: text.trim(), ran: ran !== false } : { answer: text.trim() });
2167
2182
  this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-decided', level: 'info',
2168
2183
  message: 'the operator answered the lead', data: { approvalId, question: true } });
2169
2184
  return { ok: true };
@@ -2340,12 +2355,13 @@ let OperatorService = class OperatorService {
2340
2355
  ...(ctx.actor ? { actor: ctx.actor } : {}),
2341
2356
  ...(held?.network ? { network: held.network } : {}),
2342
2357
  ...(held?.platform ? { platform: held.platform } : {}),
2358
+ ...(held?.readOnly ? { readOnly: held.readOnly } : {}),
2343
2359
  };
2344
2360
  this.waiting.set(approval.id, { approval, resolve: resolvePromise });
2345
2361
  this.parkLater(approval);
2346
2362
  this.bus.publish({ sessionId: approval.sessionId, taskId: approval.taskId, type: 'approval-requested', level: 'warn',
2347
2363
  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}`
2364
+ ? `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
2365
  : `waiting for approval: ${approval.description}`,
2350
2366
  data: { ...approval } });
2351
2367
  }), 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;
@@ -179,13 +206,13 @@ export function staticCheck(step, cfg, env = process.env, confinement) {
179
206
  * a script in one step and run it in the next. See `scriptFiles.ts`.
180
207
  */
181
208
  if (confinement) {
182
- const own = ownScriptRefusal(step.cmd, confinement.cwd, confinement.workStartedAt);
209
+ const own = ownScriptRefusal(step.cmd, confinement.cwd, confinement.workStartedAt, effectiveShell(step.shell));
183
210
  if (own)
184
211
  return { action: 'skip', reason: own };
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
+ }