iterate.com / ui

git clone https://git.iterate.com/repos/ui

A kind's view reads a few events of its agent's log by offset #2

merged panel-facts was squashed into main as ceceae6 by jonas, 2026-11-27 14:48 UTC. jonas opened it 2026-11-27 14:48 UTC.

A view that knows where a fact lies (an index in a facet's live state) had one way to it: page down the log with `loadOlder`. A pane that shows one widget paged 66,000 offsets of a call's log to a `widget-shown` from two hours before.

The frame's new verb `readEvents(after, limit)` answers the durable events after an offset of the agent's own log, at most 8 a call. It reaches nothing that `loadOlder` would not bring in the end. A page that gives no such verb refuses the call, and the view pages on as before.

Checks: `pnpm check` passes on beelink (1250 tests), with one new test in frame-view.test.tsx.

Card: tasks/a-widget-pane-gets-its-widget-s-facts-without-paging-the-log.md of /repos/task-board.

Session: claude 8bad488b-ba71-4155-869e-d4d10cbd03dd on beelink

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_013me8fQfmYw3EkNgE7ZJFVb

Conversation

Nobody has said anything yet.

Sign in to comment or to merge.

Files

6 files changed

M src/agent-kind-view/bridge.ts
@@ -5,7 +5,7 @@
 //                 go as the pages added at either end, never the whole log again.
 //   host β†’ frame  `start(input)`: the kind's `newAgent.start`, for the Dash's New agent.
 //   frame β†’ host  `loaded(…)` once (what the live read should include), then the verbs: message,
-//                 append, fileUrl, storeFiles, setState, loadOlder, and an MCP App's callTool and
+//                 append, fileUrl, storeFiles, setState, loadOlder, readEvents, and an MCP App's callTool and
 //                 readResource. Each acts on the one agent the host shows;
 //                 the host never hands over its context stub, whose `invoke` and `cd` reach the
 //                 whole mind.
@@ -80,6 +80,12 @@
   ): ReturnType<NonNullable<AgentKindViewProps["storeFiles"]>>;
   setState(patch: Partial<AgentChatState>): void;
   loadOlder(): void;
+  /** A FEW EVENTS OF THE AGENT'S OWN LOG, BY OFFSET: the durable events after `after`, at most
+   *  `limit` (the page bounds it), as the context's `readEvents` answers them. For a view that
+   *  knows where a fact lies (an index in a facet's live state) and must not page down to it:
+   *  one widget's `widget-shown` far back in a long log. It reaches nothing that `loadOlder`
+   *  would not bring in the end. */
+  readEvents(after: number, limit: number): Promise<{ events: Event[] }>;
   /** An MCP App's tool call, made as the agent at `path` (the host's own agent alone). */
   callTool(
     call: Parameters<NonNullable<AgentKindViewProps["widgetCalls"]>["callTool"]>[0],
M src/agent-kind-view/dash-agents.tsx
@@ -1149,6 +1149,9 @@
   };
 }
 
+/** How many events one `readEvents` of a kind's frame answers at most. */
+const EVENTS_BY_OFFSET_MOST = 8;
+
 /** Everything a kind's frame may do, to this agent alone: never the agent's stub, which reaches
  *  the whole mind. */
 function kindViewVerbs({
@@ -1195,6 +1198,14 @@
     },
     setState,
     loadOlder,
+    // the agent's own log alone, a few events a call: what `loadOlder` brings page by page
+    readEvents: async (after, limit) => {
+      if (!stub) throw new Error("not connected");
+      if (!Number.isSafeInteger(after) || after < 0) throw new Error("`after` is an offset.");
+      const most = Math.max(1, Math.min(EVENTS_BY_OFFSET_MOST, Math.trunc(limit) || 1));
+      const { events } = await stub.readEvents(after, most);
+      return { events };
+    },
   };
 }
 
M src/agent-kind-view/frame-view.test.tsx
@@ -204,6 +204,26 @@
   expect([...signedUrls]).toHaveLength(1);
 });
 
+test("a view reads a few events of its agent's log by offset through the host, with no older page asked for", async () => {
+  let held: AgentKindViewProps | undefined;
+  const view: LoadedView = {
+    component: (props: AgentKindViewProps) => {
+      held = props;
+      return null;
+    },
+    ephemeralEvents: [],
+  };
+  using frame = await mount({ caughtUp: true, older: pagesLeft() }, view);
+  const far = event(34_776, "test/said");
+  Object.assign(frame.host, { readEvents: vi.fn(async () => ({ events: [far] })) });
+  await expect(held!.readEvents!(34_775, 1)).resolves.toEqual({ events: [far] });
+  expect((frame.host as unknown as { readEvents: unknown }).readEvents).toHaveBeenCalledWith(
+    34_775,
+    1,
+  );
+  expect(frame.host.loadOlder).not.toHaveBeenCalled();
+});
+
 test.for<{ name: string; offsets: number[]; answered: "rows" | "empty" }>([
   { name: "a session with words", offsets: [1, 2], answered: "rows" },
   { name: "a session in which nothing was said", offsets: [], answered: "empty" },
M src/agent-kind-view/frame-view.tsx
@@ -91,13 +91,21 @@
   host: Host,
 ): Pick<
   AgentKindViewProps,
-  "onStateChange" | "onMessage" | "onAppend" | "signedUrl" | "storeFiles" | "widgetCalls"
+  | "onStateChange"
+  | "onMessage"
+  | "onAppend"
+  | "signedUrl"
+  | "readEvents"
+  | "storeFiles"
+  | "widgetCalls"
 > {
   return {
     onStateChange: (patch) => void host.setState(patch),
     onMessage: async (input) => await host.message(input),
     onAppend: async (events) => await host.append(events),
     signedUrl: async (path) => await host.fileUrl(path),
+    // a page older than this verb refuses the call: the view then pages on, as before it
+    readEvents: async (after, limit) => await host.readEvents(after, limit),
     storeFiles: async (files, key) => await host.storeFiles(files, key),
     widgetCalls: {
       callTool: async (call) => await host.callTool(call),
M src/agent-kind-view/host.ts
@@ -23,9 +23,14 @@
  *  `storeFiles` refuses a message with files that a kind appends itself. */
 export type AgentKindViewVerbs = Omit<
   AgentKindViewHostApi,
-  "loaded" | "storeFiles" | "callTool" | "readResource" | "readContext"
+  "loaded" | "storeFiles" | "callTool" | "readResource" | "readContext" | "readEvents"
 > &
-  Partial<Pick<AgentKindViewHostApi, "storeFiles" | "callTool" | "readResource" | "readContext">>;
+  Partial<
+    Pick<
+      AgentKindViewHostApi,
+      "storeFiles" | "callTool" | "readResource" | "readContext" | "readEvents"
+    >
+  >;
 
 /** One frame's link to the page: its handshake, its session, what it reported, what it holds. */
 export class AgentKindViewLink {
@@ -140,6 +145,11 @@
   }
   loadOlder() {
     this.#verbs().loadOlder();
+  }
+  readEvents(...[after, limit]: Parameters<AgentKindViewHostApi["readEvents"]>) {
+    const { readEvents } = this.#verbs();
+    if (!readEvents) throw new Error("This page reads no event by its offset for this agent.");
+    return readEvents(after, limit);
   }
   callTool(call: Parameters<AgentKindViewHostApi["callTool"]>[0]) {
     const { callTool } = this.#verbs();
M src/agent-kind-view/types.ts
@@ -94,6 +94,11 @@
   ) => Promise<{ contentType: string; filename: string; path: string; size: number }[]>;
   /** A signed download URL for a file under the agent's path. */
   signedUrl: (path: string) => Promise<string>;
+  /** A few durable events of the agent's own log, by offset: those after `after`, at most
+   *  `limit` (the page gives 8 at most). For a view that knows where a fact lies and must not
+   *  page down the log to it. It rejects on a page older than this verb: page on then, with
+   *  `context.older`. */
+  readEvents?: (after: number, limit: number) => Promise<{ events: AgentKindViewEvent[] }>;
   /** The viewer's actor id or address, when the page knows it: `AgentChat` draws no sender line
    *  under their own messages. */
   me?: string;