herm-tui 1.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +54 -0
- package/package.json +82 -0
- package/scripts/postinstall.ts +29 -0
- package/src/app/gateway.tsx +83 -0
- package/src/app/gatewayEvents.ts +203 -0
- package/src/app/launch.ts +41 -0
- package/src/app/skin.tsx +31 -0
- package/src/app/spawnHistory.ts +75 -0
- package/src/app/tabs.ts +23 -0
- package/src/app/turnReducer.ts +390 -0
- package/src/app/useAppKeys.ts +268 -0
- package/src/app/useAtRefPopover.ts +99 -0
- package/src/app/useInputHistory.ts +66 -0
- package/src/app/useSession.ts +102 -0
- package/src/app/useSlashCommands.ts +70 -0
- package/src/app/useSlashPopover.ts +48 -0
- package/src/app.tsx +917 -0
- package/src/commands/slash.ts +151 -0
- package/src/components/avatar/AnimatedAvatar.tsx +66 -0
- package/src/components/avatar/eikon.ts +144 -0
- package/src/components/avatar/states/error.ts +1155 -0
- package/src/components/avatar/states/idle.ts +1155 -0
- package/src/components/avatar/states/index.ts +30 -0
- package/src/components/avatar/states/listening.ts +1155 -0
- package/src/components/avatar/states/speaking.ts +1155 -0
- package/src/components/avatar/states/thinking.ts +1155 -0
- package/src/components/avatar/states/working.ts +1155 -0
- package/src/components/chat/AtRefPopover.tsx +54 -0
- package/src/components/chat/CodeBlock.tsx +67 -0
- package/src/components/chat/Composer.tsx +347 -0
- package/src/components/chat/DiffBlock.tsx +116 -0
- package/src/components/chat/ErrorBlock.tsx +70 -0
- package/src/components/chat/MediaChip.tsx +114 -0
- package/src/components/chat/MessageItem.tsx +282 -0
- package/src/components/chat/MessageList.tsx +114 -0
- package/src/components/chat/PromptCard.tsx +359 -0
- package/src/components/chat/SlashPopover.tsx +158 -0
- package/src/components/chat/ThoughtCloud.tsx +185 -0
- package/src/components/chat/TypingIndicator.tsx +25 -0
- package/src/components/chat/tool/Subagent.tsx +75 -0
- package/src/components/chat/tool/frame.tsx +69 -0
- package/src/components/chat/tool/index.tsx +65 -0
- package/src/components/chat/tool/preview.ts +57 -0
- package/src/components/sidebar/ContextGauge.tsx +102 -0
- package/src/components/sidebar/Sidebar.tsx +143 -0
- package/src/components/tabs/TabBar.tsx +50 -0
- package/src/components/ui/FileLink.tsx +52 -0
- package/src/config/index.ts +156 -0
- package/src/config/lane.ts +161 -0
- package/src/config/models.ts +95 -0
- package/src/config/rules.ts +80 -0
- package/src/config/schema.ts +308 -0
- package/src/dialogs/alert.tsx +52 -0
- package/src/dialogs/chafa.tsx +72 -0
- package/src/dialogs/confirm.tsx +58 -0
- package/src/dialogs/curator.tsx +153 -0
- package/src/dialogs/eikon-picker.tsx +95 -0
- package/src/dialogs/help.tsx +80 -0
- package/src/dialogs/history.tsx +92 -0
- package/src/dialogs/info.tsx +115 -0
- package/src/dialogs/keys.tsx +170 -0
- package/src/dialogs/logs.tsx +42 -0
- package/src/dialogs/message.tsx +38 -0
- package/src/dialogs/model-picker.tsx +123 -0
- package/src/dialogs/new-profile.tsx +69 -0
- package/src/dialogs/new-task.tsx +103 -0
- package/src/dialogs/profile.tsx +55 -0
- package/src/dialogs/rollback.tsx +190 -0
- package/src/dialogs/spawn-history.tsx +80 -0
- package/src/dialogs/text-prompt.tsx +68 -0
- package/src/dialogs/theme-picker.tsx +50 -0
- package/src/home/index.ts +23 -0
- package/src/home/store.ts +267 -0
- package/src/index.tsx +113 -0
- package/src/keys/catalog.ts +115 -0
- package/src/keys/chord.ts +125 -0
- package/src/keys/conflicts.ts +48 -0
- package/src/keys/context.tsx +112 -0
- package/src/keys/index.ts +5 -0
- package/src/keys/list.ts +94 -0
- package/src/keys/oc-compat.ts +87 -0
- package/src/tabs/Agents.tsx +607 -0
- package/src/tabs/Analytics.tsx +154 -0
- package/src/tabs/Chat.tsx +50 -0
- package/src/tabs/Config.tsx +605 -0
- package/src/tabs/Context.tsx +599 -0
- package/src/tabs/Cron.tsx +294 -0
- package/src/tabs/Env.tsx +227 -0
- package/src/tabs/Kanban.tsx +367 -0
- package/src/tabs/Memory.tsx +294 -0
- package/src/tabs/Sessions.tsx +786 -0
- package/src/tabs/Skills.tsx +507 -0
- package/src/tabs/Toolsets.tsx +266 -0
- package/src/theme/builtin.ts +78 -0
- package/src/theme/context.tsx +106 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/resolve.ts +134 -0
- package/src/theme/syntax.ts +31 -0
- package/src/theme/themes/aura.json +69 -0
- package/src/theme/themes/ayu.json +80 -0
- package/src/theme/themes/carbonfox.json +248 -0
- package/src/theme/themes/catppuccin-frappe.json +233 -0
- package/src/theme/themes/catppuccin-macchiato.json +233 -0
- package/src/theme/themes/catppuccin.json +112 -0
- package/src/theme/themes/cobalt2.json +228 -0
- package/src/theme/themes/cursor.json +249 -0
- package/src/theme/themes/dracula.json +219 -0
- package/src/theme/themes/everforest.json +241 -0
- package/src/theme/themes/flexoki.json +237 -0
- package/src/theme/themes/github.json +233 -0
- package/src/theme/themes/gruvbox.json +242 -0
- package/src/theme/themes/kanagawa.json +77 -0
- package/src/theme/themes/lucent-orng.json +237 -0
- package/src/theme/themes/material.json +235 -0
- package/src/theme/themes/matrix.json +77 -0
- package/src/theme/themes/mercury.json +252 -0
- package/src/theme/themes/monokai.json +221 -0
- package/src/theme/themes/nightowl.json +221 -0
- package/src/theme/themes/nord.json +223 -0
- package/src/theme/themes/one-dark.json +84 -0
- package/src/theme/themes/opencode.json +245 -0
- package/src/theme/themes/orng.json +249 -0
- package/src/theme/themes/osaka-jade.json +93 -0
- package/src/theme/themes/palenight.json +222 -0
- package/src/theme/themes/rosepine.json +234 -0
- package/src/theme/themes/solarized.json +223 -0
- package/src/theme/themes/synthwave84.json +226 -0
- package/src/theme/themes/tokyonight.json +243 -0
- package/src/theme/themes/vercel.json +245 -0
- package/src/theme/themes/vesper.json +218 -0
- package/src/theme/themes/zenburn.json +223 -0
- package/src/theme/types.ts +119 -0
- package/src/types/message.ts +97 -0
- package/src/ui/ChafaImage.tsx +64 -0
- package/src/ui/Splash.tsx +118 -0
- package/src/ui/borders.ts +28 -0
- package/src/ui/command.tsx +104 -0
- package/src/ui/dialog-select.tsx +164 -0
- package/src/ui/dialog.tsx +102 -0
- package/src/ui/fmt.ts +82 -0
- package/src/ui/kv.tsx +28 -0
- package/src/ui/shell.tsx +45 -0
- package/src/ui/spinner.tsx +59 -0
- package/src/ui/splash-art.ts +123 -0
- package/src/ui/table.tsx +117 -0
- package/src/ui/ticker.tsx +90 -0
- package/src/ui/toast.tsx +130 -0
- package/src/utils/categorical.ts +77 -0
- package/src/utils/chafa.ts +173 -0
- package/src/utils/clipboard.ts +67 -0
- package/src/utils/context-segments.ts +317 -0
- package/src/utils/control.ts +495 -0
- package/src/utils/drop.ts +25 -0
- package/src/utils/editor.ts +33 -0
- package/src/utils/fuzzy.ts +45 -0
- package/src/utils/gateway-client.ts +253 -0
- package/src/utils/gateway-types.ts +282 -0
- package/src/utils/git.ts +57 -0
- package/src/utils/hermes-analytics.ts +134 -0
- package/src/utils/hermes-home.ts +821 -0
- package/src/utils/hermes-kanban.ts +154 -0
- package/src/utils/hermes-profiles.ts +217 -0
- package/src/utils/interpolate.ts +31 -0
- package/src/utils/math-unicode.ts +818 -0
- package/src/utils/memory-activity.ts +140 -0
- package/src/utils/open-file.ts +13 -0
- package/src/utils/paths.ts +52 -0
- package/src/utils/perf.ts +235 -0
- package/src/utils/preferences.ts +150 -0
- package/src/utils/sessions-db.ts +396 -0
- package/src/utils/subagent-tree.ts +146 -0
- package/src/utils/terminal-reset.ts +129 -0
- package/src/utils/tips.ts +67 -0
- package/src/utils/tokens.ts +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 liftaris
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Herm - Dashboard TUI for Hermes
|
|
2
|
+
<img width="1711" height="927" alt="image" src="https://github.com/user-attachments/assets/d3b855a0-b1b2-4ea1-8eab-84f9716c8de9" />
|
|
3
|
+
|
|
4
|
+
> **herm** /hɜːm/ _noun_ : a sculptured head of Hermes on a square stone pillar, used in ancient Greece as a boundary marker at crossroads.
|
|
5
|
+
|
|
6
|
+
Herm is a tabbed, mouse-aware TUI built with [OpenTUI](https://github.com/anomalyco/opentui) (React renderer) and [Bun](https://bun.sh/). It talks to the same gateway `hermes` cli uses.
|
|
7
|
+
|
|
8
|
+
## What it does
|
|
9
|
+
|
|
10
|
+
- **Chat** with streaming, markdown, code blocks, diff rendering, tool-call expansion, and an animated ASCII avatar
|
|
11
|
+
- **Tabs** for sessions, context, agents, skills, cron, toolsets, memory, env, config
|
|
12
|
+
- **Command palette** (`Ctrl+K`), **slash popover**, **@-refs** for file/diff context
|
|
13
|
+
- **Fully rebindable keys** (`/keys`) and theme picker
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
Herm needs a working [Hermes Agent](https://github.com/NousResearch/hermes-agent) install and [Bun](https://bun.sh).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
bun add -g herm-tui # stable
|
|
21
|
+
bun add -g herm-tui@next # bleeding edge (every dev push)
|
|
22
|
+
herm
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or from source:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/liftaris/herm.git
|
|
29
|
+
cd herm && bun install
|
|
30
|
+
bun run src/index.tsx
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Herm looks for `~/.hermes`. If yours lives elsewhere, set `HERMES_HOME`. See [`.env.example`](./.env.example) for rarely-needed overrides.
|
|
34
|
+
|
|
35
|
+
## Development
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bun run dev # watch mode
|
|
39
|
+
bun run typecheck
|
|
40
|
+
bun test
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Motivation
|
|
44
|
+
Before Hermes, OpenCode was my daily driver. I built Herm because I wanted Hermes capabilities with an OpenCode style interface. Herm uses the same TUI framework OpenCode is built with, OpenTUI, and also exposes dashboard style tabs that centralizes everything I need to do in Hermes in my interface of choice--the terminal.
|
|
45
|
+
|
|
46
|
+
## Acknowledgments
|
|
47
|
+
|
|
48
|
+
- [Hermes Agent](https://github.com/NousResearch/hermes-agent) — the brain
|
|
49
|
+
- [OpenTUI](https://github.com/anomalyco/opentui) — the TUI framework
|
|
50
|
+
- [OpenCode](https://github.com/anomalyco/opencode) — the inspiration
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT — see [LICENSE](./LICENSE).
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "herm-tui",
|
|
3
|
+
"version": "1.0.0-dev.1",
|
|
4
|
+
"description": "A modern TUI for Hermes Agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"provenance": true
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/liftaris/herm.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/liftaris/herm#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/liftaris/herm/issues"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"herm": "src/index.tsx"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"bun": ">=1.3.0"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"src",
|
|
27
|
+
"!src/**/*.test.*",
|
|
28
|
+
"scripts/postinstall.ts",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "bun run --watch src/index.tsx",
|
|
34
|
+
"dev:perf": "PERF=1 bun run --watch src/index.tsx",
|
|
35
|
+
"dev:perf:verbose": "PERF=verbose bun run --watch src/index.tsx",
|
|
36
|
+
"dev:smol": "bun --smol run --watch src/index.tsx",
|
|
37
|
+
"dev:profile": "bun --cpu-prof --cpu-prof-dir=./profiles run src/index.tsx",
|
|
38
|
+
"dev:heap": "bun --heap-prof --heap-prof-dir=./profiles run src/index.tsx",
|
|
39
|
+
"dev:control": "CONTROL=1 bun run --watch src/index.tsx",
|
|
40
|
+
"dev:full": "PERF=1 CONTROL=1 bun run --watch src/index.tsx",
|
|
41
|
+
"gen-schema": "bun scripts/gen-schema.ts",
|
|
42
|
+
"showcase": "scripts/showcase/record.sh",
|
|
43
|
+
"build": "bun scripts/gen-schema.ts && bun build src/index.tsx node_modules/@opentui/core/parser.worker.js scripts/parser-worker-shim.ts --target=bun --outdir=dist --minify --entry-naming='[name].[ext]' && mv dist/parser-worker-shim.js dist/parser.worker.shim.js && test -f dist/parser.worker.js && test -f dist/parser.worker.shim.js",
|
|
44
|
+
"start": "bun run dist/index.js",
|
|
45
|
+
"test": "bun test",
|
|
46
|
+
"typecheck": "bunx tsc --noEmit",
|
|
47
|
+
"postinstall": "bun run scripts/postinstall.ts"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@opentui/core": "0.1.99",
|
|
51
|
+
"@opentui/react": "0.1.99",
|
|
52
|
+
"gpt-tokenizer": "^3.4.0",
|
|
53
|
+
"open": "^11.0.0",
|
|
54
|
+
"react": "^19.2.5",
|
|
55
|
+
"web-tree-sitter": "0.25.10",
|
|
56
|
+
"yaml": "^2.8.3"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
60
|
+
"@semantic-release/git": "^10.0.1",
|
|
61
|
+
"@types/bun": "1.3.13",
|
|
62
|
+
"@types/react": "^19.2.14",
|
|
63
|
+
"semantic-release": "^25.0.3",
|
|
64
|
+
"typescript": "^5.8.2"
|
|
65
|
+
},
|
|
66
|
+
"overrides": {
|
|
67
|
+
"three": "npm:empty-npm-package@1.0.0",
|
|
68
|
+
"planck": "npm:empty-npm-package@1.0.0",
|
|
69
|
+
"bun-webgpu": "npm:empty-npm-package@1.0.0",
|
|
70
|
+
"@dimforge/rapier2d-simd-compat": "npm:empty-npm-package@1.0.0",
|
|
71
|
+
"jimp": "npm:empty-npm-package@1.0.0",
|
|
72
|
+
"@jimp/core": "npm:empty-npm-package@1.0.0",
|
|
73
|
+
"@jimp/js-bmp": "npm:empty-npm-package@1.0.0",
|
|
74
|
+
"@jimp/js-gif": "npm:empty-npm-package@1.0.0",
|
|
75
|
+
"@jimp/js-jpeg": "npm:empty-npm-package@1.0.0",
|
|
76
|
+
"@jimp/js-png": "npm:empty-npm-package@1.0.0",
|
|
77
|
+
"@jimp/js-tiff": "npm:empty-npm-package@1.0.0",
|
|
78
|
+
"@jimp/plugin-resize": "npm:empty-npm-package@1.0.0",
|
|
79
|
+
"@jimp/types": "npm:empty-npm-package@1.0.0",
|
|
80
|
+
"@jimp/utils": "npm:empty-npm-package@1.0.0"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postinstall — stub out heavy optional dependencies that @opentui/core
|
|
3
|
+
* and @opentui/react pull in but Herm never uses.
|
|
4
|
+
*
|
|
5
|
+
* react-devtools-core is imported statically by @opentui/react, so it needs
|
|
6
|
+
* a real module that exports the expected API shape (not just an empty package).
|
|
7
|
+
*/
|
|
8
|
+
import { mkdirSync, writeFileSync, existsSync } from "fs"
|
|
9
|
+
import { join } from "path"
|
|
10
|
+
|
|
11
|
+
const nm = join(import.meta.dir, "..", "node_modules")
|
|
12
|
+
|
|
13
|
+
// Stub react-devtools-core with noop exports
|
|
14
|
+
const rdcDir = join(nm, "react-devtools-core")
|
|
15
|
+
if (!existsSync(rdcDir)) {
|
|
16
|
+
mkdirSync(rdcDir, { recursive: true })
|
|
17
|
+
writeFileSync(
|
|
18
|
+
join(rdcDir, "package.json"),
|
|
19
|
+
JSON.stringify({ name: "react-devtools-core", version: "0.0.0", main: "index.js" })
|
|
20
|
+
)
|
|
21
|
+
writeFileSync(
|
|
22
|
+
join(rdcDir, "index.js"),
|
|
23
|
+
[
|
|
24
|
+
"const noop = () => {};",
|
|
25
|
+
"module.exports = { initialize: noop, connectToDevTools: noop };",
|
|
26
|
+
"module.exports.default = module.exports;",
|
|
27
|
+
].join("\n")
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// GatewayClient exposed via React context. The provider accepts an
|
|
2
|
+
// injected client so tests can substitute a MockGateway without
|
|
3
|
+
// spawning the Python tui_gateway subprocess.
|
|
4
|
+
|
|
5
|
+
import { createContext, useContext, useEffect, useRef, useState, useMemo } from "react"
|
|
6
|
+
import type { ReactNode } from "react"
|
|
7
|
+
import { EventEmitter } from "events"
|
|
8
|
+
import { GatewayClient } from "../utils/gateway-client"
|
|
9
|
+
import type { GatewayEvent } from "../utils/gateway-types"
|
|
10
|
+
|
|
11
|
+
/** Minimal surface consumers depend on. GatewayClient satisfies this. */
|
|
12
|
+
export interface Gateway extends EventEmitter {
|
|
13
|
+
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>
|
|
14
|
+
setSession(sid: string): void
|
|
15
|
+
start(): void
|
|
16
|
+
drain(): void
|
|
17
|
+
kill(): void
|
|
18
|
+
tail(n?: number): string
|
|
19
|
+
readonly ready: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Ctx = {
|
|
23
|
+
client: Gateway
|
|
24
|
+
ready: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Gw = createContext<Ctx | null>(null)
|
|
28
|
+
|
|
29
|
+
export const GatewayProvider = ({ client, children }: { client?: Gateway; children: ReactNode }) => {
|
|
30
|
+
const ref = useRef<Gateway | null>(null)
|
|
31
|
+
if (!ref.current) ref.current = client ?? new GatewayClient()
|
|
32
|
+
const [ready, setReady] = useState(ref.current.ready)
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const c = ref.current!
|
|
36
|
+
const onEvent = (ev: GatewayEvent) => {
|
|
37
|
+
if (ev.type === "gateway.ready" || ev.type === "session.info") setReady(true)
|
|
38
|
+
}
|
|
39
|
+
c.on("event", onEvent)
|
|
40
|
+
c.start()
|
|
41
|
+
c.drain()
|
|
42
|
+
return () => {
|
|
43
|
+
c.off("event", onEvent)
|
|
44
|
+
c.removeAllListeners()
|
|
45
|
+
c.kill()
|
|
46
|
+
}
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
const value = useMemo<Ctx>(() => ({ client: ref.current!, ready }), [ready])
|
|
50
|
+
return <Gw.Provider value={value}>{children}</Gw.Provider>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useGateway(): Gateway {
|
|
54
|
+
const ctx = useContext(Gw)
|
|
55
|
+
if (!ctx) throw new Error("useGateway() must be inside <GatewayProvider>")
|
|
56
|
+
return ctx.client
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Subscribe to all gateway events. The first subscription drains any
|
|
61
|
+
* events buffered before React mounted, so nothing is lost between
|
|
62
|
+
* `client.start()` and component wiring.
|
|
63
|
+
*/
|
|
64
|
+
export function useGatewayEvent(handler: (ev: GatewayEvent) => void): void {
|
|
65
|
+
const ctx = useContext(Gw)
|
|
66
|
+
if (!ctx) throw new Error("useGatewayEvent() must be inside <GatewayProvider>")
|
|
67
|
+
const ref = useRef(handler)
|
|
68
|
+
ref.current = handler
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const c = ctx.client
|
|
71
|
+
const fn = (ev: GatewayEvent) => ref.current(ev)
|
|
72
|
+
c.on("event", fn)
|
|
73
|
+
c.drain()
|
|
74
|
+
return () => { c.off("event", fn) }
|
|
75
|
+
}, [ctx.client])
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** True once gateway.ready or session.info has fired. */
|
|
79
|
+
export function useGatewayReady(): boolean {
|
|
80
|
+
const ctx = useContext(Gw)
|
|
81
|
+
if (!ctx) throw new Error("useGatewayReady() must be inside <GatewayProvider>")
|
|
82
|
+
return ctx.ready
|
|
83
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Maps a GatewayEvent to a turn-reducer Action plus fire-and-forget side effects.
|
|
2
|
+
|
|
3
|
+
import * as perf from "../utils/perf"
|
|
4
|
+
import * as spawnHistory from "./spawnHistory"
|
|
5
|
+
import type { GatewayEvent, GatewaySkin, SessionInfo } from "../utils/gateway-types"
|
|
6
|
+
import type { Action } from "./turnReducer"
|
|
7
|
+
import { pid, type Usage } from "../types/message"
|
|
8
|
+
|
|
9
|
+
export type Side = {
|
|
10
|
+
onReady?: () => void
|
|
11
|
+
onSessionInfo?: (info: SessionInfo) => void
|
|
12
|
+
onUsage?: (u: Usage) => void
|
|
13
|
+
onTurnComplete?: () => void
|
|
14
|
+
onBackground?: (task_id: string, text: string) => void
|
|
15
|
+
onBtw?: (text: string) => void
|
|
16
|
+
onStatus?: (text: string) => void
|
|
17
|
+
onSkin?: (skin: GatewaySkin | null | undefined) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function count(o: Record<string, string[]> | undefined): number {
|
|
21
|
+
return o ? Object.values(o).reduce((n, v) => n + v.length, 0) : 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function mapEvent(ev: GatewayEvent, side: Side): Action | null {
|
|
25
|
+
switch (ev.type) {
|
|
26
|
+
case "gateway.ready":
|
|
27
|
+
side.onReady?.()
|
|
28
|
+
if (ev.payload?.skin) side.onSkin?.(ev.payload.skin)
|
|
29
|
+
return null
|
|
30
|
+
|
|
31
|
+
case "session.info": {
|
|
32
|
+
const si = ev.payload
|
|
33
|
+
side.onSessionInfo?.(si)
|
|
34
|
+
const label = si.model
|
|
35
|
+
? `Connected — ${si.model} · ${count(si.tools)} tools · ${count(si.skills)} skills`
|
|
36
|
+
: "Connected to Hermes"
|
|
37
|
+
if (si.credential_warning) side.onStatus?.(si.credential_warning)
|
|
38
|
+
return { kind: "system", text: label }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
case "message.start":
|
|
42
|
+
perf.count("stream:start")
|
|
43
|
+
perf.mem("stream-start")
|
|
44
|
+
return { kind: "message.start" }
|
|
45
|
+
|
|
46
|
+
case "message.delta": {
|
|
47
|
+
const chunk = ev.payload?.text ?? ""
|
|
48
|
+
if (!chunk) return null
|
|
49
|
+
perf.count("stream:chunk")
|
|
50
|
+
return { kind: "message.delta", chunk }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
case "message.complete": {
|
|
54
|
+
perf.count("stream:done")
|
|
55
|
+
perf.mem("stream-done")
|
|
56
|
+
const p = ev.payload
|
|
57
|
+
if (p?.usage) side.onUsage?.(p.usage)
|
|
58
|
+
side.onTurnComplete?.()
|
|
59
|
+
// The gateway reports in-agent failures via status (exceptions come
|
|
60
|
+
// as a separate `error` event). Without this branch a failed API
|
|
61
|
+
// call ends the turn with no visible output.
|
|
62
|
+
if (p?.status === "error")
|
|
63
|
+
return { kind: "error", text: p.text || "request failed — see messages above" }
|
|
64
|
+
if (p?.status === "interrupted")
|
|
65
|
+
return { kind: "message.complete", text: (p.text || "") + "\n\n*[interrupted]*", usage: p?.usage }
|
|
66
|
+
return { kind: "message.complete", text: p?.text ?? undefined, usage: p?.usage }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
case "tool.start":
|
|
70
|
+
return {
|
|
71
|
+
kind: "tool.start",
|
|
72
|
+
id: ev.payload.tool_id,
|
|
73
|
+
name: ev.payload.name ?? "unknown",
|
|
74
|
+
preview: ev.payload.context,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
case "tool.progress":
|
|
78
|
+
return { kind: "tool.progress", name: ev.payload.name, preview: ev.payload.preview }
|
|
79
|
+
|
|
80
|
+
case "tool.generating":
|
|
81
|
+
return { kind: "tool.generating", name: ev.payload.name }
|
|
82
|
+
|
|
83
|
+
case "tool.complete":
|
|
84
|
+
return {
|
|
85
|
+
kind: "tool.complete",
|
|
86
|
+
id: ev.payload.tool_id,
|
|
87
|
+
summary: ev.payload.summary,
|
|
88
|
+
error: ev.payload.error,
|
|
89
|
+
inline_diff: ev.payload.inline_diff,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case "thinking.delta":
|
|
93
|
+
// Cosmetic spinner text from the agent's status line, not model
|
|
94
|
+
// reasoning. Surface as transient status only.
|
|
95
|
+
side.onStatus?.(ev.payload?.text ?? "")
|
|
96
|
+
return null
|
|
97
|
+
|
|
98
|
+
case "reasoning.delta":
|
|
99
|
+
case "reasoning.available": {
|
|
100
|
+
const text = ev.payload?.text
|
|
101
|
+
if (!text) return null
|
|
102
|
+
return { kind: "thinking", text, final: ev.type === "reasoning.available" }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
case "subagent.start":
|
|
106
|
+
case "subagent.thinking":
|
|
107
|
+
case "subagent.tool":
|
|
108
|
+
case "subagent.progress":
|
|
109
|
+
case "subagent.complete": {
|
|
110
|
+
const sub = ev.type.slice(9) as "start" | "thinking" | "tool" | "progress" | "complete"
|
|
111
|
+
// Feed the turn-wide accumulator so the completed tree can be
|
|
112
|
+
// persisted (spawn_tree.save) and the Agents tab can read live
|
|
113
|
+
// tool trails without its own event listener.
|
|
114
|
+
spawnHistory.record(sub, ev.payload)
|
|
115
|
+
return { kind: "subagent", event: sub, payload: ev.payload }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
case "error":
|
|
119
|
+
return { kind: "error", text: ev.payload?.message ?? "Unknown error" }
|
|
120
|
+
|
|
121
|
+
case "clarify.request":
|
|
122
|
+
return { kind: "prompt", id: ev.payload.request_id,
|
|
123
|
+
req: { variant: "clarify", ...ev.payload } }
|
|
124
|
+
|
|
125
|
+
case "approval.request":
|
|
126
|
+
// Approval has no request_id upstream — the gateway's approval
|
|
127
|
+
// responder is a single pending slot. Mint a unique part id so
|
|
128
|
+
// multiple approvals in one turn don't alias each other when
|
|
129
|
+
// prompt.answered updates by id.
|
|
130
|
+
return { kind: "prompt", id: `approval-${pid()}`,
|
|
131
|
+
req: { variant: "approval", ...ev.payload } }
|
|
132
|
+
|
|
133
|
+
case "sudo.request":
|
|
134
|
+
return { kind: "prompt", id: ev.payload.request_id,
|
|
135
|
+
req: { variant: "sudo", ...ev.payload } }
|
|
136
|
+
|
|
137
|
+
case "secret.request":
|
|
138
|
+
return { kind: "prompt", id: ev.payload.request_id,
|
|
139
|
+
req: { variant: "secret", ...ev.payload } }
|
|
140
|
+
|
|
141
|
+
case "background.complete":
|
|
142
|
+
side.onBackground?.(ev.payload.task_id, ev.payload.text)
|
|
143
|
+
return null
|
|
144
|
+
|
|
145
|
+
case "review.summary": {
|
|
146
|
+
// Self-improvement background review saved a skill patch or
|
|
147
|
+
// memory entry. Upstream tui_gateway emits this so clients can
|
|
148
|
+
// surface the mutation — without it, the file change happens
|
|
149
|
+
// silently. Python side already formats the text with a 💾
|
|
150
|
+
// prefix, so we pass through verbatim (trimmed). Guard blank
|
|
151
|
+
// payloads: upstream does the same, and a blank system line is
|
|
152
|
+
// noise. No toast — these fire stochastically post-turn and
|
|
153
|
+
// per-event toasting would spam.
|
|
154
|
+
const text = String(ev.payload?.text ?? "").trim()
|
|
155
|
+
if (!text) return null
|
|
156
|
+
return { kind: "system", text }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
case "btw.complete":
|
|
160
|
+
side.onBtw?.(ev.payload.text)
|
|
161
|
+
return null
|
|
162
|
+
|
|
163
|
+
case "gateway.stderr": {
|
|
164
|
+
// Error-ish stderr lines (tracebacks, HTTP 4xx/5xx, auth failures)
|
|
165
|
+
// surface inline; benign chatter stays in gw.tail() only (/logs).
|
|
166
|
+
const line = ev.payload.line
|
|
167
|
+
if (/error|fail|traceback|exception|\b[45]\d\d\b|refused|denied|unauthori/i.test(line))
|
|
168
|
+
return { kind: "system", text: line.slice(0, 200) }
|
|
169
|
+
return null
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
case "skin.changed":
|
|
173
|
+
side.onSkin?.(ev.payload)
|
|
174
|
+
return null
|
|
175
|
+
|
|
176
|
+
case "gateway.start_timeout":
|
|
177
|
+
return { kind: "error", text: `gateway startup timed out (${ev.payload?.python ?? "python"} @ ${ev.payload?.cwd ?? "?"})` }
|
|
178
|
+
|
|
179
|
+
case "gateway.protocol_error":
|
|
180
|
+
return { kind: "system", text: `protocol error: ${ev.payload?.preview ?? "?"}` }
|
|
181
|
+
|
|
182
|
+
case "browser.progress": {
|
|
183
|
+
// Streamed during /browser connect (upstream e75082901). Surface as
|
|
184
|
+
// transcript rows so long CDP attach work isn't a 60s black box.
|
|
185
|
+
const text = ev.payload?.message ?? ""
|
|
186
|
+
if (!text) return null
|
|
187
|
+
return ev.payload?.level === "error"
|
|
188
|
+
? { kind: "error", text }
|
|
189
|
+
: { kind: "system", text: `· ${text}` }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
case "status.update": {
|
|
193
|
+
const kind = ev.payload?.kind
|
|
194
|
+
const text = ev.payload?.text ?? ""
|
|
195
|
+
side.onStatus?.(text)
|
|
196
|
+
// Generic "status" is cosmetic; lifecycle/error/warn carry real
|
|
197
|
+
// signal (retries, fallbacks, auth failures) and must persist.
|
|
198
|
+
if (!kind || kind === "status") return null
|
|
199
|
+
return { kind: "system", text }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return null
|
|
203
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Launch intent parsed from argv before the renderer starts.
|
|
2
|
+
// Bare `herm` → fresh session (splash shows continue-prompt).
|
|
3
|
+
// `-c` / `--continue` / `--resume [id]` → resume, no splash.
|
|
4
|
+
|
|
5
|
+
import pkg from "../../package.json" with { type: "json" }
|
|
6
|
+
|
|
7
|
+
export const VERSION = pkg.version
|
|
8
|
+
|
|
9
|
+
export type Launch =
|
|
10
|
+
| { mode: "new"; splash?: boolean }
|
|
11
|
+
| { mode: "resume"; sid?: string }
|
|
12
|
+
|
|
13
|
+
/** Parse process argv (everything after the script path). No deps. */
|
|
14
|
+
export function parseLaunch(argv: readonly string[]): Launch {
|
|
15
|
+
let splash = true
|
|
16
|
+
for (let i = 0; i < argv.length; i++) {
|
|
17
|
+
const a = argv[i]
|
|
18
|
+
if (a === "--no-splash") { splash = false; continue }
|
|
19
|
+
if (a === "-c" || a === "--continue") return { mode: "resume" }
|
|
20
|
+
if (a === "--resume") {
|
|
21
|
+
const next = argv[i + 1]
|
|
22
|
+
// Treat a following non-flag token as the session id.
|
|
23
|
+
return next && !next.startsWith("-")
|
|
24
|
+
? { mode: "resume", sid: next }
|
|
25
|
+
: { mode: "resume" }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { mode: "new", splash }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const HELP = `\
|
|
32
|
+
herm — OpenTUI client for hermes-agent
|
|
33
|
+
|
|
34
|
+
Usage:
|
|
35
|
+
herm start a fresh session
|
|
36
|
+
herm -c, --continue resume the last real TUI session
|
|
37
|
+
herm --resume [id] resume last (or the given) session
|
|
38
|
+
herm --no-splash skip the launch splash
|
|
39
|
+
herm -v, --version print version
|
|
40
|
+
herm -h, --help show this help
|
|
41
|
+
`
|
package/src/app/skin.tsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Active Hermes skin — branding strings surfaced to UI.
|
|
2
|
+
// The gateway emits skin.changed with the full skin payload;
|
|
3
|
+
// app.tsx reduces it into this context. Consumers read agentName
|
|
4
|
+
// (message headers, announcements) and the raw branding map for
|
|
5
|
+
// future needs (prompt_symbol, welcome, etc.).
|
|
6
|
+
|
|
7
|
+
import { createContext, useContext, memo, type ReactNode } from "react"
|
|
8
|
+
import type { GatewaySkin } from "../utils/gateway-types"
|
|
9
|
+
|
|
10
|
+
export type SkinState = {
|
|
11
|
+
skin?: GatewaySkin
|
|
12
|
+
/** Preferred display label for the assistant in chat. */
|
|
13
|
+
agentName: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const DEFAULT: SkinState = { agentName: "Hermes" }
|
|
17
|
+
|
|
18
|
+
const Ctx = createContext<SkinState>(DEFAULT)
|
|
19
|
+
|
|
20
|
+
export function deriveSkin(skin?: GatewaySkin | null): SkinState {
|
|
21
|
+
const name = skin?.branding?.agent_name?.trim()
|
|
22
|
+
return { skin: skin ?? undefined, agentName: name || "Hermes" }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const SkinProvider = memo(({ value, children }: { value: SkinState; children: ReactNode }) => (
|
|
26
|
+
<Ctx.Provider value={value}>{children}</Ctx.Provider>
|
|
27
|
+
))
|
|
28
|
+
|
|
29
|
+
export function useSkin(): SkinState {
|
|
30
|
+
return useContext(Ctx)
|
|
31
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Accumulates subagent.* events across a turn so the completed spawn
|
|
2
|
+
// tree can be persisted via `spawn_tree.save` and later browsed with
|
|
3
|
+
// `spawn_tree.list`/`load`. The accumulator is module-level (one turn
|
|
4
|
+
// runs at a time per session); `flush()` is called from the app-level
|
|
5
|
+
// onTurnComplete side-effect.
|
|
6
|
+
|
|
7
|
+
import type { Gateway } from "./gateway"
|
|
8
|
+
import type { SubagentPayload, SpawnSubagent } from "../utils/gateway-types"
|
|
9
|
+
|
|
10
|
+
type Event = "start" | "thinking" | "tool" | "progress" | "complete"
|
|
11
|
+
|
|
12
|
+
const TRAIL_MAX = 20
|
|
13
|
+
const acc = new Map<string, SpawnSubagent>()
|
|
14
|
+
|
|
15
|
+
export function record(ev: Event, p: SubagentPayload): void {
|
|
16
|
+
const id = p.subagent_id
|
|
17
|
+
if (!id) return
|
|
18
|
+
const now = Date.now() / 1000
|
|
19
|
+
|
|
20
|
+
if (ev === "start") {
|
|
21
|
+
acc.set(id, {
|
|
22
|
+
subagent_id: id,
|
|
23
|
+
parent_id: p.parent_id ?? null,
|
|
24
|
+
depth: p.depth ?? 0,
|
|
25
|
+
goal: p.goal,
|
|
26
|
+
model: p.model,
|
|
27
|
+
started_at: now,
|
|
28
|
+
tool_count: 0,
|
|
29
|
+
status: "running",
|
|
30
|
+
trail: [],
|
|
31
|
+
})
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const r = acc.get(id)
|
|
36
|
+
if (!r) return
|
|
37
|
+
|
|
38
|
+
if (ev === "tool" && p.tool_name) {
|
|
39
|
+
r.tool_count++
|
|
40
|
+
r.trail = [...(r.trail ?? []), { name: p.tool_name, preview: p.tool_preview }].slice(-TRAIL_MAX)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (ev === "complete") {
|
|
45
|
+
r.status = p.status ?? "completed"
|
|
46
|
+
r.finished_at = now
|
|
47
|
+
r.input_tokens = p.input_tokens
|
|
48
|
+
r.output_tokens = p.output_tokens
|
|
49
|
+
r.cost_usd = p.cost_usd
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Live read for the Agents-tab detail panel (running children only). */
|
|
54
|
+
export function trail(id: string): ReadonlyArray<{ name: string; preview?: string }> {
|
|
55
|
+
return acc.get(id)?.trail ?? []
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Persist the turn's tree (best-effort) and clear the accumulator. */
|
|
59
|
+
export function flush(gw: Gateway, sessionId: string): void {
|
|
60
|
+
if (acc.size === 0) return
|
|
61
|
+
const subagents = [...acc.values()]
|
|
62
|
+
acc.clear()
|
|
63
|
+
|
|
64
|
+
const roots = subagents.filter(s => s.parent_id == null)
|
|
65
|
+
const label = (roots.slice(0, 2).map(s => s.goal).join(" · ") || `${subagents.length} subagents`).slice(0, 120)
|
|
66
|
+
const started = Math.min(...subagents.map(s => s.started_at))
|
|
67
|
+
|
|
68
|
+
gw.request("spawn_tree.save", {
|
|
69
|
+
session_id: sessionId,
|
|
70
|
+
label,
|
|
71
|
+
started_at: started,
|
|
72
|
+
finished_at: Date.now() / 1000,
|
|
73
|
+
subagents,
|
|
74
|
+
}).catch(() => {})
|
|
75
|
+
}
|
package/src/app/tabs.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const TABS = [
|
|
2
|
+
{ name: "Chat", description: "Main chat interface" },
|
|
3
|
+
{ name: "Context", description: "Context and session info" },
|
|
4
|
+
{ name: "Sessions", description: "Session history" },
|
|
5
|
+
{ name: "Agents", description: "Profiles and running subagents" },
|
|
6
|
+
{ name: "Analytics", description: "Token usage and costs" },
|
|
7
|
+
{ name: "Skills", description: "Installed skills browser" },
|
|
8
|
+
{ name: "Cron", description: "Scheduled job manager" },
|
|
9
|
+
{ name: "Toolsets", description: "Available toolsets manager" },
|
|
10
|
+
{ name: "Config", description: "Configuration editor" },
|
|
11
|
+
{ name: "Env", description: "API keys & env variables" },
|
|
12
|
+
{ name: "Memory", description: "Agent memory browser" },
|
|
13
|
+
{ name: "Kanban", description: "Multi-agent task board" },
|
|
14
|
+
] as const
|
|
15
|
+
|
|
16
|
+
export const TAB_MAX = TABS.length - 1
|
|
17
|
+
export const CHAT_TAB = 0
|
|
18
|
+
|
|
19
|
+
/** Slash-command names that jump to a tab (F5.3). */
|
|
20
|
+
export const TAB_SLASH: Record<string, number> = Object.fromEntries(
|
|
21
|
+
TABS.map((t, i) => [t.name.toLowerCase(), i]),
|
|
22
|
+
)
|
|
23
|
+
TAB_SLASH.insights = TAB_SLASH.analytics
|