mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 11:40:00 +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>
214 lines
9.4 KiB
TypeScript
214 lines
9.4 KiB
TypeScript
import { z } from "zod";
|
|
|
|
/**
|
|
* Agent-written status for a responsibility (experimental,
|
|
* `enableResponsibilities`). Besides the status the server derives from the
|
|
* number, a responsibility can carry a status that an agent wrote: behind, at
|
|
* risk or on track (or that it cannot tell yet), one plain line saying why,
|
|
* optionally a little detail, who wrote it and when. Each report is kept; the
|
|
* newest is current. A person may correct it; the record then says a person
|
|
* wrote it.
|
|
*
|
|
* The rules live here, pure, so the server, the agent's prompt and the views
|
|
* agree on them: who the reporter is, what a report may say, and when it is
|
|
* out of date.
|
|
*/
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// What a report says
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** `unknown`: the agent looked and cannot tell yet. */
|
|
export const RESPONSIBILITY_STATUS_REPORT_STATUSES = ["behind", "at_risk", "on_track", "unknown"] as const;
|
|
export type ResponsibilityStatusReportStatus = (typeof RESPONSIBILITY_STATUS_REPORT_STATUSES)[number];
|
|
|
|
export const RESPONSIBILITY_STATUS_REPORT_LABEL: Record<ResponsibilityStatusReportStatus, string> = {
|
|
behind: "Behind",
|
|
at_risk: "At risk",
|
|
on_track: "On track",
|
|
unknown: "Can't tell yet",
|
|
};
|
|
|
|
/** A report older than this many days reads as out of date (it is still shown). */
|
|
export const RESPONSIBILITY_STATUS_REPORT_FRESH_DAYS = 7;
|
|
/** Past reports one read returns, newest first. */
|
|
export const RESPONSIBILITY_STATUS_REPORT_HISTORY_LIMIT = 10;
|
|
export const RESPONSIBILITY_STATUS_REPORT_MESSAGE_MAX = 200;
|
|
export const RESPONSIBILITY_STATUS_REPORT_DETAIL_MAX = 800;
|
|
|
|
const DAY_MS = 86_400_000;
|
|
|
|
const MARKUP = /(^#{1,6}\s)|(\*\*)|(\[[^\]]*\]\([^)]*\))|(`)/;
|
|
|
|
function statusWordsOnly(text: string) {
|
|
const plain = text.toLowerCase().replace(/[^a-z ]/g, "").replace(/\s+/g, " ").trim();
|
|
return ["behind", "at risk", "on track", "unknown", "cant tell yet", "ok", "fine", "good", "bad"].includes(plain);
|
|
}
|
|
|
|
/**
|
|
* The body of a report, whoever writes it. The author is never in the body:
|
|
* the server records the agent or person who sent it.
|
|
*/
|
|
export const writeResponsibilityStatusReportSchema = z
|
|
.object({
|
|
status: z.enum(RESPONSIBILITY_STATUS_REPORT_STATUSES),
|
|
/** One plain line saying why: "Drifted from 2.1 s to 2.4 s as the catalogue grew." */
|
|
message: z.string().trim().min(3).max(RESPONSIBILITY_STATUS_REPORT_MESSAGE_MAX),
|
|
/** Optional: a couple more sentences of detail. */
|
|
detail: z.string().trim().min(1).max(RESPONSIBILITY_STATUS_REPORT_DETAIL_MAX).optional().nullable(),
|
|
})
|
|
.strict()
|
|
.superRefine((value, ctx) => {
|
|
if (/[\r\n]/.test(value.message)) {
|
|
ctx.addIssue({ code: "custom", path: ["message"], message: "Keep the message to one line; put anything more in detail" });
|
|
}
|
|
if (MARKUP.test(value.message)) {
|
|
ctx.addIssue({ code: "custom", path: ["message"], message: "Write the message as plain words, without markdown" });
|
|
}
|
|
if (statusWordsOnly(value.message)) {
|
|
ctx.addIssue({ code: "custom", path: ["message"], message: "Say why, not only the status: what moved, and what it depends on" });
|
|
}
|
|
if (value.detail && value.detail.split(/\r?\n/).filter((line) => line.trim()).length > 4) {
|
|
ctx.addIssue({ code: "custom", path: ["detail"], message: "Keep the detail to a few sentences" });
|
|
}
|
|
});
|
|
export type WriteResponsibilityStatusReport = z.infer<typeof writeResponsibilityStatusReportSchema>;
|
|
|
|
/** The owner asks the reporter for an update. Nothing to send: the server picks the reporter. */
|
|
export const requestResponsibilityStatusUpdateSchema = z.object({}).strict();
|
|
export type RequestResponsibilityStatusUpdate = z.infer<typeof requestResponsibilityStatusUpdateSchema>;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// What the reads return
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** One report. Exactly one of `agentId` and `userId` is set, or neither once the agent is deleted. */
|
|
export interface ResponsibilityStatusReportEntry {
|
|
status: ResponsibilityStatusReportStatus;
|
|
message: string;
|
|
agentId: string | null;
|
|
userId: string | null;
|
|
/** ISO time it was written. */
|
|
writtenAt: string;
|
|
}
|
|
|
|
export interface ResponsibilityStatusReportCurrent extends ResponsibilityStatusReportEntry {
|
|
detail: string | null;
|
|
/** Older than `RESPONSIBILITY_STATUS_REPORT_FRESH_DAYS`. */
|
|
outOfDate: boolean;
|
|
}
|
|
|
|
/**
|
|
* `GET /api/responsibilities/:id/status-report` and
|
|
* `POST /api/responsibilities/:id/status-report/request`.
|
|
*/
|
|
export interface ResponsibilityStatusReportState {
|
|
current: ResponsibilityStatusReportCurrent | null;
|
|
/** The agent with the best total view of it (see `chooseResponsibilityReporter`); null when the company has no agent that can take work. */
|
|
reporterAgentId: string | null;
|
|
/** The owner asked the reporter for an update and no report has come since. */
|
|
updateRequested: boolean;
|
|
/** Newest first, at most `RESPONSIBILITY_STATUS_REPORT_HISTORY_LIMIT`, the current one included. */
|
|
history: ResponsibilityStatusReportEntry[];
|
|
}
|
|
|
|
/** Why the reporter is who it is. */
|
|
export type ResponsibilityReporterBasis = "works_under" | "top_agent" | "first_agent";
|
|
|
|
export interface ResponsibilityStatusReportSummary {
|
|
responsibilityId: string;
|
|
current: ResponsibilityStatusReportCurrent | null;
|
|
reporterAgentId: string | null;
|
|
reporterBasis: ResponsibilityReporterBasis | null;
|
|
updateRequested: boolean;
|
|
}
|
|
|
|
/** `GET /api/companies/:companyId/responsibilities/status-reports`: every active responsibility of the owner, in one read. */
|
|
export interface ResponsibilityStatusReportsOverview {
|
|
ownerUserId: string;
|
|
freshDays: number;
|
|
reports: ResponsibilityStatusReportSummary[];
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Freshness
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** True when the report is older than `days` (default `RESPONSIBILITY_STATUS_REPORT_FRESH_DAYS`). */
|
|
export function responsibilityStatusReportOutOfDate(
|
|
writtenAt: Date | string,
|
|
now: Date,
|
|
days: number = RESPONSIBILITY_STATUS_REPORT_FRESH_DAYS,
|
|
): boolean {
|
|
return now.getTime() - new Date(writtenAt).getTime() > days * DAY_MS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// The reporter rule
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** One agent's work under a responsibility: directly, or through a linked project. */
|
|
export interface ResponsibilityReporterCandidate {
|
|
agentId: string;
|
|
/** Open tasks under it assigned to the agent. */
|
|
openTasks: number;
|
|
/** Routines under it (not archived) assigned to the agent. */
|
|
routines: number;
|
|
/** Unfinished linked projects the agent leads. */
|
|
ledProjects: number;
|
|
/** The agent runs the responsibility (`runByAgentId`). */
|
|
runsIt: boolean;
|
|
/** The latest update of any of that work. */
|
|
lastActivityAt: Date | string | null;
|
|
}
|
|
|
|
export interface ResponsibilityReporterAgent {
|
|
id: string;
|
|
role: string | null;
|
|
reportsTo: string | null;
|
|
createdAt: Date | string;
|
|
/** Assignable and not paused, terminated or awaiting approval. */
|
|
canTakeWork: boolean;
|
|
}
|
|
|
|
/** How much an agent does under a responsibility: each open task, routine and led project counts one; running it counts one more. */
|
|
export function responsibilityReporterScore(candidate: Omit<ResponsibilityReporterCandidate, "agentId" | "lastActivityAt">): number {
|
|
return Math.max(0, candidate.openTasks) + Math.max(0, candidate.routines) + Math.max(0, candidate.ledProjects) + (candidate.runsIt ? 1 : 0);
|
|
}
|
|
|
|
function time(value: Date | string | null) {
|
|
return value === null ? Number.NEGATIVE_INFINITY : new Date(value).getTime();
|
|
}
|
|
|
|
/**
|
|
* The agent with the best total view of a responsibility, who writes its
|
|
* status:
|
|
* 1. Of the agents that can take work, the one doing the most under it
|
|
* (`responsibilityReporterScore`), ties broken by the most recent activity
|
|
* there, then by running it, then by who was created first.
|
|
* 2. When no such agent works under it: the organization's top agent (a CEO
|
|
* reporting to nobody, else the first-created agent reporting to nobody).
|
|
* 3. Else the first-created agent that can take work. Null when there is none.
|
|
*/
|
|
export function chooseResponsibilityReporter(
|
|
candidates: readonly ResponsibilityReporterCandidate[],
|
|
agents: readonly ResponsibilityReporterAgent[],
|
|
): { agentId: string; basis: ResponsibilityReporterBasis } | null {
|
|
const usable = [...agents]
|
|
.filter((agent) => agent.canTakeWork)
|
|
.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() || a.id.localeCompare(b.id));
|
|
if (usable.length === 0) return null;
|
|
const order = new Map(usable.map((agent, index) => [agent.id, index]));
|
|
const working = candidates
|
|
.filter((candidate) => order.has(candidate.agentId) && responsibilityReporterScore(candidate) > 0)
|
|
.sort((a, b) =>
|
|
responsibilityReporterScore(b) - responsibilityReporterScore(a)
|
|
|| time(b.lastActivityAt) - time(a.lastActivityAt)
|
|
|| Number(b.runsIt) - Number(a.runsIt)
|
|
|| order.get(a.agentId)! - order.get(b.agentId)!);
|
|
if (working[0]) return { agentId: working[0].agentId, basis: "works_under" };
|
|
const top = usable.find((agent) => agent.role === "ceo" && !agent.reportsTo) ?? usable.find((agent) => !agent.reportsTo);
|
|
if (top) return { agentId: top.id, basis: "top_agent" };
|
|
return { agentId: usable[0]!.id, basis: "first_agent" };
|
|
}
|