mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 09:50:48 +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>
221 lines
9.6 KiB
TypeScript
221 lines
9.6 KiB
TypeScript
import { and, asc, desc, eq } from "drizzle-orm";
|
|
import type { Db } from "@paperclipai/db";
|
|
import { companies, issues, responsibilities, responsibilityStatusReports } from "@paperclipai/db";
|
|
import {
|
|
RESPONSIBILITY_STATUS_REPORT_FRESH_DAYS,
|
|
RESPONSIBILITY_STATUS_REPORT_HISTORY_LIMIT,
|
|
RESPONSIBILITY_STATUS_UPDATE_ORIGIN_KIND,
|
|
responsibilityStatusReportOutOfDate,
|
|
writeResponsibilityStatusReportSchema,
|
|
type ResponsibilityStatusReportCurrent,
|
|
type ResponsibilityStatusReportEntry,
|
|
type ResponsibilityStatusReportState,
|
|
type ResponsibilityStatusReportStatus,
|
|
type ResponsibilityStatusReportsOverview,
|
|
type WriteResponsibilityStatusReport,
|
|
} from "@paperclipai/shared";
|
|
import { conflict, forbidden, notFound, unprocessable } from "../errors.js";
|
|
import type { AuthorizationActor } from "./authorization.js";
|
|
import { instanceSettingsService } from "./instance-settings.js";
|
|
import { issueService } from "./issues.js";
|
|
import {
|
|
agentWorksUnderResponsibility,
|
|
loadLatestStatusReports,
|
|
loadOpenStatusUpdateRequests,
|
|
loadResponsibilityReporters,
|
|
updateStillRequested,
|
|
type StatusReportRow,
|
|
} from "./responsibility-status-reporter.js";
|
|
|
|
type ResponsibilityRow = typeof responsibilities.$inferSelect;
|
|
type IssueRow = typeof issues.$inferSelect;
|
|
|
|
/** Who writes a report. The server sets it from the caller; it is never read from the body. */
|
|
export type StatusReportAuthor = { type: "agent"; agentId: string } | { type: "user"; userId: string };
|
|
|
|
function entry(row: StatusReportRow): ResponsibilityStatusReportEntry {
|
|
return {
|
|
status: row.status as ResponsibilityStatusReportStatus,
|
|
message: row.message,
|
|
agentId: row.agentId,
|
|
userId: row.userId,
|
|
writtenAt: row.createdAt.toISOString(),
|
|
};
|
|
}
|
|
|
|
function current(row: StatusReportRow | undefined, now: Date): ResponsibilityStatusReportCurrent | null {
|
|
if (!row) return null;
|
|
return { ...entry(row), detail: row.detail, outOfDate: responsibilityStatusReportOutOfDate(row.createdAt, now) };
|
|
}
|
|
|
|
/**
|
|
* Agent-written status for responsibilities (experimental
|
|
* `enableResponsibilities`): the reads (one responsibility, and every active
|
|
* responsibility of an owner in a fixed number of queries), writing a report
|
|
* (the routes check who may), and the owner asking the reporter for an update,
|
|
* which opens a small task for the reporter (origin
|
|
* `responsibility_status_update`, origin id = the responsibility). The
|
|
* reporter rule is `chooseResponsibilityReporter` in packages/shared.
|
|
*/
|
|
export function responsibilityStatusReportService(db: Db) {
|
|
const settings = instanceSettingsService(db);
|
|
const issuesSvc = issueService(db);
|
|
|
|
async function assertEnabled() {
|
|
const experimental = await settings.getExperimental();
|
|
if (experimental.enableResponsibilities !== true) throw notFound("Responsibilities are not enabled");
|
|
}
|
|
|
|
async function reporterOf(row: ResponsibilityRow) {
|
|
return (await loadResponsibilityReporters(db, row.companyId, [row])).get(row.id) ?? null;
|
|
}
|
|
|
|
async function state(row: ResponsibilityRow, now = new Date()): Promise<ResponsibilityStatusReportState> {
|
|
const [history, reporter, requests] = await Promise.all([
|
|
db.select().from(responsibilityStatusReports)
|
|
.where(and(eq(responsibilityStatusReports.companyId, row.companyId), eq(responsibilityStatusReports.responsibilityId, row.id)))
|
|
.orderBy(desc(responsibilityStatusReports.createdAt), desc(responsibilityStatusReports.id))
|
|
.limit(RESPONSIBILITY_STATUS_REPORT_HISTORY_LIMIT),
|
|
reporterOf(row),
|
|
loadOpenStatusUpdateRequests(db, row.companyId, [row.id]),
|
|
]);
|
|
return {
|
|
current: current(history[0], now),
|
|
reporterAgentId: reporter?.agentId ?? null,
|
|
updateRequested: updateStillRequested(requests.get(row.id), history[0]),
|
|
history: history.map(entry),
|
|
};
|
|
}
|
|
|
|
return {
|
|
assertEnabled,
|
|
state,
|
|
reporterOf,
|
|
|
|
/**
|
|
* Every active responsibility of the owner with its current report, its
|
|
* reporter and whether an update is pending. Seven queries whatever the
|
|
* count: the responsibilities, the agents, three for the work under them,
|
|
* the latest reports and the open requests.
|
|
*/
|
|
async overview(companyId: string, ownerUserId: string, now = new Date()): Promise<ResponsibilityStatusReportsOverview> {
|
|
const rows = await db.select({ id: responsibilities.id, runByAgentId: responsibilities.runByAgentId })
|
|
.from(responsibilities)
|
|
.where(and(
|
|
eq(responsibilities.companyId, companyId),
|
|
eq(responsibilities.ownerUserId, ownerUserId),
|
|
eq(responsibilities.status, "active"),
|
|
))
|
|
.orderBy(asc(responsibilities.sortOrder), asc(responsibilities.createdAt), asc(responsibilities.id));
|
|
const ids = rows.map((row) => row.id);
|
|
const [reporters, latest, requests] = await Promise.all([
|
|
loadResponsibilityReporters(db, companyId, rows),
|
|
loadLatestStatusReports(db, companyId, ids),
|
|
loadOpenStatusUpdateRequests(db, companyId, ids),
|
|
]);
|
|
return {
|
|
ownerUserId,
|
|
freshDays: RESPONSIBILITY_STATUS_REPORT_FRESH_DAYS,
|
|
reports: rows.map((row) => {
|
|
const reporter = reporters.get(row.id) ?? null;
|
|
const report = latest.get(row.id);
|
|
return {
|
|
responsibilityId: row.id,
|
|
current: current(report, now),
|
|
reporterAgentId: reporter?.agentId ?? null,
|
|
reporterBasis: reporter?.basis ?? null,
|
|
updateRequested: updateStillRequested(requests.get(row.id), report),
|
|
};
|
|
}),
|
|
};
|
|
},
|
|
|
|
/** An agent may write when it is the reporter or works under the responsibility. */
|
|
async agentMayWrite(row: ResponsibilityRow, agentId: string) {
|
|
const reporter = await reporterOf(row);
|
|
if (reporter?.agentId === agentId) return true;
|
|
return agentWorksUnderResponsibility(db, row, agentId);
|
|
},
|
|
|
|
/** Record a report. The route has already decided the author may write it. */
|
|
async write(row: ResponsibilityRow, input: WriteResponsibilityStatusReport, author: StatusReportAuthor) {
|
|
await assertEnabled();
|
|
const data = writeResponsibilityStatusReportSchema.parse(input);
|
|
if (row.status !== "active") {
|
|
throw conflict("Only an active responsibility carries a status", { code: "responsibility_status_not_active" });
|
|
}
|
|
const [created] = await db.insert(responsibilityStatusReports).values({
|
|
companyId: row.companyId,
|
|
responsibilityId: row.id,
|
|
agentId: author.type === "agent" ? author.agentId : null,
|
|
userId: author.type === "user" ? author.userId : null,
|
|
status: data.status,
|
|
message: data.message,
|
|
detail: data.detail ?? null,
|
|
}).returning();
|
|
return created!;
|
|
},
|
|
|
|
/**
|
|
* Ask the reporter for an update: a small task assigned to it whose prompt
|
|
* carries the facts and the call. While one is open and unanswered,
|
|
* asking again changes nothing. The route wakes the agent and writes
|
|
* activity.
|
|
*/
|
|
async requestUpdate(
|
|
row: ResponsibilityRow,
|
|
actor: { userId: string; runId: string | null; identityContextId: string | null; authorizationActor: AuthorizationActor },
|
|
): Promise<{ issue: IssueRow | null; created: boolean; agentId: string }> {
|
|
await assertEnabled();
|
|
if (row.status !== "active") {
|
|
throw conflict("Only an active responsibility carries a status", { code: "responsibility_status_not_active" });
|
|
}
|
|
const reporter = await reporterOf(row);
|
|
if (!reporter) {
|
|
throw unprocessable("No agent in this organization can take work, so nobody can write this status; write it yourself", {
|
|
code: "responsibility_status_no_agent",
|
|
});
|
|
}
|
|
const [requests, latest] = await Promise.all([
|
|
loadOpenStatusUpdateRequests(db, row.companyId, [row.id]),
|
|
loadLatestStatusReports(db, row.companyId, [row.id]),
|
|
]);
|
|
const open = requests.get(row.id);
|
|
if (open && updateStillRequested(open, latest.get(row.id))) {
|
|
return { issue: null, created: false, agentId: open.agentId ?? reporter.agentId };
|
|
}
|
|
const [company] = await db.select({ issuePrefix: companies.issuePrefix }).from(companies).where(eq(companies.id, row.companyId));
|
|
const backLink = company ? `[Back to ${row.title}](/${company.issuePrefix}/responsibilities/${row.id})` : null;
|
|
const description = [
|
|
`Where does **${row.title}** stand? Look at the work under it and write its status: behind, at risk or on track, with one plain line saying why.`,
|
|
...(backLink ? ["", backLink] : []),
|
|
].join("\n");
|
|
const issue = await issuesSvc.create(row.companyId, {
|
|
title: `Status update: ${row.title}`.slice(0, 200),
|
|
description,
|
|
status: "todo",
|
|
priority: "low",
|
|
assigneeAgentId: reporter.agentId,
|
|
originKind: RESPONSIBILITY_STATUS_UPDATE_ORIGIN_KIND,
|
|
originId: row.id,
|
|
createdByUserId: actor.userId,
|
|
createdByAgentId: null,
|
|
trustExplicitResponsibleUserId: true,
|
|
workspaceSelectionActor: actor.authorizationActor,
|
|
originRunId: actor.runId,
|
|
originIdentityContextId: actor.identityContextId,
|
|
actorRunId: actor.runId,
|
|
});
|
|
return { issue: issue as unknown as IssueRow, created: true, agentId: reporter.agentId };
|
|
},
|
|
|
|
assertCanBeWrittenBy(author: StatusReportAuthor, allowed: boolean) {
|
|
if (!allowed) {
|
|
throw forbidden(author.type === "agent"
|
|
? "Only the agent that reports on this responsibility, or an agent working under it, can write its status"
|
|
: "Only the person who owns this responsibility, or a company admin, can write its status");
|
|
}
|
|
},
|
|
};
|
|
}
|