mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-09 07:10:34 +01:00
## Thinking Path > - Paperclip helps people manage AI agents and their work. > - Routines create tasks for repeated work. > - Each routine has a responsible person. > - The Overview did not show this person or permit a change. > - People need to see who will be responsible for automatic tasks. > - This pull request adds a small name picker beside Default agent. > - Authorized people can adopt a routine or transfer it to an active company member. ## Linked Issues or Issue Description **What existing behavior does this improve?** The routine Overview and the routine update API. **Subsystem affected** UI, server, and shared contracts. **Current behavior** The routine stores a responsible user. The Overview does not show that person. The update API cannot change that person. **Proposed behavior** Show Responsible user beside Default agent. Click the name to search active company members. Save only the new person and the current revision ID. **Reason and benefit** People can see who owns future automatic tasks. An authorized person can adopt a routine without making a new routine. **Breaking changes** The detail response adds an optional actor-specific field. The update API adds an optional responsible user ID. Existing requests keep their current behavior. Related: #17368 covers local Board ownership migration. This change adds the routine control and explicit transfer. ## What Changed - Show a quiet, searchable person picker beside Default agent. - Explain that automatic tasks use this person. Manual runs use the person who starts them. - Permit human operators with `tasks:assign`, instance administrators, and local operators to transfer responsibility. - Check active company membership inside the update transaction. - Save a revision and record the old and new person in the activity log. - Keep existing task responsibility and ownership during revision restore. - Show errors for failed saves and stale revisions. - Add tests for permissions, company boundaries, transfers, inheritance, and picker states. - Keep the picker disabled until saved data is refreshed. Refresh the activity list after a transfer. - Capture the actual previous person under the update row lock for the activity record. - Use shared query error handling and retain cached people during a connection failure. ## Verification - Focused checks cover 145 tests in 5 files. The first post-fix run passed 144 tests. One existing Fireflies route test timed out during the first import while the UI typecheck also ran. The same test passed in the pre-fix run. The isolated route suite then passed all 21 tests with no source change. - The new tests reproduce slow detail refreshes, activity refresh, and two concurrent transfers without a base revision. The concurrency test uses PostgreSQL row locks. - UI and server TypeScript checks passed at commit `1df9587eb`. - The UI production build passed for the updated head. - The branch includes master through `26391707f`. - Design token gates, query-error policy, and Git whitespace checks passed. The query-error policy reports zero findings. - Local browser checks passed on desktop and mobile for the initial feature commit. Search, selection, reload persistence, and revision creation passed. No page errors or horizontal overflow were found. The follow-up does not change the normal layout. - Earlier full local checks could not finish: Cargo was absent, and concurrent full test/build checks exceeded the 8 GiB memory limit. These attempts are not passes. - The first CI run failed on two error-rendering policy findings. That failure is fixed locally. The three findings from the first Greptile review are fixed and their threads are resolved. - Greptile reviewed `1df9587eb2d3e034c2769b1f6955ac52323c95bb` and scored it 5/5. It confirms all three prior findings are addressed. There are no open review threads. - [CI attempt 1](https://github.com/paperclipai/paperclip/actions/runs/42046369415/attempts/1) passed 53 checks. The server 8/12 shard failed only because the existing `history-http` runtime fixture did not become ready within 10 seconds (99 refused connections). The fixture and runtime source are unchanged from the merged master. That case passed locally on the same PR head with no source change. Its full 75-test suite also passed locally. The cause of the CI failure remains unknown. - [CI attempt 2](https://github.com/paperclipai/paperclip/actions/runs/42046369415/attempts/2) passed on `1df9587eb`: 54 successful checks, 3 skipped, and 1 neutral. No failed or pending checks remained. The original fixture-readiness failure remains recorded above. - A later review found that viewers with an explicit `tasks:assign` grant could see an editable picker even though writes were denied. Commit `8b95ee707` now mirrors active-membership and viewer restrictions in the GET capability flag. Instance-admin and local-operator behavior is preserved. - Three membership regressions failed on the incorrect editable flag before the fix. After the fix, all 43 routine-route and company-access cases passed (`--testTimeout 60000` accommodated this sandbox's cold route imports; no repository timeout was changed). The first pre-fix run timed out during the cold import in one case; the second pre-fix run reproduced all three assertion failures. - Layered server typechecking and whitespace checks passed after the permission fix. - [Fresh CI](https://github.com/paperclipai/paperclip/actions/runs/42057752313) passed on `8b95ee7075417527687b4a86cbaf63ba87408364` without a retry. Greptile reviewed this exact head, scored it 5/5, and added no new findings. All four review threads are resolved. The security status is also successful. - The separate Paperclip Review check is still queued because its assigned review worker requires runtime recovery. This is the remaining check before completion; the CI workflow itself passed. ## Risks - A transfer changes the person used for future automatic tasks. Existing tasks keep their current person. - Only people can transfer responsibility. The server checks the permission again on every write. - A stale revision rejects the save. The user must reload before retrying. - No database migration is required. ## Model Used OpenAI Codex, based on GPT-6, with reasoning, tool use, and code execution. The exact runtime model ID and context window are not exposed to this session. ## 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 - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green (CI passed; separate Paperclip Review check pending) - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
261 lines
9.7 KiB
TypeScript
261 lines
9.7 KiB
TypeScript
import type {
|
|
Issue,
|
|
IssuePriority,
|
|
IssueStatus,
|
|
RoutineRunSummary,
|
|
RoutineTrigger,
|
|
} from "@paperclipai/shared";
|
|
import { ISSUE_PRIORITIES, ISSUE_STATUSES } from "@paperclipai/shared";
|
|
import { CalendarClock, Clock3, Play, Repeat, UserRound } from "lucide-react";
|
|
import { IssueRow } from "@/components/IssueRow";
|
|
import { MarkdownBody } from "@/components/MarkdownBody";
|
|
import { StatusBadge } from "@/components/StatusBadge";
|
|
import { Button } from "@/components/ui/button";
|
|
import { createIssueDetailLocationState } from "@/lib/issueDetailBreadcrumb";
|
|
import { Link } from "@/lib/router";
|
|
import {
|
|
routineDetailHref,
|
|
} from "./RoutineContextualSidebar";
|
|
import { useRoutineDetail } from "./routine-sections/context";
|
|
import { RoutineResponsibleUser } from "./RoutineResponsibleUser";
|
|
|
|
export type RoutineScheduleSummary = {
|
|
label: string;
|
|
detail: string;
|
|
nextRunAt: Date | null;
|
|
};
|
|
|
|
export function formatRoutineTimestamp(value: Date | string) {
|
|
return new Date(value).toLocaleString(undefined, {
|
|
dateStyle: "medium",
|
|
timeStyle: "short",
|
|
});
|
|
}
|
|
|
|
export function summarizeRoutineSchedule(triggers: RoutineTrigger[]): RoutineScheduleSummary {
|
|
const schedules = triggers.filter((trigger) => trigger.kind === "schedule" && trigger.enabled);
|
|
const nextRunAt = schedules
|
|
.map((trigger) => trigger.nextRunAt ? new Date(trigger.nextRunAt) : null)
|
|
.filter((value): value is Date => value !== null && Number.isFinite(value.getTime()))
|
|
.sort((left, right) => left.getTime() - right.getTime())[0] ?? null;
|
|
|
|
if (schedules.length === 0) {
|
|
const webhooks = triggers.filter((trigger) => trigger.kind === "webhook" && trigger.enabled);
|
|
if (webhooks.length > 0) {
|
|
return {
|
|
label: `${webhooks.length} active webhook${webhooks.length === 1 ? "" : "s"}`,
|
|
detail: "Runs on incoming requests",
|
|
nextRunAt: null,
|
|
};
|
|
}
|
|
return { label: "No active schedule", detail: "Manual runs only", nextRunAt: null };
|
|
}
|
|
|
|
const first = schedules[0]!;
|
|
return {
|
|
label: schedules.length === 1 ? "1 active schedule" : `${schedules.length} active schedules`,
|
|
detail: first.cronExpression
|
|
? `${first.cronExpression}${first.timezone ? ` · ${first.timezone}` : ""}`
|
|
: first.label ?? "Scheduled trigger",
|
|
nextRunAt,
|
|
};
|
|
}
|
|
|
|
function normalizeIssueStatus(value: string): IssueStatus {
|
|
return ISSUE_STATUSES.includes(value as IssueStatus) ? value as IssueStatus : "todo";
|
|
}
|
|
|
|
function normalizeIssuePriority(value: string): IssuePriority {
|
|
return ISSUE_PRIORITIES.includes(value as IssuePriority) ? value as IssuePriority : "medium";
|
|
}
|
|
|
|
/** Display-only adapter for the canonical task row; run summaries intentionally carry compact task data. */
|
|
export function routineRunIssue(
|
|
summary: NonNullable<RoutineRunSummary["linkedIssue"]>,
|
|
run: RoutineRunSummary,
|
|
companyId: string,
|
|
projectId: string | null,
|
|
): Issue {
|
|
return {
|
|
...summary,
|
|
companyId,
|
|
projectId,
|
|
projectWorkspaceId: null,
|
|
goalId: null,
|
|
parentId: null,
|
|
description: null,
|
|
status: normalizeIssueStatus(summary.status),
|
|
workMode: "standard",
|
|
priority: normalizeIssuePriority(summary.priority),
|
|
reviewPolicy: null,
|
|
assigneeAgentId: null,
|
|
assigneeUserId: null,
|
|
checkoutRunId: null,
|
|
executionRunId: null,
|
|
executionAgentNameKey: null,
|
|
executionLockedAt: null,
|
|
createdByAgentId: null,
|
|
createdByUserId: null,
|
|
responsibleUserId: null,
|
|
issueNumber: null,
|
|
originKind: "routine_execution",
|
|
originId: run.routineId,
|
|
originRunId: run.id,
|
|
requestDepth: 0,
|
|
billingCode: null,
|
|
assigneeAdapterOverrides: null,
|
|
executionWorkspaceId: null,
|
|
executionWorkspacePreference: null,
|
|
executionWorkspaceSettings: null,
|
|
startedAt: null,
|
|
completedAt: null,
|
|
cancelledAt: null,
|
|
hiddenAt: null,
|
|
createdAt: run.triggeredAt,
|
|
};
|
|
}
|
|
|
|
function OverviewFact({
|
|
icon: Icon,
|
|
label,
|
|
value,
|
|
detail,
|
|
}: {
|
|
icon: typeof Clock3;
|
|
label: string;
|
|
value: React.ReactNode;
|
|
detail?: React.ReactNode;
|
|
}) {
|
|
return (
|
|
<div className="flex min-w-0 flex-col gap-1 rounded-lg border border-border p-3">
|
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
<Icon className="h-3.5 w-3.5" aria-hidden="true" />
|
|
<span>{label}</span>
|
|
</div>
|
|
<div className="min-w-0 text-sm font-medium text-foreground">{value}</div>
|
|
{detail ? <div className="min-w-0 text-xs text-muted-foreground">{detail}</div> : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function RoutineOverview() {
|
|
const { routine, routineRuns, currentAssignee, hasLiveRun } = useRoutineDetail();
|
|
const schedule = summarizeRoutineSchedule(routine.triggers);
|
|
const hasWebhook = routine.triggers.some((trigger) => trigger.kind === "webhook" && trigger.enabled);
|
|
const sortedRuns = [...(routineRuns ?? [])].sort(
|
|
(left, right) => new Date(right.triggeredAt).getTime() - new Date(left.triggeredAt).getTime(),
|
|
);
|
|
const lastRun = sortedRuns[0] ?? null;
|
|
const recentRuns = sortedRuns.slice(0, 5);
|
|
const detailOrigin = createIssueDetailLocationState(
|
|
routine.title,
|
|
routineDetailHref(routine.id),
|
|
"issues",
|
|
);
|
|
const automationState = routine.status === "archived"
|
|
? "archived"
|
|
: !routine.assigneeAgentId
|
|
? "draft"
|
|
: routine.status;
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6" data-routine-overview-mode="read">
|
|
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
|
<OverviewFact
|
|
icon={Repeat}
|
|
label="State"
|
|
value={<StatusBadge status={automationState} />}
|
|
detail={hasLiveRun ? "A run is active now" : "No active run"}
|
|
/>
|
|
<OverviewFact
|
|
icon={CalendarClock}
|
|
label="Triggers"
|
|
value={schedule.label}
|
|
detail={<span className="font-mono">{schedule.detail}</span>}
|
|
/>
|
|
<OverviewFact
|
|
icon={Clock3}
|
|
label="Next run"
|
|
value={schedule.nextRunAt ? formatRoutineTimestamp(schedule.nextRunAt) : hasWebhook ? "On webhook delivery" : "Not scheduled"}
|
|
detail={schedule.nextRunAt ? "Scheduled" : hasWebhook ? "Waiting for an incoming request" : "Add or enable a schedule"}
|
|
/>
|
|
<OverviewFact
|
|
icon={Play}
|
|
label="Last run"
|
|
value={lastRun ? <StatusBadge status={lastRun.status} /> : "No runs yet"}
|
|
detail={lastRun ? formatRoutineTimestamp(lastRun.triggeredAt) : "Run manually or wait for a trigger"}
|
|
/>
|
|
</div>
|
|
|
|
<div className="grid gap-6 sm:grid-cols-2">
|
|
<section className="flex flex-col gap-2" aria-labelledby="routine-agent-heading">
|
|
<h2 id="routine-agent-heading" className="text-sm font-semibold">Default agent</h2>
|
|
{currentAssignee ? (
|
|
<Link
|
|
to={`/agents/${currentAssignee.urlKey ?? currentAssignee.id}`}
|
|
className="flex w-fit items-center gap-2 rounded-md text-sm font-medium hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
>
|
|
<UserRound className="h-4 w-4 text-muted-foreground" aria-hidden="true" />
|
|
{currentAssignee.name}
|
|
</Link>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">No default agent. Automatic triggers remain paused.</p>
|
|
)}
|
|
</section>
|
|
<RoutineResponsibleUser key={routine.id} routine={routine} />
|
|
</div>
|
|
|
|
<section className="flex flex-col gap-2" aria-labelledby="routine-description-heading">
|
|
<h2 id="routine-description-heading" className="text-sm font-semibold">Description</h2>
|
|
{routine.description?.trim() ? (
|
|
<MarkdownBody className="text-sm text-foreground" linkIssueReferences>
|
|
{routine.description}
|
|
</MarkdownBody>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">No description yet.</p>
|
|
)}
|
|
</section>
|
|
|
|
<section className="flex flex-col gap-2" aria-labelledby="routine-recent-runs-heading">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<h2 id="routine-recent-runs-heading" className="text-sm font-semibold">Recent runs</h2>
|
|
<Button variant="ghost" size="sm" asChild>
|
|
<Link to={routineDetailHref(routine.id, "runs")}>View all runs</Link>
|
|
</Button>
|
|
</div>
|
|
{recentRuns.length === 0 ? (
|
|
<p className="py-6 text-center text-sm text-muted-foreground">
|
|
No runs yet. Run the routine now or wait for its schedule.
|
|
</p>
|
|
) : (
|
|
<div className="flex flex-col gap-0.5">
|
|
{recentRuns.map((run) => run.linkedIssue ? (
|
|
<IssueRow
|
|
key={run.id}
|
|
issue={routineRunIssue(run.linkedIssue, run, routine.companyId, routine.projectId)}
|
|
issueLinkState={detailOrigin}
|
|
presentation="task"
|
|
metadata={(
|
|
<span className="flex items-center gap-2">
|
|
<StatusBadge status={run.status} />
|
|
<span className="font-mono text-xs text-muted-foreground">{formatRoutineTimestamp(run.triggeredAt)}</span>
|
|
</span>
|
|
)}
|
|
/>
|
|
) : (
|
|
<div key={run.id} className="flex min-w-0 items-center gap-2 rounded-lg px-2 py-2 text-sm">
|
|
<StatusBadge status={run.status} />
|
|
<span className="min-w-0 flex-1 truncate">{run.trigger?.label ?? "Routine run"}</span>
|
|
<span className="shrink-0 font-mono text-xs text-muted-foreground">{formatRoutineTimestamp(run.triggeredAt)}</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
<Button variant="link" size="sm" className="w-fit px-0" asChild>
|
|
<Link to={routineDetailHref(routine.id, "activity")}>View routine activity</Link>
|
|
</Button>
|
|
</section>
|
|
</div>
|
|
);
|
|
}
|