my-durable 0.0.58 → 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 (36) 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/errors.ts +68 -1
  4. package/apps/dpi-backend/src/gc-cli.ts +52 -19
  5. package/apps/dpi-backend/src/gc.ts +3 -1
  6. package/apps/dpi-backend/src/main.ts +23 -3
  7. package/apps/dpi-backend/src/pi-config.ts +15 -6
  8. package/apps/dpi-backend/src/store.ts +220 -22
  9. package/apps/dpi-backend/src/tunnel.ts +24 -2
  10. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-4Kyozhl0.js +81 -0
  11. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-DxGrKN6X.css → index-BkSQ2clA.css} +1 -1
  12. package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
  13. package/apps/dpi-playground/apps/dpi-playground-fe/src/App.vue +9 -2
  14. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/dialog-escape.ts +13 -0
  15. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/export-bundle.ts +70 -0
  16. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/state-draft.ts +72 -0
  17. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +15 -0
  18. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ContextBar.vue +14 -3
  19. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +82 -69
  20. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ModelPicker.vue +22 -4
  21. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/PromptDialog.vue +3 -0
  22. package/apps/dpi-playground/apps/dpi-playground-fe/src/style.css +19 -0
  23. package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +72 -30
  24. package/apps/dpi-playground/apps/dpi-playground-hub/src/mux.ts +13 -2
  25. package/apps/dpi-playground/apps/dpi-playground-hub/src/pairing.ts +38 -17
  26. package/apps/dpi-playground/apps/dpi-playground-hub/src/shares.ts +7 -1
  27. package/apps/dpi-tui/src/app.ts +108 -25
  28. package/apps/dpi-tui/src/commands.ts +16 -8
  29. package/apps/dpi-tui/src/main.ts +46 -19
  30. package/apps/dpi-tui/src/pickers.ts +4 -0
  31. package/apps/dpi-tui/src/scroll.ts +59 -0
  32. package/apps/dpi-tui/src/views.ts +17 -2
  33. package/apps/dpi-tui/src/wrap.ts +42 -0
  34. package/bin/dpi.mjs +83 -0
  35. package/package.json +1 -1
  36. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DC0Iicch.js +0 -81
@@ -0,0 +1,42 @@
1
+ // Display-width transcript wrapping (R5 finding 1). Pure — unit-testable like
2
+ // the views.
3
+ //
4
+ // The old wrap split each line exactly ONCE on UTF-16 code units
5
+ // (`[l.slice(0, w-4), l.slice(w-4)]`): the remainder was never re-wrapped, so
6
+ // pi-tui hard-clipped the tail of every overlong row — a 400-char message
7
+ // showed ~154 chars at 80 columns. And `l.length` counts UTF-16 units, not
8
+ // terminal columns, so CJK/emoji (2 cells each) overflowed their budget and
9
+ // got clipped too.
10
+ //
11
+ // wrapByColumn walks grapheme COLUMNS instead, pi-tui sliceByColumn/truncate
12
+ // semantics (the 0.0.53 panelLine lesson): every visible column lands on some
13
+ // row (no content loss), and a wide char that would straddle the budget moves
14
+ // whole to the next row (strict slice) instead of being clipped mid-glyph.
15
+ import { sliceByColumn, visibleWidth } from "@earendil-works/pi-tui";
16
+
17
+ /**
18
+ * Hard-wrap `text` on newlines, then to a display-column budget per row, and
19
+ * indent every row. Budget = width - 4 - indent, the old `w - 4` margin kept
20
+ * (with the indent now counted) so wrapped rows can never reach the frame's
21
+ * hard-clip edge even if a grapheme measures one cell wide in practice.
22
+ */
23
+ export function wrapByColumn(text: string, width: number, indent = " "): string[] {
24
+ const budget = Math.max(4, width - 4 - visibleWidth(indent));
25
+ const out: string[] = [];
26
+ for (const line of text.split("\n")) {
27
+ const total = visibleWidth(line);
28
+ if (total <= budget) {
29
+ out.push(line);
30
+ continue;
31
+ }
32
+ let col = 0;
33
+ while (col < total) {
34
+ const part = sliceByColumn(line, col, budget, true);
35
+ const partWidth = visibleWidth(part);
36
+ if (partWidth <= 0) break; // only zero-width columns remain — nothing visible lost
37
+ out.push(part);
38
+ col += partWidth;
39
+ }
40
+ }
41
+ return out.map((l) => indent + l);
42
+ }
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.58",
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": {