my-durable 0.0.37 → 0.0.39
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/README.md +1 -0
- package/apps/dpi-backend/src/doctor.ts +426 -0
- package/apps/dpi-backend/src/projects.ts +587 -0
- package/apps/dpi-backend/src/routes.ts +25 -0
- package/apps/dpi-backend/src/store.ts +274 -2
- package/apps/dpi-backend/src/vitals.ts +94 -0
- package/apps/dpi-backend/src/zip.ts +117 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-CYZxCPDU.js +81 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-v7IQ7Jg5.css +1 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/HostPanel.vue +224 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +41 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NetworkSidebar.vue +142 -4
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ProjectBar.vue +284 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/UsagePanel.vue +406 -0
- package/apps/dpi-sdk/src/api.ts +95 -0
- package/apps/dpi-sdk/src/client.ts +41 -0
- package/apps/dpi-sdk/src/protocol/rest-routes.ts +9 -0
- package/bin/dpi.mjs +11 -0
- package/docs/host-project-checklist.md +7 -7
- package/package.json +2 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-BrDwRiiN.css +0 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DdEAB2rE.js +0 -81
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Inspector USAGE tab — what the selected device has actually spent: the whole
|
|
3
|
+
// device rollup (totals, by model, by project, by session), not just this
|
|
4
|
+
// session's usage chip. Asked for when the tab is opened — no polling, matching
|
|
5
|
+
// the lazy host tab. The API already sorts each list by cost, desc.
|
|
6
|
+
import { computed, ref, watch } from "vue";
|
|
7
|
+
import { Activity, Cpu, FolderGit2, RefreshCw } from "lucide-vue-next";
|
|
8
|
+
import type { DeviceUsageReport } from "@sdk/api";
|
|
9
|
+
import { deviceClient, message } from "../client/hub";
|
|
10
|
+
import { notify, selected } from "../client/store";
|
|
11
|
+
|
|
12
|
+
const usage = ref<DeviceUsageReport>();
|
|
13
|
+
const busy = ref(false);
|
|
14
|
+
const error = ref("");
|
|
15
|
+
|
|
16
|
+
const deviceId = computed(() => selected.value?.deviceId);
|
|
17
|
+
|
|
18
|
+
/** Same numbers, same shapes as the TopBar usage chip: thousands separators and
|
|
19
|
+
* four decimals of dollars — cents are too coarse for cache reads. */
|
|
20
|
+
const tokens = (n: number) => Math.round(n || 0).toLocaleString("en-US");
|
|
21
|
+
/** Sub-cent costs are real here (one small turn is $0.0000467): fixed 4dp
|
|
22
|
+
* would print $0.0000, so small non-zero amounts keep their significant digits. */
|
|
23
|
+
const cost = (n: number) => {
|
|
24
|
+
const v = n || 0;
|
|
25
|
+
if (v === 0) return "$0.0000";
|
|
26
|
+
if (v < 0.0001) return `$${v.toPrecision(2)}`;
|
|
27
|
+
if (v < 0.01) return `$${v.toFixed(6)}`;
|
|
28
|
+
return `$${v.toFixed(4)}`;
|
|
29
|
+
};
|
|
30
|
+
/** Compact form for the per-type columns, where the magnitude matters more than
|
|
31
|
+
* the last digit and the row must stay one line. */
|
|
32
|
+
/** Shares are relative to the biggest model — a device-wide bar chart. */
|
|
33
|
+
const topModelCost = computed(() =>
|
|
34
|
+
(usage.value?.models ?? []).reduce((max, m) => Math.max(max, m.cost || 0), 0),
|
|
35
|
+
);
|
|
36
|
+
const share = (value: number) =>
|
|
37
|
+
topModelCost.value > 0 ? Math.max(0, Math.min(100, Math.round(((value || 0) / topModelCost.value) * 100))) : 0;
|
|
38
|
+
|
|
39
|
+
const empty = computed(() => {
|
|
40
|
+
const u = usage.value;
|
|
41
|
+
return !u || (!u.models.length && !u.sessions.length && !u.projects.length);
|
|
42
|
+
});
|
|
43
|
+
const readAt = computed(() =>
|
|
44
|
+
usage.value ? new Date(usage.value.at).toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit" }) : "",
|
|
45
|
+
);
|
|
46
|
+
const plural = (n: number, one: string) => `${tokens(n)} ${one}${n === 1 ? "" : "s"}`;
|
|
47
|
+
|
|
48
|
+
async function load() {
|
|
49
|
+
const id = deviceId.value;
|
|
50
|
+
usage.value = undefined;
|
|
51
|
+
error.value = "";
|
|
52
|
+
if (!id) return;
|
|
53
|
+
busy.value = true;
|
|
54
|
+
try {
|
|
55
|
+
usage.value = await deviceClient(id).deviceUsage();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
error.value = message(e).slice(0, 160);
|
|
58
|
+
} finally {
|
|
59
|
+
busy.value = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
watch(deviceId, load, { immediate: true });
|
|
64
|
+
|
|
65
|
+
async function refresh() {
|
|
66
|
+
await load();
|
|
67
|
+
if (!error.value) notify("Usage refreshed.");
|
|
68
|
+
}
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<template>
|
|
72
|
+
<section class="usage-panel" aria-label="Device usage">
|
|
73
|
+
<header class="panel-heading">
|
|
74
|
+
<span><Activity :size="16" />USAGE</span>
|
|
75
|
+
<button
|
|
76
|
+
class="icon-button"
|
|
77
|
+
:disabled="busy || !deviceId"
|
|
78
|
+
aria-label="Refresh usage"
|
|
79
|
+
title="Refresh usage"
|
|
80
|
+
@click="refresh"
|
|
81
|
+
>
|
|
82
|
+
<RefreshCw :size="15" :class="{ spin: busy }" />
|
|
83
|
+
</button>
|
|
84
|
+
</header>
|
|
85
|
+
|
|
86
|
+
<p v-if="!deviceId" class="hint">Select a session to see its device's usage.</p>
|
|
87
|
+
<p v-else-if="error" class="message-error">{{ error }}</p>
|
|
88
|
+
<p v-else-if="!usage" class="hint">{{ busy ? "Reading usage…" : "No usage recorded yet." }}</p>
|
|
89
|
+
<p v-else-if="empty" class="hint">No usage recorded yet.</p>
|
|
90
|
+
|
|
91
|
+
<template v-else>
|
|
92
|
+
<!-- 1 · TOTALS -->
|
|
93
|
+
<section class="usage-block" aria-labelledby="usage-totals">
|
|
94
|
+
<div class="section-label block-label"><span id="usage-totals">TOTALS</span></div>
|
|
95
|
+
<div class="totals">
|
|
96
|
+
<div class="total">
|
|
97
|
+
<span class="label">Tokens</span>
|
|
98
|
+
<strong>{{ tokens(usage.totals.tokens) }}</strong>
|
|
99
|
+
</div>
|
|
100
|
+
<div class="total">
|
|
101
|
+
<span class="label">Cost</span>
|
|
102
|
+
<strong>{{ cost(usage.totals.cost) }}</strong>
|
|
103
|
+
</div>
|
|
104
|
+
<div class="total">
|
|
105
|
+
<span class="label">Sessions</span>
|
|
106
|
+
<strong>{{ tokens(usage.sessions.length) }}</strong>
|
|
107
|
+
<em>{{ tokens(usage.projects.length) }} projects</em>
|
|
108
|
+
</div>
|
|
109
|
+
<div class="total">
|
|
110
|
+
<span class="label">Models</span>
|
|
111
|
+
<strong>{{ tokens(usage.models.length) }}</strong>
|
|
112
|
+
<em>costliest first</em>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</section>
|
|
116
|
+
|
|
117
|
+
<!-- 2 · BY MODEL -->
|
|
118
|
+
<section class="usage-block" aria-labelledby="usage-models">
|
|
119
|
+
<div class="section-label block-label">
|
|
120
|
+
<span id="usage-models">BY MODEL</span><Cpu :size="13" />
|
|
121
|
+
</div>
|
|
122
|
+
<div class="table-scroll">
|
|
123
|
+
<table class="usage-table" aria-label="Usage by model">
|
|
124
|
+
<colgroup>
|
|
125
|
+
<col /><col /><col /><col />
|
|
126
|
+
</colgroup>
|
|
127
|
+
<thead>
|
|
128
|
+
<tr>
|
|
129
|
+
<th scope="col">Model</th>
|
|
130
|
+
<th scope="col" class="num">Tokens</th>
|
|
131
|
+
<th scope="col" class="num">Cost</th>
|
|
132
|
+
<th scope="col" class="share-col">Share</th>
|
|
133
|
+
</tr>
|
|
134
|
+
</thead>
|
|
135
|
+
<tbody>
|
|
136
|
+
<tr v-for="m in usage.models" :key="m.key">
|
|
137
|
+
<th
|
|
138
|
+
scope="row"
|
|
139
|
+
class="model-key"
|
|
140
|
+
:title="`${m.key} — in ${m.input} · out ${m.output} · cache read ${m.cacheRead} · cache write ${m.cacheWrite}`"
|
|
141
|
+
>
|
|
142
|
+
{{ m.key }}
|
|
143
|
+
</th>
|
|
144
|
+
<td class="num">{{ tokens(m.tokens) }}</td>
|
|
145
|
+
<td class="num">{{ cost(m.cost) }}</td>
|
|
146
|
+
<td class="share-col">
|
|
147
|
+
<div class="share">
|
|
148
|
+
<div
|
|
149
|
+
class="bar"
|
|
150
|
+
role="meter"
|
|
151
|
+
:aria-valuenow="share(m.cost)"
|
|
152
|
+
aria-valuemin="0"
|
|
153
|
+
aria-valuemax="100"
|
|
154
|
+
:aria-label="`${m.key} share of the costliest model`"
|
|
155
|
+
>
|
|
156
|
+
<i :style="{ width: `${share(m.cost)}%` }" :class="{ high: share(m.cost) > 90 }" />
|
|
157
|
+
</div>
|
|
158
|
+
<em class="pct">{{ share(m.cost) }}%</em>
|
|
159
|
+
</div>
|
|
160
|
+
</td>
|
|
161
|
+
</tr>
|
|
162
|
+
</tbody>
|
|
163
|
+
</table>
|
|
164
|
+
</div>
|
|
165
|
+
</section>
|
|
166
|
+
|
|
167
|
+
<!-- 3a · BY PROJECT -->
|
|
168
|
+
<section class="usage-block" aria-labelledby="usage-projects">
|
|
169
|
+
<div class="section-label block-label">
|
|
170
|
+
<span id="usage-projects">BY PROJECT</span><FolderGit2 :size="13" />
|
|
171
|
+
</div>
|
|
172
|
+
<p v-if="!usage.projects.length" class="hint">No project usage recorded yet.</p>
|
|
173
|
+
<ul v-else class="rows">
|
|
174
|
+
<li v-for="p in usage.projects" :key="p.rootPath" class="row" :title="p.rootPath">
|
|
175
|
+
<span class="row-main">
|
|
176
|
+
<strong>{{ p.name }}</strong>
|
|
177
|
+
<em>{{ p.rootPath }}</em>
|
|
178
|
+
</span>
|
|
179
|
+
<span class="row-num">{{ tokens(p.tokens) }} tok</span>
|
|
180
|
+
<span class="row-num">{{ cost(p.cost) }}</span>
|
|
181
|
+
<span class="row-meta">{{ plural(p.sessions, "session") }}</span>
|
|
182
|
+
</li>
|
|
183
|
+
</ul>
|
|
184
|
+
</section>
|
|
185
|
+
|
|
186
|
+
<!-- 3b · BY SESSION -->
|
|
187
|
+
<section class="usage-block" aria-labelledby="usage-sessions">
|
|
188
|
+
<div class="section-label block-label"><span id="usage-sessions">BY SESSION</span></div>
|
|
189
|
+
<p v-if="!usage.sessions.length" class="hint">No session usage recorded yet.</p>
|
|
190
|
+
<ul v-else class="rows scroll">
|
|
191
|
+
<li v-for="s in usage.sessions" :key="s.id" class="row" :title="s.cwd">
|
|
192
|
+
<span class="row-main">
|
|
193
|
+
<strong>{{ s.name }}</strong>
|
|
194
|
+
<em>{{ s.project ?? s.cwd }}</em>
|
|
195
|
+
</span>
|
|
196
|
+
<span class="row-num">{{ tokens(s.tokens) }} tok</span>
|
|
197
|
+
<span class="row-num">{{ cost(s.cost) }}</span>
|
|
198
|
+
<span class="row-meta">{{ plural(s.agents, "agent") }}</span>
|
|
199
|
+
</li>
|
|
200
|
+
</ul>
|
|
201
|
+
</section>
|
|
202
|
+
|
|
203
|
+
<p class="hint">
|
|
204
|
+
<Activity :size="13" /> Read on demand — open this tab or press refresh ({{ readAt }}). Nothing polls the
|
|
205
|
+
device.
|
|
206
|
+
</p>
|
|
207
|
+
</template>
|
|
208
|
+
</section>
|
|
209
|
+
</template>
|
|
210
|
+
|
|
211
|
+
<style scoped>
|
|
212
|
+
.usage-panel {
|
|
213
|
+
display: flex;
|
|
214
|
+
flex-direction: column;
|
|
215
|
+
gap: 10px;
|
|
216
|
+
padding: 4px 2px 12px;
|
|
217
|
+
font-size: 16px;
|
|
218
|
+
}
|
|
219
|
+
.usage-block {
|
|
220
|
+
display: flex;
|
|
221
|
+
flex-direction: column;
|
|
222
|
+
gap: 8px;
|
|
223
|
+
}
|
|
224
|
+
.block-label {
|
|
225
|
+
font-size: 13px;
|
|
226
|
+
text-transform: uppercase;
|
|
227
|
+
letter-spacing: 0.04em;
|
|
228
|
+
color: var(--fg-dim, var(--fg));
|
|
229
|
+
opacity: 0.72;
|
|
230
|
+
margin-bottom: 0;
|
|
231
|
+
align-items: center;
|
|
232
|
+
}
|
|
233
|
+
.totals {
|
|
234
|
+
display: grid;
|
|
235
|
+
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
|
236
|
+
gap: 10px;
|
|
237
|
+
}
|
|
238
|
+
.total {
|
|
239
|
+
display: flex;
|
|
240
|
+
flex-direction: column;
|
|
241
|
+
gap: 2px;
|
|
242
|
+
padding: 10px 12px;
|
|
243
|
+
border: 1px solid var(--line);
|
|
244
|
+
border-radius: 10px;
|
|
245
|
+
}
|
|
246
|
+
.total .label {
|
|
247
|
+
color: var(--fg-dim, var(--fg));
|
|
248
|
+
opacity: 0.72;
|
|
249
|
+
font-size: 13px;
|
|
250
|
+
text-transform: uppercase;
|
|
251
|
+
letter-spacing: 0.04em;
|
|
252
|
+
}
|
|
253
|
+
.total strong {
|
|
254
|
+
font-size: 18px;
|
|
255
|
+
font-variant-numeric: tabular-nums;
|
|
256
|
+
}
|
|
257
|
+
.total em {
|
|
258
|
+
font-style: normal;
|
|
259
|
+
font-size: 13px;
|
|
260
|
+
opacity: 0.7;
|
|
261
|
+
}
|
|
262
|
+
.table-scroll {
|
|
263
|
+
overflow-x: auto;
|
|
264
|
+
border: 1px solid var(--line);
|
|
265
|
+
border-radius: 10px;
|
|
266
|
+
}
|
|
267
|
+
.usage-table {
|
|
268
|
+
width: 100%;
|
|
269
|
+
table-layout: fixed;
|
|
270
|
+
border-collapse: collapse;
|
|
271
|
+
font-size: 14px;
|
|
272
|
+
border: 0;
|
|
273
|
+
}
|
|
274
|
+
.usage-table th,
|
|
275
|
+
.usage-table td {
|
|
276
|
+
padding: 6px 8px;
|
|
277
|
+
text-align: left;
|
|
278
|
+
border-bottom: 1px solid var(--line);
|
|
279
|
+
white-space: nowrap;
|
|
280
|
+
}
|
|
281
|
+
.usage-table thead th {
|
|
282
|
+
font-size: 13px;
|
|
283
|
+
font-weight: 500;
|
|
284
|
+
text-transform: uppercase;
|
|
285
|
+
letter-spacing: 0.04em;
|
|
286
|
+
color: var(--fg-dim, var(--fg));
|
|
287
|
+
opacity: 0.72;
|
|
288
|
+
}
|
|
289
|
+
.usage-table tbody tr:last-child th,
|
|
290
|
+
.usage-table tbody tr:last-child td {
|
|
291
|
+
border-bottom: 0;
|
|
292
|
+
}
|
|
293
|
+
.usage-table .num {
|
|
294
|
+
text-align: right;
|
|
295
|
+
font-variant-numeric: tabular-nums;
|
|
296
|
+
}
|
|
297
|
+
.usage-table .dim {
|
|
298
|
+
opacity: 0.7;
|
|
299
|
+
}
|
|
300
|
+
/* A 390px inspector cannot hold four full-width columns: fixed layout plus a
|
|
301
|
+
single-line ellipsis, with the full figures in the row's tooltip. */
|
|
302
|
+
.usage-table col:nth-child(1) { width: 44%; }
|
|
303
|
+
.usage-table col:nth-child(2) { width: 17%; }
|
|
304
|
+
.usage-table col:nth-child(3) { width: 15%; }
|
|
305
|
+
.usage-table col:nth-child(4) { width: 24%; }
|
|
306
|
+
.model-key {
|
|
307
|
+
font-weight: 600;
|
|
308
|
+
white-space: nowrap;
|
|
309
|
+
overflow: hidden;
|
|
310
|
+
text-overflow: ellipsis;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.share {
|
|
314
|
+
display: flex;
|
|
315
|
+
align-items: center;
|
|
316
|
+
gap: 6px;
|
|
317
|
+
}
|
|
318
|
+
.share .bar {
|
|
319
|
+
flex: 1;
|
|
320
|
+
height: 6px;
|
|
321
|
+
border-radius: 999px;
|
|
322
|
+
background: var(--line);
|
|
323
|
+
overflow: hidden;
|
|
324
|
+
}
|
|
325
|
+
.share .bar i {
|
|
326
|
+
display: block;
|
|
327
|
+
height: 100%;
|
|
328
|
+
background: var(--accent);
|
|
329
|
+
transition: width 0.3s ease;
|
|
330
|
+
}
|
|
331
|
+
.share .bar i.high {
|
|
332
|
+
background: var(--warn, #e5a50a);
|
|
333
|
+
}
|
|
334
|
+
.share .pct {
|
|
335
|
+
font-style: normal;
|
|
336
|
+
font-size: 13px;
|
|
337
|
+
opacity: 0.72;
|
|
338
|
+
font-variant-numeric: tabular-nums;
|
|
339
|
+
width: 4ch;
|
|
340
|
+
text-align: right;
|
|
341
|
+
}
|
|
342
|
+
.rows {
|
|
343
|
+
display: flex;
|
|
344
|
+
flex-direction: column;
|
|
345
|
+
gap: 2px;
|
|
346
|
+
margin: 0;
|
|
347
|
+
padding: 4px 10px;
|
|
348
|
+
list-style: none;
|
|
349
|
+
border: 1px solid var(--line);
|
|
350
|
+
border-radius: 10px;
|
|
351
|
+
}
|
|
352
|
+
.rows.scroll {
|
|
353
|
+
max-height: 280px;
|
|
354
|
+
overflow: auto;
|
|
355
|
+
}
|
|
356
|
+
.row {
|
|
357
|
+
display: flex;
|
|
358
|
+
align-items: center;
|
|
359
|
+
gap: 10px;
|
|
360
|
+
padding: 4px 0;
|
|
361
|
+
font-size: 14px;
|
|
362
|
+
}
|
|
363
|
+
.row + .row {
|
|
364
|
+
border-top: 1px solid var(--line);
|
|
365
|
+
}
|
|
366
|
+
.row-main {
|
|
367
|
+
display: flex;
|
|
368
|
+
flex-direction: column;
|
|
369
|
+
gap: 1px;
|
|
370
|
+
flex: 1;
|
|
371
|
+
min-width: 0;
|
|
372
|
+
}
|
|
373
|
+
.row-main strong {
|
|
374
|
+
font-weight: 600;
|
|
375
|
+
overflow: hidden;
|
|
376
|
+
text-overflow: ellipsis;
|
|
377
|
+
white-space: nowrap;
|
|
378
|
+
}
|
|
379
|
+
.row-main em {
|
|
380
|
+
font-style: normal;
|
|
381
|
+
font-size: 13px;
|
|
382
|
+
opacity: 0.65;
|
|
383
|
+
overflow: hidden;
|
|
384
|
+
text-overflow: ellipsis;
|
|
385
|
+
white-space: nowrap;
|
|
386
|
+
}
|
|
387
|
+
.row-num {
|
|
388
|
+
font-variant-numeric: tabular-nums;
|
|
389
|
+
white-space: nowrap;
|
|
390
|
+
}
|
|
391
|
+
.row-meta {
|
|
392
|
+
font-size: 13px;
|
|
393
|
+
opacity: 0.72;
|
|
394
|
+
white-space: nowrap;
|
|
395
|
+
min-width: 9ch;
|
|
396
|
+
text-align: right;
|
|
397
|
+
}
|
|
398
|
+
.spin {
|
|
399
|
+
animation: spin 1s linear infinite;
|
|
400
|
+
}
|
|
401
|
+
@keyframes spin {
|
|
402
|
+
to {
|
|
403
|
+
transform: rotate(360deg);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
</style>
|
package/apps/dpi-sdk/src/api.ts
CHANGED
|
@@ -189,6 +189,101 @@ export function compactionThresholds(window: number, s: CompactionSettings) {
|
|
|
189
189
|
return { wait, auto: s.backgroundTokens > 0 ? Math.max(0, wait - s.backgroundTokens) : undefined };
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
/** A project: a root a session starts in, promoted to an entity (paseo model). */
|
|
193
|
+
export type ProjectKind = "git" | "plain";
|
|
194
|
+
|
|
195
|
+
export interface ProjectRecord {
|
|
196
|
+
id: string;
|
|
197
|
+
/** Absolute path of the root; sessions under it belong to this project. */
|
|
198
|
+
rootPath: string;
|
|
199
|
+
/** Derived display name (basename); never empty. */
|
|
200
|
+
name: string;
|
|
201
|
+
/** Human override; wins over `name` and survives reconciliation. */
|
|
202
|
+
customName?: string;
|
|
203
|
+
/** Free-form filters, lowercase; at most 12 per project. */
|
|
204
|
+
labels: string[];
|
|
205
|
+
kind: ProjectKind;
|
|
206
|
+
createdAt: string;
|
|
207
|
+
updatedAt: string;
|
|
208
|
+
archivedAt: string | null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface ProjectPatchBody {
|
|
212
|
+
customName?: string;
|
|
213
|
+
labels?: string[];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Device usage rollup over the sessions it still holds (archived are closed). */
|
|
217
|
+
export interface DeviceUsageReport {
|
|
218
|
+
at: number;
|
|
219
|
+
totals: { tokens: number; cost: number };
|
|
220
|
+
models: Array<{
|
|
221
|
+
key: string;
|
|
222
|
+
tokens: number;
|
|
223
|
+
cost: number;
|
|
224
|
+
input: number;
|
|
225
|
+
output: number;
|
|
226
|
+
cacheRead: number;
|
|
227
|
+
cacheWrite: number;
|
|
228
|
+
inputCost: number;
|
|
229
|
+
outputCost: number;
|
|
230
|
+
cacheReadCost: number;
|
|
231
|
+
cacheWriteCost: number;
|
|
232
|
+
}>;
|
|
233
|
+
sessions: Array<{
|
|
234
|
+
id: string;
|
|
235
|
+
name: string;
|
|
236
|
+
cwd: string;
|
|
237
|
+
/** Project display name when the cwd resolves to a registered root. */
|
|
238
|
+
project?: string;
|
|
239
|
+
tokens: number;
|
|
240
|
+
cost: number;
|
|
241
|
+
agents: number;
|
|
242
|
+
}>;
|
|
243
|
+
projects: Array<{ rootPath: string; name: string; tokens: number; cost: number; sessions: number }>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** One device's live host health — asked for on demand, never polled. */
|
|
247
|
+
export interface DeviceVitals {
|
|
248
|
+
/** Seconds the host has been up. */
|
|
249
|
+
uptime: number;
|
|
250
|
+
/** Seconds the device process has been running (the daemon's own age). */
|
|
251
|
+
processUptime: number;
|
|
252
|
+
/** 1/5/15-minute load averages; zeros on Windows, which has no equivalent. */
|
|
253
|
+
loadavg: [number, number, number];
|
|
254
|
+
cpuCount: number;
|
|
255
|
+
memory: {
|
|
256
|
+
totalBytes: number;
|
|
257
|
+
freeBytes: number;
|
|
258
|
+
usedBytes: number;
|
|
259
|
+
processRssBytes: number;
|
|
260
|
+
heapUsedBytes: number;
|
|
261
|
+
};
|
|
262
|
+
/** Free/total bytes for the volume holding the device's data dir. */
|
|
263
|
+
disk: { path: string; totalBytes: number; freeBytes: number; known: boolean };
|
|
264
|
+
pid: number;
|
|
265
|
+
at: number;
|
|
266
|
+
/** Sessions this device knows about; `archived` counts the archive directories. */
|
|
267
|
+
counts?: { sessions: number; archived: number };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** One session-search hit: the summary fields plus which of them matched. */
|
|
271
|
+
export interface SessionSearchMatch {
|
|
272
|
+
id: string;
|
|
273
|
+
name: string;
|
|
274
|
+
cwd: string;
|
|
275
|
+
model: string;
|
|
276
|
+
createdAt: number;
|
|
277
|
+
dbPath: string;
|
|
278
|
+
compaction?: CompactionSettings;
|
|
279
|
+
where: Array<"name" | "cwd" | "model">;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export interface SessionSearchResult {
|
|
283
|
+
query: string;
|
|
284
|
+
matches: SessionSearchMatch[];
|
|
285
|
+
}
|
|
286
|
+
|
|
192
287
|
export interface DeviceTree {
|
|
193
288
|
uid: string;
|
|
194
289
|
name: string;
|
|
@@ -8,12 +8,17 @@ import type {
|
|
|
8
8
|
CreateSessionBody,
|
|
9
9
|
DeviceInfo,
|
|
10
10
|
DeviceTree,
|
|
11
|
+
DeviceVitals,
|
|
11
12
|
DirListing,
|
|
12
13
|
ErrorCode,
|
|
13
14
|
ForkBody,
|
|
14
15
|
Frame,
|
|
16
|
+
DeviceUsageReport,
|
|
15
17
|
Page,
|
|
18
|
+
ProjectPatchBody,
|
|
19
|
+
ProjectRecord,
|
|
16
20
|
SendResult,
|
|
21
|
+
SessionSearchResult,
|
|
17
22
|
SessionSummary,
|
|
18
23
|
TaskOutcome,
|
|
19
24
|
WhenBusy,
|
|
@@ -195,9 +200,38 @@ export class DpiClient {
|
|
|
195
200
|
device(options?: RequestOptions) {
|
|
196
201
|
return this.request<DeviceInfo>("GET", "/v1/device", undefined, options);
|
|
197
202
|
}
|
|
203
|
+
/** Host health of this device (uptime, load, memory, disk) — on demand. */
|
|
204
|
+
vitals() {
|
|
205
|
+
return this.request<DeviceVitals>("GET", "/v1/device/vitals");
|
|
206
|
+
}
|
|
198
207
|
tree() {
|
|
199
208
|
return this.request<DeviceTree>("GET", "/v1/tree");
|
|
200
209
|
}
|
|
210
|
+
/** Projects on this device: roots with labels, custom names and archive state. */
|
|
211
|
+
projects(includeArchived = false) {
|
|
212
|
+
return this.request<{ projects: ProjectRecord[] }>(
|
|
213
|
+
"GET",
|
|
214
|
+
`/v1/projects${includeArchived ? "?includeArchived=1" : ""}`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
updateProject(id: string, patch: ProjectPatchBody) {
|
|
218
|
+
return this.request<ProjectRecord>("PATCH", `/v1/projects/${enc(id)}`, patch);
|
|
219
|
+
}
|
|
220
|
+
/** POSTs carry `{}`: the hub guard 415s a bodiless POST ("JSON required"). */
|
|
221
|
+
archiveProject(id: string) {
|
|
222
|
+
return this.request<ProjectRecord>("POST", `/v1/projects/${enc(id)}/archive`, {});
|
|
223
|
+
}
|
|
224
|
+
unarchiveProject(id: string) {
|
|
225
|
+
return this.request<ProjectRecord>("POST", `/v1/projects/${enc(id)}/unarchive`, {});
|
|
226
|
+
}
|
|
227
|
+
/** Usage rollup over the sessions this device still holds. */
|
|
228
|
+
deviceUsage() {
|
|
229
|
+
return this.request<DeviceUsageReport>("GET", "/v1/device/usage");
|
|
230
|
+
}
|
|
231
|
+
/** Session search over names/cwds/models (transcripts are not scanned). */
|
|
232
|
+
searchSessions(query: string) {
|
|
233
|
+
return this.request<SessionSearchResult>("GET", `/v1/sessions/search?q=${enc(query)}`);
|
|
234
|
+
}
|
|
201
235
|
dirs(path = "") {
|
|
202
236
|
return this.request<DirListing>("GET", `/v1/fs/dirs?path=${enc(path)}`);
|
|
203
237
|
}
|
|
@@ -239,6 +273,13 @@ export class DpiClient {
|
|
|
239
273
|
return this.request<GitOpResult>("POST", "/v1/git", { path, op, ...opts });
|
|
240
274
|
}
|
|
241
275
|
/** Paths this session's agents wrote/edited — the session-changelist. */
|
|
276
|
+
/** One zipped bundle of a session (manifest + record + agent transcripts/configs). */
|
|
277
|
+
exportSession(sessionId: string) {
|
|
278
|
+
return this.request<{ filename: string; mime: string; bytes: number; base64: string }>(
|
|
279
|
+
"GET",
|
|
280
|
+
`/v1/sessions/${enc(sessionId)}/export`,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
242
283
|
sessionGitFiles(sessionId: string) {
|
|
243
284
|
return this.request<{ files: string[] }>("GET", `/v1/sessions/${enc(sessionId)}/git-files`);
|
|
244
285
|
}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
const ROUTES: readonly (readonly [method: string, pattern: string])[] = [
|
|
13
13
|
["GET", "/device"],
|
|
14
|
+
["GET", "/device/vitals"],
|
|
15
|
+
["GET", "/device/usage"],
|
|
14
16
|
["GET", "/tree"],
|
|
15
17
|
["GET", "/fs/dirs"],
|
|
16
18
|
["GET", "/git/status"],
|
|
@@ -18,9 +20,16 @@ const ROUTES: readonly (readonly [method: string, pattern: string])[] = [
|
|
|
18
20
|
["POST", "/git/status-batch"],
|
|
19
21
|
["GET", "/docs/:kind"],
|
|
20
22
|
|
|
23
|
+
["GET", "/projects"],
|
|
24
|
+
["PATCH", "/projects/:id"],
|
|
25
|
+
["POST", "/projects/:id/archive"],
|
|
26
|
+
["POST", "/projects/:id/unarchive"],
|
|
27
|
+
|
|
21
28
|
["GET", "/sessions"],
|
|
22
29
|
["POST", "/sessions"],
|
|
30
|
+
["GET", "/sessions/search"],
|
|
23
31
|
["GET", "/sessions/:s"],
|
|
32
|
+
["GET", "/sessions/:s/export"],
|
|
24
33
|
["PATCH", "/sessions/:s"],
|
|
25
34
|
["DELETE", "/sessions/:s"],
|
|
26
35
|
["GET", "/sessions/:s/compaction"],
|
package/bin/dpi.mjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// dpi hub [--port N] [--host H] [--public-host H] web UI + device tunnel server
|
|
4
4
|
// dpi device [start|stop|status|install|uninstall] device-side daemon
|
|
5
5
|
// dpi tui terminal admin client
|
|
6
|
+
// dpi doctor [--json] [--quiet] one-shot device health check
|
|
6
7
|
// Every subcommand runs the TypeScript entry through tsx, so no build step is needed.
|
|
7
8
|
import { access } from "node:fs/promises";
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
@@ -29,6 +30,9 @@ Usage:
|
|
|
29
30
|
dpi devices [--watch] [--hub <origin>] paired machines + live status (CLI, no web)
|
|
30
31
|
dpi tui
|
|
31
32
|
Terminal admin client.
|
|
33
|
+
dpi doctor [--json] [--quiet]
|
|
34
|
+
One-shot health check: node >= 22.19.0, healthz, start-dir writability,
|
|
35
|
+
the default-model probe and the hub. Exit 1 when a check fails.
|
|
32
36
|
dpi help | dpi --help | dpi -h
|
|
33
37
|
dpi version | dpi --version | dpi -v
|
|
34
38
|
dpi update [--check]
|
|
@@ -134,6 +138,13 @@ if (command === "update" || command === "upgrade") {
|
|
|
134
138
|
register();
|
|
135
139
|
const { runPairCommand } = await import("../apps/dpi-backend/src/pair-cli.ts");
|
|
136
140
|
process.exit(await runPairCommand(commandRest));
|
|
141
|
+
} else if (command === "doctor") {
|
|
142
|
+
// One-shot health check. The logic lives in the backend as TS (testable with
|
|
143
|
+
// injected fakes); this is only the tsx loader + the exit code.
|
|
144
|
+
const { register } = await loadTsx();
|
|
145
|
+
register();
|
|
146
|
+
const { doctorCli } = await import("../apps/dpi-backend/src/doctor.ts");
|
|
147
|
+
process.exit(await doctorCli(commandRest));
|
|
137
148
|
} else if (!Object.hasOwn(COMMANDS, command)) {
|
|
138
149
|
process.stderr.write(`dpi: unknown command '${command}'\n\n${HELP}`);
|
|
139
150
|
process.exit(2);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Host / Project / Device / Session Management Feature Checklist — orca / paseo / zcode / herdr / piggery → durable-pi
|
|
2
2
|
|
|
3
3
|
Run: `team_20261024143910_47d06fe8b77400d4` · Steps: 01_explore (inventory) → 02_analyze (verify/correct) → 03_write (this file)
|
|
4
|
-
Status: **
|
|
4
|
+
Status: **Waves 1a+1b+2(projects,usage) ADOPTED (0.0.39 — live-verified in production Chrome: bell+panel, usage chip+total row, transcript download, prompt library, bulk select bar, recent-cwds chips; Host vitals with real uptime/load/memory/disk, tunnel-routed session search, and a bundle zip that real `unzip` opens).** The rest of Wave 2 (scheduling, GC, webhooks, env UI, update badge) remains planning input, and policy gates #1–#4 are still open. Companion to `docs/git-ui-checklist.md` (CLOSED): that file covered the git panel; this one covers everything **around** the agent runtime — projects/workspaces, host/device management, session lifecycle, config/credentials, diagnostics, maintenance. Git-panel features are deliberately absent here. Every load-bearing citation below was re-read in the actual files during this run (see [Verification log](#verification-log)).
|
|
5
5
|
|
|
6
6
|
## Why this doc exists
|
|
7
7
|
|
|
@@ -124,18 +124,18 @@ None of them blocks Wave 1.
|
|
|
124
124
|
|
|
125
125
|
| Tier | Feature | Source (path:line) | Ours | Adoption suggestion |
|
|
126
126
|
|---|---|---|---|---|
|
|
127
|
-
| MUST | Device vitals endpoint + card | herdr `shared/types.ts:19` (`Device.uptime`, `since`); piggery `top` (`docs/reference.md:22`) |
|
|
128
|
-
| MUST | `dpi doctor` | piggery `check`/`doctor` (`docs/reference.md:33-34`) |
|
|
129
|
-
| SHOULD | Session search (device-side first) | paseo `packages/server/src/server/agent-history-search.ts` |
|
|
130
|
-
| SHOULD | Session export bundle | paseo `packages/server/src/server/exports.ts` |
|
|
127
|
+
| MUST | Device vitals endpoint + card | herdr `shared/types.ts:19` (`Device.uptime`, `since`); piggery `top` (`docs/reference.md:22`) | ✅ (`0.0.38`) | GET `/device/vitals` (`vitals.ts`: uptime, loadavg, memory, statfs free, counts) + Inspector **Host** tab (`HostPanel.vue`). On demand only — verified 0 requests until the tab opens |
|
|
128
|
+
| MUST | `dpi doctor` | piggery `check`/`doctor` (`docs/reference.md:33-34`) | ✅ (`0.0.38`) | `dpi doctor [--json] [--quiet]` (`doctor.ts`): node ≥ 22.19, healthz, start-dir writability, default-model probe, hub reachability; exit 1 only on FAIL, probe/hub are WARN |
|
|
129
|
+
| SHOULD | Session search (device-side first) | paseo `packages/server/src/server/agent-history-search.ts` | ✅ (`0.0.38`) | GET `/sessions/search?q=` matches names/cwd/models (never transcripts — FTS first). FE: instant local filter + debounced device call merged as "more on device" |
|
|
130
|
+
| SHOULD | Session export bundle | paseo `packages/server/src/server/exports.ts` | ✅ (`0.0.38`) | GET `/sessions/:s/export` → base64 zip (`zip.ts`, zero-dep writer): manifest + session record + per-agent transcript.json/.md + config.json. Import still later |
|
|
131
131
|
|
|
132
132
|
## Wave 2 — medium
|
|
133
133
|
|
|
134
134
|
| Tier | Feature | Source (path:line) | Ours | Adoption suggestion |
|
|
135
135
|
|---|---|---|---|---|
|
|
136
|
-
| MUST | Project entity + labels + archive | paseo `workspace-registry.ts:22-40` (`PersistedProjectRecord`: projectId/rootPath/kind/displayName/projectKey with COMPAT migration, customName; atomic writes via `atomic-file.ts`); zcode `packages/services/src/project/CONTRACT.md` + `autoArchiveScheduler.ts` |
|
|
136
|
+
| MUST | Project entity + labels + archive | paseo `workspace-registry.ts:22-40` (`PersistedProjectRecord`: projectId/rootPath/kind/displayName/projectKey with COMPAT migration, customName; atomic writes via `atomic-file.ts`); zcode `packages/services/src/project/CONTRACT.md` + `autoArchiveScheduler.ts` | ✅ (`0.0.39`) | `projects.ts`: atomic 0600 registry with `.bak` + v0→v1 COMPAT migration, customName/labels/archive; seeded from every session cwd on boot and on create. FE `ProjectBar.vue` chips filter the tree, name/labels/archive through the app-styled prompt |
|
|
137
137
|
| MUST | Scheduled sessions (device-side) | orca `automations/service.ts:186-211` (scheduled trigger, precheck, completion watcher; separate drift report) | ❌ | systemd timer / launchd job through the existing service layer; the **device** owns execution, the hub only displays. New surface — `config.test.ts:25` rejects `service: cron` by design |
|
|
138
|
-
| MUST | Usage dashboard | orca `usage/agent-token-usage.ts` + `usage-calendar-range.ts` (46-file suite incl. per-provider parsers) |
|
|
138
|
+
| MUST | Usage dashboard | orca `usage/agent-token-usage.ts` + `usage-calendar-range.ts` (46-file suite incl. per-provider parsers) | ✅ (`0.0.39`) | GET `/device/usage` sums each harness's usage per session/model/project; Inspector **Usage** tab. Live: 4,307 tok → `opencode-go/claude-haiku-5-5`, attributed to its project. No calendar/persistence yet (archived sessions are closed stores) |
|
|
139
139
|
| SHOULD | Notification delivery fan-out | orca `notification-delivery-service.ts:15-49` (tray→mobile→desktop, burst cooldown); piggery notify hooks desktop/herdr/ntfy (`docs/reference.md:15`) | ❌ | webhook + ntfy targets driven from existing events; per-device cooldown like orca's |
|
|
140
140
|
| SHOULD | Env-var management UI | orca `settings/HostAgentEnvironmentEditor.tsx` + `agent-default-env-draft.ts` | ❌ | edit the `env`/`env_keys` blocks of `dpi-network.yaml` (the file that generates `backend.env`, `dpi-network.example.yaml:23-30`) |
|
|
141
141
|
| MUST | Retention / auto-GC — **policy #3** | orca `terminal-history-gc.ts`; piggery `gc --closed-before DURATION [--dry-run]` (`docs/reference.md:31`) | 🟡 (archive exists, no deletion policy) | archive → verify → delete, `--dry-run` first (piggery pattern); defaults need leader sign-off |
|