feat(daemon): collapse workspace noise into a "show hidden" section

Discovery returns every pi session directory ever seen, so the console opened on
47 rows on this machine: 20 ghosts (cwd deleted) and 21 scratch dirs under /tmp
next to the real projects. Every row now carries a derived, non-persisted
`visibility`/`visibilityReason`; nothing is filtered server-side, so
`/workspace/<id>` deep links and the chat page's id lookup still resolve.

Precedence: explicit `hidden` wins; a live instance, `pinned` or `trusted`
rescues a row; then temp paths (`PI2_WORKSPACE_HIDE_TEMP`, on), ghosts
(`PI2_WORKSPACE_HIDE_GHOSTS`, on), outside roots (`PI2_WORKSPACE_HIDE_OUTSIDE_ROOTS`,
off) and staleness (`PI2_WORKSPACE_STALE_DAYS`, off). Measured on real data:
47 → 26 default rows, 0 openable rows lost.

The browser collapses the secondary rows behind a persisted toggle and dims them
with a reason badge; `workspace.add` now clears `hidden`.
This commit is contained in:
yuez committed 2026-10-23 10:08:15 +08:00
1 parent 58e247644d
commit 64a1a98c1f
12 files changed
+888 -38

No files matched your search

+27
View File
@@ -90,6 +90,33 @@ Plugin obligations:
| `GET /api/v1/resources` | instances, sessions, RSS totals for the soft-limit notice |
| `GET /api/v1/diagnostics` | connections, event rates, slow queries, instance table |
Workspace row (`GET /api/v1/workspaces`) — registry entry ∪ disk discovery ∪ live instance state. Every known workspace is returned; rows are never filtered, so `/workspace/<workspaceId>` deep links always resolve:
| Field | Notes |
|---|---|
| `workspaceId` | `sha256(realpath(cwd)).slice(0,16)` |
| `cwd`, `name`, `alias` | `name` falls back to `alias`, then `basename(cwd)` |
| `pinned`, `hidden`, `trusted` | persisted user intent from `workspaces.json` |
| `exists` | `false` = ghost (the cwd is gone; the session files are not) |
| `sessionCount`, `liveCount`, `lastActiveAt` | disk projection (`lastActiveAt` may be `null`) |
| `instance` | live `InstanceState` or `null` |
| `visibility?: "default" \| "secondary"` | derived, never persisted: the workspace-noise policy. Missing ⇒ `default` |
| `visibilityReason?` | `hidden` \| `ghost` \| `temp` \| `outside-roots` \| `stale`; absent for `default` rows |
The classification is advisory and client-side only (precedence, first match wins):
1. `hidden: true` → `secondary`/`hidden` — explicit user intent always wins, no rescue.
2. A live instance (`instance != null` or `liveCount > 0`), `pinned` or `trusted` → `default` (rescue).
3. `PI2_WORKSPACE_HIDE_TEMP=1` (default `1`) and `cwd` is under `$TMPDIR`, `/tmp`, `/var/tmp`, `/var/folders` or `/private/var/folders` → `secondary`/`temp`.
4. `PI2_WORKSPACE_HIDE_GHOSTS=1` (default `1`) and `exists === false` → `secondary`/`ghost`.
5. `PI2_WORKSPACE_HIDE_OUTSIDE_ROOTS=1` (default `0`) and `cwd` is outside `PI2_WORKSPACE_ROOTS` → `secondary`/`outside-roots`.
6. `PI2_WORKSPACE_STALE_DAYS=<n>` (default `0` = off) and `lastActiveAt` older than `n` days → `secondary`/`stale` (`lastActiveAt: null` never counts).
7. Otherwise `default`.
A client that lets the user *choose* a workspace should list only `default` rows by
default; `secondary` rows belong behind a “show hidden” toggle. Lookups by
`workspaceId` must ignore `visibility` entirely.
Session row (`GET /api/v1/workspaces/:id/sessions`) — a subset of `SessionState` plus list metadata (`usage`, `flags`, `entries` and `attention` arrive via snapshot/events, not on this row):
| Field | Notes |