perf: rest animations, cheaper chat typing and server polls, async per-tool hooks
UI
- No animation runs forever: Sagi moods, the custom pet sprite, status dots
(pulse-dot, pulse-slow, ping) and the chat shimmer play a few cycles and
rest. An infinite animation kept the browser drawing 60 frames a second.
- useSagiBrain: frames that only move lastActivityAt by <1 s keep the old
state; the 1 s tick re-renders only when the mood changes.
- ConversationView and MessageList are memoized and PaneChat passes stable
callbacks: typing in the chat box no longer re-renders the conversation.
- The chat's 700 ms menu poll reads plain text first and scans the terminal
cell by cell (reusing one cell) only when a row could be a menu cursor row.
Server
- GET /sessions/:id/transcript?after=N skips lines <= N before JSON.parse.
- GET /sessions/:id/outline is cached until the session's events change.
- broadcastLane uses the cached tmux.liveSessions(); tmux.hasSession answers
"yes" from the fresh shared list instead of a synchronous spawn (50-150 ms
per psmux call on Windows, blocking terminal echo).
- pane-mode polls every 150 ms; writeHourly writes only changed hour buckets.
- /api/metrics: agenthub_event_loop_delay_seconds{quantile}.
Hooks
- PreToolUse/PostToolUse run with "async": true (settings installer,
plugin.json, S3 managed settings): Claude Code no longer waits a Node start
before and after every tool call.
Committed with --no-verify at the owner's request: the pre-commit full server
suite fails on 9 tests that fail identically on 0c2f498 (lane-sync merge: no
git identity on this host; read-pool; resolveHost; codex-usage 1 ms flake).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -469,11 +469,31 @@ function sessionOutline(sessionId) {
|
||||
};
|
||||
}
|
||||
|
||||
// Each open chat polls its outline every few seconds, and building it parses
|
||||
// every tool event of the session: keep the last answer per session until its
|
||||
// events change (a new id, or fewer rows after a cleanup).
|
||||
const outlineStamp = db.prepare(
|
||||
"SELECT MAX(id) AS max_id, COUNT(*) AS n FROM events WHERE session_id = ?"
|
||||
);
|
||||
const OUTLINE_CACHE_MAX = 100;
|
||||
const outlineCache = new Map();
|
||||
function cachedOutline(sessionId) {
|
||||
const st = outlineStamp.get(sessionId);
|
||||
const stamp = `${st.max_id}:${st.n}`;
|
||||
const hit = outlineCache.get(sessionId);
|
||||
if (hit && hit.stamp === stamp) return hit.body;
|
||||
const body = sessionOutline(sessionId);
|
||||
outlineCache.delete(sessionId);
|
||||
outlineCache.set(sessionId, { stamp, body });
|
||||
if (outlineCache.size > OUTLINE_CACHE_MAX) outlineCache.delete(outlineCache.keys().next().value);
|
||||
return body;
|
||||
}
|
||||
|
||||
router.get("/:id/outline", (req, res) => {
|
||||
if (!stmts.getSession.get(req.params.id)) {
|
||||
return res.status(404).json({ error: { code: "NOT_FOUND", message: "Session not found" } });
|
||||
}
|
||||
res.json(sessionOutline(req.params.id));
|
||||
res.json(cachedOutline(req.params.id));
|
||||
});
|
||||
|
||||
// An image the session's own Read tool returned (`?path=`, exact), for the Chat
|
||||
@@ -1165,10 +1185,13 @@ router.get("/:id/transcript", async (req, res) => {
|
||||
}
|
||||
|
||||
if (afterLine !== null) {
|
||||
// Incremental mode: skip lines until after afterLine, collect up to limit, then stop
|
||||
let foundStart = false;
|
||||
// Incremental mode: skip lines until after afterLine, collect up to limit, then stop.
|
||||
// A line the client already has is skipped BEFORE it is parsed: every open
|
||||
// chat tails its transcript every few seconds, and parsing the whole JSONL
|
||||
// (MBs for a long session) each time was most of the server's steady CPU.
|
||||
for await (const line of rl) {
|
||||
lineNum++;
|
||||
if (lineNum <= afterLine) continue;
|
||||
if (!line.trim()) continue;
|
||||
let entry;
|
||||
try {
|
||||
@@ -1178,11 +1201,6 @@ router.get("/:id/transcript", async (req, res) => {
|
||||
}
|
||||
if (!renders(entry)) continue;
|
||||
|
||||
if (!foundStart) {
|
||||
if (lineNum <= afterLine) continue;
|
||||
foundStart = true;
|
||||
}
|
||||
|
||||
const message = isCodex ? codexMessage(entry, lineNum) : parseMessage(entry, lineNum);
|
||||
if (!message) continue;
|
||||
total++;
|
||||
|
||||
Reference in New Issue
Block a user