pantheon-opencode 2.1.6 → 2.2.0-beta.2

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 (63) hide show
  1. package/AGENTS.global.md +2 -2
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +64 -0
  4. package/README.md +13 -9
  5. package/README.pt-BR.md +13 -9
  6. package/bin/pantheon-init.mjs +1 -1
  7. package/commands/pantheon-audit.md +4 -5
  8. package/commands/pantheon-model.md +1 -2
  9. package/package.json +8 -2
  10. package/plugin.json +1 -1
  11. package/prompts/dynamic/agora-generated.txt +2 -2
  12. package/prompts/dynamic/orchestrate-generated.txt +4 -4
  13. package/prompts/sketch.prompt.md +1 -1
  14. package/pyproject.toml +1 -1
  15. package/scripts/build-agents-md.mjs +73 -12
  16. package/scripts/build-plugin.mjs +3 -1
  17. package/scripts/hooks/format-multi-language.sh +30 -29
  18. package/scripts/install-mcp.mjs +55 -27
  19. package/scripts/prune.mjs +124 -2
  20. package/scripts/setup.mjs +1 -1
  21. package/scripts/themis_heuristic_scan.py +3 -5
  22. package/skills-lock.json +1 -1
  23. package/src/agents/aphrodite.md +1 -1
  24. package/src/agents/athena.md +6 -14
  25. package/src/agents/demeter.md +1 -1
  26. package/src/agents/hermes.md +3 -2
  27. package/src/agents/iris.md +4 -6
  28. package/src/agents/prometheus.md +3 -7
  29. package/src/agents/roster.json +567 -0
  30. package/src/agents/zeus.md +3 -0
  31. package/src/instructions/agent-return-format.instructions.md +1 -1
  32. package/src/instructions/zeus-anti-stall.instructions.md +11 -35
  33. package/src/instructions/zeus-council-synthesis.instructions.md +17 -49
  34. package/src/instructions/zeus-timeout-retry.instructions.md +12 -80
  35. package/src/mcp/mcp_codemap_module.py +6 -5
  36. package/src/mcp/pantheon-mcp-server.mjs +875 -0
  37. package/src/pantheon/agent-forge-tool.ts +316 -0
  38. package/src/pantheon/auto-permissions.ts +31 -1
  39. package/src/pantheon/codemap-tools.ts +525 -0
  40. package/src/pantheon/deepwork/plan-tracker.ts +63 -2
  41. package/src/pantheon/execute-after.ts +21 -0
  42. package/src/pantheon/hook-engine.ts +2 -1
  43. package/src/pantheon/native-memory-tools.ts +686 -0
  44. package/src/pantheon/presets.mjs +15 -0
  45. package/src/pantheon/step-ledger.ts +259 -0
  46. package/src/pantheon/swe-eval-harness.ts +211 -0
  47. package/src/pantheon/tools.ts +62 -7
  48. package/src/plugin/index.js +2091 -136
  49. package/src/plugin/index.ts +1 -14
  50. package/src/plugin.ts +167 -10
  51. package/src/plugins/tui/dist/tui.d.ts +66 -0
  52. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  53. package/src/plugins/tui/dist/tui.js +1259 -367
  54. package/src/plugins/tui/dist/tui.js.map +1 -1
  55. package/src/plugins/tui/package-lock.json +2 -2
  56. package/src/plugins/tui/package.json +1 -1
  57. package/src/plugins/tui/src/index.tsx +632 -71
  58. package/src/plugins/tui/src/pantheon-settings.tsx +78 -14
  59. package/src/plugins/tui/src/quota-state.ts +190 -0
  60. package/src/plugins/tui/src/tui-prefs.ts +169 -12
  61. package/src/routing.yml +3 -0
  62. package/src/skills/auto-continue/references/auto-continue-details.md +2 -31
  63. /package/scripts/{setup-v2-config.mjs → setup-config.mjs} +0 -0
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Native On-Demand Specialist Agent Forge (`agent-forge-tool.ts`).
3
+ *
4
+ * Allows users and `@zeus` to keep the core Pantheon roster 100% polyglot and
5
+ * language-agnostic while effortlessly forging custom, project-scoped domain
6
+ * specialists in `<workspace>/.opencode/agents/<name>.md`.
7
+ *
8
+ * Capabilities:
9
+ * - `create`: Generates a complete, schema-valid OpenCode 2.x agent definition
10
+ * (`.opencode/agents/<name>.md`) from a domain archetype (`backend`, `frontend`,
11
+ * `data`, `security`, `ml-pipeline`, `geospatial`, `custom`) with tailored
12
+ * permissions, stack conventions, and sub-10s test-slicing gates.
13
+ * - `list`: Lists all custom project specialists in `.opencode/agents/`.
14
+ * - `inspect`: Reads a custom project specialist definition.
15
+ * - `remove`: Deletes a custom project specialist from `.opencode/agents/`.
16
+ *
17
+ * @module pantheon/agent-forge-tool
18
+ */
19
+
20
+ import {
21
+ existsSync,
22
+ mkdirSync,
23
+ readdirSync,
24
+ readFileSync,
25
+ realpathSync,
26
+ rmSync,
27
+ writeFileSync,
28
+ } from 'node:fs'
29
+ import { join, resolve, sep } from 'node:path'
30
+ import { PANTHEON_AGENTS } from './delegation-policy.ts'
31
+ import { resolveToolCwd } from './tool-context.ts'
32
+ import type { PantheonToolDef, PantheonToolResult } from './tools.ts'
33
+
34
+ export type ForgeArchetype =
35
+ | 'backend'
36
+ | 'frontend'
37
+ | 'data'
38
+ | 'security'
39
+ | 'ml-pipeline'
40
+ | 'geospatial'
41
+ | 'custom'
42
+
43
+ const SAFE_AGENT_NAME_RE = /^[a-z][a-z0-9-]{1,48}$/
44
+
45
+ function isValidAgentSlug(value: unknown): value is string {
46
+ return (
47
+ typeof value === 'string' &&
48
+ SAFE_AGENT_NAME_RE.test(value) &&
49
+ !value.includes('..') &&
50
+ !value.includes('/') &&
51
+ !value.includes('\\')
52
+ )
53
+ }
54
+
55
+ function resolveAgentsDir(workspaceDir: string): string {
56
+ const dir = join(workspaceDir, '.opencode', 'agents')
57
+ mkdirSync(dir, { recursive: true })
58
+ return realpathSync(dir)
59
+ }
60
+
61
+ function resolveConfinedAgentFile(agentsDir: string, name: string): string {
62
+ const filePath = resolve(agentsDir, `${name}.md`)
63
+ const prefix = agentsDir.endsWith(sep) ? agentsDir : `${agentsDir}${sep}`
64
+ if (!filePath.startsWith(prefix)) {
65
+ throw new Error('Path traversal denied: agent file escapes .opencode/agents')
66
+ }
67
+ return filePath
68
+ }
69
+
70
+ function buildAgentMarkdown(params: {
71
+ name: string
72
+ description: string
73
+ archetype: ForgeArchetype
74
+ stack: string[]
75
+ readOnly: boolean
76
+ testCommand: string
77
+ conventions: string[]
78
+ }): string {
79
+ const { name, description, archetype, stack, readOnly, testCommand, conventions } = params
80
+ const stackLine = stack.length > 0 ? stack.join(', ') : 'Polyglot project stack'
81
+ const permEdit = readOnly ? 'deny' : 'allow'
82
+ const permShell = readOnly ? 'deny' : 'allow'
83
+ const roleKind = readOnly
84
+ ? 'READ-ONLY ANALYSIS & AUDIT SPECIALIST'
85
+ : 'DOMAIN IMPLEMENTATION SPECIALIST'
86
+
87
+ const conventionBullets =
88
+ conventions.length > 0
89
+ ? conventions.map((c) => `- ${c}`).join('\n')
90
+ : [
91
+ `- Adapt idiomatic patterns to the active stack (${stackLine}).`,
92
+ '- Follow strict TDD (RED -> GREEN -> REFACTOR) for behavioral changes.',
93
+ '- Never introduce mock servers on real service ports; fail fast on missing dependencies.',
94
+ ].join('\n')
95
+
96
+ return [
97
+ '---',
98
+ `name: ${name}`,
99
+ `description: ${JSON.stringify(description)}`,
100
+ 'mode: subagent',
101
+ `temperature: ${readOnly ? '0.1' : '0.2'}`,
102
+ 'permission:',
103
+ ' read: allow',
104
+ ' grep: allow',
105
+ ' glob: allow',
106
+ ` edit: ${permEdit}`,
107
+ ` hashline_edit: ${permEdit}`,
108
+ ` bash: ${permShell}`,
109
+ ` shell: ${permShell}`,
110
+ ` execute: ${permShell}`,
111
+ ' todowrite: allow',
112
+ ' todoread: allow',
113
+ ' task:',
114
+ ' "*": deny',
115
+ '---',
116
+ '',
117
+ `# @${name} — ${description}`,
118
+ '',
119
+ `- **Archetype:** \`${archetype}\` (${roleKind})`,
120
+ `- **Target Stack & Domain:** ${stackLine}`,
121
+ `- **Default Verification Slice:** \`${testCommand}\``,
122
+ '',
123
+ '## Role & Execution Boundaries',
124
+ '',
125
+ readOnly
126
+ ? 'You are a **READ-ONLY** domain specialist. Inspect files, analyze patterns, and return structured findings with file:line references. Never modify files or run mutating commands.'
127
+ : 'You are a **bounded domain implementer**. Inspect relevant files directly, apply surgical edits using `hashline_edit` or `edit`, and verify every change using the narrowest test slice (<10s).',
128
+ '',
129
+ '## Domain Conventions & Quality Gates',
130
+ '',
131
+ conventionBullets,
132
+ '',
133
+ '## Strict Test Slicing & Return Contract',
134
+ '',
135
+ `- Run only the targeted slice (\`${testCommand}\`); never run unconstrained full-repository suites during iterative loops.`,
136
+ '- Return a concise `## subtask_summary` with `files_changed`, `summary`, `tests` (`[PASS|WARN|FAIL] <cmd>`), `status`, and `blockers`.',
137
+ '',
138
+ ].join('\n')
139
+ }
140
+
141
+ function jsonResult(payload: unknown): PantheonToolResult {
142
+ return { output: JSON.stringify(payload) }
143
+ }
144
+
145
+ export function createAgentForgeTool(fallbackDir?: string): PantheonToolDef {
146
+ return {
147
+ name: 'pantheon_agent_forge',
148
+ description:
149
+ 'Create, list, inspect, or remove custom project-scoped domain specialist agents in .opencode/agents/<name>.md.',
150
+ input: {
151
+ type: 'object',
152
+ additionalProperties: false,
153
+ required: ['action'],
154
+ properties: {
155
+ action: {
156
+ type: 'string',
157
+ enum: ['create', 'list', 'inspect', 'remove'],
158
+ description: 'Forge operation to execute',
159
+ },
160
+ name: {
161
+ type: 'string',
162
+ description: 'Lowercase kebab-case agent identifier (e.g. rust-embedded, prisma-dba)',
163
+ },
164
+ description: {
165
+ type: 'string',
166
+ description: 'One-line role summary used for routing and @mention discovery',
167
+ },
168
+ archetype: {
169
+ type: 'string',
170
+ enum: ['backend', 'frontend', 'data', 'security', 'ml-pipeline', 'geospatial', 'custom'],
171
+ description: 'Base specialist template',
172
+ },
173
+ stack: {
174
+ type: 'array',
175
+ items: { type: 'string' },
176
+ description: 'Technologies, frameworks, or domain libraries this specialist owns',
177
+ },
178
+ readOnly: {
179
+ type: 'boolean',
180
+ description:
181
+ 'When true, denies file edits and shell execution (investigation/audit only)',
182
+ },
183
+ testCommand: {
184
+ type: 'string',
185
+ description: 'Default targeted verification slice command (<10s)',
186
+ },
187
+ conventions: {
188
+ type: 'array',
189
+ items: { type: 'string' },
190
+ description: 'Domain-specific rules and invariants enforced by this agent',
191
+ },
192
+ allowOverrideCanonical: {
193
+ type: 'boolean',
194
+ description: 'Allow creating a project override for a built-in Pantheon agent name',
195
+ },
196
+ },
197
+ },
198
+ output: {},
199
+ execute: async (input, context) => {
200
+ try {
201
+ const action = typeof input.action === 'string' ? input.action : 'list'
202
+ const cwd = resolveToolCwd(context, fallbackDir)
203
+ const agentsDir = resolveAgentsDir(cwd)
204
+
205
+ if (action === 'list') {
206
+ const files = readdirSync(agentsDir)
207
+ .filter((f) => f.endsWith('.md') && f.toLowerCase() !== 'readme.md')
208
+ .sort()
209
+ const agents = files.map((file) => {
210
+ const id = file.replace(/\.md$/, '')
211
+ const raw = readFileSync(join(agentsDir, file), 'utf8')
212
+ const descMatch = raw.match(/^description:\s*(.+)$/m)
213
+ return {
214
+ name: id,
215
+ path: `.opencode/agents/${file}`,
216
+ description: descMatch?.[1]?.replace(/^["']|["']$/g, '') ?? '',
217
+ }
218
+ })
219
+ return jsonResult({ ok: true, count: agents.length, agents })
220
+ }
221
+
222
+ const name = typeof input.name === 'string' ? input.name.trim().toLowerCase() : ''
223
+ if (!isValidAgentSlug(name)) {
224
+ return jsonResult({
225
+ ok: false,
226
+ error: 'name must be a lowercase kebab-case identifier (2..49 chars, [a-z0-9-])',
227
+ })
228
+ }
229
+
230
+ const filePath = resolveConfinedAgentFile(agentsDir, name)
231
+
232
+ if (action === 'inspect') {
233
+ if (!existsSync(filePath)) {
234
+ return jsonResult({ ok: false, error: 'agent_not_found', name })
235
+ }
236
+ return jsonResult({
237
+ ok: true,
238
+ name,
239
+ path: `.opencode/agents/${name}.md`,
240
+ content: readFileSync(filePath, 'utf8'),
241
+ })
242
+ }
243
+
244
+ if (action === 'remove') {
245
+ if (!existsSync(filePath)) {
246
+ return jsonResult({ ok: false, error: 'agent_not_found', name })
247
+ }
248
+ rmSync(filePath, { force: true })
249
+ return jsonResult({ ok: true, removed: true, name })
250
+ }
251
+
252
+ if (action === 'create') {
253
+ if (PANTHEON_AGENTS.has(name) && input.allowOverrideCanonical !== true) {
254
+ return jsonResult({
255
+ ok: false,
256
+ error: `"${name}" is a canonical Pantheon agent. Pass allowOverrideCanonical: true only if you intentionally want a project-local override.`,
257
+ })
258
+ }
259
+ const description =
260
+ typeof input.description === 'string' && input.description.trim()
261
+ ? input.description.trim()
262
+ : `Custom ${name} specialist`
263
+ const archetype: ForgeArchetype =
264
+ typeof input.archetype === 'string' &&
265
+ [
266
+ 'backend',
267
+ 'frontend',
268
+ 'data',
269
+ 'security',
270
+ 'ml-pipeline',
271
+ 'geospatial',
272
+ 'custom',
273
+ ].includes(input.archetype)
274
+ ? (input.archetype as ForgeArchetype)
275
+ : 'custom'
276
+ const readOnly =
277
+ typeof input.readOnly === 'boolean'
278
+ ? input.readOnly
279
+ : archetype === 'security' || archetype === 'geospatial'
280
+ const stack = Array.isArray(input.stack) ? input.stack.map(String) : []
281
+ const testCommand =
282
+ typeof input.testCommand === 'string' && input.testCommand.trim()
283
+ ? input.testCommand.trim()
284
+ : 'npm run test:slice'
285
+ const conventions = Array.isArray(input.conventions) ? input.conventions.map(String) : []
286
+
287
+ const markdown = buildAgentMarkdown({
288
+ name,
289
+ description,
290
+ archetype,
291
+ stack,
292
+ readOnly,
293
+ testCommand,
294
+ conventions,
295
+ })
296
+ writeFileSync(filePath, markdown, 'utf8')
297
+ return jsonResult({
298
+ ok: true,
299
+ created: true,
300
+ name,
301
+ path: `.opencode/agents/${name}.md`,
302
+ readOnly,
303
+ archetype,
304
+ })
305
+ }
306
+
307
+ return jsonResult({ ok: false, error: `Unsupported action: ${action}` })
308
+ } catch (err) {
309
+ return jsonResult({
310
+ ok: false,
311
+ error: err instanceof Error ? err.message : String(err),
312
+ })
313
+ }
314
+ },
315
+ }
316
+ }
@@ -49,6 +49,26 @@ export interface AutoPermissionResult {
49
49
  /** Agents strictly forbidden from mutating workspace files or executing arbitrary shell commands. */
50
50
  const READ_ONLY_AGENTS: ReadonlySet<string> = new Set(['zeus', 'athena', 'apollo', 'gaia'])
51
51
 
52
+ /** Agents forbidden from editing source files directly (reviewers, git/release ops, memory). */
53
+ export const NON_EDIT_AGENTS: ReadonlySet<string> = new Set([
54
+ 'zeus',
55
+ 'athena',
56
+ 'apollo',
57
+ 'gaia',
58
+ 'themis',
59
+ 'nyx',
60
+ 'iris',
61
+ ])
62
+
63
+ /** Agents forbidden from executing arbitrary shell commands. */
64
+ export const NON_SHELL_AGENTS: ReadonlySet<string> = new Set([
65
+ 'zeus',
66
+ 'athena',
67
+ 'apollo',
68
+ 'gaia',
69
+ 'mnemosyne',
70
+ ])
71
+
52
72
  /** Allowed binary names for routine workspace development. */
53
73
  const SAFE_DEV_BINARIES: ReadonlySet<string> = new Set([
54
74
  'git',
@@ -257,7 +277,7 @@ export function evaluateAutoPermission(
257
277
  return { decision: 'allow', reason: 'pantheon-native-tool' }
258
278
  }
259
279
 
260
- // 2. Read-only agents are strictly prohibited from mutating tools or shell
280
+ // 2. Read-only and role-restricted agents are strictly prohibited from mutating tools or shell
261
281
  if (READ_ONLY_AGENTS.has(agent)) {
262
282
  if (['edit', 'write', 'hashline_edit', 'bash', 'shell', 'execute'].includes(action)) {
263
283
  event.effect = 'deny'
@@ -265,6 +285,16 @@ export function evaluateAutoPermission(
265
285
  return { decision: 'deny', reason: 'read-only-role-violation' }
266
286
  }
267
287
  }
288
+ if (NON_EDIT_AGENTS.has(agent) && ['edit', 'write', 'hashline_edit'].includes(action)) {
289
+ event.effect = 'deny'
290
+ event.message = `Pantheon auto-permissions denied: agent '${agent}' cannot execute file mutation '${action}'`
291
+ return { decision: 'deny', reason: 'read-only-role-violation' }
292
+ }
293
+ if (NON_SHELL_AGENTS.has(agent) && ['bash', 'shell'].includes(action)) {
294
+ event.effect = 'deny'
295
+ event.message = `Pantheon auto-permissions denied: agent '${agent}' cannot execute shell command '${action}'`
296
+ return { decision: 'deny', reason: 'read-only-role-violation' }
297
+ }
268
298
 
269
299
  // 3. Read-only inspection tools are safe within workspace (excluding network/external URLs and excluded directories)
270
300
  if (['read', 'glob', 'grep', 'webfetch', 'question'].includes(action)) {