@clagentic/console 1.12.0-beta.2 → 1.12.0

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 (127) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/bin/cli.js +4 -2
  3. package/lib/agent-roster-ws.js +84 -0
  4. package/lib/agent-roster.js +312 -0
  5. package/lib/auth-required-notify.js +42 -0
  6. package/lib/build-sha.json +2 -2
  7. package/lib/build-update-notify.js +45 -0
  8. package/lib/build-update-offer.js +3 -4
  9. package/lib/build-update-standing.js +34 -14
  10. package/lib/cli/session-subcommands.js +26 -8
  11. package/lib/client-address.js +44 -0
  12. package/lib/daemon.js +25 -10
  13. package/lib/idle-compaction-setting.js +203 -0
  14. package/lib/mcp-bridge-credential.js +41 -0
  15. package/lib/notification-prefs.js +16 -22
  16. package/lib/notify/core.js +53 -18
  17. package/lib/notify/payload.js +2 -3
  18. package/lib/notify/type-registry.js +17 -0
  19. package/lib/notify/types.js +38 -1
  20. package/lib/outbound-access.js +12 -1
  21. package/lib/outbound-entry.js +8 -1
  22. package/lib/project-connection.js +9 -8
  23. package/lib/project-filesystem.js +23 -0
  24. package/lib/project-loop.js +16 -19
  25. package/lib/project-notifications.js +68 -7
  26. package/lib/project-sessions.js +9 -0
  27. package/lib/project-user-mention.js +22 -34
  28. package/lib/project-user-message.js +208 -4
  29. package/lib/project-user-shell.js +298 -0
  30. package/lib/project.js +26 -4
  31. package/lib/prompt-answer.js +145 -0
  32. package/lib/prompt-expiry.js +50 -0
  33. package/lib/prompt-registry.js +24 -1
  34. package/lib/prompt-source.js +16 -0
  35. package/lib/public/app.js +31 -2
  36. package/lib/public/css/agent-messages.css +96 -0
  37. package/lib/public/css/agent-roster.css +93 -0
  38. package/lib/public/css/diagnostics.css +1 -1
  39. package/lib/public/css/input.css +20 -141
  40. package/lib/public/css/login-panel.css +73 -0
  41. package/lib/public/css/menus.css +2 -2
  42. package/lib/public/css/sidebar.css +11 -0
  43. package/lib/public/css/team-panel.css +1 -6
  44. package/lib/public/css/team-view.css +101 -0
  45. package/lib/public/css/title-bar.css +10 -0
  46. package/lib/public/css/user-shell.css +144 -0
  47. package/lib/public/index.html +41 -7
  48. package/lib/public/modules/agent-avatar-picker.js +162 -0
  49. package/lib/public/modules/agent-avatar.js +153 -0
  50. package/lib/public/modules/agent-messages.js +285 -0
  51. package/lib/public/modules/agent-roster.js +157 -0
  52. package/lib/public/modules/app-connection.js +12 -0
  53. package/lib/public/modules/app-messages.js +55 -16
  54. package/lib/public/modules/app-notifications.js +59 -29
  55. package/lib/public/modules/app-panels.js +26 -3
  56. package/lib/public/modules/app-rate-limit.js +8 -165
  57. package/lib/public/modules/app-rendering.js +22 -7
  58. package/lib/public/modules/collapsible-text.js +33 -18
  59. package/lib/public/modules/compaction-state.js +34 -0
  60. package/lib/public/modules/custom-icons.js +23 -5
  61. package/lib/public/modules/diagnostics.js +52 -55
  62. package/lib/public/modules/injected-identity.js +24 -21
  63. package/lib/public/modules/input.js +176 -15
  64. package/lib/public/modules/login-panel.js +136 -0
  65. package/lib/public/modules/login-parser.js +73 -0
  66. package/lib/public/modules/login-tab.js +66 -0
  67. package/lib/public/modules/notifications.js +9 -1
  68. package/lib/public/modules/notify-client.js +114 -21
  69. package/lib/public/modules/pending-term-request.js +30 -0
  70. package/lib/public/modules/project-icon.js +22 -2
  71. package/lib/public/modules/queued-button.js +11 -0
  72. package/lib/public/modules/scheduled-input-actions.js +12 -4
  73. package/lib/public/modules/scheduled-outbox.js +230 -0
  74. package/lib/public/modules/send-now.js +200 -0
  75. package/lib/public/modules/server-settings.js +47 -1
  76. package/lib/public/modules/shell-card.js +76 -0
  77. package/lib/public/modules/shell-line.js +49 -0
  78. package/lib/public/modules/shell-queue.js +253 -0
  79. package/lib/public/modules/shell-settings-controls.js +76 -0
  80. package/lib/public/modules/sidebar-mobile.js +3 -3
  81. package/lib/public/modules/sidebar-sessions.js +8 -0
  82. package/lib/public/modules/sidebar-users.js +5 -7
  83. package/lib/public/modules/team-panel.js +30 -88
  84. package/lib/public/modules/team-view.js +211 -0
  85. package/lib/public/modules/terminal-links.js +18 -0
  86. package/lib/public/modules/terminal.js +65 -4
  87. package/lib/public/modules/tools.js +19 -0
  88. package/lib/public/modules/user-shell.js +824 -0
  89. package/lib/public/notify-sw-logic.js +35 -83
  90. package/lib/public/notify-target.js +70 -10
  91. package/lib/public/style.css +5 -0
  92. package/lib/public/sw.js +7 -3
  93. package/lib/queued-chat.js +392 -0
  94. package/lib/scheduled-input/ws.js +67 -9
  95. package/lib/sdk-bridge.js +122 -43
  96. package/lib/sdk-message-processor.js +46 -39
  97. package/lib/server-auth.js +6 -4
  98. package/lib/server-dm.js +11 -20
  99. package/lib/server-settings.js +39 -1
  100. package/lib/server.js +83 -19
  101. package/lib/session-directory.js +33 -8
  102. package/lib/session-end.js +97 -0
  103. package/lib/session-input-ipc.js +26 -0
  104. package/lib/session-input.js +176 -9
  105. package/lib/session-resume.js +1 -0
  106. package/lib/session-settings-file.js +53 -0
  107. package/lib/sessions.js +49 -5
  108. package/lib/team-traffic-ws.js +68 -0
  109. package/lib/team-traffic.js +318 -0
  110. package/lib/usage-store.js +7 -0
  111. package/lib/user-shell-settings.js +105 -0
  112. package/lib/ws-schema.js +27 -4
  113. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  114. package/lib/yoke/adapters/claude-vendor.js +6 -0
  115. package/lib/yoke/adapters/claude-worker.js +39 -11
  116. package/lib/yoke/adapters/claude.js +218 -6
  117. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  118. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  119. package/lib/yoke/adapters/codex-vendor.js +7 -0
  120. package/lib/yoke/adapters/codex.js +186 -52
  121. package/lib/yoke/codex-app-server.js +8 -2
  122. package/lib/yoke/interface.js +54 -1
  123. package/lib/yoke/mcp-bridge-server.js +12 -8
  124. package/lib/yoke/registry.js +32 -0
  125. package/lib/yoke/user-shell.js +224 -0
  126. package/package.json +1 -1
  127. package/lib/public/modules/build-notice-gate.js +0 -73
@@ -0,0 +1,230 @@
1
+ // scheduled-outbox.js - the session's armed scheduled inputs, drawn in the
2
+ // composer's outbox beside the queued chat and ! items. The scheduled-input
3
+ // service is the store and the scheduler: the page draws the list the server
4
+ // sends (scheduled_input_list) and sends Fire now and Cancel back. Nothing here
5
+ // is kept or timed by the page except the countdown text.
6
+ //
7
+ // One rendering per schedule: this row is the only one in the composer (the
8
+ // schedule panel's list is a separate surface). The rows share one container,
9
+ // which addToMessages keeps at the end of the message list, after the queued
10
+ // items.
11
+
12
+ import { addToMessages, scrollToBottom } from './app-rendering.js';
13
+ import { sendScheduledNow, cancelScheduledInput } from './scheduled-input-actions.js';
14
+ import { countdownText } from './schedule-time.js';
15
+ import { currentSendNowState, sendNowLabel } from './send-now.js';
16
+ import { queuedButton } from './queued-button.js';
17
+ import { buildCollapsibleText, needsCollapse, isNonTypedInput } from './collapsible-text.js';
18
+
19
+ var containerEl = null;
20
+ var countdowns = [];
21
+ var countdownTimer = null;
22
+ // Rows with a Fire now or Cancel request sent and not yet answered: schedule id
23
+ // -> the request id sent. The server already refuses a second send; this only
24
+ // keeps a second click from being made. A row is freed by the server's answer
25
+ // to that request (scheduled_request_result, or an error carrying the same
26
+ // request id), by the list no longer having it, or by a reconnect.
27
+ var inFlight = {};
28
+ var failures = {};
29
+ var requestSeq = 0;
30
+
31
+ function tickCountdowns() {
32
+ var now = Date.now();
33
+ countdowns.forEach(function (c) { c.el.textContent = countdownText(c.input, now); });
34
+ }
35
+
36
+ // Fire now follows the capability table like Send now of the other kinds; a
37
+ // disabled state is aria-disabled so a tap can still say why.
38
+ function paintFireNow(btn) {
39
+ var st = currentSendNowState("scheduled");
40
+ var off = st.mode === "disabled";
41
+ btn.classList.toggle("unavailable", off);
42
+ btn.setAttribute("aria-disabled", off ? "true" : "false");
43
+ btn.title = off
44
+ ? sendNowLabel("scheduled") + " (unavailable): " + st.reason
45
+ : sendNowLabel("scheduled") + ": deliver this schedule now";
46
+ }
47
+
48
+ function paintBusy(row, id) {
49
+ var busy = !!inFlight[id];
50
+ row.fireBtn.disabled = busy;
51
+ row.cancelBtn.disabled = busy;
52
+ row.fireBtn.setAttribute("aria-busy", busy ? "true" : "false");
53
+ row.cancelBtn.setAttribute("aria-busy", busy ? "true" : "false");
54
+ row.errorEl.textContent = failures[id] || "";
55
+ }
56
+
57
+ function repaintRow(id) {
58
+ if (!containerEl) return;
59
+ rows.forEach(function (r) { if (r.id === id) paintBusy(r, id); });
60
+ }
61
+
62
+ var rows = [];
63
+
64
+ // Sends one request for the row; a refused send frees the row at once, the
65
+ // server's answer frees it through completeScheduledRequest or
66
+ // failScheduledRequests, matched on the request id.
67
+ function request(id, send) {
68
+ if (inFlight[id]) return;
69
+ var requestId = "sr_" + (++requestSeq);
70
+ inFlight[id] = requestId;
71
+ delete failures[id];
72
+ repaintRow(id);
73
+ if (send(id, requestId) === false) {
74
+ delete inFlight[id];
75
+ failures[id] = "Could not send the request: the connection is not open.";
76
+ repaintRow(id);
77
+ }
78
+ }
79
+
80
+ function buildRow(input) {
81
+ var el = document.createElement("div");
82
+ el.className = "shell-queued scheduled-queued";
83
+ el.setAttribute("data-id", input.id);
84
+
85
+ var tag = document.createElement("span");
86
+ tag.className = "shell-queued-tag";
87
+ tag.textContent = "Scheduled";
88
+
89
+ var when = document.createElement("span");
90
+ when.className = "scheduled-queued-time";
91
+
92
+ var body = document.createElement("span");
93
+ body.className = "shell-queued-text";
94
+ var toggle = null;
95
+ // A schedule is input the console pushes in later: the same rule as its delivery.
96
+ if (isNonTypedInput({ initiator: "scheduled", senderKind: "automation" }) && needsCollapse(input.text)) {
97
+ var collapsible = buildCollapsibleText(input.text);
98
+ body.appendChild(collapsible.el);
99
+ toggle = collapsible.button;
100
+ } else {
101
+ body.textContent = input.text;
102
+ }
103
+
104
+ var actions = document.createElement("span");
105
+ actions.className = "shell-queued-actions";
106
+ var fireBtn = queuedButton(sendNowLabel("scheduled"), "shell-queued-send-now scheduled-queued-fire");
107
+ fireBtn.addEventListener("click", function () {
108
+ var st = currentSendNowState("scheduled");
109
+ if (st.mode === "disabled") return;
110
+ request(input.id, sendScheduledNow);
111
+ });
112
+ var cancelBtn = queuedButton("Cancel", "shell-queued-cancel scheduled-queued-cancel");
113
+ cancelBtn.addEventListener("click", function () { request(input.id, cancelScheduledInput); });
114
+ actions.appendChild(fireBtn);
115
+ actions.appendChild(cancelBtn);
116
+ if (toggle) {
117
+ toggle.classList.add("shell-queued-btn");
118
+ actions.appendChild(toggle);
119
+ }
120
+ paintFireNow(fireBtn);
121
+
122
+ var errorEl = document.createElement("span");
123
+ errorEl.className = "scheduled-queued-error";
124
+ errorEl.setAttribute("role", "alert");
125
+
126
+ el.appendChild(tag);
127
+ el.appendChild(when);
128
+ el.appendChild(body);
129
+ el.appendChild(actions);
130
+ el.appendChild(errorEl);
131
+ var row = { id: input.id, el: el, when: when, fireBtn: fireBtn, cancelBtn: cancelBtn, errorEl: errorEl };
132
+ paintBusy(row, input.id);
133
+ return row;
134
+ }
135
+
136
+ function rowsOfRequest(requestId) {
137
+ if (!requestId) return [];
138
+ return Object.keys(inFlight).filter(function (id) { return inFlight[id] === requestId; });
139
+ }
140
+
141
+ /**
142
+ * The server answered a Fire now or Cancel with an error that names the request
143
+ * (requestId): only the row that sent it is freed and shows the failure. An
144
+ * error without a request id, or with one this page is not waiting on, is not
145
+ * about any row and frees none.
146
+ * @param {string} text the server's error text
147
+ * @param {string} [requestId] the request id the error carries
148
+ */
149
+ export function failScheduledRequests(text, requestId) {
150
+ rowsOfRequest(requestId).forEach(function (id) {
151
+ delete inFlight[id];
152
+ failures[id] = text || "The request failed.";
153
+ repaintRow(id);
154
+ });
155
+ }
156
+
157
+ /**
158
+ * The server answered a Fire now or Cancel as done (scheduled_request_result):
159
+ * the row that sent it is freed. A recurring schedule stays listed after Fire
160
+ * now, so its controls are enabled again here, not by the list.
161
+ * @param {string} requestId the request id the answer carries
162
+ */
163
+ export function completeScheduledRequest(requestId) {
164
+ rowsOfRequest(requestId).forEach(function (id) {
165
+ delete inFlight[id];
166
+ repaintRow(id);
167
+ });
168
+ }
169
+
170
+ /**
171
+ * The connection came back: an answer lost with the old connection will never
172
+ * arrive, so nothing stays waiting, and the rows are repainted enabled. The
173
+ * server's list, requested on reconnect, redraws what is armed.
174
+ */
175
+ export function clearScheduledOutboxOnReconnect() {
176
+ inFlight = {};
177
+ failures = {};
178
+ rows.forEach(function (r) { paintBusy(r, r.id); });
179
+ }
180
+
181
+ /**
182
+ * Redraws the outbox rows of the session on screen from the server's list:
183
+ * one row per armed input, in the list's order. Replaces what was drawn.
184
+ * @param {Array<object>} inputs the service's armed inputs for the session
185
+ */
186
+ export function renderScheduledOutbox(inputs) {
187
+ removeScheduledOutbox();
188
+ // A schedule the server no longer lists has left: nothing of it stays waiting.
189
+ var listed = {};
190
+ (inputs || []).forEach(function (i) { listed[i.id] = true; });
191
+ Object.keys(inFlight).forEach(function (id) { if (!listed[id]) delete inFlight[id]; });
192
+ Object.keys(failures).forEach(function (id) { if (!listed[id]) delete failures[id]; });
193
+ if (!inputs || inputs.length === 0) return;
194
+ var container = document.createElement("div");
195
+ container.className = "scheduled-msgs";
196
+ inputs.forEach(function (input) {
197
+ var row = buildRow(input);
198
+ container.appendChild(row.el);
199
+ rows.push(row);
200
+ countdowns.push({ el: row.when, input: input });
201
+ });
202
+ addToMessages(container);
203
+ containerEl = container;
204
+ scrollToBottom();
205
+ tickCountdowns();
206
+ countdownTimer = setInterval(tickCountdowns, 1000);
207
+ }
208
+
209
+ /** Forgets the requests in flight and their failures (the view left the session). */
210
+ export function resetScheduledOutboxRequests() {
211
+ inFlight = {};
212
+ failures = {};
213
+ }
214
+
215
+ /** Removes the drawn rows and their countdown; the session's list is untouched. */
216
+ export function removeScheduledOutbox() {
217
+ if (containerEl) {
218
+ containerEl.remove();
219
+ containerEl = null;
220
+ }
221
+ countdowns = [];
222
+ rows = [];
223
+ if (countdownTimer) {
224
+ clearInterval(countdownTimer);
225
+ countdownTimer = null;
226
+ }
227
+ }
228
+
229
+ /** The container of the drawn rows, or null when the session has none. */
230
+ export function getScheduledOutboxEl() { return containerEl; }
@@ -0,0 +1,200 @@
1
+ // send-now.js - deliver a typed message into the running turn instead of
2
+ // queueing it for the next one. The decision is pure (state in, mode out) so
3
+ // the shortcut, the queued items' controls, the touch long press and the tests share one rule, and nothing here
4
+ // names an agent: whether a turn can be steered is the `steering` capability.
5
+
6
+ import { store } from './store.js';
7
+ import { capabilityGate } from './vendor-registry.js';
8
+
9
+ // What Send now means for each kind of queued or typed item, in one place.
10
+ // - chat: into the running turn when the agent has the steering capability
11
+ // (gate "steering"); a normal send when no turn runs.
12
+ // - shell: a ! command never goes into a turn (no two writers on the session):
13
+ // unavailable while a turn runs, and run next when the session is idle.
14
+ // - scheduled: an armed schedule is fired at once through the scheduled-input
15
+ // service's run-now path, which joins a running turn like a person's
16
+ // message; the service, not the page, owns when and how it is delivered.
17
+ // `label` is what the control says.
18
+ export var SEND_NOW_BY_KIND = {
19
+ chat: {
20
+ label: "Send now",
21
+ gate: "steering",
22
+ running: "steer",
23
+ idle: "send",
24
+ unavailableReason: "This agent cannot take a message while it is working.",
25
+ },
26
+ shell: {
27
+ label: "Send now",
28
+ gate: null,
29
+ running: "disabled",
30
+ idle: "run-next",
31
+ unavailableReason: "a command runs after the turn",
32
+ },
33
+ scheduled: {
34
+ label: "Fire now",
35
+ gate: null,
36
+ running: "fire",
37
+ idle: "fire",
38
+ unavailableReason: "",
39
+ },
40
+ };
41
+
42
+ // What Cancel and Edit mean for each kind of queued item, in one place, beside
43
+ // Send now.
44
+ // - chat: a message is pushed to the agent at once and waits there until the
45
+ // agent takes it into a turn; withdrawing it is the agent's
46
+ // `queuedMessageCancel` capability. Without it the message is not
47
+ // drawn as queued at all: it is shown as sent, as it always was.
48
+ // - shell: a ! entry is held on this page, so the page can always withdraw it.
49
+ // - scheduled: the scheduled-input service holds it; Cancel deletes it there.
50
+ // It has no Edit here (a schedule is changed from the schedule panel).
51
+ export var QUEUED_CONTROLS_BY_KIND = {
52
+ chat: {
53
+ gate: "queuedMessageCancel",
54
+ unavailableReason: "This agent cannot withdraw a message that is waiting to be delivered.",
55
+ },
56
+ shell: {
57
+ gate: null,
58
+ unavailableReason: "",
59
+ },
60
+ scheduled: {
61
+ gate: null,
62
+ unavailableReason: "",
63
+ },
64
+ };
65
+
66
+ /**
67
+ * Whether Cancel and Edit work on one kind of queued item.
68
+ * @param {string} kind a key of QUEUED_CONTROLS_BY_KIND
69
+ * @param {?{enabled: boolean, reason: string}} gate the capability gate the kind names, if any
70
+ * @returns {{cancel: {enabled: boolean, reason: string}, edit: {enabled: boolean, reason: string}}}
71
+ */
72
+ export function queuedControlsForKind(kind, gate) {
73
+ var rule = QUEUED_CONTROLS_BY_KIND[kind];
74
+ if (!rule) {
75
+ var unknown = { enabled: false, reason: "Unknown kind of item." };
76
+ return { cancel: unknown, edit: unknown };
77
+ }
78
+ var on = !rule.gate || !!(gate && gate.enabled);
79
+ var state = on
80
+ ? { enabled: true, reason: "" }
81
+ : { enabled: false, reason: (gate && gate.reason) || rule.unavailableReason };
82
+ return { cancel: state, edit: state };
83
+ }
84
+
85
+ /** The Cancel and Edit state for one kind, for the live store and the current agent. */
86
+ export function currentQueuedControls(kind) {
87
+ var rule = QUEUED_CONTROLS_BY_KIND[kind];
88
+ return queuedControlsForKind(kind, rule && rule.gate ? capabilityGate(rule.gate) : null);
89
+ }
90
+
91
+ /**
92
+ * What send-now does for one kind right now.
93
+ * - "send": chat, no turn running: a normal send.
94
+ * - "steer": chat, a turn is running and the agent can take a message into it.
95
+ * - "run-next": ! command, idle: it runs next.
96
+ * - "fire": scheduled input: the service delivers it now, running turn or not.
97
+ * - "disabled": it cannot be sent now; `reason` says why.
98
+ * @param {string} kind a key of SEND_NOW_BY_KIND
99
+ * @param {boolean} processing a turn is running
100
+ * @param {?{enabled: boolean, reason: string}} gate the capability gate the kind names, if any
101
+ * @returns {{mode: string, reason: string}}
102
+ */
103
+ export function sendNowForKind(kind, processing, gate) {
104
+ var rule = SEND_NOW_BY_KIND[kind];
105
+ if (!rule) return { mode: "disabled", reason: "Unknown kind of item." };
106
+ if (!processing) return { mode: rule.idle, reason: "" };
107
+ if (rule.running === "disabled") return { mode: "disabled", reason: rule.unavailableReason };
108
+ if (!rule.gate || (gate && gate.enabled)) return { mode: rule.running, reason: "" };
109
+ return { mode: "disabled", reason: (gate && gate.reason) || rule.unavailableReason };
110
+ }
111
+
112
+ /** What the Send now control of one kind is called ("Fire now" for a schedule). */
113
+ export function sendNowLabel(kind) {
114
+ var rule = SEND_NOW_BY_KIND[kind];
115
+ return rule ? rule.label : "Send now";
116
+ }
117
+
118
+ /** The chat rule: what send-now does to a typed message right now. */
119
+ export function sendNowState(processing, gate) {
120
+ return sendNowForKind("chat", processing, gate);
121
+ }
122
+
123
+ /**
124
+ * Whether a keydown is the send-now shortcut: Ctrl+Enter anywhere, and
125
+ * Cmd+Enter on macOS. Shift and Alt variants are left to the composer.
126
+ * @param {{key: string, ctrlKey: boolean, metaKey: boolean, shiftKey: boolean, altKey: boolean}} e
127
+ * @param {boolean} isMac
128
+ */
129
+ export function isSendNowKey(e, isMac) {
130
+ if (e.key !== "Enter" || e.shiftKey || e.altKey) return false;
131
+ return !!e.ctrlKey || (!!isMac && !!e.metaKey);
132
+ }
133
+
134
+ export function isMacPlatform() {
135
+ var platform = (typeof navigator !== "undefined" && (navigator.platform || "")) || "";
136
+ return /^Mac/i.test(platform);
137
+ }
138
+
139
+ /** The state for one kind, for the live store and the current agent. */
140
+ export function currentSendNowState(kind) {
141
+ var k = kind || "chat";
142
+ var rule = SEND_NOW_BY_KIND[k];
143
+ return sendNowForKind(k, !!store.get("processing"), rule && rule.gate ? capabilityGate(rule.gate) : null);
144
+ }
145
+
146
+ // How long after a long press ends its click can still arrive.
147
+ var SWALLOW_WINDOW_MS = 400;
148
+
149
+ /**
150
+ * Send now for a touch screen, where there is no Ctrl key and no button of its
151
+ * own: a long press on the send button, while a message is ready to go, sends
152
+ * it now. The click that ends the press is swallowed so it does not also send.
153
+ * Register this before the button's own click handler.
154
+ * @param {HTMLElement} btn
155
+ * @param {function(): boolean} canArm a press may start send-now (a turn runs and a draft is ready)
156
+ * @param {function(): void} onSendNow
157
+ * @param {number} [ms] how long a press counts as long
158
+ */
159
+ export function initSendLongPress(btn, canArm, onSendNow, ms) {
160
+ if (!btn) return;
161
+ var delay = ms || 500;
162
+ var timer = null;
163
+ var fired = false;
164
+ var settle = null;
165
+ function clear() { if (timer !== null) { clearTimeout(timer); timer = null; } }
166
+ function clearSettle() { if (settle !== null) { clearTimeout(settle); settle = null; } }
167
+ // `fired` only exists to swallow the click that ends the press that fired. That click
168
+ // follows pointerup at once, so a press that ends otherwise (pointerleave, pointercancel,
169
+ // or a click that never comes) must not leave it set to swallow a later, unrelated click.
170
+ function endPress(swallowClickFollows) {
171
+ clear();
172
+ clearSettle();
173
+ if (!fired) return;
174
+ if (!swallowClickFollows) { fired = false; return; }
175
+ settle = setTimeout(function () { settle = null; fired = false; }, SWALLOW_WINDOW_MS);
176
+ }
177
+ btn.addEventListener("pointerdown", function (e) {
178
+ fired = false;
179
+ clear();
180
+ clearSettle();
181
+ if (e && e.pointerType === "mouse") return;
182
+ if (!canArm()) return;
183
+ timer = setTimeout(function () {
184
+ timer = null;
185
+ fired = true;
186
+ onSendNow();
187
+ }, delay);
188
+ });
189
+ btn.addEventListener("pointerup", function () { endPress(true); });
190
+ btn.addEventListener("pointerleave", function () { endPress(true); });
191
+ btn.addEventListener("pointercancel", function () { endPress(false); });
192
+ btn.addEventListener("contextmenu", function (e) { if (fired || timer !== null) e.preventDefault(); });
193
+ btn.addEventListener("click", function (e) {
194
+ if (!fired) return;
195
+ fired = false;
196
+ clearSettle();
197
+ e.preventDefault();
198
+ e.stopImmediatePropagation();
199
+ });
200
+ }
@@ -8,10 +8,12 @@ import { closeFileViewer } from './filebrowser.js';
8
8
  import { renderModelList, renderModeList, renderEffortBar, renderThinkingBar, renderBetaCard, isSonnetModel } from './settings-defaults.js';
9
9
  import { capabilitiesFor, defaultVendorId } from './vendor-registry.js';
10
10
  import { renderPermissionSettings } from './permission-settings.js';
11
+ import { renderUserShellSettings } from './shell-settings-controls.js';
11
12
  import { initCustomIconsSettings, initCustomIconsUpload, loadCustomIcons } from './custom-icons-settings.js';
12
13
  import { formatBytes } from './app-panels.js';
13
14
  import { renderShadowNotice } from './env-shadow-notice.js';
14
15
  import { registerHandlers } from './app-messages.js';
16
+ import { registerPlace } from './notify-client.js';
15
17
 
16
18
  var ctx = null;
17
19
  var settingsEl = null;
@@ -64,6 +66,8 @@ export function initServerSettings(appCtx) {
64
66
  settingsBtn.addEventListener("click", function () {
65
67
  openSettings();
66
68
  });
69
+ // The update button lives here: a tap on an update notice opens it.
70
+ registerPlace("update_available", openSettings);
67
71
 
68
72
  // Close settings
69
73
  closeBtn.addEventListener("click", function () {
@@ -285,6 +289,12 @@ export function initServerSettings(appCtx) {
285
289
  ssClaudeMdSave.addEventListener("click", function () { saveGlobalClaudeMd(); });
286
290
  }
287
291
 
292
+ // Idle compaction (Claude user setting)
293
+ var ssIdleOff = document.getElementById("ss-idle-compaction-off");
294
+ if (ssIdleOff) ssIdleOff.addEventListener("click", function () { setIdleCompaction("off"); });
295
+ var ssIdleDefault = document.getElementById("ss-idle-compaction-default");
296
+ if (ssIdleDefault) ssIdleDefault.addEventListener("click", function () { setIdleCompaction("default"); });
297
+
288
298
  // Shared environment: add button
289
299
  var ssEnvAddBtn = document.getElementById("ss-env-add-btn");
290
300
  if (ssEnvAddBtn) {
@@ -522,7 +532,7 @@ function switchSection(sectionName) {
522
532
  }
523
533
 
524
534
  // Lazy-load section data
525
- if (sectionName === "claudemd") loadGlobalClaudeMd();
535
+ if (sectionName === "claudemd") { loadGlobalClaudeMd(); loadIdleCompaction(); }
526
536
  if (sectionName === "environment") loadSharedEnv();
527
537
  if (sectionName === "custom-icons") loadCustomIcons();
528
538
  if (sectionName === "admin-users" || sectionName === "admin-invites" || sectionName === "admin-projects" || sectionName === "admin-smtp") {
@@ -618,6 +628,7 @@ function populateSettings() {
618
628
  updateThinkingBar();
619
629
  updateSsBetaCard();
620
630
  renderPermissionSettings(ssSendMsg);
631
+ renderUserShellSettings(ssSendMsg);
621
632
  }
622
633
 
623
634
  function syncNotifToggles() {
@@ -1212,6 +1223,39 @@ export function handleGlobalClaudeMdWrite(msg) {
1212
1223
  }
1213
1224
  }
1214
1225
 
1226
+ // ===== Idle compaction (Claude user setting) =====
1227
+ var IDLE_COMPACTION_LABELS = {
1228
+ off: "Off. Claude Code will not compact an idle session.",
1229
+ on: "On (set outside the console).",
1230
+ "default": "Claude Code default (the setting is not set).",
1231
+ };
1232
+
1233
+ function setIdleCompactionStatus(text) {
1234
+ var el = document.getElementById("ss-idle-compaction-status");
1235
+ if (el) el.textContent = text;
1236
+ }
1237
+
1238
+ function loadIdleCompaction() {
1239
+ setIdleCompactionStatus("Loading...");
1240
+ var ws = ctx.ws;
1241
+ if (ws && ws.readyState === 1) ws.send(JSON.stringify({ type: "get_idle_compaction" }));
1242
+ }
1243
+
1244
+ function setIdleCompaction(value) {
1245
+ var ws = ctx.ws;
1246
+ if (!ws || ws.readyState !== 1) return;
1247
+ setIdleCompactionStatus("Saving...");
1248
+ ws.send(JSON.stringify({ type: "set_idle_compaction", value: value }));
1249
+ }
1250
+
1251
+ export function handleIdleCompactionResult(msg) {
1252
+ if (!msg.ok) {
1253
+ setIdleCompactionStatus("Error: " + (msg.error || "Could not read the setting"));
1254
+ return;
1255
+ }
1256
+ setIdleCompactionStatus(IDLE_COMPACTION_LABELS[msg.value] || IDLE_COMPACTION_LABELS["default"]);
1257
+ }
1258
+
1215
1259
  // ===== Shared Environment Variables =====
1216
1260
  var sharedEnvSaveTimer = null;
1217
1261
 
@@ -1404,6 +1448,8 @@ export function initSsLiteToggle() {
1404
1448
  // only place both consumers are already imported together.
1405
1449
  registerHandlers({
1406
1450
  global_claude_md_result: handleGlobalClaudeMdRead,
1451
+ idle_compaction_result: handleIdleCompactionResult,
1452
+ set_idle_compaction_result: handleIdleCompactionResult,
1407
1453
  write_global_claude_md_result: handleGlobalClaudeMdWrite,
1408
1454
  set_pin_result: handleSetPinResult,
1409
1455
  set_keep_awake_result: handleKeepAwakeChanged,
@@ -0,0 +1,76 @@
1
+ // shell-card.js - the card that shows a command typed with ! and how it ended.
2
+ // Everything a command or its output carries goes in as text (textContent), never
3
+ // as markup: output is whatever a program printed.
4
+
5
+ import { describeResult } from './shell-line.js';
6
+
7
+ /**
8
+ * A card for a command, with no outcome yet.
9
+ * @param {string} command
10
+ * @param {string} state - the card's style: pending, ok, failed, error, denied, refused
11
+ * @returns {HTMLElement}
12
+ */
13
+ export function buildCard(command, state) {
14
+ var card = document.createElement("div");
15
+ card.className = "shell-result " + state;
16
+ var cmd = document.createElement("div");
17
+ cmd.className = "shell-cmd";
18
+ var prompt = document.createElement("span");
19
+ prompt.className = "shell-prompt";
20
+ prompt.textContent = "!";
21
+ var text = document.createElement("span");
22
+ text.textContent = command || "";
23
+ cmd.appendChild(prompt);
24
+ cmd.appendChild(text);
25
+ card.appendChild(cmd);
26
+ return card;
27
+ }
28
+
29
+ function clearOutcome(card) {
30
+ card.querySelectorAll(".shell-output, .shell-status, .shell-actions").forEach(function (el) { el.remove(); });
31
+ }
32
+
33
+ function addStatus(card, text) {
34
+ var status = document.createElement("div");
35
+ status.className = "shell-status";
36
+ status.textContent = text;
37
+ card.appendChild(status);
38
+ }
39
+
40
+ /** Shows a card as still running. */
41
+ export function showRunning(card) {
42
+ clearOutcome(card);
43
+ addStatus(card, "Running…");
44
+ }
45
+
46
+ /**
47
+ * Fills a card with a shell_result: its style, its output and how it ended. A
48
+ * refused command gets an Edit action, which hands the command to
49
+ * hooks.onEdit; the page decides where it goes, so a draft is never overwritten.
50
+ * @param {HTMLElement} card
51
+ * @param {object} msg - a shell_result
52
+ * @param {{onEdit: function(string): void}} [hooks]
53
+ */
54
+ export function fillCard(card, msg, hooks) {
55
+ var described = describeResult(msg);
56
+ card.className = "shell-result " + described.state;
57
+ clearOutcome(card);
58
+ if (msg.output) {
59
+ var out = document.createElement("pre");
60
+ out.className = "shell-output";
61
+ out.textContent = msg.output;
62
+ card.appendChild(out);
63
+ }
64
+ addStatus(card, described.status);
65
+ if (msg.refused && msg.command && hooks && hooks.onEdit) {
66
+ var actions = document.createElement("div");
67
+ actions.className = "shell-actions";
68
+ var edit = document.createElement("button");
69
+ edit.type = "button";
70
+ edit.className = "shell-edit";
71
+ edit.textContent = "Edit command";
72
+ edit.addEventListener("click", function () { hooks.onEdit(msg.command); });
73
+ actions.appendChild(edit);
74
+ card.appendChild(actions);
75
+ }
76
+ }
@@ -0,0 +1,49 @@
1
+ // shell-line.js - the pure parts of the composer's ! command line: which typed
2
+ // line is a command, and how a result reads. No DOM here, so the rules are
3
+ // testable on their own; user-shell.js draws and sends.
4
+
5
+ /**
6
+ * The command a composer line carries, or null when the line is not one. A line
7
+ * is a command when it starts with ! (leading whitespace aside) and a command
8
+ * follows. Only the ! and the whitespace right after it are removed: the rest is
9
+ * the command exactly as typed, so a trailing escaped space is part of it.
10
+ * @param {string} raw - the composer's text as typed, not trimmed
11
+ * @returns {?string}
12
+ */
13
+ export function parseShellLine(raw) {
14
+ if (typeof raw !== "string") return null;
15
+ var line = raw.replace(/^\s+/, "");
16
+ if (line.charAt(0) !== "!") return null;
17
+ var command = line.slice(1).replace(/^\s+/, "");
18
+ return command.trim() ? command : null;
19
+ }
20
+
21
+ function formatDuration(ms) {
22
+ if (typeof ms !== "number" || !isFinite(ms) || ms < 0) return "";
23
+ if (ms < 1000) return Math.round(ms) + " ms";
24
+ if (ms < 60000) return (ms / 1000).toFixed(1) + " s";
25
+ return Math.floor(ms / 60000) + " min " + Math.round((ms % 60000) / 1000) + " s";
26
+ }
27
+
28
+ /**
29
+ * How one shell_result reads: its state (for the card's style) and the status
30
+ * line under the output. Every way a command can end says so in words.
31
+ * @param {object} msg - a shell_result
32
+ * @returns {{state: string, status: string}}
33
+ */
34
+ export function describeResult(msg) {
35
+ if (msg.refused) return { state: "refused", status: msg.message || msg.reason || "The command was not run." };
36
+ if (msg.denied) return { state: "denied", status: msg.message || msg.reason || "The command was not approved, so it did not run." };
37
+ if (msg.error) return { state: "error", status: "The command could not run." };
38
+ var parts = [];
39
+ if (msg.timedOut) parts.push("timed out and was stopped");
40
+ else if (msg.interrupted) parts.push("interrupted");
41
+ else if (msg.exitCode === null || msg.exitCode === undefined) parts.push("ended without an exit code");
42
+ else parts.push("exit " + msg.exitCode);
43
+ var took = formatDuration(msg.durationMs);
44
+ if (took) parts.push(took);
45
+ if (msg.truncated) parts.push("output cut at the size limit");
46
+ var failed = msg.timedOut || msg.interrupted || (typeof msg.exitCode === "number" && msg.exitCode !== 0) ||
47
+ msg.exitCode === null || msg.exitCode === undefined;
48
+ return { state: failed ? "failed" : "ok", status: parts.join(" · ") };
49
+ }