mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-19 10:36:26 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The issue properties panel can show external objects such as GitHub pull requests. > - Those objects are resolved by external-object providers and then displayed as compact status labels. > - A GitHub pull request could remain in the fallback `unknown` state and appear as `Not yet resolved`. > - That label is confusing when the object is known but has not been refreshed yet. > - This pull request refreshes due external objects from the heartbeat scheduler and improves the unknown-status copy. > - The benefit is a properties panel that moves from pending refresh to the real pull request state without a manual refresh. ## Linked Issues or Issue Description No public GitHub issue exists for this bug. I searched for related public issues and pull requests using the terms `Not yet refreshed`, `external objects refresh`, and `external PR status`, and did not find a duplicate implementation. **What happened?** The issue properties panel could show a GitHub pull request as `Not yet resolved` even when the referenced pull request was valid. The object stayed stale unless a manual refresh path ran. **Expected behavior** A known external object should show pending-refresh copy while it waits for provider data. When the scheduler refreshes it, the properties panel should show the provider status such as open, merged, or closed. **Steps to reproduce** 1. Create or view an issue that references a GitHub pull request. 2. Open the issue properties panel. 3. Observe the external object row before a manual refresh has run. **Paperclip version or commit** Current `master` before this pull request. **Deployment mode** Local dev and self-hosted server. **Installation method** Built from source. **Agent adapter(s) involved** Not adapter-specific. **Database mode** Not database-related. **Access context** Board view. **Privacy checklist** I reviewed this description and did not include logs, credentials, private URLs, internal issue IDs, or PII. ## What Changed - Added a heartbeat scheduler tick that refreshes due external objects for active companies. - Kept manual external-object refresh behavior on the same service path. - Changed display copy so known provider objects use liveness labels such as `Not yet refreshed`, while fresh unknown provider statuses show `Status unavailable`. - Added server and UI tests for scheduled refresh and label behavior. ## Verification - `corepack pnpm install --frozen-lockfile` - `pnpm check:token-gates` - `pnpm exec vitest run server/src/__tests__/external-objects-service.test.ts server/src/__tests__/server-startup-feedback-export.test.ts ui/src/components/ExternalObjectPill.test.tsx ui/src/components/IssueProperties.test.tsx ui/src/lib/external-objects.test.ts` - `pnpm --filter @paperclipai/ui typecheck` - `pnpm --filter @paperclipai/server typecheck` - `pnpm --filter @paperclipai/server build` - `pnpm --filter @paperclipai/ui build` - `pnpm run typecheck:build-gaps` - GitHub PR checks passed on head `0e7fcd30` - Greptile reported 5/5 on head `0e7fcd30` with no unresolved review threads Notes: - I ran recursive typecheck and build first. Both hit container resource limits with exit 137 during concurrent package work, so I reran the affected server and UI targets separately. - An unrelated workspace-runtime auto-port test fails in this container with a PID ownership mismatch. It is outside the files changed here. ## Risks Low to medium risk. The scheduler does more periodic external-object work, so the main risk is extra provider refresh load. The implementation bounds the work to active companies, due non-terminal objects, and 50 objects per company per tick. The path also stays behind the external-objects experimental setting. ## Model Used OpenAI GPT-5 Codex in the Codex execution environment, with shell and GitHub CLI tool use. The runtime did not expose a more specific internal model ID or context window. ## 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>
201 lines
6.9 KiB
TypeScript
201 lines
6.9 KiB
TypeScript
import type { ReactNode } from "react";
|
||
import type {
|
||
ExternalObjectLivenessState,
|
||
ExternalObjectStatusCategory,
|
||
} from "@paperclipai/shared";
|
||
import { ExternalObjectStatusIcon } from "./ExternalObjectStatusIcon";
|
||
import {
|
||
externalObjectStatusIcon,
|
||
externalObjectStatusIconDefault,
|
||
externalObjectLivenessOverlay,
|
||
} from "../lib/status-colors";
|
||
import {
|
||
externalObjectDisplayStatusLabel,
|
||
externalObjectDisplayLabel,
|
||
externalObjectLivenessLabel,
|
||
externalObjectIconForKey,
|
||
externalObjectProviderLabel,
|
||
externalObjectTypeLabel,
|
||
} from "../lib/external-objects";
|
||
import { cn } from "../lib/utils";
|
||
|
||
export interface ExternalObjectPillData {
|
||
providerKey: string | null;
|
||
objectType: string | null;
|
||
displayKey?: string | null;
|
||
iconKey?: string | null;
|
||
statusCategory: ExternalObjectStatusCategory;
|
||
liveness: ExternalObjectLivenessState;
|
||
displayTitle?: string | null;
|
||
statusLabel?: string | null;
|
||
statusIconKey?: string | null;
|
||
url?: string | null;
|
||
}
|
||
|
||
function githubObjectLabel(url: string | null | undefined): string | null {
|
||
if (!url) return null;
|
||
try {
|
||
const parsed = new URL(url);
|
||
if (parsed.hostname !== "github.com") return null;
|
||
const [, owner, repo, kind, number] = parsed.pathname.split("/");
|
||
if (!owner || !repo || !number) return null;
|
||
if (kind === "pull") return `PR ${number}`;
|
||
if (kind === "issues") return `Issue ${number}`;
|
||
return null;
|
||
} catch {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
function externalObjectValueLabel(
|
||
object: ExternalObjectPillData,
|
||
fallback: string,
|
||
statusLabel: string,
|
||
): string {
|
||
const githubLabel = object.providerKey === "github" ? githubObjectLabel(object.url) : null;
|
||
const base = githubLabel ?? object.displayTitle?.trim() ?? fallback;
|
||
return statusLabel ? `${base} - ${statusLabel}` : base;
|
||
}
|
||
|
||
function isMergedExternalObject(object: ExternalObjectPillData, statusLabel: string): boolean {
|
||
return object.statusIconKey === "git-merge" || statusLabel.toLowerCase() === "merged";
|
||
}
|
||
|
||
function externalObjectPillTone(object: ExternalObjectPillData, statusLabel: string): string {
|
||
if (isMergedExternalObject(object, statusLabel)) {
|
||
return "text-violet-600 border-violet-600 dark:text-violet-400 dark:border-violet-400";
|
||
}
|
||
return externalObjectStatusIcon[object.statusCategory] ?? externalObjectStatusIconDefault;
|
||
}
|
||
|
||
function externalObjectStatusIconKey(
|
||
object: ExternalObjectPillData,
|
||
statusLabel: string,
|
||
): string | null | undefined {
|
||
if (isMergedExternalObject(object, statusLabel)) return object.statusIconKey ?? "git-merge";
|
||
return object.statusIconKey;
|
||
}
|
||
|
||
interface ExternalObjectPillProps {
|
||
object: ExternalObjectPillData;
|
||
/** Optional external mention count (renders as `×N` superscript when > 1). */
|
||
sourceCount?: number;
|
||
/** Optional source-mention summary used as the pill's `title` attribute. */
|
||
sourceSummary?: string | null;
|
||
className?: string;
|
||
/** Optional rendered label override. Defaults to `provider object-type`. */
|
||
children?: ReactNode;
|
||
/**
|
||
* If true the pill renders without a hover treatment (used inside
|
||
* non-interactive contexts like the property panel). Defaults to false.
|
||
*/
|
||
inert?: boolean;
|
||
/**
|
||
* Hide the provider icon when the surrounding UI already names the provider.
|
||
* The status icon still renders as the single state glyph inside the pill.
|
||
*/
|
||
showProviderIcon?: boolean;
|
||
}
|
||
|
||
/**
|
||
* External-object equivalent of `IssueReferencePill`. Same `paperclip-mention-chip`
|
||
* base so external references feel native to readers (Jakob's Law).
|
||
*/
|
||
export function ExternalObjectPill({
|
||
object,
|
||
sourceCount,
|
||
sourceSummary,
|
||
className,
|
||
children,
|
||
inert,
|
||
showProviderIcon = true,
|
||
}: ExternalObjectPillProps) {
|
||
const overlay = externalObjectLivenessOverlay[object.liveness] ?? "";
|
||
const providerLabel = externalObjectProviderLabel(object.providerKey);
|
||
const typeLabel = externalObjectTypeLabel(object.objectType);
|
||
const displayKey = externalObjectDisplayLabel(object.providerKey, object.objectType, object.displayKey);
|
||
const statusLabel = externalObjectDisplayStatusLabel(object);
|
||
const tone = externalObjectPillTone(object, statusLabel);
|
||
const valueLabel = externalObjectValueLabel(object, displayKey, statusLabel);
|
||
const statusIconKey = externalObjectStatusIconKey(object, statusLabel);
|
||
const livenessLabel = externalObjectLivenessLabel(object.liveness);
|
||
const ProviderIcon = externalObjectIconForKey(object.iconKey);
|
||
const ariaKey = displayKey;
|
||
const ariaLabel = `${ariaKey} — ${statusLabel}${
|
||
object.liveness === "fresh" || object.liveness === "unknown" ? "" : ` (${livenessLabel})`
|
||
}${object.displayTitle ? `: ${object.displayTitle}` : ""}`;
|
||
|
||
const interactive = !inert && Boolean(object.url);
|
||
const classNames = cn(
|
||
"paperclip-mention-chip paperclip-mention-chip--external-object",
|
||
"inline-flex max-w-full items-center gap-1 rounded-full border border-border px-2 py-0.5 text-xs no-underline",
|
||
// Tone is applied as text classes only — the border style comes from the
|
||
// overlay (dashed for stale/auth/unreachable).
|
||
tone.split(" ").filter((c) => c.startsWith("text-")).join(" "),
|
||
overlay,
|
||
interactive
|
||
&& "hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-(length:--rad-3) focus-visible:ring-ring",
|
||
className,
|
||
);
|
||
const titleAttr = sourceSummary
|
||
? `${object.displayTitle ?? displayKey} — ${sourceSummary}`
|
||
: object.displayTitle ?? displayKey;
|
||
const labelText = children ?? (
|
||
<>
|
||
<ExternalObjectStatusIcon
|
||
category={object.statusCategory}
|
||
liveness={object.liveness}
|
||
statusIconKey={statusIconKey}
|
||
sizeClassName="h-3 w-3"
|
||
label={`${providerLabel}: ${statusLabel}`}
|
||
/>
|
||
<span className="max-w-(--sz-16rem) truncate font-medium">{valueLabel}</span>
|
||
</>
|
||
);
|
||
const countSuffix = typeof sourceCount === "number" && sourceCount > 1 ? (
|
||
<span className="tabular-nums text-(length:--text-nano) font-medium opacity-80">×{sourceCount}</span>
|
||
) : null;
|
||
const innerContent = (
|
||
<>
|
||
{showProviderIcon && ProviderIcon ? (
|
||
<ProviderIcon aria-hidden="true" className="h-3 w-3 shrink-0" />
|
||
) : null}
|
||
<span className="inline-flex min-w-0 items-center gap-1">
|
||
{labelText}
|
||
</span>
|
||
{countSuffix}
|
||
</>
|
||
);
|
||
|
||
if (interactive && object.url) {
|
||
return (
|
||
<a
|
||
href={object.url}
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
data-mention-kind="external-object"
|
||
data-external-status={object.statusCategory}
|
||
data-external-liveness={object.liveness}
|
||
className={classNames}
|
||
title={titleAttr}
|
||
aria-label={ariaLabel}
|
||
>
|
||
{innerContent}
|
||
</a>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<span
|
||
data-mention-kind="external-object"
|
||
data-external-status={object.statusCategory}
|
||
data-external-liveness={object.liveness}
|
||
className={classNames}
|
||
title={titleAttr}
|
||
aria-label={ariaLabel}
|
||
>
|
||
{innerContent}
|
||
</span>
|
||
);
|
||
}
|