herdr-remote 0.2.18 → 0.2.20

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.
Files changed (95) hide show
  1. package/bin/herdr-remote.js +3 -225
  2. package/dist/agent-status.js +130 -0
  3. package/dist/binary-plist.js +157 -0
  4. package/dist/cli.js +255 -0
  5. package/dist/config.js +270 -0
  6. package/dist/connector/agent-watch.js +110 -0
  7. package/dist/connector/font-server.js +165 -0
  8. package/dist/connector/host-connector.js +430 -0
  9. package/dist/connector/lock.js +66 -0
  10. package/dist/connector/main.js +18 -0
  11. package/dist/connector/sessions.js +366 -0
  12. package/dist/connector/update-report.js +67 -0
  13. package/dist/connector/wire.js +42 -0
  14. package/{src → dist}/exit-codes.js +1 -4
  15. package/dist/font-subset.js +110 -0
  16. package/dist/herdr-api.js +246 -0
  17. package/dist/herdr-command.js +223 -0
  18. package/dist/herdr-plugin.js +116 -0
  19. package/dist/herdr-server.js +189 -0
  20. package/dist/i18n/en.js +223 -0
  21. package/dist/i18n/index.js +48 -0
  22. package/dist/i18n/zh.js +222 -0
  23. package/dist/keepalive/detached.js +78 -0
  24. package/dist/keepalive/environment.js +44 -0
  25. package/dist/keepalive/index.js +110 -0
  26. package/dist/keepalive/launchd.js +117 -0
  27. package/dist/keepalive/systemd.js +108 -0
  28. package/dist/keepalive/types.js +1 -0
  29. package/dist/lib/process.js +12 -0
  30. package/dist/lifecycle.js +59 -0
  31. package/dist/net-interfaces.js +73 -0
  32. package/dist/pasted-files.js +115 -0
  33. package/dist/paths.js +62 -0
  34. package/dist/pty-session.js +96 -0
  35. package/dist/relay-client.js +106 -0
  36. package/dist/relay-urls.js +99 -0
  37. package/dist/runtime.js +106 -0
  38. package/dist/service.js +260 -0
  39. package/dist/settings-model.js +298 -0
  40. package/dist/socket-discovery.js +48 -0
  41. package/dist/supervisor.js +319 -0
  42. package/dist/terminal-font/deps.js +73 -0
  43. package/dist/terminal-font/files.js +354 -0
  44. package/dist/terminal-font/formats.js +335 -0
  45. package/dist/terminal-font/index.js +187 -0
  46. package/dist/terminal-font/readers.js +316 -0
  47. package/dist/terminal-font/terminals.js +128 -0
  48. package/dist/terminal-palette.js +339 -0
  49. package/dist/tui/App.js +195 -0
  50. package/dist/tui/api.js +79 -0
  51. package/dist/tui/components/TextField.js +50 -0
  52. package/dist/tui/components/common.js +80 -0
  53. package/dist/tui/index.js +36 -0
  54. package/dist/tui/mouse/index.js +164 -0
  55. package/dist/tui/mouse/protocol.js +96 -0
  56. package/dist/tui/mouse/source.js +74 -0
  57. package/dist/tui/screens/About.js +166 -0
  58. package/dist/tui/screens/Herdr.js +74 -0
  59. package/dist/tui/screens/Keepalive.js +84 -0
  60. package/dist/tui/screens/Overview.js +36 -0
  61. package/dist/tui/screens/Pair.js +74 -0
  62. package/dist/tui/screens/Relay.js +242 -0
  63. package/dist/tui/screens/Services.js +63 -0
  64. package/dist/tui/screens/Wizard.js +235 -0
  65. package/dist/tui/terminal.js +39 -0
  66. package/dist/tui/theme.js +33 -0
  67. package/dist/updater.js +382 -0
  68. package/herdr-plugin.toml +1 -1
  69. package/package.json +8 -8
  70. package/dist/tui.mjs +0 -5775
  71. package/src/agent-status.js +0 -139
  72. package/src/binary-plist.js +0 -146
  73. package/src/config.js +0 -454
  74. package/src/font-subset.js +0 -110
  75. package/src/herdr-api.js +0 -244
  76. package/src/herdr-command.js +0 -231
  77. package/src/herdr-plugin.js +0 -130
  78. package/src/herdr-server.js +0 -201
  79. package/src/host-connector.js +0 -1069
  80. package/src/i18n/en.js +0 -240
  81. package/src/i18n/index.js +0 -56
  82. package/src/i18n/zh.js +0 -239
  83. package/src/keepalive.js +0 -460
  84. package/src/lifecycle.js +0 -62
  85. package/src/net-interfaces.js +0 -76
  86. package/src/pasted-files.js +0 -176
  87. package/src/pty-session.js +0 -92
  88. package/src/service.js +0 -530
  89. package/src/settings-model.js +0 -323
  90. package/src/socket-discovery.js +0 -60
  91. package/src/state.js +0 -47
  92. package/src/supervisor.js +0 -250
  93. package/src/terminal-font.js +0 -1204
  94. package/src/terminal-palette.js +0 -325
  95. package/src/updater.js +0 -394
@@ -0,0 +1,189 @@
1
+ // Whether Herdr's server is running on this workstation, and starting it when
2
+ // the user asked for that.
3
+ //
4
+ // herdr-remote never starts Herdr on its own initiative. It starts one when a
5
+ // browser paired to this workstation asks for it, or at service start when the
6
+ // user switched that on — and both go through here.
7
+ //
8
+ // Two traps shape this file:
9
+ //
10
+ // - A socket file is not a server. Herdr leaves `herdr.sock` behind when it dies
11
+ // without cleaning up (a crash, a power cut), and a `herdr` client pointed at
12
+ // a dead socket quietly starts a server of its own. So "running" means a
13
+ // connection was accepted, not that the path exists.
14
+ // - A server started from inside herdr-remote's systemd service lives in that
15
+ // service's cgroup, and `systemctl restart herdr-remote` — an update, a keep-
16
+ // alive restart, Herdr's own plugin startup hook — would kill it along with
17
+ // every agent in it. Under a service it is therefore started in a transient
18
+ // scope of its own, the same place it would live had the user started it
19
+ // from a terminal.
20
+ import fs from 'node:fs';
21
+ import net from 'node:net';
22
+ import path from 'node:path';
23
+ import { spawn } from 'node:child_process';
24
+ import { inspectSocket } from './socket-discovery.js';
25
+ import { ensureDir } from 'herdr-remote-relay/state';
26
+ /** A Unix socket either accepts at once or is dead; this only guards a hang. */
27
+ const PROBE_TIMEOUT_MS = 1_000;
28
+ /** Herdr restores the saved session before its API socket opens. */
29
+ const START_TIMEOUT_MS = 20_000;
30
+ const START_POLL_MS = 200;
31
+ /**
32
+ * Is Herdr's server answering on `socketPath`?
33
+ *
34
+ * Resolves `{ state }`: `running`, `stopped` (no socket, or a socket nothing is
35
+ * listening on), or `unavailable` with a `reason` — a path that is not a socket
36
+ * or belongs to another user. That last one is never "stopped": the socket may
37
+ * well be live, just not ours to use, and starting a second server beside it
38
+ * would be starting somebody else's Herdr.
39
+ */
40
+ function probeHerdrServer(socketPath, { connect = net.connect, timeout = PROBE_TIMEOUT_MS } = {}) {
41
+ const info = inspectSocket(socketPath);
42
+ if (!info.ok) {
43
+ return Promise.resolve(info.missing ? { state: 'stopped' } : { state: 'unavailable', reason: info.reason });
44
+ }
45
+ return new Promise((resolve) => {
46
+ let socket;
47
+ const finish = (result) => {
48
+ clearTimeout(timer);
49
+ if (socket) {
50
+ socket.removeAllListeners();
51
+ socket.on('error', () => { });
52
+ socket.destroy();
53
+ }
54
+ resolve(result);
55
+ };
56
+ // A socket that neither accepts nor refuses has a listener behind it that
57
+ // is slow, not absent; starting another server would only fight it.
58
+ const timer = setTimeout(() => finish({ state: 'running' }), timeout);
59
+ if (typeof timer.unref === 'function')
60
+ timer.unref();
61
+ socket = connect(socketPath);
62
+ socket.once('connect', () => finish({ state: 'running' }));
63
+ socket.once('error', (error) => finish(error.code === 'ECONNREFUSED' || error.code === 'ENOENT'
64
+ ? { state: 'stopped', stale: true }
65
+ : { state: 'unavailable', reason: error.message }));
66
+ });
67
+ }
68
+ /**
69
+ * True when this process is a systemd service (herdr-remote's keep-alive), so
70
+ * anything it starts would be killed with it.
71
+ */
72
+ function runningInSystemdService({ platform = process.platform, readCgroup = () => fs.readFileSync('/proc/self/cgroup', 'utf8'), } = {}) {
73
+ if (platform !== 'linux')
74
+ return false;
75
+ try {
76
+ const unified = readCgroup()
77
+ .split('\n')
78
+ .find((line) => line.startsWith('0::'));
79
+ return unified !== undefined && /\.service$/.test(unified.trim());
80
+ }
81
+ catch {
82
+ return false;
83
+ }
84
+ }
85
+ /** The server's environment: the one a Herdr pane would give its client. */
86
+ function serverEnv(socketPath, env = process.env) {
87
+ const next = { ...env };
88
+ for (const key of Object.keys(next)) {
89
+ if (key.startsWith('HERDR_'))
90
+ delete next[key];
91
+ }
92
+ if (socketPath)
93
+ next.HERDR_SOCKET_PATH = socketPath;
94
+ return next;
95
+ }
96
+ /**
97
+ * The argv that starts Herdr's server: Herdr's own global arguments (a
98
+ * `--session`, say) followed by `server`, wrapped in `systemd-run --scope` when
99
+ * the caller is a systemd service.
100
+ */
101
+ function serverCommand({ command, args = [], inService = runningInSystemdService(), }) {
102
+ const herdr = [command, ...args, 'server'];
103
+ if (!inService)
104
+ return { file: herdr[0], args: herdr.slice(1) };
105
+ return {
106
+ file: 'systemd-run',
107
+ args: [
108
+ '--user',
109
+ '--scope',
110
+ '--quiet',
111
+ '--collect',
112
+ '--description=Herdr server started by herdr-remote',
113
+ '--',
114
+ ...herdr,
115
+ ],
116
+ };
117
+ }
118
+ /**
119
+ * Start Herdr's server in the background. Detached from this process, with its
120
+ * output appended to `logPath` rather than piped here: a pipe would break the
121
+ * moment herdr-remote exits and take the server with it.
122
+ */
123
+ function launchHerdrServer({ command, args = [], socketPath, cwd, logPath, spawnProcess = spawn, inService, }) {
124
+ const { file, args: argv } = serverCommand({ command, args, inService });
125
+ ensureDir(path.dirname(logPath));
126
+ const out = fs.openSync(logPath, 'a');
127
+ let child;
128
+ try {
129
+ child = spawnProcess(file, argv, {
130
+ cwd,
131
+ env: serverEnv(socketPath),
132
+ detached: true,
133
+ stdio: ['ignore', out, out],
134
+ });
135
+ }
136
+ finally {
137
+ fs.closeSync(out);
138
+ }
139
+ child.on('error', () => { });
140
+ child.unref();
141
+ return child;
142
+ }
143
+ function readLogTail(logPath, bytes = 2_000) {
144
+ try {
145
+ const text = fs.readFileSync(logPath, 'utf8');
146
+ return text.slice(-bytes).trim();
147
+ }
148
+ catch {
149
+ return '';
150
+ }
151
+ }
152
+ /**
153
+ * Make sure Herdr's server is running, starting it if it is not.
154
+ *
155
+ * Resolves `{ started }`, or rejects with a message that says what happened:
156
+ * the socket belongs to someone else, the server exited, or it never opened
157
+ * its socket. The last lines Herdr printed ride along, because "did not start"
158
+ * with no reason is a message nobody can act on.
159
+ */
160
+ async function ensureHerdrServer({ command, args = [], socketPath, cwd, logPath, probe = probeHerdrServer, launch = launchHerdrServer, timeout = START_TIMEOUT_MS, interval = START_POLL_MS, }) {
161
+ const before = await probe(socketPath);
162
+ if (before.state === 'running')
163
+ return { started: false };
164
+ if (before.state === 'unavailable') {
165
+ throw new Error(`Herdr socket at ${socketPath} cannot be used: ${before.reason}`);
166
+ }
167
+ const child = launch({ command, args, socketPath, cwd, logPath });
168
+ // Assigned by the listener; `as` keeps TypeScript from assuming it stays null.
169
+ let exit = null;
170
+ child.once('exit', (code, signal) => {
171
+ exit = { code, signal };
172
+ });
173
+ const deadline = Date.now() + timeout;
174
+ for (;;) {
175
+ await new Promise((resolve) => setTimeout(resolve, interval));
176
+ const now = await probe(socketPath);
177
+ if (now.state === 'running')
178
+ return { started: true };
179
+ const tail = readLogTail(logPath);
180
+ const detail = tail ? `\n${tail}` : '';
181
+ if (exit) {
182
+ throw new Error(`Herdr server exited (${exit.signal || `code ${exit.code}`}) before opening ${socketPath}.${detail}`);
183
+ }
184
+ if (Date.now() >= deadline) {
185
+ throw new Error(`Herdr server did not open ${socketPath} within ${Math.round(timeout / 1000)}s.${detail}`);
186
+ }
187
+ }
188
+ }
189
+ export { probeHerdrServer, runningInSystemdService, serverEnv, serverCommand, ensureHerdrServer };
@@ -0,0 +1,223 @@
1
+ // English message catalogue. This file is the reference: zh.ts must define
2
+ // exactly the same keys, which its type and tests/i18n.test.js enforce.
3
+ const en = {
4
+ 'app.name': 'Herdr Remote',
5
+ 'app.tagline': 'Remote browser access to Herdr workspaces',
6
+ 'common.yes': 'Yes',
7
+ 'common.no': 'No',
8
+ 'common.on': 'on',
9
+ 'common.off': 'off',
10
+ 'common.none': 'none',
11
+ 'common.auto': 'auto',
12
+ 'common.unknown': 'unknown',
13
+ 'common.running': 'running',
14
+ 'common.stopped': 'stopped',
15
+ 'common.connected': 'connected',
16
+ 'common.disconnected': 'disconnected',
17
+ 'common.installed': 'installed',
18
+ 'common.notInstalled': 'not installed',
19
+ 'common.enabled': 'enabled',
20
+ 'common.disabled': 'disabled',
21
+ 'common.loading': 'Working…',
22
+ 'common.save': 'Save settings',
23
+ 'common.saved': 'Configuration saved to {path}',
24
+ 'common.back': 'Back',
25
+ 'common.cancel': 'Cancel',
26
+ 'common.confirm': 'Confirm',
27
+ 'common.pid': 'pid {pid}',
28
+ 'common.notApplicable': 'n/a',
29
+ 'nav.overview': 'Overview',
30
+ 'nav.pair': 'Pair a device',
31
+ 'nav.services': 'Services',
32
+ 'nav.relay': 'Relay',
33
+ 'nav.keepalive': 'Keep-alive',
34
+ 'nav.herdr': 'Herdr',
35
+ 'nav.about': 'Language & about',
36
+ 'mode.local': 'This machine only',
37
+ 'mode.lan': 'Local network / Tailscale',
38
+ 'mode.official': 'Official relay',
39
+ 'mode.remote': 'Self-hosted relay',
40
+ 'mode.local.description': 'Relay listens on 127.0.0.1. Local browser only.',
41
+ 'mode.lan.description': 'Relay listens on 0.0.0.0. Accessible over LAN or Tailscale.',
42
+ 'mode.official.description': 'Connect via official relay. No server needed.',
43
+ 'mode.remote.description': 'Connect via self-hosted relay for external access.',
44
+ 'overview.title': 'Status',
45
+ 'overview.mode': 'Access mode',
46
+ 'overview.relay': 'Relay',
47
+ 'overview.host': 'Host connector',
48
+ 'overview.socket': 'Herdr socket',
49
+ 'overview.webUrl': 'Web UI',
50
+ 'overview.keepalive': 'Keep-alive',
51
+ 'overview.devices': 'Browsers',
52
+ 'overview.hosts': 'Workstations',
53
+ 'overview.uptime': 'Relay uptime',
54
+ 'overview.relayLocal': 'local, {bind}:{port}',
55
+ 'overview.relayRemote': 'remote, {url}',
56
+ 'overview.socketMissing': 'not found — is Herdr running?',
57
+ 'overview.unreachable': 'unreachable: {message}',
58
+ 'overview.notStarted': 'Services not running. Open Services tab to start.',
59
+ 'pair.title': 'Pair a device',
60
+ 'pair.generate': 'Generate pairing code',
61
+ 'pair.regenerate': 'Regenerate code',
62
+ 'pair.working': 'Generating pairing code…',
63
+ 'pair.code': 'Pairing code',
64
+ 'pair.url': 'Access URL',
65
+ 'pair.expires': 'Expires in {minutes} (at {time})',
66
+ 'pair.expired': 'Code expired. Generate a new one.',
67
+ 'pair.instructions': 'Open URL and enter code to pair.',
68
+ 'pair.qrHint': 'Scan QR code to open URL.',
69
+ 'pair.qrUnavailable': 'Terminal too narrow for QR code; use URL above.',
70
+ 'pair.failed': 'Could not create pairing code: {message}',
71
+ 'pair.hostOffline': 'Relay has no workstation connected. Start services first.',
72
+ 'services.title': 'Services',
73
+ 'services.start': 'Start services',
74
+ 'services.stop': 'Stop services',
75
+ 'services.restart': 'Restart services',
76
+ 'services.started': 'Services started.',
77
+ 'services.stopped': 'Services stopped.',
78
+ 'services.restarted': 'Services restarted.',
79
+ 'services.startFailed': 'Could not start services: {message}',
80
+ 'services.stopFailed': 'Could not stop services: {message}',
81
+ 'services.unsavedBlocked': 'Unsaved changes. Save before restarting.',
82
+ 'services.managedNotice': 'Managed by {manager}; applied via keep-alive service.',
83
+ 'services.logs': 'Recent logs',
84
+ 'services.logEmpty': 'No logs.',
85
+ 'services.logRelay': 'Relay',
86
+ 'services.logHost': 'Host connector',
87
+ 'relay.title': 'Relay settings',
88
+ 'relay.settings': 'Settings',
89
+ 'relay.locked': 'fixed',
90
+ 'relay.officialFixed': 'The official relay address is fixed and cannot be edited.',
91
+ 'relay.officialHint': 'Official relay: address is fixed and no password is needed.',
92
+ 'relay.password': 'Relay password',
93
+ 'relay.passwordHint': 'Must match RELAY_PASSWORD on relay. Leave empty if public.',
94
+ 'relay.passwordSet': 'set',
95
+ 'relay.passwordEmpty': 'not set (public)',
96
+ 'relay.passwordSaved': 'Relay password saved. Restart services to apply.',
97
+ 'relay.showPassword': 'Show password',
98
+ 'relay.hidePassword': 'Hide password',
99
+ 'relay.identity': 'Workstation ID',
100
+ 'relay.regenerate': 'Generate new ID',
101
+ 'relay.regenerated': 'New workstation identity generated. Restart services to re-register.',
102
+ 'relay.envSnippet': 'Relay startup command',
103
+ 'relay.envHint': 'Run this command on the relay host.',
104
+ 'relay.test': 'Test relay connection',
105
+ 'relay.testOk': 'Relay reachable: version {version}, {hosts} workstation(s) connected.',
106
+ 'relay.testFailed': 'Relay unreachable: {message}',
107
+ 'relay.selectAddress': 'Choose advertised address',
108
+ 'relay.listenAddress': 'Listen address',
109
+ 'relay.listenAddressHint': 'Server bind address. Browsers use advertised address below.',
110
+ 'relay.addressTailscale': 'Tailscale',
111
+ 'relay.addressLan': 'LAN',
112
+ 'relay.addressVirtual': 'virtual',
113
+ 'relay.addressLoopback': 'loopback',
114
+ 'relay.noAddresses': 'No non-loopback addresses found.',
115
+ 'relay.docsHint': 'Self-hosting guide: docs/self-hosted-relay.md',
116
+ 'keepalive.title': 'Keep-alive service',
117
+ 'keepalive.manager': 'Manager',
118
+ 'keepalive.state': 'State',
119
+ 'keepalive.install': 'Install and start',
120
+ 'keepalive.uninstall': 'Stop and remove',
121
+ 'keepalive.restart': 'Restart service',
122
+ 'keepalive.installed': 'Keep-alive installed with {manager}.',
123
+ 'keepalive.uninstalled': 'Keep-alive removed.',
124
+ 'keepalive.restarted': 'Keep-alive service restarted.',
125
+ 'keepalive.failed': 'Keep-alive operation failed: {message}',
126
+ 'keepalive.unitPath': 'Unit file',
127
+ 'keepalive.logsHint': 'View logs: {command}',
128
+ 'keepalive.linger': 'Start at boot',
129
+ 'keepalive.lingerEnabled': 'Start at boot enabled.',
130
+ 'keepalive.lingerDisabled': 'Start at boot disabled (runs while logged in).',
131
+ 'keepalive.enableLinger': 'Enable start at boot',
132
+ 'keepalive.lingerDone': 'Start at boot enabled for {username}.',
133
+ 'keepalive.fallbackNote': 'No system service manager found; background process will not survive reboot.',
134
+ 'herdr.title': 'Herdr integration',
135
+ 'herdr.socketPath': 'Socket path',
136
+ 'herdr.args': 'Extra arguments',
137
+ 'herdr.autoStartHint': 'Off: Herdr starts only when you run it, or when you confirm it from a browser. On: herdr-remote also starts it every time it starts, at boot included. Takes effect the next time herdr-remote starts.',
138
+ 'herdr.cliMissing': 'Command herdr not found. Set HERDR_BIN_PATH to its full path.',
139
+ 'herdr.version': 'Herdr version',
140
+ 'herdr.versionOutdated': 'Herdr {version} is older than {minimum}. Run "herdr update": window titles, background machine activation and large pastes misbehave in browser windows before that release.',
141
+ 'about.title': 'Language & about',
142
+ 'about.language': 'Interface language',
143
+ 'about.languageAuto': 'Follow system ({detected})',
144
+ 'about.languageZh': '中文',
145
+ 'about.languageEn': 'English',
146
+ 'about.version': 'Version',
147
+ 'about.configPath': 'Config file',
148
+ 'about.statePath': 'State directory',
149
+ 'about.relayPackage': 'Relay package',
150
+ 'about.docs': 'Self-hosting guide: docs/self-hosted-relay.md',
151
+ 'wizard.title': 'First-time setup',
152
+ 'wizard.step': 'Step {current} of {total}',
153
+ 'wizard.languageTitle': 'Choose language',
154
+ 'wizard.accessTitle': 'Access mode',
155
+ 'wizard.accessHint': 'Can be changed later in Relay settings.',
156
+ 'wizard.addressTitle': 'Browser access address',
157
+ 'wizard.relayTitle': 'Relay server',
158
+ 'wizard.relayUrlLabel': 'Relay URL (wss://…)',
159
+ 'wizard.relayHint': 'Relay must be running. See docs/self-hosted-relay.md.',
160
+ 'wizard.passwordTitle': 'Relay password',
161
+ 'wizard.passwordHint': 'RELAY_PASSWORD of the relay. Leave empty if unset.',
162
+ 'wizard.finishTitle': 'Finish',
163
+ 'wizard.finishHint': 'Configuration will be saved to {path}.',
164
+ 'wizard.startNow': 'Start services now',
165
+ 'wizard.installKeepalive': 'Run in background',
166
+ 'wizard.finish': 'Save and finish',
167
+ 'field.mode': 'Access mode',
168
+ 'field.port': 'Relay port',
169
+ 'field.lanHost': 'Browser address',
170
+ 'field.remoteUrl': 'Relay URL',
171
+ 'field.publicUrl': 'Browser URL override',
172
+ 'field.socketPath': 'Herdr socket path',
173
+ 'field.herdrArgs': 'Herdr arguments',
174
+ 'field.herdrAutoStart': 'Auto-start Herdr',
175
+ 'field.language': 'Language',
176
+ 'field.keepalive': 'Keep-alive manager',
177
+ 'placeholder.autoDiscovered': 'auto-discovered',
178
+ 'placeholder.none': 'none',
179
+ 'error.invalidMode': 'Unknown access mode.',
180
+ 'error.invalidPort': 'Port must be a number between 1 and 65535.',
181
+ 'error.invalidLanHost': 'Browser address must be a reachable LAN or Tailscale address, not loopback or 0.0.0.0.',
182
+ 'error.invalidRelayUrl': 'Relay URL must start with wss://, ws://, https:// or http://.',
183
+ 'error.invalidPublicUrl': 'Browser URL must start with https:// or http:// and cannot use 0.0.0.0 or ::.',
184
+ 'error.invalidLanguage': 'Unknown language.',
185
+ 'error.invalidKeepalive': 'Unknown keep-alive manager.',
186
+ 'error.unknownField': 'Unknown setting.',
187
+ 'error.remoteUrlRequired': 'Relay URL is required for self-hosted relay mode.',
188
+ 'error.removedHerdrArg': 'Herdr 0.9.0 removed --no-session; remove it from the extra arguments.',
189
+ 'error.saveFailed': 'Could not save configuration: {message}',
190
+ 'hint.navigate': '↑↓ move',
191
+ 'hint.select': '↵ select',
192
+ 'hint.edit': '↵ edit',
193
+ 'hint.tabs': '← → switch tab',
194
+ 'hint.back': 'esc back',
195
+ 'hint.quit': 'q quit',
196
+ 'hint.mouseOn': 'm mouse off',
197
+ 'hint.mouseOff': 'm mouse on',
198
+ 'hint.mouseUnsupported': 'mouse unsupported',
199
+ 'hint.restartRequired': 'Restart services to apply changes.',
200
+ 'hint.unsavedChanges': 'Unsaved changes (press s to save).',
201
+ 'hint.save': 's save',
202
+ 'hint.editing': '↵ confirm · esc cancel',
203
+ 'update.title': 'Updates',
204
+ 'update.banner': 'herdr-remote {latest} is out (running {current}). Press 7 and Enter on the update row to install.',
205
+ 'update.check': 'Check for updates',
206
+ 'update.checking': 'Checking npm…',
207
+ 'update.upToDate': 'Up to date ({version})',
208
+ 'update.available': 'Update {version} available (press Enter to install)',
209
+ 'update.updating': 'Installing {version}…',
210
+ 'update.updatingRetry': 'Installing {version}… (npm has not caught up yet, attempt {attempt})',
211
+ 'update.done': 'Updated to {version}',
212
+ 'update.restartHint': 'Update installed. Restart herdr-remote to apply.',
213
+ 'update.errorNetwork': 'Could not reach any npm registry',
214
+ 'update.errorNetworkDetail': 'No registry answered: {message}',
215
+ 'update.errorFailed': 'Update failed. Run: npm install -g herdr-remote@{version} --prefer-online',
216
+ 'update.errorFailedDetail': 'npm: {message}',
217
+ 'update.errorNotYetPublished': 'npm has not caught up with {version} yet (common in the first minutes after a release). Press Enter to try again shortly.',
218
+ 'update.errorNotApplied': 'npm reported success, but {installed} is still installed',
219
+ 'update.mirrorBehind': '{registries} still has an older version; installing from {source}',
220
+ 'update.cannot.source': 'Source checkout — update with git',
221
+ 'update.cannot.linked': 'Linked package — managed by npm link',
222
+ };
223
+ export default en;
@@ -0,0 +1,48 @@
1
+ import en from './en.js';
2
+ import zh from './zh.js';
3
+ const CATALOGUES = { en, zh };
4
+ const DEFAULT_LOCALE = 'en';
5
+ function isLocale(value) {
6
+ return typeof value === 'string' && Object.hasOwn(CATALOGUES, value);
7
+ }
8
+ /**
9
+ * Work out the interface language from the environment.
10
+ *
11
+ * Order matters: an explicit override wins, then the saved preference, then the
12
+ * POSIX locale variables in the order the C library itself consults them.
13
+ */
14
+ function detectLocale({ env = process.env, preference = 'auto', } = {}) {
15
+ if (preference && preference !== 'auto' && isLocale(preference))
16
+ return preference;
17
+ if (isLocale(env.HERDR_REMOTE_LANG))
18
+ return env.HERDR_REMOTE_LANG;
19
+ const raw = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || '';
20
+ const primary = String(raw).split(/[:.@]/)[0].toLowerCase();
21
+ if (primary.startsWith('zh'))
22
+ return 'zh';
23
+ return DEFAULT_LOCALE;
24
+ }
25
+ function interpolate(template, values) {
26
+ if (!values)
27
+ return template;
28
+ return template.replace(/\{(\w+)\}/g, (match, key) => Object.hasOwn(values, key) ? String(values[key]) : match);
29
+ }
30
+ /**
31
+ * Build a translator for a locale.
32
+ *
33
+ * A missing key falls back to English and finally to the key itself, so a typo
34
+ * shows up as a visible key rather than an empty gap in the layout.
35
+ */
36
+ function createTranslator(locale = DEFAULT_LOCALE) {
37
+ const active = isLocale(locale) ? CATALOGUES[locale] : CATALOGUES[DEFAULT_LOCALE];
38
+ const fallback = CATALOGUES[DEFAULT_LOCALE];
39
+ const t = (key, values) => {
40
+ const template = active[key] ?? fallback[key] ?? key;
41
+ return interpolate(template, values);
42
+ };
43
+ return Object.assign(t, {
44
+ locale,
45
+ has: (key) => Object.hasOwn(active, key),
46
+ });
47
+ }
48
+ export { CATALOGUES, detectLocale, createTranslator, interpolate };