@@ -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 < Mode , string > = { 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 <arg> 等同 /cockpit hud <arg>
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 < Mode , string > = { 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 ) = > {