pantheon-opencode 2.0.0-beta.1 → 2.0.0-beta.3

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.
@@ -36,17 +36,20 @@ export function comparePantheonVersions(left: string, right: string): number {
36
36
  .trim()
37
37
  .match(/^(\d+)\.(\d+)\.(\d+)(?:-beta\.(\d+))?$/)
38
38
  if (!match) return null
39
+ const [, major = '', minor = '', patch = '', beta = ''] = match
39
40
  return {
40
- core: [+match[1], +match[2], +match[3]],
41
- beta: match[4] === undefined ? Number.POSITIVE_INFINITY : +match[4],
41
+ core: [+major, +minor, +patch] as [number, number, number],
42
+ beta: beta === '' ? Number.POSITIVE_INFINITY : +beta,
42
43
  }
43
44
  }
44
45
  const a = parse(left)
45
46
  const b = parse(right)
46
47
  if (!a || !b) return 0
47
- for (let index = 0; index < 3; index += 1) {
48
- if (a.core[index] !== b.core[index]) return a.core[index] - b.core[index]
49
- }
48
+ const [aMajor, aMinor, aPatch] = a.core
49
+ const [bMajor, bMinor, bPatch] = b.core
50
+ if (aMajor !== bMajor) return aMajor - bMajor
51
+ if (aMinor !== bMinor) return aMinor - bMinor
52
+ if (aPatch !== bPatch) return aPatch - bPatch
50
53
  return a.beta - b.beta
51
54
  }
52
55
 
@@ -79,8 +82,9 @@ export function nextCheckState(
79
82
  notice: UpdateNotice | null,
80
83
  nowMs: number,
81
84
  ): UpdateCheckState {
85
+ const lastNotifiedVersion = notice?.version ?? previous.lastNotifiedVersion
82
86
  return {
83
87
  lastCheckMs: nowMs,
84
- lastNotifiedVersion: notice?.version ?? previous.lastNotifiedVersion,
88
+ ...(lastNotifiedVersion !== undefined ? { lastNotifiedVersion } : {}),
85
89
  }
86
90
  }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * update-status.ts — the Updates section of the settings window.
3
+ *
4
+ * TUI-local; derives rows from the update-notice.ts primitives. The registry
5
+ * fetch and state persistence stay in the .tsx glue (host side) — this module
6
+ * only classifies the channel and builds rows from injected state, so the
7
+ * whole thing is testable without network.
8
+ */
9
+
10
+ import type { SettingsRow, SettingsSection } from './pantheon-settings-state.ts'
11
+ import {
12
+ comparePantheonVersions,
13
+ UPDATE_CHECK_TTL_MS,
14
+ type UpdateCheckState,
15
+ } from './update-notice.ts'
16
+
17
+ export type UpdateChannel = 'stable' | 'beta'
18
+
19
+ /** The running version's channel: a `-beta.N` suffix rides the beta dist-tag. */
20
+ export function updateChannelFor(version: string): UpdateChannel {
21
+ return /-beta\.\d+$/.test(version) ? 'beta' : 'stable'
22
+ }
23
+
24
+ /** The npm dist-tag the registry check should query for the channel. */
25
+ export function registryTagForChannel(channel: UpdateChannel): string {
26
+ return channel === 'beta' ? 'beta' : 'latest'
27
+ }
28
+
29
+ export function registryUrlForChannel(channel: UpdateChannel): string {
30
+ return `https://registry.npmjs.org/pantheon-opencode/${registryTagForChannel(channel)}`
31
+ }
32
+
33
+ function formatAgo(ms: number): string {
34
+ if (ms < 60_000) return 'just now'
35
+ if (ms < 3_600_000) return `${Math.floor(ms / 60_000)}m ago`
36
+ if (ms < 86_400_000) return `${Math.floor(ms / 3_600_000)}h ago`
37
+ return `${Math.floor(ms / 86_400_000)}d ago`
38
+ }
39
+
40
+ export interface UpdatesSectionInput {
41
+ currentVersion: string
42
+ state: UpdateCheckState
43
+ /** Latest version seen this session (a check-now inside this window). */
44
+ lastCheckedVersion?: string
45
+ /** A check-now is in flight (this window). */
46
+ checking?: boolean
47
+ nowMs?: number
48
+ }
49
+
50
+ export function buildUpdatesSection(input: UpdatesSectionInput): SettingsSection {
51
+ const nowMs = input.nowMs ?? Date.now()
52
+ const channel = updateChannelFor(input.currentVersion)
53
+ const lastCheckMs = input.state.lastCheckMs
54
+ const latest = input.lastCheckedVersion ?? input.state.lastNotifiedVersion
55
+
56
+ const rows: SettingsRow[] = [
57
+ {
58
+ id: 'update.channel',
59
+ title: `Channel: ${channel}`,
60
+ description: 'stable tracks npm `latest`; beta tracks npm `beta`',
61
+ selectable: false,
62
+ },
63
+ {
64
+ id: 'update.check',
65
+ title: 'Check now',
66
+ description: input.checking
67
+ ? 'checking…'
68
+ : lastCheckMs
69
+ ? `last check ${formatAgo(nowMs - lastCheckMs)}`
70
+ : 'never checked',
71
+ marker: ' → ',
72
+ selectable: true,
73
+ },
74
+ ]
75
+
76
+ if (latest) {
77
+ // Same guard as pickUpdateNotice: a stable install is never advertised a
78
+ // beta — the update CLI owns that crossing (explicit opt-in).
79
+ const stable = (version: string) => !/-beta\.\d+$/.test(version)
80
+ const newer =
81
+ comparePantheonVersions(latest, input.currentVersion) > 0 &&
82
+ !(stable(input.currentVersion) && !stable(latest))
83
+ rows.push({
84
+ id: 'update.latest',
85
+ title: newer ? `Update available: v${latest}` : `Up to date (latest seen v${latest})`,
86
+ description: newer ? 'adopt with `pantheon-opencode update`' : 'checked against the registry',
87
+ marker: newer ? '[!]' : '[✓]',
88
+ selectable: false,
89
+ })
90
+ }
91
+
92
+ return {
93
+ id: 'updates',
94
+ title: 'Updates',
95
+ hint: `refresh = \`pantheon-opencode update\` · notice TTL ${UPDATE_CHECK_TTL_MS / 3_600_000}h`,
96
+ rows,
97
+ }
98
+ }
@@ -1,5 +1,12 @@
1
1
  {
2
- "//": "Typecheck gate for the V2 TUI entry only. `tsc --noEmit` at the package root was a no-op: with no tsconfig in this directory tsc walked up to the repo tsconfig.json, which excludes src/plugins/tui entirely — so nothing here was checked. tsdown bundles without type-checking, which is how an invalid event name (session.updated, absent from the OpenCode V2 event union) shipped in the V2 rewrite. This config points tsc at the V2 entry plus its ambient declarations so a type error in src/index-v2.tsx fails `npm run typecheck`. The V1 entry (src/index.tsx) is intentionally NOT included: it carries pre-existing type errors out of scope for the V2 gate. Keep this file strict JSON — the repo pre-commit `check-json` hook rejects comments.",
2
+ "//": "Typecheck gate for the settings window sources. `tsc --noEmit` at the package root was a no-op: with no tsconfig in this directory tsc walked up to the repo tsconfig.json, which excludes src/plugins/tui entirely — so nothing here was checked. tsdown bundles without type-checking, which is how a missing SettingsRow import type shipped unnoticed. This config points tsc at the settings modules (pure state + view + sections) so a type error there fails `npm run typecheck`. The legacy entry (src/index.tsx) is intentionally NOT included: it carries pre-existing type errors out of scope for this gate. Keep this file strict JSON — the repo pre-commit `check-json` hook rejects comments.",
3
3
  "extends": "./tsconfig.build.json",
4
- "include": ["src/index-v2.tsx", "src/server-v2.ts", "src/opencode.d.ts"]
4
+ "include": [
5
+ "src/pantheon-settings.tsx",
6
+ "src/pantheon-settings-state.ts",
7
+ "src/j1-gate-status.ts",
8
+ "src/update-status.ts",
9
+ "src/update-notice.ts",
10
+ "src/opencode.d.ts"
11
+ ]
5
12
  }