mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
feat(app): electron shell, 30s timer, and typed IPC bridge
- main.ts: 1200x820 BrowserWindow (contextIsolation:true,
nodeIntegration:false, sandbox:true), loads the Vite dev URL or the
built index.html, registers one ipcMain.handle per CodeburnBridge
channel, and starts a 30s tick that emits `codeburn:refresh`.
createBridgeHandlers() is a pure, injectable channel→argv map so the
spawn→IPC wiring is unit-testable without a GUI (main.test.ts).
- preload.ts: exposes window.codeburn (CodeburnBridge, exactly) and
window.codeburnEvents.onRefresh via contextBridge. Handlers return an
{ok,value|error} envelope so the structured CliError kind survives the
world boundary.
- types.ts: mirrors MenubarPayload/DailyHistoryEntry/DailyModelBreakdown
and the other CLI payload types verbatim, plus the exact CodeburnBridge
interface and Period union.
- ipc.ts: typed 1:1 wrapper + normalizeCliError.
This commit is contained in:
parent
5736c95324
commit
e22e5511ba
5 changed files with 609 additions and 0 deletions
56
app/electron/main.test.ts
Normal file
56
app/electron/main.test.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// @vitest-environment node
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
// Stub electron so importing main.ts does not require an Electron runtime.
|
||||
vi.mock('electron', () => ({
|
||||
app: { whenReady: () => Promise.resolve(), on: () => {}, quit: () => {} },
|
||||
BrowserWindow: class {},
|
||||
ipcMain: { handle: () => {} },
|
||||
}))
|
||||
|
||||
import { createBridgeHandlers } from './main'
|
||||
import { CliError } from './cli'
|
||||
|
||||
function fakeSpawn(result: unknown = { current: { cost: 12.34 } }) {
|
||||
const calls: string[][] = []
|
||||
const spawnCli = vi.fn(async (args: string[]) => {
|
||||
calls.push(args)
|
||||
return result
|
||||
})
|
||||
return { spawnCli, calls }
|
||||
}
|
||||
|
||||
describe('createBridgeHandlers (IPC wiring)', () => {
|
||||
it('getOverview spawns menubar-json for the period, omitting --provider for "all"', async () => {
|
||||
const { spawnCli, calls } = fakeSpawn()
|
||||
const handlers = createBridgeHandlers({ spawnCli, resolveCodeburnPath: () => '/bin/codeburn' })
|
||||
const res = await handlers['codeburn:getOverview']!('30days', 'all')
|
||||
expect(calls[0]).toEqual(['status', '--format', 'menubar-json', '--period', '30days'])
|
||||
expect(res).toEqual({ ok: true, value: { current: { cost: 12.34 } } })
|
||||
})
|
||||
|
||||
it('adds --provider and --by-task when requested', async () => {
|
||||
const { spawnCli, calls } = fakeSpawn([])
|
||||
const handlers = createBridgeHandlers({ spawnCli, resolveCodeburnPath: () => null })
|
||||
await handlers['codeburn:getModels']!('week', 'claude', true)
|
||||
expect(calls[0]).toEqual(['models', '--format', 'json', '--period', 'week', '--provider', 'claude', '--by-task'])
|
||||
})
|
||||
|
||||
it('returns an error envelope carrying the CliError kind', async () => {
|
||||
const spawnCli = vi.fn(async () => {
|
||||
throw new CliError('nonzero', 'boom')
|
||||
})
|
||||
const handlers = createBridgeHandlers({ spawnCli, resolveCodeburnPath: () => '/bin/codeburn' })
|
||||
const res = await handlers['codeburn:getYield']!('today')
|
||||
expect(res).toEqual({ ok: false, error: { kind: 'nonzero', message: 'boom' } })
|
||||
})
|
||||
|
||||
it('cliStatus reports the resolved binary path', async () => {
|
||||
const handlers = createBridgeHandlers({
|
||||
spawnCli: vi.fn(),
|
||||
resolveCodeburnPath: () => '/opt/homebrew/bin/codeburn',
|
||||
})
|
||||
const res = await handlers['codeburn:cliStatus']!()
|
||||
expect(res).toEqual({ ok: true, value: { found: true, path: '/opt/homebrew/bin/codeburn' } })
|
||||
})
|
||||
})
|
||||
120
app/electron/main.ts
Normal file
120
app/electron/main.ts
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
import { app, BrowserWindow, ipcMain } from 'electron'
|
||||
import path from 'node:path'
|
||||
|
||||
import { CliError, resolveCodeburnPath, spawnCli } from './cli'
|
||||
|
||||
// Result envelope: handlers never throw across IPC so the structured error
|
||||
// `kind` survives contextBridge serialization. preload.ts unwraps it.
|
||||
export type Envelope<T = unknown> = { ok: true; value: T } | { ok: false; error: { kind: string; message: string } }
|
||||
|
||||
const REFRESH_CHANNEL = 'codeburn:refresh'
|
||||
const REFRESH_INTERVAL_MS = 30_000
|
||||
|
||||
function providerArgs(provider: string | undefined): string[] {
|
||||
return provider && provider !== 'all' ? ['--provider', provider] : []
|
||||
}
|
||||
|
||||
function toEnvelopeError(err: unknown): { kind: string; message: string } {
|
||||
if (err instanceof CliError) return { kind: err.kind, message: err.message }
|
||||
return { kind: 'nonzero', message: err instanceof Error ? err.message : String(err) }
|
||||
}
|
||||
|
||||
type Deps = {
|
||||
spawnCli: (args: string[], opts?: { timeoutMs?: number }) => Promise<unknown>
|
||||
resolveCodeburnPath: () => string | null
|
||||
}
|
||||
|
||||
type Handler = (...args: any[]) => Promise<Envelope>
|
||||
|
||||
/**
|
||||
* Maps every CodeburnBridge channel to its `codeburn` argv (plain args, no
|
||||
* shell) and returns a result envelope. Pure + injectable so the wiring is
|
||||
* unit-testable without launching Electron.
|
||||
*/
|
||||
export function createBridgeHandlers(deps: Deps = { spawnCli, resolveCodeburnPath }): Record<string, Handler> {
|
||||
const run = (build: (...args: any[]) => string[]): Handler => async (...args: any[]) => {
|
||||
try {
|
||||
return { ok: true, value: await deps.spawnCli(build(...args)) }
|
||||
} catch (err) {
|
||||
return { ok: false, error: toEnvelopeError(err) }
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'codeburn:getOverview': run((period: string, provider: string) => [
|
||||
'status', '--format', 'menubar-json', '--period', period, ...providerArgs(provider),
|
||||
]),
|
||||
'codeburn:getPlans': run((period: string) => ['status', '--format', 'json', '--period', period]),
|
||||
'codeburn:getModels': run((period: string, provider: string, byTask: boolean) => [
|
||||
'models', '--format', 'json', '--period', period, ...providerArgs(provider), ...(byTask ? ['--by-task'] : []),
|
||||
]),
|
||||
'codeburn:getYield': run((period: string) => ['yield', '--format', 'json', '--period', period]),
|
||||
'codeburn:getSpendFlow': run((period: string, provider: string) => [
|
||||
'spend', '--format', 'flow-json', '--period', period, ...providerArgs(provider),
|
||||
]),
|
||||
'codeburn:getDevices': run((period: string) => ['devices', '--format', 'json', '--period', period]),
|
||||
'codeburn:getShareStatus': run(() => ['share', 'status', '--format', 'json']),
|
||||
'codeburn:getIdentity': run(() => ['identity', '--format', 'json']),
|
||||
'codeburn:cliStatus': async () => {
|
||||
const p = deps.resolveCodeburnPath()
|
||||
return { ok: true, value: { found: p !== null, path: p } }
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function registerHandlers(): void {
|
||||
const handlers = createBridgeHandlers()
|
||||
for (const [channel, handler] of Object.entries(handlers)) {
|
||||
ipcMain.handle(channel, (_event, ...args) => handler(...args))
|
||||
}
|
||||
}
|
||||
|
||||
function createWindow(): BrowserWindow {
|
||||
const win = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 820,
|
||||
minWidth: 900,
|
||||
minHeight: 600,
|
||||
backgroundColor: '#0B0D13',
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
sandbox: true,
|
||||
},
|
||||
})
|
||||
|
||||
win.once('ready-to-show', () => win.show())
|
||||
|
||||
const devUrl = process.env.VITE_DEV_SERVER_URL
|
||||
if (devUrl) {
|
||||
void win.loadURL(devUrl)
|
||||
} else {
|
||||
void win.loadFile(path.join(__dirname, '..', 'renderer', 'index.html'))
|
||||
}
|
||||
|
||||
// 30s refresh tick — the renderer's usePolled hooks revalidate on it.
|
||||
const timer = setInterval(() => {
|
||||
if (!win.isDestroyed()) win.webContents.send(REFRESH_CHANNEL)
|
||||
}, REFRESH_INTERVAL_MS)
|
||||
win.on('closed', () => clearInterval(timer))
|
||||
|
||||
return win
|
||||
}
|
||||
|
||||
function bootstrap(): void {
|
||||
void app.whenReady().then(() => {
|
||||
registerHandlers()
|
||||
createWindow()
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
}
|
||||
|
||||
if (!process.env.VITEST) bootstrap()
|
||||
38
app/electron/preload.ts
Normal file
38
app/electron/preload.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
|
||||
// Envelope mirror of main.ts. Handlers resolve with { ok, value } | { ok, error }
|
||||
// so the structured error `kind` survives the contextBridge boundary.
|
||||
type Envelope<T = unknown> = { ok: true; value: T } | { ok: false; error: { kind: string; message: string } }
|
||||
|
||||
async function invoke<T>(channel: string, ...args: unknown[]): Promise<T> {
|
||||
const res = (await ipcRenderer.invoke(channel, ...args)) as Envelope<T>
|
||||
if (res.ok) return res.value
|
||||
// Reject with a plain object so `kind` is preserved (Error subclasses lose
|
||||
// custom fields when cloned across worlds).
|
||||
return Promise.reject(res.error)
|
||||
}
|
||||
|
||||
// Shape matches CodeburnBridge (app/renderer/lib/types.ts); typing is enforced
|
||||
// renderer-side where `window.codeburn` is declared as CodeburnBridge.
|
||||
const bridge = {
|
||||
getOverview: (period: string, provider: string) => invoke('codeburn:getOverview', period, provider),
|
||||
getPlans: (period: string) => invoke('codeburn:getPlans', period),
|
||||
getModels: (period: string, provider: string, byTask: boolean) => invoke('codeburn:getModels', period, provider, byTask),
|
||||
getYield: (period: string) => invoke('codeburn:getYield', period),
|
||||
getSpendFlow: (period: string, provider: string) => invoke('codeburn:getSpendFlow', period, provider),
|
||||
getDevices: (period: string) => invoke('codeburn:getDevices', period),
|
||||
getShareStatus: () => invoke('codeburn:getShareStatus'),
|
||||
getIdentity: () => invoke('codeburn:getIdentity'),
|
||||
cliStatus: () => invoke('codeburn:cliStatus'),
|
||||
}
|
||||
|
||||
const events = {
|
||||
onRefresh: (cb: () => void): (() => void) => {
|
||||
const listener = () => cb()
|
||||
ipcRenderer.on('codeburn:refresh', listener)
|
||||
return () => ipcRenderer.removeListener('codeburn:refresh', listener)
|
||||
},
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('codeburn', bridge)
|
||||
contextBridge.exposeInMainWorld('codeburnEvents', events)
|
||||
32
app/renderer/lib/ipc.ts
Normal file
32
app/renderer/lib/ipc.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import type { CliError, CodeburnBridge } from './types'
|
||||
|
||||
// The preload script (app/electron/preload.ts) exposes `window.codeburn` as the
|
||||
// typed CodeburnBridge (methods resolve to CLI JSON or reject with a plain
|
||||
// CliError), and `window.codeburnEvents` for main→renderer push events.
|
||||
declare global {
|
||||
interface Window {
|
||||
codeburn: CodeburnBridge
|
||||
codeburnEvents: {
|
||||
/** Subscribe to the main-process 30s refresh tick. Returns an unsubscribe fn. */
|
||||
onRefresh(cb: () => void): () => void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The typed bridge. Import this instead of touching `window` directly. */
|
||||
export const codeburn: CodeburnBridge = window.codeburn
|
||||
|
||||
/** Subscribe to the main-process refresh tick. */
|
||||
export function onRefresh(cb: () => void): () => void {
|
||||
return window.codeburnEvents.onRefresh(cb)
|
||||
}
|
||||
|
||||
/** Coerce anything thrown across the IPC boundary into a CliError shape. */
|
||||
export function normalizeCliError(err: unknown): CliError {
|
||||
if (err && typeof err === 'object' && 'kind' in err && typeof (err as CliError).kind === 'string') {
|
||||
const e = err as CliError
|
||||
return { kind: e.kind, message: e.message ?? 'codeburn CLI error' }
|
||||
}
|
||||
const message = err instanceof Error ? err.message : String(err)
|
||||
return { kind: 'nonzero', message }
|
||||
}
|
||||
363
app/renderer/lib/types.ts
Normal file
363
app/renderer/lib/types.ts
Normal file
|
|
@ -0,0 +1,363 @@
|
|||
// Types mirrored verbatim from the codeburn CLI (`src/*`). The renderer is a
|
||||
// pure view over CLI JSON, so these shapes must match the emitters exactly.
|
||||
// Do not invent fields — copy from the cited source files.
|
||||
|
||||
// ————— Period + IPC error contract —————
|
||||
|
||||
export type Period = 'today' | 'week' | '30days' | 'month' | 'all'
|
||||
|
||||
export type CliErrorKind = 'not-found' | 'nonzero' | 'bad-json' | 'timeout'
|
||||
|
||||
/** Structured failure surfaced across the IPC boundary as plain data. */
|
||||
export interface CliError {
|
||||
kind: CliErrorKind
|
||||
message: string
|
||||
}
|
||||
|
||||
// ————— src/menubar-json.ts —————
|
||||
|
||||
export type DailyModelBreakdown = {
|
||||
name: string
|
||||
cost: number
|
||||
savingsUSD: number
|
||||
calls: number
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
}
|
||||
|
||||
export type DailyHistoryEntry = {
|
||||
date: string
|
||||
cost: number
|
||||
savingsUSD: number
|
||||
calls: number
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
cacheReadTokens: number
|
||||
cacheWriteTokens: number
|
||||
topModels: DailyModelBreakdown[]
|
||||
}
|
||||
|
||||
export type LocalModelSavings = {
|
||||
totalUSD: number
|
||||
calls: number
|
||||
byModel: Array<{
|
||||
name: string
|
||||
calls: number
|
||||
actualUSD: number
|
||||
savingsUSD: number
|
||||
baselineModel: string
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
}>
|
||||
byProvider: Array<{ name: string; calls: number; savingsUSD: number }>
|
||||
}
|
||||
|
||||
export type DeviceSummary = {
|
||||
id: string
|
||||
name: string
|
||||
local: boolean
|
||||
error?: string
|
||||
cost: number
|
||||
calls: number
|
||||
sessions: number
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
cacheCreateTokens: number
|
||||
cacheReadTokens: number
|
||||
totalTokens: number
|
||||
}
|
||||
|
||||
export type CombinedUsage = {
|
||||
perDevice: DeviceSummary[]
|
||||
combined: {
|
||||
cost: number
|
||||
calls: number
|
||||
sessions: number
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
cacheCreateTokens: number
|
||||
cacheReadTokens: number
|
||||
totalTokens: number
|
||||
deviceCount: number
|
||||
reachableCount: number
|
||||
}
|
||||
}
|
||||
|
||||
export type ClaudeConfigOption = {
|
||||
id: string
|
||||
label: string
|
||||
path: string
|
||||
}
|
||||
|
||||
export type ClaudeConfigSelector = {
|
||||
selectedId: string | null
|
||||
options: ClaudeConfigOption[]
|
||||
}
|
||||
|
||||
export type MenubarPayload = {
|
||||
generated: string
|
||||
current: {
|
||||
label: string
|
||||
cost: number
|
||||
calls: number
|
||||
sessions: number
|
||||
oneShotRate: number | null
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
cacheReadTokens: number
|
||||
cacheWriteTokens: number
|
||||
cacheHitPercent: number
|
||||
codexCredits: number
|
||||
topActivities: Array<{
|
||||
name: string
|
||||
cost: number
|
||||
savingsUSD: number
|
||||
turns: number
|
||||
oneShotRate: number | null
|
||||
}>
|
||||
topModels: Array<{
|
||||
name: string
|
||||
cost: number
|
||||
savingsUSD: number
|
||||
savingsBaselineModel: string
|
||||
calls: number
|
||||
}>
|
||||
unpricedModels?: Array<{ model: string; calls: number; tokens: number }>
|
||||
localModelSavings: LocalModelSavings
|
||||
providers: Record<string, number>
|
||||
topProjects: Array<{
|
||||
name: string
|
||||
cost: number
|
||||
savingsUSD: number
|
||||
sessions: number
|
||||
avgCostPerSession: number
|
||||
sessionDetails: Array<{
|
||||
cost: number
|
||||
savingsUSD: number
|
||||
calls: number
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
date: string
|
||||
models: Array<{ name: string; cost: number; savingsUSD: number }>
|
||||
}>
|
||||
}>
|
||||
modelEfficiency: Array<{
|
||||
name: string
|
||||
costPerEdit: number | null
|
||||
oneShotRate: number | null
|
||||
}>
|
||||
topSessions: Array<{
|
||||
project: string
|
||||
cost: number
|
||||
savingsUSD: number
|
||||
calls: number
|
||||
date: string
|
||||
}>
|
||||
retryTax: {
|
||||
totalUSD: number
|
||||
retries: number
|
||||
editTurns: number
|
||||
byModel: Array<{
|
||||
name: string
|
||||
taxUSD: number
|
||||
retries: number
|
||||
retriesPerEdit: number | null
|
||||
}>
|
||||
}
|
||||
routingWaste: {
|
||||
totalSavingsUSD: number
|
||||
baselineModel: string
|
||||
baselineCostPerEdit: number
|
||||
byModel: Array<{
|
||||
name: string
|
||||
costPerEdit: number
|
||||
editTurns: number
|
||||
actualUSD: number
|
||||
counterfactualUSD: number
|
||||
savingsUSD: number
|
||||
}>
|
||||
}
|
||||
tools: Array<{ name: string; calls: number }>
|
||||
skills: Array<{ name: string; turns: number; cost: number }>
|
||||
subagents: Array<{ name: string; calls: number; cost: number }>
|
||||
mcpServers: Array<{ name: string; calls: number }>
|
||||
}
|
||||
optimize: {
|
||||
findingCount: number
|
||||
savingsUSD: number
|
||||
topFindings: Array<{
|
||||
title: string
|
||||
impact: 'high' | 'medium' | 'low'
|
||||
savingsUSD: number
|
||||
}>
|
||||
}
|
||||
history: {
|
||||
daily: DailyHistoryEntry[]
|
||||
}
|
||||
combined?: CombinedUsage
|
||||
claudeConfigs?: ClaudeConfigSelector
|
||||
}
|
||||
|
||||
// ————— src/types.ts + src/models-report.ts —————
|
||||
|
||||
export type TaskCategory =
|
||||
| 'coding'
|
||||
| 'debugging'
|
||||
| 'feature'
|
||||
| 'refactoring'
|
||||
| 'testing'
|
||||
| 'exploration'
|
||||
| 'planning'
|
||||
| 'delegation'
|
||||
| 'git'
|
||||
| 'build/deploy'
|
||||
| 'conversation'
|
||||
| 'brainstorming'
|
||||
| 'general'
|
||||
|
||||
export type ModelReportRow = {
|
||||
provider: string
|
||||
providerDisplayName: string
|
||||
model: string
|
||||
modelDisplayName: string
|
||||
category: TaskCategory | null
|
||||
inputTokens: number
|
||||
outputTokens: number
|
||||
cacheWriteTokens: number
|
||||
cacheReadTokens: number
|
||||
totalTokens: number
|
||||
costUSD: number
|
||||
savingsUSD: number
|
||||
savingsBaselineModel: string
|
||||
calls: number
|
||||
credits: number | null
|
||||
topCategory?: TaskCategory
|
||||
topCategoryCost?: number
|
||||
topCategoryShare?: number
|
||||
}
|
||||
|
||||
// ————— src/yield.ts —————
|
||||
|
||||
export type YieldCategory = 'productive' | 'reverted' | 'abandoned'
|
||||
|
||||
export type YieldBucketJson = {
|
||||
costUSD: number
|
||||
sessions: number
|
||||
costPercent: number
|
||||
sessionPercent: number
|
||||
}
|
||||
|
||||
export type SessionYieldJson = {
|
||||
sessionId: string
|
||||
project: string
|
||||
category: YieldCategory
|
||||
commitCount: number
|
||||
costUSD: number
|
||||
}
|
||||
|
||||
export type YieldJsonReport = {
|
||||
period: {
|
||||
label: string
|
||||
start: string
|
||||
end: string
|
||||
}
|
||||
summary: {
|
||||
productive: YieldBucketJson
|
||||
reverted: YieldBucketJson
|
||||
abandoned: YieldBucketJson
|
||||
total: { costUSD: number; sessions: number }
|
||||
productiveToRevertedCostRatio: number | null
|
||||
}
|
||||
details: SessionYieldJson[]
|
||||
}
|
||||
|
||||
// ————— src/config.ts + src/plan-usage.ts + src/main.ts (status --format json) —————
|
||||
|
||||
export type PlanId =
|
||||
| 'claude-pro'
|
||||
| 'claude-max'
|
||||
| 'claude-max-5x'
|
||||
| 'cursor-pro'
|
||||
| 'supergrok'
|
||||
| 'supergrok-heavy'
|
||||
| 'custom'
|
||||
| 'none'
|
||||
export type PlanProvider = 'claude' | 'codex' | 'cursor' | 'grok' | 'all'
|
||||
export type PlanStatus = 'under' | 'near' | 'over'
|
||||
|
||||
/** Serialized plan summary from `attachPlanSummaries` (src/main.ts:90). */
|
||||
export type JsonPlanSummary = {
|
||||
id: PlanId
|
||||
provider: PlanProvider
|
||||
budget: number
|
||||
spent: number
|
||||
percentUsed: number
|
||||
status: PlanStatus
|
||||
projectedMonthEnd: number
|
||||
daysUntilReset: number
|
||||
periodStart: string
|
||||
periodEnd: string
|
||||
}
|
||||
|
||||
/** `codeburn status --format json` payload (src/main.ts:751), with plan summaries attached. */
|
||||
export type StatusJson = {
|
||||
currency: string
|
||||
today: { cost: number; savings: number; calls: number }
|
||||
month: { cost: number; savings: number; calls: number }
|
||||
localModelSavings?: { today: number; month: number; callsToday: number; callsMonth: number }
|
||||
plan?: JsonPlanSummary
|
||||
plans?: Partial<Record<PlanProvider, JsonPlanSummary>>
|
||||
}
|
||||
|
||||
// ————— T1a: src/spend-flow.ts (defined by the shared contract) —————
|
||||
|
||||
export type SpendFlowNode = { id: string; label: string; cost: number }
|
||||
export type SpendFlowLink = { model: string; project: string; cost: number }
|
||||
export type SpendFlow = {
|
||||
period: { label: string; start: string; end: string }
|
||||
models: SpendFlowNode[]
|
||||
projects: SpendFlowNode[]
|
||||
links: SpendFlowLink[]
|
||||
}
|
||||
|
||||
// ————— T1b: src/sharing/* (defined by the shared contract) —————
|
||||
|
||||
export type PendingPairing = { id: string; name: string; code: string }
|
||||
export type ShareStatus = {
|
||||
sharing: boolean
|
||||
name: string
|
||||
port: number
|
||||
always: boolean
|
||||
peers: number
|
||||
pending: PendingPairing[]
|
||||
}
|
||||
|
||||
/** Public identity subset served by /api/identity (src/web-dashboard.ts:229). */
|
||||
export type Identity = {
|
||||
name: string
|
||||
fingerprint: string
|
||||
}
|
||||
|
||||
export type ScannedDevice = {
|
||||
name: string
|
||||
host: string
|
||||
port: number
|
||||
fingerprint: string
|
||||
code: string
|
||||
paired: boolean
|
||||
}
|
||||
export type DeviceScanResult = { found: ScannedDevice[] }
|
||||
|
||||
// ————— IPC surface (preload contextBridge → window.codeburn) —————
|
||||
|
||||
export interface CodeburnBridge {
|
||||
getOverview(period: Period, provider: string): Promise<MenubarPayload>
|
||||
getPlans(period: Period): Promise<StatusJson>
|
||||
getModels(period: Period, provider: string, byTask: boolean): Promise<ModelReportRow[]>
|
||||
getYield(period: Period): Promise<YieldJsonReport>
|
||||
getSpendFlow(period: Period, provider: string): Promise<SpendFlow>
|
||||
getDevices(period: Period): Promise<CombinedUsage>
|
||||
getShareStatus(): Promise<ShareStatus>
|
||||
getIdentity(): Promise<Identity>
|
||||
cliStatus(): Promise<{ found: boolean; path: string | null; error?: string }>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue