pantheon-opencode 2.0.3 → 2.1.0

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 (48) hide show
  1. package/AGENTS.global.md +1 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +68 -0
  4. package/README.md +13 -6
  5. package/README.pt-BR.md +12 -5
  6. package/commands/pantheon-deepwork.md +11 -2
  7. package/package.json +2 -1
  8. package/plugin.json +1 -1
  9. package/prompts/orchestrate-with-zeus.prompt.md +2 -0
  10. package/pyproject.toml +1 -1
  11. package/scripts/cost.mjs +4 -5
  12. package/scripts/decision-router-budget.mjs +27 -6
  13. package/scripts/decision-router.mjs +76 -34
  14. package/scripts/doctor.mjs +74 -0
  15. package/scripts/install/decision-router-config.mjs +32 -7
  16. package/src/agents/apollo.md +6 -53
  17. package/src/agents/athena.md +1 -0
  18. package/src/agents/talos.md +10 -40
  19. package/src/agents/themis.md +9 -0
  20. package/src/agents/zeus.md +29 -2
  21. package/src/mcp/pantheon_vision.py +33 -2
  22. package/src/pantheon/background-job-board.ts +33 -0
  23. package/src/pantheon/bus.ts +190 -0
  24. package/src/pantheon/cost-command.ts +4 -1
  25. package/src/pantheon/deepwork/deepwork-tool.ts +370 -0
  26. package/src/pantheon/deepwork/plan-projection.ts +274 -0
  27. package/src/pantheon/deepwork/plan-schema.ts +93 -0
  28. package/src/pantheon/deepwork/plan-tracker.ts +336 -0
  29. package/src/pantheon/execution-receipt.ts +113 -0
  30. package/src/pantheon/jev-decision-tool.ts +8 -2
  31. package/src/pantheon/local-decision-budget.ts +36 -6
  32. package/src/pantheon/model-command.ts +2 -4
  33. package/src/pantheon/native-vision.ts +3 -1
  34. package/src/pantheon/prompt-cache-order.ts +89 -0
  35. package/src/pantheon/skill-search-tool.ts +2 -2
  36. package/src/pantheon/themis-reflex.ts +164 -0
  37. package/src/pantheon/tools.ts +2 -0
  38. package/src/plugin/index.js +979 -60
  39. package/src/plugins/tui/dist/tui.js +461 -289
  40. package/src/plugins/tui/dist/tui.js.map +1 -1
  41. package/src/plugins/tui/package-lock.json +2 -2
  42. package/src/plugins/tui/package.json +1 -1
  43. package/src/plugins/tui/src/autonomy-state.ts +14 -16
  44. package/src/plugins/tui/src/decision-router-state.ts +22 -10
  45. package/src/plugins/tui/src/pantheon-settings-state.ts +119 -35
  46. package/src/plugins/tui/src/pantheon-settings.tsx +142 -48
  47. package/src/plugins/tui/src/preset-state.ts +96 -6
  48. package/src/plugins/tui/src/update-status.ts +62 -22
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Prompt Prefix Cache Hierarchy Optimizer — Late-2026 KV-Cache Alignment.
3
+ *
4
+ * Enforces deterministic hierarchical ordering for agent prompts to maximize
5
+ * prefix cache hit rates across LLM providers (Anthropic Claude 3.5/3.7,
6
+ * Gemini 2.0/Flash, OpenAI GPT-5/o3/Luna):
7
+ *
8
+ * [Tier 1: Static Identity & Invariants] ->
9
+ * [Tier 2: Tool Schemas & Governance] ->
10
+ * [Tier 3: Repository Standards & Gates] ->
11
+ * [Tier 4: Ephemeral Session History] ->
12
+ * [Tier 5: Current Turn & Scratchpad]
13
+ *
14
+ * Pure TypeScript — zero external dependencies.
15
+ *
16
+ * @module prompt-cache-order
17
+ */
18
+
19
+ export interface PromptLayers {
20
+ readonly identity: string
21
+ readonly tools?: readonly string[] | undefined
22
+ readonly conventions?: readonly string[] | undefined
23
+ readonly history?: readonly string[] | undefined
24
+ readonly currentTurn: string
25
+ }
26
+
27
+ export interface CachedPromptResult {
28
+ readonly prompt: string
29
+ /** The byte/character offset separating invariant prefix from volatile turns */
30
+ readonly prefixBoundaryIndex: number
31
+ /** Estimated token length (heuristic ~4 chars/token) */
32
+ readonly estimatedTokens: number
33
+ /** Whether the prefix meets typical provider minimum threshold (e.g. 1024 tokens) */
34
+ readonly cacheEligible: boolean
35
+ }
36
+
37
+ /** Standard token threshold for provider-level prompt caching (Anthropic=1024, OpenAI=1024) */
38
+ export const DEFAULT_CACHE_MIN_TOKENS = 1024
39
+
40
+ /**
41
+ * Assemble agent prompt with strict invariant-prefix ordering to maximize KV cache hit rate.
42
+ */
43
+ export function buildPrefixCachedPrompt(
44
+ layers: PromptLayers,
45
+ minCacheTokens = DEFAULT_CACHE_MIN_TOKENS,
46
+ ): CachedPromptResult {
47
+ const invariantParts: string[] = []
48
+
49
+ // 1. Identity & Core System Instructions
50
+ invariantParts.push(layers.identity.trim())
51
+
52
+ // 2. Tools & Permissions Schemas
53
+ if (layers.tools && layers.tools.length > 0) {
54
+ invariantParts.push(`## Tool Specifications\n${layers.tools.map((t) => t.trim()).join('\n\n')}`)
55
+ }
56
+
57
+ // 3. Project Conventions & Architecture Gates
58
+ if (layers.conventions && layers.conventions.length > 0) {
59
+ invariantParts.push(
60
+ `## Project Standards & Gates\n${layers.conventions.map((c) => c.trim()).join('\n\n')}`,
61
+ )
62
+ }
63
+
64
+ const prefix = invariantParts.join('\n\n')
65
+ const prefixBoundaryIndex = prefix.length
66
+
67
+ const volatileParts: string[] = []
68
+
69
+ // 4. Conversation History (if any)
70
+ if (layers.history && layers.history.length > 0) {
71
+ volatileParts.push(
72
+ `## Conversation History\n${layers.history.map((h) => h.trim()).join('\n\n')}`,
73
+ )
74
+ }
75
+
76
+ // 5. Current Turn Payload
77
+ volatileParts.push(layers.currentTurn.trim())
78
+
79
+ const fullPrompt = [prefix, volatileParts.join('\n\n')].join('\n\n')
80
+ const estimatedTokens = Math.ceil(fullPrompt.length / 4)
81
+ const estimatedPrefixTokens = Math.ceil(prefix.length / 4)
82
+
83
+ return {
84
+ prompt: fullPrompt,
85
+ prefixBoundaryIndex,
86
+ estimatedTokens,
87
+ cacheEligible: estimatedPrefixTokens >= minCacheTokens,
88
+ }
89
+ }
@@ -41,7 +41,7 @@ const TOOL_DESCRIPTION =
41
41
  'Advisory discovery tool for skills. Queries installed Pantheon skills and external ' +
42
42
  'registries (Anthropic catalog, skills.sh, GitHub). Returns matched skill IDs, ' +
43
43
  'descriptions, install counts, and provenance tiers. Zeus uses this to recommend ' +
44
- 'skills before prompting the user to install.'
44
+ 'project-scoped skills (.agents/skills/) before proactively prompting the user via the question tool.'
45
45
 
46
46
  const SKILL_SEARCH_INPUT_SCHEMA: Record<string, unknown> = {
47
47
  type: 'object',
@@ -159,7 +159,7 @@ export function executeSkillSearch(input: Record<string, unknown>): SkillSearchO
159
159
  installed: false,
160
160
  installs: entry.installs ?? null,
161
161
  url: entry.url,
162
- installCommand: `npx skills add ${entry.skill} -a opencode`,
162
+ installCommand: `npx skills add ${entry.skill} -a opencode -y`,
163
163
  })
164
164
  }
165
165
  }
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Themis Local Reflex Loop — Self-healing inline verification for implementer agents.
3
+ *
4
+ * Catches syntax errors, lint failures, and sliced test failures directly in the
5
+ * implementer's execution cycle, granting up to 2 bounded retry attempts before
6
+ * escalating to the Zeus coordinator.
7
+ *
8
+ * Emits reactive events on `getSharedBus()` for auditability and observability.
9
+ *
10
+ * Pure TypeScript — zero external dependencies.
11
+ *
12
+ * @module themis-reflex
13
+ */
14
+
15
+ import { getSharedBus } from './bus.ts'
16
+
17
+ export interface ThemisDiscrepancy {
18
+ readonly file: string
19
+ readonly error: string
20
+ readonly expected?: string
21
+ readonly actual?: string
22
+ readonly suggestedFix?: string
23
+ }
24
+
25
+ export interface ReflexAttemptState {
26
+ taskID: string
27
+ agent: string
28
+ attempt: number
29
+ maxAttempts: number
30
+ discrepancies: ThemisDiscrepancy[]
31
+ timestamp: number
32
+ }
33
+
34
+ export type ThemisReflexDecision =
35
+ | {
36
+ readonly action: 'retry'
37
+ readonly prompt: string
38
+ readonly attempt: number
39
+ readonly maxAttempts: number
40
+ }
41
+ | {
42
+ readonly action: 'escalate'
43
+ readonly verdict: 'BLOCK' | 'FAIL'
44
+ readonly reason: string
45
+ readonly attempts: number
46
+ }
47
+ | {
48
+ readonly action: 'pass'
49
+ readonly verdict: 'PASS'
50
+ }
51
+
52
+ export class ThemisReflexController {
53
+ private readonly states: Map<string, ReflexAttemptState> = new Map()
54
+ private readonly maxRetries: number
55
+
56
+ constructor(options: { maxRetries?: number } = {}) {
57
+ this.maxRetries = options.maxRetries ?? 2
58
+ }
59
+
60
+ /**
61
+ * Evaluate a task execution result against Themis verification findings.
62
+ * If discrepancies are found and attempts remain, returns an actionable retry directive.
63
+ */
64
+ evaluate(
65
+ taskID: string,
66
+ agent: string,
67
+ discrepancies: readonly ThemisDiscrepancy[],
68
+ ): ThemisReflexDecision {
69
+ if (discrepancies.length === 0) {
70
+ const existing = this.states.get(taskID)
71
+ if (existing) {
72
+ getSharedBus().emit('themis:reflex:resolved', {
73
+ taskID,
74
+ agent,
75
+ file: existing.discrepancies[0]?.file ?? '',
76
+ error: '',
77
+ attempt: existing.attempt,
78
+ maxAttempts: this.maxRetries,
79
+ timestamp: Date.now(),
80
+ resolved: true,
81
+ })
82
+ this.states.delete(taskID)
83
+ }
84
+ return { action: 'pass', verdict: 'PASS' }
85
+ }
86
+
87
+ let state = this.states.get(taskID)
88
+ if (!state) {
89
+ state = {
90
+ taskID,
91
+ agent,
92
+ attempt: 0,
93
+ maxAttempts: this.maxRetries,
94
+ discrepancies: [...discrepancies],
95
+ timestamp: Date.now(),
96
+ }
97
+ this.states.set(taskID, state)
98
+ }
99
+
100
+ state.attempt += 1
101
+ state.discrepancies = [...discrepancies]
102
+ state.timestamp = Date.now()
103
+
104
+ const firstDisc = discrepancies[0]
105
+ getSharedBus().emit('themis:reflex:discrepancy', {
106
+ taskID,
107
+ agent,
108
+ file: firstDisc?.file ?? 'unknown',
109
+ error: firstDisc?.error ?? 'unspecified',
110
+ attempt: state.attempt,
111
+ maxAttempts: this.maxRetries,
112
+ timestamp: state.timestamp,
113
+ })
114
+
115
+ if (state.attempt <= this.maxRetries) {
116
+ const prompt = this.formatReflexPrompt(state.attempt, this.maxRetries, discrepancies)
117
+ return {
118
+ action: 'retry',
119
+ prompt,
120
+ attempt: state.attempt,
121
+ maxAttempts: this.maxRetries,
122
+ }
123
+ }
124
+
125
+ // Retries exhausted — escalate to coordinator
126
+ this.states.delete(taskID)
127
+ return {
128
+ action: 'escalate',
129
+ verdict: 'FAIL',
130
+ reason: `themis.reflex.exhausted:${state.attempt - 1}_retries_failed`,
131
+ attempts: state.attempt,
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Format an inline, high-density reflex prompt directing the implementer to self-heal.
137
+ */
138
+ private formatReflexPrompt(
139
+ attempt: number,
140
+ maxAttempts: number,
141
+ discrepancies: readonly ThemisDiscrepancy[],
142
+ ): string {
143
+ const lines = [
144
+ `[THEMIS INLINE REFLEX — Attempt ${attempt}/${maxAttempts}]`,
145
+ 'Themis automated audit detected discrepancies in your edits. Fix them directly before returning:',
146
+ ]
147
+
148
+ for (const d of discrepancies) {
149
+ lines.push(`- File: ${d.file}`)
150
+ lines.push(` Error: ${d.error}`)
151
+ if (d.expected) lines.push(` Expected: ${d.expected}`)
152
+ if (d.actual) lines.push(` Actual: ${d.actual}`)
153
+ if (d.suggestedFix) lines.push(` Fix hint: ${d.suggestedFix}`)
154
+ }
155
+
156
+ lines.push('Do NOT escalate to Zeus yet. Apply the targeted fix and re-verify your slice.')
157
+ return lines.join('\n')
158
+ }
159
+
160
+ /** Reset state for a taskID */
161
+ reset(taskID: string): void {
162
+ this.states.delete(taskID)
163
+ }
164
+ }
@@ -48,6 +48,7 @@
48
48
 
49
49
  import { createCostCommand } from './cost-command.ts'
50
50
  import type { ShadowSink } from './decision-shadow.ts'
51
+ import { createDeepworkTool } from './deepwork/deepwork-tool.ts'
51
52
  import { createHashlineEditTool, type HashlineToolResult } from './hashline/tool.ts'
52
53
  import { createV2JevDecisionDefinition, type V2JevDecisionRuntime } from './jev-decision-tool.ts'
53
54
  import { createV2LocalDecisionDefinition } from './local-decision-tool.ts'
@@ -545,6 +546,7 @@ export function createV2ToolDefinitions(
545
546
  )
546
547
  definitions.push(todowriteTool)
547
548
  definitions.push(createV2SkillSearchDefinition())
549
+ definitions.push(createDeepworkTool())
548
550
  if (visionRuntime) definitions.push(createV2VisionTool(visionRuntime))
549
551
  if (jevRuntime) definitions.push(createV2JevDecisionDefinition(jevRuntime))
550
552
  return definitions