forked from farhoodlabs/paperclip
f257530537
## Thinking Path > - Paperclip operators spend most of their time scanning the board, inbox, sidebar, and local dev status surfaces > - Small UI and dev-ops frictions make repeated operator workflows feel slower than they need to be > - The working branch contained several independent quality-of-life improvements mixed with larger cloud work > - Grouping these smaller UI/dev-ops changes together keeps review overhead reasonable without merging them into feature PRs > - This pull request collects the operator-facing QoL polish into one standalone branch > - The benefit is a cleaner board navigation and local dev recovery experience without depending on cloud upstream sync ## What Changed - Relaxed forced 44px touch targets for small inline widgets. - Fixed mobile mention menu scrolling and sidebar spacing on touch/mobile layouts. - Synced inbox hover state with j/k selection. - Moved plugin sidebar entries into the Work section. - Added manual dev-server restart action/banner behavior. - Logged plugin bridge 502 causes for better diagnosis. ## Verification - `pnpm install --frozen-lockfile --ignore-scripts` - `pnpm --filter @paperclipai/plugin-sdk build` - `pnpm exec vitest run ui/src/components/MarkdownEditor.test.tsx ui/src/components/Sidebar.test.tsx ui/src/components/SidebarProjects.test.tsx ui/src/pages/Inbox.test.tsx ui/src/components/DevRestartBanner.test.tsx server/src/__tests__/dev-server-status.test.ts server/src/__tests__/health-dev-server-token.test.ts server/src/__tests__/plugin-routes-authz.test.ts` initially failed only because plugin SDK `dist` was not built in the fresh worktree. - Rerun after build: `pnpm exec vitest run server/src/__tests__/plugin-routes-authz.test.ts` passed. - The remaining targeted UI/dev-server tests passed on the first post-install run. ## Visual Evidence - Sidebar layout and plugin Work section:  - Inbox/task row selection and hover-state surface:  - Dev restart banner desktop:  - Dev restart banner mobile:  ## Risks - Mostly UI/dev ergonomics with low data risk. - Sidebar and inbox changes touch frequently used navigation surfaces, so visual review on desktop/mobile is still useful. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - OpenAI Codex, GPT-5-based coding agent with local shell/git/tool use. Exact hosted model ID and context-window size are not exposed by the local Paperclip adapter runtime. ## 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
184 lines
6.0 KiB
TypeScript
184 lines
6.0 KiB
TypeScript
import { timingSafeEqual } from "node:crypto";
|
|
import { Router } from "express";
|
|
import type { Db } from "@paperclipai/db";
|
|
import { and, count, eq, gt, inArray, isNull, sql } from "drizzle-orm";
|
|
import { heartbeatRuns, instanceUserRoles, invites } from "@paperclipai/db";
|
|
import type { DeploymentExposure, DeploymentMode } from "@paperclipai/shared";
|
|
import { readPersistedDevServerStatus, toDevServerHealthStatus, writeDevServerRestartRequest } from "../dev-server-status.js";
|
|
import { logger } from "../middleware/logger.js";
|
|
import { instanceSettingsService } from "../services/instance-settings.js";
|
|
import { serverVersion } from "../version.js";
|
|
|
|
function shouldExposeFullHealthDetails(
|
|
actorType: "none" | "board" | "agent" | null | undefined,
|
|
deploymentMode: DeploymentMode,
|
|
) {
|
|
if (deploymentMode !== "authenticated") return true;
|
|
return actorType === "board" || actorType === "agent";
|
|
}
|
|
|
|
function hasDevServerStatusToken(providedToken: string | undefined) {
|
|
const expectedToken = process.env.PAPERCLIP_DEV_SERVER_STATUS_TOKEN?.trim();
|
|
const token = providedToken?.trim();
|
|
if (!expectedToken || !token) return false;
|
|
|
|
const expected = Buffer.from(expectedToken);
|
|
const provided = Buffer.from(token);
|
|
if (expected.length !== provided.length) return false;
|
|
return timingSafeEqual(expected, provided);
|
|
}
|
|
|
|
export function healthRoutes(
|
|
db?: Db,
|
|
opts: {
|
|
deploymentMode: DeploymentMode;
|
|
deploymentExposure: DeploymentExposure;
|
|
authReady: boolean;
|
|
companyDeletionEnabled: boolean;
|
|
} = {
|
|
deploymentMode: "local_trusted",
|
|
deploymentExposure: "private",
|
|
authReady: true,
|
|
companyDeletionEnabled: true,
|
|
},
|
|
) {
|
|
const router = Router();
|
|
|
|
router.post("/dev-server/restart", async (req, res) => {
|
|
const actorType = "actor" in req ? req.actor?.type : null;
|
|
if (opts.deploymentMode === "authenticated" && actorType !== "board") {
|
|
res.status(403).json({ error: "board_access_required" });
|
|
return;
|
|
}
|
|
|
|
const persistedDevServerStatus = readPersistedDevServerStatus();
|
|
if (!persistedDevServerStatus) {
|
|
res.status(404).json({ error: "dev_server_supervisor_unavailable" });
|
|
return;
|
|
}
|
|
|
|
const restartRequired =
|
|
persistedDevServerStatus.dirty ||
|
|
persistedDevServerStatus.changedPathCount > 0 ||
|
|
persistedDevServerStatus.pendingMigrations.length > 0;
|
|
if (!restartRequired) {
|
|
res.status(409).json({ error: "restart_not_required" });
|
|
return;
|
|
}
|
|
|
|
const written = writeDevServerRestartRequest({
|
|
requestedAt: new Date().toISOString(),
|
|
reason: "manual_restart_now",
|
|
});
|
|
if (!written) {
|
|
res.status(404).json({ error: "dev_server_supervisor_unavailable" });
|
|
return;
|
|
}
|
|
|
|
res.status(202).json({ status: "restart_requested" });
|
|
});
|
|
|
|
router.get("/", async (req, res) => {
|
|
const actorType = "actor" in req ? req.actor?.type : null;
|
|
const exposeFullDetails = shouldExposeFullHealthDetails(
|
|
actorType,
|
|
opts.deploymentMode,
|
|
);
|
|
const exposeDevServerDetails =
|
|
exposeFullDetails || hasDevServerStatusToken(req.get("x-paperclip-dev-server-status-token"));
|
|
|
|
if (!db) {
|
|
res.json(
|
|
exposeFullDetails
|
|
? { status: "ok", version: serverVersion }
|
|
: { status: "ok", deploymentMode: opts.deploymentMode },
|
|
);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await db.execute(sql`SELECT 1`);
|
|
} catch (error) {
|
|
logger.warn({ err: error }, "Health check database probe failed");
|
|
res.status(503).json({
|
|
status: "unhealthy",
|
|
version: serverVersion,
|
|
error: "database_unreachable"
|
|
});
|
|
return;
|
|
}
|
|
|
|
let bootstrapStatus: "ready" | "bootstrap_pending" = "ready";
|
|
let bootstrapInviteActive = false;
|
|
if (opts.deploymentMode === "authenticated") {
|
|
const roleCount = await db
|
|
.select({ count: count() })
|
|
.from(instanceUserRoles)
|
|
.where(sql`${instanceUserRoles.role} = 'instance_admin'`)
|
|
.then((rows) => Number(rows[0]?.count ?? 0));
|
|
bootstrapStatus = roleCount > 0 ? "ready" : "bootstrap_pending";
|
|
|
|
if (bootstrapStatus === "bootstrap_pending") {
|
|
const now = new Date();
|
|
const inviteCount = await db
|
|
.select({ count: count() })
|
|
.from(invites)
|
|
.where(
|
|
and(
|
|
eq(invites.inviteType, "bootstrap_ceo"),
|
|
isNull(invites.revokedAt),
|
|
isNull(invites.acceptedAt),
|
|
gt(invites.expiresAt, now),
|
|
),
|
|
)
|
|
.then((rows) => Number(rows[0]?.count ?? 0));
|
|
bootstrapInviteActive = inviteCount > 0;
|
|
}
|
|
}
|
|
|
|
const persistedDevServerStatus = readPersistedDevServerStatus();
|
|
let devServer: ReturnType<typeof toDevServerHealthStatus> | undefined;
|
|
if (exposeDevServerDetails && persistedDevServerStatus && typeof (db as { select?: unknown }).select === "function") {
|
|
const instanceSettings = instanceSettingsService(db);
|
|
const experimentalSettings = await instanceSettings.getExperimental();
|
|
const activeRunCount = await db
|
|
.select({ count: count() })
|
|
.from(heartbeatRuns)
|
|
.where(inArray(heartbeatRuns.status, ["queued", "running"]))
|
|
.then((rows) => Number(rows[0]?.count ?? 0));
|
|
|
|
devServer = toDevServerHealthStatus(persistedDevServerStatus, {
|
|
autoRestartEnabled: experimentalSettings.autoRestartDevServerWhenIdle ?? false,
|
|
activeRunCount,
|
|
});
|
|
}
|
|
|
|
if (!exposeFullDetails) {
|
|
res.json({
|
|
status: "ok",
|
|
deploymentMode: opts.deploymentMode,
|
|
bootstrapStatus,
|
|
bootstrapInviteActive,
|
|
...(devServer ? { devServer } : {}),
|
|
});
|
|
return;
|
|
}
|
|
|
|
res.json({
|
|
status: "ok",
|
|
version: serverVersion,
|
|
deploymentMode: opts.deploymentMode,
|
|
deploymentExposure: opts.deploymentExposure,
|
|
authReady: opts.authReady,
|
|
bootstrapStatus,
|
|
bootstrapInviteActive,
|
|
features: {
|
|
companyDeletionEnabled: opts.companyDeletionEnabled,
|
|
},
|
|
...(devServer ? { devServer } : {}),
|
|
});
|
|
});
|
|
|
|
return router;
|
|
}
|