Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(context): context:ensure IPC to track a session's transcript on demand

enesd24560b92045
diff --git a/src/main/index.ts b/src/main/index.ts
index a532af8ad..5dbc35427 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -219,6 +219,16 @@ app.whenReady().then(async () => {
return p ? readTranscriptLines(p) : []
}
)
+ // Populate the context meter without a live hook event: the renderer calls this on mount
+ // (the continuing session may be idle after a restart). Track under the sessionId (the key
+ // the meter looks up); cwd is only a path fallback. contextTail.track reads immediately and
+ // the 1s interval keeps it fresh while tracked.
+ ipcMain.on(IPC.contextEnsure, async (_e, sessionId?: string, cwd?: string) => {
+ if (!sessionId || !SESSION_ID_RE.test(sessionId)) return
+ let p = contextTail.pathFor(sessionId) ?? (await resolveTranscriptPath(sessionId))
+ if (!p && cwd) p = await transcriptPathForCwd(cwd)
+ if (p) contextTail.track(sessionId, p)
+ })
ipcMain.handle(
IPC.handoffBuild,
(_e, sessionId: string, agentId: string, sourceNodeId: string, cwd: string | undefined) =>
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 9950d53ef..eda231527 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -169,7 +169,8 @@ const api: NodeTerminalApi = {
const handler = (_e: unknown, payload: Parameters<typeof listener>[0]) => listener(payload)
ipcRenderer.on(IPC.contextUpdate, handler)
return () => ipcRenderer.removeListener(IPC.contextUpdate, handler)
- }
+ },
+ ensure: (sessionId, cwd) => ipcRenderer.send(IPC.contextEnsure, sessionId, cwd)
},
claude: {
readTranscript: (sessionId, cwd) =>
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 99bbb1c1b..96535b149 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -41,6 +41,7 @@ export const IPC = {
usageRefresh: 'usage:refresh',
usageUpdate: 'usage:update',
contextUpdate: 'context:update',
+ contextEnsure: 'context:ensure',
// Events broadcast from main to the renderer (sessionId is appended to the channel name).
ptyData: (sessionId: string) => `pty:data:${sessionId}`,
ptyExit: (sessionId: string) => `pty:exit:${sessionId}`,
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 7dbb155e6..c43e6e03f 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -492,6 +492,12 @@ export interface ContextWindowUsage {
export interface ContextApi {
/** Fires whenever a session's context fill changes. Returns unsubscribe. */
onUpdate(listener: (usage: ContextWindowUsage) => void): () => void
+ /**
+ * Ask main to start (or refresh) tracking a session's transcript so the meter populates
+ * without waiting for a live hook event — e.g. on node mount after an app restart, when
+ * the continuing session is idle. `cwd` is a transcript-path fallback only.
+ */
+ ensure(sessionId: string, cwd?: string): void
}
/** One searchable line extracted from a Claude session transcript. */