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.
Files changed (23) hide show
  1. package/apps/dpi-backend/src/daemon.ts +48 -0
  2. package/apps/dpi-backend/src/doctor.ts +17 -4
  3. package/apps/dpi-backend/src/gc-cli.ts +28 -2
  4. package/apps/dpi-backend/src/main.ts +23 -3
  5. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-4Kyozhl0.js +81 -0
  6. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-DxGrKN6X.css → index-BkSQ2clA.css} +1 -1
  7. package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
  8. package/apps/dpi-playground/apps/dpi-playground-fe/src/App.vue +9 -2
  9. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/dialog-escape.ts +13 -0
  10. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/export-bundle.ts +70 -0
  11. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/state-draft.ts +72 -0
  12. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +15 -0
  13. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ContextBar.vue +14 -3
  14. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +82 -69
  15. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ModelPicker.vue +22 -4
  16. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/PromptDialog.vue +3 -0
  17. package/apps/dpi-playground/apps/dpi-playground-fe/src/style.css +19 -0
  18. package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +5 -1
  19. package/apps/dpi-playground/apps/dpi-playground-hub/src/pairing.ts +38 -17
  20. package/apps/dpi-tui/src/main.ts +46 -19
  21. package/bin/dpi.mjs +83 -0
  22. package/package.json +1 -1
  23. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DC0Iicch.js +0 -81
@@ -30,30 +30,55 @@ const USAGE = `usage: dpi-tui [device[:session[:agent]]] [options]
30
30
  --url, --token connect to any dpi-backend directly (also DPI_URL, DPI_TOKEN)
31
31
  --save <id> store a --url device in ~/.dpi/network.sqlite under <id>`;
32
32
 
33
+ /** Run a parser whose failure is a usage error (exit 2), never a raw
34
+ * ERR_PARSE_ARGS_UNKNOWN_OPTION stack — the convention of the other subcommands
35
+ * (R6 cli finding 4: `dpi tui --bogus` used to throw). */
36
+ function parseOrUsage<T>(parse: () => T): T {
37
+ try {
38
+ return parse();
39
+ } catch (e) {
40
+ process.stderr.write(`dpi tui: ${(e as Error).message}\n\n${USAGE}\n`);
41
+ process.exit(2);
42
+ }
43
+ }
44
+
45
+ /** A connect URL must be absolute http(s) — checked at the door so a typo is a
46
+ * one-line error, not `TypeError: Invalid URL` deep in startup (R6 cli finding 3). */
47
+ export function isValidConnectUrl(candidate: string): boolean {
48
+ try {
49
+ const u = new URL(candidate);
50
+ return u.protocol === "http:" || u.protocol === "https:";
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+
33
56
  function fail(message: string): never {
34
57
  process.stderr.write(`${message}\n`);
35
58
  process.exit(1);
36
59
  }
37
60
 
38
- const { values, positionals } = parseArgs({
39
- allowPositionals: true,
40
- options: {
41
- url: { type: "string" },
42
- token: { type: "string" },
43
- save: { type: "string" },
44
- session: { type: "string", short: "s" },
45
- agent: { type: "string", short: "a" },
46
- new: { type: "string" },
47
- cwd: { type: "string" },
48
- model: { type: "string" },
49
- pair: { type: "string" },
50
- hub: { type: "string" },
51
- "hub-url": { type: "string" },
52
- "hub-token": { type: "string" },
53
- force: { type: "boolean" },
54
- help: { type: "boolean", short: "h" },
55
- },
56
- });
61
+ const { values, positionals } = parseOrUsage(() =>
62
+ parseArgs({
63
+ allowPositionals: true,
64
+ options: {
65
+ url: { type: "string" },
66
+ token: { type: "string" },
67
+ save: { type: "string" },
68
+ session: { type: "string", short: "s" },
69
+ agent: { type: "string", short: "a" },
70
+ new: { type: "string" },
71
+ cwd: { type: "string" },
72
+ model: { type: "string" },
73
+ pair: { type: "string" },
74
+ hub: { type: "string" },
75
+ "hub-url": { type: "string" },
76
+ "hub-token": { type: "string" },
77
+ force: { type: "boolean" },
78
+ help: { type: "boolean", short: "h" },
79
+ },
80
+ }),
81
+ );
57
82
  if (values.help) {
58
83
  process.stdout.write(`${USAGE}\n`);
59
84
  process.exit(0);
@@ -64,6 +89,8 @@ const config = tryLoadNetworkConfig(process.env.INIT_CWD ?? process.cwd());
64
89
  if (config) syncConfigToRegistry(config, registry);
65
90
 
66
91
  const url = values.url ?? process.env.DPI_URL;
92
+ // R6 cli finding 3: a bogus --url/DPI_URL crashed later at `new URL(url)` — fail here.
93
+ if (url !== undefined && !isValidConnectUrl(url)) fail("--url must be a valid http(s) URL");
67
94
  const [deviceRef = "", sessionRef = values.session, agentRef = values.agent] = (
68
95
  positionals[0] ?? (url ? "" : (process.env.DPI_DEVICE ?? ""))
69
96
  ).split(":");
package/bin/dpi.mjs CHANGED
@@ -59,6 +59,13 @@ Environment (hub): DPI_HOME, DPI_HUB_PORT, DPI_HUB_HOST, DPI_HUB_PUBLIC_HOST,
59
59
  Environment (device): DPI_HUB_URL, DPI_HOME
60
60
  `;
61
61
 
62
+ const UPDATE_USAGE = `dpi update | upgrade [--check]
63
+
64
+ dpi update --check compare the installed version with the registry, change nothing
65
+ dpi update install the latest published version globally
66
+ (stops and restarts the device daemon so npm can replace files)
67
+ `;
68
+
62
69
  /**
63
70
  * tsx is a dependency of the published package, but a bare repository checkout has it only
64
71
  * inside the per-app node_modules. Try the normal resolution first, then the known local
@@ -92,6 +99,69 @@ async function loadTsx() {
92
99
 
93
100
  const [first, ...rest] = process.argv.slice(2);
94
101
 
102
+ // R6 cli finding 9: every invocation that loads the store prints node:sqlite's
103
+ // ExperimentalWarning — pure noise for a CLI, and a flag a running process
104
+ // cannot take retroactively. When this launcher starts without the
105
+ // suppression flag it relaunches itself ONCE with it. --disable-warning takes
106
+ // the WARNING NAME ("experimental" does not match); any Node that has the
107
+ // flag at all accepts unknown values — worst case nothing is suppressed — so
108
+ // the version gate below is the only compatibility guard needed.
109
+ const EXPERIMENTAL_WARNING_FLAG = "--disable-warning=ExperimentalWarning";
110
+
111
+ /** Relaunch with the warning suppressed. Returns true when THIS process must
112
+ * become a thin wrapper (its only remaining job is to wait for the child). */
113
+ async function quietExperimentalWarning() {
114
+ if (process.execArgv.includes(EXPERIMENTAL_WARNING_FLAG)) return false;
115
+ if (process.env.DPI_WARNINGS_QUIETED === "1") return false;
116
+ const [major, minor] = process.versions.node.split(".").map(Number);
117
+ if (!((major === 22 && minor >= 13) || major > 22)) return false;
118
+ const { spawn } = await import("node:child_process");
119
+ const child = spawn(
120
+ process.execPath,
121
+ [...process.execArgv, EXPERIMENTAL_WARNING_FLAG, fileURLToPath(import.meta.url), ...process.argv.slice(2)],
122
+ {
123
+ stdio: "inherit",
124
+ env: {
125
+ ...process.env,
126
+ DPI_WARNINGS_QUIETED: "1",
127
+ DPI_WRAPPER_PID: String(process.pid),
128
+ },
129
+ },
130
+ );
131
+ // Ctrl-C / service stop must reach the real process, not die with the wrapper.
132
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"])
133
+ process.on(signal, () => child.kill(signal));
134
+ child.on("error", (error) => {
135
+ process.stderr.write(`dpi: relaunch failed: ${error.message}\n`);
136
+ process.exit(1);
137
+ });
138
+ child.on("close", (code, signal) => {
139
+ if (signal) process.kill(process.pid, signal);
140
+ else process.exit(code ?? 0);
141
+ });
142
+ return true;
143
+ }
144
+
145
+ if (await quietExperimentalWarning()) await new Promise(() => {});
146
+
147
+ // The relaunched child must not outlive a SIGKILLed wrapper: forwarded signals
148
+ // cover SIGINT/SIGTERM/SIGHUP, but SIGKILL cannot be caught. A cheap liveness
149
+ // poll on the wrapper closes that hole — if the wrapper is gone, this process
150
+ // is an orphan and terminates itself. unref'd: it never keeps the CLI alive.
151
+ if (process.env.DPI_WRAPPER_PID) {
152
+ const wrapperPid = Number(process.env.DPI_WRAPPER_PID);
153
+ if (Number.isInteger(wrapperPid) && wrapperPid > 0 && wrapperPid !== process.pid) {
154
+ const timer = setInterval(() => {
155
+ try {
156
+ process.kill(wrapperPid, 0);
157
+ } catch {
158
+ process.kill(process.pid, "SIGTERM");
159
+ }
160
+ }, 2_000);
161
+ timer.unref?.();
162
+ }
163
+ }
164
+
95
165
  // Bare `dpi` opens the TUI — the app, not a help screen (convention of the
96
166
  // reference clients: the product IS the terminal UI; subcommands are the extras).
97
167
  const command = !first || first === "tui" ? "tui" : first;
@@ -110,6 +180,19 @@ if (command === "version" || command === "--version" || command === "-v") {
110
180
  }
111
181
 
112
182
  if (command === "update" || command === "upgrade") {
183
+ // R6 cli finding 1: `update` MUTATES the machine (it may stop the daemon and
184
+ // run `npm install -g`), so its argv is checked HERE — before the updater
185
+ // loads — unlike every other subcommand: --help must never self-update, and
186
+ // an unknown dash-arg is a typo the operator must see, not a real update.
187
+ if (commandRest.includes("--help") || commandRest.includes("-h") || commandRest.includes("help")) {
188
+ process.stdout.write(UPDATE_USAGE);
189
+ process.exit(0);
190
+ }
191
+ const unknownFlag = commandRest.find((a) => a.startsWith("-") && a !== "--check" && a !== "-c");
192
+ if (unknownFlag) {
193
+ process.stderr.write(`dpi update: unknown flag '${unknownFlag}'\n\n${UPDATE_USAGE}`);
194
+ process.exit(2);
195
+ }
113
196
  const { readFileSync } = await import("node:fs");
114
197
  const { runUpdate, fetchLatestVersion, spawnNpm, daemonControl } = await import("./update.mjs");
115
198
  const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-durable",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "description": "Durable Pi — the durable agent network: hub web UI, device backend daemon, TUI admin and the shared SDK, packaged as one runnable monorepo install",
5
5
  "license": "MIT",
6
6
  "repository": {