From d796cbfbbef82ffa0bebcda41218697995f4494a Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:36:52 +0000 Subject: [PATCH] Helper logins in agent runs, the now feed and the item trace go to staff only --- src/agents/runs.ts | 13 +++++++------ src/dash/api/activity.ts | 2 +- src/dash/api/agents.ts | 2 +- src/dash/api/now.ts | 2 +- src/dash/api/trace.ts | 8 ++++---- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/agents/runs.ts b/src/agents/runs.ts index e1ae592b..02f26740 100644 --- a/src/agents/runs.ts +++ b/src/agents/runs.ts @@ -98,13 +98,14 @@ function refs(s: string): ItemRef[] { } } -function toRun(r: RunRow, shown: (repo: string, number: number) => ItemShown): AgentRun { +/** `via` (the helper's login) goes to staff only. */ +function toRun(r: RunRow, shown: (repo: string, number: number) => ItemShown, staff: boolean): AgentRun { return { id: r.id, jobId: r.job_id, step: r.step, stage: r.stage, promptId: r.prompt_id, promptVersion: r.prompt_version, provider: r.provider === "jev" ? "jev" : "claude", model: r.model, accountId: r.account_id, accountLabel: r.account_id ? (r.account_label ?? r.account_id) : null, items: refs(r.items).map((x) => ({ ...x, ...shown(x.repo, x.number) })), itemCount: r.item_count, state: r.state, startedAt: r.started_at, endedAt: r.ended_at, inputTokens: r.input_tokens, outputTokens: r.output_tokens, cacheReadTokens: r.cache_read_tokens, cacheWriteTokens: r.cache_write_tokens, costUsd: r.cost_usd, summary: r.summary, - ...(r.user_login && { via: { login: r.user_login, harness: r.harness ?? "", model: r.reported_model ?? "" } }), + ...(staff && r.user_login && { via: { login: r.user_login, harness: r.harness ?? "", model: r.reported_model ?? "" } }), ...(r.state === "running" && r.progress && { progress: r.progress }), }; } @@ -124,7 +125,7 @@ const CURSOR_RE = /^[1-9][0-9]{0,15}$/; export const AGENT_PAGE_DEFAULT = 50, AGENT_PAGE_MAX = 200; /** Newest first, keyset on id: a page costs index reads proportional to its size, however many runs exist. */ -export function listRuns(db: DatabaseSync, f: AgentRunFilter, hidden: HiddenRepos = []): AgentRunPage { +export function listRuns(db: DatabaseSync, f: AgentRunFilter, hidden: HiddenRepos = [], staff = false): AgentRunPage { if (f.state !== undefined && !["running", "done", "failed", "recent"].includes(f.state)) throw new RunQueryError(400, "unknown state"); if (f.step !== undefined && !STEP_RE.test(f.step)) throw new RunQueryError(400, "bad step"); if (f.account !== undefined && !ACCOUNT_RE.test(f.account)) throw new RunQueryError(400, "bad account"); @@ -152,7 +153,7 @@ export function listRuns(db: DatabaseSync, f: AgentRunFilter, hidden: HiddenRepo const rows = db.prepare(sql).all(...args, limit + 1) as RunRow[]; const shown = shownLookup(db); const page = rows.slice(0, limit); - return { runs: page.map((x) => toRun(x, shown)), nextCursor: rows.length > limit ? String(page[page.length - 1]!.id) : null }; + return { runs: page.map((x) => toRun(x, shown, staff)), nextCursor: rows.length > limit ? String(page[page.length - 1]!.id) : null }; } /** @@ -174,9 +175,9 @@ export function getRun(db: DatabaseSync, id: unknown, view: { hidden?: HiddenRep } const tools = runTools(db, id); // Tool arguments carry file paths and patch text: like the prompt, for operators only. - if (!view.texts) return { ...toRun(r, shownLookup(db)), prompt: null, output: null, error: r.error ? "failed" : null, tools: tools.map((t) => ({ ...t, args: null })), textsHidden: true }; + if (!view.texts) return { ...toRun(r, shownLookup(db), false), prompt: null, output: null, error: r.error ? "failed" : null, tools: tools.map((t) => ({ ...t, args: null })), textsHidden: true }; const t = db.prepare("SELECT prompt, output FROM agent_run_texts WHERE run_id = ?").get(id) as { prompt: unknown; output: unknown } | undefined; - return { ...toRun(r, shownLookup(db)), prompt: unpackText(t?.prompt), output: unpackText(t?.output), error: r.error, tools }; + return { ...toRun(r, shownLookup(db), view.texts === true), prompt: unpackText(t?.prompt), output: unpackText(t?.output), error: r.error, tools }; } /** The tool uses of a run in order; a check-tool use carries its model_checks row. */ diff --git a/src/dash/api/activity.ts b/src/dash/api/activity.ts index f21fbffa..f6a51503 100644 --- a/src/dash/api/activity.ts +++ b/src/dash/api/activity.ts @@ -89,7 +89,7 @@ export const SOURCES: Source[] = [ pull: (c) => newest[0] & At>(c, { cols: `${RUN_COLUMNS}, i.repo AS repo, i.number AS number, r.started_at AS ${T}`, from: "agent_runs r JOIN agent_run_items i ON i.run_id = r.id AND (i.repo, i.number) = (SELECT x.repo, x.number FROM agent_run_items x WHERE x.run_id = r.id ORDER BY x.repo, x.number LIMIT 1) LEFT JOIN claude_accounts a ON a.id = r.account_id", - time: "r.started_at", repoCol: "i.repo", where: hiddenSql(c.hidden).replace(/^ AND /, "") || undefined, args: hiddenArgs(c.hidden), map: (r) => [runEvent(r)], + time: "r.started_at", repoCol: "i.repo", where: hiddenSql(c.hidden).replace(/^ AND /, "") || undefined, args: hiddenArgs(c.hidden), map: (r) => [runEvent(r, c.staff)], }), }, plain[0] & At>("check", "model_checks", "started_at", "repo, number, id, run_id, step, head, command, crate, test_name, task_id, outcome, started_at", checkEvent), diff --git a/src/dash/api/agents.ts b/src/dash/api/agents.ts index 67fdd6b3..757d6fcc 100644 --- a/src/dash/api/agents.ts +++ b/src/dash/api/agents.ts @@ -68,7 +68,7 @@ export const list = (db: DatabaseSync, req: Req) => wrap(async () => { const f: AgentRunFilter = { state: q("state") as AgentRunState | "recent" | undefined, step: q("step"), account: q("account"), repo: q("repo"), cursor: q("cursor"), limit: intParam(req, "limit"), }; - return listRuns(db, f, await hiddenRepos(db, req)); + return listRuns(db, f, await hiddenRepos(db, req), canSeeInternals(req)); }); // The prompt and output texts hold item and comment text verbatim: operators and maintainers only. diff --git a/src/dash/api/now.ts b/src/dash/api/now.ts index 64d526b2..ed355c4a 100644 --- a/src/dash/api/now.ts +++ b/src/dash/api/now.ts @@ -227,7 +227,7 @@ function feed(db: DatabaseSync, hidden: HiddenRepos, staff: boolean, operator: b placeChild(r.job_id, base({ key: `run:${r.id}`, kind: "call", state: "running", at: r.started_at, title: stepTitle(r.step), what: r.provider === "jev" ? "Jev" : r.user_login ? r.model : operator ? `${r.model} on ${r.label ?? "an unknown account"}` : r.model, progress: blankIfHidden(r.progress, hidden) || null, item: its[0] ? item(its[0].repo, its[0].number) : null, items: its.map((i) => item(i.repo, i.number)), itemCount: Math.max(r.item_count, its.length), event: its[0] ? `run:${r.id}` : null, detail: `/agents/${r.id}`, - ...(r.user_login && { via: { login: r.user_login, harness: r.harness ?? "", model: r.reported_model ?? "" } }), + ...(staff && r.user_login && { via: { login: r.user_login, harness: r.harness ?? "", model: r.reported_model ?? "" } }), })); } for (const t of all<{ id: number; job_id: number | null; step: string; repo: string; number: number | null; state: string; queued_at: string; started_at: string | null; summary: string | null; label: string | null }>(db, diff --git a/src/dash/api/trace.ts b/src/dash/api/trace.ts index 7cc634dd..9ea6ade6 100644 --- a/src/dash/api/trace.ts +++ b/src/dash/api/trace.ts @@ -139,18 +139,18 @@ const PROMPT_TITLES: Record = { "lint.reference.jev": "Reference export const RUN_COLUMNS = `r.id, r.step, r.prompt_id, r.model, r.provider, r.state, r.started_at, r.ended_at, r.input_tokens, r.output_tokens, r.cost_usd, r.summary, r.job_id, r.user_login, r.harness, r.reported_model, COALESCE(a.label, r.account_id) AS label, (SELECT COUNT(*) FROM agent_run_tools t WHERE t.run_id = r.id) AS tools`; export const runEvent = (r: { id: number; step: string; prompt_id: string; model: string; provider: string; state: string; started_at: string; ended_at: string | null; input_tokens: number | null; output_tokens: number | null; - cost_usd: number | null; summary: string | null; label: string | null; tools: number; job_id: number | null; user_login?: string | null; harness?: string | null; reported_model?: string | null }): Ev => ({ + cost_usd: number | null; summary: string | null; label: string | null; tools: number; job_id: number | null; user_login?: string | null; harness?: string | null; reported_model?: string | null }, staff = false): Ev => ({ id: `run:${r.id}`, kind: "model-call", at: r.started_at, head: null, actor: model(r.model, "model"), summary: `${PROMPT_TITLES[r.prompt_id] ?? stepTitle(r.step)}: ${r.state === "running" ? "running" : r.state === "failed" ? "failed" : clip(r.summary, 100) || "done"}`, ref: { runId: r.id, ...(r.job_id !== null ? { jobId: r.job_id } : {}) }, - call: { promptId: r.prompt_id, step: stepTitle(r.step), model: r.model, provider: r.provider, account: r.label, state: r.state, inputTokens: r.input_tokens, outputTokens: r.output_tokens, costUsd: r.cost_usd, toolCalls: r.tools, endedAt: r.ended_at, ...(r.user_login && { via: { login: r.user_login, harness: r.harness ?? "", model: r.reported_model ?? "" } }) }, + call: { promptId: r.prompt_id, step: stepTitle(r.step), model: r.model, provider: r.provider, account: r.label, state: r.state, inputTokens: r.input_tokens, outputTokens: r.output_tokens, costUsd: r.cost_usd, toolCalls: r.tools, endedAt: r.ended_at, ...(staff && r.user_login && { via: { login: r.user_login, harness: r.harness ?? "", model: r.reported_model ?? "" } }) }, }); const modelCalls: Source = { kinds: ["model-call"], - run: ({ db, repo, n, hidden }) => rows[0]>(db, + run: ({ db, repo, n, hidden, staff }) => rows[0]>(db, `SELECT ${RUN_COLUMNS} - FROM agent_run_items i JOIN agent_runs r ON r.id = i.run_id LEFT JOIN claude_accounts a ON a.id = r.account_id WHERE i.repo = ? AND i.number = ?${hiddenSql(hidden)}`, repo, n, ...hiddenArgs(hidden)).map(runEvent), + FROM agent_run_items i JOIN agent_runs r ON r.id = i.run_id LEFT JOIN claude_accounts a ON a.id = r.account_id WHERE i.repo = ? AND i.number = ?${hiddenSql(hidden)}`, repo, n, ...hiddenArgs(hidden)).map((r) => runEvent(r, staff)), }; const CHECK_NAMES: Record = { fmt: "Format check", clippy: "Clippy", check: "Build check", test: "Tests" };