pantheon-opencode 1.6.2-beta.3 → 1.6.2-beta.4
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 +34 -0
- package/README.md +38 -1
- package/bin/pantheon-init.mjs +17 -0
- package/package.json +9 -3
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +781 -0
- package/scripts/decision-router.mjs +297 -0
- package/scripts/install/decision-router-config.mjs +432 -0
- package/scripts/install/interactive.mjs +76 -5
- package/scripts/install/opencode.mjs +12 -0
- package/scripts/install/state.mjs +5 -0
- package/scripts/install/strings.mjs +4 -0
- package/src/agents/zeus.md +12 -0
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1043 -0
- package/src/pantheon/local-decision-egress-gate.ts +264 -0
- package/src/pantheon/local-decision-prompt.ts +123 -0
- package/src/pantheon/local-decision-provider-matrix.ts +92 -0
- package/src/pantheon/local-decision-provider-protocol.ts +335 -0
- package/src/pantheon/local-decision-provider.internal.ts +260 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +171 -0
- package/src/pantheon/local-decision-tool.ts +126 -0
- package/src/pantheon/local-decision-turn.ts +338 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +207 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-tools.ts +15 -14
- package/src/plugin-v2.ts +52 -19
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/dist/tui-v2.js +3 -3
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { PANTHEON_AGENTS } from './v2-delegation-enforce.ts'
|
|
2
|
+
|
|
3
|
+
/** Explicit opt-in for the local advisory API. Unset and any value except `1` disable it. */
|
|
4
|
+
export const LOCAL_DECISION_ROUTER_ENV = 'PANTHEON_LOCAL_DECISION_ROUTER'
|
|
5
|
+
export const LOCAL_DECISION_ROUTER_POLICY_VERSION = 'local-decision-router/v1'
|
|
6
|
+
|
|
7
|
+
export const LOCAL_DECISION_COMPLEXITY_DIMENSIONS = [
|
|
8
|
+
'boundedness',
|
|
9
|
+
'reversibility',
|
|
10
|
+
'dependencies',
|
|
11
|
+
'uncertainty',
|
|
12
|
+
'verification',
|
|
13
|
+
] as const
|
|
14
|
+
|
|
15
|
+
export type LocalDecisionComplexityDimensions = Readonly<
|
|
16
|
+
Record<(typeof LOCAL_DECISION_COMPLEXITY_DIMENSIONS)[number], 0 | 1 | 2>
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
export type LocalDecisionGateStatus =
|
|
20
|
+
| 'none'
|
|
21
|
+
| 'review_required'
|
|
22
|
+
| 'human_approval_required'
|
|
23
|
+
| 'unresolved'
|
|
24
|
+
|
|
25
|
+
/** Versioned structured input; domain entries are exact canonical specialist IDs. */
|
|
26
|
+
export interface LocalDecisionInput {
|
|
27
|
+
schemaVersion: 1
|
|
28
|
+
domains: readonly string[]
|
|
29
|
+
complexity: LocalDecisionComplexityDimensions
|
|
30
|
+
gateStatus: LocalDecisionGateStatus
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type LocalDecisionRouteReasonCode =
|
|
34
|
+
| 'DISABLED'
|
|
35
|
+
| 'INVALID_INPUT'
|
|
36
|
+
| 'NO_DOMAIN'
|
|
37
|
+
| 'AMBIGUOUS_DOMAIN'
|
|
38
|
+
| 'UNKNOWN_DOMAIN'
|
|
39
|
+
| 'UNROUTABLE_ROLE'
|
|
40
|
+
| 'CANONICAL_ROLE'
|
|
41
|
+
|
|
42
|
+
export type LocalDecisionComplexityReasonCode =
|
|
43
|
+
| 'DISABLED'
|
|
44
|
+
| 'INVALID_INPUT'
|
|
45
|
+
| 'INVALID_COMPLEXITY'
|
|
46
|
+
| 'CLASSIFIED_FROM_STRUCTURED_DIMENSIONS'
|
|
47
|
+
|
|
48
|
+
export interface LocalDecisionRecommendation {
|
|
49
|
+
schemaVersion: 1
|
|
50
|
+
policyVersion: typeof LOCAL_DECISION_ROUTER_POLICY_VERSION
|
|
51
|
+
decision: 'route' | 'abstain'
|
|
52
|
+
/** Non-null only when `decision` is `route`, and always a canonical specialist ID. */
|
|
53
|
+
agent: string | null
|
|
54
|
+
reasonCode: LocalDecisionRouteReasonCode
|
|
55
|
+
complexity: {
|
|
56
|
+
label: 'low' | 'medium' | 'high' | 'abstain'
|
|
57
|
+
reasonCode: LocalDecisionComplexityReasonCode
|
|
58
|
+
}
|
|
59
|
+
/** Security/authorization status is carried separately and never changes complexity. */
|
|
60
|
+
gateStatus: LocalDecisionGateStatus
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const ROUTABLE_AGENTS: ReadonlySet<string> = new Set(
|
|
64
|
+
[...PANTHEON_AGENTS].filter((agent) => agent !== 'zeus'),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const GATE_STATUSES: ReadonlySet<string> = new Set([
|
|
68
|
+
'none',
|
|
69
|
+
'review_required',
|
|
70
|
+
'human_approval_required',
|
|
71
|
+
'unresolved',
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
const INPUT_KEYS = ['complexity', 'domains', 'gateStatus', 'schemaVersion']
|
|
75
|
+
const COMPLEXITY_KEYS = [...LOCAL_DECISION_COMPLEXITY_DIMENSIONS].sort()
|
|
76
|
+
|
|
77
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
78
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false
|
|
79
|
+
const prototype = Object.getPrototypeOf(value)
|
|
80
|
+
return prototype === Object.prototype || prototype === null
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function hasExactKeys(value: Record<string, unknown>, keys: readonly string[]): boolean {
|
|
84
|
+
const actualKeys = Object.keys(value).sort()
|
|
85
|
+
const expectedKeys = [...keys].sort()
|
|
86
|
+
return (
|
|
87
|
+
actualKeys.length === expectedKeys.length &&
|
|
88
|
+
actualKeys.every((key, index) => key === expectedKeys[index])
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isValidInputShape(input: unknown): input is LocalDecisionInput {
|
|
93
|
+
if (!isPlainRecord(input) || !hasExactKeys(input, INPUT_KEYS)) return false
|
|
94
|
+
if (
|
|
95
|
+
input.schemaVersion !== 1 ||
|
|
96
|
+
typeof input.gateStatus !== 'string' ||
|
|
97
|
+
!GATE_STATUSES.has(input.gateStatus)
|
|
98
|
+
) {
|
|
99
|
+
return false
|
|
100
|
+
}
|
|
101
|
+
if (
|
|
102
|
+
!Array.isArray(input.domains) ||
|
|
103
|
+
!input.domains.every((domain) => typeof domain === 'string')
|
|
104
|
+
) {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
if (!isPlainRecord(input.complexity) || !hasExactKeys(input.complexity, COMPLEXITY_KEYS)) {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
return classifyLocalDecisionComplexity(input.complexity).label !== 'abstain'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function classifyLocalDecisionComplexity(
|
|
114
|
+
value: unknown,
|
|
115
|
+
): LocalDecisionRecommendation['complexity'] {
|
|
116
|
+
if (!isPlainRecord(value) || !hasExactKeys(value, COMPLEXITY_KEYS)) {
|
|
117
|
+
return { label: 'abstain', reasonCode: 'INVALID_COMPLEXITY' }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const scores = LOCAL_DECISION_COMPLEXITY_DIMENSIONS.map((dimension) => value[dimension])
|
|
121
|
+
if (
|
|
122
|
+
!scores.every(
|
|
123
|
+
(score) => typeof score === 'number' && Number.isInteger(score) && score >= 0 && score <= 2,
|
|
124
|
+
)
|
|
125
|
+
) {
|
|
126
|
+
return { label: 'abstain', reasonCode: 'INVALID_COMPLEXITY' }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const label = scores.includes(2) ? 'high' : scores.includes(1) ? 'medium' : 'low'
|
|
130
|
+
return { label, reasonCode: 'CLASSIFIED_FROM_STRUCTURED_DIMENSIONS' }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createAbstention(
|
|
134
|
+
reasonCode: LocalDecisionRouteReasonCode,
|
|
135
|
+
complexityReasonCode: LocalDecisionComplexityReasonCode,
|
|
136
|
+
gateStatus: LocalDecisionGateStatus = 'unresolved',
|
|
137
|
+
): LocalDecisionRecommendation {
|
|
138
|
+
return {
|
|
139
|
+
schemaVersion: 1,
|
|
140
|
+
policyVersion: LOCAL_DECISION_ROUTER_POLICY_VERSION,
|
|
141
|
+
decision: 'abstain',
|
|
142
|
+
agent: null,
|
|
143
|
+
reasonCode,
|
|
144
|
+
complexity: { label: 'abstain', reasonCode: complexityReasonCode },
|
|
145
|
+
gateStatus,
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function evaluateEnabledInput(input: unknown): LocalDecisionRecommendation {
|
|
150
|
+
if (!isValidInputShape(input)) {
|
|
151
|
+
const gateStatus =
|
|
152
|
+
isPlainRecord(input) &&
|
|
153
|
+
typeof input.gateStatus === 'string' &&
|
|
154
|
+
GATE_STATUSES.has(input.gateStatus)
|
|
155
|
+
? (input.gateStatus as LocalDecisionGateStatus)
|
|
156
|
+
: 'unresolved'
|
|
157
|
+
const complexity = isPlainRecord(input)
|
|
158
|
+
? classifyLocalDecisionComplexity(input.complexity)
|
|
159
|
+
: { label: 'abstain' as const, reasonCode: 'INVALID_COMPLEXITY' as const }
|
|
160
|
+
const complexityReasonCode =
|
|
161
|
+
complexity.reasonCode === 'INVALID_COMPLEXITY' ? 'INVALID_COMPLEXITY' : 'INVALID_INPUT'
|
|
162
|
+
return createAbstention('INVALID_INPUT', complexityReasonCode, gateStatus)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const gateStatus = input.gateStatus
|
|
166
|
+
const complexity = classifyLocalDecisionComplexity(input.complexity)
|
|
167
|
+
|
|
168
|
+
if (input.domains.length === 0) {
|
|
169
|
+
return { ...createAbstention('NO_DOMAIN', complexity.reasonCode, gateStatus), complexity }
|
|
170
|
+
}
|
|
171
|
+
if (input.domains.length !== 1) {
|
|
172
|
+
return {
|
|
173
|
+
...createAbstention('AMBIGUOUS_DOMAIN', complexity.reasonCode, gateStatus),
|
|
174
|
+
complexity,
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const [domain] = input.domains
|
|
179
|
+
if (typeof domain !== 'string') {
|
|
180
|
+
return createAbstention('INVALID_INPUT', complexity.reasonCode, gateStatus)
|
|
181
|
+
}
|
|
182
|
+
if (domain === 'zeus') {
|
|
183
|
+
return {
|
|
184
|
+
...createAbstention('UNROUTABLE_ROLE', complexity.reasonCode, gateStatus),
|
|
185
|
+
complexity,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (!ROUTABLE_AGENTS.has(domain)) {
|
|
189
|
+
return {
|
|
190
|
+
...createAbstention('UNKNOWN_DOMAIN', complexity.reasonCode, gateStatus),
|
|
191
|
+
complexity,
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
schemaVersion: 1,
|
|
197
|
+
policyVersion: LOCAL_DECISION_ROUTER_POLICY_VERSION,
|
|
198
|
+
decision: 'route',
|
|
199
|
+
agent: domain,
|
|
200
|
+
reasonCode: 'CANONICAL_ROLE',
|
|
201
|
+
complexity,
|
|
202
|
+
gateStatus,
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Return a local advisory recommendation only when explicitly enabled.
|
|
208
|
+
*
|
|
209
|
+
* This function never calls a provider, dispatches an agent, or changes permissions.
|
|
210
|
+
* The default-off environment gate intentionally leaves native host dispatch untouched.
|
|
211
|
+
*/
|
|
212
|
+
export function recommendLocalDecision(
|
|
213
|
+
input: LocalDecisionInput,
|
|
214
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
215
|
+
): LocalDecisionRecommendation {
|
|
216
|
+
try {
|
|
217
|
+
if (env[LOCAL_DECISION_ROUTER_ENV] !== '1') {
|
|
218
|
+
return createAbstention('DISABLED', 'DISABLED')
|
|
219
|
+
}
|
|
220
|
+
return evaluateEnabledInput(input)
|
|
221
|
+
} catch {
|
|
222
|
+
// Malformed accessors and injected env are invalid data; never route on failure.
|
|
223
|
+
return createAbstention('INVALID_INPUT', 'INVALID_INPUT')
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { PANTHEON_SKILL_CATALOG, PANTHEON_SKILL_IDS } from './pantheon-decision-catalog.ts'
|
|
2
|
+
|
|
3
|
+
export type SkillSelectionReason = 'SELECTED_BY_KEYWORDS' | 'NO_LOCAL_MATCH' | 'INVALID_INPUT'
|
|
4
|
+
|
|
5
|
+
export interface LocalSkillSelection {
|
|
6
|
+
skillIds: string[]
|
|
7
|
+
reasonCode: SkillSelectionReason
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Bounded so a malformed or huge prompt can never fan out local work. */
|
|
11
|
+
export const MAX_SELECTED_SKILLS = 4
|
|
12
|
+
const MAX_REQUEST_LENGTH = 20_000
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Small, allowlisted keyword table. It is intentionally local and
|
|
16
|
+
* deterministic: no model, no embedding index, no network.
|
|
17
|
+
*/
|
|
18
|
+
const KEYWORDS: Readonly<Record<string, readonly string[]>> = Object.freeze({
|
|
19
|
+
'agent-coordination': [
|
|
20
|
+
'agent',
|
|
21
|
+
'agents',
|
|
22
|
+
'delegate',
|
|
23
|
+
'delegation',
|
|
24
|
+
'orchestrate',
|
|
25
|
+
'orchestration',
|
|
26
|
+
'route',
|
|
27
|
+
'routing',
|
|
28
|
+
'subagent',
|
|
29
|
+
],
|
|
30
|
+
'artifact-management': ['artifact', 'artifacts', 'planned', 'multi-phase', 'impl'],
|
|
31
|
+
'auto-continue': ['continue', 'continuation', 'todo', 'todos', 'multi-step', 'idle'],
|
|
32
|
+
clonedeps: ['clone', 'dependency', 'dependencies', 'internals', 'library', 'package'],
|
|
33
|
+
'code-review-checklist': ['review', 'reviews', 'pull request', 'feedback', 'checklist'],
|
|
34
|
+
codemap: ['codemap', 'structure', 'codebase', 'unfamiliar', 'repository', 'overview'],
|
|
35
|
+
'context-compression': ['compact', 'compaction', 'compress', 'context', 'checkpoint', 'resume'],
|
|
36
|
+
'git-workflow-and-versioning': [
|
|
37
|
+
'commit',
|
|
38
|
+
'commits',
|
|
39
|
+
'git',
|
|
40
|
+
'branch',
|
|
41
|
+
'version',
|
|
42
|
+
'release',
|
|
43
|
+
'tag',
|
|
44
|
+
'changelog',
|
|
45
|
+
],
|
|
46
|
+
'incremental-implementation': [
|
|
47
|
+
'increment',
|
|
48
|
+
'incremental',
|
|
49
|
+
'slice',
|
|
50
|
+
'slices',
|
|
51
|
+
'implement',
|
|
52
|
+
'implementation',
|
|
53
|
+
],
|
|
54
|
+
'loop-engineering': ['loop', 'iterate', 'iteration', 'refine', 'refinement', 'cycle'],
|
|
55
|
+
'memory-bank': ['memory', 'adr', 'adrs', 'documentation', 'docs', 'knowledge'],
|
|
56
|
+
reflect: ['reflect', 'reflection', 'retro', 'retrospective', 'friction', 'workflow'],
|
|
57
|
+
'security-hardening': [
|
|
58
|
+
'security',
|
|
59
|
+
'secure',
|
|
60
|
+
'owasp',
|
|
61
|
+
'vulnerability',
|
|
62
|
+
'vulnerabilities',
|
|
63
|
+
'secret',
|
|
64
|
+
'secrets',
|
|
65
|
+
'cve',
|
|
66
|
+
'audit',
|
|
67
|
+
],
|
|
68
|
+
'session-goal': ['goal', 'objective', 'scope', 'alignment', 'session'],
|
|
69
|
+
simplify: [
|
|
70
|
+
'simplify',
|
|
71
|
+
'simplification',
|
|
72
|
+
'refactor',
|
|
73
|
+
'complexity',
|
|
74
|
+
'readable',
|
|
75
|
+
'readability',
|
|
76
|
+
'cleanup',
|
|
77
|
+
],
|
|
78
|
+
'spec-driven-development': [
|
|
79
|
+
'spec',
|
|
80
|
+
'specification',
|
|
81
|
+
'requirements',
|
|
82
|
+
'prd',
|
|
83
|
+
'acceptance',
|
|
84
|
+
'criteria',
|
|
85
|
+
],
|
|
86
|
+
'tdd-with-agents': ['tdd', 'test', 'tests', 'testing', 'pytest', 'vitest', 'jest', 'coverage'],
|
|
87
|
+
'verification-planning': [
|
|
88
|
+
'verification',
|
|
89
|
+
'verify',
|
|
90
|
+
'evidence',
|
|
91
|
+
'validation',
|
|
92
|
+
'validate',
|
|
93
|
+
'reproduce',
|
|
94
|
+
],
|
|
95
|
+
'visual-review-pipeline': [
|
|
96
|
+
'visual',
|
|
97
|
+
'screenshot',
|
|
98
|
+
'screenshots',
|
|
99
|
+
'ui',
|
|
100
|
+
'ux',
|
|
101
|
+
'accessibility',
|
|
102
|
+
'wcag',
|
|
103
|
+
'playwright',
|
|
104
|
+
'responsive',
|
|
105
|
+
],
|
|
106
|
+
worktrees: ['worktree', 'worktrees', 'parallel', 'isolation', 'isolated'],
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const CATALOG_ORDER = new Map(PANTHEON_SKILL_CATALOG.map((entry, index) => [entry.id, index]))
|
|
110
|
+
|
|
111
|
+
function normalize(value: string): string {
|
|
112
|
+
return value
|
|
113
|
+
.normalize('NFD')
|
|
114
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
115
|
+
.toLowerCase()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function tokenize(value: string): Set<string> {
|
|
119
|
+
const tokens = value.match(/[a-z0-9]+(?:[+#.-][a-z0-9]+)*/g) ?? []
|
|
120
|
+
return new Set(tokens)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function scoreSkill(normalizedRequest: string, tokens: ReadonlySet<string>, skillId: string) {
|
|
124
|
+
const keywords = KEYWORDS[skillId] ?? []
|
|
125
|
+
let score = 0
|
|
126
|
+
for (const keyword of keywords) {
|
|
127
|
+
if (keyword.includes(' ')) {
|
|
128
|
+
if (normalizedRequest.includes(keyword)) score += 3
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
if (tokens.has(keyword)) score += 2
|
|
132
|
+
}
|
|
133
|
+
return score
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Select a small, deterministic set of allowlisted Pantheon skills for the
|
|
138
|
+
* current request. This function never reads files, memory, transcripts, or
|
|
139
|
+
* the network, and it never returns the whole catalog as a fallback.
|
|
140
|
+
*/
|
|
141
|
+
export function selectPantheonSkills(
|
|
142
|
+
request: unknown,
|
|
143
|
+
maxSkills = MAX_SELECTED_SKILLS,
|
|
144
|
+
): LocalSkillSelection {
|
|
145
|
+
if (
|
|
146
|
+
typeof request !== 'string' ||
|
|
147
|
+
request.trim().length === 0 ||
|
|
148
|
+
request.length > MAX_REQUEST_LENGTH ||
|
|
149
|
+
!Number.isInteger(maxSkills) ||
|
|
150
|
+
maxSkills < 1 ||
|
|
151
|
+
maxSkills > MAX_SELECTED_SKILLS
|
|
152
|
+
) {
|
|
153
|
+
return { skillIds: [], reasonCode: 'INVALID_INPUT' }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const normalizedRequest = normalize(request)
|
|
157
|
+
const tokens = tokenize(normalizedRequest)
|
|
158
|
+
const scored: Array<{ id: string; score: number; order: number }> = []
|
|
159
|
+
for (const skillId of PANTHEON_SKILL_IDS) {
|
|
160
|
+
const score = scoreSkill(normalizedRequest, tokens, skillId)
|
|
161
|
+
if (score <= 0) continue
|
|
162
|
+
scored.push({ id: skillId, score, order: CATALOG_ORDER.get(skillId) ?? 0 })
|
|
163
|
+
}
|
|
164
|
+
if (scored.length === 0) return { skillIds: [], reasonCode: 'NO_LOCAL_MATCH' }
|
|
165
|
+
|
|
166
|
+
scored.sort((left, right) => right.score - left.score || left.order - right.order)
|
|
167
|
+
return {
|
|
168
|
+
skillIds: scored.slice(0, maxSkills).map((entry) => entry.id),
|
|
169
|
+
reasonCode: 'SELECTED_BY_KEYWORDS',
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
|
|
12
|
+
const TOOL_DESCRIPTION =
|
|
13
|
+
'Zeus-only local advisory selector. Use selectively only when specialist routing is genuinely ' +
|
|
14
|
+
'ambiguous; obvious work should go directly to native subagent without this tool. Accepts only ' +
|
|
15
|
+
'structured candidate IDs, never task text. It does not dispatch, run a skill/resource, search ' +
|
|
16
|
+
'memory, or authorize/alter grants or review gates. Provider egress is disabled; all decisions ' +
|
|
17
|
+
'remain local.'
|
|
18
|
+
|
|
19
|
+
const gateStatuses: LocalDecisionGateStatus[] = [
|
|
20
|
+
'none',
|
|
21
|
+
'review_required',
|
|
22
|
+
'human_approval_required',
|
|
23
|
+
'unresolved',
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
const inputShape = {
|
|
27
|
+
schemaVersion: tool.schema.literal(1),
|
|
28
|
+
candidateAgents: tool.schema.array(tool.schema.string().min(1)).max(14),
|
|
29
|
+
domain: tool.schema.string().nullable(),
|
|
30
|
+
candidateSkillIds: tool.schema.array(tool.schema.string().min(1)).max(64),
|
|
31
|
+
candidateResourceIds: tool.schema.array(tool.schema.string().min(1)).max(32),
|
|
32
|
+
memorySearchRelevant: tool.schema.boolean(),
|
|
33
|
+
gateStatus: tool.schema.enum(
|
|
34
|
+
gateStatuses as [LocalDecisionGateStatus, ...LocalDecisionGateStatus[]],
|
|
35
|
+
),
|
|
36
|
+
complexity: tool.schema
|
|
37
|
+
.object({
|
|
38
|
+
boundedness: tool.schema.number().int().min(0).max(2),
|
|
39
|
+
reversibility: tool.schema.number().int().min(0).max(2),
|
|
40
|
+
dependencies: tool.schema.number().int().min(0).max(2),
|
|
41
|
+
uncertainty: tool.schema.number().int().min(0).max(2),
|
|
42
|
+
verification: tool.schema.number().int().min(0).max(2),
|
|
43
|
+
})
|
|
44
|
+
.strict(),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type LocalDecisionToolOptions = {
|
|
48
|
+
loadPolicy?: () => Promise<LocalDecisionPolicy | undefined>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function runDecision(
|
|
52
|
+
input: unknown,
|
|
53
|
+
callerAgent: unknown,
|
|
54
|
+
loadPolicy: () => Promise<LocalDecisionPolicy | undefined>,
|
|
55
|
+
): Promise<string> {
|
|
56
|
+
if (callerAgent !== 'zeus') {
|
|
57
|
+
return JSON.stringify(recommendLocalOrchestration(input, callerAgent, undefined))
|
|
58
|
+
}
|
|
59
|
+
const policy = await loadPolicy().catch(() => undefined)
|
|
60
|
+
// Caller context is a host-provided identity string, not non-forgeable runtime provenance.
|
|
61
|
+
// Keep this route hard local-only until provider authorization can be established safely.
|
|
62
|
+
return JSON.stringify(recommendLocalOrchestration(input, callerAgent, policy))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Create the V1 plugin tool; execution is fail-closed unless host context identifies Zeus. */
|
|
66
|
+
export function createLocalDecisionTool(options: LocalDecisionToolOptions = {}) {
|
|
67
|
+
const policyLoader = options.loadPolicy ?? loadLocalDecisionPolicy
|
|
68
|
+
return tool({
|
|
69
|
+
description: TOOL_DESCRIPTION,
|
|
70
|
+
args: inputShape,
|
|
71
|
+
execute: async (input, context: ToolContext) => runDecision(input, context.agent, policyLoader),
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const v2InputSchema: Record<string, unknown> = {
|
|
76
|
+
type: 'object',
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
required: [
|
|
79
|
+
'schemaVersion',
|
|
80
|
+
'candidateAgents',
|
|
81
|
+
'domain',
|
|
82
|
+
'candidateSkillIds',
|
|
83
|
+
'candidateResourceIds',
|
|
84
|
+
'memorySearchRelevant',
|
|
85
|
+
'gateStatus',
|
|
86
|
+
'complexity',
|
|
87
|
+
],
|
|
88
|
+
properties: {
|
|
89
|
+
schemaVersion: { type: 'integer', const: 1 },
|
|
90
|
+
candidateAgents: { type: 'array', maxItems: 14, items: { type: 'string', minLength: 1 } },
|
|
91
|
+
domain: { type: ['string', 'null'] },
|
|
92
|
+
candidateSkillIds: { type: 'array', maxItems: 64, items: { type: 'string', minLength: 1 } },
|
|
93
|
+
candidateResourceIds: { type: 'array', maxItems: 32, items: { type: 'string', minLength: 1 } },
|
|
94
|
+
memorySearchRelevant: { type: 'boolean' },
|
|
95
|
+
gateStatus: { type: 'string', enum: gateStatuses },
|
|
96
|
+
complexity: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
additionalProperties: false,
|
|
99
|
+
required: [...LOCAL_DECISION_COMPLEXITY_DIMENSIONS],
|
|
100
|
+
properties: Object.fromEntries(
|
|
101
|
+
LOCAL_DECISION_COMPLEXITY_DIMENSIONS.map((dimension) => [
|
|
102
|
+
dimension,
|
|
103
|
+
{ type: 'integer', minimum: 0, maximum: 2 },
|
|
104
|
+
]),
|
|
105
|
+
),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Create a V2 transform definition with the same Zeus-only execution guard and local plan. */
|
|
111
|
+
export function createV2LocalDecisionDefinition(options: LocalDecisionToolOptions = {}) {
|
|
112
|
+
const policyLoader = options.loadPolicy ?? loadLocalDecisionPolicy
|
|
113
|
+
return {
|
|
114
|
+
name: 'pantheon_local_decision',
|
|
115
|
+
description: TOOL_DESCRIPTION,
|
|
116
|
+
input: v2InputSchema,
|
|
117
|
+
output: {},
|
|
118
|
+
execute: async (input: Record<string, unknown>, context: unknown) => {
|
|
119
|
+
const callerAgent =
|
|
120
|
+
context !== null && typeof context === 'object'
|
|
121
|
+
? (context as { agent?: unknown }).agent
|
|
122
|
+
: undefined
|
|
123
|
+
return { output: await runDecision(input, callerAgent, policyLoader) }
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
}
|