pantheon-opencode 1.6.1 → 1.6.2-beta.10

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 (169) hide show
  1. package/AGENTS.global.md +11 -11
  2. package/AGENTS.md +2 -2
  3. package/CHANGELOG.md +179 -0
  4. package/README.md +268 -20
  5. package/README.pt-BR.md +34 -11
  6. package/bin/pantheon-init.mjs +301 -32
  7. package/package.json +13 -4
  8. package/plugin.json +1 -1
  9. package/prompts/README.md +58 -0
  10. package/prompts/debug-issue.prompt.md +46 -0
  11. package/prompts/dynamic/agora-generated.txt +38 -0
  12. package/prompts/dynamic/orchestrate-generated.txt +51 -0
  13. package/prompts/focus.prompt.md +42 -0
  14. package/prompts/implement-feature.prompt.md +39 -0
  15. package/prompts/optimize-database.prompt.md +58 -0
  16. package/prompts/orchestrate-with-zeus.prompt.md +441 -0
  17. package/prompts/plan-architecture.prompt.md +59 -0
  18. package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
  19. package/prompts/quick-plan-large-feature.prompt.md +197 -0
  20. package/prompts/semantic-summarize.md +50 -0
  21. package/prompts/sketch.prompt.md +91 -0
  22. package/prompts/subtask.prompt.md +131 -0
  23. package/pyproject.toml +1 -1
  24. package/scripts/build-agents-md.mjs +1 -1
  25. package/scripts/decision-router-budget.mjs +780 -0
  26. package/scripts/decision-router-v2-budget.mjs +218 -0
  27. package/scripts/decision-router-v2-egress.mjs +272 -0
  28. package/scripts/decision-router.mjs +758 -0
  29. package/scripts/docs-check-changelog.mjs +5 -3
  30. package/scripts/doctor.mjs +213 -45
  31. package/scripts/install/agents-md.mjs +2 -1
  32. package/scripts/install/component-selection.mjs +9 -4
  33. package/scripts/install/config-migration.mjs +344 -393
  34. package/scripts/install/config-paths.mjs +15 -0
  35. package/scripts/install/decision-layer-preview.mjs +376 -0
  36. package/scripts/install/decision-router-config.mjs +560 -0
  37. package/scripts/install/health-check.mjs +20 -11
  38. package/scripts/install/interactive.mjs +103 -14
  39. package/scripts/install/interrupt.mjs +4 -3
  40. package/scripts/install/mcp-permissions.mjs +164 -0
  41. package/scripts/install/migrate.mjs +123 -72
  42. package/scripts/install/opencode-version.mjs +31 -13
  43. package/scripts/install/opencode-wildcard.mjs +106 -0
  44. package/scripts/install/opencode.mjs +411 -184
  45. package/scripts/install/plan-artifact.mjs +12 -1
  46. package/scripts/install/plan.mjs +8 -1
  47. package/scripts/install/plugin.mjs +18 -1
  48. package/scripts/install/state.mjs +12 -0
  49. package/scripts/install/strings.mjs +22 -0
  50. package/scripts/install/v2-capabilities.mjs +5 -6
  51. package/scripts/install/venv.mjs +34 -17
  52. package/scripts/mcp_resources.py +11 -9
  53. package/scripts/package-evidence.mjs +1 -0
  54. package/scripts/release-notes.mjs +30 -7
  55. package/scripts/restore.mjs +22 -10
  56. package/scripts/sandbox-env.sh +174 -0
  57. package/scripts/setup-v2-config.mjs +1703 -0
  58. package/scripts/setup.mjs +415 -0
  59. package/scripts/sync-tui.mjs +9 -1
  60. package/scripts/test-opencode-v2-sandbox.sh +448 -157
  61. package/scripts/update-skills-lock.mjs +30 -0
  62. package/scripts/versioning.mjs +41 -5
  63. package/skills-lock.json +10 -10
  64. package/src/agents/aphrodite.md +11 -3
  65. package/src/agents/apollo.md +6 -0
  66. package/src/agents/athena.md +7 -1
  67. package/src/agents/demeter.md +6 -2
  68. package/src/agents/gaia.md +5 -0
  69. package/src/agents/hephaestus.md +7 -2
  70. package/src/agents/hermes.md +14 -13
  71. package/src/agents/iris.md +6 -2
  72. package/src/agents/mnemosyne.md +21 -50
  73. package/src/agents/nyx.md +6 -2
  74. package/src/agents/prometheus.md +5 -1
  75. package/src/agents/talos.md +10 -1
  76. package/src/agents/themis.md +5 -1
  77. package/src/agents/zeus.md +61 -65
  78. package/src/instructions/agent-return-format.instructions.md +1 -1
  79. package/src/instructions/memory-protocol.instructions.md +3 -3
  80. package/src/instructions/test-economy.instructions.md +6 -6
  81. package/src/mcp/eval_store.py +11 -4
  82. package/src/mcp/mcp_resources.py +11 -9
  83. package/src/mcp/memory_mcp.py +293 -150
  84. package/src/mcp/pantheon_vision.py +37 -36
  85. package/src/pantheon/cost-command.ts +30 -133
  86. package/src/pantheon/jev-decision-tool.ts +347 -0
  87. package/src/pantheon/jev-decisions.ts +625 -0
  88. package/src/pantheon/local-decision-agents.ts +170 -0
  89. package/src/pantheon/local-decision-budget.ts +1046 -0
  90. package/src/pantheon/local-decision-egress-gate.ts +144 -0
  91. package/src/pantheon/local-decision-prompt.ts +256 -0
  92. package/src/pantheon/local-decision-provider-matrix.ts +44 -0
  93. package/src/pantheon/local-decision-router.ts +225 -0
  94. package/src/pantheon/local-decision-skills.ts +281 -0
  95. package/src/pantheon/local-decision-tool.ts +160 -0
  96. package/src/pantheon/local-decision-turn.ts +101 -0
  97. package/src/pantheon/local-decision-usage-evidence.internal.ts +168 -0
  98. package/src/pantheon/local-orchestration.ts +322 -0
  99. package/src/pantheon/model-pricing.ts +1 -536
  100. package/src/pantheon/pantheon-decision-catalog.ts +101 -0
  101. package/src/pantheon/v2-decision-budget.ts +456 -0
  102. package/src/pantheon/v2-decision-contracts.ts +300 -0
  103. package/src/pantheon/v2-decision-egress.ts +203 -0
  104. package/src/pantheon/v2-decision-events.ts +180 -0
  105. package/src/pantheon/v2-decision-heuristic.ts +121 -0
  106. package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
  107. package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
  108. package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
  109. package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
  110. package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
  111. package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
  112. package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
  113. package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
  114. package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
  115. package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
  116. package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
  117. package/src/pantheon/v2-decision-points.ts +242 -0
  118. package/src/pantheon/v2-decision-policy.ts +166 -0
  119. package/src/pantheon/v2-decision-premises.ts +146 -0
  120. package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
  121. package/src/pantheon/v2-decision-rank.ts +91 -0
  122. package/src/pantheon/v2-decision-registry.ts +391 -0
  123. package/src/pantheon/v2-decision-resource-ids.ts +127 -0
  124. package/src/pantheon/v2-decision-shadow.ts +123 -0
  125. package/src/pantheon/v2-decision-telemetry.ts +214 -0
  126. package/src/pantheon/v2-decision-verify.ts +51 -0
  127. package/src/pantheon/v2-hook-engine.ts +307 -0
  128. package/src/pantheon/v2-native-decisions.ts +365 -0
  129. package/src/pantheon/v2-shell-hooks.ts +66 -2
  130. package/src/pantheon/v2-tools.ts +38 -15
  131. package/src/pantheon/v2-vision.ts +34 -29
  132. package/src/pantheon/vision.ts +43 -10
  133. package/src/plugin-v2.ts +449 -79
  134. package/src/plugin.ts +4 -0
  135. package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
  136. package/src/plugins/tui/dist/server-v2.d.ts +22 -0
  137. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
  138. package/src/plugins/tui/dist/server-v2.js +26 -0
  139. package/src/plugins/tui/dist/server-v2.js.map +1 -0
  140. package/src/plugins/tui/dist/tui-v2.d.ts +54 -51
  141. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  142. package/src/plugins/tui/dist/tui-v2.js +762 -529
  143. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  144. package/src/plugins/tui/dist/tui.js +1 -1
  145. package/src/plugins/tui/index-v2.ts +3 -6
  146. package/src/plugins/tui/package-lock.json +17 -2
  147. package/src/plugins/tui/package.json +6 -3
  148. package/src/plugins/tui/src/context-gauge.ts +59 -0
  149. package/src/plugins/tui/src/cost-data.ts +607 -0
  150. package/src/plugins/tui/src/index-v2.tsx +360 -242
  151. package/src/plugins/tui/src/model-pricing.ts +536 -0
  152. package/src/plugins/tui/src/model-usage-limits.ts +4 -0
  153. package/src/plugins/tui/src/server-v2.ts +21 -0
  154. package/src/plugins/tui/src/sidebar-width.ts +129 -0
  155. package/src/plugins/tui/tsconfig.typecheck.json +1 -1
  156. package/src/plugins/tui/tsdown.config.ts +34 -5
  157. package/src/routing.yml +72 -13
  158. package/src/skills/README.md +4 -0
  159. package/src/skills/agent-coordination/SKILL.md +0 -3
  160. package/src/skills/artifact-management/SKILL.md +0 -3
  161. package/src/skills/auto-continue/SKILL.md +0 -3
  162. package/src/skills/code-review-checklist/SKILL.md +0 -3
  163. package/src/skills/context-compression/SKILL.md +0 -3
  164. package/src/skills/memory-bank/SKILL.md +6 -28
  165. package/src/skills/session-goal/SKILL.md +0 -3
  166. package/src/skills/simplify/SKILL.md +5 -4
  167. package/src/skills/tdd-with-agents/SKILL.md +0 -3
  168. package/src/skills/visual-review-pipeline/SKILL.md +0 -1
  169. package/src/pantheon/memory-context.ts +0 -1017
@@ -10,6 +10,7 @@ import { homedir } from 'node:os'
10
10
  import { join, resolve } from 'node:path'
11
11
  import { fileURLToPath } from 'node:url'
12
12
  import { resolveActivePreset } from './presets.mjs'
13
+ import { isValidSessionId } from './session-guard.ts'
13
14
  import {
14
15
  describeImagesNative,
15
16
  NATIVE_MAX_TOKENS,
@@ -93,10 +94,10 @@ function imageReference(uri: string, mime: string, name: string): string {
93
94
  * tool's `prompt`. NOTE: the description cache keys on the full prompt, so the
94
95
  * same image asked with a new question gets a fresh describe — same image +
95
96
  * same question within the TTL reuses the stored description.
96
- * `sessionID` (the V2 `prompt` hook event's live session id, when present) is
97
- * relayed as an MCP `session_id` instruction: the MCP runs in a separate
98
- * process the host hands no session id to, and the Zen gateway rejects a
99
- * sessionless call with HTTP 400 `MissingSessionID` (mirrors
97
+ * `sessionID` (the V2 `prompt` hook event's live session id, when valid under
98
+ * the host session guard) is relayed as an MCP `session_id` instruction: the
99
+ * MCP runs in a separate process the host hands no session id to, and the Zen
100
+ * gateway rejects a sessionless call with HTTP 400 `MissingSessionID` (mirrors
100
101
  * `generateInjectionPrompt` on the V1 path).
101
102
  * The question and the session id are never logged.
102
103
  */
@@ -144,10 +145,9 @@ export function buildV2VisionPromptContext(
144
145
  }
145
146
  // MCP session relay (see the doc comment above): JSON.stringify quotes the
146
147
  // id so it cannot spoof the surrounding instruction layout; never logged.
147
- const session = sessionID?.trim()
148
- if (session) {
148
+ if (isValidSessionId(sessionID)) {
149
149
  lines.push(
150
- `Prefira a ferramenta nativa \`vision_describe\` (ela já repassa a sessão automaticamente). Se usar o MCP pantheon-vision (\`vision_describe\`/\`vision_ocr\`/\`vision_analyze\`), repasse session_id=${JSON.stringify(session)} no parâmetro \`session_id\` — sem ele o gateway Zen rejeita a chamada com MissingSessionID.`,
150
+ `Prefira a ferramenta nativa \`vision_describe\` (ela já repassa a sessão automaticamente). Se usar o MCP pantheon-vision (\`vision_describe\`/\`vision_ocr\`/\`vision_analyze\`), repasse session_id=${JSON.stringify(sessionID)} no parâmetro \`session_id\` — sem ele o gateway Zen rejeita a chamada com MissingSessionID.`,
151
151
  )
152
152
  }
153
153
  return lines.join('\n')
@@ -241,14 +241,11 @@ function exactModelMatch(models: V2VisionModel[], requested: string): V2VisionMo
241
241
  }
242
242
 
243
243
  /**
244
- * Select a native transport model. An EXPLICIT pin (`preferred` — the env
245
- * `PANTHEON_VISION_MODEL`, the config file, or the active preset) ALWAYS wins,
246
- * even when it names a free-tier model: the pin is the user's decision, so the
247
- * call surfaces the gateway's HTTP 403 with its actionable message instead of
248
- * silently substituting a different model. The free-tier exclusion
249
- * (`-free` suffix / cost ≤ 0) applies ONLY to AUTOMATIC selection — discovery
250
- * then the Go default — because the direct gateway rejects free-tier models
251
- * with HTTP 403, so they cannot serve the native describe path unasked.
244
+ * Select a native transport model. An explicit pin must be eligible for the
245
+ * native Zen image path or selection fails; it is never silently substituted.
246
+ * Free-tier exclusion (`-free` suffix / cost ≤ 0) applies only to automatic
247
+ * discovery, preserving the user's choice when a free model is explicitly
248
+ * pinned (the gateway can then return its actionable 403).
252
249
  */
253
250
  export function selectV2VisionModel(
254
251
  available: unknown,
@@ -263,8 +260,7 @@ export function selectV2VisionModel(
263
260
  )
264
261
  const pinned = preferred?.trim()
265
262
  if (pinned) {
266
- const configured = exactModelMatch(capable, pinned)
267
- if (configured) return configured
263
+ return exactModelMatch(capable, pinned)
268
264
  }
269
265
  const candidates = capable.filter((model) => !isFreeVisionModel(model))
270
266
  const defaultModel = exactModelMatch(candidates, DEFAULT_MODEL)
@@ -314,21 +310,19 @@ async function configuredVisionModel(directory: string): Promise<string | undefi
314
310
  return undefined
315
311
  }
316
312
 
317
- async function preferredVisionModel(directory: string): Promise<string> {
313
+ async function preferredVisionModel(directory: string): Promise<string | undefined> {
318
314
  const envModel = process.env.PANTHEON_VISION_MODEL?.trim()
319
315
  if (envModel) return envModel
320
316
  const configModel = await configuredVisionModel(directory)
321
317
  if (configModel) return configModel
322
318
  try {
323
- return (
324
- resolveActivePreset({
325
- env: process.env,
326
- candidates: activePresetCandidates(directory),
327
- logger: { warn: () => undefined },
328
- })?.vision?.model ?? DEFAULT_MODEL
329
- )
319
+ return resolveActivePreset({
320
+ env: process.env,
321
+ candidates: activePresetCandidates(directory),
322
+ logger: { warn: () => undefined },
323
+ })?.vision?.model
330
324
  } catch {
331
- return DEFAULT_MODEL
325
+ return undefined
332
326
  }
333
327
  }
334
328
 
@@ -551,17 +545,28 @@ export function createV2VisionTool(runtime: V2VisionRuntime): V2VisionToolDefini
551
545
  },
552
546
  output: {},
553
547
  execute: async (input, rawContext) => {
554
- let stage = 'load image'
548
+ let stage = 'validate OpenCode session'
555
549
  try {
556
- const pathValue = typeof input.path === 'string' ? input.path : ''
557
550
  const call = (asRecord(rawContext) ?? {}) as V2VisionToolContext
551
+ if (!isValidSessionId(call.sessionID)) {
552
+ throw new Error(
553
+ 'a valid OpenCode session id is required; retry this tool from an active OpenCode session',
554
+ )
555
+ }
556
+ const pathValue = typeof input.path === 'string' ? input.path : ''
558
557
  const directory = call.directory || process.cwd()
558
+ stage = 'load image'
559
559
  const image = await imageAttachment(pathValue, directory, call.signal)
560
560
  stage = 'read model catalog'
561
561
  const preferred = await preferredVisionModel(directory)
562
562
  const catalog = await runtime.model.list()
563
563
  const model = selectV2VisionModel(catalog, preferred)
564
564
  if (!model) {
565
+ if (preferred?.trim()) {
566
+ throw new Error(
567
+ `explicitly configured Vision model "${preferred}" is unavailable or ineligible for the native OpenCode Zen image path; update or remove the explicit model pin (PANTHEON_VISION_MODEL, visionModel config, or active preset), or choose an enabled image-capable OpenCode Zen model`,
568
+ )
569
+ }
565
570
  throw new Error(
566
571
  'no available OpenCode Zen multimodal model accepts image input; connect OpenCode Zen and enable an image-capable model',
567
572
  )
@@ -586,7 +591,7 @@ export function createV2VisionTool(runtime: V2VisionRuntime): V2VisionToolDefini
586
591
  // header ONLY for Zen targets, never to a non-Zen provider.
587
592
  const requestTarget: NativeVisionTarget = {
588
593
  ...target,
589
- ...(call.sessionID ? { sessionID: call.sessionID } : {}),
594
+ sessionID: call.sessionID,
590
595
  }
591
596
  let failure: NativeVisionFailure | undefined
592
597
  const output = await describeImagesNative(
@@ -2126,6 +2126,16 @@ function syntheticHistoryPart(message: VisionHistoryMessage, text: string): Text
2126
2126
  }
2127
2127
  }
2128
2128
 
2129
+ /**
2130
+ * Result of a recursive sanitize pass: the (possibly rebuilt) value plus
2131
+ * whether anything at or below it actually changed. Unchanged subtrees keep
2132
+ * the ORIGINAL value by reference so host-owned instances (objects carrying
2133
+ * methods like `.inline()`, class instances, etc.) are never replaced by
2134
+ * plain-object copies — deep-copying them strips prototypes and crashes the
2135
+ * host when it later calls methods on what should still be its own objects.
2136
+ */
2137
+ type SanitizeResult = { value: unknown; changed: boolean }
2138
+
2129
2139
  /**
2130
2140
  * Remove image-bearing parts before a provider serializer can turn them into
2131
2141
  * image_url content. This hook is deliberately synchronous in spirit: it only
@@ -2144,9 +2154,20 @@ export function sanitizeVisionHistory(
2144
2154
  const sessionID = historyMessage.info?.sessionID ?? historyMessage.sessionID ?? ''
2145
2155
  if (nativeVisionSessions.has(sessionID)) continue
2146
2156
  const descriptions = sessionVisionText.get(sessionID)
2147
- const sanitize = (value: unknown, inParts: boolean): unknown => {
2148
- if (Array.isArray(value)) return value.map((item) => sanitize(item, inParts))
2149
- if (!value || typeof value !== 'object') return value
2157
+ const sanitize = (value: unknown, inParts: boolean): SanitizeResult => {
2158
+ // Lazily-copied array: the original array is returned by reference
2159
+ // until the first changed child forces a rebuild.
2160
+ if (Array.isArray(value)) {
2161
+ let items: unknown[] | null = null
2162
+ for (let i = 0; i < value.length; i++) {
2163
+ const result = sanitize(value[i], inParts)
2164
+ if (!result.changed && !items) continue
2165
+ items ??= value.slice(0, i)
2166
+ items.push(result.value)
2167
+ }
2168
+ return items ? { value: items, changed: true } : { value, changed: false }
2169
+ }
2170
+ if (!value || typeof value !== 'object') return { value, changed: false }
2150
2171
 
2151
2172
  const raw = value as { type?: unknown; id?: unknown; mime?: unknown }
2152
2173
  const isImageUrl = raw.type === 'image_url'
@@ -2164,18 +2185,30 @@ export function sanitizeVisionHistory(
2164
2185
  const text =
2165
2186
  descriptions?.get(partID) ??
2166
2187
  'Imagem removida do histórico antes do envio ao provedor textual.'
2167
- return inParts ? syntheticHistoryPart(historyMessage, text) : { type: 'text', text }
2188
+ return {
2189
+ value: inParts ? syntheticHistoryPart(historyMessage, text) : { type: 'text', text },
2190
+ changed: true,
2191
+ }
2168
2192
  }
2169
2193
 
2170
- const copy: Record<string, unknown> = {}
2171
- for (const [key, child] of Object.entries(value)) {
2172
- copy[key] = sanitize(child, key === 'parts')
2194
+ // Lazily-copied object: untouched subtrees keep their original value —
2195
+ // including host class instances and objects with methods — so nothing
2196
+ // loses its prototype unless a nested image part must be replaced.
2197
+ const entries = Object.entries(value)
2198
+ let copy: Record<string, unknown> | null = null
2199
+ for (let i = 0; i < entries.length; i++) {
2200
+ const [key, child] = entries[i] as [string, unknown]
2201
+ const result = sanitize(child, key === 'parts')
2202
+ if (!result.changed && !copy) continue
2203
+ copy ??= Object.fromEntries(entries.slice(0, i))
2204
+ copy[key] = result.value
2173
2205
  }
2174
- return copy
2206
+ return copy ? { value: copy, changed: true } : { value, changed: false }
2175
2207
  }
2176
2208
 
2177
- const sanitized = sanitize(historyMessage, false) as VisionHistoryMessage
2178
- for (const [key, value] of Object.entries(sanitized)) {
2209
+ const sanitized = sanitize(historyMessage, false)
2210
+ if (!sanitized.changed) continue
2211
+ for (const [key, value] of Object.entries(sanitized.value as VisionHistoryMessage)) {
2179
2212
  historyMessage[key] = value
2180
2213
  }
2181
2214
  }