my-durable 0.0.57 → 0.0.59

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 (32) hide show
  1. package/apps/dpi-backend/scripts/check-contract.mjs +9 -2
  2. package/apps/dpi-backend/src/env-vars.ts +10 -1
  3. package/apps/dpi-backend/src/errors.ts +71 -2
  4. package/apps/dpi-backend/src/gc-cli.ts +24 -17
  5. package/apps/dpi-backend/src/gc.ts +3 -1
  6. package/apps/dpi-backend/src/git.ts +26 -6
  7. package/apps/dpi-backend/src/idempotency.ts +47 -1
  8. package/apps/dpi-backend/src/notify-sinks.ts +42 -8
  9. package/apps/dpi-backend/src/pi-config.ts +43 -8
  10. package/apps/dpi-backend/src/routes.ts +6 -2
  11. package/apps/dpi-backend/src/store.ts +285 -18
  12. package/apps/dpi-backend/src/tunnel.ts +24 -2
  13. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-C9ulm0b-.js → index-DC0Iicch.js} +7 -7
  14. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-C8I93zWz.css → index-DxGrKN6X.css} +1 -1
  15. package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
  16. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +28 -4
  17. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ModelPicker.vue +13 -4
  18. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/OfflinePanel.vue +6 -6
  19. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TreeRow.vue +20 -6
  20. package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +67 -29
  21. package/apps/dpi-playground/apps/dpi-playground-hub/src/mux.ts +13 -2
  22. package/apps/dpi-playground/apps/dpi-playground-hub/src/shares.ts +7 -1
  23. package/apps/dpi-sdk/src/node/ops.ts +1 -0
  24. package/apps/dpi-tui/src/app.ts +217 -49
  25. package/apps/dpi-tui/src/commands.ts +57 -22
  26. package/apps/dpi-tui/src/pickers.ts +55 -18
  27. package/apps/dpi-tui/src/scroll.ts +59 -0
  28. package/apps/dpi-tui/src/views.ts +17 -2
  29. package/apps/dpi-tui/src/wrap.ts +42 -0
  30. package/bin/update.mjs +2 -1
  31. package/package.json +1 -1
  32. package/scripts/verify.mjs +7 -0
@@ -47,13 +47,17 @@ const busy = computed(() => session.value?.busy || agent.value?.busy);
47
47
  * oldest devices predate the rename and report `durableVersion` instead of
48
48
  * `packageVersion` — they are exactly the ones the badge exists for. */
49
49
  const behind = computed(() => {
50
- const info = device.value?.info as { packageVersion?: string; durableVersion?: string } | undefined;
50
+ const info = device.value?.info as
51
+ | { packageVersion?: string; durableVersion?: string }
52
+ | undefined;
51
53
  const theirs = info?.packageVersion ?? info?.durableVersion;
52
54
  const ours = hubVersion.value;
53
55
  return Boolean(theirs && ours && ours !== "unknown" && theirs !== ours);
54
56
  });
55
57
  const theirVersion = computed(() => {
56
- const info = device.value?.info as { packageVersion?: string; durableVersion?: string } | undefined;
58
+ const info = device.value?.info as
59
+ | { packageVersion?: string; durableVersion?: string }
60
+ | undefined;
57
61
  return info?.packageVersion ?? info?.durableVersion ?? "?";
58
62
  });
59
63
  const statusText = computed(() => {
@@ -87,8 +91,11 @@ const label = computed(
87
91
  () => device.value?.name ?? device.value?.id ?? session.value?.name ?? agent.value?.name ?? "",
88
92
  );
89
93
  const title = computed(() => {
90
- if (device.value)
91
- return `${device.value.name} · ${device.value.url}${device.value.error ? `\n${device.value.error}` : ""}`;
94
+ // A tunnel device has no url (NetworkDevice.url is nullable) — never render `· null`.
95
+ if (device.value) {
96
+ const d = device.value;
97
+ return `${d.name}${d.url ? ` · ${d.url}` : ""}${d.error ? `\n${d.error}` : ""}`;
98
+ }
92
99
  if (session.value) return `${session.value.name}\n${session.value.cwd}`;
93
100
  const a = agent.value!;
94
101
  return a.kind === "fork"
@@ -176,7 +183,9 @@ const title = computed(() => {
176
183
  <FolderOpen class="ico" :size="16" />
177
184
  <b class="name">{{ label }}</b>
178
185
  <span class="path">…/{{ session.cwd.split("/").filter(Boolean).at(-1) }}</span>
179
- <span v-if="branch" class="branch" :title="`git branch of ${session.cwd}`">⎇ {{ branch }}</span>
186
+ <span v-if="branch" class="branch" :title="`git branch of ${session.cwd}`"
187
+ >⎇ {{ branch }}</span
188
+ >
180
189
  <span
181
190
  v-if="session.model"
182
191
  class="tag"
@@ -250,4 +259,9 @@ const title = computed(() => {
250
259
  </div>
251
260
  </template>
252
261
 
253
- <style scoped>.bulk-check { margin-left: 2px; flex-shrink: 0; }</style>
262
+ <style scoped>
263
+ .bulk-check {
264
+ margin-left: 2px;
265
+ flex-shrink: 0;
266
+ }
267
+ </style>
@@ -130,6 +130,14 @@ const app = express();
130
130
  // non-loopback direct connection is ignored (proxy-addr semantics).
131
131
  app.set("trust proxy", isTrustedProxy);
132
132
  app.disable("x-powered-by");
133
+ // Case-sensitive routes, matching the device: "/API/NETWORK" is a miss, not a
134
+ // silent alias of /api/network (route uniformity with the 0.0.58 device fix).
135
+ // Every hub caller already spells the mount lowercase — FE client (/api/...),
136
+ // TUI hub-feed/hub-mux (api/network, api/stream), and the public pairing
137
+ // ingress below; a case variant never carried different auth (audit R5).
138
+ // The app setting's name is Express's spelled-out form — "caseSensitive" is
139
+ // the Router option, silently ignored here (caught by the R5 test).
140
+ app.set("case sensitive routing", true);
133
141
  // Every answer is non-sniffable; the admin API is never cacheable (it carries pairing codes and, on the
134
142
  // pairing routes, a credential). Registered first so that refusals made further down carry them too.
135
143
  app.use((req, res, next) => {
@@ -343,6 +351,39 @@ app.post(
343
351
  },
344
352
  );
345
353
 
354
+ // ------------------------------------------------ conversation shares
355
+ // The shell (which holds the tunnel credentials) uploads prepared transcripts;
356
+ // the hub mints a tokenized PUBLIC link. The token is the capability, every
357
+ // share expires (retention is explicit — the checklist row demanded that
358
+ // decision up front), and the admin routes can kill one early.
359
+ //
360
+ // Registered BEFORE the global /api chain (same pattern as the pairing
361
+ // ingress): the chain's 256 KiB parser consumed the body first, so a 300 KB
362
+ // share 413'd before this route's 10 MiB parser ever ran (the 2 MB/agent,
363
+ // 8 MB/total limits in shares.ts were unreachable), and its apiRate bucket
364
+ // was charged twice. The full guard stack travels with the route.
365
+ const shares = await Shares.open(join(dpiHome(), "shares"));
366
+ app.post(
367
+ "/api/shares",
368
+ denialLogging(audit),
369
+ guard(allowedHosts),
370
+ apiRate,
371
+ express.json({ limit: "10mb" }),
372
+ adminAuth,
373
+ (req, res) => {
374
+ const body = req.body ?? {};
375
+ void shares
376
+ .create({ title: String(body.title ?? ""), agents: Array.isArray(body.agents) ? body.agents : [] })
377
+ .then((meta) =>
378
+ res.status(201).json({ token: meta.token, url: `/share/${meta.token}`, expiresAt: meta.expiresAt }),
379
+ )
380
+ .catch((e: unknown) => {
381
+ if (e instanceof ShareError) return res.status(400).json(err("invalid", e.message));
382
+ throw e;
383
+ });
384
+ },
385
+ );
386
+
346
387
  // Admin /api surface: guarded, rate-bucketed per real client IP, 256 KiB JSON,
347
388
  // and behind the admin credential (cookie or bearer).
348
389
  app.use(
@@ -456,46 +497,28 @@ app.put(
456
497
  res.json({ ok: true });
457
498
  }),
458
499
  );
459
- // ------------------------------------------------ conversation shares
460
- // The shell (which holds the tunnel credentials) uploads prepared transcripts;
461
- // the hub mints a tokenized PUBLIC link. The token is the capability, every
462
- // share expires (retention is explicit — the checklist row demanded that
463
- // decision up front), and the admin routes can kill one early.
464
- const shares = await Shares.open(join(dpiHome(), "shares"));
465
- app.post(
466
- "/api/shares",
467
- denialLogging(audit),
468
- apiRate,
469
- express.json({ limit: "10mb" }),
470
- adminAuth,
471
- (req, res) => {
472
- const body = req.body ?? {};
473
- void shares
474
- .create({ title: String(body.title ?? ""), agents: Array.isArray(body.agents) ? body.agents : [] })
475
- .then((meta) =>
476
- res.status(201).json({ token: meta.token, url: `/share/${meta.token}`, expiresAt: meta.expiresAt }),
477
- )
478
- .catch((e: unknown) => {
479
- if (e instanceof ShareError) return res.status(400).json(err("invalid", e.message));
480
- throw e;
481
- });
482
- },
483
- );
500
+ // Share admin reads/kill (the POST lives above the global chain — its body
501
+ // needs the 10 MiB parser); the chain's adminAuth + 256 KiB parser cover these.
484
502
  app.get("/api/shares", adminAuth, (_req, res) => void shares.list().then((list) => res.json({ shares: list })));
485
503
  app.delete("/api/shares/:token", adminAuth, (req, res) =>
486
504
  void shares.remove(String(req.params.token ?? "")).then((removed) => res.json({ removed })),
487
505
  );
488
506
  // The public page: transcripts only, no app shell, no scripts, inline-styled.
507
+ // Framing is refused explicitly: frame-ancestors is NOT a fetch directive, so
508
+ // it does not fall back to default-src and must be spelled out (a share page
509
+ // is public content — a frame is a clickjacking channel).
489
510
  app.get("/share/:token", (req, res) => {
490
511
  void shares.get(String(req.params.token ?? "")).then((doc) => {
491
512
  if (!doc) {
492
513
  res.status(404);
493
514
  res.set("Content-Type", "text/html; charset=utf-8");
494
- res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'");
515
+ res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'");
516
+ res.set("X-Frame-Options", "DENY");
495
517
  return res.send(renderShareNotFound());
496
518
  }
497
519
  res.set("Content-Type", "text/html; charset=utf-8");
498
- res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'");
520
+ res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'");
521
+ res.set("X-Frame-Options", "DENY");
499
522
  res.set("Cache-Control", "no-store");
500
523
  res.send(renderSharePage(doc));
501
524
  });
@@ -546,11 +569,26 @@ if (args.includes("--dev")) {
546
569
  });
547
570
  next();
548
571
  });
549
- app.use(express.static(resolve(appDir, "apps/dpi-playground-fe/dist")));
572
+ const dist = resolve(appDir, "apps/dpi-playground-fe/dist");
573
+ // Vite content-addresses /assets/* filenames, so they can cache forever; the
574
+ // documents that reference them (index.html and the SPA shell) must
575
+ // revalidate or a deploy would serve stale HTML pointing at dead hashes.
576
+ app.use("/assets", express.static(join(dist, "assets"), { immutable: true, maxAge: "365d" }));
577
+ app.use(
578
+ express.static(dist, {
579
+ setHeaders: (res, filePath) => {
580
+ if (filePath.endsWith(".html")) res.setHeader("Cache-Control", "no-cache");
581
+ },
582
+ }),
583
+ );
550
584
  app.get("/{*path}", (req, res, next) => {
551
585
  // A path that names a file is an asset that does not exist, not a page of the app.
552
586
  if (extname(req.path)) return void next();
553
- res.sendFile(resolve(appDir, "apps/dpi-playground-fe/dist/index.html"));
587
+ // An /api-shaped path is never a page — not even case-mangled (uniformity
588
+ // with the device: /API/NETWORK is a 404 miss, not the app shell).
589
+ if (/^\/api(\/|$)/i.test(req.path)) return void next();
590
+ res.setHeader("Cache-Control", "no-cache");
591
+ res.sendFile(join(dist, "index.html"));
554
592
  });
555
593
  }
556
594
  app.use((_req, res) => res.status(404).json(err("not_found", "Not found")));
@@ -56,11 +56,17 @@ const KEY =
56
56
 
57
57
  const invalidKey = () => Object.assign(Error("Invalid subscription key"), { status: 400 });
58
58
 
59
+ /** R5 cap mirror: the device's SUBSCRIBE_PATH_OK (dpi-backend/src/tunnel.ts) accepts at most 256
60
+ * characters after `?`. A docs list longer than that would open a subscription the device refuses —
61
+ * refuse it HERE (400 to the PUT caller) instead of signing the browser up for a silent starvation. */
62
+ const SUB_QUERY_MAX_CHARS = 256;
63
+
59
64
  export function parseSubKey(key: string) {
60
65
  const m = key.match(KEY);
61
66
  if (!m) throw invalidKey();
62
67
  const [, deviceId, scope, a, b, docs] = m;
63
68
  const q = docs ? `?docs=${docs}` : "";
69
+ if (q.length - 1 > SUB_QUERY_MAX_CHARS) throw invalidKey();
64
70
  const enc = (part: string) => {
65
71
  try {
66
72
  return encodeURIComponent(decodeURIComponent(part));
@@ -182,6 +188,12 @@ export class StreamMux {
182
188
  const wanted = new Map(
183
189
  (keys as string[]).filter((k) => k !== "network").map((k) => [k, parseSubKey(k)]),
184
190
  );
191
+ // All-or-nothing like the parse above (R5): every device the PUT names must exist BEFORE
192
+ // anything is closed or opened, so an unknown device cannot leave upstreams opened and
193
+ // reader slots acquired by earlier keys in the same PUT dangling behind a 404.
194
+ for (const [key, sub] of wanted)
195
+ if (!stream.upstreams.has(key) && !this.registry.get(sub.deviceId))
196
+ throw Object.assign(Error(`No device ${sub.deviceId}`), { status: 404 });
185
197
  for (const [key, ctl] of stream.upstreams)
186
198
  if (!wanted.has(key)) {
187
199
  ctl.abort();
@@ -190,10 +202,9 @@ export class StreamMux {
190
202
  }
191
203
  for (const [key, sub] of wanted)
192
204
  if (!stream.upstreams.has(key)) {
193
- if (!this.registry.get(sub.deviceId))
194
- throw Object.assign(Error(`No device ${sub.deviceId}`), { status: 404 });
195
205
  // Reader caps (04 §8): 128/device incl. the monitor's reader, 1024
196
206
  // hub-wide. A rejected NEW reader must not disturb existing readers.
207
+ // (The registry check ran before any mutation — see above.)
197
208
  if (
198
209
  this.readerCount(sub.deviceId) >= READERS_PER_DEVICE ||
199
210
  this.hubReaderCount() >= READERS_PER_HUB
@@ -203,8 +203,14 @@ export class Shares {
203
203
  // Rendered server-side: the share page is public and must not load the app
204
204
  // shell (which holds credentials), any script, or any external asset.
205
205
 
206
+ // Text nodes get the entity treatment for the HTML metacharacters, and C0/C1
207
+ // controls are STRIPPED (except tab/newline/carriage-return, which transcript
208
+ // text legitimately carries): a U+0001 or U+0007 in a markdown paste lands in
209
+ // the page raw otherwise — layout damage a reader cannot see or edit.
206
210
  const escapeHtml = (text: string) =>
207
- text.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]!);
211
+ text
212
+ .replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/g, "")
213
+ .replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]!);
208
214
 
209
215
  const PAGE_STYLE = `:root{color-scheme:dark}body{margin:0;background:#16181d;color:#e6e6e6;font:16px/1.6 ui-sans-serif,system-ui,sans-serif}
210
216
  main{max-width:52rem;margin:0 auto;padding:2rem 1rem}h1{font-size:1.3rem;margin:0 0 .25rem}
@@ -25,6 +25,7 @@ export function run(cmd: string, args: string[], options: RunOptions = {}): Prom
25
25
  cwd: options.cwd,
26
26
  env: options.env ?? process.env,
27
27
  stdio: ["pipe", "pipe", "pipe"],
28
+ windowsHide: true,
28
29
  });
29
30
  let stdout = "";
30
31
  let stderr = "";