my-durable 0.0.59 → 0.0.61

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 (27) hide show
  1. package/apps/dpi-backend/src/daemon.ts +55 -1
  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 +29 -3
  5. package/apps/dpi-backend/src/salvage.ts +187 -0
  6. package/apps/dpi-backend/src/store.ts +64 -8
  7. package/apps/dpi-backend/src/vitals.ts +72 -0
  8. package/apps/dpi-backend/src/zip.ts +17 -0
  9. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-4Kyozhl0.js +81 -0
  10. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-DxGrKN6X.css → index-BkSQ2clA.css} +1 -1
  11. package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
  12. package/apps/dpi-playground/apps/dpi-playground-fe/src/App.vue +9 -2
  13. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/dialog-escape.ts +13 -0
  14. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/export-bundle.ts +70 -0
  15. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/state-draft.ts +72 -0
  16. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +15 -0
  17. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ContextBar.vue +14 -3
  18. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +82 -69
  19. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ModelPicker.vue +22 -4
  20. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/PromptDialog.vue +3 -0
  21. package/apps/dpi-playground/apps/dpi-playground-fe/src/style.css +19 -0
  22. package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +5 -1
  23. package/apps/dpi-playground/apps/dpi-playground-hub/src/pairing.ts +38 -17
  24. package/apps/dpi-tui/src/main.ts +46 -19
  25. package/bin/dpi.mjs +83 -0
  26. package/package.json +1 -1
  27. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DC0Iicch.js +0 -81
@@ -0,0 +1,72 @@
1
+ // Draft editing for the device-wide App State JSON (Inspector's State tab).
2
+ // A draft always belongs to one device feed at one revision: switching devices
3
+ // resets it unconditionally (a context loss, never a silent cross-device
4
+ // write), a remote revision change while dirty is a conflict the user must
5
+ // resolve, and the text is pre-validated (debounced) with the same checks the
6
+ // device runs on save.
7
+ import { computed, ref, watch, type Ref } from "vue";
8
+ import { changeState, type AppState } from "@sdk/app-state";
9
+ import { message } from "./hub";
10
+
11
+ export type SharedStateFeed = { value: AppState; revision: number } | undefined;
12
+
13
+ /** The same checks the device runs on save — a root update through the SDK's
14
+ * changeState: JSON-object shape, the nesting and size limits, reserved
15
+ * field names. Empty when the text is a saveable state document. */
16
+ export function draftProblem(text: string): string {
17
+ try {
18
+ const value: unknown = JSON.parse(text);
19
+ if (!value || Array.isArray(value) || typeof value !== "object")
20
+ throw Error("App State must be a JSON object.");
21
+ changeState({}, { operation: "update", path: "", value: value as AppState });
22
+ return "";
23
+ } catch (e) {
24
+ return message(e);
25
+ }
26
+ }
27
+
28
+ export function useStateDraft(shared: Ref<SharedStateFeed>, deviceId: Ref<string | undefined>) {
29
+ const draft = ref("");
30
+ const baseline = ref("");
31
+ const revision = ref(0);
32
+ const draftDevice = ref<string>();
33
+ const saving = ref(false);
34
+ /** The draft's validation problem, refreshed (debounced) as the user types. */
35
+ const problem = ref("");
36
+ const dirty = computed(() => draft.value !== baseline.value);
37
+ /** The draft was loaded from another device — possible for one tick while a
38
+ * device switch settles; never a saveable state. */
39
+ const deviceChanged = computed(() => dirty.value && draftDevice.value !== deviceId.value);
40
+ const conflict = computed(
41
+ () => dirty.value && (deviceChanged.value || shared.value?.revision !== revision.value),
42
+ );
43
+
44
+ function reset() {
45
+ draft.value = JSON.stringify(shared.value?.value ?? {}, null, 2);
46
+ baseline.value = draft.value;
47
+ revision.value = shared.value?.revision ?? 0;
48
+ draftDevice.value = deviceId.value;
49
+ problem.value = "";
50
+ }
51
+ /** Adopt a successful save's result: the saved text becomes the new
52
+ * baseline at the device's new revision. */
53
+ function commit(value: unknown, atRevision: number) {
54
+ draft.value = JSON.stringify(value, null, 2);
55
+ baseline.value = draft.value;
56
+ revision.value = atRevision;
57
+ problem.value = "";
58
+ }
59
+ // A clean draft follows the feed; a dirty one keeps the user's text until a
60
+ // new revision turns it into a conflict.
61
+ watch(shared, () => !dirty.value && reset(), { immediate: true });
62
+ // A device switch is always a context loss: drop the draft, dirty or not.
63
+ watch(deviceId, () => reset());
64
+ // Pre-validate as the user types (debounced) so the depth/size limits
65
+ // surface before the Save click, not after it.
66
+ let timer: ReturnType<typeof setTimeout> | undefined;
67
+ watch(draft, () => {
68
+ clearTimeout(timer);
69
+ timer = setTimeout(() => (problem.value = dirty.value ? draftProblem(draft.value) : ""), 250);
70
+ });
71
+ return { draft, dirty, conflict, deviceChanged, saving, problem, revision, reset, commit };
72
+ }
@@ -243,6 +243,21 @@ export const currentModel = computed(() => {
243
243
  const m = agentState.value.agent.model;
244
244
  return models.value.find((x) => x.provider === m?.provider && x.id === m?.modelId);
245
245
  });
246
+ /** The configured model with provenance — the agent's model when set, else the
247
+ * model the session was created with. Raw ids: the pair may sit outside this
248
+ * device's catalog (picked on another device, or a newer catalog there), in
249
+ * which case modelInCatalog is undefined and the UI must say so instead of
250
+ * rendering as if no model were picked. */
251
+ export const sessionModel = computed(() => {
252
+ const m = agentState.value.agent.model;
253
+ if (m?.modelId) return m;
254
+ const s = sessionSummary.value;
255
+ return s?.model ? { provider: s.provider ?? "", modelId: s.model } : undefined;
256
+ });
257
+ export const modelInCatalog = computed(() => {
258
+ const m = sessionModel.value;
259
+ return m ? models.value.find((x) => x.provider === m.provider && x.id === m.modelId) : undefined;
260
+ });
246
261
 
247
262
  /** Tools and extensions come from GET agent (not streamed); refresh on selection and config changes. */
248
263
  export const detail = shallowRef<AgentDetail>();
@@ -13,8 +13,9 @@ import {
13
13
  import {
14
14
  agentState,
15
15
  attempt,
16
- currentModel,
16
+ modelInCatalog,
17
17
  sessionHandle,
18
+ sessionModel,
18
19
  sessionSummary,
19
20
  ui,
20
21
  } from "../client/store";
@@ -29,7 +30,14 @@ const k = (n: number) =>
29
30
  : n >= 1000
30
31
  ? `${(n / 1000).toFixed(1)}k`
31
32
  : String(n);
32
- const window = computed(() => currentModel.value?.contextWindow ?? 0);
33
+ const window = computed(() => modelInCatalog.value?.contextWindow ?? 0);
34
+ /** A model IS set but this device's catalog does not list it (picked on
35
+ * another device, or a newer catalog there): raw ids plus a note — never the
36
+ * pick-a-model prompt, which reads as "nothing chosen". */
37
+ const offCatalog = computed(() => {
38
+ const m = sessionModel.value;
39
+ return m && !modelInCatalog.value ? `${m.provider ? `${m.provider} / ` : ""}${m.modelId}` : "";
40
+ });
33
41
 
34
42
  /** The last reply's prompt plus output: what the next request starts from. */
35
43
  const used = computed(() => {
@@ -145,7 +153,10 @@ function key(which: "auto" | "wait", e: KeyboardEvent) {
145
153
  <Info :size="16" />Details
146
154
  </button>
147
155
  </div>
148
- <div v-if="!window" class="hint">Pick a model to see its context window.</div>
156
+ <div v-if="offCatalog" class="hint">
157
+ {{ offCatalog }} — not in this device's catalog, so its context window is unknown here.
158
+ </div>
159
+ <div v-else-if="!window" class="hint">Pick a model to see its context window.</div>
149
160
  <template v-else>
150
161
  <div class="context-numbers">
151
162
  <strong>{{ k(used) }}</strong
@@ -17,6 +17,7 @@ import {
17
17
  Pencil,
18
18
  Server,
19
19
  ShieldCheck,
20
+ Share2,
20
21
  Wrench,
21
22
  PanelLeftClose,
22
23
  PanelLeftOpen,
@@ -40,6 +41,8 @@ import ExtensionsPanel from "./ExtensionsPanel.vue";
40
41
  import ContextBar from "./ContextBar.vue";
41
42
  import { deviceClient, hub, message } from "../client/hub";
42
43
  import { toolSignature } from "../client/signature";
44
+ import { useExportBundle } from "../client/export-bundle";
45
+ import { useStateDraft } from "../client/state-draft";
43
46
  import {
44
47
  agentHandle,
45
48
  agentState,
@@ -49,6 +52,7 @@ import {
49
52
  detail,
50
53
  device,
51
54
  deviceFeed,
55
+ deviceId,
52
56
  hideInspector,
53
57
  icon,
54
58
  inspectorExpanded,
@@ -59,6 +63,7 @@ import {
59
63
  selected,
60
64
  session,
61
65
  sessionHandle,
66
+ sessionModel,
62
67
  sessionSummary,
63
68
  showInspector,
64
69
  tasks,
@@ -94,7 +99,6 @@ const usageRows = computed(() => [
94
99
  { label: "Cache write", tokens: usage.value.cacheWrite, cost: usage.value.cacheWriteCost },
95
100
  ]);
96
101
  const background = computed(() => tasks.value.filter((t) => t.background).length);
97
- const exporting = ref(false);
98
102
 
99
103
  function configure(
100
104
  patch: Parameters<NonNullable<typeof agentHandle.value>["configure"]>[0],
@@ -114,8 +118,12 @@ async function downloadTranscript() {
114
118
  const summary = sessionSummary.value;
115
119
  if (!dev || !summary) return;
116
120
  try {
117
- const r = await deviceClient(dev.id).agent(summary.id, selected.value?.agentId ?? 1).transcript("markdown");
118
- const blob = new Blob([typeof r === "string" ? r : JSON.stringify(r)], { type: "text/markdown" });
121
+ const r = await deviceClient(dev.id)
122
+ .agent(summary.id, selected.value?.agentId ?? 1)
123
+ .transcript("markdown");
124
+ const blob = new Blob([typeof r === "string" ? r : JSON.stringify(r)], {
125
+ type: "text/markdown",
126
+ });
119
127
  const a = document.createElement("a");
120
128
  a.href = URL.createObjectURL(blob);
121
129
  a.download = `${summary.name.replace(/[^\w.-]+/g, "_") || "session"}-${summary.id.slice(0, 8)}.md`;
@@ -128,28 +136,14 @@ async function downloadTranscript() {
128
136
  }
129
137
 
130
138
  /** Whole-session bundle (Wave 1b): manifest + record + every agent's
131
- * transcript and config, zipped on the device (base64 over the tunnel). */
132
- async function downloadBundle() {
133
- const dev = device.value;
134
- const summary = sessionSummary.value;
135
- if (!dev || !summary) return;
136
- exporting.value = true;
137
- try {
138
- const r = await deviceClient(dev.id).exportSession(summary.id);
139
- const bytes = Uint8Array.from(atob(r.base64), (c) => c.charCodeAt(0));
140
- const online = URL.createObjectURL(new Blob([bytes], { type: r.mime || "application/zip" }));
141
- const a = document.createElement("a");
142
- a.href = online;
143
- a.download = r.filename;
144
- a.click();
145
- URL.revokeObjectURL(online);
146
- notify(`Bundle downloaded (${Math.max(1, Math.round(r.bytes / 1024))} KiB).`);
147
- } catch (e) {
148
- notify(`bundle export failed: ${message(e).slice(0, 120)}`);
149
- } finally {
150
- exporting.value = false;
151
- }
152
- }
139
+ * transcript and config, zipped on the device (base64 over the tunnel). The
140
+ * loop lives in client/export-bundle.ts: a failure stays inline here with a
141
+ * retry instead of living only in a vanishing toast. */
142
+ const {
143
+ exporting: exportingBundle,
144
+ error: bundleError,
145
+ run: downloadBundle,
146
+ } = useExportBundle(computed(() => ({ device: device.value, summary: sessionSummary.value })));
153
147
 
154
148
  /**
155
149
  * Conversation share (Wave 3): upload this session's transcripts to the hub
@@ -175,10 +169,15 @@ function shareTranscript() {
175
169
  for (const agent of agents) {
176
170
  const r = await client.agent(summary.id, agent.id).transcript("markdown");
177
171
  const text =
178
- typeof r === "string" ? r : ((r as { text?: string }).text ?? JSON.stringify(r, null, 2));
172
+ typeof r === "string"
173
+ ? r
174
+ : ((r as { text?: string }).text ?? JSON.stringify(r, null, 2));
179
175
  docs.push({ name: agent.name || `agent ${agent.id}`, markdown: text });
180
176
  }
181
- const share = await hub.createShare({ title: `${summary.name} · ${dev.name}`, agents: docs });
177
+ const share = await hub.createShare({
178
+ title: `${summary.name} · ${dev.name}`,
179
+ agents: docs,
180
+ });
182
181
  const url = `${location.origin}${share.url}`;
183
182
  await navigator.clipboard?.writeText(url).catch(() => {});
184
183
  notify(`Share link copied — expires ${share.expiresAt.slice(0, 10)}.`);
@@ -224,14 +223,9 @@ watch(
224
223
  },
225
224
  { immediate: true },
226
225
  );
227
- /** The current model with provenance: the agent's configured model when set,
228
- * else the model the session was created with (SessionSummary). */
229
- const sessionModel = computed(() => {
230
- const m = agentState.value.agent.model;
231
- if (m?.modelId) return m;
232
- const s = sessionSummary.value;
233
- return s?.model ? { provider: s.provider ?? "", modelId: s.model } : undefined;
234
- });
226
+ /** The current model with provenance (store): the agent's configured model
227
+ * when set, else the model the session was created with — raw ids, which may
228
+ * not be in this device's catalog. */
235
229
  /** Longest registered root wins — the same rule the device applies on create. */
236
230
  const modelIsDefault = computed(() => {
237
231
  const m = sessionModel.value;
@@ -258,22 +252,21 @@ const modelLine = computed(
258
252
  // ------------------------------------------------------------ App State (device-wide document)
259
253
 
260
254
  const shared = deviceFeed.sharedState;
261
- const stateDraft = ref("");
262
- const stateBaseline = ref("");
263
- const stateDraftRevision = ref(0);
255
+ /** The draft belongs to one device feed at one revision (client/state-draft):
256
+ * a device switch resets it unconditionally — never a cross-device write —
257
+ * and the text is pre-validated (debounced) with the SDK's own checks. */
258
+ const {
259
+ draft: stateDraft,
260
+ dirty: stateDirty,
261
+ conflict: stateConflict,
262
+ deviceChanged: stateDeviceChanged,
263
+ problem: stateProblem,
264
+ revision: stateDraftRevision,
265
+ reset: resetStateDraft,
266
+ commit: commitStateDraft,
267
+ } = useStateDraft(shared, deviceId);
264
268
  const stateSaving = ref(false);
265
269
  const stateError = ref("");
266
- const stateDirty = computed(() => stateDraft.value !== stateBaseline.value);
267
- const stateConflict = computed(
268
- () => stateDirty.value && shared.value?.revision !== stateDraftRevision.value,
269
- );
270
- function resetStateDraft() {
271
- stateDraft.value = json(shared.value?.value ?? {});
272
- stateBaseline.value = stateDraft.value;
273
- stateDraftRevision.value = shared.value?.revision ?? 0;
274
- stateError.value = "";
275
- }
276
- watch(shared, () => !stateDirty.value && resetStateDraft(), { immediate: true });
277
270
 
278
271
  async function editState(change: StateChange) {
279
272
  if (stateSaving.value || !agentHandle.value) return;
@@ -288,7 +281,7 @@ async function editState(change: StateChange) {
288
281
  }
289
282
  }
290
283
  async function saveStateJson() {
291
- if (stateSaving.value || !agentHandle.value) return;
284
+ if (stateSaving.value || stateConflict.value || !agentHandle.value) return;
292
285
  stateError.value = "";
293
286
  stateSaving.value = true;
294
287
  try {
@@ -301,9 +294,7 @@ async function saveStateJson() {
301
294
  value,
302
295
  expectedRevision: stateDraftRevision.value,
303
296
  });
304
- stateDraft.value = json(saved.value);
305
- stateBaseline.value = stateDraft.value;
306
- stateDraftRevision.value = saved.revision;
297
+ commitStateDraft(saved.value, saved.revision);
307
298
  notify("Shared App State saved.");
308
299
  } catch (e) {
309
300
  stateError.value = message(e);
@@ -385,23 +376,23 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
385
376
  aria-label="Rename session"
386
377
  @click="renameSession"
387
378
  >
388
- <Pencil :size="18" />
389
- </button><button
379
+ <Pencil :size="18" /></button
380
+ ><button
390
381
  class="icon-button"
391
382
  title="Download transcript (markdown)"
392
383
  aria-label="Download transcript"
393
384
  @click="downloadTranscript"
394
385
  >
395
- <Download :size="18" />
396
- </button><button
386
+ <Download :size="18" /></button
387
+ ><button
397
388
  class="icon-button"
398
389
  title="Download session bundle (.zip: manifest, transcripts, configs)"
399
390
  aria-label="Download session bundle"
400
- :disabled="exporting"
391
+ :disabled="exportingBundle"
401
392
  @click="downloadBundle"
402
393
  >
403
- <PackageOpen :size="18" />
404
- </button><button
394
+ <PackageOpen :size="18" /></button
395
+ ><button
405
396
  class="icon-button"
406
397
  title="Share a public read-only link to this transcript"
407
398
  aria-label="Share transcript"
@@ -425,9 +416,17 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
425
416
  <span class="status-pill" :class="{ working: busy }"
426
417
  ><i />{{ busy ? "Working" : "Idle" }}</span
427
418
  ><span v-if="background" class="background-pill">{{ background }} background</span
428
- ><span class="saved" :title="device?.id"><Server :size="18" />{{ device?.name ?? device?.id }}</span>
419
+ ><span class="saved" :title="device?.id"
420
+ ><Server :size="18" />{{ device?.name ?? device?.id }}</span
421
+ >
429
422
  <TunnelStatusBar v-if="device" :device="device" />
430
423
  </div>
424
+ <p v-if="bundleError" class="message-error" role="alert">
425
+ {{ bundleError }}
426
+ <button class="small" :disabled="exportingBundle" @click="downloadBundle">
427
+ retry
428
+ </button>
429
+ </p>
431
430
  </section>
432
431
  <TokenManager v-if="device" :device="device" />
433
432
  <section class="model-section">
@@ -510,9 +509,10 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
510
509
  <Braces :size="18" />
511
510
  </div>
512
511
  <p class="hint app-state-description">
513
- One shared JSON object for every agent, session and fork on {{ device?.name ?? device?.id }}. You and
514
- your agents can read, create, update or delete values and fields. Changes appear live
515
- and persist across closed browsers, interrupted agents and backend restarts.
512
+ One shared JSON object for every agent, session and fork on
513
+ {{ device?.name ?? device?.id }}. You and your agents can read, create, update or delete
514
+ values and fields. Changes appear live and persist across closed browsers, interrupted
515
+ agents and backend restarts.
516
516
  </p>
517
517
  <textarea
518
518
  v-model="stateDraft"
@@ -522,10 +522,16 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
522
522
  :disabled="stateSaving || !shared"
523
523
  rows="12"
524
524
  />
525
+ <p class="hint state-limits">
526
+ One JSON object, at most 24 levels of nesting and 100,000 characters, checked as you
527
+ type.
528
+ </p>
525
529
  <div class="state-json-actions">
526
- <span v-if="stateConflict" class="hint"
527
- >State changed elsewhere. Load the latest JSON before saving.</span
528
- >
530
+ <span v-if="stateConflict" class="hint">{{
531
+ stateDeviceChanged
532
+ ? "Device changed since this draft loaded. Load the latest JSON before saving."
533
+ : "State changed elsewhere. Load the latest JSON before saving."
534
+ }}</span>
529
535
  <button
530
536
  v-if="stateDirty"
531
537
  class="secondary"
@@ -536,12 +542,13 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
536
542
  </button>
537
543
  <button
538
544
  class="primary small"
539
- :disabled="!stateDirty || stateSaving || stateConflict"
545
+ :disabled="!stateDirty || stateSaving || stateConflict || !!stateProblem"
540
546
  @click="saveStateJson"
541
547
  >
542
548
  {{ stateSaving ? "Saving…" : "Save JSON" }}
543
549
  </button>
544
550
  </div>
551
+ <p v-if="stateProblem" class="message-error" role="alert">{{ stateProblem }}</p>
545
552
  <p v-if="stateError" class="message-error" role="alert">{{ stateError }}</p>
546
553
  <StateEditor
547
554
  :value="shared?.value ?? {}"
@@ -624,4 +631,10 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
624
631
  </aside>
625
632
  </template>
626
633
 
627
- <style scoped>.usage-total th, .usage-total td { border-top: 1px solid var(--line); font-weight: 650; }</style>
634
+ <style scoped>
635
+ .usage-total th,
636
+ .usage-total td {
637
+ border-top: 1px solid var(--line);
638
+ font-weight: 650;
639
+ }
640
+ </style>
@@ -4,7 +4,6 @@ import { Check, X } from "lucide-vue-next";
4
4
  import type { ModelInfo } from "@sdk/api";
5
5
  import {
6
6
  agentHandle,
7
- agentState,
8
7
  attempt,
9
8
  device,
10
9
  icon,
@@ -12,6 +11,7 @@ import {
12
11
  notify,
13
12
  number,
14
13
  refreshDetail,
14
+ sessionModel,
15
15
  } from "../client/store";
16
16
 
17
17
  const emit = defineEmits<{ close: [] }>();
@@ -25,9 +25,20 @@ const filtered = computed(() =>
25
25
  `${m.name} ${m.id} ${m.tier}`.toLowerCase().includes(search.value.toLowerCase()),
26
26
  ),
27
27
  );
28
- const isCurrent = (m: ModelInfo) =>
29
- m.id === agentState.value.agent.model?.modelId &&
30
- m.provider === agentState.value.agent.model?.provider;
28
+ const isCurrent = (m: ModelInfo) => {
29
+ const c = sessionModel.value;
30
+ return !!c && m.id === c.modelId && m.provider === c.provider;
31
+ };
32
+ /** The active model when this device's catalog does not list it (picked on
33
+ * another device, or a newer catalog there): pinned and disabled, so the
34
+ * current model is always visible — searching the catalog alone cannot find
35
+ * it. */
36
+ const offCatalog = computed(() => {
37
+ const m = sessionModel.value;
38
+ return m && !models.value.some((x) => x.provider === m.provider && x.id === m.modelId)
39
+ ? m
40
+ : undefined;
41
+ });
31
42
 
32
43
  async function choose(m: ModelInfo) {
33
44
  const done = await attempt(() =>
@@ -60,6 +71,13 @@ async function choose(m: ModelInfo) {
60
71
  aria-label="Search models"
61
72
  />
62
73
  <div class="model-list">
74
+ <div v-if="offCatalog" class="model-row off-catalog" aria-disabled="true">
75
+ <img :src="icon(offCatalog.modelId)" alt="" />
76
+ <div>
77
+ <strong>{{ offCatalog.modelId }}</strong>
78
+ <small>{{ offCatalog.provider }} / current · not in this device's catalog</small>
79
+ </div>
80
+ </div>
63
81
  <button
64
82
  v-for="m in filtered"
65
83
  :key="`${m.provider}/${m.id}`"
@@ -28,6 +28,9 @@ async function submit() {
28
28
  }
29
29
  }
30
30
  onMounted(() => void nextTick(() => (input.value?.focus(), input.value?.select())));
31
+ // App's Escape policy asks whether an action is in flight: a busy dialog
32
+ // stays open (cf. client/dialog-escape.ts).
33
+ defineExpose({ busy });
31
34
  </script>
32
35
 
33
36
  <template>
@@ -1821,6 +1821,25 @@ svg {
1821
1821
  gap: 5px;
1822
1822
  flex: 1;
1823
1823
  }
1824
+ /* The pinned current model outside this device's catalog: laid out like a
1825
+ catalog row, but visibly inert — it cannot be chosen from here. */
1826
+ .model-list .model-row.off-catalog {
1827
+ width: 100%;
1828
+ display: flex;
1829
+ text-align: left;
1830
+ justify-content: flex-start;
1831
+ padding: 12px 10px;
1832
+ border-radius: 6px;
1833
+ gap: 12px;
1834
+ opacity: 0.75;
1835
+ cursor: default;
1836
+ }
1837
+ .model-list .model-row.off-catalog > div {
1838
+ display: flex;
1839
+ flex-direction: column;
1840
+ gap: 5px;
1841
+ flex: 1;
1842
+ }
1824
1843
  .model-list strong {
1825
1844
  font-size: 16px;
1826
1845
  font-weight: 500;
@@ -275,7 +275,11 @@ app.post("/api/pair/start", ...pairGuard, express.json({ limit: "16kb" }), (req,
275
275
  return r.ok ? res.json(r.value) : pairErr(r, res);
276
276
  });
277
277
  app.post("/api/pair/verify", ...pairGuard, express.json({ limit: "16kb" }), async (req, res) => {
278
- const r = await pairing.verify(req.body, req.ip ?? "unknown");
278
+ // Third arg (R6 F5): the origin the device actually dialed — when a signature
279
+ // fails under it but not under the configured hubOrigin, pairing.verify says
280
+ // origin_mismatch (with the DPI_HUB_ORIGIN hint) instead of counting an
281
+ // invalid signature toward the enrollment cancel limit.
282
+ const r = await pairing.verify(req.body, req.ip ?? "unknown", `${req.protocol}://${req.get("host")}`);
279
283
  if (r.ok) return res.status(r.status).json(r.value);
280
284
  pairErr(r, res);
281
285
  });
@@ -557,10 +557,17 @@ export class PairingService {
557
557
  });
558
558
  }
559
559
 
560
- /** POST /api/pair/verify — proof, poll, and (post-approval) issuance. */
560
+ /** POST /api/pair/verify — proof, poll, and (post-approval) issuance.
561
+ * `requestOrigin` is the origin the device DIALED (`${protocol}://${host}` of
562
+ * the HTTP request), best-effort from the route. The wire proof carries no
563
+ * declared origin (the signing payload binds one, but it is never sent), so
564
+ * this is the only signal that separates "wrong key" from "the hub signs as
565
+ * a different origin than the device dialed" — see the mismatch branch in
566
+ * the first-proof path (R6 cli finding 5). */
561
567
  async verify(
562
568
  body: unknown,
563
569
  address: string,
570
+ requestOrigin?: string,
564
571
  ): Promise<{ ok: true; value: PairPendingOut | TokenIssue; status: number } | PairingFailure> {
565
572
  const now = this.now();
566
573
  const ip = ipKey(address);
@@ -724,27 +731,34 @@ export class PairingService {
724
731
  }
725
732
  if (now >= code.expiresAt) return this.fail(410, "code_expired", "Pairing code expired");
726
733
 
727
- const payload = pairingSigningPayload({
728
- hubOrigin: this.deps.hubOrigin,
729
- hubId: this.deps.hubId,
730
- enrollmentId: enrollment.enrollmentId,
731
- nonce: enrollment.nonce,
732
- issuedAt: enrollment.nonceIssuedAt,
733
- deviceUid: enrollment.deviceUid,
734
- keyFingerprint: enrollment.computedFingerprint,
735
- });
736
734
  let valid = false;
737
735
  try {
738
- valid = cryptoVerify(
739
- null,
740
- Buffer.from(payload, "utf8"),
741
- createPublicKey(enrollment.publicKeyPem),
742
- Buffer.from(req.signature, "base64url"),
743
- );
736
+ valid = this.verifySignature(enrollment, req.signature, this.deps.hubOrigin);
744
737
  } catch {
745
738
  valid = false;
746
739
  }
747
740
  if (!valid) {
741
+ // R6 cli finding 5: a hub started WITHOUT DPI_HUB_ORIGIN signs as
742
+ // https://<hostname> while a LAN device signs the origin it dialed —
743
+ // every proof then "fails" and reads like an attack. When the same
744
+ // signature verifies under the request's origin, this is a misconfigured
745
+ // origin, not a bad key: say so and do NOT count it toward the cancel limit.
746
+ if (
747
+ requestOrigin &&
748
+ requestOrigin !== this.deps.hubOrigin &&
749
+ this.verifySignature(enrollment, req.signature, requestOrigin)
750
+ ) {
751
+ this.deps.audit.denied("auth.denied", ip, {
752
+ stage: "pair.verify",
753
+ enrollmentId: enrollment.enrollmentId,
754
+ originMismatch: `device=${requestOrigin} hub=${this.deps.hubOrigin}`,
755
+ });
756
+ return this.fail(
757
+ 409,
758
+ "origin_mismatch",
759
+ `origin mismatch: device signed for ${requestOrigin}, hub signs as ${this.deps.hubOrigin} — set DPI_HUB_ORIGIN on the hub`,
760
+ );
761
+ }
748
762
  enrollment.badSignatures += 1;
749
763
  this.noteFailure(ip); // sliding-window IP counter (S-1): code/UID change does not reset
750
764
  this.deps.audit.denied("auth.denied", ip, {
@@ -782,8 +796,15 @@ export class PairingService {
782
796
 
783
797
  /** Proof check shared by first-verify and every receipt poll (F02). */
784
798
  private signatureOk(enrollment: Enrollment, signature: string): boolean {
799
+ return this.verifySignature(enrollment, signature, this.deps.hubOrigin);
800
+ }
801
+
802
+ /** Ed25519 proof check for a given hub origin — the signing payload binds it,
803
+ * so the SAME signature can be retried under the request's origin (F02 + R6
804
+ * cli finding 5: origin-mismatch detection without a protocol change). */
805
+ private verifySignature(enrollment: Enrollment, signature: string, hubOrigin: string): boolean {
785
806
  const payload = pairingSigningPayload({
786
- hubOrigin: this.deps.hubOrigin,
807
+ hubOrigin,
787
808
  hubId: this.deps.hubId,
788
809
  enrollmentId: enrollment.enrollmentId,
789
810
  nonce: enrollment.nonce,