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.
@@ -1,9 +1,10 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, ref } from "vue";
3
- import { Link2, ListChecks, Network, PanelLeftClose, PanelLeftOpen } from "lucide-vue-next";
2
+ import { computed, nextTick, ref, watch } from "vue";
3
+ import { Link2, ListChecks, Network, PanelLeftClose, PanelLeftOpen, Search, X } from "lucide-vue-next";
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,
@@ -39,6 +40,88 @@ const rows = computed(() => {
39
40
  const focusKey = ref<string>();
40
41
  const list = ref<HTMLElement>();
41
42
 
43
+ /** Session search (paseo `agent-history-search`, cheap v1). The local pass
44
+ * filters the tree instantly; the device pass asks each online device for its
45
+ * own matches (names/cwds/models) so results do not depend on how fresh the
46
+ * hub's tree is. Transcripts are not scanned — that needs an FTS index. */
47
+ const query = ref("");
48
+ const deviceHits = ref<{ deviceId: string; name: string; cwd: string; id: string; where: string[] }[]>([]);
49
+ const searching = ref(false);
50
+ const needle = computed(() => query.value.trim().toLowerCase());
51
+ const filtering = computed(() => needle.value.length >= 2);
52
+
53
+ /** Sessions whose name/cwd matches — the anchor a filter keeps the tree around. */
54
+ const matchedSessions = computed(() => {
55
+ const ids = new Set<string>();
56
+ if (!filtering.value) return ids;
57
+ for (const device of network.devices.value)
58
+ for (const session of device.tree?.sessions ?? [])
59
+ if (`${session.name}\n${session.cwd}`.toLowerCase().includes(needle.value)) ids.add(session.id);
60
+ return ids;
61
+ });
62
+ /** A filter keeps the matched sessions, their agents, and the devices holding
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
+
71
+ const localRows = computed(() => {
72
+ if (!filtering.value && !projectFilter.value) return rows.value;
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;
87
+ if (node.type === "session") return matchedSessions.value.has(node.session.id);
88
+ if (node.type === "agent")
89
+ return matchedSessions.value.has(node.sessionId) || node.agent.name.toLowerCase().includes(needle.value);
90
+ return (node.device.tree?.sessions ?? []).some((s) => matchedSessions.value.has(s.id));
91
+ };
92
+ const visible = new Set(rows.value.filter((row) => keep(row.node)).map((row) => row.node.key));
93
+ return rows.value.filter((row) => visible.has(row.node.key));
94
+ });
95
+ /** Device hits the tree already shows are dropped: one row per session. */
96
+ const extraHits = computed(() =>
97
+ deviceHits.value.filter((hit) => !rows.value.some((r) => r.node.type === "session" && r.node.session.id === hit.id)),
98
+ );
99
+
100
+ let searchTimer: ReturnType<typeof setTimeout> | undefined;
101
+ watch(query, (value) => {
102
+ clearTimeout(searchTimer);
103
+ const q = value.trim();
104
+ if (q.length < 2) {
105
+ deviceHits.value = [];
106
+ searching.value = false;
107
+ return;
108
+ }
109
+ searchTimer = setTimeout(async () => {
110
+ searching.value = true;
111
+ const found: typeof deviceHits.value = [];
112
+ for (const device of network.devices.value.filter((d) => d.status === "online")) {
113
+ const result = await deviceClient(device.id)
114
+ .searchSessions(q)
115
+ .catch(() => undefined);
116
+ for (const match of result?.matches ?? [])
117
+ found.push({ deviceId: device.id, id: match.id, name: match.name, cwd: match.cwd, where: match.where });
118
+ }
119
+ deviceHits.value = found;
120
+ searching.value = false;
121
+ }, 250);
122
+ });
123
+ const clearSearch = () => ((query.value = ""), (deviceHits.value = []));
124
+
42
125
  /** Bulk session manage (orca ManageSessionsSection): select many, then
43
126
  * archive/abort each with a per-row result. Client-side loop over the
44
127
  * existing APIs — no new backend surface. */
@@ -219,6 +302,22 @@ function keydown(e: KeyboardEvent) {
219
302
  <PanelLeftClose :size="18" />
220
303
  </button>
221
304
  </header>
305
+ <div class="tree-search">
306
+ <Search :size="14" class="search-icon" />
307
+ <input
308
+ v-model="query"
309
+ type="search"
310
+ class="search-input"
311
+ placeholder="Search sessions…"
312
+ aria-label="Search sessions"
313
+ spellcheck="false"
314
+ />
315
+ <button v-if="query" class="icon-button clear" aria-label="Clear search" @click="clearSearch">
316
+ <X :size="13" />
317
+ </button>
318
+ <span v-if="searching" class="searching" aria-label="Searching devices">…</span>
319
+ </div>
320
+ <ProjectBar v-model:active="projectFilter" />
222
321
  <div
223
322
  ref="list"
224
323
  class="tree-list"
@@ -236,7 +335,7 @@ function keydown(e: KeyboardEvent) {
236
335
  </button>
237
336
  </div>
238
337
  <TreeRow
239
- v-for="row in rows"
338
+ v-for="row in localRows"
240
339
  :key="row.node.key"
241
340
  :node="row.node"
242
341
  :depth="row.depth"
@@ -251,7 +350,24 @@ function keydown(e: KeyboardEvent) {
251
350
  @action="action(row.node, $event)"
252
351
  @check="bulkToggle(row.node)"
253
352
  />
254
- <p v-if="!rows.length" class="hint tree-empty" data-testid="tree-empty">
353
+ <template v-if="filtering && extraHits.length">
354
+ <div class="hit-head hint">{{ extraHits.length }} more on device</div>
355
+ <button
356
+ v-for="hit in extraHits"
357
+ :key="`${hit.deviceId}-${hit.id}`"
358
+ class="hit"
359
+ :title="hit.cwd"
360
+ @click="select({ deviceId: hit.deviceId, sessionId: hit.id, agentId: 1 })"
361
+ >
362
+ <span class="hit-name">{{ hit.name }}</span>
363
+ <code class="hit-cwd">{{ hit.cwd }}</code>
364
+ <em v-if="hit.where.length" class="hit-where">{{ hit.where.join(" · ") }}</em>
365
+ </button>
366
+ </template>
367
+ <p v-if="filtering && !localRows.length && !extraHits.length" class="hint tree-empty">
368
+ No session matches “{{ query.trim() }}”.
369
+ </p>
370
+ <p v-if="!rows.length && !filtering" class="hint tree-empty" data-testid="tree-empty">
255
371
  No devices yet. Declare them in <code>dpi-network.yaml</code> (start from
256
372
  <code>dpi-network.example.yaml</code>), then run <code>just net up &lt;id&gt;</code>.
257
373
  </p>
@@ -292,6 +408,28 @@ function keydown(e: KeyboardEvent) {
292
408
  </template>
293
409
 
294
410
  <style scoped>
411
+ .tree-search {
412
+ display: flex; align-items: center; gap: 6px; margin: 4px 6px 2px;
413
+ padding: 0 8px; border: 1px solid var(--line); border-radius: 8px;
414
+ }
415
+ .tree-search:focus-within { border-color: var(--accent); }
416
+ .tree-search .search-icon { opacity: 0.6; flex: none; }
417
+ .search-input {
418
+ flex: 1; min-width: 0; border: 0; background: transparent; color: var(--fg);
419
+ font-size: 14px; padding: 6px 0; outline: none;
420
+ }
421
+ .search-input::-webkit-search-cancel-button { display: none; }
422
+ .tree-search .clear { padding: 2px; }
423
+ .searching { opacity: 0.6; font-size: 13px; }
424
+ .hit-head { margin: 6px 2px 2px; }
425
+ .hit {
426
+ display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left;
427
+ background: none; border: 1px solid transparent; border-radius: 8px;
428
+ padding: 5px 8px; color: var(--fg); font-size: 15px; cursor: pointer;
429
+ }
430
+ .hit:hover { border-color: var(--line); background: var(--hover, rgba(127,127,127,0.08)); }
431
+ .hit-cwd { font-size: 12px; opacity: 0.65; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
432
+ .hit-where { font-style: normal; font-size: 11px; opacity: 0.5; text-transform: uppercase; letter-spacing: 0.04em; }
295
433
  .bulk-bar {
296
434
  display: flex; gap: 8px; align-items: center; padding: 6px 10px; margin: 4px 0;
297
435
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
@@ -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>