mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 18:35:33 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The dashboard is the first page a person sees in a company > - The classic dashboard shows agents, runs, costs and recent tasks > - It does not show what the person is responsible for, or if that work goes well > - People think in areas, such as Fundraising or Customers, and in the things they own in each area > - This pull request adds a dashboard built on areas and responsibilities, behind an experimental setting that is off by default > - The benefit is that a person sees what they own, how it is going, and what agents do for it, on one page ## Linked Issues or Issue Description No public issue exists for this work. The description follows the feature request template. **Subsystem affected** Dashboard, navigation, the task conversation, routines, and the instance experimental settings. **Problem or motivation** The classic dashboard counts agents and tasks. It does not say what a person owns or if it goes well. People who run a company with agents want to see their areas, the responsibilities in each area, the bar each one must meet, and the agents and routines that serve it. **Proposed solution** A person owns responsibilities. Each responsibility belongs to an area and has a bar, a number to reach. Projects, tasks and routines link to a responsibility, and the page shows its status from those links. An agent can interview the person and draft the dashboard. The person accepts or declines each change, and any change can be undone from a saved version. **Alternatives considered** Add the same data to the classic dashboard. That page is a fixed set of cards for company activity, so a second, person-centred page is clearer. The setting lets a person pick one of the two. **Roadmap alignment** This is an experimental feature behind `enableResponsibilities`. It is off by default and changes nothing for a person who leaves it off. ## What Changed - Add the setting "Areas & Responsibilities dashboard" (`enableResponsibilities`, off by default). On, Dashboard in the sidebar opens the new page, and the classic dashboard link is not shown in the sidebars or the command palette. Off, nothing changes. - Add tables and migrations 0492 to 0497 for areas, responsibilities, links to work, metrics, status reports, saved dashboard versions, and model-call records for summaries. - Add the API: areas, responsibilities, links, bars, metrics, status reports, summaries, runs, automation, and the dashboard conversation with versions and undo. Each route checks company access and writes to the activity log. - Add four task conversations with an agent: about a bar, about an automation, about a routine, and about the whole dashboard. The agent proposes a change. Nothing applies until a person accepts it. - Add standing checks: routines that an agent carries out on its heartbeat and reports. - Add the Dashboard page: search, counts, areas that open and close, a primary New area button, and a message box at the bottom of the page. Add the responsibility page with its bar, metrics, work and routines. - Add the Paperclip skill sections and runner API entries that let an agent use these routes. The runner skill inventory is regenerated (166 to 174 rows). - Keep the new runner API tests in their own file so `runner-api.test.ts` stays at 985 lines. - Onboarding is not changed. The onboarding changes that build on this work are a separate pull request. ## Verification - Type checks pass for `packages/db`, `packages/shared`, `server` (all layers) and `ui`. - `pnpm --filter @paperclipai/db check:migrations` passes. A new `drizzle-kit generate` run produces no further change. - Tests for every changed file pass: 26 server test files (3,009 tests), 116 UI test files (1,991 tests) and 28 shared test files (432 tests). - The runner capability inventory checks pass. - I started the app on a local database that already held earlier data. Master's new migrations and these migrations applied without error. With the setting on, the Dashboard and a responsibility page loaded with no console or server errors. The More menu and the command palette show one Dashboard. - I did not run `pnpm verify`, the full local suite, or the browser suites. Required CI covers them. - The agent conversations are tested with simulated agents. No real model has run them. ## Risks - Medium. The change is large, and the setting is off by default. With it off, the new routes refuse requests and the UI is unchanged. - Migrations only add tables and columns. Two replace a CHECK constraint, and one builds an index `CONCURRENTLY`. These two have the `online_compatible` override with a reason in the file, and the second one is listed in `MIGRATIONS_WITH_TOP_LEVEL_STATEMENTS`. - Master can add migrations before this merges. The migrations then need new numbers. - `responsibilities.ts` (1,663 lines), `responsibility-summaries.ts` (1,239 lines) and one Storybook fixture file (1,305 lines) are new files over 1,000 lines. They each keep one cohesive unit together: the service for one table family, the model-call path for summaries, and the fixtures that the stories share. No existing file crosses 1,000 lines. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Anthropic Claude: Claude Fable 5.2 (`claude-fable-5-2`) wrote most of the change, with Claude Sonnet 5.5 (`claude-sonnet-5-5`) for the final steps. Both used tool use, code execution and browser checks. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Scott Tong <scott@scottsmbpm5max.lan> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
219 lines
12 KiB
TypeScript
219 lines
12 KiB
TypeScript
import { PgDialect } from "drizzle-orm/pg-core";
|
|
import { readFileSync } from "node:fs";
|
|
import type { SQL } from "drizzle-orm";
|
|
import type { Db } from "@paperclipai/db";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { readIdleSleepSafety, type IdleSleepDrainStatus } from "../services/idle-sleep-safety.js";
|
|
import { beginIdleTrackedWork } from "../services/task-admission.js";
|
|
|
|
const now = Date.UTC(2026, 10, 2);
|
|
const ownerId = "inventory-owned-hold";
|
|
const hold = (): IdleSleepDrainStatus => ({ ownerId, draining: true, startedAt: new Date(now - 1000),
|
|
expiresAt: new Date(now + 60_000), activeRuns: 0, pendingWakes: 0 });
|
|
const localNone = async () => "none" as const;
|
|
const collect = { collectDiagnostics: true } as const;
|
|
|
|
function database(present: string[] = [], change?: (row: Record<string, unknown>) => unknown,
|
|
schedules?: { routines?: unknown[]; issues?: unknown[] }) {
|
|
let keys: string[] = [];
|
|
const execute = vi.fn(async (statement: SQL) => {
|
|
const query = new PgDialect().sqlToQuery(statement).sql;
|
|
if (query.startsWith("SET LOCAL")) return [];
|
|
if (query.includes("FROM routine_triggers t JOIN routines r")) return schedules?.routines ?? [];
|
|
if (query.includes("FROM issues i JOIN companies c")) return schedules?.issues ?? [];
|
|
if (query.includes("WHERE status NOT IN ('active', 'paused', 'archived')")) return [{ blocked: false }];
|
|
if (query.endsWith(" AS blocked")) return [{ blocked: present.length > 0 }];
|
|
keys = [...query.matchAll(/ AS "([^"]+)"(?=, EXISTS |$)/g)].map(match => match[1]!);
|
|
const row = Object.fromEntries(keys.map(key => [key, present.includes(key)]));
|
|
return change ? change(row) : [row];
|
|
});
|
|
const transaction = vi.fn(async (run: (tx: unknown) => Promise<unknown>) => run({ select: () => ({ from: () => ({ where: async () => [] }) }), execute }));
|
|
return { db: { transaction } as unknown as Db, transaction, execute, keys: () => keys };
|
|
}
|
|
|
|
describe("owned idle sleep diagnostics", () => {
|
|
it("reports simultaneous blockers from every predicate in one safe snapshot", async () => {
|
|
const f = database(["agent_api_keys", "heartbeat_runs", "chat_deliveries", "muse_mailbox_items", "budget_evaluation_work"]);
|
|
const result = await readIdleSleepSafety(f.db, hold, () => now, ownerId, localNone,
|
|
undefined, undefined, false, false, collect);
|
|
expect(result.backgroundWork).toBe("present");
|
|
expect(result.diagnostics?.complete).toBe(true);
|
|
expect(result.diagnostics?.checks.filter(check => check.state === "present").map(check => check.reason))
|
|
.toEqual(["agent_api_keys", "budget_evaluation_work", "chat_deliveries", "heartbeat_runs", "muse_mailbox_items"]);
|
|
expect(f.keys()).toHaveLength(77);
|
|
expect(f.keys()).toEqual(expect.arrayContaining(["mcp_file_tickets", "mcp_authorization_handoffs"]));
|
|
expect(new Set(f.keys()).size).toBe(f.keys().length);
|
|
const inventory = readFileSync(new URL("../../../doc/plans/2026-11-02-sleep-blocker-inventory.md", import.meta.url), "utf8");
|
|
const documented = [...inventory.matchAll(/^\| `([a-z0-9_.]+)` \|/gm)].map(match => match[1]);
|
|
expect(f.keys().filter(key => !documented.includes(key))).toEqual([]);
|
|
expect(f.transaction).toHaveBeenCalledWith(expect.any(Function), { isolationLevel: "repeatable read", accessMode: "read only" });
|
|
expect(f.execute).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("can report each registered predicate independently, including every retained-table family", async () => {
|
|
const active: string[] = [];
|
|
const f = database(active);
|
|
const read = () => readIdleSleepSafety(f.db, hold, () => now, ownerId, localNone,
|
|
undefined, undefined, false, false, collect);
|
|
await read();
|
|
for (const key of f.keys()) {
|
|
active.splice(0, active.length, key);
|
|
const result = await read();
|
|
expect(result.backgroundWork, key).toBe("present");
|
|
expect(result.diagnostics?.checks.filter(check => check.state === "present"), key)
|
|
.toEqual([{ reason: key, state: "present" }]);
|
|
}
|
|
});
|
|
|
|
const routine = { id: "trigger", routine_id: "routine", company_id: "company", kind: "schedule",
|
|
setup_pending: false, cron_expression: "*/15 * * * *", timezone: "UTC", scoped: true,
|
|
next_run_at: new Date(now + 600_000), routine_updated: new Date(now), trigger_updated: new Date(now) };
|
|
const issue = { id: "issue", company_id: "company", status: "backlog", updated_at: new Date(now),
|
|
assignee_agent_id: "agent", assignee_user_id: null, checkout_run_id: null, execution_run_id: null,
|
|
execution_policy: null, execution_state: null, unblock_descriptor: null, conversation_agent_id: null,
|
|
monitor_next_check_at: null, monitor_wake_requested_at: null, monitor_attempt_count: 0,
|
|
company_status: "active", company_updated: new Date(now), agent_status: "idle", agent_updated: new Date(now),
|
|
scoped: true, unsafe_dependencies: false, dependency_ready: false, untouched_onboarding: false,
|
|
response_driven_wait: false, unblock_request_finished: false, response_wait_generation: null };
|
|
const scheduledRead = (f: ReturnType<typeof database>, diagnostics = true) => readIdleSleepSafety(f.db, hold,
|
|
() => now, ownerId, localNone, undefined, undefined, true, true, diagnostics ? collect : undefined);
|
|
|
|
it.each(["routines", "issues"] as const)("marks an overflowing %s inspection unknown without relaxing ordinary eligibility", async family => {
|
|
const f = database([], undefined, { [family]: Array(10_001).fill(family === "routines" ? routine : issue) });
|
|
expect(await scheduledRead(f, false)).toEqual({ version: 1, backgroundWork: "present" });
|
|
const result = await scheduledRead(f);
|
|
expect(result.backgroundWork).toBe("unknown");
|
|
expect(result.diagnostics?.complete).toBe(false);
|
|
expect(result.diagnostics?.checks).toContainEqual({ reason: `${family}.schedule`, state: "unknown" });
|
|
});
|
|
|
|
it.each(["routines", "issues"] as const)("fully inspects a %s catalog at the 10,000-row bound", async family => {
|
|
const f = database([], undefined, { [family]: Array(10_000).fill(family === "routines" ? routine : issue) });
|
|
const result = await scheduledRead(f);
|
|
expect(result.backgroundWork).toBe("none");
|
|
expect(result.diagnostics?.complete).toBe(true);
|
|
expect(result.diagnostics?.checks).toContainEqual({ reason: `${family}.schedule`, state: "none" });
|
|
});
|
|
|
|
it.each(["routines", "issues"] as const)("retains an actual %s blocker as known work", async family => {
|
|
const f = database([], undefined, { [family]: [family === "routines" ? { ...routine, next_run_at: new Date(now) }
|
|
: { ...issue, status: "todo" }] });
|
|
const result = await scheduledRead(f);
|
|
expect(result.backgroundWork).toBe("present");
|
|
expect(result.diagnostics?.complete).toBe(true);
|
|
expect(result.diagnostics?.checks).toContainEqual({ reason: `${family}.schedule`, state: "present" });
|
|
});
|
|
|
|
it.each(["routines", "issues"] as const)("keeps known durable work present alongside an incomplete %s inspection", async family => {
|
|
const f = database(["heartbeat_runs"], undefined, { [family]: Array(10_001).fill(family === "routines" ? routine : issue) });
|
|
const result = await scheduledRead(f);
|
|
expect(result.backgroundWork).toBe("present");
|
|
expect(result.diagnostics?.complete).toBe(false);
|
|
expect(result.diagnostics?.checks).toEqual(expect.arrayContaining([
|
|
{ reason: "heartbeat_runs", state: "present" }, { reason: `${family}.schedule`, state: "unknown" },
|
|
]));
|
|
});
|
|
|
|
it("preserves ordinary local and plugin short circuits and response shape", async () => {
|
|
const f = database();
|
|
const plugins = vi.fn(async () => ({ backgroundWork: "present" as const, pluginIds: [] }));
|
|
expect(await readIdleSleepSafety(f.db, hold, () => now, ownerId, async () => "present", plugins))
|
|
.toEqual({ version: 1, backgroundWork: "present" });
|
|
expect(plugins).not.toHaveBeenCalled();
|
|
expect(f.transaction).not.toHaveBeenCalled();
|
|
expect(await readIdleSleepSafety(f.db, hold, () => now, ownerId, localNone, plugins))
|
|
.toEqual({ version: 1, backgroundWork: "present" });
|
|
expect(f.transaction).not.toHaveBeenCalled();
|
|
expect(await readIdleSleepSafety(f.db, hold, () => now, ownerId, localNone))
|
|
.toEqual({ version: 1, backgroundWork: "none" });
|
|
});
|
|
|
|
it("continues safe inspection after local and plugin blockers without starting a backup", async () => {
|
|
const f = database(["company_secret_proposals"]);
|
|
const backup = vi.fn(async () => true);
|
|
const plugins = vi.fn(async () => ({ backgroundWork: "present" as const, pluginIds: [] }));
|
|
const result = await readIdleSleepSafety(f.db, hold, () => now, ownerId, async record => {
|
|
record?.("local.accounting_spool", "present");
|
|
record?.("local.orphan_spool", "present");
|
|
return "present";
|
|
}, plugins, backup, false, false, collect);
|
|
expect(result.backgroundWork).toBe("present");
|
|
expect(result.diagnostics?.checks).toEqual(expect.arrayContaining([
|
|
{ reason: "company_secret_proposals", state: "present" },
|
|
{ reason: "local.accounting_spool", state: "present" },
|
|
{ reason: "local.orphan_spool", state: "present" },
|
|
{ reason: "plugins.runtime_drain", state: "present" },
|
|
{ reason: "backup.checkpoint", state: "not_checked" },
|
|
]));
|
|
expect(backup).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not run checkpoint actions or treat unperformed actions as quiet", async () => {
|
|
const f = database();
|
|
const backup = vi.fn(async () => true);
|
|
const result = await readIdleSleepSafety(f.db, hold, () => now, ownerId, localNone,
|
|
undefined, backup, false, false, collect);
|
|
expect(result.backgroundWork).toBe("unknown");
|
|
expect(result.diagnostics?.complete).toBe(true);
|
|
expect(result.diagnostics?.checks).toContainEqual({ reason: "backup.checkpoint", state: "not_checked" });
|
|
expect(backup).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it.each([undefined, "wrong-owner"])("never opens the DB for diagnostic owner %s", async owner => {
|
|
const f = database();
|
|
const result = await readIdleSleepSafety(f.db, hold, () => now, owner, localNone,
|
|
undefined, undefined, false, false, collect);
|
|
expect(result.backgroundWork).toBe("unknown");
|
|
expect(result.diagnostics?.complete).toBe(false);
|
|
expect(f.transaction).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("skips unsafe plugin RPCs while accepted local work is active", async () => {
|
|
const f = database();
|
|
const plugins = vi.fn();
|
|
const finish = beginIdleTrackedWork();
|
|
try {
|
|
const result = await readIdleSleepSafety(f.db, hold, () => now, ownerId, async () => "present",
|
|
plugins, undefined, false, false, collect);
|
|
expect(result.backgroundWork).toBe("unknown");
|
|
expect(result.diagnostics?.complete).toBe(false);
|
|
expect(result.diagnostics?.checks).toContainEqual({ reason: "plugins.runtime_drain", state: "not_checked" });
|
|
expect(plugins).not.toHaveBeenCalled();
|
|
} finally { finish(); }
|
|
});
|
|
|
|
it.each(["owner", "expiry", "generation"])("invalidates the observation after changed %s", async changed => {
|
|
const f = database();
|
|
let current = hold();
|
|
let clock = now;
|
|
let reads = 0;
|
|
const result = await readIdleSleepSafety(f.db, () => current, () => clock, ownerId, async () => {
|
|
if (++reads === 2) {
|
|
if (changed === "owner") current = { ...current, ownerId: "replacement" };
|
|
if (changed === "expiry") clock += 60_001;
|
|
if (changed === "generation") { const finish = beginIdleTrackedWork(); finish(); }
|
|
}
|
|
return "none";
|
|
}, undefined, undefined, false, false, collect);
|
|
expect(result.backgroundWork).toBe("unknown");
|
|
expect(result.diagnostics?.complete).toBe(false);
|
|
});
|
|
|
|
it.each([
|
|
(row: Record<string, unknown>) => [{ ...row, heartbeat_runs: "false" }],
|
|
(row: Record<string, unknown>) => [{ ...row, extra_private_field: "sensitive" }],
|
|
(row: Record<string, unknown>) => { delete row.heartbeat_runs; return [row]; },
|
|
() => [],
|
|
(row: Record<string, unknown>) => [row, row],
|
|
() => { throw new Error("private SQL, credential, spool path"); },
|
|
])("fails closed and redacts malformed/unavailable durable reads", async change => {
|
|
const f = database([], change);
|
|
const result = await readIdleSleepSafety(f.db, hold, () => now, ownerId, localNone,
|
|
undefined, undefined, false, false, collect);
|
|
expect(result.backgroundWork).toBe("unknown");
|
|
expect(result.diagnostics?.complete).toBe(false);
|
|
expect(result.diagnostics?.checks).toContainEqual({ reason: "durable.snapshot", state: "unknown" });
|
|
expect(JSON.stringify(result)).not.toMatch(/sensitive|private SQL|credential,|extra_private/);
|
|
});
|
|
});
|