pantheon-opencode 1.5.0-beta.1 → 1.5.0-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.
- package/README.md +3 -0
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/scripts/cost.mjs +30 -14
- package/scripts/mcp_persistence_server.py +44 -7
- package/scripts/probe-context-rehydrate.mjs +240 -0
- package/scripts/probe-pantheon-cost.mjs +304 -0
- package/scripts/test-opencode-v1-v2-sandbox.sh +394 -41
- package/src/mcp/mcp_persistence_server.py +44 -7
- package/src/pantheon/cost-command.ts +49 -32
- package/src/pantheon/delegate-manager.ts +285 -0
- package/src/pantheon/token-opt.ts +237 -11
- package/src/plugin-v2.ts +2 -14
- package/src/plugin.ts +3 -8
- package/src/plugins/tui/package.json +1 -1
- package/.pantheon/code-mode/.gitkeep +0 -0
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-1.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-10.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-11.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-2.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-3.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-4.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-5.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-6.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-7.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-8.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/checkpoint-9.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/heartbeat.json +0 -8
- package/.pantheon/code-mode/.pantheon/deepwork/initial-token-40k/session.json +0 -11
- package/src/pantheon/delegate-task-adapter.ts +0 -444
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Offline/ambiental probe for pantheon_cost.
|
|
4
|
+
*
|
|
5
|
+
* The probe never reads or writes a user's real database. Without --fixture it
|
|
6
|
+
* reports AMBIENTAL because a real dependency/database is intentionally not
|
|
7
|
+
* exercised. With --fixture it imports the installed command and creates a
|
|
8
|
+
* temporary synthetic opencode database. A missing fixture runtime is also
|
|
9
|
+
* AMBIENTAL rather than a false PASS.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs'
|
|
12
|
+
import { tmpdir } from 'node:os'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
|
|
15
|
+
const requestedVersion = valueFor('--version')
|
|
16
|
+
const jsonOutput = process.argv.includes('--json')
|
|
17
|
+
const fixtureMode = process.argv.includes('--fixture')
|
|
18
|
+
|
|
19
|
+
function valueFor(name) {
|
|
20
|
+
const index = process.argv.indexOf(name)
|
|
21
|
+
return index >= 0 ? process.argv[index + 1] : undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function emit(status, detail, checks = []) {
|
|
25
|
+
const result = { status, version: requestedVersion, detail, checks }
|
|
26
|
+
if (jsonOutput) process.stdout.write(JSON.stringify(result))
|
|
27
|
+
else process.stdout.write(`${status}: ${detail}\n`)
|
|
28
|
+
if (status === 'FAIL') process.exitCode = 1
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function ambiental(detail) {
|
|
32
|
+
emit('AMBIENTAL', detail)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function setEnvironment(values) {
|
|
36
|
+
const previous = new Map()
|
|
37
|
+
for (const [key, value] of Object.entries(values)) {
|
|
38
|
+
previous.set(key, process.env[key])
|
|
39
|
+
if (value === undefined) delete process.env[key]
|
|
40
|
+
else process.env[key] = value
|
|
41
|
+
}
|
|
42
|
+
return () => {
|
|
43
|
+
for (const [key, value] of previous) {
|
|
44
|
+
if (value === undefined) delete process.env[key]
|
|
45
|
+
else process.env[key] = value
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createSyntheticDb(DatabaseSync, path, rows) {
|
|
51
|
+
const db = new DatabaseSync(path)
|
|
52
|
+
db.exec('CREATE TABLE message (data TEXT NOT NULL, time_created INTEGER NOT NULL)')
|
|
53
|
+
const insert = db.prepare('INSERT INTO message (data, time_created) VALUES (?, ?)')
|
|
54
|
+
for (const data of rows) insert.run(JSON.stringify(data), Date.now())
|
|
55
|
+
db.close()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function createIncompatibleDb(DatabaseSync, path) {
|
|
59
|
+
const db = new DatabaseSync(path)
|
|
60
|
+
db.exec('CREATE TABLE not_message (value TEXT NOT NULL)')
|
|
61
|
+
db.close()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function requireOutput(output, fragment, label) {
|
|
65
|
+
if (!output.includes(fragment)) throw new Error(`${label}: missing ${fragment}`)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function assertTokensOnly(output, expectedRows, total) {
|
|
69
|
+
requireOutput(output, 'Tokens In | Tokens Out | Tokens Total', 'tokens-only header')
|
|
70
|
+
for (const row of expectedRows) {
|
|
71
|
+
requireOutput(
|
|
72
|
+
output,
|
|
73
|
+
`| ${row.agent} | ${row.phase} | ${row.input} | ${row.output} | ${row.total} |`,
|
|
74
|
+
'token row',
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
requireOutput(
|
|
78
|
+
output,
|
|
79
|
+
`| **Total** | — | **${total.input}** | **${total.output}** | **${total.total}** |`,
|
|
80
|
+
'token total',
|
|
81
|
+
)
|
|
82
|
+
if (/Cost \(USD\)|costUsd|\$\d|\bUSD\b/i.test(output)) {
|
|
83
|
+
throw new Error('tokens-only output contains a monetary value')
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function main() {
|
|
88
|
+
if (requestedVersion !== 'v1' && requestedVersion !== 'v2') {
|
|
89
|
+
emit('FAIL', 'usage: --version v1|v2 [--fixture] [--json]')
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!fixtureMode) {
|
|
94
|
+
ambiental(
|
|
95
|
+
'real pantheon_cost dependency/database not exercised; use --fixture for synthetic checks',
|
|
96
|
+
)
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const source = new URL('../src/pantheon/cost-command.ts', import.meta.url)
|
|
101
|
+
if (!existsSync(source)) {
|
|
102
|
+
ambiental(
|
|
103
|
+
'pantheon_cost dependency is unavailable: installed package lacks src/pantheon/cost-command.ts',
|
|
104
|
+
)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let DatabaseSync
|
|
109
|
+
let createCostCommand
|
|
110
|
+
try {
|
|
111
|
+
;({ DatabaseSync } = await import('node:sqlite'))
|
|
112
|
+
;({ createCostCommand } = await import(source.href))
|
|
113
|
+
} catch (error) {
|
|
114
|
+
ambiental(
|
|
115
|
+
`pantheon_cost fixture runtime unavailable: ${error instanceof Error ? error.message : String(error)}`,
|
|
116
|
+
)
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const root = mkdtempSync(join(tmpdir(), 'pantheon-cost-probe-'))
|
|
121
|
+
const dataHome = join(root, 'data')
|
|
122
|
+
const opencodeDir = join(dataHome, 'opencode')
|
|
123
|
+
const selectedDb = join(opencodeDir, requestedVersion === 'v2' ? 'opencode-v2.db' : 'opencode.db')
|
|
124
|
+
const otherDb = join(root, 'other.db')
|
|
125
|
+
const envDb = join(root, 'env.db')
|
|
126
|
+
const explicitDb = join(root, 'explicit.db')
|
|
127
|
+
const incompatibleDb = join(root, 'incompatible.db')
|
|
128
|
+
const checks = []
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
mkdirSync(opencodeDir, { recursive: true })
|
|
132
|
+
// These rows intentionally include a monetary-looking field to prove it is
|
|
133
|
+
// ignored; only input/output/total tokens may appear in the report.
|
|
134
|
+
const selectedRows =
|
|
135
|
+
requestedVersion === 'v2'
|
|
136
|
+
? [
|
|
137
|
+
{
|
|
138
|
+
role: 'assistant',
|
|
139
|
+
agent: 'aphrodite',
|
|
140
|
+
phase: 'plan',
|
|
141
|
+
cost: 999.99,
|
|
142
|
+
tokens: { input: 7, output: 8 },
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
role: 'assistant',
|
|
146
|
+
agent: 'aphrodite',
|
|
147
|
+
phase: 'plan',
|
|
148
|
+
cost: 999.99,
|
|
149
|
+
tokens: { input: 1, output: 2 },
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
role: 'assistant',
|
|
153
|
+
agent: 'zeus',
|
|
154
|
+
phase: 'audit',
|
|
155
|
+
cost: 999.99,
|
|
156
|
+
tokens: { input: 4, output: 6 },
|
|
157
|
+
},
|
|
158
|
+
]
|
|
159
|
+
: [
|
|
160
|
+
{
|
|
161
|
+
role: 'assistant',
|
|
162
|
+
agent: 'hermes',
|
|
163
|
+
phase: 'plan',
|
|
164
|
+
cost: 999.99,
|
|
165
|
+
tokens: { input: 10, output: 20 },
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
role: 'assistant',
|
|
169
|
+
agent: 'hermes',
|
|
170
|
+
phase: 'plan',
|
|
171
|
+
cost: 999.99,
|
|
172
|
+
tokens: { input: 3, output: 4 },
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
role: 'assistant',
|
|
176
|
+
agent: 'athena',
|
|
177
|
+
phase: 'review',
|
|
178
|
+
cost: 999.99,
|
|
179
|
+
tokens: { input: 2, output: 5 },
|
|
180
|
+
},
|
|
181
|
+
]
|
|
182
|
+
createSyntheticDb(DatabaseSync, selectedDb, selectedRows)
|
|
183
|
+
createSyntheticDb(DatabaseSync, otherDb, [
|
|
184
|
+
{
|
|
185
|
+
role: 'assistant',
|
|
186
|
+
agent: 'wrong-version',
|
|
187
|
+
phase: 'other',
|
|
188
|
+
tokens: { input: 90, output: 90 },
|
|
189
|
+
},
|
|
190
|
+
])
|
|
191
|
+
createSyntheticDb(DatabaseSync, envDb, [
|
|
192
|
+
{ role: 'assistant', agent: 'env-agent', phase: 'override', tokens: { input: 1, output: 2 } },
|
|
193
|
+
])
|
|
194
|
+
createSyntheticDb(DatabaseSync, explicitDb, [
|
|
195
|
+
{
|
|
196
|
+
role: 'assistant',
|
|
197
|
+
agent: 'explicit-agent',
|
|
198
|
+
phase: 'explicit',
|
|
199
|
+
tokens: { input: 9, output: 1 },
|
|
200
|
+
},
|
|
201
|
+
])
|
|
202
|
+
createIncompatibleDb(DatabaseSync, incompatibleDb)
|
|
203
|
+
|
|
204
|
+
const restore = setEnvironment({
|
|
205
|
+
XDG_DATA_HOME: dataHome,
|
|
206
|
+
PANTHEON_OPENCODE_VERSION: requestedVersion,
|
|
207
|
+
PANTHEON_COST_DB: undefined,
|
|
208
|
+
})
|
|
209
|
+
try {
|
|
210
|
+
const selectedOutput = await createCostCommand().pantheon_cost.execute(
|
|
211
|
+
{},
|
|
212
|
+
{ sessionID: 'cost-probe' },
|
|
213
|
+
)
|
|
214
|
+
assertTokensOnly(
|
|
215
|
+
selectedOutput,
|
|
216
|
+
requestedVersion === 'v2'
|
|
217
|
+
? [
|
|
218
|
+
{ agent: 'aphrodite', phase: 'plan', input: 8, output: 10, total: 18 },
|
|
219
|
+
{ agent: 'zeus', phase: 'audit', input: 4, output: 6, total: 10 },
|
|
220
|
+
]
|
|
221
|
+
: [
|
|
222
|
+
{ agent: 'hermes', phase: 'plan', input: 13, output: 24, total: 37 },
|
|
223
|
+
{ agent: 'athena', phase: 'review', input: 2, output: 5, total: 7 },
|
|
224
|
+
],
|
|
225
|
+
requestedVersion === 'v2'
|
|
226
|
+
? { input: 12, output: 16, total: 28 }
|
|
227
|
+
: { input: 15, output: 29, total: 44 },
|
|
228
|
+
)
|
|
229
|
+
checks.push('version-selected DB: PASS')
|
|
230
|
+
} finally {
|
|
231
|
+
restore()
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const envRestore = setEnvironment({
|
|
235
|
+
XDG_DATA_HOME: dataHome,
|
|
236
|
+
PANTHEON_OPENCODE_VERSION: requestedVersion,
|
|
237
|
+
PANTHEON_COST_DB: envDb,
|
|
238
|
+
})
|
|
239
|
+
try {
|
|
240
|
+
const output = await createCostCommand().pantheon_cost.execute(
|
|
241
|
+
{},
|
|
242
|
+
{ sessionID: 'cost-probe' },
|
|
243
|
+
)
|
|
244
|
+
requireOutput(output, '| env-agent | override | 1 | 2 | 3 |', 'PANTHEON_COST_DB')
|
|
245
|
+
if (output.includes('wrong-version') || output.includes('env-agent') === false) {
|
|
246
|
+
throw new Error('PANTHEON_COST_DB did not override the version-selected database')
|
|
247
|
+
}
|
|
248
|
+
checks.push('PANTHEON_COST_DB override: PASS')
|
|
249
|
+
} finally {
|
|
250
|
+
envRestore()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const explicitRestore = setEnvironment({
|
|
254
|
+
XDG_DATA_HOME: dataHome,
|
|
255
|
+
PANTHEON_OPENCODE_VERSION: requestedVersion,
|
|
256
|
+
PANTHEON_COST_DB: envDb,
|
|
257
|
+
})
|
|
258
|
+
try {
|
|
259
|
+
const output = await createCostCommand({ dbPath: explicitDb }).pantheon_cost.execute(
|
|
260
|
+
{},
|
|
261
|
+
{ sessionID: 'cost-probe' },
|
|
262
|
+
)
|
|
263
|
+
requireOutput(output, '| explicit-agent | explicit | 9 | 1 | 10 |', 'explicit dbPath')
|
|
264
|
+
if (output.includes('env-agent')) throw new Error('explicit dbPath did not take precedence')
|
|
265
|
+
checks.push('explicit dbPath precedence: PASS')
|
|
266
|
+
} finally {
|
|
267
|
+
explicitRestore()
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const missingRestore = setEnvironment({
|
|
271
|
+
XDG_DATA_HOME: join(root, 'missing-data'),
|
|
272
|
+
PANTHEON_OPENCODE_VERSION: requestedVersion,
|
|
273
|
+
PANTHEON_COST_DB: undefined,
|
|
274
|
+
})
|
|
275
|
+
try {
|
|
276
|
+
const output = await createCostCommand().pantheon_cost.execute(
|
|
277
|
+
{},
|
|
278
|
+
{ sessionID: 'cost-probe' },
|
|
279
|
+
)
|
|
280
|
+
requireOutput(output, 'not found', 'missing DB')
|
|
281
|
+
requireOutput(
|
|
282
|
+
output,
|
|
283
|
+
requestedVersion === 'v2' ? 'opencode-v2.db' : 'opencode.db',
|
|
284
|
+
'selected missing DB path',
|
|
285
|
+
)
|
|
286
|
+
checks.push('missing DB: PASS')
|
|
287
|
+
} finally {
|
|
288
|
+
missingRestore()
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const incompatibleOutput = await createCostCommand({
|
|
292
|
+
dbPath: incompatibleDb,
|
|
293
|
+
}).pantheon_cost.execute({}, { sessionID: 'cost-probe' })
|
|
294
|
+
requireOutput(incompatibleOutput, 'incompatible opencode.db schema', 'incompatible schema')
|
|
295
|
+
checks.push('incompatible schema: PASS')
|
|
296
|
+
emit('PASS', 'offline synthetic DB checks passed; no real DB was read', checks)
|
|
297
|
+
} catch (error) {
|
|
298
|
+
emit('FAIL', error instanceof Error ? error.message : String(error), checks)
|
|
299
|
+
} finally {
|
|
300
|
+
rmSync(root, { recursive: true, force: true })
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
await main()
|