From 3db55c6c5a5bdb71761b056157d5d514e869ff6f Mon Sep 17 00:00:00 2001 From: jiantw83 Date: Mon, 12 Oct 2026 13:24:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=87=20hud=20=E5=A4=96=E6=8E=9B?= =?UTF-8?q?=E6=94=B9=E5=90=8D=E7=82=BA=20cockpit=EF=BC=8C=E6=8B=86?= =?UTF-8?q?=E5=88=86=20hud=20=E8=88=87=20companion=20=E6=A8=A1=E7=B5=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 保留 /hud 別名,指向 /cockpit hud on|off|compact。 Co-Authored-By: Claude Sonnet 5.5 --- .claude-plugin/marketplace.json | 6 +-- README.md | 11 +++-- plugins/cockpit/.claude-plugin/plugin.json | 10 +++++ plugins/cockpit/hooks/companion/index.tsx | 4 ++ plugins/{hud => cockpit}/hooks/hooks.json | 0 .../hooks => cockpit/hooks/hud}/format.ts | 0 .../hooks => cockpit/hooks/hud}/hud.test.tsx | 0 .../hooks/hud/index.tsx} | 43 +++++++++++++------ plugins/cockpit/hooks/register.tsx | 9 ++++ plugins/{hud => cockpit}/tsconfig.json | 0 plugins/{hud => cockpit}/types/index.d.ts | 2 +- plugins/hud/.claude-plugin/plugin.json | 10 ----- 12 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 plugins/cockpit/.claude-plugin/plugin.json create mode 100644 plugins/cockpit/hooks/companion/index.tsx rename plugins/{hud => cockpit}/hooks/hooks.json (100%) rename plugins/{hud/hooks => cockpit/hooks/hud}/format.ts (100%) rename plugins/{hud/hooks => cockpit/hooks/hud}/hud.test.tsx (100%) rename plugins/{hud/hooks/register.tsx => cockpit/hooks/hud/index.tsx} (76%) create mode 100644 plugins/cockpit/hooks/register.tsx rename plugins/{hud => cockpit}/tsconfig.json (100%) rename plugins/{hud => cockpit}/types/index.d.ts (97%) delete mode 100644 plugins/hud/.claude-plugin/plugin.json diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 0eb6641..1c15cee 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -6,9 +6,9 @@ }, "plugins": [ { - "name": "hud", - "source": "./plugins/hud", - "description": "輸入框上方單行 HUD:模型、目錄、分支、5h/7d 額度與重置、context、CPU/記憶體/磁碟" + "name": "cockpit", + "source": "./plugins/cockpit", + "description": "Cockpit 外掛,內含 hud 模組(輸入框上方單行 HUD):模型、目錄、分支、5h/7d 額度與重置、context、CPU/記憶體/磁碟" } ] } diff --git a/README.md b/README.md index 95e97b9..8b653cb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ JSC 自用 Claude Code mods。 | Mod | 說明 | | --- | --- | -| [hud](plugins/hud) | 輸入框上方單行 HUD:模型、目錄、分支、5h/7d 額度與重置、context、CPU/記憶體/磁碟 | +| [cockpit](plugins/cockpit) | Cockpit 外掛,內含 hud 模組(輸入框上方單行 HUD):模型、目錄、分支、5h/7d 額度與重置、context、CPU/記憶體/磁碟 | ## 安裝 @@ -12,16 +12,21 @@ JSC 自用 Claude Code mods。 ```bash claude plugin marketplace add /root/jsc-marketplace -claude plugin install hud@jsc-marketplace +claude plugin install cockpit@jsc-marketplace ``` 或透過 Gitea 遠端: ```bash claude plugin marketplace add https://gitea.jsc.idv.tw/jiantw83/jsc-marketplace.git -claude plugin install hud@jsc-marketplace +claude plugin install cockpit@jsc-marketplace ``` +## 指令 + +- `/cockpit hud on | off | compact`:切換狀態列 +- `/hud on | off | compact`:上述指令的別名 + ## 授權 [MIT License](LICENSE) diff --git a/plugins/cockpit/.claude-plugin/plugin.json b/plugins/cockpit/.claude-plugin/plugin.json new file mode 100644 index 0000000..4477598 --- /dev/null +++ b/plugins/cockpit/.claude-plugin/plugin.json @@ -0,0 +1,10 @@ +{ + "name": "cockpit", + "version": "0.1.0", + "description": "Cockpit 外掛,內含 hud 模組(輸入框上方單行 HUD):模型、目錄、分支、5h/7d 額度與重置、context、CPU/記憶體/磁碟", + "license": "MIT", + "types": "./types/index.d.ts", + "author": { + "name": "JSC" + } +} diff --git a/plugins/cockpit/hooks/companion/index.tsx b/plugins/cockpit/hooks/companion/index.tsx new file mode 100644 index 0000000..a11d86c --- /dev/null +++ b/plugins/cockpit/hooks/companion/index.tsx @@ -0,0 +1,4 @@ +import type { Register } from 'claude-code' + +// companion 模組:目前為空殼,之後的階段再補內容 +export const register: Register = () => {} diff --git a/plugins/hud/hooks/hooks.json b/plugins/cockpit/hooks/hooks.json similarity index 100% rename from plugins/hud/hooks/hooks.json rename to plugins/cockpit/hooks/hooks.json diff --git a/plugins/hud/hooks/format.ts b/plugins/cockpit/hooks/hud/format.ts similarity index 100% rename from plugins/hud/hooks/format.ts rename to plugins/cockpit/hooks/hud/format.ts diff --git a/plugins/hud/hooks/hud.test.tsx b/plugins/cockpit/hooks/hud/hud.test.tsx similarity index 100% rename from plugins/hud/hooks/hud.test.tsx rename to plugins/cockpit/hooks/hud/hud.test.tsx diff --git a/plugins/hud/hooks/register.tsx b/plugins/cockpit/hooks/hud/index.tsx similarity index 76% rename from plugins/hud/hooks/register.tsx rename to plugins/cockpit/hooks/hud/index.tsx index b3be63f..03ac216 100644 --- a/plugins/hud/hooks/register.tsx +++ b/plugins/cockpit/hooks/hud/index.tsx @@ -1,16 +1,16 @@ import { atom, read, update } from 'claude-code' import type { EngineInterface, Register, SessionContextUsage, SessionRateLimit } from 'claude-code' -import type { Mode, Sys, Usage } from '../types' +import type { Mode, Sys, Usage } from '../../types' import { cpuPercent, fit, parseCpu, parseDf, parseGit, parseMem, parseOffset } from './format' import type { CpuSample } from './format' -const usageAtom = atom({ plugin: 'hud', key: 'usage' } as const, {}) -const gitAtom = atom({ plugin: 'hud', key: 'git' } as const, null) -const sysAtom = atom({ plugin: 'hud', key: 'sys' } as const, {}) -const modeAtom = atom({ plugin: 'hud', key: 'mode' } as const, 'auto') -const alertedAtom = atom({ plugin: 'hud', key: 'alerted' } as const, []) -const effortAtom = atom({ plugin: 'hud', key: 'effort' } as const, null) +const usageAtom = atom({ plugin: 'cockpit', key: 'usage' } as const, {}) +const gitAtom = atom({ plugin: 'cockpit', key: 'git' } as const, null) +const sysAtom = atom({ plugin: 'cockpit', key: 'sys' } as const, {}) +const modeAtom = atom({ plugin: 'cockpit', key: 'mode' } as const, 'auto') +const alertedAtom = atom({ plugin: 'cockpit', key: 'alerted' } as const, []) +const effortAtom = atom({ plugin: 'cockpit', key: 'effort' } as const, null) const SYS_MS = 3000 const GIT_MS = 15_000 @@ -82,11 +82,26 @@ async function alert($: EngineInterface, rateLimits: SessionRateLimit[]) { } } +async function runHud($: EngineInterface, args: string) { + const arg = args.trim() + const mode: Mode = arg === 'off' ? 'off' : arg === 'compact' ? 'compact' : 'auto' + await update($, modeAtom, () => mode) + const said: Record = { auto: '狀態列已開啟。', off: '狀態列已隱藏。', compact: '狀態列改用極窄版。' } + + return { text: said[mode] } +} + export const register: Register = on => { on('session.start', async ($, e, next) => { + await $.command.register({ + name: 'cockpit', + description: 'Cockpit 控制:hud 狀態列', + argumentHint: 'hud on | off | compact', + }) + // 別名:/hud 等同 /cockpit hud await $.command.register({ name: 'hud', - description: '切換輸入框上方的狀態列', + description: '切換輸入框上方的狀態列(/cockpit hud 的別名)', argumentHint: 'on | off | compact', }) home = await $.env.get('HOME') @@ -128,13 +143,13 @@ export const register: Register = on => { return ran }) - on('command.run', { command: 'hud' }, async ($, e) => { - const arg = e.args.trim() - const mode: Mode = arg === 'off' ? 'off' : arg === 'compact' ? 'compact' : 'auto' - await update($, modeAtom, () => mode) - const said: Record = { auto: '狀態列已開啟。', off: '狀態列已隱藏。', compact: '狀態列改用極窄版。' } + on('command.run', { command: 'hud' }, ($, e) => runHud($, e.args)) - return { text: said[mode] } + on('command.run', { command: 'cockpit' }, async ($, e, next) => { + const [sub, ...rest] = e.args.trim().split(/\s+/) + if (sub !== 'hud') return { text: '用法:/cockpit hud on | off | compact' } + + return runHud($, rest.join(' ')) }) on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => { diff --git a/plugins/cockpit/hooks/register.tsx b/plugins/cockpit/hooks/register.tsx new file mode 100644 index 0000000..bd93a2b --- /dev/null +++ b/plugins/cockpit/hooks/register.tsx @@ -0,0 +1,9 @@ +import type { Register } from 'claude-code' + +import { register as companion } from './companion' +import { register as hud } from './hud' + +export const register: Register = on => { + hud(on) + companion(on) +} diff --git a/plugins/hud/tsconfig.json b/plugins/cockpit/tsconfig.json similarity index 100% rename from plugins/hud/tsconfig.json rename to plugins/cockpit/tsconfig.json diff --git a/plugins/hud/types/index.d.ts b/plugins/cockpit/types/index.d.ts similarity index 97% rename from plugins/hud/types/index.d.ts rename to plugins/cockpit/types/index.d.ts index e8852b4..c155965 100644 --- a/plugins/hud/types/index.d.ts +++ b/plugins/cockpit/types/index.d.ts @@ -16,7 +16,7 @@ export type Mode = 'auto' | 'compact' | 'off' declare module 'claude-code' { interface PluginState { - hud: { + cockpit: { usage: Usage git: Git | null sys: Sys diff --git a/plugins/hud/.claude-plugin/plugin.json b/plugins/hud/.claude-plugin/plugin.json deleted file mode 100644 index 819444c..0000000 --- a/plugins/hud/.claude-plugin/plugin.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "hud", - "version": "0.1.0", - "description": "輸入框上方單行 HUD:模型、目錄、分支、5h/7d 額度與重置、context、CPU/記憶體/磁碟", - "license": "MIT", - "types": "./types/index.d.ts", - "author": { - "name": "JSC" - } -} -- 2.53.0