mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-29 01:31:41 +00:00
refactor(tui): store-driven turn state + slash registry + module split
Hoist turn state from a 286-line hook into $turnState atom + turnController
singleton. createGatewayEventHandler becomes a typed dispatch over the
controller; its ctx shrinks from 30 fields to 5. Event-handler refs and 16
threaded actions are gone.
Fold three createSlash*Handler factories into a data-driven SlashCommand[]
registry under slash/commands/{core,session,ops}.ts. Aliases are data;
findSlashCommand does name+alias lookup. Shared guarded/guardedErr combinator
in slash/guarded.ts.
Split constants.ts + app/helpers.ts into config/ (timing/limits/env),
content/ (faces/placeholders/hotkeys/verbs/charms/fortunes), domain/ (roles/
details/messages/paths/slash/viewport/usage), protocol/ (interpolation/paste).
Type every RPC response in gatewayTypes.ts (26 new interfaces); drop all
`(r: any)` across slash + main app.
Shrink useMainApp from 1216 -> 646 lines by extracting useSessionLifecycle,
useSubmission, useConfigSync. Add <Fg> themed primitive and strip ~50
`as any` color casts.
Tests: 50 passing. Build + type-check clean.
This commit is contained in:
parent
9c71f3a6ea
commit
68ecdb6e26
56 changed files with 3666 additions and 4117 deletions
1
ui-tui/src/content/charms.ts
Normal file
1
ui-tui/src/content/charms.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export const LONG_RUN_CHARMS = ['still cooking…', 'polishing edges…', 'asking the void nicely…']
|
||||
17
ui-tui/src/content/faces.ts
Normal file
17
ui-tui/src/content/faces.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
export const FACES = [
|
||||
'(。•́︿•̀。)',
|
||||
'(◔_◔)',
|
||||
'(¬‿¬)',
|
||||
'( •_•)>⌐■-■',
|
||||
'(⌐■_■)',
|
||||
'(´・_・`)',
|
||||
'◉_◉',
|
||||
'(°ロ°)',
|
||||
'( ˘⌣˘)♡',
|
||||
'ヽ(>∀<☆)☆',
|
||||
'٩(๑❛ᴗ❛๑)۶',
|
||||
'(⊙_⊙)',
|
||||
'(¬_¬)',
|
||||
'( ͡° ͜ʖ ͡°)',
|
||||
'ಠ_ಠ'
|
||||
]
|
||||
40
ui-tui/src/content/fortunes.ts
Normal file
40
ui-tui/src/content/fortunes.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
const FORTUNES = [
|
||||
'you are one clean refactor away from clarity',
|
||||
'a tiny rename today prevents a huge bug tomorrow',
|
||||
'your next commit message will be immaculate',
|
||||
'the edge case you are ignoring is already solved in your head',
|
||||
'minimal diff, maximal calm',
|
||||
'today favors bold deletions over new abstractions',
|
||||
'the right helper is already in your codebase',
|
||||
'you will ship before overthinking catches up',
|
||||
'tests are about to save your future self',
|
||||
'your instincts are correctly suspicious of that one branch'
|
||||
]
|
||||
|
||||
const LEGENDARY_FORTUNES = [
|
||||
'legendary drop: one-line fix, first try',
|
||||
'legendary drop: every flaky test passes cleanly',
|
||||
'legendary drop: your diff teaches by itself'
|
||||
]
|
||||
|
||||
const hash = (input: string) => {
|
||||
let out = 2166136261
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
out ^= input.charCodeAt(i)
|
||||
out = Math.imul(out, 16777619)
|
||||
}
|
||||
|
||||
return out >>> 0
|
||||
}
|
||||
|
||||
const fromScore = (score: number) => {
|
||||
const rare = score % 20 === 0
|
||||
const bag = rare ? LEGENDARY_FORTUNES : FORTUNES
|
||||
|
||||
return `${rare ? '🌟' : '🔮'} ${bag[score % bag.length]}`
|
||||
}
|
||||
|
||||
export const randomFortune = () => fromScore(Math.floor(Math.random() * 0x7fffffff))
|
||||
|
||||
export const dailyFortune = (seed: null | string) => fromScore(hash(`${seed || 'anon'}|${new Date().toDateString()}`))
|
||||
19
ui-tui/src/content/hotkeys.ts
Normal file
19
ui-tui/src/content/hotkeys.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export const HOTKEYS: [string, string][] = [
|
||||
['Ctrl+C', 'interrupt / clear draft / exit'],
|
||||
['Ctrl+D', 'exit'],
|
||||
['Ctrl+G', 'open $EDITOR for prompt'],
|
||||
['Ctrl+L', 'new session (clear)'],
|
||||
['Alt+V / /paste', 'paste clipboard image'],
|
||||
['Tab', 'apply completion'],
|
||||
['↑/↓', 'completions / queue edit / history'],
|
||||
['Ctrl+A/E', 'home / end of line'],
|
||||
['Ctrl+Z / Ctrl+Y', 'undo / redo input edits'],
|
||||
['Ctrl+W', 'delete word'],
|
||||
['Ctrl+U/K', 'delete to start / end'],
|
||||
['Ctrl+←/→', 'jump word'],
|
||||
['Home/End', 'start / end of line'],
|
||||
['Shift+Enter / Alt+Enter', 'insert newline'],
|
||||
['\\+Enter', 'multi-line continuation (fallback)'],
|
||||
['!cmd', 'run shell command'],
|
||||
['{!cmd}', 'interpolate shell output inline']
|
||||
]
|
||||
13
ui-tui/src/content/placeholders.ts
Normal file
13
ui-tui/src/content/placeholders.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { pick } from '../lib/text.js'
|
||||
|
||||
export const PLACEHOLDERS = [
|
||||
'Ask me anything…',
|
||||
'Try "explain this codebase"',
|
||||
'Try "write a test for…"',
|
||||
'Try "refactor the auth module"',
|
||||
'Try "/help" for commands',
|
||||
'Try "fix the lint errors"',
|
||||
'Try "how does the config loader work?"'
|
||||
]
|
||||
|
||||
export const PLACEHOLDER = pick(PLACEHOLDERS)
|
||||
38
ui-tui/src/content/verbs.ts
Normal file
38
ui-tui/src/content/verbs.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
export const TOOL_VERBS: Record<string, string> = {
|
||||
browser: 'browsing',
|
||||
clarify: 'asking',
|
||||
create_file: 'creating',
|
||||
delegate_task: 'delegating',
|
||||
delete_file: 'deleting',
|
||||
execute_code: 'executing',
|
||||
image_generate: 'generating',
|
||||
list_files: 'listing',
|
||||
memory: 'remembering',
|
||||
patch: 'patching',
|
||||
read_file: 'reading',
|
||||
run_command: 'running',
|
||||
search_code: 'searching',
|
||||
search_files: 'searching',
|
||||
terminal: 'terminal',
|
||||
web_extract: 'extracting',
|
||||
web_search: 'searching',
|
||||
write_file: 'writing'
|
||||
}
|
||||
|
||||
export const VERBS = [
|
||||
'pondering',
|
||||
'contemplating',
|
||||
'musing',
|
||||
'cogitating',
|
||||
'ruminating',
|
||||
'deliberating',
|
||||
'mulling',
|
||||
'reflecting',
|
||||
'processing',
|
||||
'reasoning',
|
||||
'analyzing',
|
||||
'computing',
|
||||
'synthesizing',
|
||||
'formulating',
|
||||
'brainstorming'
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue