fix: event-loop freezes, plugin-install boot crash, tmux attach/scrollbar, Codex transcripts

- GET /api/workflows: one LEAD() window pass in a read worker (read-pool.js,
  workflow-stats.js); idx_events_session restored, idx_events_tool added
- compat-sqlite gains function/pluck/readonly so a plugin install without a
  better-sqlite3 build boots again; antigravity-usage uses db.js's Database
- install-hooks adds no checkout hooks while the agenthub plugin is enabled
  (events were doubled)
- terminal attach runs the live tmux server's own binary; the pane scrollbar
  gets a visible 2-column style, and claude panes start with
  CLAUDE_CODE_DISABLE_ALTERNATE_SCREEN=1 so tmux keeps history to scroll
- Codex sessions' conversation in GET /api/sessions/:id/transcript
- Codex/Antigravity sessions claimed by their workspace without hooks
- UI-audit follow-ups, docs and OpenAPI
This commit is contained in:
2026-10-05 17:01:05 +07:00
parent 442f133930
commit 198fbb7980
78 changed files with 2716 additions and 873 deletions
@@ -0,0 +1,29 @@
/**
* @file runWorktree.test.ts
* @description The Changes panel's worktree session for a `?run=` pane survives
* a poll that misses the run, and follows every real answer.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { describe, it, expect } from "vitest";
import { runWorktreeSession } from "../runWorktree";
const wt = { worktree: true, sessionId: "s1" };
describe("runWorktreeSession", () => {
it("follows the listed run's worktree session", () => {
expect(runWorktreeSession(null, "r1", wt)).toEqual({ run: "r1", session: "s1" });
expect(runWorktreeSession(null, "r1", { worktree: false, sessionId: "s1" })).toBeNull();
});
it("keeps the last answer through a poll that misses the run", () => {
const prev = runWorktreeSession(null, "r1", wt);
expect(runWorktreeSession(prev, "r1", undefined)).toEqual({ run: "r1", session: "s1" });
});
it("drops it for another run or no run", () => {
const prev = runWorktreeSession(null, "r1", wt);
expect(runWorktreeSession(prev, "r2", undefined)).toBeNull();
expect(runWorktreeSession(prev, null, undefined)).toBeNull();
});
});
+35
View File
@@ -0,0 +1,35 @@
/**
* @file toast.test.ts
* @description The toast queue: at most four on screen, and an error — which
* stays until dismissed — is never the one pushed out by newer toasts.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { describe, it, expect, afterEach } from "vitest";
import { toast, subscribeToasts, dismissToast, type ToastItem } from "../toast";
let current: ToastItem[] = [];
const unsubscribe = subscribeToasts((items) => (current = items));
afterEach(() => {
for (const t of current) dismissToast(t.id);
});
describe("toast queue", () => {
it("keeps an unread error when newer toasts overflow the queue", () => {
toast.error("save failed");
for (let i = 0; i < 5; i++) toast.success(`copied ${i}`);
expect(current).toHaveLength(4);
expect(current.map((t) => t.message)).toContain("save failed");
expect(current[current.length - 1]?.message).toBe("copied 4");
});
it("still shows the newest toast when only errors are queued", () => {
for (let i = 0; i < 4; i++) toast.error(`error ${i}`);
toast.info("hello");
expect(current).toHaveLength(4);
expect(current[current.length - 1]?.message).toBe("hello");
});
});
void unsubscribe;
+14 -3
View File
@@ -1255,10 +1255,21 @@ export const api = {
* "all" (which means "no filter"), keeping the default URL param-free.
*
* @param status Optional lifecycle filter; "all" (or omitted) means no filter.
* @returns {@link WorkflowData} — the aggregated workflow-intelligence panel.
* @param sections Optional subset of the bundle to compute (`?sections=`);
* the server skips the rest, so a page reading a few cards asks for those.
* @returns {@link WorkflowData} — the aggregated workflow-intelligence panel,
* or just the named sections of it.
*/
get: (status?: string) =>
request<WorkflowData>(`/workflows${status && status !== "all" ? `?status=${status}` : ""}`),
get: <K extends keyof WorkflowData = keyof WorkflowData>(
status?: string,
sections?: readonly K[]
) => {
const qs = new URLSearchParams();
if (status && status !== "all") qs.set("status", status);
if (sections?.length) qs.set("sections", sections.join(","));
const q = qs.toString();
return request<Pick<WorkflowData, K>>(`/workflows${q ? `?${q}` : ""}`);
},
/**
* GET /api/workflows/session/:id - single-session drill-in (agent tree,
* tool timeline, swim lanes).
+29
View File
@@ -0,0 +1,29 @@
/**
* @file runWorktree.ts
* @description Which `claude --worktree` session the Workspace's Changes panel
* follows for the URL's `?run=` pane. A poll that misses the run (one bad read
* lists no runs) keeps the last answer instead of moving the panel to the main
* folder — which, while it holds an unsaved edit, asked to discard it out of
* nowhere.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
export interface RunWorktree {
run: string;
session: string;
}
/**
* @param prev The previous answer.
* @param runParam The URL's `?run=`.
* @param opened That run in the latest list, if the list had it.
*/
export function runWorktreeSession(
prev: RunWorktree | null,
runParam: string | null,
opened: { worktree?: boolean; sessionId: string | null } | undefined
): RunWorktree | null {
if (!runParam) return null;
if (!opened) return prev?.run === runParam ? prev : null;
return opened.worktree && opened.sessionId ? { run: runParam, session: opened.sessionId } : null;
}
+9 -1
View File
@@ -16,6 +16,7 @@ export interface ToastItem {
}
const SUCCESS_MS = 4000;
const MAX_TOASTS = 4;
let items: ToastItem[] = [];
let nextId = 1;
const listeners = new Set<(items: ToastItem[]) => void>();
@@ -33,7 +34,14 @@ export function dismissToast(id: number): void {
function push(kind: ToastKind, message: string): number {
const id = nextId++;
// Same text twice in a row (a double click, a retry) shows once.
items = [...items.filter((t) => t.message !== message), { id, kind, message }].slice(-4);
const next = [...items.filter((t) => t.message !== message), { id, kind, message }];
// Over four: the oldest non-error goes first, so an unread error is not pushed
// out by a few copies or saves; the newest toast always stays.
while (next.length > MAX_TOASTS) {
const older = next.slice(0, -1).findIndex((t) => t.kind !== "error");
next.splice(older === -1 ? 0 : older, 1);
}
items = next;
emit();
if (kind !== "error") window.setTimeout(() => dismissToast(id), SUCCESS_MS);
return id;