Files
AgentHub/client/src/lib/projectTreePrefs.ts
T
nntrivi2001 fa156d6a59 feat: v2.6.0 — Chat UI composer (+ menu, project files, activity panel, permission mode, Stop), git on a workspace's extra folders (#70), long paste as a file (#68), S3 server mode (experimental)
Chat UI:
- Each Claude/Codex session keeps its own chat/terminal view; Settings only
  sets how new sessions open.
- Composer + menu: upload, project files and folders (#54, also dragged from
  the Files/Changes tree), context files, recent uploads, skills, plugins.
- Activity side panel (progress, outputs, files read, uploads, memory,
  skills, connectors) with a file preview; edited-file counts per turn.
- Permission-mode chip (Shift+Tab steps, read back from the pane:
  server/lib/pane-mode.js, GET|POST /api/run/:id/permission-mode).
- Stop (Esc) while the main agent works; the status is checked per agent
  (with session_id /api/agents ignores its status filter) and re-read every
  5 s while Stop shows.
- Dropped images shown in the conversation (GET /api/run/drop/:name, the
  requester's own drop dir), full-size viewer.
- A plain-text paste over 5,000 characters is attached as pasted-text.txt,
  so no prompt reaches tmux/argv limits (#68).

Changes panel: every /api/lanes/:id/git* route takes ?source=<lane_sources
id> (sourceFolder; ENOSOURCE otherwise) and a folder picker switches the
whole panel to a workspace's extra folder (#70).

Server mode S3 (one Linux user per account) — experimental, verified with
fake sudo plus a P6 managed-settings spike on a test account:
- member tmux listing runs in the background (cached, 15 s => unknown);
- transcript snapshot copy is async, chunked, temp file + rename;
- Express Layer patch only on Express 4;
- tmux capturePane/sendKey go to the member's own server.

Docs: the multi-user design moved in as docs/plans/server-mode/README.md
(the AgentHub-Server repo is gone); S3-PLAN P6 result; LANES/API/openapi.
2026-10-09 16:35:07 +07:00

87 lines
3.0 KiB
TypeScript

/**
* @file projectTreePrefs — the sidebar workspace list's viewer preferences, in
* ONE localStorage key (`agenthub.sidebar.projects`): which workspaces are
* expanded to their sessions (by lane id), the tool the list is filtered to,
* which owner groups an admin/analyst folded, and — Settings → Worktrees —
* whether a workspace home's Add folder suggests the repo's untracked
* worktrees and which sources of them (`claude` = `<repo>/.claude/worktrees/*`,
* `agenthub` = LANES_ROOT) it leaves out. A `useSyncExternalStore` reader that caches nothing
* but the parsed blob for the current raw string, so the sidebar and Settings
* can never disagree. Nothing here reaches the server.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { useSyncExternalStore } from "react";
export const PROJECT_TREE_KEY = "agenthub.sidebar.projects";
export interface ProjectTreePrefs {
/** Lane id → its sessions are shown under it in the sidebar. */
expanded: Record<string, boolean>;
/** Show only this tool's workspaces; null = every tool. */
tool: string | null;
/** Server mode, admin/analyst: owner key (user id, or "none") → its group is folded. */
collapsedOwners: Record<string, boolean>;
showUntracked: boolean;
hideSources: string[];
}
const DEFAULTS: ProjectTreePrefs = {
expanded: {},
tool: null,
collapsedOwners: {},
showUntracked: true,
hideSources: [],
};
const listeners = new Set<() => void>();
let cache: { raw: string | null; value: ProjectTreePrefs } = { raw: null, value: DEFAULTS };
function readRaw(): string | null {
try {
return localStorage.getItem(PROJECT_TREE_KEY);
} catch {
return null;
}
}
export function readProjectTreePrefs(): ProjectTreePrefs {
const raw = readRaw();
if (raw === cache.raw) return cache.value;
let value = DEFAULTS;
try {
const parsed = raw ? (JSON.parse(raw) as Partial<ProjectTreePrefs>) : {};
value = {
expanded: parsed.expanded && typeof parsed.expanded === "object" ? parsed.expanded : {},
tool: typeof parsed.tool === "string" && parsed.tool ? parsed.tool : null,
collapsedOwners:
parsed.collapsedOwners && typeof parsed.collapsedOwners === "object"
? parsed.collapsedOwners
: {},
showUntracked: parsed.showUntracked !== false,
hideSources: Array.isArray(parsed.hideSources) ? parsed.hideSources : [],
};
} catch {
value = DEFAULTS;
}
cache = { raw, value };
return value;
}
export function writeProjectTreePrefs(patch: Partial<ProjectTreePrefs>): void {
try {
localStorage.setItem(PROJECT_TREE_KEY, JSON.stringify({ ...readProjectTreePrefs(), ...patch }));
} catch {
/* disabled storage: the tree just forgets between visits */
}
listeners.forEach((l) => l());
}
function subscribe(l: () => void) {
listeners.add(l);
return () => listeners.delete(l);
}
export function useProjectTreePrefs(): ProjectTreePrefs {
return useSyncExternalStore(subscribe, readProjectTreePrefs);
}