@clagentic/console 1.2.0 → 1.2.1-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/lib/project-filesystem.js +9 -0
- package/lib/project.js +19 -1
- package/lib/public/modules/app-messages.js +22 -16
- package/lib/public/modules/app-rendering.js +13 -3
- package/lib/sessions.js +30 -6
- package/package.json +1 -1
|
@@ -26,6 +26,7 @@ function attachFilesystem(ctx) {
|
|
|
26
26
|
var sendTo = ctx.sendTo;
|
|
27
27
|
var safePath = ctx.safePath;
|
|
28
28
|
var safeAbsPath = ctx.safeAbsPath;
|
|
29
|
+
var safeClaudePath = ctx.safeClaudePath;
|
|
29
30
|
var getOsUserInfoForWs = ctx.getOsUserInfoForWs;
|
|
30
31
|
var startFileWatch = ctx.startFileWatch;
|
|
31
32
|
var stopFileWatch = ctx.stopFileWatch;
|
|
@@ -58,6 +59,10 @@ function attachFilesystem(ctx) {
|
|
|
58
59
|
if (!fsDir && getOsUserInfoForWs(ws)) {
|
|
59
60
|
fsDir = safeAbsPath(msg.path);
|
|
60
61
|
}
|
|
62
|
+
// Allow read-only access to paths within ~/.claude/ (e.g. plans/)
|
|
63
|
+
if (!fsDir && safeClaudePath) {
|
|
64
|
+
fsDir = safeClaudePath(msg.path);
|
|
65
|
+
}
|
|
61
66
|
if (!fsDir) {
|
|
62
67
|
sendTo(ws, { type: "fs_list_result", path: msg.path, entries: [], error: "Access denied" });
|
|
63
68
|
return true;
|
|
@@ -150,6 +155,10 @@ function attachFilesystem(ctx) {
|
|
|
150
155
|
if (!fsFile && getOsUserInfoForWs(ws)) {
|
|
151
156
|
fsFile = safeAbsPath(msg.path);
|
|
152
157
|
}
|
|
158
|
+
// Allow read-only access to paths within ~/.claude/ (e.g. plans/)
|
|
159
|
+
if (!fsFile && safeClaudePath) {
|
|
160
|
+
fsFile = safeClaudePath(msg.path);
|
|
161
|
+
}
|
|
153
162
|
if (!fsFile) {
|
|
154
163
|
sendTo(ws, { type: "fs_read_result", path: msg.path, error: "Access denied" });
|
|
155
164
|
return true;
|
package/lib/project.js
CHANGED
|
@@ -121,6 +121,23 @@ function safeAbsPath(requested) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
// Resolve an absolute path within the Claude Code data directory (~/.claude/).
|
|
125
|
+
// Used as read-only fallback so plan files and other Claude-owned paths that live
|
|
126
|
+
// outside the project cwd (e.g. ~/.claude/plans/) can be previewed in the file viewer.
|
|
127
|
+
function safeClaudePath(requested) {
|
|
128
|
+
if (!requested) return null;
|
|
129
|
+
var claudeDir = path.join(require("./config").REAL_HOME, ".claude");
|
|
130
|
+
var resolved = path.resolve(requested);
|
|
131
|
+
if (resolved !== claudeDir && !resolved.startsWith(claudeDir + path.sep)) return null;
|
|
132
|
+
try {
|
|
133
|
+
var real = fs.realpathSync(resolved);
|
|
134
|
+
if (real !== claudeDir && !real.startsWith(claudeDir + path.sep)) return null;
|
|
135
|
+
return real;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
124
141
|
/**
|
|
125
142
|
* Create a project context — per-project state and handlers.
|
|
126
143
|
* opts: { cwd, slug, title, pushModule, debug, dangerouslySkipPermissions, currentVersion }
|
|
@@ -969,6 +986,7 @@ function createProjectContext(opts) {
|
|
|
969
986
|
sendTo: sendTo,
|
|
970
987
|
safePath: safePath,
|
|
971
988
|
safeAbsPath: safeAbsPath,
|
|
989
|
+
safeClaudePath: safeClaudePath,
|
|
972
990
|
getOsUserInfoForWs: getOsUserInfoForWs,
|
|
973
991
|
startFileWatch: startFileWatch,
|
|
974
992
|
stopFileWatch: stopFileWatch,
|
|
@@ -1324,5 +1342,5 @@ function createProjectContext(opts) {
|
|
|
1324
1342
|
};
|
|
1325
1343
|
}
|
|
1326
1344
|
|
|
1327
|
-
module.exports = { createProjectContext: createProjectContext, safePath: safePath, validateEnvString: validateEnvString };
|
|
1345
|
+
module.exports = { createProjectContext: createProjectContext, safePath: safePath, safeClaudePath: safeClaudePath, validateEnvString: validateEnvString };
|
|
1328
1346
|
|
|
@@ -8,7 +8,7 @@ import { getWs } from './ws-ref.js';
|
|
|
8
8
|
// --- Leaf module imports ---
|
|
9
9
|
import { showToast } from './utils.js';
|
|
10
10
|
import { refreshIcons, iconHtml } from './icons.js';
|
|
11
|
-
import { renderMarkdown, highlightCodeBlocks, renderMermaidBlocks } from './markdown.js';
|
|
11
|
+
import { renderMarkdown, highlightCodeBlocks, highlightCodeBlocksBatched, renderMermaidBlocks } from './markdown.js';
|
|
12
12
|
import { updatePageTitle } from './sidebar.js';
|
|
13
13
|
import { renderSessionList, updateSessionPresence, populateCliSessionList, handleSearchResults, updateSessionBadge } from './sidebar-sessions.js';
|
|
14
14
|
import { updateDmBadge, renderSidebarPresence, setMentionActive, renderUserStrip } from './sidebar-users.js';
|
|
@@ -88,29 +88,35 @@ export function processMessage(msg) {
|
|
|
88
88
|
var nav = getPendingNavigate();
|
|
89
89
|
var hasNavTarget = nav && (nav.toolId || nav.assistantUuid);
|
|
90
90
|
if (!hasNavTarget) {
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
//
|
|
91
|
+
// Scale the quiet window with history depth. A 20-item threshold
|
|
92
|
+
// (old code) gave identical 2000ms to sessions with 21 and 1000
|
|
93
|
+
// items. The scaled formula gives fast disarm for small sessions
|
|
94
|
+
// and up to 3000ms for very large ones (≥500 events), without
|
|
95
|
+
// a hard ceiling that cuts off still-settling content on mobile.
|
|
94
96
|
var historyLen = store.get('historyTotal') || 0;
|
|
95
|
-
var quietMs = historyLen
|
|
97
|
+
var quietMs = Math.min(Math.max(500, Math.round(historyLen * 2.5)), 3000);
|
|
96
98
|
armStickyBottom(quietMs, true); // force: history replay must scroll to bottom
|
|
97
99
|
}
|
|
98
100
|
// Batched syntax highlight + mermaid pass for the entire replayed
|
|
99
101
|
// transcript. Per-message highlights are skipped during replay
|
|
100
|
-
// (see markdown.js)
|
|
101
|
-
//
|
|
102
|
+
// (see markdown.js). Uses requestIdleCallback batching to avoid
|
|
103
|
+
// blocking the main thread — the old synchronous highlightCodeBlocks()
|
|
104
|
+
// fired hljs on every code block at once, each triggering a
|
|
105
|
+
// ResizeObserver callback that reset the sticky-bottom quiet timer,
|
|
106
|
+
// keeping the scroll pinned and the UI unresponsive for several
|
|
107
|
+
// seconds on large sessions (especially on mobile). The completion
|
|
108
|
+
// callback re-arms once after all blocks are done.
|
|
102
109
|
if (messagesEl) {
|
|
103
|
-
|
|
104
|
-
renderMermaidBlocks(messagesEl);
|
|
105
|
-
// Re-arm after highlight batch completes — Highlight.js defers work
|
|
106
|
-
// via requestAnimationFrame, so the actual DOM updates may happen
|
|
107
|
-
// after the synchronous call returns. This re-arm catches the deferred
|
|
108
|
-
// work on slow browsers.
|
|
109
|
-
setTimeout(function () {
|
|
110
|
+
highlightCodeBlocksBatched(messagesEl, function () {
|
|
110
111
|
if (!store.get('processing')) {
|
|
111
|
-
armStickyBottom(500, true); // force:
|
|
112
|
+
armStickyBottom(500, true); // force: re-pin after all blocks settle
|
|
112
113
|
}
|
|
113
|
-
}
|
|
114
|
+
});
|
|
115
|
+
renderMermaidBlocks(messagesEl);
|
|
116
|
+
// NOTE: The old 300ms setTimeout re-arm is removed. The batched
|
|
117
|
+
// highlight completion callback above replaces it. The 300ms timer
|
|
118
|
+
// was a workaround for Highlight.js deferred work that no longer
|
|
119
|
+
// applies with the idle-callback batching path.
|
|
114
120
|
}
|
|
115
121
|
// Compact dead-session todo widgets (unfinished items will never
|
|
116
122
|
// resolve — the agent isn't coming back) so they don't anchor
|
|
@@ -423,6 +423,11 @@ export function finalizeAssistantBlock() {
|
|
|
423
423
|
flushStreamBuffer();
|
|
424
424
|
var msgEl = store.get('currentMsgEl');
|
|
425
425
|
var textToRender = currentFullTextLocal;
|
|
426
|
+
// Capture replay state synchronously before any async work — by the time
|
|
427
|
+
// the async callback fires, replayingHistory may have already been cleared
|
|
428
|
+
// by history_done. wasReplaying lets the callback know not to arm
|
|
429
|
+
// sticky-bottom (history_done owns that arm during replay).
|
|
430
|
+
var wasReplaying = store.get('replayingHistory');
|
|
426
431
|
|
|
427
432
|
// Clear state before async work — subsequent messages must not inherit
|
|
428
433
|
// this block's el or text.
|
|
@@ -441,9 +446,14 @@ export function finalizeAssistantBlock() {
|
|
|
441
446
|
contentEl.innerHTML = html;
|
|
442
447
|
highlightCodeBlocks(contentEl);
|
|
443
448
|
renderMermaidBlocks(contentEl);
|
|
444
|
-
//
|
|
445
|
-
//
|
|
446
|
-
|
|
449
|
+
// Only re-arm sticky-bottom for live turns. During replay,
|
|
450
|
+
// history_done owns the sticky-bottom arm. Per-turn arms from
|
|
451
|
+
// replayed finalizeAssistantBlock callbacks keep extending the
|
|
452
|
+
// quiet window after history is done, leaving the user scroll-
|
|
453
|
+
// pinned for several extra seconds on large sessions.
|
|
454
|
+
if (!wasReplaying) {
|
|
455
|
+
armStickyBottom(500);
|
|
456
|
+
}
|
|
447
457
|
}
|
|
448
458
|
}, 0);
|
|
449
459
|
});
|
package/lib/sessions.js
CHANGED
|
@@ -460,11 +460,32 @@ function createSessionManager(opts) {
|
|
|
460
460
|
// scroll-up via the existing pagination path.
|
|
461
461
|
var HISTORY_PAGE_SIZE = 100;
|
|
462
462
|
|
|
463
|
+
// Scan backward from the END of history (hard-capped at HISTORY_PAGE_SIZE) to
|
|
464
|
+
// find the most recent user_message. This ensures the initial replay window
|
|
465
|
+
// always starts at a clean turn boundary rather than mid-stream, regardless of
|
|
466
|
+
// how large the most recent turn is. For a session whose last user_message is
|
|
467
|
+
// at index N near the end, this returns N → typically ~10-100 events replayed
|
|
468
|
+
// instead of thousands.
|
|
469
|
+
function findLastTurnStart(history) {
|
|
470
|
+
var searchFloor = Math.max(0, history.length - HISTORY_PAGE_SIZE);
|
|
471
|
+
for (var i = history.length - 1; i >= searchFloor; i--) {
|
|
472
|
+
if (history[i] && history[i].type === "user_message") return i;
|
|
473
|
+
}
|
|
474
|
+
// No turn boundary found within the window — hard-cap at searchFloor.
|
|
475
|
+
return searchFloor;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Scan backward from targetIndex (capped at HISTORY_PAGE_SIZE below it) to find
|
|
479
|
+
// the nearest user_message turn boundary. Used by load_more_history scroll-up
|
|
480
|
+
// pagination to align the prepended page to a clean turn start. Falls back to
|
|
481
|
+
// targetIndex if no boundary is found within the window — a partial turn at
|
|
482
|
+
// the top is preferable to an unbounded backward scan.
|
|
463
483
|
function findTurnBoundary(history, targetIndex) {
|
|
464
|
-
|
|
484
|
+
var searchFloor = Math.max(0, targetIndex - HISTORY_PAGE_SIZE);
|
|
485
|
+
for (var i = targetIndex; i >= searchFloor; i--) {
|
|
465
486
|
if (history[i] && history[i].type === "user_message") return i;
|
|
466
487
|
}
|
|
467
|
-
return
|
|
488
|
+
return targetIndex;
|
|
468
489
|
}
|
|
469
490
|
|
|
470
491
|
function replayHistory(session, fromIndex, targetWs, transform) {
|
|
@@ -477,7 +498,12 @@ function createSessionManager(opts) {
|
|
|
477
498
|
if (total <= HISTORY_PAGE_SIZE) {
|
|
478
499
|
fromIndex = 0;
|
|
479
500
|
} else {
|
|
480
|
-
|
|
501
|
+
// Start from the most recent complete turn within the PAGE_SIZE window.
|
|
502
|
+
// max() ensures we never go past the hard floor even if the last turn
|
|
503
|
+
// start somehow lands below it.
|
|
504
|
+
var hardFloor = Math.max(0, total - HISTORY_PAGE_SIZE);
|
|
505
|
+
var lastTurn = findLastTurnStart(session.history);
|
|
506
|
+
fromIndex = Math.max(hardFloor, lastTurn);
|
|
481
507
|
}
|
|
482
508
|
}
|
|
483
509
|
|
|
@@ -487,9 +513,6 @@ function createSessionManager(opts) {
|
|
|
487
513
|
var _item = session.history[i];
|
|
488
514
|
// Skip internal bookkeeping entries not meant for the UI
|
|
489
515
|
if (_item && _item.type === "digest_checkpoint") continue;
|
|
490
|
-
if (_item && (_item.type === "mention_user" || _item.type === "mention_response")) {
|
|
491
|
-
console.log("[DEBUG replayHistory] sending mention at index=" + i + " from=" + fromIndex + " total=" + total + " type=" + _item.type + " mate=" + (_item.mateName || ""));
|
|
492
|
-
}
|
|
493
516
|
_send(transform ? transform(_item) : _item);
|
|
494
517
|
}
|
|
495
518
|
|
|
@@ -1087,6 +1110,7 @@ function createSessionManager(opts) {
|
|
|
1087
1110
|
sendAndRecord: doSendAndRecord,
|
|
1088
1111
|
sendToSession: doSendToSession,
|
|
1089
1112
|
findTurnBoundary: findTurnBoundary,
|
|
1113
|
+
findLastTurnStart: findLastTurnStart,
|
|
1090
1114
|
replayHistory: replayHistory,
|
|
1091
1115
|
searchSessions: searchSessions,
|
|
1092
1116
|
searchSessionContent: searchSessionContent,
|
package/package.json
CHANGED