pantheon-opencode 1.6.3-beta.2 → 1.6.3-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +5 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router.mjs +26 -1
- package/scripts/install/decision-router-config.mjs +45 -0
- package/scripts/install/interactive.mjs +35 -2
- package/scripts/install/plugin.mjs +17 -0
- package/scripts/sync-tui.mjs +11 -0
- package/src/pantheon/j-telemetry-file.ts +96 -0
- package/src/plugin-v2.ts +9 -2
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +457 -4
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/index-v2.tsx +6 -0
- package/src/plugins/tui/src/whats-new-highlights.ts +263 -0
- package/src/plugins/tui/src/whats-new-open.ts +80 -0
- package/src/plugins/tui/src/whats-new-state.ts +128 -0
- package/src/plugins/tui/src/whats-new.tsx +119 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* whats-new-highlights.ts — release highlights for the one-time "What's new"
|
|
3
|
+
* window, extracted from the CHANGELOG.md shipped with the plugin copy.
|
|
4
|
+
*
|
|
5
|
+
* The section-finding logic is an inline replica of scripts/changelog-extract.mjs
|
|
6
|
+
* `extractSection` (pinned by a parity test in tests/tui-whats-new.test.mjs):
|
|
7
|
+
* the copied plugin ships only dist/ + package.json (+ CHANGELOG.md, copied by
|
|
8
|
+
* both installers), so it cannot reach scripts/ at runtime — the same reason
|
|
9
|
+
* the preset resolver is mirrored in index.tsx/index-v2.tsx rather than
|
|
10
|
+
* imported. The script's CLI main is NOT replicated; the plugin only needs the
|
|
11
|
+
* pure extraction.
|
|
12
|
+
*
|
|
13
|
+
* Everything is reduced to bounded plain text: no markdown syntax artifacts,
|
|
14
|
+
* at most WHATS_NEW_MAX_ITEMS bullets. Missing CHANGELOG.md, an unknown
|
|
15
|
+
* version or an empty section all resolve to an empty highlight set — the
|
|
16
|
+
* window simply does not show (fail-open, like the rest of the plugin).
|
|
17
|
+
*/
|
|
18
|
+
import { readFile } from 'node:fs/promises'
|
|
19
|
+
import { dirname, join } from 'node:path'
|
|
20
|
+
import { fileURLToPath } from 'node:url'
|
|
21
|
+
|
|
22
|
+
/** Hard cap on bullets shown in the window (the remainder is counted). */
|
|
23
|
+
export const WHATS_NEW_MAX_ITEMS = 12
|
|
24
|
+
|
|
25
|
+
/** Prefix of the "+N more" line appended when the bullet budget is exceeded. */
|
|
26
|
+
export const WHATS_NEW_MORE_PREFIX = '… +'
|
|
27
|
+
|
|
28
|
+
/** H3 subsection headings are kept as plain-text group labels. */
|
|
29
|
+
export interface WhatsNewGroup {
|
|
30
|
+
heading: string | null
|
|
31
|
+
items: string[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface WhatsNewHighlights {
|
|
35
|
+
/** Normalized version the highlights belong to (null when not found). */
|
|
36
|
+
version: string | null
|
|
37
|
+
found: boolean
|
|
38
|
+
groups: WhatsNewGroup[]
|
|
39
|
+
/** Total bullets in the section, before the WHATS_NEW_MAX_ITEMS cut. */
|
|
40
|
+
totalItems: number
|
|
41
|
+
/** True when totalItems exceeded WHATS_NEW_MAX_ITEMS. */
|
|
42
|
+
truncated: boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const EMPTY_HIGHLIGHTS: WhatsNewHighlights = {
|
|
46
|
+
version: null,
|
|
47
|
+
found: false,
|
|
48
|
+
groups: [],
|
|
49
|
+
totalItems: 0,
|
|
50
|
+
truncated: false,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Escape regex metacharacters so a version like 1.0.0 matches literally. */
|
|
54
|
+
function escapeRegExp(text: string): string {
|
|
55
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Extract the body of a version section from changelog text — inline replica
|
|
60
|
+
* of scripts/changelog-extract.mjs `extractSection` (see that file for the
|
|
61
|
+
* full contract: `## [<version>] - YYYY-MM-DD`, leading `v` and the date
|
|
62
|
+
* optional, `## [Unreleased]` never matched).
|
|
63
|
+
*/
|
|
64
|
+
export function extractSection(
|
|
65
|
+
changelogText: string,
|
|
66
|
+
version: string,
|
|
67
|
+
): { found: boolean; body: string | null } {
|
|
68
|
+
const normalized = String(version).trim().replace(/^v/i, '')
|
|
69
|
+
if (!normalized || /^unreleased$/i.test(normalized)) return { found: false, body: null }
|
|
70
|
+
|
|
71
|
+
const escaped = escapeRegExp(normalized)
|
|
72
|
+
// Single-line heading: `## [v?1.2.1]` optionally followed by ` - YYYY-MM-DD`.
|
|
73
|
+
// [ \t] (not \s) keeps the match from crossing newlines; the lookahead
|
|
74
|
+
// requires end-of-line or whitespace so `[1.0.0-beta]` can never match `1.0.0`.
|
|
75
|
+
const headingRe = new RegExp(
|
|
76
|
+
`^##[ \\t]+\\[v?${escaped}\\](?:[ \\t]*-[ \\t]*\\d{4}-\\d{2}-\\d{2})?(?=[ \\t]|$)`,
|
|
77
|
+
'm',
|
|
78
|
+
)
|
|
79
|
+
const match = headingRe.exec(changelogText)
|
|
80
|
+
if (!match) return { found: false, body: null }
|
|
81
|
+
|
|
82
|
+
// Advance past the heading line (match.index may point mid-line).
|
|
83
|
+
const newline = changelogText.indexOf('\n', match.index)
|
|
84
|
+
const start = newline === -1 ? changelogText.length : newline + 1
|
|
85
|
+
|
|
86
|
+
// Body ends at the next `## [` heading or end of text.
|
|
87
|
+
const nextHeading = /^##[ \t]+\[/m.exec(changelogText.slice(start))
|
|
88
|
+
const end = nextHeading ? start + nextHeading.index : changelogText.length
|
|
89
|
+
|
|
90
|
+
return { found: true, body: changelogText.slice(start, end).trim() }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Reduce one markdown line to plain text: links keep their label, emphasis
|
|
95
|
+
* and inline-code markers are dropped, HTML comment fragments are removed,
|
|
96
|
+
* and whitespace collapses. Deliberately simple — the input is our own
|
|
97
|
+
* CHANGELOG (lint-capped at 200 chars per bullet), not hostile input.
|
|
98
|
+
*/
|
|
99
|
+
export function stripMarkdown(text: string): string {
|
|
100
|
+
return text
|
|
101
|
+
.replace(/<!--[\s\S]*?-->/g, ' ')
|
|
102
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
|
|
103
|
+
.replace(/(\*\*|__)/g, '')
|
|
104
|
+
.replace(/`/g, '')
|
|
105
|
+
.replace(/\s+/g, ' ')
|
|
106
|
+
.trim()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Strip the leading H3 marker (`### Added` → `Added`). */
|
|
110
|
+
function stripHeading(text: string): string {
|
|
111
|
+
return text.replace(/^#{1,6}[ \t]+/, '').trim()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Extract the release highlights for `version`: H3 subsection headings as
|
|
116
|
+
* group labels and their bullets as sanitized plain text, bounded to
|
|
117
|
+
* WHATS_NEW_MAX_ITEMS bullets. A missing section, a bullet-less section or a
|
|
118
|
+
* blank changelog all return EMPTY_HIGHLIGHTS (no window).
|
|
119
|
+
*/
|
|
120
|
+
export function extractHighlights(changelogText: string, version: string): WhatsNewHighlights {
|
|
121
|
+
const { found, body } = extractSection(changelogText ?? '', version ?? '')
|
|
122
|
+
if (!found || !body) return { ...EMPTY_HIGHLIGHTS }
|
|
123
|
+
|
|
124
|
+
const groups: WhatsNewGroup[] = []
|
|
125
|
+
let totalItems = 0
|
|
126
|
+
let truncated = false
|
|
127
|
+
|
|
128
|
+
for (const rawLine of body.split('\n')) {
|
|
129
|
+
const line = rawLine.trim()
|
|
130
|
+
if (line === '' || line.startsWith('<!--')) continue
|
|
131
|
+
|
|
132
|
+
if (/^#{1,6}[ \t]/.test(line)) {
|
|
133
|
+
const heading = stripMarkdown(stripHeading(line))
|
|
134
|
+
if (heading === '') continue
|
|
135
|
+
if (groups.at(-1)?.items.length === 0) groups.pop() // empty group boundary
|
|
136
|
+
groups.push({ heading, items: [] })
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (totalItems >= WHATS_NEW_MAX_ITEMS) {
|
|
141
|
+
// Keep scanning only to count the remainder for the "+N more" line.
|
|
142
|
+
if (/^[-*][ \t]/.test(line)) totalItems += 1
|
|
143
|
+
continue
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const isBullet = /^[-*][ \t]/.test(line)
|
|
147
|
+
const continuation = (groups.at(-1)?.items.length ?? 0) > 0
|
|
148
|
+
if (!isBullet && !continuation) continue // prose between groups — not a highlight
|
|
149
|
+
|
|
150
|
+
const content = stripMarkdown(isBullet ? line.replace(/^[-*][ \t]+/, '') : line)
|
|
151
|
+
if (content === '') continue
|
|
152
|
+
const group = groups.at(-1)
|
|
153
|
+
if (group === undefined) {
|
|
154
|
+
groups.push({ heading: null, items: [content] })
|
|
155
|
+
} else if (isBullet || group.items.length === 0) {
|
|
156
|
+
group.items.push(content)
|
|
157
|
+
} else {
|
|
158
|
+
group.items[group.items.length - 1] = `${group.items.at(-1)} ${content}`.trim()
|
|
159
|
+
}
|
|
160
|
+
if (isBullet) totalItems += 1
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const kept = groups.filter((group) => group.items.length > 0)
|
|
164
|
+
truncated = totalItems > WHATS_NEW_MAX_ITEMS
|
|
165
|
+
return {
|
|
166
|
+
version: found ? String(version).trim().replace(/^v/i, '') : null,
|
|
167
|
+
found,
|
|
168
|
+
groups: kept,
|
|
169
|
+
totalItems,
|
|
170
|
+
truncated,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Window title — mirrors the sidebar's `Pantheon v<version>` convention. */
|
|
175
|
+
export function whatsNewTitle(version: string): string {
|
|
176
|
+
return `O que há de novo — Pantheon v${String(version).trim().replace(/^v/i, '')}`
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Flat display lines for the window: group headings, `• ` bullets, `+N more`. */
|
|
180
|
+
export function whatsNewLines(highlights: WhatsNewHighlights): string[] {
|
|
181
|
+
const lines: string[] = []
|
|
182
|
+
for (const group of highlights.groups) {
|
|
183
|
+
if (group.heading !== null) lines.push(group.heading)
|
|
184
|
+
for (const item of group.items) lines.push(`• ${item}`)
|
|
185
|
+
}
|
|
186
|
+
if (highlights.truncated) {
|
|
187
|
+
const hidden = Math.max(0, highlights.totalItems - WHATS_NEW_MAX_ITEMS)
|
|
188
|
+
if (hidden > 0) lines.push(`${WHATS_NEW_MORE_PREFIX}${hidden} mais`)
|
|
189
|
+
}
|
|
190
|
+
return lines
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Candidate CHANGELOG.md locations for a bundle, first readable wins:
|
|
195
|
+
* 1. the plugin copy root (`<configDir>/plugins/pantheon-tui/CHANGELOG.md`,
|
|
196
|
+
* shipped by both installers next to package.json);
|
|
197
|
+
* 2. the package root (dev checkout; also an npm-package install when the
|
|
198
|
+
* bundle runs from `<pkg>/src/plugins/tui/dist/`).
|
|
199
|
+
*/
|
|
200
|
+
export function changelogCandidates(bundlePath: string): string[] {
|
|
201
|
+
const dist = dirname(bundlePath)
|
|
202
|
+
const copyRoot = dirname(dist)
|
|
203
|
+
// The second leg targets the package root: src/plugins/tui → plugins → src
|
|
204
|
+
// → package root (dev checkout / npm-package install). On an installed copy
|
|
205
|
+
// the same three levels land on the XDG base, where no CHANGELOG lives —
|
|
206
|
+
// harmless, the copy-root candidate is the one the installers ship.
|
|
207
|
+
const packageRoot = dirname(dirname(dirname(copyRoot)))
|
|
208
|
+
return [join(copyRoot, 'CHANGELOG.md'), join(packageRoot, 'CHANGELOG.md')]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Read the first existing candidate; null when none is readable (no window). */
|
|
212
|
+
export async function readChangelogForBundle(bundleUrl: string): Promise<string | null> {
|
|
213
|
+
try {
|
|
214
|
+
const bundlePath = fileURLToPath(bundleUrl)
|
|
215
|
+
for (const candidate of changelogCandidates(bundlePath)) {
|
|
216
|
+
try {
|
|
217
|
+
return await readFile(candidate, 'utf8')
|
|
218
|
+
} catch {}
|
|
219
|
+
}
|
|
220
|
+
return null
|
|
221
|
+
} catch {
|
|
222
|
+
return null
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Build-time embedded version (tsdown `define` in tsdown.config.ts). */
|
|
227
|
+
declare const __PANTHEON_VERSION__: string | undefined
|
|
228
|
+
|
|
229
|
+
/** The ambient build-time version, or null outside a tsdown build. */
|
|
230
|
+
export function embeddedVersion(): string | null {
|
|
231
|
+
return typeof __PANTHEON_VERSION__ !== 'undefined' && __PANTHEON_VERSION__
|
|
232
|
+
? __PANTHEON_VERSION__
|
|
233
|
+
: null
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Resolve the running Pantheon version for the what's-new window: the plugin
|
|
238
|
+
* copy's own package.json first (the copy root two levels above the bundle,
|
|
239
|
+
* then the package root four levels above — the same legs as the V1 sidebar's
|
|
240
|
+
* detectVersion try 0a/0b), falling back to the tsdown build embed. Null when
|
|
241
|
+
* nothing resolves → no window (fail-open).
|
|
242
|
+
*/
|
|
243
|
+
export async function resolveRunningVersion(
|
|
244
|
+
bundleUrl: string,
|
|
245
|
+
embedded: string | null = embeddedVersion(),
|
|
246
|
+
): Promise<string | null> {
|
|
247
|
+
try {
|
|
248
|
+
const bundlePath = fileURLToPath(bundleUrl)
|
|
249
|
+
const dist = dirname(bundlePath)
|
|
250
|
+
for (const root of [dirname(dist), dirname(dirname(dirname(dist)))]) {
|
|
251
|
+
try {
|
|
252
|
+
const raw = await readFile(join(root, 'package.json'), 'utf8')
|
|
253
|
+
const parsed = JSON.parse(raw) as { version?: unknown }
|
|
254
|
+
if (typeof parsed.version === 'string' && parsed.version.trim() !== '') {
|
|
255
|
+
return parsed.version
|
|
256
|
+
}
|
|
257
|
+
} catch {}
|
|
258
|
+
}
|
|
259
|
+
} catch {
|
|
260
|
+
/* fall through to the embed */
|
|
261
|
+
}
|
|
262
|
+
return embedded
|
|
263
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* whats-new-open.ts — the show-once decision for the "What's new" window.
|
|
3
|
+
*
|
|
4
|
+
* Plain data in, plain data out: the entrypoints (index.tsx / index-v2.tsx)
|
|
5
|
+
* resolve the running version and the shipped CHANGELOG.md, then hand this
|
|
6
|
+
* module a `show` callback that renders the view data through the host's
|
|
7
|
+
* dialog API. Keeping the decision JSX-free makes the whole one-time flow
|
|
8
|
+
* testable offline (node strips the types natively) — the Solid glue lives in
|
|
9
|
+
* whats-new.tsx.
|
|
10
|
+
*
|
|
11
|
+
* Contract (pinned by tests/tui-whats-new.test.mjs):
|
|
12
|
+
* - shows at most once per version: dismissal marks the version seen;
|
|
13
|
+
* - nothing to show (no version, missing CHANGELOG, empty section) → no
|
|
14
|
+
* window AND no pin — the next start may still show it;
|
|
15
|
+
* - never throws on its own inputs; I/O failures inside the state module
|
|
16
|
+
* are fail-open there.
|
|
17
|
+
*/
|
|
18
|
+
import {
|
|
19
|
+
EMPTY_HIGHLIGHTS,
|
|
20
|
+
extractHighlights,
|
|
21
|
+
type WhatsNewHighlights,
|
|
22
|
+
whatsNewLines,
|
|
23
|
+
whatsNewTitle,
|
|
24
|
+
} from './whats-new-highlights.ts'
|
|
25
|
+
import { markSeenWhatsNew, shouldShowWhatsNew } from './whats-new-state.ts'
|
|
26
|
+
|
|
27
|
+
/** Muted footer hint teaching the dismiss bind (Portuguese, like the sidebar). */
|
|
28
|
+
export const WHATS_NEW_CLOSE_HINT = 'esc/q fechar'
|
|
29
|
+
|
|
30
|
+
/** Everything the window needs to render — no host types, no JSX. */
|
|
31
|
+
export interface WhatsNewViewData {
|
|
32
|
+
version: string
|
|
33
|
+
title: string
|
|
34
|
+
lines: string[]
|
|
35
|
+
hint: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type WhatsNewShowFn = (render: () => WhatsNewViewData, onClose: () => void) => void
|
|
39
|
+
|
|
40
|
+
export interface WhatsNewOpenInput {
|
|
41
|
+
/** Running Pantheon version (null when unresolvable → no window). */
|
|
42
|
+
version: string | null
|
|
43
|
+
/** Path of the seen-version state file (see whats-new-state.ts). */
|
|
44
|
+
statePath: string
|
|
45
|
+
/** Shipped CHANGELOG.md content, or null when unreadable. */
|
|
46
|
+
changelogText: string | null
|
|
47
|
+
/** Host dialog opener; `onClose` fires on host dismissal (ESC / chrome). */
|
|
48
|
+
show: WhatsNewShowFn
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Open the one-time window when the version changed and highlights exist.
|
|
53
|
+
* Returns true when the window was shown; the caller's `onClose` callback
|
|
54
|
+
* (both host-initiated and local close binds) must funnel into marking seen.
|
|
55
|
+
*/
|
|
56
|
+
export async function openWhatsNew(input: WhatsNewOpenInput): Promise<boolean> {
|
|
57
|
+
const { version, statePath, changelogText, show } = input
|
|
58
|
+
if (typeof version !== 'string' || version.trim() === '') return false
|
|
59
|
+
if (!(await shouldShowWhatsNew(version, statePath))) return false
|
|
60
|
+
|
|
61
|
+
const highlights: WhatsNewHighlights = changelogText
|
|
62
|
+
? extractHighlights(changelogText, version)
|
|
63
|
+
: { ...EMPTY_HIGHLIGHTS }
|
|
64
|
+
const lines = whatsNewLines(highlights)
|
|
65
|
+
if (lines.length === 0) return false
|
|
66
|
+
|
|
67
|
+
const data: WhatsNewViewData = {
|
|
68
|
+
version,
|
|
69
|
+
title: whatsNewTitle(version),
|
|
70
|
+
lines,
|
|
71
|
+
hint: WHATS_NEW_CLOSE_HINT,
|
|
72
|
+
}
|
|
73
|
+
show(
|
|
74
|
+
() => data,
|
|
75
|
+
() => {
|
|
76
|
+
void markSeenWhatsNew(version, statePath)
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
return true
|
|
80
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* whats-new-state.ts — last-seen version for the one-time "What's new" window.
|
|
3
|
+
*
|
|
4
|
+
* The TUI shows a dismissable release-highlights dialog once per Pantheon
|
|
5
|
+
* version. Whether a version was already seen is persisted next to the other
|
|
6
|
+
* opencode-level Pantheon state: `<configDir>/.pantheon/whats-new.json`, the
|
|
7
|
+
* same directory that already holds `install-state.json` (scripts/install/
|
|
8
|
+
* state.mjs) and the active-preset file the sidebar reads. There is no
|
|
9
|
+
* established persistent TUI KV store (the host `api.kv` is per-process), so
|
|
10
|
+
* the plugin owns one small JSON file with the atomic-write discipline used
|
|
11
|
+
* across the repo (unique tmp + rename, mirrors scripts/install/verify.mjs).
|
|
12
|
+
*
|
|
13
|
+
* Fail-open everywhere: a missing or corrupt file reads as "never seen" (the
|
|
14
|
+
* window may show), a failed write is silent (the window may show again) —
|
|
15
|
+
* neither can ever block TUI startup.
|
|
16
|
+
*/
|
|
17
|
+
import { mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises'
|
|
18
|
+
import { homedir } from 'node:os'
|
|
19
|
+
import { dirname, join } from 'node:path'
|
|
20
|
+
|
|
21
|
+
/** State file name, kept next to `install-state.json` in `<configDir>/.pantheon/`. */
|
|
22
|
+
export const WHATS_NEW_STATE_FILENAME = 'whats-new.json'
|
|
23
|
+
|
|
24
|
+
/** Shape of the persisted file — the plugin owns this file outright. */
|
|
25
|
+
export interface WhatsNewStateFile {
|
|
26
|
+
seenVersion: string | null
|
|
27
|
+
updatedAt: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type Env = Record<string, string | undefined>
|
|
31
|
+
|
|
32
|
+
/** Parse a state file body; null when unreadable as the expected shape. */
|
|
33
|
+
export function parseWhatsNewState(raw: string): WhatsNewStateFile | null {
|
|
34
|
+
try {
|
|
35
|
+
const parsed: unknown = JSON.parse(raw)
|
|
36
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return null
|
|
37
|
+
const record = parsed as Record<string, unknown>
|
|
38
|
+
const seen = record.seenVersion
|
|
39
|
+
if (typeof seen !== 'string' && seen !== null) return null
|
|
40
|
+
return { seenVersion: seen, updatedAt: String(record.updatedAt ?? '') }
|
|
41
|
+
} catch {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Read the persisted state; null when missing or corrupt (never throws). */
|
|
47
|
+
export async function readWhatsNewState(statePath: string): Promise<WhatsNewStateFile | null> {
|
|
48
|
+
try {
|
|
49
|
+
return parseWhatsNewState(await readFile(statePath, 'utf8'))
|
|
50
|
+
} catch {
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether the one-time window should show for `version`: any version change
|
|
57
|
+
* since the last dismissal (including downgrades). A falsy version — the
|
|
58
|
+
* resolver failed — never shows.
|
|
59
|
+
*/
|
|
60
|
+
export async function shouldShowWhatsNew(
|
|
61
|
+
version: string | null | undefined,
|
|
62
|
+
statePath: string,
|
|
63
|
+
): Promise<boolean> {
|
|
64
|
+
if (typeof version !== 'string' || version.trim() === '') return false
|
|
65
|
+
const state = await readWhatsNewState(statePath)
|
|
66
|
+
return state?.seenVersion !== version
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Persist `version` as seen (atomic tmp + rename, 0o600). Never throws: a
|
|
71
|
+
* failed write leaves the state untouched and the window may show again —
|
|
72
|
+
* the same fail-open contract as the rest of the plugin.
|
|
73
|
+
*/
|
|
74
|
+
export async function markSeenWhatsNew(version: string, statePath: string): Promise<boolean> {
|
|
75
|
+
if (typeof version !== 'string' || version.trim() === '') return false
|
|
76
|
+
const previous = await readWhatsNewState(statePath)
|
|
77
|
+
const next: WhatsNewStateFile = {
|
|
78
|
+
seenVersion: version,
|
|
79
|
+
updatedAt: new Date().toISOString(),
|
|
80
|
+
}
|
|
81
|
+
const tmpPath = `${statePath}.tmp-${process.pid}`
|
|
82
|
+
try {
|
|
83
|
+
await mkdir(dirname(statePath), { recursive: true })
|
|
84
|
+
await writeFile(tmpPath, `${JSON.stringify({ ...previous, ...next }, null, 2)}\n`, {
|
|
85
|
+
encoding: 'utf8',
|
|
86
|
+
mode: 0o600,
|
|
87
|
+
})
|
|
88
|
+
await rename(tmpPath, statePath)
|
|
89
|
+
return true
|
|
90
|
+
} catch {
|
|
91
|
+
try {
|
|
92
|
+
await unlink(tmpPath)
|
|
93
|
+
} catch {
|
|
94
|
+
/* nothing to clean up */
|
|
95
|
+
}
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** `stat`-based existence probe (async I/O discipline). */
|
|
101
|
+
async function pathExists(path: string): Promise<boolean> {
|
|
102
|
+
try {
|
|
103
|
+
await stat(path)
|
|
104
|
+
return true
|
|
105
|
+
} catch {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Default state path: `<configDir>/.pantheon/whats-new.json`, resolving the
|
|
112
|
+
* OpenCode config directory exactly like src/pantheon/tui-version-check.ts
|
|
113
|
+
* (`$XDG_CONFIG_HOME/opencode` → `~/.opencode`), defaulting to the XDG
|
|
114
|
+
* location `init` creates when neither exists yet.
|
|
115
|
+
*/
|
|
116
|
+
export async function defaultWhatsNewStatePath(
|
|
117
|
+
env: Env = process.env,
|
|
118
|
+
home: string = homedir(),
|
|
119
|
+
): Promise<string> {
|
|
120
|
+
const xdgConfig = env.XDG_CONFIG_HOME || join(home, '.config')
|
|
121
|
+
const primary = join(xdgConfig, 'opencode')
|
|
122
|
+
if (await pathExists(primary)) return join(primary, '.pantheon', WHATS_NEW_STATE_FILENAME)
|
|
123
|
+
|
|
124
|
+
const legacy = join(home, '.opencode')
|
|
125
|
+
if (await pathExists(legacy)) return join(legacy, '.pantheon', WHATS_NEW_STATE_FILENAME)
|
|
126
|
+
|
|
127
|
+
return join(primary, '.pantheon', WHATS_NEW_STATE_FILENAME)
|
|
128
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: OpenCode exposes its TUI API at runtime.
|
|
2
|
+
// biome-ignore-all lint/a11y/noStaticElementInteractions: TUI elements, not DOM
|
|
3
|
+
/** @jsxImportSource @opentui/solid */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* whats-new.tsx — the one-time "What's new" window (per Pantheon version).
|
|
7
|
+
*
|
|
8
|
+
* When the running Pantheon version changed since the last TUI start, the V2
|
|
9
|
+
* entrypoint fires {@link maybeShowWhatsNewV2} (fire-and-forget, never
|
|
10
|
+
* awaited — startup must never block). The decision lives in
|
|
11
|
+
* whats-new-open.ts; this file is only the host glue + view:
|
|
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.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately V2-only: the two dist entries are self-contained (the V1
|
|
17
|
+
* sidebar mirrors the preset resolver rather than importing it) because any
|
|
18
|
+
* module shared by both entries becomes a content-hashed chunk in dist/,
|
|
19
|
+
* changing the artifact shape the byte-reproducible-dist gate pins. The V1
|
|
20
|
+
* generation (OpenCode 1.x, legacy) does not show the window; the pure
|
|
21
|
+
* modules here are generation-agnostic, so a V1 mirror can follow the
|
|
22
|
+
* documented inline-replica precedent if it is ever wanted.
|
|
23
|
+
*
|
|
24
|
+
* Dismissal always funnels into `markSeenWhatsNew` (idempotent), so the window
|
|
25
|
+
* is shown exactly once per version. Every failure path is silent: missing
|
|
26
|
+
* CHANGELOG.md, unreadable state, a host API that throws — the window simply
|
|
27
|
+
* does not show (fail-open, like the rest of the plugin).
|
|
28
|
+
*/
|
|
29
|
+
import type { Context } from '@opencode/plugin/tui/context'
|
|
30
|
+
import { createSignal, For } from 'solid-js'
|
|
31
|
+
import { readChangelogForBundle, resolveRunningVersion } from './whats-new-highlights.ts'
|
|
32
|
+
import { openWhatsNew, type WhatsNewViewData } from './whats-new-open.ts'
|
|
33
|
+
import { defaultWhatsNewStatePath } from './whats-new-state.ts'
|
|
34
|
+
|
|
35
|
+
/** Window body: title, rule, bounded highlight lines, dismiss hint. */
|
|
36
|
+
export function WhatsNewContent(props: { data: WhatsNewViewData; fg?: any; muted?: any }) {
|
|
37
|
+
return (
|
|
38
|
+
<box flexDirection="column" paddingLeft={1} paddingRight={1} paddingTop={1}>
|
|
39
|
+
<text attributes={1} fg={props.fg}>
|
|
40
|
+
{props.data.title}
|
|
41
|
+
</text>
|
|
42
|
+
<text fg={props.muted}>{'─'.repeat(38)}</text>
|
|
43
|
+
<For each={props.data.lines}>
|
|
44
|
+
{(line: string) => <text fg={line.startsWith('• ') ? props.fg : props.muted}>{line}</text>}
|
|
45
|
+
</For>
|
|
46
|
+
<box height={1} />
|
|
47
|
+
<text fg={props.muted}>{props.data.hint}</text>
|
|
48
|
+
</box>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Entry glue: resolve version + shipped CHANGELOG.md, then show the window
|
|
54
|
+
* through the host dialog stack once. Never throws.
|
|
55
|
+
*/
|
|
56
|
+
export async function maybeShowWhatsNewV2(context: Context): Promise<void> {
|
|
57
|
+
try {
|
|
58
|
+
const version = await resolveRunningVersion(import.meta.url)
|
|
59
|
+
if (!version) return
|
|
60
|
+
const statePath = await defaultWhatsNewStatePath()
|
|
61
|
+
const changelogText = await readChangelogForBundle(import.meta.url)
|
|
62
|
+
|
|
63
|
+
const [open, setOpen] = createSignal(false)
|
|
64
|
+
let dismiss: () => void = () => {}
|
|
65
|
+
try {
|
|
66
|
+
// Gated layer: inert (all keys fall through) while the window is closed.
|
|
67
|
+
context.keymap.layer(() => ({
|
|
68
|
+
mode: 'global',
|
|
69
|
+
enabled: () => open(),
|
|
70
|
+
commands: [
|
|
71
|
+
{
|
|
72
|
+
id: 'pantheon.whats-new.close',
|
|
73
|
+
title: 'Fechar o que há de novo',
|
|
74
|
+
bind: 'escape,q',
|
|
75
|
+
run: () => {
|
|
76
|
+
if (!open()) return false
|
|
77
|
+
dismiss()
|
|
78
|
+
return undefined
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
}))
|
|
83
|
+
} catch {
|
|
84
|
+
/* keymap API unavailable — the host dialog chrome still dismisses (ESC) */
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
await openWhatsNew({
|
|
88
|
+
version,
|
|
89
|
+
statePath,
|
|
90
|
+
changelogText,
|
|
91
|
+
show: (render, onClose) => {
|
|
92
|
+
const close = () => {
|
|
93
|
+
setOpen(false)
|
|
94
|
+
onClose()
|
|
95
|
+
}
|
|
96
|
+
dismiss = () => {
|
|
97
|
+
try {
|
|
98
|
+
context.ui.dialog.clear()
|
|
99
|
+
} catch {
|
|
100
|
+
/* already closed */
|
|
101
|
+
}
|
|
102
|
+
close()
|
|
103
|
+
}
|
|
104
|
+
setOpen(true)
|
|
105
|
+
try {
|
|
106
|
+
const theme = context.theme?.text ?? {}
|
|
107
|
+
context.ui.dialog.show(
|
|
108
|
+
() => <WhatsNewContent data={render()} fg={theme.base} muted={theme.muted} />,
|
|
109
|
+
close,
|
|
110
|
+
)
|
|
111
|
+
} catch {
|
|
112
|
+
/* dialog stack unavailable — fail-open, retried on the next start */
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
} catch {
|
|
117
|
+
/* fail-open — the window must never block or break TUI startup */
|
|
118
|
+
}
|
|
119
|
+
}
|