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
|
@@ -0,0 +1,2014 @@
|
|
|
1
|
+
/* Hermes Pilot — standard-dashboard tab.
|
|
2
|
+
*
|
|
3
|
+
* Plain IIFE, no bundler and no JSX: the host exposes React plus an
|
|
4
|
+
* authenticated fetch on window.__HERMES_PLUGIN_SDK__, and this file registers
|
|
5
|
+
* one component. Every number shown comes from /api/plugins/hermes-pilot/* —
|
|
6
|
+
* this file only formats it and owns the two-tap confirm on restart.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here ever sees the app token: the backend keeps it server-side and
|
|
9
|
+
* returns a one-time pairing code as a PNG instead (see pilot_dashboard.py).
|
|
10
|
+
*
|
|
11
|
+
* Styling lives in style.css under the `hp-` prefix and reads the host's
|
|
12
|
+
* --color-* tokens, so the tab follows whichever theme is active.
|
|
13
|
+
*/
|
|
14
|
+
(function () {
|
|
15
|
+
"use strict";
|
|
16
|
+
|
|
17
|
+
var SDK = window.__HERMES_PLUGIN_SDK__;
|
|
18
|
+
if (!SDK || !SDK.React || !SDK.hooks) {
|
|
19
|
+
console.error("[hermes-pilot] dashboard plugin SDK missing; tab not registered");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!window.__HERMES_PLUGINS__ || !window.__HERMES_PLUGINS__.register) {
|
|
23
|
+
console.error("[hermes-pilot] plugin registry missing; tab not registered");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var React = SDK.React;
|
|
28
|
+
var h = React.createElement;
|
|
29
|
+
var useState = SDK.hooks.useState;
|
|
30
|
+
var useEffect = SDK.hooks.useEffect;
|
|
31
|
+
var useCallback = SDK.hooks.useCallback;
|
|
32
|
+
var useRef = SDK.hooks.useRef || React.useRef;
|
|
33
|
+
|
|
34
|
+
var API = "/api/plugins/hermes-pilot";
|
|
35
|
+
/** The QR is rendered at 1:1 so a phone camera sees square modules. */
|
|
36
|
+
var QR_SIZE = 287;
|
|
37
|
+
|
|
38
|
+
// ------------------------------------------------------------------ strings
|
|
39
|
+
|
|
40
|
+
var STRINGS = {
|
|
41
|
+
en: {
|
|
42
|
+
title: "Hermes Pilot",
|
|
43
|
+
lead: "Pair a phone or tablet with the Hermes Pilot PWA, and keep the bridge running.",
|
|
44
|
+
refresh: "Refresh",
|
|
45
|
+
loading: "Loading…",
|
|
46
|
+
failed: "Could not load",
|
|
47
|
+
service: "Service",
|
|
48
|
+
port: "Port",
|
|
49
|
+
bridge: "Bridge",
|
|
50
|
+
version: "Version",
|
|
51
|
+
running: "running",
|
|
52
|
+
stopped: "stopped",
|
|
53
|
+
unknownState: "unknown",
|
|
54
|
+
reachable: "reachable",
|
|
55
|
+
unreachable: "unreachable",
|
|
56
|
+
noManager: "no service manager",
|
|
57
|
+
pairingTitle: "Pairing",
|
|
58
|
+
pairingLead: "Scan this with the phone camera. The code is single-use and expires.",
|
|
59
|
+
pairingMissing: "The bridge is not running, so no pairing code can be issued.",
|
|
60
|
+
newCode: "New code",
|
|
61
|
+
expiresIn: "expires in {n} min",
|
|
62
|
+
expired: "expired — press New code",
|
|
63
|
+
copy: "Copy",
|
|
64
|
+
copied: "Copied",
|
|
65
|
+
steps: [
|
|
66
|
+
"Turn Tailscale on (or join the same Wi-Fi)",
|
|
67
|
+
"Scan the QR with the camera",
|
|
68
|
+
"It opens signed in — start using it"
|
|
69
|
+
],
|
|
70
|
+
settingsTitle: "Settings",
|
|
71
|
+
settingsLead: "Where the PWA looks for repositories, and how it is reached.",
|
|
72
|
+
scanDirs: "Scan directories",
|
|
73
|
+
scanDirsHint: "One per line. Existing directories only; ~ is expanded.",
|
|
74
|
+
tlsPort: "TLS port",
|
|
75
|
+
tlsPortHint: "Optional — the HTTPS port Tailscale serve publishes.",
|
|
76
|
+
tailscaleDns: "Tailscale DNS name",
|
|
77
|
+
tailscaleDnsHint: "Optional — e.g. machine.tailnet-name.ts.net",
|
|
78
|
+
servicePort: "Bridge port",
|
|
79
|
+
save: "Save",
|
|
80
|
+
saving: "Saving…",
|
|
81
|
+
saved: "Saved",
|
|
82
|
+
serviceTitle: "Service",
|
|
83
|
+
serviceLead: "The bridge runs under launchd (macOS) or systemd --user (Linux).",
|
|
84
|
+
check: "Check status",
|
|
85
|
+
install: "Install service",
|
|
86
|
+
restart: "Restart bridge",
|
|
87
|
+
restartArmed: "Tap again to restart",
|
|
88
|
+
output: "Output",
|
|
89
|
+
linksTitle: "Open the PWA",
|
|
90
|
+
lan: "LAN",
|
|
91
|
+
tailscale: "Tailscale",
|
|
92
|
+
noLink: "Not detected yet",
|
|
93
|
+
reposTitle: "Repositories",
|
|
94
|
+
reposLead: "The working directories the PWA can open. Add, hide, pin — or give one a board.",
|
|
95
|
+
repoAdd: "Add",
|
|
96
|
+
repoAddPlaceholder: "~/Projects/repo or /absolute/path",
|
|
97
|
+
pin: "Pin",
|
|
98
|
+
unpin: "Unpin",
|
|
99
|
+
hide: "Hide",
|
|
100
|
+
unhide: "Unhide",
|
|
101
|
+
boardCreate: "Create board",
|
|
102
|
+
hiddenTitle: "Hidden",
|
|
103
|
+
hiddenNone: "Nothing is hidden.",
|
|
104
|
+
repoEmpty: "No repositories detected yet. Add one by path.",
|
|
105
|
+
repoScanDirsLabel: "Scan directories",
|
|
106
|
+
repoScanDirsHint: "Edit them in Settings — saving there updates config.json and repos.json together.",
|
|
107
|
+
repoFromFile: "Bridge offline — this list comes from repos.json.",
|
|
108
|
+
reposSaved: "Saved",
|
|
109
|
+
boardReady: "Board ready",
|
|
110
|
+
snippetsTitle: "Snippets",
|
|
111
|
+
snippetsLead: "The chat and terminal shortcuts. Hot pins one to the PWA's quick bar.",
|
|
112
|
+
tabChat: "Chat",
|
|
113
|
+
tabTerm: "Terminal",
|
|
114
|
+
hot: "Hot",
|
|
115
|
+
hiddenTag: "Hidden",
|
|
116
|
+
customTag: "custom",
|
|
117
|
+
remove: "Remove",
|
|
118
|
+
snippetNew: "Add snippet",
|
|
119
|
+
snippetLabel: "Label",
|
|
120
|
+
snippetText: "Text",
|
|
121
|
+
snippetRun: "Executes a command",
|
|
122
|
+
saveSnippets: "Save snippets",
|
|
123
|
+
resetSnippets: "Reset",
|
|
124
|
+
resetArmed: "Tap again to reset",
|
|
125
|
+
snippetsFileOnly: "Bridge offline — only the saved custom entries can be edited.",
|
|
126
|
+
pipelineTitle: "Pipeline & Architect",
|
|
127
|
+
pipelineLead: "Who drafts the spec, and the one-tap A2B optimization (SOUL.md + skills).",
|
|
128
|
+
pipelineRunner: "Architect runner",
|
|
129
|
+
pipelineHermes: "Hermes Native",
|
|
130
|
+
pipelineHermesFixed:
|
|
131
|
+
"Fixed to Hermes Native — specs come from docs/SPEC-*.md files, so no external AI CLI is ever spawned.",
|
|
132
|
+
pipelineSoul: "SOUL.md",
|
|
133
|
+
pipelineSkills: "Skills",
|
|
134
|
+
pipelineApplied: "applied",
|
|
135
|
+
pipelineMissing: "not applied",
|
|
136
|
+
pipelineJobs: "Architect jobs",
|
|
137
|
+
pipelinePending: "Unfiled specs",
|
|
138
|
+
pipelineOptimize: "Optimize now",
|
|
139
|
+
pipelineOptimizing: "Optimizing…",
|
|
140
|
+
pipelineOptimized: "Applied",
|
|
141
|
+
pipelineUnavailable: "Pipeline API unavailable",
|
|
142
|
+
pipelineEmpty: "No Architect jobs yet.",
|
|
143
|
+
pipelineBatches: "{n} batches",
|
|
144
|
+
logsTitle: "Logs & audit",
|
|
145
|
+
logsLead: "Tail of the gateway, error, bridge and audit logs. Tokens are redacted before they reach this page.",
|
|
146
|
+
logGateway: "Gateway",
|
|
147
|
+
logErrors: "Errors",
|
|
148
|
+
logPilot: "Bridge",
|
|
149
|
+
logAudit: "Audit",
|
|
150
|
+
logEmpty: "No entries yet.",
|
|
151
|
+
logMissing: "This log file does not exist yet.",
|
|
152
|
+
langLabel: "Language",
|
|
153
|
+
langHint: "Auto follows the browser. EN / 日本語 is saved to config.json.",
|
|
154
|
+
langAuto: "Auto",
|
|
155
|
+
navLabel: "Jump to a section",
|
|
156
|
+
auditList: "List",
|
|
157
|
+
auditRaw: "Raw",
|
|
158
|
+
auditShowMore: "▼ Show {n} more",
|
|
159
|
+
auditCollapse: "▲ Collapse",
|
|
160
|
+
auditEmpty: "No audit entries yet.",
|
|
161
|
+
err: {
|
|
162
|
+
not_a_directory: "Not an existing directory",
|
|
163
|
+
home_directory: "Pick the folders under your home directory",
|
|
164
|
+
empty: "Add at least one directory",
|
|
165
|
+
too_many: "Too many directories",
|
|
166
|
+
invalid_list: "Expected a list of directories",
|
|
167
|
+
out_of_range: "Must be between 1 and 65535",
|
|
168
|
+
not_a_number: "Must be a number",
|
|
169
|
+
required: "Required",
|
|
170
|
+
invalid_hostname: "Not a valid hostname",
|
|
171
|
+
invalid_lang: "Unsupported language"
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
ja: {
|
|
175
|
+
title: "Hermes Pilot",
|
|
176
|
+
lead: "スマホ・タブレットを PWA とペアリングし、ブリッジを常駐させます。",
|
|
177
|
+
refresh: "更新",
|
|
178
|
+
loading: "読み込み中…",
|
|
179
|
+
failed: "読み込めませんでした",
|
|
180
|
+
service: "サービス",
|
|
181
|
+
port: "ポート",
|
|
182
|
+
bridge: "ブリッジ",
|
|
183
|
+
version: "バージョン",
|
|
184
|
+
running: "稼働中",
|
|
185
|
+
stopped: "停止",
|
|
186
|
+
unknownState: "不明",
|
|
187
|
+
reachable: "到達可",
|
|
188
|
+
unreachable: "到達不可",
|
|
189
|
+
noManager: "サービス管理なし",
|
|
190
|
+
pairingTitle: "ペアリング",
|
|
191
|
+
pairingLead: "スマホのカメラで読み取ってください。コードは 1 回限り・有効期限あり。",
|
|
192
|
+
pairingMissing: "ブリッジが動いていないため、ペアリングコードを発行できません。",
|
|
193
|
+
newCode: "コードを再発行",
|
|
194
|
+
expiresIn: "残り {n} 分",
|
|
195
|
+
expired: "期限切れ — コードを再発行してください",
|
|
196
|
+
copy: "コピー",
|
|
197
|
+
copied: "コピーしました",
|
|
198
|
+
steps: [
|
|
199
|
+
"Tailscale をオンにする(または同じ Wi-Fi に接続)",
|
|
200
|
+
"QR をカメラで読み取る",
|
|
201
|
+
"そのままログイン済みで開きます"
|
|
202
|
+
],
|
|
203
|
+
settingsTitle: "設定",
|
|
204
|
+
settingsLead: "PWA がリポジトリを探す場所と、接続方法。",
|
|
205
|
+
scanDirs: "スキャン対象ディレクトリ",
|
|
206
|
+
scanDirsHint: "1 行に 1 つ。実在するディレクトリのみ。~ は展開されます。",
|
|
207
|
+
tlsPort: "TLS ポート",
|
|
208
|
+
tlsPortHint: "任意 — Tailscale serve が公開する HTTPS ポート。",
|
|
209
|
+
tailscaleDns: "Tailscale DNS 名",
|
|
210
|
+
tailscaleDnsHint: "任意 — 例: machine.tailnet-name.ts.net",
|
|
211
|
+
servicePort: "ブリッジのポート",
|
|
212
|
+
save: "保存",
|
|
213
|
+
saving: "保存中…",
|
|
214
|
+
saved: "保存しました",
|
|
215
|
+
serviceTitle: "サービス",
|
|
216
|
+
serviceLead: "ブリッジは launchd(macOS)/ systemd --user(Linux)で常駐します。",
|
|
217
|
+
check: "状態を確認",
|
|
218
|
+
install: "サービスを登録",
|
|
219
|
+
restart: "ブリッジを再起動",
|
|
220
|
+
restartArmed: "もう一度タップで再起動",
|
|
221
|
+
output: "出力",
|
|
222
|
+
linksTitle: "PWA を開く",
|
|
223
|
+
lan: "LAN",
|
|
224
|
+
tailscale: "Tailscale",
|
|
225
|
+
noLink: "未検出",
|
|
226
|
+
reposTitle: "リポジトリ",
|
|
227
|
+
reposLead: "PWA から開ける作業ディレクトリ。追加・非表示・ピン留め・ボード作成。",
|
|
228
|
+
repoAdd: "追加",
|
|
229
|
+
repoAddPlaceholder: "~/Projects/repo か絶対パス",
|
|
230
|
+
pin: "ピン",
|
|
231
|
+
unpin: "外す",
|
|
232
|
+
hide: "非表示",
|
|
233
|
+
unhide: "再表示",
|
|
234
|
+
boardCreate: "ボード作成",
|
|
235
|
+
hiddenTitle: "非表示中",
|
|
236
|
+
hiddenNone: "非表示のリポジトリはありません。",
|
|
237
|
+
repoEmpty: "まだリポジトリが見つかっていません。パスで追加してください。",
|
|
238
|
+
repoScanDirsLabel: "スキャン対象",
|
|
239
|
+
repoScanDirsHint: "編集は「設定」で。保存すると config.json と repos.json の両方が更新されます。",
|
|
240
|
+
repoFromFile: "ブリッジ停止中 — repos.json の内容を表示しています。",
|
|
241
|
+
reposSaved: "保存しました",
|
|
242
|
+
boardReady: "ボードを用意しました",
|
|
243
|
+
snippetsTitle: "スニペット",
|
|
244
|
+
snippetsLead: "チャットとターミナルの定型文。Hot にすると PWA のクイックバーに出ます。",
|
|
245
|
+
tabChat: "チャット",
|
|
246
|
+
tabTerm: "ターミナル",
|
|
247
|
+
hot: "Hot",
|
|
248
|
+
hiddenTag: "非表示",
|
|
249
|
+
customTag: "カスタム",
|
|
250
|
+
remove: "削除",
|
|
251
|
+
snippetNew: "スニペットを追加",
|
|
252
|
+
snippetLabel: "ラベル",
|
|
253
|
+
snippetText: "本文",
|
|
254
|
+
snippetRun: "コマンドを実行する",
|
|
255
|
+
saveSnippets: "スニペットを保存",
|
|
256
|
+
resetSnippets: "既定に戻す",
|
|
257
|
+
resetArmed: "もう一度タップでリセット",
|
|
258
|
+
snippetsFileOnly: "ブリッジ停止中 — 保存済みのカスタムだけ編集できます。",
|
|
259
|
+
pipelineTitle: "パイプライン&Architect",
|
|
260
|
+
pipelineLead: "仕様書を誰が書くか、そして 1 タップの A2B 最適化(SOUL.md + スキル)。",
|
|
261
|
+
pipelineRunner: "Architect のランナー",
|
|
262
|
+
pipelineHermes: "Hermes Native",
|
|
263
|
+
pipelineHermesFixed:
|
|
264
|
+
"Hermes Native に固定 — 仕様書は docs/SPEC-*.md のファイル経由で受け取るため、外部 AI CLI は起動しません。",
|
|
265
|
+
pipelineSoul: "SOUL.md",
|
|
266
|
+
pipelineSkills: "スキル",
|
|
267
|
+
pipelineApplied: "適用済み",
|
|
268
|
+
pipelineMissing: "未適用",
|
|
269
|
+
pipelineJobs: "Architect ジョブ",
|
|
270
|
+
pipelinePending: "未起票の仕様書",
|
|
271
|
+
pipelineOptimize: "今すぐ最適化",
|
|
272
|
+
pipelineOptimizing: "適用中…",
|
|
273
|
+
pipelineOptimized: "適用しました",
|
|
274
|
+
pipelineUnavailable: "パイプライン API が使えません",
|
|
275
|
+
pipelineEmpty: "Architect ジョブはまだありません。",
|
|
276
|
+
pipelineBatches: "{n} バッチ",
|
|
277
|
+
logsTitle: "ログ・監査",
|
|
278
|
+
logsLead: "ゲートウェイ・エラー・ブリッジ・監査ログの末尾。トークンは秘匿してから返します。",
|
|
279
|
+
logGateway: "ゲートウェイ",
|
|
280
|
+
logErrors: "エラー",
|
|
281
|
+
logPilot: "ブリッジ",
|
|
282
|
+
logAudit: "監査",
|
|
283
|
+
logEmpty: "まだ出力がありません。",
|
|
284
|
+
logMissing: "このログファイルはまだありません。",
|
|
285
|
+
langLabel: "言語",
|
|
286
|
+
langHint: "「自動」はブラウザの言語に従います。EN / 日本語 は config.json に保存されます。",
|
|
287
|
+
langAuto: "自動",
|
|
288
|
+
navLabel: "セクションへ移動",
|
|
289
|
+
auditList: "一覧",
|
|
290
|
+
auditRaw: "生ログ",
|
|
291
|
+
auditShowMore: "▼ 他 {n} 件を表示",
|
|
292
|
+
auditCollapse: "▲ 折りたたむ",
|
|
293
|
+
auditEmpty: "監査ログはまだありません。",
|
|
294
|
+
err: {
|
|
295
|
+
not_a_directory: "実在するディレクトリではありません",
|
|
296
|
+
home_directory: "ホーム直下ではなく、その下のフォルダを指定してください",
|
|
297
|
+
empty: "1 つ以上指定してください",
|
|
298
|
+
too_many: "指定が多すぎます",
|
|
299
|
+
invalid_list: "ディレクトリの一覧が必要です",
|
|
300
|
+
out_of_range: "1〜65535 の範囲で指定してください",
|
|
301
|
+
not_a_number: "数値で指定してください",
|
|
302
|
+
required: "必須です",
|
|
303
|
+
invalid_hostname: "ホスト名の形式ではありません",
|
|
304
|
+
invalid_lang: "未対応の言語です"
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
/** The tab follows the browser language; English is the fallback (SPEC D5). */
|
|
310
|
+
function detectLang() {
|
|
311
|
+
var list = (navigator.languages && navigator.languages.length ? navigator.languages : [navigator.language || "en"]);
|
|
312
|
+
for (var i = 0; i < list.length; i++) {
|
|
313
|
+
var tag = String(list[i] || "").toLowerCase();
|
|
314
|
+
if (tag.indexOf("ja") === 0) return "ja";
|
|
315
|
+
if (tag.indexOf("en") === 0) return "en";
|
|
316
|
+
}
|
|
317
|
+
return "en";
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ------------------------------------------------------- language preference
|
|
321
|
+
|
|
322
|
+
/** Where the browser remembers an explicit EN/日本語 choice (SPEC V3 §3.5). */
|
|
323
|
+
var LANG_KEY = "hp.dashboard.lang";
|
|
324
|
+
|
|
325
|
+
function readStoredLang() {
|
|
326
|
+
try {
|
|
327
|
+
var raw = window.localStorage.getItem(LANG_KEY);
|
|
328
|
+
return raw === "en" || raw === "ja" ? raw : null;
|
|
329
|
+
} catch (e) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** `null` forgets the choice, so the tab falls back to config + browser. */
|
|
335
|
+
function writeStoredLang(value) {
|
|
336
|
+
try {
|
|
337
|
+
if (value === "en" || value === "ja") window.localStorage.setItem(LANG_KEY, value);
|
|
338
|
+
else window.localStorage.removeItem(LANG_KEY);
|
|
339
|
+
} catch (e) {
|
|
340
|
+
/* private mode / disabled storage: the tab still works, it just forgets */
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Which language to render, in priority order (SPEC V3 §3.5).
|
|
346
|
+
*
|
|
347
|
+
* 1. an explicit choice in this browser (`hp.dashboard.lang`)
|
|
348
|
+
* 2. `config.json`'s `lang` — but only when it says `ja`, because `en` is also
|
|
349
|
+
* the fresh-install default and would otherwise hide a Japanese browser
|
|
350
|
+
* 3. the browser language, English fallback (SPEC D5) — also what `auto` means
|
|
351
|
+
*/
|
|
352
|
+
function pickLang(stored, configLang, browserLang) {
|
|
353
|
+
if (stored === "en" || stored === "ja") return stored;
|
|
354
|
+
if (configLang === "ja") return "ja";
|
|
355
|
+
return browserLang === "ja" ? "ja" : "en";
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function saveLang(next) {
|
|
359
|
+
if (next !== "en" && next !== "ja" && next !== "auto") return Promise.resolve(null);
|
|
360
|
+
// Silent by design: the tab must never show an error because config.json
|
|
361
|
+
// could not be written — the local choice already took effect.
|
|
362
|
+
return request("/config", {
|
|
363
|
+
method: "PUT",
|
|
364
|
+
headers: { "content-type": "application/json" },
|
|
365
|
+
body: JSON.stringify({ lang: next })
|
|
366
|
+
}).catch(function () {
|
|
367
|
+
return null;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// ------------------------------------------------------------ audit parsing
|
|
372
|
+
|
|
373
|
+
/** How many audit entries stay visible before the accordion (SPEC V3 §3.5). */
|
|
374
|
+
var AUDIT_VISIBLE = 8;
|
|
375
|
+
|
|
376
|
+
/** One audit line → `{at, kind, ok, detail}`; junk lines still render. */
|
|
377
|
+
function parseAuditEntry(line) {
|
|
378
|
+
var text = String(line == null ? "" : line);
|
|
379
|
+
var parsed = null;
|
|
380
|
+
try {
|
|
381
|
+
parsed = JSON.parse(text);
|
|
382
|
+
} catch (e) {
|
|
383
|
+
parsed = null;
|
|
384
|
+
}
|
|
385
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
386
|
+
return { at: "", kind: "", ok: null, detail: text };
|
|
387
|
+
}
|
|
388
|
+
var detail = [];
|
|
389
|
+
Object.keys(parsed).forEach(function (key) {
|
|
390
|
+
if (key === "at" || key === "kind" || key === "ok") return;
|
|
391
|
+
var value = parsed[key];
|
|
392
|
+
if (value === null || value === undefined || value === "") return;
|
|
393
|
+
detail.push(key + "=" + (typeof value === "object" ? JSON.stringify(value) : String(value)));
|
|
394
|
+
});
|
|
395
|
+
return {
|
|
396
|
+
at: typeof parsed.at === "string" ? parsed.at : "",
|
|
397
|
+
kind: typeof parsed.kind === "string" ? parsed.kind : "",
|
|
398
|
+
ok: typeof parsed.ok === "boolean" ? parsed.ok : null,
|
|
399
|
+
detail: detail.join(" · ")
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** `2026-11-14T02:08:31.123Z` → `11-14 02:08:31`; anything else passes through. */
|
|
404
|
+
function shortTime(value) {
|
|
405
|
+
var text = String(value || "");
|
|
406
|
+
if (text.length >= 19 && text.charAt(10) === "T") return text.slice(5, 19).replace("T", " ");
|
|
407
|
+
return text;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** Newest first: the tail of the file is what the reader wants first. */
|
|
411
|
+
function parseAuditLines(lines) {
|
|
412
|
+
var out = [];
|
|
413
|
+
for (var i = (lines || []).length - 1; i >= 0; i--) out.push(parseAuditEntry(lines[i]));
|
|
414
|
+
return out;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// ------------------------------------------------------------------ helpers
|
|
418
|
+
|
|
419
|
+
/** One JSON request against the plugin backend, auth handled by the host SDK. */
|
|
420
|
+
function request(path, options) {
|
|
421
|
+
return SDK.authedFetch(API + path, options).then(function (res) {
|
|
422
|
+
return res
|
|
423
|
+
.json()
|
|
424
|
+
.catch(function () {
|
|
425
|
+
return {};
|
|
426
|
+
})
|
|
427
|
+
.then(function (body) {
|
|
428
|
+
return { status: res.status, body: body || {} };
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** Human-readable reason from an error envelope. */
|
|
434
|
+
function reasonOf(res, fallback) {
|
|
435
|
+
if (res && res.body && (res.body.error || res.body.code)) return res.body.error || res.body.code;
|
|
436
|
+
if (res && res.status) return "HTTP " + res.status;
|
|
437
|
+
return fallback;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function copyText(text) {
|
|
441
|
+
if (navigator.clipboard && navigator.clipboard.writeText) return navigator.clipboard.writeText(text);
|
|
442
|
+
return Promise.reject(new Error("clipboard unavailable"));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function Chip(props) {
|
|
446
|
+
return h(
|
|
447
|
+
"span",
|
|
448
|
+
{ className: "hp-chip" + (props.tone ? " hp-chip-" + props.tone : "") },
|
|
449
|
+
h("span", { className: "hp-chip-label" }, props.label),
|
|
450
|
+
h("strong", null, props.value)
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function Card(props) {
|
|
455
|
+
return h(
|
|
456
|
+
"section",
|
|
457
|
+
{ className: "hp-card", id: props.id || undefined },
|
|
458
|
+
h(
|
|
459
|
+
"header",
|
|
460
|
+
{ className: "hp-card-head" },
|
|
461
|
+
h("h2", null, props.title),
|
|
462
|
+
props.hint ? h("p", { className: "hp-hint" }, props.hint) : null
|
|
463
|
+
),
|
|
464
|
+
props.children
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** The section ids the jump chips scroll to (SPEC V3 §3.5). */
|
|
469
|
+
var SECTIONS = [
|
|
470
|
+
{ id: "hp-sec-pairing", key: "pairingTitle" },
|
|
471
|
+
{ id: "hp-sec-repos", key: "reposTitle" },
|
|
472
|
+
{ id: "hp-sec-settings", key: "settingsTitle" },
|
|
473
|
+
{ id: "hp-sec-snippets", key: "snippetsTitle" },
|
|
474
|
+
{ id: "hp-sec-pipeline", key: "pipelineTitle" },
|
|
475
|
+
{ id: "hp-sec-logs", key: "logsTitle" },
|
|
476
|
+
{ id: "hp-sec-service", key: "serviceTitle" },
|
|
477
|
+
{ id: "hp-sec-links", key: "linksTitle" }
|
|
478
|
+
];
|
|
479
|
+
|
|
480
|
+
/** Scroll a card to the top of the viewport; no-ops if it has not rendered. */
|
|
481
|
+
function jumpTo(id) {
|
|
482
|
+
var el = typeof document !== "undefined" ? document.getElementById(id) : null;
|
|
483
|
+
if (!el || !el.scrollIntoView) return;
|
|
484
|
+
var reduced =
|
|
485
|
+
typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
486
|
+
if (reduced) {
|
|
487
|
+
el.scrollIntoView({ block: "start" });
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
var before = window.scrollY;
|
|
491
|
+
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
492
|
+
// A hidden tab (or a browser that drops the animation) never moves; land
|
|
493
|
+
// instantly instead of leaving the reader where they tapped.
|
|
494
|
+
setTimeout(function () {
|
|
495
|
+
if (Math.abs(window.scrollY - before) < 2) el.scrollIntoView({ block: "start" });
|
|
496
|
+
}, 350);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** Wrapping chip row: one tap per card instead of scrolling a long page. */
|
|
500
|
+
function SectionNav(props) {
|
|
501
|
+
var t = props.t;
|
|
502
|
+
return h(
|
|
503
|
+
"nav",
|
|
504
|
+
{ className: "hp-nav", "aria-label": t.navLabel },
|
|
505
|
+
SECTIONS.map(function (section) {
|
|
506
|
+
return h(
|
|
507
|
+
"button",
|
|
508
|
+
{
|
|
509
|
+
key: section.id,
|
|
510
|
+
type: "button",
|
|
511
|
+
className: "hp-nav-chip",
|
|
512
|
+
"data-target": section.id,
|
|
513
|
+
onClick: function () {
|
|
514
|
+
jumpTo(section.id);
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
t[section.key]
|
|
518
|
+
);
|
|
519
|
+
})
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** EN / 日本語 segmented switch, mirrored by the Settings card's select. */
|
|
524
|
+
function LangSwitch(props) {
|
|
525
|
+
var t = props.t;
|
|
526
|
+
var options = [
|
|
527
|
+
{ value: "en", label: "EN" },
|
|
528
|
+
{ value: "ja", label: "日本語" }
|
|
529
|
+
];
|
|
530
|
+
return h(
|
|
531
|
+
"div",
|
|
532
|
+
{ className: "hp-lang", role: "group", "aria-label": t.langLabel },
|
|
533
|
+
options.map(function (option) {
|
|
534
|
+
return h(
|
|
535
|
+
"button",
|
|
536
|
+
{
|
|
537
|
+
key: "lang-" + option.value,
|
|
538
|
+
type: "button",
|
|
539
|
+
className: "hp-lang-btn" + (props.lang === option.value ? " hp-lang-active" : ""),
|
|
540
|
+
"aria-pressed": props.lang === option.value,
|
|
541
|
+
lang: option.value,
|
|
542
|
+
onClick: function () {
|
|
543
|
+
props.onChange(option.value);
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
option.label
|
|
547
|
+
);
|
|
548
|
+
})
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// ------------------------------------------------------------------ sections
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Pipeline & Architect (SPEC V5 §3.2 / D25): who writes the spec, and the
|
|
556
|
+
* one-tap A2B optimization. Both buttons run on the bridge so the audit trail
|
|
557
|
+
* records them; this card only reflects what the bridge reports back.
|
|
558
|
+
*/
|
|
559
|
+
function PipelineSection(props) {
|
|
560
|
+
var t = props.t;
|
|
561
|
+
var dataState = useState(null);
|
|
562
|
+
var data = dataState[0];
|
|
563
|
+
var setData = dataState[1];
|
|
564
|
+
var busyState = useState(false);
|
|
565
|
+
var busy = busyState[0];
|
|
566
|
+
var setBusy = busyState[1];
|
|
567
|
+
var errState = useState(null);
|
|
568
|
+
var err = errState[0];
|
|
569
|
+
var setErr = errState[1];
|
|
570
|
+
var noteState = useState(null);
|
|
571
|
+
var note = noteState[0];
|
|
572
|
+
var setNote = noteState[1];
|
|
573
|
+
|
|
574
|
+
var load = useCallback(function () {
|
|
575
|
+
return request("/pipeline")
|
|
576
|
+
.then(function (res) {
|
|
577
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
578
|
+
setData(res.body);
|
|
579
|
+
setErr(null);
|
|
580
|
+
} else {
|
|
581
|
+
setErr(reasonOf(res, t.pipelineUnavailable));
|
|
582
|
+
}
|
|
583
|
+
})
|
|
584
|
+
.catch(function (e) {
|
|
585
|
+
setErr(String((e && e.message) || e));
|
|
586
|
+
});
|
|
587
|
+
}, [t.pipelineUnavailable]);
|
|
588
|
+
|
|
589
|
+
useEffect(function () {
|
|
590
|
+
load();
|
|
591
|
+
}, [load]);
|
|
592
|
+
|
|
593
|
+
function act(body) {
|
|
594
|
+
setBusy(true);
|
|
595
|
+
setNote(null);
|
|
596
|
+
return request("/pipeline", {
|
|
597
|
+
method: "POST",
|
|
598
|
+
headers: { "content-type": "application/json" },
|
|
599
|
+
body: JSON.stringify(body)
|
|
600
|
+
})
|
|
601
|
+
.then(function (res) {
|
|
602
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
603
|
+
setNote(body.action === "optimize" ? t.pipelineOptimized : t.reposSaved);
|
|
604
|
+
setErr(null);
|
|
605
|
+
return load();
|
|
606
|
+
}
|
|
607
|
+
setErr(reasonOf(res, t.pipelineUnavailable));
|
|
608
|
+
})
|
|
609
|
+
.catch(function (e) {
|
|
610
|
+
setErr(String((e && e.message) || e));
|
|
611
|
+
})
|
|
612
|
+
.then(function () {
|
|
613
|
+
setBusy(false);
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
var pipeline = data && data.pipeline;
|
|
618
|
+
var soulApplied = Boolean(pipeline && pipeline.soul && pipeline.soul.applied);
|
|
619
|
+
var skillsPresent = pipeline && pipeline.hermes && Array.isArray(pipeline.hermes.present) ? pipeline.hermes.present.length : 0;
|
|
620
|
+
var jobs = (data && data.jobs) || [];
|
|
621
|
+
var pending = (data && data.pending) || [];
|
|
622
|
+
|
|
623
|
+
return h(
|
|
624
|
+
Card,
|
|
625
|
+
{ id: "hp-sec-pipeline", title: t.pipelineTitle, hint: t.pipelineLead },
|
|
626
|
+
err ? h("p", { className: "hp-error" }, err) : null,
|
|
627
|
+
note ? h("p", { className: "hp-hint" }, note) : null,
|
|
628
|
+
data && data.notice ? h("p", { className: "hp-hint" }, data.notice) : null,
|
|
629
|
+
h(Chip, { label: t.pipelineRunner, value: t.pipelineHermes }),
|
|
630
|
+
h("p", { className: "hp-hint" }, t.pipelineHermesFixed),
|
|
631
|
+
h(
|
|
632
|
+
"div",
|
|
633
|
+
{ className: "hp-kv" },
|
|
634
|
+
h("span", null, t.pipelineSoul),
|
|
635
|
+
h("strong", null, soulApplied ? t.pipelineApplied : t.pipelineMissing)
|
|
636
|
+
),
|
|
637
|
+
h("div", { className: "hp-kv" }, h("span", null, t.pipelineSkills), h("strong", null, String(skillsPresent))),
|
|
638
|
+
h("div", { className: "hp-kv" }, h("span", null, t.pipelineJobs), h("strong", null, String(jobs.length))),
|
|
639
|
+
h("div", { className: "hp-kv" }, h("span", null, t.pipelinePending), h("strong", null, String(pending.length))),
|
|
640
|
+
pending.length
|
|
641
|
+
? h(
|
|
642
|
+
"ul",
|
|
643
|
+
{ className: "hp-list" },
|
|
644
|
+
pending.map(function (row) {
|
|
645
|
+
return h(
|
|
646
|
+
"li",
|
|
647
|
+
{ key: "pending-" + row.path },
|
|
648
|
+
h("span", null, row.title || row.path),
|
|
649
|
+
" ",
|
|
650
|
+
h("span", { className: "hp-hint" }, t.pipelineBatches.replace("{n}", String(row.pendingCount || 0)))
|
|
651
|
+
);
|
|
652
|
+
})
|
|
653
|
+
)
|
|
654
|
+
: null,
|
|
655
|
+
!jobs.length ? h("p", { className: "hp-hint" }, t.pipelineEmpty) : null,
|
|
656
|
+
h(
|
|
657
|
+
"div",
|
|
658
|
+
{ className: "hp-actions" },
|
|
659
|
+
h(
|
|
660
|
+
"button",
|
|
661
|
+
{
|
|
662
|
+
type: "button",
|
|
663
|
+
className: "hp-btn hp-btn-primary",
|
|
664
|
+
disabled: busy || !data || data.source === "offline",
|
|
665
|
+
onClick: function () {
|
|
666
|
+
act({ action: "optimize" });
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
busy ? t.pipelineOptimizing : t.pipelineOptimize
|
|
670
|
+
),
|
|
671
|
+
h(
|
|
672
|
+
"button",
|
|
673
|
+
{
|
|
674
|
+
type: "button",
|
|
675
|
+
className: "hp-btn hp-btn-sm",
|
|
676
|
+
disabled: busy,
|
|
677
|
+
onClick: function () {
|
|
678
|
+
load();
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
t.refresh
|
|
682
|
+
)
|
|
683
|
+
)
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function StatusBar(props) {
|
|
688
|
+
var t = props.t;
|
|
689
|
+
var s = props.status;
|
|
690
|
+
if (!s) return h("div", { className: "hp-chips" }, h(Chip, { label: t.loading, value: "…" }));
|
|
691
|
+
var svc = s.service || {};
|
|
692
|
+
var stateLabel =
|
|
693
|
+
svc.state === "running" ? t.running : svc.state === "stopped" ? t.stopped : t.unknownState;
|
|
694
|
+
var manager = svc.manager && svc.manager !== "none" ? svc.manager : t.noManager;
|
|
695
|
+
var bridge = s.bridge || {};
|
|
696
|
+
return h(
|
|
697
|
+
"div",
|
|
698
|
+
{ className: "hp-chips" },
|
|
699
|
+
h(Chip, {
|
|
700
|
+
label: t.service,
|
|
701
|
+
value: manager + " · " + stateLabel,
|
|
702
|
+
tone: svc.state === "running" ? "ok" : "muted"
|
|
703
|
+
}),
|
|
704
|
+
h(Chip, { label: t.port, value: String(s.port || "—") }),
|
|
705
|
+
h(Chip, {
|
|
706
|
+
label: t.bridge,
|
|
707
|
+
value: bridge.reachable ? t.reachable : t.unreachable,
|
|
708
|
+
tone: bridge.reachable ? "ok" : "bad"
|
|
709
|
+
}),
|
|
710
|
+
h(Chip, { label: t.version, value: bridge.version ? String(bridge.version) : "—" })
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function PairingSection(props) {
|
|
715
|
+
var t = props.t;
|
|
716
|
+
var dataState = useState(null);
|
|
717
|
+
var data = dataState[0];
|
|
718
|
+
var setData = dataState[1];
|
|
719
|
+
var busyState = useState(false);
|
|
720
|
+
var busy = busyState[0];
|
|
721
|
+
var setBusy = busyState[1];
|
|
722
|
+
var errState = useState(null);
|
|
723
|
+
var err = errState[0];
|
|
724
|
+
var setErr = errState[1];
|
|
725
|
+
var nowState = useState(Date.now());
|
|
726
|
+
var now = nowState[0];
|
|
727
|
+
var setNow = nowState[1];
|
|
728
|
+
var copiedState = useState("");
|
|
729
|
+
var copied = copiedState[0];
|
|
730
|
+
var setCopied = copiedState[1];
|
|
731
|
+
|
|
732
|
+
var load = useCallback(function () {
|
|
733
|
+
setBusy(true);
|
|
734
|
+
return request("/pairing")
|
|
735
|
+
.then(function (res) {
|
|
736
|
+
if (res.status === 200 && res.body && res.body.qrPng) {
|
|
737
|
+
setData(res.body);
|
|
738
|
+
setErr(null);
|
|
739
|
+
} else {
|
|
740
|
+
setData(null);
|
|
741
|
+
setErr(reasonOf(res, t.failed));
|
|
742
|
+
}
|
|
743
|
+
setBusy(false);
|
|
744
|
+
})
|
|
745
|
+
.catch(function (e) {
|
|
746
|
+
setData(null);
|
|
747
|
+
setErr(String((e && e.message) || e));
|
|
748
|
+
setBusy(false);
|
|
749
|
+
});
|
|
750
|
+
}, []);
|
|
751
|
+
|
|
752
|
+
useEffect(function () {
|
|
753
|
+
load();
|
|
754
|
+
}, [load]);
|
|
755
|
+
|
|
756
|
+
var expiresAt = data && data.expiresAt ? Number(data.expiresAt) : 0;
|
|
757
|
+
useEffect(
|
|
758
|
+
function () {
|
|
759
|
+
if (!expiresAt) return undefined;
|
|
760
|
+
var id = setInterval(function () {
|
|
761
|
+
setNow(Date.now());
|
|
762
|
+
}, 1000);
|
|
763
|
+
return function () {
|
|
764
|
+
clearInterval(id);
|
|
765
|
+
};
|
|
766
|
+
},
|
|
767
|
+
[expiresAt]
|
|
768
|
+
);
|
|
769
|
+
|
|
770
|
+
var targets = (data && data.targets) || [];
|
|
771
|
+
var minutes = expiresAt ? Math.max(0, Math.ceil((expiresAt - (now || Date.now())) / 60000)) : 0;
|
|
772
|
+
|
|
773
|
+
function copy(url) {
|
|
774
|
+
copyText(url)
|
|
775
|
+
.then(function () {
|
|
776
|
+
setCopied(url);
|
|
777
|
+
setTimeout(function () {
|
|
778
|
+
setCopied("");
|
|
779
|
+
}, 1500);
|
|
780
|
+
})
|
|
781
|
+
.catch(function () {
|
|
782
|
+
setCopied("");
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
return h(
|
|
787
|
+
Card,
|
|
788
|
+
{ id: "hp-sec-pairing", title: t.pairingTitle, hint: t.pairingLead },
|
|
789
|
+
err
|
|
790
|
+
? h("p", { className: "hp-error" }, t.pairingMissing + " (" + err + ")")
|
|
791
|
+
: data
|
|
792
|
+
? h(
|
|
793
|
+
"div",
|
|
794
|
+
{ className: "hp-pairing" },
|
|
795
|
+
h("img", {
|
|
796
|
+
className: "hp-qr",
|
|
797
|
+
src: data.qrPng,
|
|
798
|
+
width: QR_SIZE,
|
|
799
|
+
height: QR_SIZE,
|
|
800
|
+
alt: "Hermes Pilot pairing QR code"
|
|
801
|
+
}),
|
|
802
|
+
h(
|
|
803
|
+
"div",
|
|
804
|
+
{ className: "hp-pairing-side" },
|
|
805
|
+
h(
|
|
806
|
+
"ol",
|
|
807
|
+
{ className: "hp-steps" },
|
|
808
|
+
t.steps.map(function (step, i) {
|
|
809
|
+
return h("li", { key: "s" + i }, step);
|
|
810
|
+
})
|
|
811
|
+
),
|
|
812
|
+
h(
|
|
813
|
+
"p",
|
|
814
|
+
{ className: "hp-expiry" + (minutes ? "" : " hp-expiry-over") },
|
|
815
|
+
minutes ? t.expiresIn.replace("{n}", String(minutes)) : t.expired
|
|
816
|
+
),
|
|
817
|
+
h(
|
|
818
|
+
"ul",
|
|
819
|
+
{ className: "hp-targets" },
|
|
820
|
+
targets.map(function (target, i) {
|
|
821
|
+
var url = (target && target.url) || "";
|
|
822
|
+
return h(
|
|
823
|
+
"li",
|
|
824
|
+
{ key: "t" + i },
|
|
825
|
+
h("span", { className: "hp-target-label" }, (target && target.label) || url),
|
|
826
|
+
h("code", { className: "hp-url" }, url),
|
|
827
|
+
url
|
|
828
|
+
? h(
|
|
829
|
+
"button",
|
|
830
|
+
{
|
|
831
|
+
type: "button",
|
|
832
|
+
className: "hp-btn hp-btn-sm",
|
|
833
|
+
onClick: function () {
|
|
834
|
+
copy(url);
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
copied === url ? t.copied : t.copy
|
|
838
|
+
)
|
|
839
|
+
: null
|
|
840
|
+
);
|
|
841
|
+
})
|
|
842
|
+
),
|
|
843
|
+
h(
|
|
844
|
+
"button",
|
|
845
|
+
{ type: "button", className: "hp-btn", onClick: load, disabled: busy },
|
|
846
|
+
busy ? t.loading : t.newCode
|
|
847
|
+
)
|
|
848
|
+
)
|
|
849
|
+
)
|
|
850
|
+
: h("p", { className: "hp-hint" }, busy ? t.loading : t.failed)
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
function SettingsSection(props) {
|
|
855
|
+
var t = props.t;
|
|
856
|
+
var formState = useState(null);
|
|
857
|
+
var form = formState[0];
|
|
858
|
+
var setForm = formState[1];
|
|
859
|
+
var errState = useState({});
|
|
860
|
+
var errors = errState[0];
|
|
861
|
+
var setErrors = errState[1];
|
|
862
|
+
var noteState = useState(null);
|
|
863
|
+
var note = noteState[0];
|
|
864
|
+
var setNote = noteState[1];
|
|
865
|
+
var busyState = useState(false);
|
|
866
|
+
var busy = busyState[0];
|
|
867
|
+
var setBusy = busyState[1];
|
|
868
|
+
|
|
869
|
+
useEffect(function () {
|
|
870
|
+
request("/config")
|
|
871
|
+
.then(function (res) {
|
|
872
|
+
var cfg = (res.body && res.body.config) || {};
|
|
873
|
+
setForm({
|
|
874
|
+
scanDirs: Array.isArray(cfg.scanDirs) ? cfg.scanDirs.join("\n") : "",
|
|
875
|
+
tlsPort: cfg.tlsPort == null ? "" : String(cfg.tlsPort),
|
|
876
|
+
tailscaleDns: cfg.tailscaleDns || "",
|
|
877
|
+
servicePort: cfg.servicePort == null ? "" : String(cfg.servicePort)
|
|
878
|
+
});
|
|
879
|
+
})
|
|
880
|
+
.catch(function (e) {
|
|
881
|
+
setNote(String((e && e.message) || e));
|
|
882
|
+
});
|
|
883
|
+
}, []);
|
|
884
|
+
|
|
885
|
+
function field(name, label, hint, type, wide) {
|
|
886
|
+
var errCode = errors[name];
|
|
887
|
+
var message = errCode ? (t.err[errCode] || errCode) : null;
|
|
888
|
+
return h(
|
|
889
|
+
"label",
|
|
890
|
+
{ className: "hp-field" + (wide ? " hp-field-wide" : "") + (errCode ? " hp-field-bad" : "") },
|
|
891
|
+
h("span", { className: "hp-field-label" }, label),
|
|
892
|
+
type === "area"
|
|
893
|
+
? h("textarea", {
|
|
894
|
+
rows: 4,
|
|
895
|
+
value: form[name],
|
|
896
|
+
spellCheck: false,
|
|
897
|
+
onChange: function (e) {
|
|
898
|
+
var next = {};
|
|
899
|
+
next[name] = e.target.value;
|
|
900
|
+
setForm(Object.assign({}, form, next));
|
|
901
|
+
}
|
|
902
|
+
})
|
|
903
|
+
: h("input", {
|
|
904
|
+
type: "text",
|
|
905
|
+
inputMode: "text",
|
|
906
|
+
value: form[name],
|
|
907
|
+
spellCheck: false,
|
|
908
|
+
onChange: function (e) {
|
|
909
|
+
var next = {};
|
|
910
|
+
next[name] = e.target.value;
|
|
911
|
+
setForm(Object.assign({}, form, next));
|
|
912
|
+
}
|
|
913
|
+
}),
|
|
914
|
+
hint ? h("span", { className: "hp-field-hint" }, hint) : null,
|
|
915
|
+
message ? h("span", { className: "hp-field-error" }, message) : null
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* `auto` / `en` / `ja` — the same choice the header's segmented switch makes,
|
|
921
|
+
* so the select is driven by App's state instead of a second copy here.
|
|
922
|
+
*/
|
|
923
|
+
function langField() {
|
|
924
|
+
var value = props.langChoice || "auto";
|
|
925
|
+
var errCode = errors.lang;
|
|
926
|
+
return h(
|
|
927
|
+
"label",
|
|
928
|
+
{ className: "hp-field" + (errCode ? " hp-field-bad" : "") },
|
|
929
|
+
h("span", { className: "hp-field-label" }, t.langLabel),
|
|
930
|
+
h(
|
|
931
|
+
"select",
|
|
932
|
+
{
|
|
933
|
+
className: "hp-field-select",
|
|
934
|
+
value: value,
|
|
935
|
+
onChange: function (e) {
|
|
936
|
+
// Immediate (SPEC V3 §3.5): labels and the snippet default language
|
|
937
|
+
// switch on change; App also PUTs the choice to config.json.
|
|
938
|
+
if (props.onLangChange) props.onLangChange(e.target.value);
|
|
939
|
+
}
|
|
940
|
+
},
|
|
941
|
+
[
|
|
942
|
+
{ value: "auto", label: t.langAuto },
|
|
943
|
+
{ value: "en", label: "EN" },
|
|
944
|
+
{ value: "ja", label: "日本語" }
|
|
945
|
+
].map(function (option) {
|
|
946
|
+
return h("option", { key: "lang-" + option.value, value: option.value }, option.label);
|
|
947
|
+
})
|
|
948
|
+
),
|
|
949
|
+
h("span", { className: "hp-field-hint" }, t.langHint),
|
|
950
|
+
errCode ? h("span", { className: "hp-field-error" }, t.err[errCode] || errCode) : null
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
if (!form) return h(Card, { id: "hp-sec-settings", title: t.settingsTitle }, h("p", { className: "hp-hint" }, t.loading));
|
|
955
|
+
|
|
956
|
+
function save() {
|
|
957
|
+
setBusy(true);
|
|
958
|
+
setNote(null);
|
|
959
|
+
var payload = {
|
|
960
|
+
// `auto` is a legal config.json value (LANGUAGES): it means "follow the
|
|
961
|
+
// browser", so the choice survives on this machine and on others.
|
|
962
|
+
lang: props.langChoice || "auto",
|
|
963
|
+
scanDirs: form.scanDirs,
|
|
964
|
+
tlsPort: form.tlsPort === "" ? null : form.tlsPort,
|
|
965
|
+
tailscaleDns: form.tailscaleDns,
|
|
966
|
+
servicePort: form.servicePort === "" ? null : form.servicePort
|
|
967
|
+
};
|
|
968
|
+
request("/config", {
|
|
969
|
+
method: "PUT",
|
|
970
|
+
headers: { "content-type": "application/json" },
|
|
971
|
+
body: JSON.stringify(payload)
|
|
972
|
+
})
|
|
973
|
+
.then(function (res) {
|
|
974
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
975
|
+
setErrors({});
|
|
976
|
+
// scanDirs is written to config.json *and* repos.json (G3).
|
|
977
|
+
setNote(res.body.sync ? t.saved + " · repos.json" : t.saved);
|
|
978
|
+
if (props.onSaved) props.onSaved();
|
|
979
|
+
} else {
|
|
980
|
+
setErrors((res.body && res.body.errors) || {});
|
|
981
|
+
setNote(reasonOf(res, t.failed));
|
|
982
|
+
}
|
|
983
|
+
setBusy(false);
|
|
984
|
+
})
|
|
985
|
+
.catch(function (e) {
|
|
986
|
+
setNote(String((e && e.message) || e));
|
|
987
|
+
setBusy(false);
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
return h(
|
|
992
|
+
Card,
|
|
993
|
+
{ id: "hp-sec-settings", title: t.settingsTitle, hint: t.settingsLead },
|
|
994
|
+
h(
|
|
995
|
+
"div",
|
|
996
|
+
{ className: "hp-form" },
|
|
997
|
+
langField(),
|
|
998
|
+
field("scanDirs", t.scanDirs, t.scanDirsHint, "area", true),
|
|
999
|
+
field("servicePort", t.servicePort, null, "text"),
|
|
1000
|
+
field("tlsPort", t.tlsPort, t.tlsPortHint, "text"),
|
|
1001
|
+
field("tailscaleDns", t.tailscaleDns, t.tailscaleDnsHint, "text")
|
|
1002
|
+
),
|
|
1003
|
+
h(
|
|
1004
|
+
"div",
|
|
1005
|
+
{ className: "hp-actions" },
|
|
1006
|
+
h("button", { type: "button", className: "hp-btn hp-btn-primary", onClick: save, disabled: busy }, busy ? t.saving : t.save),
|
|
1007
|
+
note ? h("span", { className: "hp-note" }, note) : null
|
|
1008
|
+
)
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
function ServiceSection(props) {
|
|
1013
|
+
var t = props.t;
|
|
1014
|
+
var busyState = useState("");
|
|
1015
|
+
var busy = busyState[0];
|
|
1016
|
+
var setBusy = busyState[1];
|
|
1017
|
+
var outState = useState(null);
|
|
1018
|
+
var out = outState[0];
|
|
1019
|
+
var setOut = outState[1];
|
|
1020
|
+
var armedState = useState(false);
|
|
1021
|
+
var armed = armedState[0];
|
|
1022
|
+
var setArmed = armedState[1];
|
|
1023
|
+
var timer = useRef(null);
|
|
1024
|
+
|
|
1025
|
+
useEffect(function () {
|
|
1026
|
+
return function () {
|
|
1027
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1028
|
+
};
|
|
1029
|
+
}, []);
|
|
1030
|
+
|
|
1031
|
+
function run(action) {
|
|
1032
|
+
setBusy(action);
|
|
1033
|
+
setOut(null);
|
|
1034
|
+
request("/service/" + action, { method: "POST" })
|
|
1035
|
+
.then(function (res) {
|
|
1036
|
+
var body = res.body || {};
|
|
1037
|
+
setOut((body.stdout || reasonOf(res, "")) + (body.ok ? "" : " (exit " + body.code + ")"));
|
|
1038
|
+
setBusy("");
|
|
1039
|
+
if (props.onChanged) props.onChanged();
|
|
1040
|
+
})
|
|
1041
|
+
.catch(function (e) {
|
|
1042
|
+
setOut(String((e && e.message) || e));
|
|
1043
|
+
setBusy("");
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function restart() {
|
|
1048
|
+
if (!armed) {
|
|
1049
|
+
setArmed(true);
|
|
1050
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1051
|
+
timer.current = setTimeout(function () {
|
|
1052
|
+
setArmed(false);
|
|
1053
|
+
}, 5000);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1057
|
+
setArmed(false);
|
|
1058
|
+
run("restart");
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
return h(
|
|
1062
|
+
Card,
|
|
1063
|
+
{ id: "hp-sec-service", title: t.serviceTitle, hint: t.serviceLead },
|
|
1064
|
+
h(
|
|
1065
|
+
"div",
|
|
1066
|
+
{ className: "hp-actions" },
|
|
1067
|
+
h(
|
|
1068
|
+
"button",
|
|
1069
|
+
{ type: "button", className: "hp-btn", onClick: function () { run("status"); }, disabled: Boolean(busy) },
|
|
1070
|
+
t.check
|
|
1071
|
+
),
|
|
1072
|
+
h(
|
|
1073
|
+
"button",
|
|
1074
|
+
{ type: "button", className: "hp-btn", onClick: function () { run("install"); }, disabled: Boolean(busy) },
|
|
1075
|
+
t.install
|
|
1076
|
+
),
|
|
1077
|
+
h(
|
|
1078
|
+
"button",
|
|
1079
|
+
{ type: "button", className: "hp-btn" + (armed ? " hp-btn-warn" : ""), onClick: restart, disabled: Boolean(busy) },
|
|
1080
|
+
armed ? t.restartArmed : t.restart
|
|
1081
|
+
)
|
|
1082
|
+
),
|
|
1083
|
+
out
|
|
1084
|
+
? h(
|
|
1085
|
+
"details",
|
|
1086
|
+
{ className: "hp-out", open: true },
|
|
1087
|
+
h("summary", null, t.output),
|
|
1088
|
+
h("pre", null, out)
|
|
1089
|
+
)
|
|
1090
|
+
: null
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function LinksSection(props) {
|
|
1095
|
+
var t = props.t;
|
|
1096
|
+
var s = props.status || {};
|
|
1097
|
+
var links = [
|
|
1098
|
+
{ label: t.lan, url: s.lanUrl },
|
|
1099
|
+
{ label: t.tailscale, url: s.tailscaleUrl }
|
|
1100
|
+
];
|
|
1101
|
+
return h(
|
|
1102
|
+
Card,
|
|
1103
|
+
{ id: "hp-sec-links", title: t.linksTitle },
|
|
1104
|
+
h(
|
|
1105
|
+
"ul",
|
|
1106
|
+
{ className: "hp-links" },
|
|
1107
|
+
links.map(function (link, i) {
|
|
1108
|
+
return h(
|
|
1109
|
+
"li",
|
|
1110
|
+
{ key: "l" + i },
|
|
1111
|
+
h("span", { className: "hp-target-label" }, link.label),
|
|
1112
|
+
link.url
|
|
1113
|
+
? h("a", { className: "hp-url", href: link.url, target: "_blank", rel: "noreferrer" }, link.url)
|
|
1114
|
+
: h("span", { className: "hp-hint" }, t.noLink)
|
|
1115
|
+
);
|
|
1116
|
+
})
|
|
1117
|
+
)
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// ------------------------------------------------------------- repositories
|
|
1122
|
+
|
|
1123
|
+
/** A checkbox that reads as a chip (Hot / Hidden). */
|
|
1124
|
+
function Toggle(props) {
|
|
1125
|
+
return h(
|
|
1126
|
+
"label",
|
|
1127
|
+
{ className: "hp-toggle" + (props.on ? " hp-toggle-on" : "") },
|
|
1128
|
+
h("input", {
|
|
1129
|
+
type: "checkbox",
|
|
1130
|
+
checked: Boolean(props.on),
|
|
1131
|
+
onChange: function (e) {
|
|
1132
|
+
props.onChange(e.target.checked);
|
|
1133
|
+
}
|
|
1134
|
+
}),
|
|
1135
|
+
h("span", null, props.label)
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
function basename(value) {
|
|
1140
|
+
var parts = String(value || "").split("/").filter(Boolean);
|
|
1141
|
+
return parts.length ? parts[parts.length - 1] : String(value || "");
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
function RepositoriesSection(props) {
|
|
1145
|
+
var t = props.t;
|
|
1146
|
+
var dataState = useState(null);
|
|
1147
|
+
var data = dataState[0];
|
|
1148
|
+
var setData = dataState[1];
|
|
1149
|
+
var busyState = useState("");
|
|
1150
|
+
var busy = busyState[0];
|
|
1151
|
+
var setBusy = busyState[1];
|
|
1152
|
+
var errState = useState(null);
|
|
1153
|
+
var err = errState[0];
|
|
1154
|
+
var setErr = errState[1];
|
|
1155
|
+
var noteState = useState(null);
|
|
1156
|
+
var note = noteState[0];
|
|
1157
|
+
var setNote = noteState[1];
|
|
1158
|
+
var pathState = useState("");
|
|
1159
|
+
var path = pathState[0];
|
|
1160
|
+
var setPath = pathState[1];
|
|
1161
|
+
|
|
1162
|
+
var load = useCallback(function () {
|
|
1163
|
+
return request("/repos")
|
|
1164
|
+
.then(function (res) {
|
|
1165
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
1166
|
+
setData(res.body);
|
|
1167
|
+
setErr(null);
|
|
1168
|
+
} else {
|
|
1169
|
+
setErr(reasonOf(res, t.failed));
|
|
1170
|
+
}
|
|
1171
|
+
})
|
|
1172
|
+
.catch(function (e) {
|
|
1173
|
+
setErr(String((e && e.message) || e));
|
|
1174
|
+
});
|
|
1175
|
+
}, []);
|
|
1176
|
+
|
|
1177
|
+
useEffect(
|
|
1178
|
+
function () {
|
|
1179
|
+
load();
|
|
1180
|
+
},
|
|
1181
|
+
[load, props.tick]
|
|
1182
|
+
);
|
|
1183
|
+
|
|
1184
|
+
function act(action, extra) {
|
|
1185
|
+
setBusy(action);
|
|
1186
|
+
setNote(null);
|
|
1187
|
+
setErr(null);
|
|
1188
|
+
var body = Object.assign({ action: action }, extra || {});
|
|
1189
|
+
request("/repos", {
|
|
1190
|
+
method: "POST",
|
|
1191
|
+
headers: { "content-type": "application/json" },
|
|
1192
|
+
body: JSON.stringify(body)
|
|
1193
|
+
})
|
|
1194
|
+
.then(function (res) {
|
|
1195
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
1196
|
+
setNote(action === "createBoard" ? t.boardReady : t.reposSaved);
|
|
1197
|
+
load();
|
|
1198
|
+
if (props.onChanged) props.onChanged();
|
|
1199
|
+
} else {
|
|
1200
|
+
setErr(reasonOf(res, t.failed));
|
|
1201
|
+
}
|
|
1202
|
+
setBusy("");
|
|
1203
|
+
})
|
|
1204
|
+
.catch(function (e) {
|
|
1205
|
+
setErr(String((e && e.message) || e));
|
|
1206
|
+
setBusy("");
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
var repos = (data && data.repos) || [];
|
|
1211
|
+
var hidden = (data && data.config && data.config.hidden) || [];
|
|
1212
|
+
var scanDirs = (data && data.scanDirs) || [];
|
|
1213
|
+
var fromFile = data && data.source === "file";
|
|
1214
|
+
|
|
1215
|
+
return h(
|
|
1216
|
+
Card,
|
|
1217
|
+
{ id: "hp-sec-repos", title: t.reposTitle, hint: t.reposLead },
|
|
1218
|
+
err ? h("p", { className: "hp-error" }, err) : null,
|
|
1219
|
+
fromFile ? h("p", { className: "hp-hint" }, t.repoFromFile) : null,
|
|
1220
|
+
h(
|
|
1221
|
+
"div",
|
|
1222
|
+
{ className: "hp-actions hp-add-row" },
|
|
1223
|
+
h("input", {
|
|
1224
|
+
className: "hp-input",
|
|
1225
|
+
type: "text",
|
|
1226
|
+
placeholder: t.repoAddPlaceholder,
|
|
1227
|
+
value: path,
|
|
1228
|
+
spellCheck: false,
|
|
1229
|
+
onChange: function (e) {
|
|
1230
|
+
setPath(e.target.value);
|
|
1231
|
+
}
|
|
1232
|
+
}),
|
|
1233
|
+
h(
|
|
1234
|
+
"button",
|
|
1235
|
+
{
|
|
1236
|
+
type: "button",
|
|
1237
|
+
className: "hp-btn",
|
|
1238
|
+
disabled: Boolean(busy) || !String(path || "").trim(),
|
|
1239
|
+
onClick: function () {
|
|
1240
|
+
act("add", { path: path });
|
|
1241
|
+
setPath("");
|
|
1242
|
+
}
|
|
1243
|
+
},
|
|
1244
|
+
t.repoAdd
|
|
1245
|
+
),
|
|
1246
|
+
h(
|
|
1247
|
+
"button",
|
|
1248
|
+
{ type: "button", className: "hp-btn hp-btn-sm", onClick: load, disabled: Boolean(busy) },
|
|
1249
|
+
t.refresh
|
|
1250
|
+
)
|
|
1251
|
+
),
|
|
1252
|
+
h(
|
|
1253
|
+
"p",
|
|
1254
|
+
{ className: "hp-hint hp-scanhint" },
|
|
1255
|
+
h("strong", null, t.repoScanDirsLabel + ": "),
|
|
1256
|
+
h("span", { className: "hp-scanhint-value" }, scanDirs.join(" · ") || "—"),
|
|
1257
|
+
" ",
|
|
1258
|
+
t.repoScanDirsHint
|
|
1259
|
+
),
|
|
1260
|
+
repos.length
|
|
1261
|
+
? h(
|
|
1262
|
+
"ul",
|
|
1263
|
+
{ className: "hp-repos" },
|
|
1264
|
+
repos.map(function (repo) {
|
|
1265
|
+
var boards = repo.boards || [];
|
|
1266
|
+
return h(
|
|
1267
|
+
"li",
|
|
1268
|
+
{ key: "repo-" + repo.id, className: "hp-repo" },
|
|
1269
|
+
h(
|
|
1270
|
+
"div",
|
|
1271
|
+
{ className: "hp-repo-main" },
|
|
1272
|
+
h("strong", { className: "hp-repo-label" }, repo.label),
|
|
1273
|
+
h("code", { className: "hp-repo-path" }, repo.path),
|
|
1274
|
+
h("span", { className: "hp-badge" }, repo.source)
|
|
1275
|
+
),
|
|
1276
|
+
h(
|
|
1277
|
+
"div",
|
|
1278
|
+
{ className: "hp-repo-actions" },
|
|
1279
|
+
h(
|
|
1280
|
+
"button",
|
|
1281
|
+
{
|
|
1282
|
+
type: "button",
|
|
1283
|
+
className: "hp-btn hp-btn-sm",
|
|
1284
|
+
onClick: function () {
|
|
1285
|
+
act(repo.pinned ? "unpin" : "pin", { id: repo.id });
|
|
1286
|
+
}
|
|
1287
|
+
},
|
|
1288
|
+
repo.pinned ? t.unpin : t.pin
|
|
1289
|
+
),
|
|
1290
|
+
h(
|
|
1291
|
+
"button",
|
|
1292
|
+
{
|
|
1293
|
+
type: "button",
|
|
1294
|
+
className: "hp-btn hp-btn-sm",
|
|
1295
|
+
onClick: function () {
|
|
1296
|
+
act("hide", { id: repo.id });
|
|
1297
|
+
}
|
|
1298
|
+
},
|
|
1299
|
+
t.hide
|
|
1300
|
+
),
|
|
1301
|
+
boards.length
|
|
1302
|
+
? boards.map(function (b) {
|
|
1303
|
+
return h("span", { key: "board-" + (b.slug || b.name), className: "hp-badge hp-badge-ok" }, b.name || b.slug);
|
|
1304
|
+
})
|
|
1305
|
+
: h(
|
|
1306
|
+
"button",
|
|
1307
|
+
{
|
|
1308
|
+
type: "button",
|
|
1309
|
+
className: "hp-btn hp-btn-sm",
|
|
1310
|
+
disabled: Boolean(busy),
|
|
1311
|
+
onClick: function () {
|
|
1312
|
+
act("createBoard", { id: repo.id });
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
t.boardCreate
|
|
1316
|
+
)
|
|
1317
|
+
)
|
|
1318
|
+
);
|
|
1319
|
+
})
|
|
1320
|
+
)
|
|
1321
|
+
: h("p", { className: "hp-hint" }, data ? t.repoEmpty : t.loading),
|
|
1322
|
+
h(
|
|
1323
|
+
"div",
|
|
1324
|
+
{ className: "hp-sub" },
|
|
1325
|
+
h("h3", null, t.hiddenTitle + (hidden.length ? " (" + hidden.length + ")" : "")),
|
|
1326
|
+
hidden.length
|
|
1327
|
+
? h(
|
|
1328
|
+
"ul",
|
|
1329
|
+
{ className: "hp-repos hp-repos-hidden" },
|
|
1330
|
+
hidden.map(function (item, i) {
|
|
1331
|
+
return h(
|
|
1332
|
+
"li",
|
|
1333
|
+
{ key: "hidden-" + i, className: "hp-repo" },
|
|
1334
|
+
h("div", { className: "hp-repo-main" }, h("span", { className: "hp-target-label" }, basename(item)), h("code", { className: "hp-repo-path" }, item)),
|
|
1335
|
+
h(
|
|
1336
|
+
"div",
|
|
1337
|
+
{ className: "hp-repo-actions" },
|
|
1338
|
+
h(
|
|
1339
|
+
"button",
|
|
1340
|
+
{
|
|
1341
|
+
type: "button",
|
|
1342
|
+
className: "hp-btn hp-btn-sm",
|
|
1343
|
+
onClick: function () {
|
|
1344
|
+
act("unhide", { id: item });
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
t.unhide
|
|
1348
|
+
)
|
|
1349
|
+
)
|
|
1350
|
+
);
|
|
1351
|
+
})
|
|
1352
|
+
)
|
|
1353
|
+
: h("p", { className: "hp-hint" }, t.hiddenNone)
|
|
1354
|
+
),
|
|
1355
|
+
note ? h("p", { className: "hp-note" }, note) : null
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
// ----------------------------------------------------------------- snippets
|
|
1360
|
+
|
|
1361
|
+
function SnippetsSection(props) {
|
|
1362
|
+
var t = props.t;
|
|
1363
|
+
var kindState = useState("chat");
|
|
1364
|
+
var kind = kindState[0];
|
|
1365
|
+
var setKind = kindState[1];
|
|
1366
|
+
var langState = useState(props.lang || "en");
|
|
1367
|
+
var lang = langState[0];
|
|
1368
|
+
var setLang = langState[1];
|
|
1369
|
+
var dataState = useState(null);
|
|
1370
|
+
var data = dataState[0];
|
|
1371
|
+
var setData = dataState[1];
|
|
1372
|
+
var overridesState = useState({});
|
|
1373
|
+
var overrides = overridesState[0];
|
|
1374
|
+
var setOverrides = overridesState[1];
|
|
1375
|
+
var customState = useState([]);
|
|
1376
|
+
var custom = customState[0];
|
|
1377
|
+
var setCustom = customState[1];
|
|
1378
|
+
var busyState = useState("");
|
|
1379
|
+
var busy = busyState[0];
|
|
1380
|
+
var setBusy = busyState[1];
|
|
1381
|
+
var errState = useState(null);
|
|
1382
|
+
var err = errState[0];
|
|
1383
|
+
var setErr = errState[1];
|
|
1384
|
+
var noteState = useState(null);
|
|
1385
|
+
var note = noteState[0];
|
|
1386
|
+
var setNote = noteState[1];
|
|
1387
|
+
var armedState = useState(false);
|
|
1388
|
+
var armed = armedState[0];
|
|
1389
|
+
var setArmed = armedState[1];
|
|
1390
|
+
var timer = useRef(null);
|
|
1391
|
+
|
|
1392
|
+
var load = useCallback(
|
|
1393
|
+
function () {
|
|
1394
|
+
setBusy("load");
|
|
1395
|
+
return request("/snippets?kind=" + kind + "&lang=" + lang)
|
|
1396
|
+
.then(function (res) {
|
|
1397
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
1398
|
+
setData(res.body);
|
|
1399
|
+
setOverrides(res.body.overrides || {});
|
|
1400
|
+
setCustom(res.body.custom || []);
|
|
1401
|
+
setErr(null);
|
|
1402
|
+
} else {
|
|
1403
|
+
setErr(reasonOf(res, t.failed));
|
|
1404
|
+
}
|
|
1405
|
+
setBusy("");
|
|
1406
|
+
})
|
|
1407
|
+
.catch(function (e) {
|
|
1408
|
+
setErr(String((e && e.message) || e));
|
|
1409
|
+
setBusy("");
|
|
1410
|
+
});
|
|
1411
|
+
},
|
|
1412
|
+
[kind, lang]
|
|
1413
|
+
);
|
|
1414
|
+
|
|
1415
|
+
useEffect(
|
|
1416
|
+
function () {
|
|
1417
|
+
load();
|
|
1418
|
+
},
|
|
1419
|
+
[load]
|
|
1420
|
+
);
|
|
1421
|
+
|
|
1422
|
+
useEffect(function () {
|
|
1423
|
+
return function () {
|
|
1424
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1425
|
+
};
|
|
1426
|
+
}, []);
|
|
1427
|
+
|
|
1428
|
+
// The header's EN / 日本語 switch owns the snippet default language
|
|
1429
|
+
// (SPEC V3 §3.5). The local EN/JA tabs remain, but the tab re-syncs when the
|
|
1430
|
+
// header changes so both always agree on the default.
|
|
1431
|
+
useEffect(
|
|
1432
|
+
function () {
|
|
1433
|
+
setLang(props.lang === "ja" ? "ja" : "en");
|
|
1434
|
+
},
|
|
1435
|
+
[props.lang]
|
|
1436
|
+
);
|
|
1437
|
+
|
|
1438
|
+
function save(body, done) {
|
|
1439
|
+
setBusy("save");
|
|
1440
|
+
setNote(null);
|
|
1441
|
+
setErr(null);
|
|
1442
|
+
request("/snippets?kind=" + kind + "&lang=" + lang, {
|
|
1443
|
+
method: "PUT",
|
|
1444
|
+
headers: { "content-type": "application/json" },
|
|
1445
|
+
body: JSON.stringify(body)
|
|
1446
|
+
})
|
|
1447
|
+
.then(function (res) {
|
|
1448
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
1449
|
+
setData(res.body);
|
|
1450
|
+
setOverrides(res.body.overrides || {});
|
|
1451
|
+
setCustom(res.body.custom || []);
|
|
1452
|
+
setNote(done || t.saved);
|
|
1453
|
+
if (props.onChanged) props.onChanged();
|
|
1454
|
+
} else {
|
|
1455
|
+
setErr(reasonOf(res, t.failed));
|
|
1456
|
+
}
|
|
1457
|
+
setBusy("");
|
|
1458
|
+
})
|
|
1459
|
+
.catch(function (e) {
|
|
1460
|
+
setErr(String((e && e.message) || e));
|
|
1461
|
+
setBusy("");
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
function override(id, patch) {
|
|
1466
|
+
var current = overrides[id] || {};
|
|
1467
|
+
var next = Object.assign({}, overrides);
|
|
1468
|
+
next[id] = Object.assign({}, current, patch);
|
|
1469
|
+
setOverrides(next);
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
function editCustom(index, patch) {
|
|
1473
|
+
setCustom(
|
|
1474
|
+
custom.map(function (item, i) {
|
|
1475
|
+
return i === index ? Object.assign({}, item, patch) : item;
|
|
1476
|
+
})
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
function resetNow() {
|
|
1481
|
+
if (!armed) {
|
|
1482
|
+
setArmed(true);
|
|
1483
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1484
|
+
timer.current = setTimeout(function () {
|
|
1485
|
+
setArmed(false);
|
|
1486
|
+
}, 5000);
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1490
|
+
setArmed(false);
|
|
1491
|
+
save({ reset: true }, t.saved);
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
var all = (data && data.allSnippets) || [];
|
|
1495
|
+
var builtin = all.filter(function (item) {
|
|
1496
|
+
return !item.custom;
|
|
1497
|
+
});
|
|
1498
|
+
var fromFile = data && data.source === "file";
|
|
1499
|
+
|
|
1500
|
+
function tabButton(value, label) {
|
|
1501
|
+
return h(
|
|
1502
|
+
"button",
|
|
1503
|
+
{
|
|
1504
|
+
type: "button",
|
|
1505
|
+
className: "hp-tab" + (kind === value ? " hp-tab-active" : ""),
|
|
1506
|
+
onClick: function () {
|
|
1507
|
+
setKind(value);
|
|
1508
|
+
}
|
|
1509
|
+
},
|
|
1510
|
+
label
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
return h(
|
|
1515
|
+
Card,
|
|
1516
|
+
{ id: "hp-sec-snippets", title: t.snippetsTitle, hint: t.snippetsLead },
|
|
1517
|
+
err ? h("p", { className: "hp-error" }, err) : null,
|
|
1518
|
+
h(
|
|
1519
|
+
"div",
|
|
1520
|
+
{ className: "hp-tabs" },
|
|
1521
|
+
tabButton("chat", t.tabChat),
|
|
1522
|
+
tabButton("term", t.tabTerm),
|
|
1523
|
+
h(
|
|
1524
|
+
"button",
|
|
1525
|
+
{
|
|
1526
|
+
type: "button",
|
|
1527
|
+
className: "hp-tab" + (lang === "en" ? " hp-tab-active" : ""),
|
|
1528
|
+
onClick: function () {
|
|
1529
|
+
setLang("en");
|
|
1530
|
+
}
|
|
1531
|
+
},
|
|
1532
|
+
"EN"
|
|
1533
|
+
),
|
|
1534
|
+
h(
|
|
1535
|
+
"button",
|
|
1536
|
+
{
|
|
1537
|
+
type: "button",
|
|
1538
|
+
className: "hp-tab" + (lang === "ja" ? " hp-tab-active" : ""),
|
|
1539
|
+
onClick: function () {
|
|
1540
|
+
setLang("ja");
|
|
1541
|
+
}
|
|
1542
|
+
},
|
|
1543
|
+
"JA"
|
|
1544
|
+
)
|
|
1545
|
+
),
|
|
1546
|
+
fromFile ? h("p", { className: "hp-hint" }, t.snippetsFileOnly) : null,
|
|
1547
|
+
builtin.length
|
|
1548
|
+
? h(
|
|
1549
|
+
"ul",
|
|
1550
|
+
{ className: "hp-snippets" },
|
|
1551
|
+
builtin.map(function (item) {
|
|
1552
|
+
var ov = overrides[item.id] || {};
|
|
1553
|
+
var hot = typeof ov.hot === "boolean" ? ov.hot : item.hot;
|
|
1554
|
+
var hid = typeof ov.hidden === "boolean" ? ov.hidden : item.hidden;
|
|
1555
|
+
return h(
|
|
1556
|
+
"li",
|
|
1557
|
+
{ key: "snip-" + item.id, className: "hp-snippet" },
|
|
1558
|
+
h(
|
|
1559
|
+
"div",
|
|
1560
|
+
{ className: "hp-snippet-head" },
|
|
1561
|
+
h("strong", null, item.label),
|
|
1562
|
+
h("code", { className: "hp-snippet-id" }, item.id),
|
|
1563
|
+
h(
|
|
1564
|
+
"div",
|
|
1565
|
+
{ className: "hp-snippet-toggles" },
|
|
1566
|
+
h(Toggle, {
|
|
1567
|
+
label: t.hot,
|
|
1568
|
+
on: hot,
|
|
1569
|
+
onChange: function (next) {
|
|
1570
|
+
override(item.id, { hot: next });
|
|
1571
|
+
}
|
|
1572
|
+
}),
|
|
1573
|
+
h(Toggle, {
|
|
1574
|
+
label: t.hiddenTag,
|
|
1575
|
+
on: hid,
|
|
1576
|
+
onChange: function (next) {
|
|
1577
|
+
override(item.id, { hidden: next });
|
|
1578
|
+
}
|
|
1579
|
+
})
|
|
1580
|
+
)
|
|
1581
|
+
),
|
|
1582
|
+
h("p", { className: "hp-snippet-text" }, item.text)
|
|
1583
|
+
);
|
|
1584
|
+
})
|
|
1585
|
+
)
|
|
1586
|
+
: null,
|
|
1587
|
+
h(
|
|
1588
|
+
"div",
|
|
1589
|
+
{ className: "hp-sub" },
|
|
1590
|
+
h("h3", null, t.snippetNew + (custom.length ? " (" + custom.length + ")" : "")),
|
|
1591
|
+
custom.map(function (item, index) {
|
|
1592
|
+
return h(
|
|
1593
|
+
"div",
|
|
1594
|
+
{ key: "custom-" + index, className: "hp-custom" },
|
|
1595
|
+
h(
|
|
1596
|
+
"div",
|
|
1597
|
+
{ className: "hp-custom-row" },
|
|
1598
|
+
h("input", {
|
|
1599
|
+
className: "hp-input hp-input-sm",
|
|
1600
|
+
type: "text",
|
|
1601
|
+
placeholder: t.snippetLabel,
|
|
1602
|
+
value: item.label || "",
|
|
1603
|
+
onChange: function (e) {
|
|
1604
|
+
editCustom(index, { label: e.target.value });
|
|
1605
|
+
}
|
|
1606
|
+
}),
|
|
1607
|
+
h(Toggle, {
|
|
1608
|
+
label: t.hot,
|
|
1609
|
+
on: Boolean(item.hot),
|
|
1610
|
+
onChange: function (next) {
|
|
1611
|
+
editCustom(index, { hot: next });
|
|
1612
|
+
}
|
|
1613
|
+
}),
|
|
1614
|
+
kind === "term"
|
|
1615
|
+
? h(Toggle, {
|
|
1616
|
+
label: t.snippetRun,
|
|
1617
|
+
on: item.run !== false,
|
|
1618
|
+
onChange: function (next) {
|
|
1619
|
+
editCustom(index, { run: next });
|
|
1620
|
+
}
|
|
1621
|
+
})
|
|
1622
|
+
: null,
|
|
1623
|
+
h(
|
|
1624
|
+
"button",
|
|
1625
|
+
{
|
|
1626
|
+
type: "button",
|
|
1627
|
+
className: "hp-btn hp-btn-sm",
|
|
1628
|
+
onClick: function () {
|
|
1629
|
+
setCustom(
|
|
1630
|
+
custom.filter(function (_, i) {
|
|
1631
|
+
return i !== index;
|
|
1632
|
+
})
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
},
|
|
1636
|
+
t.remove
|
|
1637
|
+
)
|
|
1638
|
+
),
|
|
1639
|
+
h("textarea", {
|
|
1640
|
+
className: "hp-input hp-textarea",
|
|
1641
|
+
rows: 2,
|
|
1642
|
+
value: item.text || "",
|
|
1643
|
+
placeholder: t.snippetText,
|
|
1644
|
+
onChange: function (e) {
|
|
1645
|
+
editCustom(index, { text: e.target.value });
|
|
1646
|
+
}
|
|
1647
|
+
})
|
|
1648
|
+
);
|
|
1649
|
+
}),
|
|
1650
|
+
h(
|
|
1651
|
+
"button",
|
|
1652
|
+
{
|
|
1653
|
+
type: "button",
|
|
1654
|
+
className: "hp-btn hp-btn-sm",
|
|
1655
|
+
onClick: function () {
|
|
1656
|
+
setCustom(
|
|
1657
|
+
custom.concat([
|
|
1658
|
+
{
|
|
1659
|
+
id: "c-" + Math.random().toString(36).slice(2, 6),
|
|
1660
|
+
label: "",
|
|
1661
|
+
text: "",
|
|
1662
|
+
hot: false,
|
|
1663
|
+
run: true
|
|
1664
|
+
}
|
|
1665
|
+
])
|
|
1666
|
+
);
|
|
1667
|
+
}
|
|
1668
|
+
},
|
|
1669
|
+
t.snippetNew
|
|
1670
|
+
)
|
|
1671
|
+
),
|
|
1672
|
+
h(
|
|
1673
|
+
"div",
|
|
1674
|
+
{ className: "hp-actions" },
|
|
1675
|
+
h(
|
|
1676
|
+
"button",
|
|
1677
|
+
{
|
|
1678
|
+
type: "button",
|
|
1679
|
+
className: "hp-btn hp-btn-primary",
|
|
1680
|
+
disabled: Boolean(busy),
|
|
1681
|
+
onClick: function () {
|
|
1682
|
+
save({ custom: custom, overrides: overrides }, t.saved);
|
|
1683
|
+
}
|
|
1684
|
+
},
|
|
1685
|
+
busy === "save" ? t.saving : t.saveSnippets
|
|
1686
|
+
),
|
|
1687
|
+
h(
|
|
1688
|
+
"button",
|
|
1689
|
+
{
|
|
1690
|
+
type: "button",
|
|
1691
|
+
className: "hp-btn" + (armed ? " hp-btn-warn" : ""),
|
|
1692
|
+
disabled: Boolean(busy),
|
|
1693
|
+
onClick: resetNow
|
|
1694
|
+
},
|
|
1695
|
+
armed ? t.resetArmed : t.resetSnippets
|
|
1696
|
+
),
|
|
1697
|
+
note ? h("span", { className: "hp-note" }, note) : null
|
|
1698
|
+
)
|
|
1699
|
+
);
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
// --------------------------------------------------------------------- logs
|
|
1703
|
+
|
|
1704
|
+
var LOG_FILES = ["gateway", "errors", "pilot", "audit"];
|
|
1705
|
+
|
|
1706
|
+
function LogsSection(props) {
|
|
1707
|
+
var t = props.t;
|
|
1708
|
+
var nameState = useState("gateway");
|
|
1709
|
+
var name = nameState[0];
|
|
1710
|
+
var setName = nameState[1];
|
|
1711
|
+
var linesState = useState(120);
|
|
1712
|
+
var lines = linesState[0];
|
|
1713
|
+
var setLines = linesState[1];
|
|
1714
|
+
var dataState = useState(null);
|
|
1715
|
+
var data = dataState[0];
|
|
1716
|
+
var setData = dataState[1];
|
|
1717
|
+
var busyState = useState(false);
|
|
1718
|
+
var busy = busyState[0];
|
|
1719
|
+
var setBusy = busyState[1];
|
|
1720
|
+
var errState = useState(null);
|
|
1721
|
+
var err = errState[0];
|
|
1722
|
+
var setErr = errState[1];
|
|
1723
|
+
// Audit card: newest 8 rows, the rest behind one accordion (SPEC V3 §3.5).
|
|
1724
|
+
var expandedState = useState(false);
|
|
1725
|
+
var expanded = expandedState[0];
|
|
1726
|
+
var setExpanded = expandedState[1];
|
|
1727
|
+
var rawState = useState(false);
|
|
1728
|
+
var rawView = rawState[0];
|
|
1729
|
+
var setRawView = rawState[1];
|
|
1730
|
+
|
|
1731
|
+
var load = useCallback(
|
|
1732
|
+
function () {
|
|
1733
|
+
setBusy(true);
|
|
1734
|
+
return request("/logs?file=" + name + "&lines=" + lines)
|
|
1735
|
+
.then(function (res) {
|
|
1736
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
1737
|
+
setData(res.body);
|
|
1738
|
+
setErr(null);
|
|
1739
|
+
} else {
|
|
1740
|
+
setErr(reasonOf(res, t.failed));
|
|
1741
|
+
}
|
|
1742
|
+
setBusy(false);
|
|
1743
|
+
})
|
|
1744
|
+
.catch(function (e) {
|
|
1745
|
+
setErr(String((e && e.message) || e));
|
|
1746
|
+
setBusy(false);
|
|
1747
|
+
});
|
|
1748
|
+
},
|
|
1749
|
+
[name, lines]
|
|
1750
|
+
);
|
|
1751
|
+
|
|
1752
|
+
useEffect(
|
|
1753
|
+
function () {
|
|
1754
|
+
load();
|
|
1755
|
+
},
|
|
1756
|
+
[load]
|
|
1757
|
+
);
|
|
1758
|
+
|
|
1759
|
+
// Switching files starts collapsed again, so the card never grows silently.
|
|
1760
|
+
useEffect(
|
|
1761
|
+
function () {
|
|
1762
|
+
setExpanded(false);
|
|
1763
|
+
setRawView(false);
|
|
1764
|
+
},
|
|
1765
|
+
[name, lines]
|
|
1766
|
+
);
|
|
1767
|
+
|
|
1768
|
+
var labels = { gateway: t.logGateway, errors: t.logErrors, pilot: t.logPilot, audit: t.logAudit };
|
|
1769
|
+
var body = (data && data.lines) || [];
|
|
1770
|
+
var text = body.length ? body.join("\n") : data && data.missing ? t.logMissing : t.logEmpty;
|
|
1771
|
+
var isAudit = name === "audit";
|
|
1772
|
+
// Older backends only send `lines`; parse them here so both shapes render.
|
|
1773
|
+
var auditEntries = isAudit ? (Array.isArray(data && data.entries) ? data.entries : parseAuditLines(body)) : [];
|
|
1774
|
+
var auditHead = auditEntries.slice(0, AUDIT_VISIBLE);
|
|
1775
|
+
var auditRest = auditEntries.slice(AUDIT_VISIBLE);
|
|
1776
|
+
var auditShown = expanded ? auditEntries : auditHead;
|
|
1777
|
+
|
|
1778
|
+
return h(
|
|
1779
|
+
Card,
|
|
1780
|
+
{ id: "hp-sec-logs", title: t.logsTitle, hint: t.logsLead },
|
|
1781
|
+
err ? h("p", { className: "hp-error" }, err) : null,
|
|
1782
|
+
h(
|
|
1783
|
+
"div",
|
|
1784
|
+
{ className: "hp-actions" },
|
|
1785
|
+
LOG_FILES.map(function (value) {
|
|
1786
|
+
return h(
|
|
1787
|
+
"button",
|
|
1788
|
+
{
|
|
1789
|
+
key: "log-" + value,
|
|
1790
|
+
type: "button",
|
|
1791
|
+
className: "hp-tab" + (name === value ? " hp-tab-active" : ""),
|
|
1792
|
+
onClick: function () {
|
|
1793
|
+
setName(value);
|
|
1794
|
+
}
|
|
1795
|
+
},
|
|
1796
|
+
labels[value]
|
|
1797
|
+
);
|
|
1798
|
+
}),
|
|
1799
|
+
h(
|
|
1800
|
+
"select",
|
|
1801
|
+
{
|
|
1802
|
+
className: "hp-select",
|
|
1803
|
+
value: String(lines),
|
|
1804
|
+
onChange: function (e) {
|
|
1805
|
+
setLines(Number(e.target.value));
|
|
1806
|
+
}
|
|
1807
|
+
},
|
|
1808
|
+
[60, 120, 300].map(function (n) {
|
|
1809
|
+
return h("option", { key: "n" + n, value: String(n) }, String(n));
|
|
1810
|
+
})
|
|
1811
|
+
),
|
|
1812
|
+
h(
|
|
1813
|
+
"button",
|
|
1814
|
+
{ type: "button", className: "hp-btn hp-btn-sm", onClick: load, disabled: busy },
|
|
1815
|
+
t.refresh
|
|
1816
|
+
)
|
|
1817
|
+
),
|
|
1818
|
+
h("p", { className: "hp-hint hp-log-meta" }, (data && data.path) || "", data ? " · " + body.length : ""),
|
|
1819
|
+
isAudit
|
|
1820
|
+
? h(
|
|
1821
|
+
"div",
|
|
1822
|
+
{ className: "hp-audit-toggle" },
|
|
1823
|
+
h(
|
|
1824
|
+
"button",
|
|
1825
|
+
{
|
|
1826
|
+
type: "button",
|
|
1827
|
+
className: "hp-tab" + (rawView ? "" : " hp-tab-active"),
|
|
1828
|
+
"aria-pressed": !rawView,
|
|
1829
|
+
onClick: function () {
|
|
1830
|
+
setRawView(false);
|
|
1831
|
+
}
|
|
1832
|
+
},
|
|
1833
|
+
t.auditList
|
|
1834
|
+
),
|
|
1835
|
+
h(
|
|
1836
|
+
"button",
|
|
1837
|
+
{
|
|
1838
|
+
type: "button",
|
|
1839
|
+
className: "hp-tab" + (rawView ? " hp-tab-active" : ""),
|
|
1840
|
+
"aria-pressed": rawView,
|
|
1841
|
+
onClick: function () {
|
|
1842
|
+
setRawView(true);
|
|
1843
|
+
}
|
|
1844
|
+
},
|
|
1845
|
+
t.auditRaw
|
|
1846
|
+
)
|
|
1847
|
+
)
|
|
1848
|
+
: null,
|
|
1849
|
+
isAudit && !rawView
|
|
1850
|
+
? auditShown.length
|
|
1851
|
+
? h(
|
|
1852
|
+
"ul",
|
|
1853
|
+
{ className: "hp-audit" },
|
|
1854
|
+
auditShown.map(function (entry, i) {
|
|
1855
|
+
var tone = entry.ok === false ? " hp-audit-bad" : entry.ok === true ? " hp-audit-ok" : "";
|
|
1856
|
+
return h(
|
|
1857
|
+
"li",
|
|
1858
|
+
{ key: "audit-" + i, className: "hp-audit-row" + tone },
|
|
1859
|
+
h(
|
|
1860
|
+
"div",
|
|
1861
|
+
{ className: "hp-audit-head" },
|
|
1862
|
+
h("span", { className: "hp-audit-kind" }, entry.kind || "—"),
|
|
1863
|
+
h("span", { className: "hp-audit-at" }, shortTime(entry.at))
|
|
1864
|
+
),
|
|
1865
|
+
entry.detail ? h("p", { className: "hp-audit-detail" }, entry.detail) : null
|
|
1866
|
+
);
|
|
1867
|
+
})
|
|
1868
|
+
)
|
|
1869
|
+
: h("p", { className: "hp-hint" }, data && data.missing ? t.logMissing : t.auditEmpty)
|
|
1870
|
+
: h("pre", { className: "hp-log" }, text),
|
|
1871
|
+
isAudit && !rawView && auditRest.length
|
|
1872
|
+
? h(
|
|
1873
|
+
"button",
|
|
1874
|
+
{
|
|
1875
|
+
type: "button",
|
|
1876
|
+
className: "hp-btn hp-btn-sm hp-audit-more",
|
|
1877
|
+
"aria-expanded": expanded,
|
|
1878
|
+
onClick: function () {
|
|
1879
|
+
setExpanded(!expanded);
|
|
1880
|
+
}
|
|
1881
|
+
},
|
|
1882
|
+
expanded ? t.auditCollapse : t.auditShowMore.replace("{n}", String(auditRest.length))
|
|
1883
|
+
)
|
|
1884
|
+
: null
|
|
1885
|
+
);
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
// ------------------------------------------------------------------ root
|
|
1889
|
+
|
|
1890
|
+
function App() {
|
|
1891
|
+
// uiLang: an explicit choice in this browser wins; otherwise config.json's ja,
|
|
1892
|
+
// otherwise the browser language (SPEC V3 §3.5 / D5).
|
|
1893
|
+
var storedLang = readStoredLang();
|
|
1894
|
+
var langState = useState(storedLang || detectLang());
|
|
1895
|
+
var lang = langState[0];
|
|
1896
|
+
var setLang = langState[1];
|
|
1897
|
+
// What the Settings select shows: the explicit choice, or `auto`.
|
|
1898
|
+
var choiceState = useState(storedLang || "auto");
|
|
1899
|
+
var langChoice = choiceState[0];
|
|
1900
|
+
var setLangChoice = choiceState[1];
|
|
1901
|
+
var hasLocalPref = useRef(Boolean(storedLang));
|
|
1902
|
+
var t = STRINGS[lang] || STRINGS.en;
|
|
1903
|
+
var statusState = useState(null);
|
|
1904
|
+
var status = statusState[0];
|
|
1905
|
+
var setStatus = statusState[1];
|
|
1906
|
+
var errState = useState(null);
|
|
1907
|
+
var err = errState[0];
|
|
1908
|
+
var setErr = errState[1];
|
|
1909
|
+
// Bumped when Settings saves, so the Repositories card re-reads scanDirs.
|
|
1910
|
+
var tickState = useState(0);
|
|
1911
|
+
var tick = tickState[0];
|
|
1912
|
+
var setTick = tickState[1];
|
|
1913
|
+
|
|
1914
|
+
function bump() {
|
|
1915
|
+
setTick(function (n) {
|
|
1916
|
+
return n + 1;
|
|
1917
|
+
});
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
/**
|
|
1921
|
+
* `en` / `ja` apply at once and persist to config.json; `auto` forgets the
|
|
1922
|
+
* local choice and falls back to config + browser (that is what the Settings
|
|
1923
|
+
* select's third option means, and it is never written to config.json).
|
|
1924
|
+
*/
|
|
1925
|
+
var changeLang = useCallback(function (next) {
|
|
1926
|
+
if (next === "auto") {
|
|
1927
|
+
writeStoredLang(null);
|
|
1928
|
+
hasLocalPref.current = false;
|
|
1929
|
+
setLangChoice("auto");
|
|
1930
|
+
setLang(detectLang());
|
|
1931
|
+
saveLang("auto");
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1934
|
+
if (next !== "en" && next !== "ja") return;
|
|
1935
|
+
writeStoredLang(next);
|
|
1936
|
+
hasLocalPref.current = true;
|
|
1937
|
+
setLangChoice(next);
|
|
1938
|
+
setLang(next);
|
|
1939
|
+
saveLang(next);
|
|
1940
|
+
}, []);
|
|
1941
|
+
|
|
1942
|
+
// Follow config.json on first load, unless this browser already chose.
|
|
1943
|
+
useEffect(function () {
|
|
1944
|
+
request("/config")
|
|
1945
|
+
.then(function (res) {
|
|
1946
|
+
if (!(res.status === 200 && res.body && res.body.ok)) return;
|
|
1947
|
+
if (hasLocalPref.current) return;
|
|
1948
|
+
var cfg = res.body.config || {};
|
|
1949
|
+
// `ja` in config.json is a deliberate choice elsewhere, so mirror it in
|
|
1950
|
+
// the select; `en` is also the init default and stays `auto`.
|
|
1951
|
+
setLangChoice(cfg.lang === "ja" ? "ja" : "auto");
|
|
1952
|
+
var next = pickLang(null, cfg.lang, detectLang());
|
|
1953
|
+
setLang(function (prev) {
|
|
1954
|
+
return next === prev ? prev : next;
|
|
1955
|
+
});
|
|
1956
|
+
})
|
|
1957
|
+
.catch(function () {
|
|
1958
|
+
/* the status card already reports an unreachable backend */
|
|
1959
|
+
});
|
|
1960
|
+
}, []);
|
|
1961
|
+
|
|
1962
|
+
var load = useCallback(function () {
|
|
1963
|
+
return request("/status")
|
|
1964
|
+
.then(function (res) {
|
|
1965
|
+
if (res.status === 200 && res.body && res.body.ok) {
|
|
1966
|
+
setStatus(res.body);
|
|
1967
|
+
setErr(null);
|
|
1968
|
+
} else {
|
|
1969
|
+
setErr(reasonOf(res, t.failed));
|
|
1970
|
+
}
|
|
1971
|
+
})
|
|
1972
|
+
.catch(function (e) {
|
|
1973
|
+
setErr(String((e && e.message) || e));
|
|
1974
|
+
});
|
|
1975
|
+
}, []);
|
|
1976
|
+
|
|
1977
|
+
useEffect(function () {
|
|
1978
|
+
load();
|
|
1979
|
+
}, [load]);
|
|
1980
|
+
|
|
1981
|
+
return h(
|
|
1982
|
+
"div",
|
|
1983
|
+
{ className: "hp-root" },
|
|
1984
|
+
h(
|
|
1985
|
+
"div",
|
|
1986
|
+
{ className: "hp-header" },
|
|
1987
|
+
h("div", { className: "hp-heading" }, h("h1", null, t.title), h("p", null, t.lead)),
|
|
1988
|
+
h(
|
|
1989
|
+
"div",
|
|
1990
|
+
{ className: "hp-head-actions" },
|
|
1991
|
+
h(LangSwitch, { t: t, lang: lang, onChange: changeLang }),
|
|
1992
|
+
h(
|
|
1993
|
+
"button",
|
|
1994
|
+
{ type: "button", className: "hp-btn", onClick: load },
|
|
1995
|
+
t.refresh
|
|
1996
|
+
)
|
|
1997
|
+
)
|
|
1998
|
+
),
|
|
1999
|
+
err ? h("p", { className: "hp-error" }, t.failed + ": " + err) : null,
|
|
2000
|
+
h(StatusBar, { t: t, status: status }),
|
|
2001
|
+
h(SectionNav, { t: t }),
|
|
2002
|
+
h(PairingSection, { t: t }),
|
|
2003
|
+
h(RepositoriesSection, { t: t, tick: tick, onChanged: load }),
|
|
2004
|
+
h(SettingsSection, { t: t, onSaved: bump, onLangChange: changeLang, langChoice: langChoice }),
|
|
2005
|
+
h(SnippetsSection, { t: t, lang: lang, onChanged: load }),
|
|
2006
|
+
h(PipelineSection, { t: t }),
|
|
2007
|
+
h(LogsSection, { t: t }),
|
|
2008
|
+
h(ServiceSection, { t: t, onChanged: load }),
|
|
2009
|
+
h(LinksSection, { t: t, status: status })
|
|
2010
|
+
);
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
window.__HERMES_PLUGINS__.register("hermes-pilot", App);
|
|
2014
|
+
})();
|