Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(usage): bill Antigravity conversations that history.jsonl never logged
Adam Eivy13f119e0bd75
diff --git a/server/services/usageInteractiveScan.js b/server/services/usageInteractiveScan.jsindex 698eb0294d..4f2d21bdcf 100644--- a/server/services/usageInteractiveScan.js+++ b/server/services/usageInteractiveScan.js@@ -6,7 +6,6 @@ import { createMutex } from '../lib/asyncMutex.js';import {UNKNOWN_MODEL,decodeGrokSessionDir,- parseAgyHistory,parseAgyTranscript,parseGrokTurns,parseJsonLines,@@ -16,6 +15,7 @@ import {WINDOW_SLACK_MS,agyEstimatedBuckets,cwdMatches,+ listAgyConversations,listSubdirs,recordsFromMeasured,resolveFamilyProvider@@ -109,6 +109,9 @@ async function loadRunWindows(runsDir, from, now) {const windowsFor = (byCwd, sessionCwd) => {const out = [];+ // Unknown cwd (an agy conversation history never logged): any PortOS run+ // window may own it, so subtract them all rather than risk double-billing.+ if (!sessionCwd) return [...byCwd.values()].flat();for (const [workspacePath, windows] of byCwd) {if (cwdMatches(sessionCwd, workspacePath)) out.push(...windows);}@@ -134,8 +137,7 @@ async function listSessions(family, home, from) {}} else {const root = join(home, '.gemini', 'antigravity-cli');- const historyText = await tryReadFile(join(root, 'history.jsonl'));- for (const conversation of historyText ? parseAgyHistory(historyText) : []) {+ for (const conversation of await listAgyConversations(root)) {await add(conversation.workspace, join(root, 'brain', conversation.conversationId, '.system_generated', 'logs', 'transcript.jsonl'));}}diff --git a/server/services/usageInteractiveScan.test.js b/server/services/usageInteractiveScan.test.jsindex c90f7e1011..91c1da07e1 100644--- a/server/services/usageInteractiveScan.test.js+++ b/server/services/usageInteractiveScan.test.js@@ -109,4 +109,20 @@ describe('refreshInteractiveUsage', () => {const record = applied.find((c) => c.providerId === 'antigravity-cli').siblings[0];expect(record).toMatchObject({ source: 'estimate', tokensIn: 100, tokensOut: 50, cacheReadTokens: 100, model: 'example-agy-model' });});++ it('bills an Antigravity conversation that history.jsonl never logged', async () => {+ const root = join(home, '.gemini', 'antigravity-cli');+ const logs = join(root, 'brain', 'orphan-1', '.system_generated', 'logs');+ await mkdir(logs, { recursive: true });+ await writeFile(join(root, 'history.jsonl'), JSON.stringify({ display: '/usage', timestamp: NOW, workspace: CWD, type: 'slash_command' }));+ const step = (i, type, at, content) => JSON.stringify({ step_index: i, type, created_at: at, content });+ await writeFile(join(logs, 'transcript.jsonl'), [+ step(0, 'USER_INPUT', new Date(NOW - 2 * HOUR).toISOString(), 'u'.repeat(400)),+ step(1, 'PLANNER_RESPONSE', new Date(NOW - 2 * HOUR + 60_000).toISOString(), 'p'.repeat(200))+ ].join('\n'));++ await refreshInteractiveUsage({ home, runsDir, providers: [AGY], now: NOW });+ const record = applied.find((c) => c.providerId === 'antigravity-cli').siblings[0];+ expect(record).toMatchObject({ source: 'estimate', tokensIn: 100, tokensOut: 50 });+ });});diff --git a/server/services/usageReconciler.js b/server/services/usageReconciler.jsindex 64f9248b1b..1f275872e1 100644--- a/server/services/usageReconciler.js+++ b/server/services/usageReconciler.js@@ -423,18 +423,37 @@ async function readGrokSessions({ home, workspacePath, from, to, fold, reserveFr}}+/**+ * Every conversation `agy` recorded. `history.jsonl` names only the ones with a+ * logged workspace (a small minority — most conversations never get a line+ * carrying a `conversationId`), so the brain directory is the authoritative+ * list; a conversation absent from history has `workspace: null`.+ */+export async function listAgyConversations(root) {+ const historyText = await tryReadFile(join(root, 'history.jsonl'));+ const conversations = historyText ? parseAgyHistory(historyText) : [];+ const known = new Set(conversations.map((c) => c.conversationId));+ for (const conversationId of await listSubdirs(join(root, 'brain'))) {+ if (!known.has(conversationId)) conversations.push({ conversationId, workspace: null, timestamp: null });+ }+ return conversations;+}+async function readAgySessions({ home, workspacePath, from, to, fold, reserveFrom, excludeFor }) {// Antigravity writes no token counts anywhere, so every row it produces is// an honest chars/4 estimate. `history.jsonl` is the only cwd-keyed index;// the brain transcript it points at carries the per-step timestamps that// place the work inside a run's window.const root = join(home, '.gemini', 'antigravity-cli');- const historyText = await tryReadFile(join(root, 'history.jsonl'));- for (const conversation of historyText ? parseAgyHistory(historyText) : []) {- if (!cwdMatches(conversation.workspace, workspacePath)) continue;+ for (const conversation of await listAgyConversations(root)) {+ // A conversation history never logged has no workspace; its transcript+ // names the files it touched, so a worktree path appearing in it is the+ // match (worktree paths are unique per run).+ if (conversation.workspace && !cwdMatches(conversation.workspace, workspacePath)) continue;const transcriptPath = join(root, 'brain', conversation.conversationId, '.system_generated', 'logs', 'transcript.jsonl');const text = await tryReadFile(transcriptPath);if (!text) continue;+ if (!conversation.workspace && !text.includes(workspacePath)) continue;const parsed = parseAgyTranscript(text, { from, to, exclude: excludeFor(transcriptPath) });const estimated = agyEstimatedBuckets(parsed);if (totalTranscriptTokens(estimated) === 0) continue;