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
@@ -0,0 +1,100 @@
1
+ import type { Context, KeymapCommand } from '@opencode/plugin/tui/context'
2
+ import type { GoKeyDiagnosticResult } from './go-key-diagnostic'
3
+ import { quotaRpc } from './quota-rpc'
4
+
5
+ const EXPLANATIONS: Record<GoKeyDiagnosticResult['category'], string> = {
6
+ not_run: 'No request was sent. No eligible Go API key was available or the attempt was canceled.',
7
+ already_used:
8
+ 'No request was sent. The one-shot diagnostic was already used in this plugin runtime.',
9
+ success: 'HTTP success only; not proof of a stable quota contract or parsed quota correctness.',
10
+ unauthorized: 'Request rejected; cause unknown.',
11
+ redirect: 'Redirect was not followed.',
12
+ http_error: 'HTTP error; cause unknown.',
13
+ timeout: 'Request timed out; no retry was made.',
14
+ network_error: 'Network error; no retry was made.',
15
+ }
16
+
17
+ const ERROR_STRUCTURE_EXPLANATIONS = {
18
+ present: 'erro estruturado presente',
19
+ absent: 'erro estruturado não detectado',
20
+ unavailable: 'não foi possível inspecionar',
21
+ } satisfies Record<NonNullable<GoKeyDiagnosticResult['error_structure']>, string>
22
+
23
+ /** Treat RPC data as untrusted: only render allowlisted categories and coarse metadata. */
24
+ function resultMessage(value: unknown): string {
25
+ if (!value || typeof value !== 'object' || !('category' in value)) {
26
+ return 'Diagnostic result unavailable. Request outcome unknown; no automatic retry.'
27
+ }
28
+ const category = value.category
29
+ if (typeof category !== 'string' || !Object.hasOwn(EXPLANATIONS, category)) {
30
+ return 'Diagnostic result unavailable. Request outcome unknown; no automatic retry.'
31
+ }
32
+ const status =
33
+ 'status' in value &&
34
+ typeof value.status === 'number' &&
35
+ Number.isInteger(value.status) &&
36
+ value.status >= 100 &&
37
+ value.status <= 599
38
+ ? ` · HTTP ${value.status}`
39
+ : ''
40
+ const contentType =
41
+ 'content_type' in value &&
42
+ typeof value.content_type === 'string' &&
43
+ ['application/json', 'text/plain', 'text/html', 'other', 'missing'].includes(value.content_type)
44
+ ? ` · content type: ${value.content_type}`
45
+ : ''
46
+ const errorStructure =
47
+ category === 'unauthorized' &&
48
+ 'status' in value &&
49
+ value.status === 401 &&
50
+ 'error_structure' in value &&
51
+ typeof value.error_structure === 'string' &&
52
+ Object.hasOwn(ERROR_STRUCTURE_EXPLANATIONS, value.error_structure)
53
+ ? ` · ${ERROR_STRUCTURE_EXPLANATIONS[value.error_structure as keyof typeof ERROR_STRUCTURE_EXPLANATIONS]}`
54
+ : ''
55
+ return `${category}${status}${contentType}${errorStructure}\n${EXPLANATIONS[category as GoKeyDiagnosticResult['category']]}`
56
+ }
57
+
58
+ /** Native keyboard-accessible dialogs; never invoked by quota refresh or panel mounting. */
59
+ export function quotaGoCheckCommand(
60
+ context: Pick<Context, 'ui' | 'client' | 'location' | 'data'>,
61
+ ): KeymapCommand {
62
+ let active = false
63
+ return {
64
+ id: 'pantheon.quota.go-check',
65
+ title: 'Pantheon: Go API-key check (one-shot)',
66
+ description: 'Manual diagnostic with confirmation; not a quota refresh',
67
+ group: 'Pantheon',
68
+ palette: true,
69
+ slash: { name: 'quota-go-check' },
70
+ run: async (): Promise<void> => {
71
+ if (active) return
72
+ active = true
73
+ try {
74
+ const confirmed = await context.ui.dialog.confirm({
75
+ title: 'Go API-key diagnostic — send once?',
76
+ message:
77
+ 'Send one GET to https://opencode.ai/zen/go/v1/usage using the configured Go API key once? OAuth is not used. No request body, redirects, or retries. Only HTTP 401 bodies are inspected (up to 4096 bytes) for a top-level JSON error property; no error values or response details are shown. Rejection cause remains unknown. 5-second timeout. One attempt per plugin runtime, including failed or unavailable-key attempts. This does not refresh quota.',
78
+ label: { confirm: 'Send once', cancel: 'Cancel (no request)' },
79
+ })
80
+ if (confirmed !== true) return
81
+ let message: string
82
+ try {
83
+ const result = await context.client.rpc(quotaRpc).go_key_diagnostic(
84
+ {},
85
+ {
86
+ location: context.location ?? context.data.location.default(),
87
+ },
88
+ )
89
+ message = resultMessage(result)
90
+ } catch {
91
+ // Transport errors may contain credentials or provider text. Never render/log them.
92
+ message = 'Diagnostic result unavailable. Request outcome unknown; no automatic retry.'
93
+ }
94
+ await context.ui.dialog.alert({ title: 'Go API-key diagnostic', message })
95
+ } finally {
96
+ active = false
97
+ }
98
+ },
99
+ }
100
+ }
@@ -0,0 +1,125 @@
1
+ /** Deliberately excludes response bodies, provider messages, and credential data. */
2
+ export type GoKeyDiagnosticResult = {
3
+ category:
4
+ | 'not_run'
5
+ | 'already_used'
6
+ | 'success'
7
+ | 'unauthorized'
8
+ | 'redirect'
9
+ | 'http_error'
10
+ | 'timeout'
11
+ | 'network_error'
12
+ status?: number
13
+ content_type?: 'application/json' | 'text/plain' | 'text/html' | 'other' | 'missing'
14
+ error_structure?: 'present' | 'absent' | 'unavailable'
15
+ }
16
+
17
+ /** Parse at most 4 KiB; inspect only own top-level error presence, never its value. */
18
+ async function errorStructure(
19
+ body: ReadableStream<Uint8Array> | null,
20
+ signal: AbortSignal,
21
+ ): Promise<NonNullable<GoKeyDiagnosticResult['error_structure']>> {
22
+ if (!body) return 'unavailable'
23
+ let reader: ReadableStreamDefaultReader<Uint8Array> | undefined
24
+ let abort: () => void = () => {}
25
+ let complete = false
26
+ try {
27
+ reader = body.getReader()
28
+ const aborted = new Promise<never>((_, reject) => {
29
+ abort = () => reject(new Error('aborted'))
30
+ signal.addEventListener('abort', abort, { once: true })
31
+ })
32
+ const bytes = new Uint8Array(4096)
33
+ let length = 0
34
+ while (true) {
35
+ signal.throwIfAborted()
36
+ const { done, value } = await Promise.race([reader.read(), aborted])
37
+ if (done) {
38
+ complete = true
39
+ break
40
+ }
41
+ if (value.byteLength > bytes.length - length) return 'unavailable'
42
+ bytes.set(value, length)
43
+ length += value.byteLength
44
+ }
45
+ const parsed: unknown = JSON.parse(
46
+ new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, length)),
47
+ )
48
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return 'unavailable'
49
+ return Object.hasOwn(parsed, 'error') ? 'present' : 'absent'
50
+ } catch {
51
+ // Untrusted parse/stream errors may contain body text; never forward or log them.
52
+ return 'unavailable'
53
+ } finally {
54
+ signal.removeEventListener('abort', abort)
55
+ if (!complete) void (reader ? reader.cancel() : body.cancel()).catch(() => {})
56
+ reader?.releaseLock()
57
+ }
58
+ }
59
+
60
+ /** One explicit invocation per plugin runtime, including failed/no-credential attempts. */
61
+ export function createGoKeyDiagnostic() {
62
+ let attempted = false
63
+ return async (
64
+ resolveKey: () => Promise<string | undefined>,
65
+ signal: AbortSignal,
66
+ ): Promise<GoKeyDiagnosticResult> => {
67
+ if (attempted) return { category: 'already_used' }
68
+ // Claim synchronously, before credential resolution or any other await.
69
+ attempted = true
70
+ let key: string | undefined
71
+ try {
72
+ key = await resolveKey()
73
+ } catch {
74
+ return { category: 'not_run' }
75
+ }
76
+ if (!key || signal.aborted) return { category: 'not_run' }
77
+
78
+ const timeout = AbortSignal.timeout(5_000)
79
+ const requestSignal = AbortSignal.any([signal, timeout])
80
+ try {
81
+ const response = await fetch('https://opencode.ai/zen/go/v1/usage', {
82
+ method: 'GET',
83
+ headers: {
84
+ Authorization: `Bearer ${key}`,
85
+ 'x-opencode-session': 'pantheon-quota',
86
+ 'user-agent': 'Pantheon-Quota/1.0',
87
+ },
88
+ redirect: 'manual',
89
+ signal: requestSignal,
90
+ })
91
+ const mediaType = response.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase()
92
+ const contentType = !mediaType
93
+ ? 'missing'
94
+ : mediaType === 'application/json' ||
95
+ mediaType === 'text/plain' ||
96
+ mediaType === 'text/html'
97
+ ? mediaType
98
+ : 'other'
99
+ let structure: GoKeyDiagnosticResult['error_structure']
100
+ if (response.status === 401 && contentType === 'application/json') {
101
+ structure = await errorStructure(response.body, requestSignal)
102
+ } else {
103
+ // Cancel without reading and never inspect Location.
104
+ void response.body?.cancel().catch(() => {})
105
+ if (response.status === 401) structure = 'unavailable'
106
+ }
107
+ return {
108
+ category:
109
+ response.status === 401
110
+ ? 'unauthorized'
111
+ : response.status >= 300 && response.status < 400
112
+ ? 'redirect'
113
+ : response.ok
114
+ ? 'success'
115
+ : 'http_error',
116
+ status: response.status,
117
+ content_type: contentType,
118
+ ...(structure ? { error_structure: structure } : {}),
119
+ }
120
+ } catch {
121
+ // Fetch errors can include headers, URLs, or provider body text. Never forward/log them.
122
+ return { category: timeout.aborted ? 'timeout' : 'network_error' }
123
+ }
124
+ }
125
+ }