Files
PaperClipAI/ui/src/components/responsibilities/ResponsibilityOneScreenV2.tsx
T
bca282e587 feat(recents): add tasks from manual routine runs to Recents (#23675)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The sidebar Recents list shows the tasks from a person's own recent
activity
> - A person can run a routine manually with "Run now", and the run
creates a task
> - That task does not show in Recents, and opening it does not keep it
there, because Recents only admits tasks under the Mine participation
rule. This also affects every routine, channel, and agent-created task
that a person opens
> - The Mine rule keeps these tasks out of Mine on purpose, so we must
not change that rule
> - This pull request adds a separate Recents eligibility flag. It also
admits tasks that the viewer opened and tasks from manual routine runs
that the viewer started. The UI records the new task in Recents when the
run starts
> - The benefit is that people can find the task they just started from
the sidebar at once, and Mine stays unchanged

## Linked Issues or Issue Description

**Is your feature request related to a problem? Please describe.**
When I run a routine manually and it creates a task, the task is not in
my Recents list. I must go to the routine or the task list to find it.

**Describe the solution you'd like**
When I run a routine manually and a task is created, add that task to my
Recents list automatically, even if I did not open it.

Also, a task that a routine creates does not show in Recents even after
I open it.

**Additional context**
Mine must continue to keep routine tasks out by default, including
routines that a person starts manually (see `doc/PRODUCT.md`).

## What Changed

- `server/src/services/issue-summaries.ts`: navigation summaries return
a new `isRecentEligibleForMe` flag. It is true when one of these
conditions is true:
  - The viewer participates under the Mine rule.
- The viewer opened the task. The check is the viewer's
`issue_read_states` row, which is unique on company, issue, and user.
- The viewer started the manual routine run that created the task. The
check is a `routine_runs` row found through the indexed
`linked_issue_id`, with `source = 'manual'` and the same ID as the
issue's `originRunId`. The issue `createdByUserId` must be the viewer,
with no creating agent.
  `isParticipantForMe`, Mine, and unread state do not change.
- `packages/shared`: add `isRecentEligibleForMe` to `IssueSummary`.
- `ui/src/hooks/useRecentTasks.ts`: Recents uses `isRecentEligibleForMe`
(with a fallback to `isParticipantForMe` for older cached summaries) to
show, keep, and prune entries.
- `ui/src/lib/recent-tasks.ts`: add `recordStartedRoutineRunTask`. It
puts the run's task at the top of Recents. The summary fetch then
supplies the title and status and confirms eligibility.
- New `useRecordRoutineRunInRecents` hook. All five "Run now" paths call
it on success: Routines (both list variants), Routine detail, Execution
workspace detail, and the Responsibility screen.
- `tests/runner-e2e/source-sdk-public-inputs.json`: refresh the pin for
`packages/shared/src/types/issue.ts`.
- `doc/PRODUCT.md`: document the Recents behavior.

## Verification

- `cd ui && npx vitest run src/hooks/useRecentTasks.test.tsx`: 29
passed. The new test "shows a task from the viewer's manual routine run
at the top before it is opened" fails on the old hook (red) and passes
with the change (green). Other new tests cover a run that the server
does not confirm (for example, a coalesced run) and a repeat run for a
task that is already in Recents.
- `cd server && npx vitest run
src/__tests__/issue-summaries-routes.test.ts` (embedded Postgres): 24
passed. One new test checks that a manual run by the viewer is
Recents-eligible but not a Mine participant, and that runs by another
person and scheduled runs are not eligible. Another new test checks that
a routine task the viewer opened is Recents-eligible, and that a task
opened only by another person is not. That test fails on the previous
service code (red) and passes with the change (green).
- `ui` typecheck: no errors in changed files. (Errors exist only in
ungenerated Storybook feature-map indexes, which this change does not
touch.)
- The full `server` typecheck was killed by the local memory limit. CI
covers it.
- Manual check: run a routine with "Run now", then look at sidebar
Recents. The new task shows at the top before you open it. Mine does not
show it.

## Risks

- Low risk. No schema change and no migration.
- The summaries query adds two `EXISTS` subqueries per requested task.
Both use indexes (the read-state unique index and
`routine_runs_linked_issue_idx`). The request is bounded by
`ISSUE_SUMMARIES_MAX_IDS`.
- Behavior change: Recents now keeps tasks that the person opened, also
when the task is automatic work. Old local Recents entries for automatic
tasks that the person read can come back.
- If a manual run coalesces into an existing task that the viewer did
not start, the entry is pruned after the summary read. That task does
not show in Recents.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code with tool use
(shell, file edit, test runs).

## 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
- [ ] 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)
- [ ] 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
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 20:54:26 -08:00

622 lines
26 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 { useMemo, useRef, useState, type FormEvent, type ReactNode } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import type { Agent, CompanyArtifact, ResponsibilityProjectSummary, ResponsibilityRoutineSummary, ResponsibilitySkillSummary } from "@paperclipai/shared";
import { FileText, MoreHorizontal, Plus } from "lucide-react";
import { describeError } from "@/api/errors";
import { QueryErrorState, useQueryView } from "@/components/QueryView";
import { responsibilitiesApi } from "@/api/responsibilities";
import { routinesApi } from "@/api/routines";
import { glyphOf, subjectFromCompanyArtifact } from "@/components/artifacts/v1/kinds";
import { NewProjectForm } from "@/components/NewProjectDialog";
import { StatusIcon } from "@/components/StatusIcon";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import { agentDetailHref } from "@/pages/agent-detail-navigation";
import { queryKeys } from "@/lib/queryKeys";
import { skillRoute } from "@/lib/company-skill-routes";
import { agentsWorkingUnder, routinePath } from "@/lib/responsibilities";
import {
ago,
projectDueStat,
projectProgressLabel,
routineStat,
runStat,
splitTasksForTable,
} from "@/lib/responsibility-one-screen-v2";
import { isFinishedProject } from "@/lib/responsibility-views";
import { Link } from "@/lib/router";
import { taskStatusIconProps } from "@/lib/task-status-presentation";
import { agentRouteRef, issueUrl, projectUrl } from "@/lib/utils";
import { AddExistingWorkPicker, type ResponsibilityWorkKind } from "./AddExistingWorkPicker";
import { BarModule } from "./BarModule";
import { MakeRoutineDialog } from "./MakeRoutineDialog";
import { AreaRadioItems, useMoveToArea } from "./MoveToArea";
import { useResponsibilityRuns } from "./RecentRuns";
import { ProposalsNotice } from "./ResponsibilityViewParts";
import {
SectionTable,
SectionTableFooterButton,
SectionTableNote,
SectionTableRow,
TaskRefStat,
WhoAvatar,
} from "./SectionTable";
import type { ResponsibilityViewProps } from "./view-props";
import { useRecordRoutineRunInRecents } from "@/hooks/useRecordRoutineRunInRecents";
/** The sections under the bar, in order. Each is one table whose header bar is just the word. */
export const ONE_SCREEN_V2_SECTIONS = ["routines", "skills", "projects", "tasks", "runs", "artifacts"] as const;
type SectionKey = (typeof ONE_SCREEN_V2_SECTIONS)[number];
const SECTION_TITLE: Record<SectionKey, string> = {
routines: "Routines",
skills: "Skills",
projects: "Projects",
tasks: "Tasks",
runs: "Recent runs",
artifacts: "Artifacts",
};
const TASK_CAP = 8;
/** A skill row shows up to this many holders; past it, the rest as "+N". */
const SKILL_HOLDER_CAP = 4;
/** The agents who hold a skill, as avatars; past the cap, the first few and "+N". */
function SkillHolders({ agentIds, agentsById }: { agentIds: readonly string[]; agentsById: ReadonlyMap<string, Agent> }) {
const overflow = agentIds.length > SKILL_HOLDER_CAP;
const shown = overflow ? agentIds.slice(0, SKILL_HOLDER_CAP - 1) : agentIds;
return (
<>
{shown.map((id) => <WhoAvatar key={id} agentId={id} agentsById={agentsById} />)}
{overflow ? <span className="text-sm text-muted-foreground tabular-nums">+{agentIds.length - shown.length}</span> : null}
</>
);
}
/** A thin meter of a project's done tasks; its words are on hover and for screen readers. */
function ProjectProgress({ progress }: { progress: NonNullable<ResponsibilityProjectSummary["progress"]> }) {
const label = projectProgressLabel(progress);
const percent = Math.round((Math.min(progress.done, progress.total) / progress.total) * 100);
return (
<span role="img" aria-label={label} title={label} className="relative block h-1 w-16 overflow-hidden rounded-full bg-muted" data-project-progress={percent}>
<span className="absolute inset-y-0 left-0 rounded-full bg-muted-foreground" style={{ width: `${percent}%` }} />
</span>
);
}
/** The small kind mark the artifacts surfaces use (PDF's three bars read as a document here). */
function ArtifactKindMark({ artifact }: { artifact: CompanyArtifact }) {
const glyph = glyphOf(subjectFromCompanyArtifact(artifact));
const Icon = glyph === "bars" ? FileText : glyph;
return <Icon aria-hidden="true" className="size-4 shrink-0 text-muted-foreground" />;
}
/** The "+" at a heading's right: one menu with "new" (when the page can make one) and "add existing". */
function AddMenu({
label,
newLabel,
onNew,
existing,
onExisting,
}: {
/** "Add a routine". */
label: string;
newLabel: string;
onNew?: () => void;
existing?: boolean;
onExisting?: () => void;
}) {
// The picker opens once the menu has closed, so the menu's focus return does not dismiss it.
const pickExisting = useRef(false);
if (!onNew && !existing) return null;
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button type="button" size="icon-xs" variant="ghost" className="text-muted-foreground" aria-label={label} data-section-add="">
<Plus aria-hidden="true" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent
align="end"
onCloseAutoFocus={(event) => {
if (!pickExisting.current) return;
pickExisting.current = false;
event.preventDefault();
onExisting?.();
}}
>
{onNew ? <DropdownMenuItem onSelect={onNew}>{newLabel}</DropdownMenuItem> : null}
{existing && onExisting ? (
<DropdownMenuItem onSelect={() => { pickExisting.current = true; }}>Add existing</DropdownMenuItem>
) : null}
</DropdownMenuContent>
</DropdownMenu>
);
}
/**
* The Skills "+": file an existing company skill here, remove one filed here,
* or open an agent's skills to give it one. Skills an agent holds come from
* that agent, so they are not removed here.
*/
function SkillsMenu({
onExisting,
filed,
onRemove,
removingLinkId,
agents,
}: {
onExisting: () => void;
/** Skills filed here by hand. */
filed: readonly ResponsibilitySkillSummary[];
onRemove: (skill: ResponsibilitySkillSummary) => void;
removingLinkId: string | null;
/** The agents working on this, whose skills page can give them one. */
agents: readonly Agent[];
}) {
// The picker opens once the menu has closed, so the menu's focus return does not dismiss it.
const pickExisting = useRef(false);
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button type="button" size="icon-xs" variant="ghost" className="text-muted-foreground" aria-label="Add or remove a skill" data-section-add="">
<Plus aria-hidden="true" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent
align="end"
onCloseAutoFocus={(event) => {
if (!pickExisting.current) return;
pickExisting.current = false;
event.preventDefault();
onExisting();
}}
>
<DropdownMenuItem onSelect={() => { pickExisting.current = true; }}>Add existing skill</DropdownMenuItem>
{filed.length > 0 ? (
<>
<DropdownMenuSeparator />
<DropdownMenuLabel>Remove from this responsibility</DropdownMenuLabel>
{filed.map((skill) => (
<DropdownMenuItem
key={skill.id}
disabled={removingLinkId === skill.linkId}
aria-label={`Remove ${skill.name} from this responsibility`}
onSelect={() => onRemove(skill)}
>
{skill.name}
</DropdownMenuItem>
))}
</>
) : null}
{agents.length > 0 ? (
<>
<DropdownMenuSeparator />
<DropdownMenuLabel>Give a skill to</DropdownMenuLabel>
{agents.map((agent) => (
<DropdownMenuItem key={agent.id} asChild>
<Link to={agentDetailHref(agentRouteRef(agent), "skills")}>{agent.name}</Link>
</DropdownMenuItem>
))}
</>
) : null}
</DropdownMenuContent>
</DropdownMenu>
);
}
/** A "+" that cannot do anything yet, with why, on hover and for screen readers. */
function DisabledAdd({ label, reason }: { label: string; reason: string }) {
return (
<span title={reason} className="inline-flex" data-section-add-disabled="">
<Button type="button" size="icon-xs" variant="ghost" className="text-muted-foreground" aria-label={`${label}: ${reason}`} disabled>
<Plus aria-hidden="true" />
</Button>
</span>
);
}
function RenameDialog({ open, onOpenChange, title, onSave }: { open: boolean; onOpenChange: (open: boolean) => void; title: string; onSave: (title: string) => Promise<unknown> | void }) {
const [value, setValue] = useState(title);
const [error, setError] = useState<unknown>(null);
const [saving, setSaving] = useState(false);
const submit = async (event: FormEvent) => {
event.preventDefault();
const next = value.trim();
if (!next || saving) return;
if (next === title) {
onOpenChange(false);
return;
}
setSaving(true);
setError(null);
try {
await onSave(next);
onOpenChange(false);
} catch (caught) {
setError(caught);
} finally {
setSaving(false);
}
};
return (
<Dialog open={open} onOpenChange={(next) => { if (next) setValue(title); onOpenChange(next); }}>
<DialogContent className="sm:max-w-md">
<form className="flex flex-col gap-4" onSubmit={submit}>
<DialogHeader>
<DialogTitle>Rename</DialogTitle>
<DialogDescription className="sr-only">The short name this responsibility goes by.</DialogDescription>
</DialogHeader>
<Input aria-label="Name" value={value} maxLength={200} autoFocus onChange={(event) => setValue(event.target.value)} />
{error ? <p role="alert" className="text-sm text-destructive">Couldn’t rename it. {describeError(error).body}</p> : null}
<DialogFooter className="sm:justify-between">
<Button type="button" variant="ghost" onClick={() => onOpenChange(false)}>Cancel</Button>
<Button type="submit" disabled={!value.trim() || saving}>{saving ? "Saving…" : "Save"}</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}
/**
* "One screen v2": a deliberately spare layout. The responsibility's sentence
* as the heading (its area above it, the rare actions in one menu), the bar,
* then Routines, Skills, Projects, Tasks, Recent runs and Artifacts, each one
* table (`SectionTable`) whose header bar is just the word and a "+" for
* adding one here (new, or existing). Each row is what it is, one stat in
* plain words, and who has it. No status words, counts or explanations.
*/
export function ResponsibilityOneScreenV2({
responsibility,
companyId,
agents,
agentsById,
areas,
now,
notices,
actions,
onReviewProposal,
}: ResponsibilityViewProps) {
const queryClient = useQueryClient();
const isActive = responsibility.status === "active";
const editable = responsibility.status !== "dismissed";
const barEditable = responsibility.status === "active" || responsibility.status === "proposed";
const heading = responsibility.standard?.trim() || responsibility.title;
const move = useMoveToArea(responsibility.id);
const [renaming, setRenaming] = useState(false);
const [picking, setPicking] = useState<ResponsibilityWorkKind | null>(null);
const [newRoutine, setNewRoutine] = useState(false);
const [newProject, setNewProject] = useState(false);
const [filingError, setFilingError] = useState<unknown>(null);
const [showAllTasks, setShowAllTasks] = useState(false);
const [showDoneTasks, setShowDoneTasks] = useState(false);
const runs = useResponsibilityRuns(responsibility.id);
const runsView = useQueryView(runs);
const linkedIds = useMemo(() => ({
project: new Set(responsibility.projects.map((project) => project.id)),
task: new Set(responsibility.tasks.filter((task) => task.membership === "direct").map((task) => task.id)),
routine: new Set(responsibility.routines.filter((routine) => routine.membership === "direct").map((routine) => routine.id)),
skill: new Set(responsibility.skills.filter((skill) => skill.linkId).map((skill) => skill.id)),
}), [responsibility.projects, responsibility.tasks, responsibility.routines, responsibility.skills]);
const routines = responsibility.routines.filter((routine) => routine.status !== "archived");
const projects = responsibility.projects.filter((project) => !isFinishedProject(project));
const { open: openTasks, done: doneTasks } = useMemo(() => splitTasksForTable(responsibility.tasks), [responsibility.tasks]);
const shownTasks = [
...(showAllTasks ? openTasks : openTasks.slice(0, TASK_CAP)),
...(showDoneTasks ? doneTasks : []),
];
const working = useMemo(() => {
const ids = agentsWorkingUnder(responsibility).map((entry) => entry.agentId);
if (responsibility.runByAgentId && !ids.includes(responsibility.runByAgentId)) ids.unshift(responsibility.runByAgentId);
return ids.flatMap((id) => {
const agent = agentsById.get(id);
return agent ? [agent] : [];
});
}, [responsibility, agentsById]);
const firstAgentId = working[0]?.id ?? null;
const recordRoutineRunInRecents = useRecordRoutineRunInRecents();
const runNow = useMutation({
mutationFn: (routine: ResponsibilityRoutineSummary) => routinesApi.run(routine.id, {}),
onSuccess: async (run) => {
recordRoutineRunInRecents(run);
await Promise.all([
queryClient.invalidateQueries({ queryKey: queryKeys.responsibilities.runs(responsibility.id) }),
queryClient.invalidateQueries({ queryKey: queryKeys.responsibilities.detail(responsibility.id) }),
]);
},
});
const picker = (kind: ResponsibilityWorkKind, anchor: ReactNode) => (
<AddExistingWorkPicker
companyId={companyId}
responsibilityId={responsibility.id}
kind={kind}
linkedIds={linkedIds[kind]}
open={picking === kind}
onOpenChange={(open) => setPicking(open ? kind : null)}
anchor={anchor}
/>
);
const whoFor = (agentId: string | null) => (agentId ? <WhoAvatar agentId={agentId} agentsById={agentsById} /> : null);
const runnable = routines.filter((routine) => routine.status === "active");
const runsAdd = !isActive ? null : runnable.length === 0 ? (
<DisabledAdd label="Run a routine now" reason={routines.length === 0 ? "No routines to run yet" : "No active routine to run"} />
) : (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button type="button" size="icon-xs" variant="ghost" className="text-muted-foreground" aria-label="Run a routine now" disabled={runNow.isPending} data-section-add="">
<Plus aria-hidden="true" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Run now</DropdownMenuLabel>
{runnable.map((routine) => (
<DropdownMenuItem key={routine.id} onSelect={() => runNow.mutate(routine)}>{routine.title}</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
);
const filedSkills = useMemo(() => responsibility.skills.filter((skill) => skill.linkId), [responsibility.skills]);
const skillsAdd = !editable ? null : picker("skill", (
<SkillsMenu
onExisting={() => setPicking("skill")}
filed={filedSkills}
removingLinkId={actions.unlinkingId}
onRemove={(skill) => actions.unlink({ linkId: skill.linkId!, label: skill.name, relink: { skillId: skill.id } })}
agents={working}
/>
));
const fileNewProject = async (project: { id: string }) => {
setFilingError(null);
try {
await responsibilitiesApi.link(responsibility.id, { projectId: project.id });
} catch (error) {
setFilingError(error);
}
await queryClient.invalidateQueries({ queryKey: queryKeys.responsibilities.all });
};
return (
<div className="mx-auto flex w-full max-w-3xl flex-col gap-8" data-responsibility-view="one_screen_v2">
<header className="flex flex-col gap-1">
{responsibility.area ? <p className="text-xs text-muted-foreground" data-area="">{responsibility.area.title}</p> : null}
<div className="flex items-start justify-between gap-3">
<h1 className="min-w-0 flex-1 text-xl font-semibold text-foreground">{heading}</h1>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button size="icon-sm" variant="ghost" className="shrink-0 text-muted-foreground" aria-label="More actions for this responsibility">
<MoreHorizontal aria-hidden="true" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onSelect={() => setRenaming(true)}>Rename…</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger>Move to area</DropdownMenuSubTrigger>
<DropdownMenuSubContent className="max-h-(--sz-50vh) overflow-y-auto">
<AreaRadioItems
areas={responsibility.area && !areas.some((candidate) => candidate.id === responsibility.area!.id) ? [responsibility.area, ...areas] : areas}
value={responsibility.area?.id ?? null}
onChange={(areaId) => {
if (areaId !== (responsibility.area?.id ?? null)) move.mutate(areaId);
}}
/>
</DropdownMenuSubContent>
</DropdownMenuSub>
{isActive ? (
<DropdownMenuItem onSelect={() => actions.setStatus("let_go")}>Let go</DropdownMenuItem>
) : responsibility.status === "let_go" || responsibility.status === "dismissed" ? (
<DropdownMenuItem onSelect={() => actions.setStatus("active")}>Take it back on</DropdownMenuItem>
) : null}
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" onSelect={actions.requestDelete}>Delete…</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
{responsibility.status === "let_go" ? (
<p className="text-sm text-muted-foreground">You let go of this.</p>
) : responsibility.status === "dismissed" ? (
<p className="text-sm text-muted-foreground">You dismissed this.</p>
) : null}
{move.error ? <p role="alert" className="text-sm text-destructive">Couldn’t move it. {describeError(move.error).body}</p> : null}
{notices}
</header>
{responsibility.status === "proposed" ? <ProposalsNotice count={1} subject="this" onReview={onReviewProposal} /> : null}
<BarModule responsibility={responsibility} agentsById={agentsById} now={now} editable={barEditable} />
<div className="flex flex-col gap-6" data-section-order="">
<SectionTable
section="routines"
title={SECTION_TITLE.routines}
add={editable ? picker("routine", (
<AddMenu
label="Add a routine"
newLabel="New routine"
onNew={isActive ? () => setNewRoutine(true) : undefined}
existing
onExisting={() => setPicking("routine")}
/>
)) : null}
empty={routines.length === 0 ? "None yet." : null}
>
{routines.map((routine) => (
<SectionTableRow
key={routine.id}
rowData={{ "data-work-id": routine.id }}
to={routinePath(routine.id)}
title={routine.title}
stat={routineStat(routine, now)}
who={whoFor(routine.assigneeAgentId)}
/>
))}
</SectionTable>
<SectionTable
section="skills"
title={SECTION_TITLE.skills}
add={skillsAdd}
empty={responsibility.skills.length === 0 ? "None yet." : null}
>
{responsibility.skills.map((skill) => (
<SectionTableRow
key={skill.id}
rowData={{ "data-work-id": skill.id }}
to={skillRoute(skill)}
title={skill.name}
stat={skill.linkId ? "Filed here" : undefined}
who={skill.agentIds.length > 0 ? <SkillHolders agentIds={skill.agentIds} agentsById={agentsById} /> : null}
/>
))}
</SectionTable>
<SectionTable
section="projects"
title={SECTION_TITLE.projects}
add={editable ? picker("project", (
<AddMenu
label="Add a project"
newLabel="New project"
onNew={isActive ? () => setNewProject(true) : undefined}
existing
onExisting={() => setPicking("project")}
/>
)) : null}
empty={projects.length === 0 ? (responsibility.projects.length > 0 ? "None open." : "None yet.") : null}
footer={filingError ? (
<SectionTableNote alert>The project was made but couldn’t be filed here. {describeError(filingError).body}</SectionTableNote>
) : null}
>
{projects.map((project) => (
<SectionTableRow
key={project.id}
rowData={{ "data-work-id": project.id }}
to={projectUrl(project)}
title={project.name}
aside={project.progress ? <ProjectProgress progress={project.progress} /> : null}
stat={projectDueStat(project, now)}
who={whoFor(project.leadAgentId)}
/>
))}
</SectionTable>
<SectionTable
section="tasks"
title={SECTION_TITLE.tasks}
add={editable ? picker("task", (
<AddMenu
label="Add a task"
newLabel="New task"
onNew={isActive ? () => actions.newTask({ defaultTitle: "" }) : undefined}
existing
onExisting={() => setPicking("task")}
/>
)) : null}
empty={shownTasks.length === 0 ? (responsibility.tasks.length > 0 ? "None open." : "None yet.") : null}
footer={(
<>
{!showAllTasks && openTasks.length > TASK_CAP ? (
<SectionTableFooterButton onClick={() => setShowAllTasks(true)}>Show {openTasks.length - TASK_CAP} more</SectionTableFooterButton>
) : null}
{doneTasks.length > 0 ? (
<SectionTableFooterButton onClick={() => setShowDoneTasks((shown) => !shown)}>
{showDoneTasks ? "Hide done" : `Show ${doneTasks.length} done`}
</SectionTableFooterButton>
) : null}
</>
)}
>
{shownTasks.map((task) => (
<SectionTableRow
key={task.id}
rowData={{ "data-work-id": task.id }}
to={issueUrl(task)}
leading={<StatusIcon {...taskStatusIconProps(task)} size="sm" />}
title={task.title}
stat={<TaskRefStat identifier={task.identifier} when={ago(task.updatedAt, now)} />}
who={whoFor(task.assigneeAgentId)}
/>
))}
</SectionTable>
<SectionTable
section="runs"
title={SECTION_TITLE.runs}
add={runsAdd}
empty={runsView.kind === "error" ? (
<QueryErrorState error={runsView.error} size="inline" action="load the runs" onRetry={runsView.retry} retrying={runsView.isFetching} />
) : !runs.data ? (
<span role="status">Loading…</span>
) : runs.data.runs.length === 0 ? "None yet." : null}
footer={runNow.error ? (
<SectionTableNote alert>Couldn’t start the run. {describeError(runNow.error).body}</SectionTableNote>
) : null}
>
{(runsView.kind === "error" ? [] : runs.data?.runs ?? []).map((run) => {
const stat = runStat(run, now);
return (
<SectionTableRow
key={run.id}
rowData={{ "data-run-id": run.id, "data-run-status": run.status }}
to={`/agents/${run.agentId}/runs/${run.id}`}
label={`${agentsById.get(run.agentId)?.name ?? "An agent"} on ${run.issue.title}: ${stat}`}
title={run.issue.title}
stat={stat}
who={whoFor(run.agentId)}
/>
);
})}
</SectionTable>
<SectionTable
section="artifacts"
title={SECTION_TITLE.artifacts}
withWho={false}
empty={responsibility.artifacts.length === 0 ? "None yet." : null}
>
{responsibility.artifacts.map((artifact) => (
<SectionTableRow
key={`${artifact.source}:${artifact.id}`}
rowData={{ "data-artifact-id": artifact.id }}
to={artifact.href}
leading={<ArtifactKindMark artifact={artifact} />}
title={artifact.title}
stat={<TaskRefStat identifier={artifact.issue.identifier} when={ago(artifact.updatedAt, now)} />}
/>
))}
</SectionTable>
</div>
<RenameDialog open={renaming} onOpenChange={setRenaming} title={responsibility.title} onSave={actions.saveTitle} />
<MakeRoutineDialog
open={newRoutine}
onOpenChange={setNewRoutine}
companyId={companyId}
task={null}
newFor={{ responsibilityId: responsibility.id, responsibilityTitle: responsibility.title, assigneeAgentId: firstAgentId }}
agents={agents}
filedUnder={[responsibility.title]}
/>
{newProject ? (
<NewProjectForm companyId={companyId} onClose={() => setNewProject(false)} onCreated={fileNewProject} />
) : null}
</div>
);
}