my-durable 0.0.39 → 0.0.41

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 (27) hide show
  1. package/apps/dpi-backend/src/doctor.ts +29 -9
  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/notify-cli.ts +211 -0
  5. package/apps/dpi-backend/src/notify-sinks.ts +947 -0
  6. package/apps/dpi-backend/src/routes.ts +17 -0
  7. package/apps/dpi-backend/src/schedule-cli.ts +211 -0
  8. package/apps/dpi-backend/src/schedules.ts +676 -0
  9. package/apps/dpi-backend/src/store.ts +275 -7
  10. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-D6ClJqd8.css +1 -0
  11. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DMb-n4O-.js +81 -0
  12. package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
  13. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/hub.ts +2 -0
  14. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +4 -0
  15. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +8 -0
  16. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NotifyPanel.vue +292 -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-hub/src/main.ts +20 -1
  20. package/apps/dpi-sdk/src/api.ts +100 -0
  21. package/apps/dpi-sdk/src/client.ts +38 -0
  22. package/apps/dpi-sdk/src/protocol/rest-routes.ts +12 -0
  23. package/bin/dpi.mjs +22 -0
  24. package/docs/host-project-checklist.md +6 -6
  25. package/package.json +1 -1
  26. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-CYZxCPDU.js +0 -81
  27. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-v7IQ7Jg5.css +0 -1
@@ -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[];
@@ -213,6 +215,104 @@ export interface ProjectPatchBody {
213
215
  labels?: string[];
214
216
  }
215
217
 
218
+ /** What a live model probe found. `status` is what a picker can show as a hint. */
219
+ export interface ModelProbe {
220
+ ok: boolean;
221
+ detail: string;
222
+ /** "rate_limited" is the actionable one: the model works, you must wait. */
223
+ status?: "rate_limited" | "auth" | "missing" | "error";
224
+ /** From a provider's Retry-After, when it said so. */
225
+ retryAfterMs?: number;
226
+ }
227
+
228
+ /** One outbound notification target on the device (webhook or ntfy). */
229
+ export type NotifySinkKind = "webhook" | "ntfy";
230
+
231
+ export interface NotifySinkRecord {
232
+ id: string;
233
+ kind: NotifySinkKind;
234
+ url: string;
235
+ enabled: boolean;
236
+ /** Empty/absent = every event; supports `schedule.*` wildcards. */
237
+ events?: string[];
238
+ label?: string;
239
+ priority?: "min" | "low" | "default" | "high" | "max";
240
+ tags?: string[];
241
+ createdAt: number;
242
+ updatedAt: number;
243
+ lastDeliveryAt?: number;
244
+ lastError?: string;
245
+ lastStatus?: number;
246
+ }
247
+
248
+ /** What a UI shows: the record plus live cooldown state. */
249
+ export interface NotifySinkView extends NotifySinkRecord {
250
+ silencedUntil: number | null;
251
+ }
252
+
253
+ export interface NotifySinkBody {
254
+ kind: NotifySinkKind;
255
+ url: string;
256
+ enabled?: boolean;
257
+ events?: string[];
258
+ label?: string;
259
+ priority?: NotifySinkRecord["priority"];
260
+ tags?: string[];
261
+ }
262
+
263
+ /** Per-sink result of one fan-out (also what `POST /v1/notify/test` returns). */
264
+ export interface NotifyDelivery {
265
+ id: string;
266
+ kind: NotifySinkKind;
267
+ status: "sent" | "skipped" | "failed";
268
+ detail?: string;
269
+ ms?: number;
270
+ }
271
+
272
+ /** A scheduled session: the device owns the clock, the hub only displays it. */
273
+ export interface ScheduleModelRef {
274
+ provider: string;
275
+ modelId: string;
276
+ }
277
+
278
+ export interface ScheduleRecord {
279
+ id: string;
280
+ name: string;
281
+ /** Directory each run's session starts in. */
282
+ cwd: string;
283
+ model: ScheduleModelRef;
284
+ /** Message sent to the new session's root agent. */
285
+ prompt: string;
286
+ /** Interval trigger in minutes (5–1440). Exactly one trigger is set. */
287
+ everyMinutes?: number;
288
+ /** Daily trigger, local time "HH:MM". Exactly one trigger is set. */
289
+ dailyAt?: string;
290
+ enabled: boolean;
291
+ lastRunAt?: number;
292
+ lastSessionId?: string;
293
+ lastOutcome?: "ok" | "failed";
294
+ lastError?: string;
295
+ createdAt: number;
296
+ updatedAt: number;
297
+ }
298
+
299
+ /** What a UI shows: the record plus the clock the device computed and live state. */
300
+ export interface ScheduleView extends ScheduleRecord {
301
+ nextRunAt: number | null;
302
+ /** A turn is in flight for this schedule right now. */
303
+ running: boolean;
304
+ }
305
+
306
+ export interface SchedulePatchBody {
307
+ name?: string;
308
+ cwd?: string;
309
+ model?: ScheduleModelRef;
310
+ prompt?: string;
311
+ everyMinutes?: number;
312
+ dailyAt?: string;
313
+ enabled?: boolean;
314
+ }
315
+
216
316
  /** Device usage rollup over the sessions it still holds (archived are closed). */
217
317
  export interface DeviceUsageReport {
218
318
  at: number;
@@ -14,9 +14,14 @@ import type {
14
14
  ForkBody,
15
15
  Frame,
16
16
  DeviceUsageReport,
17
+ NotifyDelivery,
18
+ NotifySinkBody,
19
+ NotifySinkView,
17
20
  Page,
18
21
  ProjectPatchBody,
19
22
  ProjectRecord,
23
+ SchedulePatchBody,
24
+ ScheduleView,
20
25
  SendResult,
21
26
  SessionSearchResult,
22
27
  SessionSummary,
@@ -224,6 +229,39 @@ export class DpiClient {
224
229
  unarchiveProject(id: string) {
225
230
  return this.request<ProjectRecord>("POST", `/v1/projects/${enc(id)}/unarchive`, {});
226
231
  }
232
+ /** Outbound notification sinks (webhook/ntfy) on this device. */
233
+ notifySinks() {
234
+ return this.request<{ sinks: NotifySinkView[] }>("GET", "/v1/notify/sinks");
235
+ }
236
+ createNotifySink(input: NotifySinkBody) {
237
+ return this.request<NotifySinkView>("POST", "/v1/notify/sinks", input);
238
+ }
239
+ updateNotifySink(id: string, patch: Partial<NotifySinkBody>) {
240
+ return this.request<NotifySinkView>("PATCH", `/v1/notify/sinks/${enc(id)}`, patch);
241
+ }
242
+ removeNotifySink(id: string) {
243
+ return this.request<{ removed: boolean }>("DELETE", `/v1/notify/sinks/${enc(id)}`);
244
+ }
245
+ /** Fire a test event through every enabled sink. */
246
+ testNotifySinks() {
247
+ return this.request<{ results: NotifyDelivery[] }>("POST", "/v1/notify/test", {});
248
+ }
249
+ /** Scheduled sessions on this device (device-owned clock). */
250
+ schedules() {
251
+ return this.request<{ schedules: ScheduleView[] }>("GET", "/v1/schedules");
252
+ }
253
+ createSchedule(input: SchedulePatchBody & { name: string; cwd: string; prompt: string }) {
254
+ return this.request<ScheduleView>("POST", "/v1/schedules", input);
255
+ }
256
+ updateSchedule(id: string, patch: SchedulePatchBody) {
257
+ return this.request<ScheduleView>("PATCH", `/v1/schedules/${enc(id)}`, patch);
258
+ }
259
+ removeSchedule(id: string) {
260
+ return this.request<{ removed: boolean }>("DELETE", `/v1/schedules/${enc(id)}`);
261
+ }
262
+ runSchedule(id: string) {
263
+ return this.request<ScheduleView>("POST", `/v1/schedules/${enc(id)}/run`, {});
264
+ }
227
265
  /** Usage rollup over the sessions this device still holds. */
228
266
  deviceUsage() {
229
267
  return this.request<DeviceUsageReport>("GET", "/v1/device/usage");
@@ -25,6 +25,18 @@ const ROUTES: readonly (readonly [method: string, pattern: string])[] = [
25
25
  ["POST", "/projects/:id/archive"],
26
26
  ["POST", "/projects/:id/unarchive"],
27
27
 
28
+ ["GET", "/notify/sinks"],
29
+ ["POST", "/notify/sinks"],
30
+ ["PATCH", "/notify/sinks/:id"],
31
+ ["DELETE", "/notify/sinks/:id"],
32
+ ["POST", "/notify/test"],
33
+
34
+ ["GET", "/schedules"],
35
+ ["POST", "/schedules"],
36
+ ["PATCH", "/schedules/:id"],
37
+ ["DELETE", "/schedules/:id"],
38
+ ["POST", "/schedules/:id/run"],
39
+
28
40
  ["GET", "/sessions"],
29
41
  ["POST", "/sessions"],
30
42
  ["GET", "/sessions/search"],
package/bin/dpi.mjs CHANGED
@@ -3,6 +3,9 @@
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 notify [list|add|enable|disable|remove|test] outbound notifications
8
+ // dpi gc --closed-before 30d [--dry-run|--yes] retention (dry-run default)
6
9
  // dpi doctor [--json] [--quiet] one-shot device health check
7
10
  // Every subcommand runs the TypeScript entry through tsx, so no build step is needed.
8
11
  import { access } from "node:fs/promises";
@@ -138,6 +141,25 @@ if (command === "update" || command === "upgrade") {
138
141
  register();
139
142
  const { runPairCommand } = await import("../apps/dpi-backend/src/pair-cli.ts");
140
143
  process.exit(await runPairCommand(commandRest));
144
+ } else if (command === "schedule") {
145
+ // Scheduled sessions: the CLI only edits the device's records over its own API,
146
+ // so a running daemon picks changes up without a restart.
147
+ const { register } = await loadTsx();
148
+ register();
149
+ const { scheduleCli } = await import("../apps/dpi-backend/src/schedule-cli.ts");
150
+ process.exit(await scheduleCli(commandRest));
151
+ } else if (command === "notify") {
152
+ // Outbound fan-out: the CLI edits the device's sinks over its own API.
153
+ const { register } = await loadTsx();
154
+ register();
155
+ const { notifyCli } = await import("../apps/dpi-backend/src/notify-cli.ts");
156
+ process.exit(await notifyCli(commandRest));
157
+ } else if (command === "gc") {
158
+ // Retention: dry-run unless --yes. Never runs on its own (policy gate #3).
159
+ const { register } = await loadTsx();
160
+ register();
161
+ const { gcCli } = await import("../apps/dpi-backend/src/gc-cli.ts");
162
+ process.exit(await gcCli({ argv: commandRest }));
141
163
  } else if (command === "doctor") {
142
164
  // One-shot health check. The logic lives in the backend as TS (testable with
143
165
  // injected fakes); this is only the tsx loader + the exit code.
@@ -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: **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)).
4
+ Status: **Waves 1a+1b+2 ADOPTED (0.0.41 — 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).** Remaining: env UI, backup/restore, per-project settings (Wave 2 SHOULDs) and Wave 3. Policy gates #1/#2/#4 are still open; #3 is implemented as manual-only GC (no defaults, no timer). 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
 
@@ -134,14 +134,14 @@ None of them blocks Wave 1.
134
134
  | Tier | Feature | Source (path:line) | Ours | Adoption suggestion |
135
135
  |---|---|---|---|---|
136
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
- | 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 |
137
+ | MUST | Scheduled sessions (device-side) | orca `automations/service.ts:186-211` (scheduled trigger, precheck, completion watcher; separate drift report) | ✅ (`0.0.40`) | `schedules.ts` registry + a 30 s unref'd device loop (`store.ts`): a run creates a **fresh session** (`<name> · <time>`), sends the prompt, records the outcome. `dpi schedule list/add/enable/disable/run/remove`; Inspector **Auto** tab. Live: run → `ok`, next run computed |
138
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
- | 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 |
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`) | ✅ (`0.0.41`) | `notify-sinks.ts`: webhook + ntfy sinks, per-(sink,event-kind) 10 s cooldown, SSRF guard with `DPI_NOTIFY_ALLOW_PRIVATE=1` for LAN. Events: `session.failed`, `schedule.ok`, `schedule.failed`, `test`. `dpi notify list/add/enable/disable/remove/test/events`; Inspector **Notify** tab. Live: ntfy.sh received the test sent from the panel |
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
- | 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 |
142
- | SHOULD | Remote update badge — **policy #4** | orca `ssh/managed-server-update-check.ts` + `orcad-update-plan.ts` | 🟡 (`dpi update --check` exists, `dpi.mjs:36`) | hub compares `/device` version vs registry → badge. Device always self-updates; hub never pushes code |
141
+ | MUST | Retention / auto-GC — **policy #3** | orca `terminal-history-gc.ts`; piggery `gc --closed-before DURATION [--dry-run]` (`docs/reference.md:31`) | ✅ manual-only (`0.0.40`) | `gc.ts` + `dpi gc --closed-before 30d [--yes]`: **dry-run is the default and nothing schedules itself** — the retention policy stays the operator's call (gate #3 remains open for defaults) |
142
+ | SHOULD | Remote update badge — **policy #4** | orca `ssh/managed-server-update-check.ts` + `orcad-update-plan.ts` | ✅ (`0.0.40`) | `GET /api/version` (hub walks up to the `my-durable` package.json) + device `packageVersion` in `/v1/device` → tree badge "update". Hint only: devices self-update, the hub never pushes code. Verified 0 badges when versions match, and the 1.3.0-vs-0.0.39 trap (pi-durable's version) is fixed by reporting both |
143
143
  | SHOULD | Backup/restore of session data | orca `rolling-file-backup.ts`; paseo `migrations/` (schema side) | ❌ | rolling copies of registry + device store ahead of schema migrations |
144
- | SHOULD | Rate-limit surfacing | orca `rate-limits/` | ❌ | parse provider 429/limit info at probe/send time → hint in model picker |
144
+ | SHOULD | Rate-limit surfacing | orca `rate-limits/` | ✅ device-side (`0.0.41`) | `classifyProviderError`: 429/quota → `rate_limited` (+`retryAfterMs` from Retry-After), 401/403 → `auth`, 404 → `missing`; `probeModel` returns the provider's own words, `dpi doctor` prints "rate limited — retry in 30s" / "provider key rejected". **Not** in the web picker: `probe-model` is deliberately local-only (never tunnelled), so the FE cannot probe |
145
145
  | SHOULD | Per-project settings/instructions | orca `settings/RepositoryPane.tsx` | ❌ | after the project entity: per-project model/env defaults |
146
146
 
147
147
  ## Wave 3 — differentiators / later
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-durable",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
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": {