diff --git a/docs/ocm-cli.md b/docs/ocm-cli.md index bf68d46d..8e576cfe 100644 --- a/docs/ocm-cli.md +++ b/docs/ocm-cli.md @@ -39,13 +39,9 @@ Add the TUI plugin entry to your OpenCode config and OpenCode will fetch the pac } ``` -The next time OpenCode starts it will run `bun install` for the plugin. You'll see: +The next time OpenCode starts it will run `bun install` for the plugin. The installer stays quiet so it does not break the TUI layout; after the plugin loads, OpenCode shows a one-time toast confirming where `ocm` was linked. -``` -ocm installed at /Users/you/.local/bin/ocm -``` - -If `~/.local/bin` is not on your PATH, the message will tell you. Add this to your shell rc: +If `~/.local/bin` is not on your PATH, add this to your shell rc: ```bash export PATH="$HOME/.local/bin:$PATH" diff --git a/ocm-cli/scripts/postinstall.mjs b/ocm-cli/scripts/postinstall.mjs index 1b2bb257..0a5c978b 100644 --- a/ocm-cli/scripts/postinstall.mjs +++ b/ocm-cli/scripts/postinstall.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { existsSync, mkdirSync, symlinkSync, unlinkSync, lstatSync, readlinkSync, chmodSync } from 'node:fs' +import { existsSync, mkdirSync, symlinkSync, unlinkSync, lstatSync, readlinkSync, chmodSync, writeFileSync } from 'node:fs' import { homedir } from 'node:os' import { join, resolve, dirname } from 'node:path' import { fileURLToPath } from 'node:url' @@ -26,16 +26,24 @@ if (process.env.npm_config_global === 'true' || process.env.npm_config_global == } const binDir = join(homedir(), '.local', 'bin') +const link = join(binDir, 'ocm') +const noticeDir = join(homedir(), '.config', 'opencode-manager') +const noticeFile = join(noticeDir, 'install-notice.json') + +function writeInstallNotice(pathMissing) { + try { + mkdirSync(noticeDir, { recursive: true }) + writeFileSync(noticeFile, JSON.stringify({ link, binDir, pathMissing }, null, 2), { mode: 0o600 }) + } catch { + } +} try { mkdirSync(binDir, { recursive: true }) -} catch (err) { - process.stderr.write(`ocm-cli: cannot create ${binDir}: ${err.message}\n`) +} catch { process.exit(0) } -const link = join(binDir, 'ocm') - try { const stat = lstatSync(link) if (stat.isSymbolicLink()) { @@ -44,7 +52,6 @@ try { } unlinkSync(link) } else { - process.stderr.write(`ocm-cli: ${link} exists and is not a symlink; leaving alone\n`) process.exit(0) } } catch { @@ -53,15 +60,9 @@ try { try { symlinkSync(target, link) -} catch (err) { - process.stderr.write(`ocm-cli: failed to symlink ${link}: ${err.message}\n`) +} catch { process.exit(0) } -process.stdout.write(`ocm installed at ${link}\n`) - const path = process.env.PATH ?? '' -if (!path.split(':').includes(binDir)) { - process.stdout.write(`note: ${binDir} is not on your PATH. Add to your shell rc:\n`) - process.stdout.write(` export PATH="${binDir}:$PATH"\n`) -} +writeInstallNotice(!path.split(':').includes(binDir)) diff --git a/ocm-cli/src/state.ts b/ocm-cli/src/state.ts index 6eeb3995..96921cc8 100644 --- a/ocm-cli/src/state.ts +++ b/ocm-cli/src/state.ts @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs' +import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs' import { homedir } from 'os' import { dirname, join } from 'path' @@ -11,8 +11,15 @@ export interface OcmState { updatedAt?: number } +export interface InstallNotice { + link: string + binDir: string + pathMissing: boolean +} + const STATE_DIR = join(homedir(), '.config', 'opencode-manager') const STATE_FILE = join(STATE_DIR, 'state.json') +const INSTALL_NOTICE_FILE = join(STATE_DIR, 'install-notice.json') export function getStatePath(): string { return STATE_FILE @@ -41,3 +48,25 @@ export function clearState(): void { writeFileSync(STATE_FILE, '{}', { mode: 0o600 }) } } + +export function readInstallNotice(): InstallNotice | null { + if (!existsSync(INSTALL_NOTICE_FILE)) return null + try { + const raw = readFileSync(INSTALL_NOTICE_FILE, 'utf-8') + const parsed = JSON.parse(raw) as InstallNotice + if (!parsed.link || !parsed.binDir) return null + return parsed + } catch { + return null + } finally { + deleteInstallNotice() + } +} + +function deleteInstallNotice(): void { + try { + unlinkSync(INSTALL_NOTICE_FILE) + } catch { + return + } +} diff --git a/ocm-cli/src/tui-plugin.ts b/ocm-cli/src/tui-plugin.ts index 3d6d092d..c508c7a7 100644 --- a/ocm-cli/src/tui-plugin.ts +++ b/ocm-cli/src/tui-plugin.ts @@ -1,5 +1,5 @@ import type { TuiPluginApi, TuiPluginModule } from './tui-types.js' -import { readState } from './state.js' +import { readInstallNotice, readState } from './state.js' import { getToken } from './keychain.js' import { fetchRepos, toRemoteRepoSummaries } from './manager-repos.js' import { ManagerApi, ManagerApiError } from './manager-api.js' @@ -9,6 +9,7 @@ import { createManagerReplay } from './remote-replay.js' import { readSessionEvents } from './local-history.js' const tui = async (api: TuiPluginApi): Promise => { + showInstallNotice(api) api.keymap.registerLayer({ commands: [ { @@ -24,6 +25,20 @@ const tui = async (api: TuiPluginApi): Promise => { }) } +function showInstallNotice(api: TuiPluginApi): void { + const notice = readInstallNotice() + if (!notice) return + + api.ui.toast({ + variant: 'success', + title: 'ocm installed', + message: notice.pathMissing + ? `Linked at ${notice.link}. Add export PATH="$HOME/.local/bin:$PATH" to your shell rc if ocm is unavailable.` + : `Linked at ${notice.link}`, + duration: 10000, + }) +} + async function runSessionMove(api: TuiPluginApi): Promise { try { const current = api.route.current diff --git a/ocm-cli/src/tui-types.ts b/ocm-cli/src/tui-types.ts index dfd2efcc..003470f2 100644 --- a/ocm-cli/src/tui-types.ts +++ b/ocm-cli/src/tui-types.ts @@ -1,6 +1,6 @@ export type TuiRouteCurrent = { name: 'session'; params: { sessionID: string } } | { name: string; params?: Record } export type TuiSessionInfo = { id: string; directory: string; title?: string } -export type TuiToast = { title?: string; message: string; variant?: 'info' | 'success' | 'error' | 'warning' } +export type TuiToast = { title?: string; message: string; variant?: 'info' | 'success' | 'error' | 'warning'; duration?: number } export type TuiCommandDef = { name: string; title: string; desc?: string; category?: string; namespace?: string; slashName?: string; run: () => void | Promise } export type TuiPluginApi = { route: { readonly current: TuiRouteCurrent } @@ -8,4 +8,4 @@ export type TuiPluginApi = { ui: { toast: (input: TuiToast) => void } keymap: { registerLayer: (layer: { commands: TuiCommandDef[]; bindings?: Record }) => unknown } } -export type TuiPluginModule = { id?: string; tui: (api: TuiPluginApi, options?: Record) => Promise } \ No newline at end of file +export type TuiPluginModule = { id?: string; tui: (api: TuiPluginApi, options?: Record) => Promise }