mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-01 23:43:16 +01:00
## Thinking Path > - Paperclip is the open source control plane people use to coordinate AI agents, issues, approvals, comments, and work products. > - The involved subsystem is issue context: markdown links, issue properties, related work, lists, filters, inbox/sidebar status, and plugin-provided external context. > - The gap is that URLs to external systems currently remain mostly plain links, so humans and agents must manually open them to understand status, identity, and liveness. > - This matters because external work objects such as GitHub issues and pull requests are part of the operational state of a Paperclip company. > - The implementation keeps core provider-neutral: shared contracts, storage, sync, routes, and UI surfaces live in core while providers can contribute detection and status resolution. > - This pull request adds the external object reference foundation, GitHub provider support, issue-surface rendering, filters, sidebar/list/inbox signals, and test/story coverage. > - The benefit is that linked external work becomes inspectable Paperclip context without hardcoding every provider directly into the UI. ## Linked Issues or Issue Description No public GitHub issue exists for this work. Feature request: - Problem: URLs in Paperclip issues, comments, documents, and related surfaces do not expose provider status or object identity inline. - Proposed behavior: detect supported external object URLs, persist normalized references, refresh provider status, and render concise status-aware links across issue surfaces. - Users affected: board users, agents, and maintainers who triage issues containing external work links. - Acceptance: external object references are company-scoped, provider-extensible, visible in key issue surfaces, filterable where relevant, and covered by focused shared/server/UI tests. Related PR search: - No open duplicate PRs found for `external object references`. - Closed related prior attempt: #4556. ## What Changed - Added shared external-object contracts, validators, status/liveness helpers, and plugin protocol declarations. - Added database schema and additive migrations for external objects, source mentions, and display metadata. - Added server services/routes for detecting, syncing, summarizing, refreshing, and resolving external objects across issues, documents, comments, projects, and plugins. - Added a GitHub external-object provider plus plugin SDK authoring docs. - Wired UI presentation across markdown links, comments, issue chat, documents, properties, related work, issue rows, filters, inbox/sidebar badges, and Storybook stories. - Rebasing cleanup: moved the branch onto current `master`, repaired stale worktree provision config, hardened environment-sensitive tests/mocks, and removed committed screenshot artifacts from the PR branch to keep the reviewable file set below tool limits. ## Verification - `pnpm exec vitest run packages/shared/src/external-objects.test.ts server/src/__tests__/external-object-routes.test.ts server/src/__tests__/external-objects-service.test.ts ui/src/components/ExternalObjectPill.test.tsx ui/src/lib/external-objects.test.ts` passed after rebasing: 5 files, 56 tests. - Historical branch verification before this PR creation included `pnpm test:run`, `pnpm -r typecheck`, and `pnpm build`; this PR body does not claim those were rerun after the final rebase. ## Risks - Medium: this adds a new cross-surface sync path on issue/document/comment writes. The implementation uses safe sync wrappers so external-object failures warn instead of blocking core mutations. - Medium: the migrations introduce new tables and indexes. They are additive and company-scoped. - Medium: provider-specific URL parsing can miss or misclassify edge cases. Shared canonicalization tests and provider tests cover current GitHub shapes. - Low: UI badge/filter behavior could add visual noise for object-heavy issues; component tests and Storybook stories cover the intended surfaces. > Roadmap checked: `ROADMAP.md` references the plugin system as the current extension path and does not list a duplicate core feature. Related long-range docs discuss external references, work products, preview URLs, and plugin extension points; this PR implements the scoped external-object reference foundation. ## Model Used OpenAI Codex, GPT-5 coding-agent runtime, with shell and GitHub CLI tool use. Reasoning mode: medium. Exact deployed runtime model ID and context window were not exposed in the environment. ## 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 - [x] All Paperclip CI gates are green - [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>
215 lines
7.5 KiB
TypeScript
215 lines
7.5 KiB
TypeScript
import type { IssueRelatedWorkItem, IssueRelatedWorkSummary } from "@paperclipai/shared";
|
||
import { IssueReferencePill } from "./IssueReferencePill";
|
||
import { ExternalObjectPill } from "./ExternalObjectPill";
|
||
import type { IssueExternalObjectGroup } from "../hooks/useIssueExternalObjects";
|
||
import { externalObjectToneSeverity } from "../lib/external-objects";
|
||
|
||
type GroupedSource = {
|
||
label: string;
|
||
count: number;
|
||
sampleMatchedText: string | null;
|
||
};
|
||
|
||
function groupSourcesByLabel(sources: IssueRelatedWorkItem["sources"]): GroupedSource[] {
|
||
const groups = new Map<string, GroupedSource>();
|
||
for (const source of sources) {
|
||
const existing = groups.get(source.label);
|
||
if (existing) {
|
||
existing.count += 1;
|
||
} else {
|
||
groups.set(source.label, {
|
||
label: source.label,
|
||
count: 1,
|
||
sampleMatchedText: source.matchedText ?? null,
|
||
});
|
||
}
|
||
}
|
||
return Array.from(groups.values());
|
||
}
|
||
|
||
function Section({
|
||
title,
|
||
description,
|
||
items,
|
||
emptyLabel,
|
||
}: {
|
||
title: string;
|
||
description: string;
|
||
items: IssueRelatedWorkItem[];
|
||
emptyLabel: string;
|
||
}) {
|
||
return (
|
||
<section className="space-y-3 rounded-lg border border-border p-3">
|
||
<div className="space-y-1">
|
||
<h3 className="text-sm font-semibold">{title}</h3>
|
||
<p className="text-xs text-muted-foreground">{description}</p>
|
||
</div>
|
||
|
||
{items.length === 0 ? (
|
||
<p className="text-xs text-muted-foreground">{emptyLabel}</p>
|
||
) : (
|
||
<ul className="-mx-1 flex flex-col">
|
||
{items.map((item) => {
|
||
const groupedSources = groupSourcesByLabel(item.sources);
|
||
const showTitle = item.issue.identifier !== item.issue.title;
|
||
return (
|
||
<li
|
||
key={item.issue.id}
|
||
className="flex flex-wrap items-center gap-x-2 gap-y-1.5 rounded-md px-1 py-1.5 hover:bg-accent/40"
|
||
>
|
||
<IssueReferencePill issue={item.issue} />
|
||
{showTitle ? (
|
||
<span className="min-w-0 flex-1 truncate text-sm text-muted-foreground">
|
||
{item.issue.title}
|
||
</span>
|
||
) : null}
|
||
<div className="flex flex-wrap items-center gap-1.5">
|
||
{groupedSources.map((group) => (
|
||
<span
|
||
key={`${item.issue.id}:${group.label}`}
|
||
className="inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs text-muted-foreground"
|
||
title={group.sampleMatchedText ?? undefined}
|
||
>
|
||
<span>{group.label}</span>
|
||
{group.count > 1 ? (
|
||
<span className="tabular-nums text-[10px] font-medium opacity-80">×{group.count}</span>
|
||
) : null}
|
||
</span>
|
||
))}
|
||
</div>
|
||
</li>
|
||
);
|
||
})}
|
||
</ul>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function ExternalObjectsSection({
|
||
groups,
|
||
isLoading,
|
||
isError,
|
||
onRetry,
|
||
}: {
|
||
groups: IssueExternalObjectGroup[];
|
||
isLoading: boolean;
|
||
isError: boolean;
|
||
onRetry?: () => void;
|
||
}) {
|
||
// Severity-first sort with most-recently-changed as the secondary sort.
|
||
const sorted = [...groups].sort((a, b) => {
|
||
const aTone = externalObjectToneSeverity(a.pill.statusCategory ? a.group.object?.statusTone ?? null : null);
|
||
const bTone = externalObjectToneSeverity(b.pill.statusCategory ? b.group.object?.statusTone ?? null : null);
|
||
if (aTone !== bTone) return bTone - aTone;
|
||
const aChanged = a.group.object?.lastChangedAt ?? a.group.object?.lastResolvedAt ?? "";
|
||
const bChanged = b.group.object?.lastChangedAt ?? b.group.object?.lastResolvedAt ?? "";
|
||
return aChanged < bChanged ? 1 : aChanged > bChanged ? -1 : 0;
|
||
});
|
||
|
||
return (
|
||
<section className="space-y-3 rounded-lg border border-border p-3">
|
||
<div className="space-y-1">
|
||
<h3 className="text-sm font-semibold">External objects</h3>
|
||
<p className="text-xs text-muted-foreground">
|
||
Remote work referenced from this issue — pull requests, deployments, tickets in other systems, and more.
|
||
</p>
|
||
</div>
|
||
|
||
{isError ? (
|
||
<p className="text-xs text-muted-foreground">
|
||
Couldn't load external objects.{" "}
|
||
{onRetry ? (
|
||
<button
|
||
type="button"
|
||
onClick={onRetry}
|
||
className="text-primary underline-offset-2 hover:underline"
|
||
>
|
||
Retry
|
||
</button>
|
||
) : null}
|
||
</p>
|
||
) : isLoading ? (
|
||
<p className="text-xs text-muted-foreground">Loading external objects…</p>
|
||
) : sorted.length === 0 ? (
|
||
<p className="text-xs text-muted-foreground">
|
||
This issue does not reference any external objects yet.
|
||
</p>
|
||
) : (
|
||
<ul className="-mx-1 flex flex-col">
|
||
{sorted.map(({ pill, mentionCount, sourceLabels, group }) => {
|
||
const object = group.object;
|
||
return (
|
||
<li
|
||
key={object?.id ?? `${pill.providerKey}:${pill.objectType}:${pill.url ?? "anon"}`}
|
||
className="flex flex-wrap items-center gap-x-2 gap-y-1.5 rounded-md px-1 py-1.5 hover:bg-accent/40"
|
||
>
|
||
<ExternalObjectPill object={pill} sourceCount={mentionCount} sourceSummary={sourceLabels.join(", ")} />
|
||
{pill.displayTitle ? (
|
||
<span className="min-w-0 flex-1 truncate text-sm text-muted-foreground">
|
||
{pill.displayTitle}
|
||
</span>
|
||
) : null}
|
||
<div className="flex flex-wrap items-center gap-1.5">
|
||
{sourceLabels.map((label) => (
|
||
<span
|
||
key={`${object?.id ?? pill.url ?? label}:${label}`}
|
||
className="inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs text-muted-foreground"
|
||
>
|
||
<span>{label}</span>
|
||
</span>
|
||
))}
|
||
</div>
|
||
</li>
|
||
);
|
||
})}
|
||
</ul>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
export function IssueRelatedWorkPanel({
|
||
relatedWork,
|
||
externalObjectsEnabled = true,
|
||
externalObjects,
|
||
externalObjectsLoading,
|
||
externalObjectsError,
|
||
onRetryExternalObjects,
|
||
}: {
|
||
relatedWork?: IssueRelatedWorkSummary | null;
|
||
externalObjectsEnabled?: boolean;
|
||
externalObjects?: IssueExternalObjectGroup[];
|
||
externalObjectsLoading?: boolean;
|
||
externalObjectsError?: boolean;
|
||
onRetryExternalObjects?: () => void;
|
||
}) {
|
||
const outbound = relatedWork?.outbound ?? [];
|
||
const inbound = relatedWork?.inbound ?? [];
|
||
|
||
return (
|
||
<div className="space-y-3">
|
||
<Section
|
||
title="References"
|
||
description="Other tasks this task currently points at in its title, description, comments, or documents."
|
||
items={outbound}
|
||
emptyLabel="This task does not reference any other tasks yet."
|
||
/>
|
||
{externalObjectsEnabled ? (
|
||
<ExternalObjectsSection
|
||
groups={externalObjects ?? []}
|
||
isLoading={Boolean(externalObjectsLoading)}
|
||
isError={Boolean(externalObjectsError)}
|
||
onRetry={onRetryExternalObjects}
|
||
/>
|
||
) : null}
|
||
<Section
|
||
title="Referenced by"
|
||
description="Other tasks that currently point at this task."
|
||
items={inbound}
|
||
emptyLabel="No other tasks reference this task yet."
|
||
/>
|
||
</div>
|
||
);
|
||
}
|