@clagentic/console 1.11.0-beta.1 → 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 (46) hide show
  1. package/README.md +0 -1
  2. package/bin/cli.js +24 -14
  3. package/lib/bash-auto-approve.js +1 -1
  4. package/lib/build-sha.json +2 -2
  5. package/lib/cli/arg-validation.js +50 -0
  6. package/lib/cli/daemon-launch.js +5 -4
  7. package/lib/cli/menus.js +2 -2
  8. package/lib/cli/session-subcommands.js +3 -2
  9. package/lib/daemon.js +18 -1
  10. package/lib/identity/index.js +9 -4
  11. package/lib/permission-mode-policy.js +2 -2
  12. package/lib/permission-settings.js +96 -0
  13. package/lib/project-connection.js +9 -11
  14. package/lib/project-loop.js +24 -3
  15. package/lib/project-permission-settings.js +59 -0
  16. package/lib/project-prompt-responses.js +7 -3
  17. package/lib/project-sessions.js +93 -41
  18. package/lib/project.js +11 -13
  19. package/lib/public/app.js +1 -2
  20. package/lib/public/css/overlays.css +0 -3
  21. package/lib/public/css/scheduler-modal.css +5 -0
  22. package/lib/public/index.html +44 -8
  23. package/lib/public/modules/app-loop-ui.js +11 -1
  24. package/lib/public/modules/app-messages.js +4 -13
  25. package/lib/public/modules/app-panels.js +1 -1
  26. package/lib/public/modules/app-rate-limit.js +1 -1
  27. package/lib/public/modules/approve-tools-toggle.js +33 -0
  28. package/lib/public/modules/loop-hooks-warning.js +20 -0
  29. package/lib/public/modules/mode-options.js +16 -0
  30. package/lib/public/modules/permission-settings.js +56 -0
  31. package/lib/public/modules/project-settings.js +3 -0
  32. package/lib/public/modules/scheduler-config.js +12 -0
  33. package/lib/public/modules/scheduler.js +8 -0
  34. package/lib/public/modules/server-settings.js +5 -9
  35. package/lib/public/modules/settings-defaults.js +18 -4
  36. package/lib/scheduler.js +4 -0
  37. package/lib/sdk-bridge.js +74 -40
  38. package/lib/server.js +9 -3
  39. package/lib/session-input-ipc.js +1 -0
  40. package/lib/session-input.js +41 -4
  41. package/lib/session-resume.js +2 -0
  42. package/lib/sessions.js +67 -2
  43. package/lib/updater.js +8 -2
  44. package/lib/ws-schema.js +5 -2
  45. package/lib/yoke/adapters/claude.js +0 -10
  46. package/package.json +1 -1
package/lib/sdk-bridge.js CHANGED
@@ -392,7 +392,6 @@ function createSDKBridge(opts) {
392
392
  var getNotificationsModule = opts.getNotificationsModule || function () { return null; };
393
393
  var adapter = opts.adapter;
394
394
  var adapters = opts.adapters || {};
395
- var dangerouslySkipPermissions = opts.dangerouslySkipPermissions || false;
396
395
  // Whether the daemon isolates users at the OS level. An agent that does not
397
396
  // support that (Codex) is disabled then: never created, never started.
398
397
  var osUsersMode = !!opts.osUsers;
@@ -405,6 +404,19 @@ function createSDKBridge(opts) {
405
404
  return _mcpServersSrc;
406
405
  }
407
406
  var getRemoteMcpServers = opts.getRemoteMcpServers || null;
407
+ // The server's permission settings, read at each decision so a change needs
408
+ // no restart. Absent means the defaults (nothing turned off).
409
+ function autoApproveReadOnlyOn() {
410
+ var settings = typeof opts.getPermissionSettings === "function" ? opts.getPermissionSettings() : null;
411
+ return !settings || settings.autoApproveReadOnly !== false;
412
+ }
413
+ // The mode a client is shown for a session: its own, else the project default
414
+ // (sessions.js effectiveSessionMode). A session manager without the helper
415
+ // (a test double) gets the same fallback inline.
416
+ function shownMode(session) {
417
+ if (typeof sm.effectiveSessionMode === "function") return sm.effectiveSessionMode(session);
418
+ return (session && session.permissionMode) || sm.currentPermissionMode || "default";
419
+ }
408
420
  var clayPort = opts.clayPort || 2633;
409
421
  var clayTls = opts.clayTls || false;
410
422
  var clayAuthToken = opts.clayAuthToken || null;
@@ -923,6 +935,11 @@ function createSDKBridge(opts) {
923
935
  // Returns { behavior: "allow", updatedInput } if whitelisted, or null if not.
924
936
  // Shared by handleCanUseTool and mate mention canUseTool handlers.
925
937
  function checkToolWhitelist(toolName, input, toolOpts) {
938
+ // The "Auto-approve read-only tools" setting. Off sends every item below
939
+ // (read-only built-ins, the safe Bash list, browser watch/unwatch, the MCP
940
+ // servers the person enabled) to the normal prompt.
941
+ if (!autoApproveReadOnlyOn()) return null;
942
+
926
943
  // Auto-approve read-only tools for ALL sessions.
927
944
  // These tools only inspect files and fetch data — no side effects.
928
945
  var readOnlyTools = { Read: true, Glob: true, Grep: true, WebFetch: true, WebSearch: true };
@@ -986,7 +1003,7 @@ function createSDKBridge(opts) {
986
1003
  // Which commands are read-only, and which option tokens each accepts,
987
1004
  // is declared in lib/bash-auto-approve.js. Commands that can write,
988
1005
  // execute or hang (time, sort, uniq, csplit, xxd, yq, tree, ag/ack,
989
- // yes, ping, man, info, top, htop, timedatectl, tail, ss, file) are not
1006
+ // yes, ping, man, info, top, htop, timedatectl, tail, ss, file, sleep) are not
990
1007
  // listed: a dropped entry only costs a prompt. `env` and `command` are
991
1008
  // execution primitives and stay out for the same reason.
992
1009
  // Split compound commands on operators (&&, ||, ;, |) while respecting
@@ -1033,12 +1050,16 @@ function createSDKBridge(opts) {
1033
1050
  // Whether a mode may be applied to this session, by the shared policy
1034
1051
  // (lib/permission-mode-policy.js). checkVendor adds the session's vendor
1035
1052
  // capability list to the check. A refusal is logged.
1036
- function modeAllowed(session, mode, what, checkVendor) {
1053
+ function checkModeFor(session, mode, checkVendor) {
1037
1054
  var vendor = sessionCapabilities.effectiveVendorId(sm, session, adapter && adapter.vendor);
1038
- var verdict = checkPermissionMode(mode, {
1039
- skipPermissionsAllowed: dangerouslySkipPermissions === true,
1055
+ return checkPermissionMode(mode, {
1040
1056
  supportedModes: checkVendor ? sessionCapabilities.capabilitiesFor(sm, vendor).permissionModes : null,
1041
1057
  });
1058
+ }
1059
+
1060
+ // checkModeFor, with a refusal logged under `what`; true when the mode is allowed.
1061
+ function modeAllowed(session, mode, what, checkVendor) {
1062
+ var verdict = checkModeFor(session, mode, checkVendor);
1042
1063
  if (!verdict.ok) {
1043
1064
  console.warn("[sdk-bridge] refused " + what + " " + logField(mode) + " in " + slug + ": " + verdict.error);
1044
1065
  }
@@ -1071,7 +1092,12 @@ function createSDKBridge(opts) {
1071
1092
  if (toolName === "EnterPlanMode") {
1072
1093
  return Promise.resolve({ behavior: "deny", message: "Do not enter plan mode. Execute directly." });
1073
1094
  }
1074
- return Promise.resolve({ behavior: "allow", updatedInput: input });
1095
+ // The loop's "Approve tools automatically" setting. A record that never
1096
+ // carried it approves, as every loop did before it existed. Off sends the
1097
+ // call down the normal path below (read-only list, then a prompt).
1098
+ if (session.loop.approveTools !== false) {
1099
+ return Promise.resolve({ behavior: "allow", updatedInput: input });
1100
+ }
1075
1101
  }
1076
1102
 
1077
1103
  // Check shared whitelist (read-only tools, safe browser tools, safe bash commands)
@@ -1262,11 +1288,14 @@ function createSDKBridge(opts) {
1262
1288
  // reply (project-sessions.js's set_model/switch_session).
1263
1289
  session.model = metaData.model;
1264
1290
  sendModelInfoToSession(session, session.vendor || (adapter && adapter.vendor) || "claude", metaData.model);
1265
- sendToSession(session, { type: "config_state", model: metaData.model, mode: session.permissionMode || sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [] });
1291
+ sendToSession(session, { type: "config_state", model: metaData.model, mode: shownMode(session), effort: sm.currentEffort || "medium", betas: sm.currentBetas || [] });
1266
1292
  break;
1267
1293
  case "effort_changed":
1268
1294
  sm.currentEffort = metaData.effort;
1269
- send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort, betas: sm.currentBetas || [] });
1295
+ // A broadcast about the effort carries no mode: the project's
1296
+ // default is not any viewer's session mode, and a push without a
1297
+ // mode leaves every chip as it is.
1298
+ send({ type: "config_state", model: sm.currentModel || "", effort: sm.currentEffort, betas: sm.currentBetas || [] });
1270
1299
  break;
1271
1300
  case "permission_mode_changed":
1272
1301
  // One session's worker changed its own mode (plan entered or
@@ -1278,6 +1307,7 @@ function createSDKBridge(opts) {
1278
1307
  // session on its previous mode.
1279
1308
  if (!modeAllowed(session, metaData.mode, "worker permission mode", true)) break;
1280
1309
  session.permissionMode = metaData.mode;
1310
+ sm.saveSessionFile(session);
1281
1311
  sendToSession(session, { type: "config_state", model: session.model || sm.currentModel || "", mode: metaData.mode, effort: sm.currentEffort || "medium", betas: sm.currentBetas || [] });
1282
1312
  break;
1283
1313
  case "worker_error":
@@ -1677,7 +1707,6 @@ function createSDKBridge(opts) {
1677
1707
  vendorAdapter = await yoke.lazyCreateAdapter(adapters, vendor, withRuntimeEnv({
1678
1708
  cwd: cwd,
1679
1709
  osUsers: osUsersMode,
1680
- dangerouslySkipPermissions: dangerouslySkipPermissions,
1681
1710
  linuxUser: linuxUser || undefined,
1682
1711
  clayPort: clayPort,
1683
1712
  clayTls: clayTls,
@@ -1687,7 +1716,6 @@ function createSDKBridge(opts) {
1687
1716
  } else if ((!sm.modelsByVendor || !sm.modelsByVendor[vendor]) && typeof vendorAdapter.init === "function") {
1688
1717
  recordInit(await vendorAdapter.init(withRuntimeEnv({
1689
1718
  cwd: cwd,
1690
- dangerouslySkipPermissions: dangerouslySkipPermissions,
1691
1719
  linuxUser: linuxUser || undefined,
1692
1720
  clayPort: clayPort,
1693
1721
  clayTls: clayTls,
@@ -2083,33 +2111,32 @@ function createSDKBridge(opts) {
2083
2111
  claudeOpts.settings = Object.assign({}, claudeOpts.settings || {}, { disableAllHooks: ls.disableAllHooks });
2084
2112
  }
2085
2113
 
2086
- if (dangerouslySkipPermissions) {
2087
- claudeOpts.allowDangerouslySkipPermissions = true;
2088
- claudeOpts.permissionMode = "bypassPermissions";
2089
- } else {
2090
- var globalMode = session.permissionMode || sm.currentPermissionMode || "default";
2091
- // A stored mode (session file, saved default) is checked again here: a
2092
- // bypassPermissions written by an older build or by hand must not start
2093
- // a query while the server does not allow it.
2094
- // The vendor is known here, so a mode the session's vendor lacks (auto
2095
- // after a switch to a vendor without it) falls back too.
2096
- if (!modeAllowed(session, globalMode, "stored permission mode", true)) {
2097
- globalMode = "default";
2098
- // The session's own mode too, so the bypass branch of canUseTool
2099
- // (which reads it) agrees with what this query starts with.
2100
- if (session.permissionMode) session.permissionMode = "default";
2101
- }
2102
- var effectiveDefault;
2103
- if (globalMode === "bypassPermissions") effectiveDefault = "bypassPermissions";
2104
- else if (session.acceptEditsAfterStart) effectiveDefault = "acceptEdits";
2105
- else effectiveDefault = globalMode;
2106
- var modeToApply = session._loopPermissionMode || effectiveDefault;
2107
- if (modeToApply && modeToApply !== "default") {
2108
- claudeOpts.permissionMode = modeToApply;
2114
+ var globalMode = session.permissionMode || sm.currentPermissionMode || "default";
2115
+ // A stored mode (session file, saved default) is checked again here: a
2116
+ // bypassPermissions written by an older build or by hand must not start
2117
+ // a query while the server does not allow it.
2118
+ // The vendor is known here, so a mode the session's vendor lacks (auto
2119
+ // after a switch to a vendor without it) falls back too.
2120
+ if (!modeAllowed(session, globalMode, "stored permission mode", true)) {
2121
+ globalMode = "default";
2122
+ // The session's own mode too, so the bypass branch of canUseTool
2123
+ // (which reads it) agrees with what this query starts with.
2124
+ if (session.permissionMode) {
2125
+ session.permissionMode = "default";
2126
+ // The saved value too, or the next load reads the refused mode back.
2127
+ sm.saveSessionFile(session);
2109
2128
  }
2110
2129
  }
2111
- // Clear one-shot acceptEditsAfterStart regardless of which branch ran above,
2112
- // so the flag does not linger into subsequent turns.
2130
+ var effectiveDefault;
2131
+ if (globalMode === "bypassPermissions") effectiveDefault = "bypassPermissions";
2132
+ else if (session.acceptEditsAfterStart) effectiveDefault = "acceptEdits";
2133
+ else effectiveDefault = globalMode;
2134
+ var modeToApply = session._loopPermissionMode || effectiveDefault;
2135
+ if (modeToApply && modeToApply !== "default") {
2136
+ claudeOpts.permissionMode = modeToApply;
2137
+ }
2138
+ // Clear one-shot acceptEditsAfterStart so the flag does not linger into
2139
+ // subsequent turns.
2113
2140
  if (session.acceptEditsAfterStart) delete session.acceptEditsAfterStart;
2114
2141
  if (session.cliSessionId && session.lastRewindUuid) {
2115
2142
  claudeOpts.resumeSessionAt = session.lastRewindUuid;
@@ -2424,7 +2451,6 @@ function createSDKBridge(opts) {
2424
2451
  try {
2425
2452
  var result = await adapter.init(withRuntimeEnv({
2426
2453
  cwd: cwd,
2427
- dangerouslySkipPermissions: dangerouslySkipPermissions,
2428
2454
  linuxUser: linuxUser || undefined,
2429
2455
  clayPort: clayPort,
2430
2456
  clayTls: clayTls,
@@ -2561,7 +2587,7 @@ function createSDKBridge(opts) {
2561
2587
  async function setEffort(session, effort) {
2562
2588
  if (!session.queryInstance) {
2563
2589
  sm.currentEffort = effort;
2564
- send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort, betas: sm.currentBetas || [] });
2590
+ send({ type: "config_state", model: sm.currentModel || "", effort: sm.currentEffort, betas: sm.currentBetas || [] });
2565
2591
  return { ok: true };
2566
2592
  }
2567
2593
  try {
@@ -2573,27 +2599,34 @@ function createSDKBridge(opts) {
2573
2599
  return { ok: false, error: errMsg };
2574
2600
  }
2575
2601
  sm.currentEffort = effort;
2576
- send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort, betas: sm.currentBetas || [] });
2602
+ send({ type: "config_state", model: sm.currentModel || "", effort: sm.currentEffort, betas: sm.currentBetas || [] });
2577
2603
  return { ok: true };
2578
2604
  }
2579
2605
 
2606
+ // Returns true when the session now has the mode (and it is saved, so a
2607
+ // resume or restart keeps it), false when it was refused or the running query
2608
+ // would not take it.
2580
2609
  async function setPermissionMode(session, mode) {
2581
2610
  // The handlers check first; this keeps any other caller (a prompt answer,
2582
2611
  // a loop) from handing the session a mode the server does not allow.
2583
- if (!modeAllowed(session, mode, "setPermissionMode", false)) return;
2612
+ if (!modeAllowed(session, mode, "setPermissionMode", true)) return false;
2584
2613
  if (!session.queryInstance) {
2585
2614
  // No active query — store on session only (not sm — that's for project defaults).
2586
2615
  // config_state sent targeted by caller (project-sessions.js).
2587
2616
  session.permissionMode = mode;
2588
- return;
2617
+ sm.saveSessionFile(session);
2618
+ return true;
2589
2619
  }
2590
2620
  try {
2591
2621
  // Route through QueryHandle (works for both in-process and worker paths)
2592
2622
  await session.queryInstance.setPermissionMode(mode);
2593
2623
  session.permissionMode = mode;
2624
+ sm.saveSessionFile(session);
2594
2625
  // config_state sent targeted by caller — no broadcast here.
2626
+ return true;
2595
2627
  } catch (e) {
2596
2628
  send({ type: "error", text: "Failed to set permission mode: " + (e.message || e) });
2629
+ return false;
2597
2630
  }
2598
2631
  }
2599
2632
 
@@ -2651,6 +2684,7 @@ function createSDKBridge(opts) {
2651
2684
  setModel: setModel,
2652
2685
  setEffort: setEffort,
2653
2686
  setPermissionMode: setPermissionMode,
2687
+ checkModeFor: checkModeFor,
2654
2688
  isClaudeProcess: isClaudeProcess,
2655
2689
  permissionPushTitle: permissionPushTitle,
2656
2690
  permissionPushBody: permissionPushBody,
package/lib/server.js CHANGED
@@ -222,14 +222,13 @@ function isPublicShellAssetPath(projectUrlPath) {
222
222
 
223
223
  /**
224
224
  * Create a multi-project server.
225
- * opts: { tlsOptions, caPath, pinHash, port, debug, dangerouslySkipPermissions }
225
+ * opts: { tlsOptions, caPath, pinHash, port, debug }
226
226
  */
227
227
  function createServer(opts) {
228
228
  var tlsOptions = opts.tlsOptions || null;
229
229
  var caPath = opts.caPath || null;
230
230
  var portNum = opts.port || 2633;
231
231
  var debug = opts.debug || false;
232
- var dangerouslySkipPermissions = opts.dangerouslySkipPermissions || false;
233
232
  var osUsers = opts.osUsers || false;
234
233
  var lanHost = opts.lanHost || null;
235
234
  // lr-20e71c: operator-declared trust boundary for reading X-Forwarded-Proto
@@ -266,6 +265,8 @@ function createServer(opts) {
266
265
  var onSetServerDefaultMode = opts.onSetServerDefaultMode || null;
267
266
  var onGetProjectDefaultMode = opts.onGetProjectDefaultMode || null;
268
267
  var onSetProjectDefaultMode = opts.onSetProjectDefaultMode || null;
268
+ var onGetPermissionSettings = opts.onGetPermissionSettings || null;
269
+ var onSetPermissionSettings = opts.onSetPermissionSettings || null;
269
270
  var onGetServerDefaultBetas = opts.onGetServerDefaultBetas || null;
270
271
  var onSetServerDefaultBetas = opts.onSetServerDefaultBetas || null;
271
272
  var onGetProjectDefaultBetas = opts.onGetProjectDefaultBetas || null;
@@ -398,6 +399,10 @@ function createServer(opts) {
398
399
  // send-input).
399
400
  var _sessionInput = require("./session-input").createSessionInput({
400
401
  getProject: function (slug) { return projects.get(slug) || null; },
402
+ // Read when a session is opened, so a change needs no restart.
403
+ getPermissionSettings: function () {
404
+ return onGetPermissionSettings ? onGetPermissionSettings() : null;
405
+ },
401
406
  listProjects: function () {
402
407
  var held = [];
403
408
  projects.forEach(function (ctx, slug) { held.push({ slug: slug, project: ctx }); });
@@ -1330,7 +1335,6 @@ function createServer(opts) {
1330
1335
  worktreeMeta: worktreeMeta || null,
1331
1336
  pushModule: pushModule,
1332
1337
  debug: debug,
1333
- dangerouslySkipPermissions: dangerouslySkipPermissions,
1334
1338
  osUsers: osUsers,
1335
1339
  currentVersion: currentVersion,
1336
1340
  lanHost: lanHost,
@@ -1483,6 +1487,8 @@ function createServer(opts) {
1483
1487
  onSetServerDefaultMode: onSetServerDefaultMode,
1484
1488
  onGetProjectDefaultMode: onGetProjectDefaultMode,
1485
1489
  onSetProjectDefaultMode: onSetProjectDefaultMode,
1490
+ onGetPermissionSettings: onGetPermissionSettings,
1491
+ onSetPermissionSettings: onSetPermissionSettings,
1486
1492
  onGetServerDefaultBetas: onGetServerDefaultBetas,
1487
1493
  onSetServerDefaultBetas: onSetServerDefaultBetas,
1488
1494
  onGetProjectDefaultBetas: onGetProjectDefaultBetas,
@@ -20,6 +20,7 @@ function handleSessionCommand(sessionInput, msg) {
20
20
  agentName: msg.agentName,
21
21
  sessionName: msg.sessionName,
22
22
  sessionVisibility: msg.sessionVisibility,
23
+ permissionMode: msg.permissionMode,
23
24
  initiator: msg.initiator,
24
25
  });
25
26
  }
@@ -22,6 +22,8 @@ var { validateFrom, validateFromSession, senderFields, forClient, stampRecord, n
22
22
  var senderRef = require("./sender-ref");
23
23
  var { findNameHolder, releaseReapedHolders } = require("./session-name-holder");
24
24
  var directory = require("./session-directory");
25
+ var permissionSettings = require("./permission-settings");
26
+ var { checkPermissionMode } = require("./permission-mode-policy");
25
27
  var { slugifyAgentName } = agentsModule;
26
28
 
27
29
  // The result vocabulary reported to the caller. "error" is not a verdict on
@@ -179,6 +181,8 @@ function present(value) {
179
181
  // getProject(slug) -> project context | null
180
182
  // listProjects() -> [{ slug, project }] every project held (default: none)
181
183
  // agentCatalog(project) -> [{ name }] named agents on offer (default: the picker's catalog)
184
+ // getPermissionSettings() -> the server's permission settings (lib/permission-settings.js)
185
+ // or null (default: the settings' defaults)
182
186
  function createSessionInput(deps) {
183
187
  var getProject = deps.getProject;
184
188
  var listProjects = deps.listProjects || function () { return []; };
@@ -609,6 +613,35 @@ function createSessionInput(deps) {
609
613
  return holder ? "session " + String(holder.localId) : null;
610
614
  }
611
615
 
616
+ // The mode a session opened here starts in: the request's own permissionMode,
617
+ // else the server setting "Mode for sessions opened by the CLI or a trigger",
618
+ // else accept edits. Every value passes the shared mode check for the vendor
619
+ // the session will run on. A mode the request names that fails it refuses the
620
+ // open; a stored setting that fails it falls back to accept edits (logged).
621
+ // Returns { mode } or { refusal }.
622
+ function resolveOpenMode(project, req, options) {
623
+ if (req.permissionMode !== undefined && req.permissionMode !== null && typeof req.permissionMode !== "string") {
624
+ return { refusal: refused("permissionMode must be a string") };
625
+ }
626
+ var settings = deps.getPermissionSettings ? deps.getPermissionSettings() : null;
627
+ var vendorProbe = { vendor: options.vendor || null };
628
+ var chosen = permissionSettings.resolveOpenedSessionMode({
629
+ requested: req.permissionMode,
630
+ setting: settings && settings.openedSessionMode,
631
+ check: function (mode) {
632
+ // A project without the vendor-aware check (a bare double) still gets
633
+ // the mode and server-setting checks.
634
+ if (typeof project.checkPermissionModeFor === "function") return project.checkPermissionModeFor(vendorProbe, mode);
635
+ return checkPermissionMode(mode, {});
636
+ },
637
+ onFallback: function (why) {
638
+ console.warn("[session-input] stored opened-session mode " + logField(settings.openedSessionMode) + " refused (" + why + "); using " + permissionSettings.DEFAULT_OPENED_SESSION_MODE);
639
+ },
640
+ });
641
+ if (chosen.error) return { refusal: refused("permissionMode " + shown(req.permissionMode) + " refused: " + chosen.error) };
642
+ return { mode: chosen.mode };
643
+ }
644
+
612
645
  // The token of an address, for a session to open: a named agent of the project's
613
646
  // catalog, else a vendor (opening addresses no existing session, so there is
614
647
  // nothing to be ambiguous). Returns { kind: { agentName } | { vendor } } or { refusal }.
@@ -622,7 +655,7 @@ function createSessionInput(deps) {
622
655
  }
623
656
 
624
657
  // req: { projectSlug, prompt, vendor?, agentName?, sessionVisibility?,
625
- // initiator?, contextNote?, cwd?, triggerId? }
658
+ // permissionMode?, initiator?, contextNote?, cwd?, triggerId? }
626
659
  // Returns the result, or a Promise of it when the first turn starts
627
660
  // asynchronously (see settle()).
628
661
  function openSession(req) {
@@ -660,11 +693,17 @@ function createSessionInput(deps) {
660
693
  }
661
694
  var kind = resolveSessionKind(project, req);
662
695
  if (kind.refusal) return kind.refusal;
696
+ var openMode = resolveOpenMode(project, req, kind.options);
697
+ if (openMode.refusal) return openMode.refusal;
663
698
  var gate = getNewWorkRefusal();
664
699
  if (gate) return refusedForLoad(gate);
665
700
 
666
701
  var sm = project.sm;
667
- var sess = sm.createSession(kind.options);
702
+ // The opened mode is given at creation, so the session_switched that
703
+ // createSession emits already carries it (not the project default). It is
704
+ // saved with the session just below: a follow-up from a person, a resume
705
+ // and a restart all keep it.
706
+ var sess = sm.createSession(Object.assign({}, kind.options, { permissionMode: openMode.mode }));
668
707
  var label = req.triggerId ? " — " + String(req.triggerId).substring(0, 12) : "";
669
708
  sess.title = (req.contextNote || "External trigger") + label;
670
709
  if (req.cwd) sess.cwd = req.cwd;
@@ -674,8 +713,6 @@ function createSessionInput(deps) {
674
713
  sess.isProcessing = true;
675
714
  project.onProcessingChanged();
676
715
  sess.sentToolResults = {};
677
- // The session stays open for follow-up from a person.
678
- sess.acceptEditsAfterStart = true;
679
716
 
680
717
  function opened() {
681
718
  var out = describe(project, sess);
@@ -127,6 +127,8 @@ function resumeStoredSession(deps, cliSessionId, opts) {
127
127
  if (meta.sessionName) resumeOpts.sessionName = meta.sessionName;
128
128
  if (meta.ownerId) resumeOpts.ownerId = meta.ownerId;
129
129
  if (meta.sessionVisibility) resumeOpts.sessionVisibility = meta.sessionVisibility;
130
+ // The mode the session had; the session manager checks it before use.
131
+ if (typeof meta.permissionMode === "string" && meta.permissionMode) resumeOpts.permissionMode = meta.permissionMode;
130
132
  // Sanitized so a crafted meta record cannot auto-approve a tool.
131
133
  if (meta.allowedTools) resumeOpts.allowedTools = utils.sanitizeAllowedTools(meta.allowedTools);
132
134
  }
package/lib/sessions.js CHANGED
@@ -12,6 +12,8 @@ var sessionReclaim = require("./session-reclaim");
12
12
  var sessionFileScan = require("./session-file-scan");
13
13
  var { findNameHolder } = require("./session-name-holder");
14
14
  var { createSenderRecorder } = require("./message-sender-record");
15
+ var { checkPermissionMode, savedModeOrDefault } = require("./permission-mode-policy");
16
+ var { logField } = require("./log-field");
15
17
 
16
18
  // lr-2ea2a7: hard cap on how many history entries a session may hold in the
17
19
  // heap array, regardless of isProcessing state. On-disk JSONL remains the
@@ -42,6 +44,16 @@ function effectiveSessionModel(session, sm) {
42
44
  return (sm && sm.currentModel) || "";
43
45
  }
44
46
 
47
+ // The permission mode THIS session's clients should see: the session's own
48
+ // (saved with it), falling back to the project default only for a session that
49
+ // has none. Every client-facing push of a session's mode reads it here, never
50
+ // the shared sm.currentPermissionMode, which is the project default and not any
51
+ // one session's mode (the same split as effectiveSessionModel above).
52
+ function effectiveSessionMode(session, sm) {
53
+ if (session && session.permissionMode) return session.permissionMode;
54
+ return (sm && sm.currentPermissionMode) || "default";
55
+ }
56
+
45
57
  // Message types whose client-side handler writes the global client-local
46
58
  // 'processing'/'sessionIsProcessing' edge latch (app-messages.js's status/
47
59
  // done/auth_required handlers). Stamping localId at the shared send choke
@@ -162,6 +174,9 @@ function createSessionManager(opts) {
162
174
  // the project/global default happened to be, indistinguishable from the
163
175
  // user never having picked a model at all.
164
176
  if (session.model) metaObj.model = session.model;
177
+ // The session's own permission mode, so a resume or a restart keeps it
178
+ // instead of taking whatever the project default is by then.
179
+ if (session.permissionMode) metaObj.permissionMode = session.permissionMode;
165
180
  // Persist per-session "allow for session" tool grants (lr-8b2e) so they
166
181
  // survive daemon restart / resume-by-cliSessionId rehydration instead of
167
182
  // silently re-prompting. Only written when non-empty — grants that were
@@ -783,6 +798,19 @@ function createSessionManager(opts) {
783
798
  // restart — see buildMetaLine's write side above for why this must
784
799
  // persist (session.model, not the project/global default).
785
800
  if (m.model) session.model = m.model;
801
+ // The saved permission mode, through the same check as any mode entering
802
+ // the server. One that fails it (a bypass written while the server
803
+ // allowed it, or by hand) loads as "default" and says so. The vendor
804
+ // check waits for query start, when the vendor's capabilities are known.
805
+ // A session saved before modes were kept has none and takes the project
806
+ // default when the project finishes starting (lib/project.js).
807
+ if (m.permissionMode) {
808
+ var savedMode = savedModeOrDefault(m.permissionMode);
809
+ if (savedMode.error) {
810
+ console.warn("[sessions] saved permission mode " + logField(m.permissionMode) + " of session " + logField(m.cliSessionId) + " refused (" + savedMode.error + "); using default");
811
+ }
812
+ session.permissionMode = savedMode.mode;
813
+ }
786
814
  if (m.ownerId) session.ownerId = m.ownerId;
787
815
  session.sessionVisibility = m.sessionVisibility || "shared";
788
816
  session.bookmarked = !!m.bookmarked;
@@ -894,6 +922,31 @@ function createSessionManager(opts) {
894
922
  }
895
923
  }
896
924
 
925
+ // A new session takes its mode at creation and keeps it (it is saved with the
926
+ // session): the mode the creator names, else the project's default. Before the
927
+ // project has loaded its default (the session made while this manager is
928
+ // built) there is none to give; lib/project.js gives it once it does.
929
+ function giveStartingMode(session, sessionOpts) {
930
+ var mode;
931
+ if (sessionOpts && sessionOpts.permissionMode) {
932
+ // Named by the creator, or read from a stored record on resume: checked
933
+ // like any mode that enters the server, with the session's vendor once
934
+ // that vendor has reported what it can run.
935
+ var vendorCaps = capabilitiesByVendor && (sessionOpts.vendor || defaultVendor)
936
+ ? capabilitiesByVendor[sessionOpts.vendor || defaultVendor] : null;
937
+ var verdict = checkPermissionMode(sessionOpts.permissionMode, {
938
+ supportedModes: vendorCaps && Array.isArray(vendorCaps.permissionModes) ? vendorCaps.permissionModes : null,
939
+ });
940
+ if (!verdict.ok) {
941
+ console.warn("[sessions] permission mode " + logField(sessionOpts.permissionMode) + " refused for a new session (" + verdict.error + "); using default");
942
+ }
943
+ mode = verdict.ok ? sessionOpts.permissionMode : "default";
944
+ } else {
945
+ mode = _instance && _instance._savedDefaultMode;
946
+ }
947
+ if (mode) session.permissionMode = mode;
948
+ }
949
+
897
950
  function createSession(sessionOpts, targetWs) {
898
951
  var localId = nextLocalId++;
899
952
  var session = {
@@ -924,6 +977,7 @@ function createSessionManager(opts) {
924
977
  agentName: (sessionOpts && sessionOpts.agentName) || null,
925
978
  sessionName: (sessionOpts && sessionOpts.sessionName) || null,
926
979
  };
980
+ giveStartingMode(session, sessionOpts);
927
981
  sessions.set(localId, session);
928
982
  switchSession(localId, targetWs);
929
983
  return session;
@@ -959,6 +1013,7 @@ function createSessionManager(opts) {
959
1013
  vendor: (sessionOpts && sessionOpts.vendor) || null,
960
1014
  agentName: (sessionOpts && sessionOpts.agentName) || null,
961
1015
  };
1016
+ giveStartingMode(session, sessionOpts);
962
1017
  sessions.set(localId, session);
963
1018
  return session;
964
1019
  }
@@ -1161,7 +1216,7 @@ function createSessionManager(opts) {
1161
1216
  // client hydrating from session_switched alone (no separate config_state
1162
1217
  // round-trip needed) never has to fall back to guessing the shared
1163
1218
  // project/global default — see effectiveSessionModel() above.
1164
- _send({ type: "session_switched", id: localId, cliSessionId: session.cliSessionId || null, loop: session.loop || null, vendor: session.vendor || null, model: effectiveSessionModel(session, _instance), hasHistory: (session._historyLoaded ? session.history.length > 0 : !!session.cliSessionId), capabilities: _vendorCaps, isProcessing: !!session.isProcessing, agentName: session.agentName || null });
1219
+ _send({ type: "session_switched", id: localId, cliSessionId: session.cliSessionId || null, loop: session.loop || null, vendor: session.vendor || null, model: effectiveSessionModel(session, _instance), mode: effectiveSessionMode(session, _instance), hasHistory: (session._historyLoaded ? session.history.length > 0 : !!session.cliSessionId), capabilities: _vendorCaps, isProcessing: !!session.isProcessing, agentName: session.agentName || null });
1165
1220
  // Send vendor-specific slash commands
1166
1221
  var _vendorCmds = slashCommandsByVendor[_sessionVendor] || slashCommands || [];
1167
1222
  _send({ type: "slash_commands", commands: _vendorCmds, vendor: _sessionVendor });
@@ -1442,6 +1497,8 @@ function createSessionManager(opts) {
1442
1497
  };
1443
1498
  if (opts && opts.vendor) session.vendor = opts.vendor;
1444
1499
  if (opts && opts.agentName) session.agentName = opts.agentName;
1500
+ // A session resumed from its stored record keeps the mode saved with it.
1501
+ giveStartingMode(session, opts);
1445
1502
  if (opts && opts.sessionName) {
1446
1503
  // The resume is never refused over a name: when another session holds it,
1447
1504
  // this one comes back unnamed and saveSessionFile below clears the meta.
@@ -1720,6 +1777,13 @@ function createSessionManager(opts) {
1720
1777
  set codexWebSearch(v) { codexWebSearch = v; },
1721
1778
  sessions: sessions,
1722
1779
  sessionsDir: sessionsDir,
1780
+ // Once the project has loaded its default mode: a session saved before
1781
+ // sessions kept their own mode (or made before the default was known) takes
1782
+ // that default now and keeps it, so a later change of the default does not
1783
+ // move it. In memory only; it is saved with the session's next write.
1784
+ adoptDefaultMode: function (mode) {
1785
+ sessions.forEach(function (s) { if (!s.permissionMode) s.permissionMode = mode; });
1786
+ },
1723
1787
  HISTORY_PAGE_SIZE: HISTORY_PAGE_SIZE,
1724
1788
  getActiveSession: getActiveSession,
1725
1789
  createSession: createSession,
@@ -1880,6 +1944,7 @@ function createSessionManager(opts) {
1880
1944
  // `sm.effectiveSessionModel(session)` without importing this module
1881
1945
  // separately.
1882
1946
  effectiveSessionModel: function (session) { return effectiveSessionModel(session, _instance); },
1947
+ effectiveSessionMode: function (session) { return effectiveSessionMode(session, _instance); },
1883
1948
  // Called when the project owning this session manager is torn down. No
1884
1949
  // prompt resolver outlives it, so every pending prompt ends here and its
1885
1950
  // outcome is flushed to disk; then the exit flusher registered above is
@@ -1894,4 +1959,4 @@ function createSessionManager(opts) {
1894
1959
  return _instance;
1895
1960
  }
1896
1961
 
1897
- module.exports = { createSessionManager, effectiveSessionModel, stampActivityLocalId };
1962
+ module.exports = { createSessionManager, effectiveSessionModel, effectiveSessionMode, stampActivityLocalId };
package/lib/updater.js CHANGED
@@ -96,8 +96,14 @@ function performUpdate(version) {
96
96
  }
97
97
  }
98
98
 
99
+ // Argument vector handed to node on re-exec: the script path and the original
100
+ // arguments, plus --no-update. Split out so a test can read the real argv shape.
101
+ function reExecArgs(argv) {
102
+ return argv.slice(1).concat("--no-update");
103
+ }
104
+
99
105
  function reExec() {
100
- var args = process.argv.slice(1).concat("--no-update");
106
+ var args = reExecArgs(process.argv);
101
107
  var child = spawn(process.execPath, args, { stdio: "inherit" });
102
108
  child.on("exit", function (code) {
103
109
  process.exit(code);
@@ -144,4 +150,4 @@ async function checkAndUpdate(currentVersion, skipUpdate, channel) {
144
150
  return false;
145
151
  }
146
152
 
147
- module.exports = { checkAndUpdate, fetchLatestVersion, fetchVersion, isNewer };
153
+ module.exports = { checkAndUpdate, fetchLatestVersion, fetchVersion, isNewer, reExecArgs };
package/lib/ws-schema.js CHANGED
@@ -198,7 +198,8 @@ var schema = {
198
198
  "set_server_default_model": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the server-wide default model" },
199
199
  "set_project_default_model": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the project default model" },
200
200
  "set_permission_mode": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set permission mode for the current session" },
201
- "set_server_default_mode": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the server-wide default permission mode" },
201
+ "set_server_default_mode": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the server-wide default permission mode; applyToRunning: true also re-modes this project's sessions" },
202
+ "set_permission_settings": { direction: "c2s", handler: "lib/project-permission-settings.js", description: "Change the server-wide permission settings (admin only): autoApproveReadOnly, openedSessionMode" },
202
203
  "set_project_default_mode": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the project default permission mode" },
203
204
  "set_effort": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set effort level for the current session" },
204
205
  "set_server_default_effort": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the server-wide default effort level" },
@@ -210,7 +211,9 @@ var schema = {
210
211
  "model_info": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Current model and available models list" },
211
212
  "vendor_registry": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Every registered agent with display data, install state, login command and capabilities; the agent picker and capability-gated controls render from it" },
212
213
  "recheck_vendors": { direction: "c2s", handler: "lib/project-sessions.js", description: "Look again for installed agents and broadcast the vendor registry" },
213
- "config_state": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Full config state: model, mode, effort, betas, thinking" },
214
+ "config_state": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Config state: model, effort, betas, thinking, and the viewed session's mode (absent when the push is not about a mode)" },
215
+ "permission_settings": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "The server-wide permission settings: autoApproveReadOnly, openedSessionMode" },
216
+ "permission_mode_applied": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Result of applying a new default mode to the running sessions: applied count and skipped sessions with reasons" },
214
217
  "slash_commands": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Available slash commands list" },
215
218
  "fast_mode_state": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Fast mode toggle state" },
216
219
  "client_count": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Number of connected clients" },
@@ -1647,7 +1647,6 @@ function createClaudeAdapter(opts) {
1647
1647
  if (co.thinking) sdkOptions.thinking = co.thinking;
1648
1648
  if (co.betas && co.betas.length > 0) sdkOptions.betas = co.betas;
1649
1649
  if (co.permissionMode) sdkOptions.permissionMode = co.permissionMode;
1650
- if (co.allowDangerouslySkipPermissions) sdkOptions.allowDangerouslySkipPermissions = true;
1651
1650
  if (co.resumeSessionAt) sdkOptions.resumeSessionAt = co.resumeSessionAt;
1652
1651
  if (co.settings) sdkOptions.settings = co.settings;
1653
1652
 
@@ -1766,7 +1765,6 @@ function createClaudeAdapter(opts) {
1766
1765
  if (claudeOpts.thinking) queryOptions.thinking = claudeOpts.thinking;
1767
1766
  if (claudeOpts.betas && claudeOpts.betas.length > 0) queryOptions.betas = claudeOpts.betas;
1768
1767
  if (claudeOpts.permissionMode) queryOptions.permissionMode = claudeOpts.permissionMode;
1769
- if (claudeOpts.allowDangerouslySkipPermissions) queryOptions.allowDangerouslySkipPermissions = true;
1770
1768
  if (claudeOpts.settings) queryOptions.settings = claudeOpts.settings;
1771
1769
  // The worker lays these over its own environment (the OS user's), then
1772
1770
  // hands the SDK the complete result.
@@ -1820,10 +1818,6 @@ function createClaudeAdapter(opts) {
1820
1818
  };
1821
1819
  if (_claudeBinaryPath) warmupOptions.pathToClaudeCodeExecutable = _claudeBinaryPath;
1822
1820
 
1823
- if (initOpts && initOpts.dangerouslySkipPermissions) {
1824
- warmupOptions.permissionMode = "bypassPermissions";
1825
- warmupOptions.allowDangerouslySkipPermissions = true;
1826
- }
1827
1821
  // The warmup starts the same CLI a query does, so it gets the same environment.
1828
1822
  warmupOptions.env = turnInitiator.claudeProcessEnv(process.env, initOpts && initOpts.runtimeEnv);
1829
1823
 
@@ -1893,10 +1887,6 @@ function createClaudeAdapter(opts) {
1893
1887
 
1894
1888
  var warmupOptions = { cwd: workerCwd, settingSources: ["user", "project", "local"], settings: { disableAllHooks: true } };
1895
1889
  if (_claudeBinaryPath) warmupOptions.pathToClaudeCodeExecutable = _claudeBinaryPath;
1896
- if (initOpts && initOpts.dangerouslySkipPermissions) {
1897
- warmupOptions.permissionMode = "bypassPermissions";
1898
- warmupOptions.allowDangerouslySkipPermissions = true;
1899
- }
1900
1890
  if (initOpts && runtimeEnv.hasOverlay(initOpts.runtimeEnv)) warmupOptions.runtimeEnv = initOpts.runtimeEnv;
1901
1891
 
1902
1892
  return new Promise(function(resolve, reject) {