pantheon-opencode 1.6.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/AGENTS.global.md +11 -11
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +179 -0
- package/README.md +268 -20
- package/README.pt-BR.md +34 -11
- package/bin/pantheon-init.mjs +301 -32
- package/package.json +13 -4
- 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/build-agents-md.mjs +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/doctor.mjs +213 -45
- package/scripts/install/agents-md.mjs +2 -1
- package/scripts/install/component-selection.mjs +9 -4
- package/scripts/install/config-migration.mjs +344 -393
- package/scripts/install/config-paths.mjs +15 -0
- 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/mcp-permissions.mjs +164 -0
- package/scripts/install/migrate.mjs +123 -72
- package/scripts/install/opencode-version.mjs +31 -13
- package/scripts/install/opencode-wildcard.mjs +106 -0
- package/scripts/install/opencode.mjs +411 -184
- package/scripts/install/plan-artifact.mjs +12 -1
- package/scripts/install/plan.mjs +8 -1
- package/scripts/install/plugin.mjs +18 -1
- package/scripts/install/state.mjs +12 -0
- package/scripts/install/strings.mjs +22 -0
- package/scripts/install/v2-capabilities.mjs +5 -6
- package/scripts/install/venv.mjs +34 -17
- package/scripts/mcp_resources.py +11 -9
- package/scripts/package-evidence.mjs +1 -0
- package/scripts/release-notes.mjs +30 -7
- package/scripts/restore.mjs +22 -10
- 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 +448 -157
- package/scripts/update-skills-lock.mjs +30 -0
- package/scripts/versioning.mjs +41 -5
- package/skills-lock.json +10 -10
- package/src/agents/aphrodite.md +11 -3
- package/src/agents/apollo.md +6 -0
- package/src/agents/athena.md +7 -1
- package/src/agents/demeter.md +6 -2
- package/src/agents/gaia.md +5 -0
- package/src/agents/hephaestus.md +7 -2
- package/src/agents/hermes.md +14 -13
- package/src/agents/iris.md +6 -2
- package/src/agents/mnemosyne.md +21 -50
- package/src/agents/nyx.md +6 -2
- package/src/agents/prometheus.md +5 -1
- package/src/agents/talos.md +10 -1
- package/src/agents/themis.md +5 -1
- package/src/agents/zeus.md +61 -65
- 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/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- package/src/mcp/pantheon_vision.py +37 -36
- 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/pantheon/v2-vision.ts +34 -29
- package/src/pantheon/vision.ts +43 -10
- package/src/plugin-v2.ts +449 -79
- 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 +22 -0
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/server-v2.js +26 -0
- package/src/plugins/tui/dist/server-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui-v2.d.ts +54 -51
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +762 -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 +17 -2
- package/src/plugins/tui/package.json +6 -3
- package/src/plugins/tui/src/context-gauge.ts +59 -0
- package/src/plugins/tui/src/cost-data.ts +607 -0
- package/src/plugins/tui/src/index-v2.tsx +360 -242
- package/src/plugins/tui/src/model-pricing.ts +536 -0
- package/src/plugins/tui/src/model-usage-limits.ts +4 -0
- package/src/plugins/tui/src/server-v2.ts +21 -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 +34 -5
- 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
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { PANTHEON_SKILL_CATALOG, PANTHEON_SKILL_IDS } from './pantheon-decision-catalog.ts'
|
|
2
|
+
|
|
3
|
+
export type SkillSelectionReason =
|
|
4
|
+
| 'SELECTED_BY_KEYWORDS'
|
|
5
|
+
| 'SELECTED_BY_MATERIAL_REQUIREMENT'
|
|
6
|
+
| 'NO_LOCAL_MATCH'
|
|
7
|
+
| 'INVALID_INPUT'
|
|
8
|
+
|
|
9
|
+
/** Material requirement that must seat `artifact-management` (D2). */
|
|
10
|
+
export type MaterialRequirement = 'gate' | 'planning'
|
|
11
|
+
|
|
12
|
+
export interface LocalSkillSelection {
|
|
13
|
+
skillIds: string[]
|
|
14
|
+
reasonCode: SkillSelectionReason
|
|
15
|
+
/** `null` unless the request materially requires a gate or a plan (D2). */
|
|
16
|
+
materialRequirement: MaterialRequirement | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Bounded so a malformed or huge prompt can never fan out local work. */
|
|
20
|
+
export const MAX_SELECTED_SKILLS = 4
|
|
21
|
+
const MAX_REQUEST_LENGTH = 20_000
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Small, allowlisted keyword table. It is intentionally local and
|
|
25
|
+
* deterministic: no model, no embedding index, no network.
|
|
26
|
+
*/
|
|
27
|
+
const KEYWORDS: Readonly<Record<string, readonly string[]>> = Object.freeze({
|
|
28
|
+
'agent-coordination': [
|
|
29
|
+
'agent',
|
|
30
|
+
'agents',
|
|
31
|
+
'delegate',
|
|
32
|
+
'delegation',
|
|
33
|
+
'orchestrate',
|
|
34
|
+
'orchestration',
|
|
35
|
+
'route',
|
|
36
|
+
'routing',
|
|
37
|
+
'subagent',
|
|
38
|
+
],
|
|
39
|
+
'artifact-management': ['artifact', 'artifacts', 'planned', 'multi-phase', 'impl'],
|
|
40
|
+
'auto-continue': ['continue', 'continuation', 'todo', 'todos', 'multi-step', 'idle'],
|
|
41
|
+
clonedeps: ['clone', 'dependency', 'dependencies', 'internals', 'library', 'package'],
|
|
42
|
+
'code-review-checklist': ['review', 'reviews', 'pull request', 'feedback', 'checklist'],
|
|
43
|
+
codemap: ['codemap', 'structure', 'codebase', 'unfamiliar', 'repository', 'overview'],
|
|
44
|
+
'context-compression': ['compact', 'compaction', 'compress', 'context', 'checkpoint', 'resume'],
|
|
45
|
+
'git-workflow-and-versioning': [
|
|
46
|
+
'commit',
|
|
47
|
+
'commits',
|
|
48
|
+
'git',
|
|
49
|
+
'branch',
|
|
50
|
+
'version',
|
|
51
|
+
'release',
|
|
52
|
+
'tag',
|
|
53
|
+
'changelog',
|
|
54
|
+
],
|
|
55
|
+
'incremental-implementation': [
|
|
56
|
+
'increment',
|
|
57
|
+
'incremental',
|
|
58
|
+
'slice',
|
|
59
|
+
'slices',
|
|
60
|
+
'implement',
|
|
61
|
+
'implementation',
|
|
62
|
+
],
|
|
63
|
+
'loop-engineering': ['loop', 'iterate', 'iteration', 'refine', 'refinement', 'cycle'],
|
|
64
|
+
'memory-bank': ['memory', 'adr', 'adrs', 'documentation', 'docs', 'knowledge'],
|
|
65
|
+
reflect: ['reflect', 'reflection', 'retro', 'retrospective', 'friction', 'workflow'],
|
|
66
|
+
'security-hardening': [
|
|
67
|
+
'security',
|
|
68
|
+
'secure',
|
|
69
|
+
'owasp',
|
|
70
|
+
'vulnerability',
|
|
71
|
+
'vulnerabilities',
|
|
72
|
+
'secret',
|
|
73
|
+
'secrets',
|
|
74
|
+
'cve',
|
|
75
|
+
'audit',
|
|
76
|
+
],
|
|
77
|
+
'session-goal': ['goal', 'objective', 'scope', 'alignment', 'session'],
|
|
78
|
+
simplify: [
|
|
79
|
+
'simplify',
|
|
80
|
+
'simplification',
|
|
81
|
+
'refactor',
|
|
82
|
+
'complexity',
|
|
83
|
+
'readable',
|
|
84
|
+
'readability',
|
|
85
|
+
'cleanup',
|
|
86
|
+
],
|
|
87
|
+
'spec-driven-development': [
|
|
88
|
+
'spec',
|
|
89
|
+
'specification',
|
|
90
|
+
'requirements',
|
|
91
|
+
'prd',
|
|
92
|
+
'acceptance',
|
|
93
|
+
'criteria',
|
|
94
|
+
],
|
|
95
|
+
'tdd-with-agents': ['tdd', 'test', 'tests', 'testing', 'pytest', 'vitest', 'jest', 'coverage'],
|
|
96
|
+
'verification-planning': [
|
|
97
|
+
'verification',
|
|
98
|
+
'verify',
|
|
99
|
+
'evidence',
|
|
100
|
+
'validation',
|
|
101
|
+
'validate',
|
|
102
|
+
'reproduce',
|
|
103
|
+
],
|
|
104
|
+
'visual-review-pipeline': [
|
|
105
|
+
'visual',
|
|
106
|
+
'screenshot',
|
|
107
|
+
'screenshots',
|
|
108
|
+
'ui',
|
|
109
|
+
'ux',
|
|
110
|
+
'accessibility',
|
|
111
|
+
'wcag',
|
|
112
|
+
'playwright',
|
|
113
|
+
'responsive',
|
|
114
|
+
],
|
|
115
|
+
worktrees: ['worktree', 'worktrees', 'parallel', 'isolation', 'isolated'],
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Material gate/planning signals (D2).
|
|
120
|
+
*
|
|
121
|
+
* `artifact-management` exists for planned or materially risky work. Keyword
|
|
122
|
+
* scoring alone left it unreachable when the request demanded a gate or a plan
|
|
123
|
+
* without naming the artifact: "breaking change with human approval and a
|
|
124
|
+
* rollback plan" matched no keyword at all. These are static phrase/token
|
|
125
|
+
* lists, so detection stays local, deterministic, and bounded: no file, memory,
|
|
126
|
+
* catalog, or network read.
|
|
127
|
+
*/
|
|
128
|
+
const MATERIAL_GATE_TOKENS: ReadonlySet<string> = new Set([
|
|
129
|
+
'approval',
|
|
130
|
+
'cutover',
|
|
131
|
+
'gate',
|
|
132
|
+
'irreversible',
|
|
133
|
+
'signoff',
|
|
134
|
+
])
|
|
135
|
+
|
|
136
|
+
const MATERIAL_GATE_PHRASES: readonly string[] = Object.freeze([
|
|
137
|
+
'breaking change',
|
|
138
|
+
'risk assessment',
|
|
139
|
+
'risk review',
|
|
140
|
+
'schema change',
|
|
141
|
+
'sign off',
|
|
142
|
+
])
|
|
143
|
+
|
|
144
|
+
const MATERIAL_PLANNING_TOKENS: ReadonlySet<string> = new Set([
|
|
145
|
+
'deliverable',
|
|
146
|
+
'deliverables',
|
|
147
|
+
'milestone',
|
|
148
|
+
'milestones',
|
|
149
|
+
'plan',
|
|
150
|
+
'planning',
|
|
151
|
+
'roadmap',
|
|
152
|
+
'rollback',
|
|
153
|
+
])
|
|
154
|
+
|
|
155
|
+
const MATERIAL_PLANNING_PHRASES: readonly string[] = Object.freeze([
|
|
156
|
+
'across phases',
|
|
157
|
+
'break down',
|
|
158
|
+
'design doc',
|
|
159
|
+
'implementation plan',
|
|
160
|
+
'migration plan',
|
|
161
|
+
'rollout plan',
|
|
162
|
+
'work breakdown',
|
|
163
|
+
])
|
|
164
|
+
|
|
165
|
+
const ARTIFACT_SKILL_ID = 'artifact-management'
|
|
166
|
+
|
|
167
|
+
const CATALOG_ORDER = new Map(PANTHEON_SKILL_CATALOG.map((entry, index) => [entry.id, index]))
|
|
168
|
+
|
|
169
|
+
function normalize(value: string): string {
|
|
170
|
+
return value
|
|
171
|
+
.normalize('NFD')
|
|
172
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
173
|
+
.toLowerCase()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function tokenize(value: string): Set<string> {
|
|
177
|
+
const tokens = value.match(/[a-z0-9]+(?:[+#.-][a-z0-9]+)*/g) ?? []
|
|
178
|
+
return new Set(tokens)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function scoreSkill(normalizedRequest: string, tokens: ReadonlySet<string>, skillId: string) {
|
|
182
|
+
const keywords = KEYWORDS[skillId] ?? []
|
|
183
|
+
let score = 0
|
|
184
|
+
for (const keyword of keywords) {
|
|
185
|
+
if (keyword.includes(' ')) {
|
|
186
|
+
if (normalizedRequest.includes(keyword)) score += 3
|
|
187
|
+
continue
|
|
188
|
+
}
|
|
189
|
+
if (tokens.has(keyword)) score += 2
|
|
190
|
+
}
|
|
191
|
+
return score
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function hasMaterialSignal(
|
|
195
|
+
normalizedRequest: string,
|
|
196
|
+
tokens: ReadonlySet<string>,
|
|
197
|
+
signalTokens: ReadonlySet<string>,
|
|
198
|
+
signalPhrases: readonly string[],
|
|
199
|
+
): boolean {
|
|
200
|
+
for (const token of signalTokens) {
|
|
201
|
+
if (tokens.has(token)) return true
|
|
202
|
+
}
|
|
203
|
+
return signalPhrases.some((phrase) => normalizedRequest.includes(phrase))
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Detect a material gate or planning requirement (D2). A gate requirement wins
|
|
208
|
+
* over a planning one, so the reported token is stable when both are present.
|
|
209
|
+
*/
|
|
210
|
+
function detectMaterialRequirement(
|
|
211
|
+
normalizedRequest: string,
|
|
212
|
+
tokens: ReadonlySet<string>,
|
|
213
|
+
): MaterialRequirement | null {
|
|
214
|
+
if (hasMaterialSignal(normalizedRequest, tokens, MATERIAL_GATE_TOKENS, MATERIAL_GATE_PHRASES)) {
|
|
215
|
+
return 'gate'
|
|
216
|
+
}
|
|
217
|
+
if (
|
|
218
|
+
hasMaterialSignal(
|
|
219
|
+
normalizedRequest,
|
|
220
|
+
tokens,
|
|
221
|
+
MATERIAL_PLANNING_TOKENS,
|
|
222
|
+
MATERIAL_PLANNING_PHRASES,
|
|
223
|
+
)
|
|
224
|
+
) {
|
|
225
|
+
return 'planning'
|
|
226
|
+
}
|
|
227
|
+
return null
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Select a small, deterministic set of allowlisted Pantheon skills for the
|
|
232
|
+
* current request. This function never reads files, memory, transcripts, or
|
|
233
|
+
* the network, and it never returns the whole catalog as a fallback.
|
|
234
|
+
*
|
|
235
|
+
* D2 — when the request materially requires a gate or a plan, the artifact
|
|
236
|
+
* skill is guaranteed a seat instead of depending on the literal keywords
|
|
237
|
+
* `artifact`/`planned`/`multi-phase`/`impl`. That seat is first, so a hard
|
|
238
|
+
* budget drops the lowest-scoring keyword skill rather than the required one.
|
|
239
|
+
* This only ranks identifiers: it does not filter or mutate any prompt, and P2
|
|
240
|
+
* remains an empirical no-op on the default path (F-09).
|
|
241
|
+
*/
|
|
242
|
+
export function selectPantheonSkills(
|
|
243
|
+
request: unknown,
|
|
244
|
+
maxSkills = MAX_SELECTED_SKILLS,
|
|
245
|
+
): LocalSkillSelection {
|
|
246
|
+
if (
|
|
247
|
+
typeof request !== 'string' ||
|
|
248
|
+
request.trim().length === 0 ||
|
|
249
|
+
request.length > MAX_REQUEST_LENGTH ||
|
|
250
|
+
!Number.isInteger(maxSkills) ||
|
|
251
|
+
maxSkills < 1 ||
|
|
252
|
+
maxSkills > MAX_SELECTED_SKILLS
|
|
253
|
+
) {
|
|
254
|
+
return { skillIds: [], reasonCode: 'INVALID_INPUT', materialRequirement: null }
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const normalizedRequest = normalize(request)
|
|
258
|
+
const tokens = tokenize(normalizedRequest)
|
|
259
|
+
const material = detectMaterialRequirement(normalizedRequest, tokens)
|
|
260
|
+
const scored: Array<{ id: string; score: number; order: number }> = []
|
|
261
|
+
for (const skillId of PANTHEON_SKILL_IDS) {
|
|
262
|
+
const score = scoreSkill(normalizedRequest, tokens, skillId)
|
|
263
|
+
if (score <= 0) continue
|
|
264
|
+
scored.push({ id: skillId, score, order: CATALOG_ORDER.get(skillId) ?? 0 })
|
|
265
|
+
}
|
|
266
|
+
if (material === null && scored.length === 0) {
|
|
267
|
+
return { skillIds: [], reasonCode: 'NO_LOCAL_MATCH', materialRequirement: null }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
scored.sort((left, right) => right.score - left.score || left.order - right.order)
|
|
271
|
+
const ranked = scored.map((entry) => entry.id)
|
|
272
|
+
const ordered =
|
|
273
|
+
material === null
|
|
274
|
+
? ranked
|
|
275
|
+
: [ARTIFACT_SKILL_ID, ...ranked.filter((id) => id !== ARTIFACT_SKILL_ID)]
|
|
276
|
+
return {
|
|
277
|
+
skillIds: ordered.slice(0, maxSkills),
|
|
278
|
+
reasonCode: material === null ? 'SELECTED_BY_KEYWORDS' : 'SELECTED_BY_MATERIAL_REQUIREMENT',
|
|
279
|
+
materialRequirement: material,
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type ToolContext, tool } from '@opencode-ai/plugin'
|
|
2
|
+
import {
|
|
3
|
+
LOCAL_DECISION_COMPLEXITY_DIMENSIONS,
|
|
4
|
+
type LocalDecisionGateStatus,
|
|
5
|
+
} from './local-decision-router.ts'
|
|
6
|
+
import {
|
|
7
|
+
type LocalDecisionPolicy,
|
|
8
|
+
loadLocalDecisionPolicy,
|
|
9
|
+
recommendLocalOrchestration,
|
|
10
|
+
} from './local-orchestration.ts'
|
|
11
|
+
import { evaluateComplexityPoint } from './v2-decision-points/p3-complexity.ts'
|
|
12
|
+
import type { ShadowSink } from './v2-decision-shadow.ts'
|
|
13
|
+
|
|
14
|
+
const TOOL_DESCRIPTION =
|
|
15
|
+
'Zeus-only local advisory selector. Use selectively only when specialist routing is genuinely ' +
|
|
16
|
+
'ambiguous; obvious work should go directly to native subagent without this tool. Accepts only ' +
|
|
17
|
+
'structured candidate IDs, never task text. It does not dispatch, run a skill/resource, search ' +
|
|
18
|
+
'memory, or authorize/alter grants or review gates. Provider egress is disabled; all decisions ' +
|
|
19
|
+
'remain local.'
|
|
20
|
+
|
|
21
|
+
const gateStatuses: LocalDecisionGateStatus[] = [
|
|
22
|
+
'none',
|
|
23
|
+
'review_required',
|
|
24
|
+
'human_approval_required',
|
|
25
|
+
'unresolved',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
const inputShape = {
|
|
29
|
+
schemaVersion: tool.schema.literal(1),
|
|
30
|
+
candidateAgents: tool.schema.array(tool.schema.string().min(1)).max(14),
|
|
31
|
+
domain: tool.schema.string().nullable(),
|
|
32
|
+
candidateSkillIds: tool.schema.array(tool.schema.string().min(1)).max(64),
|
|
33
|
+
candidateResourceIds: tool.schema.array(tool.schema.string().min(1)).max(32),
|
|
34
|
+
memorySearchRelevant: tool.schema.boolean(),
|
|
35
|
+
gateStatus: tool.schema.enum(
|
|
36
|
+
gateStatuses as [LocalDecisionGateStatus, ...LocalDecisionGateStatus[]],
|
|
37
|
+
),
|
|
38
|
+
complexity: tool.schema
|
|
39
|
+
.object({
|
|
40
|
+
boundedness: tool.schema.number().int().min(0).max(2),
|
|
41
|
+
reversibility: tool.schema.number().int().min(0).max(2),
|
|
42
|
+
dependencies: tool.schema.number().int().min(0).max(2),
|
|
43
|
+
uncertainty: tool.schema.number().int().min(0).max(2),
|
|
44
|
+
verification: tool.schema.number().int().min(0).max(2),
|
|
45
|
+
})
|
|
46
|
+
.strict(),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type LocalDecisionToolOptions = {
|
|
50
|
+
loadPolicy?: () => Promise<LocalDecisionPolicy | undefined>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Optional shadow observer for the V2 tool point.
|
|
55
|
+
*
|
|
56
|
+
* P3 declares `tool.invoke`, and the local selector's input is the surface that
|
|
57
|
+
* carries `complexity` and `gateStatus`. The sink is supplied by the plugin when
|
|
58
|
+
* it registers the tool; nothing here applies its record.
|
|
59
|
+
*/
|
|
60
|
+
type LocalDecisionShadowOptions = {
|
|
61
|
+
sink?: ShadowSink
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Observe P3 in shadow at `tool.invoke`.
|
|
66
|
+
*
|
|
67
|
+
* Contained on purpose: the adapter already contains its own failures, and
|
|
68
|
+
* this wrapper guarantees that even an unexpected throw cannot change the
|
|
69
|
+
* tool result. No input is mutated and no decision is applied.
|
|
70
|
+
*/
|
|
71
|
+
function observeToolComplexity(input: unknown, sink?: ShadowSink): void {
|
|
72
|
+
try {
|
|
73
|
+
evaluateComplexityPoint(input, sink)
|
|
74
|
+
} catch {
|
|
75
|
+
// Shadow is best-effort; the tool result is unaffected.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function runDecision(
|
|
80
|
+
input: unknown,
|
|
81
|
+
callerAgent: unknown,
|
|
82
|
+
loadPolicy: () => Promise<LocalDecisionPolicy | undefined>,
|
|
83
|
+
): Promise<string> {
|
|
84
|
+
if (callerAgent !== 'zeus') {
|
|
85
|
+
return JSON.stringify(recommendLocalOrchestration(input, callerAgent, undefined))
|
|
86
|
+
}
|
|
87
|
+
const policy = await loadPolicy().catch(() => undefined)
|
|
88
|
+
// Caller context is a host-provided identity string, not non-forgeable runtime provenance.
|
|
89
|
+
// Keep this route hard local-only until provider authorization can be established safely.
|
|
90
|
+
return JSON.stringify(recommendLocalOrchestration(input, callerAgent, policy))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Create the V1 plugin tool; execution is fail-closed unless host context identifies Zeus. */
|
|
94
|
+
export function createLocalDecisionTool(options: LocalDecisionToolOptions = {}) {
|
|
95
|
+
const policyLoader = options.loadPolicy ?? loadLocalDecisionPolicy
|
|
96
|
+
return tool({
|
|
97
|
+
description: TOOL_DESCRIPTION,
|
|
98
|
+
args: inputShape,
|
|
99
|
+
execute: async (input, context: ToolContext) => runDecision(input, context.agent, policyLoader),
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const v2InputSchema: Record<string, unknown> = {
|
|
104
|
+
type: 'object',
|
|
105
|
+
additionalProperties: false,
|
|
106
|
+
required: [
|
|
107
|
+
'schemaVersion',
|
|
108
|
+
'candidateAgents',
|
|
109
|
+
'domain',
|
|
110
|
+
'candidateSkillIds',
|
|
111
|
+
'candidateResourceIds',
|
|
112
|
+
'memorySearchRelevant',
|
|
113
|
+
'gateStatus',
|
|
114
|
+
'complexity',
|
|
115
|
+
],
|
|
116
|
+
properties: {
|
|
117
|
+
schemaVersion: { type: 'integer', const: 1 },
|
|
118
|
+
candidateAgents: { type: 'array', maxItems: 14, items: { type: 'string', minLength: 1 } },
|
|
119
|
+
domain: { type: ['string', 'null'] },
|
|
120
|
+
candidateSkillIds: { type: 'array', maxItems: 64, items: { type: 'string', minLength: 1 } },
|
|
121
|
+
candidateResourceIds: { type: 'array', maxItems: 32, items: { type: 'string', minLength: 1 } },
|
|
122
|
+
memorySearchRelevant: { type: 'boolean' },
|
|
123
|
+
gateStatus: { type: 'string', enum: gateStatuses },
|
|
124
|
+
complexity: {
|
|
125
|
+
type: 'object',
|
|
126
|
+
additionalProperties: false,
|
|
127
|
+
required: [...LOCAL_DECISION_COMPLEXITY_DIMENSIONS],
|
|
128
|
+
properties: Object.fromEntries(
|
|
129
|
+
LOCAL_DECISION_COMPLEXITY_DIMENSIONS.map((dimension) => [
|
|
130
|
+
dimension,
|
|
131
|
+
{ type: 'integer', minimum: 0, maximum: 2 },
|
|
132
|
+
]),
|
|
133
|
+
),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Create a V2 transform definition with the same Zeus-only execution guard and local plan. */
|
|
139
|
+
export function createV2LocalDecisionDefinition(
|
|
140
|
+
options: LocalDecisionToolOptions & LocalDecisionShadowOptions = {},
|
|
141
|
+
) {
|
|
142
|
+
const policyLoader = options.loadPolicy ?? loadLocalDecisionPolicy
|
|
143
|
+
return {
|
|
144
|
+
name: 'pantheon_local_decision',
|
|
145
|
+
description: TOOL_DESCRIPTION,
|
|
146
|
+
input: v2InputSchema,
|
|
147
|
+
output: {},
|
|
148
|
+
execute: async (input: Record<string, unknown>, context: unknown) => {
|
|
149
|
+
// P3 shadow observation at `tool.invoke`. The input schema declares
|
|
150
|
+
// `complexity` and `gateStatus`, so this is the one wired surface that
|
|
151
|
+
// can feed a complexity decision; the record never alters the result.
|
|
152
|
+
observeToolComplexity(input, options.sink)
|
|
153
|
+
const callerAgent =
|
|
154
|
+
context !== null && typeof context === 'object'
|
|
155
|
+
? (context as { agent?: unknown }).agent
|
|
156
|
+
: undefined
|
|
157
|
+
return { output: await runDecision(input, callerAgent, policyLoader) }
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deterministic local advisory decision for one turn.
|
|
3
|
+
*
|
|
4
|
+
* The production V2 prompt hook uses `decideLocalForTurn` only. It is
|
|
5
|
+
* deterministic and local-only: no provider branch, no consent/credential/
|
|
6
|
+
* permission path, no transport, no cache — the legacy provider-capable
|
|
7
|
+
* `decideForTurn` and its one-call-per-turn cache were removed with the
|
|
8
|
+
* direct-fetch provider runner (the native route is the explicit
|
|
9
|
+
* `pantheon_jev_decide` tool, which correlates its own turn).
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
isUserDecisionRouterEnabled,
|
|
13
|
+
readUserDecisionRouterConfig,
|
|
14
|
+
type UserDecisionRouterConfig,
|
|
15
|
+
} from '../../scripts/install/decision-router-config.mjs'
|
|
16
|
+
import { hasDelegationSignal, recommendLocalDecisionAgent } from './local-decision-agents.ts'
|
|
17
|
+
import { selectPantheonSkills } from './local-decision-skills.ts'
|
|
18
|
+
import { type LocalDecisionPolicy, loadLocalDecisionPolicy } from './local-orchestration.ts'
|
|
19
|
+
|
|
20
|
+
export type TurnDecisionSource = 'local'
|
|
21
|
+
|
|
22
|
+
export interface TurnDecision {
|
|
23
|
+
schemaVersion: 1
|
|
24
|
+
active: boolean
|
|
25
|
+
source: TurnDecisionSource
|
|
26
|
+
skillIds: string[]
|
|
27
|
+
agent: string | null
|
|
28
|
+
reasonCode: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TurnDecisionInput {
|
|
32
|
+
request: unknown
|
|
33
|
+
sessionID: unknown
|
|
34
|
+
messageID: unknown
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const MAX_REQUEST_LENGTH = 20_000
|
|
38
|
+
|
|
39
|
+
function inactive(reasonCode: string): TurnDecision {
|
|
40
|
+
return {
|
|
41
|
+
schemaVersion: 1,
|
|
42
|
+
active: false,
|
|
43
|
+
source: 'local',
|
|
44
|
+
skillIds: [],
|
|
45
|
+
agent: null,
|
|
46
|
+
reasonCode,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readConfig(): UserDecisionRouterConfig | undefined {
|
|
51
|
+
try {
|
|
52
|
+
return readUserDecisionRouterConfig()
|
|
53
|
+
} catch {
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function localDecision(
|
|
59
|
+
request: string,
|
|
60
|
+
policy: LocalDecisionPolicy | undefined,
|
|
61
|
+
reasonCode: string,
|
|
62
|
+
): TurnDecision {
|
|
63
|
+
const skills = selectPantheonSkills(request)
|
|
64
|
+
const agent = hasDelegationSignal(request)
|
|
65
|
+
? recommendLocalDecisionAgent(request, policy).agent
|
|
66
|
+
: null
|
|
67
|
+
return {
|
|
68
|
+
schemaVersion: 1,
|
|
69
|
+
active: true,
|
|
70
|
+
source: 'local',
|
|
71
|
+
skillIds: skills.skillIds,
|
|
72
|
+
agent,
|
|
73
|
+
reasonCode,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Produce the deterministic local recommendation without entering the
|
|
79
|
+
* provider, consent, credential, permission, or transport path. The legacy
|
|
80
|
+
* per-turn `enabled` preference gates this advisory behavior; provider-selection
|
|
81
|
+
* and egress settings do not.
|
|
82
|
+
*/
|
|
83
|
+
export async function decideLocalForTurn(input: TurnDecisionInput): Promise<TurnDecision> {
|
|
84
|
+
const request = typeof input.request === 'string' ? input.request : ''
|
|
85
|
+
const sessionID = typeof input.sessionID === 'string' ? input.sessionID.trim() : ''
|
|
86
|
+
const messageID = typeof input.messageID === 'string' ? input.messageID.trim() : ''
|
|
87
|
+
if (
|
|
88
|
+
request.trim().length === 0 ||
|
|
89
|
+
request.length > MAX_REQUEST_LENGTH ||
|
|
90
|
+
sessionID.length === 0 ||
|
|
91
|
+
messageID.length === 0
|
|
92
|
+
) {
|
|
93
|
+
return inactive('INVALID_INPUT')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const config = readConfig()
|
|
97
|
+
if (config === undefined || !isUserDecisionRouterEnabled(config)) return inactive('DISABLED')
|
|
98
|
+
|
|
99
|
+
const policy = await loadLocalDecisionPolicy().catch(() => undefined)
|
|
100
|
+
return localDecision(request, policy, 'LOCAL_SELECTION')
|
|
101
|
+
}
|