pantheon-opencode 1.6.1 → 1.6.2-beta.1
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/AGENTS.global.md +11 -11
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +16 -0
- package/README.md +91 -19
- package/README.pt-BR.md +14 -9
- package/bin/pantheon-init.mjs +106 -19
- package/package.json +3 -2
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +1 -1
- package/scripts/doctor.mjs +213 -45
- package/scripts/install/agents-md.mjs +2 -1
- package/scripts/install/config-migration.mjs +344 -393
- package/scripts/install/config-paths.mjs +15 -0
- package/scripts/install/mcp-permissions.mjs +164 -0
- package/scripts/install/opencode-version.mjs +31 -13
- package/scripts/install/opencode-wildcard.mjs +106 -0
- package/scripts/install/opencode.mjs +240 -69
- package/scripts/install/plan-artifact.mjs +12 -1
- package/scripts/install/plugin.mjs +17 -1
- package/scripts/install/v2-capabilities.mjs +5 -6
- package/scripts/package-evidence.mjs +1 -0
- package/scripts/sandbox-env.sh +174 -0
- package/scripts/setup-v2-config.mjs +1703 -0
- package/scripts/setup.mjs +415 -0
- package/scripts/sync-tui.mjs +9 -1
- package/scripts/test-opencode-v2-sandbox.sh +438 -151
- package/scripts/update-skills-lock.mjs +30 -0
- package/skills-lock.json +10 -10
- package/src/agents/aphrodite.md +5 -2
- package/src/agents/apollo.md +5 -0
- package/src/agents/athena.md +6 -1
- package/src/agents/demeter.md +5 -1
- package/src/agents/gaia.md +4 -0
- package/src/agents/hephaestus.md +6 -1
- package/src/agents/hermes.md +6 -3
- package/src/agents/iris.md +5 -1
- package/src/agents/mnemosyne.md +20 -50
- package/src/agents/nyx.md +5 -1
- package/src/agents/prometheus.md +4 -0
- package/src/agents/talos.md +4 -0
- package/src/agents/themis.md +4 -0
- package/src/agents/zeus.md +9 -3
- package/src/instructions/agent-return-format.instructions.md +1 -1
- package/src/instructions/memory-protocol.instructions.md +3 -3
- package/src/instructions/test-economy.instructions.md +6 -6
- package/src/mcp/pantheon_vision.py +37 -36
- package/src/pantheon/v2-vision.ts +34 -29
- package/src/pantheon/vision.ts +43 -10
- package/src/plugin-v2.ts +30 -53
- package/src/plugins/tui/dist/quota-adapters.d.ts +89 -0
- package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-adapters.js +1142 -0
- package/src/plugins/tui/dist/quota-adapters.js.map +1 -0
- package/src/plugins/tui/dist/quota-cli.d.ts +17 -0
- package/src/plugins/tui/dist/quota-cli.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-cli.js +184 -0
- package/src/plugins/tui/dist/quota-cli.js.map +1 -0
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js +390 -0
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +1 -0
- package/src/plugins/tui/dist/server-v2.d.ts +14 -0
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/server-v2.js +673 -0
- package/src/plugins/tui/dist/server-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui-v2.d.ts +247 -52
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +2492 -529
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/index-v2.ts +3 -6
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +3 -2
- package/src/plugins/tui/src/context-gauge.ts +59 -0
- package/src/plugins/tui/src/go-key-diagnostic-ui.ts +100 -0
- package/src/plugins/tui/src/go-key-diagnostic.ts +125 -0
- package/src/plugins/tui/src/index-v2.tsx +199 -240
- package/src/plugins/tui/src/model-usage-limits.ts +4 -0
- package/src/plugins/tui/src/quota-adapters.ts +1598 -0
- package/src/plugins/tui/src/quota-cli.ts +237 -0
- package/src/plugins/tui/src/quota-rpc.ts +209 -0
- package/src/plugins/tui/src/quota-v2-model.ts +1032 -0
- package/src/plugins/tui/src/quota-v2.tsx +986 -0
- package/src/plugins/tui/src/server-v2.ts +841 -0
- package/src/plugins/tui/src/sidebar-width.ts +129 -0
- package/src/plugins/tui/tsconfig.typecheck.json +1 -1
- package/src/plugins/tui/tsdown.config.ts +8 -1
- package/src/routing.yml +72 -13
- package/src/skills/README.md +4 -0
- package/src/skills/agent-coordination/SKILL.md +0 -3
- package/src/skills/artifact-management/SKILL.md +0 -3
- package/src/skills/auto-continue/SKILL.md +0 -3
- package/src/skills/code-review-checklist/SKILL.md +0 -3
- package/src/skills/context-compression/SKILL.md +0 -3
- package/src/skills/memory-bank/SKILL.md +6 -28
- package/src/skills/session-goal/SKILL.md +0 -3
- package/src/skills/simplify/SKILL.md +5 -4
- package/src/skills/tdd-with-agents/SKILL.md +0 -3
- package/src/skills/visual-review-pipeline/SKILL.md +0 -1
- 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
|
|
97
|
-
* relayed as an MCP `session_id` instruction: the
|
|
98
|
-
* process the host hands no session id to, and the Zen
|
|
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
|
-
|
|
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(
|
|
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
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
|
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 = '
|
|
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
|
-
|
|
594
|
+
sessionID: call.sessionID,
|
|
590
595
|
}
|
|
591
596
|
let failure: NativeVisionFailure | undefined
|
|
592
597
|
const output = await describeImagesNative(
|
package/src/pantheon/vision.ts
CHANGED
|
@@ -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):
|
|
2148
|
-
|
|
2149
|
-
|
|
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
|
|
2188
|
+
return {
|
|
2189
|
+
value: inParts ? syntheticHistoryPart(historyMessage, text) : { type: 'text', text },
|
|
2190
|
+
changed: true,
|
|
2191
|
+
}
|
|
2168
2192
|
}
|
|
2169
2193
|
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
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)
|
|
2178
|
-
|
|
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
|
}
|
package/src/plugin-v2.ts
CHANGED
|
@@ -108,12 +108,6 @@ import {
|
|
|
108
108
|
} from './pantheon/delegation-enforce.ts'
|
|
109
109
|
import { GOAL_LOOP_DEFAULTS, GoalStore } from './pantheon/goal-loop.ts'
|
|
110
110
|
import { createGuardPathResolver } from './pantheon/guard-path.ts'
|
|
111
|
-
import {
|
|
112
|
-
applyMemoryInjection,
|
|
113
|
-
MemoryInjectionCache,
|
|
114
|
-
resolveMemoryInjectionConfig,
|
|
115
|
-
warnInvalidMemoryInjectionConfig,
|
|
116
|
-
} from './pantheon/memory-context.ts'
|
|
117
111
|
import { getSharedBoard } from './pantheon/shared-board.ts'
|
|
118
112
|
import {
|
|
119
113
|
TODO_ENFORCER_DEFAULTS,
|
|
@@ -895,7 +889,6 @@ async function onSessionDeleted(event: V2SessionEvent): Promise<void> {
|
|
|
895
889
|
return
|
|
896
890
|
}
|
|
897
891
|
readOnlyRegistry.unregister(sessionID)
|
|
898
|
-
memoryInjectionCache.delete(sessionID)
|
|
899
892
|
}
|
|
900
893
|
|
|
901
894
|
/**
|
|
@@ -918,17 +911,35 @@ async function onSessionCompacted(_event: V2SessionEvent): Promise<void> {}
|
|
|
918
911
|
|
|
919
912
|
// ─── V2 Session Hooks ───────────────────────────────────────────────────
|
|
920
913
|
|
|
921
|
-
/**
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
914
|
+
/** One entry per no-op reason and session/site; successful passes retain each saving. */
|
|
915
|
+
const pruneSkipSessions = new Set<string>()
|
|
916
|
+
const PRUNE_SKIP_SESSIONS_MAX = 256
|
|
917
|
+
|
|
918
|
+
function logContextPrune(stats: PruneStats, sessionID: unknown): void {
|
|
919
|
+
if (stats.changed) {
|
|
920
|
+
appendV2HookLog(
|
|
921
|
+
`[context-pruner] site=${stats.site} messages=${stats.messagesTouched} ` +
|
|
922
|
+
`parts=${stats.partsPruned} est_tokens_saved=${stats.estimatedTokensSaved}`,
|
|
923
|
+
)
|
|
924
|
+
return
|
|
925
|
+
}
|
|
926
|
+
if (
|
|
927
|
+
stats.skipReason === null ||
|
|
928
|
+
stats.skipReason === 'not-array' ||
|
|
929
|
+
stats.skipReason === 'malformed'
|
|
930
|
+
) {
|
|
931
|
+
return
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const session = typeof sessionID === 'string' && sessionID !== '' ? sessionID : 'unknown'
|
|
935
|
+
const key = `${stats.site}:${session}:${stats.skipReason}`
|
|
936
|
+
if (pruneSkipSessions.has(key)) return
|
|
937
|
+
if (pruneSkipSessions.size >= PRUNE_SKIP_SESSIONS_MAX) pruneSkipSessions.clear()
|
|
938
|
+
pruneSkipSessions.add(key)
|
|
929
939
|
appendV2HookLog(
|
|
930
|
-
`[context-pruner] site=${stats.site}
|
|
931
|
-
`
|
|
940
|
+
`[context-pruner] site=${stats.site} skip=${stats.skipReason} ` +
|
|
941
|
+
`messages=${stats.messagesTouched} parts=${stats.partsPruned} ` +
|
|
942
|
+
`est_tokens_saved=${stats.estimatedTokensSaved}`,
|
|
932
943
|
)
|
|
933
944
|
}
|
|
934
945
|
|
|
@@ -989,17 +1000,6 @@ function warnContextPrunerConfigOnce(options: unknown): void {
|
|
|
989
1000
|
}
|
|
990
1001
|
}
|
|
991
1002
|
|
|
992
|
-
// ─── Ambient memory injection (opt-in, V2 context hook) ─────────────────
|
|
993
|
-
|
|
994
|
-
/**
|
|
995
|
-
* One payload per session, computed on the session's first request. Bounded by
|
|
996
|
-
* `MEMORY_CACHE_MAX_SESSIONS` inside the cache (FIFO), so a long-lived host
|
|
997
|
-
* cannot grow it without limit. The payload is built, rendered and logged by
|
|
998
|
-
* `memory-context.ts`; this module only supplies the hook wiring and the
|
|
999
|
-
* `hooks.log` channel.
|
|
1000
|
-
*/
|
|
1001
|
-
const memoryInjectionCache = new MemoryInjectionCache()
|
|
1002
|
-
|
|
1003
1003
|
/**
|
|
1004
1004
|
* Empty description cache for {@link sanitizeVisionHistory}.
|
|
1005
1005
|
*
|
|
@@ -1024,7 +1024,6 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
1024
1024
|
// Config validity is independent of hook availability; warn before the early
|
|
1025
1025
|
// return so a typo is visible even on a host that registers no session hook.
|
|
1026
1026
|
warnContextPrunerConfigOnce(context.options)
|
|
1027
|
-
warnInvalidMemoryInjectionConfig(context.options, appendV2HookLog)
|
|
1028
1027
|
const sessionCtx = hostDomains(context).session
|
|
1029
1028
|
|
|
1030
1029
|
if (!sessionCtx?.hook) {
|
|
@@ -1037,11 +1036,6 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
1037
1036
|
// applies the rules unconditionally.
|
|
1038
1037
|
const prunerConfig = resolveContextPrunerConfig(context.options)
|
|
1039
1038
|
|
|
1040
|
-
// Ambient memory injection is opt-in and default OFF: with `enabled: false`
|
|
1041
|
-
// this hook adds nothing, so `system` stays byte-identical to the policy-only
|
|
1042
|
-
// output. Resolved here (not per request) for the same reason as the pruner.
|
|
1043
|
-
const memoryConfig = resolveMemoryInjectionConfig(context.options)
|
|
1044
|
-
|
|
1045
1039
|
let registered = false
|
|
1046
1040
|
|
|
1047
1041
|
try {
|
|
@@ -1078,23 +1072,6 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
1078
1072
|
normalized.push({ type: 'text', text: POLICY } satisfies SystemPart)
|
|
1079
1073
|
}
|
|
1080
1074
|
}
|
|
1081
|
-
// Opt-in ambient memory injection: the top-K memories relevant to the
|
|
1082
|
-
// session's first user message, computed once per session and re-added
|
|
1083
|
-
// verbatim on later requests. Deliberately OUTSIDE the block above: with
|
|
1084
|
-
// `enabled: true` and no usable `system` there is nowhere to push, and
|
|
1085
|
-
// the module reports `skip=no-system` once per session instead of the
|
|
1086
|
-
// feature going silently inert. Off by default, so this is the only
|
|
1087
|
-
// thing `enabled: false` skips.
|
|
1088
|
-
if (memoryConfig.enabled) {
|
|
1089
|
-
applyMemoryInjection(
|
|
1090
|
-
normalized ?? ctx.system,
|
|
1091
|
-
ctx.messages,
|
|
1092
|
-
ctx.sessionID,
|
|
1093
|
-
memoryConfig,
|
|
1094
|
-
memoryInjectionCache,
|
|
1095
|
-
appendV2HookLog,
|
|
1096
|
-
)
|
|
1097
|
-
}
|
|
1098
1075
|
// Vision history sanitization (V1
|
|
1099
1076
|
// `experimental.chat.messages.transform` parity, #266). Image parts are
|
|
1100
1077
|
// replaced with their cached description, or with the same placeholder
|
|
@@ -1120,7 +1097,7 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
1120
1097
|
if (prunerConfig.enabled) {
|
|
1121
1098
|
try {
|
|
1122
1099
|
const stats = pruneMessages(ctx.messages, prunerConfig, 'context')
|
|
1123
|
-
logContextPrune(stats)
|
|
1100
|
+
logContextPrune(stats, ctx.sessionID)
|
|
1124
1101
|
logPruneShapeIssue(stats, ctx.sessionID, 'context')
|
|
1125
1102
|
} catch (error) {
|
|
1126
1103
|
logPruneFailureOnce(ctx.sessionID, 'context', error)
|
|
@@ -2227,7 +2204,7 @@ export const plugin = define({
|
|
|
2227
2204
|
: undefined
|
|
2228
2205
|
const prunerConfig = resolveContextPrunerConfig(context.options)
|
|
2229
2206
|
const stats = pruneMessages(payload?.messages, prunerConfig, 'compaction')
|
|
2230
|
-
logContextPrune(stats)
|
|
2207
|
+
logContextPrune(stats, sessionID)
|
|
2231
2208
|
logPruneShapeIssue(stats, sessionID, 'compaction')
|
|
2232
2209
|
|
|
2233
2210
|
// Compaction context (V1 `experimental.session.compacting`
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { queryAlibabaTokenPlanUsage } from "./quota-cli.js";
|
|
2
|
+
//#region src/quota-rpc.d.ts
|
|
3
|
+
/** Full provider matrix approved for the V2 quota surface. */
|
|
4
|
+
declare const QUOTA_PROVIDER_IDS: readonly ['anthropic', 'chutes', 'cursor', 'github-copilot', 'google-agy', 'kilo-gateway', 'nanogpt', 'ollama-cloud', 'openai', 'opencode-go', 'opencode-zen', 'openrouter', 'synthetic', 'xai-supergrok', 'gemini-cli', 'alibaba-coding-plan', 'alibaba-token-plan', 'deepseek', 'kimi-code-global', 'kimi-code-cn', 'minimax-plan-global', 'minimax-plan-cn', 'xiaomi-mimo', 'zai-coding-plan', 'zhipu-coding-plan'];
|
|
5
|
+
type QuotaProviderId = (typeof QUOTA_PROVIDER_IDS)[number];
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/quota-adapters.d.ts
|
|
8
|
+
export declare const OPENAI_CODEX_OAUTH_METHOD_IDS: readonly ['chatgpt-browser', 'chatgpt-headless'];
|
|
9
|
+
type OpenAICodexOAuthMethodID = (typeof OPENAI_CODEX_OAUTH_METHOD_IDS)[number];
|
|
10
|
+
export declare function isOpenAICodexOAuthMethod(value: unknown): value is OpenAICodexOAuthMethodID;
|
|
11
|
+
export declare const OPENCODE_CONSOLE_OAUTH_METHOD_IDS: readonly ['device'];
|
|
12
|
+
type OpenCodeConsoleOAuthMethodID = (typeof OPENCODE_CONSOLE_OAUTH_METHOD_IDS)[number];
|
|
13
|
+
export declare function isOpenCodeConsoleOAuthMethod(value: unknown): value is OpenCodeConsoleOAuthMethodID;
|
|
14
|
+
type OAuthMethodID = OpenAICodexOAuthMethodID | OpenCodeConsoleOAuthMethodID;
|
|
15
|
+
export type QuotaAdapterContext = {
|
|
16
|
+
readonly projectId?: string;
|
|
17
|
+
readonly accountId?: string;
|
|
18
|
+
readonly orgId?: string;
|
|
19
|
+
readonly methodID?: OAuthMethodID;
|
|
20
|
+
};
|
|
21
|
+
export type QuotaAudience = 'us_personal' | 'us_business' | 'china_personal' | 'china_business';
|
|
22
|
+
export type QuotaMetric = {
|
|
23
|
+
kind: 'provider_quota';
|
|
24
|
+
used: number;
|
|
25
|
+
remaining: number;
|
|
26
|
+
unit: string;
|
|
27
|
+
label: string;
|
|
28
|
+
period?: string;
|
|
29
|
+
resetsAt?: number;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'balance';
|
|
32
|
+
amount: number;
|
|
33
|
+
currency: 'USD' | 'CNY';
|
|
34
|
+
label: string;
|
|
35
|
+
status?: 'available' | 'unavailable' | 'active' | 'inactive';
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'estimate';
|
|
38
|
+
amount: number;
|
|
39
|
+
unit: string;
|
|
40
|
+
label: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'provider_status';
|
|
43
|
+
status: 'available' | 'unavailable' | 'active' | 'inactive';
|
|
44
|
+
label: string;
|
|
45
|
+
} | {
|
|
46
|
+
kind: 'key_usage';
|
|
47
|
+
amount: number;
|
|
48
|
+
currency: 'USD' | 'CNY';
|
|
49
|
+
label: string;
|
|
50
|
+
period?: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'session_usage';
|
|
53
|
+
amount: number;
|
|
54
|
+
unit: string;
|
|
55
|
+
label: string;
|
|
56
|
+
};
|
|
57
|
+
export type AdapterFailureReason = 'provider_error' | 'not_subscribed' | 'rate_limited' | 'unauthorized' | 'forbidden' | 'timeout' | 'network_error' | 'invalid_response' | 'cli_identity_unavailable' | 'eligibility_unverified';
|
|
58
|
+
export type AdapterFailure = {
|
|
59
|
+
readonly reason: AdapterFailureReason;
|
|
60
|
+
readonly retryAfterMs?: number;
|
|
61
|
+
};
|
|
62
|
+
type ProviderDefinition = {
|
|
63
|
+
readonly label: string;
|
|
64
|
+
readonly integrationID: string;
|
|
65
|
+
readonly fallbackIntegrationIDs?: readonly string[];
|
|
66
|
+
readonly audiences: readonly QuotaAudience[];
|
|
67
|
+
readonly scope: 'account' | 'selected_key' | 'team' | 'session';
|
|
68
|
+
readonly methods: readonly ('key' | 'oauth' | 'cli')[];
|
|
69
|
+
readonly source?: 'integration' | 'local-cli';
|
|
70
|
+
readonly adapter?: 'anthropic' | 'chutes' | 'copilot' | 'deepseek' | 'google-agy' | 'alibaba-token-plan-cli' | 'kilo-gateway' | 'kimi-global' | 'kimi-cn' | 'minimax-global' | 'minimax-cn' | 'nanogpt' | 'ollama-cloud' | 'openai' | 'openrouter' | 'opencode-go' | 'opencode-zen' | 'synthetic' | 'xai-supergrok' | 'zai' | 'zhipu';
|
|
71
|
+
readonly blockedReason?: 'unsupported' | 'private_endpoint' | 'eligibility_unverified' | 'runtime_accounting_unavailable' | 'cli_identity_unavailable';
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Closed provider/integration/method allowlist. Only rows with a reviewed
|
|
75
|
+
* adapter may make a network request; remaining rows are explicitly blocked.
|
|
76
|
+
* Audience lists describe the approved matrix and do not claim that account
|
|
77
|
+
* type was inferred from credentials.
|
|
78
|
+
*/
|
|
79
|
+
export declare const QUOTA_PROVIDER_CATALOG: Record<QuotaProviderId, ProviderDefinition>;
|
|
80
|
+
export type AdapterResult = {
|
|
81
|
+
readonly state: 'available';
|
|
82
|
+
readonly metrics: QuotaMetric[];
|
|
83
|
+
readonly routeKind?: 'api_key' | 'console_oauth';
|
|
84
|
+
} | (AdapterFailure & {
|
|
85
|
+
readonly routeKind?: 'api_key' | 'console_oauth';
|
|
86
|
+
});
|
|
87
|
+
export declare function runQuotaAdapter(provider: QuotaProviderId, secret: string | undefined, shutdownSignal: AbortSignal, queryCli?: typeof queryAlibabaTokenPlanUsage, adapterContext?: QuotaAdapterContext, fallbackSecret?: string): Promise<AdapterResult>;
|
|
88
|
+
//#endregion
|
|
89
|
+
//# sourceMappingURL=quota-adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota-adapters.d.ts","names":[],"sources":["../src/quota-rpc.ts","../src/quota-adapters.ts"],"mappings":";;;cAGa;KA4BD,0BAA0B;;;qBC1BzB;KACR,mCAAmC;wBAExB,yBAAyB,iBAAiB,SAAS;qBAQtD;KACR,uCAAuC;wBAE5B,6BACd,iBACC,SAAS;KAOP,gBAAgB,2BAA2B;YAEpC;WACD;WACA;WACA;WACA,WAAW;;YAGV;YACA;EAEN;EACA;EACA;EACA;EACA;EACA;EACA;;EAGA;EACA;EACA;EACA;EACA;;EAEA;EAAkB;EAAgB;EAAc;;EAEhD;EACA;EACA;;EAGA;EACA;EACA;EACA;EACA;;EAEA;EAAuB;EAAgB;EAAc;;YAE/C;YAWA;WACD,QAAQ;WACR;;KAGN;WACM;WACA;WACA;WACA,oBAAoB;WACpB;WACA;WACA;WACA;WAsBA;;;;;;;;qBAsBE,wBAAwB,OAAO,iBAAiB;YAqNjD;WAEG;WACA,SAAS;WACT;KAEV;WAA4B;;wBA2/BX,gBACpB,UAAU,iBACV,4BACA,gBAAgB,aAChB,kBAAiB,4BACjB,iBAAgB,qBAChB,0BACC,QAAQ"}
|