Files
PaperClipAI/ui/src/lib/responsibility-agent-status.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

137 lines
7.3 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.
import { describe, expect, it } from "vitest";
import {
ALL_FIXTURE_AREAS,
fundraisingBehind,
homeOverviewFixture,
metricFixture,
RESPONSIBILITY_FIXTURE_OWNER_ID,
} from "../../storybook/fixtures/responsibilities";
import {
allFreshStatusReportsFixture,
denseAgentStatusOverviewFixture,
denseStatusReportsFixture,
mixedStatusReportsFixture,
noneWrittenStatusReportsFixture,
} from "../../storybook/fixtures/responsibility-status-reports";
import {
agentStatusAreaGroups,
agentStatusMetricCell,
agentStatusRows,
agentStatusTiles,
areaStatusKind,
composeAgentStatusSummary,
} from "./responsibility-agent-status";
const names: Record<string, string> = { "agent-codex": "CodexCoder", "agent-cto": "CTO", "agent-qa": "QA" };
const agentName = (id: string) => names[id];
const rows = (reports = mixedStatusReportsFixture) => agentStatusRows(homeOverviewFixture.responsibilities, reports);
const byId = (id: string, reports = mixedStatusReportsFixture) => rows(reports).find((row) => row.responsibility.id === id)!;
describe("a row's status", () => {
it("uses the agent's report when there is one", () => {
expect(byId("resp-fundraising")).toMatchObject({ kind: "behind", label: "Behind", source: "agent", authorAgentId: "agent-codex", outOfDate: false });
});
it("keeps an out-of-date report, marked", () => {
expect(byId("resp-lp-updates")).toMatchObject({ kind: "at_risk", source: "agent", outOfDate: true });
});
it("says when a person wrote it", () => {
expect(byId("resp-board-reporting")).toMatchObject({ source: "person", authorUserId: RESPONSIBILITY_FIXTURE_OWNER_ID, authorAgentId: null });
});
it("falls back to the number, saying so, with whose view it waits for", () => {
expect(byId("resp-hiring")).toMatchObject({
kind: "unclear", label: "Not measured", source: "number", reporterAgentId: "agent-cto", updateRequested: true,
message: homeOverviewFixture.responsibilities.find((item) => item.id === "resp-hiring")!.rollup.statusSentence,
});
});
it("reads an agent's 'cannot tell yet' as unclear", () => {
expect(byId("resp-hiring", allFreshStatusReportsFixture)).toMatchObject({ kind: "unclear", label: "Can't tell yet", source: "agent" });
});
});
describe("the four numbers", () => {
it("count each responsibility by the status it shows, and say where those come from", () => {
const tiles = agentStatusTiles(rows());
expect(tiles.tiles.map((tile) => [tile.label, tile.value, tile.line])).toEqual([
["On track", 1, "Of 5 responsibilities"],
["At risk", 2, "In 2 areas"],
["Behind", 1, "In 1 area"],
["Unclear", 1, "1 not measured"],
]);
expect(tiles.provenance).toBe("3 written by agents · 1 out of date · 1 written by a person · 1 from the number");
});
it("read sensibly with nothing written", () => {
const tiles = agentStatusTiles(rows(noneWrittenStatusReportsFixture));
expect(tiles.byAgent).toBe(0);
expect(tiles.provenance).toBe("0 written by agents · 5 from the numbers");
});
});
describe("the summary", () => {
it("leads with how much is written, then the most concerning messages, attributed, then whose update is awaited", () => {
const summary = composeAgentStatusSummary(rows(), agentName, RESPONSIBILITY_FIXTURE_OWNER_ID);
expect(summary.lead).toBe("4 of your 5 statuses are written; the rest come from the numbers. They put 1 behind and 2 at risk. 1 is older than 7 days.");
expect(summary.lines.map((line) => [line.row.responsibility.title, line.by])).toEqual([
["Seed extension", "CodexCoder"],
["Board reporting", "You"],
["LP updates", "CTO"],
]);
expect(summary.waiting).toBe("CTO, for 1 update");
});
it("says plainly when no agent has written anything", () => {
expect(composeAgentStatusSummary(rows(noneWrittenStatusReportsFixture), agentName, null)).toEqual({
lead: "No agent has written a status yet. Every status below comes from the numbers.",
lines: [],
waiting: null,
});
});
it("says when everything is written and nothing is wrong", () => {
const fresh = rows(allFreshStatusReportsFixture).filter((row) => row.kind === "on_track");
expect(composeAgentStatusSummary(fresh, agentName, null).lead).toBe("All 2 of your statuses are written. None of the written ones is behind or at risk.");
});
});
describe("areas", () => {
it("give each area its worst status, its most concerning line, the share on track and who reports there", () => {
const groups = agentStatusAreaGroups(ALL_FIXTURE_AREAS, rows(), agentName, RESPONSIBILITY_FIXTURE_OWNER_ID);
const fundraising = groups.find((group) => group.area?.id === "area-fundraising")!;
expect(fundraising.kind).toBe("behind");
expect(fundraising.headline).toEqual({ text: "Nine of twenty contacted, and the deck the rest are waiting for is three days late.", by: "CodexCoder", fromNumber: false });
expect(fundraising.onTrackLabel).toBe("0 of 2 responsibilities on track");
expect(fundraising.agentIds).toEqual(["agent-codex", "agent-cto"]);
const team = groups.find((group) => group.area?.id === "area-team")!;
expect(team).toMatchObject({ kind: "unclear", headline: { by: null, fromNumber: true } });
const loose = groups.at(-1)!;
expect(loose.area).toBeNull();
expect(loose.rows.map((row) => row.responsibility.id)).toEqual(["resp-board-reporting"]);
});
it("is unclear only when nothing in it has a clearer status", () => {
expect(areaStatusKind([{ kind: "unclear" }, { kind: "on_track" }])).toBe("on_track");
expect(areaStatusKind([{ kind: "unclear" }])).toBe("unclear");
expect(areaStatusKind([])).toBeNull();
});
it("holds 46 responsibilities across 22 areas", () => {
const dense = agentStatusRows(denseAgentStatusOverviewFixture.responsibilities, denseStatusReportsFixture);
const groups = agentStatusAreaGroups(denseAgentStatusOverviewFixture.areas, dense, agentName, null);
expect(dense).toHaveLength(46);
expect(groups).toHaveLength(22);
expect(groups.every((group) => group.rows.length >= 2)).toBe(true);
});
});
describe("the metric column", () => {
it("reads every bar template through the shared helper", () => {
expect(agentStatusMetricCell(metricFixture({ name: "LCP p75", unit: "s", target: 2, current: 2.4, direction: "at_most" })))
.toEqual({ label: "LCP p75", value: "2.4 s", target: "target at most 2 s" });
expect(agentStatusMetricCell(metricFixture({ name: "Investors contacted", target: 20, current: 9 })))
.toEqual({ label: "Investors contacted", value: "9", target: "target 20" });
expect(agentStatusMetricCell(metricFixture({ kind: "range", name: "Runway", unit: "months", target: null, low: 12, high: 24, current: 10 })))
.toEqual({ label: "Runway", value: "10 months", target: "range 12–24 months" });
expect(agentStatusMetricCell(metricFixture({ kind: "yes_no", name: "Board pack sent a week ahead", target: null, current: 1 })))
.toEqual({ label: "Board pack sent a week ahead", value: "Yes", target: "should be yes" });
expect(agentStatusMetricCell(metricFixture({ name: "Investors contacted", target: 20, current: null })))
.toEqual({ label: "Investors contacted", value: "No reading yet", target: "target 20" });
expect(agentStatusMetricCell(fundraisingBehind.rollup.metric)?.label).toBe("Investors contacted");
expect(agentStatusMetricCell(null)).toBeNull();
});
});