pantheon-opencode 1.7.0 → 2.0.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 (173) hide show
  1. package/AGENTS.global.md +2 -2
  2. package/AGENTS.md +3 -3
  3. package/CHANGELOG.md +85 -59
  4. package/README.md +74 -48
  5. package/README.pt-BR.md +19 -19
  6. package/bin/pantheon-init.mjs +11 -48
  7. package/package.json +9 -13
  8. package/plugin.json +2 -2
  9. package/pyproject.toml +1 -1
  10. package/scripts/build-agents-md.mjs +7 -6
  11. package/scripts/{check-plugin-v2-coverage.mjs → check-plugin-coverage.mjs} +7 -7
  12. package/scripts/{decision-router-v2-budget.mjs → decision-router-budget-gates.mjs} +1 -1
  13. package/scripts/{decision-router-v2-egress.mjs → decision-router-egress.mjs} +1 -1
  14. package/scripts/decision-router.mjs +2 -2
  15. package/scripts/docs-media.mjs +1 -1
  16. package/scripts/doctor.mjs +225 -136
  17. package/scripts/install/behavior-overrides.bundle.mjs +123 -0
  18. package/scripts/install/{v2-capabilities.mjs → capabilities.mjs} +7 -7
  19. package/scripts/install/config-migration.mjs +60 -253
  20. package/scripts/install/file-inventory.mjs +6 -4
  21. package/scripts/install/interactive.mjs +1 -1
  22. package/scripts/install/opencode-state.mjs +13 -12
  23. package/scripts/install/opencode-version.mjs +97 -162
  24. package/scripts/install/opencode.mjs +271 -428
  25. package/scripts/install/plan.mjs +1 -9
  26. package/scripts/install/plugin.mjs +19 -35
  27. package/scripts/install/shared.mjs +40 -1
  28. package/scripts/package-evidence.mjs +1 -4
  29. package/scripts/probe-pantheon-cost.mjs +1 -1
  30. package/scripts/reconcile.mjs +5 -7
  31. package/scripts/release-gates.mjs +22 -61
  32. package/scripts/setup-v2-config.mjs +10 -8
  33. package/scripts/setup.mjs +12 -22
  34. package/scripts/sync-tui.mjs +9 -17
  35. package/scripts/{test-opencode-v2-sandbox.sh → test-opencode-sandbox.sh} +9 -9
  36. package/scripts/update-skills-lock.mjs +24 -12
  37. package/scripts/update.mjs +17 -1
  38. package/scripts/validate-routing.mjs +79 -4
  39. package/scripts/validate-sandbox-install.mjs +3 -3
  40. package/skills-lock.json +25 -8
  41. package/src/agents/zeus.md +1 -0
  42. package/src/pantheon/behavior-overrides.ts +191 -0
  43. package/src/pantheon/{v2-bounded-read.ts → bounded-read.ts} +1 -1
  44. package/src/pantheon/cost-command.ts +1 -1
  45. package/src/pantheon/{v2-decision-contracts.ts → decision-contracts.ts} +3 -3
  46. package/src/pantheon/{v2-decision-points → decision-points}/p1-agent.ts +3 -3
  47. package/src/pantheon/{v2-decision-points → decision-points}/p10-claims.ts +2 -2
  48. package/src/pantheon/{v2-decision-points → decision-points}/p11-catalog.ts +2 -2
  49. package/src/pantheon/{v2-decision-points → decision-points}/p2-skill.ts +3 -3
  50. package/src/pantheon/{v2-decision-points → decision-points}/p3-complexity.ts +6 -6
  51. package/src/pantheon/{v2-decision-points → decision-points}/p4-memory.ts +2 -2
  52. package/src/pantheon/{v2-decision-points → decision-points}/p5-themis-verify.ts +2 -2
  53. package/src/pantheon/{v2-decision-points → decision-points}/p6-council.ts +3 -3
  54. package/src/pantheon/{v2-decision-points → decision-points}/p7-loop.ts +5 -5
  55. package/src/pantheon/{v2-decision-points → decision-points}/p8-guardrail.ts +2 -2
  56. package/src/pantheon/{v2-decision-points → decision-points}/p9-memory-compaction.ts +2 -2
  57. package/src/pantheon/{v2-decision-points.ts → decision-points.ts} +5 -5
  58. package/src/pantheon/{v2-decision-policy.ts → decision-policy.ts} +2 -2
  59. package/src/pantheon/{v2-decision-prompt-surface.ts → decision-prompt-surface.ts} +3 -3
  60. package/src/pantheon/{v2-decision-registry.ts → decision-registry.ts} +10 -13
  61. package/src/pantheon/{v2-decision-resource-ids.ts → decision-resource-ids.ts} +1 -1
  62. package/src/pantheon/{v2-decision-shadow.ts → decision-shadow.ts} +1 -1
  63. package/src/pantheon/{v2-decision-telemetry.ts → decision-telemetry.ts} +1 -1
  64. package/src/pantheon/{v2-execute-after.ts → execute-after.ts} +4 -4
  65. package/src/pantheon/goal-store.ts +7 -0
  66. package/src/pantheon/{v2-hook-engine.ts → hook-engine.ts} +3 -3
  67. package/src/pantheon/jev-decision-tool.ts +3 -3
  68. package/src/pantheon/jev-decisions.ts +12 -6
  69. package/src/pantheon/jev-escalation.ts +6 -6
  70. package/src/pantheon/jev-quality-score.ts +2 -2
  71. package/src/pantheon/jev-rank-verify.ts +2 -2
  72. package/src/pantheon/jev-risk-gate.ts +4 -4
  73. package/src/pantheon/local-decision-agents.ts +1 -1
  74. package/src/pantheon/local-decision-router.ts +1 -1
  75. package/src/pantheon/local-decision-tool.ts +2 -2
  76. package/src/pantheon/local-orchestration.ts +1 -1
  77. package/src/pantheon/model-command.ts +1 -1
  78. package/src/pantheon/{v2-vision.ts → native-vision.ts} +12 -15
  79. package/src/pantheon/pantheon-decision-catalog.ts +12 -0
  80. package/src/pantheon/{v2-shell-hooks.ts → shell-hooks.ts} +4 -4
  81. package/src/pantheon/{v2-tools.ts → tools.ts} +4 -4
  82. package/src/pantheon/{v2-unsupported.d.mts → unsupported.d.mts} +3 -3
  83. package/src/pantheon/{v2-unsupported.mjs → unsupported.mjs} +8 -8
  84. package/src/pantheon/update-notifier.ts +101 -0
  85. package/src/pantheon/vision-local.ts +12 -3
  86. package/src/pantheon/vision.ts +120 -2
  87. package/src/{plugin-v2 → plugin}/index.ts +7 -7
  88. package/src/plugin.ts +2870 -500
  89. package/src/plugins/hook-runner.ts +3 -3
  90. package/src/plugins/tui/dist/server.d.ts +23 -9
  91. package/src/plugins/tui/dist/server.d.ts.map +1 -1
  92. package/src/plugins/tui/dist/server.js +25 -12
  93. package/src/plugins/tui/dist/server.js.map +1 -1
  94. package/src/plugins/tui/dist/tui.d.ts +1023 -494
  95. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  96. package/src/plugins/tui/dist/tui.js +5612 -2086
  97. package/src/plugins/tui/dist/tui.js.map +1 -1
  98. package/src/plugins/tui/{index-v2.ts → index.ts} +1 -1
  99. package/src/plugins/tui/package-lock.json +2 -42
  100. package/src/plugins/tui/package.json +4 -10
  101. package/src/plugins/tui/src/cost-data.ts +1 -1
  102. package/src/plugins/tui/src/decision-router-state.ts +242 -0
  103. package/src/plugins/tui/src/doctor-state.ts +198 -0
  104. package/src/plugins/tui/src/index.tsx +4222 -2822
  105. package/src/plugins/tui/src/j1-gate-status.ts +85 -0
  106. package/src/plugins/tui/src/pantheon-settings-state.ts +245 -0
  107. package/src/plugins/tui/src/pantheon-settings.tsx +442 -0
  108. package/src/plugins/tui/src/preset-state.ts +143 -0
  109. package/src/plugins/tui/src/server.ts +23 -10
  110. package/src/plugins/tui/src/update-notice.ts +90 -0
  111. package/src/plugins/tui/src/update-status.ts +98 -0
  112. package/src/plugins/tui/tsconfig.typecheck.json +9 -2
  113. package/src/plugins/tui/tsdown.config.ts +3 -5
  114. package/src/plugins/tui/tui.ts +1 -2
  115. package/src/routing.yml +36 -0
  116. package/src/skills/README.md +16 -1
  117. package/src/skills/artifact-management/SKILL.md +10 -67
  118. package/src/skills/artifact-management/references/artifact-templates.md +71 -0
  119. package/src/skills/auto-continue/SKILL.md +10 -0
  120. package/src/skills/code-review-checklist/SKILL.md +11 -44
  121. package/src/skills/code-review-checklist/references/review-checklists.md +54 -0
  122. package/src/skills/instruction-forge/SKILL.md +57 -0
  123. package/src/skills/instruction-forge/references/agents-md-doctrine.md +50 -0
  124. package/src/skills/instruction-forge/references/eval-doctrine.md +37 -0
  125. package/src/skills/instruction-forge/references/skill-doctrine.md +62 -0
  126. package/src/skills/memory-bank/SKILL.md +11 -90
  127. package/src/skills/memory-bank/references/anti-patterns.md +33 -0
  128. package/src/skills/memory-bank/references/product-adoption.md +19 -0
  129. package/src/skills/memory-bank/references/storage-model.md +21 -0
  130. package/src/skills/memory-bank/references/structure-and-frequency.md +44 -0
  131. package/src/skills/reflect/SKILL.md +1 -0
  132. package/src/skills/session-goal/SKILL.md +7 -54
  133. package/src/skills/session-goal/references/goal-format.md +26 -0
  134. package/src/skills/session-goal/references/session-reuse.md +44 -0
  135. package/src/skills/tdd-with-agents/SKILL.md +11 -101
  136. package/src/skills/tdd-with-agents/references/advanced-testing-patterns.md +58 -0
  137. package/src/skills/tdd-with-agents/references/testing-by-layer.md +60 -0
  138. package/src/skills/visual-review-pipeline/SKILL.md +11 -120
  139. package/src/skills/visual-review-pipeline/references/findings-schema.md +49 -0
  140. package/src/skills/visual-review-pipeline/references/workflow-steps.md +111 -0
  141. package/scripts/hooks/log-session-start.sh +0 -48
  142. package/scripts/hooks/validate-post-conditions.sh +0 -21
  143. package/scripts/hooks/validate-talos-scope.sh +0 -50
  144. package/scripts/hooks/validate-tool-safety.sh +0 -49
  145. package/src/pantheon/goal-loop.ts +0 -314
  146. package/src/pantheon/idle-continuation.ts +0 -52
  147. package/src/pantheon/todo-preserve.ts +0 -301
  148. package/src/pantheon/tool-ceiling.ts +0 -159
  149. package/src/pantheon/v2-bridge.ts +0 -153
  150. package/src/plugin-v2.ts +0 -2954
  151. package/src/plugins/pantheon-hooks.ts +0 -1433
  152. package/src/plugins/tui/dist/server-v2.d.ts +0 -30
  153. package/src/plugins/tui/dist/server-v2.d.ts.map +0 -1
  154. package/src/plugins/tui/dist/server-v2.js +0 -33
  155. package/src/plugins/tui/dist/server-v2.js.map +0 -1
  156. package/src/plugins/tui/dist/tui-v2.d.ts +0 -1039
  157. package/src/plugins/tui/dist/tui-v2.d.ts.map +0 -1
  158. package/src/plugins/tui/dist/tui-v2.js +0 -4597
  159. package/src/plugins/tui/dist/tui-v2.js.map +0 -1
  160. package/src/plugins/tui/src/index-v2.tsx +0 -4496
  161. package/src/plugins/tui/src/server-v2.ts +0 -28
  162. package/src/plugins/tui/tui-v2.ts +0 -2
  163. /package/src/pantheon/{v2-decision-budget.ts → decision-budget.ts} +0 -0
  164. /package/src/pantheon/{v2-decision-egress.ts → decision-egress.ts} +0 -0
  165. /package/src/pantheon/{v2-decision-events.ts → decision-events.ts} +0 -0
  166. /package/src/pantheon/{v2-decision-heuristic.ts → decision-heuristic.ts} +0 -0
  167. /package/src/pantheon/{v2-decision-premises.ts → decision-premises.ts} +0 -0
  168. /package/src/pantheon/{v2-decision-rank.ts → decision-rank.ts} +0 -0
  169. /package/src/pantheon/{v2-decision-verify.ts → decision-verify.ts} +0 -0
  170. /package/src/pantheon/{v2-delegation-enforce.ts → delegation-policy.ts} +0 -0
  171. /package/src/pantheon/{v2-model-overrides.ts → model-overrides.ts} +0 -0
  172. /package/src/pantheon/{v2-native-decisions.ts → native-decisions.ts} +0 -0
  173. /package/src/plugins/tui/src/{opencode-v2.d.ts → opencode.d.ts} +0 -0
@@ -74,13 +74,15 @@ const IMAGE_URI_PATTERN = /\.(?:png|jpe?g|webp|gif)(?:[?#].*)?$/i
74
74
  */
75
75
  function imageReference(uri: string, mime: string, name: string): string {
76
76
  if (!/^data:image\//i.test(uri)) {
77
- return `${JSON.stringify(name)} em ${JSON.stringify(uri)}`
77
+ return `${JSON.stringify(name)} at ${JSON.stringify(uri)}`
78
78
  }
79
79
  const path = saveDataUrlImageSync(uri, mime)
80
80
  if (path) {
81
- return `${JSON.stringify(name)} em ${JSON.stringify(path)} (anexo inline materializado em arquivo temporário local; use este caminho — o payload não é repetido no texto)`
81
+ // The payload is never repeated in text; the materialized temp path is
82
+ // the reference (and is swept with the session's temp files).
83
+ return `${JSON.stringify(name)} at ${JSON.stringify(path)}`
82
84
  }
83
- return `${JSON.stringify(name)} (conteúdo anexado; URI codificada omitida)`
85
+ return `${JSON.stringify(name)} (inline attachment; data URI omitted)`
84
86
  }
85
87
 
86
88
  /**
@@ -128,28 +130,23 @@ export function buildV2VisionPromptContext(
128
130
  return [reference]
129
131
  })
130
132
  if (images.length === 0) return undefined
131
- const lines = [
132
- '<!-- pantheon-v2-visual-context -->',
133
- '[Contexto visual do Pantheon]',
134
- `O usuário anexou imagem(ns):\n${images.map((image) => `- ${image}`).join('\n')}`,
135
- 'Se a imagem orientar uma implementação, inspecione-a com vision_describe ou visão nativa antes de delegar. Inclua a referência e observações visuais relevantes no handoff para @aphrodite. Preserve alterações existentes fora do escopo: a imagem não autoriza apagar nem reverter trabalho; se a substituição for necessária e não estiver explícita, pergunte antes.',
136
- ]
133
+ // Under-the-hood contract (user feedback, 2.0 cycle): the block is a
134
+ // minimal relay, not an essay — inspect silently, route UI work to
135
+ // @aphrodite, never revert based on an image.
136
+ const lines = ['<!-- pantheon-v2-visual-context -->', `[Visual] ${images.join(' | ')}`]
137
137
  const question = truncateUserText(userText ?? '')
138
138
  if (question) {
139
139
  // JSON.stringify quotes/escapes the question so it cannot spoof the
140
140
  // surrounding instruction layout; the value is never re-expanded and
141
141
  // never logged.
142
- lines.push(
143
- `Pergunta do usuário neste turno: ${JSON.stringify(question)} — ao inspecionar com vision_describe, repasse essa pergunta no parâmetro \`prompt\` da ferramenta para uma análise direcionada.`,
144
- )
142
+ lines.push(`User turn: ${JSON.stringify(question)}`)
145
143
  }
146
144
  // MCP session relay (see the doc comment above): JSON.stringify quotes the
147
145
  // id so it cannot spoof the surrounding instruction layout; never logged.
148
146
  if (isValidSessionId(sessionID)) {
149
- lines.push(
150
- `Prefira a ferramenta nativa \`vision_describe\` (ela já repassa a sessão automaticamente). Se usar o MCP pantheon-vision (\`vision_describe\`/\`vision_ocr\`/\`vision_analyze\`), repasse session_id=${JSON.stringify(sessionID)} no parâmetro \`session_id\` — sem ele o gateway Zen rejeita a chamada com MissingSessionID.`,
151
- )
147
+ lines.push(`MCP relay: session_id=${JSON.stringify(sessionID)}`)
152
148
  }
149
+ lines.push('UI handoff -> @aphrodite; an image never authorizes a revert.')
153
150
  return lines.join('\n')
154
151
  }
155
152
 
@@ -13,6 +13,10 @@ export interface DecisionCatalogEntry {
13
13
 
14
14
  export const PANTHEON_SKILL_CATALOG: readonly DecisionCatalogEntry[] = Object.freeze([
15
15
  { id: 'agent-coordination', description: 'Multi-agent orchestration, routing, and delegation.' },
16
+ {
17
+ id: 'agent-forge',
18
+ description: 'Forge a new OpenCode agent on demand — interview, draft, confirm.',
19
+ },
16
20
  { id: 'artifact-management', description: 'Structured artifacts for planned or risky work.' },
17
21
  { id: 'auto-continue', description: 'Continue multi-step todos while keeping safety gates.' },
18
22
  { id: 'clonedeps', description: 'Clone dependency source locally for inspection.' },
@@ -21,6 +25,10 @@ export const PANTHEON_SKILL_CATALOG: readonly DecisionCatalogEntry[] = Object.fr
21
25
  { id: 'context-compression', description: 'Explicit compaction and resumable checkpoints.' },
22
26
  { id: 'git-workflow-and-versioning', description: 'Atomic commits and versioning workflow.' },
23
27
  { id: 'incremental-implementation', description: 'Thin, testable, rollback-safe slices.' },
28
+ {
29
+ id: 'instruction-forge',
30
+ description: 'Write and maintain instructions — one home per rule, tested triggers.',
31
+ },
24
32
  { id: 'loop-engineering', description: 'Controlled iterative refinement cycles.' },
25
33
  { id: 'memory-bank', description: 'Memory-bank structure, rules, and maintenance.' },
26
34
  { id: 'reflect', description: 'Turn repeated workflow friction into reusable assets.' },
@@ -35,6 +43,10 @@ export const PANTHEON_SKILL_CATALOG: readonly DecisionCatalogEntry[] = Object.fr
35
43
  id: 'tdd-with-agents',
36
44
  description: 'RED, GREEN, REFACTOR test-driven implementation.',
37
45
  },
46
+ {
47
+ id: 'prompt-refinery',
48
+ description: 'Refine a vague multi-concern request — silent adjust, >> full contract.',
49
+ },
38
50
  { id: 'verification-planning', description: 'Plan the evidence path before changing code.' },
39
51
  {
40
52
  id: 'visual-review-pipeline',
@@ -10,7 +10,7 @@
10
10
  * `delegations.log` audit records (start/stop joined on `delegation_id`).
11
11
  *
12
12
  * `pantheon-hooks.ts` is a SEPARATE plugin and is never loaded on a V2-only
13
- * install — `opencode.json` `plugins` declares only `src/plugin-v2` — so both
13
+ * install — `opencode.json` `plugins` declares only `src/plugin` — so both
14
14
  * were dead on V2. The scripts themselves are environment-independent (they
15
15
  * read the Claude Code payload from stdin and write their own log files), so
16
16
  * they are run through the same `runHook` runner the secret scan already uses;
@@ -33,7 +33,7 @@
33
33
  * or a malformed payload can never break the tool call it observes. The audit
34
34
  * trail is telemetry; the security decisions live in the guards, not here.
35
35
  *
36
- * @module v2-shell-hooks
36
+ * @module shell-hooks
37
37
  */
38
38
 
39
39
  import { randomUUID } from 'node:crypto'
@@ -43,14 +43,14 @@ import {
43
43
  delegationStartLine,
44
44
  delegationStopLine,
45
45
  formatterApplies,
46
- } from './v2-hook-engine.ts'
46
+ } from './hook-engine.ts'
47
47
 
48
48
  /**
49
49
  * Delegation tool names. MIRRORS `DELEGATION_TOOL_RE` in
50
50
  * `src/plugins/pantheon-hooks.ts` (V1). Duplicated rather than imported: that
51
51
  * module is the V1 plugin, not loaded on a V2-only install, and importing it
52
52
  * for one regex would resurrect the V1 coupling V2 exists to remove. The drift
53
- * risk is asserted by tests/pantheon/v2-shell-hooks.test.ts.
53
+ * risk is asserted by tests/pantheon/shell-hooks.test.ts.
54
54
  */
55
55
  export const V2_DELEGATION_TOOL_RE = /^(task|.*subagent.*)$/i
56
56
 
@@ -12,7 +12,7 @@
12
12
  * They are therefore absent from this surface rather than registered as
13
13
  * placeholders that resolve to a message — a placeholder still fails the host's
14
14
  * output contract on every call, so it buys nothing. See
15
- * `V2_UNSUPPORTED_FEATURES` in `../plugin-v2.ts` (marker `goal-tools`).
15
+ * `V2_UNSUPPORTED_FEATURES` in `../plugin.ts` (marker `goal-tools`).
16
16
  *
17
17
  * `hashline_edit` (pure filesystem), `pantheon_cost` (reads `opencode.db`),
18
18
  * `pantheon_model` (reads/writes `active-preset.json`), and the local-only
@@ -43,17 +43,17 @@
43
43
  * must move together. `V2ToolDef` makes the field required so TypeScript
44
44
  * rejects a tool that forgets it.
45
45
  *
46
- * @module pantheon/v2-tools
46
+ * @module pantheon/tools
47
47
  */
48
48
 
49
49
  import { createCostCommand } from './cost-command.ts'
50
+ import type { ShadowSink } from './decision-shadow.ts'
50
51
  import { createHashlineEditTool, type HashlineToolResult } from './hashline/tool.ts'
51
52
  import { createV2JevDecisionDefinition, type V2JevDecisionRuntime } from './jev-decision-tool.ts'
52
53
  import { createV2LocalDecisionDefinition } from './local-decision-tool.ts'
53
54
  import { createModelCommand } from './model-command.ts'
55
+ import { createV2VisionTool, type V2VisionRuntime } from './native-vision.ts'
54
56
  import type { ToolContextLike } from './tool-context.ts'
55
- import type { ShadowSink } from './v2-decision-shadow.ts'
56
- import { createV2VisionTool, type V2VisionRuntime } from './v2-vision.ts'
57
57
 
58
58
  // ─── Contract types ─────────────────────────────────────────────────────
59
59
 
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Type declarations for v2-unsupported.mjs (the V2 feature-reduction seed).
3
- * Consumed by src/plugin-v2.ts via `import ... from './pantheon/v2-unsupported.mjs'`,
2
+ * Type declarations for unsupported.mjs (the V2 feature-reduction seed).
3
+ * Consumed by src/plugin.ts via `import ... from './pantheon/unsupported.mjs'`,
4
4
  * and by the plain-`.mjs` install/health scripts at runtime.
5
5
  */
6
6
 
7
7
  /** Statically-known V2 feature reductions, in report order. */
8
- export declare const V2_UNSUPPORTED_FEATURE_SEED: readonly string[]
8
+ export declare const UNSUPPORTED_FEATURE_SEED: readonly string[]
9
9
 
10
10
  /** A fresh, mutable copy of the seed, so a reporter cannot mutate the shared list. */
11
11
  export declare function listV2UnsupportedFeatures(): string[]
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * v2-unsupported.mjs — the SEED of V2 feature reductions, in plain ESM.
3
+ * unsupported.mjs — the SEED of V2 feature reductions, in plain ESM.
4
4
  *
5
5
  * WHY A SEPARATE PLAIN-`.mjs` MODULE: these strings must be readable by three
6
6
  * very different consumers, and only one of them can import TypeScript.
7
7
  *
8
- * - `src/plugin-v2.ts` (TypeScript) — owns the LIVE list, appending to it at
8
+ * - `src/plugin.ts` (TypeScript) — owns the LIVE list, appending to it at
9
9
  * runtime via `markUnsupported()` when a host API turns out to be missing,
10
10
  * and exposes it through `getUnsupportedFeatures()`.
11
11
  * - `scripts/install/opencode.mjs` — reports the reduction at install time
@@ -17,7 +17,7 @@
17
17
  * devDependency only, and no plain-Node script in `scripts/` or `bin/` imports
18
18
  * a `.ts` module — every `.ts` path there is a string to copy, stat or read as
19
19
  * text (`scripts/install/opencode.mjs`, `scripts/probe-pantheon-cost.mjs`,
20
- * `scripts/package-evidence.mjs`, `scripts/check-plugin-v2-coverage.mjs`).
20
+ * `scripts/package-evidence.mjs`, `scripts/check-plugin-coverage.mjs`).
21
21
  * So a `.mjs` import is the only form all three consumers can share, and it
22
22
  * matches the existing `src/pantheon/presets.mjs` + `.d.mts` precedent.
23
23
  *
@@ -41,21 +41,21 @@
41
41
  * two are expected to differ there. Do not copy these strings into a script;
42
42
  * import them.
43
43
  *
44
- * @module v2-unsupported
44
+ * @module unsupported
45
45
  */
46
46
 
47
47
  /**
48
48
  * Statically-known V2 feature reductions, in the order a reader should meet
49
- * them. Frozen: `plugin-v2.ts` copies it into its own mutable live array, and
49
+ * them. Frozen: `plugin.ts` copies it into its own mutable live array, and
50
50
  * every other consumer goes through {@link listV2UnsupportedFeatures}.
51
51
  *
52
52
  * @type {readonly string[]}
53
53
  */
54
- export const V2_UNSUPPORTED_FEATURE_SEED = Object.freeze([
54
+ export const UNSUPPORTED_FEATURE_SEED = Object.freeze([
55
55
  'legacy-hooks',
56
56
  // `ctx.catalog` is the one domain a live 2.0.22 host does NOT have: it is
57
57
  // absent from `Object.keys(ctx)`, measured in
58
- // tests/canary/plugin-v2-tool-canary.test.mjs. (`catalog` IS in the 1.18.33
58
+ // tests/canary/plugin-tool-canary.test.mjs. (`catalog` IS in the 1.18.33
59
59
  // SDK's PluginContext, so the SDK types it and the host does not provide it.)
60
60
  'catalog-transform',
61
61
  // Adapter support, NOT host availability: 2.0.22 exposes ctx.integration and
@@ -113,5 +113,5 @@ export const V2_UNSUPPORTED_FEATURE_SEED = Object.freeze([
113
113
  * @returns {string[]}
114
114
  */
115
115
  export function listV2UnsupportedFeatures() {
116
- return [...V2_UNSUPPORTED_FEATURE_SEED]
116
+ return [...UNSUPPORTED_FEATURE_SEED]
117
117
  }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Update notifier — pin + notify, never silent auto-update.
3
+ *
4
+ * Pure decision core: given the installed version, the registry's latest for
5
+ * the installed channel, and the persisted notification state, decide whether
6
+ * a notice should surface (TTL-cached, once per notified version) and what it
7
+ * says. The network call is injectable; offline always means silent.
8
+ *
9
+ * Doctrine (2.0 design, docs/design/2.0-settings-and-install.md): pin by
10
+ * default, one aggregate notice per version, adoption via
11
+ * `pantheon-opencode update` — the stable line never advertises a beta.
12
+ */
13
+
14
+ export const UPDATE_CHECK_TTL_MS = 6 * 60 * 60 * 1000
15
+
16
+ export interface UpdateCheckState {
17
+ /** Last version a notice was surfaced for (no repeats per version). */
18
+ lastNotifiedVersion?: string
19
+ /** Last time the registry was queried, for the TTL. */
20
+ lastCheckMs?: number
21
+ }
22
+
23
+ export interface UpdateNoticeInput {
24
+ currentVersion: string
25
+ latestVersion: string
26
+ state?: UpdateCheckState
27
+ nowMs?: number
28
+ ttlMs?: number
29
+ }
30
+
31
+ export interface UpdateNotice {
32
+ version: string
33
+ message: string
34
+ }
35
+
36
+ /** Semver-ish compare for X.Y.Z[-beta.N]; betas sort before their release. */
37
+ export function comparePantheonVersions(left: string, right: string): number {
38
+ const parse = (version: string) => {
39
+ const match = String(version)
40
+ .trim()
41
+ .match(/^(\d+)\.(\d+)\.(\d+)(?:-beta\.(\d+))?$/)
42
+ if (!match) return null
43
+ if (match[1] === undefined || match[2] === undefined || match[3] === undefined) {
44
+ return null
45
+ }
46
+ return {
47
+ core: [Number(match[1]), Number(match[2]), Number(match[3])],
48
+ beta: match[4] === undefined ? Number.POSITIVE_INFINITY : +match[4],
49
+ }
50
+ }
51
+ const a = parse(left)
52
+ const b = parse(right)
53
+ if (!a || !b) return 0
54
+ for (let index = 0; index < 3; index += 1) {
55
+ const left = a.core[index] ?? 0
56
+ const right = b.core[index] ?? 0
57
+ if (left !== right) return left - right
58
+ }
59
+ return a.beta - b.beta
60
+ }
61
+
62
+ /**
63
+ * The update decision: a notice fires when the registry version is NEWER than
64
+ * the installed one, the installed line is the same channel family the
65
+ * registry serves (a stable install is never advertised a beta — the update
66
+ * guard owns that crossing), and the TTL since the last check has elapsed.
67
+ */
68
+ export function pickUpdateNotice(input: UpdateNoticeInput): UpdateNotice | null {
69
+ const { currentVersion, latestVersion, state = {}, nowMs = Date.now() } = input
70
+ const ttlMs = input.ttlMs ?? UPDATE_CHECK_TTL_MS
71
+
72
+ const lastCheck = state.lastCheckMs ?? 0
73
+ if (nowMs - lastCheck < ttlMs) return null
74
+ if (state.lastNotifiedVersion === latestVersion) return null
75
+
76
+ const stable = (version: string) => !/-beta\.\d+$/.test(version)
77
+ // A stable install is never advertised a beta: the update guard owns that
78
+ // crossing and requires explicit opt-in there.
79
+ if (stable(currentVersion) && !stable(latestVersion)) return null
80
+
81
+ if (comparePantheonVersions(latestVersion, currentVersion) <= 0) return null
82
+
83
+ return {
84
+ version: latestVersion,
85
+ message:
86
+ `pantheon-opencode ${latestVersion} available (installed ${currentVersion}) — ` +
87
+ 'changelog in /pantheon-settings, adopt with `pantheon-opencode update`',
88
+ }
89
+ }
90
+
91
+ /** The state to persist after a check (notified or not) for the TTL. */
92
+ export function nextCheckState(
93
+ previous: UpdateCheckState,
94
+ notice: UpdateNotice | null,
95
+ nowMs: number,
96
+ ): UpdateCheckState {
97
+ const next: UpdateCheckState = { lastCheckMs: nowMs }
98
+ const carried = notice?.version ?? previous.lastNotifiedVersion
99
+ if (carried !== undefined) next.lastNotifiedVersion = carried
100
+ return next
101
+ }
@@ -416,9 +416,18 @@ function formatFromMime(mime: string | null): LocalImageFormat {
416
416
  }
417
417
 
418
418
  function mimeFromUrl(source: string): string | null {
419
- const match = /\.([a-z0-9]+)(?:[?#].*)?$/i.exec(source)
420
- if (!match) return null
421
- const extension = (match[1] ?? '').toLowerCase()
419
+ // Linear by construction: no regex backtracking over attacker-controlled
420
+ // strings (CodeQL js/polynomial-redos) — split on the first ? or #, then
421
+ // take the last dot of the remaining path.
422
+ const fragmentIndex = Math.min(
423
+ ...['?', '#'].map((ch) => source.indexOf(ch)).filter((index) => index >= 0),
424
+ source.length,
425
+ )
426
+ const path = source.slice(0, fragmentIndex)
427
+ const dotIndex = path.lastIndexOf('.')
428
+ if (dotIndex < 0) return null
429
+ const extension = path.slice(dotIndex + 1).toLowerCase()
430
+ if (!/^[a-z0-9]+$/.test(extension)) return null
422
431
  if (extension === 'png') return 'image/png'
423
432
  if (extension === 'jpg' || extension === 'jpeg') return 'image/jpeg'
424
433
  if (extension === 'gif') return 'image/gif'
@@ -3,8 +3,10 @@ import {
3
3
  chmodSync,
4
4
  existsSync,
5
5
  mkdirSync,
6
+ readdirSync,
6
7
  readFileSync,
7
8
  renameSync,
9
+ statSync,
8
10
  unlinkSync,
9
11
  writeFileSync,
10
12
  } from 'node:fs'
@@ -613,7 +615,7 @@ export async function fetchProvidersCatalog(
613
615
  function defaultAuthStateDir(): string {
614
616
  // Honor XDG_DATA_HOME so a relocated data root resolves the same auth store
615
617
  // (auth.json) and V2 credential db (opencode.db) as the plugin and the MCP.
616
- // Mirrors v2-vision.ts; OPENCODE_DB still names the exact db file.
618
+ // Mirrors native-vision.ts; OPENCODE_DB still names the exact db file.
617
619
  const dataHome = process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share')
618
620
  return join(dataHome, 'opencode')
619
621
  }
@@ -989,6 +991,114 @@ export async function enforceTempFileCap(
989
991
  return evicted
990
992
  }
991
993
 
994
+ // ─── Temp-dir reconciliation (restart orphans) ────────────────────────────
995
+ // The LRU registry is process memory: after a host restart it starts EMPTY,
996
+ // so `enforceTempFileCap` cannot see — and can never evict — the content-hash
997
+ // images a previous process left on disk (the V2 path has no session threading
998
+ // to sweep them; see the deferred-idle note in plugin.ts). Reconciliation
999
+ // makes those orphans VISIBLE again without inventing a new deletion policy:
1000
+ // adoption only adds registry entries, and eviction still goes through the
1001
+ // existing cap + grace. The one provably-safe unlink is a stray
1002
+ // `<hash>.<ext>.tmp-<pid>` from `writeFileAtomicSync` — crash detritus that is
1003
+ // never a valid file — still age-guarded so a concurrent write in ANOTHER live
1004
+ // process survives. The directory itself is still never blanket-removed.
1005
+
1006
+ /** Filename shape written by `writeTempImageSync` (sha256 hex + known ext). */
1007
+ const TEMP_IMAGE_NAME = /^[0-9a-f]{64}\.(?:png|jpe?g|webp|gif)$/
1008
+
1009
+ /** Crash stray from `writeFileAtomicSync`: `<hash>.<ext>.tmp-<pid>`. */
1010
+ const TEMP_STRAY_NAME = /^[0-9a-f]{64}\.(?:png|jpe?g|webp|gif)\.tmp-\d+$/
1011
+
1012
+ function defaultTempDir(): string {
1013
+ return join(tmpdir(), TEMP_DIR_NAME)
1014
+ }
1015
+
1016
+ /**
1017
+ * Register on-disk content-hash images from previous processes into the LRU,
1018
+ * keyed by their on-disk mtime as recency — so the OLDEST file is inserted
1019
+ * FIRST (insertion order = eviction order) and the next cap enforcement
1020
+ * evicts restart orphans before files this process actually touched. Entries
1021
+ * already in the registry are never clobbered: a live entry keeps the recency
1022
+ * this process gave it regardless of how old the file looks on disk.
1023
+ * Returns how many files were adopted. Never throws.
1024
+ */
1025
+ export function adoptOrphanTempImages(
1026
+ dir: string = defaultTempDir(),
1027
+ now: number = Date.now(),
1028
+ ): number {
1029
+ let names: string[]
1030
+ try {
1031
+ names = readdirSync(dir)
1032
+ } catch {
1033
+ return 0 // dir absent — nothing to adopt
1034
+ }
1035
+ const candidates: { path: string; mtimeMs: number }[] = []
1036
+ for (const name of names) {
1037
+ if (!TEMP_IMAGE_NAME.test(name)) continue
1038
+ const path = join(dir, name)
1039
+ if (tempFileLRU.has(path)) continue
1040
+ try {
1041
+ candidates.push({ path, mtimeMs: statSync(path).mtimeMs })
1042
+ } catch {
1043
+ // Vanished between readdir and stat — nothing to adopt.
1044
+ }
1045
+ }
1046
+ candidates.sort((a, b) => a.mtimeMs - b.mtimeMs)
1047
+ for (const { path, mtimeMs } of candidates) {
1048
+ tempFileLRU.set(path, Math.min(mtimeMs, now))
1049
+ }
1050
+ return candidates.length
1051
+ }
1052
+
1053
+ /**
1054
+ * Unlink crash strays (`<hash>.<ext>.tmp-<pid>`) older than `graceMs`. A
1055
+ * young stray belongs to a write in flight — possibly in ANOTHER live
1056
+ * process — so age is the only safe signal. Real content-hash images are
1057
+ * never touched. Returns how many strays were unlinked. Never throws.
1058
+ */
1059
+ export function sweepStrayTempWrites(
1060
+ dir: string = defaultTempDir(),
1061
+ now: number = Date.now(),
1062
+ graceMs: number = TEMP_FILE_GRACE_MS,
1063
+ ): number {
1064
+ let names: string[]
1065
+ try {
1066
+ names = readdirSync(dir)
1067
+ } catch {
1068
+ return 0
1069
+ }
1070
+ let swept = 0
1071
+ for (const name of names) {
1072
+ if (!TEMP_STRAY_NAME.test(name)) continue
1073
+ const path = join(dir, name)
1074
+ try {
1075
+ if (now - statSync(path).mtimeMs <= graceMs) continue
1076
+ unlinkSync(path)
1077
+ swept += 1
1078
+ } catch {
1079
+ // Best effort: vanished concurrently, or unlink refused — leave it.
1080
+ }
1081
+ }
1082
+ return swept
1083
+ }
1084
+
1085
+ /** Dirs already reconciled this process (one pass per dir, then no-op). */
1086
+ const reconciledDirs = new Set<string>()
1087
+
1088
+ /**
1089
+ * Run adoption + stray sweep once per directory per process. Called off the
1090
+ * first temp write so a restarted host re-bounds its temp dir without a
1091
+ * startup hook; every pass is read/stat/unlink on one small directory.
1092
+ */
1093
+ export function reconcileTempImagesOnce(dir: string = defaultTempDir()): {
1094
+ adopted: number
1095
+ swept: number
1096
+ } {
1097
+ if (reconciledDirs.has(dir)) return { adopted: 0, swept: 0 }
1098
+ reconciledDirs.add(dir)
1099
+ return { adopted: adoptOrphanTempImages(dir), swept: sweepStrayTempWrites(dir) }
1100
+ }
1101
+
992
1102
  /**
993
1103
  * Decode a base64 image data URI to its bytes. The regex accepts OPTIONAL
994
1104
  * parameters between the mime type and the `;base64` marker (e.g.
@@ -1050,6 +1160,14 @@ function fileHasContent(filePath: string, data: Buffer): boolean {
1050
1160
  * regardless of a permissive umask; the bytes are never logged.
1051
1161
  */
1052
1162
  export function writeTempImageSync(data: Buffer, mime: string): string {
1163
+ // First write this process makes: adopt previous-process orphans into the
1164
+ // LRU and sweep crash strays, so the disk cap keeps its meaning across a
1165
+ // restart. Best-effort — the write itself must never be blocked by it.
1166
+ try {
1167
+ reconcileTempImagesOnce()
1168
+ } catch {
1169
+ // Fail-open.
1170
+ }
1053
1171
  const dir = join(tmpdir(), TEMP_DIR_NAME)
1054
1172
  mkdirSync(dir, { recursive: true, mode: 0o700 })
1055
1173
  chmodSync(dir, 0o700)
@@ -1606,7 +1724,7 @@ function unescapeXml(text: string): string {
1606
1724
  * Payload bound for the user's question interpolated into vision prompts:
1607
1725
  * prompts longer than this are clipped (with an ellipsis marker) so a long
1608
1726
  * turn never bloats the gateway request. Exported because the V2 path
1609
- * (v2-vision.ts) applies the same cap to its own describe prompt.
1727
+ * (native-vision.ts) applies the same cap to its own describe prompt.
1610
1728
  */
1611
1729
  export const MAX_PROMPT_USER_TEXT_CHARS = 2000
1612
1730
 
@@ -5,17 +5,17 @@
5
5
  * the beta only accepts `plugins` entries that are DIRECTORIES containing a
6
6
  * real index.js/index.ts — a file path warns "must be a directory" and a
7
7
  * symlink is ignored. The installer therefore registers this directory
8
- * (`<pkg>/src/plugin-v2`), never the `src/plugin-v2.ts` file directly.
8
+ * (`<pkg>/src/plugin`), never the `src/plugin.ts` file directly.
9
9
  *
10
10
  * This index is a thin re-export shim over the real entry at
11
- * `src/plugin-v2.ts` (kept as the single source of truth so the
12
- * `./plugin-v2` package export, unit tests, and V1 tooling keep working
11
+ * `src/plugin.ts` (kept as the single source of truth so the
12
+ * `./plugin` package export, unit tests, and V1 tooling keep working
13
13
  * unchanged). The shim shape mirrors the verified probe:
14
- * `export { default } from '<installed>/src/plugin-v2.ts'` loads with zero
14
+ * `export { default } from '<installed>/src/plugin.ts'` loads with zero
15
15
  * errors and exposes the full orchestration plugin (tools, events, hooks).
16
16
  *
17
- * @module plugin-v2/index
17
+ * @module plugin/index
18
18
  */
19
19
 
20
- export * from '../plugin-v2.ts'
21
- export { default } from '../plugin-v2.ts'
20
+ export * from '../plugin.ts'
21
+ export { default } from '../plugin.ts'