pantheon-opencode 2.1.2 → 2.1.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.
Files changed (42) hide show
  1. package/AGENTS.global.md +7 -7
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +77 -0
  4. package/README.md +10 -0
  5. package/package.json +7 -4
  6. package/plugin.json +1 -1
  7. package/pyproject.toml +1 -1
  8. package/scripts/build-plugin.mjs +35 -9
  9. package/scripts/build-roster.mjs +139 -0
  10. package/scripts/doctor.mjs +111 -2
  11. package/scripts/install/opencode.mjs +16 -0
  12. package/scripts/sync-tui.mjs +2 -0
  13. package/scripts/test-slice.mjs +352 -0
  14. package/skills-lock.json +1 -1
  15. package/src/agents/aphrodite.md +8 -6
  16. package/src/agents/apollo.md +9 -7
  17. package/src/agents/athena.md +21 -18
  18. package/src/agents/demeter.md +7 -5
  19. package/src/agents/gaia.md +7 -8
  20. package/src/agents/hephaestus.md +7 -5
  21. package/src/agents/hermes.md +20 -16
  22. package/src/agents/iris.md +10 -8
  23. package/src/agents/mnemosyne.md +17 -19
  24. package/src/agents/nyx.md +7 -5
  25. package/src/agents/prometheus.md +7 -5
  26. package/src/agents/talos.md +11 -5
  27. package/src/agents/themis.md +11 -4
  28. package/src/agents/zeus.md +23 -2
  29. package/src/instructions/agent-return-format.instructions.md +1 -1
  30. package/src/instructions/test-economy.instructions.md +6 -6
  31. package/src/mcp/pantheon_vision.py +24 -0
  32. package/src/pantheon/auto-permissions.ts +328 -0
  33. package/src/pantheon/deepwork/deepwork-tool.ts +14 -0
  34. package/src/pantheon/delegation-enforce.ts +43 -12
  35. package/src/pantheon/native-vision.ts +54 -2
  36. package/src/pantheon/tools.ts +102 -3
  37. package/src/plugin/index.js +342 -16
  38. package/src/plugin.ts +7 -0
  39. package/src/plugins/tui/dist/tui.js +5 -5
  40. package/src/plugins/tui/package-lock.json +2 -2
  41. package/src/plugins/tui/package.json +1 -1
  42. package/src/skills/test-slicing/SKILL.md +44 -15
@@ -183,6 +183,7 @@ export const DEFAULT_BLOCKED_TOOLS: ReadonlySet<string> = new Set([
183
183
  'edit',
184
184
  'write',
185
185
  'bash',
186
+ 'shell',
186
187
  'task',
187
188
  'hashline_edit',
188
189
  // `pantheon_model` writes active-preset.json in BOTH the project and the
@@ -199,9 +200,15 @@ export const DEFAULT_BLOCKED_TOOLS: ReadonlySet<string> = new Set([
199
200
  /**
200
201
  * Path patterns that Zeus must NOT read directly. Zeus must delegate
201
202
  * codebase reads to @apollo to avoid context bloat and enforce separation
202
- * of concerns.
203
+ * of concerns. .git and node_modules are excluded repository noise.
203
204
  */
204
- export const ZEUS_READ_DENY_PATTERNS: ReadonlyArray<RegExp> = [/^src\//, /^tests?\//, /^scripts?\//]
205
+ export const ZEUS_READ_DENY_PATTERNS: ReadonlyArray<RegExp> = [
206
+ /^src\//,
207
+ /^tests?\//,
208
+ /^scripts?\//,
209
+ /(^|\/)\.git(\/|$)/,
210
+ /(^|\/)node_modules(\/|$)/,
211
+ ]
205
212
 
206
213
  /**
207
214
  * Normalize a tool-supplied path before it meets the deny patterns.
@@ -278,13 +285,37 @@ function isDeniedReadPath(candidate: string, target: boolean): boolean {
278
285
  export type GuardPathResolver = (rawPath: string) => GuardPathResolution
279
286
 
280
287
  /**
281
- * Glob expansion is controlled by the host and its symlink-follow behavior is
282
- * not part of this guard's contract. Only exact, non-glob paths are safe to
283
- * preflight; fail closed on glob metacharacters rather than infer the host's
284
- * expansion semantics.
288
+ * File extensions that identify source code or test files. Zeus must delegate
289
+ * source code exploration and search to @apollo.
285
290
  */
286
- function hasGlobMeta(value: string): boolean {
287
- return ['*', '?', '[', ']', '{', '}', '(', ')'].some((meta) => value.includes(meta))
291
+ const CODE_FILE_EXTENSIONS =
292
+ /\.(ts|tsx|js|jsx|mjs|cjs|py|go|rs|c|cpp|h|hpp|java|kt|rb|php|swift|cs|scala|vue|svelte)$/i
293
+
294
+ // Glob patterns that Zeus is denied from evaluating.
295
+ // Zeus is the orchestrator and must NOT read source code, tests, or scripts.
296
+ //
297
+ // Denied:
298
+ // - Direct targets into denied code roots (src/, tests/, scripts/)
299
+ // - Path traversal (../, ..)
300
+ // - Source code extensions (.ts, .py, etc.)
301
+ //
302
+ // Allowed:
303
+ // - Project-level metadata and non-code patterns: *, *.json, *.md, **/package.json, docs/**, .pantheon/**, memories/**
304
+ export function isDeniedGlobPattern(pattern: string): boolean {
305
+ const normalized = normalizeGuardPath(pattern)
306
+ if (normalized.startsWith('../') || normalized === '..' || normalized.includes('/../')) {
307
+ return true
308
+ }
309
+ if (/(^|\/)(\.git|node_modules)(\/|$)/.test(normalized)) {
310
+ return true
311
+ }
312
+ if (isDeniedReadPath(normalized, true)) {
313
+ return true
314
+ }
315
+ if (CODE_FILE_EXTENSIONS.test(normalized)) {
316
+ return true
317
+ }
318
+ return false
288
319
  }
289
320
 
290
321
  /**
@@ -372,10 +403,10 @@ export function zeusReadGuard(
372
403
  if (tool === 'grep' && candidate.target) deny()
373
404
  continue
374
405
  }
375
- // Resolve every direct grep/glob path before any policy decision. Wildcard
376
- // expansion itself cannot be safely preflighted using the host's unknown
377
- // symlink semantics, so Zeus may glob exact paths only.
378
- if (tool === 'glob' && candidate.target && hasGlobMeta(effectivePath)) deny()
406
+ // Resolve every direct grep/glob path before any policy decision.
407
+ // Zeus is allowed to glob project-level metadata and non-code files (*, **/package.json),
408
+ // but denied from globbing code roots (src/, tests/, scripts/) or source code files.
409
+ if (tool === 'glob' && candidate.target && isDeniedGlobPattern(effectivePath)) deny()
379
410
  if (isDeniedReadPath(effectivePath, candidate.target)) deny()
380
411
  }
381
412
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type { LookupAddress } from 'node:dns'
4
4
  import { lookup as dnsLookup } from 'node:dns/promises'
5
+ import { existsSync } from 'node:fs'
5
6
  import { readFile } from 'node:fs/promises'
6
7
  import { request as httpRequest } from 'node:http'
7
8
  import { request as httpsRequest } from 'node:https'
@@ -524,6 +525,53 @@ async function imageAttachment(
524
525
  return toImageAttachment(bytes, localPath.split(/[\\/]/).at(-1) || 'image')
525
526
  }
526
527
 
528
+ /**
529
+ * Discover the active OpenCode session ID from environment or opencode.db.
530
+ */
531
+ export function discoverActiveSessionId(directory?: string): string | undefined {
532
+ for (const envVar of ['OPENCODE_SESSION_ID', 'SESSION_ID']) {
533
+ const val = (process.env[envVar] ?? '').trim()
534
+ if (isValidSessionId(val)) return val
535
+ }
536
+ try {
537
+ const dataHome = process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share')
538
+ const dbPath = process.env.OPENCODE_DB || join(dataHome, 'opencode', 'opencode.db')
539
+ if (!existsSync(dbPath)) return undefined
540
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
541
+ const sqlite = require('node:sqlite') as {
542
+ DatabaseSync: new (
543
+ path: string,
544
+ options: { readOnly: boolean },
545
+ ) => {
546
+ prepare: (query: string) => {
547
+ get: (...params: unknown[]) => Record<string, unknown> | undefined
548
+ }
549
+ close: () => void
550
+ }
551
+ }
552
+ const db = new sqlite.DatabaseSync(dbPath, { readOnly: true })
553
+ try {
554
+ if (directory) {
555
+ const row = db
556
+ .prepare(
557
+ 'SELECT id FROM session_v2 WHERE directory = ? ORDER BY time_created DESC LIMIT 1',
558
+ )
559
+ .get(directory)
560
+ if (row && isValidSessionId(row.id)) return String(row.id)
561
+ }
562
+ const fallbackRow = db
563
+ .prepare('SELECT id FROM session_v2 ORDER BY time_created DESC LIMIT 1')
564
+ .get()
565
+ if (fallbackRow && isValidSessionId(fallbackRow.id)) return String(fallbackRow.id)
566
+ } finally {
567
+ db.close()
568
+ }
569
+ } catch {
570
+ // Graceful fallback when node:sqlite is unavailable or db schema differs
571
+ }
572
+ return undefined
573
+ }
574
+
527
575
  export function createV2VisionTool(runtime: V2VisionRuntime): V2VisionToolDefinition {
528
576
  return {
529
577
  name: 'vision_describe',
@@ -551,7 +599,11 @@ export function createV2VisionTool(runtime: V2VisionRuntime): V2VisionToolDefini
551
599
  let stage = 'validate OpenCode session'
552
600
  try {
553
601
  const call = (asRecord(rawContext) ?? {}) as V2VisionToolContext
554
- if (!isValidSessionId(call.sessionID)) {
602
+ let sessionID = isValidSessionId(call.sessionID) ? call.sessionID : undefined
603
+ if (!sessionID) {
604
+ sessionID = discoverActiveSessionId(call.directory || process.cwd())
605
+ }
606
+ if (!sessionID) {
555
607
  throw new Error(
556
608
  'a valid OpenCode session id is required; retry this tool from an active OpenCode session',
557
609
  )
@@ -594,7 +646,7 @@ export function createV2VisionTool(runtime: V2VisionRuntime): V2VisionToolDefini
594
646
  // header ONLY for Zen targets, never to a non-Zen provider.
595
647
  const requestTarget: NativeVisionTarget = {
596
648
  ...target,
597
- sessionID: call.sessionID,
649
+ sessionID,
598
650
  }
599
651
  let failure: NativeVisionFailure | undefined
600
652
  const output = await describeImagesNative(
@@ -46,6 +46,8 @@
46
46
  * @module pantheon/tools
47
47
  */
48
48
 
49
+ import { exec } from 'node:child_process'
50
+ import { promisify } from 'node:util'
49
51
  import { createCostCommand } from './cost-command.ts'
50
52
  import type { ShadowSink } from './decision-shadow.ts'
51
53
  import { createDeepworkTool } from './deepwork/deepwork-tool.ts'
@@ -476,6 +478,16 @@ const TODOWRITE_INPUT = {
476
478
  },
477
479
  } as const
478
480
 
481
+ let latestSessionTodos: unknown[] = []
482
+
483
+ export function getLatestSessionTodos(): unknown[] {
484
+ return latestSessionTodos
485
+ }
486
+
487
+ export function setLatestSessionTodos(todos: unknown[]): void {
488
+ latestSessionTodos = todos
489
+ }
490
+
479
491
  /** A V2 pass-through `todowrite`: the host stores the tool part in the
480
492
  * transcript, and the TUI todo panel renders the newest completed write. The
481
493
  * tool itself is stateless — the transcript IS the store. */
@@ -487,13 +499,98 @@ const todowriteTool: V2ToolDef = {
487
499
  input: TODOWRITE_INPUT,
488
500
  output: {},
489
501
  execute: async (input) => {
490
- const todos = Array.isArray((input as Record<string, unknown>).todos)
491
- ? (input as Record<string, unknown>).todos
492
- : []
502
+ const rawTodos = (input as Record<string, unknown>).todos
503
+ const todos: unknown[] = Array.isArray(rawTodos) ? (rawTodos as unknown[]) : []
504
+ latestSessionTodos = todos
493
505
  return { ok: true, todos, output: JSON.stringify({ todos }) }
494
506
  },
495
507
  }
496
508
 
509
+ const TODOREAD_INPUT = {
510
+ type: 'object',
511
+ additionalProperties: false,
512
+ properties: {
513
+ status: {
514
+ type: 'string',
515
+ description: 'Optional filter by task status (pending, in_progress, completed, cancelled)',
516
+ },
517
+ },
518
+ } as const
519
+
520
+ /** A V2 `todoread`: returns the newest task list written via `todowrite`. */
521
+ const todoreadTool: V2ToolDef = {
522
+ name: 'todoread',
523
+ description:
524
+ 'Read the active session task checklist. Returns the newest list of tasks written via todowrite.',
525
+ input: TODOREAD_INPUT,
526
+ output: {},
527
+ execute: async (input) => {
528
+ const statusFilter = (input as Record<string, unknown>)?.status
529
+ let todos = latestSessionTodos
530
+ if (typeof statusFilter === 'string' && statusFilter.trim() !== '') {
531
+ todos = todos.filter(
532
+ (t) =>
533
+ typeof t === 'object' &&
534
+ t !== null &&
535
+ (t as Record<string, unknown>).status === statusFilter,
536
+ )
537
+ }
538
+ return {
539
+ ok: true,
540
+ todos,
541
+ output: JSON.stringify({ todos }),
542
+ }
543
+ },
544
+ }
545
+
546
+ const execAsync = promisify(exec)
547
+
548
+ const SHELL_INPUT = {
549
+ type: 'object',
550
+ required: ['command'],
551
+ properties: {
552
+ command: {
553
+ type: 'string',
554
+ description: 'The shell command to execute in the workspace directory',
555
+ },
556
+ },
557
+ } as const
558
+
559
+ /**
560
+ * A V2 fallback shell tool alias. OpenCode registers `bash`, but models frequently
561
+ * attempt to invoke `shell` because of agent permission YAML conventions.
562
+ * This alias ensures terminal commands execute seamlessly without tool-not-found errors.
563
+ */
564
+ const shellTool: V2ToolDef = {
565
+ name: 'shell',
566
+ description: 'Execute a shell command in the workspace directory. Alias for bash execution.',
567
+ input: SHELL_INPUT,
568
+ output: {},
569
+ execute: async (input, context) => {
570
+ const command = String((input as Record<string, unknown>).command ?? '')
571
+ if (!command.trim()) {
572
+ return { output: '', ok: false, error: 'Command cannot be empty' }
573
+ }
574
+ const toolCtx = toolContext(context)
575
+ const cwd = toolCtx.directory || process.cwd()
576
+ try {
577
+ const { stdout, stderr } = await execAsync(command, {
578
+ cwd,
579
+ maxBuffer: 10 * 1024 * 1024,
580
+ shell: '/bin/bash',
581
+ })
582
+ const output = [stdout, stderr].filter(Boolean).join('\n')
583
+ return { output, ok: true }
584
+ } catch (err: unknown) {
585
+ const execError = err as { stdout?: string; stderr?: string; message?: string }
586
+ const output = [execError.stdout, execError.stderr, execError.message]
587
+ .filter(Boolean)
588
+ .join('\n')
589
+ return { output, ok: false, error: output }
590
+ }
591
+ },
592
+ }
593
+
497
594
  export function createV2ToolDefinitions(
498
595
  visionRuntime?: V2VisionRuntime,
499
596
  shadow: V2ToolShadowOptions = {},
@@ -545,6 +642,8 @@ export function createV2ToolDefinitions(
545
642
  }),
546
643
  )
547
644
  definitions.push(todowriteTool)
645
+ definitions.push(todoreadTool)
646
+ definitions.push(shellTool)
548
647
  definitions.push(createV2SkillSearchDefinition())
549
648
  definitions.push(createDeepworkTool())
550
649
  if (visionRuntime) definitions.push(createV2VisionTool(visionRuntime))