my-durable 0.0.119 → 0.0.121
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/git.ts +83 -8
- package/apps/dpi-backend/src/vitals.ts +5 -4
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-CLWbWp89.js → index-z0H7S2Vj.js} +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +1 -1
- package/apps/dpi-sdk/src/api.ts +6 -1
- package/apps/dpi-tui/src/app.ts +55 -6
- package/apps/dpi-tui/src/commands.ts +85 -1
- package/apps/dpi-tui/src/hub-mux.ts +24 -0
- package/apps/dpi-tui/src/pickers.ts +406 -51
- package/apps/dpi-tui/src/views.ts +10 -2
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<meta name="referrer" content="no-referrer" />
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="/icons/durable-pi.svg" />
|
|
9
9
|
<title>Durable Pi | Network</title>
|
|
10
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
+
<script type="module" crossorigin src="/assets/index-z0H7S2Vj.js"></script>
|
|
11
11
|
<link rel="stylesheet" crossorigin href="/assets/index-DD66rPUN.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
package/apps/dpi-sdk/src/api.ts
CHANGED
|
@@ -503,7 +503,12 @@ export interface DeviceVitals {
|
|
|
503
503
|
* is stalling the panel". Required: the backend always returns it (0.0.117+,
|
|
504
504
|
* pinned by dpi-backend/tests/git-priority-r11.test.ts).
|
|
505
505
|
*/
|
|
506
|
-
|
|
506
|
+
/**
|
|
507
|
+
* Git spawn semaphore (run-11 h2-2; queuedAged in run-13): live children,
|
|
508
|
+
* waiting callers, interactive "high"-lane waiters, and cumulative low→high
|
|
509
|
+
* aging rescues (>10s — the f4 starvation gauge, backend 0.0.120+).
|
|
510
|
+
*/
|
|
511
|
+
gitSpawns: { live: number; queued: number; queuedHigh: number; queuedAged: number };
|
|
507
512
|
pid: number;
|
|
508
513
|
at: number;
|
|
509
514
|
/** Sessions this device knows about; `archived` counts the archive directories. */
|
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,6 +514,14 @@ 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();
|
|
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
|
+
if (!this.muxSessionsBusy) {
|
|
522
|
+
this.muxSessionsBusy = true;
|
|
523
|
+
void this.refreshSessions().finally(() => (this.muxSessionsBusy = false));
|
|
524
|
+
}
|
|
503
525
|
// …and re-fetch the device info (R5 finding 5): the model catalog rode
|
|
504
526
|
// the boot-time /device fetch, so after a reconnect the cached catalog
|
|
505
527
|
// could miss the session's model and the ctx bar died ("ctx —").
|
|
@@ -1066,37 +1088,56 @@ export class App {
|
|
|
1066
1088
|
|
|
1067
1089
|
prompt(label: string, initial: string) {
|
|
1068
1090
|
return new Promise<string | undefined>((done) => {
|
|
1091
|
+
let settled = false;
|
|
1092
|
+
const settle = (v: string | undefined) => {
|
|
1093
|
+
if (settled) return; // first-wins (r14 review m1)
|
|
1094
|
+
settled = true;
|
|
1095
|
+
done(v);
|
|
1096
|
+
};
|
|
1069
1097
|
this.overlay(
|
|
1070
1098
|
new Prompt(
|
|
1071
1099
|
label,
|
|
1072
1100
|
initial,
|
|
1073
1101
|
(value) => {
|
|
1074
1102
|
this.closeOverlay();
|
|
1075
|
-
|
|
1103
|
+
settle(value.trim());
|
|
1076
1104
|
},
|
|
1077
1105
|
() => {
|
|
1078
1106
|
this.closeOverlay();
|
|
1079
|
-
|
|
1107
|
+
settle(undefined);
|
|
1080
1108
|
},
|
|
1081
1109
|
),
|
|
1110
|
+
// r14 review m1: an app-level dismissal (ctrl+c / closeOverlay from
|
|
1111
|
+
// outside) bypasses Prompt's onCancel — the overlay's onClose settles
|
|
1112
|
+
// undefined so the awaiting command can never hang (the pick* wiring
|
|
1113
|
+
// pattern, applied to the prompt pair too).
|
|
1114
|
+
() => settle(undefined),
|
|
1082
1115
|
);
|
|
1083
1116
|
});
|
|
1084
1117
|
}
|
|
1085
1118
|
|
|
1086
1119
|
promptSecret(label: string) {
|
|
1087
1120
|
return new Promise<string | undefined>((done) => {
|
|
1121
|
+
let settled = false;
|
|
1122
|
+
const settle = (v: string | undefined) => {
|
|
1123
|
+
if (settled) return; // first-wins (r14 review m1)
|
|
1124
|
+
settled = true;
|
|
1125
|
+
done(v);
|
|
1126
|
+
};
|
|
1088
1127
|
this.overlay(
|
|
1089
1128
|
new SecretPrompt(
|
|
1090
1129
|
label,
|
|
1091
1130
|
(value) => {
|
|
1092
1131
|
this.closeOverlay();
|
|
1093
|
-
|
|
1132
|
+
settle(value.trim());
|
|
1094
1133
|
},
|
|
1095
1134
|
() => {
|
|
1096
1135
|
this.closeOverlay();
|
|
1097
|
-
|
|
1136
|
+
settle(undefined);
|
|
1098
1137
|
},
|
|
1099
1138
|
),
|
|
1139
|
+
// r14 review m1: same as prompt() — external dismissal settles undefined.
|
|
1140
|
+
() => settle(undefined),
|
|
1100
1141
|
);
|
|
1101
1142
|
});
|
|
1102
1143
|
}
|
|
@@ -1230,6 +1271,13 @@ export class App {
|
|
|
1230
1271
|
: this.connection === "idle"
|
|
1231
1272
|
? "no agent"
|
|
1232
1273
|
: String(this.connection);
|
|
1274
|
+
// run-14 (hub resilience): while the hub is OFFLINE, count down to the
|
|
1275
|
+
// mux's next reconnect attempt (HubMux.nextRetryInMs — pure observability
|
|
1276
|
+
// over the unchanged 1s→30s backoff). "hub connecting" keeps its exact
|
|
1277
|
+
// old shape: an attempt is in flight, nothing is scheduled to show. The
|
|
1278
|
+
// 120ms tick repaints continuously, so the seconds flip with no new timer.
|
|
1279
|
+
const retryMs =
|
|
1280
|
+
this.viaHub && this.muxState === "offline" ? (this.mux?.nextRetryInMs() ?? null) : null;
|
|
1233
1281
|
return (
|
|
1234
1282
|
" " +
|
|
1235
1283
|
renderHeader(w - 2, {
|
|
@@ -1239,6 +1287,7 @@ export class App {
|
|
|
1239
1287
|
devicesTotal: devices.length || undefined,
|
|
1240
1288
|
conn,
|
|
1241
1289
|
connOk: hubDown ? false : this.connection === "live",
|
|
1290
|
+
retry: retryMs === null ? undefined : `↻${Math.ceil(retryMs / 1000)}s`,
|
|
1242
1291
|
})
|
|
1243
1292
|
);
|
|
1244
1293
|
}
|
|
@@ -4,11 +4,12 @@ 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, 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";
|
|
11
11
|
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
12
|
+
import { access, writeFile } from "node:fs/promises";
|
|
12
13
|
|
|
13
14
|
export const COMMANDS: SlashCommand[] = [
|
|
14
15
|
{ name: "sessions", description: "switch or create a session on this device" },
|
|
@@ -29,6 +30,11 @@ export const COMMANDS: SlashCommand[] = [
|
|
|
29
30
|
{ name: "name", description: "rename this agent", argumentHint: "<name>" },
|
|
30
31
|
{ name: "tasks", description: "live tasks in this session" },
|
|
31
32
|
{ name: "find", description: "search every session's transcript on this device", argumentHint: "<text>" },
|
|
33
|
+
// run-13 wave 2 — session take-out. :export writes the device's zip bundle
|
|
34
|
+
// to a local path; :archive walks the archived sessions (transcript /
|
|
35
|
+
// restore). No delete door: the SDK exposes no endpoint for it.
|
|
36
|
+
{ name: "export", description: "save a session bundle (zip) to a local path", argumentHint: "[sessionId]" },
|
|
37
|
+
{ name: "archive", description: "archived sessions: read a transcript, restore" },
|
|
32
38
|
{ name: "pair", description: "pair THIS device with a hub", argumentHint: "<CODE|PAIR_URL> [--hub ORIGIN] [--force]" },
|
|
33
39
|
{
|
|
34
40
|
name: "git",
|
|
@@ -47,6 +53,10 @@ export const COMMANDS: SlashCommand[] = [
|
|
|
47
53
|
{ name: "notify", description: "notify sinks: list them and fire a test event" },
|
|
48
54
|
{ name: "usage", description: "token/cost rollup — toast + log view" },
|
|
49
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)" },
|
|
50
60
|
{ name: "help", description: "keys and commands" },
|
|
51
61
|
{ name: "quit", description: "exit (the agent keeps running)" },
|
|
52
62
|
];
|
|
@@ -204,6 +214,56 @@ async function usageCommand(app: App) {
|
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
216
|
|
|
217
|
+
// ---------------------------------------------- run-13: :export
|
|
218
|
+
|
|
219
|
+
/** run-13 A1: the export download name is DEVICE-AUTHORED (Content-Disposition
|
|
220
|
+
* — SessionExport.filename), so before it seeds the save-path prompt it gets
|
|
221
|
+
* the FE r16 fold: oneLine first (it is chrome AND a path segment — CR/LF
|
|
222
|
+
* must go before the charset fold), then [^A-Za-z0-9._-] → "_", capped at 80.
|
|
223
|
+
* The operator's TYPED path is trusted; only the seeded default passes here. */
|
|
224
|
+
export function sanitizeExportName(filename: string): string {
|
|
225
|
+
return oneLine(String(filename ?? ""))
|
|
226
|
+
.replace(/[^A-Za-z0-9._-]/g, "_")
|
|
227
|
+
.slice(0, 80);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** /export (run-13 A1) — pull a session's zip bundle and write it to a local
|
|
231
|
+
* path. Every failure mode (device refusal, bad path, disk full) lands in one
|
|
232
|
+
* error toast: the command is operator-driven (prompts between awaits), so it
|
|
233
|
+
* must never throw out of runCommand. */
|
|
234
|
+
async function exportCommand(app: App, sessionId: string) {
|
|
235
|
+
let filename = "session.bundle.zip";
|
|
236
|
+
let bytes: Uint8Array = new Uint8Array();
|
|
237
|
+
try {
|
|
238
|
+
const ex = await app.client.exportSession(sessionId);
|
|
239
|
+
filename = sanitizeExportName(ex.filename) || filename;
|
|
240
|
+
bytes = ex.bytes;
|
|
241
|
+
} catch (e) {
|
|
242
|
+
return app.notify(`export: ${(e as Error).message.slice(0, 80)}`, true);
|
|
243
|
+
}
|
|
244
|
+
const typed = await app.prompt("Save export as", `./${filename}`);
|
|
245
|
+
if (typed === undefined || !typed.trim()) return app.flash("export cancelled"), true;
|
|
246
|
+
const target = typed.trim();
|
|
247
|
+
try {
|
|
248
|
+
// The overwrite gate — the same y/n /reset asks (R4 finding 4): only the
|
|
249
|
+
// operator's explicit y may clobber an existing file.
|
|
250
|
+
const exists = await access(target).then(
|
|
251
|
+
() => true,
|
|
252
|
+
() => false,
|
|
253
|
+
);
|
|
254
|
+
if (exists) {
|
|
255
|
+
const ok = await app.prompt(`Overwrite ${target}? y/n`, "");
|
|
256
|
+
if (ok === undefined || !ok.trim().toLowerCase().startsWith("y"))
|
|
257
|
+
return app.flash("export cancelled — kept the existing file"), true;
|
|
258
|
+
}
|
|
259
|
+
await writeFile(target, bytes);
|
|
260
|
+
app.notify(`saved ${target} (${fmtBytes(bytes.length)})`);
|
|
261
|
+
app.logEvent("export", `saved ${oneLine(target)} · ${fmtBytes(bytes.length)} · ${oneLine(filename)}`);
|
|
262
|
+
} catch (e) {
|
|
263
|
+
app.notify(`export: ${(e as Error).message.slice(0, 80)}`, true);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
207
267
|
const KEYS: [string, string][] = [
|
|
208
268
|
["enter", "send; steers the agent while it works"],
|
|
209
269
|
["alt+enter", "queue as a follow-up"],
|
|
@@ -335,6 +395,25 @@ export async function runCommand(app: App, text: string): Promise<boolean> {
|
|
|
335
395
|
case "git":
|
|
336
396
|
await gitCommand(app, arg);
|
|
337
397
|
break;
|
|
398
|
+
// run-13 wave 2: session take-out — :export writes a bundle to disk,
|
|
399
|
+
// :archive opens the archived-session picker (pickers.ts owns its rows).
|
|
400
|
+
case "export": {
|
|
401
|
+
// No argument → the session picker (attach-on-pick is that door's
|
|
402
|
+
// documented behavior), then export the picked id. Esc and +New resolve
|
|
403
|
+
// undefined — /export stays quiet rather than flashing "cancelled" over
|
|
404
|
+
// a flow that tells its own story.
|
|
405
|
+
let id = arg;
|
|
406
|
+
if (!id) {
|
|
407
|
+
const picked = await pickSession(app);
|
|
408
|
+
if (picked === undefined) break;
|
|
409
|
+
id = picked;
|
|
410
|
+
}
|
|
411
|
+
await exportCommand(app, id);
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
case "archive":
|
|
415
|
+
await pickArchived(app);
|
|
416
|
+
break;
|
|
338
417
|
// run-12: the five device-ops doors — the pickers own their row hotkeys.
|
|
339
418
|
case "schedules":
|
|
340
419
|
await pickSchedules(app);
|
|
@@ -351,6 +430,11 @@ export async function runCommand(app: App, text: string): Promise<boolean> {
|
|
|
351
430
|
case "vitals":
|
|
352
431
|
await vitalsCommand(app);
|
|
353
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;
|
|
354
438
|
case "pair":
|
|
355
439
|
await runPairing(app, parsePairArgs(arg));
|
|
356
440
|
break;
|
|
@@ -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");
|