@clagentic/console 1.12.0-beta.3 → 1.13.0-beta.1
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.
- package/README.md +7 -1
- package/bin/cli.js +18 -15
- package/lib/agent-roster-ws.js +38 -13
- package/lib/agent-roster.js +111 -12
- package/lib/agents.js +68 -33
- package/lib/atomic-install.js +334 -0
- package/lib/build-changes.js +33 -4
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +12 -0
- package/lib/chat-width.js +31 -0
- package/lib/cli/agent-usage.js +126 -0
- package/lib/cli/arg-validation.js +1 -1
- package/lib/cli/compact-output.js +69 -0
- package/lib/cli/ipc-subcommands.js +92 -67
- package/lib/cli/output.js +28 -0
- package/lib/cli/restart-verb.js +132 -0
- package/lib/cli/schedule-input-subcommands.js +45 -8
- package/lib/cli/session-subcommands.js +37 -11
- package/lib/cli/settings-subcommands.js +74 -0
- package/lib/cli-transcript-title.js +56 -3
- package/lib/client-files.js +79 -0
- package/lib/daemon.js +100 -28
- package/lib/default-avatar-color.js +4 -0
- package/lib/drain.js +58 -10
- package/lib/mcp-tool-input.js +2 -2
- package/lib/model-families.js +49 -1
- package/lib/notify/type-registry.js +4 -0
- package/lib/notify/types.js +7 -4
- package/lib/pages.js +13 -63
- package/lib/permission-summary.js +12 -16
- package/lib/plan-usage-reader.js +70 -0
- package/lib/project-connection.js +4 -2
- package/lib/project-filesystem.js +6 -7
- package/lib/project-notifications.js +55 -8
- package/lib/project-prompt-expiry-settings.js +42 -0
- package/lib/project-sessions.js +52 -0
- package/lib/project-settings-gate.js +98 -0
- package/lib/project-user-mention.js +3 -2
- package/lib/project.js +1 -1
- package/lib/prompt-expiry-settings.js +49 -0
- package/lib/prompt-expiry.js +24 -3
- package/lib/prompt-kinds/codecs.js +6 -2
- package/lib/public/app.js +36 -36
- package/lib/public/css/admin.css +156 -170
- package/lib/public/css/agent-messages.css +24 -24
- package/lib/public/css/agent-picker.css +90 -38
- package/lib/public/css/agent-roster.css +61 -27
- package/lib/public/css/at-agents.css +10 -10
- package/lib/public/css/base.css +207 -184
- package/lib/public/css/chat-layout.css +228 -0
- package/lib/public/css/command-palette.css +86 -88
- package/lib/public/css/diagnostics.css +78 -204
- package/lib/public/css/diff.css +10 -10
- package/lib/public/css/filebrowser.css +32 -60
- package/lib/public/css/home-hub.css +100 -100
- package/lib/public/css/icon-strip.css +195 -238
- package/lib/public/css/input.css +191 -212
- package/lib/public/css/login-panel.css +16 -16
- package/lib/public/css/loop.css +96 -187
- package/lib/public/css/mention.css +49 -110
- package/lib/public/css/menus.css +162 -169
- package/lib/public/css/messages.css +49 -123
- package/lib/public/css/mobile-nav.css +207 -264
- package/lib/public/css/notifications-center.css +45 -124
- package/lib/public/css/overlay.css +269 -0
- package/lib/public/css/overlays.css +134 -156
- package/lib/public/css/playbook.css +41 -41
- package/lib/public/css/profile.css +43 -112
- package/lib/public/css/rewind.css +112 -112
- package/lib/public/css/scheduler-modal.css +27 -135
- package/lib/public/css/scheduler.css +204 -210
- package/lib/public/css/server-settings.css +173 -239
- package/lib/public/css/session-search.css +20 -20
- package/lib/public/css/settings-nav.css +197 -0
- package/lib/public/css/sidebar.css +213 -304
- package/lib/public/css/skills.css +121 -135
- package/lib/public/css/sticky-notes.css +114 -200
- package/lib/public/css/stt.css +17 -26
- package/lib/public/css/team-panel.css +36 -36
- package/lib/public/css/team-view.css +9 -9
- package/lib/public/css/title-bar.css +83 -100
- package/lib/public/css/tooltip.css +10 -10
- package/lib/public/css/user-settings.css +78 -131
- package/lib/public/css/user-shell.css +125 -29
- package/lib/public/index.html +178 -177
- package/lib/public/manifest.json +0 -2
- package/lib/public/modules/admin.js +54 -92
- package/lib/public/modules/agent-avatar.js +134 -3
- package/lib/public/modules/agent-messages.js +2 -1
- package/lib/public/modules/agent-picker.js +23 -21
- package/lib/public/modules/agent-roster-groups.js +128 -0
- package/lib/public/modules/agent-roster.js +40 -11
- package/lib/public/modules/app-connection.js +13 -1
- package/lib/public/modules/app-cursors.js +9 -9
- package/lib/public/modules/app-favicon.js +8 -16
- package/lib/public/modules/app-header.js +28 -19
- package/lib/public/modules/app-history-replay.js +67 -4
- package/lib/public/modules/app-home-hub.js +15 -0
- package/lib/public/modules/app-loop-ui.js +41 -47
- package/lib/public/modules/app-loop-wizard.js +9 -10
- package/lib/public/modules/app-messages.js +32 -36
- package/lib/public/modules/app-misc.js +22 -92
- package/lib/public/modules/app-modals.js +98 -0
- package/lib/public/modules/app-notifications.js +124 -135
- package/lib/public/modules/app-panels.js +28 -32
- package/lib/public/modules/app-projects.js +30 -40
- package/lib/public/modules/app-rate-limit.js +26 -9
- package/lib/public/modules/app-rendering.js +128 -110
- package/lib/public/modules/app-skills-install.js +6 -4
- package/lib/public/modules/assistant-identity.js +55 -0
- package/lib/public/modules/at-agents.js +3 -0
- package/lib/public/modules/build-guard.js +25 -11
- package/lib/public/modules/chat-width-choice.js +75 -0
- package/lib/public/modules/chat-width-prefs.js +52 -0
- package/lib/public/modules/chat-width.js +102 -0
- package/lib/public/modules/collapsible-text.js +36 -4
- package/lib/public/modules/command-palette.js +28 -34
- package/lib/public/modules/context-sources.js +3 -5
- package/lib/public/modules/diagnostics.js +130 -129
- package/lib/public/modules/info-panel.js +31 -0
- package/lib/public/modules/injected-identity.js +8 -8
- package/lib/public/modules/input-list-menu.js +39 -0
- package/lib/public/modules/input.js +22 -21
- package/lib/public/modules/markdown.js +10 -11
- package/lib/public/modules/mcp-ui.js +4 -14
- package/lib/public/modules/mention.js +100 -229
- package/lib/public/modules/message-header.js +80 -0
- package/lib/public/modules/message-participants.js +39 -0
- package/lib/public/modules/mobile-action-sheet.js +46 -0
- package/lib/public/modules/mobile-nav-sheet.js +104 -0
- package/lib/public/modules/model-families.js +41 -4
- package/lib/public/modules/note-order.js +39 -0
- package/lib/public/modules/notifications.js +35 -52
- package/lib/public/modules/overlay-history.js +73 -19
- package/lib/public/modules/overlay-menu.js +123 -0
- package/lib/public/modules/overlay-modal.js +186 -0
- package/lib/public/modules/overlay-registry.js +392 -0
- package/lib/public/modules/overlay-stack.js +110 -0
- package/lib/public/modules/overlay.js +117 -0
- package/lib/public/modules/popover-position.js +18 -2
- package/lib/public/modules/preference-sync.js +28 -0
- package/lib/public/modules/profile.js +24 -49
- package/lib/public/modules/project-settings.js +27 -172
- package/lib/public/modules/prompt-expiry-controls.js +46 -0
- package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
- package/lib/public/modules/prompt-kinds/permission.js +70 -92
- package/lib/public/modules/prompts.js +1 -2
- package/lib/public/modules/qrcode.js +6 -21
- package/lib/public/modules/queued-button.js +15 -2
- package/lib/public/modules/rewind.js +9 -3
- package/lib/public/modules/schedule-time.js +32 -7
- package/lib/public/modules/scheduled-outbox.js +51 -18
- package/lib/public/modules/scheduler-config.js +87 -127
- package/lib/public/modules/scheduler.js +29 -26
- package/lib/public/modules/serialized-save.js +79 -0
- package/lib/public/modules/server-settings.js +75 -65
- package/lib/public/modules/session-grants.js +16 -19
- package/lib/public/modules/session-list-avatars.js +98 -0
- package/lib/public/modules/session-vendor-state.js +86 -0
- package/lib/public/modules/settings-access.js +35 -0
- package/lib/public/modules/settings-hub.js +125 -0
- package/lib/public/modules/settings-nav.js +182 -0
- package/lib/public/modules/shell-line.js +24 -0
- package/lib/public/modules/sidebar-mobile.js +151 -195
- package/lib/public/modules/sidebar-projects.js +88 -129
- package/lib/public/modules/sidebar-sessions.js +66 -34
- package/lib/public/modules/sidebar.js +2 -2
- package/lib/public/modules/skills.js +11 -26
- package/lib/public/modules/sticky-notes.js +19 -16
- package/lib/public/modules/stt.js +9 -23
- package/lib/public/modules/terminal.js +86 -90
- package/lib/public/modules/theme-choice.js +126 -0
- package/lib/public/modules/theme-colors.js +19 -0
- package/lib/public/modules/theme-prefs.js +121 -0
- package/lib/public/modules/theme.js +227 -605
- package/lib/public/modules/tool-palette.js +7 -17
- package/lib/public/modules/tools.js +8 -10
- package/lib/public/modules/user-settings.js +59 -115
- package/lib/public/modules/user-shell.js +9 -2
- package/lib/public/modules/utils.js +10 -12
- package/lib/public/modules/vendor-picker.js +4 -2
- package/lib/public/modules/vendor-registry.js +1 -2
- package/lib/public/style.css +3 -1
- package/lib/public/sw.js +9 -2
- package/lib/public/theme-core.js +411 -0
- package/lib/request-body.js +70 -0
- package/lib/sdk-bridge.js +227 -88
- package/lib/sdk-message-processor.js +44 -16
- package/lib/server-admin.js +198 -200
- package/lib/server-auth.js +16 -13
- package/lib/server-dm.js +4 -3
- package/lib/server-settings.js +177 -130
- package/lib/server.js +87 -36
- package/lib/session-background-tasks.js +79 -0
- package/lib/session-directory.js +138 -13
- package/lib/session-input-ipc.js +2 -0
- package/lib/session-input.js +39 -5
- package/lib/session-list-avatars.js +16 -0
- package/lib/session-reclaim.js +37 -25
- package/lib/session-vendor.js +37 -0
- package/lib/sessions.js +99 -34
- package/lib/settings-ipc.js +60 -0
- package/lib/settings-registry.js +86 -0
- package/lib/terminal-manager.js +17 -5
- package/lib/theme-files.js +132 -0
- package/lib/theme-seed.js +136 -0
- package/lib/themes/clagentic-dark.json +13 -6
- package/lib/themes/clagentic-light.json +12 -5
- package/lib/updater.js +6 -4
- package/lib/usage-store.js +97 -10
- package/lib/users-preferences.js +118 -19
- package/lib/users.js +19 -10
- package/lib/vendor-catalog.js +130 -0
- package/lib/ws-schema.js +4 -2
- package/lib/yoke/adapters/claude.js +81 -1
- package/lib/yoke/adapters/codex-user-shell.js +87 -23
- package/lib/yoke/adapters/codex.js +89 -5
- package/lib/yoke/codex-binary.js +59 -0
- package/package.json +1 -1
- package/scripts/check-test-count.js +5 -0
- package/scripts/install-local-test.js +50 -9
- package/scripts/write-build-sha.js +18 -2
- package/lib/public/css/channel-layout.css +0 -329
- package/lib/themes/ayu-light.json +0 -9
- package/lib/themes/catppuccin-latte.json +0 -9
- package/lib/themes/catppuccin-mocha.json +0 -9
- package/lib/themes/dracula.json +0 -9
- package/lib/themes/everforest-light.json +0 -9
- package/lib/themes/everforest.json +0 -9
- package/lib/themes/github-light.json +0 -9
- package/lib/themes/gruvbox-dark.json +0 -9
- package/lib/themes/gruvbox-light.json +0 -9
- package/lib/themes/monokai.json +0 -9
- package/lib/themes/nord-light.json +0 -9
- package/lib/themes/nord.json +0 -9
- package/lib/themes/one-dark.json +0 -9
- package/lib/themes/one-light.json +0 -9
- package/lib/themes/rose-pine-dawn.json +0 -9
- package/lib/themes/rose-pine.json +0 -9
- package/lib/themes/solarized-dark.json +0 -9
- package/lib/themes/solarized-light.json +0 -9
- package/lib/themes/tokyo-night-light.json +0 -9
- package/lib/themes/tokyo-night.json +0 -9
package/lib/sessions.js
CHANGED
|
@@ -17,6 +17,7 @@ var { createSenderRecorder } = require("./message-sender-record");
|
|
|
17
17
|
var { checkPermissionMode, savedModeOrDefault } = require("./permission-mode-policy");
|
|
18
18
|
var { logField } = require("./log-field");
|
|
19
19
|
var queuedChat = require("./queued-chat");
|
|
20
|
+
var { resolveVendor, vendorSourceLabel } = require("./session-vendor");
|
|
20
21
|
|
|
21
22
|
// lr-2ea2a7: hard cap on how many history entries a session may hold in the
|
|
22
23
|
// heap array, regardless of isProcessing state. On-disk JSONL remains the
|
|
@@ -748,6 +749,65 @@ function createSessionManager(opts) {
|
|
|
748
749
|
session._historyBaseIndex = (session._historyBaseIndex || 0) + trimCount;
|
|
749
750
|
}
|
|
750
751
|
|
|
752
|
+
// First line of a file, or null when it cannot be read. The meta line can be
|
|
753
|
+
// long (queued chat text rides on it), so it reads on until the line ends
|
|
754
|
+
// rather than stopping at a fixed size.
|
|
755
|
+
// Throws on an open or read failure, so a caller that must tell "no line"
|
|
756
|
+
// from "could not read" can.
|
|
757
|
+
function readFirstLineStrict(filePath) {
|
|
758
|
+
var fd;
|
|
759
|
+
try {
|
|
760
|
+
fd = fs.openSync(filePath, "r");
|
|
761
|
+
var buf = Buffer.alloc(4096);
|
|
762
|
+
var offset = 0;
|
|
763
|
+
var chunks = [];
|
|
764
|
+
var lineEnd = -1;
|
|
765
|
+
while (lineEnd === -1) {
|
|
766
|
+
var bytesRead = fs.readSync(fd, buf, 0, 4096, offset);
|
|
767
|
+
if (bytesRead === 0) break;
|
|
768
|
+
var piece = Buffer.from(buf.subarray(0, bytesRead));
|
|
769
|
+
lineEnd = piece.indexOf(10);
|
|
770
|
+
chunks.push(lineEnd === -1 ? piece : piece.subarray(0, lineEnd));
|
|
771
|
+
offset += bytesRead;
|
|
772
|
+
}
|
|
773
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
774
|
+
} finally {
|
|
775
|
+
if (fd !== undefined) try { fs.closeSync(fd); } catch (e) {}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function readFirstLine(filePath) {
|
|
780
|
+
try { return readFirstLineStrict(filePath); } catch (e) { return null; }
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// Looks up the vendor the session's stored meta line records. Three states:
|
|
784
|
+
// "present" (vendor set), "absent" (the meta was read and records no vendor,
|
|
785
|
+
// or there is no file yet) and "error" (the file could not be opened, read or
|
|
786
|
+
// parsed). Only "absent" may be bound to a default; an error says nothing
|
|
787
|
+
// about the session's real vendor.
|
|
788
|
+
function lookupMetaVendor(session) {
|
|
789
|
+
if (!session || !session.cliSessionId) return { state: "absent", vendor: null };
|
|
790
|
+
var line;
|
|
791
|
+
try {
|
|
792
|
+
line = readFirstLineStrict(sessionFilePath(session.cliSessionId));
|
|
793
|
+
} catch (e) {
|
|
794
|
+
if (e && e.code === "ENOENT") return { state: "absent", vendor: null };
|
|
795
|
+
return { state: "error", vendor: null };
|
|
796
|
+
}
|
|
797
|
+
if (!line) return { state: "absent", vendor: null };
|
|
798
|
+
var meta;
|
|
799
|
+
try { meta = JSON.parse(line); } catch (e) { return { state: "error", vendor: null }; }
|
|
800
|
+
if (meta && meta.type === "meta" && typeof meta.vendor === "string" && meta.vendor) {
|
|
801
|
+
return { state: "present", vendor: meta.vendor };
|
|
802
|
+
}
|
|
803
|
+
return { state: "absent", vendor: null };
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// The recorded vendor, or null when there is none or it could not be read.
|
|
807
|
+
function readMetaVendor(session) {
|
|
808
|
+
return lookupMetaVendor(session).vendor;
|
|
809
|
+
}
|
|
810
|
+
|
|
751
811
|
function loadSessions() {
|
|
752
812
|
var files;
|
|
753
813
|
try { files = fs.readdirSync(sessionsDir); } catch { return; }
|
|
@@ -763,28 +823,8 @@ function createSessionManager(opts) {
|
|
|
763
823
|
for (var i = 0; i < files.length; i++) {
|
|
764
824
|
if (!files[i].endsWith(".jsonl")) continue;
|
|
765
825
|
// Read only the first line (meta record) — history is lazy-loaded on demand.
|
|
766
|
-
var
|
|
767
|
-
|
|
768
|
-
try {
|
|
769
|
-
fd = fs.openSync(path.join(sessionsDir, files[i]), "r");
|
|
770
|
-
// The meta line can be long (queued chat text rides on it), so read on
|
|
771
|
-
// until the line ends rather than stopping at a fixed size.
|
|
772
|
-
var buf = Buffer.alloc(4096);
|
|
773
|
-
var offset = 0;
|
|
774
|
-
var chunks = [];
|
|
775
|
-
var lineEnd = -1;
|
|
776
|
-
while (lineEnd === -1) {
|
|
777
|
-
var bytesRead = fs.readSync(fd, buf, 0, 4096, offset);
|
|
778
|
-
if (bytesRead === 0) break;
|
|
779
|
-
var piece = Buffer.from(buf.subarray(0, bytesRead));
|
|
780
|
-
lineEnd = piece.indexOf(10);
|
|
781
|
-
chunks.push(lineEnd === -1 ? piece : piece.subarray(0, lineEnd));
|
|
782
|
-
offset += bytesRead;
|
|
783
|
-
}
|
|
784
|
-
firstLine = Buffer.concat(chunks).toString("utf8");
|
|
785
|
-
} catch { continue; } finally {
|
|
786
|
-
if (fd !== undefined) try { fs.closeSync(fd); } catch (e) {}
|
|
787
|
-
}
|
|
826
|
+
var firstLine = readFirstLine(path.join(sessionsDir, files[i]));
|
|
827
|
+
if (firstLine === null) continue;
|
|
788
828
|
|
|
789
829
|
var meta;
|
|
790
830
|
try { meta = JSON.parse(firstLine); } catch { continue; }
|
|
@@ -1092,6 +1132,19 @@ function createSessionManager(opts) {
|
|
|
1092
1132
|
// backward scans as a structural trap for this exact pagination path).
|
|
1093
1133
|
var MAX_VISIBILITY_EXTENSIONS = 5;
|
|
1094
1134
|
|
|
1135
|
+
// One assistant reply is stored as a run of consecutive delta records. A page
|
|
1136
|
+
// that starts inside the run renders the reply as two messages, so a start
|
|
1137
|
+
// index inside a run moves back to the run's first record. The scan is
|
|
1138
|
+
// bounded by the run itself, which is one message the client must render
|
|
1139
|
+
// whole anyway.
|
|
1140
|
+
function alignToDeltaRunStart(history, index) {
|
|
1141
|
+
while (index > 0 && history[index] && history[index].type === "delta" &&
|
|
1142
|
+
history[index - 1] && history[index - 1].type === "delta") {
|
|
1143
|
+
index--;
|
|
1144
|
+
}
|
|
1145
|
+
return index;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1095
1148
|
// Scan backward from the END of history (hard-capped at HISTORY_PAGE_SIZE) to
|
|
1096
1149
|
// find the most recent user_message. This ensures the initial replay window
|
|
1097
1150
|
// always starts at a clean turn boundary rather than mid-stream, regardless of
|
|
@@ -1111,13 +1164,14 @@ function createSessionManager(opts) {
|
|
|
1111
1164
|
// the nearest user_message turn boundary. Used by load_more_history scroll-up
|
|
1112
1165
|
// pagination to align the prepended page to a clean turn start. Falls back to
|
|
1113
1166
|
// targetIndex if no boundary is found within the window — a partial turn at
|
|
1114
|
-
// the top is preferable to an unbounded backward scan
|
|
1167
|
+
// the top is preferable to an unbounded backward scan, except that the top
|
|
1168
|
+
// never falls inside a delta run (alignToDeltaRunStart).
|
|
1115
1169
|
function findTurnBoundary(history, targetIndex) {
|
|
1116
1170
|
var searchFloor = Math.max(0, targetIndex - HISTORY_PAGE_SIZE);
|
|
1117
1171
|
for (var i = targetIndex; i >= searchFloor; i--) {
|
|
1118
1172
|
if (history[i] && history[i].type === "user_message") return i;
|
|
1119
1173
|
}
|
|
1120
|
-
return targetIndex;
|
|
1174
|
+
return alignToDeltaRunStart(history, targetIndex);
|
|
1121
1175
|
}
|
|
1122
1176
|
|
|
1123
1177
|
// Returns true when history[from..to) contains at least one event that
|
|
@@ -1178,7 +1232,7 @@ function createSessionManager(opts) {
|
|
|
1178
1232
|
// start somehow lands below it.
|
|
1179
1233
|
var hardFloor = Math.max(0, heapLen - HISTORY_PAGE_SIZE);
|
|
1180
1234
|
var lastTurn = findLastTurnStart(session.history);
|
|
1181
|
-
heapFrom = Math.max(hardFloor, lastTurn);
|
|
1235
|
+
heapFrom = alignToDeltaRunStart(session.history, Math.max(hardFloor, lastTurn));
|
|
1182
1236
|
// Same yield guarantee as load_more_history (lr-c24b): a turn
|
|
1183
1237
|
// dominated by invisible-yield events (todo/task bookkeeping, hidden
|
|
1184
1238
|
// plan tools, thinking deltas) can otherwise replay zero visible
|
|
@@ -1216,6 +1270,19 @@ function createSessionManager(opts) {
|
|
|
1216
1270
|
_send({ type: "history_done", lastUsage: lastUsage, lastModelUsage: lastModelUsage, lastCost: lastCost, lastStreamInputTokens: lastStreamInputTokens, contextUsage: session.lastContextUsage || null });
|
|
1217
1271
|
}
|
|
1218
1272
|
|
|
1273
|
+
// The session_switched payload, built here for every sender (a switch and a
|
|
1274
|
+
// reconnect's hydration) so the two cannot drift. The vendor is the same
|
|
1275
|
+
// resolution a query uses (session, stored meta, project default); building
|
|
1276
|
+
// the message only reads it and binds nothing. `vendorSource` tells the client
|
|
1277
|
+
// an unreadable meta from an absent vendor. The model is the session's own
|
|
1278
|
+
// effective model so a client hydrating from this message alone never guesses
|
|
1279
|
+
// the shared default. hasHistory is the caller's, as each counts it its own way.
|
|
1280
|
+
function buildSessionSwitchedMessage(session, hasHistory) {
|
|
1281
|
+
var resolved = resolveVendor(session, { lookupMetaVendor: lookupMetaVendor, defaultVendor: defaultVendor });
|
|
1282
|
+
var caps = (resolved.vendor && (capabilitiesByVendor || {})[resolved.vendor]) || {};
|
|
1283
|
+
return { type: "session_switched", id: session.localId, cliSessionId: session.cliSessionId || null, loop: session.loop || null, vendor: resolved.vendor || null, vendorSource: vendorSourceLabel(resolved.source), model: effectiveSessionModel(session, _instance), mode: effectiveSessionMode(session, _instance), hasHistory: !!hasHistory, capabilities: caps, isProcessing: !!session.isProcessing, agentName: session.agentName || null, compacting: !!session.compacting };
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1219
1286
|
function switchSession(localId, targetWs, transform) {
|
|
1220
1287
|
if (!sessions.has(localId)) {
|
|
1221
1288
|
// Only send structured error when a client ws is the initiator. Internal
|
|
@@ -1270,16 +1337,11 @@ function createSessionManager(opts) {
|
|
|
1270
1337
|
// In multi-user mode with a specific client, only send to that client
|
|
1271
1338
|
var _send = (targetWs && sendTo) ? function (obj) { sendTo(targetWs, obj); } : send;
|
|
1272
1339
|
|
|
1273
|
-
var
|
|
1274
|
-
var _sessionVendor =
|
|
1275
|
-
|
|
1276
|
-
// lr-041af8: carry the session's own effective model on the wire so a
|
|
1277
|
-
// client hydrating from session_switched alone (no separate config_state
|
|
1278
|
-
// round-trip needed) never has to fall back to guessing the shared
|
|
1279
|
-
// project/global default — see effectiveSessionModel() above.
|
|
1280
|
-
_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, compacting: !!session.compacting });
|
|
1340
|
+
var _switchedMsg = buildSessionSwitchedMessage(session, (session._historyLoaded ? session.history.length > 0 : !!session.cliSessionId));
|
|
1341
|
+
var _sessionVendor = _switchedMsg.vendor;
|
|
1342
|
+
_send(_switchedMsg);
|
|
1281
1343
|
// Send vendor-specific slash commands
|
|
1282
|
-
var _vendorCmds = slashCommandsByVendor[_sessionVendor] || slashCommands || [];
|
|
1344
|
+
var _vendorCmds = (_sessionVendor && slashCommandsByVendor[_sessionVendor]) || slashCommands || [];
|
|
1283
1345
|
_send({ type: "slash_commands", commands: _vendorCmds, vendor: _sessionVendor });
|
|
1284
1346
|
broadcastSessionList();
|
|
1285
1347
|
replayHistory(session, undefined, targetWs, transform);
|
|
@@ -1850,6 +1912,8 @@ function createSessionManager(opts) {
|
|
|
1850
1912
|
set capabilitiesByVendor(v) { capabilitiesByVendor = v; },
|
|
1851
1913
|
get defaultVendor() { return defaultVendor; },
|
|
1852
1914
|
set defaultVendor(v) { defaultVendor = v; },
|
|
1915
|
+
readMetaVendor: readMetaVendor,
|
|
1916
|
+
lookupMetaVendor: lookupMetaVendor,
|
|
1853
1917
|
get codexApproval() { return codexApproval; },
|
|
1854
1918
|
set codexApproval(v) { codexApproval = v; },
|
|
1855
1919
|
get codexSandbox() { return codexSandbox; },
|
|
@@ -2042,6 +2106,7 @@ function createSessionManager(opts) {
|
|
|
2042
2106
|
// separately.
|
|
2043
2107
|
effectiveSessionModel: function (session) { return effectiveSessionModel(session, _instance); },
|
|
2044
2108
|
effectiveSessionMode: function (session) { return effectiveSessionMode(session, _instance); },
|
|
2109
|
+
buildSessionSwitchedMessage: buildSessionSwitchedMessage,
|
|
2045
2110
|
// Called when the project owning this session manager is torn down. No
|
|
2046
2111
|
// prompt resolver outlives it, so every pending prompt ends here and its
|
|
2047
2112
|
// outcome is flushed to disk; then the exit flusher registered above is
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The daemon side of `clagentic-console settings get|set|list`. Every reply
|
|
4
|
+
// carries a `result` (read, saved, listed, refused, unknown-key), because the
|
|
5
|
+
// CLI treats a reply without one as an error.
|
|
6
|
+
//
|
|
7
|
+
// deps:
|
|
8
|
+
// getConfig() the live daemon configuration object
|
|
9
|
+
// set(key, value) stores an accepted value (the same path the Settings page
|
|
10
|
+
// uses) or returns false when the key has no setter
|
|
11
|
+
// announce(key) tells connected pages the new state
|
|
12
|
+
// registry { findSetting, settingKeys } (lib/settings-registry.js)
|
|
13
|
+
|
|
14
|
+
function unknownKey(registry, key) {
|
|
15
|
+
return {
|
|
16
|
+
ok: false,
|
|
17
|
+
result: "unknown-key",
|
|
18
|
+
key: key === undefined ? null : key,
|
|
19
|
+
reason: "Unknown setting: " + String(key) + ". Known: " + registry.settingKeys().join(", "),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function describe(entry, key, config) {
|
|
24
|
+
return { key: key, value: entry.read(config), default: entry.default };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function handleSettingsCommand(deps, msg) {
|
|
28
|
+
var registry = deps.registry;
|
|
29
|
+
var config = deps.getConfig();
|
|
30
|
+
|
|
31
|
+
if (msg.cmd === "settings_list") {
|
|
32
|
+
return {
|
|
33
|
+
ok: true,
|
|
34
|
+
result: "listed",
|
|
35
|
+
settings: registry.settingKeys().map(function (key) {
|
|
36
|
+
return describe(registry.findSetting(key), key, config);
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var entry = typeof msg.key === "string" ? registry.findSetting(msg.key) : null;
|
|
42
|
+
if (!entry) return unknownKey(registry, msg.key);
|
|
43
|
+
|
|
44
|
+
if (msg.cmd === "settings_get") {
|
|
45
|
+
return Object.assign({ ok: true, result: "read" }, describe(entry, msg.key, config));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var picked = entry.pick(msg.value);
|
|
49
|
+
if (!picked.ok) {
|
|
50
|
+
return Object.assign({ ok: false, result: "refused", reason: picked.reason }, describe(entry, msg.key, config));
|
|
51
|
+
}
|
|
52
|
+
if (deps.set(msg.key, picked.value) === false) {
|
|
53
|
+
return { ok: false, result: "error", key: msg.key, reason: "The server cannot store " + msg.key + "." };
|
|
54
|
+
}
|
|
55
|
+
deps.announce(msg.key);
|
|
56
|
+
// Read back from the in-memory configuration: the file write is asynchronous.
|
|
57
|
+
return Object.assign({ ok: true, result: "saved" }, describe(entry, msg.key, deps.getConfig()));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { handleSettingsCommand: handleSettingsCommand };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The server-wide settings the `clagentic-console settings` verb can read and
|
|
4
|
+
// change, keyed by name. Each entry is { read, pick, apply, default }:
|
|
5
|
+
// read(config) the value now in effect
|
|
6
|
+
// pick(value) { ok: true, value } or { ok: false, reason }; the same
|
|
7
|
+
// validator the Settings page uses, never a second copy
|
|
8
|
+
// apply(config, value) updates the daemon configuration object in place
|
|
9
|
+
// default the value used when nothing is stored
|
|
10
|
+
// A new key is a new entry here; the IPC and CLI layers do not change.
|
|
11
|
+
|
|
12
|
+
var promptExpiry = require("./prompt-expiry");
|
|
13
|
+
var promptExpirySettings = require("./prompt-expiry-settings");
|
|
14
|
+
var chatWidth = require("./chat-width");
|
|
15
|
+
var sessionListAvatars = require("./session-list-avatars");
|
|
16
|
+
|
|
17
|
+
var SETTINGS = {};
|
|
18
|
+
|
|
19
|
+
SETTINGS[promptExpiry.KEY] = {
|
|
20
|
+
default: promptExpiry.DEFAULT_MINUTES,
|
|
21
|
+
read: function (config) {
|
|
22
|
+
return promptExpiry.readExpiryMinutes(config);
|
|
23
|
+
},
|
|
24
|
+
pick: function (value) {
|
|
25
|
+
var request = { type: "set_prompt_expiry_settings" };
|
|
26
|
+
request[promptExpiry.KEY] = value;
|
|
27
|
+
var picked = promptExpirySettings.pickSettingChange(request);
|
|
28
|
+
return picked.ok ? { ok: true, value: picked.minutes } : { ok: false, reason: picked.reason };
|
|
29
|
+
},
|
|
30
|
+
apply: function (config, value) {
|
|
31
|
+
return promptExpirySettings.applySettingChange(config, value);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// The width of the conversation column for a person who has not chosen one in
|
|
36
|
+
// Appearance. Each person's own choice (a per-user setting) always wins; this is
|
|
37
|
+
// only what the profile reports when they have none.
|
|
38
|
+
SETTINGS.chatWidth = {
|
|
39
|
+
default: chatWidth.DEFAULT_CHAT_WIDTH,
|
|
40
|
+
read: function (config) {
|
|
41
|
+
return chatWidth.isChatWidth(config.chatWidth) ? config.chatWidth : chatWidth.DEFAULT_CHAT_WIDTH;
|
|
42
|
+
},
|
|
43
|
+
pick: function (value) {
|
|
44
|
+
if (chatWidth.isChatWidth(value)) return { ok: true, value: value };
|
|
45
|
+
return { ok: false, reason: "chatWidth must be one of: " + chatWidth.CHAT_WIDTHS.join(", ") + "." };
|
|
46
|
+
},
|
|
47
|
+
apply: function (config, value) {
|
|
48
|
+
if (value === chatWidth.DEFAULT_CHAT_WIDTH) delete config.chatWidth;
|
|
49
|
+
else config.chatWidth = value;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Whether a session run by a named agent shows that agent's avatar in the session
|
|
54
|
+
// lists, for a person who has not chosen in Appearance. Their own choice (a
|
|
55
|
+
// per-user setting) always wins; this is only what the profile reports when they
|
|
56
|
+
// have none.
|
|
57
|
+
SETTINGS.sessionListAvatars = {
|
|
58
|
+
default: sessionListAvatars.DEFAULT_SESSION_LIST_AVATARS,
|
|
59
|
+
read: function (config) {
|
|
60
|
+
return sessionListAvatars.isSessionListAvatars(config.sessionListAvatars)
|
|
61
|
+
? config.sessionListAvatars
|
|
62
|
+
: sessionListAvatars.DEFAULT_SESSION_LIST_AVATARS;
|
|
63
|
+
},
|
|
64
|
+
pick: function (value) {
|
|
65
|
+
if (sessionListAvatars.isSessionListAvatars(value)) return { ok: true, value: value };
|
|
66
|
+
return { ok: false, reason: "sessionListAvatars must be true or false." };
|
|
67
|
+
},
|
|
68
|
+
apply: function (config, value) {
|
|
69
|
+
if (value === sessionListAvatars.DEFAULT_SESSION_LIST_AVATARS) delete config.sessionListAvatars;
|
|
70
|
+
else config.sessionListAvatars = value;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** The entry for a key, or null. Own keys only, so "constructor" is not a setting. */
|
|
75
|
+
function findSetting(key) {
|
|
76
|
+
return Object.prototype.hasOwnProperty.call(SETTINGS, key) ? SETTINGS[key] : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function settingKeys() {
|
|
80
|
+
return Object.keys(SETTINGS);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
findSetting: findSetting,
|
|
85
|
+
settingKeys: settingKeys,
|
|
86
|
+
};
|
package/lib/terminal-manager.js
CHANGED
|
@@ -51,6 +51,15 @@ function createTerminalManager(opts) {
|
|
|
51
51
|
return caller.id === session.ownerUserId;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
// True when callerWs is the terminal's owning user (admins are not owners).
|
|
55
|
+
// No ws context or an unowned terminal: allowed, as in isAuthorized.
|
|
56
|
+
function isOwnerCaller(session, callerWs) {
|
|
57
|
+
if (!callerWs) return true;
|
|
58
|
+
if (!session.ownerUserId) return true;
|
|
59
|
+
var caller = callerWs._clagenticUser;
|
|
60
|
+
return !!caller && caller.id === session.ownerUserId;
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
function create(cols, rows, osUserInfo, ownerWs) {
|
|
55
64
|
if (terminals.size >= MAX_TERMINALS) return null;
|
|
56
65
|
|
|
@@ -70,7 +79,6 @@ function createTerminalManager(opts) {
|
|
|
70
79
|
exited: false,
|
|
71
80
|
exitCode: null,
|
|
72
81
|
subscribers: new Set(),
|
|
73
|
-
ownerWs: ownerWs || null,
|
|
74
82
|
ownerUserId: (ownerWs && ownerWs._clagenticUser && ownerWs._clagenticUser.id) ? ownerWs._clagenticUser.id : null,
|
|
75
83
|
};
|
|
76
84
|
|
|
@@ -142,7 +150,9 @@ function createTerminalManager(opts) {
|
|
|
142
150
|
// Replay scrollback only for newly attached clients
|
|
143
151
|
if (!alreadySubscribed && session.scrollback.length > 0) {
|
|
144
152
|
var replay = session.scrollback.map(function(c) { return c.data; }).join("");
|
|
145
|
-
|
|
153
|
+
// replay: true tells the client to replace its screen with this and to
|
|
154
|
+
// keep the terminal's answers to queries in it (OSC 11, DSR) off the PTY.
|
|
155
|
+
sendTo(ws, { type: "term_output", id: id, data: replay, replay: true });
|
|
146
156
|
}
|
|
147
157
|
|
|
148
158
|
// Send current terminal dimensions so the client renders at the correct size
|
|
@@ -182,9 +192,11 @@ function createTerminalManager(opts) {
|
|
|
182
192
|
function resize(id, cols, rows, sourceWs) {
|
|
183
193
|
var session = terminals.get(id);
|
|
184
194
|
if (!session || !session.pty) return;
|
|
185
|
-
// Only the
|
|
186
|
-
//
|
|
187
|
-
|
|
195
|
+
// Only the owning user can resize the PTY. Compared by user identity, not
|
|
196
|
+
// by connection: the creating socket is gone after a reconnect.
|
|
197
|
+
// Observers (admins included) resizing would cause SIGWINCH and flood the
|
|
198
|
+
// owner with escape sequences.
|
|
199
|
+
if (!isOwnerCaller(session, sourceWs)) return;
|
|
188
200
|
if (cols > 0 && rows > 0) {
|
|
189
201
|
try {
|
|
190
202
|
session.pty.resize(cols, rows);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Reads theme files from disk and decides which ones the Appearance choice may
|
|
4
|
+
// offer. Two sources: the themes shipped in lib/themes/ and the user's own
|
|
5
|
+
// files in <console home>/themes/. A file that is unreadable, oversized, not
|
|
6
|
+
// JSON or not a complete palette is skipped, so one bad file never hides the
|
|
7
|
+
// good ones or breaks the page.
|
|
8
|
+
//
|
|
9
|
+
// File format (documented in docs/guides/THEMES.md): a JSON object with a
|
|
10
|
+
// "name", sixteen base16 colours "base00".."base0F" as six hex digits without
|
|
11
|
+
// a leading "#", an optional "variant" ("dark" or "light"; derived from
|
|
12
|
+
// base00 when absent), an optional "accent2" and an optional "tokens" object
|
|
13
|
+
// of exact colours. The theme id is the file name without ".json".
|
|
14
|
+
|
|
15
|
+
var fs = require("fs");
|
|
16
|
+
var path = require("path");
|
|
17
|
+
var core = require("./public/theme-core.js");
|
|
18
|
+
|
|
19
|
+
var BASE_KEYS = core.BASE_KEYS;
|
|
20
|
+
|
|
21
|
+
var MAX_THEME_BYTES = 16 * 1024;
|
|
22
|
+
var MAX_NAME_LENGTH = 60;
|
|
23
|
+
var HEX6 = /^[0-9a-fA-F]{6}$/;
|
|
24
|
+
// The same rule theme-prefs.js applies in the browser; a test holds them together.
|
|
25
|
+
var THEME_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
26
|
+
|
|
27
|
+
function isValidThemeId(id) {
|
|
28
|
+
return typeof id === "string" && THEME_ID.test(id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A palette the client can draw, or null. Only known fields are copied, so a
|
|
33
|
+
* file cannot smuggle extra properties into the page.
|
|
34
|
+
*/
|
|
35
|
+
function normalizeTheme(raw) {
|
|
36
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
37
|
+
if (typeof raw.name !== "string") return null;
|
|
38
|
+
var name = raw.name.trim();
|
|
39
|
+
if (!name || name.length > MAX_NAME_LENGTH) return null;
|
|
40
|
+
|
|
41
|
+
var theme = { name: name };
|
|
42
|
+
for (var i = 0; i < BASE_KEYS.length; i++) {
|
|
43
|
+
var value = raw[BASE_KEYS[i]];
|
|
44
|
+
if (typeof value !== "string" || !HEX6.test(value)) return null;
|
|
45
|
+
theme[BASE_KEYS[i]] = value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (raw.variant === undefined || raw.variant === null || raw.variant === "") {
|
|
49
|
+
theme.variant = core.inferVariant(theme.base00);
|
|
50
|
+
} else if (raw.variant === "dark" || raw.variant === "light") {
|
|
51
|
+
theme.variant = raw.variant;
|
|
52
|
+
} else {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (raw.accent2 !== undefined && raw.accent2 !== null) {
|
|
57
|
+
if (typeof raw.accent2 !== "string" || !HEX6.test(raw.accent2)) return null;
|
|
58
|
+
theme.accent2 = raw.accent2;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var tokens = core.readTokens(raw.tokens);
|
|
62
|
+
if (tokens === null) return null;
|
|
63
|
+
if (tokens && Object.keys(tokens).length) theme.tokens = tokens;
|
|
64
|
+
return theme;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** One theme file: { id, theme } or { id, reason }. Never throws. */
|
|
68
|
+
function readThemeFile(dir, fileName) {
|
|
69
|
+
var id = fileName.replace(/\.json$/, "");
|
|
70
|
+
if (!isValidThemeId(id)) return { id: id, reason: "invalid-id" };
|
|
71
|
+
try {
|
|
72
|
+
var full = path.join(dir, fileName);
|
|
73
|
+
var stat = fs.statSync(full);
|
|
74
|
+
if (!stat.isFile()) return { id: id, reason: "not-a-file" };
|
|
75
|
+
if (stat.size > MAX_THEME_BYTES) return { id: id, reason: "too-large" };
|
|
76
|
+
var parsed = JSON.parse(fs.readFileSync(full, "utf8"));
|
|
77
|
+
var theme = normalizeTheme(parsed);
|
|
78
|
+
return theme ? { id: id, theme: theme } : { id: id, reason: "invalid-palette" };
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return { id: id, reason: "unreadable" };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function readDir(dir, into, skipped, taken) {
|
|
85
|
+
var files;
|
|
86
|
+
try {
|
|
87
|
+
files = fs.readdirSync(dir);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return; // no folder is the normal case for a fresh install
|
|
90
|
+
}
|
|
91
|
+
files.sort();
|
|
92
|
+
for (var i = 0; i < files.length; i++) {
|
|
93
|
+
if (!files[i].endsWith(".json")) continue;
|
|
94
|
+
var result = readThemeFile(dir, files[i]);
|
|
95
|
+
if (!result.theme) {
|
|
96
|
+
skipped.push({ file: files[i], reason: result.reason });
|
|
97
|
+
} else if (taken && Object.prototype.hasOwnProperty.call(taken, result.id)) {
|
|
98
|
+
// Dark and Light are always the console's own palettes.
|
|
99
|
+
skipped.push({ file: files[i], reason: "reserved-id" });
|
|
100
|
+
} else {
|
|
101
|
+
into[result.id] = result.theme;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* { bundled, custom, skipped } for the two directories. `skipped` is for
|
|
108
|
+
* tests and diagnostics; the API does not return it. `bundledPinned` (the
|
|
109
|
+
* themes of an earlier read) stands in for `bundledDir`.
|
|
110
|
+
*/
|
|
111
|
+
function listThemes(dirs) {
|
|
112
|
+
var bundled = {};
|
|
113
|
+
var custom = {};
|
|
114
|
+
var skipped = [];
|
|
115
|
+
if (dirs.bundledPinned) {
|
|
116
|
+
// The bundled themes the process read at startup: not read from disk again.
|
|
117
|
+
Object.assign(bundled, dirs.bundledPinned);
|
|
118
|
+
} else {
|
|
119
|
+
readDir(dirs.bundledDir, bundled, skipped, null);
|
|
120
|
+
}
|
|
121
|
+
readDir(dirs.customDir, custom, skipped, bundled);
|
|
122
|
+
return { bundled: bundled, custom: custom, skipped: skipped };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = {
|
|
126
|
+
BASE_KEYS: BASE_KEYS,
|
|
127
|
+
MAX_THEME_BYTES: MAX_THEME_BYTES,
|
|
128
|
+
THEME_ID: THEME_ID,
|
|
129
|
+
isValidThemeId: isValidThemeId,
|
|
130
|
+
normalizeTheme: normalizeTheme,
|
|
131
|
+
listThemes: listThemes,
|
|
132
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// What the server paints before the browser has run any script: the
|
|
4
|
+
// first-paint stylesheet, the manifest colours, the offline page, and the CSS
|
|
5
|
+
// variables of the sign-in and setup pages. All of it comes from the two
|
|
6
|
+
// bundled theme files (lib/themes/) through the one derivation in
|
|
7
|
+
// lib/public/theme-core.js, the same function the browser applies after
|
|
8
|
+
// load, so what is painted first is what is painted last.
|
|
9
|
+
//
|
|
10
|
+
// Dark is the default. A visitor whose system asks for light gets Light: the
|
|
11
|
+
// pages here are served before a stored choice can be read.
|
|
12
|
+
|
|
13
|
+
var path = require("path");
|
|
14
|
+
var themeFiles = require("./theme-files");
|
|
15
|
+
var clientFiles = require("./client-files");
|
|
16
|
+
var core = require("./public/theme-core.js");
|
|
17
|
+
|
|
18
|
+
var THEMES_DIR = path.join(__dirname, "themes");
|
|
19
|
+
var DARK_ID = "clagentic-dark";
|
|
20
|
+
var LIGHT_ID = "clagentic-light";
|
|
21
|
+
|
|
22
|
+
// Both are read when this module loads (daemon startup), not on first request,
|
|
23
|
+
// so a later install cannot change what this process serves: the script comes
|
|
24
|
+
// from the pinned client file set, the palettes from the files read here.
|
|
25
|
+
var CORE_SOURCE = (clientFiles.publicFiles.read("theme-core.js") || Buffer.alloc(0)).toString("utf8");
|
|
26
|
+
var PINNED_BUNDLED = readBundledOrThrow();
|
|
27
|
+
|
|
28
|
+
// The listing skips a bad file so user themes never break the page; the
|
|
29
|
+
// bundled set ships with the build, so any skip or absence is a failed read and
|
|
30
|
+
// must stop startup rather than publish a partial palette set.
|
|
31
|
+
function readBundledOrThrow() {
|
|
32
|
+
var listed = themeFiles.listThemes({ bundledDir: THEMES_DIR, customDir: null });
|
|
33
|
+
if (listed.skipped.length) {
|
|
34
|
+
var s = listed.skipped[0];
|
|
35
|
+
throw new Error("Clagentic: Console cannot start: bundled theme " + path.join(THEMES_DIR, s.file) + " failed: " + s.reason);
|
|
36
|
+
}
|
|
37
|
+
[DARK_ID, LIGHT_ID].forEach(function (id) {
|
|
38
|
+
if (!listed.bundled[id]) {
|
|
39
|
+
throw new Error("Clagentic: Console cannot start: bundled theme " + path.join(THEMES_DIR, id + ".json") + " failed: not read");
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return listed.bundled;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var cache = null;
|
|
46
|
+
|
|
47
|
+
/** The bundled themes this process loaded, by id. A copy: callers may not change the pinned set. */
|
|
48
|
+
function pinnedBundledThemes() {
|
|
49
|
+
return Object.assign({}, PINNED_BUNDLED);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function bundledVars() {
|
|
53
|
+
return loadBundled().vars;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function loadBundled() {
|
|
57
|
+
if (cache) return cache;
|
|
58
|
+
var listed = PINNED_BUNDLED;
|
|
59
|
+
if (!listed[DARK_ID] || !listed[LIGHT_ID]) {
|
|
60
|
+
throw new Error("the bundled themes " + DARK_ID + " and " + LIGHT_ID + " could not be read from " + THEMES_DIR);
|
|
61
|
+
}
|
|
62
|
+
cache = {
|
|
63
|
+
themes: { dark: listed[DARK_ID], light: listed[LIGHT_ID] },
|
|
64
|
+
vars: {
|
|
65
|
+
dark: core.deriveVars(listed[DARK_ID]),
|
|
66
|
+
light: core.deriveVars(listed[LIGHT_ID]),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
return cache;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// lib/public/theme-core.js as the browser receives it: the file, plus the two
|
|
73
|
+
// built-in palettes read from the theme files. The browser's theme code holds
|
|
74
|
+
// them before /api/themes answers; under Node the file reads them itself.
|
|
75
|
+
function themeCoreScript() {
|
|
76
|
+
var t = loadBundled().themes;
|
|
77
|
+
if (!CORE_SOURCE) throw new Error("theme-core.js was not part of the client files loaded at startup");
|
|
78
|
+
return CORE_SOURCE +
|
|
79
|
+
"\nglobalThis.ClagenticThemeCore.builtin = " + JSON.stringify({ dark: t.dark, light: t.light }) + ";\n";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Variables for the pages that carry no script: dark by default, light when
|
|
83
|
+
// the system asks for it.
|
|
84
|
+
function systemVarsCss() {
|
|
85
|
+
var v = bundledVars();
|
|
86
|
+
return ":root{" + core.varsToCss(v.dark) + "}" +
|
|
87
|
+
"@media(prefers-color-scheme:light){:root{" + core.varsToCss(v.light) + "}}";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The stylesheet the app shell links before anything else. The class the
|
|
91
|
+
// first-paint script puts on <html> (light-theme or dark-theme) selects the
|
|
92
|
+
// block; with neither class, the system preference does.
|
|
93
|
+
function firstPaintCss() {
|
|
94
|
+
var v = bundledVars();
|
|
95
|
+
var dark = core.varsToCss(v.dark);
|
|
96
|
+
var light = core.varsToCss(v.light);
|
|
97
|
+
return ":root{" + dark + "}\n" +
|
|
98
|
+
":root.light-theme{" + light + "}\n" +
|
|
99
|
+
"@media (prefers-color-scheme: light){:root:not(.dark-theme){" + light + "}}\n";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// manifest.json with its two colours set to the Dark page colour.
|
|
103
|
+
function stampManifest(source) {
|
|
104
|
+
var manifest = JSON.parse(source);
|
|
105
|
+
var bg = bundledVars().dark["--bg"];
|
|
106
|
+
manifest.background_color = bg;
|
|
107
|
+
manifest.theme_color = bg;
|
|
108
|
+
return JSON.stringify(manifest, null, 2) + "\n";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// The style of the page the service worker shows when the shell is not cached.
|
|
112
|
+
function offlinePageCss() {
|
|
113
|
+
var v = bundledVars();
|
|
114
|
+
function body(vars) {
|
|
115
|
+
return "body{background:" + vars["--bg"] + ";color:" + vars["--text-muted"] + "}";
|
|
116
|
+
}
|
|
117
|
+
return body(v.dark) + "@media(prefers-color-scheme:light){" + body(v.light) + "}";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
var OFFLINE_PLACEHOLDER = /"__OFFLINE_PAGE_CSS__"/;
|
|
121
|
+
|
|
122
|
+
// sw.js with the offline page style filled in.
|
|
123
|
+
function stampServiceWorker(source) {
|
|
124
|
+
var css = JSON.stringify(offlinePageCss());
|
|
125
|
+
return source.replace(OFFLINE_PLACEHOLDER, function () { return css; });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = {
|
|
129
|
+
pinnedBundledThemes: pinnedBundledThemes,
|
|
130
|
+
themeCoreScript: themeCoreScript,
|
|
131
|
+
systemVarsCss: systemVarsCss,
|
|
132
|
+
firstPaintCss: firstPaintCss,
|
|
133
|
+
stampManifest: stampManifest,
|
|
134
|
+
offlinePageCss: offlinePageCss,
|
|
135
|
+
stampServiceWorker: stampServiceWorker,
|
|
136
|
+
};
|