fix(chat): keep a long turn's Edited N files card whole across the page cut (#86)
The reported turn (/vp-auto, ~120 messages) showed "Edited 1 file": the chat loads the newest 50 messages, and the turn's other Write (rbac_routes_test.go, +176) was in the part before the page. - turnCarry (agent-edits.js): every message the route's sliding window drops goes through it; it keeps the file changes since the last prompt it dropped (a dropped call whose result is on the page, and dropped subagents, included). - A Claude page that starts mid-turn answers them as `turn_edits`; the chat keeps the one from the page that holds its oldest message and adds it to that turn's card. Files a turn changed through Bash (python/sed writing a file) are still not listed: nothing in the transcript says which files a command wrote.
This commit is contained in:
@@ -1177,6 +1177,9 @@ router.get("/:id/transcript", async (req, res) => {
|
||||
: (e, n) => parseMessage(e, n);
|
||||
|
||||
const parseMessage = createClaudeLineParser(isSubagentFile);
|
||||
const claudeFile = !isCodex && !isOmp && !isCursor && !isAgy;
|
||||
// The edits of the turn the page starts inside of (agent-edits.js).
|
||||
const carry = claudeFile ? require("../lib/agent-edits").turnCarry() : null;
|
||||
|
||||
if (afterLine !== null) {
|
||||
// Incremental mode: skip lines until after afterLine, collect up to limit, then stop.
|
||||
@@ -1232,7 +1235,7 @@ router.get("/:id/transcript", async (req, res) => {
|
||||
messages.push(message);
|
||||
// Sliding window: only keep the last `limit` messages
|
||||
if (messages.length > limit) {
|
||||
messages.shift();
|
||||
carry?.drop(messages.shift());
|
||||
}
|
||||
}
|
||||
if (total > limit) hasMore = true;
|
||||
@@ -1283,7 +1286,7 @@ router.get("/:id/transcript", async (req, res) => {
|
||||
messages.push(message);
|
||||
// Sliding window: only keep the last `limit` messages in memory
|
||||
if (messages.length > limit) {
|
||||
messages.shift();
|
||||
carry?.drop(messages.shift());
|
||||
}
|
||||
}
|
||||
// If we shifted any messages out, there are more
|
||||
@@ -1292,8 +1295,10 @@ router.get("/:id/transcript", async (req, res) => {
|
||||
|
||||
// A Claude subagent's own Write/Edit calls are in ITS transcript: put the
|
||||
// files on its Agent result, so the turn's "Edited N files" counts them.
|
||||
if (!isCodex && !isOmp && !isCursor && !isAgy) {
|
||||
let turnEdits = null;
|
||||
if (claudeFile) {
|
||||
await require("../lib/agent-edits").attachAgentEdits(messages, req.params.id, session.cwd);
|
||||
turnEdits = await carry.result(messages, req.params.id, session.cwd);
|
||||
}
|
||||
|
||||
const lastLine = messages.length > 0 ? messages[messages.length - 1].line : 0;
|
||||
@@ -1310,6 +1315,7 @@ router.get("/:id/transcript", async (req, res) => {
|
||||
has_more: hasMore,
|
||||
last_line: lastLine,
|
||||
first_line: firstLine,
|
||||
...(turnEdits ? { turn_edits: turnEdits } : {}),
|
||||
});
|
||||
} catch (err) {
|
||||
res.json({ messages: [], total: 0, has_more: false, last_line: 0, first_line: 0 });
|
||||
|
||||
Reference in New Issue
Block a user