feat: right-click menus everywhere, workspace/session cost, long-term DB safety

Right-click menus: one portal shell (components/ContextMenu.tsx) for every
item with actions - sidebar/Recents/archived session rows (SessionMenu),
console tabs, pane headers, the Changes panel's files/tree/commits, the
workspace home, sessions outside a workspace (SessionRowMenu: Sessions
table, Dashboard, Activity, Workflow runs), prompt images, every Settings
list and every Claude Code/Codex config list (FileItemMenu). Buttons stay;
a delete keeps its button's confirm; the shell stops portal clicks from
reaching the card that opened it.

Status bar: Workspace $ and Session $ on the Workspace page, from
?lane= on GET /api/pricing/cost and the focused/replayed session's cost.

Database, no data dropped: synchronous=NORMAL, journal_size_limit 64 MB,
hourly PASSIVE checkpoint + PRAGMA optimize, idx_events_session_created
(replacing the redundant idx_events_session), watchdog reads
sessions.transcript_path, transcript parsed before the hook's write
transaction, GET /api/sessions/:id?events=0 for the web page (reloads only
on its own session, debounced), streamed export, transactional clear-data
and chunked cleanup, subagent import reads tool_use_ids once, runtime logs
rotated past 5 MB.
This commit is contained in:
2026-10-05 09:37:48 +07:00
parent 65fe680d38
commit ad6e80192d
80 changed files with 2914 additions and 489 deletions
+45 -1
View File
@@ -1813,13 +1813,57 @@ describe("Database Integrity", () => {
assert.ok(indexes.includes("idx_agents_session"));
assert.ok(indexes.includes("idx_agents_status"));
assert.ok(indexes.includes("idx_events_session"));
// (session_id, created_at) replaces the bare session_id index, a prefix of
// idx_events_session_type that only cost disk.
assert.ok(indexes.includes("idx_events_session_created"));
assert.ok(!indexes.includes("idx_events_session"));
assert.ok(indexes.includes("idx_events_type"));
assert.ok(indexes.includes("idx_events_created"));
assert.ok(indexes.includes("idx_sessions_status"));
assert.ok(indexes.includes("idx_sessions_started"));
});
it("keeps the WAL bounded and fsyncs at checkpoints, not every commit", () => {
assert.equal(db.pragma("synchronous", { simple: true }), 1); // NORMAL
assert.equal(db.pragma("journal_size_limit", { simple: true }), 64 * 1024 * 1024);
});
it("exports every event in time order, streamed in pages", async () => {
db.prepare(
"INSERT OR IGNORE INTO sessions (id, name, status, started_at, updated_at) VALUES ('exp-s', 'e', 'completed', '2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z')"
).run();
const ins = db.prepare(
"INSERT INTO events (session_id, event_type, summary, data, created_at) VALUES ('exp-s', 'PostToolUse', ?, '{}', ?)"
);
db.transaction(() => {
// 1203 rows, with ties on created_at, across the 500-row page edges.
for (let i = 0; i < 1203; i++) {
const ts = new Date(Date.UTC(2026, 0, 1, 0, 0, Math.floor(i / 3))).toISOString();
ins.run(`exp-${i}`, ts);
}
})();
const all = db.prepare("SELECT COUNT(*) AS c FROM events").get().c;
const res = await fetch("/api/settings/export");
assert.equal(res.status, 200);
assert.match(res.headers["content-disposition"], /attachment/);
const { events, sessions, agents, token_usage, model_pricing, exported_at } = res.body;
assert.ok(exported_at && sessions && agents && token_usage && model_pricing);
assert.equal(events.length, all);
assert.equal(new Set(events.map((e) => e.id)).size, all);
for (let i = 1; i < events.length; i++) {
assert.ok(events[i - 1].created_at >= events[i].created_at);
}
assert.equal(events.filter((e) => e.session_id === "exp-s").length, 1203);
});
it("upkeep checkpoints without waiting and optimizes", () => {
const { maintainDatabase } = require("../db");
const out = maintainDatabase();
assert.equal(out.checkpointError, undefined);
assert.equal(out.optimizeError, undefined);
assert.equal(out.checkpoint[0].busy, 0);
});
it("should use WAL journal mode", () => {
const mode = db.pragma("journal_mode", { simple: true });
assert.equal(mode, "wal");
+25
View File
@@ -154,6 +154,31 @@ describe("GET /api/pricing/cost daily split", () => {
});
});
describe("GET /api/pricing/cost?lane=", () => {
it("prices only the sessions a workspace owns, including one its run holds unstamped", async () => {
const lane = require("../lib/lanes").createLane({
title: "w",
cwd: fs.mkdtempSync(path.join(ROOT, "lane-")),
tool: "claude",
});
session("owned", "2026-08-01T00:00:00.000Z");
session("held", "2026-08-01T00:00:00.000Z");
session("other", "2026-08-01T00:00:00.000Z");
db.prepare("UPDATE sessions SET lane_id = ? WHERE id = 'owned'").run(lane.id);
db.prepare(
"INSERT INTO dashboard_runs (id, lane_id, session_id, cwd, status) VALUES ('run-held', ?, 'held', '/x', 'exited')"
).run(lane.id);
total("owned", 2 * M);
total("held", 1 * M);
total("other", 5 * M);
const r = await call("GET", `/api/pricing/cost?tz_offset=0&lane=${lane.id}`);
assert.equal(r.status, 200);
assert.equal(r.body.total_cost, 3);
assert.equal((await call("GET", "/api/pricing/cost?lane=x")).status, 400);
});
});
describe("TranscriptCache tokensByHour", () => {
it("splits by message hour, counts a message once, and survives an incremental read", () => {
const file = path.join(ROOT, "t.jsonl");
+12
View File
@@ -375,6 +375,18 @@ describe("test probe + clear-data", () => {
assert.equal(stmts.lastWebhookDeliveryForTarget.get(created.body.target.id), undefined);
assert.ok(stmts.getWebhookTarget.get(created.body.target.id)); // target survives
});
it("clear-data leaves no workflow run behind its cleared session, and turns foreign keys back on", async () => {
db.prepare(
"INSERT OR IGNORE INTO sessions (id, name, status, started_at, updated_at) VALUES ('wf-s', 'w', 'completed', '2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z')"
).run();
db.prepare("INSERT INTO workflows (run_id, session_id) VALUES ('wf-run', 'wf-s')").run();
const res = await post("/api/settings/clear-data");
assert.equal(res.status, 200);
assert.equal(db.prepare("SELECT COUNT(*) AS c FROM workflows").get().c, 0);
assert.equal(db.prepare("SELECT COUNT(*) AS c FROM sessions").get().c, 0);
assert.equal(db.pragma("foreign_keys", { simple: true }), 1);
});
});
describe("provider registry", () => {