feat: workspaces own their sessions; desktop parity; sidebar and settings cleanup

Workspace sessions (docs/plans/desktop-parity, phases 1-5 and 7):
- sessions.lane_id: a workspace lists only the sessions its panes held,
  stamped by bindRunSession (first writer wins, nested `claude -p`
  excluded); GET /api/sessions?lane=&archived=
- session row state dot, double-click rename, archive (sessions.archived_at,
  hides only); the activity bar's duplicate Sessions tab removed
- Fork beside Resume (--fork-session, Claude only), Ctrl/Cmd+click a live
  session opens it in a second pane, a diff line's comment is pasted into
  the workspace's last-focused pane (lib/panePaste.ts)

dashboard_runs stability:
- a pane's previous run is archived as <pane>@<started_at> instead of being
  overwritten by INSERT OR REPLACE
- a run is flagged abandoned only once its tmux session is gone, at boot and
  on the run-heal beat (panes outlive a server restart)

UI:
- sidebar: no footer, language or theme block; small collapse button in the
  brand corner; version + update check in the connection details modal, a
  status-bar dot while a release is out; language in Settings -> General
- one Switch component for every switch, the themed Checkbox for every
  checkbox (no native checkboxes)

Also: AI Tools catalog trimmed to 10 built-ins (custom-file prompt modes
tested through fixtures), and the workspace plans under docs/plans/ (the
multi-user server plan lives in the AgentHub-Server repo).
This commit is contained in:
2026-10-02 12:05:00 +07:00
parent 5b269698f6
commit a6bd33bcff
121 changed files with 2699 additions and 1552 deletions
+42 -12
View File
@@ -14,6 +14,13 @@
* Workspace page can list one lane's own run history; runs spawned straight
* from POST /api/run leave it null.
*
* A run's id is its tmux pane name (`agenthub-lane-<id>[-slot]`), which every
* Start in that pane reuses. So a new run first ARCHIVES the row it replaces
* under `<id>@<its started_at>` (flagged `abandoned` if it never said it
* ended) — history is kept, and `getRun(<pane name>)` is always the pane's
* current run. A row is flagged dead only once its tmux session is gone
* (`reconcileOrphans(isAlive)`): panes outlive a server restart.
*
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -66,11 +73,28 @@ const getStmt = db.prepare(`
FROM dashboard_runs WHERE id = @id
`);
// The row a new run in the same pane replaces, kept under its own id.
const archiveStmt = db.prepare(`
UPDATE dashboard_runs
SET id = id || '@' || started_at,
status = CASE WHEN status IN ('running', 'spawning') THEN 'abandoned' ELSE status END,
ended_at = COALESCE(ended_at, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
WHERE id = ?
`);
/**
* Insert a new run record at spawn time. Idempotent on `id`.
* Insert a new run record at spawn time; the pane's previous run, if any, is
* archived first rather than overwritten.
*/
function recordRun(handle) {
try {
try {
archiveStmt.run(handle.id);
} catch (err) {
// An archive id already taken (an imported bundle) — fall back to the
// replace below rather than lose the new run.
console.warn(`[dashboard-runs] could not archive run ${handle?.id}: ${err.message}`);
}
const startedAt = new Date(handle.startedAt || Date.now()).toISOString();
const endedAt = handle.endedAt ? new Date(handle.endedAt).toISOString() : null;
const prompt = typeof handle.prompt === "string" ? handle.prompt : "";
@@ -137,26 +161,32 @@ function getRun(id) {
}
}
const reconcileStmt = db.prepare(`
const runningStmt = db.prepare(
"SELECT id FROM dashboard_runs WHERE status IN ('running', 'spawning')"
);
const abandonStmt = db.prepare(`
UPDATE dashboard_runs
SET status = 'abandoned',
ended_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
WHERE status IN ('running', 'spawning')
ended_at = COALESCE(ended_at, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
WHERE id = ? AND status IN ('running', 'spawning')
`);
/**
* On server boot, any rows still flagged `running` or `spawning` are
* orphans — the spawner only persists those statuses for handles it knows
* about, and the in-memory map was just wiped by the restart. Mark them as
* `abandoned` so the UI doesn't display them as live and the user can
* resume them like any other completed past run.
* Flags `abandoned` every row still marked running/spawning whose pane is
* gone — the pane's process quit (Ctrl+C, `exit`), or the machine rebooted.
* A pane is a tmux session, which outlives a server restart, so liveness is
* asked of `isAlive(id)` (tmux), never assumed from the restart. Run at boot
* and on the server's run-heal beat.
*
* Returns the number of rows updated.
*/
function reconcileOrphans() {
function reconcileOrphans(isAlive = () => false) {
try {
const info = reconcileStmt.run();
return info.changes || 0;
let changes = 0;
for (const { id } of runningStmt.all()) {
if (!isAlive(id)) changes += abandonStmt.run(id).changes;
}
return changes;
} catch {
return 0;
}
+16 -1
View File
@@ -106,6 +106,7 @@ function buildClaudeArgv({
permissionMode,
effort,
resumeSessionId,
forkSession = false,
initialPrompt,
addDirs = [],
systemPromptFile = null,
@@ -129,6 +130,9 @@ function buildClaudeArgv({
if (model) argv.push("--model", model);
if (effort && EFFORT_LEVELS.has(effort)) argv.push("--effort", effort);
if (resumeSessionId) argv.push("--resume", resumeSessionId);
// A fork resumes the history into a NEW session id; the original is left as
// it was.
if (resumeSessionId && forkSession) argv.push("--fork-session");
if (initialPrompt) argv.push(promptArg(initialPrompt));
return argv;
}
@@ -222,6 +226,8 @@ function buildArgv(args, entry) {
* @param {string} [args.sandbox]
* @param {string} [args.approval]
* @param {string} [args.resumeSessionId]
* @param {boolean} [args.forkSession] resume `resumeSessionId` into a new
* session id (`claude --fork-session`); Claude only.
* @param {boolean} [args.resumeLast]
* @param {boolean} [args.bypass] the user ticked "bypass permissions" for THIS
* run; appends the catalog's bypass args/env. Claude has no catalog bypass.
@@ -241,6 +247,7 @@ function spawnRun(args) {
sandbox,
approval,
resumeSessionId,
forkSession,
resumeLast,
bypass,
initialPrompt,
@@ -293,6 +300,12 @@ function spawnRun(args) {
) {
throw makeErr("EBADSESSION", "resumeSessionId is not a valid session id");
}
if (forkSession === true) {
if (!resumeSessionId) throw makeErr("EBADSESSION", "a fork needs resumeSessionId");
if (entry.launcher !== "claude") {
throw makeErr("EUNSUPPORTED", `${tool} cannot fork a session`);
}
}
// A run IS a tmux session, so an absent binary is a precondition failure, not
// a spawn failure. Without this the caller gets `spawnSync tmux ENOENT` from
@@ -330,6 +343,7 @@ function spawnRun(args) {
sandbox,
approval,
resumeSessionId,
forkSession: forkSession === true,
resumeLast,
bypass: bypass === true,
initialPrompt,
@@ -343,7 +357,8 @@ function spawnRun(args) {
if (!dashboardRuns) return;
dashboardRuns.recordRun({
id,
sessionId: resumeSessionId || null,
// A fork's own id arrives with its first hook (bindRunSession).
sessionId: (forkSession !== true && resumeSessionId) || null,
// `dashboard_runs.mode` is NOT NULL. Passing null made every insert throw
// inside recordRun's best-effort catch, so no tmux-backed run was ever
// persisted: publicRun then read its cwd/model/prompt/startedAt off a row