pantheon-opencode 1.6.2-beta.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.
- package/CHANGELOG.md +163 -0
- package/README.md +236 -60
- package/README.pt-BR.md +19 -1
- package/bin/pantheon-init.mjs +195 -13
- package/package.json +11 -3
- package/plugin.json +1 -1
- package/prompts/README.md +58 -0
- package/prompts/debug-issue.prompt.md +46 -0
- package/prompts/dynamic/agora-generated.txt +38 -0
- package/prompts/dynamic/orchestrate-generated.txt +51 -0
- package/prompts/focus.prompt.md +42 -0
- package/prompts/implement-feature.prompt.md +39 -0
- package/prompts/optimize-database.prompt.md +58 -0
- package/prompts/orchestrate-with-zeus.prompt.md +441 -0
- package/prompts/plan-architecture.prompt.md +59 -0
- package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
- package/prompts/quick-plan-large-feature.prompt.md +197 -0
- package/prompts/semantic-summarize.md +50 -0
- package/prompts/sketch.prompt.md +91 -0
- package/prompts/subtask.prompt.md +131 -0
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +780 -0
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +758 -0
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/component-selection.mjs +9 -4
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +560 -0
- package/scripts/install/health-check.mjs +20 -11
- package/scripts/install/interactive.mjs +103 -14
- package/scripts/install/interrupt.mjs +4 -3
- package/scripts/install/migrate.mjs +123 -72
- package/scripts/install/opencode.mjs +178 -122
- package/scripts/install/plan.mjs +8 -1
- package/scripts/install/plugin.mjs +4 -3
- package/scripts/install/state.mjs +12 -0
- package/scripts/install/strings.mjs +22 -0
- package/scripts/install/venv.mjs +34 -17
- package/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/restore.mjs +22 -10
- package/scripts/sync-tui.mjs +3 -3
- package/scripts/test-opencode-v2-sandbox.sh +10 -6
- package/scripts/versioning.mjs +41 -5
- package/src/agents/aphrodite.md +6 -1
- package/src/agents/apollo.md +1 -0
- package/src/agents/athena.md +1 -0
- package/src/agents/demeter.md +1 -1
- package/src/agents/gaia.md +1 -0
- package/src/agents/hephaestus.md +1 -1
- package/src/agents/hermes.md +8 -10
- package/src/agents/iris.md +1 -1
- package/src/agents/mnemosyne.md +1 -0
- package/src/agents/nyx.md +1 -1
- package/src/agents/prometheus.md +1 -1
- package/src/agents/talos.md +6 -1
- package/src/agents/themis.md +1 -1
- package/src/agents/zeus.md +52 -62
- package/src/mcp/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- package/src/pantheon/cost-command.ts +30 -133
- package/src/pantheon/jev-decision-tool.ts +347 -0
- package/src/pantheon/jev-decisions.ts +625 -0
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1046 -0
- package/src/pantheon/local-decision-egress-gate.ts +144 -0
- package/src/pantheon/local-decision-prompt.ts +256 -0
- package/src/pantheon/local-decision-provider-matrix.ts +44 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +281 -0
- package/src/pantheon/local-decision-tool.ts +160 -0
- package/src/pantheon/local-decision-turn.ts +101 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +168 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/model-pricing.ts +1 -536
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-decision-budget.ts +456 -0
- package/src/pantheon/v2-decision-contracts.ts +300 -0
- package/src/pantheon/v2-decision-egress.ts +203 -0
- package/src/pantheon/v2-decision-events.ts +180 -0
- package/src/pantheon/v2-decision-heuristic.ts +121 -0
- package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
- package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
- package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
- package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
- package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
- package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
- package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
- package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
- package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
- package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
- package/src/pantheon/v2-decision-points.ts +242 -0
- package/src/pantheon/v2-decision-policy.ts +166 -0
- package/src/pantheon/v2-decision-premises.ts +146 -0
- package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
- package/src/pantheon/v2-decision-rank.ts +91 -0
- package/src/pantheon/v2-decision-registry.ts +391 -0
- package/src/pantheon/v2-decision-resource-ids.ts +127 -0
- package/src/pantheon/v2-decision-shadow.ts +123 -0
- package/src/pantheon/v2-decision-telemetry.ts +214 -0
- package/src/pantheon/v2-decision-verify.ts +51 -0
- package/src/pantheon/v2-hook-engine.ts +307 -0
- package/src/pantheon/v2-native-decisions.ts +365 -0
- package/src/pantheon/v2-shell-hooks.ts +66 -2
- package/src/pantheon/v2-tools.ts +38 -15
- package/src/plugin-v2.ts +419 -26
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
- package/src/plugins/tui/dist/server-v2.d.ts +19 -11
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/server-v2.js +19 -666
- package/src/plugins/tui/dist/server-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui-v2.d.ts +11 -203
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +187 -1917
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +17 -2
- package/src/plugins/tui/package.json +4 -2
- package/src/plugins/tui/src/cost-data.ts +607 -0
- package/src/plugins/tui/src/index-v2.tsx +213 -54
- package/src/plugins/tui/src/model-pricing.ts +536 -0
- package/src/plugins/tui/src/server-v2.ts +18 -838
- package/src/plugins/tui/tsdown.config.ts +28 -6
- package/src/plugins/tui/dist/quota-adapters.d.ts +0 -89
- package/src/plugins/tui/dist/quota-adapters.d.ts.map +0 -1
- package/src/plugins/tui/dist/quota-adapters.js +0 -1142
- package/src/plugins/tui/dist/quota-adapters.js.map +0 -1
- package/src/plugins/tui/dist/quota-cli.d.ts +0 -17
- package/src/plugins/tui/dist/quota-cli.d.ts.map +0 -1
- package/src/plugins/tui/dist/quota-cli.js +0 -184
- package/src/plugins/tui/dist/quota-cli.js.map +0 -1
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js +0 -390
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +0 -1
- package/src/plugins/tui/src/go-key-diagnostic-ui.ts +0 -100
- package/src/plugins/tui/src/go-key-diagnostic.ts +0 -125
- package/src/plugins/tui/src/quota-adapters.ts +0 -1598
- package/src/plugins/tui/src/quota-cli.ts +0 -237
- package/src/plugins/tui/src/quota-rpc.ts +0 -209
- package/src/plugins/tui/src/quota-v2-model.ts +0 -1032
- package/src/plugins/tui/src/quota-v2.tsx +0 -986
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offline scaffolding for OpenCode V2.2.5's native Decisions API.
|
|
3
|
+
*
|
|
4
|
+
* This module intentionally has no host call site. It resolves only model refs
|
|
5
|
+
* already present in the host model catalog, prepares a minimal current-turn
|
|
6
|
+
* request, and consumes a mocked/host response as non-authoritative advice.
|
|
7
|
+
* Nothing here calls a provider, reads credentials, or changes host behavior.
|
|
8
|
+
*/
|
|
9
|
+
import type { Model } from '@opencode/plugin'
|
|
10
|
+
import type { Context } from '@opencode/plugin/promise/plugin'
|
|
11
|
+
import type { SessionPrompt } from '@opencode/plugin/promise/session'
|
|
12
|
+
import { PANTHEON_AGENT_CATALOG } from './pantheon-decision-catalog.ts'
|
|
13
|
+
|
|
14
|
+
export const NATIVE_DECISION_ANSWER_NAME = 'specialist'
|
|
15
|
+
export const NATIVE_DECISION_MAX_PROMPT_LENGTH = 12_000
|
|
16
|
+
|
|
17
|
+
type NativeDecisionGenerator = Context['experimental']['generate']['decisions']
|
|
18
|
+
export type NativeDecisionRequest = Parameters<NativeDecisionGenerator>[0]
|
|
19
|
+
export type NativeDecisionResponse = Awaited<ReturnType<NativeDecisionGenerator>>
|
|
20
|
+
export type NativeDecisionModelRef = NativeDecisionRequest['model']
|
|
21
|
+
|
|
22
|
+
export const NATIVE_STOCK_DECISION_ROUTES = Object.freeze([
|
|
23
|
+
Object.freeze({
|
|
24
|
+
providerID: 'opencode',
|
|
25
|
+
id: 'jev-1.13',
|
|
26
|
+
kind: 'opencode-console-jev',
|
|
27
|
+
billing: 'OpenCode Console',
|
|
28
|
+
}),
|
|
29
|
+
Object.freeze({
|
|
30
|
+
providerID: 'openrouter',
|
|
31
|
+
id: 'typesafe/jev-1.13',
|
|
32
|
+
kind: 'openrouter-jev',
|
|
33
|
+
billing: 'OpenRouter',
|
|
34
|
+
}),
|
|
35
|
+
] as const)
|
|
36
|
+
|
|
37
|
+
type NativeDecisionRouteKind =
|
|
38
|
+
| (typeof NATIVE_STOCK_DECISION_ROUTES)[number]['kind']
|
|
39
|
+
| 'custom-decision'
|
|
40
|
+
|
|
41
|
+
export interface ResolvedNativeDecisionRoute {
|
|
42
|
+
readonly model: NativeDecisionModelRef
|
|
43
|
+
readonly kind: NativeDecisionRouteKind
|
|
44
|
+
readonly billing: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type NativeDecisionRouteFailure =
|
|
48
|
+
| 'AUTO_MODEL_UNAVAILABLE'
|
|
49
|
+
| 'INVALID_MODEL_REF'
|
|
50
|
+
| 'DIRECT_OPENAI_UNSUPPORTED'
|
|
51
|
+
| 'MODEL_NOT_IN_CATALOG'
|
|
52
|
+
| 'AMBIGUOUS_MODEL'
|
|
53
|
+
| 'MODEL_NOT_DECISION'
|
|
54
|
+
|
|
55
|
+
export type NativeDecisionRouteResolution =
|
|
56
|
+
| { readonly ok: true; readonly route: ResolvedNativeDecisionRoute }
|
|
57
|
+
| { readonly ok: false; readonly reasonCode: NativeDecisionRouteFailure }
|
|
58
|
+
|
|
59
|
+
export type NativeDecisionSelection = 'auto' | NativeDecisionModelRef
|
|
60
|
+
|
|
61
|
+
type DecisionModelCatalogEntry = Pick<Model.Info, 'providerID' | 'id' | 'type'>
|
|
62
|
+
|
|
63
|
+
function readModelRef(value: unknown): NativeDecisionModelRef | null {
|
|
64
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return null
|
|
65
|
+
const record = value as Record<string, unknown>
|
|
66
|
+
if (
|
|
67
|
+
typeof record.providerID !== 'string' ||
|
|
68
|
+
record.providerID.length === 0 ||
|
|
69
|
+
record.providerID.trim() !== record.providerID ||
|
|
70
|
+
typeof record.id !== 'string' ||
|
|
71
|
+
record.id.length === 0 ||
|
|
72
|
+
record.id.trim() !== record.id ||
|
|
73
|
+
(record.variant !== undefined && typeof record.variant !== 'string')
|
|
74
|
+
) {
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
providerID: record.providerID,
|
|
79
|
+
id: record.id,
|
|
80
|
+
...(record.variant === undefined ? {} : { variant: record.variant }),
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function findRouteKind(
|
|
85
|
+
model: NativeDecisionModelRef,
|
|
86
|
+
): Pick<ResolvedNativeDecisionRoute, 'kind' | 'billing'> {
|
|
87
|
+
const stock = NATIVE_STOCK_DECISION_ROUTES.find(
|
|
88
|
+
(candidate) => candidate.providerID === model.providerID && candidate.id === model.id,
|
|
89
|
+
)
|
|
90
|
+
if (stock !== undefined) return { kind: stock.kind, billing: stock.billing }
|
|
91
|
+
if (model.providerID === 'openrouter') {
|
|
92
|
+
return { kind: 'custom-decision', billing: 'OpenRouter' }
|
|
93
|
+
}
|
|
94
|
+
if (model.providerID === 'opencode') {
|
|
95
|
+
return { kind: 'custom-decision', billing: 'OpenCode Console' }
|
|
96
|
+
}
|
|
97
|
+
return { kind: 'custom-decision', billing: 'Provider configured in OpenCode' }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Resolve Auto strictly against the exact effective session model. It never
|
|
102
|
+
* searches for a substitute, changes providers, or infers decision capability
|
|
103
|
+
* from a chat model's provider or id.
|
|
104
|
+
*/
|
|
105
|
+
export function resolveNativeDecisionRoute(
|
|
106
|
+
selection: NativeDecisionSelection,
|
|
107
|
+
effectiveSessionModel: unknown,
|
|
108
|
+
modelCatalog: readonly DecisionModelCatalogEntry[],
|
|
109
|
+
): NativeDecisionRouteResolution {
|
|
110
|
+
const requested =
|
|
111
|
+
selection === 'auto' ? readModelRef(effectiveSessionModel) : readModelRef(selection)
|
|
112
|
+
if (selection === 'auto' && requested === null) {
|
|
113
|
+
return { ok: false, reasonCode: 'AUTO_MODEL_UNAVAILABLE' }
|
|
114
|
+
}
|
|
115
|
+
if (requested === null) return { ok: false, reasonCode: 'INVALID_MODEL_REF' }
|
|
116
|
+
if (requested.providerID === 'openai') {
|
|
117
|
+
return { ok: false, reasonCode: 'DIRECT_OPENAI_UNSUPPORTED' }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const matches = modelCatalog.filter(
|
|
121
|
+
(model) => model.providerID === requested.providerID && model.id === requested.id,
|
|
122
|
+
)
|
|
123
|
+
if (matches.length === 0) return { ok: false, reasonCode: 'MODEL_NOT_IN_CATALOG' }
|
|
124
|
+
if (matches.length !== 1) return { ok: false, reasonCode: 'AMBIGUOUS_MODEL' }
|
|
125
|
+
if (matches[0]?.type !== 'decision') {
|
|
126
|
+
return { ok: false, reasonCode: 'MODEL_NOT_DECISION' }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
ok: true,
|
|
131
|
+
route: Object.freeze({ model: requested, ...findRouteKind(requested) }),
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface NativeDecisionConsentEntry {
|
|
136
|
+
readonly providerID: string
|
|
137
|
+
readonly modelID: string
|
|
138
|
+
readonly enabled: boolean
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type NativeDecisionConsentResult =
|
|
142
|
+
| { readonly allowed: true; readonly reasonCode: 'EXACT_ROUTE_CONSENT' }
|
|
143
|
+
| {
|
|
144
|
+
readonly allowed: false
|
|
145
|
+
readonly reasonCode: 'CONSENT_MISSING' | 'CONSENT_AMBIGUOUS' | 'CONSENT_DISABLED'
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Pure provider+model-specific consent check. Missing consent is always off. */
|
|
149
|
+
export function evaluateNativeDecisionConsent(
|
|
150
|
+
route: ResolvedNativeDecisionRoute,
|
|
151
|
+
entries: readonly NativeDecisionConsentEntry[] = [],
|
|
152
|
+
): NativeDecisionConsentResult {
|
|
153
|
+
const exact = entries.filter(
|
|
154
|
+
(entry) => entry.providerID === route.model.providerID && entry.modelID === route.model.id,
|
|
155
|
+
)
|
|
156
|
+
if (exact.length === 0) return { allowed: false, reasonCode: 'CONSENT_MISSING' }
|
|
157
|
+
if (exact.length !== 1) return { allowed: false, reasonCode: 'CONSENT_AMBIGUOUS' }
|
|
158
|
+
if (exact[0]?.enabled !== true) return { allowed: false, reasonCode: 'CONSENT_DISABLED' }
|
|
159
|
+
return { allowed: true, reasonCode: 'EXACT_ROUTE_CONSENT' }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Evidence required to bind a prompt callback to exactly one current turn.
|
|
164
|
+
* OpenCode V2.2.5's SessionPrompt event does not supply these queue/activity
|
|
165
|
+
* facts, so this contract is currently test-only and cannot authorize a call.
|
|
166
|
+
*/
|
|
167
|
+
export interface NativeDecisionCorrelationEvidence {
|
|
168
|
+
readonly sessionID: string
|
|
169
|
+
readonly messageID: string
|
|
170
|
+
readonly currentMessageID: string
|
|
171
|
+
readonly delivery: 'steer' | 'queue'
|
|
172
|
+
readonly pendingMessageIDs: readonly string[]
|
|
173
|
+
readonly activeMessageID: string | null
|
|
174
|
+
readonly continuation: boolean
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type NativeDecisionCorrelationFailure =
|
|
178
|
+
| 'CORRELATION_UNAVAILABLE'
|
|
179
|
+
| 'CORRELATION_MISMATCH'
|
|
180
|
+
| 'QUEUED_TURN'
|
|
181
|
+
| 'CONCURRENT_TURN'
|
|
182
|
+
| 'CONTINUATION_TURN'
|
|
183
|
+
|
|
184
|
+
function isNonBlankID(value: unknown): value is string {
|
|
185
|
+
return typeof value === 'string' && value.trim().length > 0
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function validateNativeDecisionCorrelation(
|
|
189
|
+
event: SessionPrompt,
|
|
190
|
+
evidence: NativeDecisionCorrelationEvidence | undefined,
|
|
191
|
+
): NativeDecisionCorrelationFailure | null {
|
|
192
|
+
if (event === null || typeof event !== 'object' || Array.isArray(event)) {
|
|
193
|
+
return 'CORRELATION_MISMATCH'
|
|
194
|
+
}
|
|
195
|
+
if (!isNonBlankID(event.sessionID) || !isNonBlankID(event.messageID)) {
|
|
196
|
+
return 'CORRELATION_MISMATCH'
|
|
197
|
+
}
|
|
198
|
+
if (evidence === undefined) return 'CORRELATION_UNAVAILABLE'
|
|
199
|
+
if (evidence === null || typeof evidence !== 'object' || Array.isArray(evidence)) {
|
|
200
|
+
return 'CORRELATION_UNAVAILABLE'
|
|
201
|
+
}
|
|
202
|
+
if (
|
|
203
|
+
!isNonBlankID(evidence.sessionID) ||
|
|
204
|
+
!isNonBlankID(evidence.messageID) ||
|
|
205
|
+
!isNonBlankID(evidence.currentMessageID) ||
|
|
206
|
+
(evidence.delivery !== 'steer' && evidence.delivery !== 'queue') ||
|
|
207
|
+
!Array.isArray(evidence.pendingMessageIDs) ||
|
|
208
|
+
evidence.pendingMessageIDs.some((id) => !isNonBlankID(id)) ||
|
|
209
|
+
(evidence.activeMessageID !== null && !isNonBlankID(evidence.activeMessageID)) ||
|
|
210
|
+
typeof evidence.continuation !== 'boolean'
|
|
211
|
+
) {
|
|
212
|
+
return 'CORRELATION_UNAVAILABLE'
|
|
213
|
+
}
|
|
214
|
+
if (
|
|
215
|
+
event.sessionID !== evidence.sessionID ||
|
|
216
|
+
event.messageID !== evidence.messageID ||
|
|
217
|
+
event.messageID !== evidence.currentMessageID
|
|
218
|
+
) {
|
|
219
|
+
return 'CORRELATION_MISMATCH'
|
|
220
|
+
}
|
|
221
|
+
if (event.delivery !== 'steer' || evidence.delivery !== 'steer') return 'QUEUED_TURN'
|
|
222
|
+
if (
|
|
223
|
+
evidence.activeMessageID !== null ||
|
|
224
|
+
evidence.pendingMessageIDs.length !== 1 ||
|
|
225
|
+
evidence.pendingMessageIDs[0] !== event.messageID
|
|
226
|
+
) {
|
|
227
|
+
return 'CONCURRENT_TURN'
|
|
228
|
+
}
|
|
229
|
+
if (evidence.continuation) return 'CONTINUATION_TURN'
|
|
230
|
+
return null
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const DECISION_AGENT_IDS = new Set(
|
|
234
|
+
PANTHEON_AGENT_CATALOG.filter((agent) => agent.id !== 'zeus').map((agent) => agent.id),
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
export type NativeDecisionPreparationFailure =
|
|
238
|
+
| NativeDecisionRouteFailure
|
|
239
|
+
| NativeDecisionCorrelationFailure
|
|
240
|
+
| 'CONSENT_MISSING'
|
|
241
|
+
| 'CONSENT_AMBIGUOUS'
|
|
242
|
+
| 'CONSENT_DISABLED'
|
|
243
|
+
| 'PROMPT_EMPTY'
|
|
244
|
+
| 'PROMPT_TOO_LONG'
|
|
245
|
+
| 'FILES_NOT_ALLOWED'
|
|
246
|
+
| 'INVALID_CANDIDATES'
|
|
247
|
+
|
|
248
|
+
export type NativeDecisionPreparation =
|
|
249
|
+
| { readonly ok: true; readonly request: NativeDecisionRequest }
|
|
250
|
+
| { readonly ok: false; readonly reasonCode: NativeDecisionPreparationFailure }
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Prepare only the current user text and a fixed question. This function does
|
|
254
|
+
* not invoke the native API and does not accept history, tools, paths, files,
|
|
255
|
+
* system instructions, memory, or catalog descriptions as inputs.
|
|
256
|
+
*/
|
|
257
|
+
export function prepareNativeDecisionRequest(
|
|
258
|
+
route: ResolvedNativeDecisionRoute,
|
|
259
|
+
event: SessionPrompt,
|
|
260
|
+
eligibleAgentIDs: readonly string[],
|
|
261
|
+
consentEntries: readonly NativeDecisionConsentEntry[] = [],
|
|
262
|
+
correlationEvidence?: NativeDecisionCorrelationEvidence,
|
|
263
|
+
): NativeDecisionPreparation {
|
|
264
|
+
if (
|
|
265
|
+
event === null ||
|
|
266
|
+
typeof event !== 'object' ||
|
|
267
|
+
event.prompt === null ||
|
|
268
|
+
typeof event.prompt !== 'object'
|
|
269
|
+
) {
|
|
270
|
+
return { ok: false, reasonCode: 'CORRELATION_MISMATCH' }
|
|
271
|
+
}
|
|
272
|
+
const consent = evaluateNativeDecisionConsent(route, consentEntries)
|
|
273
|
+
if (!consent.allowed) return { ok: false, reasonCode: consent.reasonCode }
|
|
274
|
+
|
|
275
|
+
const correlationFailure = validateNativeDecisionCorrelation(event, correlationEvidence)
|
|
276
|
+
if (correlationFailure !== null) return { ok: false, reasonCode: correlationFailure }
|
|
277
|
+
|
|
278
|
+
const promptFiles = (event.prompt as { files?: unknown }).files
|
|
279
|
+
if (promptFiles !== undefined && (!Array.isArray(promptFiles) || promptFiles.length > 0)) {
|
|
280
|
+
return { ok: false, reasonCode: 'FILES_NOT_ALLOWED' }
|
|
281
|
+
}
|
|
282
|
+
const promptText = event.prompt.text
|
|
283
|
+
if (typeof promptText !== 'string' || promptText.trim().length === 0) {
|
|
284
|
+
return { ok: false, reasonCode: 'PROMPT_EMPTY' }
|
|
285
|
+
}
|
|
286
|
+
if (promptText.length > NATIVE_DECISION_MAX_PROMPT_LENGTH) {
|
|
287
|
+
return { ok: false, reasonCode: 'PROMPT_TOO_LONG' }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const candidates = new Set<string>()
|
|
291
|
+
for (const id of eligibleAgentIDs) {
|
|
292
|
+
if (typeof id !== 'string' || !DECISION_AGENT_IDS.has(id) || candidates.has(id)) {
|
|
293
|
+
return { ok: false, reasonCode: 'INVALID_CANDIDATES' }
|
|
294
|
+
}
|
|
295
|
+
candidates.add(id)
|
|
296
|
+
}
|
|
297
|
+
if (candidates.size > DECISION_AGENT_IDS.size) {
|
|
298
|
+
return { ok: false, reasonCode: 'INVALID_CANDIDATES' }
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const request = {
|
|
302
|
+
model: route.model,
|
|
303
|
+
input: [{ type: 'text', text: promptText }],
|
|
304
|
+
questions: [
|
|
305
|
+
{
|
|
306
|
+
type: 'choice',
|
|
307
|
+
name: NATIVE_DECISION_ANSWER_NAME,
|
|
308
|
+
instructions:
|
|
309
|
+
'Choose one listed specialist only when the current request clearly needs it; otherwise choose none. This is advisory only.',
|
|
310
|
+
choices: [...[...candidates].map((value) => ({ value })), { value: 'none' }],
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
} satisfies NativeDecisionRequest
|
|
314
|
+
|
|
315
|
+
return { ok: true, request: Object.freeze(request) }
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export interface NativeDecisionAdvice {
|
|
319
|
+
readonly agent: string | null
|
|
320
|
+
readonly reasonCode: 'RECOMMENDED' | 'ABSTAIN' | 'INVALID_RESPONSE' | 'LOW_CONFIDENCE'
|
|
321
|
+
readonly effect: 'none'
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Bounded consumer: validates one candidate and returns advice only. */
|
|
325
|
+
export function consumeNativeDecisionAdvice(
|
|
326
|
+
response: unknown,
|
|
327
|
+
eligibleAgentIDs: readonly string[],
|
|
328
|
+
): NativeDecisionAdvice {
|
|
329
|
+
const abstain = (reasonCode: NativeDecisionAdvice['reasonCode']): NativeDecisionAdvice =>
|
|
330
|
+
Object.freeze({ agent: null, reasonCode, effect: 'none' })
|
|
331
|
+
if (response === null || typeof response !== 'object' || Array.isArray(response)) {
|
|
332
|
+
return abstain('INVALID_RESPONSE')
|
|
333
|
+
}
|
|
334
|
+
const answers = (response as { answers?: unknown }).answers
|
|
335
|
+
if (!Array.isArray(answers)) return abstain('INVALID_RESPONSE')
|
|
336
|
+
const matches = answers.filter(
|
|
337
|
+
(answer): answer is Record<string, unknown> =>
|
|
338
|
+
answer !== null &&
|
|
339
|
+
typeof answer === 'object' &&
|
|
340
|
+
!Array.isArray(answer) &&
|
|
341
|
+
answer.name === NATIVE_DECISION_ANSWER_NAME,
|
|
342
|
+
)
|
|
343
|
+
if (matches.length !== 1) return abstain(matches.length === 0 ? 'ABSTAIN' : 'INVALID_RESPONSE')
|
|
344
|
+
|
|
345
|
+
const answer = matches[0]
|
|
346
|
+
if (answer?.type !== 'choice') return abstain('ABSTAIN')
|
|
347
|
+
if (answer.choice === 'none') return abstain('ABSTAIN')
|
|
348
|
+
if (typeof answer.choice !== 'string' || !eligibleAgentIDs.includes(answer.choice)) {
|
|
349
|
+
return abstain('INVALID_RESPONSE')
|
|
350
|
+
}
|
|
351
|
+
if (
|
|
352
|
+
typeof answer.confidence !== 'number' ||
|
|
353
|
+
!Number.isFinite(answer.confidence) ||
|
|
354
|
+
answer.confidence < 0 ||
|
|
355
|
+
answer.confidence > 1
|
|
356
|
+
) {
|
|
357
|
+
return abstain('INVALID_RESPONSE')
|
|
358
|
+
}
|
|
359
|
+
if (!DECISION_AGENT_IDS.has(answer.choice)) return abstain('INVALID_RESPONSE')
|
|
360
|
+
return Object.freeze({ agent: answer.choice, reasonCode: 'RECOMMENDED', effect: 'none' })
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// This type assertion keeps the source contract tied to @opencode/plugin@2.2.5.
|
|
364
|
+
// Any removal or schema change to the native method fails `npm run typecheck`.
|
|
365
|
+
export type OpenCodeV225DecisionApi = Pick<Context['experimental']['generate'], 'decisions'>
|
|
@@ -38,6 +38,12 @@
|
|
|
38
38
|
|
|
39
39
|
import { randomUUID } from 'node:crypto'
|
|
40
40
|
import { type HookPayload, type HookResult, runHook } from '../plugins/hook-runner.ts'
|
|
41
|
+
import {
|
|
42
|
+
appendDelegationAuditLine,
|
|
43
|
+
delegationStartLine,
|
|
44
|
+
delegationStopLine,
|
|
45
|
+
formatterApplies,
|
|
46
|
+
} from './v2-hook-engine.ts'
|
|
41
47
|
|
|
42
48
|
/**
|
|
43
49
|
* Delegation tool names. MIRRORS `DELEGATION_TOOL_RE` in
|
|
@@ -53,10 +59,68 @@ export const FORMATTER_SCRIPT = 'format-multi-language.sh'
|
|
|
53
59
|
export const DELEGATION_START_SCRIPT = 'on-subagent-delegation-start.sh'
|
|
54
60
|
export const DELEGATION_STOP_SCRIPT = 'on-subagent-delegation-stop.sh'
|
|
55
61
|
|
|
56
|
-
/** One
|
|
62
|
+
/** One audit/formatter invocation. Injected in tests to avoid spawning a shell. */
|
|
57
63
|
export type V2ShellRunner = (script: string, payload: HookPayload) => Promise<HookResult>
|
|
58
64
|
|
|
59
|
-
const
|
|
65
|
+
const IDLE_RESULT: HookResult = { code: 0, stdout: '', stderr: '', signal: null, timedOut: false }
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* In-process dispatcher. Start/stop audit lines are written directly (same
|
|
69
|
+
* JSON shape and LOG_DIR resolution as the shell scripts); the formatter
|
|
70
|
+
* still spawns when the tool call touched a formattable file and is skipped —
|
|
71
|
+
* without a child process — for every call the script would no-op anyway.
|
|
72
|
+
*/
|
|
73
|
+
const defaultRunner: V2ShellRunner = async (script, payload) => {
|
|
74
|
+
const record = (payload ?? {}) as Record<string, unknown>
|
|
75
|
+
const tool = typeof record.tool_name === 'string' ? record.tool_name : ''
|
|
76
|
+
if (script === DELEGATION_START_SCRIPT) {
|
|
77
|
+
const delegationID = typeof record.delegation_id === 'string' ? record.delegation_id : ''
|
|
78
|
+
const agent = typeof record.agent_id === 'string' ? record.agent_id : ''
|
|
79
|
+
const sessionID = typeof record.session_id === 'string' ? record.session_id : ''
|
|
80
|
+
const task =
|
|
81
|
+
record.tool_input !== null && typeof record.tool_input === 'object'
|
|
82
|
+
? String((record.tool_input as Record<string, unknown>).description ?? '')
|
|
83
|
+
: ''
|
|
84
|
+
appendDelegationAuditLine(
|
|
85
|
+
delegationStartLine({ agent, task, sessionID, delegationID, now: Date.now() }),
|
|
86
|
+
)
|
|
87
|
+
return IDLE_RESULT
|
|
88
|
+
}
|
|
89
|
+
if (script === DELEGATION_STOP_SCRIPT) {
|
|
90
|
+
const delegationID = typeof record.delegation_id === 'string' ? record.delegation_id : ''
|
|
91
|
+
const agent = typeof record.agent_id === 'string' ? record.agent_id : ''
|
|
92
|
+
const sessionID = typeof record.session_id === 'string' ? record.session_id : ''
|
|
93
|
+
const status = typeof record.status === 'string' ? record.status : ''
|
|
94
|
+
const taskID = typeof record.task_id === 'string' ? record.task_id : ''
|
|
95
|
+
const duration =
|
|
96
|
+
typeof record.duration_ms === 'number' && Number.isFinite(record.duration_ms)
|
|
97
|
+
? Math.max(0, Math.round(record.duration_ms))
|
|
98
|
+
: null
|
|
99
|
+
appendDelegationAuditLine(
|
|
100
|
+
delegationStopLine({
|
|
101
|
+
agent,
|
|
102
|
+
status,
|
|
103
|
+
reason: status,
|
|
104
|
+
task:
|
|
105
|
+
record.tool_input !== null && typeof record.tool_input === 'object'
|
|
106
|
+
? String((record.tool_input as Record<string, unknown>).description ?? '')
|
|
107
|
+
: '',
|
|
108
|
+
sessionID,
|
|
109
|
+
result: record.tool_output ?? null,
|
|
110
|
+
delegationID,
|
|
111
|
+
taskID,
|
|
112
|
+
durationMs: duration,
|
|
113
|
+
now: Date.now(),
|
|
114
|
+
}),
|
|
115
|
+
)
|
|
116
|
+
return IDLE_RESULT
|
|
117
|
+
}
|
|
118
|
+
if (script === FORMATTER_SCRIPT) {
|
|
119
|
+
if (!formatterApplies(tool, record.tool_input)) return IDLE_RESULT
|
|
120
|
+
return runHook(script, payload)
|
|
121
|
+
}
|
|
122
|
+
return runHook(script, payload)
|
|
123
|
+
}
|
|
60
124
|
|
|
61
125
|
/** Hard cap on pending records — a tool result may never arrive. */
|
|
62
126
|
const MAX_PENDING_STARTS = 256
|
package/src/pantheon/v2-tools.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* V2 tool surface — the Pantheon tools that are self-sufficient on the
|
|
3
3
|
* OpenCode V2 host, declared for `ctx.tool.transform`'s `draft.add`.
|
|
4
4
|
*
|
|
5
|
-
* ## Why
|
|
5
|
+
* ## Why four unconditional tools
|
|
6
6
|
*
|
|
7
7
|
* A V2 tool can only be served here when it needs no V1 infrastructure. The
|
|
8
8
|
* three goal tools (`pantheon_goal_create`, `pantheon_goal_get`,
|
|
@@ -14,18 +14,19 @@
|
|
|
14
14
|
* output contract on every call, so it buys nothing. See
|
|
15
15
|
* `V2_UNSUPPORTED_FEATURES` in `../plugin-v2.ts` (marker `goal-tools`).
|
|
16
16
|
*
|
|
17
|
-
* `hashline_edit` (pure filesystem), `pantheon_cost` (reads `opencode.db`)
|
|
18
|
-
* `pantheon_model` (reads/writes `active-preset.json`)
|
|
19
|
-
*
|
|
17
|
+
* `hashline_edit` (pure filesystem), `pantheon_cost` (reads `opencode.db`),
|
|
18
|
+
* `pantheon_model` (reads/writes `active-preset.json`), and the local-only
|
|
19
|
+
* `pantheon_local_decision` selector need none of that. Its execution rejects
|
|
20
|
+
* any host context that does not identify Zeus.
|
|
20
21
|
*
|
|
21
|
-
* ##
|
|
22
|
+
* ## Four unconditional tools, up to two host-dependent ones
|
|
22
23
|
*
|
|
23
|
-
* The
|
|
24
|
+
* The four above are always built. Two more exist on the V2 host and are
|
|
24
25
|
* conditional: `vision_describe` is added here when the caller supplies a
|
|
25
26
|
* vision runtime (the host model catalog), and `pantheon_bounded_read` is
|
|
26
27
|
* appended by the plugin when the host exposes its permission and session APIs
|
|
27
|
-
* (root Zeus sessions only). The effective count is therefore
|
|
28
|
-
* plus up to 2 host-dependent
|
|
28
|
+
* (root Zeus sessions only). The effective count is therefore 4 unconditional
|
|
29
|
+
* plus up to 2 host-dependent.
|
|
29
30
|
*
|
|
30
31
|
* ## The output declaration is mandatory
|
|
31
32
|
*
|
|
@@ -47,8 +48,11 @@
|
|
|
47
48
|
|
|
48
49
|
import { createCostCommand } from './cost-command.ts'
|
|
49
50
|
import { createHashlineEditTool, type HashlineToolResult } from './hashline/tool.ts'
|
|
51
|
+
import { createV2JevDecisionDefinition, type V2JevDecisionRuntime } from './jev-decision-tool.ts'
|
|
52
|
+
import { createV2LocalDecisionDefinition } from './local-decision-tool.ts'
|
|
50
53
|
import { createModelCommand } from './model-command.ts'
|
|
51
54
|
import type { ToolContextLike } from './tool-context.ts'
|
|
55
|
+
import type { ShadowSink } from './v2-decision-shadow.ts'
|
|
52
56
|
import { createV2VisionTool, type V2VisionRuntime } from './v2-vision.ts'
|
|
53
57
|
|
|
54
58
|
// ─── Contract types ─────────────────────────────────────────────────────
|
|
@@ -418,6 +422,17 @@ async function executeModel(
|
|
|
418
422
|
|
|
419
423
|
// ─── Tool set ───────────────────────────────────────────────────────────
|
|
420
424
|
|
|
425
|
+
/**
|
|
426
|
+
* Optional shadow sinks wired at tool registration.
|
|
427
|
+
*
|
|
428
|
+
* `complexity` belongs to P3, whose declared host surface is `tool.invoke`: the
|
|
429
|
+
* local selector's own input carries the complexity vector and gate status, so
|
|
430
|
+
* the observation is constructed where the payload can actually feed it.
|
|
431
|
+
*/
|
|
432
|
+
export interface V2ToolShadowOptions {
|
|
433
|
+
readonly complexitySink?: ShadowSink
|
|
434
|
+
}
|
|
435
|
+
|
|
421
436
|
/**
|
|
422
437
|
* Build the V2 tool definitions.
|
|
423
438
|
*
|
|
@@ -427,14 +442,16 @@ async function executeModel(
|
|
|
427
442
|
* to fail validation. The protection against forgetting the field is the
|
|
428
443
|
* required `output` on `V2ToolDef`, not the emptiness of this schema.
|
|
429
444
|
*
|
|
430
|
-
* The
|
|
431
|
-
* module-level consts created once at import
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
* performs filesystem or database work at construction, so importing this
|
|
435
|
-
* module stays side-effect free.
|
|
445
|
+
* The existing tool instances (`hashlineEdit`, `costCommand`, `modelCommand`)
|
|
446
|
+
* are module-level consts created once at import. The local selector is a
|
|
447
|
+
* per-call definition with no construction-time I/O. A fresh descriptor array
|
|
448
|
+
* prevents callers from mutating another registration's definitions.
|
|
436
449
|
*/
|
|
437
|
-
export function createV2ToolDefinitions(
|
|
450
|
+
export function createV2ToolDefinitions(
|
|
451
|
+
visionRuntime?: V2VisionRuntime,
|
|
452
|
+
shadow: V2ToolShadowOptions = {},
|
|
453
|
+
jevRuntime?: V2JevDecisionRuntime,
|
|
454
|
+
): V2ToolDef[] {
|
|
438
455
|
const definitions: V2ToolDef[] = [
|
|
439
456
|
{
|
|
440
457
|
name: 'hashline_edit',
|
|
@@ -475,6 +492,12 @@ export function createV2ToolDefinitions(visionRuntime?: V2VisionRuntime): V2Tool
|
|
|
475
492
|
execute: executeModel,
|
|
476
493
|
},
|
|
477
494
|
]
|
|
495
|
+
definitions.push(
|
|
496
|
+
createV2LocalDecisionDefinition({
|
|
497
|
+
...(shadow.complexitySink === undefined ? {} : { sink: shadow.complexitySink }),
|
|
498
|
+
}),
|
|
499
|
+
)
|
|
478
500
|
if (visionRuntime) definitions.push(createV2VisionTool(visionRuntime))
|
|
501
|
+
if (jevRuntime) definitions.push(createV2JevDecisionDefinition(jevRuntime))
|
|
479
502
|
return definitions
|
|
480
503
|
}
|