my-durable 0.0.38 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/apps/dpi-backend/src/doctor.ts +10 -8
  2. package/apps/dpi-backend/src/gc-cli.ts +113 -0
  3. package/apps/dpi-backend/src/gc.ts +142 -0
  4. package/apps/dpi-backend/src/projects.ts +587 -0
  5. package/apps/dpi-backend/src/routes.ts +27 -0
  6. package/apps/dpi-backend/src/schedule-cli.ts +211 -0
  7. package/apps/dpi-backend/src/schedules.ts +676 -0
  8. package/apps/dpi-backend/src/store.ts +304 -2
  9. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DMJMesxP.css +1 -0
  10. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-jDhVa5sg.js +81 -0
  11. package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
  12. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/hub.ts +2 -0
  13. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +4 -0
  14. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +8 -0
  15. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NetworkSidebar.vue +23 -1
  16. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ProjectBar.vue +284 -0
  17. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/SchedulesPanel.vue +289 -0
  18. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TreeRow.vue +13 -1
  19. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/UsagePanel.vue +406 -0
  20. package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +20 -1
  21. package/apps/dpi-sdk/src/api.ts +100 -0
  22. package/apps/dpi-sdk/src/client.ts +42 -0
  23. package/apps/dpi-sdk/src/protocol/rest-routes.ts +12 -0
  24. package/bin/dpi.mjs +15 -0
  25. package/docs/host-project-checklist.md +6 -6
  26. package/package.json +1 -1
  27. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-D4M8tCcs.js +0 -81
  28. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-xOvj8ub1.css +0 -1
@@ -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>
@@ -4,7 +4,8 @@
4
4
  import express from "express";
5
5
  import { createServer } from "node:http";
6
6
  import { fileURLToPath } from "node:url";
7
- import { extname, resolve } from "node:path";
7
+ import { readFileSync } from "node:fs";
8
+ import { extname, join, resolve } from "node:path";
8
9
  import { hostname, networkInterfaces } from "node:os";
9
10
  import { NetworkRegistry, UI_STATE_MAX_CHARS } from "../../../../dpi-sdk/src/node/registry.js";
10
11
  import { ByteBudget } from "../../../../dpi-sdk/src/node/chunk.js";
@@ -112,6 +113,24 @@ app.use((req, res, next) => {
112
113
  next();
113
114
  });
114
115
  app.get("/healthz", (_req, res) => res.json({ ok: true }));
116
+ // The hub's own version, so a UI can flag devices that are behind it (the hub
117
+ // never pushes code — this is a badge, not an update channel).
118
+ const HUB_VERSION = (() => {
119
+ // Walk up to the package that owns this build: the checkout and the published
120
+ // layout nest the hub at different depths, so a fixed "../.." would lie.
121
+ let dir = fileURLToPath(new URL(".", import.meta.url));
122
+ for (let i = 0; i < 8; i += 1) {
123
+ try {
124
+ const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")) as { name?: string; version?: string };
125
+ if (pkg.name === "my-durable" && pkg.version) return pkg.version;
126
+ } catch {
127
+ /* keep walking */
128
+ }
129
+ dir = resolve(dir, "..");
130
+ }
131
+ return "unknown";
132
+ })();
133
+ app.get("/api/version", (_req, res) => res.json({ version: HUB_VERSION, node: process.version }));
115
134
  // All CANON limits must be sane or the hub refuses to start (P2-22: fail startup, not per-request).
116
135
  assertLimitsConfig();
117
136
  /** Operator floor for free space on the registry volume (bytes); below it audited changes are refused with 503. */
@@ -89,6 +89,8 @@ export interface DeviceInfo {
89
89
  platform: string;
90
90
  apiVersion: typeof API_VERSION;
91
91
  durableVersion: string;
92
+ /** The my-durable build this device runs (what `dpi update` replaces). */
93
+ packageVersion?: string;
92
94
  startedAt: number;
93
95
  /** Where new sessions start: the directory browser opens here, relative cwds resolve against the first. */
94
96
  startDirs: string[];
@@ -189,6 +191,104 @@ export function compactionThresholds(window: number, s: CompactionSettings) {
189
191
  return { wait, auto: s.backgroundTokens > 0 ? Math.max(0, wait - s.backgroundTokens) : undefined };
190
192
  }
191
193
 
194
+ /** A project: a root a session starts in, promoted to an entity (paseo model). */
195
+ export type ProjectKind = "git" | "plain";
196
+
197
+ export interface ProjectRecord {
198
+ id: string;
199
+ /** Absolute path of the root; sessions under it belong to this project. */
200
+ rootPath: string;
201
+ /** Derived display name (basename); never empty. */
202
+ name: string;
203
+ /** Human override; wins over `name` and survives reconciliation. */
204
+ customName?: string;
205
+ /** Free-form filters, lowercase; at most 12 per project. */
206
+ labels: string[];
207
+ kind: ProjectKind;
208
+ createdAt: string;
209
+ updatedAt: string;
210
+ archivedAt: string | null;
211
+ }
212
+
213
+ export interface ProjectPatchBody {
214
+ customName?: string;
215
+ labels?: string[];
216
+ }
217
+
218
+ /** A scheduled session: the device owns the clock, the hub only displays it. */
219
+ export interface ScheduleModelRef {
220
+ provider: string;
221
+ modelId: string;
222
+ }
223
+
224
+ export interface ScheduleRecord {
225
+ id: string;
226
+ name: string;
227
+ /** Directory each run's session starts in. */
228
+ cwd: string;
229
+ model: ScheduleModelRef;
230
+ /** Message sent to the new session's root agent. */
231
+ prompt: string;
232
+ /** Interval trigger in minutes (5–1440). Exactly one trigger is set. */
233
+ everyMinutes?: number;
234
+ /** Daily trigger, local time "HH:MM". Exactly one trigger is set. */
235
+ dailyAt?: string;
236
+ enabled: boolean;
237
+ lastRunAt?: number;
238
+ lastSessionId?: string;
239
+ lastOutcome?: "ok" | "failed";
240
+ lastError?: string;
241
+ createdAt: number;
242
+ updatedAt: number;
243
+ }
244
+
245
+ /** What a UI shows: the record plus the clock the device computed and live state. */
246
+ export interface ScheduleView extends ScheduleRecord {
247
+ nextRunAt: number | null;
248
+ /** A turn is in flight for this schedule right now. */
249
+ running: boolean;
250
+ }
251
+
252
+ export interface SchedulePatchBody {
253
+ name?: string;
254
+ cwd?: string;
255
+ model?: ScheduleModelRef;
256
+ prompt?: string;
257
+ everyMinutes?: number;
258
+ dailyAt?: string;
259
+ enabled?: boolean;
260
+ }
261
+
262
+ /** Device usage rollup over the sessions it still holds (archived are closed). */
263
+ export interface DeviceUsageReport {
264
+ at: number;
265
+ totals: { tokens: number; cost: number };
266
+ models: Array<{
267
+ key: string;
268
+ tokens: number;
269
+ cost: number;
270
+ input: number;
271
+ output: number;
272
+ cacheRead: number;
273
+ cacheWrite: number;
274
+ inputCost: number;
275
+ outputCost: number;
276
+ cacheReadCost: number;
277
+ cacheWriteCost: number;
278
+ }>;
279
+ sessions: Array<{
280
+ id: string;
281
+ name: string;
282
+ cwd: string;
283
+ /** Project display name when the cwd resolves to a registered root. */
284
+ project?: string;
285
+ tokens: number;
286
+ cost: number;
287
+ agents: number;
288
+ }>;
289
+ projects: Array<{ rootPath: string; name: string; tokens: number; cost: number; sessions: number }>;
290
+ }
291
+
192
292
  /** One device's live host health — asked for on demand, never polled. */
193
293
  export interface DeviceVitals {
194
294
  /** Seconds the host has been up. */
@@ -13,7 +13,12 @@ import type {
13
13
  ErrorCode,
14
14
  ForkBody,
15
15
  Frame,
16
+ DeviceUsageReport,
16
17
  Page,
18
+ ProjectPatchBody,
19
+ ProjectRecord,
20
+ SchedulePatchBody,
21
+ ScheduleView,
17
22
  SendResult,
18
23
  SessionSearchResult,
19
24
  SessionSummary,
@@ -204,6 +209,43 @@ export class DpiClient {
204
209
  tree() {
205
210
  return this.request<DeviceTree>("GET", "/v1/tree");
206
211
  }
212
+ /** Projects on this device: roots with labels, custom names and archive state. */
213
+ projects(includeArchived = false) {
214
+ return this.request<{ projects: ProjectRecord[] }>(
215
+ "GET",
216
+ `/v1/projects${includeArchived ? "?includeArchived=1" : ""}`,
217
+ );
218
+ }
219
+ updateProject(id: string, patch: ProjectPatchBody) {
220
+ return this.request<ProjectRecord>("PATCH", `/v1/projects/${enc(id)}`, patch);
221
+ }
222
+ /** POSTs carry `{}`: the hub guard 415s a bodiless POST ("JSON required"). */
223
+ archiveProject(id: string) {
224
+ return this.request<ProjectRecord>("POST", `/v1/projects/${enc(id)}/archive`, {});
225
+ }
226
+ unarchiveProject(id: string) {
227
+ return this.request<ProjectRecord>("POST", `/v1/projects/${enc(id)}/unarchive`, {});
228
+ }
229
+ /** Scheduled sessions on this device (device-owned clock). */
230
+ schedules() {
231
+ return this.request<{ schedules: ScheduleView[] }>("GET", "/v1/schedules");
232
+ }
233
+ createSchedule(input: SchedulePatchBody & { name: string; cwd: string; prompt: string }) {
234
+ return this.request<ScheduleView>("POST", "/v1/schedules", input);
235
+ }
236
+ updateSchedule(id: string, patch: SchedulePatchBody) {
237
+ return this.request<ScheduleView>("PATCH", `/v1/schedules/${enc(id)}`, patch);
238
+ }
239
+ removeSchedule(id: string) {
240
+ return this.request<{ removed: boolean }>("DELETE", `/v1/schedules/${enc(id)}`);
241
+ }
242
+ runSchedule(id: string) {
243
+ return this.request<ScheduleView>("POST", `/v1/schedules/${enc(id)}/run`, {});
244
+ }
245
+ /** Usage rollup over the sessions this device still holds. */
246
+ deviceUsage() {
247
+ return this.request<DeviceUsageReport>("GET", "/v1/device/usage");
248
+ }
207
249
  /** Session search over names/cwds/models (transcripts are not scanned). */
208
250
  searchSessions(query: string) {
209
251
  return this.request<SessionSearchResult>("GET", `/v1/sessions/search?q=${enc(query)}`);
@@ -12,6 +12,7 @@
12
12
  const ROUTES: readonly (readonly [method: string, pattern: string])[] = [
13
13
  ["GET", "/device"],
14
14
  ["GET", "/device/vitals"],
15
+ ["GET", "/device/usage"],
15
16
  ["GET", "/tree"],
16
17
  ["GET", "/fs/dirs"],
17
18
  ["GET", "/git/status"],
@@ -19,6 +20,17 @@ const ROUTES: readonly (readonly [method: string, pattern: string])[] = [
19
20
  ["POST", "/git/status-batch"],
20
21
  ["GET", "/docs/:kind"],
21
22
 
23
+ ["GET", "/projects"],
24
+ ["PATCH", "/projects/:id"],
25
+ ["POST", "/projects/:id/archive"],
26
+ ["POST", "/projects/:id/unarchive"],
27
+
28
+ ["GET", "/schedules"],
29
+ ["POST", "/schedules"],
30
+ ["PATCH", "/schedules/:id"],
31
+ ["DELETE", "/schedules/:id"],
32
+ ["POST", "/schedules/:id/run"],
33
+
22
34
  ["GET", "/sessions"],
23
35
  ["POST", "/sessions"],
24
36
  ["GET", "/sessions/search"],
package/bin/dpi.mjs CHANGED
@@ -3,6 +3,8 @@
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 schedule [list|add|enable|disable|run|remove] scheduled sessions
7
+ // dpi gc --closed-before 30d [--dry-run|--yes] retention (dry-run default)
6
8
  // dpi doctor [--json] [--quiet] one-shot device health check
7
9
  // Every subcommand runs the TypeScript entry through tsx, so no build step is needed.
8
10
  import { access } from "node:fs/promises";
@@ -138,6 +140,19 @@ if (command === "update" || command === "upgrade") {
138
140
  register();
139
141
  const { runPairCommand } = await import("../apps/dpi-backend/src/pair-cli.ts");
140
142
  process.exit(await runPairCommand(commandRest));
143
+ } else if (command === "schedule") {
144
+ // Scheduled sessions: the CLI only edits the device's records over its own API,
145
+ // so a running daemon picks changes up without a restart.
146
+ const { register } = await loadTsx();
147
+ register();
148
+ const { scheduleCli } = await import("../apps/dpi-backend/src/schedule-cli.ts");
149
+ process.exit(await scheduleCli(commandRest));
150
+ } else if (command === "gc") {
151
+ // Retention: dry-run unless --yes. Never runs on its own (policy gate #3).
152
+ const { register } = await loadTsx();
153
+ register();
154
+ const { gcCli } = await import("../apps/dpi-backend/src/gc-cli.ts");
155
+ process.exit(await gcCli({ argv: commandRest }));
141
156
  } else if (command === "doctor") {
142
157
  // One-shot health check. The logic lives in the backend as TS (testable with
143
158
  // injected fakes); this is only the tsx loader + the exit code.