pantheon-opencode 1.5.0-beta.16 → 1.5.0-beta.18

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +13 -25
  3. package/README.pt-BR.md +4 -5
  4. package/package.json +1 -1
  5. package/plugin.json +1 -1
  6. package/pyproject.toml +1 -1
  7. package/scripts/mcp_persistence_server.py +1 -1
  8. package/src/agents/apollo.md +1 -0
  9. package/src/agents/gaia.md +1 -0
  10. package/src/agents/zeus.md +8 -29
  11. package/src/mcp/mcp_persistence_server.py +1 -1
  12. package/src/pantheon/{delegation-compaction.ts → compaction-context.ts} +10 -100
  13. package/src/pantheon/cost-command.ts +1 -2
  14. package/src/pantheon/delegation-enforce.ts +59 -14
  15. package/src/pantheon/goal-loop.ts +1 -1
  16. package/src/pantheon/goal-store.ts +1 -1
  17. package/src/pantheon/idle-continuation.ts +4 -6
  18. package/src/pantheon/model-command.ts +1 -2
  19. package/src/pantheon/native-task-status.ts +2 -2
  20. package/src/pantheon/session-id.ts +30 -0
  21. package/src/pantheon/task-result-guard.ts +2 -3
  22. package/src/pantheon/todo-enforcer.ts +3 -3
  23. package/src/pantheon/tool-context.ts +23 -0
  24. package/src/pantheon/v2-bridge.ts +1 -4
  25. package/src/plugin-v2.ts +4 -15
  26. package/src/plugin.ts +61 -245
  27. package/src/plugins/tui/dist/tui.d.ts +49 -79
  28. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  29. package/src/plugins/tui/dist/tui.js +48 -189
  30. package/src/plugins/tui/package-lock.json +2 -2
  31. package/src/plugins/tui/package.json +1 -1
  32. package/src/plugins/tui/src/index.tsx +97 -295
  33. package/src/skills/context-compression/SKILL.md +1 -1
  34. package/src/pantheon/delegate-manager.ts +0 -851
  35. package/src/pantheon/delegation-classifier.ts +0 -306
  36. package/src/pantheon/delegation-finalize.ts +0 -468
  37. package/src/pantheon/delegation-notify.ts +0 -212
  38. package/src/pantheon/delegation-toast.ts +0 -73
  39. package/src/pantheon/delegation.ts +0 -1349
  40. package/src/pantheon/native-probe.ts +0 -234
  41. package/src/pantheon/step-cap.ts +0 -110
@@ -1,234 +0,0 @@
1
- /**
2
- * Native Probe — lazy capability detection for native task() delegation.
3
- *
4
- * The probe is invoked on the FIRST native delegation of a session (not at
5
- * startup). It creates a child session with a minimal "ping" prompt, waits
6
- * for idle, and classifies the output.
7
- *
8
- * Results are cached per probe instance (singleton guard):
9
- * - UNAVAILABLE is TERMINAL — no retry.
10
- * - AVAILABLE is also cached — no re-probe.
11
- *
12
- * Uses the OpenCode V1 session API (session.create + promptAsync) injected via
13
- * the parent context.
14
- *
15
- * @module native-probe
16
- */
17
-
18
- import { createPantheonLogger } from './logger.ts'
19
-
20
- const log = createPantheonLogger({ module: 'native-probe' })
21
-
22
- // ─── Types ─────────────────────────────────────────────────────────────
23
-
24
- /** Possible outcomes of a native capability probe. */
25
- export type NativeProbeResult = {
26
- status: 'AVAILABLE' | 'UNAVAILABLE' | 'UNSUPPORTED'
27
- }
28
-
29
- /** Minimal V1 client shape needed by the probe (session.create + promptAsync). */
30
- export interface ProbeClient {
31
- session: {
32
- create: (input: { body: { parentID: string } }) => Promise<{ id: string }>
33
- promptAsync: (input: {
34
- path: { id: string }
35
- body: { agent: string; parts: Array<{ type: 'text'; text: string }> }
36
- }) => Promise<unknown>
37
- }
38
- }
39
-
40
- /** Context injected into the probe function. */
41
- export interface NativeProbeContext {
42
- client: ProbeClient
43
- parentSessionID: string
44
- }
45
-
46
- /** Options for a single probe invocation. */
47
- export interface NativeProbeOptions {
48
- /** Timeout in milliseconds. Default: 30000. */
49
- timeoutMs?: number
50
- }
51
-
52
- /** The probe function signature. */
53
- export type NativeProbeFn = (
54
- ctx: NativeProbeContext,
55
- options?: NativeProbeOptions,
56
- ) => Promise<NativeProbeResult>
57
-
58
- // ─── Helpers ───────────────────────────────────────────────────────────
59
-
60
- /** Default timeout for the probe. */
61
- const DEFAULT_TIMEOUT_MS = 30_000
62
-
63
- /** Sentinel value indicating a timeout occurred. */
64
- const TIMEOUT_SENTINEL = Symbol('timeout')
65
-
66
- /**
67
- * Wrap a promise with a timeout.
68
- * Returns the value on success, throws the original error on rejection,
69
- * or returns TIMEOUT_SENTINEL if the timeout fires first.
70
- */
71
- async function withTimeout<T>(
72
- promise: Promise<T>,
73
- ms: number,
74
- ): Promise<T | typeof TIMEOUT_SENTINEL> {
75
- return new Promise<T | typeof TIMEOUT_SENTINEL>((resolve, reject) => {
76
- const timer = setTimeout(() => resolve(TIMEOUT_SENTINEL), ms)
77
- void promise.then(
78
- (value) => {
79
- clearTimeout(timer)
80
- resolve(value)
81
- },
82
- (err: unknown) => {
83
- clearTimeout(timer)
84
- reject(err)
85
- },
86
- )
87
- })
88
- }
89
-
90
- /**
91
- * Extract text content from a promptAsync response.
92
- * Returns empty string if no recognizable content found.
93
- */
94
- function extractOutput(result: unknown): string {
95
- if (result == null) return ''
96
- if (typeof result === 'string') return result
97
- if (typeof result === 'object') {
98
- const obj = result as Record<string, unknown>
99
- // Check common shapes: { output }, { content }, { text }
100
- if (typeof obj.output === 'string') return obj.output
101
- if (typeof obj.content === 'string') return obj.content
102
- if (typeof obj.text === 'string') return obj.text
103
- }
104
- // Non-empty object → treat as content (accepted message, etc.)
105
- if (typeof result === 'object' && result !== null) {
106
- return 'acknowledged'
107
- }
108
- return ''
109
- }
110
-
111
- function isUnsupportedError(message: string): boolean {
112
- const lower = message.toLowerCase()
113
- return (
114
- lower.includes('not available') ||
115
- lower.includes('not supported') ||
116
- lower.includes('unsupported') ||
117
- lower.includes('method not found')
118
- )
119
- }
120
-
121
- // ─── Implementation ────────────────────────────────────────────────────
122
-
123
- /**
124
- * Create a native probe function with per-instance caching.
125
- *
126
- * The probe is LAZY: it does not run at startup. Call it on the first
127
- * native delegation of the session. The result is cached — subsequent
128
- * calls return the cached value without re-probing.
129
- *
130
- * @returns A probe function that caches results per instance.
131
- */
132
- export function createNativeProbe(): NativeProbeFn {
133
- let cachedResult: NativeProbeResult | null = null
134
- let inFlight: Promise<NativeProbeResult> | null = null
135
-
136
- return async (
137
- ctx: NativeProbeContext,
138
- options?: NativeProbeOptions,
139
- ): Promise<NativeProbeResult> => {
140
- // Return cached result if available (singleton guard)
141
- if (cachedResult !== null) {
142
- return cachedResult
143
- }
144
- // Concurrent first dispatches share one probe instead of creating multiple
145
- // child sessions. The promise is cleared only after a terminal result.
146
- if (inFlight !== null) return inFlight
147
-
148
- inFlight = probe(ctx, options)
149
- try {
150
- return await inFlight
151
- } finally {
152
- inFlight = null
153
- }
154
- }
155
-
156
- async function probe(
157
- ctx: NativeProbeContext,
158
- options?: NativeProbeOptions,
159
- ): Promise<NativeProbeResult> {
160
- const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS
161
-
162
- // ── Phase 1: create child session ──────────────────────────────
163
- let childID: string
164
- try {
165
- const createResult = await withTimeout(
166
- ctx.client.session.create({ body: { parentID: ctx.parentSessionID } }),
167
- timeoutMs,
168
- )
169
- if (createResult === TIMEOUT_SENTINEL) {
170
- // Timeout during session.create → UNAVAILABLE
171
- log.warn('[Native Probe] session.create timed out after', timeoutMs, 'ms')
172
- const result: NativeProbeResult = { status: 'UNAVAILABLE' }
173
- cachedResult = result
174
- return result
175
- }
176
- childID = createResult.id
177
- } catch (err: unknown) {
178
- const msg = err instanceof Error ? err.message : String(err)
179
- log.error('[Native Probe] session.create failed:', msg)
180
- // Check for unsupported API patterns
181
- if (isUnsupportedError(msg)) {
182
- const result: NativeProbeResult = { status: 'UNSUPPORTED' }
183
- cachedResult = result
184
- return result
185
- }
186
- // Other creation failures → UNAVAILABLE
187
- const result: NativeProbeResult = { status: 'UNAVAILABLE' }
188
- cachedResult = result
189
- return result
190
- }
191
-
192
- // ── Phase 2: send probe prompt ─────────────────────────────────
193
- let promptResult: unknown
194
- try {
195
- const raw = await withTimeout(
196
- ctx.client.session.promptAsync({
197
- path: { id: childID },
198
- body: { agent: 'probe', parts: [{ type: 'text', text: 'Reply with PONG.' }] },
199
- }),
200
- timeoutMs,
201
- )
202
- if (raw === TIMEOUT_SENTINEL) {
203
- // Timeout during promptAsync → UNAVAILABLE
204
- log.warn('[Native Probe] promptAsync timed out after', timeoutMs, 'ms')
205
- const result: NativeProbeResult = { status: 'UNAVAILABLE' }
206
- cachedResult = result
207
- return result
208
- }
209
- promptResult = raw
210
- } catch (err: unknown) {
211
- const msg = err instanceof Error ? err.message : String(err)
212
- log.error('[Native Probe] promptAsync failed:', msg)
213
- if (isUnsupportedError(msg)) {
214
- const result: NativeProbeResult = { status: 'UNSUPPORTED' }
215
- cachedResult = result
216
- return result
217
- }
218
- // promptAsync error → UNAVAILABLE
219
- const result: NativeProbeResult = { status: 'UNAVAILABLE' }
220
- cachedResult = result
221
- return result
222
- }
223
-
224
- // ── Phase 3: classify output ───────────────────────────────────
225
- const output = extractOutput(promptResult)
226
- const hasContent = output.trim() !== ''
227
-
228
- const result: NativeProbeResult = {
229
- status: hasContent ? 'AVAILABLE' : 'UNAVAILABLE',
230
- }
231
- cachedResult = result
232
- return result
233
- }
234
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * R4 — Per-agent step caps (max_steps).
3
- *
4
- * Pure library. routing.yml `agents.<name>.max_steps` gives each agent a
5
- * step budget (e.g. explore: 25, reviewer: 25, oracle: 15). When an agent's
6
- * step count reaches max_steps it is forced to summarize-and-stop: the
7
- * delegation is either skipped with a capped summary (already at cap) or
8
- * the prompt is appended with a stop instruction (cap hit mid-dispatch).
9
- *
10
- * The tracker is PERMANENT-PER-PROCESS: counters accumulate for the process
11
- * lifetime and are intentionally NOT reset on successful delegations or
12
- * session end — a per-session reset would let an agent exceed its process
13
- * budget over a long session. `reset()` exists as a tested utility for
14
- * tests and future explicit reset points; no production caller wires it.
15
- *
16
- * @module step-cap
17
- */
18
-
19
- // ─── Types ─────────────────────────────────────────────────────────────
20
-
21
- /** Default step budget when routing.yml omits max_steps for an agent. */
22
- export const DEFAULT_MAX_STEPS = 25
23
-
24
- // ─── Stop instruction ──────────────────────────────────────────────────
25
-
26
- /**
27
- * The forced summarize-and-stop instruction injected into a prompt when an
28
- * agent's step count reaches max_steps.
29
- */
30
- export function buildStopInstruction(agent: string, maxSteps: number): string {
31
- return (
32
- `\n\n[STEP CAP REACHED — ${agent} at ${maxSteps} steps] ` +
33
- `You have reached the maximum step budget for this delegation. ` +
34
- `STOP working immediately and summarize what was accomplished (and ` +
35
- `what remains, if any) as your final message. Do not start new work.`
36
- )
37
- }
38
-
39
- /**
40
- * The text returned when a delegation is skipped because the agent is
41
- * already at its step cap — marks the delegation as capped and asks for a
42
- * summary of prior results instead of starting new work.
43
- */
44
- export function cappedSummary(agent: string, maxSteps: number): string {
45
- return (
46
- `[STEP CAP REACHED] ${agent} has reached its max_steps budget (${maxSteps}). ` +
47
- `Delegation skipped — no new work was started. ` +
48
- `Summarize prior results and stop.`
49
- )
50
- }
51
-
52
- // ─── Tracker ───────────────────────────────────────────────────────────
53
-
54
- /**
55
- * Per-agent step counters with a max_steps budget. Keyed by lowercase agent
56
- * name (matching is case-insensitive). Agents without a configured budget
57
- * are never capped.
58
- */
59
- export class StepCapTracker {
60
- private readonly steps = new Map<string, number>()
61
- readonly maxStepsByAgent: Readonly<Record<string, number>>
62
-
63
- constructor(maxStepsByAgent: Readonly<Record<string, number>> = {}) {
64
- this.maxStepsByAgent = maxStepsByAgent
65
- }
66
-
67
- /** The configured budget for an agent, or undefined when uncapped. */
68
- maxStepsFor(agent: string): number | undefined {
69
- return this.maxStepsByAgent[agent.toLowerCase()]
70
- }
71
-
72
- /** Current step count for an agent. */
73
- stepCount(agent: string): number {
74
- return this.steps.get(agent.toLowerCase()) ?? 0
75
- }
76
-
77
- /** Whether the agent has reached (or exceeded) its max_steps budget. */
78
- isCapped(agent: string): boolean {
79
- const max = this.maxStepsFor(agent)
80
- if (max === undefined) return false
81
- return this.stepCount(agent) >= max
82
- }
83
-
84
- /**
85
- * Record one step for an agent. Returns the new count and whether this
86
- * step hit the cap (capped === true exactly when steps >= maxSteps).
87
- */
88
- recordStep(agent: string): {
89
- steps: number
90
- capped: boolean
91
- maxSteps: number | undefined
92
- } {
93
- const key = agent.toLowerCase()
94
- const max = this.maxStepsFor(agent)
95
- const steps = (this.steps.get(key) ?? 0) + 1
96
- this.steps.set(key, steps)
97
- return { steps, capped: max !== undefined && steps >= max, maxSteps: max }
98
- }
99
-
100
- /**
101
- * Reset an agent's step count.
102
- *
103
- * Intentionally NOT wired in production: the tracker is permanent-per-
104
- * process (see module docstring) so agents cannot exceed their process
105
- * budget via resets. Exists for tests and future explicit reset points.
106
- */
107
- reset(agent: string): void {
108
- this.steps.delete(agent.toLowerCase())
109
- }
110
- }