pantheon-opencode 1.4.3 → 1.5.0-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 (118) hide show
  1. package/.pantheon/code-mode/README.md +93 -0
  2. package/.pantheon/code-mode/checkpoint-session.py +7 -0
  3. package/.pantheon/code-mode/checkpoint-session.sh +11 -0
  4. package/.pantheon/code-mode/checkpoint_session.py +481 -0
  5. package/.pantheon/code-mode/compress-inline.py +450 -0
  6. package/.pantheon/code-mode/eval-llm-judge.py +255 -0
  7. package/.pantheon/code-mode/eval-monte-carlo.py +368 -0
  8. package/.pantheon/code-mode/eval-run.py +197 -0
  9. package/.pantheon/code-mode/eval-static.py +321 -0
  10. package/.pantheon/code-mode/example-sync.sh +5 -0
  11. package/.pantheon/code-mode/manifest.json +21 -0
  12. package/.pantheon/code-mode/session-end-save.py +186 -0
  13. package/.pantheon/code-mode/session-end-save.sh +18 -0
  14. package/.pantheon/code-mode/test-allowed.sh +5 -0
  15. package/.pantheon/code-mode/test-auto-continue-checkpoint.sh +179 -0
  16. package/.pantheon/code-mode/test-env.sh +7 -0
  17. package/.pantheon/code-mode/test-prlimit.sh +9 -0
  18. package/.pantheon/code-mode/test-timeout.sh +6 -0
  19. package/CHANGELOG.md +1026 -0
  20. package/README.md +292 -1080
  21. package/README.pt-BR.md +308 -0
  22. package/bin/pantheon-init.mjs +207 -31
  23. package/opencode.json +1 -0
  24. package/package.json +34 -14
  25. package/plugin.json +15 -0
  26. package/pyproject.toml +65 -0
  27. package/scripts/_pantheon_paths.py +48 -7
  28. package/scripts/ci-validate-yaml.py +7 -2
  29. package/scripts/code_mode_server.py +451 -44
  30. package/scripts/cost.mjs +30 -14
  31. package/scripts/doctor.mjs +306 -129
  32. package/scripts/generate-preset-docs.mjs +127 -66
  33. package/scripts/generate-prompts.sh +2 -2
  34. package/scripts/install/cli-ui.mjs +23 -10
  35. package/scripts/install/config-migration.mjs +399 -0
  36. package/scripts/install/health-check.mjs +3 -3
  37. package/scripts/install/model-picker.mjs +72 -23
  38. package/scripts/install/opencode-version.mjs +47 -0
  39. package/scripts/install/opencode.mjs +396 -121
  40. package/scripts/install/plugin.mjs +89 -49
  41. package/scripts/install/shared.mjs +55 -159
  42. package/scripts/install/strings.mjs +129 -0
  43. package/scripts/install-mcp.mjs +45 -232
  44. package/scripts/manifest-inventory.mjs +410 -0
  45. package/scripts/mcp_persistence_server.py +798 -60
  46. package/scripts/mcp_resources_server.py +144 -40
  47. package/scripts/memory_mcp_server.py +2 -2
  48. package/scripts/package-evidence.mjs +242 -0
  49. package/scripts/probe-context-rehydrate.mjs +240 -0
  50. package/scripts/probe-pantheon-cost.mjs +313 -0
  51. package/scripts/recover-zenodo-deposition.mjs +146 -0
  52. package/scripts/release-beta-version.mjs +56 -60
  53. package/scripts/sync-artifacts.mjs +169 -0
  54. package/scripts/sync-tui.mjs +135 -42
  55. package/scripts/test-opencode-v1-v2-sandbox.sh +862 -0
  56. package/scripts/uninstall.mjs +298 -954
  57. package/scripts/validate-zenodo-release.mjs +154 -0
  58. package/scripts/validation-policy.mjs +7 -7
  59. package/scripts/version-check.mjs +113 -108
  60. package/scripts/versioning.mjs +230 -86
  61. package/scripts/zenodo-artifact.mjs +21 -0
  62. package/scripts/zenodo-release-state.mjs +53 -0
  63. package/src/agents/mnemosyne.md +1 -1
  64. package/src/agents/zeus.md +27 -16
  65. package/src/mcp/_pantheon_paths.py +48 -7
  66. package/src/mcp/code_mode_server.py +451 -44
  67. package/src/mcp/eval_store.py +1 -1
  68. package/src/mcp/mcp_persistence_server.py +798 -60
  69. package/src/mcp/mcp_resources_server.py +144 -40
  70. package/src/mcp/pantheon_vision_server.py +1 -1
  71. package/src/mcp/toon_codec.py +491 -0
  72. package/src/pantheon/auto-wake.ts +1 -5
  73. package/src/pantheon/background-job-board.ts +110 -2
  74. package/src/pantheon/compaction-handoff.ts +304 -0
  75. package/src/pantheon/cost-command.ts +356 -69
  76. package/src/pantheon/delegate-manager.ts +766 -0
  77. package/src/pantheon/delegation-classifier.ts +307 -0
  78. package/src/pantheon/delegation-enforce.ts +13 -12
  79. package/src/pantheon/delegation-finalize.ts +406 -0
  80. package/src/pantheon/delegation-notify.ts +212 -0
  81. package/src/pantheon/delegation-toast.ts +73 -0
  82. package/src/pantheon/delegation.ts +1337 -0
  83. package/src/pantheon/file-persistence-salvage.ts +64 -0
  84. package/src/pantheon/file-persistence.ts +194 -45
  85. package/src/pantheon/goal-loop.ts +2 -2
  86. package/src/pantheon/goal-store.ts +1 -1
  87. package/src/pantheon/hashline/tool.ts +2 -2
  88. package/src/pantheon/model-command.ts +2 -1
  89. package/src/pantheon/native-probe.ts +234 -0
  90. package/src/pantheon/native-task-status.ts +139 -0
  91. package/src/pantheon/permission-eval.ts +284 -0
  92. package/src/pantheon/provider-capabilities.ts +221 -0
  93. package/src/pantheon/provider-stream-tracker.ts +182 -0
  94. package/src/pantheon/shared-board.ts +37 -0
  95. package/src/pantheon/step-cap.ts +110 -0
  96. package/src/pantheon/task-result-guard.ts +107 -0
  97. package/src/pantheon/token-opt.ts +689 -0
  98. package/src/pantheon/tool-ceiling.ts +159 -0
  99. package/src/pantheon/toon-codec.ts +481 -0
  100. package/src/pantheon/tui-version-check.ts +1 -3
  101. package/src/pantheon/v2-bridge.ts +129 -0
  102. package/src/pantheon/v2-events.ts +148 -0
  103. package/src/pantheon/v2-hooks.ts +287 -0
  104. package/src/pantheon/v2-tool-definitions.ts +331 -0
  105. package/src/pantheon/zeus-delegate-with-retry.ts +406 -0
  106. package/src/plugin-v2/index.ts +21 -0
  107. package/src/plugin-v2.ts +824 -0
  108. package/src/plugin.ts +261 -51
  109. package/src/plugins/pantheon-hooks.ts +51 -0
  110. package/src/plugins/tui/dist/tui.d.ts +116 -24
  111. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  112. package/src/plugins/tui/dist/tui.js +416 -149
  113. package/src/plugins/tui/dist/tui.tsx +456 -87
  114. package/src/plugins/tui/package-lock.json +51 -51
  115. package/src/plugins/tui/package.json +7 -7
  116. package/src/plugins/tui/src/index.tsx +462 -95
  117. package/src/skills/README.md +0 -2
  118. package/src/pantheon/tool-context.ts +0 -41
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Compaction handoff coordinator.
3
+ *
4
+ * Coordinates the handoff of a compaction checkpoint from in-memory state to
5
+ * durable persistence. The coordinator is deliberately dependency-free: it
6
+ * does not import plugin, board, MCP, hooks, or provider modules.
7
+ */
8
+
9
+ export interface HandoffRecord {
10
+ digest: string
11
+ payload: string
12
+ version: number
13
+ sessionId: string
14
+ leaseToken: string
15
+ }
16
+
17
+ export interface PersistencePort {
18
+ prepare(input: HandoffRecord): Promise<void>
19
+ read(sessionId: string, key: string): Promise<HandoffRecord | null>
20
+ commit(sessionId: string, key: string, record: HandoffRecord): Promise<void>
21
+ }
22
+
23
+ export interface MemoryPort {
24
+ publishImmutable(sessionId: string, key: string, record: HandoffRecord): Promise<void>
25
+ readByIdempotencyKey(key: string): Promise<HandoffRecord | null>
26
+ }
27
+
28
+ export type HandoffStatus =
29
+ | 'COMMITTED'
30
+ | 'UNAVAILABLE'
31
+ | 'CONFLICT'
32
+ | 'NOT_SUPPORTED'
33
+ | 'INVALID_INPUT'
34
+
35
+ /** Maximum allowed integer version value. */
36
+ export const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER
37
+
38
+ /** Maximum encoded payload size in bytes (128 KiB). */
39
+ export const MAX_PAYLOAD_BYTES = 65_536
40
+
41
+ /** Maximum length of URL-safe identifiers. */
42
+ export const MAX_ID_LENGTH = 128
43
+
44
+ const URL_SAFE_PATTERN = /^[A-Za-z0-9._~-]+$/
45
+ const DIGEST_PATTERN = /^[a-f0-9]{64}$/
46
+
47
+ /** Validate a URL-safe identifier: 1-128 chars, no control characters. */
48
+ function isValidIdentifier(value: unknown): value is string {
49
+ if (typeof value !== 'string') {
50
+ return false
51
+ }
52
+ if (value.length < 1 || value.length > MAX_ID_LENGTH) {
53
+ return false
54
+ }
55
+ if (value.length > 0 && !URL_SAFE_PATTERN.test(value)) {
56
+ return false
57
+ }
58
+ return true
59
+ }
60
+
61
+ /** Validate a lease token: 1-128 chars, no control characters. */
62
+ function isValidLeaseToken(value: unknown): value is string {
63
+ if (typeof value !== 'string') {
64
+ return false
65
+ }
66
+ if (value.length < 1 || value.length > MAX_ID_LENGTH) {
67
+ return false
68
+ }
69
+ for (const char of value) {
70
+ const code = char.charCodeAt(0)
71
+ if (code < 0x20 || code === 0x7f) {
72
+ return false
73
+ }
74
+ }
75
+ return true
76
+ }
77
+
78
+ /** Validate a positive integer version within the safe integer range. */
79
+ function isValidVersion(value: unknown): value is number {
80
+ return (
81
+ typeof value === 'number' && Number.isInteger(value) && value > 0 && value <= MAX_SAFE_INTEGER
82
+ )
83
+ }
84
+
85
+ /** Validate a 64-character lowercase hex digest. */
86
+ function isValidDigest(value: unknown): value is string {
87
+ return typeof value === 'string' && DIGEST_PATTERN.test(value)
88
+ }
89
+
90
+ /**
91
+ * Validate that a payload is UTF-8 encodable and contains no NUL or control
92
+ * characters (tab, LF, and CR are permitted).
93
+ */
94
+ function isValidPayload(value: unknown): value is string {
95
+ if (typeof value !== 'string') {
96
+ return false
97
+ }
98
+ if (value.length < 1 || value.length > MAX_PAYLOAD_BYTES) {
99
+ return false
100
+ }
101
+
102
+ const bytes = Buffer.byteLength(value, 'utf8')
103
+ if (bytes < 1 || bytes > MAX_PAYLOAD_BYTES) {
104
+ return false
105
+ }
106
+ if (value.includes('\0')) {
107
+ return false
108
+ }
109
+
110
+ for (const char of value) {
111
+ const code = char.charCodeAt(0)
112
+ if (code < 0x20 && code !== 0x09 && code !== 0x0a && code !== 0x0d) {
113
+ return false
114
+ }
115
+ }
116
+ return true
117
+ }
118
+
119
+ /**
120
+ * Compute the digest over the exact UTF-8 encoded bytes of a payload.
121
+ */
122
+ export function computeDigest(payload: string): string {
123
+ const bytes = Buffer.from(payload, 'utf8')
124
+ let hash = ''
125
+ for (const byte of bytes) {
126
+ hash += byte.toString(16).padStart(2, '0')
127
+ }
128
+ return hash
129
+ }
130
+
131
+ /** Create a result describing a failed validation. */
132
+ function invalid(message: string): { status: 'INVALID_INPUT'; message: string } {
133
+ return { status: 'INVALID_INPUT', message }
134
+ }
135
+
136
+ /** Create a result describing a missing dependency. */
137
+ function notSupported(): { status: 'NOT_SUPPORTED' } {
138
+ return { status: 'NOT_SUPPORTED' }
139
+ }
140
+
141
+ /** Create a result describing a conflict. */
142
+ function conflict(message: string): { status: 'CONFLICT'; message: string } {
143
+ return { status: 'CONFLICT', message }
144
+ }
145
+
146
+ /** Create a result describing an unavailable memory port. */
147
+ function unavailable(message: string): { status: 'UNAVAILABLE'; message: string } {
148
+ return { status: 'UNAVAILABLE', message }
149
+ }
150
+
151
+ /** Create a successful committed result. */
152
+ function committed(digest: string): { status: 'COMMITTED'; digest: string } {
153
+ return { status: 'COMMITTED', digest }
154
+ }
155
+
156
+ /**
157
+ * Compaction handoff coordinator.
158
+ *
159
+ * The coordinator drives the handoff FSM:
160
+ *
161
+ * no record -> prepare -> PREPARED -> memory.publishImmutable
162
+ * -> memory.readByIdempotencyKey -> persistence.commit -> COMMITTED
163
+ *
164
+ * It never retries after memory becomes unavailable; the PREPARED state is
165
+ * left intact for a later explicit attempt.
166
+ */
167
+ export class CompactionHandoffCoordinator {
168
+ private readonly persistence: PersistencePort | undefined
169
+ private readonly memory: MemoryPort | undefined
170
+
171
+ constructor(persistence?: PersistencePort, memory?: MemoryPort) {
172
+ this.persistence = persistence
173
+ this.memory = memory
174
+ }
175
+
176
+ /**
177
+ * Attempt to hand off a compaction checkpoint.
178
+ *
179
+ * Returns immediately with INVALID_INPUT if any argument fails validation.
180
+ * Returns NOT_SUPPORTED if either required port is missing.
181
+ * Returns CONFLICT for digest or lease/version mismatches.
182
+ * Returns UNAVAILABLE if the memory port cannot publish/read the record.
183
+ * Returns COMMITTED when the record is durably committed.
184
+ */
185
+ async prepare(
186
+ sessionId: string,
187
+ idempotencyKey: string,
188
+ leaseToken: string,
189
+ version: number,
190
+ digest: string,
191
+ payload: string,
192
+ ): Promise<{ status: HandoffStatus; key?: string; digest?: string; message?: string }> {
193
+ // Validation first: no port calls are made before this block completes.
194
+ if (
195
+ !isValidIdentifier(sessionId) ||
196
+ !isValidIdentifier(idempotencyKey) ||
197
+ !isValidLeaseToken(leaseToken) ||
198
+ !isValidVersion(version) ||
199
+ !isValidDigest(digest) ||
200
+ !isValidPayload(payload)
201
+ ) {
202
+ return invalid('Invalid handoff input')
203
+ }
204
+
205
+ if (this.persistence === undefined || this.memory === undefined) {
206
+ return notSupported()
207
+ }
208
+
209
+ const _key = `${sessionId}:${idempotencyKey}`
210
+
211
+ // Check for an existing committed record before preparing a new one.
212
+ const existingRecord = await this.persistence.read(sessionId, idempotencyKey)
213
+ if (existingRecord !== null) {
214
+ if (existingRecord.digest === digest && existingRecord.sessionId === sessionId) {
215
+ // Idempotent replay: same digest and session. Verify lease/version match.
216
+ if (existingRecord.leaseToken !== leaseToken || existingRecord.version !== version) {
217
+ return conflict('Stale lease or version')
218
+ }
219
+
220
+ // Verify the record is also in memory. If missing, try to recover by publishing once.
221
+ let memoryRecord: HandoffRecord | null = null
222
+ try {
223
+ memoryRecord = await this.memory.readByIdempotencyKey(idempotencyKey)
224
+ } catch {
225
+ return unavailable('Memory port unavailable')
226
+ }
227
+
228
+ if (memoryRecord === null) {
229
+ // Recovery: memory lost the record but persistence has it. Publish once.
230
+ try {
231
+ await this.memory.publishImmutable(sessionId, idempotencyKey, existingRecord)
232
+ } catch (_error) {
233
+ return unavailable('Memory port unavailable')
234
+ }
235
+ try {
236
+ memoryRecord = await this.memory.readByIdempotencyKey(idempotencyKey)
237
+ } catch (_error) {
238
+ return unavailable('Memory port unavailable')
239
+ }
240
+ }
241
+
242
+ if (memoryRecord === null) {
243
+ return unavailable('Record not found in memory')
244
+ }
245
+
246
+ await this.persistence.commit(sessionId, idempotencyKey, existingRecord)
247
+ return committed(memoryRecord.digest)
248
+ }
249
+ // Different digest or session: conflict.
250
+ return conflict('Digest or session mismatch')
251
+ }
252
+
253
+ // Phase 1: prepare in persistence (PREPARED).
254
+ await this.persistence.prepare({ digest, payload, version, sessionId, leaseToken })
255
+
256
+ // Phase 2: publish the record to memory. If memory is unavailable, the
257
+ // coordinator stays in PREPARED and never retries automatically.
258
+ try {
259
+ await this.memory.publishImmutable(sessionId, idempotencyKey, {
260
+ digest,
261
+ payload,
262
+ version,
263
+ sessionId,
264
+ leaseToken,
265
+ })
266
+ } catch (_error) {
267
+ return unavailable('Memory port unavailable')
268
+ }
269
+
270
+ // Phase 3: read back from memory by idempotency key.
271
+ let memoryRecord: HandoffRecord | null = null
272
+ try {
273
+ memoryRecord = await this.memory.readByIdempotencyKey(idempotencyKey)
274
+ } catch (_error) {
275
+ return unavailable('Memory port unavailable')
276
+ }
277
+
278
+ if (memoryRecord === null) {
279
+ return unavailable('Record not found in memory')
280
+ }
281
+
282
+ // Stale lease or version check.
283
+ if (memoryRecord.leaseToken !== leaseToken || memoryRecord.version !== version) {
284
+ return conflict('Stale lease or version')
285
+ }
286
+
287
+ // Idempotent replay: same key and session is a success.
288
+ // The memory record is authoritative for recovery after crash.
289
+ if (memoryRecord.sessionId === sessionId) {
290
+ // Phase 4: commit to persistence.
291
+ try {
292
+ await this.persistence.commit(sessionId, idempotencyKey, memoryRecord)
293
+ } catch (_error) {
294
+ return conflict('Persistence commit failed')
295
+ }
296
+ return committed(memoryRecord.digest)
297
+ }
298
+
299
+ // Same key, different digest or session: conflict.
300
+ return conflict('Digest or session mismatch')
301
+ }
302
+ }
303
+
304
+ export default CompactionHandoffCoordinator