my-durable 0.0.120 → 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-playground/apps/dpi-playground-fe/dist/assets/{index-CG_nQ-Sz.js → index-z0H7S2Vj.js} +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +1 -1
- package/apps/dpi-tui/src/app.ts +55 -6
- package/apps/dpi-tui/src/commands.ts +10 -1
- package/apps/dpi-tui/src/hub-mux.ts +24 -0
- package/apps/dpi-tui/src/pickers.ts +248 -34
- package/apps/dpi-tui/src/views.ts +9 -1
- 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-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,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;
|
|
@@ -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");
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type SelectItem,
|
|
13
13
|
} from "@earendil-works/pi-tui";
|
|
14
14
|
import { THINKING_LEVELS, type ThinkingLevel } from "../../dpi-sdk/src/api.ts";
|
|
15
|
-
import type { ArchivedView, DeviceTree, EnvFileView, NotifySinkView, ScheduleView } from "../../dpi-sdk/src/api.ts";
|
|
15
|
+
import type { ArchivedView, DeviceTree, EnvFileView, GraphRecord, GraphRunRecord, NotifySinkView, ScheduleView } from "../../dpi-sdk/src/api.ts";
|
|
16
16
|
import { agentTree, type TreeNode } from "../../dpi-sdk/src/models.ts";
|
|
17
17
|
import { fmtBytes, fmtDur } from "./commands.ts";
|
|
18
18
|
import { oneLine, sanitizeTerminal } from "./sanitize.ts";
|
|
@@ -319,28 +319,41 @@ export function pickSession(app: App): Promise<string | undefined> {
|
|
|
319
319
|
};
|
|
320
320
|
}),
|
|
321
321
|
];
|
|
322
|
+
// r13 NIT (fixed run-14): a pick* promise used to hang FOREVER when its
|
|
323
|
+
// overlay was dismissed outside the picker's esc path — app-level ctrl+c
|
|
324
|
+
// closes overlays through closeOverlay() (app.ts:1060), which fires the
|
|
325
|
+
// overlay's onClose and never the picker's onCancel. The onClose below
|
|
326
|
+
// settles the same promise. Promise resolution is first-wins, so every
|
|
327
|
+
// pick path must settle BEFORE closeOverlay — otherwise the close's
|
|
328
|
+
// onClose undefined would win over the picked id. Double-resolve is
|
|
329
|
+
// harmless; order is everything.
|
|
330
|
+
const settle = (value: string | undefined) => {
|
|
331
|
+
done(value);
|
|
332
|
+
app.closeOverlay();
|
|
333
|
+
};
|
|
322
334
|
app.overlay(
|
|
323
335
|
new Picker(`Sessions on ${oneLine(app.device.id)}`, items, (item) => {
|
|
324
|
-
app.closeOverlay();
|
|
325
336
|
// +New hands the flow to the new-session chain — resolve undefined so
|
|
326
337
|
// a waiting /export stays quiet instead of flashing "cancelled" over
|
|
327
338
|
// a flow that is telling its own story.
|
|
328
339
|
if (item.value === "+new") {
|
|
329
|
-
|
|
340
|
+
settle(undefined);
|
|
330
341
|
return void newSession(app);
|
|
331
342
|
}
|
|
332
343
|
const s = tree.sessions.find((x) => x.id === item.value)!;
|
|
333
344
|
const root = s.agents.find((a) => a.kind === "root") ?? s.agents[0];
|
|
345
|
+
settle(s.id);
|
|
334
346
|
void app.attach(s.id, root?.id ?? 1);
|
|
335
|
-
done(s.id);
|
|
336
347
|
}, () => {
|
|
337
348
|
// Esc must never surprise-quit (0.0.52): with no attached session the
|
|
338
349
|
// cancel used to pass exitIfNothing=true and picker→Esc→Esc killed the
|
|
339
350
|
// whole process (R4 finding 1). Landing in the herd/network view is the
|
|
340
351
|
// honest cancel; quitting stays on q / ctrl+c / /quit.
|
|
341
|
-
|
|
342
|
-
done(undefined);
|
|
352
|
+
settle(undefined);
|
|
343
353
|
}),
|
|
354
|
+
// The external-dismissal door (ctrl+c at app level): see the r13 NIT
|
|
355
|
+
// note above — resolves undefined, never hangs.
|
|
356
|
+
() => done(undefined),
|
|
344
357
|
);
|
|
345
358
|
})();
|
|
346
359
|
});
|
|
@@ -398,27 +411,50 @@ export async function newSession(app: App, presetName?: string) {
|
|
|
398
411
|
*/
|
|
399
412
|
export function walkDirs(app: App, path: string): Promise<string | undefined | null> {
|
|
400
413
|
return new Promise((done) => {
|
|
414
|
+
// r13 NIT (fixed run-14): the external-dismissal settle — see pickSession.
|
|
415
|
+
// One wrinkle unique to this flow: stepping DOWN a level legitimately
|
|
416
|
+
// closes this step's overlay to mount the next, and that close must NOT
|
|
417
|
+
// settle the walk (the promise stays pending across steps). The per-step
|
|
418
|
+
// `handoff` mark tells the overlay onClose "a successor owns the keyboard
|
|
419
|
+
// now"; only a dismissal with no successor resolves undefined.
|
|
420
|
+
let settled = false;
|
|
421
|
+
const settle = (v: string | undefined | null) => {
|
|
422
|
+
if (settled) return;
|
|
423
|
+
settled = true;
|
|
424
|
+
done(v);
|
|
425
|
+
};
|
|
401
426
|
const step = async (at: string) => {
|
|
402
427
|
// A cold tunnel lists in 2-20s — hold the message line so the silence
|
|
403
428
|
// never reads as a dead app (R4 finding 8).
|
|
404
429
|
app.setPending(`listing ${at || "start dirs"} on ${app.device.name}…`);
|
|
405
430
|
const listing = await app.client.dirs(at).catch((e: Error) => (app.flash(e.message, true), undefined));
|
|
406
431
|
app.setPending(null);
|
|
407
|
-
if (!listing) return
|
|
432
|
+
if (!listing) return settle(null);
|
|
408
433
|
const items: SelectItem[] = [
|
|
409
434
|
...(listing.path ? [{ value: `use:${listing.path}`, label: `✓ Use ${oneLine(String(listing.path ?? ""))}` }] : []),
|
|
410
435
|
...(listing.path ? [{ value: listing.parent ?? "", label: listing.parent ? ".." : "⌂ start dirs" }] : []),
|
|
411
436
|
...listing.dirs.map((d) => ({ value: d.path, label: `${oneLine(String(d.name ?? ""))}/` })),
|
|
412
437
|
];
|
|
438
|
+
let handoff = false;
|
|
413
439
|
app.overlay(
|
|
414
440
|
new Picker(`Working directory on ${oneLine(String(app.device.name ?? ""))}`, items, (item) => {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
441
|
+
if (item.value.startsWith("use:")) {
|
|
442
|
+
// Settle BEFORE the close: the close fires the overlay onClose,
|
|
443
|
+
// and first-wins resolution must let the PICKED path win.
|
|
444
|
+
settle(item.value.slice(4));
|
|
445
|
+
app.closeOverlay();
|
|
446
|
+
} else {
|
|
447
|
+
handoff = true;
|
|
448
|
+
app.closeOverlay();
|
|
449
|
+
void step(item.value);
|
|
450
|
+
}
|
|
418
451
|
}, () => {
|
|
419
452
|
app.closeOverlay();
|
|
420
|
-
|
|
453
|
+
settle(undefined);
|
|
421
454
|
}),
|
|
455
|
+
() => {
|
|
456
|
+
if (!handoff) settle(undefined);
|
|
457
|
+
},
|
|
422
458
|
);
|
|
423
459
|
};
|
|
424
460
|
void step(path);
|
|
@@ -428,17 +464,19 @@ export function walkDirs(app: App, path: string): Promise<string | undefined | n
|
|
|
428
464
|
function chooseModel(app: App, current?: string) {
|
|
429
465
|
return new Promise<(typeof app.info.models)[number] | undefined>((done) => {
|
|
430
466
|
const models = app.info.models;
|
|
467
|
+
// r13 NIT (fixed run-14): the overlay onClose settles the promise on
|
|
468
|
+
// external dismissal (app-level ctrl+c bypasses the picker's onCancel —
|
|
469
|
+
// see pickSession). Pick paths settle BEFORE closeOverlay so the picked
|
|
470
|
+
// model wins the first-wins resolution.
|
|
471
|
+
const settle = (m: (typeof app.info.models)[number] | undefined) => {
|
|
472
|
+
done(m);
|
|
473
|
+
app.closeOverlay();
|
|
474
|
+
};
|
|
431
475
|
const picker = new Picker(
|
|
432
476
|
`Model (${oneLine(String(app.device.name ?? ""))})`,
|
|
433
477
|
models.map((m) => ({ value: `${m.provider}/${m.id}`, label: oneLine(String(m.name ?? "")), description: `${oneLine(String(m.tier ?? ""))} │ ${oneLine(String(m.provider ?? ""))}` })),
|
|
434
|
-
(item) => {
|
|
435
|
-
|
|
436
|
-
done(models.find((m) => `${m.provider}/${m.id}` === item.value));
|
|
437
|
-
},
|
|
438
|
-
() => {
|
|
439
|
-
app.closeOverlay();
|
|
440
|
-
done(undefined);
|
|
441
|
-
},
|
|
478
|
+
(item) => settle(models.find((m) => `${m.provider}/${m.id}` === item.value)),
|
|
479
|
+
() => settle(undefined),
|
|
442
480
|
undefined,
|
|
443
481
|
// The keyless device still lists the built-in catalog — say why chat
|
|
444
482
|
// will fail, instead of letting the first request be the messenger.
|
|
@@ -448,7 +486,7 @@ function chooseModel(app: App, current?: string) {
|
|
|
448
486
|
);
|
|
449
487
|
const index = models.findIndex((m) => m.id === current);
|
|
450
488
|
if (index >= 0) picker.list.setSelectedIndex(index);
|
|
451
|
-
app.overlay(picker);
|
|
489
|
+
app.overlay(picker, () => done(undefined));
|
|
452
490
|
});
|
|
453
491
|
}
|
|
454
492
|
|
|
@@ -459,22 +497,23 @@ function chooseModel(app: App, current?: string) {
|
|
|
459
497
|
*/
|
|
460
498
|
export function pickThinking(app: App, current?: string) {
|
|
461
499
|
return new Promise<ThinkingLevel | undefined>((done) => {
|
|
500
|
+
// r13 NIT (fixed run-14): same settle-before-close wiring as pickSession —
|
|
501
|
+
// an externally dismissed overlay (ctrl+c at app level) resolves undefined
|
|
502
|
+
// instead of hanging the /thinking chain.
|
|
503
|
+
const settle = (level: ThinkingLevel | undefined) => {
|
|
504
|
+
done(level);
|
|
505
|
+
app.closeOverlay();
|
|
506
|
+
};
|
|
462
507
|
const picker = new Picker(
|
|
463
508
|
"Thinking level",
|
|
464
509
|
THINKING_LEVELS.map((level) => ({ value: level, label: level })),
|
|
465
|
-
(item) =>
|
|
466
|
-
|
|
467
|
-
done(item.value as ThinkingLevel);
|
|
468
|
-
},
|
|
469
|
-
() => {
|
|
470
|
-
app.closeOverlay();
|
|
471
|
-
done(undefined);
|
|
472
|
-
},
|
|
510
|
+
(item) => settle(item.value as ThinkingLevel),
|
|
511
|
+
() => settle(undefined),
|
|
473
512
|
);
|
|
474
513
|
const wanted = current && THINKING_LEVELS.includes(current as ThinkingLevel) ? current : "medium";
|
|
475
514
|
const index = THINKING_LEVELS.indexOf(wanted as ThinkingLevel);
|
|
476
515
|
if (index >= 0) picker.list.setSelectedIndex(index);
|
|
477
|
-
app.overlay(picker);
|
|
516
|
+
app.overlay(picker, () => done(undefined));
|
|
478
517
|
});
|
|
479
518
|
}
|
|
480
519
|
|
|
@@ -869,21 +908,29 @@ export async function pickNotify(app: App) {
|
|
|
869
908
|
const TRANSCRIPT_MAX_LINES = 400;
|
|
870
909
|
const TRANSCRIPT_MAX_BYTES = 100 * 1024;
|
|
871
910
|
|
|
872
|
-
export function capTranscriptLines(
|
|
911
|
+
export function capTranscriptLines(
|
|
912
|
+
text: string,
|
|
913
|
+
opts?: { maxLines?: number; maxBytes?: number },
|
|
914
|
+
): string[] {
|
|
915
|
+
// run-14: :graphs detail rides the same helper with a tighter line budget;
|
|
916
|
+
// the defaults keep the r13 :archive contract byte-for-byte (the r13 tests
|
|
917
|
+
// pin the marker format AND both caps — do not shift them silently).
|
|
918
|
+
const maxLines = opts?.maxLines ?? TRANSCRIPT_MAX_LINES;
|
|
919
|
+
const maxBytes = opts?.maxBytes ?? TRANSCRIPT_MAX_BYTES;
|
|
873
920
|
const raw = String(text ?? "");
|
|
874
921
|
let cut = false;
|
|
875
922
|
let body = raw;
|
|
876
|
-
if (Buffer.byteLength(body, "utf8") >
|
|
923
|
+
if (Buffer.byteLength(body, "utf8") > maxBytes) {
|
|
877
924
|
// Byte-boundary cut on the UTF-8 encoding (a char-count slice could leave
|
|
878
925
|
// up to 4× the budget for multibyte text); toString drops any dangling
|
|
879
926
|
// multibyte fragment as U+FFFD.
|
|
880
927
|
cut = true;
|
|
881
|
-
body = Buffer.from(body, "utf8").subarray(0,
|
|
928
|
+
body = Buffer.from(body, "utf8").subarray(0, maxBytes).toString("utf8");
|
|
882
929
|
}
|
|
883
930
|
const total = raw.split("\n").length;
|
|
884
931
|
const all = body.split("\n");
|
|
885
|
-
const lines = all.slice(0,
|
|
886
|
-
if (all.length >
|
|
932
|
+
const lines = all.slice(0, maxLines);
|
|
933
|
+
if (all.length > maxLines) cut = true;
|
|
887
934
|
const out = lines.map((l) => sanitizeTerminal(l));
|
|
888
935
|
if (cut) {
|
|
889
936
|
// The count names the lines the operator will not see (a byte cut can hide
|
|
@@ -968,3 +1015,170 @@ export async function pickArchived(app: App) {
|
|
|
968
1015
|
),
|
|
969
1016
|
);
|
|
970
1017
|
}
|
|
1018
|
+
|
|
1019
|
+
// ---------------------------------------------- run-14: :graphs
|
|
1020
|
+
// The last uncovered SDK surface (client.graphs/graph/runGraph/removeGraph).
|
|
1021
|
+
// The palette is a keyboard, not a DAG editor: NO create/update door — the
|
|
1022
|
+
// web FE owns graph authoring (run-14 Unit A scope). The TUI lists, dumps
|
|
1023
|
+
// detail, fires a run and removes behind the same y/n gate the other
|
|
1024
|
+
// destructive doors use. Every device-authored field (graph name, cwd, task
|
|
1025
|
+
// names/ids/deps, run ids/status) goes through oneLine INCLUDING the label
|
|
1026
|
+
// path — pi-tui never LF-normalizes labels (the r12 m1 lesson, pinned by
|
|
1027
|
+
// test in tui-graphs-r14.test.ts).
|
|
1028
|
+
|
|
1029
|
+
/** Detail cap (run-14): the :archive convention — the dump adds at most this
|
|
1030
|
+
* many body lines to the 500-entry log ring, plus the LEADING truncation
|
|
1031
|
+
* marker when it cut (same counting :archive's 400 uses). */
|
|
1032
|
+
const GRAPH_DETAIL_MAX_LINES = 200;
|
|
1033
|
+
|
|
1034
|
+
/** Runs the detail view shows — the newest 10; older ones stay on the device
|
|
1035
|
+
* (a 100-run graph would flood the log ring for no reading value). */
|
|
1036
|
+
const GRAPH_DETAIL_MAX_RUNS = 10;
|
|
1037
|
+
|
|
1038
|
+
/** lastRun glyph for the row label — the status IS the vocabulary:
|
|
1039
|
+
* ✓ ok · ✗ failed · ● running · ⏸ interrupted · ◇ never ran. */
|
|
1040
|
+
const graphRunGlyph = (status: string) =>
|
|
1041
|
+
status === "ok" ? "✓" : status === "failed" ? "✗" : status === "running" ? "●" : status === "interrupted" ? "⏸" : "◇";
|
|
1042
|
+
|
|
1043
|
+
/** The lastRun half of a row: "ok 1m ago" / "never run". Age is measured
|
|
1044
|
+
* from finishedAt when the run closed, else startedAt (a running graph has
|
|
1045
|
+
* no finish yet); a garbage timestamp degrades to no age, never a NaN row. */
|
|
1046
|
+
const graphRunState = (run: GraphRunRecord | undefined, now: number): string => {
|
|
1047
|
+
if (!run) return "never run";
|
|
1048
|
+
const t = Date.parse(String(run.finishedAt ?? run.startedAt ?? ""));
|
|
1049
|
+
const age = Number.isFinite(t) && t > 0 ? ` ${fmtDur(Math.max(0, (now - t) / 1000))} ago` : "";
|
|
1050
|
+
return `${oneLine(String(run.status ?? "?"))}${age}`;
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* The :graphs detail dump — pure for tests (now is injectable). Graph meta,
|
|
1055
|
+
* one line per task (id · name · deps · model), then the last ≤10 runs with
|
|
1056
|
+
* per-run ok/total counts. Every field is device-authored: logEvent writes
|
|
1057
|
+
* verbatim, so a task name must never split its own log line (r12 m1). The
|
|
1058
|
+
* caller caps the joined text through capTranscriptLines.
|
|
1059
|
+
*/
|
|
1060
|
+
export function graphDetailLines(graph: GraphRecord, runs: GraphRunRecord[], now = Date.now()): string[] {
|
|
1061
|
+
const tasks = Array.isArray(graph.tasks) ? graph.tasks : [];
|
|
1062
|
+
const age = (iso: unknown) => {
|
|
1063
|
+
const t = Date.parse(String(iso ?? ""));
|
|
1064
|
+
return Number.isFinite(t) && t > 0 ? fmtDur(Math.max(0, (now - t) / 1000)) : "?";
|
|
1065
|
+
};
|
|
1066
|
+
const lines: string[] = [
|
|
1067
|
+
`${oneLine(String(graph.name ?? "?"))} — ${tasks.length} task${tasks.length === 1 ? "" : "s"} · ${oneLine(String(graph.cwd ?? ""))}`,
|
|
1068
|
+
`created ${age(graph.createdAt)} ago · updated ${age(graph.updatedAt)} ago${graph.archivedAt ? " · archived" : ""}`,
|
|
1069
|
+
];
|
|
1070
|
+
for (const t of tasks)
|
|
1071
|
+
lines.push(
|
|
1072
|
+
` ${oneLine(String(t?.id ?? "?"))} ${oneLine(String(t?.name ?? "?"))} · deps [${(Array.isArray(t?.dependsOn) ? t.dependsOn : [])
|
|
1073
|
+
.map((d) => oneLine(String(d)))
|
|
1074
|
+
.join(", ")}]${t?.model ? ` · ${oneLine(String(t.model?.provider ?? "?"))}/${oneLine(String(t.model?.modelId ?? "?"))}` : ""}`,
|
|
1075
|
+
);
|
|
1076
|
+
lines.push("");
|
|
1077
|
+
const recent = (Array.isArray(runs) ? runs : []).slice(-GRAPH_DETAIL_MAX_RUNS);
|
|
1078
|
+
if (!recent.length) {
|
|
1079
|
+
lines.push("no runs yet");
|
|
1080
|
+
return lines;
|
|
1081
|
+
}
|
|
1082
|
+
lines.push(`last ${recent.length} run${recent.length === 1 ? "" : "s"}:`);
|
|
1083
|
+
for (const run of recent) {
|
|
1084
|
+
const states = Object.values(run?.tasks ?? {});
|
|
1085
|
+
const total = states.length;
|
|
1086
|
+
const ok = states.filter((s) => s?.status === "ok").length;
|
|
1087
|
+
const failed = states.filter((s) => s?.status === "failed").length;
|
|
1088
|
+
lines.push(
|
|
1089
|
+
` run ${oneLine(String(run?.id ?? "?"))} · ${oneLine(String(run?.status ?? "?"))} · ${ok}/${total} ok${failed ? ` · ${failed} failed` : ""} · started ${age(run?.startedAt)} ago${run?.finishedAt ? ` · finished ${age(run?.finishedAt)} ago` : ""}`,
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
return lines;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/** /graphs (run-14): list · enter detail · r run · d delete. No create door —
|
|
1096
|
+
* DAG editing belongs to the web FE. Enter keeps the list up (reading is
|
|
1097
|
+
* read-only, the pickArchived pattern) and dumps the capped detail into the
|
|
1098
|
+
* log view; r/d close + refetch on fresh device state. */
|
|
1099
|
+
export async function pickGraphs(app: App) {
|
|
1100
|
+
let list: Array<GraphRecord & { lastRun?: GraphRunRecord }>;
|
|
1101
|
+
try {
|
|
1102
|
+
list = (await app.client.graphs()).graphs;
|
|
1103
|
+
} catch (e) {
|
|
1104
|
+
return app.notify(`graphs: ${(e as Error).message.slice(0, 80)}`, true);
|
|
1105
|
+
}
|
|
1106
|
+
if (!list.length)
|
|
1107
|
+
return app.notify("no task-graphs on this device — create one in the web FE");
|
|
1108
|
+
// Sort by name — the oneLine'd name, so hostile whitespace cannot reorder
|
|
1109
|
+
// the rows either (the rows are composed from the same fold).
|
|
1110
|
+
const graphs = [...list].sort((a, b) =>
|
|
1111
|
+
oneLine(String(a.name ?? "")).localeCompare(oneLine(String(b.name ?? ""))),
|
|
1112
|
+
);
|
|
1113
|
+
const now = Date.now();
|
|
1114
|
+
const items: SelectItem[] = graphs.map((g) => {
|
|
1115
|
+
const n = Array.isArray(g.tasks) ? g.tasks.length : 0;
|
|
1116
|
+
return {
|
|
1117
|
+
// value is never rendered — keep the RAW id so detail/run/remove hit the
|
|
1118
|
+
// device's true graph (same rule as pickArchived's session ids).
|
|
1119
|
+
value: String(g.id ?? ""),
|
|
1120
|
+
label: `${graphRunGlyph(String(g.lastRun?.status ?? ""))} ${oneLine(String(g.name ?? ""))}`,
|
|
1121
|
+
description: `${n} task${n === 1 ? "" : "s"} · ${oneLine(String(g.cwd ?? ""))} · last ${graphRunState(g.lastRun, now)}`,
|
|
1122
|
+
};
|
|
1123
|
+
});
|
|
1124
|
+
// r14 review n7: a graph whose name is "" falls through to the id — the
|
|
1125
|
+
// ?? only catches nullish, and an empty toast ("removed ") reads as a bug.
|
|
1126
|
+
const labelOf = (id: string) => {
|
|
1127
|
+
const name = oneLine(String(graphs.find((x) => x.id === id)?.name ?? ""));
|
|
1128
|
+
return name || oneLine(id);
|
|
1129
|
+
};
|
|
1130
|
+
const showDetail = async (item: SelectItem) => {
|
|
1131
|
+
const label = labelOf(item.value);
|
|
1132
|
+
try {
|
|
1133
|
+
const { graph, runs } = await app.client.graph(item.value);
|
|
1134
|
+
const lines = capTranscriptLines(graphDetailLines(graph, runs).join("\n"), {
|
|
1135
|
+
maxLines: GRAPH_DETAIL_MAX_LINES,
|
|
1136
|
+
});
|
|
1137
|
+
for (const line of lines) app.logEvent("graph", line);
|
|
1138
|
+
app.notify(`${label} — detail, ${lines.length} line${lines.length === 1 ? "" : "s"} (log view: L)`);
|
|
1139
|
+
} catch (e) {
|
|
1140
|
+
app.notify(`graph: ${(e as Error).message.slice(0, 80)}`, true);
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
app.overlay(
|
|
1144
|
+
new ActionPicker(
|
|
1145
|
+
`Graphs on ${oneLine(app.device.id)}`,
|
|
1146
|
+
items,
|
|
1147
|
+
(item) => void showDetail(item),
|
|
1148
|
+
() => app.closeOverlay(),
|
|
1149
|
+
"enter detail · r run · d delete · esc close",
|
|
1150
|
+
{
|
|
1151
|
+
// Fire-and-forget by design (run-14): the device owns the run; the TUI
|
|
1152
|
+
// toasts "started" and does NOT poll or attach — results land in this
|
|
1153
|
+
// same detail view on the next visit (or the tasks tab).
|
|
1154
|
+
r: async (item) => {
|
|
1155
|
+
const label = labelOf(item.value);
|
|
1156
|
+
app.closeOverlay();
|
|
1157
|
+
await app.run(async () => {
|
|
1158
|
+
await app.client.runGraph(item.value);
|
|
1159
|
+
app.notify(`graph ${label} started`);
|
|
1160
|
+
app.logEvent("graph", `${label} run fired by hand`);
|
|
1161
|
+
});
|
|
1162
|
+
void pickGraphs(app);
|
|
1163
|
+
},
|
|
1164
|
+
d: async (item) => {
|
|
1165
|
+
const label = labelOf(item.value);
|
|
1166
|
+
// The same y/n gate /reset and /schedules d ask (R4 finding 4): a
|
|
1167
|
+
// destructive door confirms; esc or anything not starting with y
|
|
1168
|
+
// keeps the graph.
|
|
1169
|
+
const ok = await app.prompt(`Remove graph ${label}? y/n`, "");
|
|
1170
|
+
if (ok === undefined || !ok.trim().toLowerCase().startsWith("y"))
|
|
1171
|
+
return app.flash("remove cancelled"), undefined;
|
|
1172
|
+
app.closeOverlay();
|
|
1173
|
+
await app.run(async () => {
|
|
1174
|
+
await app.client.removeGraph(item.value);
|
|
1175
|
+
app.notify(`removed ${label}`);
|
|
1176
|
+
app.logEvent("graph", `removed ${label}`);
|
|
1177
|
+
});
|
|
1178
|
+
void pickGraphs(app);
|
|
1179
|
+
},
|
|
1180
|
+
},
|
|
1181
|
+
"run/remove only — DAG editing lives in the web FE",
|
|
1182
|
+
),
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
@@ -311,13 +311,21 @@ export function renderHeader(
|
|
|
311
311
|
devicesTotal?: number;
|
|
312
312
|
conn: string;
|
|
313
313
|
connOk: boolean;
|
|
314
|
+
/**
|
|
315
|
+
* run-14 (hub resilience): a countdown to the next reconnect attempt
|
|
316
|
+
* (`↻12s`), appended to the conn chip while the hub is OFFLINE so the
|
|
317
|
+
* operator sees WHEN the retry fires instead of a dead `hub offline`.
|
|
318
|
+
* Absent (live, connecting, direct devices) → byte-identical to the
|
|
319
|
+
* pre-run-14 render — the r12/r13 header tests pin those bytes.
|
|
320
|
+
*/
|
|
321
|
+
retry?: string;
|
|
314
322
|
},
|
|
315
323
|
): string {
|
|
316
324
|
const left = [
|
|
317
325
|
`${c.accent("▲")} ${c.bold("dpi")}`,
|
|
318
326
|
c.muted("tui"),
|
|
319
327
|
c.muted("│"),
|
|
320
|
-
`${opts.connOk ? c.ok("●") : c.err("○")} ${c.text(opts.conn)}`,
|
|
328
|
+
`${opts.connOk ? c.ok("●") : c.err("○")} ${c.text(opts.conn)}${opts.retry ? c.muted(` · ${opts.retry}`) : ""}`,
|
|
321
329
|
c.muted(`${opts.sessions} session${opts.sessions === 1 ? "" : "s"}`),
|
|
322
330
|
opts.devicesTotal !== undefined
|
|
323
331
|
? c.muted(`${opts.devicesOnline ?? 0}/${opts.devicesTotal} devices`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-durable",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.121",
|
|
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": {
|