pantheon-opencode 1.6.3-beta.6 → 1.7.0-beta.1

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 (69) hide show
  1. package/AGENTS.global.md +1 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +201 -0
  4. package/README.md +16 -2
  5. package/README.pt-BR.md +1 -1
  6. package/bin/pantheon-init.mjs +46 -28
  7. package/package.json +2 -2
  8. package/plugin.json +2 -2
  9. package/pyproject.toml +1 -1
  10. package/scripts/decision-router-budget.mjs +102 -2
  11. package/scripts/decision-router-v2-budget.mjs +2 -2
  12. package/scripts/decision-router.mjs +82 -25
  13. package/scripts/doctor.mjs +4 -1
  14. package/scripts/install/cli-ui.mjs +2 -1
  15. package/scripts/install/decision-router-config.mjs +12 -4
  16. package/scripts/install/interactive.mjs +45 -28
  17. package/scripts/install/opencode.mjs +151 -30
  18. package/scripts/jev-live-probe.mjs +212 -0
  19. package/scripts/skill-search.mjs +273 -0
  20. package/skills-lock.json +3 -1
  21. package/src/agents/aphrodite.md +34 -1
  22. package/src/agents/apollo.md +227 -0
  23. package/src/agents/athena.md +26 -0
  24. package/src/agents/demeter.md +33 -0
  25. package/src/agents/gaia.md +24 -0
  26. package/src/agents/hephaestus.md +24 -0
  27. package/src/agents/hermes.md +33 -0
  28. package/src/agents/iris.md +24 -0
  29. package/src/agents/mnemosyne.md +25 -3
  30. package/src/agents/nyx.md +50 -22
  31. package/src/agents/prometheus.md +242 -1
  32. package/src/agents/talos.md +24 -0
  33. package/src/agents/themis.md +24 -0
  34. package/src/agents/zeus.md +81 -6
  35. package/src/pantheon/j1-approvals.ts +123 -0
  36. package/src/pantheon/jev-decision-tool.ts +293 -35
  37. package/src/pantheon/jev-decisions.ts +95 -12
  38. package/src/pantheon/jev-escalation.ts +1 -1
  39. package/src/pantheon/jev-quality-score.ts +45 -10
  40. package/src/pantheon/jev-rank-verify.ts +665 -0
  41. package/src/pantheon/jev-risk-gate.ts +82 -12
  42. package/src/pantheon/local-decision-budget.ts +169 -2
  43. package/src/pantheon/local-decision-prompt.ts +2 -0
  44. package/src/pantheon/local-decision-router.ts +16 -0
  45. package/src/pantheon/local-decision-turn.ts +110 -4
  46. package/src/pantheon/local-decision-usage-evidence.internal.ts +2 -2
  47. package/src/pantheon/pantheon-decision-catalog.ts +9 -2
  48. package/src/pantheon/v2-decision-budget.ts +4 -2
  49. package/src/pantheon/v2-tools.ts +42 -0
  50. package/src/plugin-v2.ts +85 -5
  51. package/src/plugins/tui/dist/server-v2.d.ts +14 -6
  52. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
  53. package/src/plugins/tui/dist/server-v2.js +16 -9
  54. package/src/plugins/tui/dist/server-v2.js.map +1 -1
  55. package/src/plugins/tui/dist/tui-v2.js +128 -25
  56. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  57. package/src/plugins/tui/dist/tui.js +1 -1
  58. package/src/plugins/tui/package-lock.json +2 -2
  59. package/src/plugins/tui/package.json +1 -1
  60. package/src/plugins/tui/src/server-v2.ts +14 -7
  61. package/src/plugins/tui/src/whats-new-highlights.ts +59 -5
  62. package/src/plugins/tui/src/whats-new-open.ts +41 -1
  63. package/src/plugins/tui/src/whats-new.tsx +61 -8
  64. package/src/routing.yml +2 -0
  65. package/src/skills/README.md +1 -1
  66. package/src/skills/agent-forge/SKILL.md +76 -0
  67. package/src/skills/auto-continue/SKILL.md +12 -163
  68. package/src/skills/auto-continue/references/auto-continue-details.md +175 -0
  69. package/src/skills/prompt-refinery/SKILL.md +60 -0
@@ -1 +1 @@
1
- {"version":3,"file":"tui-v2.js","names":["numberOrNull"],"sources":["../src/context-gauge.ts","../src/model-usage-limits.ts","../src/sidebar-width.ts","../src/whats-new-highlights.ts","../src/whats-new-state.ts","../src/whats-new-open.ts"],"sourcesContent":["/** Shared, data-only formatting and visual helpers for compact context gauges. */\n\nexport type ContextProgressTone = 'info' | 'success' | 'warning' | 'error'\n\nexport const CONTEXT_BAR_CELLS = 12\nexport const CONTEXT_BAR_FILLED_CELL = '\\u25B0'\nexport const CONTEXT_BAR_EMPTY_CELL = '\\u25B1'\n\nfunction numberOrNull(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\nexport function contextUsageTone(percent: number): ContextProgressTone {\n if (percent > 90) return 'error'\n if (percent > 50) return 'warning'\n if (percent > 25) return 'success'\n return 'info'\n}\n\nexport function formatTokenCount(tokens: number | null | undefined): string | null {\n const value = numberOrNull(tokens)\n if (value === null || value < 0) return null\n return Math.round(value).toLocaleString('en-US')\n}\n\nexport function formatContextWindow(limit: number | null | undefined): string | null {\n const value = numberOrNull(limit)\n if (value === null || value <= 0) return null\n if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`\n if (value >= 1_000) return `${Math.floor(value / 1_000)}K`\n return `${Math.floor(value)}`\n}\n\nexport function contextBarFilled(percent: number, cells = CONTEXT_BAR_CELLS): number {\n const total = Math.max(1, Math.floor(cells))\n const filled = Math.round((percent / 100) * total)\n if (!Number.isFinite(filled)) return 0\n return Math.min(total, Math.max(0, filled))\n}\n\nexport function contextBar(\n percent: number | null | undefined,\n cells = CONTEXT_BAR_CELLS,\n): { filled: string; empty: string } | null {\n const value = numberOrNull(percent)\n if (value === null) return null\n const total = Math.max(1, Math.floor(cells))\n const filled = contextBarFilled(value, total)\n return {\n filled: CONTEXT_BAR_FILLED_CELL.repeat(filled),\n empty: CONTEXT_BAR_EMPTY_CELL.repeat(total - filled),\n }\n}\n\nexport function formatSpent(cost: number | null | undefined): string | null {\n const value = numberOrNull(cost)\n if (value === null || value < 0) return null\n return `$${value.toFixed(2)}`\n}\n","/** Shared bounds for cached recent model-usage aggregation. */\nexport const MODEL_USAGE_VISIBLE_CEILING = 3\nexport const MODEL_USAGE_MESSAGE_LIMIT = 400\nexport const MODEL_USAGE_SESSION_LIMIT = 8\n","/** Conservative content budget; the host sidebar slot does not report its runtime width. */\nexport const SIDEBAR_CONTENT_WIDTH = 34\n\nexport const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n\n/** A grapheme the host draws two cells wide: emoji presentation, an extended\n * pictograph (a bare `❤` counts too, exactly as the host's `emoji-regex`\n * does) and a regional-indicator pair (a flag). */\nconst EMOJI_GLYPH = /\\p{Emoji_Presentation}|\\p{Extended_Pictographic}|\\p{Regional_Indicator}/u\n/** VS16 asks for emoji presentation; without it `1` is one cell, with it the\n * keycap sequence is drawn as one two-cell glyph. */\nconst EMOJI_PRESENTATION_SELECTOR = '\\uFE0F'\n/** Unicode default-ignorable code points carry no width of their own. */\nconst IGNORABLE_GLYPH = /^\\p{Default_Ignorable_Code_Point}$/u\n/** East Asian Wide/Fullwidth ranges — two cells, never the ambiguous width\n * (the host measures ambiguous as narrow, so `▸`/`✓`/`—` stay one cell).\n * Generated from the host's own measurement (`string-width` over every code\n * point, emoji excluded), so this table can be regenerated verbatim when the\n * host upgrades its Unicode data instead of being hand-edited. */\nconst CELL_WIDE_RANGES: readonly (readonly [number, number])[] = [\n [0x1100, 0x115e],\n [0x2329, 0x232a],\n [0x2630, 0x2637],\n [0x268a, 0x268f],\n [0x2e80, 0x2e99],\n [0x2e9b, 0x2ef3],\n [0x2f00, 0x2fd5],\n [0x2ff0, 0x302f],\n [0x3031, 0x303c],\n [0x303e, 0x303e],\n [0x3041, 0x3096],\n [0x3099, 0x30ff],\n [0x3105, 0x312f],\n [0x3131, 0x3163],\n [0x3165, 0x318e],\n [0x3190, 0x31e5],\n [0x31ef, 0x321e],\n [0x3220, 0x3247],\n [0x3250, 0x3296],\n [0x3298, 0x3298],\n [0x329a, 0xa48c],\n [0xa490, 0xa4c6],\n [0xa960, 0xa97c],\n [0xac00, 0xd7a3],\n [0xf900, 0xfaff],\n [0xfe10, 0xfe19],\n [0xfe30, 0xfe52],\n [0xfe54, 0xfe66],\n [0xfe68, 0xfe6b],\n [0xff01, 0xff60],\n [0xffe0, 0xffe6],\n [0x16fe0, 0x16fe4],\n [0x16ff0, 0x16ff6],\n [0x17000, 0x18cda],\n [0x18cff, 0x18d20],\n [0x18d80, 0x18df2],\n [0x18e00, 0x19191],\n [0x191a0, 0x191d2],\n [0x1aff0, 0x1aff3],\n [0x1aff5, 0x1affb],\n [0x1affd, 0x1affe],\n [0x1b000, 0x1b128],\n [0x1b132, 0x1b132],\n [0x1b150, 0x1b152],\n [0x1b155, 0x1b155],\n [0x1b164, 0x1b168],\n [0x1b170, 0x1b2fb],\n [0x1d300, 0x1d356],\n [0x1d360, 0x1d376],\n [0x1f200, 0x1f200],\n [0x1f210, 0x1f219],\n [0x1f21b, 0x1f22e],\n [0x1f230, 0x1f231],\n [0x1f23b, 0x1f23b],\n [0x1f240, 0x1f248],\n [0x1f260, 0x1f265],\n [0x20000, 0x2fffd],\n [0x30000, 0x3fffd],\n]\n\n/** One code point the terminal draws no cell for: control characters, the\n * zero-width joiners/marks, combining marks and variation selectors. */\nfunction isZeroWidthCodePoint(code: number, glyph: string): boolean {\n if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) return true\n if (code >= 0x200b && code <= 0x200f) return true\n if (code === 0xfeff) return true\n if (code >= 0x300 && code <= 0x36f) return true\n if (code >= 0x1ab0 && code <= 0x1aff) return true\n if (code >= 0x1dc0 && code <= 0x1dff) return true\n if (code >= 0x20d0 && code <= 0x20ff) return true\n if (code >= 0xfe00 && code <= 0xfe0f) return true\n if (code >= 0xfe20 && code <= 0xfe2f) return true\n if (code >= 0xe0100 && code <= 0xe01ef) return true\n if (code >= 0xd800 && code <= 0xdfff) return true // a lone surrogate\n return IGNORABLE_GLYPH.test(glyph)\n}\n\nfunction isWideCodePoint(code: number): boolean {\n for (const [low, high] of CELL_WIDE_RANGES) {\n if (code < low) return false\n if (code <= high) return true\n }\n return false\n}\n\n/** Cells one grapheme occupies. */\nfunction graphemeWidth(segment: string): number {\n if (EMOJI_GLYPH.test(segment)) return 2\n // A lone VS16 carries no width; after a base it asks for emoji presentation.\n if (segment.length > 1 && segment.includes(EMOJI_PRESENTATION_SELECTOR)) return 2\n let width = 0\n for (const glyph of segment) {\n const code = glyph.codePointAt(0) ?? 0\n if (isZeroWidthCodePoint(code, glyph)) continue\n width += isWideCodePoint(code) ? 2 : 1\n }\n return width\n}\n\n/** Terminal cells `value` occupies — the unit every column in this plugin is\n * measured in. Mirrors the host (that is how `@opentui/core` sizes a text\n * run): emoji count as two cells, East Asian Wide/Fullwidth as two, East\n * Asian Ambiguous as one, combining marks and variation selectors as none.\n * Pure. */\nexport function cellWidth(value: string): number {\n let width = 0\n for (const { segment } of GRAPHEMES.segment(value)) width += graphemeWidth(segment)\n return width\n}\n","/**\n * whats-new-highlights.ts — release highlights for the one-time \"What's new\"\n * window, extracted from the CHANGELOG.md shipped with the plugin copy.\n *\n * The section-finding logic is an inline replica of scripts/changelog-extract.mjs\n * `extractSection` (pinned by a parity test in tests/tui-whats-new.test.mjs):\n * the copied plugin ships only dist/ + package.json (+ CHANGELOG.md, copied by\n * both installers), so it cannot reach scripts/ at runtime — the same reason\n * the preset resolver is mirrored in index.tsx/index-v2.tsx rather than\n * imported. The script's CLI main is NOT replicated; the plugin only needs the\n * pure extraction.\n *\n * Everything is reduced to bounded plain text: no markdown syntax artifacts,\n * at most WHATS_NEW_MAX_ITEMS bullets. Missing CHANGELOG.md, an unknown\n * version or an empty section all resolve to an empty highlight set — the\n * window simply does not show (fail-open, like the rest of the plugin).\n */\nimport { readFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n/** Hard cap on bullets shown in the window (the remainder is counted). */\nexport const WHATS_NEW_MAX_ITEMS = 12\n\n/** Prefix of the \"+N more\" line appended when the bullet budget is exceeded. */\nexport const WHATS_NEW_MORE_PREFIX = '… +'\n\n/** H3 subsection headings are kept as plain-text group labels. */\nexport interface WhatsNewGroup {\n heading: string | null\n items: string[]\n}\n\nexport interface WhatsNewHighlights {\n /** Normalized version the highlights belong to (null when not found). */\n version: string | null\n found: boolean\n groups: WhatsNewGroup[]\n /** Total bullets in the section, before the WHATS_NEW_MAX_ITEMS cut. */\n totalItems: number\n /** True when totalItems exceeded WHATS_NEW_MAX_ITEMS. */\n truncated: boolean\n}\n\nexport const EMPTY_HIGHLIGHTS: WhatsNewHighlights = {\n version: null,\n found: false,\n groups: [],\n totalItems: 0,\n truncated: false,\n}\n\n/** Escape regex metacharacters so a version like 1.0.0 matches literally. */\nfunction escapeRegExp(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Extract the body of a version section from changelog text — inline replica\n * of scripts/changelog-extract.mjs `extractSection` (see that file for the\n * full contract: `## [<version>] - YYYY-MM-DD`, leading `v` and the date\n * optional, `## [Unreleased]` never matched).\n */\nexport function extractSection(\n changelogText: string,\n version: string,\n): { found: boolean; body: string | null } {\n const normalized = String(version).trim().replace(/^v/i, '')\n if (!normalized || /^unreleased$/i.test(normalized)) return { found: false, body: null }\n\n const escaped = escapeRegExp(normalized)\n // Single-line heading: `## [v?1.2.1]` optionally followed by ` - YYYY-MM-DD`.\n // [ \\t] (not \\s) keeps the match from crossing newlines; the lookahead\n // requires end-of-line or whitespace so `[1.0.0-beta]` can never match `1.0.0`.\n const headingRe = new RegExp(\n `^##[ \\\\t]+\\\\[v?${escaped}\\\\](?:[ \\\\t]*-[ \\\\t]*\\\\d{4}-\\\\d{2}-\\\\d{2})?(?=[ \\\\t]|$)`,\n 'm',\n )\n const match = headingRe.exec(changelogText)\n if (!match) return { found: false, body: null }\n\n // Advance past the heading line (match.index may point mid-line).\n const newline = changelogText.indexOf('\\n', match.index)\n const start = newline === -1 ? changelogText.length : newline + 1\n\n // Body ends at the next `## [` heading or end of text.\n const nextHeading = /^##[ \\t]+\\[/m.exec(changelogText.slice(start))\n const end = nextHeading ? start + nextHeading.index : changelogText.length\n\n return { found: true, body: changelogText.slice(start, end).trim() }\n}\n\n/**\n * Reduce one markdown line to plain text: links keep their label, emphasis\n * and inline-code markers are dropped, HTML comment fragments are removed,\n * and whitespace collapses. Deliberately simple — the input is our own\n * CHANGELOG (lint-capped at 200 chars per bullet), not hostile input.\n */\nexport function stripMarkdown(text: string): string {\n return text\n .replace(/<!--[\\s\\S]*?-->/g, ' ')\n .replace(/\\[([^\\]]+)\\]\\([^)]*\\)/g, '$1')\n .replace(/(\\*\\*|__)/g, '')\n .replace(/`/g, '')\n .replace(/\\s+/g, ' ')\n .trim()\n}\n\n/** Strip the leading H3 marker (`### Added` → `Added`). */\nfunction stripHeading(text: string): string {\n return text.replace(/^#{1,6}[ \\t]+/, '').trim()\n}\n\n/**\n * Extract the release highlights for `version`: H3 subsection headings as\n * group labels and their bullets as sanitized plain text, bounded to\n * WHATS_NEW_MAX_ITEMS bullets. A missing section, a bullet-less section or a\n * blank changelog all return EMPTY_HIGHLIGHTS (no window).\n */\nexport function extractHighlights(changelogText: string, version: string): WhatsNewHighlights {\n const { found, body } = extractSection(changelogText ?? '', version ?? '')\n if (!found || !body) return { ...EMPTY_HIGHLIGHTS }\n\n const groups: WhatsNewGroup[] = []\n let totalItems = 0\n let truncated = false\n\n for (const rawLine of body.split('\\n')) {\n const line = rawLine.trim()\n if (line === '' || line.startsWith('<!--')) continue\n\n if (/^#{1,6}[ \\t]/.test(line)) {\n const heading = stripMarkdown(stripHeading(line))\n if (heading === '') continue\n if (groups.at(-1)?.items.length === 0) groups.pop() // empty group boundary\n groups.push({ heading, items: [] })\n continue\n }\n\n if (totalItems >= WHATS_NEW_MAX_ITEMS) {\n // Keep scanning only to count the remainder for the \"+N more\" line.\n if (/^[-*][ \\t]/.test(line)) totalItems += 1\n continue\n }\n\n const isBullet = /^[-*][ \\t]/.test(line)\n const continuation = (groups.at(-1)?.items.length ?? 0) > 0\n if (!isBullet && !continuation) continue // prose between groups — not a highlight\n\n const content = stripMarkdown(isBullet ? line.replace(/^[-*][ \\t]+/, '') : line)\n if (content === '') continue\n const group = groups.at(-1)\n if (group === undefined) {\n groups.push({ heading: null, items: [content] })\n } else if (isBullet || group.items.length === 0) {\n group.items.push(content)\n } else {\n group.items[group.items.length - 1] = `${group.items.at(-1)} ${content}`.trim()\n }\n if (isBullet) totalItems += 1\n }\n\n const kept = groups.filter((group) => group.items.length > 0)\n truncated = totalItems > WHATS_NEW_MAX_ITEMS\n return {\n version: found ? String(version).trim().replace(/^v/i, '') : null,\n found,\n groups: kept,\n totalItems,\n truncated,\n }\n}\n\n/** Window title — mirrors the sidebar's `Pantheon v<version>` convention. */\nexport function whatsNewTitle(version: string): string {\n return `O que há de novo — Pantheon v${String(version).trim().replace(/^v/i, '')}`\n}\n\n/** Flat display lines for the window: group headings, `• ` bullets, `+N more`. */\nexport function whatsNewLines(highlights: WhatsNewHighlights): string[] {\n const lines: string[] = []\n for (const group of highlights.groups) {\n if (group.heading !== null) lines.push(group.heading)\n for (const item of group.items) lines.push(`• ${item}`)\n }\n if (highlights.truncated) {\n const hidden = Math.max(0, highlights.totalItems - WHATS_NEW_MAX_ITEMS)\n if (hidden > 0) lines.push(`${WHATS_NEW_MORE_PREFIX}${hidden} mais`)\n }\n return lines\n}\n\n/**\n * Candidate CHANGELOG.md locations for a bundle, first readable wins:\n * 1. the plugin copy root (`<configDir>/plugins/pantheon-tui/CHANGELOG.md`,\n * shipped by both installers next to package.json);\n * 2. the package root (dev checkout; also an npm-package install when the\n * bundle runs from `<pkg>/src/plugins/tui/dist/`).\n */\nexport function changelogCandidates(bundlePath: string): string[] {\n const dist = dirname(bundlePath)\n const copyRoot = dirname(dist)\n // The second leg targets the package root: src/plugins/tui → plugins → src\n // → package root (dev checkout / npm-package install). On an installed copy\n // the same three levels land on the XDG base, where no CHANGELOG lives —\n // harmless, the copy-root candidate is the one the installers ship.\n const packageRoot = dirname(dirname(dirname(copyRoot)))\n return [join(copyRoot, 'CHANGELOG.md'), join(packageRoot, 'CHANGELOG.md')]\n}\n\n/** Read the first existing candidate; null when none is readable (no window). */\nexport async function readChangelogForBundle(bundleUrl: string): Promise<string | null> {\n try {\n const bundlePath = fileURLToPath(bundleUrl)\n for (const candidate of changelogCandidates(bundlePath)) {\n try {\n return await readFile(candidate, 'utf8')\n } catch {}\n }\n return null\n } catch {\n return null\n }\n}\n\n/** Build-time embedded version (tsdown `define` in tsdown.config.ts). */\ndeclare const __PANTHEON_VERSION__: string | undefined\n\n/** The ambient build-time version, or null outside a tsdown build. */\nexport function embeddedVersion(): string | null {\n return typeof __PANTHEON_VERSION__ !== 'undefined' && __PANTHEON_VERSION__\n ? __PANTHEON_VERSION__\n : null\n}\n\n/**\n * Resolve the running Pantheon version for the what's-new window: the plugin\n * copy's own package.json first (the copy root two levels above the bundle,\n * then the package root four levels above — the same legs as the V1 sidebar's\n * detectVersion try 0a/0b), falling back to the tsdown build embed. Null when\n * nothing resolves → no window (fail-open).\n */\nexport async function resolveRunningVersion(\n bundleUrl: string,\n embedded: string | null = embeddedVersion(),\n): Promise<string | null> {\n try {\n const bundlePath = fileURLToPath(bundleUrl)\n const dist = dirname(bundlePath)\n for (const root of [dirname(dist), dirname(dirname(dirname(dist)))]) {\n try {\n const raw = await readFile(join(root, 'package.json'), 'utf8')\n const parsed = JSON.parse(raw) as { version?: unknown }\n if (typeof parsed.version === 'string' && parsed.version.trim() !== '') {\n return parsed.version\n }\n } catch {}\n }\n } catch {\n /* fall through to the embed */\n }\n return embedded\n}\n","/**\n * whats-new-state.ts — last-seen version for the one-time \"What's new\" window.\n *\n * The TUI shows a dismissable release-highlights dialog once per Pantheon\n * version. Whether a version was already seen is persisted next to the other\n * opencode-level Pantheon state: `<configDir>/.pantheon/whats-new.json`, the\n * same directory that already holds `install-state.json` (scripts/install/\n * state.mjs) and the active-preset file the sidebar reads. There is no\n * established persistent TUI KV store (the host `api.kv` is per-process), so\n * the plugin owns one small JSON file with the atomic-write discipline used\n * across the repo (unique tmp + rename, mirrors scripts/install/verify.mjs).\n *\n * Fail-open everywhere: a missing or corrupt file reads as \"never seen\" (the\n * window may show), a failed write is silent (the window may show again) —\n * neither can ever block TUI startup.\n */\nimport { mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { dirname, join } from 'node:path'\n\n/** State file name, kept next to `install-state.json` in `<configDir>/.pantheon/`. */\nexport const WHATS_NEW_STATE_FILENAME = 'whats-new.json'\n\n/** Shape of the persisted file — the plugin owns this file outright. */\nexport interface WhatsNewStateFile {\n seenVersion: string | null\n updatedAt: string\n}\n\ntype Env = Record<string, string | undefined>\n\n/** Parse a state file body; null when unreadable as the expected shape. */\nexport function parseWhatsNewState(raw: string): WhatsNewStateFile | null {\n try {\n const parsed: unknown = JSON.parse(raw)\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return null\n const record = parsed as Record<string, unknown>\n const seen = record.seenVersion\n if (typeof seen !== 'string' && seen !== null) return null\n return { seenVersion: seen, updatedAt: String(record.updatedAt ?? '') }\n } catch {\n return null\n }\n}\n\n/** Read the persisted state; null when missing or corrupt (never throws). */\nexport async function readWhatsNewState(statePath: string): Promise<WhatsNewStateFile | null> {\n try {\n return parseWhatsNewState(await readFile(statePath, 'utf8'))\n } catch {\n return null\n }\n}\n\n/**\n * Whether the one-time window should show for `version`: any version change\n * since the last dismissal (including downgrades). A falsy version — the\n * resolver failed — never shows.\n */\nexport async function shouldShowWhatsNew(\n version: string | null | undefined,\n statePath: string,\n): Promise<boolean> {\n if (typeof version !== 'string' || version.trim() === '') return false\n const state = await readWhatsNewState(statePath)\n return state?.seenVersion !== version\n}\n\n/**\n * Persist `version` as seen (atomic tmp + rename, 0o600). Never throws: a\n * failed write leaves the state untouched and the window may show again —\n * the same fail-open contract as the rest of the plugin.\n */\nexport async function markSeenWhatsNew(version: string, statePath: string): Promise<boolean> {\n if (typeof version !== 'string' || version.trim() === '') return false\n const previous = await readWhatsNewState(statePath)\n const next: WhatsNewStateFile = {\n seenVersion: version,\n updatedAt: new Date().toISOString(),\n }\n const tmpPath = `${statePath}.tmp-${process.pid}`\n try {\n await mkdir(dirname(statePath), { recursive: true })\n await writeFile(tmpPath, `${JSON.stringify({ ...previous, ...next }, null, 2)}\\n`, {\n encoding: 'utf8',\n mode: 0o600,\n })\n await rename(tmpPath, statePath)\n return true\n } catch {\n try {\n await unlink(tmpPath)\n } catch {\n /* nothing to clean up */\n }\n return false\n }\n}\n\n/** `stat`-based existence probe (async I/O discipline). */\nasync function pathExists(path: string): Promise<boolean> {\n try {\n await stat(path)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Default state path: `<configDir>/.pantheon/whats-new.json`, resolving the\n * OpenCode config directory exactly like src/pantheon/tui-version-check.ts\n * (`$XDG_CONFIG_HOME/opencode` → `~/.opencode`), defaulting to the XDG\n * location `init` creates when neither exists yet.\n */\nexport async function defaultWhatsNewStatePath(\n env: Env = process.env,\n home: string = homedir(),\n): Promise<string> {\n const xdgConfig = env.XDG_CONFIG_HOME || join(home, '.config')\n const primary = join(xdgConfig, 'opencode')\n if (await pathExists(primary)) return join(primary, '.pantheon', WHATS_NEW_STATE_FILENAME)\n\n const legacy = join(home, '.opencode')\n if (await pathExists(legacy)) return join(legacy, '.pantheon', WHATS_NEW_STATE_FILENAME)\n\n return join(primary, '.pantheon', WHATS_NEW_STATE_FILENAME)\n}\n","/**\n * whats-new-open.ts — the show-once decision for the \"What's new\" window.\n *\n * Plain data in, plain data out: the entrypoints (index.tsx / index-v2.tsx)\n * resolve the running version and the shipped CHANGELOG.md, then hand this\n * module a `show` callback that renders the view data through the host's\n * dialog API. Keeping the decision JSX-free makes the whole one-time flow\n * testable offline (node strips the types natively) — the Solid glue lives in\n * whats-new.tsx.\n *\n * Contract (pinned by tests/tui-whats-new.test.mjs):\n * - shows at most once per version: dismissal marks the version seen;\n * - nothing to show (no version, missing CHANGELOG, empty section) → no\n * window AND no pin — the next start may still show it;\n * - never throws on its own inputs; I/O failures inside the state module\n * are fail-open there.\n */\nimport {\n EMPTY_HIGHLIGHTS,\n extractHighlights,\n type WhatsNewHighlights,\n whatsNewLines,\n whatsNewTitle,\n} from './whats-new-highlights.ts'\nimport { markSeenWhatsNew, shouldShowWhatsNew } from './whats-new-state.ts'\n\n/** Muted footer hint teaching the dismiss bind (Portuguese, like the sidebar). */\nexport const WHATS_NEW_CLOSE_HINT = 'esc/q fechar'\n\n/** Everything the window needs to render — no host types, no JSX. */\nexport interface WhatsNewViewData {\n version: string\n title: string\n lines: string[]\n hint: string\n}\n\nexport type WhatsNewShowFn = (render: () => WhatsNewViewData, onClose: () => void) => void\n\nexport interface WhatsNewOpenInput {\n /** Running Pantheon version (null when unresolvable → no window). */\n version: string | null\n /** Path of the seen-version state file (see whats-new-state.ts). */\n statePath: string\n /** Shipped CHANGELOG.md content, or null when unreadable. */\n changelogText: string | null\n /** Host dialog opener; `onClose` fires on host dismissal (ESC / chrome). */\n show: WhatsNewShowFn\n}\n\n/**\n * Open the one-time window when the version changed and highlights exist.\n * Returns true when the window was shown; the caller's `onClose` callback\n * (both host-initiated and local close binds) must funnel into marking seen.\n */\nexport async function openWhatsNew(input: WhatsNewOpenInput): Promise<boolean> {\n const { version, statePath, changelogText, show } = input\n if (typeof version !== 'string' || version.trim() === '') return false\n if (!(await shouldShowWhatsNew(version, statePath))) return false\n\n const highlights: WhatsNewHighlights = changelogText\n ? extractHighlights(changelogText, version)\n : { ...EMPTY_HIGHLIGHTS }\n const lines = whatsNewLines(highlights)\n if (lines.length === 0) return false\n\n const data: WhatsNewViewData = {\n version,\n title: whatsNewTitle(version),\n lines,\n hint: WHATS_NEW_CLOSE_HINT,\n }\n show(\n () => data,\n () => {\n void markSeenWhatsNew(version, statePath)\n },\n )\n return true\n}\n"],"mappings":";;;;;;;;;AAIA,MAAa,oBAAoB;AACjC,MAAa,0BAA0B;AACvC,MAAa,yBAAyB;AAEtC,SAASA,eAAa,OAA+B;CACnD,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAEA,SAAgB,iBAAiB,SAAsC;CACrE,IAAI,UAAU,IAAI,OAAO;CACzB,IAAI,UAAU,IA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,OAAO,KAAK,QAAQ,aAAa,wBAAwB;CAEvF,OAAO,KAAK,SAAS,aAAa,wBAAwB;AAC5D;;;;;;;;;;;;;;;;;;;;;ACpGA,MAAa,uBAAuB;;;;;;AA4BpC,eAAsB,aAAa,OAA4C;CAC7E,MAAM,EAAE,SAAS,WAAW,eAAe,SAAS;CACpD,IAAI,OAAO,YAAY,YAAY,QAAQ,KAAK,MAAM,IAAI,OAAO;CACjE,IAAI,CAAE,MAAM,mBAAmB,SAAS,SAAS,GAAI,OAAO;CAK5D,MAAM,QAAQ,cAHyB,gBACnC,kBAAkB,eAAe,OAAO,IACxC,EAAE,GAAG,iBAAiB,CACY;CACtC,IAAI,MAAM,WAAW,GAAG,OAAO;CAE/B,MAAM,OAAyB;EAC7B;EACA,OAAO,cAAc,OAAO;EAC5B;EACA,MAAM;CACR;CACA,WACQ,YACA;EACJ,iBAAsB,SAAS,SAAS;CAC1C,CACF;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"tui-v2.js","names":["numberOrNull"],"sources":["../src/context-gauge.ts","../src/model-usage-limits.ts","../src/sidebar-width.ts","../src/whats-new-highlights.ts","../src/whats-new-state.ts","../src/whats-new-open.ts"],"sourcesContent":["/** Shared, data-only formatting and visual helpers for compact context gauges. */\n\nexport type ContextProgressTone = 'info' | 'success' | 'warning' | 'error'\n\nexport const CONTEXT_BAR_CELLS = 12\nexport const CONTEXT_BAR_FILLED_CELL = '\\u25B0'\nexport const CONTEXT_BAR_EMPTY_CELL = '\\u25B1'\n\nfunction numberOrNull(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\nexport function contextUsageTone(percent: number): ContextProgressTone {\n if (percent > 90) return 'error'\n if (percent > 50) return 'warning'\n if (percent > 25) return 'success'\n return 'info'\n}\n\nexport function formatTokenCount(tokens: number | null | undefined): string | null {\n const value = numberOrNull(tokens)\n if (value === null || value < 0) return null\n return Math.round(value).toLocaleString('en-US')\n}\n\nexport function formatContextWindow(limit: number | null | undefined): string | null {\n const value = numberOrNull(limit)\n if (value === null || value <= 0) return null\n if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`\n if (value >= 1_000) return `${Math.floor(value / 1_000)}K`\n return `${Math.floor(value)}`\n}\n\nexport function contextBarFilled(percent: number, cells = CONTEXT_BAR_CELLS): number {\n const total = Math.max(1, Math.floor(cells))\n const filled = Math.round((percent / 100) * total)\n if (!Number.isFinite(filled)) return 0\n return Math.min(total, Math.max(0, filled))\n}\n\nexport function contextBar(\n percent: number | null | undefined,\n cells = CONTEXT_BAR_CELLS,\n): { filled: string; empty: string } | null {\n const value = numberOrNull(percent)\n if (value === null) return null\n const total = Math.max(1, Math.floor(cells))\n const filled = contextBarFilled(value, total)\n return {\n filled: CONTEXT_BAR_FILLED_CELL.repeat(filled),\n empty: CONTEXT_BAR_EMPTY_CELL.repeat(total - filled),\n }\n}\n\nexport function formatSpent(cost: number | null | undefined): string | null {\n const value = numberOrNull(cost)\n if (value === null || value < 0) return null\n return `$${value.toFixed(2)}`\n}\n","/** Shared bounds for cached recent model-usage aggregation. */\nexport const MODEL_USAGE_VISIBLE_CEILING = 3\nexport const MODEL_USAGE_MESSAGE_LIMIT = 400\nexport const MODEL_USAGE_SESSION_LIMIT = 8\n","/** Conservative content budget; the host sidebar slot does not report its runtime width. */\nexport const SIDEBAR_CONTENT_WIDTH = 34\n\nexport const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n\n/** A grapheme the host draws two cells wide: emoji presentation, an extended\n * pictograph (a bare `❤` counts too, exactly as the host's `emoji-regex`\n * does) and a regional-indicator pair (a flag). */\nconst EMOJI_GLYPH = /\\p{Emoji_Presentation}|\\p{Extended_Pictographic}|\\p{Regional_Indicator}/u\n/** VS16 asks for emoji presentation; without it `1` is one cell, with it the\n * keycap sequence is drawn as one two-cell glyph. */\nconst EMOJI_PRESENTATION_SELECTOR = '\\uFE0F'\n/** Unicode default-ignorable code points carry no width of their own. */\nconst IGNORABLE_GLYPH = /^\\p{Default_Ignorable_Code_Point}$/u\n/** East Asian Wide/Fullwidth ranges — two cells, never the ambiguous width\n * (the host measures ambiguous as narrow, so `▸`/`✓`/`—` stay one cell).\n * Generated from the host's own measurement (`string-width` over every code\n * point, emoji excluded), so this table can be regenerated verbatim when the\n * host upgrades its Unicode data instead of being hand-edited. */\nconst CELL_WIDE_RANGES: readonly (readonly [number, number])[] = [\n [0x1100, 0x115e],\n [0x2329, 0x232a],\n [0x2630, 0x2637],\n [0x268a, 0x268f],\n [0x2e80, 0x2e99],\n [0x2e9b, 0x2ef3],\n [0x2f00, 0x2fd5],\n [0x2ff0, 0x302f],\n [0x3031, 0x303c],\n [0x303e, 0x303e],\n [0x3041, 0x3096],\n [0x3099, 0x30ff],\n [0x3105, 0x312f],\n [0x3131, 0x3163],\n [0x3165, 0x318e],\n [0x3190, 0x31e5],\n [0x31ef, 0x321e],\n [0x3220, 0x3247],\n [0x3250, 0x3296],\n [0x3298, 0x3298],\n [0x329a, 0xa48c],\n [0xa490, 0xa4c6],\n [0xa960, 0xa97c],\n [0xac00, 0xd7a3],\n [0xf900, 0xfaff],\n [0xfe10, 0xfe19],\n [0xfe30, 0xfe52],\n [0xfe54, 0xfe66],\n [0xfe68, 0xfe6b],\n [0xff01, 0xff60],\n [0xffe0, 0xffe6],\n [0x16fe0, 0x16fe4],\n [0x16ff0, 0x16ff6],\n [0x17000, 0x18cda],\n [0x18cff, 0x18d20],\n [0x18d80, 0x18df2],\n [0x18e00, 0x19191],\n [0x191a0, 0x191d2],\n [0x1aff0, 0x1aff3],\n [0x1aff5, 0x1affb],\n [0x1affd, 0x1affe],\n [0x1b000, 0x1b128],\n [0x1b132, 0x1b132],\n [0x1b150, 0x1b152],\n [0x1b155, 0x1b155],\n [0x1b164, 0x1b168],\n [0x1b170, 0x1b2fb],\n [0x1d300, 0x1d356],\n [0x1d360, 0x1d376],\n [0x1f200, 0x1f200],\n [0x1f210, 0x1f219],\n [0x1f21b, 0x1f22e],\n [0x1f230, 0x1f231],\n [0x1f23b, 0x1f23b],\n [0x1f240, 0x1f248],\n [0x1f260, 0x1f265],\n [0x20000, 0x2fffd],\n [0x30000, 0x3fffd],\n]\n\n/** One code point the terminal draws no cell for: control characters, the\n * zero-width joiners/marks, combining marks and variation selectors. */\nfunction isZeroWidthCodePoint(code: number, glyph: string): boolean {\n if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) return true\n if (code >= 0x200b && code <= 0x200f) return true\n if (code === 0xfeff) return true\n if (code >= 0x300 && code <= 0x36f) return true\n if (code >= 0x1ab0 && code <= 0x1aff) return true\n if (code >= 0x1dc0 && code <= 0x1dff) return true\n if (code >= 0x20d0 && code <= 0x20ff) return true\n if (code >= 0xfe00 && code <= 0xfe0f) return true\n if (code >= 0xfe20 && code <= 0xfe2f) return true\n if (code >= 0xe0100 && code <= 0xe01ef) return true\n if (code >= 0xd800 && code <= 0xdfff) return true // a lone surrogate\n return IGNORABLE_GLYPH.test(glyph)\n}\n\nfunction isWideCodePoint(code: number): boolean {\n for (const [low, high] of CELL_WIDE_RANGES) {\n if (code < low) return false\n if (code <= high) return true\n }\n return false\n}\n\n/** Cells one grapheme occupies. */\nfunction graphemeWidth(segment: string): number {\n if (EMOJI_GLYPH.test(segment)) return 2\n // A lone VS16 carries no width; after a base it asks for emoji presentation.\n if (segment.length > 1 && segment.includes(EMOJI_PRESENTATION_SELECTOR)) return 2\n let width = 0\n for (const glyph of segment) {\n const code = glyph.codePointAt(0) ?? 0\n if (isZeroWidthCodePoint(code, glyph)) continue\n width += isWideCodePoint(code) ? 2 : 1\n }\n return width\n}\n\n/** Terminal cells `value` occupies — the unit every column in this plugin is\n * measured in. Mirrors the host (that is how `@opentui/core` sizes a text\n * run): emoji count as two cells, East Asian Wide/Fullwidth as two, East\n * Asian Ambiguous as one, combining marks and variation selectors as none.\n * Pure. */\nexport function cellWidth(value: string): number {\n let width = 0\n for (const { segment } of GRAPHEMES.segment(value)) width += graphemeWidth(segment)\n return width\n}\n","/**\n * whats-new-highlights.ts — release highlights for the one-time \"What's new\"\n * window, extracted from the CHANGELOG.md shipped with the plugin copy.\n *\n * The section-finding logic is an inline replica of scripts/changelog-extract.mjs\n * `extractSection` (pinned by a parity test in tests/tui-whats-new.test.mjs):\n * the copied plugin ships only dist/ + package.json (+ CHANGELOG.md, copied by\n * both installers), so it cannot reach scripts/ at runtime — the same reason\n * the preset resolver is mirrored in index.tsx/index-v2.tsx rather than\n * imported. The script's CLI main is NOT replicated; the plugin only needs the\n * pure extraction.\n *\n * Everything is reduced to bounded plain text: no markdown syntax artifacts,\n * at most WHATS_NEW_MAX_ITEMS bullets. Missing CHANGELOG.md, an unknown\n * version or an empty section all resolve to an empty highlight set — the\n * window simply does not show (fail-open, like the rest of the plugin).\n */\nimport { readFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n/** Hard cap on bullets shown in the window (the remainder is counted). */\nexport const WHATS_NEW_MAX_ITEMS = 12\n\n/**\n * Cap for the curated `🆕 What's New` summary block — the window shows the\n * summary, never the full Added/Changed/Fixed walls.\n */\nexport const WHATS_NEW_SUMMARY_MAX_ITEMS = 6\n\n/** Bullets longer than this are truncated with an ellipsis (one-line rule). */\nexport const WHATS_NEW_ITEM_MAX_CHARS = 140\n\n/** Prefix of the \"+N more\" line appended when the bullet budget is exceeded. */\nexport const WHATS_NEW_MORE_PREFIX = '… +'\n\n/** H3 subsection headings are kept as plain-text group labels. */\nexport interface WhatsNewGroup {\n heading: string | null\n items: string[]\n}\n\nexport interface WhatsNewHighlights {\n /** Normalized version the highlights belong to (null when not found). */\n version: string | null\n found: boolean\n groups: WhatsNewGroup[]\n /** Total bullets in the section, before the WHATS_NEW_MAX_ITEMS cut. */\n totalItems: number\n /** True when totalItems exceeded WHATS_NEW_MAX_ITEMS. */\n truncated: boolean\n}\n\nexport const EMPTY_HIGHLIGHTS: WhatsNewHighlights = {\n version: null,\n found: false,\n groups: [],\n totalItems: 0,\n truncated: false,\n}\n\n/** Escape regex metacharacters so a version like 1.0.0 matches literally. */\nfunction escapeRegExp(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Extract the body of a version section from changelog text — inline replica\n * of scripts/changelog-extract.mjs `extractSection` (see that file for the\n * full contract: `## [<version>] - YYYY-MM-DD`, leading `v` and the date\n * optional, `## [Unreleased]` never matched).\n */\nexport function extractSection(\n changelogText: string,\n version: string,\n): { found: boolean; body: string | null } {\n const normalized = String(version).trim().replace(/^v/i, '')\n if (!normalized || /^unreleased$/i.test(normalized)) return { found: false, body: null }\n\n const escaped = escapeRegExp(normalized)\n // Single-line heading: `## [v?1.2.1]` optionally followed by ` - YYYY-MM-DD`.\n // [ \\t] (not \\s) keeps the match from crossing newlines; the lookahead\n // requires end-of-line or whitespace so `[1.0.0-beta]` can never match `1.0.0`.\n const headingRe = new RegExp(\n `^##[ \\\\t]+\\\\[v?${escaped}\\\\](?:[ \\\\t]*-[ \\\\t]*\\\\d{4}-\\\\d{2}-\\\\d{2})?(?=[ \\\\t]|$)`,\n 'm',\n )\n const match = headingRe.exec(changelogText)\n if (!match) return { found: false, body: null }\n\n // Advance past the heading line (match.index may point mid-line).\n const newline = changelogText.indexOf('\\n', match.index)\n const start = newline === -1 ? changelogText.length : newline + 1\n\n // Body ends at the next `## [` heading or end of text.\n const nextHeading = /^##[ \\t]+\\[/m.exec(changelogText.slice(start))\n const end = nextHeading ? start + nextHeading.index : changelogText.length\n\n return { found: true, body: changelogText.slice(start, end).trim() }\n}\n\n/**\n * Reduce one markdown line to plain text: links keep their label, emphasis\n * and inline-code markers are dropped, HTML comment fragments are removed,\n * and whitespace collapses. Deliberately simple — the input is our own\n * CHANGELOG (lint-capped at 200 chars per bullet), not hostile input.\n */\nexport function stripMarkdown(text: string): string {\n return text\n .replace(/<!--[\\s\\S]*?-->/g, ' ')\n .replace(/\\[([^\\]]+)\\]\\([^)]*\\)/g, '$1')\n .replace(/(\\*\\*|__)/g, '')\n .replace(/`/g, '')\n .replace(/\\s+/g, ' ')\n .trim()\n}\n\n/** Strip the leading H3 marker (`### Added` → `Added`). */\nfunction stripHeading(text: string): string {\n return text.replace(/^#{1,6}[ \\t]+/, '').trim()\n}\n\n/**\n * Extract the curated summary block (`### 🆕 What's New` or `## 🆕 What's New`)\n * from a section body: its bullets only, each truncated to\n * WHATS_NEW_ITEM_MAX_CHARS, capped to WHATS_NEW_SUMMARY_MAX_ITEMS. Null when\n * the section carries no summary block (the full-section fallback applies).\n */\nexport function extractWhatsNewSummary(body: string): string[] | null {\n const lines = body.split('\\n')\n const start = lines.findIndex((line) => /^#{2,3}[ \\t]+.*What'?s New/i.test(line.trim()))\n if (start === -1) return null\n const items: string[] = []\n for (const rawLine of lines.slice(start + 1)) {\n const line = rawLine.trim()\n if (line === '' || line.startsWith('<!--')) continue\n if (/^#{1,6}[ \\t]/.test(line)) break // next subsection — summary ended\n if (!/^[-*][ \\t]/.test(line)) continue\n if (items.length >= WHATS_NEW_SUMMARY_MAX_ITEMS) break\n const content = stripMarkdown(line.replace(/^[-*][ \\t]+/, ''))\n if (content === '') continue\n items.push(\n content.length > WHATS_NEW_ITEM_MAX_CHARS\n ? `${content.slice(0, WHATS_NEW_ITEM_MAX_CHARS - 1)}…`\n : content,\n )\n }\n return items.length > 0 ? items : null\n}\n\n/**\n * Extract the release highlights for `version`. When the section carries a\n * curated `🆕 What's New` summary block, THE WINDOW SHOWS ONLY THAT (the\n * full Added/Changed/Fixed walls are for the CHANGELOG readers, not the\n * dialog); otherwise it falls back to the H3-group extraction bounded to\n * WHATS_NEW_MAX_ITEMS bullets. A missing section, a bullet-less section or a\n * blank changelog all return EMPTY_HIGHLIGHTS (no window).\n */\nexport function extractHighlights(changelogText: string, version: string): WhatsNewHighlights {\n const { found, body } = extractSection(changelogText ?? '', version ?? '')\n if (!found || !body) return { ...EMPTY_HIGHLIGHTS }\n\n const summary = extractWhatsNewSummary(body)\n if (summary !== null) {\n return {\n version: String(version).trim().replace(/^v/i, ''),\n found: true,\n groups: [{ heading: null, items: summary }],\n totalItems: summary.length,\n truncated: false,\n }\n }\n\n const groups: WhatsNewGroup[] = []\n let totalItems = 0\n let truncated = false\n\n for (const rawLine of body.split('\\n')) {\n const line = rawLine.trim()\n if (line === '' || line.startsWith('<!--')) continue\n\n if (/^#{1,6}[ \\t]/.test(line)) {\n const heading = stripMarkdown(stripHeading(line))\n if (heading === '') continue\n if (groups.at(-1)?.items.length === 0) groups.pop() // empty group boundary\n groups.push({ heading, items: [] })\n continue\n }\n\n if (totalItems >= WHATS_NEW_MAX_ITEMS) {\n // Keep scanning only to count the remainder for the \"+N more\" line.\n if (/^[-*][ \\t]/.test(line)) totalItems += 1\n continue\n }\n\n const isBullet = /^[-*][ \\t]/.test(line)\n const continuation = (groups.at(-1)?.items.length ?? 0) > 0\n if (!isBullet && !continuation) continue // prose between groups — not a highlight\n\n const content = stripMarkdown(isBullet ? line.replace(/^[-*][ \\t]+/, '') : line)\n if (content === '') continue\n const bounded =\n content.length > WHATS_NEW_ITEM_MAX_CHARS\n ? `${content.slice(0, WHATS_NEW_ITEM_MAX_CHARS - 1)}…`\n : content\n const group = groups.at(-1)\n if (group === undefined) {\n groups.push({ heading: null, items: [bounded] })\n } else if (isBullet || group.items.length === 0) {\n group.items.push(bounded)\n } else {\n group.items[group.items.length - 1] = `${group.items.at(-1)} ${bounded}`.trim()\n }\n if (isBullet) totalItems += 1\n }\n\n const kept = groups.filter((group) => group.items.length > 0)\n truncated = totalItems > WHATS_NEW_MAX_ITEMS\n return {\n version: found ? String(version).trim().replace(/^v/i, '') : null,\n found,\n groups: kept,\n totalItems,\n truncated,\n }\n}\n\n/** Window title — mirrors the sidebar's `Pantheon v<version>` convention. */\nexport function whatsNewTitle(version: string): string {\n return `O que há de novo — Pantheon v${String(version).trim().replace(/^v/i, '')}`\n}\n\n/** Flat display lines for the window: group headings, `• ` bullets, `+N more`. */\nexport function whatsNewLines(highlights: WhatsNewHighlights): string[] {\n const lines: string[] = []\n for (const group of highlights.groups) {\n if (group.heading !== null) lines.push(group.heading)\n for (const item of group.items) lines.push(`• ${item}`)\n }\n if (highlights.truncated) {\n const hidden = Math.max(0, highlights.totalItems - WHATS_NEW_MAX_ITEMS)\n if (hidden > 0) lines.push(`${WHATS_NEW_MORE_PREFIX}${hidden} mais`)\n }\n return lines\n}\n\n/**\n * Candidate CHANGELOG.md locations for a bundle, first readable wins:\n * 1. the plugin copy root (`<configDir>/plugins/pantheon-tui/CHANGELOG.md`,\n * shipped by both installers next to package.json);\n * 2. the package root (dev checkout; also an npm-package install when the\n * bundle runs from `<pkg>/src/plugins/tui/dist/`).\n */\nexport function changelogCandidates(bundlePath: string): string[] {\n const dist = dirname(bundlePath)\n const copyRoot = dirname(dist)\n // The second leg targets the package root: src/plugins/tui → plugins → src\n // → package root (dev checkout / npm-package install). On an installed copy\n // the same three levels land on the XDG base, where no CHANGELOG lives —\n // harmless, the copy-root candidate is the one the installers ship.\n const packageRoot = dirname(dirname(dirname(copyRoot)))\n return [join(copyRoot, 'CHANGELOG.md'), join(packageRoot, 'CHANGELOG.md')]\n}\n\n/** Read the first existing candidate; null when none is readable (no window). */\nexport async function readChangelogForBundle(bundleUrl: string): Promise<string | null> {\n try {\n const bundlePath = fileURLToPath(bundleUrl)\n for (const candidate of changelogCandidates(bundlePath)) {\n try {\n return await readFile(candidate, 'utf8')\n } catch {}\n }\n return null\n } catch {\n return null\n }\n}\n\n/** Build-time embedded version (tsdown `define` in tsdown.config.ts). */\ndeclare const __PANTHEON_VERSION__: string | undefined\n\n/** The ambient build-time version, or null outside a tsdown build. */\nexport function embeddedVersion(): string | null {\n return typeof __PANTHEON_VERSION__ !== 'undefined' && __PANTHEON_VERSION__\n ? __PANTHEON_VERSION__\n : null\n}\n\n/**\n * Resolve the running Pantheon version for the what's-new window: the plugin\n * copy's own package.json first (the copy root two levels above the bundle,\n * then the package root four levels above — the same legs as the V1 sidebar's\n * detectVersion try 0a/0b), falling back to the tsdown build embed. Null when\n * nothing resolves → no window (fail-open).\n */\nexport async function resolveRunningVersion(\n bundleUrl: string,\n embedded: string | null = embeddedVersion(),\n): Promise<string | null> {\n try {\n const bundlePath = fileURLToPath(bundleUrl)\n const dist = dirname(bundlePath)\n for (const root of [dirname(dist), dirname(dirname(dirname(dist)))]) {\n try {\n const raw = await readFile(join(root, 'package.json'), 'utf8')\n const parsed = JSON.parse(raw) as { version?: unknown }\n if (typeof parsed.version === 'string' && parsed.version.trim() !== '') {\n return parsed.version\n }\n } catch {}\n }\n } catch {\n /* fall through to the embed */\n }\n return embedded\n}\n","/**\n * whats-new-state.ts — last-seen version for the one-time \"What's new\" window.\n *\n * The TUI shows a dismissable release-highlights dialog once per Pantheon\n * version. Whether a version was already seen is persisted next to the other\n * opencode-level Pantheon state: `<configDir>/.pantheon/whats-new.json`, the\n * same directory that already holds `install-state.json` (scripts/install/\n * state.mjs) and the active-preset file the sidebar reads. There is no\n * established persistent TUI KV store (the host `api.kv` is per-process), so\n * the plugin owns one small JSON file with the atomic-write discipline used\n * across the repo (unique tmp + rename, mirrors scripts/install/verify.mjs).\n *\n * Fail-open everywhere: a missing or corrupt file reads as \"never seen\" (the\n * window may show), a failed write is silent (the window may show again) —\n * neither can ever block TUI startup.\n */\nimport { mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { dirname, join } from 'node:path'\n\n/** State file name, kept next to `install-state.json` in `<configDir>/.pantheon/`. */\nexport const WHATS_NEW_STATE_FILENAME = 'whats-new.json'\n\n/** Shape of the persisted file — the plugin owns this file outright. */\nexport interface WhatsNewStateFile {\n seenVersion: string | null\n updatedAt: string\n}\n\ntype Env = Record<string, string | undefined>\n\n/** Parse a state file body; null when unreadable as the expected shape. */\nexport function parseWhatsNewState(raw: string): WhatsNewStateFile | null {\n try {\n const parsed: unknown = JSON.parse(raw)\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return null\n const record = parsed as Record<string, unknown>\n const seen = record.seenVersion\n if (typeof seen !== 'string' && seen !== null) return null\n return { seenVersion: seen, updatedAt: String(record.updatedAt ?? '') }\n } catch {\n return null\n }\n}\n\n/** Read the persisted state; null when missing or corrupt (never throws). */\nexport async function readWhatsNewState(statePath: string): Promise<WhatsNewStateFile | null> {\n try {\n return parseWhatsNewState(await readFile(statePath, 'utf8'))\n } catch {\n return null\n }\n}\n\n/**\n * Whether the one-time window should show for `version`: any version change\n * since the last dismissal (including downgrades). A falsy version — the\n * resolver failed — never shows.\n */\nexport async function shouldShowWhatsNew(\n version: string | null | undefined,\n statePath: string,\n): Promise<boolean> {\n if (typeof version !== 'string' || version.trim() === '') return false\n const state = await readWhatsNewState(statePath)\n return state?.seenVersion !== version\n}\n\n/**\n * Persist `version` as seen (atomic tmp + rename, 0o600). Never throws: a\n * failed write leaves the state untouched and the window may show again —\n * the same fail-open contract as the rest of the plugin.\n */\nexport async function markSeenWhatsNew(version: string, statePath: string): Promise<boolean> {\n if (typeof version !== 'string' || version.trim() === '') return false\n const previous = await readWhatsNewState(statePath)\n const next: WhatsNewStateFile = {\n seenVersion: version,\n updatedAt: new Date().toISOString(),\n }\n const tmpPath = `${statePath}.tmp-${process.pid}`\n try {\n await mkdir(dirname(statePath), { recursive: true })\n await writeFile(tmpPath, `${JSON.stringify({ ...previous, ...next }, null, 2)}\\n`, {\n encoding: 'utf8',\n mode: 0o600,\n })\n await rename(tmpPath, statePath)\n return true\n } catch {\n try {\n await unlink(tmpPath)\n } catch {\n /* nothing to clean up */\n }\n return false\n }\n}\n\n/** `stat`-based existence probe (async I/O discipline). */\nasync function pathExists(path: string): Promise<boolean> {\n try {\n await stat(path)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Default state path: `<configDir>/.pantheon/whats-new.json`, resolving the\n * OpenCode config directory exactly like src/pantheon/tui-version-check.ts\n * (`$XDG_CONFIG_HOME/opencode` → `~/.opencode`), defaulting to the XDG\n * location `init` creates when neither exists yet.\n */\nexport async function defaultWhatsNewStatePath(\n env: Env = process.env,\n home: string = homedir(),\n): Promise<string> {\n const xdgConfig = env.XDG_CONFIG_HOME || join(home, '.config')\n const primary = join(xdgConfig, 'opencode')\n if (await pathExists(primary)) return join(primary, '.pantheon', WHATS_NEW_STATE_FILENAME)\n\n const legacy = join(home, '.opencode')\n if (await pathExists(legacy)) return join(legacy, '.pantheon', WHATS_NEW_STATE_FILENAME)\n\n return join(primary, '.pantheon', WHATS_NEW_STATE_FILENAME)\n}\n","/**\n * whats-new-open.ts — the show-once decision for the \"What's new\" window.\n *\n * Plain data in, plain data out: the entrypoints (index.tsx / index-v2.tsx)\n * resolve the running version and the shipped CHANGELOG.md, then hand this\n * module a `show` callback that renders the view data through the host's\n * dialog API. Keeping the decision JSX-free makes the whole one-time flow\n * testable offline (node strips the types natively) — the Solid glue lives in\n * whats-new.tsx.\n *\n * Contract (pinned by tests/tui-whats-new.test.mjs):\n * - shows at most once per version: dismissal marks the version seen;\n * - nothing to show (no version, missing CHANGELOG, empty section) → no\n * window AND no pin — the next start may still show it;\n * - never throws on its own inputs; I/O failures inside the state module\n * are fail-open there.\n */\nimport {\n EMPTY_HIGHLIGHTS,\n extractHighlights,\n type WhatsNewHighlights,\n whatsNewLines,\n whatsNewTitle,\n} from './whats-new-highlights.ts'\nimport { markSeenWhatsNew, shouldShowWhatsNew } from './whats-new-state.ts'\n\n/** Muted footer hint teaching the dismiss bind (Portuguese, like the sidebar). */\nexport const WHATS_NEW_CLOSE_HINT = 'esc/q fechar'\n\n/** Hint variant when the highlights span more than one page. */\nexport const WHATS_NEW_PAGES_HINT = 'esc/q fechar · n próxima · p volta'\n\n/** The CHANGELOG pointer shown under the highlights (the window summarizes; the file is complete). */\nexport const WHATS_NEW_MORE_HINT = 'CHANGELOG completo: CHANGELOG.md no pacote'\n\n/** Rows per page — bounded so no changelog can overflow the terminal. */\nexport const WHATS_NEW_PAGE_SIZE = 14\n\n/** Hard-wrap one display line into rows of at most `width` columns (>= 10). */\nexport function wrapWhatsNewLine(line: string, width: number): string[] {\n const bounded = Number.isInteger(width) && width > 10 ? width : 76\n const text = String(line)\n if (text.length <= bounded) return [text]\n const rows: string[] = []\n let rest = text\n while (rest.length > bounded) {\n rows.push(rest.slice(0, bounded))\n rest = rest.slice(bounded)\n }\n if (rest.length > 0) rows.push(rest)\n return rows\n}\n\n/** Slice display lines into fixed-size pages (>= 1 page, empty-safe). */\nexport function paginateWhatsNewLines(\n lines: string[],\n pageSize: number = WHATS_NEW_PAGE_SIZE,\n): string[][] {\n const size = Number.isInteger(pageSize) && pageSize > 0 ? pageSize : WHATS_NEW_PAGE_SIZE\n if (lines.length === 0) return [[]]\n const pages: string[][] = []\n for (let i = 0; i < lines.length; i += size) pages.push(lines.slice(i, i + size))\n return pages\n}\n\n/** Everything the window needs to render — no host types, no JSX. */\nexport interface WhatsNewViewData {\n version: string\n title: string\n lines: string[]\n /** Fixed-size pages of `lines` (single page when the highlights are short). */\n pages: string[][]\n hint: string\n}\n\nexport type WhatsNewShowFn = (render: () => WhatsNewViewData, onClose: () => void) => void\n\nexport interface WhatsNewOpenInput {\n /** Running Pantheon version (null when unresolvable → no window). */\n version: string | null\n /** Path of the seen-version state file (see whats-new-state.ts). */\n statePath: string\n /** Shipped CHANGELOG.md content, or null when unreadable. */\n changelogText: string | null\n /** Host dialog opener; `onClose` fires on host dismissal (ESC / chrome). */\n show: WhatsNewShowFn\n}\n\n/**\n * Open the one-time window when the version changed and highlights exist.\n * Returns true when the window was shown; the caller's `onClose` callback\n * (both host-initiated and local close binds) must funnel into marking seen.\n */\nexport async function openWhatsNew(input: WhatsNewOpenInput): Promise<boolean> {\n const { version, statePath, changelogText, show } = input\n if (typeof version !== 'string' || version.trim() === '') return false\n if (!(await shouldShowWhatsNew(version, statePath))) return false\n\n const highlights: WhatsNewHighlights = changelogText\n ? extractHighlights(changelogText, version)\n : { ...EMPTY_HIGHLIGHTS }\n const lines = whatsNewLines(highlights)\n if (lines.length === 0) return false\n\n const pages = paginateWhatsNewLines(lines)\n const data: WhatsNewViewData = {\n version,\n title: whatsNewTitle(version),\n lines,\n pages,\n hint: pages.length > 1 ? WHATS_NEW_PAGES_HINT : WHATS_NEW_CLOSE_HINT,\n }\n show(\n () => data,\n () => {\n void markSeenWhatsNew(version, statePath)\n },\n )\n return true\n}\n"],"mappings":";;;;;;;;;AAIA,MAAa,oBAAoB;AACjC,MAAa,0BAA0B;AACvC,MAAa,yBAAyB;AAEtC,SAASA,eAAa,OAA+B;CACnD,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAEA,SAAgB,iBAAiB,SAAsC;CACrE,IAAI,UAAU,IAAI,OAAO;CACzB,IAAI,UAAU,IAAI,OAAO;CACzB,IAAI,UAAU,IAAI,OAAO;CACzB,OAAO;AACT;AAEA,SAAgB,iBAAiB,QAAkD;CACjF,MAAM,QAAQA,eAAa,MAAM;CACjC,IAAI,UAAU,QAAQ,QAAQ,GAAG,OAAO;CACxC,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC,eAAe,OAAO;AACjD;AAEA,SAAgB,oBAAoB,OAAiD;CACnF,MAAM,QAAQA,eAAa,KAAK;CAChC,IAAI,UAAU,QAAQ,SAAS,GAAG,OAAO;CACzC,IAAI,SAAS,KAAW,OAAO,IAAI,QAAQ,IAAA,CAAW,QAAQ,CAAC,EAAE;CACjE,IAAI,SAAS,KAAO,OAAO,GAAG,KAAK,MAAM,QAAQ,GAAK,EAAE;CACxD,OAAO,GAAG,KAAK,MAAM,KAAK;AAC5B;AAEA,SAAgB,iBAAiB,SAAiB,QAAA,IAAmC;CACnF,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC;CAC3C,MAAM,SAAS,KAAK,MAAO,UAAU,MAAO,KAAK;CACjD,IAAI,CAAC,OAAO,SAAS,MAAM,GAAG,OAAO;CACrC,OAAO,KAAK,IAAI,OAAO,KAAK,IAAI,GAAG,MAAM,CAAC;AAC5C;AAEA,SAA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AAS,SAAS,GAAI,OAAO;CAK5D,MAAM,QAAQ,cAHyB,gBACnC,kBAAkB,eAAe,OAAO,IACxC,EAAE,GAAG,iBAAiB,CACY;CACtC,IAAI,MAAM,WAAW,GAAG,OAAO;CAE/B,MAAM,QAAQ,sBAAsB,KAAK;CACzC,MAAM,OAAyB;EAC7B;EACA,OAAO,cAAc,OAAO;EAC5B;EACA;EACA,MAAM,MAAM,SAAS,IAAI,uBAAuB;CAClD;CACA,WACQ,YACA;EACJ,iBAAsB,SAAS,SAAS;CAC1C,CACF;CACA,OAAO;AACT"}
@@ -167,7 +167,7 @@ async function detectVersion(api) {
167
167
  if (ver) return ver;
168
168
  }
169
169
  } catch {}
170
- return "1.6.3-beta.6";
170
+ return "1.6.3-beta.28";
171
171
  }
172
172
  /**
173
173
  * usage-bar — AI subscription usage gauge for the opencode TUI.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pantheon-tui",
3
- "version": "1.6.3-beta.6",
3
+ "version": "1.7.0-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pantheon-tui",
9
- "version": "1.6.3-beta.6",
9
+ "version": "1.7.0-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@opencode-ai/plugin": "1.18.33",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pantheon-tui",
3
3
  "type": "module",
4
- "version": "1.6.3-beta.6",
4
+ "version": "1.7.0-beta.1",
5
5
  "description": "Pantheon TUI plugin — V1 rich sidebar and usage gauges; native V2 status, session and delegation sidebar",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -10,12 +10,19 @@
10
10
  * channel — the initial JSX mounts but effects/refresh/events stay dead (the
11
11
  * "mudo panel" symptom; same contract as the V1 `server.ts` stub).
12
12
  *
13
- * This stub satisfies the loader contract. The native quota RPC that used to
14
- * live here was removed in 1.6.2 — provider quota/usage visibility is now the
15
- * community plugin's job (`@slkiser/opencode-quota`,
16
- * docs/tui-v2-quota-providers.md) — and pantheon-tui has no other background
17
- * server work of its own.
13
+ * This stub satisfies the loader contract. Field report (beta.13): host 2.2.5
14
+ * validates the default export as a DEFINITION OBJECT — "Plugin must export a
15
+ * default definition with an id and an effect or setup function
16
+ * (SchemaError(Expected object at ["default"]))" — the bare `server()`
17
+ * function form failed that schema on every boot (~3.4k load failures in the
18
+ * host log). The native quota RPC that used to live here was removed in 1.6.2
19
+ * — provider quota/usage visibility is now the community plugin's job
20
+ * (`@slkiser/opencode-quota`, docs/tui-v2-quota-providers.md) — and
21
+ * pantheon-tui has no other background server work of its own.
18
22
  */
19
- export default function server() {
20
- return {}
23
+ export default {
24
+ id: 'pantheon.tui.server',
25
+ setup() {
26
+ return {}
27
+ },
21
28
  }
@@ -22,6 +22,15 @@ import { fileURLToPath } from 'node:url'
22
22
  /** Hard cap on bullets shown in the window (the remainder is counted). */
23
23
  export const WHATS_NEW_MAX_ITEMS = 12
24
24
 
25
+ /**
26
+ * Cap for the curated `🆕 What's New` summary block — the window shows the
27
+ * summary, never the full Added/Changed/Fixed walls.
28
+ */
29
+ export const WHATS_NEW_SUMMARY_MAX_ITEMS = 6
30
+
31
+ /** Bullets longer than this are truncated with an ellipsis (one-line rule). */
32
+ export const WHATS_NEW_ITEM_MAX_CHARS = 140
33
+
25
34
  /** Prefix of the "+N more" line appended when the bullet budget is exceeded. */
26
35
  export const WHATS_NEW_MORE_PREFIX = '… +'
27
36
 
@@ -112,8 +121,38 @@ function stripHeading(text: string): string {
112
121
  }
113
122
 
114
123
  /**
115
- * Extract the release highlights for `version`: H3 subsection headings as
116
- * group labels and their bullets as sanitized plain text, bounded to
124
+ * Extract the curated summary block (`### 🆕 What's New` or `## 🆕 What's New`)
125
+ * from a section body: its bullets only, each truncated to
126
+ * WHATS_NEW_ITEM_MAX_CHARS, capped to WHATS_NEW_SUMMARY_MAX_ITEMS. Null when
127
+ * the section carries no summary block (the full-section fallback applies).
128
+ */
129
+ export function extractWhatsNewSummary(body: string): string[] | null {
130
+ const lines = body.split('\n')
131
+ const start = lines.findIndex((line) => /^#{2,3}[ \t]+.*What'?s New/i.test(line.trim()))
132
+ if (start === -1) return null
133
+ const items: string[] = []
134
+ for (const rawLine of lines.slice(start + 1)) {
135
+ const line = rawLine.trim()
136
+ if (line === '' || line.startsWith('<!--')) continue
137
+ if (/^#{1,6}[ \t]/.test(line)) break // next subsection — summary ended
138
+ if (!/^[-*][ \t]/.test(line)) continue
139
+ if (items.length >= WHATS_NEW_SUMMARY_MAX_ITEMS) break
140
+ const content = stripMarkdown(line.replace(/^[-*][ \t]+/, ''))
141
+ if (content === '') continue
142
+ items.push(
143
+ content.length > WHATS_NEW_ITEM_MAX_CHARS
144
+ ? `${content.slice(0, WHATS_NEW_ITEM_MAX_CHARS - 1)}…`
145
+ : content,
146
+ )
147
+ }
148
+ return items.length > 0 ? items : null
149
+ }
150
+
151
+ /**
152
+ * Extract the release highlights for `version`. When the section carries a
153
+ * curated `🆕 What's New` summary block, THE WINDOW SHOWS ONLY THAT (the
154
+ * full Added/Changed/Fixed walls are for the CHANGELOG readers, not the
155
+ * dialog); otherwise it falls back to the H3-group extraction bounded to
117
156
  * WHATS_NEW_MAX_ITEMS bullets. A missing section, a bullet-less section or a
118
157
  * blank changelog all return EMPTY_HIGHLIGHTS (no window).
119
158
  */
@@ -121,6 +160,17 @@ export function extractHighlights(changelogText: string, version: string): Whats
121
160
  const { found, body } = extractSection(changelogText ?? '', version ?? '')
122
161
  if (!found || !body) return { ...EMPTY_HIGHLIGHTS }
123
162
 
163
+ const summary = extractWhatsNewSummary(body)
164
+ if (summary !== null) {
165
+ return {
166
+ version: String(version).trim().replace(/^v/i, ''),
167
+ found: true,
168
+ groups: [{ heading: null, items: summary }],
169
+ totalItems: summary.length,
170
+ truncated: false,
171
+ }
172
+ }
173
+
124
174
  const groups: WhatsNewGroup[] = []
125
175
  let totalItems = 0
126
176
  let truncated = false
@@ -149,13 +199,17 @@ export function extractHighlights(changelogText: string, version: string): Whats
149
199
 
150
200
  const content = stripMarkdown(isBullet ? line.replace(/^[-*][ \t]+/, '') : line)
151
201
  if (content === '') continue
202
+ const bounded =
203
+ content.length > WHATS_NEW_ITEM_MAX_CHARS
204
+ ? `${content.slice(0, WHATS_NEW_ITEM_MAX_CHARS - 1)}…`
205
+ : content
152
206
  const group = groups.at(-1)
153
207
  if (group === undefined) {
154
- groups.push({ heading: null, items: [content] })
208
+ groups.push({ heading: null, items: [bounded] })
155
209
  } else if (isBullet || group.items.length === 0) {
156
- group.items.push(content)
210
+ group.items.push(bounded)
157
211
  } else {
158
- group.items[group.items.length - 1] = `${group.items.at(-1)} ${content}`.trim()
212
+ group.items[group.items.length - 1] = `${group.items.at(-1)} ${bounded}`.trim()
159
213
  }
160
214
  if (isBullet) totalItems += 1
161
215
  }
@@ -27,11 +27,49 @@ import { markSeenWhatsNew, shouldShowWhatsNew } from './whats-new-state.ts'
27
27
  /** Muted footer hint teaching the dismiss bind (Portuguese, like the sidebar). */
28
28
  export const WHATS_NEW_CLOSE_HINT = 'esc/q fechar'
29
29
 
30
+ /** Hint variant when the highlights span more than one page. */
31
+ export const WHATS_NEW_PAGES_HINT = 'esc/q fechar · n próxima · p volta'
32
+
33
+ /** The CHANGELOG pointer shown under the highlights (the window summarizes; the file is complete). */
34
+ export const WHATS_NEW_MORE_HINT = 'CHANGELOG completo: CHANGELOG.md no pacote'
35
+
36
+ /** Rows per page — bounded so no changelog can overflow the terminal. */
37
+ export const WHATS_NEW_PAGE_SIZE = 14
38
+
39
+ /** Hard-wrap one display line into rows of at most `width` columns (>= 10). */
40
+ export function wrapWhatsNewLine(line: string, width: number): string[] {
41
+ const bounded = Number.isInteger(width) && width > 10 ? width : 76
42
+ const text = String(line)
43
+ if (text.length <= bounded) return [text]
44
+ const rows: string[] = []
45
+ let rest = text
46
+ while (rest.length > bounded) {
47
+ rows.push(rest.slice(0, bounded))
48
+ rest = rest.slice(bounded)
49
+ }
50
+ if (rest.length > 0) rows.push(rest)
51
+ return rows
52
+ }
53
+
54
+ /** Slice display lines into fixed-size pages (>= 1 page, empty-safe). */
55
+ export function paginateWhatsNewLines(
56
+ lines: string[],
57
+ pageSize: number = WHATS_NEW_PAGE_SIZE,
58
+ ): string[][] {
59
+ const size = Number.isInteger(pageSize) && pageSize > 0 ? pageSize : WHATS_NEW_PAGE_SIZE
60
+ if (lines.length === 0) return [[]]
61
+ const pages: string[][] = []
62
+ for (let i = 0; i < lines.length; i += size) pages.push(lines.slice(i, i + size))
63
+ return pages
64
+ }
65
+
30
66
  /** Everything the window needs to render — no host types, no JSX. */
31
67
  export interface WhatsNewViewData {
32
68
  version: string
33
69
  title: string
34
70
  lines: string[]
71
+ /** Fixed-size pages of `lines` (single page when the highlights are short). */
72
+ pages: string[][]
35
73
  hint: string
36
74
  }
37
75
 
@@ -64,11 +102,13 @@ export async function openWhatsNew(input: WhatsNewOpenInput): Promise<boolean> {
64
102
  const lines = whatsNewLines(highlights)
65
103
  if (lines.length === 0) return false
66
104
 
105
+ const pages = paginateWhatsNewLines(lines)
67
106
  const data: WhatsNewViewData = {
68
107
  version,
69
108
  title: whatsNewTitle(version),
70
109
  lines,
71
- hint: WHATS_NEW_CLOSE_HINT,
110
+ pages,
111
+ hint: pages.length > 1 ? WHATS_NEW_PAGES_HINT : WHATS_NEW_CLOSE_HINT,
72
112
  }
73
113
  show(
74
114
  () => data,
@@ -10,8 +10,13 @@
10
10
  * awaited — startup must never block). The decision lives in
11
11
  * whats-new-open.ts; this file is only the host glue + view:
12
12
  * `context.ui.dialog.show` plus a keymap layer gated on the open signal so
13
- * `escape`/`q` dismiss while (and only while) the window is up — the same
14
- * gated-layer pattern as the dispatch panel.
13
+ * `escape`/`q` dismiss and `n`/`p` flip pages while (and only while) the
14
+ * window is up — the same gated-layer pattern as the dispatch panel.
15
+ *
16
+ * The window shows the curated 🆕 What's New summary (whats-new-highlights
17
+ * prefers it), hard-wrapped to the window width and sliced into fixed-size
18
+ * pages — a big changelog can never overflow the terminal; the footer points
19
+ * at the complete CHANGELOG.md.
15
20
  *
16
21
  * Deliberately V2-only: the two dist entries are self-contained (the V1
17
22
  * sidebar mirrors the preset resolver rather than importing it) because any
@@ -29,22 +34,37 @@
29
34
  import type { Context } from '@opencode/plugin/tui/context'
30
35
  import { createSignal, For } from 'solid-js'
31
36
  import { readChangelogForBundle, resolveRunningVersion } from './whats-new-highlights.ts'
32
- import { openWhatsNew, type WhatsNewViewData } from './whats-new-open.ts'
37
+ import { openWhatsNew, type WhatsNewViewData, wrapWhatsNewLine } from './whats-new-open.ts'
33
38
  import { defaultWhatsNewStatePath } from './whats-new-state.ts'
34
39
 
35
- /** Window body: title, rule, bounded highlight lines, dismiss hint. */
36
- export function WhatsNewContent(props: { data: WhatsNewViewData; fg?: any; muted?: any }) {
40
+ /** Window body: title, rule, the current page (wrapped), footer hint. */
41
+ export function WhatsNewContent(props: {
42
+ data: WhatsNewViewData
43
+ page: () => number
44
+ pageCount: () => number
45
+ fg?: any
46
+ muted?: any
47
+ }) {
48
+ const rows = () => {
49
+ const current = props.data.pages[Math.min(props.page(), props.pageCount() - 1)] ?? []
50
+ const wrapped: string[] = []
51
+ for (const line of current) wrapped.push(...wrapWhatsNewLine(line, 76))
52
+ return wrapped
53
+ }
37
54
  return (
38
55
  <box flexDirection="column" paddingLeft={1} paddingRight={1} paddingTop={1}>
39
56
  <text attributes={1} fg={props.fg}>
40
57
  {props.data.title}
41
58
  </text>
42
59
  <text fg={props.muted}>{'─'.repeat(38)}</text>
43
- <For each={props.data.lines}>
60
+ <For each={rows()}>
44
61
  {(line: string) => <text fg={line.startsWith('• ') ? props.fg : props.muted}>{line}</text>}
45
62
  </For>
46
63
  <box height={1} />
47
- <text fg={props.muted}>{props.data.hint}</text>
64
+ <text fg={props.muted}>
65
+ {props.pageCount() > 1 ? `${props.page() + 1}/${props.pageCount()} · ` : ''}
66
+ {props.data.hint}
67
+ </text>
48
68
  </box>
49
69
  )
50
70
  }
@@ -61,6 +81,9 @@ export async function maybeShowWhatsNewV2(context: Context): Promise<void> {
61
81
  const changelogText = await readChangelogForBundle(import.meta.url)
62
82
 
63
83
  const [open, setOpen] = createSignal(false)
84
+ const [page, setPage] = createSignal(0)
85
+ let viewData: WhatsNewViewData | undefined
86
+ const pageCount = () => Math.max(1, Math.ceil(viewData?.pages.length ?? 1))
64
87
  let dismiss: () => void = () => {}
65
88
  try {
66
89
  // Gated layer: inert (all keys fall through) while the window is closed.
@@ -78,6 +101,26 @@ export async function maybeShowWhatsNewV2(context: Context): Promise<void> {
78
101
  return undefined
79
102
  },
80
103
  },
104
+ {
105
+ id: 'pantheon.whats-new.next',
106
+ title: 'Próxima página',
107
+ bind: 'n,right',
108
+ run: () => {
109
+ if (!open()) return false
110
+ setPage((current) => Math.min(current + 1, pageCount() - 1))
111
+ return undefined
112
+ },
113
+ },
114
+ {
115
+ id: 'pantheon.whats-new.prev',
116
+ title: 'Página anterior',
117
+ bind: 'p,left',
118
+ run: () => {
119
+ if (!open()) return false
120
+ setPage((current) => Math.max(current - 1, 0))
121
+ return undefined
122
+ },
123
+ },
81
124
  ],
82
125
  }))
83
126
  } catch {
@@ -101,11 +144,21 @@ export async function maybeShowWhatsNewV2(context: Context): Promise<void> {
101
144
  }
102
145
  close()
103
146
  }
147
+ viewData = render()
148
+ setPage(0)
104
149
  setOpen(true)
105
150
  try {
106
151
  const theme = context.theme?.text ?? {}
107
152
  context.ui.dialog.show(
108
- () => <WhatsNewContent data={render()} fg={theme.base} muted={theme.muted} />,
153
+ () => (
154
+ <WhatsNewContent
155
+ data={viewData as WhatsNewViewData}
156
+ page={page}
157
+ pageCount={pageCount}
158
+ fg={theme.base}
159
+ muted={theme.muted}
160
+ />
161
+ ),
109
162
  close,
110
163
  )
111
164
  } catch {
package/src/routing.yml CHANGED
@@ -174,9 +174,11 @@ agents:
174
174
  - talos
175
175
  skills:
176
176
  - agent-coordination
177
+ - agent-forge
177
178
  - artifact-management
178
179
  - auto-continue
179
180
  - codemap
181
+ - prompt-refinery
180
182
  - context-compression
181
183
  - incremental-implementation
182
184
  - loop-engineering
@@ -4,7 +4,7 @@
4
4
 
5
5
  Skills are reference modules loaded on demand by agents. Each skill provides domain-specific knowledge — architecture patterns, security checklists, optimization strategies, and implementation guides. Agents load skills when their task matches the skill's description, keeping context focused and token-efficient.
6
6
 
7
- There are **20 skills** divided into **5 domains**.
7
+ There are **22 skills** divided into **5 domains**.
8
8
 
9
9
  ## Skills by Domain
10
10
 
@@ -0,0 +1,76 @@
1
+ ---
2
+ name: agent-forge
3
+ description: "Forge a new OpenCode agent on demand. Use when the user asks for 'um agente que faça X', 'create an agent for X', or wants a specialist the roster lacks."
4
+ ---
5
+
6
+ # Agent Forge
7
+
8
+ > **A new agent is a contract, not a vibe. Interview, draft against the canonical shape, confirm, forge — and never shadow an existing specialist.**
9
+
10
+ ---
11
+
12
+ ## When this fires
13
+
14
+ - The user asks for a dedicated agent ("cria um agente de reviews de PR", "I want an agent that watches deploys").
15
+ - A recurring task keeps being delegated with ad-hoc Briefs and would benefit from a standing definition.
16
+
17
+ Do NOT fire when an existing specialist covers the domain — route there instead (the 14 canonical agents + any agents already forged in this project).
18
+
19
+ ---
20
+
21
+ ## The interview (before any writing)
22
+
23
+ Ask AT MOST four questions, with your recommended default on each so silence proceeds:
24
+
25
+ 1. **Gap** — what recurring task/domain should this agent own? (default: infer from the request)
26
+ 2. **Surface** — which tools does it need? read-only, edit, shell, webfetch, MCP grants? (default: least privilege that can do the job)
27
+ 3. **Scope** — project (`.opencode/agents/`) or user-global (`~/.config/opencode/agents/`)? (default: project)
28
+ 4. **Model posture** — reasoning effort low/medium/high (default: medium; low for narrow mechanical agents).
29
+
30
+ Then present the draft definition for confirm-or-adjust BEFORE writing (the same contract discipline as prompt-refinery).
31
+
32
+ ---
33
+
34
+ ## The forged file (canonical shape)
35
+
36
+ ```markdown
37
+ ---
38
+ name: <kebab-id> # must NOT collide with the 14 canonical ids
39
+ description: "<what it owns> — <domain keywords for routing>. Use when <trigger>."
40
+ mode: subagent # or 'all' when it may also be invoked directly
41
+ reasoning_effort: low|medium|high
42
+ permission:
43
+ read: allow
44
+ grep: allow
45
+ glob: allow
46
+ edit: allow|deny # least privilege from the interview
47
+ shell: allow|deny
48
+ webfetch: allow|deny
49
+ task: { "*": deny } # forged agents do not dispatch by default
50
+ mcp_tools: # ONLY registered servers/tools; 'all' or exact lists
51
+ pantheon-resources: all
52
+ skills: [] # add only installed, reviewed skills
53
+ ---
54
+
55
+ ## MCP governance (identical ladder, grant-aware)
56
+ <copy the governance ladder block verbatim from any canonical agent — the
57
+ escalation order and cost rules are identical for every agent.>
58
+
59
+ ## Role
60
+ <2-4 sentences: what it owns, what it NEVER does, and where it escalates.>
61
+ ```
62
+
63
+ Rules that are NOT optional:
64
+
65
+ - **No collision** — the id must differ from every canonical agent and every already-forged agent in scope; on collision, propose a distinguishable name.
66
+ - **Grants must exist** — every `mcp_tools` entry names a server/tool that is actually registered; an exact list beats `all` whenever the role is narrow.
67
+ - **Governance identical** — the ladder block is byte-copied from a canonical agent; a forged agent never invents its own escalation rules.
68
+ - **Never overwrite** — if the target file exists, show it and ask before replacing.
69
+ - **Routing honesty** — project agents are picked up by the host automatically; do not claim they are in `routing.yml` or the decision catalogs (those are package-level and validated by tests).
70
+ - **Referência de fluxo**: o `skill-creator` da Anthropic (entender objetivo → quando ativa → formato → como testar → rascunho → iterar) é o precedentes do nosso interview → draft → confirm.
71
+
72
+ ---
73
+
74
+ ## After forging
75
+
76
+ Tell the user: restart OpenCode (or start a new session) for the host to load the new agent; invoke it with `@<name>`. If the agent should also appear in the local decision routing later, that is a package-level change — note it as a follow-up, never silently.