my-durable 0.0.59 → 0.0.60
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/daemon.ts +48 -0
- package/apps/dpi-backend/src/doctor.ts +17 -4
- package/apps/dpi-backend/src/gc-cli.ts +28 -2
- package/apps/dpi-backend/src/main.ts +23 -3
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-4Kyozhl0.js +81 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-DxGrKN6X.css → index-BkSQ2clA.css} +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/src/App.vue +9 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/dialog-escape.ts +13 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/export-bundle.ts +70 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/state-draft.ts +72 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +15 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ContextBar.vue +14 -3
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +82 -69
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ModelPicker.vue +22 -4
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/PromptDialog.vue +3 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/style.css +19 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +5 -1
- package/apps/dpi-playground/apps/dpi-playground-hub/src/pairing.ts +38 -17
- package/apps/dpi-tui/src/main.ts +46 -19
- package/bin/dpi.mjs +83 -0
- package/package.json +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DC0Iicch.js +0 -81
|
@@ -172,6 +172,43 @@ const execDefault = (cmd: string, args: string[]) =>
|
|
|
172
172
|
|
|
173
173
|
const delay = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
|
|
174
174
|
|
|
175
|
+
/** R6 cli finding 10: `dpi device stop` twice hung 40s+ with zero output while
|
|
176
|
+
* the daemon stayed healthy. No shutdown step may block forever: race the
|
|
177
|
+
* step against a ceiling; on expiry say so and CONTINUE (the shutdown caller
|
|
178
|
+
* still force-exits). A step that throws rejects normally — only the hang is
|
|
179
|
+
* bounded. Exported so the sequencing is unit-testable. */
|
|
180
|
+
export async function boundedStep<T>(
|
|
181
|
+
label: string,
|
|
182
|
+
ms: number,
|
|
183
|
+
run: () => T | Promise<T>,
|
|
184
|
+
log: (line: string) => void = () => {},
|
|
185
|
+
): Promise<T | undefined> {
|
|
186
|
+
let done = false;
|
|
187
|
+
let failed: { error: unknown } | undefined;
|
|
188
|
+
const step = Promise.resolve(run()).then(
|
|
189
|
+
(v) => {
|
|
190
|
+
done = true;
|
|
191
|
+
return v;
|
|
192
|
+
},
|
|
193
|
+
(error: unknown) => {
|
|
194
|
+
done = true;
|
|
195
|
+
failed = { error };
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
let timer: NodeJS.Timeout | undefined;
|
|
199
|
+
const ceiling = new Promise<void>((resolve) => {
|
|
200
|
+
timer = setTimeout(() => resolve(), ms);
|
|
201
|
+
});
|
|
202
|
+
await Promise.race([step, ceiling]);
|
|
203
|
+
if (timer) clearTimeout(timer);
|
|
204
|
+
if (!done) {
|
|
205
|
+
log(`shutdown: ${label} did not finish within ${ms}ms — continuing without it`);
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
if (failed) throw failed.error;
|
|
209
|
+
return (await step) as T;
|
|
210
|
+
}
|
|
211
|
+
|
|
175
212
|
function ioOf(opts: RunOpts): Io {
|
|
176
213
|
return {
|
|
177
214
|
env: opts.env ?? process.env,
|
|
@@ -385,6 +422,17 @@ async function cmdInstall(io: Io): Promise<number> {
|
|
|
385
422
|
if (!env.DPI_HOME) env.DPI_HOME = daemonPaths(io.env).home;
|
|
386
423
|
if (p === "linux") {
|
|
387
424
|
const unit = join(homedir(), ".config/systemd/user/dpi-device.service");
|
|
425
|
+
// R6 cli finding 8: probe systemd BEFORE writing anything. A host without a
|
|
426
|
+
// user systemd (containers, non-systemd distros) used to get a stray unit
|
|
427
|
+
// file plus an empty "systemctl enable failed:" — daemon-reload is the same
|
|
428
|
+
// first step a real install takes, so it is the honest probe.
|
|
429
|
+
const probe = await io.exec("systemctl", ["--user", "daemon-reload"]);
|
|
430
|
+
if (!probe.ok) {
|
|
431
|
+
const reason = probe.output.trim().split("\n")[0] || "systemctl is not usable on this host";
|
|
432
|
+
io.print(`no systemd --user on this host — nothing was installed (${reason})`);
|
|
433
|
+
io.print("start the daemon after login instead: dpi device start");
|
|
434
|
+
return 1;
|
|
435
|
+
}
|
|
388
436
|
await io.writeFile(unit, systemdUnit({ node, dpi, env }));
|
|
389
437
|
await io.exec("systemctl", ["--user", "daemon-reload"]);
|
|
390
438
|
const enable = await io.exec("systemctl", ["--user", "enable", "--now", "dpi-device.service"]);
|
|
@@ -131,6 +131,11 @@ export function splitModel(
|
|
|
131
131
|
): { provider: string; modelId: string } | undefined {
|
|
132
132
|
const exact = models?.find((m) => `${m.provider}/${m.id}` === defaultModel);
|
|
133
133
|
if (exact) return { provider: exact.provider, modelId: exact.id };
|
|
134
|
+
// R6 cli finding 7: local catalogs (faux provider) report a BARE id as the
|
|
135
|
+
// defaultModel — match it against models[].id before the split heuristic so
|
|
136
|
+
// healthy faux devices stop warning "no usable defaultModel".
|
|
137
|
+
const bare = models?.find((m) => m.id === defaultModel && m.provider);
|
|
138
|
+
if (bare) return { provider: bare.provider, modelId: bare.id };
|
|
134
139
|
const i = defaultModel.indexOf("/");
|
|
135
140
|
if (i <= 0 || i === defaultModel.length - 1) return undefined;
|
|
136
141
|
return { provider: defaultModel.slice(0, i), modelId: defaultModel.slice(i + 1) };
|
|
@@ -321,13 +326,21 @@ async function hubCheck(io: DoctorIo, cfg: DeviceEndpoint): Promise<DoctorCheck>
|
|
|
321
326
|
const source = origin ? "DPI_HUB_URL" : "pairing.json";
|
|
322
327
|
if (!origin) {
|
|
323
328
|
const file = join(cfg.home, "pairing.json");
|
|
324
|
-
|
|
325
|
-
|
|
329
|
+
if (io.exists(file)) {
|
|
330
|
+
try {
|
|
326
331
|
const paired = JSON.parse(io.readFile(file)) as { hubOrigin?: unknown };
|
|
327
332
|
if (typeof paired.hubOrigin === "string") origin = paired.hubOrigin.trim().replace(/\/+$/, "");
|
|
333
|
+
} catch (error) {
|
|
334
|
+
// R6 cli finding 6: a corrupt/unreadable pairing file is NOT "no hub
|
|
335
|
+
// configured" — the operator must learn the file is broken, because
|
|
336
|
+
// the hub check cannot run at all until it is fixed.
|
|
337
|
+
return {
|
|
338
|
+
id,
|
|
339
|
+
label: "hub",
|
|
340
|
+
status: "warn",
|
|
341
|
+
detail: `pairing.json is corrupt/unreadable — fix or delete ${file} (${describeError(error, 0)})`,
|
|
342
|
+
};
|
|
328
343
|
}
|
|
329
|
-
} catch {
|
|
330
|
-
/* unreadable/garbled pairing file: report as not configured */
|
|
331
344
|
}
|
|
332
345
|
}
|
|
333
346
|
if (!origin) return { id, label: "hub", status: "skip", detail: "no hub configured (no DPI_HUB_URL, no saved pairing)" };
|
|
@@ -52,7 +52,25 @@ export function resolveDataDir(argv: readonly string[], io: GcIo): string {
|
|
|
52
52
|
return i >= 0 ? argv[i + 1] : undefined;
|
|
53
53
|
};
|
|
54
54
|
const envFile = io.env.DPI_ENV_FILE;
|
|
55
|
-
|
|
55
|
+
let fileEnv: Record<string, string> = {};
|
|
56
|
+
if (envFile) {
|
|
57
|
+
// R6 cli finding 2: a missing/unreadable env file used to escape as a raw
|
|
58
|
+
// ENOENT/EACCES stack from deep inside resolution — say it in one line.
|
|
59
|
+
try {
|
|
60
|
+
fileEnv = readEnvFile(io.readFile(envFile));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
const code = (e as NodeJS.ErrnoException)?.code;
|
|
63
|
+
const why =
|
|
64
|
+
code === "ENOENT"
|
|
65
|
+
? "the file does not exist"
|
|
66
|
+
: code === "EACCES"
|
|
67
|
+
? "the file is not readable"
|
|
68
|
+
: e instanceof Error
|
|
69
|
+
? e.message
|
|
70
|
+
: String(e);
|
|
71
|
+
throw new Error(`cannot read DPI_ENV_FILE '${envFile}' — ${why}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
56
74
|
const value = (key: string) =>
|
|
57
75
|
io.env[key] ?? (typeof fileEnv[key] === "string" ? fileEnv[key] : undefined);
|
|
58
76
|
const dataDirArg = flag("--data-dir") ?? value("DPI_DATA_DIR");
|
|
@@ -87,7 +105,15 @@ export async function gcCli(args: GcArgs, io: GcIo = defaultGcIo()): Promise<num
|
|
|
87
105
|
return 2;
|
|
88
106
|
}
|
|
89
107
|
const apply = argv.includes("--yes");
|
|
90
|
-
|
|
108
|
+
// R6 cli finding 2: resolveDataDir touches the env file — keep its failures
|
|
109
|
+
// in the one-line pretty-error regime (exit 1), like the plan/apply calls.
|
|
110
|
+
let archiveDir: string;
|
|
111
|
+
try {
|
|
112
|
+
archiveDir = join(resolveDataDir(argv, io), "archive");
|
|
113
|
+
} catch (e) {
|
|
114
|
+
io.printErr(`dpi gc: ${e instanceof Error ? e.message : String(e)}`);
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
91
117
|
const options = { closedBeforeDays: days, now: io.now() };
|
|
92
118
|
|
|
93
119
|
// The plan/apply calls live inside the pretty-error path (R5 finding 6): a bad
|
|
@@ -14,7 +14,7 @@ import { v1 } from "./routes.js";
|
|
|
14
14
|
import { DevicePairing } from "./pairing.js";
|
|
15
15
|
import { DeviceConnector, readCaPem } from "./tunnel.js";
|
|
16
16
|
import { PAIR_PAGE_HTML } from "./pair-page.js";
|
|
17
|
-
import { parseDeviceSub, runDeviceCommand, daemonPaths } from "./daemon.js";
|
|
17
|
+
import { parseDeviceSub, runDeviceCommand, daemonPaths, boundedStep } from "./daemon.js";
|
|
18
18
|
|
|
19
19
|
// `dpi device start|stop|status|install|uninstall` manage a background daemon
|
|
20
20
|
// and exit; everything else (bare `dpi device` or flags) runs the daemon here.
|
|
@@ -249,15 +249,35 @@ let closing = false;
|
|
|
249
249
|
const shutdown = async () => {
|
|
250
250
|
if (closing) return;
|
|
251
251
|
closing = true;
|
|
252
|
-
|
|
252
|
+
// R6 cli finding 10: `dpi device stop` hung twice at teardown (40s+, zero
|
|
253
|
+
// output, device stayed healthy; direct SIGTERM exits <5s). No step of the
|
|
254
|
+
// shutdown may block forever:
|
|
255
|
+
// - connector.stop is synchronous; a throw is logged, never fatal;
|
|
256
|
+
// - store.close is raced against a 5s ceiling (boundedStep) and abandoned;
|
|
257
|
+
// - a hard watchdog guarantees the process still exits at 10s.
|
|
258
|
+
const log = (line: string) => console.log(line);
|
|
259
|
+
const watchdog = setTimeout(() => {
|
|
260
|
+
console.log("shutdown: still not down after 10s — forcing exit");
|
|
261
|
+
process.exit(0);
|
|
262
|
+
}, 10_000);
|
|
263
|
+
try {
|
|
264
|
+
await boundedStep("connector.stop", 5_000, () => connector.stop("backend shutdown"), log);
|
|
265
|
+
} catch (e) {
|
|
266
|
+
log(`shutdown: connector stop failed (${e instanceof Error ? e.message : String(e)}) — continuing`);
|
|
267
|
+
}
|
|
253
268
|
server.close();
|
|
254
269
|
server.closeAllConnections();
|
|
255
|
-
|
|
270
|
+
try {
|
|
271
|
+
await boundedStep("store.close", 5_000, () => store.close(), log);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
log(`shutdown: store close failed (${e instanceof Error ? e.message : String(e)}) — exiting anyway`);
|
|
274
|
+
}
|
|
256
275
|
try {
|
|
257
276
|
rmSync(daemonPaths(process.env).pid, { force: true });
|
|
258
277
|
} catch {
|
|
259
278
|
/* nothing to clean */
|
|
260
279
|
}
|
|
280
|
+
clearTimeout(watchdog);
|
|
261
281
|
process.exit(0);
|
|
262
282
|
};
|
|
263
283
|
process.on("SIGTERM", () => void shutdown());
|