wherdr 1.3.0 → 1.3.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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{BB3uOVbO.js → 8ksjcuDu.js} +51 -41
- package/.output/public/_nuxt/{AgentView.DE2GDt4O.css → AgentView.C4YOwvZG.css} +1 -1
- package/.output/public/_nuxt/B7QP1TFs.js +23 -0
- package/.output/public/_nuxt/{Bta8at9w.js → BOpBIziZ.js} +2 -2
- package/.output/public/_nuxt/BWXdFfeg.js +17 -0
- package/.output/public/_nuxt/COFCNFpG.js +83 -0
- package/.output/public/_nuxt/{C3BWhslt.js → Cd8j9O5w.js} +1 -1
- package/.output/public/_nuxt/CkZ8t6uB.js +1 -0
- package/.output/public/_nuxt/{OAXEskzA.js → D4Yz4rat.js} +4 -4
- package/.output/public/_nuxt/{C3P2P5Mv.js → D7sxNXx1.js} +1 -1
- package/.output/public/_nuxt/DViwOclv.js +1 -0
- package/.output/public/_nuxt/DoD7Qb5P.js +30 -0
- package/.output/public/_nuxt/DyBZDSCV.js +2 -0
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/7afbf062-5369-4002-b20d-7a582ff6e0f1.json +1 -0
- package/.output/public/_nuxt/{entry.SHBiCXBL.css → entry.Crt1r4l3.css} +1 -1
- package/.output/public/_nuxt/hePW80VL.js +1 -0
- package/.output/public/sw.js +1 -1
- package/.output/server/chunks/_/branding.mjs +1 -1
- package/.output/server/chunks/_/package.mjs +96 -0
- package/.output/server/chunks/_/plugins.mjs +11 -3
- package/.output/server/chunks/_/projectBoard.mjs +1 -1
- package/.output/server/chunks/_/projectsPlugin.mjs +1 -1
- package/.output/server/chunks/_/selfupdate.mjs +82 -0
- package/.output/server/chunks/_/updates.mjs +50 -0
- package/.output/server/chunks/_/worktrees.mjs +1 -1
- package/.output/server/chunks/_/ws.mjs +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +1728 -917
- package/.output/server/chunks/raw/bump-homebrew.mjs +7 -0
- package/.output/server/chunks/raw/herdr-plugin.mjs +1 -1
- package/.output/server/chunks/routes/api/_..._.mjs +5 -1
- package/.output/server/chunks/routes/api/agents.post.mjs +5 -1
- package/.output/server/chunks/routes/api/ask-tab.post.mjs +5 -1
- package/.output/server/chunks/routes/api/attach.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/disable.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/lock-all.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/lock.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/login/options.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/login/verify.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/max-session.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/register/options.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/register/verify.post.mjs +5 -1
- package/.output/server/chunks/routes/api/auth/status.get.mjs +5 -1
- package/.output/server/chunks/routes/api/changes.get.mjs +5 -1
- package/.output/server/chunks/routes/api/chat/image.get.mjs +5 -1
- package/.output/server/chunks/routes/api/chat.get.mjs +5 -1
- package/.output/server/chunks/routes/api/choose.post.mjs +5 -1
- package/.output/server/chunks/routes/api/claude-statusline.post.mjs +5 -1
- package/.output/server/chunks/routes/api/close/status.get.mjs +5 -1
- package/.output/server/chunks/routes/api/close.post.mjs +5 -1
- package/.output/server/chunks/routes/api/codex-update.post.mjs +5 -1
- package/.output/server/chunks/routes/api/commands.get.mjs +5 -1
- package/.output/server/chunks/routes/api/config.get.mjs +5 -1
- package/.output/server/chunks/routes/api/dirs.get.mjs +5 -1
- package/.output/server/chunks/routes/api/dismiss.post.mjs +5 -1
- package/.output/server/chunks/routes/api/effort.post.mjs +5 -1
- package/.output/server/chunks/routes/api/efforts.get.mjs +5 -1
- package/.output/server/chunks/routes/api/file.post.mjs +5 -1
- package/.output/server/chunks/routes/api/gitroot.get.mjs +5 -1
- package/.output/server/chunks/routes/api/health.get.mjs +36 -0
- package/.output/server/chunks/routes/api/index.get.mjs +5 -1
- package/.output/server/chunks/routes/api/input.post.mjs +5 -1
- package/.output/server/chunks/routes/api/interrupt.post.mjs +5 -1
- package/.output/server/chunks/routes/api/isgit.get.mjs +5 -1
- package/.output/server/chunks/routes/api/machine/awake.get.mjs +5 -1
- package/.output/server/chunks/routes/api/machine/awake.post.mjs +5 -1
- package/.output/server/chunks/routes/api/machine/order.get.mjs +5 -1
- package/.output/server/chunks/routes/api/machine/order.post.mjs +5 -1
- package/.output/server/chunks/routes/api/machine/rename.post.mjs +5 -1
- package/.output/server/chunks/routes/api/menu.post.mjs +5 -1
- package/.output/server/chunks/routes/api/model.post.mjs +5 -1
- package/.output/server/chunks/routes/api/models.get.mjs +5 -1
- package/.output/server/chunks/routes/api/nav.post.mjs +5 -1
- package/.output/server/chunks/routes/api/onboarding.get.mjs +5 -1
- package/.output/server/chunks/routes/api/onboarding.post.mjs +5 -1
- package/.output/server/chunks/routes/api/phone.get.mjs +5 -6
- package/.output/server/chunks/routes/api/phone.post.mjs +5 -6
- package/.output/server/chunks/routes/api/plugins/actions.get.mjs +5 -1
- package/.output/server/chunks/routes/api/plugins/invoke.post.mjs +5 -1
- package/.output/server/chunks/routes/api/plugins/profiles.get.mjs +5 -1
- package/.output/server/chunks/routes/api/plugins/projects.get.mjs +5 -1
- package/.output/server/chunks/routes/api/plugins/projects.post.mjs +5 -1
- package/.output/server/chunks/routes/api/plugins/thread-limits.get.mjs +6 -2
- package/.output/server/chunks/routes/api/plugins/thread-limits.post.mjs +6 -2
- package/.output/server/chunks/routes/api/project/report.get.mjs +5 -1
- package/.output/server/chunks/routes/api/prompt.post.mjs +6 -2
- package/.output/server/chunks/routes/api/push/quiet.post.mjs +6 -2
- package/.output/server/chunks/routes/api/push/subscribe.post.mjs +6 -2
- package/.output/server/chunks/routes/api/push/test.post.mjs +6 -2
- package/.output/server/chunks/routes/api/push/unsubscribe.post.mjs +6 -2
- package/.output/server/chunks/routes/api/quotas.get.mjs +6 -2
- package/.output/server/chunks/routes/api/rename.post.mjs +5 -1
- package/.output/server/chunks/routes/api/requeue.post.mjs +6 -2
- package/.output/server/chunks/routes/api/restart.get.mjs +5 -1
- package/.output/server/chunks/routes/api/restart.post.mjs +5 -1
- package/.output/server/chunks/routes/api/reveal.post.mjs +5 -1
- package/.output/server/chunks/routes/api/screen-key.post.mjs +6 -2
- package/.output/server/chunks/routes/api/screen.get.mjs +12 -6
- package/.output/server/chunks/routes/api/search.get.mjs +6 -2
- package/.output/server/chunks/routes/api/seen.post.mjs +6 -2
- package/.output/server/chunks/routes/api/sessions.get.mjs +6 -2
- package/.output/server/chunks/routes/api/sessions.post.mjs +6 -2
- package/.output/server/chunks/routes/api/space.post.mjs +6 -2
- package/.output/server/chunks/routes/api/state.get.mjs +6 -2
- package/.output/server/chunks/routes/api/unqueue.post.mjs +6 -2
- package/.output/server/chunks/routes/api/update/status.get.mjs +38 -0
- package/.output/server/chunks/routes/api/update.get.mjs +11 -50
- package/.output/server/chunks/routes/api/update.post.mjs +41 -0
- package/.output/server/chunks/routes/api/upload.post.mjs +5 -1
- package/.output/server/chunks/routes/api/worktrees/remove.post.mjs +5 -1
- package/.output/server/chunks/routes/api/worktrees.get.mjs +5 -1
- package/.output/server/chunks/routes/favicon.ico.get.mjs +5 -1
- package/.output/server/chunks/routes/icons/_name_.get.mjs +6 -2
- package/.output/server/chunks/routes/renderer.mjs +7 -3
- package/.output/server/chunks/routes/uploads/_...name_.get.mjs +6 -2
- package/.output/server/chunks/routes/ws/_..._.mjs +6 -2
- package/.output/server/chunks/routes/ws/events.mjs +6 -2
- package/.output/server/chunks/routes/ws/mirror.mjs +6 -2
- package/.output/server/chunks/routes/ws/term.mjs +8 -4
- package/.output/server/chunks/virtual/precomputed.mjs +1 -1
- package/.output/server/index.mjs +6 -2
- package/.output/server/package.json +1 -1
- package/README.md +216 -45
- package/bin/lib/brew.mjs +86 -0
- package/bin/lib/commands.mjs +74 -16
- package/bin/lib/core.mjs +23 -3
- package/bin/lib/tailnet.d.mts +12 -3
- package/bin/lib/tailnet.mjs +103 -25
- package/bin/lib/updater.mjs +267 -0
- package/package.json +2 -1
- package/.output/public/_nuxt/01adBkx4.js +0 -1
- package/.output/public/_nuxt/BJsf0WRn.js +0 -2
- package/.output/public/_nuxt/BpQH8Ho1.js +0 -1
- package/.output/public/_nuxt/Cc2bsOcu.js +0 -83
- package/.output/public/_nuxt/DKmoLFfn.js +0 -30
- package/.output/public/_nuxt/DLLQgP0d.js +0 -1
- package/.output/public/_nuxt/DcCZr0Ya.js +0 -17
- package/.output/public/_nuxt/DsD2R-37.js +0 -23
- package/.output/public/_nuxt/builds/meta/ff11fc8b-1e70-4261-a76e-a52155efb196.json +0 -1
- package/.output/server/chunks/_/phone.mjs +0 -343
package/bin/lib/commands.mjs
CHANGED
|
@@ -7,10 +7,11 @@ import net from 'node:net'
|
|
|
7
7
|
import os from 'node:os'
|
|
8
8
|
import path from 'node:path'
|
|
9
9
|
import { pathToFileURL } from 'node:url'
|
|
10
|
-
import { BIN, CliError, SERVER, VERSION, bad, c, localUrl, ok, portTaken, probe, row, say, serverEnv, settingsFile, warn, wherdrDir, withSettings } from './core.mjs'
|
|
10
|
+
import { BIN, CliError, SERVER, VERSION, bad, c, homebrewInstall, localUrl, ok, portTaken, probe, row, say, serverEnv, settingsFile, warn, wherdrDir, withSettings } from './core.mjs'
|
|
11
11
|
import { RUNTIME_HELP, findRuntime, isBun, runtimeOk, runtimeVersion, temporaryInstall } from './runtime.mjs'
|
|
12
|
+
import { brewDoctor, brewRedirect, brewService, brewStatusRows } from './brew.mjs'
|
|
12
13
|
import { controlService, installService, serviceFile, servicePlatform, serviceState, uninstallService } from './service.mjs'
|
|
13
|
-
import { LINKS, inspect, reachable } from './tailnet.mjs'
|
|
14
|
+
import { LINKS, inspect, publishCommand, reachable } from './tailnet.mjs'
|
|
14
15
|
|
|
15
16
|
export const HELP = `${'wherdr'}: your Herdr agents from your phone and browser.
|
|
16
17
|
|
|
@@ -139,6 +140,13 @@ export async function run(opts) {
|
|
|
139
140
|
export async function start(opts) {
|
|
140
141
|
needServer()
|
|
141
142
|
const ctx = context(opts)
|
|
143
|
+
const brew = brewService()
|
|
144
|
+
if (brew) {
|
|
145
|
+
const redirect = brewRedirect('start', brew)
|
|
146
|
+
if (redirect) throw new CliError(redirect)
|
|
147
|
+
ok(`wherdr already runs as a Homebrew service: ${c.cyan(ctx.url)}`)
|
|
148
|
+
return
|
|
149
|
+
}
|
|
142
150
|
const svc = serviceState()
|
|
143
151
|
if (svc.installed) {
|
|
144
152
|
if (svc.running && await probe(ctx.port, ctx.host)) { ok(`wherdr already runs as a login service: ${c.cyan(ctx.url)}`); return }
|
|
@@ -187,6 +195,12 @@ async function waitUp(ctx, alive, seconds = 45) {
|
|
|
187
195
|
// ------------------------------------------------------------------ stop
|
|
188
196
|
export async function stop(opts, { quiet = false } = {}) {
|
|
189
197
|
const ctx = context(opts)
|
|
198
|
+
const brew = brewService()
|
|
199
|
+
const redirect = brewRedirect('stop', brew)
|
|
200
|
+
if (redirect) {
|
|
201
|
+
if (quiet) return false
|
|
202
|
+
throw new CliError(redirect)
|
|
203
|
+
}
|
|
190
204
|
const svc = serviceState()
|
|
191
205
|
if (svc.installed && svc.running) {
|
|
192
206
|
controlService('stop')
|
|
@@ -213,6 +227,8 @@ export async function stop(opts, { quiet = false } = {}) {
|
|
|
213
227
|
}
|
|
214
228
|
|
|
215
229
|
export async function restart(opts) {
|
|
230
|
+
const redirect = brewRedirect('restart', brewService())
|
|
231
|
+
if (redirect) throw new CliError(redirect)
|
|
216
232
|
const svc = serviceState()
|
|
217
233
|
if (svc.installed) {
|
|
218
234
|
const ctx = context(opts)
|
|
@@ -231,20 +247,22 @@ export async function status(opts) {
|
|
|
231
247
|
const answer = await probe(ctx.port, ctx.host)
|
|
232
248
|
const pid = livePid(ctx.files.pid)
|
|
233
249
|
const svc = serviceState()
|
|
250
|
+
const brew = brewService()
|
|
251
|
+
const hb = brew && brewStatusRows(brew)
|
|
234
252
|
say(`${c.bold('wherdr')} ${VERSION}`)
|
|
235
253
|
row('Address', answer === 'wherdr' ? `${c.green('●')} ${c.cyan(ctx.url)} answers` : answer ? `${c.yellow('●')} port ${ctx.port} is taken by another program` : `${c.dim('○')} port ${ctx.port} free: not running`)
|
|
236
|
-
row('Process', svc.running ? 'login service' : pid ? `pid ${pid} (wherdr start)` : answer === 'wherdr' ? 'started another way (Docker, plugin, a terminal…)' : 'none')
|
|
237
|
-
row('Service', svc.installed ? `installed (${serviceFile()})${svc.running ? '' : ', not running'}` : 'not installed · wherdr service install')
|
|
254
|
+
row('Process', hb?.process ? hb.process : svc.running ? 'login service' : pid ? `pid ${pid} (wherdr start)` : answer === 'wherdr' ? 'started another way (Docker, plugin, a terminal…)' : 'none')
|
|
255
|
+
row('Service', hb ? hb.service : svc.installed ? `installed (${serviceFile()})${svc.running ? '' : ', not running'}` : 'not installed · wherdr service install')
|
|
238
256
|
row('Data', ctx.env.DATA_DIR)
|
|
239
|
-
row('Log', ctx.files.log)
|
|
257
|
+
row('Log', hb ? hb.log : ctx.files.log)
|
|
240
258
|
if (ctx.env.HERDR_WEB_SESSION) row('Session', ctx.env.HERDR_WEB_SESSION)
|
|
241
|
-
if (!answer) say(c.dim('\n Start it: wherdr start (background) or wherdr (foreground).'))
|
|
259
|
+
if (!answer) say(c.dim(hb ? hb.hint : '\n Start it: wherdr start (background) or wherdr (foreground).'))
|
|
242
260
|
}
|
|
243
261
|
|
|
244
262
|
// ------------------------------------------------------------------ logs
|
|
245
263
|
export async function logs(opts) {
|
|
246
264
|
const ctx = context(opts)
|
|
247
|
-
const log = ctx.files.log
|
|
265
|
+
const log = brewService()?.log ?? ctx.files.log
|
|
248
266
|
if (!existsSync(log)) { say(`No log yet (${log}).`); if (!opts.follow) return }
|
|
249
267
|
const text = tailText(log, Number(opts.lines ?? 50))
|
|
250
268
|
if (text) say(text)
|
|
@@ -271,16 +289,39 @@ export function openUrl(url) {
|
|
|
271
289
|
return r.status === 0
|
|
272
290
|
}
|
|
273
291
|
|
|
292
|
+
// Does the published address answer? 'host' means wherdr answers but does not
|
|
293
|
+
// know that name yet (`tailscale serve` run a moment ago): a local request to
|
|
294
|
+
// /api/phone makes it read Tailscale again and adopt the address
|
|
295
|
+
// (server/utils/phone.ts), then it is asked again. `reach` / `allow` are
|
|
296
|
+
// injectable for the tests.
|
|
297
|
+
export async function phoneReach(localUrl, phoneUrl, { reach = reachable, allow = url => fetch(`${url}/api/phone`).catch(() => {}), timeoutMs = 8000 } = {}) {
|
|
298
|
+
let r = await reach(phoneUrl, timeoutMs)
|
|
299
|
+
if (r === 'host') { await allow(localUrl); r = await reach(phoneUrl, timeoutMs) }
|
|
300
|
+
return r
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// The address to open: the tailnet one when wherdr is already published there
|
|
304
|
+
// and it answers (passkeys are tied to the address they were created on),
|
|
305
|
+
// else the local one.
|
|
306
|
+
export async function openAddress(localUrl, port, { net = inspect, ...probes } = {}) {
|
|
307
|
+
const phone = (await net(port)).phone
|
|
308
|
+
if (!phone?.served) return localUrl
|
|
309
|
+
return await phoneReach(localUrl, phone.url, { timeoutMs: 5000, ...probes }) === 'ok' ? phone.url.replace(/\/$/, '') : localUrl
|
|
310
|
+
}
|
|
311
|
+
|
|
274
312
|
export async function open(opts) {
|
|
275
313
|
const ctx = context(opts)
|
|
276
314
|
if (await probe(ctx.port, ctx.host) !== 'wherdr') warn(`wherdr does not answer on port ${ctx.port}: run \`wherdr start\` first.`)
|
|
277
|
-
|
|
278
|
-
|
|
315
|
+
const url = await openAddress(ctx.url, ctx.port)
|
|
316
|
+
if (openUrl(url)) ok(`opened ${c.cyan(url)}`)
|
|
317
|
+
else say(url)
|
|
279
318
|
}
|
|
280
319
|
|
|
281
320
|
// ----------------------------------------------------------------- phone
|
|
282
321
|
// The phone setup lives in the app (Settings › Phone: publish on the tailnet,
|
|
283
|
-
// live check, APP_URL, QR code). Here: the real state, the
|
|
322
|
+
// live check, APP_URL, QR code). Here: the real state, the command that
|
|
323
|
+
// publishes wherdr when it is not (a server without a screen has no browser
|
|
324
|
+
// for that page; wherdr adopts the address by itself), the link to the page,
|
|
284
325
|
// and the QR code only when the address answers.
|
|
285
326
|
export const phoneSetupUrl = url => `${url}/#/settings?section=phone`
|
|
286
327
|
|
|
@@ -293,6 +334,13 @@ async function qr(text) {
|
|
|
293
334
|
} catch { return null }
|
|
294
335
|
}
|
|
295
336
|
|
|
337
|
+
// Why a published address is not usable yet, for `wherdr phone`.
|
|
338
|
+
export function phoneRefusal(reach, phone, running) {
|
|
339
|
+
if (reach !== 'host') return running ? 'does not answer yet (the HTTPS certificate can take a minute)' : 'wherdr is not running'
|
|
340
|
+
if (phone.funnel) return 'also open to the Internet by `tailscale funnel`, which wherdr never enables: turn the funnel off'
|
|
341
|
+
return 'wherdr refuses it: it could not read `tailscale serve status` itself (is `tailscale` on the PATH of the wherdr server?)'
|
|
342
|
+
}
|
|
343
|
+
|
|
296
344
|
export async function phone(opts) {
|
|
297
345
|
const ctx = context(opts)
|
|
298
346
|
const setup = phoneSetupUrl(ctx.url)
|
|
@@ -305,17 +353,21 @@ export async function phone(opts) {
|
|
|
305
353
|
let reach = null
|
|
306
354
|
if (!net.installed) warn(`Tailscale is not installed: ${c.cyan(LINKS.download)}`)
|
|
307
355
|
else if (!net.connected || !net.phone) warn('Tailscale is not connected on this machine.')
|
|
308
|
-
else if (!net.phone.served)
|
|
309
|
-
|
|
310
|
-
|
|
356
|
+
else if (!net.phone.served) {
|
|
357
|
+
warn(`${c.bold('Not reachable from your phone yet')}: wherdr is not published on your tailnet.`)
|
|
358
|
+
say(` Publish it (private, only your Tailscale devices): ${c.cyan(publishCommand(ctx.port))}`)
|
|
359
|
+
say(' wherdr enables that address by itself; run `wherdr phone` again for its QR code.')
|
|
360
|
+
} else {
|
|
361
|
+
reach = await phoneReach(ctx.url, net.phone.url)
|
|
311
362
|
if (reach === 'ok') ok(`${c.cyan(net.phone.url)} answers`)
|
|
312
|
-
else warn(`${c.bold('Not reachable from your phone yet')}: ${net.phone.url} is published but ${reach === '
|
|
363
|
+
else warn(`${c.bold('Not reachable from your phone yet')}: ${net.phone.url} is published but ${phoneRefusal(reach, net.phone, local === 'wherdr')}.`)
|
|
313
364
|
}
|
|
314
365
|
if (reach === 'ok') {
|
|
315
366
|
const code = await qr(net.phone.url)
|
|
316
367
|
if (code) { say(); say(code.split('\n').map(l => ` ${l}`).join('\n')) }
|
|
317
368
|
say(` ${code ? 'Scan it with the iPhone camera' : `Open ${c.cyan(net.phone.url)} on the iPhone`}, then Share → Add to Home Screen.`)
|
|
318
369
|
say(' In the app: Settings → Enable notifications, then Security → Enable passkey lock.')
|
|
370
|
+
say(` Enable the lock on ${c.cyan(net.phone.url)}, not on localhost: a passkey is tied to its address.`)
|
|
319
371
|
}
|
|
320
372
|
say()
|
|
321
373
|
say(` Set up your phone in the app, on this computer: ${c.cyan(setup)}`)
|
|
@@ -342,6 +394,8 @@ export async function service(opts) {
|
|
|
342
394
|
npm install -g wherdr (or: bun add -g wherdr, pnpm add -g wherdr)
|
|
343
395
|
wherdr service install`)
|
|
344
396
|
}
|
|
397
|
+
// A LaunchAgent pointing into Cellar/wherdr/<version> would break at the next `brew upgrade`.
|
|
398
|
+
if (homebrewInstall(bin)) throw new CliError(brewRedirect('service', {}))
|
|
345
399
|
const runtime = findRuntime(ctx.env)
|
|
346
400
|
if (!runtime) throw new CliError(RUNTIME_HELP)
|
|
347
401
|
// The background server of `wherdr start` would hold the port.
|
|
@@ -409,10 +463,14 @@ export async function doctor(opts) {
|
|
|
409
463
|
const taken = answer ? null : await portTaken(ctx.port, ctx.host)
|
|
410
464
|
if (answer === 'wherdr') ok(`Port ${ctx.port}: wherdr answers (${ctx.url})`)
|
|
411
465
|
else if (answer || taken) fail(`Port ${ctx.port}: ${taken?.error || 'taken by another program'}. Use --port.`)
|
|
412
|
-
else warn(`Port ${ctx.port}: free, wherdr is not running (wherdr start).`)
|
|
466
|
+
else warn(`Port ${ctx.port}: free, wherdr is not running (${homebrewInstall(BIN) ? 'brew services start wherdr' : 'wherdr start'}).`)
|
|
413
467
|
|
|
414
468
|
const svc = serviceState()
|
|
415
|
-
|
|
469
|
+
const brew = brewService()
|
|
470
|
+
if (brew) {
|
|
471
|
+
const [level, text] = brewDoctor(brew)
|
|
472
|
+
;({ ok, warn, fail })[level](text)
|
|
473
|
+
} else if (!servicePlatform()) warn(`Login service: not available on ${process.platform}.`)
|
|
416
474
|
else if (!svc.installed) warn('Login service: not installed (wherdr service install starts wherdr at login).')
|
|
417
475
|
else if (svc.running) ok(`Login service: running (${serviceFile()})`)
|
|
418
476
|
else fail(`Login service: installed but not running (${serviceFile()}). See wherdr logs.`)
|
package/bin/lib/core.mjs
CHANGED
|
@@ -12,6 +12,23 @@ export const BIN = path.join(ROOT, 'bin', 'wherdr.mjs')
|
|
|
12
12
|
export const VERSION = JSON.parse(readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version
|
|
13
13
|
export const DEFAULT_PORT = '7683'
|
|
14
14
|
|
|
15
|
+
// Installed by the Homebrew formula: the package lives in <prefix>/Cellar/wherdr/<version>/libexec.
|
|
16
|
+
export function homebrewInstall(file) {
|
|
17
|
+
return /[\\/]Cellar[\\/]wherdr[\\/]/.test(file)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// How this copy of wherdr was installed (shared/updates.ts InstallMode), from
|
|
21
|
+
// the path of its bin/wherdr.mjs: the Homebrew Cellar; the copy the Herdr
|
|
22
|
+
// plugin keeps in <wherdr dir>/app; `npm i -g` (<prefix>/lib/node_modules/wherdr,
|
|
23
|
+
// never a temporary npx folder); otherwise a temporary package (npx, bunx, pnpm dlx).
|
|
24
|
+
export function installKind(bin, dir) {
|
|
25
|
+
if (homebrewInstall(bin)) return 'brew'
|
|
26
|
+
const root = path.resolve(bin, '..', '..')
|
|
27
|
+
if (root === path.join(dir, 'app')) return 'plugin'
|
|
28
|
+
if (/[\\/]lib[\\/]node_modules[\\/]wherdr$/.test(root) && !/[\\/]_npx[\\/]/.test(root)) return 'npm-global'
|
|
29
|
+
return 'npm'
|
|
30
|
+
}
|
|
31
|
+
|
|
15
32
|
export const COMMANDS = ['run', 'start', 'stop', 'restart', 'status', 'logs', 'open', 'phone', 'panel', 'service', 'doctor', 'help', 'version']
|
|
16
33
|
const VALUE_OPTIONS = { '--port': 'port', '--host': 'host', '--data-dir': 'dataDir', '--session': 'session', '--lines': 'lines', '-n': 'lines' }
|
|
17
34
|
const FLAGS = { '-h': 'help', '--help': 'help', '-v': 'version', '--version': 'version', '-f': 'follow', '--follow': 'follow' }
|
|
@@ -83,7 +100,7 @@ export function withSettings(env, dir) {
|
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
// Environment of the server: options win over the environment, which wins over the defaults.
|
|
86
|
-
export function serverEnv(opts, env, home = os.homedir()) {
|
|
103
|
+
export function serverEnv(opts, env, home = os.homedir(), bin = BIN) {
|
|
87
104
|
const out = { ...env }
|
|
88
105
|
const dir = wherdrDir(env, home)
|
|
89
106
|
out.PORT = opts.port ?? env.PORT ?? DEFAULT_PORT
|
|
@@ -93,8 +110,11 @@ export function serverEnv(opts, env, home = os.homedir()) {
|
|
|
93
110
|
out.NODE_ENV = 'production'
|
|
94
111
|
// Open WebSockets do not hold Ctrl+C for 30 s; clients reconnect on their own.
|
|
95
112
|
out.NITRO_SHUTDOWN_TIMEOUT ??= '1500'
|
|
96
|
-
// Update command offered in the app (shared/updates.ts)
|
|
97
|
-
|
|
113
|
+
// Update command, or one-tap update, offered in the app (shared/updates.ts):
|
|
114
|
+
// the package to replace and the folder of its state and log (server/utils/selfupdate.ts).
|
|
115
|
+
out.WHERDR_INSTALL = installKind(bin, dir)
|
|
116
|
+
out.WHERDR_ROOT = path.resolve(bin, '..', '..')
|
|
117
|
+
out.WHERDR_DIR = dir
|
|
98
118
|
// Nitro reads NITRO_PORT / NITRO_HOST before PORT / HOST.
|
|
99
119
|
delete out.NITRO_PORT
|
|
100
120
|
delete out.NITRO_HOST
|
package/bin/lib/tailnet.d.mts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
// Types of tailnet.mjs, for the server (server/utils/phone.ts).
|
|
2
|
-
|
|
2
|
+
// funnel: also published on the Internet by `tailscale funnel` (never adopted).
|
|
3
|
+
export interface PhoneAddress { url: string, served: boolean, httpsPort: string, funnel?: boolean }
|
|
3
4
|
export interface Tailnet {
|
|
4
5
|
installed: boolean
|
|
5
|
-
bin?: string
|
|
6
|
+
bin?: string | null
|
|
7
|
+
// Tailscale's socket, when the state was read there (no CLI: Docker).
|
|
8
|
+
socket?: string | null
|
|
6
9
|
name?: string | null
|
|
7
10
|
connected?: boolean
|
|
8
11
|
https?: boolean
|
|
9
12
|
phone?: PhoneAddress | null
|
|
10
13
|
taken?: boolean
|
|
14
|
+
// Addresses published for wherdr's port; null when they could not be read.
|
|
15
|
+
served?: string[] | null
|
|
11
16
|
}
|
|
12
17
|
export type Reach = 'ok' | 'host' | 'other' | 'unreachable'
|
|
13
18
|
export type ReachCause = 'dns' | 'refused' | 'timeout' | 'cert' | 'tls' | 'network'
|
|
@@ -15,18 +20,22 @@ export interface Probe { reach: Reach, cause?: ReachCause, status?: number }
|
|
|
15
20
|
export type ServeErrorCode = 'operator' | 'https' | 'offline'
|
|
16
21
|
|
|
17
22
|
export const LINKS: { download: string, https: string, operator: string }
|
|
23
|
+
export const TAILSCALED_SOCKET: string
|
|
24
|
+
export function tailscaledSocket(env?: Record<string, string | undefined>, exists?: (p: string) => boolean): string | null
|
|
18
25
|
export function tailscaleBin(env?: Record<string, string | undefined>, exists?: (p: string) => boolean): string | null
|
|
19
26
|
export function tailnetStatus(statusJson: string): { name: string | null, connected: boolean, https: boolean }
|
|
20
27
|
export function phoneAddress(name: string | null, port: string | number, serveJson: string): PhoneAddress | null
|
|
28
|
+
export function servedAddresses(name: string | null, port: string | number, serveJson: string): string[] | null
|
|
21
29
|
export function servedPorts(serveJson: string): string[]
|
|
22
30
|
export function publishCommand(port: string | number, httpsPort?: string | number): string
|
|
23
31
|
export function publishArgs(port: string | number): string[]
|
|
24
32
|
export function unpublishArgs(httpsPort: string): string[]
|
|
25
33
|
export function tailnetUrl(text: unknown): string | null
|
|
26
34
|
export function serveError(output: string): { code: ServeErrorCode, link: string } | null
|
|
27
|
-
export function inspect(port: string | number, bin?: string | null): Promise<Tailnet>
|
|
35
|
+
export function inspect(port: string | number, bin?: string | null, socket?: string | null): Promise<Tailnet>
|
|
28
36
|
export function tailnetDomain(resolvConf: string): string | null
|
|
29
37
|
export function reachable(url: string, timeoutMs?: number): Promise<Reach>
|
|
38
|
+
export function healthReach(status: number, text: string): 'ok' | 'host' | null
|
|
30
39
|
export function probe(url: string, timeoutMs?: number): Promise<Probe>
|
|
31
40
|
export function failureCause(err: unknown): ReachCause
|
|
32
41
|
export function runTailscale(bin: string, args: string[], timeoutMs?: number): Promise<{ code: number, output: string }>
|
package/bin/lib/tailnet.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { execFile } from 'node:child_process'
|
|
8
8
|
import dns from 'node:dns'
|
|
9
9
|
import { existsSync } from 'node:fs'
|
|
10
|
+
import http from 'node:http'
|
|
10
11
|
import https from 'node:https'
|
|
11
12
|
import path from 'node:path'
|
|
12
13
|
import { promisify } from 'node:util'
|
|
@@ -26,6 +27,32 @@ export function tailscaleBin(env = process.env, exists = existsSync) {
|
|
|
26
27
|
return dirs.find(p => exists(p)) || null
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
// Tailscale's own socket on Linux. Its local API answers the same JSON as the
|
|
31
|
+
// CLI: a Docker container has no `tailscale` command, but docker-compose.yml
|
|
32
|
+
// mounts this folder, so wherdr reads the state there. Anyone may read; the
|
|
33
|
+
// API also accepts changes from Tailscale's operator, but wherdr only ever
|
|
34
|
+
// sends GET requests to it (localApi below).
|
|
35
|
+
export const TAILSCALED_SOCKET = '/var/run/tailscale/tailscaled.sock'
|
|
36
|
+
export function tailscaledSocket(env = process.env, exists = existsSync) {
|
|
37
|
+
const file = env.WHERDR_TAILSCALED_SOCKET || TAILSCALED_SOCKET
|
|
38
|
+
return exists(file) ? file : null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// GET on Tailscale's local API → the body, '' on any failure.
|
|
42
|
+
function localApi(socketPath, route, timeoutMs = 4000) {
|
|
43
|
+
const { promise, resolve } = Promise.withResolvers()
|
|
44
|
+
const req = http.get({ socketPath, path: `/localapi/v0/${route}`, headers: { host: 'local-tailscaled.sock' }, timeout: timeoutMs }, (res) => {
|
|
45
|
+
let text = ''
|
|
46
|
+
res.setEncoding('utf8')
|
|
47
|
+
res.on('data', (c) => { if (text.length < 1 << 20) text += c })
|
|
48
|
+
res.on('end', () => resolve(res.statusCode === 200 ? text : ''))
|
|
49
|
+
res.on('error', () => resolve(''))
|
|
50
|
+
})
|
|
51
|
+
req.on('timeout', () => req.destroy())
|
|
52
|
+
req.on('error', () => resolve(''))
|
|
53
|
+
return promise
|
|
54
|
+
}
|
|
55
|
+
|
|
29
56
|
// `tailscale status --json` → { name, connected, https }: this machine's
|
|
30
57
|
// tailnet name (machine.tailnet.ts.net) or null, whether Tailscale is up,
|
|
31
58
|
// and whether the tailnet issues HTTPS certificates.
|
|
@@ -40,22 +67,51 @@ export function tailnetStatus(statusJson) {
|
|
|
40
67
|
}
|
|
41
68
|
}
|
|
42
69
|
|
|
70
|
+
// The HTTPS entries of a serve configuration that proxy to wherdr's local
|
|
71
|
+
// port on this machine's own name: [{ hostPort, httpsPort, funnel }], or null
|
|
72
|
+
// when the configuration could not be read (Tailscale stopped, not JSON).
|
|
73
|
+
// Background entries (`--bg`) and those of a `tailscale serve` still running
|
|
74
|
+
// in a terminal (Foreground) both count. `funnel`: also open to the Internet.
|
|
75
|
+
function wherdrEntries(name, port, serveJson) {
|
|
76
|
+
let config = null
|
|
77
|
+
try { config = JSON.parse(serveJson) } catch {}
|
|
78
|
+
if (!name || !config || typeof config !== 'object' || Array.isArray(config)) return null
|
|
79
|
+
const target = new RegExp(`^(https?://)?(127\\.0\\.0\\.1|localhost):${port}/?$`)
|
|
80
|
+
const out = []
|
|
81
|
+
for (const part of [config, ...Object.values(config.Foreground || {})]) {
|
|
82
|
+
for (const [hostPort, entry] of Object.entries(part?.Web || {})) {
|
|
83
|
+
const colon = hostPort.lastIndexOf(':')
|
|
84
|
+
if (hostPort.slice(0, colon).toLowerCase() !== name.toLowerCase()) continue
|
|
85
|
+
if (!Object.values(entry?.Handlers || {}).some(h => target.test(h?.Proxy || ''))) continue
|
|
86
|
+
out.push({ hostPort, httpsPort: hostPort.slice(colon + 1), funnel: Boolean(part.AllowFunnel?.[hostPort]) })
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const addressOf = (name, httpsPort) => `https://${name}${httpsPort === '443' ? '' : `:${httpsPort}`}/`
|
|
93
|
+
|
|
43
94
|
// Phone address: the `tailscale serve` entry whose proxy targets wherdr's
|
|
44
95
|
// local port (served on any HTTPS port), else the address publishing would
|
|
45
96
|
// give (same port) with served: false. Null without a tailnet name.
|
|
46
97
|
export function phoneAddress(name, port, serveJson) {
|
|
47
98
|
if (!name) return null
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
for (const [hostPort, entry] of Object.entries(web)) {
|
|
52
|
-
if (!Object.values(entry?.Handlers || {}).some(h => target.test(h?.Proxy || ''))) continue
|
|
53
|
-
const servedPort = hostPort.slice(hostPort.lastIndexOf(':') + 1)
|
|
54
|
-
return { url: `https://${name}${servedPort === '443' ? '' : `:${servedPort}`}/`, served: true, httpsPort: servedPort }
|
|
55
|
-
}
|
|
99
|
+
const entries = wherdrEntries(name, port, serveJson) || []
|
|
100
|
+
const hit = entries.find(e => !e.funnel) || entries[0]
|
|
101
|
+
if (hit) return { url: addressOf(name, hit.httpsPort), served: true, httpsPort: hit.httpsPort, ...(hit.funnel ? { funnel: true } : {}) }
|
|
56
102
|
return { url: `https://${name}:${port}/`, served: false, httpsPort: String(port) }
|
|
57
103
|
}
|
|
58
104
|
|
|
105
|
+
// The addresses wherdr adopts by itself (server/utils/phone.ts): what
|
|
106
|
+
// `tailscale serve` publishes for its port on this machine's name, read from
|
|
107
|
+
// Tailscale, which only the owner of the machine configures. null: unknown
|
|
108
|
+
// (nothing is changed then); []: nothing is published. An address that
|
|
109
|
+
// `tailscale funnel` also opens to the Internet is never adopted.
|
|
110
|
+
export function servedAddresses(name, port, serveJson) {
|
|
111
|
+
const entries = wherdrEntries(name, port, serveJson)
|
|
112
|
+
return entries && entries.filter(e => !e.funnel).map(e => addressOf(name, e.httpsPort))
|
|
113
|
+
}
|
|
114
|
+
|
|
59
115
|
// HTTPS ports already published by `tailscale serve` (for anything).
|
|
60
116
|
export function servedPorts(serveJson) {
|
|
61
117
|
try {
|
|
@@ -92,16 +148,18 @@ export function serveError(output) {
|
|
|
92
148
|
return null
|
|
93
149
|
}
|
|
94
150
|
|
|
95
|
-
// Tailscale's state for wherdr's port: { installed, bin,
|
|
96
|
-
|
|
97
|
-
|
|
151
|
+
// Tailscale's state for wherdr's port: { installed, bin, socket, connected,
|
|
152
|
+
// https, name, phone, taken, served }. Read with the CLI, or without one
|
|
153
|
+
// (Docker) from Tailscale's socket.
|
|
154
|
+
export async function inspect(port, bin = tailscaleBin(), socket = bin ? null : tailscaledSocket()) {
|
|
155
|
+
if (!bin && !socket) return { installed: false }
|
|
98
156
|
const run = args => exec(bin, args, { encoding: 'utf8', timeout: 8000 }).then(r => r.stdout, () => '')
|
|
99
|
-
const status = tailnetStatus(await run(['status', '--json']))
|
|
100
|
-
const serve = status.name ? await run(['serve', 'status', '--json']) : ''
|
|
157
|
+
const status = tailnetStatus(bin ? await run(['status', '--json']) : await localApi(socket, 'status?peers=false'))
|
|
158
|
+
const serve = !status.name ? '' : bin ? await run(['serve', 'status', '--json']) : await localApi(socket, 'serve-config')
|
|
101
159
|
const phone = phoneAddress(status.name, port, serve)
|
|
102
160
|
// Publishing on wherdr's port would replace whatever else is served there.
|
|
103
161
|
const taken = Boolean(phone && !phone.served && servedPorts(serve).includes(String(port)))
|
|
104
|
-
return { installed: true, bin, ...status, phone, taken }
|
|
162
|
+
return { installed: true, bin, socket, ...status, phone, taken, served: servedAddresses(status.name, port, serve) }
|
|
105
163
|
}
|
|
106
164
|
|
|
107
165
|
// The tailnet's DNS suffix (tailnet.ts.net) from /etc/resolv.conf's search
|
|
@@ -152,29 +210,49 @@ export function failureCause(err) {
|
|
|
152
210
|
return 'network'
|
|
153
211
|
}
|
|
154
212
|
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
export function probe(url, timeoutMs = 8000) {
|
|
213
|
+
// GET of `route` on the address → { status, text }, or { cause } when it failed.
|
|
214
|
+
function fetchText(url, route, timeoutMs) {
|
|
158
215
|
const { promise, resolve } = Promise.withResolvers()
|
|
159
216
|
let u
|
|
160
|
-
try { u = new URL(
|
|
217
|
+
try { u = new URL(route, url) } catch { return Promise.resolve({ cause: 'network' }) }
|
|
161
218
|
// Accept JSON: a refused host then answers { code: 'host' }, not the HTML page.
|
|
162
219
|
const req = https.get(u, { lookup, timeout: timeoutMs, headers: { accept: 'application/json' } }, (res) => {
|
|
163
220
|
let text = ''
|
|
164
221
|
res.setEncoding('utf8')
|
|
165
222
|
res.on('data', (c) => { if (text.length < 65536) text += c })
|
|
166
|
-
res.on('end', () => {
|
|
167
|
-
|
|
168
|
-
if (status >= 200 && status < 300) resolve({ reach: text.includes('wherdr') ? 'ok' : 'other', status })
|
|
169
|
-
else resolve({ reach: status === 403 && /"code"\s*:\s*"host"/.test(text) ? 'host' : 'other', status })
|
|
170
|
-
})
|
|
171
|
-
res.on('error', e => resolve({ reach: 'unreachable', cause: failureCause(e) }))
|
|
223
|
+
res.on('end', () => resolve({ status: res.statusCode || 0, text }))
|
|
224
|
+
res.on('error', e => resolve({ cause: failureCause(e) }))
|
|
172
225
|
})
|
|
173
226
|
req.on('timeout', () => req.destroy(new Error('timeout')))
|
|
174
|
-
req.on('error', e => resolve({
|
|
227
|
+
req.on('error', e => resolve({ cause: failureCause(e) }))
|
|
175
228
|
return promise
|
|
176
229
|
}
|
|
177
230
|
|
|
231
|
+
// What an answer of /api/health means: 'ok' (wherdr, and it accepts this
|
|
232
|
+
// address), 'host' (wherdr's host check refused it), or null: not a wherdr
|
|
233
|
+
// that has this route (versions up to 1.3.1, or another program).
|
|
234
|
+
export function healthReach(status, text) {
|
|
235
|
+
if (status >= 200 && status < 300 && /"name"\s*:\s*"wherdr"/.test(text)) return 'ok'
|
|
236
|
+
if (status === 403 && /"code"\s*:\s*"host"/.test(text)) return 'host'
|
|
237
|
+
return null
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// reachable() with the details: { reach, cause?, status? }: `cause` when
|
|
241
|
+
// unreachable (failureCause), `status` the HTTP code when something answered.
|
|
242
|
+
// /api/health is asked first: it goes through wherdr's host check, which the
|
|
243
|
+
// static manifest does not (it answers for any host name). The manifest only
|
|
244
|
+
// recognizes an older wherdr without that route.
|
|
245
|
+
export async function probe(url, timeoutMs = 8000) {
|
|
246
|
+
const health = await fetchText(url, 'api/health', timeoutMs)
|
|
247
|
+
if (health.cause) return { reach: 'unreachable', cause: health.cause }
|
|
248
|
+
const reach = healthReach(health.status, health.text)
|
|
249
|
+
if (reach) return { reach, status: health.status }
|
|
250
|
+
const manifest = await fetchText(url, 'manifest.webmanifest', timeoutMs)
|
|
251
|
+
if (manifest.cause) return { reach: 'unreachable', cause: manifest.cause }
|
|
252
|
+
const ok = manifest.status >= 200 && manifest.status < 300 && manifest.text.includes('wherdr')
|
|
253
|
+
return { reach: ok ? 'ok' : 'other', status: ok ? manifest.status : health.status }
|
|
254
|
+
}
|
|
255
|
+
|
|
178
256
|
// Runs `tailscale <args>` without a terminal → { code, output }. On a tailnet
|
|
179
257
|
// without HTTPS, `tailscale serve` prints a link and waits: the timeout ends it.
|
|
180
258
|
export function runTailscale(bin, args, timeoutMs = 30_000) {
|