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
@@ -7,8 +7,8 @@
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-D4M8tCcs.js"></script>
11
- <link rel="stylesheet" crossorigin href="/assets/index-xOvj8ub1.css">
10
+ <script type="module" crossorigin src="/assets/index-jDhVa5sg.js"></script>
11
+ <link rel="stylesheet" crossorigin href="/assets/index-DMJMesxP.css">
12
12
  </head>
13
13
  <body>
14
14
  <div id="app"></div>
@@ -26,6 +26,8 @@ async function call<T>(method: string, path: string, body?: unknown): Promise<T>
26
26
 
27
27
  export const hub = {
28
28
  network: () => call<{ configFile?: string; devices: NetworkDevice[] }>("GET", "/network"),
29
+ /** The hub's own version, for the "device is behind" badge. */
30
+ version: () => call<{ version: string; node: string }>("GET", "/version"),
29
31
  /** Probe a device now. Devices themselves are configured in dpi-network.yaml, not here. */
30
32
  check: (id: string) =>
31
33
  call<NetworkDevice>("POST", `/devices/${encodeURIComponent(id)}/check`, {}),
@@ -15,6 +15,9 @@ export const streamState = ref(stream.state);
15
15
  stream.onState((s) => (streamState.value = s));
16
16
  export const network = useNetwork(stream);
17
17
  export const configFile = ref<string>();
18
+ /** The hub's own version. A device reporting another one is behind (badge only:
19
+ * the hub never pushes code, devices self-update). */
20
+ export const hubVersion = ref<string>();
18
21
 
19
22
  // ------------------------------------------------------------------ selection + persisted UI state
20
23
 
@@ -122,6 +125,7 @@ export async function boot() {
122
125
  hub.uiGet<{ tree: boolean; inspector: boolean }>("layout.panels"),
123
126
  ]);
124
127
  if (panels) Object.assign(layout, panels);
128
+ void hub.version().then((v) => (hubVersion.value = v.version)).catch(() => {});
125
129
  configFile.value = net.configFile;
126
130
  if (!network.model.devices.length)
127
131
  network.model.apply({ type: "network", devices: net.devices });
@@ -5,6 +5,8 @@ import {
5
5
  Braces,
6
6
  Download,
7
7
  PackageOpen,
8
+ PiggyBank,
9
+ CalendarClock,
8
10
  GitBranch,
9
11
  ChevronDown,
10
12
  FolderOpen,
@@ -24,6 +26,8 @@ import TokenManager from "./TokenManager.vue";
24
26
  import TasksPanel from "./TasksPanel.vue";
25
27
  import GitPanel from "./GitPanel.vue";
26
28
  import HostPanel from "./HostPanel.vue";
29
+ import UsagePanel from "./UsagePanel.vue";
30
+ import SchedulesPanel from "./SchedulesPanel.vue";
27
31
  import ExtensionsPanel from "./ExtensionsPanel.vue";
28
32
  import ContextBar from "./ContextBar.vue";
29
33
  import { deviceClient, message } from "../client/hub";
@@ -64,6 +68,8 @@ const tabs = [
64
68
  { id: "session", label: "Session", icon: FolderOpen },
65
69
  { id: "git", label: "Git", icon: GitBranch },
66
70
  { id: "host", label: "Host", icon: Activity },
71
+ { id: "usage", label: "Usage", icon: PiggyBank },
72
+ { id: "auto", label: "Auto", icon: CalendarClock },
67
73
  { id: "state", label: "State", icon: Braces },
68
74
  { id: "tasks", label: "Tasks", icon: Activity },
69
75
  { id: "tools", label: "Tools", icon: Wrench },
@@ -433,6 +439,8 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
433
439
  <TasksPanel v-if="ui.tab === 'tasks'" />
434
440
  <GitPanel v-if="ui.tab === 'git'" />
435
441
  <HostPanel v-if="ui.tab === 'host'" />
442
+ <UsagePanel v-if="ui.tab === 'usage'" />
443
+ <SchedulesPanel v-if="ui.tab === 'auto'" />
436
444
  <ExtensionsPanel v-if="ui.tab === 'extensions'" />
437
445
  <template v-if="ui.tab === 'tools'"
438
446
  ><div class="panel-heading">
@@ -4,6 +4,7 @@ import { Link2, ListChecks, Network, PanelLeftClose, PanelLeftOpen, Search, X }
4
4
  import DeviceIcon from "./DeviceIcon.vue";
5
5
  import type { TreeNode } from "@sdk/models";
6
6
  import TreeRow from "./TreeRow.vue";
7
+ import ProjectBar from "./ProjectBar.vue";
7
8
  import { deviceClient, hub } from "../client/hub";
8
9
  import {
9
10
  attempt,
@@ -60,9 +61,29 @@ const matchedSessions = computed(() => {
60
61
  });
61
62
  /** A filter keeps the matched sessions, their agents, and the devices holding
62
63
  * them — a hit you cannot locate in the tree is a riddle, not a result. */
64
+ /** Project chip filter: a session belongs to the project whose root holds its cwd. */
65
+ const projectFilter = ref<{ deviceId: string; rootPath: string }>();
66
+ const inProject = (deviceId: string, cwd: string) =>
67
+ !projectFilter.value ||
68
+ (projectFilter.value.deviceId === deviceId &&
69
+ (cwd === projectFilter.value.rootPath || cwd.startsWith(`${projectFilter.value.rootPath}/`)));
70
+
63
71
  const localRows = computed(() => {
64
- if (!filtering.value) return rows.value;
72
+ if (!filtering.value && !projectFilter.value) return rows.value;
65
73
  const keep = (node: TreeNode): boolean => {
74
+ if (projectFilter.value) {
75
+ const deviceId = node.type === "device" ? node.device.id : node.deviceId;
76
+ if (node.type === "session" && !inProject(deviceId, node.session.cwd)) return false;
77
+ if (node.type === "agent") {
78
+ const session = network.devices.value
79
+ .find((d) => d.id === node.deviceId)
80
+ ?.tree?.sessions.find((s) => s.id === node.sessionId);
81
+ if (session && !inProject(node.deviceId, session.cwd)) return false;
82
+ }
83
+ if (node.type === "device")
84
+ return (node.device.tree?.sessions ?? []).some((s) => inProject(node.device.id, s.cwd));
85
+ }
86
+ if (!filtering.value) return true;
66
87
  if (node.type === "session") return matchedSessions.value.has(node.session.id);
67
88
  if (node.type === "agent")
68
89
  return matchedSessions.value.has(node.sessionId) || node.agent.name.toLowerCase().includes(needle.value);
@@ -296,6 +317,7 @@ function keydown(e: KeyboardEvent) {
296
317
  </button>
297
318
  <span v-if="searching" class="searching" aria-label="Searching devices">…</span>
298
319
  </div>
320
+ <ProjectBar v-model:active="projectFilter" />
299
321
  <div
300
322
  ref="list"
301
323
  class="tree-list"
@@ -0,0 +1,284 @@
1
+ <script setup lang="ts">
2
+ // Projects (Wave 2): the roots sessions start in, promoted to entities you can
3
+ // name, label and archive — paseo's workspace-registry model, device-owned.
4
+ //
5
+ // The bar is a filter: click a project to narrow the tree to its sessions.
6
+ // Chips load once per online device (asked for, never polled).
7
+ import { computed, ref, watch } from "vue";
8
+ import { FolderGit2, Folder, Tag, Pencil, Archive, ArchiveRestore, X } from "lucide-vue-next";
9
+ import type { ProjectRecord } from "@sdk/api";
10
+ import { deviceClient, message } from "../client/hub";
11
+ import { network, notify, ui } from "../client/store";
12
+
13
+ interface Listed {
14
+ deviceId: string;
15
+ project: ProjectRecord;
16
+ sessions: number;
17
+ }
18
+
19
+ /** v-model:active — the filter lives in the sidebar (it narrows the tree). */
20
+ const active = defineModel<{ deviceId: string; rootPath: string } | undefined>("active");
21
+ const items = ref<Listed[]>([]);
22
+ const loading = ref(false);
23
+ const failed = ref("");
24
+ const showArchived = ref(false);
25
+
26
+ const onlineIds = computed(() =>
27
+ network.devices.value.filter((d) => d.status === "online").map((d) => d.id),
28
+ );
29
+
30
+ async function load() {
31
+ loading.value = true;
32
+ failed.value = "";
33
+ const out: Listed[] = [];
34
+ const errors: string[] = [];
35
+ for (const id of onlineIds.value) {
36
+ const device = network.devices.value.find((d) => d.id === id);
37
+ const result = await deviceClient(id)
38
+ .projects(showArchived.value)
39
+ .catch((e) => {
40
+ // A device on an older build has no /projects route (it answers 404, or
41
+ // its own allowlist refuses the route). That is not an error the human
42
+ // can act on, so it is not shown — the project list is just shorter.
43
+ const text = message(e);
44
+ const stale = (e as { code?: string }).code === "not_found" || /allowlist|not found/i.test(text);
45
+ if (!stale) errors.push(`${id}: ${text.slice(0, 60)}`);
46
+ return undefined;
47
+ });
48
+ for (const project of result?.projects ?? []) {
49
+ const sessions = (device?.tree?.sessions ?? []).filter(
50
+ (s) => s.cwd === project.rootPath || s.cwd.startsWith(`${project.rootPath}/`),
51
+ ).length;
52
+ out.push({ deviceId: id, project, sessions });
53
+ }
54
+ }
55
+ items.value = out.sort((a, b) => display(a.project).localeCompare(display(b.project)));
56
+ if (errors.length) failed.value = errors.join(" · ");
57
+ loading.value = false;
58
+ }
59
+
60
+ watch([onlineIds, showArchived], load, { immediate: true });
61
+
62
+ const display = (project: ProjectRecord) => project.customName ?? project.name;
63
+ const isActive = (item: Listed) =>
64
+ active.value?.deviceId === item.deviceId && active.value.rootPath === item.project.rootPath;
65
+
66
+ function toggle(item: Listed) {
67
+ active.value = isActive(item) ? undefined : { deviceId: item.deviceId, rootPath: item.project.rootPath };
68
+ }
69
+
70
+ /** Two separate app-styled prompts (not chained: the dialog closes after each run). */
71
+ function rename(item: Listed) {
72
+ const project = item.project;
73
+ ui.dialog = {
74
+ kind: "prompt",
75
+ title: `Rename ${display(project)}`,
76
+ label: "Project name",
77
+ hint: "Shown in the tree and in usage rollups. Leave empty to use the folder name.",
78
+ value: project.customName ?? "",
79
+ placeholder: project.name,
80
+ submit: "Save name",
81
+ run: async (value) => {
82
+ const updated = await deviceClient(item.deviceId).updateProject(project.id, { customName: value });
83
+ notify(`Project renamed to ${updated.customName ?? updated.name}.`);
84
+ await load();
85
+ },
86
+ };
87
+ }
88
+
89
+ function labels(item: Listed) {
90
+ const project = item.project;
91
+ ui.dialog = {
92
+ kind: "prompt",
93
+ title: `Labels for ${display(project)}`,
94
+ label: "Labels (comma separated)",
95
+ hint: "Lowercase, up to 12 labels of 32 characters. Used to filter projects.",
96
+ value: project.labels.join(", "),
97
+ submit: "Save labels",
98
+ run: async (value) => {
99
+ const updated = await deviceClient(item.deviceId).updateProject(project.id, {
100
+ labels: value
101
+ .split(",")
102
+ .map((l) => l.trim())
103
+ .filter(Boolean),
104
+ });
105
+ notify(
106
+ updated.labels.length ? `Labels: ${updated.labels.join(", ")}.` : `Labels cleared on ${display(updated)}.`,
107
+ );
108
+ await load();
109
+ },
110
+ };
111
+ }
112
+
113
+ function archive(item: Listed) {
114
+ const project = item.project;
115
+ const archived = project.archivedAt !== null;
116
+ ui.dialog = {
117
+ kind: "prompt",
118
+ title: `${archived ? "Restore" : "Archive"} ${display(project)}?`,
119
+ hint: archived
120
+ ? "The project returns to the tree. Its sessions were never touched."
121
+ : "Bookkeeping only: the project leaves the list, its sessions keep running. Nothing is deleted.",
122
+ submit: archived ? "Restore project" : "Archive project",
123
+ danger: !archived,
124
+ run: async () => {
125
+ const client = deviceClient(item.deviceId);
126
+ if (archived) await client.unarchiveProject(project.id);
127
+ else await archiveAt(client, project.id);
128
+ if (!archived && isActive(item)) active.value = undefined;
129
+ await load();
130
+ },
131
+ };
132
+ }
133
+
134
+ const archiveAt = (client: ReturnType<typeof deviceClient>, id: string) => client.archiveProject(id);
135
+
136
+ defineExpose({ reload: load });
137
+ </script>
138
+
139
+ <template>
140
+ <div class="project-bar" aria-label="Projects">
141
+ <div class="project-head">
142
+ <span class="project-title"><FolderGit2 :size="13" />PROJECTS</span>
143
+ <button
144
+ class="icon-button tiny"
145
+ :class="{ on: showArchived }"
146
+ :aria-label="showArchived ? 'Hide archived projects' : 'Show archived projects'"
147
+ :title="showArchived ? 'Hide archived projects' : 'Show archived projects'"
148
+ @click="showArchived = !showArchived"
149
+ >
150
+ <Archive :size="12" />
151
+ </button>
152
+ <span v-if="loading" class="project-hint">…</span>
153
+ </div>
154
+ <div v-if="items.length" class="chips">
155
+ <button
156
+ v-for="item in items"
157
+ :key="`${item.deviceId}-${item.project.id}`"
158
+ class="chip"
159
+ :class="{ on: isActive(item), archived: item.project.archivedAt }"
160
+ :title="`${item.project.rootPath} — ${item.sessions} session${item.sessions === 1 ? '' : 's'}`"
161
+ @click="toggle(item)"
162
+ @dblclick="rename(item)"
163
+ >
164
+ <Folder v-if="item.project.kind === 'plain'" :size="11" />
165
+ <FolderGit2 v-else :size="11" />
166
+ <span class="chip-name">{{ display(item.project) }}</span>
167
+ <em class="chip-count">{{ item.sessions }}</em>
168
+ <span v-for="label in item.project.labels.slice(0, 2)" :key="label" class="chip-label">{{ label }}</span>
169
+ </button>
170
+ </div>
171
+ <p v-else-if="!loading" class="project-hint">
172
+ No projects yet — a project appears when a session starts in a folder.
173
+ </p>
174
+
175
+ <div v-if="active" class="project-actions">
176
+ <span class="project-hint">filtering</span>
177
+ <template v-for="item in items.filter(isActive)" :key="item.project.id">
178
+ <button class="small" @click="rename(item)"><Pencil :size="12" />name</button>
179
+ <button class="small" @click="labels(item)"><Tag :size="12" />labels</button>
180
+ <button class="small" @click="archive(item)">
181
+ <ArchiveRestore v-if="item.project.archivedAt" :size="12" />
182
+ <Archive v-else :size="12" />
183
+ {{ item.project.archivedAt ? "restore" : "archive" }}
184
+ </button>
185
+ <button class="icon-button tiny" aria-label="Clear project filter" @click="active = undefined">
186
+ <X :size="12" />
187
+ </button>
188
+ </template>
189
+ </div>
190
+ <p v-if="failed" class="message-error">{{ failed }}</p>
191
+ <p v-if="items.some((i) => i.project.labels.length)" class="project-hint labels-hint">
192
+ <Tag :size="11" />labels: {{ [...new Set(items.flatMap((i) => i.project.labels))].join(" · ") }}
193
+ </p>
194
+ </div>
195
+ </template>
196
+
197
+ <style scoped>
198
+ .project-bar {
199
+ display: flex;
200
+ flex-direction: column;
201
+ gap: 6px;
202
+ margin: 2px 6px 4px;
203
+ }
204
+ .project-head {
205
+ display: flex;
206
+ align-items: center;
207
+ gap: 6px;
208
+ }
209
+ .project-title {
210
+ display: inline-flex;
211
+ align-items: center;
212
+ gap: 4px;
213
+ font-size: 12px;
214
+ letter-spacing: 0.06em;
215
+ opacity: 0.6;
216
+ }
217
+ .project-hint {
218
+ font-size: 13px;
219
+ opacity: 0.6;
220
+ display: inline-flex;
221
+ align-items: center;
222
+ gap: 4px;
223
+ margin: 0;
224
+ }
225
+ .chips {
226
+ display: flex;
227
+ flex-wrap: wrap;
228
+ gap: 5px;
229
+ }
230
+ .chip {
231
+ display: inline-flex;
232
+ align-items: center;
233
+ gap: 5px;
234
+ max-width: 100%;
235
+ padding: 3px 8px;
236
+ border: 1px solid var(--line);
237
+ border-radius: 999px;
238
+ background: none;
239
+ color: var(--fg);
240
+ font-size: 14px;
241
+ cursor: pointer;
242
+ }
243
+ .chip:hover {
244
+ border-color: var(--accent);
245
+ }
246
+ .chip.on {
247
+ border-color: var(--accent);
248
+ background: color-mix(in srgb, var(--accent) 14%, transparent);
249
+ }
250
+ .chip.archived {
251
+ opacity: 0.55;
252
+ }
253
+ .chip-name {
254
+ overflow: hidden;
255
+ text-overflow: ellipsis;
256
+ white-space: nowrap;
257
+ max-width: 160px;
258
+ }
259
+ .chip-count {
260
+ font-style: normal;
261
+ font-size: 11px;
262
+ opacity: 0.65;
263
+ font-variant-numeric: tabular-nums;
264
+ }
265
+ .chip-label {
266
+ font-size: 11px;
267
+ padding: 0 5px;
268
+ border-radius: 6px;
269
+ border: 1px solid var(--line);
270
+ opacity: 0.75;
271
+ }
272
+ .project-actions {
273
+ display: flex;
274
+ align-items: center;
275
+ gap: 6px;
276
+ flex-wrap: wrap;
277
+ }
278
+ .icon-button.tiny {
279
+ padding: 2px;
280
+ }
281
+ .labels-hint {
282
+ flex-wrap: wrap;
283
+ }
284
+ </style>