my-durable 0.0.120 → 0.0.122
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/backup.ts +57 -3
- package/apps/dpi-backend/src/git.ts +21 -3
- package/apps/dpi-backend/src/store.ts +6 -5
- package/apps/dpi-backend/src/tunnel.ts +9 -4
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-CG_nQ-Sz.js → index-DgGnG9bL.js} +2 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +1 -1
- package/apps/dpi-playground/apps/dpi-playground-hub/src/monitor.ts +19 -1
- package/apps/dpi-playground/apps/dpi-playground-hub/src/mux.ts +281 -110
- package/apps/dpi-playground/apps/dpi-playground-hub/src/transport.ts +8 -4
- package/apps/dpi-playground/package.json +1 -1
- package/apps/dpi-sdk/src/api.ts +17 -2
- package/apps/dpi-sdk/src/client.ts +7 -2
- package/apps/dpi-sdk/src/models.ts +8 -1
- package/apps/dpi-tui/src/app.ts +73 -17
- package/apps/dpi-tui/src/commands.ts +26 -7
- package/apps/dpi-tui/src/hub-mux.ts +24 -0
- package/apps/dpi-tui/src/pairing.ts +5 -1
- package/apps/dpi-tui/src/pickers.ts +256 -37
- package/apps/dpi-tui/src/views.ts +19 -4
- package/package.json +2 -2
package/apps/dpi-tui/src/app.ts
CHANGED
|
@@ -206,6 +206,13 @@ export class App {
|
|
|
206
206
|
private muxState?: MuxState;
|
|
207
207
|
/** One-shot disconnect toast: shown once per outage, echoed by the reconnect note. */
|
|
208
208
|
private muxToastShown = false;
|
|
209
|
+
/**
|
|
210
|
+
* run-14: a live-transition sessions refresh is in flight. Every hello
|
|
211
|
+
* already rides refreshHubNetwork + a /device fetch; collapsing concurrent
|
|
212
|
+
* /tree calls behind this flag keeps a burst of transitions (or a rapid
|
|
213
|
+
* offline→live flapping hub) from stampeding the device.
|
|
214
|
+
*/
|
|
215
|
+
private muxSessionsBusy = false;
|
|
209
216
|
/** True while the current device is reached through the hub proxy. */
|
|
210
217
|
private viaHub = false;
|
|
211
218
|
private hubRows: DeviceRow[] = [];
|
|
@@ -295,7 +302,13 @@ export class App {
|
|
|
295
302
|
private refreshOps() {
|
|
296
303
|
if (this.opsLoading) return;
|
|
297
304
|
this.opsLoading = true;
|
|
298
|
-
|
|
305
|
+
// r12 m2 (fixed run-14): remember whether THIS flow took the message line —
|
|
306
|
+
// settle must clear only the note it set, never an unrelated picker flow's
|
|
307
|
+
// ("creating schedule…" used to vanish the moment any ops fetch settled,
|
|
308
|
+
// because settle called setPending(null) unconditionally while the note is
|
|
309
|
+
// only set on the FIRST load, when opsData is still empty).
|
|
310
|
+
const didPending = !Object.keys(this.opsData).length;
|
|
311
|
+
if (didPending) this.setPending("loading device ops…");
|
|
299
312
|
const grab = <K extends keyof OpsData>(key: K, p: Promise<OpsData[K]>) =>
|
|
300
313
|
p
|
|
301
314
|
.then((v) => {
|
|
@@ -315,7 +328,8 @@ export class App {
|
|
|
315
328
|
grab("sinks", this.client.notifySinks().then((r) => r.sinks)),
|
|
316
329
|
]).then(() => {
|
|
317
330
|
this.opsLoading = false;
|
|
318
|
-
this.
|
|
331
|
+
// r12 m2 (run-14): clear the pending note only if this flow set one.
|
|
332
|
+
if (didPending) this.setPending(null);
|
|
319
333
|
if (!Object.keys(this.opsData).length && Object.keys(this.opsErrors).length)
|
|
320
334
|
this.notify(`ops: ${Object.values(this.opsErrors)[0] ?? "device unreachable"}`, true);
|
|
321
335
|
this.requestRender();
|
|
@@ -500,16 +514,27 @@ export class App {
|
|
|
500
514
|
// Frames flow again: re-fetch the network rows that froze with the old
|
|
501
515
|
// connection (R4 finding 6 — the view stayed empty through every switch).
|
|
502
516
|
this.refreshHubNetwork();
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
.
|
|
517
|
+
// run-14: the session LIST froze with the connection too — the herd kept
|
|
518
|
+
// stale rows through an outage, and sessions born while the hub was down
|
|
519
|
+
// only appeared after a manual switch. Refresh once per live transition;
|
|
520
|
+
// the in-flight guard collapses concurrent hellos into one /tree.
|
|
521
|
+
// run-15 u3-8: the /device re-fetch (R5 finding 5) rides the SAME
|
|
522
|
+
// single-flight guard — it used to fire per live transition, so a
|
|
523
|
+
// flapping hub stampeded /tree AND /device in lockstep.
|
|
524
|
+
if (!this.muxSessionsBusy) {
|
|
525
|
+
this.muxSessionsBusy = true;
|
|
526
|
+
void this.refreshSessions()
|
|
527
|
+
// …and re-fetch the device info (R5 finding 5): the model catalog rode
|
|
528
|
+
// the boot-time /device fetch, so after a reconnect the cached catalog
|
|
529
|
+
// could miss the session's model and the ctx bar died ("ctx —").
|
|
530
|
+
.then(() => this.client.device({ timeoutMs: 10_000 }))
|
|
531
|
+
.then((info) => {
|
|
532
|
+
this.info = info;
|
|
533
|
+
this.requestRender();
|
|
534
|
+
})
|
|
535
|
+
.catch(() => {})
|
|
536
|
+
.finally(() => (this.muxSessionsBusy = false));
|
|
537
|
+
}
|
|
513
538
|
}
|
|
514
539
|
this.requestRender();
|
|
515
540
|
}
|
|
@@ -1066,37 +1091,56 @@ export class App {
|
|
|
1066
1091
|
|
|
1067
1092
|
prompt(label: string, initial: string) {
|
|
1068
1093
|
return new Promise<string | undefined>((done) => {
|
|
1094
|
+
let settled = false;
|
|
1095
|
+
const settle = (v: string | undefined) => {
|
|
1096
|
+
if (settled) return; // first-wins (r14 review m1)
|
|
1097
|
+
settled = true;
|
|
1098
|
+
done(v);
|
|
1099
|
+
};
|
|
1069
1100
|
this.overlay(
|
|
1070
1101
|
new Prompt(
|
|
1071
1102
|
label,
|
|
1072
1103
|
initial,
|
|
1073
1104
|
(value) => {
|
|
1074
1105
|
this.closeOverlay();
|
|
1075
|
-
|
|
1106
|
+
settle(value.trim());
|
|
1076
1107
|
},
|
|
1077
1108
|
() => {
|
|
1078
1109
|
this.closeOverlay();
|
|
1079
|
-
|
|
1110
|
+
settle(undefined);
|
|
1080
1111
|
},
|
|
1081
1112
|
),
|
|
1113
|
+
// r14 review m1: an app-level dismissal (ctrl+c / closeOverlay from
|
|
1114
|
+
// outside) bypasses Prompt's onCancel — the overlay's onClose settles
|
|
1115
|
+
// undefined so the awaiting command can never hang (the pick* wiring
|
|
1116
|
+
// pattern, applied to the prompt pair too).
|
|
1117
|
+
() => settle(undefined),
|
|
1082
1118
|
);
|
|
1083
1119
|
});
|
|
1084
1120
|
}
|
|
1085
1121
|
|
|
1086
1122
|
promptSecret(label: string) {
|
|
1087
1123
|
return new Promise<string | undefined>((done) => {
|
|
1124
|
+
let settled = false;
|
|
1125
|
+
const settle = (v: string | undefined) => {
|
|
1126
|
+
if (settled) return; // first-wins (r14 review m1)
|
|
1127
|
+
settled = true;
|
|
1128
|
+
done(v);
|
|
1129
|
+
};
|
|
1088
1130
|
this.overlay(
|
|
1089
1131
|
new SecretPrompt(
|
|
1090
1132
|
label,
|
|
1091
1133
|
(value) => {
|
|
1092
1134
|
this.closeOverlay();
|
|
1093
|
-
|
|
1135
|
+
settle(value.trim());
|
|
1094
1136
|
},
|
|
1095
1137
|
() => {
|
|
1096
1138
|
this.closeOverlay();
|
|
1097
|
-
|
|
1139
|
+
settle(undefined);
|
|
1098
1140
|
},
|
|
1099
1141
|
),
|
|
1142
|
+
// r14 review m1: same as prompt() — external dismissal settles undefined.
|
|
1143
|
+
() => settle(undefined),
|
|
1100
1144
|
);
|
|
1101
1145
|
});
|
|
1102
1146
|
}
|
|
@@ -1230,6 +1274,13 @@ export class App {
|
|
|
1230
1274
|
: this.connection === "idle"
|
|
1231
1275
|
? "no agent"
|
|
1232
1276
|
: String(this.connection);
|
|
1277
|
+
// run-14 (hub resilience): while the hub is OFFLINE, count down to the
|
|
1278
|
+
// mux's next reconnect attempt (HubMux.nextRetryInMs — pure observability
|
|
1279
|
+
// over the unchanged 1s→30s backoff). "hub connecting" keeps its exact
|
|
1280
|
+
// old shape: an attempt is in flight, nothing is scheduled to show. The
|
|
1281
|
+
// 120ms tick repaints continuously, so the seconds flip with no new timer.
|
|
1282
|
+
const retryMs =
|
|
1283
|
+
this.viaHub && this.muxState === "offline" ? (this.mux?.nextRetryInMs() ?? null) : null;
|
|
1233
1284
|
return (
|
|
1234
1285
|
" " +
|
|
1235
1286
|
renderHeader(w - 2, {
|
|
@@ -1239,6 +1290,7 @@ export class App {
|
|
|
1239
1290
|
devicesTotal: devices.length || undefined,
|
|
1240
1291
|
conn,
|
|
1241
1292
|
connOk: hubDown ? false : this.connection === "live",
|
|
1293
|
+
retry: retryMs === null ? undefined : `↻${Math.ceil(retryMs / 1000)}s`,
|
|
1242
1294
|
})
|
|
1243
1295
|
);
|
|
1244
1296
|
}
|
|
@@ -1448,7 +1500,11 @@ export class App {
|
|
|
1448
1500
|
if (this.tab === "state") {
|
|
1449
1501
|
const u = sumUsage(s.usage);
|
|
1450
1502
|
const state = {
|
|
1451
|
-
|
|
1503
|
+
// run-15 u3-5: the device id is registry/hub-supplied and rides the
|
|
1504
|
+
// JSON.stringify below RAW — the C1 range (OSC/CSI 8-bit) survives both
|
|
1505
|
+
// stringify and the muted() paint, so oneLine at the data boundary like
|
|
1506
|
+
// every other chrome row (R20 cold-1 M4 discipline).
|
|
1507
|
+
device: oneLine(this.device.id),
|
|
1452
1508
|
session: this.sessionId,
|
|
1453
1509
|
agent: this.agentId,
|
|
1454
1510
|
connection: this.connection,
|
|
@@ -4,7 +4,7 @@ import { THINKING_LEVELS, type ThinkingLevel } from "../../dpi-sdk/src/api.ts";
|
|
|
4
4
|
import type { App } from "./app.ts";
|
|
5
5
|
import { sanitizeTerminal, oneLine } from "./sanitize.ts";
|
|
6
6
|
export { oneLine };
|
|
7
|
-
import { Panel, pickAgent, pickArchived, pickDevice, pickEnv, pickModel, pickNotify, pickSession, pickSchedules, pickThinking } from "./pickers.ts";
|
|
7
|
+
import { Panel, pickAgent, pickArchived, pickDevice, pickEnv, pickGraphs, pickModel, pickNotify, pickSession, pickSchedules, pickThinking } from "./pickers.ts";
|
|
8
8
|
import { parsePairArgs, runPairing } from "./pairing.ts";
|
|
9
9
|
import { gitStateSuffix } from "./views.ts";
|
|
10
10
|
import { c } from "./theme.ts";
|
|
@@ -53,6 +53,10 @@ export const COMMANDS: SlashCommand[] = [
|
|
|
53
53
|
{ name: "notify", description: "notify sinks: list them and fire a test event" },
|
|
54
54
|
{ name: "usage", description: "token/cost rollup — toast + log view" },
|
|
55
55
|
{ name: "vitals", description: "device health: uptime, memory, disk, lag, git spawns" },
|
|
56
|
+
// run-14: the last uncovered SDK surface — task-graphs. Read/run/remove
|
|
57
|
+
// only; DAG authoring is the web FE's job, so there is no create door and
|
|
58
|
+
// no argument to complete (the row hotkeys live in pickGraphs).
|
|
59
|
+
{ name: "graphs", description: "task-graphs: detail, run, remove (DAG editing lives in the web FE)" },
|
|
56
60
|
{ name: "help", description: "keys and commands" },
|
|
57
61
|
{ name: "quit", description: "exit (the agent keeps running)" },
|
|
58
62
|
];
|
|
@@ -426,6 +430,11 @@ export async function runCommand(app: App, text: string): Promise<boolean> {
|
|
|
426
430
|
case "vitals":
|
|
427
431
|
await vitalsCommand(app);
|
|
428
432
|
break;
|
|
433
|
+
// run-14: the graphs door — pickers.ts owns the picker + capped detail
|
|
434
|
+
// dump; runGraph is fire-and-forget, remove sits behind a y/n gate.
|
|
435
|
+
case "graphs":
|
|
436
|
+
await pickGraphs(app);
|
|
437
|
+
break;
|
|
429
438
|
case "pair":
|
|
430
439
|
await runPairing(app, parsePairArgs(arg));
|
|
431
440
|
break;
|
|
@@ -436,25 +445,35 @@ export async function runCommand(app: App, text: string): Promise<boolean> {
|
|
|
436
445
|
if (!arg) return app.flash("usage: /find <text> — searches every session's transcript", true), true;
|
|
437
446
|
await app.run(async () => {
|
|
438
447
|
const result = await app.client.searchSessions(arg, "all");
|
|
439
|
-
|
|
448
|
+
// run-15 u3-3 (MED): the search response is a JSON.parse cast — a
|
|
449
|
+
// missing/non-array `matches` threw in .slice()/.length and a missing
|
|
450
|
+
// `where` threw in the Panel body (which re-runs EVERY render, so the
|
|
451
|
+
// crash looped the whole TUI). Normalize once HERE; the closure below
|
|
452
|
+
// reads only the coerced list. Sanitize/hit-slicing discipline (R18/R19/R20)
|
|
453
|
+
// is unchanged.
|
|
454
|
+
const matches = Array.isArray(result?.matches) ? result.matches : [];
|
|
455
|
+
const shown = matches.slice(0, 12);
|
|
440
456
|
app.overlay(
|
|
441
457
|
new Panel(() => {
|
|
442
458
|
const lines = [
|
|
443
|
-
c.bold(c.accent(`"${sanitizeTerminal(arg)}" — ${sanitizeTerminal(String(
|
|
459
|
+
c.bold(c.accent(`"${sanitizeTerminal(arg)}" — ${sanitizeTerminal(String(matches.length))} session${matches.length === 1 ? "" : "s"}`)),
|
|
444
460
|
"",
|
|
445
461
|
];
|
|
446
|
-
if (!
|
|
462
|
+
if (!matches.length) lines.push(c.muted("No matches (names, folders, models or transcripts)."));
|
|
447
463
|
for (const m of shown) {
|
|
448
464
|
lines.push(
|
|
449
465
|
// R20 h5: the match header is in the SAME panel as the fixed hit
|
|
450
466
|
// lines — a \n in a session name split the row above the hits.
|
|
451
|
-
|
|
467
|
+
// run-15 u3-3: `where` is wire-borne too — guard the membership
|
|
468
|
+
// test so a missing/hostile value renders no marker instead of
|
|
469
|
+
// throwing (String() keeps array membership semantics).
|
|
470
|
+
`${c.secondary(oneLine(m.name))} ${c.muted(oneLine(m.cwd))}${String(m.where ?? "").includes("transcript") ? " " + c.warn("◍ transcript") : ""}`,
|
|
452
471
|
);
|
|
453
472
|
for (const hit of (m.hits ?? []).slice(0, 3))
|
|
454
473
|
lines.push(c.muted(findHitLine(m.name, hit)));
|
|
455
474
|
}
|
|
456
|
-
if (
|
|
457
|
-
if (result
|
|
475
|
+
if (matches.length > shown.length) lines.push(c.muted(`… ${sanitizeTerminal(String(matches.length - shown.length))} more`));
|
|
476
|
+
if (result?.scanned?.truncated)
|
|
458
477
|
lines.push(c.muted(`scan budget reached (${sanitizeTerminal(String(result.scanned.entries))} entries) — refine the query`));
|
|
459
478
|
lines.push("", c.muted("esc close"));
|
|
460
479
|
return lines;
|
|
@@ -25,6 +25,14 @@ export class HubMux {
|
|
|
25
25
|
private listeners = new Map<string, Set<Subscriber>>();
|
|
26
26
|
private source?: AbortController;
|
|
27
27
|
private state: MuxState = "connecting";
|
|
28
|
+
/**
|
|
29
|
+
* When the CURRENT offline wait ends (run-14): the absolute deadline of the
|
|
30
|
+
* backoff sleep, recorded the moment the wait begins and cleared as soon as
|
|
31
|
+
* the hub proves alive again (the hello that runs backoff.reset()) or stop()
|
|
32
|
+
* tears the loop down. Pure observability for nextRetryInMs — the reconnect
|
|
33
|
+
* cadence itself still reads backoff.ms directly and is untouched.
|
|
34
|
+
*/
|
|
35
|
+
private retryAt?: number;
|
|
28
36
|
|
|
29
37
|
constructor(
|
|
30
38
|
private readonly hub: { url: string; token: string },
|
|
@@ -68,6 +76,7 @@ export class HubMux {
|
|
|
68
76
|
this.streamId = mux.frame.streamId;
|
|
69
77
|
this.setState("live");
|
|
70
78
|
backoff.reset();
|
|
79
|
+
this.retryAt = undefined; // run-14: live again — no retry is scheduled
|
|
71
80
|
// Reconnects reopen fresh upstreams: resubscribe everything.
|
|
72
81
|
await this.put([...this.wanted]);
|
|
73
82
|
continue;
|
|
@@ -82,6 +91,9 @@ export class HubMux {
|
|
|
82
91
|
if (ctl.signal.aborted) return;
|
|
83
92
|
this.setState("offline");
|
|
84
93
|
}
|
|
94
|
+
// run-14: the offline wait begins — record when the next attempt fires
|
|
95
|
+
// so nextRetryInMs can count down to it. The sleep below is unchanged.
|
|
96
|
+
this.retryAt = Date.now() + backoff.ms;
|
|
85
97
|
await new Promise((resolve) => setTimeout(resolve, backoff.ms));
|
|
86
98
|
backoff.advance();
|
|
87
99
|
}
|
|
@@ -157,10 +169,22 @@ export class HubMux {
|
|
|
157
169
|
}
|
|
158
170
|
}
|
|
159
171
|
|
|
172
|
+
/**
|
|
173
|
+
* ms until the next reconnect attempt (run-14) — feeds the header's ↻
|
|
174
|
+
* countdown. null while live or before any failure (nothing is scheduled).
|
|
175
|
+
* The value is derived, never cached: any `now` may be passed, and a just-
|
|
176
|
+
* missed deadline clamps to 0 ("now"), never a negative number. Reconnect
|
|
177
|
+
* cadence, subscription and frame semantics are all untouched.
|
|
178
|
+
*/
|
|
179
|
+
nextRetryInMs(now: number = Date.now()): number | null {
|
|
180
|
+
return this.retryAt === undefined ? null : Math.max(0, this.retryAt - now);
|
|
181
|
+
}
|
|
182
|
+
|
|
160
183
|
stop() {
|
|
161
184
|
this.source?.abort();
|
|
162
185
|
this.source = undefined;
|
|
163
186
|
this.streamId = "";
|
|
187
|
+
this.retryAt = undefined; // run-14: a stopped mux never retries
|
|
164
188
|
this.listeners.clear();
|
|
165
189
|
this.wanted.clear();
|
|
166
190
|
this.setState("offline");
|
|
@@ -160,7 +160,11 @@ export function pairingViewLines(
|
|
|
160
160
|
lines.push(c.muted(oneLine(`device: ${status.deviceName ?? status.deviceUid ?? "?"} · uid ${status.deviceUid ?? "?"}`)));
|
|
161
161
|
lines.push("");
|
|
162
162
|
lines.push(c.bold("key fingerprint (compare with the hub wizard):"));
|
|
163
|
-
|
|
163
|
+
// run-15 u3-7: fingerprint is typed string by convention only — a hostile
|
|
164
|
+
// pairing status rode a non-string straight into the fingerprint block. A
|
|
165
|
+
// non-string renders NO chunk rows instead of leaking the raw value.
|
|
166
|
+
const fpRows = typeof status.fingerprint === "string" ? wrapFingerprint(status.fingerprint, width) : [];
|
|
167
|
+
for (const line of fpRows) lines.push(` ${c.secondary(oneLine(line))}`);
|
|
164
168
|
lines.push("");
|
|
165
169
|
if (status.pending) {
|
|
166
170
|
lines.push(c.warn("Awaiting approval on the hub…"));
|