@clagentic/console 1.9.0-beta.2 → 1.9.0-beta.3
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/bin/cli.js +12 -1
- package/lib/build-sha.json +2 -2
- package/lib/cli/ipc-subcommands.js +44 -0
- package/lib/daemon.js +86 -6
- package/lib/effective-protocol.js +82 -0
- package/lib/project-connection.js +6 -6
- package/lib/project-filesystem.js +4 -4
- package/lib/project-http.js +4 -4
- package/lib/project-loop.js +4 -4
- package/lib/project-sessions.js +147 -77
- package/lib/project-user-mention.js +7 -7
- package/lib/project-user-message.js +11 -11
- package/lib/project.js +21 -21
- package/lib/public/app.js +10 -6
- package/lib/public/css/filebrowser.css +6 -0
- package/lib/public/css/server-settings.css +9 -0
- package/lib/public/index.html +8 -2
- package/lib/public/modules/activity-latch.js +25 -139
- package/lib/public/modules/activity-state.js +44 -6
- package/lib/public/modules/app-connection.js +24 -5
- package/lib/public/modules/app-favicon.js +52 -65
- package/lib/public/modules/app-messages.js +114 -54
- package/lib/public/modules/app-projects.js +24 -7
- package/lib/public/modules/server-settings.js +256 -21
- package/lib/public/modules/theme.js +2 -2
- package/lib/sdk-bridge.js +76 -13
- package/lib/server-dm.js +5 -5
- package/lib/server-hub-sessions.js +1 -1
- package/lib/server.js +55 -22
- package/lib/session-activity.js +1 -1
- package/lib/sessions.js +17 -17
- package/lib/terminal-manager.js +6 -6
- package/package.json +1 -1
- package/scripts/verify-installed-build.js +242 -15
|
@@ -236,29 +236,30 @@ export function initServerSettings(appCtx) {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
// Advanced Memory: min available memory input
|
|
239
|
+
// Advanced Memory: min available memory input.
|
|
240
|
+
// change (blur/Enter) stays wired as an implicit commit path for users who
|
|
241
|
+
// expect it; the explicit ss-memory-save-btn click below (lr-9e6569) is
|
|
242
|
+
// the primary, discoverable affordance — this panel had none before.
|
|
240
243
|
var memAvailInput = document.getElementById("settings-mem-available-min");
|
|
241
244
|
if (memAvailInput) {
|
|
242
|
-
memAvailInput.addEventListener("change", function () {
|
|
243
|
-
var val = parseInt(this.value, 10);
|
|
244
|
-
if (isNaN(val) || val < 0) return;
|
|
245
|
-
var ws = ctx.ws;
|
|
246
|
-
if (ws && ws.readyState === 1) {
|
|
247
|
-
ws.send(JSON.stringify({ type: "set_mem_available_threshold", value: val }));
|
|
248
|
-
}
|
|
249
|
-
});
|
|
245
|
+
memAvailInput.addEventListener("change", function () { saveMemAvailableThreshold(); });
|
|
250
246
|
}
|
|
251
247
|
|
|
252
|
-
// Advanced Memory: tokens per MB headroom input
|
|
248
|
+
// Advanced Memory: tokens per MB headroom input (same change-listener rationale).
|
|
253
249
|
var tpmInput = document.getElementById("settings-tokens-per-mb-headroom");
|
|
254
250
|
if (tpmInput) {
|
|
255
|
-
tpmInput.addEventListener("change", function () {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
251
|
+
tpmInput.addEventListener("change", function () { saveTokensPerMbHeadroom(); });
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Advanced Memory: explicit Save button (lr-9e6569). The panel previously had
|
|
255
|
+
// no commit affordance at all -- only the native change event above, which
|
|
256
|
+
// never fires for a user who types a value and navigates away without
|
|
257
|
+
// blurring. Saves both fields; each still validates independently.
|
|
258
|
+
var memorySaveBtn = document.getElementById("ss-memory-save-btn");
|
|
259
|
+
if (memorySaveBtn) {
|
|
260
|
+
memorySaveBtn.addEventListener("click", function () {
|
|
261
|
+
saveMemAvailableThreshold();
|
|
262
|
+
saveTokensPerMbHeadroom();
|
|
262
263
|
});
|
|
263
264
|
}
|
|
264
265
|
|
|
@@ -744,11 +745,23 @@ export function updateDaemonConfig(config) {
|
|
|
744
745
|
var portEl = document.getElementById("settings-port");
|
|
745
746
|
if (portEl) portEl.textContent = String(config.port || "-");
|
|
746
747
|
|
|
747
|
-
//
|
|
748
|
+
// HTTPS (lr-20e71c): three states, not two. tlsState distinguishes the
|
|
749
|
+
// daemon terminating TLS itself ("direct") from a trusted reverse proxy
|
|
750
|
+
// terminating it in front of the daemon ("proxy") — both are genuinely
|
|
751
|
+
// HTTPS from the client's perspective, but only "direct" means tlsOptions
|
|
752
|
+
// is set. A real unencrypted deployment ("disabled") must render visibly
|
|
753
|
+
// distinct from both, never silently reported as Enabled.
|
|
748
754
|
var tlsEl = document.getElementById("settings-tls");
|
|
749
755
|
if (tlsEl) {
|
|
750
|
-
|
|
751
|
-
|
|
756
|
+
var tlsState = config.tlsState || (config.tls ? "direct" : "disabled");
|
|
757
|
+
var tlsLabel = tlsState === "direct" ? "Enabled" :
|
|
758
|
+
tlsState === "proxy" ? "Enabled (proxy)" : "Disabled";
|
|
759
|
+
tlsEl.textContent = tlsLabel;
|
|
760
|
+
tlsEl.classList.toggle("settings-badge-green", tlsState === "direct");
|
|
761
|
+
tlsEl.classList.toggle("settings-badge-proxy", tlsState === "proxy");
|
|
762
|
+
tlsEl.title = tlsState === "proxy"
|
|
763
|
+
? "TLS is terminated by a reverse proxy in front of this daemon, not by the daemon itself."
|
|
764
|
+
: "";
|
|
752
765
|
}
|
|
753
766
|
|
|
754
767
|
// Debug
|
|
@@ -796,14 +809,53 @@ export function updateDaemonConfig(config) {
|
|
|
796
809
|
liteAutoEnrollToggle.checked = !!config.liteAutoEnroll;
|
|
797
810
|
}
|
|
798
811
|
|
|
799
|
-
// Advanced Memory inputs
|
|
812
|
+
// Advanced Memory inputs. lr-9e6569: memAvailableMinMBIsDefault /
|
|
813
|
+
// tokensPerMbHeadroomIsDefault distinguish "this number is a fallback
|
|
814
|
+
// because nothing was ever persisted" from "this number was saved" -- an
|
|
815
|
+
// absent config key renders a value visually identical to a persisted one
|
|
816
|
+
// otherwise, which is part of why a discarded edit went unnoticed.
|
|
800
817
|
var memAvailEl = document.getElementById("settings-mem-available-min");
|
|
801
818
|
if (memAvailEl && config.memAvailableMinMB !== undefined) {
|
|
802
819
|
memAvailEl.value = String(config.memAvailableMinMB);
|
|
820
|
+
// lr-9e6569 fold-in (BOBBIE bobbie.uncat.1): the dedup marker means "the
|
|
821
|
+
// value the server is known to hold", not "the last value this tab
|
|
822
|
+
// optimistically transmitted". This snapshot IS the server's authoritative
|
|
823
|
+
// state, so reconcile the marker here too -- otherwise a save whose
|
|
824
|
+
// response never arrives (disconnect between send and daemon processing)
|
|
825
|
+
// leaves the marker pinned to the unconfirmed value; a reconnect repaints
|
|
826
|
+
// .value but not the marker, and a later legitimate retry of that exact
|
|
827
|
+
// value is then silently suppressed by saveMemAvailableThreshold's
|
|
828
|
+
// `val === lastSentMemAvailableMin` check with no send and no feedback.
|
|
829
|
+
// A fallback default is intentionally NOT marked as last-sent: clicking
|
|
830
|
+
// Save on "Using default — not yet saved" must still persist the key.
|
|
831
|
+
lastSentMemAvailableMin = config.memAvailableMinMBIsDefault === true ? null : config.memAvailableMinMB;
|
|
832
|
+
}
|
|
833
|
+
// lr-9e6569 fold-in (PEACHES finding 3): updateDaemonConfig also receives
|
|
834
|
+
// the PARTIAL daemon_config_changed broadcast (currently just
|
|
835
|
+
// { liteAutoEnroll }), not only the full onGetDaemonConfig snapshot -- see
|
|
836
|
+
// app-messages.js's daemon_config_changed -> updateDaemonConfig wiring.
|
|
837
|
+
// Every other field above guards on `!== undefined` so a partial broadcast
|
|
838
|
+
// leaves it untouched; the note lines below must do the same. Gating only
|
|
839
|
+
// on `!== undefined` before writing keeps an unrelated setting change
|
|
840
|
+
// (e.g. Lite auto-enroll) elsewhere in the app from clearing "Using
|
|
841
|
+
// default — not yet saved" for memory settings that were never part of
|
|
842
|
+
// that broadcast in the first place.
|
|
843
|
+
var memAvailNoteEl = document.getElementById("settings-mem-available-min-default-note");
|
|
844
|
+
if (memAvailNoteEl && config.memAvailableMinMBIsDefault !== undefined) {
|
|
845
|
+
memAvailNoteEl.textContent = config.memAvailableMinMBIsDefault ? "Using default — not yet saved" : "";
|
|
803
846
|
}
|
|
804
847
|
var tpmEl = document.getElementById("settings-tokens-per-mb-headroom");
|
|
805
848
|
if (tpmEl && config.tokensPerMbHeadroom !== undefined) {
|
|
806
849
|
tpmEl.value = String(config.tokensPerMbHeadroom);
|
|
850
|
+
// lr-9e6569 fold-in (BOBBIE bobbie.uncat.1): same reconciliation as
|
|
851
|
+
// memAvailableMinMB above -- see that comment for the full failure
|
|
852
|
+
// sequence this closes.
|
|
853
|
+
// A fallback default must remain persistable by clicking Save.
|
|
854
|
+
lastSentTokensPerMbHeadroom = config.tokensPerMbHeadroomIsDefault === true ? null : config.tokensPerMbHeadroom;
|
|
855
|
+
}
|
|
856
|
+
var tpmNoteEl = document.getElementById("settings-tokens-per-mb-headroom-default-note");
|
|
857
|
+
if (tpmNoteEl && config.tokensPerMbHeadroomIsDefault !== undefined) {
|
|
858
|
+
tpmNoteEl.textContent = config.tokensPerMbHeadroomIsDefault ? "Using default — not yet saved" : "";
|
|
807
859
|
}
|
|
808
860
|
|
|
809
861
|
// Show keep awake subsection only on macOS (lives inside the Advanced section)
|
|
@@ -818,6 +870,182 @@ export function updateDaemonConfig(config) {
|
|
|
818
870
|
}
|
|
819
871
|
}
|
|
820
872
|
|
|
873
|
+
// lr-93e3c8 (fnd-66af4e): the Advanced > Memory inputs had a working change
|
|
874
|
+
// listener and a working daemon-side handler, but zero client-side feedback
|
|
875
|
+
// on either success or failure — a working control was indistinguishable
|
|
876
|
+
// from a dead one. Every other control in this panel (CLAUDE.md save,
|
|
877
|
+
// shared-env autosave) has a status element; these had none.
|
|
878
|
+
//
|
|
879
|
+
// lr-9e6569 fold-in (PEACHES finding 1): both memory fields share this one
|
|
880
|
+
// status element, but each field saves independently and responses can
|
|
881
|
+
// arrive out of order. Writing text unconditionally meant an error from one
|
|
882
|
+
// field was silently overwritten by "Saving..."/"Saved" from the other --
|
|
883
|
+
// a green success indication for a field that actually failed. Track each
|
|
884
|
+
// field's own outcome and render the combined result: any field currently
|
|
885
|
+
// in error wins the display (an error is never masked by the other field's
|
|
886
|
+
// success), and the shared element only clears once neither field is in
|
|
887
|
+
// error and neither has a message actively pending.
|
|
888
|
+
var MEMORY_FIELD_LABELS = {
|
|
889
|
+
memAvail: "Min available memory",
|
|
890
|
+
tpm: "Tokens per MB headroom",
|
|
891
|
+
};
|
|
892
|
+
var memoryFieldStatus = {
|
|
893
|
+
memAvail: { text: "", isError: false, seq: 0 },
|
|
894
|
+
tpm: { text: "", isError: false, seq: 0 },
|
|
895
|
+
};
|
|
896
|
+
var memoryStatusSeq = 0;
|
|
897
|
+
|
|
898
|
+
function renderMemorySaveStatus() {
|
|
899
|
+
var el = document.getElementById("ss-memory-save-status");
|
|
900
|
+
if (!el) return;
|
|
901
|
+
var memAvail = memoryFieldStatus.memAvail;
|
|
902
|
+
var tpm = memoryFieldStatus.tpm;
|
|
903
|
+
var errors = [];
|
|
904
|
+
if (memAvail.isError && memAvail.text) errors.push(MEMORY_FIELD_LABELS.memAvail + ": " + memAvail.text);
|
|
905
|
+
if (tpm.isError && tpm.text) errors.push(MEMORY_FIELD_LABELS.tpm + ": " + tpm.text);
|
|
906
|
+
|
|
907
|
+
if (errors.length > 0) {
|
|
908
|
+
// An error is never masked by the other field's success -- always wins the display.
|
|
909
|
+
el.textContent = errors.join(" | ");
|
|
910
|
+
el.classList.add("ps-save-status-error");
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
el.classList.remove("ps-save-status-error");
|
|
915
|
+
// Neither field is in error: show whichever non-empty status is most recent
|
|
916
|
+
// (the field object holding text is the one that just transitioned).
|
|
917
|
+
var latest = memAvail.seq >= tpm.seq ? memAvail : tpm;
|
|
918
|
+
var other = latest === memAvail ? tpm : memAvail;
|
|
919
|
+
el.textContent = latest.text || other.text || "";
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function setFieldSaveStatus(field, text, isError) {
|
|
923
|
+
memoryFieldStatus[field] = { text: text, isError: !!isError, seq: ++memoryStatusSeq };
|
|
924
|
+
renderMemorySaveStatus();
|
|
925
|
+
if (!isError && text) {
|
|
926
|
+
setTimeout(function () {
|
|
927
|
+
if (memoryFieldStatus[field].text === text && !memoryFieldStatus[field].isError) {
|
|
928
|
+
memoryFieldStatus[field] = { text: "", isError: false, seq: memoryFieldStatus[field].seq };
|
|
929
|
+
renderMemorySaveStatus();
|
|
930
|
+
}
|
|
931
|
+
}, 2000);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// lr-9e6569: a value the daemon derived from DEFAULT_MEM_AVAILABLE_MIN_MB /
|
|
936
|
+
// DEFAULT_TOKENS_PER_MB_HEADROOM because the config key was never set renders
|
|
937
|
+
// visually identical to a persisted value equal to that default -- part of
|
|
938
|
+
// why a silently-discarded edit went unnoticed for three rounds. Once this
|
|
939
|
+
// module explicitly saves a value, it IS persisted, so clear the note here
|
|
940
|
+
// rather than waiting on the next full daemon_config round-trip.
|
|
941
|
+
function clearDefaultNote(elId) {
|
|
942
|
+
var el = document.getElementById(elId);
|
|
943
|
+
if (el) el.textContent = "";
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// lr-9e6569 fold-in (PEACHES finding 2): the blur/Enter `change` listener and
|
|
947
|
+
// the explicit Save button's click listener both call these same save
|
|
948
|
+
// functions, so typing a value then clicking Save fired the WS send twice
|
|
949
|
+
// for the same field (blur fires `change` first, then the click handler
|
|
950
|
+
// calls the save function again with the identical, already-sent value).
|
|
951
|
+
// Track the last value this field successfully attempted to send; if the
|
|
952
|
+
// current input value hasn't changed since then, the second call is a
|
|
953
|
+
// no-op. A genuinely new edit (different value) still sends -- this only
|
|
954
|
+
// suppresses the redundant repeat of a value already in flight/saved,
|
|
955
|
+
// keeping both commit paths (blur/Enter and the button) working for their
|
|
956
|
+
// own distinct edits.
|
|
957
|
+
var lastSentMemAvailableMin = null;
|
|
958
|
+
var lastSentTokensPerMbHeadroom = null;
|
|
959
|
+
|
|
960
|
+
function saveMemAvailableThreshold() {
|
|
961
|
+
var input = document.getElementById("settings-mem-available-min");
|
|
962
|
+
if (!input) return;
|
|
963
|
+
var val = parseInt(input.value, 10);
|
|
964
|
+
if (isNaN(val) || val < 0) {
|
|
965
|
+
setFieldSaveStatus("memAvail", "Invalid value — must be 0 or greater", true);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
if (val === lastSentMemAvailableMin) return;
|
|
969
|
+
var ws = ctx.ws;
|
|
970
|
+
if (ws && ws.readyState === 1) {
|
|
971
|
+
lastSentMemAvailableMin = val;
|
|
972
|
+
setFieldSaveStatus("memAvail", "Saving...", false);
|
|
973
|
+
ws.send(JSON.stringify({ type: "set_mem_available_threshold", value: val }));
|
|
974
|
+
} else {
|
|
975
|
+
setFieldSaveStatus("memAvail", "Not connected — change not saved", true);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function saveTokensPerMbHeadroom() {
|
|
980
|
+
var input = document.getElementById("settings-tokens-per-mb-headroom");
|
|
981
|
+
if (!input) return;
|
|
982
|
+
var val = parseInt(input.value, 10);
|
|
983
|
+
if (isNaN(val) || val < 10 || val > 500) {
|
|
984
|
+
setFieldSaveStatus("tpm", "Invalid value — must be 10-500", true);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (val === lastSentTokensPerMbHeadroom) return;
|
|
988
|
+
var ws = ctx.ws;
|
|
989
|
+
if (ws && ws.readyState === 1) {
|
|
990
|
+
lastSentTokensPerMbHeadroom = val;
|
|
991
|
+
setFieldSaveStatus("tpm", "Saving...", false);
|
|
992
|
+
ws.send(JSON.stringify({ type: "set_tokens_per_mb_headroom", value: val }));
|
|
993
|
+
} else {
|
|
994
|
+
setFieldSaveStatus("tpm", "Not connected — change not saved", true);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
export function handleSetMemAvailableThresholdResult(msg) {
|
|
999
|
+
if (msg.ok) {
|
|
1000
|
+
setFieldSaveStatus("memAvail", "Saved", false);
|
|
1001
|
+
var memAvailEl = document.getElementById("settings-mem-available-min");
|
|
1002
|
+
if (memAvailEl && typeof msg.memAvailableMinMB === "number") {
|
|
1003
|
+
memAvailEl.value = String(msg.memAvailableMinMB);
|
|
1004
|
+
lastSentMemAvailableMin = msg.memAvailableMinMB;
|
|
1005
|
+
}
|
|
1006
|
+
clearDefaultNote("settings-mem-available-min-default-note");
|
|
1007
|
+
} else {
|
|
1008
|
+
// A failed save must not be treated as "in flight" for dedup purposes --
|
|
1009
|
+
// clear the last-sent marker so a retry of the same value is not
|
|
1010
|
+
// silently suppressed.
|
|
1011
|
+
lastSentMemAvailableMin = null;
|
|
1012
|
+
setFieldSaveStatus("memAvail", "Error: " + (msg.error || "Failed to save"), true);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
export function handleMemAvailableThresholdChanged(msg) {
|
|
1017
|
+
var memAvailEl = document.getElementById("settings-mem-available-min");
|
|
1018
|
+
if (memAvailEl && typeof msg.memAvailableMinMB === "number") {
|
|
1019
|
+
memAvailEl.value = String(msg.memAvailableMinMB);
|
|
1020
|
+
lastSentMemAvailableMin = msg.memAvailableMinMB;
|
|
1021
|
+
}
|
|
1022
|
+
clearDefaultNote("settings-mem-available-min-default-note");
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
export function handleSetTokensPerMbHeadroomResult(msg) {
|
|
1026
|
+
if (msg.ok) {
|
|
1027
|
+
setFieldSaveStatus("tpm", "Saved", false);
|
|
1028
|
+
var tpmEl = document.getElementById("settings-tokens-per-mb-headroom");
|
|
1029
|
+
if (tpmEl && typeof msg.tokensPerMbHeadroom === "number") {
|
|
1030
|
+
tpmEl.value = String(msg.tokensPerMbHeadroom);
|
|
1031
|
+
lastSentTokensPerMbHeadroom = msg.tokensPerMbHeadroom;
|
|
1032
|
+
}
|
|
1033
|
+
clearDefaultNote("settings-tokens-per-mb-headroom-default-note");
|
|
1034
|
+
} else {
|
|
1035
|
+
lastSentTokensPerMbHeadroom = null;
|
|
1036
|
+
setFieldSaveStatus("tpm", "Error: " + (msg.error || "Failed to save"), true);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
export function handleTokensPerMbHeadroomChanged(msg) {
|
|
1041
|
+
var tpmEl = document.getElementById("settings-tokens-per-mb-headroom");
|
|
1042
|
+
if (tpmEl && typeof msg.tokensPerMbHeadroom === "number") {
|
|
1043
|
+
tpmEl.value = String(msg.tokensPerMbHeadroom);
|
|
1044
|
+
lastSentTokensPerMbHeadroom = msg.tokensPerMbHeadroom;
|
|
1045
|
+
}
|
|
1046
|
+
clearDefaultNote("settings-tokens-per-mb-headroom-default-note");
|
|
1047
|
+
}
|
|
1048
|
+
|
|
821
1049
|
export function handleSetPinResult(msg) {
|
|
822
1050
|
if (msg.ok) {
|
|
823
1051
|
updatePinStatus(!!msg.pinEnabled);
|
|
@@ -1188,4 +1416,11 @@ registerHandlers({
|
|
|
1188
1416
|
refresh_agents_result: handleRefreshAgentsResult,
|
|
1189
1417
|
restart_server_result: handleRestartResult,
|
|
1190
1418
|
shutdown_server_result: handleShutdownResult,
|
|
1419
|
+
// lr-93e3c8: these four were declared in ws-schema.js with app-messages.js
|
|
1420
|
+
// named as handler but never actually implemented anywhere (fnd-66af4e) —
|
|
1421
|
+
// the client-side half of why edits to Advanced > Memory silently reverted.
|
|
1422
|
+
set_mem_available_threshold_result: handleSetMemAvailableThresholdResult,
|
|
1423
|
+
mem_available_threshold_changed: handleMemAvailableThresholdChanged,
|
|
1424
|
+
set_tokens_per_mb_headroom_result: handleSetTokensPerMbHeadroomResult,
|
|
1425
|
+
tokens_per_mb_headroom_changed: handleTokensPerMbHeadroomChanged,
|
|
1191
1426
|
});
|
|
@@ -787,8 +787,8 @@ export function initTheme() {
|
|
|
787
787
|
updateToggleIcon();
|
|
788
788
|
|
|
789
789
|
var islandToggle = document.getElementById("user-theme-toggle-btn");
|
|
790
|
-
if (islandToggle && !islandToggle.
|
|
791
|
-
islandToggle.
|
|
790
|
+
if (islandToggle && !islandToggle._clagenticThemeBound) {
|
|
791
|
+
islandToggle._clagenticThemeBound = true;
|
|
792
792
|
islandToggle.addEventListener("click", function () {
|
|
793
793
|
toggleDarkMode();
|
|
794
794
|
});
|
package/lib/sdk-bridge.js
CHANGED
|
@@ -169,10 +169,24 @@ var DEFAULT_MEM_AVAILABLE_MIN_MB = 1024;
|
|
|
169
169
|
// nothing.
|
|
170
170
|
var MAX_PENDING_MESSAGES = 20;
|
|
171
171
|
|
|
172
|
-
// --- lr-2d91: cgroup context token guard ---
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
|
|
172
|
+
// --- lr-2d91 / lr-93e3c8: cgroup context token guard ---
|
|
173
|
+
// Recalibrated (lr-93e3c8, fnd-0ca818): the original 67 tok/MB figure was
|
|
174
|
+
// derived from ONE pathological 17M-cache-read-tokens/turn session that
|
|
175
|
+
// caused two real OOM kills, generalized to a claude-opus-4-at-1M-context
|
|
176
|
+
// assumption of ~15 GB RSS. That generalization does not hold for this
|
|
177
|
+
// daemon's actual cgroup: this service's own all-time memory.peak
|
|
178
|
+
// (readable at /sys/fs/cgroup/system.slice/<unit>.service/memory.peak,
|
|
179
|
+
// same directory as memory.current/memory.max already read below) was
|
|
180
|
+
// observed at 2732 MB while carrying a confirmed ~661K-token session --
|
|
181
|
+
// i.e. this real workload's worst-case-to-date density is roughly
|
|
182
|
+
// 661000 / 2732 =~ 242 tokens/MB, not 67. 240 is used here (rounded down,
|
|
183
|
+
// the conservative direction: assuming slightly MORE memory per token than
|
|
184
|
+
// observed keeps the guard's allowance slightly lower than the measured
|
|
185
|
+
// ceiling, never higher). This is still a single data point, not a
|
|
186
|
+
// distribution -- operators with a different workload shape should tune
|
|
187
|
+
// tokensPerMbHeadroom in Server Settings > Advanced > Memory rather than
|
|
188
|
+
// relying on this default being right for their traffic.
|
|
189
|
+
var DEFAULT_TOKENS_PER_MB_HEADROOM = 240;
|
|
176
190
|
|
|
177
191
|
// Configurable warn fractions for context guards (lr-1f7e).
|
|
178
192
|
// cgroupWarnFraction: warn when context tokens exceed this fraction of the
|
|
@@ -183,6 +197,37 @@ var DEFAULT_TOKENS_PER_MB_HEADROOM = 67;
|
|
|
183
197
|
var DEFAULT_CGROUP_WARN_FRACTION = 0.8;
|
|
184
198
|
var DEFAULT_CONTEXT_WINDOW_WARN_FRACTION = 0.8;
|
|
185
199
|
|
|
200
|
+
// Resolve the effective MemAvailable gate threshold (MB) from daemon config.
|
|
201
|
+
// Pulled out as a pure function so the accept/honor agreement between this
|
|
202
|
+
// consumer and daemon.js's onSetMemAvailableThreshold setter (both must treat
|
|
203
|
+
// 0 as "disable the gate", not "unset -- use the default") can be unit
|
|
204
|
+
// tested directly, without needing to fake /proc/meminfo through startQuery.
|
|
205
|
+
function resolveMemAvailableThresholdMB(config) {
|
|
206
|
+
if (config && typeof config.memAvailableMinMB === "number" && config.memAvailableMinMB >= 0) {
|
|
207
|
+
return config.memAvailableMinMB;
|
|
208
|
+
}
|
|
209
|
+
return DEFAULT_MEM_AVAILABLE_MIN_MB;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Build the operator-facing "why was this blocked" clause for the cgroup
|
|
213
|
+
// context hard gate, given the freshly-read host MemAvailable (MB, or null
|
|
214
|
+
// if unreadable) and the cgroup headroom (MB) that triggered the block.
|
|
215
|
+
// Pulled out as a pure function (lr-93e3c8 fold-in, PEACHES finding 2) so the
|
|
216
|
+
// boundary condition and the null-host-read fallback can be unit tested
|
|
217
|
+
// directly -- readMemAvailableMB()/readCgroupHeadroomMB() read real
|
|
218
|
+
// /proc/meminfo and /sys/fs/cgroup, which is not host-independently
|
|
219
|
+
// mockable, but this decision is pure once those two numbers are in hand.
|
|
220
|
+
function computeCgroupBlockCauseMessage(hostMemAvailMB, cgHeadroomMB) {
|
|
221
|
+
var hostIsGenerous = hostMemAvailMB !== null && hostMemAvailMB >= cgHeadroomMB * 2;
|
|
222
|
+
if (hostIsGenerous) {
|
|
223
|
+
return "This daemon's service memory cap (systemd MemoryMax) is the limiting factor, not host memory (" + hostMemAvailMB + " MB free on the host). Raise 'Context tokens per MB headroom' in Server Settings > Advanced > Memory, or raise MemoryMax in the clagentic-console systemd unit, if this is a false positive.";
|
|
224
|
+
}
|
|
225
|
+
if (hostMemAvailMB !== null) {
|
|
226
|
+
return "Available memory (host and service cap alike) is genuinely low right now.";
|
|
227
|
+
}
|
|
228
|
+
return "Could not read host memory to determine the cause; the service memory cap (" + cgHeadroomMB + " MB headroom) is the limiting factor measured here.";
|
|
229
|
+
}
|
|
230
|
+
|
|
186
231
|
// Read Linux MemAvailable from /proc/meminfo synchronously.
|
|
187
232
|
// Returns available memory in MB, or null on non-Linux or read failure.
|
|
188
233
|
// Sub-millisecond on Linux; the synchronous read is correct here — this is a
|
|
@@ -1718,13 +1763,7 @@ function createSDKBridge(opts) {
|
|
|
1718
1763
|
if (isNewQuery) {
|
|
1719
1764
|
var memAvailMB = readMemAvailableMB();
|
|
1720
1765
|
var getConfig = opts.getConfig;
|
|
1721
|
-
var memThresholdMB =
|
|
1722
|
-
if (typeof getConfig === "function") {
|
|
1723
|
-
var dc = getConfig();
|
|
1724
|
-
if (dc && typeof dc.memAvailableMinMB === "number" && dc.memAvailableMinMB > 0) {
|
|
1725
|
-
memThresholdMB = dc.memAvailableMinMB;
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1766
|
+
var memThresholdMB = resolveMemAvailableThresholdMB(typeof getConfig === "function" ? getConfig() : null);
|
|
1728
1767
|
if (memAvailMB !== null && memAvailMB < memThresholdMB) {
|
|
1729
1768
|
console.warn("[sdk-bridge] MemAvailable gate: " + memAvailMB + " MB available, " + memThresholdMB + " MB required — rejecting new query for session " + session.localId);
|
|
1730
1769
|
session.isProcessing = false;
|
|
@@ -1788,7 +1827,31 @@ function createSDKBridge(opts) {
|
|
|
1788
1827
|
console.warn("[sdk-bridge] cgroup context guard: " + Math.round(contextTokens / 1000) + "K tokens >= " + Math.round(allowedTokens / 1000) + "K allowed (" + cgHeadroomMB + " MB headroom) — blocking session " + session.localId);
|
|
1789
1828
|
session.isProcessing = false;
|
|
1790
1829
|
onProcessingChanged();
|
|
1791
|
-
|
|
1830
|
+
// lr-93e3c8 (fnd-0ca818): the guard reads exactly two inputs — cgroup
|
|
1831
|
+
// headroom and this session's own context tokens — and never
|
|
1832
|
+
// consults _activeLiveCount. The old message unconditionally
|
|
1833
|
+
// suggested "wait for other sessions to complete" even when
|
|
1834
|
+
// _activeLiveCount was 0, asserting a cause the code never
|
|
1835
|
+
// evaluates. _activeLiveCount here reflects OTHER currently-running
|
|
1836
|
+
// sessions only: this session's own slot is claimed later (see
|
|
1837
|
+
// "Claim the slot now" below), so it has not incremented the
|
|
1838
|
+
// counter yet at this point in the flow.
|
|
1839
|
+
var otherLiveSessions = _activeLiveCount;
|
|
1840
|
+
// lr-93e3c8 (item 3): distinguish "this daemon's service cgroup is
|
|
1841
|
+
// capped low" from "the machine itself is out of memory" -- these
|
|
1842
|
+
// call for different operator actions (raise MemoryMax in the
|
|
1843
|
+
// unit file / raise tokensPerMbHeadroom, vs. actually free host
|
|
1844
|
+
// RAM) and the prior message conflated them under one generic
|
|
1845
|
+
// "available memory" phrase. readMemAvailableMB() (host-wide
|
|
1846
|
+
// /proc/meminfo) is already read earlier in this function for the
|
|
1847
|
+
// separate MemAvailable gate; read fresh here so it reflects
|
|
1848
|
+
// current state at block time, not whatever it was at query start.
|
|
1849
|
+
var _hostMemAvailMB = readMemAvailableMB();
|
|
1850
|
+
var causeMsg = computeCgroupBlockCauseMessage(_hostMemAvailMB, cgHeadroomMB);
|
|
1851
|
+
var blockMsg = "Session context too large for available memory (" + Math.round(contextTokens / 1000) + "K tokens, " + cgHeadroomMB + " MB service headroom). " +
|
|
1852
|
+
(otherLiveSessions > 0
|
|
1853
|
+
? "Start a new session, or wait for " + otherLiveSessions + " other active session" + (otherLiveSessions === 1 ? "" : "s") + " to complete to free up headroom."
|
|
1854
|
+
: "Start a new session. " + causeMsg);
|
|
1792
1855
|
sendAndRecord(session, { type: "error", text: blockMsg });
|
|
1793
1856
|
sendAndRecord(session, { type: "done", code: 1 });
|
|
1794
1857
|
send({ type: "toast", level: "error", message: "Session blocked — context too large for available memory.", duration: 7000 });
|
|
@@ -2528,5 +2591,5 @@ function getActiveLiveCount() {
|
|
|
2528
2591
|
return _activeLiveCount;
|
|
2529
2592
|
}
|
|
2530
2593
|
|
|
2531
|
-
module.exports = { createSDKBridge, createMessageQueue, readMemAvailableMB, readCgroupHeadroomMB, DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount, getActivityDivergenceStats, buildActivityDiagnosticsResponse };
|
|
2594
|
+
module.exports = { createSDKBridge, createMessageQueue, readMemAvailableMB, readCgroupHeadroomMB, resolveMemAvailableThresholdMB, computeCgroupBlockCauseMessage, DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount, getActivityDivergenceStats, buildActivityDiagnosticsResponse };
|
|
2532
2595
|
|
package/lib/server-dm.js
CHANGED
|
@@ -15,8 +15,8 @@ function attachDm(ctx) {
|
|
|
15
15
|
var pushModule = ctx.pushModule;
|
|
16
16
|
|
|
17
17
|
function handleMessage(ws, msg) {
|
|
18
|
-
if (!ws.
|
|
19
|
-
var userId = ws.
|
|
18
|
+
if (!ws._clagenticUser) return false;
|
|
19
|
+
var userId = ws._clagenticUser.id;
|
|
20
20
|
|
|
21
21
|
if (msg.type === "dm_list") {
|
|
22
22
|
var dmList = dm.getDmList(userId);
|
|
@@ -76,7 +76,7 @@ function attachDm(ctx) {
|
|
|
76
76
|
projects.forEach(function (ctx) {
|
|
77
77
|
ctx.forEachClient(function (otherWs) {
|
|
78
78
|
if (otherWs === ws) return;
|
|
79
|
-
if (!otherWs.
|
|
79
|
+
if (!otherWs._clagenticUser || otherWs._clagenticUser.id !== targetId) return;
|
|
80
80
|
if (otherWs.readyState !== 1) return;
|
|
81
81
|
otherWs.send(JSON.stringify({ type: "dm_typing", dmKey: dmKey, userId: userId, typing: !!msg.typing }));
|
|
82
82
|
});
|
|
@@ -101,13 +101,13 @@ function attachDm(ctx) {
|
|
|
101
101
|
projects.forEach(function (ctx) {
|
|
102
102
|
ctx.forEachClient(function (otherWs) {
|
|
103
103
|
if (otherWs === ws) return;
|
|
104
|
-
if (!otherWs.
|
|
104
|
+
if (!otherWs._clagenticUser || otherWs._clagenticUser.id !== targetId) return;
|
|
105
105
|
if (otherWs.readyState !== 1) return;
|
|
106
106
|
otherWs.send(JSON.stringify({ type: "dm_message", dmKey: msg.dmKey, message: message }));
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
// Send push notification to target user
|
|
110
|
-
var senderName = ws.
|
|
110
|
+
var senderName = ws._clagenticUser ? (ws._clagenticUser.displayName || ws._clagenticUser.username || "Someone") : "Someone";
|
|
111
111
|
var preview = (msg.text || "").substring(0, 140);
|
|
112
112
|
if (pushModule && pushModule.sendPushToUser) {
|
|
113
113
|
pushModule.sendPushToUser(targetId, {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// see. Fails CLOSED: no userId (or no onGetProjectAccess) means no sessions
|
|
13
13
|
// are returned. There is no legitimate no-auth caller of this function --
|
|
14
14
|
// the WS upgrade handler in lib/server.js rejects any connection without an
|
|
15
|
-
// authenticated user with 401 before ws.
|
|
15
|
+
// authenticated user with 401 before ws._clagenticUser can ever be set, including
|
|
16
16
|
// in single-user/PIN mode (still a real authenticated user, just one
|
|
17
17
|
// account) -- so failing closed here never breaks a real deployment mode.
|
|
18
18
|
//
|