@clagentic/console 1.10.0 → 1.11.0-beta.2

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 (97) hide show
  1. package/README.md +14 -1
  2. package/bin/cli.js +38 -16
  3. package/lib/agents.js +1 -55
  4. package/lib/bash-auto-approve.js +133 -0
  5. package/lib/build-identity.js +23 -5
  6. package/lib/build-sha.json +2 -2
  7. package/lib/build-update-check.js +0 -62
  8. package/lib/build-update-offer.js +23 -13
  9. package/lib/build-update-restart.js +59 -43
  10. package/lib/cli/arg-validation.js +50 -0
  11. package/lib/cli/daemon-launch.js +5 -4
  12. package/lib/cli/menus.js +2 -2
  13. package/lib/cli/schedule-input-subcommands.js +327 -0
  14. package/lib/cli/session-subcommands.js +101 -17
  15. package/lib/client-build-id.js +56 -0
  16. package/lib/daemon.js +38 -6
  17. package/lib/identity/index.js +9 -4
  18. package/lib/injected-sender.js +225 -0
  19. package/lib/message-sender-record.js +133 -0
  20. package/lib/pending-prompts.js +55 -0
  21. package/lib/permission-mode-policy.js +63 -0
  22. package/lib/permission-settings.js +96 -0
  23. package/lib/permission-summary.js +67 -0
  24. package/lib/project-connection.js +10 -11
  25. package/lib/project-external-trigger.js +9 -1
  26. package/lib/project-loop.js +50 -23
  27. package/lib/project-permission-settings.js +59 -0
  28. package/lib/project-prompt-responses.js +25 -15
  29. package/lib/project-sessions.js +164 -60
  30. package/lib/project-user-message.js +18 -47
  31. package/lib/project.js +46 -74
  32. package/lib/public/app.js +4 -7
  33. package/lib/public/css/channel-layout.css +20 -0
  34. package/lib/public/css/diagnostics.css +7 -0
  35. package/lib/public/css/input.css +78 -0
  36. package/lib/public/css/menus.css +17 -0
  37. package/lib/public/css/overlays.css +0 -3
  38. package/lib/public/css/scheduler-modal.css +5 -0
  39. package/lib/public/index.html +44 -8
  40. package/lib/public/modules/app-connection.js +18 -1
  41. package/lib/public/modules/app-loop-ui.js +11 -1
  42. package/lib/public/modules/app-messages.js +23 -30
  43. package/lib/public/modules/app-panels.js +10 -3
  44. package/lib/public/modules/app-rate-limit.js +64 -88
  45. package/lib/public/modules/app-rendering.js +37 -6
  46. package/lib/public/modules/approve-tools-toggle.js +33 -0
  47. package/lib/public/modules/at-agents.js +8 -0
  48. package/lib/public/modules/build-guard.js +61 -0
  49. package/lib/public/modules/build-update-detail.js +1 -4
  50. package/lib/public/modules/diagnostics.js +98 -9
  51. package/lib/public/modules/injected-identity.js +78 -0
  52. package/lib/public/modules/injected-label.js +62 -0
  53. package/lib/public/modules/input.js +64 -114
  54. package/lib/public/modules/loop-hooks-warning.js +20 -0
  55. package/lib/public/modules/mode-options.js +35 -16
  56. package/lib/public/modules/permission-settings.js +56 -0
  57. package/lib/public/modules/project-settings.js +3 -0
  58. package/lib/public/modules/rate-limit-state.js +47 -22
  59. package/lib/public/modules/schedule-panel.js +234 -0
  60. package/lib/public/modules/schedule-time.js +193 -0
  61. package/lib/public/modules/scheduled-input-actions.js +19 -0
  62. package/lib/public/modules/scheduler-config.js +12 -0
  63. package/lib/public/modules/scheduler.js +8 -0
  64. package/lib/public/modules/server-settings.js +5 -9
  65. package/lib/public/modules/settings-defaults.js +18 -4
  66. package/lib/runtime-env.js +4 -0
  67. package/lib/scheduled-input/ipc.js +92 -0
  68. package/lib/scheduled-input/rate-limit-resume.js +53 -0
  69. package/lib/scheduled-input/records.js +350 -0
  70. package/lib/scheduled-input/service.js +743 -0
  71. package/lib/scheduled-input/store.js +132 -0
  72. package/lib/scheduled-input/ws.js +194 -0
  73. package/lib/scheduler.js +4 -0
  74. package/lib/sdk-bridge.js +194 -175
  75. package/lib/sdk-message-processor.js +13 -5
  76. package/lib/sdk-skill-discovery.js +17 -0
  77. package/lib/sender-ref.js +109 -0
  78. package/lib/server.js +37 -11
  79. package/lib/session-directory.js +224 -0
  80. package/lib/session-file-scan.js +55 -0
  81. package/lib/session-input-ipc.js +21 -0
  82. package/lib/session-input.js +396 -23
  83. package/lib/session-name-holder.js +82 -0
  84. package/lib/session-resume.js +3 -0
  85. package/lib/sessions.js +111 -2
  86. package/lib/turn-initiator.js +6 -2
  87. package/lib/updater.js +8 -2
  88. package/lib/ws-schema.js +20 -9
  89. package/lib/yoke/adapters/claude-worker.js +3 -1
  90. package/lib/yoke/adapters/claude.js +13 -17
  91. package/lib/yoke/adapters/codex.js +18 -5
  92. package/lib/yoke/adapters/permission-relay.js +9 -0
  93. package/lib/yoke/interface.js +7 -1
  94. package/package.json +1 -1
  95. package/scripts/check-test-count.js +1 -1
  96. package/scripts/install-local-test.js +45 -1
  97. package/scripts/postinstall.js +1 -0
package/README.md CHANGED
@@ -16,6 +16,18 @@
16
16
 
17
17
  Clagentic: Console is a self-hosted team workspace where human developers and named AI agents share the same interface. Multiple users connect to a single daemon, each with their own account and project access. Agents are first-class participants — not background processes you poll, but named entities with their own conversation history, context window, and session state, visible to the whole team. Every project, every session, every tool approval lives on your machine and stays there.
18
18
 
19
+ ## Agents are first-class users
20
+
21
+ Agents do not need a browser. From a shell, or from inside a console session, an agent can:
22
+
23
+ - **Open sessions:** `clagentic-console open-session --to reviewer@my-project --prompt "Review the open change."`
24
+ - **Message sessions:** `clagentic-console send-input --to builder@my-project --prompt "The build passed."` The input is pushed into the session, which is resumed first if it was reaped.
25
+ - **Reply:** `clagentic-console send-input --reply --prompt "Done."` answers whoever last messaged the calling session.
26
+ - **List sessions:** `clagentic-console list-sessions --state live` shows each session's state and any prompts it is waiting on.
27
+ - **Schedule input:** `clagentic-console schedule-input create --session 12 --project my-project --every 30m --count 4 --prompt "Check the build."` sends text into a session later, once or on a repeat that always has an end. People do the same from the clock button next to the message box.
28
+
29
+ Every injected message records who sent it, and an agent's message is never recorded as a human's. See the [agents guide](docs/guides/AGENT-GUIDE.md) for every verb and flag.
30
+
19
31
  ## Install
20
32
 
21
33
  ```bash
@@ -40,6 +52,8 @@ npx @clagentic/console
40
52
 
41
53
  On Linux, a global npm install runs a postinstall script that registers and enables a `clagentic-console.service` systemd unit. The script never restarts an already-running daemon — active sessions are not interrupted. Self-updates triggered from inside the app skip the restart entirely and let systemd's `Restart=always` handle the handoff after graceful shutdown.
42
54
 
55
+ The install never reads or writes your Claude Code settings. To let agents run `list-sessions`, `send-input` and `open-session` without permission prompts, add the suggested rules to `permissions.allow` in your own Claude Code settings; see [Suggested allow rules](docs/guides/AGENT-GUIDE.md#suggested-allow-rules), which also carries the migration note for the 1.10.x installer (#468) that used to add the `list-sessions` rule.
56
+
43
57
  To skip the postinstall script:
44
58
 
45
59
  ```bash
@@ -93,7 +107,6 @@ npx @clagentic/console --add . # Add current directory to running daemon
93
107
  npx @clagentic/console --remove . # Remove project
94
108
  npx @clagentic/console --list # List registered projects
95
109
  npx @clagentic/console --shutdown # Stop daemon
96
- npx @clagentic/console --dangerously-skip-permissions
97
110
  ```
98
111
 
99
112
  Also available as `clagentic-console` if installed globally.
package/bin/cli.js CHANGED
@@ -43,6 +43,12 @@ var args = process.argv.slice(2);
43
43
  // start exits 78 (EX_CONFIG), which the unit lists in RestartPreventExitStatus
44
44
  // so a mis-installed package is not restart-looped.
45
45
  if (args[0] === "daemon") {
46
+ // The documented form takes no further tokens. 78, not 1: the unit lists 78 in
47
+ // RestartPreventExitStatus, so a mis-edited ExecStart is refused once, not looped.
48
+ if (args.length > 1) {
49
+ console.error(require("../lib/cli/arg-validation").unrecognisedArgMessage(args[1]));
50
+ process.exit(78);
51
+ }
46
52
  var { findLinkTrap, linkTrapMessage, LinkTrapProbeError } = require("../lib/link-trap");
47
53
  var linkTrap = null;
48
54
  try {
@@ -65,7 +71,10 @@ if (args[0] === "daemon") {
65
71
  // Positional subcommand, handled before flag parsing: `clagentic-console release list-betas`.
66
72
  if (args[0] === "release") {
67
73
  var releaseSub = args[1];
68
- if (releaseSub === "list-betas") {
74
+ if (releaseSub === "list-betas" && args.length > 2) {
75
+ console.error(require("../lib/cli/arg-validation").unrecognisedArgMessage(args[2]));
76
+ process.exit(1);
77
+ } else if (releaseSub === "list-betas") {
69
78
  var releaseList = require("../lib/release-list");
70
79
  var betasResult = releaseList.readBetasFile(process.cwd());
71
80
  var betasLines = releaseList.formatBetasOutput(betasResult);
@@ -80,7 +89,7 @@ if (args[0] === "release") {
80
89
  }
81
90
  }
82
91
 
83
- // --- `open-session` / `send-input`: drive a session through the running daemon ---
92
+ // --- `open-session` / `send-input` / `list-sessions`: drive a session through the running daemon ---
84
93
  // Positional verbs, handled before flag parsing: `clagentic-console send-input --project <slug> ...`.
85
94
  var { SESSION_VERBS, runSessionVerb } = require("../lib/cli/session-subcommands");
86
95
  if (SESSION_VERBS.indexOf(args[0]) !== -1) {
@@ -88,6 +97,11 @@ if (SESSION_VERBS.indexOf(args[0]) !== -1) {
88
97
  return;
89
98
  }
90
99
 
100
+ if (args[0] === "schedule-input") {
101
+ require("../lib/cli/schedule-input-subcommands").runScheduleInput(args.slice(1));
102
+ return;
103
+ }
104
+
91
105
  var port = _isDev ? 2635 : 2633;
92
106
  var useHttps = true;
93
107
  var forceMkcert = false;
@@ -103,13 +117,20 @@ var removePath = null;
103
117
  var listMode = false;
104
118
  var activityDiagnosticsMode = false;
105
119
  var processBuildStatusMode = false;
106
- var dangerouslySkipPermissions = false;
107
120
  var headlessMode = false;
108
121
  var watchMode = false;
109
122
  var host = null;
110
123
  var multiUserMode = false;
111
124
  var osUsersMode = false;
112
125
 
126
+ // Reject unknown words/flags before any action runs (no IPC, no daemon fork).
127
+ var { findUnrecognisedArg, unrecognisedArgMessage } = require("../lib/cli/arg-validation");
128
+ var _badArg = findUnrecognisedArg(args);
129
+ if (_badArg !== null) {
130
+ console.error(unrecognisedArgMessage(_badArg));
131
+ process.exit(1);
132
+ }
133
+
113
134
  for (var i = 0; i < args.length; i++) {
114
135
  if (args[i] === "-p" || args[i] === "--port") {
115
136
  port = parseInt(args[i + 1], 10);
@@ -160,7 +181,8 @@ for (var i = 0; i < args.length; i++) {
160
181
  headlessMode = true;
161
182
  autoYes = true;
162
183
  } else if (args[i] === "--dangerously-skip-permissions") {
163
- dangerouslySkipPermissions = true;
184
+ console.error("clagentic-console: --dangerously-skip-permissions has been removed. Tool approval follows each agent's own permission settings; Clagentic: Console does not bypass it.");
185
+ process.exit(1);
164
186
  } else if (args[i] === "--multi-user") {
165
187
  multiUserMode = true;
166
188
  } else if (args[i] === "--os-users") {
@@ -172,8 +194,15 @@ for (var i = 0; i < args.length; i++) {
172
194
  console.log(" clagentic-console --list List registered projects");
173
195
  console.log(" clagentic-console --activity-diagnostics Print activity-divergence probe totals as JSON (agent-readable)");
174
196
  console.log(" clagentic-console --process-build-status Print the running process's loaded build SHA as JSON (agent-readable)");
175
- console.log(" clagentic-console open-session --project <slug> --prompt <text|-> [--vendor <id>] [--agent <name>] Open a session and run a first prompt (prints JSON)");
176
- console.log(" clagentic-console send-input --project <slug> --session <id> --prompt <text|-> Send input to a session, resuming it if needed (prints JSON)");
197
+ console.log(" clagentic-console open-session (--project <slug> | --to <address>) --prompt <text|-> [--vendor <id>] [--agent <name>] [--name <session-name>] [--visibility shared|private] [--permission-mode <mode>] [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>] Open a session and run a first prompt (prints JSON)");
198
+ console.log(" clagentic-console send-input (--project <slug> --session <id> | --to <address> | --reply) --prompt <text|-> [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>] Send input to a session, resuming it if needed (prints JSON; exit 3 ambiguous, 4 not found by address)");
199
+ console.log(" clagentic-console list-sessions [--project <slug>] [--agent <name>] [--vendor <id>] [--state live|idle|reaped|any] List the console's sessions (prints JSON)");
200
+ console.log(" clagentic-console schedule-input create --session <id> [--project <slug>] (--in <dur> | --at <time> | --every <dur> (--until <time> | --count <n>)) (--prompt <text|-> | --prompt-file <path>) Send text into a session later, once or on a repeat with an end (prints JSON)");
201
+ console.log(" clagentic-console schedule-input list [--session <id>] [--project <slug>] [--state armed|done|ended|any] List scheduled input, from the browser or the CLI (prints JSON)");
202
+ console.log(" clagentic-console schedule-input delete --id <id> [--project <slug>] Cancel a scheduled input");
203
+ console.log(" <dur> is minutes or parts like 90, 10m, 1h30m; <time> is a local HH:MM (a past one means tomorrow)");
204
+ console.log(" <address> is <agent>@<project>, <vendor>@<project> (a plain session) or @<project>, each with an optional /<session-name>");
205
+ console.log(" Several matches resolve live over idle over reaped; /<session-name> names one session exactly");
177
206
  console.log(" clagentic-console release list-betas List promotable beta versions (maintainer/release-engineering)");
178
207
  console.log(" clagentic-console daemon Run the daemon in the foreground (used by the systemd unit)");
179
208
  console.log("");
@@ -197,8 +226,6 @@ for (var i = 0; i < args.length; i++) {
197
226
  console.log(" --headless Start daemon and exit immediately (implies --yes)");
198
227
  console.log(" --multi-user Start in multi-user mode (use with --yes for headless)");
199
228
  console.log(" --os-users Enable OS-level user isolation (Linux, requires root + --multi-user)");
200
- console.log(" --dangerously-skip-permissions");
201
- console.log(" Bypass all permission prompts");
202
229
  process.exit(0);
203
230
  }
204
231
  }
@@ -268,7 +295,6 @@ function currentCliOpts() {
268
295
  forceMkcert: forceMkcert,
269
296
  debugMode: debugMode,
270
297
  headlessMode: headlessMode,
271
- dangerouslySkipPermissions: dangerouslySkipPermissions,
272
298
  osUsersMode: osUsersMode,
273
299
  cliPin: cliPin,
274
300
  watchMode: watchMode,
@@ -318,7 +344,7 @@ var currentVersion = require("../package.json").version;
318
344
  setup(function (mode, keepAwake, wantOsUsers, chosenPort) {
319
345
  port = chosenPort;
320
346
  devMode(mode, keepAwake, null, wantOsUsers, currentCliOpts());
321
- }, port, { host: host, dangerouslySkipPermissions: dangerouslySkipPermissions });
347
+ }, port, { host: host });
322
348
  } else {
323
349
  // Reuse existing config (repeat run)
324
350
  await devMode(devConfig.mode || "single", devConfig.keepAwake || false, devConfig.pinHash || null, devConfig.osUsers || false, currentCliOpts());
@@ -448,8 +474,7 @@ var currentVersion = require("../package.json").version;
448
474
 
449
475
  if (savedConfig && savedConfig.port) port = savedConfig.port;
450
476
  if (savedConfig && savedConfig.host) host = savedConfig.host;
451
- if (savedConfig && savedConfig.dangerouslySkipPermissions) dangerouslySkipPermissions = true;
452
- // Re-sync: port/host/dangerouslySkipPermissions above may have just
477
+ // Re-sync: port/host above may have just
453
478
  // changed after the initial setDaemonWatcherOpts() call at module
454
479
  // load — keep the crash-watcher/getCliOpts() snapshot current so a
455
480
  // later crash-restart or "re-run setup" re-fork doesn't use stale values.
@@ -458,9 +483,6 @@ var currentVersion = require("../package.json").version;
458
483
  if (autoYes) {
459
484
  console.log(" " + sym.done + " Auto-accepted disclaimer");
460
485
  console.log(" " + sym.done + " Mode: " + savedMode);
461
- if (dangerouslySkipPermissions) {
462
- console.log(" " + sym.warn + " " + a.yellow + "Skip permissions mode enabled" + a.reset);
463
- }
464
486
  }
465
487
 
466
488
  var autoRc = loadClayrc();
@@ -499,7 +521,7 @@ var currentVersion = require("../package.json").version;
499
521
  log("");
500
522
  forkDaemon(mode, keepAwake, undefined, true, wantOsUsers, currentCliOpts());
501
523
  }
502
- }, port, { host: host, dangerouslySkipPermissions: dangerouslySkipPermissions });
524
+ }, port, { host: host });
503
525
  }
504
526
  }
505
527
  })();
package/lib/agents.js CHANGED
@@ -76,58 +76,6 @@ function slugifyAgentName(name) {
76
76
  .slice(0, 64);
77
77
  }
78
78
 
79
- // lr-4c90 — Read the tools list for a named agent directly from its on-disk
80
- // frontmatter. The SDK AgentInfo surface (supportedAgents()) does not expose
81
- // the tools field — only name, description, and model are returned. Reading
82
- // the file directly is the only synchronous path for belt-and-suspenders
83
- // enforcement in the query setup path.
84
- //
85
- // agentName: the agent identity string (e.g. "agentic-director").
86
- // globalAgentsDir: optional override of AGENTS_SOURCE_DIR. On a shared
87
- // multi-user daemon, callers resolve the SESSION OWNER's home
88
- // (os-users.getLinuxUserHome(linuxUser)) and pass
89
- // path.join(thatHome, ".claude", "agents") here so the on-disk agent
90
- // definition is read from the invoking user's own home, not the daemon
91
- // process's REAL_HOME (lr-3ccc78 twin of the skill-discovery fix).
92
- // Returns: string[] of tool names if the tools field is a valid JSON array,
93
- // null if the file is absent, the frontmatter is missing, or the
94
- // tools field cannot be parsed.
95
- //
96
- // Failures are silent (logged at debug level) — callers treat null as "no
97
- // restriction from this source" and fall through to whatever the SDK applies
98
- // via claudeOpts.agent.
99
- function readAgentToolsFromFile(agentName, globalAgentsDir) {
100
- if (!agentName || typeof agentName !== "string") return null;
101
- var slug = slugifyAgentName(agentName);
102
- if (!slug) return null;
103
- var baseDir = (typeof globalAgentsDir === "string" && globalAgentsDir) ? globalAgentsDir : AGENTS_SOURCE_DIR;
104
- var filePath = path.join(baseDir, slug + ".md");
105
- var raw;
106
- try {
107
- raw = fs.readFileSync(filePath, "utf8");
108
- } catch (e) {
109
- // File not found is expected for agents with no on-disk definition.
110
- return null;
111
- }
112
- var parsed = parseFrontmatter(raw);
113
- if (!parsed || !parsed.meta) return null;
114
- var toolsVal = parsed.meta.tools;
115
- if (!toolsVal || typeof toolsVal !== "string") return null;
116
- var trimmed = toolsVal.trim();
117
- if (trimmed.charAt(0) !== "[") return null; // not a JSON array — skip
118
- try {
119
- var arr = JSON.parse(trimmed);
120
- if (!Array.isArray(arr)) return null;
121
- var result = [];
122
- for (var i = 0; i < arr.length; i++) {
123
- if (typeof arr[i] === "string" && arr[i]) result.push(arr[i]);
124
- }
125
- return result.length > 0 ? result : null;
126
- } catch (e) {
127
- return null;
128
- }
129
- }
130
-
131
79
  // --- SDK-backed discovery cache ---
132
80
 
133
81
  // Module-level cache. Populated by refresh(); read by getAll().
@@ -265,8 +213,7 @@ function _readAgentsFromDir(agentsDir) {
265
213
 
266
214
  // _globalAgentsDir is an optional override of the global agents directory.
267
215
  // Tests use it to point at a fixture dir; production callers on a shared
268
- // multi-user daemon pass the session owner's own ~/.claude/agents (see
269
- // readAgentToolsFromFile above, lr-3ccc78).
216
+ // multi-user daemon pass the session owner's own ~/.claude/agents.
270
217
  function readProjectAgents(projectDir, _globalAgentsDir) {
271
218
  if (!projectDir || typeof projectDir !== "string") return [];
272
219
 
@@ -299,7 +246,6 @@ module.exports = {
299
246
  AGENTS_SOURCE_DIR: AGENTS_SOURCE_DIR,
300
247
  parseFrontmatter: parseFrontmatter,
301
248
  slugifyAgentName: slugifyAgentName,
302
- readAgentToolsFromFile: readAgentToolsFromFile,
303
249
  readProjectAgents: readProjectAgents,
304
250
  // New SDK-backed surface:
305
251
  refresh: refresh,
@@ -0,0 +1,133 @@
1
+ // Per-command option ALLOWLISTS for the read-only Bash auto-approve.
2
+ //
3
+ // Every auto-approvable command declares the exact option tokens it accepts.
4
+ // A token that starts with "-" and is not exactly in the command's set means
5
+ // the call goes to the permission prompt. There is no prefix matching (GNU
6
+ // long options accept unique abbreviations, so "--outp" would reach "--output"
7
+ // if a denylist named only the full spelling) and a token like "-xyz" is never
8
+ // split into letters. A command that declares no options accepts none.
9
+ // Non-option tokens (paths, revisions) are allowed; the caller has already
10
+ // restricted every token to the character allowlist.
11
+ //
12
+ // When in doubt leave an option out: it only costs a prompt.
13
+
14
+ var DIGIT_OPTION_RE = /^-[0-9]+$/;
15
+
16
+ function opts(list) {
17
+ var set = {};
18
+ list.split(/\s+/).filter(Boolean).forEach(function (o) { set[o] = true; });
19
+ return set;
20
+ }
21
+
22
+ var GREP_OPTS = "-r -R -n -i -v -l -c -E -F -w -x -o -h -H -q -s -e -rn -ri -rl -rin -in -ni -nr -il -iv";
23
+
24
+ // name -> { opts: set, digits: true when "-<digits>" is accepted }
25
+ var COMMANDS = {
26
+ // Navigation
27
+ cd: {}, pushd: {}, popd: {},
28
+ // File and directory inspection
29
+ ls: { opts: opts("-l -a -la -al -h -lh -1 -R -t -r -A -lA -lah -ltr") },
30
+ cat: { opts: opts("-n") },
31
+ head: { opts: opts("-n -c"), digits: true },
32
+ wc: { opts: opts("-l -w -c -m") },
33
+ stat: {}, du: { opts: opts("-h -s -sh -c") }, df: { opts: opts("-h -T") },
34
+ readlink: {}, realpath: {}, basename: {}, dirname: {},
35
+ // Search
36
+ grep: { opts: opts(GREP_OPTS) },
37
+ fgrep: { opts: opts(GREP_OPTS) },
38
+ egrep: { opts: opts(GREP_OPTS) },
39
+ rg: { opts: opts("-n -i -l -c -w -F -v -t -e") },
40
+ // Lookup
41
+ which: { opts: opts("-a") }, type: { opts: opts("-a -t") }, whereis: {}, hash: {},
42
+ // Environment and system info
43
+ echo: { opts: opts("-n") }, printf: {}, printenv: {}, pwd: {},
44
+ whoami: {}, id: { opts: opts("-u -g -n") }, groups: {},
45
+ uname: { opts: opts("-a -r -m -s -n") }, uptime: { opts: opts("-p") }, arch: {},
46
+ nproc: {}, free: { opts: opts("-h -m -g") }, lsb_release: { opts: opts("-a") },
47
+ sw_vers: {}, locale: {},
48
+ // Text processing (stdin to stdout)
49
+ jq: { opts: opts("-r -c -s -n -e") },
50
+ cut: { opts: opts("-d -f -c -s") },
51
+ tr: { opts: opts("-d -s -c") },
52
+ paste: { opts: opts("-s -d") },
53
+ column: { opts: opts("-t -s") },
54
+ fold: { opts: opts("-w -s") },
55
+ rev: {}, tac: {}, nl: {}, expand: {}, unexpand: {},
56
+ fmt: {}, pr: {}, comm: { opts: opts("-1 -2 -3 -12 -13 -23") }, join: {},
57
+ // Comparison and hashing
58
+ diff: { opts: opts("-u -q -r -i -w -b") },
59
+ cmp: { opts: opts("-s -l") },
60
+ md5sum: { opts: opts("-c") }, sha256sum: { opts: opts("-c") }, sha1sum: { opts: opts("-c") },
61
+ shasum: { opts: opts("-c") }, cksum: {}, sum: {}, b2sum: { opts: opts("-c") },
62
+ base64: { opts: opts("-d") },
63
+ od: { opts: opts("-c -x") }, hexdump: { opts: opts("-C") },
64
+ // Misc read-only
65
+ test: { opts: opts("-e -f -d -r -w -x -s -z -n") }, "true": {}, "false": {}, seq: {},
66
+ help: {}, apropos: {},
67
+ cal: { opts: opts("-y") }, bc: { opts: opts("-l") }, expr: {}, factor: {},
68
+ lsof: { opts: opts("-i -n -P") },
69
+ ps: { opts: opts("-e -f -ef -A") },
70
+ pgrep: { opts: opts("-f -l -a -x") },
71
+ netstat: { opts: opts("-a -n -l -t -u -p -r -tuln -tulnp -tlnp -an") },
72
+ dig: {}, nslookup: {}, host: {}, traceroute: {},
73
+ };
74
+
75
+ var GIT_SUBCOMMANDS = {
76
+ status: { opts: opts("-s --short -b --branch --porcelain") },
77
+ log: { opts: opts("--oneline -n --stat --graph --decorate"), digitsMax: 50 },
78
+ diff: { opts: opts("--stat --name-only --name-status --cached --staged") },
79
+ show: { opts: opts("--stat --name-only") },
80
+ };
81
+
82
+ // Whether every option token in args is declared by spec.
83
+ function optionsAllowed(args, spec, startIndex) {
84
+ var declared = spec.opts || {};
85
+ for (var i = startIndex; i < args.length; i++) {
86
+ var tok = args[i];
87
+ if (tok.charAt(0) !== "-") continue;
88
+ if (Object.prototype.hasOwnProperty.call(declared, tok)) continue;
89
+ if (DIGIT_OPTION_RE.test(tok)) {
90
+ if (spec.digitsMax) {
91
+ var n = parseInt(tok.slice(1), 10);
92
+ if (n >= 1 && n <= spec.digitsMax) continue;
93
+ } else if (spec.digits) {
94
+ continue;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ return true;
100
+ }
101
+
102
+ // Commands whose whole argument form, not just the options, is fixed.
103
+ var EXACT_FORMS = {
104
+ // date -s sets the clock: only no argument or one +FORMAT.
105
+ date: function (args) {
106
+ return args.length === 0 || (args.length === 1 && args[0].charAt(0) === "+");
107
+ },
108
+ // hostname NAME renames the host; ifconfig with arguments configures an interface.
109
+ hostname: function (args) { return args.length === 0; },
110
+ ifconfig: function (args) { return args.length === 0; },
111
+ // "ip link set ..." and the rest write: only the two plain listings.
112
+ ip: function (args) {
113
+ return args.length === 1 && (args[0] === "addr" || args[0] === "route");
114
+ },
115
+ // Only the read-only subcommands; no remote, tag, branch (mutating forms).
116
+ git: function (args) {
117
+ if (args.length === 0) return false;
118
+ if (args[0] === "--version") return args.length === 1;
119
+ if (!Object.prototype.hasOwnProperty.call(GIT_SUBCOMMANDS, args[0])) return false;
120
+ return optionsAllowed(args, GIT_SUBCOMMANDS[args[0]], 1);
121
+ },
122
+ };
123
+
124
+ // tokens: the segment's words, command word first.
125
+ function isAutoApprovableSegment(tokens) {
126
+ var name = tokens[0];
127
+ if (!name) return false;
128
+ if (Object.prototype.hasOwnProperty.call(EXACT_FORMS, name)) return EXACT_FORMS[name](tokens.slice(1));
129
+ if (!Object.prototype.hasOwnProperty.call(COMMANDS, name)) return false;
130
+ return optionsAllowed(tokens.slice(1), COMMANDS[name], 0);
131
+ }
132
+
133
+ module.exports = { isAutoApprovableSegment: isAutoApprovableSegment };
@@ -66,12 +66,23 @@ function walkFiles(dir, relBase, fn) {
66
66
  }
67
67
  }
68
68
 
69
+ // lib/build-sha.json is the build's identity, compared by sha on its own. It also
70
+ // carries a `writtenAt` timestamp that prepack rewrites on every pack, so two
71
+ // packs of the same commit differ in exactly this file. Hashing it would make
72
+ // every same-sha reinstall look like a different build.
73
+ var IDENTITY_FILE = 'lib/build-sha.json';
74
+
69
75
  /**
70
76
  * A hasher over one package root (the directory holding lib/ and
71
- * package.json). `hash()` returns a hex digest of every file under lib/ plus
72
- * package.json, or null when the tree cannot be read right now (an install in
77
+ * package.json). `hash()` returns a hex digest of every file under lib/ (except
78
+ * the identity file above) plus package.json, or null when the tree cannot be read right now (an install in
73
79
  * progress removes files mid-walk). Per-file digests are remembered by
74
80
  * (inode, size, mtime), so a poll re-reads only files an install replaced.
81
+ *
82
+ * Known limit: a same-size rewrite of a file in place (same inode) that lands in
83
+ * the same filesystem timestamp tick as the previous hash() keeps the same
84
+ * key, so the old digest is reused. Real installs replace files with new
85
+ * inodes and are unaffected.
75
86
  */
76
87
  function createTreeHasher(packageRoot) {
77
88
  var known = new Map(); // abs path -> { key, digest }
@@ -98,7 +109,9 @@ function createTreeHasher(packageRoot) {
98
109
  seen.add(abs);
99
110
  outer.update(rel + '\0' + fileDigest(abs) + '\n');
100
111
  };
101
- walkFiles(path.join(packageRoot, 'lib'), 'lib', add);
112
+ walkFiles(path.join(packageRoot, 'lib'), 'lib', function (abs, rel) {
113
+ if (rel !== IDENTITY_FILE) add(abs, rel);
114
+ });
102
115
  add(path.join(packageRoot, 'package.json'), 'package.json');
103
116
  // Files that left the tree must not keep their remembered digest.
104
117
  known.forEach(function (_v, abs) { if (!seen.has(abs)) known.delete(abs); });
@@ -152,8 +165,13 @@ function assessBuild(loaded, installed) {
152
165
  return result(STATES.STALE, 'sha', 'the installed build (' + i.sha + ') is not the one this process loaded (' + l.sha + ')');
153
166
  }
154
167
  if (l.contentHash !== i.contentHash) {
155
- return result(STATES.STALE, 'content',
156
- 'the installed files differ from the ones this process loaded, although both report build ' + l.sha);
168
+ // Same build id on both sides: a restart would load the build already
169
+ // running, so this is never offered. It is not "adopted" either (the files
170
+ // do differ), so it is reported as inconclusive, which the monitor journals
171
+ // and no client is told about.
172
+ return result(STATES.INCONCLUSIVE, 'same-sha-content-differs',
173
+ 'the installed files differ from the ones this process loaded, although both report build ' + l.sha +
174
+ '; a restart would load the same build id, so none is offered');
157
175
  }
158
176
  return result(STATES.ADOPTED, 'identical', 'the installed build is the one this process loaded');
159
177
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "3b16bd4528948b0e235f81c22553b390e1461821",
3
- "writtenAt": "2026-10-16T13:54:15.216Z"
2
+ "sha": "5933d0c3d1e21fbe7af541057983cc4c0c879276",
3
+ "writtenAt": "2026-10-23T20:53:39.484Z"
4
4
  }
@@ -70,69 +70,7 @@ function checkForNewerInstalledBuild(opts) {
70
70
  };
71
71
  }
72
72
 
73
- /**
74
- * Bounded wait for in-flight sessions to finish, then invoke `onIdle()`.
75
- * Extracted out of lib/daemon.js's onRestartForBuildUpdate so this timing
76
- * logic is unit-testable without spinning up a real daemon process (the
77
- * daemon script itself has no other exported surface — see
78
- * test/daemon-bootstrap-guard.test.js's subprocess-spawn approach for why
79
- * that path is reserved for bootstrap-only cases, not routine logic).
80
- *
81
- * This is the ONLY thing standing between "operator clicked restart" and
82
- * "daemon actually restarts" — it never fires without that click (see
83
- * lib/project-sessions.js's restart_for_build_update handler, which is the
84
- * sole caller of the onRestartForBuildUpdate that wraps this). It exists so
85
- * that click does not also mean "drop whatever is running right now" when
86
- * waiting a bounded amount of time can avoid that.
87
- *
88
- * @param {object} opts
89
- * @param {function(): number} opts.getActiveCount — same shape as
90
- * drain.js's opts.getActiveCount (lib/sdk-bridge.js's getActiveLiveCount).
91
- * @param {function(): void} opts.onIdle — called exactly once, either when
92
- * getActiveCount() reaches <= 0 or when the timeout elapses.
93
- * @param {number} [opts.timeoutMs] — defaults to DEFAULT_RESTART_WAIT_MS.
94
- * @param {number} [opts.pollIntervalMs] — defaults to 1000.
95
- * @param {function(function(): void, number): void} [opts.setTimeoutFn] —
96
- * injectable for tests (default: a thin wrapper over the global
97
- * setTimeout). Called as setTimeoutFn(fn, delayMs); must invoke fn with no
98
- * arguments after that delay, same contract as the global setTimeout.
99
- * @param {function(): number} [opts.nowMs] — injectable for tests (default
100
- * Date.now).
101
- */
102
- var DEFAULT_RESTART_WAIT_MS = 60 * 1000;
103
-
104
- function waitForIdleThenAct(opts) {
105
- var o = opts || {};
106
- if (typeof o.getActiveCount !== 'function') {
107
- throw new Error('waitForIdleThenAct: opts.getActiveCount must be a function');
108
- }
109
- if (typeof o.onIdle !== 'function') {
110
- throw new Error('waitForIdleThenAct: opts.onIdle must be a function');
111
- }
112
- var timeoutMs = (typeof o.timeoutMs === 'number' && o.timeoutMs > 0) ? o.timeoutMs : DEFAULT_RESTART_WAIT_MS;
113
- var pollIntervalMs = (typeof o.pollIntervalMs === 'number' && o.pollIntervalMs > 0) ? o.pollIntervalMs : 1000;
114
- var now = typeof o.nowMs === 'function' ? o.nowMs : Date.now;
115
- var scheduleFn = typeof o.setTimeoutFn === 'function' ? o.setTimeoutFn : function (fn, delay) { setTimeout(fn, delay); };
116
-
117
- var deadline = now() + timeoutMs;
118
- var acted = false;
119
-
120
- function tick() {
121
- if (acted) return; // idempotent — a stray extra tick must never double-fire
122
- if (o.getActiveCount() <= 0 || now() >= deadline) {
123
- acted = true;
124
- o.onIdle();
125
- return;
126
- }
127
- scheduleFn(tick, pollIntervalMs);
128
- }
129
-
130
- tick();
131
- }
132
-
133
73
  module.exports = {
134
74
  readInstalledBuildSha: readInstalledBuildSha,
135
75
  checkForNewerInstalledBuild: checkForNewerInstalledBuild,
136
- waitForIdleThenAct: waitForIdleThenAct,
137
- DEFAULT_RESTART_WAIT_MS: DEFAULT_RESTART_WAIT_MS,
138
76
  };
@@ -66,18 +66,12 @@ function collectInterruptions(projects) {
66
66
  };
67
67
  }
68
68
 
69
- /** True when every key in `current` was already in `offered`. */
70
- function coveredBy(current, offered) {
71
- var have = new Set(offered);
72
- return current.every(function (k) { return have.has(k); });
73
- }
74
-
75
69
  function plural(n, word) {
76
70
  return n + ' ' + word + (n === 1 ? '' : 's');
77
71
  }
78
72
 
79
73
  /** The operator-facing statement of what a restart ends. */
80
- function describeInterruptions(i, waitSeconds) {
74
+ function describeInterruptions(i) {
81
75
  if (i.sessionCount === 0) {
82
76
  return 'No session is live, so the restart ends nothing that is running.';
83
77
  }
@@ -92,7 +86,7 @@ function describeInterruptions(i, waitSeconds) {
92
86
  : '';
93
87
  lines.push('- [' + s.slug + '] ' + s.title + ' (' + state + agents + ')');
94
88
  });
95
- lines.push('Running turns and agents get up to ' + waitSeconds + ' seconds to finish first. ' +
89
+ lines.push('Restarting ends these sessions and any that start before the restart happens. ' +
96
90
  'Ended sessions resume when you send them a message.');
97
91
  return lines.join('\n');
98
92
  }
@@ -117,7 +111,7 @@ function buildOffer(o) {
117
111
  sessionCount: o.interruptions.sessionCount,
118
112
  agentCount: o.interruptions.agentCount,
119
113
  };
120
- offer.interruptionText = describeInterruptions(o.interruptions, o.waitSeconds);
114
+ offer.interruptionText = describeInterruptions(o.interruptions);
121
115
  }
122
116
  if (o.token) offer.token = o.token;
123
117
  return offer;
@@ -126,9 +120,7 @@ function buildOffer(o) {
126
120
  /** One line naming both builds, for the notice and the log. */
127
121
  function summarizeOffer(a) {
128
122
  var short = function (s) { return s ? s.slice(0, 12) : '(unknown)'; };
129
- return a.reason === 'content'
130
- ? 'Build ' + short(a.installedBuildSha) + ' is installed with different files than the running process loaded.'
131
- : 'Running build ' + short(a.loadedBuildSha) + '; installed build ' + short(a.installedBuildSha) + '.';
123
+ return 'Running build ' + short(a.loadedBuildSha) + '; installed build ' + short(a.installedBuildSha) + '.';
132
124
  }
133
125
 
134
126
  var DEFAULT_NOTICE_COOLDOWN_MS = 60 * 60 * 1000;
@@ -157,12 +149,30 @@ function composeNotice(assessment, changes, cooldownMs) {
157
149
  };
158
150
  }
159
151
 
152
+ // The restart-pending state is its own source so withdrawing the offer
153
+ // (source build-update) never removes it. `persistent` tells the client not to
154
+ // close it on a timer: it stays until the restarted daemon replaces the page.
155
+ var RESTARTING_SOURCE = 'build-update-restart';
156
+
157
+ /** The one message that stands in for the offer while a confirmed restart is pending. */
158
+ function composeRestartingNotice() {
159
+ return {
160
+ type: 'diagnostic',
161
+ severity: 'warning',
162
+ source: RESTARTING_SOURCE,
163
+ persistent: true,
164
+ message: 'Restarting Clagentic: Console to apply the installed update. This page reconnects when ' +
165
+ 'it is back. Nothing more to confirm.',
166
+ };
167
+ }
168
+
160
169
  module.exports = {
170
+ RESTARTING_SOURCE: RESTARTING_SOURCE,
171
+ composeRestartingNotice: composeRestartingNotice,
161
172
  DEFAULT_NOTICE_COOLDOWN_MS: DEFAULT_NOTICE_COOLDOWN_MS,
162
173
  noticeCooldownFrom: noticeCooldownFrom,
163
174
  composeNotice: composeNotice,
164
175
  collectInterruptions: collectInterruptions,
165
- coveredBy: coveredBy,
166
176
  describeInterruptions: describeInterruptions,
167
177
  buildOffer: buildOffer,
168
178
  summarizeOffer: summarizeOffer,