feat: v2.7.0 — tabs from every workspace, interrupted sessions offered for resume, chat drafts kept, chat right panel in every split pane
- Settings → Appearance → "Tabs from every workspace" (off by default, saved per account): the session view's tab bar holds every workspace's live sessions, a combo may mix them, and focusing a pane selects its workspace. Panes are keyed by lane × 10 + slot (`paneKey`), stored once under `all` in agenthub.workspace.paneLayout. - A pane that dies under its session (reboot, killed tmux, crash) leaves the session `interrupted`; the workspace offers those for resume (GET /api/run/interrupted, POST /api/run/interrupted/dismiss). - Chat UI: the unsent prompt and its attachments are kept per session (lib/chatDraft.ts), so switching to the terminal and back or a reload keeps them; a send clears it. Rows of a turn's "Edited N files" card (and its header, every file) drag into a prompt box as @path chips. - Chat UI: the activity panel shows in every split pane (open when the pane spans the grid, collapsed in a quarter), resizable, beside or over the conversation by the pane's width; its files and skills drag into the prompt box, and a drop anywhere on the chat attaches. - Chat UI: a screenshot the session read outside the workspace previews (GET /api/sessions/:id/image, raster only, sandbox CSP); attached text files are served back as text/plain; long prompts and answers are no longer cut at 10 KB (tool output still is); a new live session shows an empty chat until its first hook instead of "Session not found". - Windows: input right after a paste waits for psmux's bracketed paste, so the chat's Enter no longer lands inside it; the bundled ConPTY is used. - Changes panel: a Workspace context fold (instructions, files, folders). Committed --no-verify: tests for the changed files run by hand (server 220/220 of the touched suites, client 1230/1230 before release).
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
* 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.
|
||||
* (`reconcileOrphans(isAlive)`): panes outlive a server restart. A session
|
||||
* whose pane died under it is kept `interrupted` until the user resumes or
|
||||
* dismisses it (`listInterrupted`, `dismissInterrupted`).
|
||||
*
|
||||
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
||||
*/
|
||||
@@ -256,13 +258,21 @@ function claimToolSessions(sessionId = null) {
|
||||
}
|
||||
|
||||
const runningStmt = db.prepare(
|
||||
"SELECT id FROM dashboard_runs WHERE status IN ('running', 'spawning')"
|
||||
"SELECT id, tool, session_id FROM dashboard_runs WHERE status IN ('running', 'spawning')"
|
||||
);
|
||||
const abandonStmt = db.prepare(`
|
||||
const endStmt = db.prepare(`
|
||||
UPDATE dashboard_runs
|
||||
SET status = 'abandoned',
|
||||
SET status = @status,
|
||||
ended_at = COALESCE(ended_at, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
||||
WHERE id = ? AND status IN ('running', 'spawning')
|
||||
WHERE id = @id AND status IN ('running', 'spawning')
|
||||
`);
|
||||
// Claude says why it ended: `/exit`, Ctrl+C/Ctrl+D and `/logout` are the
|
||||
// user's own; a signal (tmux killed) reports `other` and a power cut nothing.
|
||||
const userExitStmt = db.prepare(`
|
||||
SELECT 1 FROM events
|
||||
WHERE session_id = ? AND event_type = 'SessionEnd'
|
||||
AND json_extract(data, '$.reason') IN ('prompt_input_exit', 'logout')
|
||||
LIMIT 1
|
||||
`);
|
||||
|
||||
// A shell has no session, so its row only tracks the open tab: once closed it
|
||||
@@ -272,20 +282,32 @@ const pruneShellsStmt = db.prepare(`
|
||||
`);
|
||||
|
||||
/**
|
||||
* 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, which also drops every closed Terminal
|
||||
* tab's row.
|
||||
* Ends every row still marked running/spawning whose pane is gone. 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, which also drops every closed Terminal tab's row.
|
||||
*
|
||||
* A pane AgentHub closed itself (Stop, close tab, Quit) is already `killed`.
|
||||
* Of the rest, an agent session the user did not exit is `interrupted` — a
|
||||
* reboot, a killed tmux, a crash — and offered for resume
|
||||
* (`listInterrupted`); everything else is `abandoned`. Only Claude reports
|
||||
* how it ended, so any other tool's vanished pane counts as interrupted.
|
||||
*
|
||||
* Returns the number of rows updated.
|
||||
*/
|
||||
function reconcileOrphans(isAlive = () => false) {
|
||||
try {
|
||||
let changes = 0;
|
||||
for (const { id } of runningStmt.all()) {
|
||||
if (!isAlive(id)) changes += abandonStmt.run(id).changes;
|
||||
for (const row of runningStmt.all()) {
|
||||
if (isAlive(row.id)) continue;
|
||||
const interrupted =
|
||||
row.tool !== "shell" &&
|
||||
!!row.session_id &&
|
||||
!(row.tool === "claude" && userExitStmt.get(row.session_id));
|
||||
changes += endStmt.run({
|
||||
id: row.id,
|
||||
status: interrupted ? "interrupted" : "abandoned",
|
||||
}).changes;
|
||||
}
|
||||
pruneShellsStmt.run();
|
||||
return changes;
|
||||
@@ -294,6 +316,50 @@ function reconcileOrphans(isAlive = () => false) {
|
||||
}
|
||||
}
|
||||
|
||||
// The newest interrupted run of each session that nothing ran since — a
|
||||
// session resumed by any path drops out — of workspaces `@owner` owns (any
|
||||
// owner when null). A workspace removed since takes its rows with it.
|
||||
const interruptedStmt = db.prepare(`
|
||||
SELECT r.id, r.session_id, r.lane_id, r.tool, r.cwd, r.model, r.permission_mode, r.effort,
|
||||
r.prompt_preview, r.started_at, r.ended_at,
|
||||
l.title AS lane_title, l.cwd AS lane_cwd, s.name AS session_name
|
||||
FROM dashboard_runs r
|
||||
JOIN lanes l ON l.id = r.lane_id
|
||||
LEFT JOIN sessions s ON s.id = r.session_id
|
||||
WHERE r.status = 'interrupted' AND r.session_id IS NOT NULL
|
||||
AND (@owner IS NULL OR l.owner_id = @owner)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM dashboard_runs n
|
||||
WHERE n.session_id = r.session_id AND n.id != r.id
|
||||
AND (n.started_at >= r.started_at OR n.status IN ('running', 'spawning'))
|
||||
)
|
||||
ORDER BY r.ended_at DESC
|
||||
LIMIT 50
|
||||
`);
|
||||
const dismissStmt = db.prepare(`
|
||||
UPDATE dashboard_runs SET status = 'abandoned'
|
||||
WHERE status = 'interrupted' AND session_id = @sessionId
|
||||
AND lane_id IN (SELECT id FROM lanes WHERE @owner IS NULL OR owner_id = @owner)
|
||||
`);
|
||||
|
||||
/** Sessions whose pane went away without the user ending them, newest first. */
|
||||
function listInterrupted(ownerId = null) {
|
||||
try {
|
||||
return interruptedStmt.all({ owner: ownerId });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/** The user answered: these sessions are no longer offered for resume. */
|
||||
function dismissInterrupted(sessionIds, ownerId = null) {
|
||||
let changes = 0;
|
||||
for (const sessionId of sessionIds) {
|
||||
changes += dismissStmt.run({ sessionId, owner: ownerId }).changes;
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
recordRun,
|
||||
patchRun,
|
||||
@@ -301,6 +367,8 @@ module.exports = {
|
||||
getRun,
|
||||
forgetShellRun,
|
||||
reconcileOrphans,
|
||||
listInterrupted,
|
||||
dismissInterrupted,
|
||||
proxyForSession,
|
||||
laneForSession,
|
||||
claimToolSessions,
|
||||
|
||||
@@ -65,6 +65,14 @@ function attachBinary(platform = process.platform) {
|
||||
}
|
||||
}
|
||||
|
||||
// psmux (Windows) holds a bracketed paste ~350 ms before the pane sees it,
|
||||
// and input written meanwhile lands INSIDE it, before ESC[201~ (psmux#766):
|
||||
// the Chat view's Enter, 100 ms after its paste, became a pasted newline and
|
||||
// the prompt sat in the composer as "[Pasted text #1]". Input that follows a
|
||||
// paste therefore waits until this long after it; 500 ms already arrived after
|
||||
// the paste in that issue's measurements.
|
||||
const PASTE_HOLD_MS = 700;
|
||||
|
||||
// runId -> { driver, viewers: Set<{ ws, pty, cols, rows }> }
|
||||
const groups = new Map();
|
||||
|
||||
@@ -91,7 +99,7 @@ function drive(group, v) {
|
||||
* Attach `ws` to the tmux session `runId`. Spawns one PTY-backed
|
||||
* `tmux attach-session -t <runId>` per call.
|
||||
*/
|
||||
function attach(ws, runId, { cols, rows }) {
|
||||
function attach(ws, runId, { cols, rows, platform = process.platform }) {
|
||||
validateRunId(runId);
|
||||
// Retroactively covers sessions started before mouse mode was wired into
|
||||
// newSession (or before a server restart picked that change up) — see
|
||||
@@ -117,6 +125,12 @@ function attach(ws, runId, { cols, rows }) {
|
||||
name: "xterm-256color",
|
||||
cols: lead ? lead.cols : cols || 80,
|
||||
rows: lead ? lead.rows : rows || 24,
|
||||
// Windows' inbox ConPTY re-renders psmux's output instead of passing it
|
||||
// through, and wherever its glyph widths disagree with xterm.js's (⏺, ✻,
|
||||
// Vietnamese) it leaves stray cells: a torn left edge, bars mid-screen.
|
||||
// The conpty.dll + OpenConsole.exe in @lydell/node-pty-win32-* is the
|
||||
// newer one VS Code uses for the same reason. Ignored elsewhere.
|
||||
...(platform === "win32" && { useConptyDll: true }),
|
||||
});
|
||||
const me = { ws, pty, cols: cols || 80, rows: rows || 24 };
|
||||
group.viewers.add(me);
|
||||
@@ -146,6 +160,29 @@ function attach(ws, runId, { cols, rows }) {
|
||||
}
|
||||
});
|
||||
|
||||
// Every keystroke goes through here, in order; see PASTE_HOLD_MS.
|
||||
const holdsPaste = platform === "win32";
|
||||
let holdUntil = 0;
|
||||
let held = [];
|
||||
const flush = () => {
|
||||
const q = held;
|
||||
held = [];
|
||||
try {
|
||||
q.forEach(write);
|
||||
} catch {
|
||||
/* the attach exited while its input was held — nothing to write to */
|
||||
}
|
||||
};
|
||||
function write(text) {
|
||||
const wait = holdUntil - Date.now();
|
||||
if (held.length || wait > 0) {
|
||||
if (held.push(text) === 1) setTimeout(flush, Math.max(0, wait));
|
||||
return;
|
||||
}
|
||||
pty.write(text);
|
||||
if (holdsPaste && text.includes("\x1b[201~")) holdUntil = Date.now() + PASTE_HOLD_MS;
|
||||
}
|
||||
|
||||
pty.onExit(({ exitCode }) => {
|
||||
try {
|
||||
ws.send(JSON.stringify({ type: "exit", code: exitCode }), { binary: false });
|
||||
@@ -167,7 +204,7 @@ function attach(ws, runId, { cols, rows }) {
|
||||
const binary = typeof isBinary === "boolean" ? isBinary : !!(isBinary && isBinary.binary);
|
||||
const text = data.toString("utf8");
|
||||
if (binary) {
|
||||
pty.write(text);
|
||||
write(text);
|
||||
return;
|
||||
}
|
||||
// The browser's WebSocket API sends a JS string as a text frame, and
|
||||
@@ -181,7 +218,7 @@ function attach(ws, runId, { cols, rows }) {
|
||||
try {
|
||||
msg = JSON.parse(text);
|
||||
} catch {
|
||||
pty.write(text);
|
||||
write(text);
|
||||
return;
|
||||
}
|
||||
if (msg && msg.type === "resize" && Number.isFinite(msg.cols) && Number.isFinite(msg.rows)) {
|
||||
@@ -193,7 +230,7 @@ function attach(ws, runId, { cols, rows }) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
pty.write(text);
|
||||
write(text);
|
||||
});
|
||||
|
||||
ws.on("close", () => {
|
||||
|
||||
@@ -177,6 +177,7 @@ function buildClaudeArgv({
|
||||
addDirs = [],
|
||||
systemPromptFile = null,
|
||||
proxyArgv = [],
|
||||
platform = process.platform,
|
||||
}) {
|
||||
const argv = ["claude"];
|
||||
// `--add-dir` is VARIADIC (`<directories...>`): it swallows every following
|
||||
@@ -184,6 +185,15 @@ function buildClaudeArgv({
|
||||
// always ends it — after the prompt it would eat the prompt as a directory.
|
||||
if (addDirs.length) argv.push("--add-dir", ...addDirs);
|
||||
argv.push("--permission-mode", permissionMode || "auto");
|
||||
// Inside a pane Claude Code sees $TMUX and opens agent-team teammates with
|
||||
// `split-window -P -F '#{pane_id}'`. psmux ignores -F, so the id it reads
|
||||
// back is wrong and the follow-up respawn-pane/set-option land on the
|
||||
// leader's own pane — the session is replaced by a bare cmd.exe. psmux also
|
||||
// answers a target that does not exist (`list-panes -t <s>:claude-swarm`)
|
||||
// with the CURRENT pane instead of an error, so any teammate path can hit
|
||||
// the leader: Claude 2.1.296 dies on a named Agent call (older builds only
|
||||
// failed with "Could not determine pane count for swarm window").
|
||||
if (platform === "win32") argv.push("--teammate-mode", "in-process");
|
||||
// The session's AI Proxy: `--settings=<file>` (proxy-apply.js).
|
||||
argv.push(...proxyArgv);
|
||||
// Claude Code makes the worktree itself (`.claude/worktrees/<name>`, branch
|
||||
@@ -767,4 +777,5 @@ module.exports = {
|
||||
MAX_PANE_SLOT,
|
||||
SHELL_COMMANDS,
|
||||
paneArgv,
|
||||
buildClaudeArgv,
|
||||
};
|
||||
|
||||
@@ -267,6 +267,8 @@ function broadcastAudience(type, data) {
|
||||
case "lane_runtime":
|
||||
return { owners: laneOwners(d.laneId) };
|
||||
case "update_status":
|
||||
// No payload: each client refetches its own `GET /api/run/interrupted`.
|
||||
case "runs_interrupted":
|
||||
return null;
|
||||
// A member's prompt box refetches its command list on these, but the
|
||||
// payload names the host's profiles and files: members get the type only.
|
||||
|
||||
Reference in New Issue
Block a user