chore: formatting etc
This commit is contained in:
@@ -579,6 +579,78 @@ def _(rid, params: dict) -> dict:
|
|||||||
return _err(rid, 5015, str(e))
|
return _err(rid, 5015, str(e))
|
||||||
|
|
||||||
|
|
||||||
|
@method("commands.catalog")
|
||||||
|
def _(rid, params: dict) -> dict:
|
||||||
|
"""Registry-backed slash metadata (same surface as SlashCommandCompleter)."""
|
||||||
|
try:
|
||||||
|
from hermes_cli.commands import COMMAND_REGISTRY, COMMANDS, SUBCOMMANDS
|
||||||
|
|
||||||
|
pairs = sorted(COMMANDS.items(), key=lambda kv: kv[0])
|
||||||
|
sub = {k: v[:] for k, v in SUBCOMMANDS.items()}
|
||||||
|
canon: dict[str, str] = {}
|
||||||
|
for cmd in COMMAND_REGISTRY:
|
||||||
|
if cmd.gateway_only:
|
||||||
|
continue
|
||||||
|
c = f"/{cmd.name}"
|
||||||
|
canon[c.lower()] = c
|
||||||
|
for a in cmd.aliases:
|
||||||
|
canon[f"/{a}".lower()] = c
|
||||||
|
skills = []
|
||||||
|
try:
|
||||||
|
from agent.skill_commands import scan_skill_commands
|
||||||
|
for k, info in scan_skill_commands().items():
|
||||||
|
d = str(info.get("description", "Skill"))
|
||||||
|
skills.append([k, f"⚡ {d[:120]}{'…' if len(d) > 120 else ''}"])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return _ok(rid, {"pairs": pairs + skills, "sub": sub, "canon": canon})
|
||||||
|
except Exception as e:
|
||||||
|
return _err(rid, 5020, str(e))
|
||||||
|
|
||||||
|
|
||||||
|
def _cli_exec_blocked(argv: list[str]) -> str | None:
|
||||||
|
"""Return user hint if this argv must not run headless in the gateway process."""
|
||||||
|
if not argv:
|
||||||
|
return "bare `hermes` is interactive — use `/hermes chat -q …` or run `hermes` in another terminal"
|
||||||
|
a0 = argv[0].lower()
|
||||||
|
if a0 == "setup":
|
||||||
|
return "`hermes setup` needs a full terminal — run it outside the Ink UI"
|
||||||
|
if a0 == "gateway":
|
||||||
|
return "`hermes gateway` is long-running — run it in another terminal"
|
||||||
|
if a0 == "sessions" and len(argv) > 1 and argv[1].lower() == "browse":
|
||||||
|
return "`hermes sessions browse` is interactive — use /resume here, or run browse in another terminal"
|
||||||
|
if a0 == "config" and len(argv) > 1 and argv[1].lower() == "edit":
|
||||||
|
return "`hermes config edit` needs $EDITOR in a real terminal"
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@method("cli.exec")
|
||||||
|
def _(rid, params: dict) -> dict:
|
||||||
|
"""Run `python -m hermes_cli.main` with argv; capture stdout/stderr (non-interactive only)."""
|
||||||
|
argv = params.get("argv", [])
|
||||||
|
if not isinstance(argv, list) or not all(isinstance(x, str) for x in argv):
|
||||||
|
return _err(rid, 4003, "argv must be list[str]")
|
||||||
|
hint = _cli_exec_blocked(argv)
|
||||||
|
if hint:
|
||||||
|
return _ok(rid, {"blocked": True, "hint": hint, "code": -1, "output": ""})
|
||||||
|
try:
|
||||||
|
r = subprocess.run(
|
||||||
|
[sys.executable, "-m", "hermes_cli.main", *argv],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=min(int(params.get("timeout", 240)), 600),
|
||||||
|
cwd=os.getcwd(),
|
||||||
|
env=os.environ.copy(),
|
||||||
|
)
|
||||||
|
parts = [r.stdout or "", r.stderr or ""]
|
||||||
|
out = "\n".join(p for p in parts if p).strip() or "(no output)"
|
||||||
|
return _ok(rid, {"blocked": False, "code": r.returncode, "output": out[:48_000]})
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
return _err(rid, 5016, "cli.exec: timeout")
|
||||||
|
except Exception as e:
|
||||||
|
return _err(rid, 5017, str(e))
|
||||||
|
|
||||||
|
|
||||||
@method("command.resolve")
|
@method("command.resolve")
|
||||||
def _(rid, params: dict) -> dict:
|
def _(rid, params: dict) -> dict:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export default [
|
|||||||
'unused-imports': unusedImports
|
'unused-imports': unusedImports
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
|
'no-fallthrough': ['error', { allowEmptyCase: true }],
|
||||||
curly: ['error', 'all'],
|
curly: ['error', 'all'],
|
||||||
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
|
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
|
||||||
'@typescript-eslint/no-unused-vars': 'off',
|
'@typescript-eslint/no-unused-vars': 'off',
|
||||||
@@ -63,6 +64,6 @@ export default [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ignores: ['node_modules/', 'dist/', '*.config.*']
|
ignores: ['node_modules/', 'dist/', '*.config.*', 'src/**/*.js']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -5,20 +5,31 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|||||||
import { AltScreen } from './altScreen.js'
|
import { AltScreen } from './altScreen.js'
|
||||||
import { Banner, SessionPanel } from './components/branding.js'
|
import { Banner, SessionPanel } from './components/branding.js'
|
||||||
import { CommandPalette } from './components/commandPalette.js'
|
import { CommandPalette } from './components/commandPalette.js'
|
||||||
|
import { MaskedPrompt } from './components/maskedPrompt.js'
|
||||||
import { MessageLine } from './components/messageLine.js'
|
import { MessageLine } from './components/messageLine.js'
|
||||||
import { ApprovalPrompt, ClarifyPrompt } from './components/prompts.js'
|
import { ApprovalPrompt, ClarifyPrompt } from './components/prompts.js'
|
||||||
import { QueuedMessages } from './components/queuedMessages.js'
|
import { QueuedMessages } from './components/queuedMessages.js'
|
||||||
import { MaskedPrompt } from './components/maskedPrompt.js'
|
|
||||||
import { SessionPicker } from './components/sessionPicker.js'
|
import { SessionPicker } from './components/sessionPicker.js'
|
||||||
import { Thinking } from './components/thinking.js'
|
import { Thinking } from './components/thinking.js'
|
||||||
import { COMMANDS, HOTKEYS, INTERPOLATION_RE, MAX_CTX, PLACEHOLDERS, TOOL_VERBS, ZERO } from './constants.js'
|
import { HOTKEYS, INTERPOLATION_RE, MAX_CTX, PLACEHOLDERS, TOOL_VERBS, ZERO } from './constants.js'
|
||||||
import { type GatewayClient, type GatewayEvent } from './gatewayClient.js'
|
import { type GatewayClient, type GatewayEvent } from './gatewayClient.js'
|
||||||
import * as inputHistory from './lib/history.js'
|
import * as inputHistory from './lib/history.js'
|
||||||
import { writeOsc52Clipboard } from './lib/osc52.js'
|
|
||||||
import { upsert } from './lib/messages.js'
|
import { upsert } from './lib/messages.js'
|
||||||
|
import { writeOsc52Clipboard } from './lib/osc52.js'
|
||||||
|
import { paletteForLine, tabAdvance } from './lib/slash.js'
|
||||||
import { estimateRows, flat, fmtK, hasInterpolation, pick, userDisplay } from './lib/text.js'
|
import { estimateRows, flat, fmtK, hasInterpolation, pick, userDisplay } from './lib/text.js'
|
||||||
import { DEFAULT_THEME, fromSkin, type Theme } from './theme.js'
|
import { DEFAULT_THEME, fromSkin, type Theme } from './theme.js'
|
||||||
import type { ActiveTool, ApprovalReq, ClarifyReq, Msg, SecretReq, SessionInfo, SudoReq, Usage } from './types.js'
|
import type {
|
||||||
|
ActiveTool,
|
||||||
|
ApprovalReq,
|
||||||
|
ClarifyReq,
|
||||||
|
Msg,
|
||||||
|
SecretReq,
|
||||||
|
SessionInfo,
|
||||||
|
SlashCatalog,
|
||||||
|
SudoReq,
|
||||||
|
Usage
|
||||||
|
} from './types.js'
|
||||||
|
|
||||||
const PLACEHOLDER = pick(PLACEHOLDERS)
|
const PLACEHOLDER = pick(PLACEHOLDERS)
|
||||||
|
|
||||||
@@ -53,6 +64,7 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
const [historyIdx, setHistoryIdx] = useState<number | null>(null)
|
const [historyIdx, setHistoryIdx] = useState<number | null>(null)
|
||||||
const [scrollOffset, setScrollOffset] = useState(0)
|
const [scrollOffset, setScrollOffset] = useState(0)
|
||||||
const [queuedDisplay, setQueuedDisplay] = useState<string[]>([])
|
const [queuedDisplay, setQueuedDisplay] = useState<string[]>([])
|
||||||
|
const [catalog, setCatalog] = useState<SlashCatalog | null>(null)
|
||||||
|
|
||||||
const buf = useRef('')
|
const buf = useRef('')
|
||||||
const stickyRef = useRef(true)
|
const stickyRef = useRef(true)
|
||||||
@@ -92,6 +104,7 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
|
|
||||||
const pushHistory = (text: string) => {
|
const pushHistory = (text: string) => {
|
||||||
const trimmed = text.trim()
|
const trimmed = text.trim()
|
||||||
|
|
||||||
if (trimmed && historyRef.current.at(-1) !== trimmed) {
|
if (trimmed && historyRef.current.at(-1) !== trimmed) {
|
||||||
historyRef.current.push(trimmed)
|
historyRef.current.push(trimmed)
|
||||||
inputHistory.append(trimmed)
|
inputHistory.append(trimmed)
|
||||||
@@ -143,12 +156,18 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
|
|
||||||
const newSession = (msg?: string) =>
|
const newSession = (msg?: string) =>
|
||||||
rpc('session.create').then((r: any) => {
|
rpc('session.create').then((r: any) => {
|
||||||
if (!r) return
|
if (!r) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setSid(r.session_id)
|
setSid(r.session_id)
|
||||||
setMessages([])
|
setMessages([])
|
||||||
setUsage(ZERO)
|
setUsage(ZERO)
|
||||||
setStatus('ready')
|
setStatus('ready')
|
||||||
if (msg) sys(msg)
|
|
||||||
|
if (msg) {
|
||||||
|
sys(msg)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const idle = () => {
|
const idle = () => {
|
||||||
@@ -276,6 +295,16 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!inputBuf.length && key.tab && input.startsWith('/')) {
|
||||||
|
const next = tabAdvance(input, catalog)
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
setInput(next)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (key.pageUp) {
|
if (key.pageUp) {
|
||||||
scrollUp(5)
|
scrollUp(5)
|
||||||
|
|
||||||
@@ -373,6 +402,20 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
setTheme(fromSkin(p.skin.colors ?? {}, p.skin.branding ?? {}))
|
setTheme(fromSkin(p.skin.colors ?? {}, p.skin.branding ?? {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpc('commands.catalog', {})
|
||||||
|
.then((r: any) => {
|
||||||
|
if (!r?.pairs) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setCatalog({
|
||||||
|
canon: (r.canon ?? {}) as Record<string, string>,
|
||||||
|
pairs: r.pairs as [string, string][],
|
||||||
|
sub: (r.sub ?? {}) as Record<string, string[]>
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
|
||||||
setStatus('forging session…')
|
setStatus('forging session…')
|
||||||
newSession()
|
newSession()
|
||||||
|
|
||||||
@@ -384,7 +427,10 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case 'thinking.delta':
|
case 'thinking.delta':
|
||||||
if (p?.text) setThinkingText(prev => prev + p.text)
|
if (p?.text) {
|
||||||
|
setThinkingText(prev => prev + p.text)
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'message.start':
|
case 'message.start':
|
||||||
@@ -449,24 +495,29 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
case 'approval.request':
|
case 'approval.request':
|
||||||
setApproval({ command: p.command, description: p.description })
|
setApproval({ command: p.command, description: p.description })
|
||||||
setStatus('approval needed')
|
setStatus('approval needed')
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'sudo.request':
|
case 'sudo.request':
|
||||||
setSudo({ requestId: p.request_id })
|
setSudo({ requestId: p.request_id })
|
||||||
setStatus('sudo password needed')
|
setStatus('sudo password needed')
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'secret.request':
|
case 'secret.request':
|
||||||
setSecret({ requestId: p.request_id, prompt: p.prompt, envVar: p.env_var })
|
setSecret({ requestId: p.request_id, prompt: p.prompt, envVar: p.env_var })
|
||||||
setStatus('secret input needed')
|
setStatus('secret input needed')
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'background.complete':
|
case 'background.complete':
|
||||||
sys(`[bg ${p.task_id}] ${p.text}`)
|
sys(`[bg ${p.task_id}] ${p.text}`)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'btw.complete':
|
case 'btw.complete':
|
||||||
sys(`[btw] ${p.text}`)
|
sys(`[btw] ${p.text}`)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'message.delta':
|
case 'message.delta':
|
||||||
@@ -547,22 +598,31 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
const arg = rest.join(' ')
|
const arg = rest.join(' ')
|
||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'help':
|
case 'help': {
|
||||||
|
const rows = catalog?.pairs ?? []
|
||||||
|
const cap = 52
|
||||||
|
const lines = rows.slice(0, cap).map(([c, d]) => ` ${c.padEnd(16)} ${d}`)
|
||||||
|
|
||||||
sys(
|
sys(
|
||||||
[
|
[
|
||||||
' Commands:',
|
' Commands:',
|
||||||
...COMMANDS.map(([c, d]) => ` ${c.padEnd(12)} ${d}`),
|
...lines,
|
||||||
|
rows.length > cap ? ` … ${rows.length - cap} more` : '',
|
||||||
'',
|
'',
|
||||||
' Hotkeys:',
|
' Hotkeys:',
|
||||||
...HOTKEYS.map(([k, d]) => ` ${k.padEnd(12)} ${d}`)
|
...HOTKEYS.map(([k, d]) => ` ${k.padEnd(14)} ${d}`)
|
||||||
].join('\n')
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
case 'clear':
|
case 'clear':
|
||||||
setStatus('forging session…')
|
setStatus('forging session…')
|
||||||
newSession()
|
newSession()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'quit': // falls through
|
case 'quit': // falls through
|
||||||
@@ -575,6 +635,7 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
case 'new':
|
case 'new':
|
||||||
setStatus('forging session…')
|
setStatus('forging session…')
|
||||||
newSession('new session started')
|
newSession('new session started')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'undo':
|
case 'undo':
|
||||||
@@ -582,44 +643,51 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc('session.undo', { session_id: sid })
|
rpc('session.undo', { session_id: sid }).then((r: any) => {
|
||||||
.then((r: any) => {
|
if (r.removed > 0) {
|
||||||
if (r.removed > 0) {
|
setMessages(prev => {
|
||||||
setMessages(prev => {
|
const q = [...prev]
|
||||||
const q = [...prev]
|
|
||||||
|
|
||||||
while (q.at(-1)?.role === 'assistant' || q.at(-1)?.role === 'tool') {
|
while (q.at(-1)?.role === 'assistant' || q.at(-1)?.role === 'tool') {
|
||||||
q.pop()
|
q.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q.at(-1)?.role === 'user') {
|
if (q.at(-1)?.role === 'user') {
|
||||||
q.pop()
|
q.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
return q
|
return q
|
||||||
})
|
})
|
||||||
sys(`undid ${r.removed} messages`)
|
sys(`undid ${r.removed} messages`)
|
||||||
} else {
|
} else {
|
||||||
sys('nothing to undo')
|
sys('nothing to undo')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'retry':
|
case 'retry':
|
||||||
if (!lastUserMsg) {
|
if (!lastUserMsg) {
|
||||||
sys('nothing to retry')
|
sys('nothing to retry')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sid) {
|
if (sid) {
|
||||||
gw.request('session.undo', { session_id: sid }).catch(() => {})
|
gw.request('session.undo', { session_id: sid }).catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
setMessages(prev => {
|
setMessages(prev => {
|
||||||
const q = [...prev]
|
const q = [...prev]
|
||||||
while (q.at(-1)?.role === 'assistant' || q.at(-1)?.role === 'tool') q.pop()
|
|
||||||
|
while (q.at(-1)?.role === 'assistant' || q.at(-1)?.role === 'tool') {
|
||||||
|
q.pop()
|
||||||
|
}
|
||||||
|
|
||||||
return q
|
return q
|
||||||
})
|
})
|
||||||
send(lastUserMsg)
|
send(lastUserMsg)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'compact':
|
case 'compact':
|
||||||
@@ -633,14 +701,13 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc('session.compress', { session_id: sid })
|
rpc('session.compress', { session_id: sid }).then((r: any) => {
|
||||||
.then((r: any) => {
|
sys('context compressed')
|
||||||
sys('context compressed')
|
|
||||||
|
|
||||||
if (r.usage) {
|
if (r.usage) {
|
||||||
setUsage(r.usage)
|
setUsage(r.usage)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@@ -695,319 +762,484 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
|
|
||||||
case 'resume':
|
case 'resume':
|
||||||
setPicker(true)
|
setPicker(true)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'history':
|
case 'history':
|
||||||
if (!sid) { setPicker(true); return true }
|
if (!sid) {
|
||||||
rpc('session.history', { session_id: sid })
|
setPicker(true)
|
||||||
.then((r: any) => sys(`session ${sid}: ${r.count} messages in context`))
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc('session.history', { session_id: sid }).then((r: any) =>
|
||||||
|
sys(`session ${sid}: ${r.count} messages in context`)
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'title':
|
case 'title':
|
||||||
if (!sid) return true
|
if (!sid) {
|
||||||
if (!arg) {
|
|
||||||
rpc('session.title', { session_id: sid })
|
|
||||||
.then((r: any) => sys(`title: ${r.title || '(none)'} session: ${r.session_key}`))
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rpc('session.title', { session_id: sid, title: arg })
|
|
||||||
.then(() => sys(`title → ${arg}`))
|
if (!arg) {
|
||||||
|
rpc('session.title', { session_id: sid }).then((r: any) =>
|
||||||
|
sys(`title: ${r.title || '(none)'} session: ${r.session_key}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc('session.title', { session_id: sid, title: arg }).then(() => sys(`title → ${arg}`))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'tools':
|
case 'tools':
|
||||||
if (!info?.tools || !Object.keys(info.tools).length) {
|
if (!info?.tools || !Object.keys(info.tools).length) {
|
||||||
sys('no tools loaded')
|
sys('no tools loaded')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
sys(
|
sys(
|
||||||
Object.entries(info.tools)
|
Object.entries(info.tools)
|
||||||
.map(([k, vs]) => `${k} (${vs.length}): ${vs.join(', ')}`)
|
.map(([k, vs]) => `${k} (${vs.length}): ${vs.join(', ')}`)
|
||||||
.join('\n')
|
.join('\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'skills':
|
case 'skills':
|
||||||
if (!arg || arg === 'list') {
|
if (!arg || arg === 'list') {
|
||||||
if (!info?.skills || !Object.keys(info.skills).length) {
|
if (!info?.skills || !Object.keys(info.skills).length) {
|
||||||
sys('no skills loaded')
|
sys('no skills loaded')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
sys(Object.entries(info.skills).map(([k, vs]) => `${k}: ${vs.join(', ')}`).join('\n'))
|
|
||||||
|
sys(
|
||||||
|
Object.entries(info.skills)
|
||||||
|
.map(([k, vs]) => `${k}: ${vs.join(', ')}`)
|
||||||
|
.join('\n')
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith('search ')) {
|
if (arg.startsWith('search ')) {
|
||||||
rpc('skills.manage', { action: 'search', query: arg.slice(7).trim() })
|
rpc('skills.manage', { action: 'search', query: arg.slice(7).trim() }).then((r: any) => {
|
||||||
.then((r: any) => {
|
if (!r.results?.length) {
|
||||||
if (!r.results?.length) { sys('no results'); return }
|
sys('no results')
|
||||||
sys(r.results.map((s: any) => ` ${s.name}: ${s.description}`).join('\n'))
|
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sys(r.results.map((s: any) => ` ${s.name}: ${s.description}`).join('\n'))
|
||||||
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith('install ')) {
|
if (arg.startsWith('install ')) {
|
||||||
rpc('skills.manage', { action: 'install', query: arg.slice(8).trim() })
|
rpc('skills.manage', { action: 'install', query: arg.slice(8).trim() }).then((r: any) =>
|
||||||
.then((r: any) => sys(r.installed ? `installed ${r.name}` : 'install failed'))
|
sys(r.installed ? `installed ${r.name}` : 'install failed')
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg === 'browse' || arg.startsWith('browse ')) {
|
if (arg === 'browse' || arg.startsWith('browse ')) {
|
||||||
rpc('skills.manage', { action: 'browse', query: arg.slice(6).trim() })
|
rpc('skills.manage', { action: 'browse', query: arg.slice(6).trim() }).then((r: any) => {
|
||||||
.then((r: any) => {
|
if (!r.results?.length) {
|
||||||
if (!r.results?.length) { sys('no skills available'); return }
|
sys('no skills available')
|
||||||
sys(r.results.map((s: any) => ` ${s.name}: ${s.description}`).join('\n'))
|
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sys(r.results.map((s: any) => ` ${s.name}: ${s.description}`).join('\n'))
|
||||||
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith('inspect ')) {
|
if (arg.startsWith('inspect ')) {
|
||||||
rpc('skills.manage', { action: 'inspect', query: arg.slice(8).trim() })
|
rpc('skills.manage', { action: 'inspect', query: arg.slice(8).trim() }).then((r: any) =>
|
||||||
.then((r: any) => sys(JSON.stringify(r.info, null, 2)))
|
sys(JSON.stringify(r.info, null, 2))
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
sys('usage: /skills [list|search <q>|install <name>|browse|inspect <name>]')
|
sys('usage: /skills [list|search <q>|install <name>|browse|inspect <name>]')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'verbose':
|
case 'verbose':
|
||||||
rpc('config.set', { key: 'verbose', value: arg || 'cycle' })
|
rpc('config.set', { key: 'verbose', value: arg || 'cycle' }).then((r: any) => sys(`verbose → ${r.value}`))
|
||||||
.then((r: any) => sys(`verbose → ${r.value}`))
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'yolo':
|
case 'yolo':
|
||||||
rpc('config.set', { key: 'yolo', value: '' })
|
rpc('config.set', { key: 'yolo', value: '' }).then((r: any) =>
|
||||||
.then((r: any) => sys(`yolo → ${r.value === '1' ? 'on' : 'off'}`))
|
sys(`yolo → ${r.value === '1' ? 'on' : 'off'}`)
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'reasoning':
|
case 'reasoning':
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
sys('usage: /reasoning <none|low|medium|high|xhigh|show|hide>')
|
sys('usage: /reasoning <none|low|medium|high|xhigh|show|hide>')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rpc('config.set', { key: 'reasoning', value: arg })
|
|
||||||
.then((r: any) => sys(`reasoning → ${r.value}`))
|
rpc('config.set', { key: 'reasoning', value: arg }).then((r: any) => sys(`reasoning → ${r.value}`))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'stop':
|
case 'stop':
|
||||||
rpc('process.stop')
|
rpc('process.stop').then((r: any) => sys(`killed ${r.killed} process(es)`))
|
||||||
.then((r: any) => sys(`killed ${r.killed} process(es)`))
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'profile':
|
case 'profile':
|
||||||
gw.request('config.get', { key: 'profile' })
|
gw.request('config.get', { key: 'profile' })
|
||||||
.then((r: any) => sys(`profile: ${r.display}`))
|
.then((r: any) => sys(`profile: ${r.display}`))
|
||||||
.catch(() => sys(`profile: ${process.env.HERMES_HOME ?? '~/.hermes'}`))
|
.catch(() => sys(`profile: ${process.env.HERMES_HOME ?? '~/.hermes'}`))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'save':
|
case 'save':
|
||||||
if (!sid) return true
|
if (!sid) {
|
||||||
rpc('session.save', { session_id: sid })
|
return true
|
||||||
.then((r: any) => sys(`saved to ${r.file}`))
|
}
|
||||||
|
|
||||||
|
rpc('session.save', { session_id: sid }).then((r: any) => sys(`saved to ${r.file}`))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'provider':
|
case 'provider':
|
||||||
rpc('config.get', { key: 'provider' })
|
rpc('config.get', { key: 'provider' }).then((r: any) => {
|
||||||
.then((r: any) => {
|
const lines = [`model: ${r.model} provider: ${r.provider}`]
|
||||||
const lines = [`model: ${r.model} provider: ${r.provider}`]
|
|
||||||
if (r.providers?.length) lines.push(`available: ${r.providers.join(', ')}`)
|
if (r.providers?.length) {
|
||||||
sys(lines.join('\n'))
|
lines.push(`available: ${r.providers.join(', ')}`)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
sys(lines.join('\n'))
|
||||||
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'prompt':
|
case 'prompt':
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
rpc('config.get', { key: 'prompt' })
|
rpc('config.get', { key: 'prompt' }).then((r: any) => sys(`custom prompt: ${r.prompt || '(none set)'}`))
|
||||||
.then((r: any) => sys(`custom prompt: ${r.prompt || '(none set)'}`))
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rpc('config.set', { key: 'prompt', value: arg })
|
|
||||||
.then((r: any) => sys(r.value ? `prompt set (${r.value.length} chars)` : 'prompt cleared'))
|
rpc('config.set', { key: 'prompt', value: arg }).then((r: any) =>
|
||||||
|
sys(r.value ? `prompt set (${r.value.length} chars)` : 'prompt cleared')
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'personality':
|
case 'personality':
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
sys('usage: /personality <name> (concise, creative, analytical, friendly, none)')
|
sys('usage: /personality <name> (concise, creative, analytical, friendly, none)')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rpc('config.set', { key: 'personality', value: arg })
|
|
||||||
.then((r: any) => sys(`personality → ${r.value || 'default'}`))
|
rpc('config.set', { key: 'personality', value: arg }).then((r: any) =>
|
||||||
|
sys(`personality → ${r.value || 'default'}`)
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'plan':
|
case 'plan':
|
||||||
send(arg ? `/plan ${arg}` : 'Create a detailed plan for the current task.')
|
send(arg ? `/plan ${arg}` : 'Create a detailed plan for the current task.')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'background':
|
case 'background':
|
||||||
|
|
||||||
case 'bg':
|
case 'bg':
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
sys('usage: /background <prompt>')
|
sys('usage: /background <prompt>')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rpc('prompt.background', { session_id: sid, text: arg })
|
|
||||||
.then((r: any) => sys(`background task ${r.task_id} started`))
|
rpc('prompt.background', { session_id: sid, text: arg }).then((r: any) =>
|
||||||
|
sys(`background task ${r.task_id} started`)
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'btw':
|
case 'btw':
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
sys('usage: /btw <question>')
|
sys('usage: /btw <question>')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rpc('prompt.btw', { session_id: sid, text: arg })
|
|
||||||
.then(() => sys('btw running…'))
|
rpc('prompt.btw', { session_id: sid, text: arg }).then(() => sys('btw running…'))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'queue':
|
case 'queue':
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
sys(`${queueRef.current.length} queued message(s)`)
|
sys(`${queueRef.current.length} queued message(s)`)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
enqueue(arg)
|
enqueue(arg)
|
||||||
sys(`queued: "${arg.slice(0, 50)}${arg.length > 50 ? '…' : ''}"`)
|
sys(`queued: "${arg.slice(0, 50)}${arg.length > 50 ? '…' : ''}"`)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'rollback':
|
case 'rollback':
|
||||||
if (!sid) return true
|
if (!sid) {
|
||||||
if (!arg) {
|
|
||||||
rpc('rollback.list', { session_id: sid })
|
|
||||||
.then((r: any) => {
|
|
||||||
if (!r.enabled) { sys('checkpoints not enabled — use hermes --checkpoints'); return }
|
|
||||||
if (!r.checkpoints?.length) { sys('no checkpoints'); return }
|
|
||||||
sys(r.checkpoints.map((c: any, i: number) =>
|
|
||||||
` ${i + 1}. ${c.message || c.hash.slice(0, 8)} (${c.timestamp})`
|
|
||||||
).join('\n'))
|
|
||||||
})
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!arg) {
|
||||||
|
rpc('rollback.list', { session_id: sid }).then((r: any) => {
|
||||||
|
if (!r.enabled) {
|
||||||
|
sys('checkpoints not enabled — use hermes --checkpoints')
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!r.checkpoints?.length) {
|
||||||
|
sys('no checkpoints')
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sys(
|
||||||
|
r.checkpoints
|
||||||
|
.map((c: any, i: number) => ` ${i + 1}. ${c.message || c.hash.slice(0, 8)} (${c.timestamp})`)
|
||||||
|
.join('\n')
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if (arg.startsWith('diff ')) {
|
if (arg.startsWith('diff ')) {
|
||||||
const ref = arg.slice(5).trim()
|
const ref = arg.slice(5).trim()
|
||||||
rpc('rollback.list', { session_id: sid }).then((r: any) => {
|
rpc('rollback.list', { session_id: sid }).then((r: any) => {
|
||||||
const hash = /^\d+$/.test(ref) ? r.checkpoints?.[parseInt(ref) - 1]?.hash : ref
|
const hash = /^\d+$/.test(ref) ? r.checkpoints?.[parseInt(ref) - 1]?.hash : ref
|
||||||
if (!hash) { sys(`checkpoint ${ref} not found`); return }
|
|
||||||
rpc('rollback.diff', { session_id: sid, hash })
|
if (!hash) {
|
||||||
.then((d: any) => sys(d.stat || d.diff || 'no changes'))
|
sys(`checkpoint ${ref} not found`)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc('rollback.diff', { session_id: sid, hash }).then((d: any) => sys(d.stat || d.diff || 'no changes'))
|
||||||
})
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const parts = arg.trim().split(/\s+/)
|
const parts = arg.trim().split(/\s+/)
|
||||||
const ref = parts[0]!
|
const ref = parts[0]!
|
||||||
const file = parts[1]
|
const file = parts[1]
|
||||||
rpc('rollback.list', { session_id: sid }).then((r: any) => {
|
rpc('rollback.list', { session_id: sid }).then((r: any) => {
|
||||||
const hash = /^\d+$/.test(ref) ? r.checkpoints?.[parseInt(ref) - 1]?.hash : ref
|
const hash = /^\d+$/.test(ref) ? r.checkpoints?.[parseInt(ref) - 1]?.hash : ref
|
||||||
if (!hash) { sys(`checkpoint ${ref} not found`); return }
|
|
||||||
rpc('rollback.restore', { session_id: sid, hash, ...(file ? { file } : {}) })
|
if (!hash) {
|
||||||
.then((d: any) => sys(d.success ? `restored${file ? ` ${file}` : ''}` : `failed: ${d.error || 'unknown'}`))
|
sys(`checkpoint ${ref} not found`)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc('rollback.restore', { session_id: sid, hash, ...(file ? { file } : {}) }).then((d: any) =>
|
||||||
|
sys(d.success ? `restored${file ? ` ${file}` : ''}` : `failed: ${d.error || 'unknown'}`)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'insights':
|
case 'insights':
|
||||||
rpc('insights.get', { days: arg ? parseInt(arg) : 30 })
|
rpc('insights.get', { days: arg ? parseInt(arg) : 30 }).then((r: any) =>
|
||||||
.then((r: any) => sys(`last ${r.days}d: ${r.sessions} sessions, ${r.messages} messages`))
|
sys(`last ${r.days}d: ${r.sessions} sessions, ${r.messages} messages`)
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'toolsets':
|
case 'toolsets':
|
||||||
if (!info?.tools) {
|
if (!info?.tools) {
|
||||||
sys('no toolsets loaded')
|
sys('no toolsets loaded')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
sys(Object.entries(info.tools).map(([k, vs]) => `${k}: ${vs.length} tools`).join('\n'))
|
|
||||||
|
sys(
|
||||||
|
Object.entries(info.tools)
|
||||||
|
.map(([k, vs]) => `${k}: ${vs.length} tools`)
|
||||||
|
.join('\n')
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'paste':
|
case 'paste':
|
||||||
sys('clipboard paste: use your terminal\'s paste shortcut (images not yet supported in TUI)')
|
sys("clipboard paste: use your terminal's paste shortcut (images not yet supported in TUI)")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'reload-mcp':
|
case 'reload-mcp':
|
||||||
|
|
||||||
case 'reload_mcp':
|
case 'reload_mcp':
|
||||||
rpc('reload.mcp', { session_id: sid })
|
rpc('reload.mcp', { session_id: sid }).then(() => sys('MCP servers reloaded'))
|
||||||
.then(() => sys('MCP servers reloaded'))
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'browser':
|
case 'browser':
|
||||||
if (!arg || arg === 'status') {
|
if (!arg || arg === 'status') {
|
||||||
rpc('browser.manage', { action: 'status' })
|
rpc('browser.manage', { action: 'status' }).then((r: any) =>
|
||||||
.then((r: any) => sys(r.connected ? `browser: connected (${r.url})` : 'browser: not connected'))
|
sys(r.connected ? `browser: connected (${r.url})` : 'browser: not connected')
|
||||||
|
)
|
||||||
} else if (arg === 'connect' || arg.startsWith('connect ')) {
|
} else if (arg === 'connect' || arg.startsWith('connect ')) {
|
||||||
const url = arg.split(/\s+/)[1]
|
const url = arg.split(/\s+/)[1]
|
||||||
rpc('browser.manage', { action: 'connect', ...(url ? { url } : {}) })
|
rpc('browser.manage', { action: 'connect', ...(url ? { url } : {}) }).then((r: any) =>
|
||||||
.then((r: any) => sys(`browser connected: ${r.url}`))
|
sys(`browser connected: ${r.url}`)
|
||||||
|
)
|
||||||
} else if (arg === 'disconnect') {
|
} else if (arg === 'disconnect') {
|
||||||
rpc('browser.manage', { action: 'disconnect' })
|
rpc('browser.manage', { action: 'disconnect' }).then(() => sys('browser disconnected'))
|
||||||
.then(() => sys('browser disconnected'))
|
|
||||||
} else {
|
} else {
|
||||||
sys('usage: /browser [connect|disconnect|status]')
|
sys('usage: /browser [connect|disconnect|status]')
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'platforms':
|
case 'platforms':
|
||||||
|
|
||||||
case 'gateway':
|
case 'gateway':
|
||||||
sys('gateway status is not available in TUI mode')
|
sys('gateway status is not available in TUI mode')
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'statusbar':
|
case 'statusbar':
|
||||||
|
|
||||||
case 'sb':
|
case 'sb':
|
||||||
setStatusBar(v => !v)
|
setStatusBar(v => !v)
|
||||||
sys(`status bar ${statusBar ? 'off' : 'on'}`)
|
sys(`status bar ${statusBar ? 'off' : 'on'}`)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'voice':
|
case 'voice':
|
||||||
if (!arg || arg === 'status') {
|
if (!arg || arg === 'status') {
|
||||||
rpc('voice.toggle', { action: 'status' })
|
rpc('voice.toggle', { action: 'status' }).then((r: any) => sys(`voice: ${r.enabled ? 'on' : 'off'}`))
|
||||||
.then((r: any) => sys(`voice: ${r.enabled ? 'on' : 'off'}`))
|
|
||||||
} else if (arg === 'on' || arg === 'off') {
|
} else if (arg === 'on' || arg === 'off') {
|
||||||
rpc('voice.toggle', { action: arg })
|
rpc('voice.toggle', { action: arg }).then((r: any) => sys(`voice → ${r.enabled ? 'on' : 'off'}`))
|
||||||
.then((r: any) => sys(`voice → ${r.enabled ? 'on' : 'off'}`))
|
|
||||||
} else if (arg === 'record') {
|
} else if (arg === 'record') {
|
||||||
rpc('voice.record', { action: 'start' })
|
rpc('voice.record', { action: 'start' }).then(() => sys('recording… (use /voice stop to transcribe)'))
|
||||||
.then(() => sys('recording… (use /voice stop to transcribe)'))
|
|
||||||
} else if (arg === 'stop') {
|
} else if (arg === 'stop') {
|
||||||
rpc('voice.record', { action: 'stop' })
|
rpc('voice.record', { action: 'stop' }).then((r: any) => {
|
||||||
.then((r: any) => {
|
if (r.text) {
|
||||||
if (r.text) { send(r.text) } else { sys('no speech detected') }
|
send(r.text)
|
||||||
})
|
} else {
|
||||||
|
sys('no speech detected')
|
||||||
|
}
|
||||||
|
})
|
||||||
} else if (arg === 'tts') {
|
} else if (arg === 'tts') {
|
||||||
const last = messages.filter(m => m.role === 'assistant').at(-1)
|
const last = messages.filter(m => m.role === 'assistant').at(-1)
|
||||||
|
|
||||||
if (last) {
|
if (last) {
|
||||||
rpc('voice.tts', { text: last.text })
|
rpc('voice.tts', { text: last.text }).then(() => sys('speaking…'))
|
||||||
.then(() => sys('speaking…'))
|
|
||||||
} else {
|
} else {
|
||||||
sys('no response to speak')
|
sys('no response to speak')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sys('usage: /voice [on|off|status|record|stop|tts]')
|
sys('usage: /voice [on|off|status|record|stop|tts]')
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'plugins':
|
case 'plugins':
|
||||||
rpc('plugins.list')
|
rpc('plugins.list').then((r: any) => {
|
||||||
.then((r: any) => {
|
if (!r.plugins?.length) {
|
||||||
if (!r.plugins?.length) { sys('no plugins installed'); return }
|
sys('no plugins installed')
|
||||||
sys(r.plugins.map((p: any) => ` ${p.name} v${p.version} ${p.enabled ? '✓' : '✗'}`).join('\n'))
|
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sys(r.plugins.map((p: any) => ` ${p.name} v${p.version} ${p.enabled ? '✓' : '✗'}`).join('\n'))
|
||||||
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'cron':
|
case 'cron':
|
||||||
if (!arg || arg === 'list') {
|
if (!arg || arg === 'list') {
|
||||||
rpc('cron.manage', { action: 'list' })
|
rpc('cron.manage', { action: 'list' }).then((r: any) => {
|
||||||
.then((r: any) => {
|
const jobs = r.jobs || r.schedules || []
|
||||||
const jobs = r.jobs || r.schedules || []
|
|
||||||
if (!jobs.length) { sys('no cron jobs'); return }
|
if (!jobs.length) {
|
||||||
sys(jobs.map((j: any) => ` ${j.name}: ${j.schedule} ${j.paused ? '(paused)' : ''}`).join('\n'))
|
sys('no cron jobs')
|
||||||
})
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sys(jobs.map((j: any) => ` ${j.name}: ${j.schedule} ${j.paused ? '(paused)' : ''}`).join('\n'))
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
const parts = arg.split(/\s+/)
|
const parts = arg.split(/\s+/)
|
||||||
const sub = parts[0]!
|
const sub = parts[0]!
|
||||||
|
|
||||||
if (sub === 'add' || sub === 'create') {
|
if (sub === 'add' || sub === 'create') {
|
||||||
const name = parts[1] || ''
|
const name = parts[1] || ''
|
||||||
const schedule = parts[2] || ''
|
const schedule = parts[2] || ''
|
||||||
const prompt = parts.slice(3).join(' ')
|
const prompt = parts.slice(3).join(' ')
|
||||||
rpc('cron.manage', { action: 'add', name, schedule, prompt })
|
rpc('cron.manage', { action: 'add', name, schedule, prompt }).then((r: any) =>
|
||||||
.then((r: any) => sys(r.message || r.status || 'created'))
|
sys(r.message || r.status || 'created')
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
rpc('cron.manage', { action: sub, name: parts[1] || '' })
|
rpc('cron.manage', { action: sub, name: parts[1] || '' }).then((r: any) =>
|
||||||
.then((r: any) => sys(r.message || r.status || JSON.stringify(r)))
|
sys(r.message || r.status || JSON.stringify(r))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'update':
|
case 'update':
|
||||||
sys('update not available in TUI mode — run: pip install -U hermes-agent')
|
sys('update not available in TUI mode — run: pip install -U hermes-agent')
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
case 'hermes':
|
||||||
|
if (!arg) {
|
||||||
|
sys(
|
||||||
|
'usage: /hermes <args…> non-interactive `hermes` CLI (e.g. sessions list, chat -q "hi"). Interactive setup/browse/edit must run in a separate terminal.'
|
||||||
|
)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc('cli.exec', { argv: arg.split(/\s+/).filter(Boolean) })
|
||||||
|
.then((r: any) => {
|
||||||
|
if (r.blocked) {
|
||||||
|
sys(r.hint ?? 'blocked')
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sys(r.output ?? '(no output)')
|
||||||
|
|
||||||
|
if (r.code !== 0) {
|
||||||
|
sys(`exit ${r.code}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e: Error) => sys(`error: ${e.message}`))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case 'model':
|
case 'model':
|
||||||
@@ -1017,8 +1249,7 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc('config.set', { key: 'model', value: arg })
|
rpc('config.set', { key: 'model', value: arg }).then(() => sys(`model → ${arg}`))
|
||||||
.then(() => sys(`model → ${arg}`))
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@@ -1029,8 +1260,7 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc('config.set', { key: 'skin', value: arg })
|
rpc('config.set', { key: 'skin', value: arg }).then(() => sys(`skin → ${arg} (restart to apply)`))
|
||||||
.then(() => sys(`skin → ${arg} (restart to apply)`))
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@@ -1060,11 +1290,12 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
})
|
})
|
||||||
.catch(() => sys(`unknown command: /${name}`))
|
.catch(() => sys(`unknown command: /${name}`))
|
||||||
})
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
[compact, gw, info, lastUserMsg, messages, newSession, rpc, send, sid, status, sys, usage, statusBar]
|
[catalog, compact, gw, info, lastUserMsg, messages, newSession, rpc, send, sid, status, sys, usage, statusBar]
|
||||||
)
|
)
|
||||||
|
|
||||||
const submit = useCallback(
|
const submit = useCallback(
|
||||||
@@ -1320,7 +1551,7 @@ export function App({ gw }: { gw: GatewayClient }) {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!blocked && input.startsWith('/') && <CommandPalette filter={input} t={theme} />}
|
{!blocked && input.startsWith('/') && <CommandPalette matches={paletteForLine(input, catalog)} t={theme} />}
|
||||||
|
|
||||||
<QueuedMessages cols={cols} queued={queuedDisplay} queueEditIdx={queueEditIdx} t={theme} />
|
<QueuedMessages cols={cols} queued={queuedDisplay} queueEditIdx={queueEditIdx} t={theme} />
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
import { Box, Text } from 'ink'
|
import { Box, Text } from 'ink'
|
||||||
|
|
||||||
import { COMMANDS } from '../constants.js'
|
|
||||||
import type { Theme } from '../theme.js'
|
import type { Theme } from '../theme.js'
|
||||||
|
|
||||||
export function CommandPalette({ filter, t }: { filter: string; t: Theme }) {
|
export function CommandPalette({ matches, t }: { matches: [string, string][]; t: Theme }) {
|
||||||
const matches = COMMANDS.filter(([cmd]) => cmd.startsWith(filter))
|
|
||||||
|
|
||||||
if (!matches.length) {
|
if (!matches.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column" marginBottom={1}>
|
||||||
{matches.map(([cmd, desc]) => (
|
{matches.map(([cmd, desc], i) => (
|
||||||
<Text key={cmd}>
|
<Text key={`${i}-${cmd}`}>
|
||||||
<Text bold color={t.color.amber}>
|
<Text bold color={t.color.amber}>
|
||||||
{cmd}
|
{cmd}
|
||||||
</Text>
|
</Text>
|
||||||
<Text color={t.color.dim}> — {desc}</Text>
|
|
||||||
|
{desc ? <Text color={t.color.dim}> — {desc}</Text> : null}
|
||||||
</Text>
|
</Text>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -147,37 +147,47 @@ export function Md({ compact, t, text }: { compact?: boolean; t: Theme; text: st
|
|||||||
|
|
||||||
if (line.match(/^>\s?/)) {
|
if (line.match(/^>\s?/)) {
|
||||||
const quoteLines: string[] = []
|
const quoteLines: string[] = []
|
||||||
|
|
||||||
while (i < lines.length && lines[i]!.match(/^>\s?/)) {
|
while (i < lines.length && lines[i]!.match(/^>\s?/)) {
|
||||||
quoteLines.push(lines[i]!.replace(/^>\s?/, ''))
|
quoteLines.push(lines[i]!.replace(/^>\s?/, ''))
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.push(
|
nodes.push(
|
||||||
<Box flexDirection="column" key={key}>
|
<Box flexDirection="column" key={key}>
|
||||||
{quoteLines.map((ql, qi) => (
|
{quoteLines.map((ql, qi) => (
|
||||||
<Text color={t.color.dim} key={qi}>
|
<Text color={t.color.dim} key={qi}>
|
||||||
{' │ '}<MdInline t={t} text={ql} />
|
{' │ '}
|
||||||
|
<MdInline t={t} text={ql} />
|
||||||
</Text>
|
</Text>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes('|') && line.trim().startsWith('|')) {
|
if (line.includes('|') && line.trim().startsWith('|')) {
|
||||||
const tableRows: string[][] = []
|
const tableRows: string[][] = []
|
||||||
|
|
||||||
while (i < lines.length && lines[i]!.trim().startsWith('|')) {
|
while (i < lines.length && lines[i]!.trim().startsWith('|')) {
|
||||||
const row = lines[i]!.trim()
|
const row = lines[i]!.trim()
|
||||||
|
|
||||||
if (!/^[|\s:-]+$/.test(row)) {
|
if (!/^[|\s:-]+$/.test(row)) {
|
||||||
tableRows.push(
|
tableRows.push(
|
||||||
row.split('|').filter(Boolean).map(c => c.trim())
|
row
|
||||||
|
.split('|')
|
||||||
|
.filter(Boolean)
|
||||||
|
.map(c => c.trim())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tableRows.length) {
|
if (tableRows.length) {
|
||||||
const widths = tableRows[0]!.map((_, ci) =>
|
const widths = tableRows[0]!.map((_, ci) => Math.max(...tableRows.map(r => (r[ci] ?? '').length)))
|
||||||
Math.max(...tableRows.map(r => (r[ci] ?? '').length))
|
|
||||||
)
|
|
||||||
nodes.push(
|
nodes.push(
|
||||||
<Box flexDirection="column" key={key} paddingLeft={2}>
|
<Box flexDirection="column" key={key} paddingLeft={2}>
|
||||||
{tableRows.map((row, ri) => (
|
{tableRows.map((row, ri) => (
|
||||||
@@ -188,6 +198,7 @@ export function Md({ compact, t, text }: { compact?: boolean; t: Theme; text: st
|
|||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ import { useState } from 'react'
|
|||||||
import type { Theme } from '../theme.js'
|
import type { Theme } from '../theme.js'
|
||||||
|
|
||||||
export function MaskedPrompt({
|
export function MaskedPrompt({
|
||||||
icon, label, onSubmit, sub, t
|
icon,
|
||||||
|
label,
|
||||||
|
onSubmit,
|
||||||
|
sub,
|
||||||
|
t
|
||||||
}: {
|
}: {
|
||||||
icon: string
|
icon: string
|
||||||
label: string
|
label: string
|
||||||
@@ -17,8 +21,10 @@ export function MaskedPrompt({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
<Text bold color={t.color.warn}>{icon} {label}</Text>
|
<Text bold color={t.color.warn}>
|
||||||
{sub && <Text color={t.color.dim}> {sub}</Text>}
|
{icon} {label}
|
||||||
|
</Text>
|
||||||
|
{sub && <Text color={t.color.dim}> {sub}</Text>}
|
||||||
|
|
||||||
<Box>
|
<Box>
|
||||||
<Text color={t.color.label}>{'> '}</Text>
|
<Text color={t.color.label}>{'> '}</Text>
|
||||||
|
|||||||
@@ -14,8 +14,15 @@ interface SessionItem {
|
|||||||
|
|
||||||
function age(ts: number): string {
|
function age(ts: number): string {
|
||||||
const d = (Date.now() / 1000 - ts) / 86400
|
const d = (Date.now() / 1000 - ts) / 86400
|
||||||
if (d < 1) return 'today'
|
|
||||||
if (d < 2) return 'yesterday'
|
if (d < 1) {
|
||||||
|
return 'today'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d < 2) {
|
||||||
|
return 'yesterday'
|
||||||
|
}
|
||||||
|
|
||||||
return `${Math.floor(d)}d ago`
|
return `${Math.floor(d)}d ago`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,16 +53,32 @@ export function SessionPicker({
|
|||||||
}, [gw])
|
}, [gw])
|
||||||
|
|
||||||
useInput((ch, key) => {
|
useInput((ch, key) => {
|
||||||
if (key.escape) return onCancel()
|
if (key.escape) {
|
||||||
if (key.upArrow && sel > 0) setSel(s => s - 1)
|
return onCancel()
|
||||||
if (key.downArrow && sel < items.length - 1) setSel(s => s + 1)
|
}
|
||||||
if (key.return && items[sel]) onSelect(items[sel]!.id)
|
|
||||||
|
if (key.upArrow && sel > 0) {
|
||||||
|
setSel(s => s - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.downArrow && sel < items.length - 1) {
|
||||||
|
setSel(s => s + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.return && items[sel]) {
|
||||||
|
onSelect(items[sel]!.id)
|
||||||
|
}
|
||||||
|
|
||||||
const n = parseInt(ch)
|
const n = parseInt(ch)
|
||||||
if (n >= 1 && n <= Math.min(9, items.length)) onSelect(items[n - 1]!.id)
|
|
||||||
|
if (n >= 1 && n <= Math.min(9, items.length)) {
|
||||||
|
onSelect(items[n - 1]!.id)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (loading) return <Text color={t.color.dim}>loading sessions…</Text>
|
if (loading) {
|
||||||
|
return <Text color={t.color.dim}>loading sessions…</Text>
|
||||||
|
}
|
||||||
|
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
return (
|
return (
|
||||||
@@ -71,10 +94,13 @@ export function SessionPicker({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
<Text bold color={t.color.amber}>Resume Session</Text>
|
<Text bold color={t.color.amber}>
|
||||||
{off > 0 && <Text color={t.color.dim}> ↑ {off} more</Text>}
|
Resume Session
|
||||||
|
</Text>
|
||||||
|
{off > 0 && <Text color={t.color.dim}> ↑ {off} more</Text>}
|
||||||
{visible.map((s, vi) => {
|
{visible.map((s, vi) => {
|
||||||
const i = off + vi
|
const i = off + vi
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text key={s.id}>
|
<Text key={s.id}>
|
||||||
<Text color={sel === i ? t.color.label : t.color.dim}>{sel === i ? '▸ ' : ' '}</Text>
|
<Text color={sel === i ? t.color.label : t.color.dim}>{sel === i ? '▸ ' : ' '}</Text>
|
||||||
@@ -82,12 +108,13 @@ export function SessionPicker({
|
|||||||
{i + 1}. {s.title || s.preview || s.id.slice(0, 8)}
|
{i + 1}. {s.title || s.preview || s.id.slice(0, 8)}
|
||||||
</Text>
|
</Text>
|
||||||
<Text color={t.color.dim}>
|
<Text color={t.color.dim}>
|
||||||
{' '}({s.message_count} msgs, {age(s.started_at)})
|
{' '}
|
||||||
|
({s.message_count} msgs, {age(s.started_at)})
|
||||||
</Text>
|
</Text>
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
{off + VISIBLE < items.length && <Text color={t.color.dim}> ↓ {items.length - off - VISIBLE} more</Text>}
|
{off + VISIBLE < items.length && <Text color={t.color.dim}> ↓ {items.length - off - VISIBLE} more</Text>}
|
||||||
<Text color={t.color.dim}>↑/↓ select · Enter resume · 1-9 quick · Esc cancel</Text>
|
<Text color={t.color.dim}>↑/↓ select · Enter resume · 1-9 quick · Esc cancel</Text>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,17 @@ import { pick } from '../lib/text.js'
|
|||||||
import type { Theme } from '../theme.js'
|
import type { Theme } from '../theme.js'
|
||||||
import type { ActiveTool } from '../types.js'
|
import type { ActiveTool } from '../types.js'
|
||||||
|
|
||||||
export function Thinking({ reasoning, t, thinking, tools }: { reasoning: string; t: Theme; thinking?: string; tools: ActiveTool[] }) {
|
export function Thinking({
|
||||||
|
reasoning,
|
||||||
|
t,
|
||||||
|
thinking,
|
||||||
|
tools
|
||||||
|
}: {
|
||||||
|
reasoning: string
|
||||||
|
t: Theme
|
||||||
|
thinking?: string
|
||||||
|
tools: ActiveTool[]
|
||||||
|
}) {
|
||||||
const [frame, setFrame] = useState(0)
|
const [frame, setFrame] = useState(0)
|
||||||
const [verb] = useState(() => pick(VERBS))
|
const [verb] = useState(() => pick(VERBS))
|
||||||
const [face] = useState(() => pick(FACES))
|
const [face] = useState(() => pick(FACES))
|
||||||
|
|||||||
@@ -1,50 +1,6 @@
|
|||||||
import type { Theme } from './theme.js'
|
import type { Theme } from './theme.js'
|
||||||
import type { Role, Usage } from './types.js'
|
import type { Role, Usage } from './types.js'
|
||||||
|
|
||||||
export const COMMANDS: [string, string][] = [
|
|
||||||
['/help', 'commands & hotkeys'],
|
|
||||||
['/new', 'new session'],
|
|
||||||
['/resume', 'resume a previous session'],
|
|
||||||
['/title', 'set session title'],
|
|
||||||
['/history', 'show session list'],
|
|
||||||
['/clear', 'reset session + chat'],
|
|
||||||
['/undo', 'drop last exchange'],
|
|
||||||
['/retry', 'resend last message'],
|
|
||||||
['/save', 'save conversation to file'],
|
|
||||||
['/compact', 'toggle compact [focus]'],
|
|
||||||
['/compress', 'compress context'],
|
|
||||||
['/model', 'switch model'],
|
|
||||||
['/skin', 'change theme'],
|
|
||||||
['/provider', 'show model/provider info'],
|
|
||||||
['/prompt', 'set custom system prompt'],
|
|
||||||
['/personality', 'set personality preset'],
|
|
||||||
['/verbose', 'cycle tool verbosity'],
|
|
||||||
['/yolo', 'toggle auto-approve mode'],
|
|
||||||
['/reasoning', 'set reasoning level'],
|
|
||||||
['/tools', 'list active tools'],
|
|
||||||
['/toolsets', 'list toolsets'],
|
|
||||||
['/skills', 'list skills'],
|
|
||||||
['/stop', 'kill background processes'],
|
|
||||||
['/background', 'run prompt in background'],
|
|
||||||
['/btw', 'side question (no tools)'],
|
|
||||||
['/plan', 'invoke plan skill'],
|
|
||||||
['/queue', 'queue prompt for next turn'],
|
|
||||||
['/profile', 'show active profile'],
|
|
||||||
['/cost', 'token usage stats'],
|
|
||||||
['/context', 'context window info'],
|
|
||||||
['/insights', 'usage analytics'],
|
|
||||||
['/copy', 'copy last response'],
|
|
||||||
['/paste', 'clipboard info'],
|
|
||||||
['/config', 'show config'],
|
|
||||||
['/status', 'session info'],
|
|
||||||
['/statusbar', 'toggle status bar'],
|
|
||||||
['/voice', 'voice mode toggle'],
|
|
||||||
['/reload-mcp', 'reload MCP servers'],
|
|
||||||
['/rollback', 'checkpoint info'],
|
|
||||||
['/browser', 'browser tools info'],
|
|
||||||
['/quit', 'exit hermes']
|
|
||||||
]
|
|
||||||
|
|
||||||
export const FACES = [
|
export const FACES = [
|
||||||
'(。•́︿•̀。)',
|
'(。•́︿•̀。)',
|
||||||
'(◔_◔)',
|
'(◔_◔)',
|
||||||
@@ -67,6 +23,7 @@ export const HOTKEYS: [string, string][] = [
|
|||||||
['Ctrl+C', 'interrupt / clear / exit'],
|
['Ctrl+C', 'interrupt / clear / exit'],
|
||||||
['Ctrl+D', 'exit'],
|
['Ctrl+D', 'exit'],
|
||||||
['Ctrl+L', 'clear screen'],
|
['Ctrl+L', 'clear screen'],
|
||||||
|
['Tab', 'complete /commands (registry-aware)'],
|
||||||
['↑/↓', 'queue edit (if queued) / input history'],
|
['↑/↓', 'queue edit (if queued) / input history'],
|
||||||
['PgUp/PgDn', 'scroll messages'],
|
['PgUp/PgDn', 'scroll messages'],
|
||||||
['Esc', 'clear input'],
|
['Esc', 'clear input'],
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
|
||||||
import { render } from 'ink'
|
import { render } from 'ink'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
import { App } from './app.js'
|
import { App } from './app.js'
|
||||||
import { GatewayClient } from './gatewayClient.js'
|
import { GatewayClient } from './gatewayClient.js'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { existsSync, mkdirSync, readFileSync, appendFileSync } from 'node:fs'
|
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs'
|
||||||
import { homedir } from 'node:os'
|
import { homedir } from 'node:os'
|
||||||
import { join } from 'node:path'
|
import { join } from 'node:path'
|
||||||
|
|
||||||
@@ -17,34 +17,51 @@ function decode(s: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function load(): string[] {
|
export function load(): string[] {
|
||||||
if (cache) return cache
|
if (cache) {
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (existsSync(file)) {
|
if (existsSync(file)) {
|
||||||
cache = readFileSync(file, 'utf8')
|
cache = readFileSync(file, 'utf8').split('\n').filter(Boolean).map(decode).slice(-MAX)
|
||||||
.split('\n')
|
|
||||||
.filter(Boolean)
|
|
||||||
.map(decode)
|
|
||||||
.slice(-MAX)
|
|
||||||
} else {
|
} else {
|
||||||
cache = []
|
cache = []
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
cache = []
|
cache = []
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache
|
return cache
|
||||||
}
|
}
|
||||||
|
|
||||||
export function append(line: string): void {
|
export function append(line: string): void {
|
||||||
const trimmed = line.trim()
|
const trimmed = line.trim()
|
||||||
if (!trimmed) return
|
|
||||||
|
if (!trimmed) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const items = load()
|
const items = load()
|
||||||
if (items.at(-1) === trimmed) return
|
|
||||||
|
if (items.at(-1) === trimmed) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
items.push(trimmed)
|
items.push(trimmed)
|
||||||
if (items.length > MAX) items.splice(0, items.length - MAX)
|
|
||||||
|
if (items.length > MAX) {
|
||||||
|
items.splice(0, items.length - MAX)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
if (!existsSync(dir)) {
|
||||||
|
mkdirSync(dir, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
appendFileSync(file, encode(trimmed) + '\n')
|
appendFileSync(file, encode(trimmed) + '\n')
|
||||||
} catch { /* ignore */ }
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function all(): string[] {
|
export function all(): string[] {
|
||||||
|
|||||||
124
ui-tui/src/lib/slash.ts
Normal file
124
ui-tui/src/lib/slash.ts
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import type { SlashCatalog } from '../types.js'
|
||||||
|
|
||||||
|
/** Match SlashCommandCompleter: command names, subcommands, then skills. */
|
||||||
|
export function paletteForLine(line: string, c: SlashCatalog | null): [string, string][] {
|
||||||
|
if (!c || !line.startsWith('/')) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = line.split(/\s+/)
|
||||||
|
const baseRaw = parts[0]!
|
||||||
|
const base = baseRaw.toLowerCase()
|
||||||
|
const inSub = parts.length > 1 || (parts.length === 1 && line.endsWith(' '))
|
||||||
|
|
||||||
|
if (inSub) {
|
||||||
|
const subText = parts.length > 1 ? parts.slice(1).join(' ') : ''
|
||||||
|
|
||||||
|
if (subText.includes(' ') || parts.length > 2) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const head = subText.split(/\s+/)[0] ?? ''
|
||||||
|
|
||||||
|
if (subText.includes(' ') && head !== subText) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const canonical = c.canon[base] ?? baseRaw
|
||||||
|
const subs = c.sub[canonical]
|
||||||
|
|
||||||
|
if (!subs?.length) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const lo = head.toLowerCase()
|
||||||
|
|
||||||
|
return subs
|
||||||
|
.filter(s => s.toLowerCase().startsWith(lo) && s.toLowerCase() !== lo)
|
||||||
|
.slice(0, 14)
|
||||||
|
.map(s => [s, ''])
|
||||||
|
}
|
||||||
|
|
||||||
|
const word = line.slice(1)
|
||||||
|
|
||||||
|
return c.pairs
|
||||||
|
.filter(([k]) => k.slice(1).startsWith(word))
|
||||||
|
.slice(0, 16)
|
||||||
|
.map(([k, d]) => [k, d])
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tab: longest common prefix of palette matches, or first unique completion + space. */
|
||||||
|
export function tabAdvance(line: string, c: SlashCatalog | null): string | null {
|
||||||
|
if (!c || !line.startsWith('/')) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = paletteForLine(line, c)
|
||||||
|
|
||||||
|
if (!rows.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = line.split(/\s+/)
|
||||||
|
const baseRaw = parts[0]!
|
||||||
|
const base = baseRaw.toLowerCase()
|
||||||
|
const inSub = parts.length > 1 || (parts.length === 1 && line.endsWith(' '))
|
||||||
|
|
||||||
|
if (inSub) {
|
||||||
|
const subText = parts.length > 1 ? parts.slice(1).join(' ') : ''
|
||||||
|
const head = subText.split(/\s+/)[0] ?? ''
|
||||||
|
const picks = rows.map(([s]) => s)
|
||||||
|
|
||||||
|
if (picks.length === 1) {
|
||||||
|
return `${baseRaw} ${picks[0]!} `
|
||||||
|
}
|
||||||
|
|
||||||
|
const cp = commonPrefix(picks)
|
||||||
|
|
||||||
|
if (cp.length > head.length) {
|
||||||
|
return `${baseRaw} ${cp}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const word = line.slice(1)
|
||||||
|
const names = rows.map(([k]) => k.slice(1))
|
||||||
|
const cp = commonPrefix(names)
|
||||||
|
|
||||||
|
if (names.length === 1) {
|
||||||
|
return `/${names[0]!} `
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cp.length > word.length) {
|
||||||
|
return `/${cp}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function commonPrefix(xs: string[]): string {
|
||||||
|
if (!xs.length) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
let n = 0
|
||||||
|
|
||||||
|
outer: while (true) {
|
||||||
|
const ch = xs[0]![n]
|
||||||
|
|
||||||
|
if (ch === undefined) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const x of xs) {
|
||||||
|
if (x[n] !== ch) {
|
||||||
|
break outer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
|
||||||
|
return xs[0]!.slice(0, n)
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
|
||||||
import { render } from 'ink'
|
import { render } from 'ink'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
import { App } from './app.js'
|
import { App } from './app.js'
|
||||||
import { GatewayClient } from './gatewayClient.js'
|
import { GatewayClient } from './gatewayClient.js'
|
||||||
|
|||||||
@@ -43,3 +43,10 @@ export interface SecretReq {
|
|||||||
prompt: string
|
prompt: string
|
||||||
requestId: string
|
requestId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** From `commands.catalog` — mirrors hermes_cli.commands COMMANDS + SUBCOMMANDS + skills. */
|
||||||
|
export interface SlashCatalog {
|
||||||
|
canon: Record<string, string>
|
||||||
|
pairs: [string, string][]
|
||||||
|
sub: Record<string, string[]>
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user