mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat(ocm-cli): add remote indicator to TUI when attached to Manager (#313)
* feat(ocm-cli): add remote indicator to TUI when attached to Manager * chore(ocm-cli): bump version to 0.2.3 * feat(ocm-cli): show remote indicator on home screen and session prompt * feat(ocm-cli): remove arrow icon from remote indicator * docs: remove arrow icon from remote indicator description
This commit is contained in:
1 parent
7c7e9f3c77
commit
ed02ddabba
13 files changed
+1435
-37
No files matched your search
@@ -0,0 +1,30 @@
|
||||
export const REMOTE_MANAGER_URL_ENV = 'OCM_REMOTE_MANAGER_URL'
|
||||
export const REMOTE_REPO_NAME_ENV = 'OCM_REMOTE_REPO_NAME'
|
||||
|
||||
export type RemoteContext = {
|
||||
managerHost: string
|
||||
repoName?: string
|
||||
}
|
||||
|
||||
export function buildRemoteAttachEnv(managerUrl: string, repoName: string): Record<string, string> {
|
||||
return {
|
||||
[REMOTE_MANAGER_URL_ENV]: managerUrl,
|
||||
[REMOTE_REPO_NAME_ENV]: repoName,
|
||||
}
|
||||
}
|
||||
|
||||
export function readRemoteContext(env: NodeJS.ProcessEnv): RemoteContext | undefined {
|
||||
const urlValue = env[REMOTE_MANAGER_URL_ENV]
|
||||
if (!urlValue) return undefined
|
||||
|
||||
let managerHost: string
|
||||
try {
|
||||
managerHost = new URL(urlValue).host
|
||||
} catch {
|
||||
managerHost = urlValue.trim()
|
||||
}
|
||||
|
||||
const repoName = env[REMOTE_REPO_NAME_ENV] || undefined
|
||||
|
||||
return { managerHost, repoName }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { TuiPluginApi, TuiPluginModule } from './tui-types.js'
|
||||
import type { TuiPluginApi } from './tui-types.js'
|
||||
import { readInstallNotice, readState } from './state.js'
|
||||
import { getToken } from './keychain.js'
|
||||
import { fetchRepos, toRemoteRepoSummaries } from './manager-repos.js'
|
||||
@@ -8,7 +8,7 @@ import { transferSession } from './session-move.js'
|
||||
import { createManagerReplay } from './remote-replay.js'
|
||||
import { readSessionEvents } from './local-history.js'
|
||||
|
||||
const tui = async (api: TuiPluginApi): Promise<void> => {
|
||||
export async function setupOcm(api: TuiPluginApi): Promise<void> {
|
||||
showInstallNotice(api)
|
||||
api.keymap.registerLayer({
|
||||
commands: [
|
||||
@@ -124,4 +124,4 @@ async function runSessionMove(api: TuiPluginApi): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export default { id: 'ocm', tui } satisfies TuiPluginModule
|
||||
export { readRemoteContext } from './remote-context.js'
|
||||
@@ -1,3 +1,19 @@
|
||||
import type { RGBA } from '@opentui/core'
|
||||
|
||||
export type TuiThemeColors = {
|
||||
accent: RGBA
|
||||
text: RGBA
|
||||
textMuted: RGBA
|
||||
backgroundElement: RGBA
|
||||
}
|
||||
|
||||
export type TuiSlotContext = { theme: { readonly current: TuiThemeColors } }
|
||||
|
||||
export type TuiSlotRegistration = {
|
||||
order?: number
|
||||
slots: Record<string, (ctx: TuiSlotContext, props: Record<string, unknown>) => unknown>
|
||||
}
|
||||
|
||||
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'; duration?: number }
|
||||
@@ -7,5 +23,6 @@ export type TuiPluginApi = {
|
||||
state: { session: { get: (sessionID: string) => TuiSessionInfo | undefined } }
|
||||
ui: { toast: (input: TuiToast) => void }
|
||||
keymap: { registerLayer: (layer: { commands: TuiCommandDef[]; bindings?: Record<string, unknown> }) => unknown }
|
||||
slots: { register: (registration: TuiSlotRegistration) => string }
|
||||
}
|
||||
export type TuiPluginModule = { id?: string; tui: (api: TuiPluginApi, options?: Record<string, unknown>) => Promise<void> }
|
||||
@@ -0,0 +1,33 @@
|
||||
/** @jsxImportSource @opentui/solid */
|
||||
import { setupOcm, readRemoteContext } from './tui-plugin.js'
|
||||
import type { TuiPluginApi, TuiPluginModule, TuiSlotContext } from './tui-types.js'
|
||||
|
||||
const tui = async (api: TuiPluginApi): Promise<void> => {
|
||||
await setupOcm(api)
|
||||
|
||||
const remote = readRemoteContext(process.env)
|
||||
if (!remote) return
|
||||
|
||||
const label = remote.repoName ? `${remote.managerHost} · ${remote.repoName}` : remote.managerHost
|
||||
const indicator = (ctx: TuiSlotContext) => {
|
||||
const theme = ctx.theme.current
|
||||
return (
|
||||
<box flexDirection="row" flexShrink={0} gap={1}>
|
||||
<text fg={theme.accent}>
|
||||
<b>REMOTE</b>
|
||||
</text>
|
||||
<text fg={theme.textMuted}>{label}</text>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
|
||||
api.slots.register({
|
||||
order: 300,
|
||||
slots: {
|
||||
session_prompt_right: indicator,
|
||||
home_prompt_right: indicator,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export default { id: 'ocm', tui } satisfies TuiPluginModule
|
||||
Reference in new issue
Block a user