Files
PaperClipAI/ui/src/lib/responsibility-automation.test.ts
T
43b2d8be22 feat(dashboard): add an experimental areas and responsibilities dashboard (#22069)
## 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>
2026-11-17 20:45:44 -08:00

201 lines
11 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from "vitest";
import {
automationFixture,
automationItemFixture,
automationOverviewFixture,
candidateFixture,
denseAutomationFixture,
denseBoardOverviewFixture,
homeAutomationFixture,
homeOverviewFixture,
RESPONSIBILITY_FIXTURE_NOW,
webhookStartFixture,
} from "../../storybook/fixtures/responsibilities";
import {
automationAreaGroups,
automationCountsLine,
automationLevelCounts,
automationSentence,
automationShareLabel,
automationStartWords,
candidateReasonWords,
conversationButtonLabel,
describeCheckAge,
noCandidatesWords,
readDismissedCandidates,
remainingCandidateCount,
stalledWords,
visibleCandidates,
writeDismissedCandidates,
} from "./responsibility-automation";
const names: Record<string, string> = { "agent-codex": "CodexCoder", "agent-qa": "QA" };
const agentName = (id: string) => names[id];
const now = RESPONSIBILITY_FIXTURE_NOW;
afterEach(() => {
localStorage.clear();
vi.restoreAllMocks();
});
describe("the Automation view's words", () => {
it("puts the counts and the share in words", () => {
expect(automationShareLabel(null)).toBeNull();
expect(automationShareLabel(0.4)).toBe("40% automated");
expect(automationCountsLine({ automationCount: 1, manualTaskCount: 1, nothingFiled: false })).toBe("1 automation · 1 manual task");
expect(automationCountsLine({ automationCount: 2, manualTaskCount: 5, nothingFiled: false })).toBe("2 automations · 5 manual tasks");
expect(automationCountsLine({ automationCount: 0, manualTaskCount: 0, nothingFiled: true })).toBe("Nothing is filed under this yet.");
expect(automationCountsLine({ automationCount: 0, manualTaskCount: 0, nothingFiled: false })).toBe("No automations and no recent manual tasks.");
});
it.each([
[{ total: 20, manual: 9, candidates: 14 }, "9 of your 20 responsibilities have nothing automated yet; 14 manual tasks could be automated."],
[{ total: 5, manual: 1, candidates: 1 }, "1 of your 5 responsibilities has nothing automated yet; 1 manual task could be automated."],
[{ total: 3, manual: 3, candidates: 0 }, "None of your 3 responsibilities has anything automated yet."],
[{ total: 1, manual: 1, candidates: 2 }, "Your responsibility has nothing automated yet; 2 manual tasks could be automated."],
[{ total: 4, manual: 0, candidates: 3 }, "Every responsibility you own has something automated; 3 manual tasks could be automated."],
[{ total: 4, manual: 0, candidates: 0 }, "Everything you own is automated."],
[{ total: 0, manual: 0, candidates: 0 }, "You do not own any responsibilities yet."],
])("overall: %o", (input, sentence) => {
expect(automationSentence(input)).toBe(sentence);
});
it("says how each automation starts, who runs it and what happened last", () => {
expect(automationStartWords(automationItemFixture({ id: "a", title: "A" }), now)).toEqual({
kind: "schedule", label: "On a schedule", detail: "Every Monday at 9 AM", status: null,
});
expect(automationStartWords(automationItemFixture({ id: "b", title: "B", start: webhookStartFixture }), now)).toMatchObject({
kind: "webhook", label: "From a webhook", detail: "when another system calls it", status: "Last called yesterday",
});
expect(automationStartWords(automationItemFixture({ id: "c", title: "C", assigneeAgentId: "agent-qa", start: { kind: "standing_check", lastResult: null } }), now))
.toMatchObject({ kind: "standing_check", label: "Standing check", detail: "on each wake-up", status: "Not checked yet" });
const acted = automationStartWords(automationItemFixture({
id: "d", title: "D", start: { kind: "standing_check", lastResult: { checkedAt: new Date(now.getTime() - 2 * 3_600_000).toISOString(), outcome: "acted", note: "Nudged two owners", issue: null } },
}), now);
expect(acted.status).toBe("Last checked 2 hours ago: acted (Nudged two owners)");
expect(automationStartWords(automationItemFixture({ id: "e", title: "E", start: { kind: "on_request" } }), now)).toMatchObject({ label: "On request" });
expect(describeCheckAge(now, now)).toBe("just now");
expect(describeCheckAge(new Date(now.getTime() - 5 * 60_000), now)).toBe("5 minutes ago");
});
it("says why an automation is not running", () => {
expect(stalledWords({ reason: "paused", assigneeAgentId: "agent-codex" }, agentName)).toBe("Paused");
expect(stalledWords({ reason: "no_agent", assigneeAgentId: null }, agentName)).toBe("No agent to run it");
expect(stalledWords({ reason: "no_wakeups", assigneeAgentId: "agent-qa" }, agentName)).toBe("Not running: QA doesn’t wake up on its own (heartbeat off)");
});
it("says why a task is listed, and labels the primary action with the agent", () => {
const done = candidateFixture({ issueId: "t", title: "Call the bank", status: "done", assigneeAgentId: "agent-codex", completedAt: "2026-11-10T12:00:00Z" });
expect(done.hint).toBeNull();
expect(candidateReasonWords(done, agentName, now)).toBe("Done by CodexCoder 3 days ago");
expect(candidateReasonWords({ ...done, reason: "done", assigneeAgentId: null }, agentName, now)).toBe("Done by hand 3 days ago");
expect(candidateReasonWords({ ...done, reason: "with_agent", status: "in_progress" }, agentName, now)).toBe("With CodexCoder now");
expect(candidateReasonWords({ ...done, reason: "open" }, agentName, now)).toBeNull();
const hinted = candidateFixture({ issueId: "h", title: "Triage new support tickets" });
expect(hinted).toMatchObject({ reason: "hint", hint: { trigger: "webhook" } });
expect(candidateReasonWords(hinted, agentName, now)).toBe(hinted.hint!.why);
expect(conversationButtonLabel({ responsibleAgentId: "agent-codex", conversation: null }, agentName)).toBe("Automate with CodexCoder");
expect(conversationButtonLabel({ responsibleAgentId: "agent-codex", conversation: { issueId: "c", identifier: null, agentId: "agent-codex", state: "discussing" } }, agentName)).toBe("Continue with CodexCoder");
expect(conversationButtonLabel({ responsibleAgentId: "agent-codex", conversation: { issueId: "c", identifier: null, agentId: "agent-codex", state: "proposal_waiting" } }, agentName)).toBe("Review CodexCoder’s proposal");
});
it("says something true when nothing is left to suggest", () => {
expect(noCandidatesWords({ automationCount: 2, manualTaskCount: 0, nothingFiled: false })).toBe("The automations are covering the work.");
expect(noCandidatesWords({ automationCount: 0, manualTaskCount: 0, nothingFiled: false })).toBe("No recent manual tasks to automate.");
expect(noCandidatesWords({ automationCount: 1, manualTaskCount: 3, nothingFiled: false })).toBe("Nothing else here looks worth automating.");
expect(noCandidatesWords({ automationCount: 0, manualTaskCount: 0, nothingFiled: true })).toBeNull();
});
});
describe("placing the rows", () => {
it("groups by area like the Board, the most manual first within each", () => {
const groups = automationAreaGroups(homeOverviewFixture.areas, homeOverviewFixture.responsibilities, homeAutomationFixture);
expect(groups.map((group) => [group.area?.title ?? null, group.automationShare, group.items.map((item) => item.id)])).toEqual([
["Fundraising", "14% automated", ["resp-lp-updates", "resp-fundraising"]],
["Portfolio", "100% automated", ["resp-portfolio"]],
["Team", null, ["resp-hiring"]],
[null, "67% automated", ["resp-board-reporting"]],
]);
expect(automationLevelCounts(homeOverviewFixture.responsibilities, homeAutomationFixture)).toEqual({
manual: 2, some_automated: 1, mostly_automated: 1, automated: 1,
});
});
it("filters to the chosen levels and drops empty areas", () => {
const groups = automationAreaGroups(homeOverviewFixture.areas, homeOverviewFixture.responsibilities, homeAutomationFixture, new Set(["manual"]));
expect(groups.map((group) => [group.area?.title ?? null, group.items.map((item) => item.id)])).toEqual([
["Fundraising", ["resp-lp-updates"]],
["Team", ["resp-hiring"]],
]);
});
it("counts a responsibility the read does not cover yet as manual", () => {
const read = automationOverviewFixture([]);
const groups = automationAreaGroups(homeOverviewFixture.areas, homeOverviewFixture.responsibilities, read, new Set(["manual"]));
expect(groups.flatMap((group) => group.items)).toHaveLength(5);
});
it("covers every level in the dense fixture", () => {
const counts = automationLevelCounts(denseBoardOverviewFixture.responsibilities, denseAutomationFixture);
expect(Object.values(counts).every((value) => value > 0)).toBe(true);
expect(Object.values(counts).reduce((sum, value) => sum + value, 0)).toBe(denseBoardOverviewFixture.responsibilities.length);
});
});
describe("which manual tasks a row shows", () => {
const automation = automationFixture({
responsibilityId: "r",
areaId: null,
runningCount: 1,
manual: 8,
candidates: [
candidateFixture({ issueId: "plain-1", title: "Call the bank" }),
candidateFixture({ issueId: "weekly", title: "Weekly pipeline review" }),
candidateFixture({ issueId: "tickets", title: "Triage new support tickets" }),
candidateFixture({ issueId: "plain-2", title: "Clean up the drive" }),
candidateFixture({ issueId: "invoices", title: "Follow up on overdue invoices" }),
candidateFixture({ issueId: "report", title: "Prepare the board report" }),
],
});
it("shows tasks with a hint first, keeps the rest reachable, and counts what the read only counted", () => {
expect(visibleCandidates(automation, new Set())).toMatchObject({
shown: [{ issueId: "weekly" }, { issueId: "tickets" }, { issueId: "invoices" }],
others: [{ issueId: "plain-1" }, { issueId: "plain-2" }, { issueId: "report" }],
unlisted: 2,
more: 5,
});
expect(visibleCandidates(automation, new Set(["weekly"]))).toMatchObject({
shown: [{ issueId: "tickets" }, { issueId: "invoices" }, { issueId: "report" }],
more: 4,
});
expect(remainingCandidateCount(automationOverviewFixture([automation]), new Set(["weekly", "tickets"]))).toBe(6);
});
it("offers the first task to work out with the agent when none has a hint", () => {
const plain = automationFixture({
responsibilityId: "p", areaId: null,
candidates: [candidateFixture({ issueId: "a", title: "Call the bank" }), candidateFixture({ issueId: "b", title: "Clean up the drive" })],
});
expect(visibleCandidates(plain, new Set())).toMatchObject({ shown: [{ issueId: "a" }], others: [{ issueId: "b" }], unlisted: 0, more: 1 });
});
it("remembers dismissals per company, and works without storage", () => {
writeDismissedCandidates("company-a", new Set(["x", "y"]));
expect([...readDismissedCandidates("company-a")]).toEqual(["x", "y"]);
expect(readDismissedCandidates("company-b").size).toBe(0);
localStorage.setItem("paperclip:responsibilities:automation-dismissed:company-c", "not json");
expect(readDismissedCandidates("company-c").size).toBe(0);
vi.spyOn(Storage.prototype, "getItem").mockImplementation(() => {
throw new Error("blocked");
});
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
throw new Error("blocked");
});
expect(() => writeDismissedCandidates("company-a", new Set(["z"]))).not.toThrow();
expect(readDismissedCandidates("company-a").size).toBe(0);
});
});