my-durable 0.0.10 → 0.0.12
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/apps/dpi-backend/src/main.ts +4 -0
- package/apps/dpi-backend/src/pair-cli.ts +489 -0
- package/apps/dpi-backend/src/routes.ts +6 -2
- package/apps/dpi-backend/src/store.ts +30 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-CoYMgU-2.js → index-DEFBWh1G.js} +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NewSessionDialog.vue +5 -3
- package/apps/dpi-sdk/src/api.ts +2 -0
- package/apps/dpi-sdk/src/protocol/pairing.ts +6 -1
- package/apps/dpi-tui/src/app.ts +101 -18
- package/apps/dpi-tui/src/pickers.ts +7 -1
- package/apps/dpi-tui/src/views.ts +4 -3
- package/bin/dpi.mjs +43 -66
- package/bin/update.d.mts +24 -0
- package/bin/update.mjs +198 -0
- package/package.json +2 -2
- package/scripts/verify.mjs +6 -0
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<meta name="referrer" content="no-referrer" />
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="/icons/durable-pi.svg" />
|
|
9
9
|
<title>Durable Pi | Network</title>
|
|
10
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
+
<script type="module" crossorigin src="/assets/index-DEFBWh1G.js"></script>
|
|
11
11
|
<link rel="stylesheet" crossorigin href="/assets/index-Cg3vey95.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
@@ -38,6 +38,8 @@ const models = computed(() => {
|
|
|
38
38
|
const catalogEmpty = computed(
|
|
39
39
|
() => !models.value.length || (device.value?.info?.models?.length ?? 0) === 0,
|
|
40
40
|
);
|
|
41
|
+
/** The device lists its built-in catalog but chat needs the key (0.0.12+ devices). */
|
|
42
|
+
const keyless = computed(() => !!(device.value?.info as { providerKeyMissing?: boolean } | undefined)?.providerKeyMissing);
|
|
41
43
|
const key = (m: { provider: string; id: string }) => `${m.provider}/${m.id}`;
|
|
42
44
|
const draft = ref({ name: "", cwd: "", model: "" });
|
|
43
45
|
const pending = ref(false);
|
|
@@ -121,10 +123,10 @@ async function create() {
|
|
|
121
123
|
</div>
|
|
122
124
|
<label
|
|
123
125
|
>Model<span
|
|
124
|
-
v-if="catalogEmpty"
|
|
126
|
+
v-if="catalogEmpty || keyless"
|
|
125
127
|
class="hint"
|
|
126
|
-
title="The device
|
|
127
|
-
>no key on device —
|
|
128
|
+
title="The device has no provider key — it lists its built-in catalog, and chat needs OPENROUTER_API_KEY set in the device's env file"
|
|
129
|
+
>no API key on device — chat needs one</span
|
|
128
130
|
><select v-model="draft.model" aria-label="New session model">
|
|
129
131
|
<option v-for="m in models" :key="key(m)" :value="key(m)">
|
|
130
132
|
{{ m.tier }} / {{ m.name }}
|
package/apps/dpi-sdk/src/api.ts
CHANGED
|
@@ -96,6 +96,8 @@ export interface DeviceInfo {
|
|
|
96
96
|
defaultModel: string;
|
|
97
97
|
/** Provider id of this device ("openrouter" | "faux"); FE model fallback. */
|
|
98
98
|
provider?: string;
|
|
99
|
+
/** No provider key on the device: the catalog shown is the built-in list and chat needs the key. */
|
|
100
|
+
providerKeyMissing?: boolean;
|
|
99
101
|
storage: { dataDir: string; catalogPath: string; appStatePath: string };
|
|
100
102
|
/** The checkout the backend runs from (repo root locally, `code_dir` on deployed devices). */
|
|
101
103
|
codeDir?: string;
|
|
@@ -383,7 +383,12 @@ export function parseHubOrigin(
|
|
|
383
383
|
return { ok: false, error: "origin: not a valid URL" };
|
|
384
384
|
}
|
|
385
385
|
if (url.protocol !== "https:") {
|
|
386
|
-
|
|
386
|
+
// Loopback dev hubs (one machine running both ends) speak plain HTTP. The
|
|
387
|
+
// same rule as the device's own origin check: only 127.0.0.1/[::1]/localhost
|
|
388
|
+
// qualify, so a hub another machine can reach is still HTTPS-only.
|
|
389
|
+
const loopback =
|
|
390
|
+
url.protocol === "http:" && /^(127\.0\.0\.1|\[::1\]|localhost)$/.test(url.hostname);
|
|
391
|
+
if (!loopback) return { ok: false, error: "origin: HTTPS origin required" };
|
|
387
392
|
}
|
|
388
393
|
if (url.username || url.password) {
|
|
389
394
|
return { ok: false, error: "origin: userinfo not allowed" };
|
package/apps/dpi-tui/src/app.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type { DeviceRow, NetworkRegistry } from "../../dpi-sdk/src/node/registry
|
|
|
28
28
|
import { COMMANDS, runCommand } from "./commands.ts";
|
|
29
29
|
import { Prompt, SecretPrompt, pickModel, newSession } from "./pickers.ts";
|
|
30
30
|
import { renderHeader, renderHerd, renderHerdPanel, renderNetwork, renderStatusbar, renderViewbar, herdRows, joinPanel, networkRows } from "./views.ts";
|
|
31
|
+
import { appendFileSync } from "node:fs";
|
|
31
32
|
import { fetchHubNetwork } from "./hub-feed.ts";
|
|
32
33
|
import { HubMux } from "./hub-mux.ts";
|
|
33
34
|
import { box, c, STATE_COLOR, STATE_GLYPH, type RowState } from "./theme.ts";
|
|
@@ -358,7 +359,13 @@ export class App {
|
|
|
358
359
|
];
|
|
359
360
|
}
|
|
360
361
|
|
|
361
|
-
|
|
362
|
+
/** Herd and network rows share a shape; `kind` tells a header from an entry. */
|
|
363
|
+
private rows(): Array<{
|
|
364
|
+
kind: "group" | "session" | "device";
|
|
365
|
+
sessionId?: string;
|
|
366
|
+
deviceId?: string;
|
|
367
|
+
label: string;
|
|
368
|
+
}> {
|
|
362
369
|
if (this.view === "herd") return herdRows(this.sessions, this.filter);
|
|
363
370
|
if (this.view === "network") return networkRows(this.devicesCache, this.device.id, this.filter);
|
|
364
371
|
return [];
|
|
@@ -368,6 +375,14 @@ export class App {
|
|
|
368
375
|
const rows = this.rows();
|
|
369
376
|
const row = rows[this.cursor] ?? rows.find((r) => r.sessionId);
|
|
370
377
|
if (row?.sessionId) return this.openSession(row.sessionId, row.deviceId);
|
|
378
|
+
// A group header opens its first session — pressing enter on a header used
|
|
379
|
+
// to do literally nothing.
|
|
380
|
+
if (row?.kind === "group") {
|
|
381
|
+
// The next session row after the header belongs to that group.
|
|
382
|
+
const at = rows.indexOf(row);
|
|
383
|
+
const target = rows.slice(at + 1).find((r) => r.kind !== "group");
|
|
384
|
+
if (target?.sessionId) return this.openSession(target.sessionId, target.deviceId);
|
|
385
|
+
}
|
|
371
386
|
if (row?.deviceId && this.view === "network") {
|
|
372
387
|
const target = this.devicesCache.find((d) => d.id === row.deviceId);
|
|
373
388
|
if (!target) return;
|
|
@@ -402,7 +417,11 @@ export class App {
|
|
|
402
417
|
|
|
403
418
|
/** 1-9 jump: the nth session row of the current view. */
|
|
404
419
|
private jump(n: number) {
|
|
405
|
-
|
|
420
|
+
// Digits address sessions, so they work from the agent view as well — that
|
|
421
|
+
// is the fastest way out of a session you no longer want.
|
|
422
|
+
const rows = (this.view === "herd" ? this.rows() : herdRows(this.sessions, this.filter)).filter(
|
|
423
|
+
(r): r is { kind: "session"; sessionId: string; deviceId?: string; label: string } => !!r.sessionId,
|
|
424
|
+
);
|
|
406
425
|
const nth = rows[n - 1];
|
|
407
426
|
if (nth?.sessionId) this.openSession(nth.sessionId, nth.deviceId);
|
|
408
427
|
else this.notify(`no session #${n} in this view`);
|
|
@@ -454,6 +473,17 @@ export class App {
|
|
|
454
473
|
// ------------------------------------------------------------------- input
|
|
455
474
|
|
|
456
475
|
handleInput(data: string): TuiInputListenerResult {
|
|
476
|
+
// DPI_TUI_KEYS=<file> traces every key the app receives — the fastest way to
|
|
477
|
+
// tell "the terminal never sent it" from "a branch swallowed it".
|
|
478
|
+
if (process.env.DPI_TUI_KEYS)
|
|
479
|
+
try {
|
|
480
|
+
appendFileSync(
|
|
481
|
+
process.env.DPI_TUI_KEYS,
|
|
482
|
+
`${JSON.stringify({ data, view: this.view, tab: this.tab, input: this.input?.kind ?? null, overlays: this.overlays.length })}\n`,
|
|
483
|
+
);
|
|
484
|
+
} catch {
|
|
485
|
+
/* tracing must never break input */
|
|
486
|
+
}
|
|
457
487
|
// pi-tui overlays (welcome screen, pickers, prompts) own the keyboard while
|
|
458
488
|
// open; only ctrl+c still closes them from here.
|
|
459
489
|
if (this.overlays.length) {
|
|
@@ -489,7 +519,7 @@ export class App {
|
|
|
489
519
|
else if (data === "/") {
|
|
490
520
|
this.beginInput("message", "follow-up ❯ ");
|
|
491
521
|
this.input!.value = "/";
|
|
492
|
-
} else if (data === "f") this.beginInput("filter", "
|
|
522
|
+
} else if (data === "f") this.beginInput("filter", "filter ❯ ");
|
|
493
523
|
else if (data === "n") this.beginInput("new", "new session › ");
|
|
494
524
|
else if (data === "x") this.beginInput("kill", `reset ${this.sessionSummary()?.name ?? "context"}? y/n`);
|
|
495
525
|
else if (data === "g") this.setView("herd");
|
|
@@ -508,12 +538,9 @@ export class App {
|
|
|
508
538
|
else if (data === "]" || matchesKey(data, "tab")) this.cycleTab(1);
|
|
509
539
|
else if (data === "[" || matchesKey(data, "shift+tab")) this.cycleTab(-1);
|
|
510
540
|
else if (/^[1-9]$/.test(data)) this.jump(Number(data));
|
|
511
|
-
//
|
|
512
|
-
//
|
|
513
|
-
|
|
514
|
-
this.beginInput("message", "follow-up ❯ ");
|
|
515
|
-
this.input!.value = data;
|
|
516
|
-
}
|
|
541
|
+
// No catch-all: a stray letter used to jump views or open the composer with
|
|
542
|
+
// itself as the first character. herdr and piggery both require an explicit
|
|
543
|
+
// key (m, / or enter), and so do we now.
|
|
517
544
|
return { consume: true };
|
|
518
545
|
}
|
|
519
546
|
|
|
@@ -526,6 +553,20 @@ export class App {
|
|
|
526
553
|
this.toast = "";
|
|
527
554
|
return true;
|
|
528
555
|
}
|
|
556
|
+
// The slash suggestion list is a MENU while it is open: ↑/↓ steer it and
|
|
557
|
+
// enter picks — history recall waits until the list is gone. (Reported:
|
|
558
|
+
// "danh sách slash command không điều hướng được, enter không autocomplete".)
|
|
559
|
+
const sugg = input.kind === "message" ? slashSuggestions(input.value, COMMANDS) : null;
|
|
560
|
+
if (sugg && matchesKey(data, "up")) {
|
|
561
|
+
this.suggIndex = Math.max(0, this.suggIndex - 1);
|
|
562
|
+
this.requestRender();
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
if (sugg && matchesKey(data, "down")) {
|
|
566
|
+
this.suggIndex = Math.min(sugg.names.length - 1, this.suggIndex + 1);
|
|
567
|
+
this.requestRender();
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
529
570
|
// ↑/↓ recall sent messages; the current draft survives the round-trip.
|
|
530
571
|
if (input.kind === "message" && matchesKey(data, "up")) {
|
|
531
572
|
if (this.inputHistory.length) {
|
|
@@ -548,13 +589,11 @@ export class App {
|
|
|
548
589
|
}
|
|
549
590
|
// Tab completes the selected slash suggestion; shift+tab cycles it.
|
|
550
591
|
if (input.kind === "message" && matchesKey(data, "shift+tab")) {
|
|
551
|
-
const sugg = slashSuggestions(input.value, COMMANDS);
|
|
552
592
|
if (sugg) this.suggIndex = (this.suggIndex + 1) % sugg.names.length;
|
|
553
593
|
this.requestRender();
|
|
554
594
|
return true;
|
|
555
595
|
}
|
|
556
596
|
if (input.kind === "message" && matchesKey(data, "tab")) {
|
|
557
|
-
const sugg = slashSuggestions(input.value, COMMANDS);
|
|
558
597
|
if (sugg) {
|
|
559
598
|
const pick = sugg.names[this.suggIndex % sugg.names.length]!;
|
|
560
599
|
input.value = `/${pick} `;
|
|
@@ -572,6 +611,21 @@ export class App {
|
|
|
572
611
|
return true;
|
|
573
612
|
}
|
|
574
613
|
if (matchesKey(data, "enter")) {
|
|
614
|
+
// Enter completes the highlighted suggestion (the completed text gains a
|
|
615
|
+
// trailing space, the list closes, and the NEXT enter submits). An exact
|
|
616
|
+
// command ("/model") runs immediately instead — completing it would force
|
|
617
|
+
// a pointless second enter.
|
|
618
|
+
if (
|
|
619
|
+
sugg &&
|
|
620
|
+
input.kind === "message" &&
|
|
621
|
+
!COMMANDS.some((c) => `/${c.name}` === input.value)
|
|
622
|
+
) {
|
|
623
|
+
const pick = sugg.names[this.suggIndex % sugg.names.length]!;
|
|
624
|
+
input.value = `/${pick} `;
|
|
625
|
+
this.suggIndex = 0;
|
|
626
|
+
this.requestRender();
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
575
629
|
const value = input.value;
|
|
576
630
|
this.input = null;
|
|
577
631
|
this.toast = "";
|
|
@@ -607,15 +661,27 @@ export class App {
|
|
|
607
661
|
this.requestRender();
|
|
608
662
|
}
|
|
609
663
|
|
|
664
|
+
/**
|
|
665
|
+
* esc is BACK, the way every list/detail client behaves (piggery: "esc back").
|
|
666
|
+
* Interrupting a running turn is a destructive action and keeps its own key
|
|
667
|
+
* (i) — folding it into esc meant "leave this screen" did nothing at all while
|
|
668
|
+
* an agent was idle.
|
|
669
|
+
*/
|
|
610
670
|
private escape() {
|
|
611
671
|
if (this.filter) {
|
|
612
672
|
this.filter = "";
|
|
613
673
|
this.notify("filter cleared");
|
|
614
|
-
} else if (this.view === "agent") {
|
|
615
|
-
|
|
616
|
-
}
|
|
674
|
+
} else if (this.view === "agent" || this.view === "log") {
|
|
675
|
+
this.setView("herd");
|
|
676
|
+
}
|
|
617
677
|
}
|
|
618
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Move the cursor. Group rows ("~/project/ · 3 agents") are headers, not
|
|
681
|
+
* entries: stepping onto one left the marker and the OVERVIEW panel frozen on
|
|
682
|
+
* the previous session, which reads as "navigation is dead". Skip them, the
|
|
683
|
+
* way piggery's list only ever has real rows under the cursor.
|
|
684
|
+
*/
|
|
619
685
|
private move(delta: number) {
|
|
620
686
|
if (this.view === "agent" && this.tab === "transcript") {
|
|
621
687
|
// Scroll the transcript instead of moving a cursor (herdr H04's lesson).
|
|
@@ -625,9 +691,24 @@ export class App {
|
|
|
625
691
|
}
|
|
626
692
|
const rows = this.rows();
|
|
627
693
|
if (!rows.length) return;
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
694
|
+
const selectable = (i: number) => !!rows[i] && rows[i].kind !== "group";
|
|
695
|
+
let next = this.cursor;
|
|
696
|
+
for (let step = 0; step < rows.length; step += 1) {
|
|
697
|
+
next += delta;
|
|
698
|
+
if (next < 0 || next >= rows.length) break;
|
|
699
|
+
if (selectable(next)) {
|
|
700
|
+
this.cursor = next;
|
|
701
|
+
this.selectedId = rows[next]!.sessionId ?? this.selectedId;
|
|
702
|
+
this.requestRender();
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
// Nothing selectable in that direction: still clamp to a valid row so the
|
|
707
|
+
// highlight never points past the list.
|
|
708
|
+
if (!selectable(this.cursor)) {
|
|
709
|
+
const first = rows.findIndex((_, i) => selectable(i));
|
|
710
|
+
if (first >= 0) this.cursor = first;
|
|
711
|
+
}
|
|
631
712
|
this.requestRender();
|
|
632
713
|
}
|
|
633
714
|
|
|
@@ -767,7 +848,9 @@ export class App {
|
|
|
767
848
|
|
|
768
849
|
tick() {
|
|
769
850
|
if (this.toastTicks > 0 && --this.toastTicks === 0) this.toast = "";
|
|
770
|
-
|
|
851
|
+
// Live network: refresh the hub feed every ~5 s (tick = 120 ms), so a device
|
|
852
|
+
// paired from the CLI shows up while the operator is looking at the list.
|
|
853
|
+
if (this.hub && ++this.hubTick >= 42) {
|
|
771
854
|
this.hubTick = 0;
|
|
772
855
|
void fetchHubNetwork(this.hub.url, this.hub.token).then((rows) => {
|
|
773
856
|
if (rows) {
|
|
@@ -323,7 +323,7 @@ function chooseModel(app: App, current?: string) {
|
|
|
323
323
|
return new Promise<(typeof app.info.models)[number] | undefined>((done) => {
|
|
324
324
|
const models = app.info.models;
|
|
325
325
|
const picker = new Picker(
|
|
326
|
-
`Model (${app.device.
|
|
326
|
+
`Model (${app.device.name})`,
|
|
327
327
|
models.map((m) => ({ value: `${m.provider}/${m.id}`, label: m.name, description: `${m.tier} │ ${m.provider}` })),
|
|
328
328
|
(item) => {
|
|
329
329
|
app.closeOverlay();
|
|
@@ -333,6 +333,12 @@ function chooseModel(app: App, current?: string) {
|
|
|
333
333
|
app.closeOverlay();
|
|
334
334
|
done(undefined);
|
|
335
335
|
},
|
|
336
|
+
undefined,
|
|
337
|
+
// The keyless device still lists the built-in catalog — say why chat
|
|
338
|
+
// will fail, instead of letting the first request be the messenger.
|
|
339
|
+
(app.info as { providerKeyMissing?: boolean }).providerKeyMissing
|
|
340
|
+
? "no API key on this device — chat needs OPENROUTER_API_KEY in its env file"
|
|
341
|
+
: undefined,
|
|
336
342
|
);
|
|
337
343
|
const index = models.findIndex((m) => m.id === current);
|
|
338
344
|
if (index >= 0) picker.list.setSelectedIndex(index);
|
|
@@ -121,9 +121,10 @@ export function renderHerd(
|
|
|
121
121
|
if (row.kind === "group") {
|
|
122
122
|
const group = sessions.filter((s) => basename(s.cwd) === row.label);
|
|
123
123
|
const busy = group.filter((s) => s.busy).length;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
|
124
|
+
const header = `${c.muted("~/")}${c.text(row.label)}${c.muted("/")} ${c.muted(`· ${group.length} agent${group.length === 1 ? "" : "s"} · ${busy} busy`)}`;
|
|
125
|
+
// The cursor is drawn on headers too: a keypress must always be visible,
|
|
126
|
+
// even though j/k skips them (they are not selectable entries).
|
|
127
|
+
lines.push(cursorRow === row ? c.inverse(fit(header, w)) : fit(header, w));
|
|
127
128
|
continue;
|
|
128
129
|
}
|
|
129
130
|
const s = sessions.find((x) => x.id === row.sessionId);
|
package/bin/dpi.mjs
CHANGED
|
@@ -23,6 +23,10 @@ Usage:
|
|
|
23
23
|
dpi device start | stop | status background daemon without a terminal
|
|
24
24
|
dpi device install | uninstall OS service (systemd/launchd); Windows: no
|
|
25
25
|
autostart — run "dpi device start" after login
|
|
26
|
+
dpi pair <code|link> [--hub <origin>] pair THIS machine from the CLI (no browser)
|
|
27
|
+
dpi pair --hub <origin> this machine asks the hub itself
|
|
28
|
+
dpi pair offer|list|approve|revoke operator side, from the CLI (dpi pair --help)
|
|
29
|
+
dpi devices [--watch] [--hub <origin>] paired machines + live status (CLI, no web)
|
|
26
30
|
dpi tui
|
|
27
31
|
Terminal admin client.
|
|
28
32
|
dpi help | dpi --help | dpi -h
|
|
@@ -88,75 +92,48 @@ if (command === "version" || command === "--version" || command === "-v") {
|
|
|
88
92
|
|
|
89
93
|
if (command === "update" || command === "upgrade") {
|
|
90
94
|
const { readFileSync } = await import("node:fs");
|
|
91
|
-
const {
|
|
95
|
+
const { runUpdate, fetchLatestVersion, spawnNpm, daemonControl } = await import("./update.mjs");
|
|
92
96
|
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z.]+)?$/.test(String(latest)))
|
|
106
|
-
throw new Error(`registry returned a malformed version: ${latest}`);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
process.stderr.write(`dpi update: cannot reach the npm registry (${error.message})\n`);
|
|
109
|
-
process.exit(1);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Numeric triple compare; a prerelease tag on either side counts as older.
|
|
113
|
-
const rank = (v) => {
|
|
114
|
-
const [core, ...pre] = String(v).split("-");
|
|
115
|
-
const nums = core.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
116
|
-
return { nums: [nums[0] ?? 0, nums[1] ?? 0, nums[2] ?? 0], pre: pre.length > 0 };
|
|
117
|
-
};
|
|
118
|
-
const a = rank(current);
|
|
119
|
-
const b = rank(latest);
|
|
120
|
-
let order = 0;
|
|
121
|
-
for (let i = 0; i < 3; i += 1) {
|
|
122
|
-
if (a.nums[i] !== b.nums[i]) {
|
|
123
|
-
order = a.nums[i] < b.nums[i] ? -1 : 1;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (order === 0 && a.pre !== b.pre) order = a.pre ? -1 : 1;
|
|
128
|
-
|
|
129
|
-
if (order >= 0) {
|
|
130
|
-
process.stdout.write(`dpi ${current} is up to date (latest ${latest}).\n`);
|
|
131
|
-
process.exit(0);
|
|
132
|
-
}
|
|
133
|
-
process.stdout.write(`dpi ${current} -> ${latest} available.\n`);
|
|
134
|
-
if (checkOnly) {
|
|
135
|
-
process.stdout.write("Run `dpi update` to install it.\n");
|
|
136
|
-
process.exit(0);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Windows: npm is npm.cmd and cmd.exe only executes batch files through a
|
|
140
|
-
// shell — a bare spawn("npm") dies with ENOENT (CreateProcess does no
|
|
141
|
-
// PATHEXT resolution). Args are literals plus the strictly-validated
|
|
142
|
-
// version above, so shell: true has no injection surface here.
|
|
143
|
-
const onWindows = process.platform === "win32";
|
|
144
|
-
const child = spawn(onWindows ? "npm.cmd" : "npm", ["install", "-g", `my-durable@${latest}`], {
|
|
145
|
-
stdio: "inherit",
|
|
146
|
-
shell: onWindows,
|
|
147
|
-
});
|
|
148
|
-
child.on("error", (error) => {
|
|
149
|
-
process.stderr.write(`dpi update: cannot run npm (${error.message})\n`);
|
|
150
|
-
process.exit(1);
|
|
97
|
+
const port = Number(process.env.DPI_PORT ?? "4780");
|
|
98
|
+
const code = await runUpdate({
|
|
99
|
+
argv: commandRest,
|
|
100
|
+
pkg,
|
|
101
|
+
nodeVersion: process.versions.node,
|
|
102
|
+
fetchLatest: fetchLatestVersion,
|
|
103
|
+
// Stop/start through this same launcher: the daemon must not block npm's
|
|
104
|
+
// rename on Windows, and it must come back afterwards.
|
|
105
|
+
daemon: daemonControl(fileURLToPath(import.meta.url), port),
|
|
106
|
+
runNpm: (version) => spawnNpm(["install", "-g", `my-durable@${version}`]),
|
|
107
|
+
print: (line) => process.stdout.write(`${line}\n`),
|
|
108
|
+
printErr: (line) => process.stderr.write(`${line}\n`),
|
|
151
109
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
110
|
+
process.exit(code);
|
|
111
|
+
} else if (command === "devices") {
|
|
112
|
+
// The CLI view of the network: same data the web sidebar and the TUI show.
|
|
113
|
+
process.argv = [process.argv[0], process.argv[1], ...commandRest];
|
|
114
|
+
const { register } = await loadTsx();
|
|
115
|
+
register();
|
|
116
|
+
const { listDevices } = await import("../apps/dpi-backend/src/pair-cli.ts");
|
|
117
|
+
const hubIdx = commandRest.indexOf("--hub");
|
|
118
|
+
process.exit(
|
|
119
|
+
await listDevices({}, hubIdx >= 0 ? commandRest[hubIdx + 1] : undefined, commandRest.includes("--watch")),
|
|
120
|
+
);
|
|
121
|
+
} else if (command === "pair") {
|
|
122
|
+
// Pairing is its own surface: it runs headless (no TUI, no browser) and both
|
|
123
|
+
// directions live in one command — this machine, and the operator's side.
|
|
124
|
+
if (commandRest.includes("--help") || commandRest.includes("-h")) {
|
|
125
|
+
process.argv = [process.argv[0], process.argv[1], ...commandRest];
|
|
126
|
+
const { register } = await loadTsx();
|
|
127
|
+
register();
|
|
128
|
+
const { PAIR_USAGE } = await import("../apps/dpi-backend/src/pair-cli.ts");
|
|
129
|
+
process.stdout.write(PAIR_USAGE);
|
|
158
130
|
process.exit(0);
|
|
159
|
-
}
|
|
131
|
+
}
|
|
132
|
+
process.argv = [process.argv[0], process.argv[1], ...commandRest];
|
|
133
|
+
const { register } = await loadTsx();
|
|
134
|
+
register();
|
|
135
|
+
const { runPairCommand } = await import("../apps/dpi-backend/src/pair-cli.ts");
|
|
136
|
+
process.exit(await runPairCommand(commandRest));
|
|
160
137
|
} else if (!Object.hasOwn(COMMANDS, command)) {
|
|
161
138
|
process.stderr.write(`dpi: unknown command '${command}'\n\n${HELP}`);
|
|
162
139
|
process.exit(2);
|
package/bin/update.d.mts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Types for bin/update.mjs — the updater is plain JS (it must run before any
|
|
2
|
+
// TS toolchain is available), so its public surface is declared here.
|
|
3
|
+
export interface UpdateDeps {
|
|
4
|
+
argv: string[];
|
|
5
|
+
pkg: { version: string; engines?: { node?: string } };
|
|
6
|
+
nodeVersion: string;
|
|
7
|
+
fetchLatest: () => Promise<string>;
|
|
8
|
+
daemon: { running: () => Promise<boolean>; stop: () => Promise<unknown>; start: () => Promise<unknown> };
|
|
9
|
+
runNpm: (version: string) => Promise<{ code: number; output: string }>;
|
|
10
|
+
print: (line: string) => void;
|
|
11
|
+
printErr: (line: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export function rank(version: string): { nums: number[]; pre: boolean };
|
|
14
|
+
export function compareVersions(a: string, b: string): -1 | 0 | 1;
|
|
15
|
+
export function satisfiesEngine(current: string, required: string): boolean;
|
|
16
|
+
export function normalizeExitCode(code: number | undefined): number;
|
|
17
|
+
export function isBusyFailure(text: string): boolean;
|
|
18
|
+
export function runUpdate(deps: UpdateDeps): Promise<number>;
|
|
19
|
+
export function spawnNpm(args: string[]): Promise<{ code: number; output: string }>;
|
|
20
|
+
export function fetchLatestVersion(): Promise<string>;
|
|
21
|
+
export function daemonControl(
|
|
22
|
+
dpiPath: string,
|
|
23
|
+
port: number,
|
|
24
|
+
): { running: () => Promise<boolean>; stop: () => Promise<number>; start: () => Promise<number> };
|