feat(webui): inspect file context in a live graph sidebar (#6562)
* feat(webui): inspect file context in a live graph sidebar * refactor(webui): place preview controls in the shared sidebar header * fix(webui): synchronize npm lockfile for graph dependencies * fix(webui): preserve compacted context and refine graph inspection * fix(context): harden provenance, request usage, and drawer lifecycle * fix(webui): align source skeleton and browser fixtures * perf(context): reuse source analysis and capture request graphs once * perf(webui): compact graph history and render graph motion on canvas * fix(webui): remove redundant context sidebar header * style(webui): clarify context replay icon * perf(webui): pace context replay on an adaptive timeline * feat(webui): briefly reveal labels for new context nodes * fix(webui): reveal new labels only for loaded context files * fix(webui): restart graph animation clock after idle * fix(webui): reveal labels when replay reverses node exit * refactor(context): project file-use facts without retention tracking * refactor(context): observe file reads outside agent execution * fix(webui): animate context sidebar closing * refactor(context): remove unused graph and usage panel code * refactor(context): isolate prompt observation from execution metadata * fix(webui): clarify cache rate and show context token usage * fix(webui): abbreviate context token counts in thousands * fix(webui): omit token unit from context usage details * fix(webui): restore large source preview highlighting and panel elevation * fix(webui): distinguish modifier scrolling from keyboard focus * fix(webui): align preview tab and panel corner radii * fix(webui): attach file tabs to the header divider * fix(webui): use one action to toggle file preview mode * fix(webui): use hover hint for context replay * fix(webui): share composer layout between graph and file sidebars * fix(webui): align sidebar bottom with composer surface * fix(webui): restore mobile graph drawing and touch file details * test(webui): align legacy cache assertions with current label * perf(context): retain source analysis and bound graph animation work * style(webui): add light elevation to user messages * test(webui): await lazy graph scene before replay assertions * fix(webui): align preview skeleton and browser contracts
This commit is contained in:
1 parent
2b44088413
commit
519ed81132
132 files changed
+4673
-1159
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseWebuiThreadPayload } from "@/lib/api";
|
||||
import { composerContextSnapshots } from "@/lib/context-graph";
|
||||
import { composerUsageSnapshots } from "@/lib/model-request";
|
||||
import { projectWebuiThreadMessages } from "@/lib/thread-display-projection";
|
||||
import { ThreadTranscript } from "@/lib/thread-transcript";
|
||||
@@ -18,6 +19,20 @@ function project(transcript: ThreadTranscript, event: ThreadProjectionEvent, per
|
||||
}
|
||||
|
||||
describe("model request snapshots", () => {
|
||||
it("replays each request's matching file graph and usage after reload", () => {
|
||||
const transcript = new ThreadTranscript();
|
||||
const first = { nodes: [{ path: "/a.md", name: "a.md", state: "loaded" as const, tokens: 100 }], edges: [] };
|
||||
const second = { nodes: [...first.nodes, { path: "/b.md", name: "b.md", state: "discovered" as const, tokens: 0 }], edges: [{ source: "/a.md", target: "/b.md" }] };
|
||||
for (const event of [
|
||||
request(1, { request_id: "first", context_graph: first }),
|
||||
request(2, { request_id: "first", phase: "completed", context_graph: first, round_usages: rounds(1) }),
|
||||
request(3, { request_id: "second", context_graph: second }),
|
||||
request(4, { request_id: "second", phase: "completed", context_graph: second, round_usages: rounds(2) }),
|
||||
]) project(transcript, event, true);
|
||||
expect(transcript.modelRequests.get("turn")?.contextSnapshots?.map((snapshot) => ({
|
||||
graph: snapshot.graph, tokens: snapshot.usage?.prompt_tokens,
|
||||
}))).toEqual([{ graph: first, tokens: 100 }, { graph: second, tokens: 101 }]);
|
||||
});
|
||||
it("validates request identity, phase, sequence, and usage at the history boundary", () => {
|
||||
for (const invalid of [{ phase: "unknown" }, { sequence: -1 }, { run_id: null }, { usage: { context_tokens: "123" } }]) {
|
||||
expect(() => parseWebuiThreadPayload({ schemaVersion: 3, projection: "events", events: [{ ...request(1), ...invalid }] })).toThrow();
|
||||
@@ -60,10 +75,10 @@ describe("model request snapshots", () => {
|
||||
expect(latest().compacted).toBe(false);
|
||||
send({ ...envelope, event: "context_compaction", compaction_id: "compact", phase: "succeeded", turn_seq: 3 });
|
||||
expect(latest().compacted).toBe(true);
|
||||
expect(latest().roundUsages).toEqual(rounds(1));
|
||||
expect(latest().roundUsages).toBeUndefined();
|
||||
send(request(4, { usage: usage(1), round_usages: rounds(1) }));
|
||||
expect(latest().compacted).toBe(true);
|
||||
expect(latest().roundUsages).toEqual(rounds(1));
|
||||
expect(latest().roundUsages).toBeUndefined();
|
||||
expect(projectWebuiThreadMessages(transcript.messages).map((row) => row.kind)).toEqual(["compaction"]);
|
||||
const smaller = { ...usage(2), context_tokens: 50 };
|
||||
send(request(5, { request_id: "request-4", phase: "completed", usage: smaller, round_usages: rounds(2) }));
|
||||
@@ -86,7 +101,7 @@ describe("model request snapshots", () => {
|
||||
] as ThreadProjectionEvent[]) project(transcript, event, persisted);
|
||||
const snapshot = composerUsageSnapshots(transcript.messages, transcript.modelRequests).at(-1)!;
|
||||
expect(snapshot.compacted).toBe(true);
|
||||
expect(snapshot.roundUsages).toEqual(rounds(1));
|
||||
expect(snapshot.roundUsages).toBeUndefined();
|
||||
});
|
||||
|
||||
it("preserves legacy compaction invalidation and historical rounds without request events", () => {
|
||||
@@ -203,3 +218,42 @@ describe("model request snapshots", () => {
|
||||
expect(snapshot.roundUsages?.[0].prompt_tokens).toBe(102);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it.each([false, true])("starts a new graph history and estimated meter at compaction (persisted=%s)", (persisted) => {
|
||||
const transcript = new ThreadTranscript();
|
||||
const oldGraph = { nodes: [{ path: "/read.md", name: "read.md", state: "loaded" as const, tokens: 300 }], edges: [] };
|
||||
const systemGraph = { nodes: [{ path: "/SOUL.md", name: "SOUL.md", state: "loaded" as const, tokens: 40 }], edges: [] };
|
||||
project(transcript, request(1, { context_graph: oldGraph, phase: "completed", usage: usage(1) }), persisted);
|
||||
const event = parseWebuiThreadPayload({ schemaVersion: 3, projection: "events", events: [{ ...envelope, event: "context_compaction", compaction_id: "boundary",
|
||||
phase: "succeeded", turn_seq: 2, context_snapshot: { graph: systemGraph, estimated_tokens: 1200, context_window_tokens: 10000 } }] }).events[0];
|
||||
expect(event).not.toBeNull();
|
||||
if (!event) throw new Error("Compaction snapshot rejected");
|
||||
project(transcript, event, persisted);
|
||||
expect(composerContextSnapshots(transcript.messages, transcript.modelRequests)).toEqual([
|
||||
{ id: "compaction-boundary", graph: systemGraph, estimatedTokens: 1200, contextWindowTokens: 10000 },
|
||||
]);
|
||||
expect(composerUsageSnapshots(transcript.messages, transcript.modelRequests).at(-1)).toMatchObject({
|
||||
compacted: true, estimatedContextTokens: 1200, contextWindowTokens: 10000,
|
||||
});
|
||||
const reloadedRequests = new Map(transcript.modelRequests);
|
||||
reloadedRequests.set("older-turn", {
|
||||
...transcript.modelRequests.get("turn")!, createdAt: 0,
|
||||
contextSnapshots: [{ id: "older-request", graph: oldGraph, turnSeq: 1 }],
|
||||
});
|
||||
expect(composerContextSnapshots(transcript.messages, reloadedRequests).map((s) => s.id))
|
||||
.toEqual(["compaction-boundary"]);
|
||||
project(transcript, request(3, { context_graph: systemGraph, phase: "completed", usage: { context_tokens: 1300, request_count: 2 } }), persisted);
|
||||
expect(composerContextSnapshots(transcript.messages, transcript.modelRequests).map((s) => s.id)).toEqual(["compaction-boundary", "request-3"]);
|
||||
expect(composerUsageSnapshots(transcript.messages, transcript.modelRequests).at(-1)).toMatchObject({ compacted: false, usage: { context_tokens: 1300 } });
|
||||
});
|
||||
|
||||
it.each(["failed", "cancelled", "completed"] as const)("does not borrow previous usage for a %s request without measurement", (phase) => {
|
||||
const transcript = new ThreadTranscript();
|
||||
const graph = { nodes: [{ path: "/a.md", name: "a.md", state: "loaded" as const, tokens: 20 }], edges: [] };
|
||||
project(transcript, request(1, { phase: "completed", context_graph: graph, request_usage: usage(1), round_usages: rounds(1) }));
|
||||
project(transcript, request(2, { phase, context_graph: graph, request_usage: null, round_usages: rounds(1) }));
|
||||
const frames = composerContextSnapshots(transcript.messages, transcript.modelRequests);
|
||||
expect(frames[0].usage).toEqual(usage(1));
|
||||
expect(frames[1].usage).toBeUndefined();
|
||||
});
|
||||
Reference in new issue
Block a user