fix(web): render the chat session tree from parent/sub-session lineage
The sidebar treated every workspace session as a root and only nested the manifest sub-agents, so sub-session files showed up as siblings (the same child twice); sub-sessions the plugin marked hidden were listed anyway. - build the tree from `parentId` in a pure `buildSessionTree` model: orphans are promoted to roots, cycles and duplicate ids are guarded, real child-session rows win over the manifest projection, and the routed row force-opens its ancestors - honour the plugin's `:PiSessions` visibility (`visible: false`) with a "show hidden sub-sessions" toggle, the routed-row exception and a dedicated all-hidden empty state - keep tree metadata across WS snapshots, reducer events, id migration and parent removal; prefer a root row for the `/chat` index and add a "back to parent" action - document the session-row and `pi2:subagents` list metadata in the protocol
This commit is contained in:
1 parent
7e780515ac
commit
06e70204e7
15 files changed
+1133
-240
No files matched your search
+35
-2
@@ -82,7 +82,7 @@ Plugin obligations:
|
||||
| `GET /api/v1/info` | `{v, daemonId, machineId, platform, hostname, os, version, uptimeMs, pid, port, capabilities, limits}` |
|
||||
| `GET /api/v1/health` | `{ok, items:[{name, ok, detail}]}` |
|
||||
| `GET /api/v1/workspaces` | `WorkspaceInfo[]` (registry + disk index + instance state) |
|
||||
| `GET /api/v1/workspaces/:id/sessions` | relayed `workspace.query{kind:"sessions"}` |
|
||||
| `GET /api/v1/workspaces/:id/sessions` | relayed `workspace.query{kind:"sessions"}` (row fields below) |
|
||||
| `GET /api/v1/sessions/:sid/entries?before=&limit=` | relayed; plugin paginates |
|
||||
| `GET /api/v1/attention?workspaceId=` | pending attention for one workspace |
|
||||
| `GET /api/v1/devices` | paired devices (daemon-owned) |
|
||||
@@ -90,6 +90,32 @@ 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 |
|
||||
|
||||
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 |
|
||||
|---|---|
|
||||
| `sessionId`, `sessionFile?`, `name?`, `cwd?`, `timestamp?`, `modified?`, `firstMessage?` | identity + disk projection |
|
||||
| `tab?`, `live?` | live projection |
|
||||
| `status?` | live status when `live` (`busy`, `compacting`, `idle`, `exited`); otherwise the child's manifest status (`dormant`, `done`, `error`, `interrupted`, `exited`). Absent on a non-live root. |
|
||||
| `model?`, `thinking?` | per-session model pin; the child's manifest thinking level |
|
||||
| `visible: boolean` | always present; the plugin's `:PiSessions` visibility decision |
|
||||
| `parentId?: string` | sub-session rows only: the parent session id (normally present in the same list) |
|
||||
| `task?`, `agentSpawned?`, `reported?` | sub-session rows only, carried through from the spawn request |
|
||||
| `createdAt?`, `lastActiveAt?` | epoch ms; ordering/aging hints, never required |
|
||||
|
||||
Sub-session rows sit in the same flat list as their parent: build the tree from `parentId`
|
||||
(an unknown `parentId`, or one whose row was pruned, promotes the row to a root so a row is
|
||||
never lost). `status` of a non-live child is one of `dormant|done|error|interrupted|exited`;
|
||||
a live child reports its live status.
|
||||
|
||||
Visibility follows the plugin's `:PiSessions` policy (`visible: false` = hidden), but the
|
||||
field is advisory: a client may still render hidden rows on request (pi2 web's “show hidden
|
||||
sub-sessions” toggle) or when the row is the routed/selected session. An active search filter
|
||||
takes precedence over the routed row in pi2 web (a non-matching row stays out, even when it is
|
||||
selected). A manifest `pi2:subagents` entry that also has a session row (same id) must render
|
||||
as that row only — the session row wins. `pi2:subagents` entries may additionally carry
|
||||
`parentId?`, `visible?`, `createdAt?`, `lastActiveAt?`.
|
||||
|
||||
### 3.2 Commands (writes)
|
||||
|
||||
`POST /api/v1/cmd` with `{method, params, sessionId?, clientRequestId?}` → `202 {accepted, disposition}`.
|
||||
@@ -136,11 +162,18 @@ interface SessionState {
|
||||
items: { ref: string; name?: string; status: string; error?: string }[];
|
||||
summary?: { total: number; done: number; ok: number; failed: number; cancelled: number; running: number } }[];
|
||||
subagents: { id: string; name?: string; status: "active" | "completed" | "failed" | "interrupted" | "dormant";
|
||||
model?: string; thinking?: string; task?: string; children?: unknown[] }[];
|
||||
model?: string; thinking?: string; task?: string; children?: unknown[];
|
||||
parentId?: string; visible?: boolean }[];
|
||||
attention: { requestId: string; method: string; title?: string; message?: string;
|
||||
options?: { id: string; label: string }[]; payload?: unknown; timeoutSec?: number;
|
||||
createdAt: number; receivedAt: number }[];
|
||||
entries: Entry[];
|
||||
|
||||
// List metadata — enriched by the session list (`§3.1`) / snapshot from the
|
||||
// web client's cached row, never emitted by the reducer.
|
||||
parentId?: string | null; // null = root (client-side only; the plugin omits the field)
|
||||
visible?: boolean; // plugin `:PiSessions` visibility decision
|
||||
task?: string; // subagent task description from the spawn request
|
||||
}
|
||||
|
||||
type Block =
|
||||
|
||||
Reference in new issue
Block a user