pantheon-opencode 1.6.1 → 1.6.2-beta.2

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 (115) hide show
  1. package/AGENTS.global.md +11 -11
  2. package/AGENTS.md +2 -2
  3. package/CHANGELOG.md +29 -0
  4. package/README.md +100 -19
  5. package/README.pt-BR.md +27 -11
  6. package/bin/pantheon-init.mjs +106 -19
  7. package/package.json +3 -2
  8. package/plugin.json +1 -1
  9. package/pyproject.toml +1 -1
  10. package/scripts/build-agents-md.mjs +1 -1
  11. package/scripts/doctor.mjs +213 -45
  12. package/scripts/install/agents-md.mjs +2 -1
  13. package/scripts/install/config-migration.mjs +344 -393
  14. package/scripts/install/config-paths.mjs +15 -0
  15. package/scripts/install/mcp-permissions.mjs +164 -0
  16. package/scripts/install/opencode-version.mjs +31 -13
  17. package/scripts/install/opencode-wildcard.mjs +106 -0
  18. package/scripts/install/opencode.mjs +240 -69
  19. package/scripts/install/plan-artifact.mjs +12 -1
  20. package/scripts/install/plugin.mjs +17 -1
  21. package/scripts/install/v2-capabilities.mjs +5 -6
  22. package/scripts/package-evidence.mjs +1 -0
  23. package/scripts/sandbox-env.sh +174 -0
  24. package/scripts/setup-v2-config.mjs +1703 -0
  25. package/scripts/setup.mjs +415 -0
  26. package/scripts/sync-tui.mjs +9 -1
  27. package/scripts/test-opencode-v2-sandbox.sh +438 -151
  28. package/scripts/update-skills-lock.mjs +30 -0
  29. package/skills-lock.json +10 -10
  30. package/src/agents/aphrodite.md +5 -2
  31. package/src/agents/apollo.md +5 -0
  32. package/src/agents/athena.md +6 -1
  33. package/src/agents/demeter.md +5 -1
  34. package/src/agents/gaia.md +4 -0
  35. package/src/agents/hephaestus.md +6 -1
  36. package/src/agents/hermes.md +6 -3
  37. package/src/agents/iris.md +5 -1
  38. package/src/agents/mnemosyne.md +20 -50
  39. package/src/agents/nyx.md +5 -1
  40. package/src/agents/prometheus.md +4 -0
  41. package/src/agents/talos.md +4 -0
  42. package/src/agents/themis.md +4 -0
  43. package/src/agents/zeus.md +9 -3
  44. package/src/instructions/agent-return-format.instructions.md +1 -1
  45. package/src/instructions/memory-protocol.instructions.md +3 -3
  46. package/src/instructions/test-economy.instructions.md +6 -6
  47. package/src/mcp/pantheon_vision.py +37 -36
  48. package/src/pantheon/cost-command.ts +30 -133
  49. package/src/pantheon/model-pricing.ts +1 -536
  50. package/src/pantheon/v2-vision.ts +34 -29
  51. package/src/pantheon/vision.ts +43 -10
  52. package/src/plugin-v2.ts +30 -53
  53. package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
  54. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +749 -0
  55. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +1 -0
  56. package/src/plugins/tui/dist/quota-adapters.d.ts +89 -0
  57. package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -0
  58. package/src/plugins/tui/dist/quota-adapters.js +1142 -0
  59. package/src/plugins/tui/dist/quota-adapters.js.map +1 -0
  60. package/src/plugins/tui/dist/quota-cli.d.ts +17 -0
  61. package/src/plugins/tui/dist/quota-cli.d.ts.map +1 -0
  62. package/src/plugins/tui/dist/quota-cli.js +184 -0
  63. package/src/plugins/tui/dist/quota-cli.js.map +1 -0
  64. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js +684 -0
  65. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +1 -0
  66. package/src/plugins/tui/dist/server-v2.d.ts +14 -0
  67. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
  68. package/src/plugins/tui/dist/server-v2.js +796 -0
  69. package/src/plugins/tui/dist/server-v2.js.map +1 -0
  70. package/src/plugins/tui/dist/tui-v2.d.ts +375 -53
  71. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  72. package/src/plugins/tui/dist/tui-v2.js +5876 -530
  73. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  74. package/src/plugins/tui/dist/tui.js +1 -1
  75. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +118 -0
  76. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +1 -0
  77. package/src/plugins/tui/dist/usage-history-worker.js +25 -0
  78. package/src/plugins/tui/dist/usage-history-worker.js.map +1 -0
  79. package/src/plugins/tui/index-v2.ts +3 -6
  80. package/src/plugins/tui/package-lock.json +17 -2
  81. package/src/plugins/tui/package.json +6 -3
  82. package/src/plugins/tui/src/context-gauge.ts +59 -0
  83. package/src/plugins/tui/src/cost-data.ts +607 -0
  84. package/src/plugins/tui/src/go-key-diagnostic-ui.ts +100 -0
  85. package/src/plugins/tui/src/go-key-diagnostic.ts +125 -0
  86. package/src/plugins/tui/src/index-v2.tsx +231 -240
  87. package/src/plugins/tui/src/model-pricing.ts +536 -0
  88. package/src/plugins/tui/src/model-usage-limits.ts +4 -0
  89. package/src/plugins/tui/src/quota-adapters.ts +1598 -0
  90. package/src/plugins/tui/src/quota-cli.ts +237 -0
  91. package/src/plugins/tui/src/quota-rpc.ts +373 -0
  92. package/src/plugins/tui/src/quota-v2-model.ts +1032 -0
  93. package/src/plugins/tui/src/quota-v2.tsx +1238 -0
  94. package/src/plugins/tui/src/server-v2.ts +985 -0
  95. package/src/plugins/tui/src/sidebar-width.ts +129 -0
  96. package/src/plugins/tui/src/usage-history-contract.ts +217 -0
  97. package/src/plugins/tui/src/usage-history-validation.ts +104 -0
  98. package/src/plugins/tui/src/usage-history-view.tsx +236 -0
  99. package/src/plugins/tui/src/usage-history-worker.ts +25 -0
  100. package/src/plugins/tui/src/usage-view-model.ts +272 -0
  101. package/src/plugins/tui/tsconfig.typecheck.json +6 -1
  102. package/src/plugins/tui/tsdown.config.ts +44 -5
  103. package/src/routing.yml +72 -13
  104. package/src/skills/README.md +4 -0
  105. package/src/skills/agent-coordination/SKILL.md +0 -3
  106. package/src/skills/artifact-management/SKILL.md +0 -3
  107. package/src/skills/auto-continue/SKILL.md +0 -3
  108. package/src/skills/code-review-checklist/SKILL.md +0 -3
  109. package/src/skills/context-compression/SKILL.md +0 -3
  110. package/src/skills/memory-bank/SKILL.md +6 -28
  111. package/src/skills/session-goal/SKILL.md +0 -3
  112. package/src/skills/simplify/SKILL.md +5 -4
  113. package/src/skills/tdd-with-agents/SKILL.md +0 -3
  114. package/src/skills/visual-review-pipeline/SKILL.md +0 -1
  115. package/src/pantheon/memory-context.ts +0 -1017
@@ -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
  *