mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
Adds an opt-in `codeburn sync` command group: setup, push, status,
logout, reset. Developers authenticate via standard OIDC browser login
(Authorization Code + PKCE, provider-agnostic — Cognito, Auth0, Okta,
Keycloak, etc.) and push per-call usage metadata to a team-operated
OTLP/HTTP endpoint.
Privacy is structural: the payload builder has no field that can carry
prompts, responses, file contents, or bash commands. Only metadata
leaves the machine (provider, model, tokens, cost, project, tool names,
timestamps). There is deliberately no flag to include more.
Setup derives everything from a single URL:
GET {base}/.well-known/codeburn-export.json
→ issuer, client_id, traces_path, max_batch_size
Modules:
- discovery.ts discovery doc fetch/validation (version-gated)
- auth.ts OIDC discovery, PKCE, localhost callback (:19876-78),
token exchange/refresh/revoke
- credentials.ts refresh token in OS keychain (macOS security / Linux
libsecret / Windows DPAPI / 0600 file fallback). All
subprocess calls use execFileSync arg arrays; tokens
flow via stdin or env var — never shell-interpolated
- config.ts ~/.config/codeburn/sync.json
- ledger.ts client-side sent-ledger for exact dedup (no watermark
races), 6-month prune
- otlp.ts ParsedApiCall[] → ExportTraceServiceRequest JSON with
deterministic IDs: span=SHA256(dedupKey)[:8],
trace=SHA256(sessionId)[:16] — every retry idempotent
- push.ts orchestration with typed outcomes; pushes run to
completion — 429 Retry-After honored (≤120s/wait,
3 retries/batch) before deferring; partial_success is
batch-atomic (nothing ledgered, whole batch retries);
50K safety valve, no routine cap
- cli.ts command layer; --dry-run reports exact counts/cost
without sending
Preview feature: protocol may change between releases.
AI-Origin: human
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
/**
|
|
* codeburn sync — config file management.
|
|
*
|
|
* Stores non-secret sync configuration at ~/.config/codeburn/sync.json
|
|
*/
|
|
|
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { homedir } from 'os'
|
|
|
|
export interface SyncConfig {
|
|
baseUrl: string
|
|
clientId: string
|
|
tracesPath: string
|
|
issuer: string
|
|
lastSync?: string
|
|
}
|
|
|
|
function configDir(): string {
|
|
return join(homedir(), '.config', 'codeburn')
|
|
}
|
|
|
|
function configPath(): string {
|
|
return join(configDir(), 'sync.json')
|
|
}
|
|
|
|
export function readSyncConfig(): SyncConfig | null {
|
|
const path = configPath()
|
|
if (!existsSync(path)) return null
|
|
|
|
try {
|
|
const raw = readFileSync(path, 'utf-8')
|
|
const data = JSON.parse(raw) as Record<string, unknown>
|
|
|
|
if (typeof data.baseUrl !== 'string' || typeof data.clientId !== 'string') {
|
|
return null
|
|
}
|
|
|
|
return {
|
|
baseUrl: data.baseUrl,
|
|
clientId: data.clientId,
|
|
tracesPath: typeof data.tracesPath === 'string' ? data.tracesPath : '/v1/traces',
|
|
issuer: typeof data.issuer === 'string' ? data.issuer : '',
|
|
lastSync: typeof data.lastSync === 'string' ? data.lastSync : undefined,
|
|
}
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function writeSyncConfig(config: SyncConfig): void {
|
|
const dir = configDir()
|
|
mkdirSync(dir, { recursive: true })
|
|
writeFileSync(configPath(), JSON.stringify(config, null, 2) + '\n')
|
|
}
|
|
|
|
export function updateLastSync(): void {
|
|
const config = readSyncConfig()
|
|
if (!config) return
|
|
config.lastSync = new Date().toISOString()
|
|
writeSyncConfig(config)
|
|
}
|
|
|
|
export function deleteSyncConfig(): void {
|
|
try { unlinkSync(configPath()) } catch { /* may not exist */ }
|
|
}
|