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
@@ -244,12 +244,19 @@ export function useChatSocket(workspaceId: string | undefined, sessionIds: strin
|
||||
setWsState(state);
|
||||
},
|
||||
onSnapshot: (message) => {
|
||||
const state = normalizeSnapshotState(message.sessionId, workspaceId, message.payload);
|
||||
const store = useSessionsStore.getState();
|
||||
const state = normalizeSnapshotState(
|
||||
message.sessionId,
|
||||
workspaceId,
|
||||
message.payload,
|
||||
// The snapshot never carries list metadata (`parentId` /
|
||||
// `visible` / `task`); the cached row owns it, so pass it in.
|
||||
store.getSession(message.sessionId),
|
||||
);
|
||||
if (!state.entries.length) {
|
||||
const raw = snapshotEntries(message.payload);
|
||||
if (raw.length) state.entries = projectEntries(raw);
|
||||
}
|
||||
const store = useSessionsStore.getState();
|
||||
store.upsertSession(state);
|
||||
},
|
||||
onEvent: (message) => {
|
||||
@@ -316,7 +323,8 @@ export interface SessionLookup {
|
||||
* A non-empty `sessionId` that the loaded list does not contain resolves to
|
||||
* `undefined` — falling back to `sessions[0]` would silently show a different
|
||||
* session for an unknown deep link. The first-session fallback stays for the
|
||||
* `/chat` index (no id), which means "the workspace's most recent session".
|
||||
* `/chat` index (no id), which means "the workspace's most recent root session"
|
||||
* (a sub-session row is never the index default).
|
||||
*
|
||||
* @param sessionId Route session id (`undefined` on `/chat`).
|
||||
* @param sessions Sessions of the active workspace.
|
||||
@@ -328,7 +336,7 @@ export function useSessionLookup(
|
||||
loaded: boolean,
|
||||
): SessionLookup {
|
||||
return useMemo(() => {
|
||||
if (!sessionId) return { session: sessions[0], missing: false };
|
||||
if (!sessionId) return { session: sessions.find((session) => !session.parentId) ?? sessions[0], missing: false };
|
||||
const match = sessions.find((session) => session.sessionId === sessionId);
|
||||
if (match) return { session: match, missing: false };
|
||||
return { session: undefined, missing: loaded };
|
||||
|
||||
@@ -32,6 +32,9 @@ export interface EmptySessionInput {
|
||||
status?: SessionState["status"];
|
||||
model?: ModelRef | null;
|
||||
thinking?: ThinkingLevel | null;
|
||||
parentId?: string | null;
|
||||
visible?: boolean;
|
||||
task?: string;
|
||||
}
|
||||
|
||||
export function emptySessionState(input: EmptySessionInput): SessionState {
|
||||
@@ -53,6 +56,12 @@ export function emptySessionState(input: EmptySessionInput): SessionState {
|
||||
subagents: [],
|
||||
attention: [],
|
||||
entries: [],
|
||||
// `parentId`/`visible` are list metadata with an `undefined` = "not
|
||||
// carried" meaning: a fresh/empty state must not clobber the cached
|
||||
// row's tree position when it is upserted over it.
|
||||
...(input.parentId !== undefined ? { parentId: input.parentId } : {}),
|
||||
...(input.visible !== undefined ? { visible: input.visible } : {}),
|
||||
...(input.task !== undefined ? { task: input.task } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -226,8 +235,19 @@ export function applySessionEvent(state: SessionState, event: SessionEvent): Ses
|
||||
return next;
|
||||
}
|
||||
|
||||
/** `parentId` as carried by a list row: string → value, explicit null → `null`. */
|
||||
function summaryParentId(record: Record<string, unknown>, base: SessionState): string | null {
|
||||
if (!("parentId" in record) && !("parent_id" in record)) return base.parentId ?? null;
|
||||
return str(record.parentId) ?? str(record.parent_id) ?? null;
|
||||
}
|
||||
|
||||
/** Enrich a snapshot with its separately-carried entry tail. */
|
||||
export function normalizeSnapshotState(sessionId: string, workspaceId: string, payload: unknown): SessionState {
|
||||
export function normalizeSnapshotState(
|
||||
sessionId: string,
|
||||
workspaceId: string,
|
||||
payload: unknown,
|
||||
existing?: SessionState,
|
||||
): SessionState {
|
||||
const record = rec(payload);
|
||||
const candidate = rec(record?.state) ?? record ?? {};
|
||||
const base = emptySessionState({
|
||||
@@ -235,11 +255,19 @@ export function normalizeSnapshotState(sessionId: string, workspaceId: string, p
|
||||
workspaceId: str(candidate.workspaceId) ?? workspaceId,
|
||||
cwd: str(candidate.cwd) ?? "",
|
||||
});
|
||||
// The list row owns the tree metadata; a snapshot without it (the normal
|
||||
// case — the reducer never emits these) must not turn a child into a root.
|
||||
const parentId = str(candidate.parentId ?? candidate.parent_id) ?? existing?.parentId ?? null;
|
||||
const visible = typeof candidate.visible === "boolean" ? candidate.visible : (existing?.visible ?? true);
|
||||
const task = str(candidate.task) ?? existing?.task;
|
||||
const state: SessionState = {
|
||||
...base,
|
||||
...candidate,
|
||||
sessionId,
|
||||
workspaceId: str(candidate.workspaceId) ?? workspaceId,
|
||||
parentId,
|
||||
visible,
|
||||
...(task !== undefined ? { task } : {}),
|
||||
flags: {
|
||||
attention: candidate.flags ? rec(candidate.flags)?.attention === true : false,
|
||||
done: rec(candidate.flags)?.done === true,
|
||||
@@ -292,6 +320,7 @@ export function normalizeSessionSummary(raw: unknown, workspaceId: string, exist
|
||||
|
||||
const thinkingValue = str(record.thinking);
|
||||
const hasQueue = Array.isArray(record.queue);
|
||||
const task = str(record.task) ?? base.task;
|
||||
return {
|
||||
...base,
|
||||
sessionId,
|
||||
@@ -314,6 +343,9 @@ export function normalizeSessionSummary(raw: unknown, workspaceId: string, exist
|
||||
subagents: Array.isArray(record.subagents) ? arr(record.subagents) : base.subagents,
|
||||
attention: Array.isArray(record.attention) ? arr(record.attention) : base.attention,
|
||||
entries: Array.isArray(record.entries) ? arr<Entry>(record.entries) : base.entries,
|
||||
parentId: summaryParentId(record, base),
|
||||
visible: typeof record.visible === "boolean" ? record.visible : base.visible,
|
||||
...(task !== undefined ? { task } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
import type { SessionState, Subagent } from "@protocol/types";
|
||||
|
||||
/**
|
||||
* The session tree the sidebar renders: workspace sessions nest under their
|
||||
* `parentId` (sub-sessions are separate rows of the same REST list), and a
|
||||
* manifest subagent only renders as a synthetic row when it has no row of its
|
||||
* own (the child session row always wins).
|
||||
*
|
||||
* Pure and React-free, so the shape is unit-testable without a DOM.
|
||||
*/
|
||||
|
||||
export interface SessionTreeNode {
|
||||
kind: "session";
|
||||
session: SessionState;
|
||||
depth: number;
|
||||
children: TreeNode[];
|
||||
/** Number of children actually rendered, so a `(N)` badge matches the UI. */
|
||||
childCount: number;
|
||||
/** True when the row is hidden by the plugin's visibility policy. */
|
||||
hidden: boolean;
|
||||
/** Keep this row open even when the user folded it (selected/filtered descendant). */
|
||||
forcedOpen: boolean;
|
||||
}
|
||||
|
||||
export interface SubagentTreeNode {
|
||||
kind: "subagent";
|
||||
/** The session that owns the manifest entry. */
|
||||
session: SessionState;
|
||||
subagent: Subagent;
|
||||
depth: number;
|
||||
children: TreeNode[];
|
||||
/** Number of children actually rendered, so a `(N)` badge matches the UI. */
|
||||
childCount: number;
|
||||
/** True when the row is hidden by the plugin's visibility policy. */
|
||||
hidden: boolean;
|
||||
/** Keep this row open even when the user folded it (search match below). */
|
||||
forcedOpen: boolean;
|
||||
}
|
||||
|
||||
export type TreeNode = SessionTreeNode | SubagentTreeNode;
|
||||
|
||||
export interface SessionTreeOptions {
|
||||
/** Case-insensitive name needle; empty (or absent) means "no filter". */
|
||||
filter?: string;
|
||||
/** Render rows the plugin marked `visible: false`. */
|
||||
showHidden?: boolean;
|
||||
/** The routed session; always rendered, even when it is hidden/filtered out. */
|
||||
selectedId?: string | null;
|
||||
}
|
||||
|
||||
/** Stable key for a node (manifest ids are not unique across sessions). */
|
||||
export function treeNodeKey(node: TreeNode): string {
|
||||
return node.kind === "session" ? `s:${node.session.sessionId}` : `a:${node.session.sessionId}:${node.subagent.id}`;
|
||||
}
|
||||
|
||||
/** Id a node addresses (`data-session-id` / `data-subagent-id`). */
|
||||
export function treeNodeId(node: TreeNode): string {
|
||||
return node.kind === "session" ? node.session.sessionId : node.subagent.id;
|
||||
}
|
||||
|
||||
/** Does this subtree contain `id` (used to expand the path to the routed row)? */
|
||||
function containsNode(node: TreeNode, id: string): boolean {
|
||||
if (treeNodeId(node) === id) return true;
|
||||
return node.children.some((child) => containsNode(child, id));
|
||||
}
|
||||
|
||||
function sessionLabel(session: SessionState): string {
|
||||
return session.name?.trim() || session.sessionId;
|
||||
}
|
||||
|
||||
function subagentLabel(subagent: Subagent): string {
|
||||
return subagent.name?.trim() || subagent.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent a row is grouped under, or `null` when it is a root.
|
||||
*
|
||||
* A `parentId` that is not in the list is promoted to a root (a filtered-out
|
||||
* parent must never lose its children), and a cycle is cut by rendering every
|
||||
* member of the cycle as a root.
|
||||
*/
|
||||
function effectiveParent(session: SessionState, index: Map<string, SessionState>): string | null {
|
||||
const parentId = session.parentId ?? null;
|
||||
if (!parentId || parentId === session.sessionId || !index.has(parentId)) return null;
|
||||
const seen = new Set<string>([session.sessionId]);
|
||||
let cursor: string | null = parentId;
|
||||
while (cursor) {
|
||||
if (seen.has(cursor)) return null;
|
||||
seen.add(cursor);
|
||||
const next: string | null = index.get(cursor)?.parentId ?? null;
|
||||
if (!next || next === cursor) break;
|
||||
cursor = next;
|
||||
}
|
||||
return parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the render tree for one workspace.
|
||||
*
|
||||
* Input order is preserved (never sorted): root sessions and siblings keep the
|
||||
* order the list delivered; a session's synthetic subagent rows follow its real
|
||||
* child sessions, in manifest order.
|
||||
*/
|
||||
export function buildSessionTree(sessions: SessionState[], options: SessionTreeOptions = {}): TreeNode[] {
|
||||
const showHidden = options.showHidden === true;
|
||||
const selectedId = options.selectedId ?? null;
|
||||
const needle = (options.filter ?? "").trim().toLowerCase();
|
||||
|
||||
const index = new Map<string, SessionState>();
|
||||
for (const session of sessions) {
|
||||
// Duplicate ids (a list/payload race) must not render twice or key twice.
|
||||
if (!index.has(session.sessionId)) index.set(session.sessionId, session);
|
||||
}
|
||||
|
||||
// Children grouped by their effective parent, in list order.
|
||||
const childSessions = new Map<string | null, SessionState[]>();
|
||||
for (const session of sessions) {
|
||||
if (index.get(session.sessionId) !== session) continue;
|
||||
const parentId = effectiveParent(session, index);
|
||||
const siblings = childSessions.get(parentId);
|
||||
if (siblings) siblings.push(session);
|
||||
else childSessions.set(parentId, [session]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selection, search and ancestry; visibility is only one of the inputs.
|
||||
*
|
||||
* Selection overrides the visibility policy (a deep-linked hidden row always
|
||||
* renders) but NOT an explicit search: the filter is the user's intent and a
|
||||
* non-matching row stays out.
|
||||
*/
|
||||
function keepRow(id: string, label: string, selfVisible: boolean, children: TreeNode[]): boolean {
|
||||
if (needle !== "") {
|
||||
// Search is an explicit intent: a matching hidden row IS shown.
|
||||
if (label.toLowerCase().includes(needle)) return true;
|
||||
return children.length > 0;
|
||||
}
|
||||
if (selectedId !== null && id === selectedId) return true;
|
||||
if (showHidden || selfVisible) return true;
|
||||
// Hidden, but kept because a rendered descendant needs its ancestor.
|
||||
return children.length > 0;
|
||||
}
|
||||
|
||||
function buildSessionNode(session: SessionState, depth: number, path: Set<string>): SessionTreeNode | null {
|
||||
if (path.has(session.sessionId)) return null;
|
||||
const nextPath = new Set(path).add(session.sessionId);
|
||||
const children: TreeNode[] = [];
|
||||
for (const child of childSessions.get(session.sessionId) ?? []) {
|
||||
const node = buildSessionNode(child, depth + 1, nextPath);
|
||||
if (node) children.push(node);
|
||||
}
|
||||
for (const subagent of session.subagents ?? []) {
|
||||
const node = buildSubagentNode(session, subagent, depth + 1, nextPath);
|
||||
if (node) children.push(node);
|
||||
}
|
||||
const selfVisible = session.visible !== false;
|
||||
if (!keepRow(session.sessionId, sessionLabel(session), selfVisible, children)) return null;
|
||||
return {
|
||||
kind: "session",
|
||||
session,
|
||||
depth,
|
||||
children,
|
||||
childCount: children.length,
|
||||
hidden: !selfVisible,
|
||||
// A folded parent must still reveal the routed row or a search hit
|
||||
// inside it; otherwise the selection would silently disappear.
|
||||
forcedOpen:
|
||||
children.length > 0 &&
|
||||
(needle !== "" || (selectedId !== null && children.some((child) => containsNode(child, selectedId)))),
|
||||
};
|
||||
}
|
||||
|
||||
function buildSubagentNode(
|
||||
session: SessionState,
|
||||
subagent: Subagent,
|
||||
depth: number,
|
||||
path: Set<string>,
|
||||
): SubagentTreeNode | null {
|
||||
// Dedupe: a manifest entry with a session row of its own is that row.
|
||||
if (index.has(subagent.id) || path.has(subagent.id)) return null;
|
||||
const nextPath = new Set(path).add(subagent.id);
|
||||
const children: TreeNode[] = [];
|
||||
for (const child of subagent.children ?? []) {
|
||||
const node = buildSubagentNode(session, child, depth + 1, nextPath);
|
||||
if (node) children.push(node);
|
||||
}
|
||||
const selfVisible = subagent.visible !== false;
|
||||
if (!keepRow(subagent.id, subagentLabel(subagent), selfVisible, children)) return null;
|
||||
return {
|
||||
kind: "subagent",
|
||||
session,
|
||||
subagent,
|
||||
depth,
|
||||
children,
|
||||
childCount: children.length,
|
||||
hidden: !selfVisible,
|
||||
forcedOpen: children.length > 0 && needle !== "",
|
||||
};
|
||||
}
|
||||
|
||||
const roots: TreeNode[] = [];
|
||||
const emptyPath = new Set<string>();
|
||||
for (const session of childSessions.get(null) ?? []) {
|
||||
const node = buildSessionNode(session, 0, emptyPath);
|
||||
if (node) roots.push(node);
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { SessionState, Subagent, WorkspaceInfo } from "@protocol/types";
|
||||
import { useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Icon } from "@/components/icons";
|
||||
@@ -8,6 +9,14 @@ import { Input } from "@/components/ui/input";
|
||||
import { StatusDot, subagentDotClass } from "@/components/ui/status-dot";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { flattenSubagents, sessionDot, sessionStatusKey } from "./session-state";
|
||||
import {
|
||||
buildSessionTree,
|
||||
treeNodeId,
|
||||
treeNodeKey,
|
||||
type SessionTreeNode,
|
||||
type SubagentTreeNode,
|
||||
type TreeNode,
|
||||
} from "./session-tree-model";
|
||||
|
||||
export interface SessionTreeProps {
|
||||
sessions: SessionState[];
|
||||
@@ -16,11 +25,14 @@ export interface SessionTreeProps {
|
||||
selectedId?: string | null;
|
||||
filter: string;
|
||||
collapsed: Record<string, boolean>;
|
||||
/** Render sub-sessions the plugin marked `visible: false`. */
|
||||
showHidden: boolean;
|
||||
connected?: boolean;
|
||||
creating?: boolean;
|
||||
onFilter: (value: string) => void;
|
||||
onToggleCollapse: (id: string) => void;
|
||||
onToggleAll: () => void;
|
||||
onToggleShowHidden: () => void;
|
||||
onSelectSession: (id: string) => void;
|
||||
onSelectWorkspace?: (id: string) => void;
|
||||
onNewSession: () => void;
|
||||
@@ -36,15 +48,6 @@ function sessionName(session: SessionState, fallback: string): string {
|
||||
return session.name?.trim() || fallback;
|
||||
}
|
||||
|
||||
function matchesFilter(session: SessionState, filter: string, fallback: string): boolean {
|
||||
if (!filter) return true;
|
||||
const needle = filter.toLowerCase();
|
||||
if (sessionName(session, fallback).toLowerCase().includes(needle)) return true;
|
||||
return flattenSubagents(session.subagents).some(({ subagent }) =>
|
||||
(subagent.name ?? "").toLowerCase().includes(needle),
|
||||
);
|
||||
}
|
||||
|
||||
function ChevronToggle({
|
||||
hasChildren,
|
||||
collapsed,
|
||||
@@ -72,93 +75,50 @@ function ChevronToggle({
|
||||
);
|
||||
}
|
||||
|
||||
function SubagentRow({
|
||||
session,
|
||||
subagent,
|
||||
collapsed,
|
||||
onToggleCollapse,
|
||||
onOpenSubagent,
|
||||
onRenameSubagent,
|
||||
}: {
|
||||
session: SessionState;
|
||||
subagent: Subagent;
|
||||
collapsed: Record<string, boolean>;
|
||||
interface TreeHandlers {
|
||||
onToggleCollapse: (id: string) => void;
|
||||
onSelectSession: (id: string) => void;
|
||||
onRenameSession: (session: SessionState) => void;
|
||||
onCloseSession: (session: SessionState) => void;
|
||||
onOpenSubagent?: (session: SessionState, subagent: Subagent) => void;
|
||||
onRenameSubagent?: (subagent: Subagent) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const children = subagent.children ?? [];
|
||||
const isCollapsed = collapsed[subagent.id] === true;
|
||||
const status = t(`state.${subagent.status}`);
|
||||
const name = subagent.name ?? subagent.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* One row of the session tree plus its children.
|
||||
*
|
||||
* A real child session renders as a `tree-row--sub` (indent only, no vertical
|
||||
* guides) and navigates to its own transcript; a manifest subagent keeps the
|
||||
* eye/rename affordances of the subagent preview.
|
||||
*/
|
||||
function TreeRow({
|
||||
node,
|
||||
selectedId,
|
||||
collapsed,
|
||||
...handlers
|
||||
}: TreeHandlers & { node: TreeNode; selectedId?: string | null; collapsed: Record<string, boolean> }) {
|
||||
const isCollapsed = collapsed[treeNodeId(node)] === true && !node.forcedOpen;
|
||||
return (
|
||||
<li>
|
||||
<div
|
||||
className="tree-row tree-row--sub"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={name}
|
||||
data-subagent-id={subagent.id}
|
||||
onClick={() => onOpenSubagent?.(session, subagent)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
onOpenSubagent?.(session, subagent);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ChevronToggle
|
||||
hasChildren={children.length > 0}
|
||||
{node.kind === "session" ? (
|
||||
<SessionNodeRow
|
||||
node={node}
|
||||
collapsed={isCollapsed}
|
||||
onClick={() => onToggleCollapse(subagent.id)}
|
||||
selected={node.session.sessionId === selectedId}
|
||||
{...handlers}
|
||||
/>
|
||||
<span className={cn("dot", subagentDotClass(subagent.status))} title={status} />
|
||||
<span className="t-main">
|
||||
<span className="t-name truncate">{name}</span>
|
||||
<span className="t-sub truncate muted">
|
||||
{subagent.model ?? "—"}
|
||||
{subagent.thinking ? ` · ${subagent.thinking}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
<span className="t-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn"
|
||||
title={t("chat.preview")}
|
||||
aria-label={t("chat.previewSubagent")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onOpenSubagent?.(session, subagent);
|
||||
}}
|
||||
>
|
||||
<Icon name="eye" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn"
|
||||
title={t("chat.rename")}
|
||||
aria-label={t("chat.renameSubagentAria")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onRenameSubagent?.(subagent);
|
||||
}}
|
||||
>
|
||||
<Icon name="edit" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
{children.length && !isCollapsed ? (
|
||||
) : (
|
||||
<SubagentNodeRow node={node} collapsed={isCollapsed} {...handlers} />
|
||||
)}
|
||||
{node.children.length && !isCollapsed ? (
|
||||
<ul>
|
||||
{children.map((child) => (
|
||||
<SubagentRow
|
||||
key={child.id}
|
||||
session={session}
|
||||
subagent={child}
|
||||
{node.children.map((child) => (
|
||||
<TreeRow
|
||||
key={treeNodeKey(child)}
|
||||
node={child}
|
||||
collapsed={collapsed}
|
||||
onToggleCollapse={onToggleCollapse}
|
||||
onOpenSubagent={onOpenSubagent}
|
||||
onRenameSubagent={onRenameSubagent}
|
||||
selectedId={selectedId}
|
||||
{...handlers}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
@@ -167,116 +127,168 @@ function SubagentRow({
|
||||
);
|
||||
}
|
||||
|
||||
function SessionRow({
|
||||
session,
|
||||
selected,
|
||||
function SessionNodeRow({
|
||||
node,
|
||||
collapsed,
|
||||
selected,
|
||||
onToggleCollapse,
|
||||
onSelectSession,
|
||||
onRenameSession,
|
||||
onCloseSession,
|
||||
onOpenSubagent,
|
||||
onRenameSubagent,
|
||||
}: {
|
||||
session: SessionState;
|
||||
node: SessionTreeNode;
|
||||
collapsed: boolean;
|
||||
selected: boolean;
|
||||
collapsed: Record<string, boolean>;
|
||||
onToggleCollapse: (id: string) => void;
|
||||
onSelectSession: (id: string) => void;
|
||||
onRenameSession: (session: SessionState) => void;
|
||||
onCloseSession: (session: SessionState) => void;
|
||||
onOpenSubagent?: (session: SessionState, subagent: Subagent) => void;
|
||||
onRenameSubagent?: (subagent: Subagent) => void;
|
||||
}) {
|
||||
} & Pick<TreeHandlers, "onToggleCollapse" | "onSelectSession" | "onRenameSession" | "onCloseSession">) {
|
||||
const { t } = useTranslation();
|
||||
const subagents = session.subagents ?? [];
|
||||
const isCollapsed = collapsed[session.sessionId] === true;
|
||||
const dot = sessionDot(session);
|
||||
const session = node.session;
|
||||
const status = t(`state.${sessionStatusKey(session)}`);
|
||||
const name = sessionName(session, session.sessionId);
|
||||
return (
|
||||
<li>
|
||||
<div
|
||||
className={cn("tree-row", selected && "selected")}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={name}
|
||||
aria-current={selected ? "true" : undefined}
|
||||
data-session-id={session.sessionId}
|
||||
onClick={() => onSelectSession(session.sessionId)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
onSelectSession(session.sessionId);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ChevronToggle
|
||||
hasChildren={subagents.length > 0}
|
||||
collapsed={isCollapsed}
|
||||
onClick={() => onToggleCollapse(session.sessionId)}
|
||||
/>
|
||||
<StatusDot status={dot} title={status} />
|
||||
<span className="t-main">
|
||||
<span className="t-name truncate">
|
||||
{name}
|
||||
{session.flags.attention && session.attention.length ? (
|
||||
<Badge tone="warn">{`!${session.attention.length}`}</Badge>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="t-sub truncate muted">
|
||||
{session.model?.id ?? "—"}
|
||||
{session.thinking ? ` · ${session.thinking}` : ""}
|
||||
</span>
|
||||
<div
|
||||
className={cn("tree-row", node.depth > 0 && "tree-row--sub", selected && "selected")}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={name}
|
||||
aria-current={selected ? "true" : undefined}
|
||||
data-session-id={session.sessionId}
|
||||
data-hidden={node.hidden ? "true" : undefined}
|
||||
onClick={() => onSelectSession(session.sessionId)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
onSelectSession(session.sessionId);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ChevronToggle
|
||||
hasChildren={node.children.length > 0}
|
||||
collapsed={collapsed}
|
||||
onClick={() => onToggleCollapse(session.sessionId)}
|
||||
/>
|
||||
<StatusDot status={sessionDot(session)} title={status} />
|
||||
<span className="t-main">
|
||||
<span className="t-name truncate">
|
||||
{name}
|
||||
{session.flags.attention && session.attention.length ? (
|
||||
<Badge tone="warn">{`!${session.attention.length}`}</Badge>
|
||||
) : null}
|
||||
</span>
|
||||
{subagents.length ? (
|
||||
<span className="t-meta" title={t("chat.subagentCount", { n: subagents.length })}>
|
||||
{`(${subagents.length})`}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="t-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn"
|
||||
title={t("chat.rename")}
|
||||
aria-label={t("chat.renameSession")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onRenameSession(session);
|
||||
}}
|
||||
>
|
||||
<Icon name="edit" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn icon-btn--danger"
|
||||
title={t("chat.closeProcess")}
|
||||
aria-label={t("chat.closeProcess")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onCloseSession(session);
|
||||
}}
|
||||
>
|
||||
<Icon name="x" />
|
||||
</button>
|
||||
<span className="t-sub truncate muted">
|
||||
{session.model?.id ?? "—"}
|
||||
{session.thinking ? ` · ${session.thinking}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
{node.childCount ? (
|
||||
<span className="t-meta" title={t("chat.childCount", { n: node.childCount })}>
|
||||
{`(${node.childCount})`}
|
||||
</span>
|
||||
</div>
|
||||
{subagents.length && !isCollapsed ? (
|
||||
<ul>
|
||||
{subagents.map((subagent) => (
|
||||
<SubagentRow
|
||||
key={subagent.id}
|
||||
session={session}
|
||||
subagent={subagent}
|
||||
collapsed={collapsed}
|
||||
onToggleCollapse={onToggleCollapse}
|
||||
onOpenSubagent={onOpenSubagent}
|
||||
onRenameSubagent={onRenameSubagent}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
</li>
|
||||
<span className="t-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn"
|
||||
title={t("chat.rename")}
|
||||
aria-label={t("chat.renameSession")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onRenameSession(session);
|
||||
}}
|
||||
>
|
||||
<Icon name="edit" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn icon-btn--danger"
|
||||
title={t("chat.closeProcess")}
|
||||
aria-label={t("chat.closeProcess")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onCloseSession(session);
|
||||
}}
|
||||
>
|
||||
<Icon name="x" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SubagentNodeRow({
|
||||
node,
|
||||
collapsed,
|
||||
onToggleCollapse,
|
||||
onOpenSubagent,
|
||||
onRenameSubagent,
|
||||
}: {
|
||||
node: SubagentTreeNode;
|
||||
collapsed: boolean;
|
||||
} & Pick<TreeHandlers, "onToggleCollapse" | "onOpenSubagent" | "onRenameSubagent">) {
|
||||
const { t } = useTranslation();
|
||||
const { session, subagent } = node;
|
||||
const status = t(`state.${subagent.status}`);
|
||||
const name = subagent.name ?? subagent.id;
|
||||
return (
|
||||
<div
|
||||
className="tree-row tree-row--sub"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={name}
|
||||
data-subagent-id={subagent.id}
|
||||
data-hidden={node.hidden ? "true" : undefined}
|
||||
onClick={() => onOpenSubagent?.(session, subagent)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
onOpenSubagent?.(session, subagent);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ChevronToggle
|
||||
hasChildren={node.children.length > 0}
|
||||
collapsed={collapsed}
|
||||
onClick={() => onToggleCollapse(subagent.id)}
|
||||
/>
|
||||
<span className={cn("dot", subagentDotClass(subagent.status))} title={status} />
|
||||
<span className="t-main">
|
||||
<span className="t-name truncate">{name}</span>
|
||||
<span className="t-sub truncate muted">
|
||||
{subagent.model ?? "—"}
|
||||
{subagent.thinking ? ` · ${subagent.thinking}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
{node.childCount ? (
|
||||
<span className="t-meta" title={t("chat.childCount", { n: node.childCount })}>
|
||||
{`(${node.childCount})`}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="t-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn"
|
||||
title={t("chat.preview")}
|
||||
aria-label={t("chat.previewSubagent")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onOpenSubagent?.(session, subagent);
|
||||
}}
|
||||
>
|
||||
<Icon name="eye" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn"
|
||||
title={t("chat.rename")}
|
||||
aria-label={t("chat.renameSubagentAria")}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onRenameSubagent?.(subagent);
|
||||
}}
|
||||
>
|
||||
<Icon name="edit" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -288,11 +300,13 @@ export function SessionTree({
|
||||
selectedId,
|
||||
filter,
|
||||
collapsed,
|
||||
showHidden,
|
||||
connected = false,
|
||||
creating = false,
|
||||
onFilter,
|
||||
onToggleCollapse,
|
||||
onToggleAll,
|
||||
onToggleShowHidden,
|
||||
onSelectSession,
|
||||
onSelectWorkspace,
|
||||
onNewSession,
|
||||
@@ -304,7 +318,12 @@ export function SessionTree({
|
||||
className,
|
||||
}: SessionTreeProps) {
|
||||
const { t } = useTranslation();
|
||||
const visible = sessions.filter((session) => matchesFilter(session, filter, session.sessionId));
|
||||
const nodes = useMemo(
|
||||
() => buildSessionTree(sessions, { filter, showHidden, selectedId }),
|
||||
[sessions, filter, showHidden, selectedId],
|
||||
);
|
||||
// Every id — including rows the visibility policy or the filter dropped — so
|
||||
// "collapse all" also folds folded-away parents.
|
||||
const allIds = sessions.flatMap((session) => [
|
||||
session.sessionId,
|
||||
...flattenSubagents(session.subagents).map(({ subagent }) => subagent.id),
|
||||
@@ -375,6 +394,16 @@ export function SessionTree({
|
||||
<StatusDot status={connected ? "ok" : "exited"} />
|
||||
<span className="muted">{t(connected ? "state.online" : "state.offline")}</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className={cn("icon-btn", showHidden && "is-on")}
|
||||
title={t("chat.showHidden")}
|
||||
aria-label={t("chat.showHiddenAria")}
|
||||
aria-pressed={showHidden}
|
||||
onClick={onToggleShowHidden}
|
||||
>
|
||||
<Icon name="eye" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="icon-btn"
|
||||
@@ -387,13 +416,13 @@ export function SessionTree({
|
||||
</div>
|
||||
</div>
|
||||
<div className="pane-scroll">
|
||||
{visible.length ? (
|
||||
{nodes.length ? (
|
||||
<ul className="tree">
|
||||
{visible.map((session) => (
|
||||
<SessionRow
|
||||
key={session.sessionId}
|
||||
session={session}
|
||||
selected={session.sessionId === selectedId}
|
||||
{nodes.map((node) => (
|
||||
<TreeRow
|
||||
key={treeNodeKey(node)}
|
||||
node={node}
|
||||
selectedId={selectedId}
|
||||
collapsed={collapsed}
|
||||
onToggleCollapse={onToggleCollapse}
|
||||
onSelectSession={onSelectSession}
|
||||
@@ -404,12 +433,24 @@ export function SessionTree({
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
) : sessions.length ? (
|
||||
) : filter.trim() ? (
|
||||
<Empty
|
||||
icon={<Icon name="search" />}
|
||||
title={t("chat.noMatch")}
|
||||
description={t("chat.tryOther")}
|
||||
/>
|
||||
) : sessions.length ? (
|
||||
<Empty
|
||||
icon={<Icon name="eye" />}
|
||||
title={t("chat.allHidden")}
|
||||
description={t("chat.allHiddenText")}
|
||||
action={
|
||||
<button type="button" className="btn btn--sm" onClick={onToggleShowHidden}>
|
||||
<Icon name="eye" />
|
||||
{t("chat.showHidden")}
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<Empty
|
||||
icon={<Icon name="chat" />}
|
||||
|
||||
@@ -47,6 +47,8 @@ export interface ChatStore {
|
||||
tab: PanelTab;
|
||||
filter: string;
|
||||
collapsed: Record<string, boolean>;
|
||||
/** Render sub-sessions the plugin hid (`:PiSessions` policy). */
|
||||
showHidden: boolean;
|
||||
treeOpen: boolean;
|
||||
panelOpen: boolean;
|
||||
treeCollapsed: boolean;
|
||||
@@ -62,6 +64,7 @@ export interface ChatStore {
|
||||
setFilter: (filter: string) => void;
|
||||
toggleCollapsed: (id: string) => void;
|
||||
setAllCollapsed: (ids: string[], collapsed: boolean) => void;
|
||||
toggleShowHidden: () => void;
|
||||
setTreeOpen: (open: boolean) => void;
|
||||
setPanelOpen: (open: boolean) => void;
|
||||
setTreeCollapsed: (collapsed: boolean) => void;
|
||||
@@ -105,6 +108,7 @@ export const useChatStore = create<ChatStore>((set) => ({
|
||||
tab: "subagents",
|
||||
filter: "",
|
||||
collapsed: {},
|
||||
showHidden: false,
|
||||
treeOpen: false,
|
||||
panelOpen: false,
|
||||
treeCollapsed: false,
|
||||
@@ -127,6 +131,7 @@ export const useChatStore = create<ChatStore>((set) => ({
|
||||
}),
|
||||
setAllCollapsed: (ids, collapsed) =>
|
||||
set(() => ({ collapsed: collapsed ? Object.fromEntries(ids.map((id) => [id, true])) : {} })),
|
||||
toggleShowHidden: () => set((state) => ({ showHidden: !state.showHidden })),
|
||||
setTreeOpen: (treeOpen) => set({ treeOpen }),
|
||||
setPanelOpen: (panelOpen) => set({ panelOpen }),
|
||||
setTreeCollapsed: (treeCollapsed) => set({ treeCollapsed }),
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
"chat.acceptedAll": "Accepted all {n} files",
|
||||
"chat.addAttachment": "Add attachment",
|
||||
"chat.allowOnce": "Allow once",
|
||||
"chat.allHidden": "All sub-sessions are hidden",
|
||||
"chat.allHiddenText": "Turn on “Show hidden sub-sessions” to list them.",
|
||||
"chat.attachTitle": "Add attachment",
|
||||
"chat.attachmentAdded": "Added attachment {name}",
|
||||
"chat.attachmentFailed": "Could not read attachment: {name}",
|
||||
@@ -20,6 +22,7 @@
|
||||
"chat.batchFailed": "{n} failed",
|
||||
"chat.batchRunning": "{n} running",
|
||||
"chat.cancelSiblingsLabel": "Cancel sibling subagents on failure (cancel_siblings_on_fail)",
|
||||
"chat.childCount": "{n} children",
|
||||
"chat.closePanel": "Close panel",
|
||||
"chat.closeProcess": "Close process",
|
||||
"chat.closeSessionText": "This ends the pi process for session \"{name}\". History is kept and it can be revived.",
|
||||
@@ -103,6 +106,8 @@
|
||||
"chat.sendTitle": "Send (Enter)",
|
||||
"chat.sending": "Sending…",
|
||||
"chat.sessions": "Sessions",
|
||||
"chat.showHidden": "Show hidden sub-sessions",
|
||||
"chat.showHiddenAria": "Show hidden sub-sessions",
|
||||
"chat.source": "Source: {name}",
|
||||
"chat.status": "Status",
|
||||
"chat.steer": "Steer",
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
"chat.acceptedAll": "已接受全部 {n} 个文件",
|
||||
"chat.addAttachment": "添加附件",
|
||||
"chat.allowOnce": "允许一次",
|
||||
"chat.allHidden": "所有子会话均已隐藏",
|
||||
"chat.allHiddenText": "开启「显示隐藏的子会话」即可显示。",
|
||||
"chat.attachTitle": "添加附件",
|
||||
"chat.attachmentAdded": "已添加附件 {name}",
|
||||
"chat.attachmentFailed": "附件读取失败:{name}",
|
||||
@@ -20,6 +22,7 @@
|
||||
"chat.batchFailed": "{n} 失败",
|
||||
"chat.batchRunning": "{n} 运行中",
|
||||
"chat.cancelSiblingsLabel": "失败时取消同级子代理(cancel_siblings_on_fail)",
|
||||
"chat.childCount": "{n} 个子项",
|
||||
"chat.closePanel": "关闭面板",
|
||||
"chat.closeProcess": "关闭进程",
|
||||
"chat.closeSessionText": "将结束 session「{name}」的 pi 进程。会话历史仍保留,可重新唤醒。",
|
||||
@@ -103,6 +106,8 @@
|
||||
"chat.sendTitle": "发送(Enter)",
|
||||
"chat.sending": "发送中…",
|
||||
"chat.sessions": "会话",
|
||||
"chat.showHidden": "显示隐藏的子会话",
|
||||
"chat.showHiddenAria": "显示隐藏的子会话",
|
||||
"chat.source": "来源:{name}",
|
||||
"chat.status": "状态",
|
||||
"chat.steer": "Steer",
|
||||
|
||||
@@ -111,6 +111,8 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
const setFilter = useChatStore((state) => state.setFilter);
|
||||
const collapsed = useChatStore((state) => state.collapsed);
|
||||
const toggleCollapsed = useChatStore((state) => state.toggleCollapsed);
|
||||
const showHidden = useChatStore((state) => state.showHidden);
|
||||
const toggleShowHidden = useChatStore((state) => state.toggleShowHidden);
|
||||
const setAllCollapsed = useChatStore((state) => state.setAllCollapsed);
|
||||
const tab = useChatStore((state) => state.tab);
|
||||
const setTab = useChatStore((state) => state.setTab);
|
||||
@@ -322,6 +324,12 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
[sessions],
|
||||
);
|
||||
const anyOpen = allIds.some((id) => !collapsed[id]);
|
||||
// Only offer the way back when the parent is actually in this workspace list;
|
||||
// a pruned/archived parent would otherwise dead-end on the not-found page.
|
||||
const parentSessionId =
|
||||
active?.parentId && sessions.some((session) => session.sessionId === active.parentId)
|
||||
? active.parentId
|
||||
: null;
|
||||
|
||||
const streamHead = (
|
||||
<div className="stream-head">
|
||||
@@ -342,6 +350,17 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
>
|
||||
<Icon name="chevron-right" />
|
||||
</button>
|
||||
{parentSessionId ? (
|
||||
// A sub-session row is reachable from the tree and by deep link;
|
||||
// this is the way back up without opening the tree.
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn--sm btn--ghost"
|
||||
onClick={() => navigateSession(parentSessionId)}
|
||||
>
|
||||
{t("chat.backToParent")}
|
||||
</button>
|
||||
) : null}
|
||||
<div className="stream-title">
|
||||
{active ? <StatusDot status={sessionDot(active)} title={t(`state.${sessionStatusKey(active)}`)} /> : null}
|
||||
<span className="stream-name truncate">
|
||||
@@ -394,11 +413,13 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
selectedId={active?.sessionId ?? null}
|
||||
filter={filter}
|
||||
collapsed={collapsed}
|
||||
showHidden={showHidden}
|
||||
connected={connected}
|
||||
creating={creating}
|
||||
onFilter={setFilter}
|
||||
onToggleCollapse={toggleCollapsed}
|
||||
onToggleAll={() => setAllCollapsed(allIds, anyOpen)}
|
||||
onToggleShowHidden={toggleShowHidden}
|
||||
onSelectSession={navigateSession}
|
||||
onSelectWorkspace={navigateWorkspace}
|
||||
onNewSession={() => void handleNewSession()}
|
||||
|
||||
+45
-12
@@ -42,7 +42,22 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
|
||||
set((state) => {
|
||||
const list = state.byWorkspace[session.workspaceId] ?? [];
|
||||
const index = list.findIndex((s) => s.sessionId === session.sessionId);
|
||||
const next = index === -1 ? [...list, session] : list.map((s, i) => (i === index ? session : s));
|
||||
if (index === -1) {
|
||||
return { byWorkspace: { ...state.byWorkspace, [session.workspaceId]: [...list, session] } };
|
||||
}
|
||||
// Tree metadata is list metadata: a live update (`pi2:session`,
|
||||
// reducer events, a rename) carries no `parentId`/`visible`/`task` and
|
||||
// must not orphan the row. Explicit `undefined` is the only
|
||||
// "not carried" marker — an explicit `parentId: null` means root and
|
||||
// wins, which `??` would invert.
|
||||
const previous = list[index] as SessionState;
|
||||
const merged: SessionState = {
|
||||
...session,
|
||||
parentId: session.parentId !== undefined ? session.parentId : previous.parentId,
|
||||
visible: session.visible !== undefined ? session.visible : previous.visible,
|
||||
task: session.task !== undefined ? session.task : previous.task,
|
||||
};
|
||||
const next = list.map((s, i) => (i === index ? merged : s));
|
||||
return { byWorkspace: { ...state.byWorkspace, [session.workspaceId]: next } };
|
||||
}),
|
||||
|
||||
@@ -53,18 +68,32 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
|
||||
let moved = false;
|
||||
for (const [workspaceId, list] of Object.entries(state.byWorkspace)) {
|
||||
const index = list.findIndex((session) => session.sessionId === from);
|
||||
if (index === -1) {
|
||||
byWorkspace[workspaceId] = list;
|
||||
continue;
|
||||
}
|
||||
moved = true;
|
||||
byWorkspace[workspaceId] = list
|
||||
.map((session, position) =>
|
||||
position === index ? { ...session, sessionId: to } : session,
|
||||
)
|
||||
let changed = false;
|
||||
let next = list.map((session, position) => {
|
||||
let row = session;
|
||||
if (position === index) {
|
||||
row = { ...row, sessionId: to };
|
||||
changed = true;
|
||||
}
|
||||
// `tmp-N` → real id migration: children (sub-session rows) keep
|
||||
// pointing at their parent, now under its real id.
|
||||
if (row.parentId === from) {
|
||||
row = { ...row, parentId: to };
|
||||
changed = true;
|
||||
}
|
||||
return row;
|
||||
});
|
||||
if (index !== -1) {
|
||||
// A row already cached under the new id would now duplicate the
|
||||
// migrated one (the REST list can be ahead of the event).
|
||||
.filter((session, position) => position === index || session.sessionId !== to);
|
||||
const deduped = next.filter(
|
||||
(session, position) => position === index || session.sessionId !== to,
|
||||
);
|
||||
if (deduped.length !== next.length) changed = true;
|
||||
next = deduped;
|
||||
}
|
||||
if (changed) moved = true;
|
||||
byWorkspace[workspaceId] = next;
|
||||
}
|
||||
if (!moved) return state;
|
||||
return {
|
||||
@@ -77,7 +106,11 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
|
||||
set((state) => {
|
||||
const byWorkspace: Record<string, SessionState[]> = {};
|
||||
for (const [workspaceId, list] of Object.entries(state.byWorkspace)) {
|
||||
byWorkspace[workspaceId] = list.filter((s) => s.sessionId !== sessionId);
|
||||
byWorkspace[workspaceId] = list
|
||||
.filter((s) => s.sessionId !== sessionId)
|
||||
// Never orphan a child: a removed parent promotes its children to
|
||||
// roots instead of hiding them behind a missing row.
|
||||
.map((s) => (s.parentId === sessionId ? { ...s, parentId: null } : s));
|
||||
}
|
||||
return { byWorkspace, selectedSessionId: state.selectedSessionId === sessionId ? null : state.selectedSessionId };
|
||||
}),
|
||||
|
||||
@@ -138,6 +138,22 @@
|
||||
.tree-row .badge {
|
||||
margin-left: var(--space-1);
|
||||
}
|
||||
/* Child sessions: indentation only, no vertical guides — muted and smaller. */
|
||||
.tree-row--sub .t-name {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.tree-row--sub:not(.selected) .t-name {
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
.tree-row[data-hidden="true"] .t-name {
|
||||
/* Muted, not illegible: keep body text above the WCAG AA contrast floor. */
|
||||
opacity: 0.85;
|
||||
}
|
||||
.icon-btn.is-on {
|
||||
background: var(--accent);
|
||||
color: var(--foreground);
|
||||
}
|
||||
.tree-toggle {
|
||||
align-items: center;
|
||||
width: 1.1rem;
|
||||
|
||||
Reference in new issue
Block a user