mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-24 01:41:42 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The experimental server info debug view helps local operators inspect what code a running dev instance is actually serving > - The view was moved into the account-menu drawer, which only mounts while that drawer is open > - That made stale health-query data easier to see after restarts, and the server was also caching the running commit at process boot > - A clean commit label alone is incomplete when the checkout has uncommitted local changes > - This pull request keeps the drawer health data fresh, refreshes git metadata on demand, and adds a path-free checkout-state summary > - The benefit is that the debug view reports restart time, running commit, and dirty-checkout state without exposing local paths, secrets, logs, or environment details ## Linked Issues or Issue Description Fixes: #8752 ## What Changed - `SidebarServerInfo.tsx`: refetch the health query whenever the drawer opens and poll every 2s while the dev server is active. - `server-info.ts`: keep `processStartedAt` stable while refreshing git HEAD through a short TTL cache instead of freezing commit metadata at module boot. - Shared health contract/OpenAPI: add `serverInfo.git.localChanges` with only staged, unstaged, and untracked counts plus safe unavailable fallbacks. - `SidebarServerInfo.tsx`: add a `Checkout state` row that renders clean/dirty/unavailable copy without file paths. - Tests: cover stale drawer refresh, interval polling, TTL commit refresh, health response shape, checkout-state count parsing, and path-free UI rendering. ## Verification - `npx vitest run server/src/__tests__/server-info.test.ts server/src/__tests__/health.test.ts ui/src/components/SidebarServerInfo.test.tsx` -> 3 files / 19 tests passing. - `pnpm install --frozen-lockfile --ignore-scripts` -> refreshed stale workspace links without lockfile/source churn. - `pnpm --filter @paperclipai/shared --filter @paperclipai/server --filter @paperclipai/ui typecheck` -> passing. - `pnpm --filter @paperclipai/ui typecheck` -> passing after the Greptile test-coverage fix. - `pnpm check:tokens` -> no forbidden tokens found. - Local diff scans for obvious secrets, credentials, private URLs, local paths, and PII patterns -> no matches. - GitHub PR checks on head `56defd446` -> all green, including `verify`, canary dry run, e2e, security scans, and Greptile Review. - Greptile latest summary -> Confidence Score 5/5, 0 new comments; the prior P2 polling-coverage thread is resolved. ## Risks Low risk. The UI remains behind the experimental `enableServerInfoDebugView` flag. The extra git status call is throttled by the existing server-info TTL and reports only counts, not paths or file names. If git status is unavailable, the commit row still works and the checkout-state row shows clear fallback copy. ## Model Used Claude Opus (claude-opus-4-8), extended thinking, with tool use / code execution assisted the original stale-metadata fix. OpenAI GPT-5 via Codex local, with tool use and code execution, added the checkout-state follow-up, Greptile fix-up, and PR verification. ## 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>
140 lines
4.8 KiB
TypeScript
140 lines
4.8 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { Clock3, FileDiff, GitCommit, type LucideIcon } from "lucide-react";
|
|
import { healthApi, type HealthStatus } from "@/api/health";
|
|
import { instanceSettingsApi } from "@/api/instanceSettings";
|
|
import { queryKeys } from "@/lib/queryKeys";
|
|
|
|
function formatTimestamp(value: string | null | undefined): string {
|
|
if (!value) return "Unavailable";
|
|
const date = new Date(value);
|
|
if (Number.isNaN(date.getTime())) return "Unavailable";
|
|
return new Intl.DateTimeFormat(undefined, {
|
|
dateStyle: "medium",
|
|
timeStyle: "short",
|
|
}).format(date);
|
|
}
|
|
|
|
function isValidTimestamp(value: string | null | undefined): value is string {
|
|
return !!value && !Number.isNaN(new Date(value).getTime());
|
|
}
|
|
|
|
function restartTimestamp(health: HealthStatus | undefined): string | null {
|
|
return health?.devServer?.lastRestartAt ?? health?.serverInfo?.processStartedAt ?? null;
|
|
}
|
|
|
|
function commitLabel(health: HealthStatus | undefined): string {
|
|
const git = health?.serverInfo?.git;
|
|
if (!git?.available) return "Commit unavailable";
|
|
return `${git.shortSha} · ${git.subject}`;
|
|
}
|
|
|
|
function localChangesLabel(health: HealthStatus | undefined): string {
|
|
const git = health?.serverInfo?.git;
|
|
if (!git?.available) return "Unavailable";
|
|
const localChanges = git.localChanges;
|
|
if (!localChanges) return "Change status unavailable";
|
|
if (!localChanges.available) return "Change status unavailable";
|
|
if (!localChanges.hasLocalChanges) return "Clean checkout";
|
|
|
|
const parts = [
|
|
[localChanges.stagedFileCount, "staged"],
|
|
[localChanges.unstagedFileCount, "unstaged"],
|
|
[localChanges.untrackedFileCount, "untracked"],
|
|
]
|
|
.filter(([count]) => Number(count) > 0)
|
|
.map(([count, label]) => `${count} ${label}`);
|
|
|
|
return parts.length > 0 ? `Local changes present (${parts.join(", ")})` : "Local changes present";
|
|
}
|
|
|
|
function ServerInfoRow({
|
|
icon: Icon,
|
|
label,
|
|
value,
|
|
dateTime,
|
|
}: {
|
|
icon: LucideIcon;
|
|
label: string;
|
|
value: string;
|
|
dateTime?: string | null;
|
|
}) {
|
|
return (
|
|
<div className="flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left">
|
|
<span className="mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground">
|
|
<Icon className="size-4" />
|
|
</span>
|
|
<span className="min-w-0 flex-1">
|
|
<span className="block text-sm font-medium text-foreground">{label}</span>
|
|
{dateTime ? (
|
|
<time dateTime={dateTime} className="block break-words text-xs text-muted-foreground">
|
|
{value}
|
|
</time>
|
|
) : (
|
|
<span className="block break-words text-xs text-muted-foreground">{value}</span>
|
|
)}
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function SidebarServerInfo() {
|
|
const experimentalQuery = useQuery({
|
|
queryKey: queryKeys.instance.experimentalSettings,
|
|
queryFn: () => instanceSettingsApi.getExperimental(),
|
|
});
|
|
const enabled = experimentalQuery.data?.enableServerInfoDebugView === true;
|
|
const healthQuery = useQuery({
|
|
queryKey: queryKeys.health,
|
|
queryFn: () => healthApi.get(),
|
|
enabled,
|
|
// The drawer only mounts while the account popover is open, so it cannot
|
|
// rely on Layout's background health poll (which is itself gated on
|
|
// devServer.enabled). Always refetch on open and poll while open so a server
|
|
// restart is reflected without leaving stale boot-time serverInfo on screen.
|
|
refetchOnMount: "always",
|
|
refetchInterval: (query) => {
|
|
const data = query.state.data as HealthStatus | undefined;
|
|
return data?.devServer?.enabled ? 2000 : false;
|
|
},
|
|
});
|
|
|
|
if (!enabled) return null;
|
|
|
|
const health = healthQuery.data;
|
|
const isWaitingForHealth = healthQuery.isLoading && !health;
|
|
const healthUnavailable = healthQuery.isError;
|
|
const restartedAt = restartTimestamp(health);
|
|
const restartedAtIsValid = isValidTimestamp(restartedAt);
|
|
const lastRestartedLabel = healthUnavailable
|
|
? "Health unavailable"
|
|
: isWaitingForHealth
|
|
? "Loading..."
|
|
: formatTimestamp(restartedAt);
|
|
const commit = healthUnavailable
|
|
? "Health unavailable"
|
|
: isWaitingForHealth
|
|
? "Loading..."
|
|
: commitLabel(health);
|
|
const localChanges = healthUnavailable
|
|
? "Health unavailable"
|
|
: isWaitingForHealth
|
|
? "Loading..."
|
|
: localChangesLabel(health);
|
|
|
|
return (
|
|
<div className="mt-2 border-t border-border pt-2">
|
|
<p className="px-3 pb-1 pt-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
|
Server
|
|
</p>
|
|
<ServerInfoRow
|
|
icon={Clock3}
|
|
label="Last restarted"
|
|
value={lastRestartedLabel}
|
|
dateTime={!healthUnavailable && !isWaitingForHealth && restartedAtIsValid ? restartedAt : null}
|
|
/>
|
|
<ServerInfoRow icon={GitCommit} label="Running commit" value={commit} />
|
|
<ServerInfoRow icon={FileDiff} label="Checkout state" value={localChanges} />
|
|
</div>
|
|
);
|
|
}
|