@clagentic/console 1.6.0-beta.4 → 1.7.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/bin/cli.js +20 -102
- package/deploy/clagentic-console.service +10 -1
- package/lib/agents-favorites.js +0 -1
- package/lib/agents.js +0 -10
- package/lib/cli-sessions.js +0 -12
- package/lib/codex-defaults.js +4 -1
- package/lib/config.js +0 -8
- package/lib/daemon.js +88 -9
- package/lib/dm.js +0 -1
- package/lib/ipc.js +129 -59
- package/lib/loop-handoff.js +5 -1
- package/lib/memory-limits.js +214 -36
- package/lib/memory-shed.js +207 -0
- package/lib/notes.js +0 -20
- package/lib/os-users.js +0 -3
- package/lib/project-connection.js +31 -5
- package/lib/project-external-trigger.js +2 -1
- package/lib/project-filesystem.js +18 -11
- package/lib/project-knowledge.js +0 -8
- package/lib/project-loop.js +162 -9
- package/lib/project-sessions.js +87 -21
- package/lib/project-user-mention.js +2 -1
- package/lib/project-user-message.js +16 -5
- package/lib/project.js +14 -25
- package/lib/public/app.js +1 -2
- package/lib/public/css/channel-layout.css +25 -158
- package/lib/public/css/diagnostics.css +17 -1
- package/lib/public/css/icon-strip.css +1 -32
- package/lib/public/css/input.css +0 -56
- package/lib/public/css/loop.css +94 -0
- package/lib/public/css/messages.css +23 -4
- package/lib/public/css/mobile-nav.css +0 -124
- package/lib/public/index.html +11 -11
- package/lib/public/modules/app-connection.js +2 -1
- package/lib/public/modules/app-favicon.js +1 -1
- package/lib/public/modules/app-loop-ui.js +140 -4
- package/lib/public/modules/app-messages.js +17 -11
- package/lib/public/modules/app-projects.js +1 -1
- package/lib/public/modules/custom-icons.js +15 -1
- package/lib/public/modules/dom-refs.js +1 -2
- package/lib/public/modules/emoji-picker.js +6 -1
- package/lib/public/modules/filebrowser.js +33 -9
- package/lib/public/modules/input.js +39 -0
- package/lib/public/modules/scheduler.js +20 -6
- package/lib/public/modules/sidebar-mobile.js +0 -64
- package/lib/public/modules/sidebar-projects.js +90 -25
- package/lib/public/modules/sidebar-sessions.js +80 -13
- package/lib/public/modules/stt.js +2 -6
- package/lib/public/modules/tool-palette.js +0 -1
- package/lib/public/modules/tools.js +2 -6
- package/lib/public/style.css +0 -1
- package/lib/scheduler.js +0 -1
- package/lib/sdk-bridge.js +126 -194
- package/lib/sdk-message-processor.js +24 -9
- package/lib/sdk-permission-ownership.js +51 -0
- package/lib/server-auth.js +25 -18
- package/lib/server-dm.js +1 -1
- package/lib/server-skills.js +9 -1
- package/lib/server.js +18 -3
- package/lib/session-search.js +4 -299
- package/lib/sessions.js +467 -82
- package/lib/smtp.js +0 -15
- package/lib/user-presence.js +0 -12
- package/lib/users-preferences.js +2 -2
- package/lib/users.js +0 -5
- package/lib/utils.js +56 -0
- package/lib/ws-schema.js +3 -14
- package/lib/yoke/adapters/codex.js +96 -10
- package/lib/yoke/codex-local-image.js +79 -0
- package/package.json +1 -1
- package/scripts/postinstall.js +16 -11
- package/lib/ask-user-mcp-server.js +0 -121
- package/lib/project-memory.js +0 -39
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/debate.css +0 -1610
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-dark.svg +0 -32
- package/lib/public/favicon.svg +0 -32
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icons/email/gmail.svg +0 -7
- package/lib/public/icons/email/outlook.svg +0 -35
- package/lib/public/icons/email/yahoo.svg +0 -1
- package/lib/public/modules/events.js +0 -21
- package/lib/public/modules/state.js +0 -3
- package/lib/sdk-worker.js +0 -730
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// memory-shed.js — in-process memory shedding response to a MemoryHigh
|
|
2
|
+
// watermark crossing (lr-5e70).
|
|
3
|
+
//
|
|
4
|
+
// lib/memory-limits.js's startMemoryHighWatcher detects a MemoryHigh
|
|
5
|
+
// crossing and fires an onCrossing callback, but on its own performs no
|
|
6
|
+
// in-process mitigation — the drain controller (lr-6b30) uses that same
|
|
7
|
+
// callback to start refusing new connections and eventually exit, which is
|
|
8
|
+
// the "make the daemon go away" response. This module is the other half:
|
|
9
|
+
// an immediate, in-process attempt to actually reduce RSS before drain's
|
|
10
|
+
// slower shutdown path completes, using machinery that already exists:
|
|
11
|
+
// - retrimHistory() (lr-2ea2a7): re-applies the bounded in-heap history
|
|
12
|
+
// tail cap to every loaded session, including the active/isProcessing
|
|
13
|
+
// ones that are normally exempt from history trimming pressure.
|
|
14
|
+
// - forceEvictToLimit() (lr-5e70, lib/sessions.js): drives the per-project
|
|
15
|
+
// LRU-loaded-session count down to a pressure limit, well below the
|
|
16
|
+
// normal LRU_HISTORY_LIMIT, evicting more aggressively than the routine
|
|
17
|
+
// one-at-a-time post-load check.
|
|
18
|
+
// - rebuildable caches: process-lifetime caches that exist purely as an
|
|
19
|
+
// optimization and are safe to drop, because whatever reads them next
|
|
20
|
+
// lazily rebuilds from source. Currently: lib/server-skills.js's
|
|
21
|
+
// skillsCache (parsed skills.sh proxy responses, TTL-cached; a dropped
|
|
22
|
+
// entry just re-fetches on next request).
|
|
23
|
+
//
|
|
24
|
+
// Design constraints:
|
|
25
|
+
// - Never touches the actively-viewed session's history (retrimHistory
|
|
26
|
+
// only trims down to the normal cap, never below it, and forceEvict
|
|
27
|
+
// always skips a project's activeSessionId — same invariant every other
|
|
28
|
+
// LRU/eviction path in this codebase already honors).
|
|
29
|
+
// - Rate-limited to at most one shedding pass per RATE_LIMIT_MS: the
|
|
30
|
+
// watermark watcher can re-fire on RSS hysteresis (strategy B), and a
|
|
31
|
+
// shedding pass that is mostly I/O (disk reads for cache repopulation)
|
|
32
|
+
// should not be allowed to run back-to-back.
|
|
33
|
+
// - Never throws — a shedding pass must not itself crash the process that
|
|
34
|
+
// is already under memory pressure.
|
|
35
|
+
|
|
36
|
+
'use strict';
|
|
37
|
+
|
|
38
|
+
// Minimum interval between shedding passes (ms). A crossing that arrives
|
|
39
|
+
// inside this window returns immediately with skipped=true rather than
|
|
40
|
+
// running a second pass.
|
|
41
|
+
var RATE_LIMIT_MS = 60 * 1000;
|
|
42
|
+
|
|
43
|
+
// Pressure-limit fraction applied to each project's normal LRU_HISTORY_LIMIT
|
|
44
|
+
// when forceEvictToLimit is driven under memory pressure — half the normal
|
|
45
|
+
// loaded-session ceiling, per the lr-5e70 spec.
|
|
46
|
+
var PRESSURE_LRU_FRACTION = 0.5;
|
|
47
|
+
|
|
48
|
+
var _lastShedAt = 0;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Reset the internal rate-limit clock. Test-only — production code has no
|
|
52
|
+
* legitimate reason to force a second pass inside the rate-limit window.
|
|
53
|
+
* Set far enough in the past (not 0) so a caller-supplied `nowMs` override
|
|
54
|
+
* near the Unix epoch (e.g. small test fixture values like 1000) is still
|
|
55
|
+
* treated as outside the rate-limit window relative to this reset point.
|
|
56
|
+
*/
|
|
57
|
+
function _resetRateLimitForTest() {
|
|
58
|
+
_lastShedAt = -Infinity;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Run one memory-shedding pass across every loaded project.
|
|
63
|
+
*
|
|
64
|
+
* @param {object} opts
|
|
65
|
+
* @param {Array<{slug: string, sm: object, send?: function(object): void}>} opts.projects
|
|
66
|
+
* Live project contexts to shed from. Each `sm` is a session manager
|
|
67
|
+
* instance (lib/sessions.js createSessionManager return value). `send`,
|
|
68
|
+
* when provided, is used to broadcast the memory_shed diagnostic to that
|
|
69
|
+
* project's connected clients (lib/project.js's ctx.send — session-
|
|
70
|
+
* independent, matches the existing settings-preflight diagnostic path).
|
|
71
|
+
* @param {object} [opts.caches]
|
|
72
|
+
* Rebuildable caches to drop, keyed by name -> { drop: function(): void }.
|
|
73
|
+
* Each drop() is called inside a try/catch; failures are swallowed and
|
|
74
|
+
* that cache is omitted from cachesDropped.
|
|
75
|
+
* @param {function(object): void} [opts.log]
|
|
76
|
+
* Structured log emitter. Defaults to a JSON line on stderr.
|
|
77
|
+
* @param {number} [opts.nowMs] — override for testing (default Date.now()).
|
|
78
|
+
* @param {number} [opts.rssBefore] — override for testing (default
|
|
79
|
+
* process.memoryUsage().rss).
|
|
80
|
+
* @param {function(): number} [opts.readRssBytes] — override for testing;
|
|
81
|
+
* called once before and once after shedding to compute the before/after
|
|
82
|
+
* RSS delta reported in the log and diagnostic.
|
|
83
|
+
* @returns {{
|
|
84
|
+
* skipped: boolean,
|
|
85
|
+
* reason?: string,
|
|
86
|
+
* beforeBytes?: number,
|
|
87
|
+
* afterBytes?: number,
|
|
88
|
+
* sessionsTrimmed?: number,
|
|
89
|
+
* sessionsEvicted?: number,
|
|
90
|
+
* cachesDropped?: string[]
|
|
91
|
+
* }}
|
|
92
|
+
*/
|
|
93
|
+
function shedMemory(opts) {
|
|
94
|
+
var o = opts || {};
|
|
95
|
+
var projects = Array.isArray(o.projects) ? o.projects : [];
|
|
96
|
+
var caches = o.caches || {};
|
|
97
|
+
var _log = typeof o.log === 'function' ? o.log : function (event) {
|
|
98
|
+
try { process.stderr.write('[memory-shed] ' + JSON.stringify(event) + '\n'); } catch (_) {}
|
|
99
|
+
};
|
|
100
|
+
var readRss = typeof o.readRssBytes === 'function'
|
|
101
|
+
? o.readRssBytes
|
|
102
|
+
: function () { return process.memoryUsage().rss; };
|
|
103
|
+
var now = typeof o.nowMs === 'number' ? o.nowMs : Date.now();
|
|
104
|
+
|
|
105
|
+
if (now - _lastShedAt < RATE_LIMIT_MS) {
|
|
106
|
+
return { skipped: true, reason: 'rate_limited' };
|
|
107
|
+
}
|
|
108
|
+
_lastShedAt = now;
|
|
109
|
+
|
|
110
|
+
var beforeBytes = typeof o.rssBefore === 'number' ? o.rssBefore : readRss();
|
|
111
|
+
|
|
112
|
+
var sessionsTrimmed = 0;
|
|
113
|
+
var sessionsEvicted = 0;
|
|
114
|
+
|
|
115
|
+
for (var pi = 0; pi < projects.length; pi++) {
|
|
116
|
+
var proj = projects[pi];
|
|
117
|
+
if (!proj || !proj.sm) continue;
|
|
118
|
+
var sm = proj.sm;
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
// 1. retrimHistory on every loaded session, including active/processing.
|
|
122
|
+
// retrimHistory() is idempotent and a no-op when a session is already
|
|
123
|
+
// within HISTORY_INMEM_MAX, so calling it unconditionally here is safe
|
|
124
|
+
// and cheap even for sessions that never grew past the cap.
|
|
125
|
+
sm.sessions.forEach(function (session) {
|
|
126
|
+
if (!session._historyLoaded) return;
|
|
127
|
+
var beforeLen = session.history.length;
|
|
128
|
+
sm.retrimHistory(session);
|
|
129
|
+
if (session.history.length < beforeLen) sessionsTrimmed++;
|
|
130
|
+
});
|
|
131
|
+
} catch (e) {
|
|
132
|
+
// A single project's shedding step must not abort the whole pass.
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
// 2. Force-evict beyond the normal LRU limit down to a pressure limit,
|
|
137
|
+
// still skipping the active session (forceEvictToLimit's own
|
|
138
|
+
// invariant, shared with the routine LRU path).
|
|
139
|
+
if (typeof sm.forceEvictToLimit === 'function' && typeof sm.LRU_HISTORY_LIMIT === 'number') {
|
|
140
|
+
var pressureLimit = Math.max(1, Math.floor(sm.LRU_HISTORY_LIMIT * PRESSURE_LRU_FRACTION));
|
|
141
|
+
sessionsEvicted += sm.forceEvictToLimit(pressureLimit);
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
// Same isolation as above — one project's failure does not block others.
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 3. Drop rebuildable caches.
|
|
149
|
+
var cachesDropped = [];
|
|
150
|
+
var cacheNames = Object.keys(caches);
|
|
151
|
+
for (var ci = 0; ci < cacheNames.length; ci++) {
|
|
152
|
+
var name = cacheNames[ci];
|
|
153
|
+
var entry = caches[name];
|
|
154
|
+
if (!entry || typeof entry.drop !== 'function') continue;
|
|
155
|
+
try {
|
|
156
|
+
entry.drop();
|
|
157
|
+
cachesDropped.push(name);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
// Skip — a cache that fails to drop is omitted from the report, not fatal.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
var afterBytes = readRss();
|
|
164
|
+
|
|
165
|
+
var summary = {
|
|
166
|
+
skipped: false,
|
|
167
|
+
beforeBytes: beforeBytes,
|
|
168
|
+
afterBytes: afterBytes,
|
|
169
|
+
sessionsTrimmed: sessionsTrimmed,
|
|
170
|
+
sessionsEvicted: sessionsEvicted,
|
|
171
|
+
cachesDropped: cachesDropped,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
_log(Object.assign({
|
|
175
|
+
event: 'memory_shed',
|
|
176
|
+
timestamp: new Date(now).toISOString(),
|
|
177
|
+
}, summary));
|
|
178
|
+
|
|
179
|
+
// 4. UI diagnostic — session-independent, project-scoped broadcast (same
|
|
180
|
+
// delivery path as settings-preflight's diagnostics: plain send(), not
|
|
181
|
+
// sendAndRecord, since this has no session to attach to and is ephemeral).
|
|
182
|
+
var deltaBytes = beforeBytes - afterBytes;
|
|
183
|
+
var diagnostic = {
|
|
184
|
+
type: 'diagnostic',
|
|
185
|
+
severity: 'warning',
|
|
186
|
+
source: 'memory',
|
|
187
|
+
message: 'Memory pressure detected — shed ' + sessionsTrimmed + ' session history tail(s), evicted '
|
|
188
|
+
+ sessionsEvicted + ' loaded session(s), dropped ' + cachesDropped.length + ' cache(s). '
|
|
189
|
+
+ 'RSS ' + Math.round(beforeBytes / 1048576) + 'MB -> ' + Math.round(afterBytes / 1048576) + 'MB'
|
|
190
|
+
+ (deltaBytes > 0 ? ' (-' + Math.round(deltaBytes / 1048576) + 'MB)' : ''),
|
|
191
|
+
};
|
|
192
|
+
for (var si = 0; si < projects.length; si++) {
|
|
193
|
+
var p = projects[si];
|
|
194
|
+
if (p && typeof p.send === 'function') {
|
|
195
|
+
try { p.send(diagnostic); } catch (e) { /* one client's send failure must not block others */ }
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return summary;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
module.exports = {
|
|
203
|
+
shedMemory: shedMemory,
|
|
204
|
+
RATE_LIMIT_MS: RATE_LIMIT_MS,
|
|
205
|
+
PRESSURE_LRU_FRACTION: PRESSURE_LRU_FRACTION,
|
|
206
|
+
_resetRateLimitForTest: _resetRateLimitForTest,
|
|
207
|
+
};
|
package/lib/notes.js
CHANGED
|
@@ -109,32 +109,12 @@ function createNotesManager(opts) {
|
|
|
109
109
|
return update(id, { zIndex: maxZ + 1 });
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
/**
|
|
113
|
-
* Return formatted text of all active (non-hidden) notes.
|
|
114
|
-
* Used to inject into mate CLAUDE.md so the mate can read them.
|
|
115
|
-
*/
|
|
116
|
-
function getActiveNotesText() {
|
|
117
|
-
var active = [];
|
|
118
|
-
for (var i = 0; i < notes.length; i++) {
|
|
119
|
-
if (!notes[i].hidden && notes[i].text) active.push(notes[i]);
|
|
120
|
-
}
|
|
121
|
-
if (active.length === 0) return "";
|
|
122
|
-
var lines = [];
|
|
123
|
-
for (var j = 0; j < active.length; j++) {
|
|
124
|
-
var n = active[j];
|
|
125
|
-
var label = n.color ? "[" + n.color + "]" : "";
|
|
126
|
-
lines.push("- " + label + " " + n.text.trim());
|
|
127
|
-
}
|
|
128
|
-
return lines.join("\n");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
112
|
return {
|
|
132
113
|
list: list,
|
|
133
114
|
create: create,
|
|
134
115
|
update: update,
|
|
135
116
|
remove: remove,
|
|
136
117
|
bringToFront: bringToFront,
|
|
137
|
-
getActiveNotesText: getActiveNotesText,
|
|
138
118
|
};
|
|
139
119
|
}
|
|
140
120
|
|
package/lib/os-users.js
CHANGED
|
@@ -519,17 +519,14 @@ module.exports = {
|
|
|
519
519
|
fsAsUser: fsAsUser,
|
|
520
520
|
grantProjectAccess: grantProjectAccess,
|
|
521
521
|
revokeProjectAccess: revokeProjectAccess,
|
|
522
|
-
toLinuxUsername: toLinuxUsername,
|
|
523
522
|
linuxUserExists: linuxUserExists,
|
|
524
523
|
provisionLinuxUser: provisionLinuxUser,
|
|
525
524
|
provisionAllUsers: provisionAllUsers,
|
|
526
525
|
grantAllUsersAccess: grantAllUsersAccess,
|
|
527
|
-
installClaudeCli: installClaudeCli,
|
|
528
526
|
deactivateLinuxUser: deactivateLinuxUser,
|
|
529
527
|
ensureProjectsDir: ensureProjectsDir,
|
|
530
528
|
isHomeDirectory: isHomeDirectory,
|
|
531
529
|
getLinuxUserHome: getLinuxUserHome,
|
|
532
530
|
getLinuxUserUid: getLinuxUserUid,
|
|
533
|
-
isSafeLinuxUsername: isSafeLinuxUsername,
|
|
534
531
|
};
|
|
535
532
|
|
|
@@ -180,17 +180,31 @@ function attachConnection(ctx) {
|
|
|
180
180
|
autoCreated = true;
|
|
181
181
|
}
|
|
182
182
|
if (active && !autoCreated) {
|
|
183
|
-
if (!active.ownerId && wsUser) {
|
|
184
|
-
active.ownerId = wsUser.id;
|
|
185
|
-
sm.saveSessionFile(active);
|
|
186
|
-
}
|
|
187
183
|
ws._clayActiveSession = active.localId;
|
|
188
184
|
var _vendorCaps = (sm.capabilitiesByVendor && sm.capabilitiesByVendor[active.vendor || sm.defaultVendor || "claude"]) || {};
|
|
189
185
|
// Load history from disk before checking hasHistory — the session may have
|
|
190
186
|
// been evicted from the LRU cache (lr-f311 lazy load), in which case
|
|
191
187
|
// active.history is [] in memory even though the session file has content.
|
|
188
|
+
//
|
|
189
|
+
// This must run before the ownership-claim save below (lr-768c9e): if an
|
|
190
|
+
// unowned session was evicted, active.history is [] in memory. Claiming
|
|
191
|
+
// ownership and calling saveSessionFile() first would serialize that
|
|
192
|
+
// empty array and truncate the on-disk history. Loading history first
|
|
193
|
+
// guarantees saveSessionFile() has the full in-memory history to persist.
|
|
192
194
|
sm.loadSessionHistory(active);
|
|
193
|
-
|
|
195
|
+
if (!active.ownerId && wsUser) {
|
|
196
|
+
active.ownerId = wsUser.id;
|
|
197
|
+
sm.saveSessionFile(active);
|
|
198
|
+
}
|
|
199
|
+
// lr-2ea2a7: hasHistory uses the ABSOLUTE count (_historyBaseIndex +
|
|
200
|
+
// heap length), not the raw heap length — with a bounded tail-loaded
|
|
201
|
+
// session the heap length alone is still correct here (a session with
|
|
202
|
+
// ANY persisted history always has a non-empty tail once loaded), but
|
|
203
|
+
// the absolute form is the more defensible invariant to depend on and
|
|
204
|
+
// matches how every other index/count in the wire contract is derived
|
|
205
|
+
// post-lr-2ea2a7.
|
|
206
|
+
var _hasHistory = ((active._historyBaseIndex || 0) + active.history.length) > 0;
|
|
207
|
+
sendTo(ws, { type: "session_switched", id: active.localId, cliSessionId: active.cliSessionId || null, loop: active.loop || null, vendor: active.vendor || null, hasHistory: _hasHistory, capabilities: _vendorCaps, agentName: active.agentName || null });
|
|
194
208
|
// Send per-session context sources
|
|
195
209
|
var sessionSources = loadContextSources(slug, active.localId);
|
|
196
210
|
sendTo(ws, { type: "context_sources_state", active: sessionSources });
|
|
@@ -248,6 +262,18 @@ function attachConnection(ctx) {
|
|
|
248
262
|
ws.on("close", function () {
|
|
249
263
|
handleDisconnection(ws);
|
|
250
264
|
});
|
|
265
|
+
|
|
266
|
+
// Per-client socket faults (e.g. ECONNRESET when a phone/browser drops
|
|
267
|
+
// WiFi mid-connection) emit 'error' on the ws instance. Without a
|
|
268
|
+
// listener, EventEmitter re-throws, which reaches the daemon's
|
|
269
|
+
// uncaughtException handler and tears down every project/session
|
|
270
|
+
// (gracefulShutdown) for a single client's network blip. Log and drop
|
|
271
|
+
// only this socket; 'close' still fires afterward and runs the normal
|
|
272
|
+
// handleDisconnection cleanup.
|
|
273
|
+
ws.on("error", function (err) {
|
|
274
|
+
console.error("[project-connection] client socket error for " + slug + ":", err && err.message ? err.message : err);
|
|
275
|
+
try { ws.terminate(); } catch (e) {}
|
|
276
|
+
});
|
|
251
277
|
}
|
|
252
278
|
|
|
253
279
|
function handleDisconnection(ws) {
|
|
@@ -105,7 +105,8 @@ function attachExternalTrigger(ctx) {
|
|
|
105
105
|
sm.broadcastSessionList();
|
|
106
106
|
|
|
107
107
|
var userMsg = { type: "user_message", text: trigger.initialPrompt };
|
|
108
|
-
|
|
108
|
+
// lr-2ea2a7: routes through the shared history-cap helper (see grep-guard test).
|
|
109
|
+
sm.recordHistoryEntry(sess, userMsg, true);
|
|
109
110
|
sm.appendToSessionFile(sess, userMsg);
|
|
110
111
|
|
|
111
112
|
sess.isProcessing = true;
|
|
@@ -345,14 +345,21 @@ function attachFilesystem(ctx) {
|
|
|
345
345
|
var absHistPath = path.resolve(cwd, histPath);
|
|
346
346
|
var entries = [];
|
|
347
347
|
|
|
348
|
-
// Collect session edits
|
|
348
|
+
// Collect session edits.
|
|
349
|
+
// lr-2ea2a7: reads full history via a streaming disk scan
|
|
350
|
+
// (sm.readSessionHistoryFromDisk) instead of session.history — the
|
|
351
|
+
// heap array is now a bounded tail window and would silently miss
|
|
352
|
+
// edits older than the trim point for a long-running session. The
|
|
353
|
+
// disk read does not call loadSessionHistory() and does not mutate
|
|
354
|
+
// session.history/_historyLoaded/LRU state.
|
|
349
355
|
sm.sessions.forEach(function (session) {
|
|
350
356
|
var sessionLocalId = session.localId;
|
|
351
357
|
var sessionTitle = session.title || "Untitled";
|
|
352
|
-
var
|
|
358
|
+
var history = sm.readSessionHistoryFromDisk(session);
|
|
359
|
+
var histLen = history.length || 1;
|
|
353
360
|
|
|
354
|
-
for (var hi = 0; hi <
|
|
355
|
-
var entry =
|
|
361
|
+
for (var hi = 0; hi < history.length; hi++) {
|
|
362
|
+
var entry = history[hi];
|
|
356
363
|
if (entry.type !== "tool_executing") continue;
|
|
357
364
|
if (entry.name !== "Edit" && entry.name !== "Write") continue;
|
|
358
365
|
if (!entry.input || !entry.input.file_path) continue;
|
|
@@ -362,8 +369,8 @@ function attachFilesystem(ctx) {
|
|
|
362
369
|
var assistantUuid = null;
|
|
363
370
|
var uuidIndex = -1;
|
|
364
371
|
for (var hj = hi - 1; hj >= 0; hj--) {
|
|
365
|
-
if (
|
|
366
|
-
assistantUuid =
|
|
372
|
+
if (history[hj].type === "message_uuid" && history[hj].messageType === "assistant") {
|
|
373
|
+
assistantUuid = history[hj].uuid;
|
|
367
374
|
uuidIndex = hj;
|
|
368
375
|
break;
|
|
369
376
|
}
|
|
@@ -373,8 +380,8 @@ function attachFilesystem(ctx) {
|
|
|
373
380
|
var messageSnippet = "";
|
|
374
381
|
var searchFrom = uuidIndex >= 0 ? uuidIndex : hi;
|
|
375
382
|
for (var hk = searchFrom - 1; hk >= 0; hk--) {
|
|
376
|
-
if (
|
|
377
|
-
messageSnippet =
|
|
383
|
+
if (history[hk].type === "user_message" && history[hk].text) {
|
|
384
|
+
messageSnippet = history[hk].text.trim().substring(0, 100);
|
|
378
385
|
break;
|
|
379
386
|
}
|
|
380
387
|
}
|
|
@@ -387,7 +394,7 @@ function attachFilesystem(ctx) {
|
|
|
387
394
|
var assistantSnippet = "";
|
|
388
395
|
var deltaChunks = [];
|
|
389
396
|
for (var hd = hi - 1; hd >= 0; hd--) {
|
|
390
|
-
var hEntry =
|
|
397
|
+
var hEntry = history[hd];
|
|
391
398
|
if (hEntry.type === "tool_start") continue;
|
|
392
399
|
if (hEntry.type === "delta" && hEntry.text) {
|
|
393
400
|
deltaChunks.unshift(hEntry.text);
|
|
@@ -399,13 +406,13 @@ function attachFilesystem(ctx) {
|
|
|
399
406
|
// No delta immediately before; scan past tool blocks
|
|
400
407
|
// to find the nearest preceding delta in the same turn
|
|
401
408
|
for (var hd2 = hi - 1; hd2 >= 0; hd2--) {
|
|
402
|
-
var hEntry2 =
|
|
409
|
+
var hEntry2 = history[hd2];
|
|
403
410
|
if (hEntry2.type === "tool_start" || hEntry2.type === "tool_executing" || hEntry2.type === "tool_result") continue;
|
|
404
411
|
if (hEntry2.type === "delta" && hEntry2.text) {
|
|
405
412
|
// Found a delta before an earlier tool in the same turn.
|
|
406
413
|
// Collect this contiguous block of deltas.
|
|
407
414
|
for (var hd3 = hd2; hd3 >= 0; hd3--) {
|
|
408
|
-
var hEntry3 =
|
|
415
|
+
var hEntry3 = history[hd3];
|
|
409
416
|
if (hEntry3.type === "tool_start") continue;
|
|
410
417
|
if (hEntry3.type === "delta" && hEntry3.text) {
|
|
411
418
|
deltaChunks.unshift(hEntry3.text);
|
package/lib/project-knowledge.js
CHANGED
|
@@ -4,9 +4,6 @@ var path = require("path");
|
|
|
4
4
|
/**
|
|
5
5
|
* Attach knowledge file management to a project context.
|
|
6
6
|
* ctx fields: cwd, sendTo
|
|
7
|
-
*
|
|
8
|
-
* Note: knowledge_promote and knowledge_depromote were mate-only features (lr-316f).
|
|
9
|
-
* Those message types are kept as no-ops for safe handling.
|
|
10
7
|
*/
|
|
11
8
|
function attachKnowledge(ctx) {
|
|
12
9
|
var cwd = ctx.cwd;
|
|
@@ -72,11 +69,6 @@ function attachKnowledge(ctx) {
|
|
|
72
69
|
return true;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
// knowledge_promote and knowledge_depromote are no-op stubs (mate-only feature, lr-316f)
|
|
76
|
-
if (msg.type === "knowledge_promote" || msg.type === "knowledge_depromote") {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
72
|
return false;
|
|
81
73
|
}
|
|
82
74
|
|