pantheon-opencode 1.6.2-beta.1 → 1.6.2-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +41 -29
  3. package/README.pt-BR.md +12 -1
  4. package/bin/pantheon-init.mjs +51 -13
  5. package/package.json +2 -1
  6. package/plugin.json +1 -1
  7. package/prompts/README.md +58 -0
  8. package/prompts/debug-issue.prompt.md +46 -0
  9. package/prompts/dynamic/agora-generated.txt +38 -0
  10. package/prompts/dynamic/orchestrate-generated.txt +51 -0
  11. package/prompts/focus.prompt.md +42 -0
  12. package/prompts/implement-feature.prompt.md +39 -0
  13. package/prompts/optimize-database.prompt.md +58 -0
  14. package/prompts/orchestrate-with-zeus.prompt.md +441 -0
  15. package/prompts/plan-architecture.prompt.md +59 -0
  16. package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
  17. package/prompts/quick-plan-large-feature.prompt.md +197 -0
  18. package/prompts/semantic-summarize.md +50 -0
  19. package/prompts/sketch.prompt.md +91 -0
  20. package/prompts/subtask.prompt.md +131 -0
  21. package/pyproject.toml +1 -1
  22. package/scripts/install/component-selection.mjs +9 -4
  23. package/scripts/install/health-check.mjs +20 -11
  24. package/scripts/install/interactive.mjs +9 -16
  25. package/scripts/install/interrupt.mjs +4 -3
  26. package/scripts/install/migrate.mjs +123 -72
  27. package/scripts/install/opencode.mjs +150 -114
  28. package/scripts/install/plan.mjs +8 -1
  29. package/scripts/install/state.mjs +7 -0
  30. package/scripts/install/strings.mjs +6 -0
  31. package/scripts/install/venv.mjs +34 -17
  32. package/scripts/restore.mjs +22 -10
  33. package/scripts/test-opencode-v2-sandbox.sh +10 -6
  34. package/src/pantheon/cost-command.ts +30 -133
  35. package/src/pantheon/model-pricing.ts +1 -536
  36. package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
  37. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +749 -0
  38. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +1 -0
  39. package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -1
  40. package/src/plugins/tui/dist/quota-adapters.js +1 -1
  41. package/src/plugins/tui/dist/{quota-rpc-UL2HuFRJ.js → quota-rpc-DMmXBhBe.js} +295 -1
  42. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +1 -0
  43. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
  44. package/src/plugins/tui/dist/server-v2.js +135 -12
  45. package/src/plugins/tui/dist/server-v2.js.map +1 -1
  46. package/src/plugins/tui/dist/tui-v2.d.ts +132 -5
  47. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  48. package/src/plugins/tui/dist/tui-v2.js +3720 -337
  49. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  50. package/src/plugins/tui/dist/tui.js +1 -1
  51. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +118 -0
  52. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +1 -0
  53. package/src/plugins/tui/dist/usage-history-worker.js +25 -0
  54. package/src/plugins/tui/dist/usage-history-worker.js.map +1 -0
  55. package/src/plugins/tui/package-lock.json +17 -2
  56. package/src/plugins/tui/package.json +4 -2
  57. package/src/plugins/tui/src/cost-data.ts +607 -0
  58. package/src/plugins/tui/src/index-v2.tsx +32 -0
  59. package/src/plugins/tui/src/model-pricing.ts +536 -0
  60. package/src/plugins/tui/src/quota-rpc.ts +164 -0
  61. package/src/plugins/tui/src/quota-v2-model.ts +2 -2
  62. package/src/plugins/tui/src/quota-v2.tsx +338 -86
  63. package/src/plugins/tui/src/server-v2.ts +159 -15
  64. package/src/plugins/tui/src/usage-history-contract.ts +217 -0
  65. package/src/plugins/tui/src/usage-history-validation.ts +104 -0
  66. package/src/plugins/tui/src/usage-history-view.tsx +236 -0
  67. package/src/plugins/tui/src/usage-history-worker.ts +25 -0
  68. package/src/plugins/tui/src/usage-view-model.ts +272 -0
  69. package/src/plugins/tui/tsconfig.typecheck.json +6 -1
  70. package/src/plugins/tui/tsdown.config.ts +36 -4
  71. package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +0 -1
@@ -43,8 +43,8 @@ export function venvPythonPath(target) {
43
43
  * Set up a Python virtual environment and install MCP dependencies.
44
44
  *
45
45
  * @param {string} target - Target installation directory (e.g. ~/.config/opencode)
46
- * @param {{ dryRun?: boolean, skipInstall?: boolean, force?: boolean, recorder?: (change: object) => void, reviewedRemovals?: Set<string>|null, reviewedSnapshots?: Map<string, object>|null }} [options]
47
- * @returns {{ venvPath: string, python: string }}
46
+ * @param {{ dryRun?: boolean, skipInstall?: boolean, force?: boolean, verbose?: boolean, recorder?: (change: object) => void, reviewedRemovals?: Set<string>|null, reviewedSnapshots?: Map<string, object>|null }} [options]
47
+ * @returns {{ venvPath: string, python: string, runtimeEffects: { venv: 'create'|'reuse'|'recreate', dependencies: 'install'|'skip' } }}
48
48
  */
49
49
  export function setupVenv(
50
50
  target,
@@ -52,6 +52,7 @@ export function setupVenv(
52
52
  dryRun = false,
53
53
  skipInstall = false,
54
54
  force = false,
55
+ verbose = false,
55
56
  recorder = null,
56
57
  reviewedRemovals = null,
57
58
  reviewedSnapshots = null,
@@ -59,9 +60,13 @@ export function setupVenv(
59
60
  ) {
60
61
  const venvPath = join(target, '.venv')
61
62
  const pythonBin = venvPythonPath(target)
63
+ const hadVenv = existsSync(venvPath)
64
+ const recreateVenv = force && hadVenv
65
+ const hadPython = existsSync(pythonBin)
66
+ const venvAction = recreateVenv ? 'recreate' : hadPython ? 'reuse' : 'create'
62
67
 
63
68
  // Step 1: Force recreate venv if --force
64
- if (force && existsSync(venvPath)) {
69
+ if (recreateVenv) {
65
70
  if (dryRun) {
66
71
  recordRemovalTree(venvPath, recorder)
67
72
  info('.venv would be removed (--force)')
@@ -74,7 +79,7 @@ export function setupVenv(
74
79
  }
75
80
 
76
81
  // Step 1b: Create venv if not exists
77
- const venvExists = existsSync(pythonBin)
82
+ const venvExists = !recreateVenv && hadPython
78
83
  if (!venvExists) {
79
84
  if (dryRun) {
80
85
  // Never claim a directory was created by a run that writes nothing.
@@ -116,12 +121,12 @@ export function setupVenv(
116
121
  // Ensure PIP_USER=0 to install into venv, not user site-packages
117
122
  const pipEnv = { ...process.env, PIP_USER: '0' }
118
123
 
119
- // stdio is 'ignore' (pip is noisy here), so the step marker is the ONLY
120
- // evidence this ran — report both start and outcome instead of a silent
121
- // 30s pause.
124
+ // Inherit pip output while the step marker makes the upgrade's start
125
+ // and outcome explicit.
122
126
  const pipUpgradeStep = step('Upgrading pip')
123
- const pipUpgrade = spawnSync(pip, ['install', '--upgrade', 'pip'], {
124
- stdio: 'ignore',
127
+ const pipVerbosity = verbose ? ['--verbose'] : ['--quiet']
128
+ const pipUpgrade = spawnSync(pip, ['install', ...pipVerbosity, '--upgrade', 'pip'], {
129
+ stdio: 'inherit',
125
130
  timeout: 30_000,
126
131
  env: pipEnv,
127
132
  })
@@ -129,8 +134,9 @@ export function setupVenv(
129
134
  pipUpgradeStep(upgraded)
130
135
  if (!upgraded) warning('pip upgrade failed — continuing with the bundled version')
131
136
 
132
- // Install requirements — attempt 1: normal
133
- const r = spawnSync(pip, ['install', '-r', reqFile], {
137
+ // Pip's quiet mode keeps normal init output concise while preserving
138
+ // stderr and its non-zero status; --verbose retains resolver detail.
139
+ const r = spawnSync(pip, ['install', ...pipVerbosity, '-r', reqFile], {
134
140
  stdio: 'inherit',
135
141
  timeout: 120_000,
136
142
  env: pipEnv,
@@ -139,11 +145,15 @@ export function setupVenv(
139
145
  if (r.status !== 0) {
140
146
  // Attempt 2: --break-system-packages (PEP 668 / externally-managed)
141
147
  warning('First attempt failed, retrying with --break-system-packages...')
142
- const r2 = spawnSync(pip, ['install', '-r', reqFile, '--break-system-packages'], {
143
- stdio: 'inherit',
144
- timeout: 120_000,
145
- env: pipEnv,
146
- })
148
+ const r2 = spawnSync(
149
+ pip,
150
+ ['install', ...pipVerbosity, '-r', reqFile, '--break-system-packages'],
151
+ {
152
+ stdio: 'inherit',
153
+ timeout: 120_000,
154
+ env: pipEnv,
155
+ },
156
+ )
147
157
  if (r2.status !== 0) {
148
158
  throw new Error(
149
159
  'Failed to install MCP dependencies. ' +
@@ -169,7 +179,14 @@ export function setupVenv(
169
179
  info('Dependency install skipped (--skip-install)')
170
180
  }
171
181
 
172
- return { venvPath, python: pythonBin }
182
+ return {
183
+ venvPath,
184
+ python: pythonBin,
185
+ runtimeEffects: {
186
+ venv: venvAction,
187
+ dependencies: skipInstall ? 'skip' : 'install',
188
+ },
189
+ }
173
190
  }
174
191
 
175
192
  // ---------------------------------------------------------------------------
@@ -35,6 +35,7 @@ import {
35
35
  restoreBackupSet,
36
36
  verifyBackupSet,
37
37
  } from './install/backup.mjs'
38
+ import { PROMPT_CANCELED } from './install/prompt-result.mjs'
38
39
 
39
40
  /**
40
41
  * Resolve the config dir whose `opencode.json` the installer manages.
@@ -122,9 +123,16 @@ export function pickBackupSet(configDir, from) {
122
123
  * @param {string} opts.backupDir
123
124
  * @param {boolean} [opts.dryRun]
124
125
  * @param {boolean} [opts.yes]
125
- * @returns {Promise<{ ok: boolean, code: number, entries?: object[] }>}
126
+ * @param {(message: string, options: object) => Promise<unknown>} [opts.promptReview]
127
+ * @returns {Promise<{ ok: boolean, code: number, reason?: string, entries?: object[] }>}
126
128
  */
127
- export async function runRestore({ configDir, backupDir, dryRun = false, yes = false }) {
129
+ export async function runRestore({
130
+ configDir,
131
+ backupDir,
132
+ dryRun = false,
133
+ yes = false,
134
+ promptReview: injectedPromptReview = null,
135
+ }) {
128
136
  const verify = verifyBackupSet(backupDir)
129
137
  if (!verify.ok) {
130
138
  console.error(
@@ -155,22 +163,26 @@ export async function runRestore({ configDir, backupDir, dryRun = false, yes = f
155
163
 
156
164
  if (dryRun) {
157
165
  console.log(' (dry-run) No files were written.')
158
- return { ok: true, code: 0, entries: plan.entries }
166
+ return { ok: true, code: 0, reason: 'preview', entries: plan.entries }
159
167
  }
160
168
 
161
- if (!yes) {
169
+ if (yes !== true) {
162
170
  // Reuse the shared confirm semantics (default NO). An interactive TTY may
163
171
  // authorize without --yes; a non-TTY run must never proceed silently.
164
172
  const tty = Boolean(process.stdin.isTTY && process.stdout.isTTY)
165
- if (!tty) {
173
+ if (!tty && typeof injectedPromptReview !== 'function') {
166
174
  console.error('❌ Refusing to restore without authorization. Re-run with --yes.')
167
- return { ok: false, code: 1 }
175
+ return { ok: false, code: 1, reason: 'not-authorized', entries: plan.entries }
168
176
  }
169
- const { promptReview } = await import('./install/interactive.mjs')
177
+ const promptReview =
178
+ injectedPromptReview ?? (await import('./install/interactive.mjs')).promptReview
170
179
  const accepted = await promptReview('Restore these changes?', { default: false })
171
- if (!accepted) {
180
+ if (accepted === PROMPT_CANCELED) {
181
+ return { ok: false, code: 130, reason: 'canceled', entries: plan.entries }
182
+ }
183
+ if (accepted !== true) {
172
184
  console.log(' Nothing restored.')
173
- return { ok: true, code: 0, entries: plan.entries }
185
+ return { ok: true, code: 0, reason: 'declined', entries: plan.entries }
174
186
  }
175
187
  }
176
188
 
@@ -189,7 +201,7 @@ export async function runRestore({ configDir, backupDir, dryRun = false, yes = f
189
201
 
190
202
  restoreBackupSet(backupDir, configDir, { dryRun: false })
191
203
  console.log(` ✅ Restored ${plan.entries.length} path(s).`)
192
- return { ok: true, code: 0, entries: plan.entries }
204
+ return { ok: true, code: 0, reason: 'restored', entries: plan.entries }
193
205
  }
194
206
 
195
207
  async function main() {
@@ -17,8 +17,9 @@
17
17
  #
18
18
  # Modes (run sequentially; a failure stops later checks):
19
19
  # --prepare Build tarball, install pantheon-opencode + the OpenCode V2
20
- # binary in the sandbox prefix, headless init, and generate
21
- # the project config and sandbox run-test.sh.
20
+ # binary in the sandbox prefix, headless init with the
21
+ # default components plus opt-in runtime, and generate the
22
+ # project config and sandbox run-test.sh.
22
23
  # --run v2 Base validation: opencode mcp list + doctor (config is
23
24
  # regenerated first).
24
25
  # --prompts Prompt battery via `opencode run --format json`.
@@ -1043,7 +1044,8 @@ npm install -g "$TGZ"
1043
1044
  if ! git -C "$REPO_DIR" ls-files --error-unmatch -- "$TGZ" >/dev/null 2>&1; then rm -f -- "$TGZ"; fi
1044
1045
 
1045
1046
  echo "--- Init (headless) ---"
1046
- pantheon-opencode init --headless -y
1047
+ pantheon-opencode init --headless -y \
1048
+ --components agents,skills,instructions,commands,plugins,runtime
1047
1049
  rewrite_v2_mcp_config
1048
1050
  if ! node "$REPO_DIR/scripts/validate-sandbox-install.mjs" \
1049
1051
  --repo "$REPO_DIR" \
@@ -1436,7 +1438,7 @@ prepare_project() {
1436
1438
  pan="$(sandbox_bin_for "pantheon-opencode")" \
1437
1439
  || die "pantheon-opencode not installed in sandbox prefix — run $0 --prepare first"
1438
1440
  log "--- Regenerating config in $dir ---"
1439
- (cd "$dir" && "$pan" init --project --version "$TARGET_VERSION" --model "$PANTHEON_SANDBOX_MODEL" -y) \
1441
+ (cd "$dir" && "$pan" init --project --version "$TARGET_VERSION" --model "$PANTHEON_SANDBOX_MODEL" --components agents,skills,instructions,commands,plugins,runtime -y) \
1440
1442
  || die "sandbox project initialization failed"
1441
1443
  rewrite_v2_mcp_config
1442
1444
  validate_sandbox_install
@@ -1550,8 +1552,10 @@ cmd_prepare() {
1550
1552
  local pan
1551
1553
  pan="$(sandbox_bin_for "pantheon-opencode")" \
1552
1554
  || die "pantheon-opencode not found in sandbox prefix after install"
1553
- log "--- Headless init (global venv + runtime) ---"
1554
- "$pan" init --headless -y --model "$PANTHEON_SANDBOX_MODEL" \
1555
+ log "--- Headless init (default components + runtime) ---"
1556
+ "$pan" init --headless -y \
1557
+ --components agents,skills,instructions,commands,plugins,runtime \
1558
+ --model "$PANTHEON_SANDBOX_MODEL" \
1555
1559
  || die "pantheon-opencode init --headless failed"
1556
1560
  prepare_project
1557
1561
  write_extract_py
@@ -37,15 +37,21 @@
37
37
  */
38
38
  import { execFile } from 'node:child_process'
39
39
  import { accessSync, constants, existsSync, statSync } from 'node:fs'
40
- import { homedir } from 'node:os'
41
40
  import { delimiter, dirname, join } from 'node:path'
42
41
  import { fileURLToPath } from 'node:url'
43
42
  import { z } from 'zod'
43
+ import type { CostSource, SqliteDatabase, SqliteModule } from '../plugins/tui/src/cost-data.ts'
44
+ import {
45
+ ledgerLabel,
46
+ numberOf,
47
+ priceTokens,
48
+ requestedVersion,
49
+ resolveCostDbPath,
50
+ resolveSources,
51
+ } from '../plugins/tui/src/cost-data.ts'
44
52
  import {
45
- computeModelCost,
46
53
  forceRefreshPricing,
47
54
  loadPricing,
48
- lookupModelPrice,
49
55
  type PricingOptions,
50
56
  type PricingSnapshot,
51
57
  type UnpricedReason,
@@ -53,6 +59,27 @@ import {
53
59
  import type { NativeTaskStatus } from './native-task-status.ts'
54
60
  import type { ToolContextLike } from './tool-context.ts'
55
61
 
62
+ export type {
63
+ ActiveContextCostEstimate,
64
+ ActiveContextCostInput,
65
+ CostSource,
66
+ OpenCodeVersion,
67
+ SqliteModule,
68
+ UsageHistoryBucket,
69
+ UsageHistoryModel,
70
+ UsageHistoryOptions,
71
+ UsageHistoryPeriod,
72
+ UsageHistoryPricing,
73
+ UsageHistoryResult,
74
+ UsagePricingStatus,
75
+ UsageTokenTotals,
76
+ } from '../plugins/tui/src/cost-data.ts'
77
+ export {
78
+ estimateActiveContextCost,
79
+ queryUsageHistory,
80
+ resolveCostDbPath,
81
+ } from '../plugins/tui/src/cost-data.ts'
82
+
56
83
  const __filename = fileURLToPath(import.meta.url)
57
84
  const __dirname = dirname(__filename)
58
85
 
@@ -120,26 +147,6 @@ export interface CostSessionScope {
120
147
  hierarchy: boolean
121
148
  }
122
149
 
123
- /**
124
- * Host table families that can carry a token ledger. A migrated database
125
- * carries both at once.
126
- */
127
- export type CostSource = 'message' | 'session_message'
128
-
129
- const COST_SOURCES: readonly CostSource[] = ['message', 'session_message']
130
-
131
- /**
132
- * Which table family each host generation stores its ledger in.
133
- *
134
- * Spelled out rather than comparing the literals: `'message' === 'v1'` is
135
- * false, so a filter written as `source === requested` narrows to nothing and
136
- * every version-pinned read fails.
137
- */
138
- const VERSION_SOURCES: Record<OpenCodeVersion, CostSource> = {
139
- v1: 'message',
140
- v2: 'session_message',
141
- }
142
-
143
150
  /** What the query actually found, so the report can describe its own coverage. */
144
151
  export interface CostCoverage {
145
152
  /** Table families that contributed rows. */
@@ -176,17 +183,6 @@ export interface CostCommandOptions {
176
183
  pricing?: PricingOptions
177
184
  }
178
185
 
179
- export type OpenCodeVersion = 'v1' | 'v2'
180
-
181
- interface SqliteDatabase {
182
- prepare(sql: string): { get(): unknown; all(...args: unknown[]): unknown[] }
183
- close(): void
184
- }
185
-
186
- export interface SqliteModule {
187
- DatabaseSync: new (path: string, options: { readOnly: boolean }) => SqliteDatabase
188
- }
189
-
190
186
  /** One cost tool: description + zod args shape + execute (delegation.ts shape). */
191
187
  export interface CostTool<Args extends z.ZodRawShape = typeof costArgs> {
192
188
  description: string
@@ -224,41 +220,6 @@ const costArgs = {
224
220
  /** Parsed arguments of the cost tool. */
225
221
  type CostArgs = z.infer<z.ZodObject<typeof costArgs>>
226
222
 
227
- /** The XDG state directory every real host installation writes its ledger to. */
228
- function defaultDbPath(): string {
229
- const xdg = process.env.XDG_DATA_HOME
230
- const dataHome = xdg !== undefined && xdg !== '' ? xdg : join(homedir(), '.local', 'share')
231
- return join(dataHome, 'opencode', 'opencode.db')
232
- }
233
-
234
- /** Read and validate the optional host-generation selector. */
235
- function requestedVersion(): OpenCodeVersion | undefined {
236
- const configured = process.env.PANTHEON_OPENCODE_VERSION
237
- if (configured === undefined) return undefined
238
- if (configured !== 'v1' && configured !== 'v2') {
239
- throw new Error(`invalid PANTHEON_OPENCODE_VERSION "${configured}"; expected "v1" or "v2"`)
240
- }
241
- return configured
242
- }
243
-
244
- /**
245
- * Resolve the database.
246
- *
247
- * Precedence: explicit option → PANTHEON_COST_DB → OPENCODE_DB → the XDG
248
- * default `opencode.db`. An invalid PANTHEON_OPENCODE_VERSION fails fast rather
249
- * than being silently ignored.
250
- *
251
- * There is deliberately NO per-version filename. Deriving one from the host
252
- * generation pointed the V2 report at `opencode-v2.db`, which exists only
253
- * because a sandbox sets OPENCODE_DB — hence OPENCODE_DB's place in this chain.
254
- */
255
- export function resolveCostDbPath(options?: CostCommandOptions): string {
256
- const explicit = options?.dbPath || process.env.PANTHEON_COST_DB || process.env.OPENCODE_DB
257
- if (explicit) return explicit
258
- requestedVersion()
259
- return defaultDbPath()
260
- }
261
-
262
223
  /**
263
224
  * First existing db path, or undefined. An EXPLICIT override shadows the
264
225
  * candidate list entirely (testability: a fake path must not fall through
@@ -270,42 +231,6 @@ function findExistingDb(override?: string): string | undefined {
270
231
  return existsSync(candidate) ? candidate : undefined
271
232
  }
272
233
 
273
- /**
274
- * Detect the ledger families by TABLE PRESENCE.
275
- *
276
- * Presence is the only reliable discriminator: a migrated database carries both
277
- * families, so pinning a schema-version constant would break whichever
278
- * population it excluded, and no manifest declares a supported host range.
279
- * PANTHEON_OPENCODE_VERSION only NARROWS an already-detected set — it never
280
- * chooses a file and never invents a family that is not there.
281
- */
282
- function resolveSources(db: SqliteDatabase, requested: OpenCodeVersion | undefined): CostSource[] {
283
- const present = new Set(
284
- (
285
- db
286
- .prepare(
287
- "SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('message', 'session_message')",
288
- )
289
- .all() as Array<{ name?: unknown }>
290
- ).map((row) => String(row.name)),
291
- )
292
- const detected = COST_SOURCES.filter((source) => present.has(source))
293
- if (detected.length === 0) {
294
- throw new Error(
295
- 'incompatible opencode.db schema: neither the "message" nor the "session_message" table exists, so there is no token ledger to read',
296
- )
297
- }
298
- if (requested === undefined) return detected
299
- const wanted = VERSION_SOURCES[requested]
300
- const narrowed = detected.filter((source) => source === wanted)
301
- if (narrowed.length === 0) {
302
- throw new Error(
303
- `incompatible opencode.db schema: PANTHEON_OPENCODE_VERSION=${requested} selected no table family, but this database contains ${detected.join(' and ')}`,
304
- )
305
- }
306
- return narrowed
307
- }
308
-
309
234
  /**
310
235
  * Per-family aggregation, grouped finely enough to price and to attribute.
311
236
  *
@@ -538,12 +463,6 @@ const DATABASE_START_SQL: Record<CostSource, string> = {
538
463
 
539
464
  type Counters = { scanned?: unknown; windowStart?: unknown; assistantRows?: unknown }
540
465
 
541
- function numberOf(value: unknown): number | undefined {
542
- if (value === null || value === undefined) return undefined
543
- const parsed = Number(value)
544
- return Number.isFinite(parsed) ? parsed : undefined
545
- }
546
-
547
466
  function emptyCoverage(sources: CostSource[]): CostCoverage {
548
467
  return { sources, scanned: 0, assistantRows: 0 }
549
468
  }
@@ -588,28 +507,6 @@ interface SessionAccumulator {
588
507
  reason: UnpricedReason | undefined
589
508
  }
590
509
 
591
- /** A ledger label the catalog cannot know; never an empty string. */
592
- function ledgerLabel(value: unknown): string {
593
- if (value === undefined || value === null) return 'unknown'
594
- const text = String(value).trim()
595
- return text === '' ? 'unknown' : text
596
- }
597
-
598
- /** Price one group, or explain why it cannot be priced. */
599
- function priceTokens(
600
- pricing: PricingSnapshot | undefined,
601
- provider: string,
602
- model: string,
603
- tokens: { input: number; output: number; cacheRead: number; cacheWrite: number },
604
- ): { usd: number } | { reason: UnpricedReason } {
605
- if (pricing === undefined) return { reason: 'no-pricing' }
606
- const lookup = lookupModelPrice(pricing, provider, model)
607
- if (!lookup.ok) return { reason: lookup.reason }
608
- const cost = computeModelCost(lookup.price, tokens)
609
- if (!cost.ok) return { reason: cost.reason }
610
- return { usd: cost.usd }
611
- }
612
-
613
510
  /**
614
511
  * Read the token ledger of one database, read-only.
615
512
  *