mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(ocm-cli): replace raw postinstall output with TUI toast notification
This commit is contained in:
1 parent
436ef83df5
commit
7b13da6b25
5 files changed
+65
-24
No files matched your search
+2
-6
@@ -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"
|
||||
|
||||
@@ -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))
|
||||
+30
-1
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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<void> => {
|
||||
showInstallNotice(api)
|
||||
api.keymap.registerLayer({
|
||||
commands: [
|
||||
{
|
||||
@@ -24,6 +25,20 @@ const tui = async (api: TuiPluginApi): Promise<void> => {
|
||||
})
|
||||
}
|
||||
|
||||
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<void> {
|
||||
try {
|
||||
const current = api.route.current
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export type TuiRouteCurrent = { name: 'session'; params: { sessionID: string } } | { name: string; params?: Record<string, unknown> }
|
||||
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<void> }
|
||||
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<string, unknown> }) => unknown }
|
||||
}
|
||||
export type TuiPluginModule = { id?: string; tui: (api: TuiPluginApi, options?: Record<string, unknown>) => Promise<void> }
|
||||
export type TuiPluginModule = { id?: string; tui: (api: TuiPluginApi, options?: Record<string, unknown>) => Promise<void> }
|
||||
Reference in new issue
Block a user