pantheon-opencode 1.6.2-beta.3 → 1.6.2-beta.5

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 (71) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +209 -1
  3. package/bin/pantheon-init.mjs +22 -0
  4. package/package.json +9 -3
  5. package/plugin.json +1 -1
  6. package/pyproject.toml +1 -1
  7. package/scripts/decision-router-budget.mjs +781 -0
  8. package/scripts/decision-router-v2-budget.mjs +218 -0
  9. package/scripts/decision-router-v2-egress.mjs +272 -0
  10. package/scripts/decision-router.mjs +519 -0
  11. package/scripts/docs-check-changelog.mjs +5 -3
  12. package/scripts/install/decision-layer-preview.mjs +376 -0
  13. package/scripts/install/decision-router-config.mjs +579 -0
  14. package/scripts/install/interactive.mjs +76 -5
  15. package/scripts/install/opencode.mjs +12 -0
  16. package/scripts/install/state.mjs +5 -0
  17. package/scripts/install/strings.mjs +4 -0
  18. package/scripts/mcp_resources.py +11 -9
  19. package/scripts/release-notes.mjs +30 -7
  20. package/scripts/versioning.mjs +41 -5
  21. package/src/agents/zeus.md +12 -0
  22. package/src/mcp/eval_store.py +11 -4
  23. package/src/mcp/mcp_resources.py +11 -9
  24. package/src/mcp/memory_mcp.py +293 -150
  25. package/src/pantheon/local-decision-agents.ts +170 -0
  26. package/src/pantheon/local-decision-budget.ts +1043 -0
  27. package/src/pantheon/local-decision-egress-gate.ts +264 -0
  28. package/src/pantheon/local-decision-prompt.ts +268 -0
  29. package/src/pantheon/local-decision-provider-matrix.ts +92 -0
  30. package/src/pantheon/local-decision-provider-protocol.ts +335 -0
  31. package/src/pantheon/local-decision-provider.internal.ts +260 -0
  32. package/src/pantheon/local-decision-router.ts +225 -0
  33. package/src/pantheon/local-decision-skills.ts +281 -0
  34. package/src/pantheon/local-decision-tool.ts +160 -0
  35. package/src/pantheon/local-decision-turn.ts +338 -0
  36. package/src/pantheon/local-decision-usage-evidence.internal.ts +207 -0
  37. package/src/pantheon/local-orchestration.ts +322 -0
  38. package/src/pantheon/pantheon-decision-catalog.ts +101 -0
  39. package/src/pantheon/v2-decision-budget.ts +456 -0
  40. package/src/pantheon/v2-decision-contracts.ts +300 -0
  41. package/src/pantheon/v2-decision-egress.ts +203 -0
  42. package/src/pantheon/v2-decision-events.ts +180 -0
  43. package/src/pantheon/v2-decision-heuristic.ts +121 -0
  44. package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
  45. package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
  46. package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
  47. package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
  48. package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
  49. package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
  50. package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
  51. package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
  52. package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
  53. package/src/pantheon/v2-decision-points/p8-guardrail.ts +366 -0
  54. package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
  55. package/src/pantheon/v2-decision-points.ts +242 -0
  56. package/src/pantheon/v2-decision-policy.ts +166 -0
  57. package/src/pantheon/v2-decision-premises.ts +146 -0
  58. package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
  59. package/src/pantheon/v2-decision-rank.ts +91 -0
  60. package/src/pantheon/v2-decision-registry.ts +391 -0
  61. package/src/pantheon/v2-decision-resource-ids.ts +127 -0
  62. package/src/pantheon/v2-decision-shadow.ts +123 -0
  63. package/src/pantheon/v2-decision-telemetry.ts +214 -0
  64. package/src/pantheon/v2-decision-verify.ts +51 -0
  65. package/src/pantheon/v2-tools.ts +35 -15
  66. package/src/plugin-v2.ts +357 -22
  67. package/src/plugin.ts +4 -0
  68. package/src/plugins/tui/dist/tui-v2.js +3 -3
  69. package/src/plugins/tui/dist/tui.js +1 -1
  70. package/src/plugins/tui/package-lock.json +2 -2
  71. package/src/plugins/tui/package.json +1 -1
@@ -50,6 +50,7 @@ import {
50
50
  validateMcpV1toV2Source,
51
51
  } from './config-migration.mjs'
52
52
  import { resolveGlobalConfigDirectory } from './config-paths.mjs'
53
+ import { migrateDecisionRouterConfig } from './decision-router-config.mjs'
53
54
  import { componentForInstalledPath, updateFileInventory } from './file-inventory.mjs'
54
55
  import { healthCheck } from './health-check.mjs'
55
56
  import {
@@ -1640,6 +1641,9 @@ async function installPass(
1640
1641
  const componentSet = new Set(
1641
1642
  opts.noMcp ? components.filter((component) => component !== 'runtime') : components,
1642
1643
  )
1644
+ let decisionRouterConfig = migrateDecisionRouterConfig(
1645
+ opts.decisionRouterConfig ?? readState(target)?.decision_router,
1646
+ )
1643
1647
  const stats = summary.opencode
1644
1648
  // Per-call baseline. `stats` is the module-level cumulative summary, so the
1645
1649
  // consistency guard must compare against THIS call's delta, not the total.
@@ -1789,6 +1793,10 @@ async function installPass(
1789
1793
  components: promptComponents,
1790
1794
  defaultComponents: promptDefaults,
1791
1795
  noMcp: opts.noMcp === true,
1796
+ getDecisionRouterConfig: (selection) => {
1797
+ const selectionTarget = selection === 'project' ? process.cwd() : target
1798
+ return readState(selectionTarget)?.decision_router
1799
+ },
1792
1800
  prompts: opts.deps?.prompts,
1793
1801
  isTTY: opts.deps?.isTTY,
1794
1802
  })
@@ -1824,6 +1832,8 @@ async function installPass(
1824
1832
  for (const c of newComponents) componentSet.add(c)
1825
1833
 
1826
1834
  target = selectedTarget
1835
+ decisionRouterConfig = migrateDecisionRouterConfig(result.decisionRouterConfig)
1836
+ opts.decisionRouterConfig = decisionRouterConfig
1827
1837
  if (!dryRun && _lastRun) _lastRun.target = target
1828
1838
  }
1829
1839
 
@@ -3171,6 +3181,7 @@ async function installPass(
3171
3181
  const packageVersion = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).version
3172
3182
  let state = projectedState ?? readState(target)
3173
3183
  if (!state) state = createInitialState(packageVersion, planTimestamp)
3184
+ state.decision_router = decisionRouterConfig
3174
3185
  state.pantheon_version = packageVersion
3175
3186
  state.updated_at = planTimestamp
3176
3187
  state.schema_version = 2
@@ -3319,6 +3330,7 @@ async function installPass(
3319
3330
  throw new Error('Installation state exists but cannot be read; refusing to replace it')
3320
3331
  }
3321
3332
  state ??= createInitialState(packageVersion, planTimestamp)
3333
+ state.decision_router = decisionRouterConfig
3322
3334
  state.pantheon_version = packageVersion
3323
3335
  state.updated_at = planTimestamp
3324
3336
  for (const component of ['agents', 'skills', 'plugins', 'runtime']) {
@@ -31,6 +31,7 @@
31
31
 
32
32
  import { existsSync, mkdirSync, readFileSync } from 'node:fs'
33
33
  import { join, resolve } from 'node:path'
34
+ import { migrateDecisionRouterConfig } from './decision-router-config.mjs'
34
35
  import { assertNoSymlinkAncestors, writeFileAtomically } from './verify.mjs'
35
36
 
36
37
  const STATE_FILE = 'install-state.json'
@@ -82,6 +83,7 @@ export function createInitialState(version, updatedAt = new Date().toISOString()
82
83
  plugins: { version: 1, status: 'pending' },
83
84
  runtime: { version: 1, status: 'pending' },
84
85
  },
86
+ decision_router: migrateDecisionRouterConfig(undefined),
85
87
  file_inventory: emptyFileInventory(false),
86
88
  }
87
89
  }
@@ -139,6 +141,7 @@ export function upgradeStateV1toV2(state) {
139
141
  plugins: { version: 1, status: 'unknown' },
140
142
  runtime: { version: 1, status: 'unknown' },
141
143
  },
144
+ decision_router: migrateDecisionRouterConfig(state.decision_router),
142
145
  file_inventory: normalizeFileInventory(state),
143
146
  }
144
147
  }
@@ -174,6 +177,7 @@ function ensureV2Shape(state) {
174
177
  ) {
175
178
  state.file_inventory = invalidFileInventory()
176
179
  }
180
+ state.decision_router = migrateDecisionRouterConfig(state.decision_router)
177
181
  return state
178
182
  }
179
183
 
@@ -206,6 +210,7 @@ export function writeState(target, state, options = {}) {
206
210
  state.schema_version = 2
207
211
  if (!Object.hasOwn(state, 'migration_schema_version')) state.migration_schema_version = null
208
212
  if (!Array.isArray(state.applied_migrations)) state.applied_migrations = []
213
+ state.decision_router = migrateDecisionRouterConfig(state.decision_router)
209
214
  if (!Object.hasOwn(state, 'file_inventory')) {
210
215
  state.file_inventory = emptyFileInventory(true)
211
216
  } else if (
@@ -21,6 +21,8 @@ const TABLE = {
21
21
  cancelPoints: {
22
22
  components: 'component selection',
23
23
  target: 'install location',
24
+ decisionRouter: 'decision router selection',
25
+ egressConsent: 'external data-sharing consent',
24
26
  confirmation: 'pre-install confirmation',
25
27
  review: 'review prompt',
26
28
  interrupt: 'interrupt (Ctrl-C)',
@@ -114,6 +116,8 @@ const TABLE = {
114
116
  cancelPoints: {
115
117
  components: 'seleção de componentes',
116
118
  target: 'local da instalação',
119
+ decisionRouter: 'seleção do roteador decisório',
120
+ egressConsent: 'consentimento de compartilhamento externo',
117
121
  confirmation: 'confirmação antes de instalar',
118
122
  review: 'prompt de revisão',
119
123
  interrupt: 'interrupção (Ctrl-C)',
@@ -23,7 +23,6 @@ from fastmcp import FastMCP
23
23
 
24
24
  # ── Path Resolution ──────────────────────────────────────────────────────────
25
25
  _PANTHEON_HOME: Path = pantheon_home()
26
- _PANTHEON_PROJECT: Path | None = pantheon_project()
27
26
 
28
27
 
29
28
  def _within(path: Path, parent: Path) -> bool:
@@ -68,12 +67,13 @@ def _resource_root(name: str) -> Path | None:
68
67
  preserves the global fallback while preventing symlink escapes.
69
68
  """
70
69
  candidates: list[tuple[Path, Path]] = []
71
- if _PANTHEON_PROJECT is not None:
70
+ project = pantheon_project()
71
+ if project is not None:
72
72
  if name in {"agents", "skills"}:
73
- local = _PANTHEON_PROJECT / ".opencode"
73
+ local = project / ".opencode"
74
74
  candidates.append((local / name, local))
75
75
  elif name in {"deepwork", "memory-bank"}:
76
- local = _PANTHEON_PROJECT / ".pantheon"
76
+ local = project / ".pantheon"
77
77
  candidates.append((local / name, local))
78
78
  candidates.append((_PANTHEON_HOME / name, _PANTHEON_HOME))
79
79
  for root, parent in candidates:
@@ -86,9 +86,10 @@ def _resource_root(name: str) -> Path | None:
86
86
  def _resource_roots(name: str) -> list[Path]:
87
87
  """Return safe resource roots in local-first precedence order."""
88
88
  roots: list[Path] = []
89
- if _PANTHEON_PROJECT is not None:
89
+ project = pantheon_project()
90
+ if project is not None:
90
91
  base_name = ".opencode" if name in {"agents", "skills"} else ".pantheon"
91
- base = _PANTHEON_PROJECT / base_name
92
+ base = project / base_name
92
93
  local = _safe_root(base / name, base)
93
94
  if local is not None:
94
95
  roots.append(local)
@@ -208,9 +209,10 @@ async def list_skills() -> str:
208
209
  async def get_routing() -> str:
209
210
  """Return the full content of routing.yml."""
210
211
  routing_file = _safe_child(_PANTHEON_HOME, "routing.yml")
211
- if routing_file is None and _PANTHEON_PROJECT:
212
- routing_file = _safe_child(_PANTHEON_PROJECT / "src", "routing.yml")
213
- if routing_file is None or not routing_file.exists():
212
+ project = pantheon_project()
213
+ if (routing_file is None or not routing_file.is_file()) and project:
214
+ routing_file = _safe_child(project / "src", "routing.yml")
215
+ if routing_file is None or not routing_file.is_file():
214
216
  return "routing.yml not found."
215
217
  return routing_file.read_text(encoding="utf-8")
216
218
 
@@ -19,8 +19,8 @@
19
19
  * bullet `- #N - <subject>` per referenced issue
20
20
  * (deduped); the group is OMITTED when no refs exist
21
21
  *
22
- * Omitted (internal, never user-facing): chore | refactor | test | ci |
23
- * build | style | revert (unknown conventional types too).
22
+ * Omitted (internal, never user-facing): release scope and chore | refactor |
23
+ * test | ci | build | style | revert (unknown conventional types too).
24
24
  *
25
25
  * Breaking: `BREAKING CHANGE` footer or `type!:` / `type(scope)!:` — the
26
26
  * commit keeps its type bucket and the bullet is prefixed with 💥
@@ -126,6 +126,27 @@ function parseIssueRefs(body) {
126
126
  return [...body.matchAll(/\b(?:Closes|Fixes|Resolves)\s+#(\d+)\b/gi)].map((m) => Number(m[1]))
127
127
  }
128
128
 
129
+ /**
130
+ * Detect the documented BREAKING CHANGE trailer in the final body paragraph.
131
+ * The marker must be a trailer line, not a phrase embedded in body prose.
132
+ *
133
+ * @param {string} body
134
+ * @returns {boolean}
135
+ */
136
+ function hasBreakingFooter(body) {
137
+ const footerLines = body
138
+ .trimEnd()
139
+ .split(/\r?\n(?:[ \t]*\r?\n)+/)
140
+ .at(-1)
141
+ .split(/\r?\n/)
142
+ const isTrailerLine = /^[A-Za-z][A-Za-z-]*(?: [A-Za-z][A-Za-z-]*)*:[ \t]+\S/
143
+
144
+ return (
145
+ isTrailerLine.test(footerLines[0]) &&
146
+ footerLines.some((line) => /^BREAKING CHANGE:[ \t]+\S.*$/i.test(line))
147
+ )
148
+ }
149
+
129
150
  /**
130
151
  * Parse one "subject|body" record into a conventional-commit entry.
131
152
  * Returns null for records that must be skipped: merge commits ("Merge ..."),
@@ -151,7 +172,7 @@ export function parseCommitLine(line) {
151
172
  type: type.toLowerCase(),
152
173
  scope: scope || null,
153
174
  subject: cleanSubject,
154
- breaking: Boolean(bang) || /BREAKING CHANGE/i.test(body),
175
+ breaking: Boolean(bang) || hasBreakingFooter(body),
155
176
  refs: parseIssueRefs(body),
156
177
  }
157
178
  }
@@ -159,7 +180,8 @@ export function parseCommitLine(line) {
159
180
  /**
160
181
  * Conventional type → final release-note group. Types missing from this map
161
182
  * (chore, refactor, test, ci, build, style, revert, unknown) are internal
162
- * and omitted from the notes.
183
+ * and omitted from the notes. The maintainer-only `release` scope is also
184
+ * omitted, including its issue references.
163
185
  */
164
186
  const TYPE_GROUPS = {
165
187
  feat: 'whatsNew',
@@ -172,8 +194,9 @@ const TYPE_GROUPS = {
172
194
  /**
173
195
  * Group parsed commits into the final release-note sections. Breaking
174
196
  * commits keep their type bucket (the 💥 marker is applied at render time);
175
- * internal types are dropped; issue refs from ANY commit body feed
176
- * closedIssues (deduped, first occurrence wins). Entries keep git log order.
197
+ * internal types and the `release` scope are dropped; issue refs from remaining
198
+ * commit bodies feed closedIssues (deduped, first occurrence wins). Entries
199
+ * keep git log order.
177
200
  *
178
201
  * @param {Array<ReturnType<typeof parseCommitLine>>} entries
179
202
  * @param {{knownIssues?: string[]|string|null}} [options]
@@ -192,7 +215,7 @@ export function groupCommits(entries, options = {}) {
192
215
  }
193
216
  const seenRefs = new Set()
194
217
  for (const entry of entries) {
195
- if (!entry) continue
218
+ if (!entry || entry.scope === 'release') continue
196
219
  const bucket = TYPE_GROUPS[entry.type]
197
220
  if (bucket) groups[bucket].push(entry)
198
221
  for (const ref of entry.refs) {
@@ -61,6 +61,29 @@ function getLatestTag() {
61
61
  return tags.at(-1) || 'v0.0.0'
62
62
  }
63
63
 
64
+ function getLatestBetaTag() {
65
+ const tags = runGit(['tag', '-l', 'v*'])
66
+ .split('\n')
67
+ .filter((tag) => /^v\d+\.\d+\.\d+-beta\.\d+$/.test(tag))
68
+ tags.sort((left, right) => {
69
+ const a = left
70
+ .slice(1)
71
+ .match(/^(\d+)\.(\d+)\.(\d+)-beta\.(\d+)$/)
72
+ .slice(1)
73
+ .map(Number)
74
+ const b = right
75
+ .slice(1)
76
+ .match(/^(\d+)\.(\d+)\.(\d+)-beta\.(\d+)$/)
77
+ .slice(1)
78
+ .map(Number)
79
+ for (let index = 0; index < a.length; index += 1) {
80
+ if (a[index] !== b[index]) return a[index] - b[index]
81
+ }
82
+ return 0
83
+ })
84
+ return tags.at(-1) || null
85
+ }
86
+
64
87
  function getCurrentVersion() {
65
88
  return validateInventory(ROOT).sourceVersion
66
89
  }
@@ -400,9 +423,9 @@ switch (command) {
400
423
  const useBeta = command === 'beta' || args.includes('--beta')
401
424
 
402
425
  // Beta: advance the committed X.Y.Z-beta.N line and promote the
403
- // [Unreleased] CHANGELOG section into [vX.Y.Z-beta.N], exactly like the
404
- // stable path. The committed manifest is the single source of truth — no
405
- // npm lookup, no git lookup, and no runtime version computation.
426
+ // [Unreleased] CHANGELOG section into [vX.Y.Z-beta.N]. Optional --notes
427
+ // uses commits since the latest beta tag; without it, the manual
428
+ // [Unreleased] body is preserved.
406
429
  if (useBeta) {
407
430
  if (!contentHasUnreleased())
408
431
  throw new Error('CHANGELOG.md is missing the [Unreleased] section')
@@ -410,7 +433,18 @@ switch (command) {
410
433
  const newVersion = nextBetaVersion(current)
411
434
  const date = new Date().toISOString().slice(0, 10)
412
435
  console.log(`Bumping ${current} → ${newVersion} (beta)`)
413
- const changelogPlan = prepareUnreleased(newVersion, date)
436
+ let notesBody = null
437
+ if (useNotes) {
438
+ const since = getLatestBetaTag()
439
+ if (!since) throw new Error('cannot generate beta release notes: no prior beta tag found')
440
+ const raw = collectEntries({ since })
441
+ notesBody = renderChangelog(groupCommits(raw.map(parseCommitLine)))
442
+ if (!notesBody) {
443
+ throw new Error(`cannot generate beta release notes: no generated notes since ${since}`)
444
+ }
445
+ console.log(` --notes generated from ${raw.length} commits since ${since}`)
446
+ }
447
+ const changelogPlan = prepareUnreleased(newVersion, date, notesBody)
414
448
  const manifestPlan = prepareManifests(newVersion)
415
449
  commitPreparedRelease(
416
450
  { ...manifestPlan, version: newVersion },
@@ -508,9 +542,11 @@ Commands:
508
542
  apply [type] Bump manifests + move [Unreleased] → [vX.Y.Z]
509
543
  type: patch | minor | major | auto (default: auto)
510
544
  --notes: pre-fill the promoted entry with release
511
- notes generated from conventional commits
545
+ notes since the latest stable tag
512
546
  --beta: advance the committed X.Y.Z-beta.N line and
513
547
  promote [Unreleased] → [vX.Y.Z-beta.N] in CHANGELOG
548
+ --beta --notes: generate notes since the latest beta tag
549
+ (fails without a beta baseline or non-empty notes)
514
550
  beta Alias for 'apply --beta'
515
551
  changelog [version] Promote [Unreleased], or merge into an existing version section
516
552
 
@@ -36,6 +36,18 @@ skills:
36
36
 
37
37
  **Coordenador APENAS. Zeus NUNCA lê arquivos de código-fonte.** Toda leitura de `src/`, `tests/`, `scripts/` vai para @apollo. Leia apenas: config, docs, memory bank, delegação.
38
38
 
39
+ ## Local advisory routing before native delegation
40
+
41
+ - For an obvious, bounded task with one clear specialist, dispatch directly with the native `subagent` tool. Do not call `pantheon_local_decision`, Jev, council, or Athena planning just to confirm an obvious route.
42
+ - For a genuinely ambiguous specialist choice, use `pantheon_local_decision` only if it is present. It evaluates locally only; provider transport/API has been removed, and provider configuration, consent, caps, or period confirmation do not enable runtime calls. If absent, unconfigured, or it abstains, continue with your own routing judgment and the host's actual native tool schema.
43
+ - Build `candidateAgents` only from targets currently shown as available by native `subagent` and allowed by current routing/grants. Do not invent candidates. Supply only relevant available skill IDs and resource IDs; `domain` is one exact candidate ID only when the domain mapping is clear, otherwise null. Pass no task text, transcript, file contents, memory contents, credentials, or secrets.
44
+ - Treat the returned agent/skill/resource IDs and memory boolean as recommendations, not authorization. Re-check the candidate against current routing, grants, and availability before dispatch. Preserve all fixed review, human-approval, data-integrity, and security gates regardless of complexity or recommendation.
45
+ - If `recommendMemorySearch` is true and prior project history could change the outcome, Zeus may make one selective local `pantheon-memory` search. Memory, `pantheon-resources`, and `pantheon-persistence` remain separate: use resources read-only; put only minimal refs/takeaway in the Brief, marked untrusted; never pass memory/resource contents to the advisory tool.
46
+ - Construct the final Brief locally and use native `subagent` unchanged; native dispatch is always the final routing action. The local recommendation tool never dispatches, loads skills/resources, searches memory, or changes grants/gates. No remote Jev or OpenAI Decisions runtime calls are available, regardless of user control settings.
47
+ This local-only guarantee applies only to decision routing, not all product egress.
48
+ Separately documented quota (including manual `/quota-go-check`) and Vision
49
+ integrations retain their own external-request behavior.
50
+
39
51
  ## Visual Context for Implementation
40
52
 
41
53
  Zeus never implements code, but visual references from the user are implementation context and must reach the specialist who does the work.
@@ -67,10 +67,17 @@ def _connect() -> sqlite3.Connection:
67
67
  """Open (creating if needed) the memory DB with row access."""
68
68
  path = _db_path()
69
69
  path.parent.mkdir(parents=True, exist_ok=True)
70
- conn = sqlite3.connect(str(path))
71
- conn.row_factory = sqlite3.Row
72
- conn.execute("PRAGMA journal_mode=WAL")
73
- conn.executescript(_SCHEMA_SQL)
70
+ conn = sqlite3.connect(str(path), timeout=5.0)
71
+ try:
72
+ conn.row_factory = sqlite3.Row
73
+ # Keep the busy wait explicit so eval resource reads tolerate the
74
+ # memory MCP's short SQLite write transactions.
75
+ conn.execute("PRAGMA busy_timeout=5000")
76
+ conn.execute("PRAGMA journal_mode=WAL")
77
+ conn.executescript(_SCHEMA_SQL)
78
+ except BaseException:
79
+ conn.close()
80
+ raise
74
81
  return conn
75
82
 
76
83
 
@@ -23,7 +23,6 @@ from fastmcp import FastMCP
23
23
 
24
24
  # ── Path Resolution ──────────────────────────────────────────────────────────
25
25
  _PANTHEON_HOME: Path = pantheon_home()
26
- _PANTHEON_PROJECT: Path | None = pantheon_project()
27
26
 
28
27
 
29
28
  def _within(path: Path, parent: Path) -> bool:
@@ -68,12 +67,13 @@ def _resource_root(name: str) -> Path | None:
68
67
  preserves the global fallback while preventing symlink escapes.
69
68
  """
70
69
  candidates: list[tuple[Path, Path]] = []
71
- if _PANTHEON_PROJECT is not None:
70
+ project = pantheon_project()
71
+ if project is not None:
72
72
  if name in {"agents", "skills"}:
73
- local = _PANTHEON_PROJECT / ".opencode"
73
+ local = project / ".opencode"
74
74
  candidates.append((local / name, local))
75
75
  elif name in {"deepwork", "memory-bank"}:
76
- local = _PANTHEON_PROJECT / ".pantheon"
76
+ local = project / ".pantheon"
77
77
  candidates.append((local / name, local))
78
78
  candidates.append((_PANTHEON_HOME / name, _PANTHEON_HOME))
79
79
  for root, parent in candidates:
@@ -86,9 +86,10 @@ def _resource_root(name: str) -> Path | None:
86
86
  def _resource_roots(name: str) -> list[Path]:
87
87
  """Return safe resource roots in local-first precedence order."""
88
88
  roots: list[Path] = []
89
- if _PANTHEON_PROJECT is not None:
89
+ project = pantheon_project()
90
+ if project is not None:
90
91
  base_name = ".opencode" if name in {"agents", "skills"} else ".pantheon"
91
- base = _PANTHEON_PROJECT / base_name
92
+ base = project / base_name
92
93
  local = _safe_root(base / name, base)
93
94
  if local is not None:
94
95
  roots.append(local)
@@ -208,9 +209,10 @@ async def list_skills() -> str:
208
209
  async def get_routing() -> str:
209
210
  """Return the full content of routing.yml."""
210
211
  routing_file = _safe_child(_PANTHEON_HOME, "routing.yml")
211
- if routing_file is None and _PANTHEON_PROJECT:
212
- routing_file = _safe_child(_PANTHEON_PROJECT / "src", "routing.yml")
213
- if routing_file is None or not routing_file.exists():
212
+ project = pantheon_project()
213
+ if (routing_file is None or not routing_file.is_file()) and project:
214
+ routing_file = _safe_child(project / "src", "routing.yml")
215
+ if routing_file is None or not routing_file.is_file():
214
216
  return "routing.yml not found."
215
217
  return routing_file.read_text(encoding="utf-8")
216
218