hermes-pilot 0.0.0-stage → 0.2.2
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.ja.md +419 -0
- package/README.md +428 -2
- package/__init__.py +15 -0
- package/apps/bridge/src/api-errors.js +165 -0
- package/apps/bridge/src/architect.js +1298 -0
- package/apps/bridge/src/auth.js +202 -0
- package/apps/bridge/src/capabilities.js +256 -0
- package/apps/bridge/src/capture.js +145 -0
- package/apps/bridge/src/chat-profile.js +95 -0
- package/apps/bridge/src/config.js +73 -0
- package/apps/bridge/src/discord.js +89 -0
- package/apps/bridge/src/gitinfo.js +211 -0
- package/apps/bridge/src/hermes.js +97 -0
- package/apps/bridge/src/inbox.js +347 -0
- package/apps/bridge/src/kanban.js +361 -0
- package/apps/bridge/src/lang.js +60 -0
- package/apps/bridge/src/live.js +285 -0
- package/apps/bridge/src/memos.js +150 -0
- package/apps/bridge/src/ops.js +201 -0
- package/apps/bridge/src/pair-codes.js +125 -0
- package/apps/bridge/src/pipeline-optimizer.js +513 -0
- package/apps/bridge/src/pipeline-watcher.js +1022 -0
- package/apps/bridge/src/qr.js +808 -0
- package/apps/bridge/src/repos.js +544 -0
- package/apps/bridge/src/review-watcher.js +271 -0
- package/apps/bridge/src/review.js +1749 -0
- package/apps/bridge/src/search.js +162 -0
- package/apps/bridge/src/server.js +1745 -0
- package/apps/bridge/src/snippets.js +373 -0
- package/apps/bridge/src/specs.js +806 -0
- package/apps/bridge/src/tail.js +28 -0
- package/apps/bridge/src/telemetry.js +667 -0
- package/apps/bridge/src/term-snippets.js +228 -0
- package/apps/bridge/src/transcript.js +231 -0
- package/apps/bridge/src/usage.js +294 -0
- package/apps/bridge/src/workerFeed.js +72 -0
- package/apps/dashboard/index.js +2014 -0
- package/apps/dashboard/manifest.json +14 -0
- package/apps/dashboard/pilot_dashboard.py +1466 -0
- package/apps/dashboard/plugin_api.py +237 -0
- package/apps/dashboard/plugin_init.py +15 -0
- package/apps/dashboard/style.css +928 -0
- package/apps/web/dist/assets/TermPane-DYP7pi_n.css +32 -0
- package/apps/web/dist/assets/TermPane-q4f5Zu0I.js +12 -0
- package/apps/web/dist/assets/index-BzUof8lw.js +94 -0
- package/apps/web/dist/assets/index-DwZdbPU7.css +1 -0
- package/apps/web/dist/favicon.ico +0 -0
- package/apps/web/dist/icon-180-v6.png +0 -0
- package/apps/web/dist/icon-192-v6.png +0 -0
- package/apps/web/dist/icon-512-v6.png +0 -0
- package/apps/web/dist/icon-maskable-192-v6.png +0 -0
- package/apps/web/dist/icon-maskable-512-v6.png +0 -0
- package/apps/web/dist/icon-v6.svg +15 -0
- package/apps/web/dist/index.html +21 -0
- package/apps/web/dist/manifest.webmanifest +49 -0
- package/apps/web/dist/sw.js +69 -0
- package/bin/hermes-pilot.mjs +964 -0
- package/dashboard/dist/index.js +2014 -0
- package/dashboard/dist/style.css +928 -0
- package/dashboard/manifest.json +14 -0
- package/dashboard/pilot_dashboard.py +1466 -0
- package/dashboard/plugin_api.py +237 -0
- package/package.json +75 -4
- package/plugin.json +70 -0
- package/plugin.yaml +4 -0
- package/scripts/deploy.mjs +58 -0
- package/scripts/migrate-to-hermes-pilot.mjs +472 -0
- package/scripts/postinstall.mjs +32 -0
- package/scripts/sync-dashboard.mjs +98 -0
- package/skills/annotation/SKILL.md +138 -0
- package/skills/quick-review/SKILL.md +200 -0
- package/skills/quick-review/assets/sheet-template.html +175 -0
- package/skills/spec-architect/SKILL.md +226 -0
package/README.md
CHANGED
|
@@ -1,3 +1,429 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Hermes Pilot
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Drive an autonomous [Hermes Agent](https://hermes-agent.nousresearch.com/docs) from your phone or tablet.
|
|
4
|
+
**Hermes Pilot** turns the decisions an agent needs into one-tap review sheets and annotated screenshots,
|
|
5
|
+
carries a one-line idea all the way to filed, self-running kanban batches (**the A2B pipeline**), and puts
|
|
6
|
+
kanban, chat, terminal and usage into a single installable PWA.
|
|
7
|
+
|
|
8
|
+
日本語版は [`README.ja.md`](README.ja.md)。
|
|
9
|
+
|
|
10
|
+
**[▶ Try the interactive demo](https://hajimemanila.github.io/hermes-pilot/)** — no install, no Hermes: a self-contained mock of the A2B flow (Spec Seed → Quick Review → Spec Launchpad → Architect progress → Mission Receipt). The single file is also in this repo at [`demo/index.html`](demo/index.html) and embeds into Google Sites.
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
[phone / tablet PWA] → https://<tailscale-host>/ (or http://<lan-ip>:4097)
|
|
14
|
+
│
|
|
15
|
+
[bridge :4097] ──► http://127.0.0.1:9119 (the existing Hermes dashboard, untouched)
|
|
16
|
+
├── kanban SQLite (read-only)
|
|
17
|
+
├── Hermes WebSocket (chat JSON-RPC relay)
|
|
18
|
+
└── ~/.hermes/plugin-data/hermes-pilot/ (token, review sheets, shots, feed)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What you get
|
|
22
|
+
|
|
23
|
+
- **Quick Review** — the agent writes a sheet of 3 (±1) questions with a recommended option, opens it as a
|
|
24
|
+
blocked kanban task, and you answer with one tap. The answer comes back as a comment and the worker is
|
|
25
|
+
unblocked. Skill: `skills/quick-review/`.
|
|
26
|
+
- **Annotation** — the agent attaches a screenshot; you draw on it with a finger (rectangles, arrows, notes)
|
|
27
|
+
and send back an ordered, coordinate-tagged fix list. Skill: `skills/annotation/`.
|
|
28
|
+
- **Spec Architect** — a one-line seed becomes a design interview, then a `docs/SPEC-*.md` whose batches a
|
|
29
|
+
worker can execute without asking again. Skill: `skills/spec-architect/`.
|
|
30
|
+
- **Tasks / Inbox** — boards, task detail, event history, per-task git diff, approve / comment / abort, plus **🧠 Brainstorm** and **🛠 Refactor** sheets alongside **Spec Seed**.
|
|
31
|
+
- **Chat** — streaming Hermes chat with thinking log, tool log, attachments, snippets, cross-session search, bubble context menu (copy, save to Memos, summarize, continue instructing), and clear *Reply / RO* + running indicators in the session drawer.
|
|
32
|
+
- **Memos (Ideas & Report Inbox)** — Keep-style card grid for one-line capture, checklists, tags, search, and scheduled/completion report inbox, with direct handoff to Brainstorm and Spec Seed.
|
|
33
|
+
- **Terminal** — a real PTY over the bridge, with command snippets that follow your OS.
|
|
34
|
+
- **Persistent tab state** — all six tabs (Tasks, Review, Chat, Memos, Terminal, Settings) stay mounted in the background so switching tabs preserves scroll position, drafts, and loaded state without reload lag.
|
|
35
|
+
- **English and Japanese** (`en` is the fallback, `ja` is bundled), **Dark / Light / System** themes and two
|
|
36
|
+
two-pane layouts: a **narrow master-detail from 680 px** (280 px master, for portrait tablets such as the
|
|
37
|
+
iPad mini) and the **wide two-pane from 820 px** (380 px review master / 360 px tasks master). Below 680 px
|
|
38
|
+
every detail opens as a full-height sheet.
|
|
39
|
+
- **No external plugins required** — repositories are found by scanning your project folders, and system
|
|
40
|
+
status uses only the standard Hermes APIs.
|
|
41
|
+
|
|
42
|
+
## The A2B pipeline (seed → running batches)
|
|
43
|
+
|
|
44
|
+
One line of intent becomes a spec a worker can finish, without a chat backlog of questions.
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
📝 Spec Seed ──► Quick Review ──► 📄 SPEC-<SLUG>.md ──► 🚀 Spec Launchpad ──► ⚡ live run ──► 🏆 Mission Receipt
|
|
48
|
+
one line 3(±1) questions Execution Mode per idempotent batch ArchitectJobBar 1200×630 PNG
|
|
49
|
+
(or dictation) 1-tap answers batch + acceptance filing (kanban) LiveSheet/WorkerFeed X-weight ≤ 280 text
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Two safe routes — neither spawns an external AI CLI:**
|
|
53
|
+
|
|
54
|
+
- **A. SPEC file → one-tap autonomous run (the basic route)** — place `docs/SPEC-*.md` (and, when you want a
|
|
55
|
+
review round first, `review/sheets/*.json`) into the repository yourself: your terminal, the official
|
|
56
|
+
Antigravity Remote PWA, or any editor. Hermes Pilot only watches the files (`Spec Launchpad` /
|
|
57
|
+
`reviewWatcher`), so one tap files the batches and the autonomous run starts with no external process.
|
|
58
|
+
- **B. `Hermes Native` spec authoring (phone-only)** — `Spec Seed` → Quick Review → `docs/SPEC-*.md` →
|
|
59
|
+
Launchpad, driven by `hermes kanban create` inside Hermes itself (steps 1–4 below).
|
|
60
|
+
|
|
61
|
+
1. **📝 Spec Seed** — type (or dictate) one line in the Tasks tab and pick an **execution policy**:
|
|
62
|
+
- **`Zero-Stop`** (default) — every batch runs to the end autonomously; no approval stops.
|
|
63
|
+
- **`Visual-Gate`** — the run pauses at checkpoints so you can look at the rendered result (screenshot /
|
|
64
|
+
annotation) before the next batch starts.
|
|
65
|
+
- **Runner** — fixed to `Hermes Native`: the Architect is driven inside Hermes itself, and Hermes Pilot
|
|
66
|
+
never starts an external AI CLI as a subprocess (see *Two safe routes* above).
|
|
67
|
+
2. **Quick Review interview** — the Architect asks 3 (±1) questions on a sheet with recommended options; the
|
|
68
|
+
*⚡ Accept All Recommended* button answers them all in one tap.
|
|
69
|
+
3. **📄 Spec** — a second round writes `docs/SPEC-<SLUG>.md`: decisions table, per-batch `Execution Mode`,
|
|
70
|
+
changed-file list and acceptance commands, so a worker never has to ask "how should this work?".
|
|
71
|
+
4. **🚀 Spec Launchpad** — the Tasks tab lists the spec's `### Batch <ID>` entries with an accordion and
|
|
72
|
+
Markdown preview, and files them as kanban tasks. A batch whose `[ID]` task is still open is skipped, and
|
|
73
|
+
re-tapping or reloading never duplicates cards.
|
|
74
|
+
5. **⚡ Live run** — `ArchitectJobBar` shows the job's phase (`spawning → round1_sheet → round2_spec →
|
|
75
|
+
spec_ready → launched`), a stall warning when a phase stops moving, and a one-tap retry for a job that
|
|
76
|
+
failed or stalled. `LiveSheet` and `WorkerFeed` stream the running workers.
|
|
77
|
+
6. **🏆 Mission Receipt** — when the batches finish, the completion summary exports a **1200×630 PNG receipt**
|
|
78
|
+
and a share text that is **X-weighted ≤ 280 characters in both JA and EN** (KPI numbers are never dropped;
|
|
79
|
+
the header and footer give way first).
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# 1) seed (returns 202 with a jobId; the Architect runs in the background)
|
|
83
|
+
curl -s -X POST -H "x-client: mobile" -H "content-type: application/json" \
|
|
84
|
+
-d '{"board":"<board>","seedText":"Add a dark-mode receipt export","autoStart":false}' \
|
|
85
|
+
"http://127.0.0.1:4097/api/architect/seed?t=$(cat ~/.hermes/plugin-data/hermes-pilot/token)"
|
|
86
|
+
|
|
87
|
+
# 2) job status / completed specs / un-filed specs
|
|
88
|
+
curl -s -H "x-client: mobile" \
|
|
89
|
+
"http://127.0.0.1:4097/api/architect/jobs?board=<board>&t=$(cat ~/.hermes/plugin-data/hermes-pilot/token)"
|
|
90
|
+
|
|
91
|
+
# 3) file the batches (idempotent; same-board open tasks are skipped)
|
|
92
|
+
curl -s -X POST -H "x-client: mobile" -H "content-type: application/json" \
|
|
93
|
+
-d '{"board":"<board>","specRelPath":"docs/SPEC-DARK-RECEIPT.md","batchIds":["B1","B2"]}' \
|
|
94
|
+
"http://127.0.0.1:4097/api/specs/launch?t=$(cat ~/.hermes/plugin-data/hermes-pilot/token)"
|
|
95
|
+
|
|
96
|
+
# 4) done — completion summary + receipt data (read-only aggregation)
|
|
97
|
+
curl -s -H "x-client: mobile" \
|
|
98
|
+
"http://127.0.0.1:4097/api/telemetry/receipt?board=<board>&hours=24&t=$(cat ~/.hermes/plugin-data/hermes-pilot/token)"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Abstract roles and native delegation
|
|
102
|
+
|
|
103
|
+
A batch is routed by **role**, not by model name. Four abstract roles cover the whole pipeline, and they are
|
|
104
|
+
the only vocabulary the repo and the bundled skills use:
|
|
105
|
+
|
|
106
|
+
- `role:planner` — design, spec authoring, impact analysis, hard root-cause work.
|
|
107
|
+
- `role:builder` — implementation, test repair, builds, routine kanban work (the default).
|
|
108
|
+
- `role:visual-reviewer` — screenshot / annotation reading and `390×844` / `820×1180` visual acceptance.
|
|
109
|
+
- `role:decision-framer` — quick-review question design and trade-off framing.
|
|
110
|
+
|
|
111
|
+
A batch may declare `- **Recommended Role**: \`role:planner\``; the bridge extracts it and adds the role
|
|
112
|
+
guidance to the `[Hermes Pilot Execution Contract]` appended to the filed task. Specs without the line behave
|
|
113
|
+
exactly as before.
|
|
114
|
+
|
|
115
|
+
Delegation is **native** — Hermes's own `delegate_task` — and never an external AI CLI subprocess
|
|
116
|
+
(`gemini -p`, `agy -p`, …); `npm run check:oauth` fails if a runtime file tries to spawn one. It is also
|
|
117
|
+
**non-blocking**: if the delegated model errors, is rate-limited, times out or is not configured, the parent
|
|
118
|
+
continues on its own model in the fallback order its profile declares, and the batch still finishes. A failed
|
|
119
|
+
delegation never leaves a task stopped.
|
|
120
|
+
|
|
121
|
+
**Where the models are named: not here.** The repository and the three bundled skills speak only abstract
|
|
122
|
+
roles. The mapping (which role uses which model, in what fallback order) belongs to the operator and lives in
|
|
123
|
+
the Hermes profile — `~/.hermes/SOUL.md` for the short always-read contract, the profile's own `SOUL.md` and
|
|
124
|
+
memory for the concrete assignment table. That split is what keeps the plugin installable for anyone.
|
|
125
|
+
`POST /api/pipeline/optimize` writes the marker block into `~/.hermes/SOUL.md` **and** every
|
|
126
|
+
`~/.hermes/profiles/<name>/SOUL.md` it finds, idempotently and after a `.bak-<stamp>` backup;
|
|
127
|
+
`GET /api/pipeline/status` reports which profiles are applied without returning any file content.
|
|
128
|
+
|
|
129
|
+
## Decision cockpit (v2)
|
|
130
|
+
|
|
131
|
+
Five additions that shorten the loop from "the agent needs a decision" to "it is running again".
|
|
132
|
+
Every one of them is reachable from the phone and from the standard dashboard.
|
|
133
|
+
|
|
134
|
+
- **Spec Launchpad** — the Tasks tab reads `docs/SPEC-*.md` of the board's repository, lists the batches the
|
|
135
|
+
spec defines (`### Batch P1: …`) and files them as kanban tasks with one tap. A batch whose `[ID]` task is
|
|
136
|
+
still open is skipped, so double-taps and reloads never pile up duplicates.
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
curl -s -H "x-client: mobile" "http://127.0.0.1:4097/api/specs?board=<board>&t=$(cat ~/.hermes/plugin-data/hermes-pilot/token)"
|
|
140
|
+
curl -s -X POST -H "x-client: mobile" -H "content-type: application/json" \
|
|
141
|
+
-d '{"board":"<board>","specRelPath":"docs/SPEC-PILOT-V2.md","batchIds":["P5"]}' \
|
|
142
|
+
"http://127.0.0.1:4097/api/specs/launch?t=$(cat ~/.hermes/plugin-data/hermes-pilot/token)"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- **1-Tap Fast-Track** — when a review sheet's questions carry recommended options, the pane shows
|
|
146
|
+
*⚡ Accept All Recommended (Q1:A · Q2:B) & Resume*: one tap sends every recommended answer, unblocks the
|
|
147
|
+
worker and jumps to the next waiting sheet (`POST /api/review/:id/answer`).
|
|
148
|
+
|
|
149
|
+
- **Before ↔ After** — an annotation review that has a previous round (`*.before.png` or the previous
|
|
150
|
+
numbered shot) gets a compare toggle, so you can flip between the red pen you drew and the latest
|
|
151
|
+
screenshot; *✅ Looks Good* closes the task in one tap (`POST /api/review/:id/approve`).
|
|
152
|
+
|
|
153
|
+
- **Standard dashboard integration** — the *Hermes Pilot* tab of the Hermes dashboard (`:9119`) manages
|
|
154
|
+
repositories (add / pin / hide / create board), chat & terminal snippets, and the bridge / gateway / audit
|
|
155
|
+
logs against the same files the PWA uses, so `scanDirs` is configured in exactly one place.
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
node bin/hermes-pilot.mjs init --force # refresh the dashboard plugin files after an upgrade
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
- **Snippet editing** — built-in snippets can be pinned to the chip bar (Hot) or hidden, and you can add,
|
|
162
|
+
edit, reorder and delete your own, for chat and terminal, in English and Japanese, with
|
|
163
|
+
*Reset to defaults*.
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
curl -s -H "x-client: mobile" "http://127.0.0.1:4097/api/snippets?lang=en" # chat
|
|
167
|
+
curl -s -H "x-client: mobile" "http://127.0.0.1:4097/api/snippets/term?lang=ja" # terminal
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Comfort and one-tap setup
|
|
171
|
+
|
|
172
|
+
- **Vibe mode** — `⚡ Dopamine ⇄ 🧘 Serotonin` in Settings changes how loud the app is (HUD bevels,
|
|
173
|
+
chat bubble glow, topbar/badge pulses, `sakuga-vfx`-inspired spring & canvas bursts with EN/JA
|
|
174
|
+
onomatopoeia, `Working…` aurora borders, and the receipt canvas title), not what it does. Haptics and
|
|
175
|
+
sound are separate toggles and **survive a Vibe switch**, so turning the volume down never silently
|
|
176
|
+
disables the buzz you rely on.
|
|
177
|
+
- **Snippet band toggle** — the chip band above the chat composer, the annotation toolbar and the terminal
|
|
178
|
+
keys can each be collapsed. The choice is per band and remembered, so a small phone keeps the composer and
|
|
179
|
+
the keyboard from fighting for the same 390 px.
|
|
180
|
+
- **1-tap environment optimisation** — *Settings → Optimise this Hermes* (`POST /api/pipeline/optimize`)
|
|
181
|
+
appends the A2B discipline section to `~/.hermes/SOUL.md` and to each profile's
|
|
182
|
+
`~/.hermes/profiles/<name>/SOUL.md` (idempotent — an existing section is never duplicated, and a
|
|
183
|
+
`.bak-<stamp>` backup is taken first), then places the three bundled skills into `~/.hermes/skills/`.
|
|
184
|
+
`GET /api/pipeline/status` reports what is already applied, per profile, without returning any `SOUL.md`
|
|
185
|
+
content.
|
|
186
|
+
- **Legacy cron cleanup** — `migrate` (and `init`) removes the old `mobile-akapen-watch` /
|
|
187
|
+
`mobile-review-watch` cron entries, because the bridge's own watcher writes the completion feed now and two
|
|
188
|
+
writers produced duplicate reports. Other cron entries and the store's top-level shape are untouched.
|
|
189
|
+
|
|
190
|
+
## Interactive demo (no backend needed)
|
|
191
|
+
|
|
192
|
+
`npm run build:demo` produces a static site in `apps/web/dist-demo` that needs **no bridge, no gateway and no
|
|
193
|
+
database** — put it on GitHub Pages (or any static host) and anyone can walk the pipeline.
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
npm run build:demo # VITE_DEMO_MODE=1, base ./, outDir apps/web/dist-demo
|
|
197
|
+
npx serve apps/web/dist-demo # or: python3 -m http.server -d apps/web/dist-demo 4321
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
- **On a phone** it is the normal PWA, opened straight in the browser (no device frame).
|
|
201
|
+
- **On a desktop browser (≥ 900 px)** the app is shown inside a device simulator: `Phone 390×844`,
|
|
202
|
+
`Tablet 820×1180` (the two-pane layout) or `Full window`, plus instant `Dopamine ⇄ Serotonin`,
|
|
203
|
+
sound, `Dark ⇄ Light`, `EN ⇄ JA` and *Restart tour*. The frame is a real `<iframe>`, so media queries,
|
|
204
|
+
`position: fixed` sheets, toasts and the bottom nav behave exactly as on the device.
|
|
205
|
+
- **A 4-step guided tour** (top banner with a jump button on every step): ① approve the Architect's
|
|
206
|
+
decision sheet with *Accept All Recommended* → ② file the generated spec's batches and watch them run →
|
|
207
|
+
③ stamp a redline or accept the Before ↔ After visual gate → ④ open the completion summary and the
|
|
208
|
+
**completion receipt** (1200×630 PNG / share text).
|
|
209
|
+
|
|
210
|
+
All data is in memory (`apps/web/src/demo/mockApi.js`); the screenshots used by the visual gate are
|
|
211
|
+
generated as inline SVG data URLs, so the demo has no network dependency at all.
|
|
212
|
+
|
|
213
|
+
**Production is untouched**: `main.jsx` reads `import.meta.env.VITE_DEMO_MODE`, so a normal `npm run build`
|
|
214
|
+
strips the demo branch and its dynamic imports — `apps/web/dist` contains no mock code, no tour CSS and no
|
|
215
|
+
screenshots (only the `demo.*` UI strings that live in the shared dictionaries). `apps/web/dist-demo` is
|
|
216
|
+
git-ignored and excluded from `npm pack`.
|
|
217
|
+
|
|
218
|
+
### Google Sites (single-file embed)
|
|
219
|
+
|
|
220
|
+
`npm run build:demo` also writes **`apps/web/dist-demo/google-sites-embed.html`**: one self-contained file
|
|
221
|
+
with the JS, CSS and SVG images inlined, `localStorage` replaced by an in-memory shim and the PWA `<link>`
|
|
222
|
+
tags removed. The build fails (`exit 1`) if any external reference survives its own `verifyEmbedHtml()`
|
|
223
|
+
check, so a broken file cannot reach the site.
|
|
224
|
+
|
|
225
|
+
1. `npm run build:demo`
|
|
226
|
+
2. Google Sites → *Insert* → **Embed** → **Embed code** → paste the whole content of
|
|
227
|
+
`google-sites-embed.html` → *Insert*.
|
|
228
|
+
3. Open the page on a desktop browser: because the embedded document knows it is a frame
|
|
229
|
+
(`window.__HM_DEMO_FRAME__`), it still renders the **`Phone 390×844` / `Tablet 820×1180` / `Full window`**
|
|
230
|
+
device simulator with its top bar. *Restart tour* re-creates the inner iframe instead of reloading the
|
|
231
|
+
`srcdoc` page, so it works inside Google Sites too.
|
|
232
|
+
4. For GitHub Pages, publish `apps/web/dist-demo` as-is (relative `base`); the embed file is optional there.
|
|
233
|
+
|
|
234
|
+
## Requirements
|
|
235
|
+
|
|
236
|
+
- Node.js **≥ 22.19**
|
|
237
|
+
- Hermes Agent installed and running (the bridge proxies `http://127.0.0.1:9119`)
|
|
238
|
+
- Optional: [Tailscale](https://tailscale.com/) for HTTPS access from anywhere. On the same LAN, plain
|
|
239
|
+
`http://<lan-ip>:4097` works without it.
|
|
240
|
+
|
|
241
|
+
## Install
|
|
242
|
+
|
|
243
|
+
Two routes, same three steps after the first one: **get the code → `npm ci` → `init`**.
|
|
244
|
+
There is no published npm release yet, so every command below runs the checked-in CLI
|
|
245
|
+
(`node bin/hermes-pilot.mjs …`) from the repository or plugin directory instead of `npx`.
|
|
246
|
+
|
|
247
|
+
**A. From the Hermes plugin catalog (recommended)**
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
hermes plugins install hajimemanila/hermes-pilot --ref <sha> # pin a commit; omit --ref to track the default branch
|
|
251
|
+
cd ~/.hermes/plugins/hermes-pilot
|
|
252
|
+
npm ci
|
|
253
|
+
node bin/hermes-pilot.mjs init
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**B. From a clone of this repository**
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
git clone https://github.com/hajimemanila/hermes-pilot.git
|
|
260
|
+
cd hermes-pilot
|
|
261
|
+
npm ci
|
|
262
|
+
node bin/hermes-pilot.mjs init
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
`npm ci` is not optional: the bridge needs `ws` and the **native** addon `node-pty`, and the
|
|
266
|
+
`postinstall` step restores the `spawn-helper` exec bit that npm's tarball extraction drops
|
|
267
|
+
(without it the terminal tab fails with `posix_spawnp failed`).
|
|
268
|
+
|
|
269
|
+
Every `node bin/hermes-pilot.mjs …` below assumes the current directory is that repository /
|
|
270
|
+
plugin directory. If you prefer the short form, run `npm link` once and use `hermes-pilot …`.
|
|
271
|
+
|
|
272
|
+
`init` is idempotent and does five things:
|
|
273
|
+
|
|
274
|
+
1. creates `~/.hermes/plugin-data/hermes-pilot/` (and `review/{sheets,shots,library}`),
|
|
275
|
+
2. generates a **256-bit hex app token** in `token` with mode `0600` (an existing token is never replaced),
|
|
276
|
+
3. if a legacy `~/Projects/akapen`, `~/.hermes/plugin-data/akapen` or `~/.hermes/mobile-pwa` exists, migrates
|
|
277
|
+
it (files are **copied**, `mtime` preserved, kanban `[akapen]` tags rewritten to `[review]`),
|
|
278
|
+
4. copies the bundled skills `quick-review`, `annotation` and `spec-architect` into `~/.hermes/skills/`,
|
|
279
|
+
5. detects your reachable address (Tailscale MagicDNS name, otherwise the LAN IP) and prints the
|
|
280
|
+
**pairing URL plus a QR code in the terminal**.
|
|
281
|
+
|
|
282
|
+
Then start the bridge:
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
node bin/hermes-pilot.mjs start # http://127.0.0.1:4097
|
|
286
|
+
node bin/hermes-pilot.mjs start --port 4097 --host 127.0.0.1
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Pairing a device (no long token to type)
|
|
290
|
+
|
|
291
|
+
- **From the terminal**: `node bin/hermes-pilot.mjs qr` prints the candidates and a QR. Pass `--tls-port 8444` when
|
|
292
|
+
Tailscale `serve` publishes HTTPS on a non-443 port.
|
|
293
|
+
- **From the app**: Settings → *Pair a device* → *Show Pairing QR* (`GET /api/auth/pairing`). Show it to a
|
|
294
|
+
second phone or tablet.
|
|
295
|
+
|
|
296
|
+
Scanning the QR opens `https://<host>/?token=<token>` (or `#token=`). The app exchanges the token for an
|
|
297
|
+
**HttpOnly session cookie** through `POST /api/auth/login` and immediately removes it from the address bar
|
|
298
|
+
with `history.replaceState`, so the token stays out of history, bookmarks and screenshots.
|
|
299
|
+
|
|
300
|
+
> The QR contains the app token. Anyone who scans it can control this Hermes — treat a screenshot of it like
|
|
301
|
+
> a password. Rotate the token with `rm ~/.hermes/plugin-data/hermes-pilot/token` and restart the bridge;
|
|
302
|
+
> every device is signed out.
|
|
303
|
+
|
|
304
|
+
## Keeping it running
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
node bin/hermes-pilot.mjs service install # launchd on macOS, systemd --user on Linux
|
|
308
|
+
node bin/hermes-pilot.mjs service status
|
|
309
|
+
node bin/hermes-pilot.mjs service restart
|
|
310
|
+
node bin/hermes-pilot.mjs service uninstall
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
- macOS: `~/Library/LaunchAgents/ai.hermes.pilot.plist` (label `ai.hermes.pilot`), logs in
|
|
314
|
+
`~/.hermes/logs/pilot.out.log` and `pilot.err.log`.
|
|
315
|
+
- Linux: `~/.config/systemd/user/hermes-pilot.service`
|
|
316
|
+
(`systemctl --user enable --now hermes-pilot.service`).
|
|
317
|
+
|
|
318
|
+
### Migrating from `hermes-mobile-pwa` (HEADS-UP)
|
|
319
|
+
|
|
320
|
+
The service label changed from `ai.hermes.hermes-mobile` to `ai.hermes.pilot`, and the package name from
|
|
321
|
+
`hermes-mobile-pwa` to `hermes-pilot`. **The old agent is intentionally left running** so you can switch over
|
|
322
|
+
without downtime:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
node bin/hermes-pilot.mjs init # copy the data (old files stay in place)
|
|
326
|
+
node bin/hermes-pilot.mjs service install # register + start the NEW label
|
|
327
|
+
node bin/hermes-pilot.mjs service status # confirm it is running
|
|
328
|
+
|
|
329
|
+
# once you are happy with the new one, retire the old one:
|
|
330
|
+
launchctl bootout gui/$(id -u)/ai.hermes.hermes-mobile
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Both labels want port 4097. If the old agent is still bound to it, start the new one on another port first
|
|
334
|
+
(`node bin/hermes-pilot.mjs start --port 4098`), verify, then swap. The old `~/.hermes/mobile-pwa/` directory is
|
|
335
|
+
copied, never deleted — remove it yourself when you no longer need it.
|
|
336
|
+
|
|
337
|
+
## Security
|
|
338
|
+
|
|
339
|
+
The bridge is the only thing listening, and it is the only thing that can reach Hermes.
|
|
340
|
+
|
|
341
|
+
| Surface | Rule |
|
|
342
|
+
|---|---|
|
|
343
|
+
| Listen address | `127.0.0.1:4097` by default. Nothing is exposed unless you put Tailscale `serve` (or another TLS proxy) in front of it. |
|
|
344
|
+
| Device credential | A 256-bit hex app token in `~/.hermes/plugin-data/hermes-pilot/token` (`0600`). It is exchanged once for an **`HttpOnly`, `SameSite=Strict` session cookie**; the token is then stripped from the address bar with `history.replaceState`. |
|
|
345
|
+
| QR pairing | The QR carries a **one-time pairing code** (10-minute TTL, single use), not the app token. Treat a screenshot of it as a password anyway; rotations are `rm …/token` + restart, which signs every device out. |
|
|
346
|
+
| Hermes session token | Never leaves the bridge. The PWA only ever holds the app token / cookie. |
|
|
347
|
+
| Writes | Every mutating call needs the **`X-Client: mobile`** header (401 without it) **and** the session cookie, so a cross-site form post cannot drive the app. |
|
|
348
|
+
| Kill switch | Long-press 1.5 s + typed confirmation, and the API re-checks the `confirm` field. The UI never shells out to raw `launchctl`. |
|
|
349
|
+
| Rate limits | Reads 120/min per endpoint bucket, writes 60/min. |
|
|
350
|
+
| Audit | Every write appends to `~/.hermes/plugin-data/hermes-pilot/audit.jsonl` (viewable in Settings). |
|
|
351
|
+
| Read-only data | Kanban SQLite, usage and receipts are opened read-only; the bridge aggregates them and never migrates a board on its own. |
|
|
352
|
+
| Public paths | Only the app shell (`/`, `/assets/*`, `/manifest.webmanifest`, `/sw.js`, `/icon-*`, `/auth`, `/healthz`) is unauthenticated — Android's WebAPK generator fetches those without credentials. Everything under `/api/*` and `/ws/*` is behind auth. |
|
|
353
|
+
| Demo | `apps/web/dist-demo` (and the Google Sites embed) is **mock data only** — no token, no bridge, no network calls; nothing from it can reach your Hermes. |
|
|
354
|
+
|
|
355
|
+
## Data and environment
|
|
356
|
+
|
|
357
|
+
Everything persistent lives under `~/.hermes/plugin-data/hermes-pilot/`:
|
|
358
|
+
|
|
359
|
+
```text
|
|
360
|
+
config.json { lang, scanDirs, servicePort, tlsPort? }
|
|
361
|
+
token app token (0600)
|
|
362
|
+
audit.jsonl audit log (every write)
|
|
363
|
+
repos.json scanDirs / pinned / hidden / custom repositories
|
|
364
|
+
snippets.json user chat snippets
|
|
365
|
+
review/ sheets/, shots/, library/, feed.jsonl, chat-reports.jsonl, task-chats.json
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
| Variable | Meaning |
|
|
369
|
+
|---|---|
|
|
370
|
+
| `HP_DATA_DIR` | plugin data dir (default `~/.hermes/plugin-data/hermes-pilot`) |
|
|
371
|
+
| `HM_DATA` | full override of the data dir (development/testing) |
|
|
372
|
+
| `HM_PORT` / `HM_HOST` | bridge listen address (default `4097` / `127.0.0.1`) |
|
|
373
|
+
| `HERMES_HOME` | Hermes home (default `~/.hermes`; a `profiles/<name>` path is normalized to the root) |
|
|
374
|
+
|
|
375
|
+
## How it works
|
|
376
|
+
|
|
377
|
+
| Item | Decision |
|
|
378
|
+
|---|---|
|
|
379
|
+
| Exposure | `https://<host>:8444` via Tailscale `serve`; bridge listens on `127.0.0.1:4097` only |
|
|
380
|
+
| Auth | app-token session cookie (`HttpOnly`, `SameSite=Strict`) + `X-Client: mobile` on writes |
|
|
381
|
+
| Kanban | each board's SQLite is read directly (read-only); there is no HTTP API for it |
|
|
382
|
+
| Kill switch | Hermes `/api/gateway/*` — never raw `launchctl` from the UI |
|
|
383
|
+
| Review data | `~/.hermes/plugin-data/hermes-pilot/review/` (sheets, shots, library, feed) |
|
|
384
|
+
| Completion feed | in-bridge `review-watcher.js` writes `feed.jsonl` / `chat-reports.jsonl` (no cron) |
|
|
385
|
+
|
|
386
|
+
## Development
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
npm install # postinstall fixes node-pty permissions
|
|
390
|
+
npm run dev # Vite on :4098, proxies /api and /ws to :4097
|
|
391
|
+
npm test # unit tests (808)
|
|
392
|
+
npm run verify # test + check:pwa (34 checks) + check:oauth + production build + audit:responsive
|
|
393
|
+
npm run build:demo # static interactive demo -> apps/web/dist-demo (+ google-sites-embed.html)
|
|
394
|
+
npm run deploy # atomic, verified swap of apps/web/dist
|
|
395
|
+
npm run migrate:pilot # the same migration as `init`, on demand
|
|
396
|
+
node bin/hermes-pilot.mjs --help
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
`npm run verify` is the gate every change has to pass, measured on this tree:
|
|
400
|
+
|
|
401
|
+
| Step | What it proves |
|
|
402
|
+
|---|---|
|
|
403
|
+
| `npm test` | **808** unit / integration tests, 0 fail (node:test, no framework). |
|
|
404
|
+
| `check:pwa` | **34/34** PWA checks against `apps/web/public` (manifest, icons, maskable, service worker, viewport). |
|
|
405
|
+
| `check:oauth` | **0** violations: no device credential or OAuth token is readable from the browser bundle. |
|
|
406
|
+
| `build` | Vite production build succeeds and contains no `demo/` code. |
|
|
407
|
+
| `audit:responsive` | layout audit at `390×844`, `844×390`, `820×1180` … — tap targets ≥ 44 px, no clipping regressions. |
|
|
408
|
+
|
|
409
|
+
Layout:
|
|
410
|
+
|
|
411
|
+
```text
|
|
412
|
+
bin/hermes-pilot.mjs CLI: init / start / qr / service / migrate
|
|
413
|
+
apps/bridge/src/ bridge (server.js, auth.js, review.js, qr.js, capabilities.js, ...)
|
|
414
|
+
apps/bridge/test/ bridge unit tests (qr.test.js compares against qrencode fixtures)
|
|
415
|
+
apps/web/src/ React PWA (i18n/, features/, lib/pairing.js, lib/theme.js)
|
|
416
|
+
apps/web/src/demo/ interactive demo only (mockApi.js, DemoStage.jsx, demo.css) — never in dist/
|
|
417
|
+
apps/web/dist/ production build served by the bridge
|
|
418
|
+
apps/web/dist-demo/ static demo build (`npm run build:demo`, git-ignored)
|
|
419
|
+
skills/ bundled skills: quick-review / annotation / spec-architect
|
|
420
|
+
docs/ SPEC-PUBLIC-PLUGIN.md (the spec), OPERATIONS.md, PLAN.md, EVIDENCE.md
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
QR generation is dependency-free (`apps/bridge/src/qr.js`): byte mode, error-correction level M, versions
|
|
424
|
+
1–10, SVG for the UI and ANSI half-block output for the terminal. Its module matrices are asserted against
|
|
425
|
+
`qrencode` reference fixtures in `apps/bridge/test/qr.test.js`.
|
|
426
|
+
|
|
427
|
+
## License
|
|
428
|
+
|
|
429
|
+
MIT
|
package/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Hermes Pilot — plugin package entry (installed as ``__init__.py``).
|
|
2
|
+
|
|
3
|
+
A user plugin's dashboard backend is only mounted when the plugin is a real,
|
|
4
|
+
enabled Hermes plugin, so this module has to exist even though there is no
|
|
5
|
+
agent-side surface: ``hermes plugins enable hermes-pilot`` resolves the name
|
|
6
|
+
through it. ``register`` is intentionally a no-op — the whole plugin is the
|
|
7
|
+
dashboard tab plus its FastAPI router under ``dashboard/``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def register(ctx) -> None: # noqa: ARG001 - signature fixed by the plugin API
|
|
14
|
+
"""No agent-side tools, hooks or commands; the dashboard half is the plugin."""
|
|
15
|
+
return None
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ブリッジ API のエラー応答(SPEC §6.3)。
|
|
3
|
+
*
|
|
4
|
+
* 形式は `{ ok: false, code: 'NOT_WAITING', error: '<英語既定>', params: { ... } }`。
|
|
5
|
+
* - `code` … 機械可読。フロントは `t('err.' + code, params)` で自言語化する
|
|
6
|
+
* - `error` … 英語の既定メッセージ(辞書に無いコードでも読めるように)
|
|
7
|
+
* - `params` … プレースホルダ値(辞書の `{var}` と同名)
|
|
8
|
+
*
|
|
9
|
+
* コード命名は `<DOMAIN>_<REASON>`(SPEC-i18n-resp B1)。既存 12 コードは温存。
|
|
10
|
+
* ここに載るコードは**必ず 1 コード 1 英語既定文**を持ち、`err.<code>` の訳が
|
|
11
|
+
* 辞書に無くても画面が英語で読める状態を保つ。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** @typedef {'AUTH_REQUIRED'|'BAD_REQUEST'|'CONFLICT'|'CONFIRM_MISMATCH'|'INTERNAL'|'NOT_FOUND'|'NOT_WAITING'|'NO_SESSION'|'QUERY_REQUIRED'|'RATE_LIMITED'|'SESSION_REQUIRED'|'UNKNOWN_ENDPOINT'} CoreErrorCode */
|
|
15
|
+
|
|
16
|
+
/** 英語既定メッセージ(`apps/web/src/i18n/en.json` の `err.*` と同じ意味)。 */
|
|
17
|
+
export const ERROR_MESSAGES = {
|
|
18
|
+
// --- 基盤(既存 12。順序も既存のまま) ---
|
|
19
|
+
AUTH_REQUIRED: 'Sign-in required',
|
|
20
|
+
BAD_REQUEST: 'The request could not be processed',
|
|
21
|
+
CONFLICT: 'The state changed. Reload and try again',
|
|
22
|
+
CONFIRM_MISMATCH: 'Confirmation text does not match',
|
|
23
|
+
INTERNAL: 'Internal error',
|
|
24
|
+
NOT_FOUND: 'Not found',
|
|
25
|
+
NOT_WAITING: 'Task is not waiting for review',
|
|
26
|
+
NO_SESSION: 'This task has no worker session',
|
|
27
|
+
QUERY_REQUIRED: 'A query is required',
|
|
28
|
+
RATE_LIMITED: 'Too many requests. Wait a moment and retry',
|
|
29
|
+
SESSION_REQUIRED: 'session_id is required',
|
|
30
|
+
UNKNOWN_ENDPOINT: 'Unknown endpoint',
|
|
31
|
+
|
|
32
|
+
// --- repo(repos.js / specs.js / review.js) ---
|
|
33
|
+
REPO_PATH_REQUIRED: 'A repository path is required',
|
|
34
|
+
REPO_PATH_INVALID: 'The repository path must be an absolute path',
|
|
35
|
+
REPO_PATH_FORBIDDEN: 'The home directory cannot be added as a repository',
|
|
36
|
+
REPO_NOT_GIT: 'Not a Git repository (.git is missing)',
|
|
37
|
+
REPO_NOT_FOUND: 'The repository is not registered',
|
|
38
|
+
REPO_ID_REQUIRED: 'A repository id is required',
|
|
39
|
+
SCAN_DIRS_INVALID: 'scanDirs must be an array',
|
|
40
|
+
SCAN_DIR_NOT_ABSOLUTE: 'Not an absolute path: {path}',
|
|
41
|
+
SCAN_DIR_FORBIDDEN: 'Cannot scan directly under the home directory. Specify a subdirectory',
|
|
42
|
+
SCAN_DIR_NOT_DIRECTORY: 'Not a directory: {path}',
|
|
43
|
+
SCAN_DIR_MISSING: 'Does not exist: {path}',
|
|
44
|
+
|
|
45
|
+
// --- board / task(repos.js / capture.js / specs.js / kanban.js / inbox.js) ---
|
|
46
|
+
BOARD_NAME_INVALID: 'The board name contains characters that cannot be used',
|
|
47
|
+
BOARD_NOT_FOUND: 'Board {board} was not found',
|
|
48
|
+
TASK_ID_INVALID: 'The task id is invalid',
|
|
49
|
+
TASK_ID_MISSING: 'Could not get the task id',
|
|
50
|
+
TASK_NOT_FOUND: 'Task {id} was not found',
|
|
51
|
+
TASK_STATE_LOCKED: 'The task is not in a state that allows this action (status: {status})',
|
|
52
|
+
TASK_TITLE_REQUIRED: 'A title is required',
|
|
53
|
+
TASK_TITLE_TOO_LONG: 'The title must be {max} characters or fewer',
|
|
54
|
+
|
|
55
|
+
// --- comment / action / cli(inbox.js / ops.js / review.js) ---
|
|
56
|
+
COMMENT_REQUIRED: 'A comment is required',
|
|
57
|
+
COMMENT_FAILED: 'Could not post the comment',
|
|
58
|
+
ACTION_INVALID: 'Unknown action: {action}',
|
|
59
|
+
CLI_FAILED: 'The Hermes command failed',
|
|
60
|
+
HERMES_REJECTED: 'Hermes rejected the operation (HTTP {status})',
|
|
61
|
+
CREATE_FAILED: 'Creating the task failed',
|
|
62
|
+
UNKNOWN_TARGET: 'Unknown target. Choose a registered repository',
|
|
63
|
+
|
|
64
|
+
// --- spec(specs.js) ---
|
|
65
|
+
SPEC_PATH_REQUIRED: 'A spec path is required',
|
|
66
|
+
SPEC_PATH_NOT_RELATIVE: 'The spec path must be relative to the repository',
|
|
67
|
+
SPEC_PATH_OUTSIDE: 'The spec path points outside the repository',
|
|
68
|
+
SPEC_READ_FAILED: 'Could not read the spec: {path}',
|
|
69
|
+
SPEC_BATCH_HEADING_MISSING: 'No batch heading (### Batch <ID>: <Title>) was found',
|
|
70
|
+
SPEC_BATCH_NOT_FOUND: 'The selected batch is not in the spec',
|
|
71
|
+
SPEC_NOT_MARKDOWN: 'Only Markdown (.md) specs can be previewed: {path}',
|
|
72
|
+
|
|
73
|
+
// --- review / sheet / approval(review.js) ---
|
|
74
|
+
NO_SHEET: 'This task has no sheet',
|
|
75
|
+
SHEET_MISSING: 'Sheet not found',
|
|
76
|
+
DATA_MISSING: 'sheet.json is missing',
|
|
77
|
+
REVIEW_ALREADY_ANSWERED: 'The same answer is already saved',
|
|
78
|
+
APPROVAL_ALREADY_RECORDED: 'Approval is already recorded',
|
|
79
|
+
|
|
80
|
+
// --- image / annotation(review.js) ---
|
|
81
|
+
NO_IMAGE: 'This task has no base image',
|
|
82
|
+
IMAGE_MISSING: 'Base image not found',
|
|
83
|
+
NO_COMPARE: 'No previous image to compare against',
|
|
84
|
+
NO_ANNOTATION: 'No annotations yet',
|
|
85
|
+
BAD_IMAGE: 'image must be data:image/(png|jpeg);base64,…',
|
|
86
|
+
TOO_LARGE: 'The image is too large',
|
|
87
|
+
THUMB_MISSING: 'Illustration not found',
|
|
88
|
+
BAD_THUMB: 'The illustration path is invalid',
|
|
89
|
+
BAD_PATH: 'The path is invalid',
|
|
90
|
+
OUTSIDE: 'Only files under library / shots are served',
|
|
91
|
+
BAD_EXT: 'Not an image file',
|
|
92
|
+
|
|
93
|
+
// --- その他(chat-profile.js / hermes.js / architect.js) ---
|
|
94
|
+
PROFILE_UNKNOWN: 'Unknown profile: {profile}',
|
|
95
|
+
HERMES_TOKEN_MISSING: 'Could not get the Hermes session token (is the dashboard running?)',
|
|
96
|
+
INVALID_RUNNER: 'Only the Hermes Native runner is supported',
|
|
97
|
+
INVALID_SEED: 'A seed text is required',
|
|
98
|
+
INVALID_BOARD: 'The board name is invalid',
|
|
99
|
+
INVALID_REPO: 'The repository path is invalid',
|
|
100
|
+
INVALID_JOB_ID: 'A job id is required',
|
|
101
|
+
JOB_NOT_FOUND: 'The architect job was not found',
|
|
102
|
+
WRITE_FAILED: 'Could not write the output',
|
|
103
|
+
MEMO_EMPTY: 'Note text or checklist is required',
|
|
104
|
+
MEMO_NOT_FOUND: 'Note not found',
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 英語既定文の無いコードで使う既定コード。
|
|
109
|
+
* @type {string}
|
|
110
|
+
*/
|
|
111
|
+
export const FALLBACK_CODE = 'BAD_REQUEST'
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* エラー本文を組み立てる。`fail()` の実体でもある(SPEC §6.3)。
|
|
115
|
+
* @param {string} code エラーコード
|
|
116
|
+
* @param {Record<string, unknown>} [params] プレースホルダ値
|
|
117
|
+
* @returns {{ok: false, code: string, error: string, params: Record<string, unknown>}} 本文
|
|
118
|
+
*/
|
|
119
|
+
export function errorBody(code, params = {}) {
|
|
120
|
+
const c = String(code || FALLBACK_CODE)
|
|
121
|
+
return {
|
|
122
|
+
ok: false,
|
|
123
|
+
code: c,
|
|
124
|
+
error: ERROR_MESSAGES[c] ?? ERROR_MESSAGES[FALLBACK_CODE],
|
|
125
|
+
params: params && typeof params === 'object' ? params : {},
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 失敗結果を返す(**throw しない**)。戻り値は `{ ok:false, code, error, params }`。
|
|
131
|
+
*
|
|
132
|
+
* 呼び出し側が `return` する規約(`{ok:false, ...}` を返すモジュール群)に合わせるための
|
|
133
|
+
* 糖衣で、中身は `errorBody()` と同一。
|
|
134
|
+
* @param {string} code エラーコード
|
|
135
|
+
* @param {Record<string, unknown>} [params] プレースホルダ値
|
|
136
|
+
* @returns {{ok: false, code: string, error: string, params: Record<string, unknown>}} 失敗結果
|
|
137
|
+
*/
|
|
138
|
+
export function fail(code, params = {}) {
|
|
139
|
+
return errorBody(code, params)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* `throw` したい場所(inbox.js / ops.js など)用のエラー。
|
|
144
|
+
*
|
|
145
|
+
* `server.js` の `sendFailure` が `code` / `params` を読み、`statusCode` を HTTP ステータスに使う。
|
|
146
|
+
* `message` は英語既定文(`detail` に載る文が日本語にならないように)。
|
|
147
|
+
*/
|
|
148
|
+
export class ApiError extends Error {
|
|
149
|
+
/**
|
|
150
|
+
* @param {string} code エラーコード
|
|
151
|
+
* @param {Record<string, unknown>} [params] プレースホルダ値
|
|
152
|
+
* @param {number} [statusCode] HTTP ステータス(既定 400)
|
|
153
|
+
*/
|
|
154
|
+
constructor(code, params = {}, statusCode = 400) {
|
|
155
|
+
const c = String(code || FALLBACK_CODE)
|
|
156
|
+
super(ERROR_MESSAGES[c] ?? ERROR_MESSAGES[FALLBACK_CODE])
|
|
157
|
+
this.name = 'ApiError'
|
|
158
|
+
this.code = c
|
|
159
|
+
this.params = params && typeof params === 'object' ? params : {}
|
|
160
|
+
this.statusCode = statusCode
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** コード表(テストと将来の網羅チェック用)。 */
|
|
165
|
+
export const ERROR_CODES = Object.keys(ERROR_MESSAGES)
|