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
+44 -2
View File
@@ -144,6 +144,13 @@ const db = new Database(DB_PATH);
db.pragma("journal_mode = WAL");
db.pragma("foreign_keys = ON");
db.pragma("busy_timeout = 5000");
// WAL + NORMAL never corrupts the file; a power cut can lose only the last
// commits, which hooks re-send. FULL fsynced every commit — several per hook.
db.pragma("synchronous = NORMAL");
// A checkpoint truncates the WAL back to this. Unset, one big transaction
// (an import, a cleanup) left a WAL of hundreds of MB that never shrank while
// any dashboard kept the database open. See also `maintainDatabase`.
db.pragma("journal_size_limit = 67108864");
db.exec(`
CREATE TABLE IF NOT EXISTS sessions (
@@ -298,7 +305,12 @@ db.exec(`
CREATE INDEX IF NOT EXISTS idx_agents_session ON agents(session_id);
CREATE INDEX IF NOT EXISTS idx_agents_status ON agents(status);
CREATE INDEX IF NOT EXISTS idx_events_session ON events(session_id);
-- (session_id, created_at): a session's newest event and its time order,
-- read by the watchdog every 15 s and by every lane payload. Without it each
-- read walked the rows' overflow chains (created_at sits after data).
CREATE INDEX IF NOT EXISTS idx_events_session_created ON events(session_id, created_at);
-- A prefix of idx_events_session_type: never needed, ~1% of the file.
DROP INDEX IF EXISTS idx_events_session;
CREATE INDEX IF NOT EXISTS idx_events_type ON events(event_type);
CREATE INDEX IF NOT EXISTS idx_events_created ON events(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_sessions_status ON sessions(status);
@@ -2127,4 +2139,34 @@ const stmts = {
),
};
module.exports = { db, stmts, DB_PATH, DEFAULT_PRICING, applyIntroPricing, topUpDefaultPricing };
/**
* Periodic upkeep, run hourly by the server: a PASSIVE checkpoint (never waits
* on a reader — the other dashboard's), after which the next write truncates
* the WAL to `journal_size_limit`; and `PRAGMA optimize`, which refreshes the
* planner's statistics only where they went stale. Never VACUUM: it rewrites
* the whole file under an exclusive lock.
*/
function maintainDatabase() {
const out = {};
try {
out.checkpoint = db.pragma("wal_checkpoint(PASSIVE)", { simple: false });
} catch (err) {
out.checkpointError = err.message;
}
try {
db.pragma("optimize");
} catch (err) {
out.optimizeError = err.message;
}
return out;
}
module.exports = {
db,
stmts,
DB_PATH,
DEFAULT_PRICING,
applyIntroPricing,
topUpDefaultPricing,
maintainDatabase,
};