From eae42d97d98bcbe707549049b19a99a0161697cd Mon Sep 17 00:00:00 2001 From: g-but <41178744+g-but@users.noreply.github.com> Date: Sun, 31 May 2026 02:36:36 +0200 Subject: [PATCH] fix(projects): surface dirPath + agentPref on bare project cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aec0ef8 dropped the dashed "Add context →" placeholder, leaving bare tiles with just a title. Honest, but the user still had to click in to see anything concrete. user_projects already stores the SSOT for project runtime metadata (dirPath, agentPref) — surfacing it on the card removes the need for that click. DB: add fetchRuntimeMetaByEntityIds() that joins user_projects by entityProjectId. Use in both getProjects and getOrgEntityProjects so the returned ProjectRow gains dirPath + agentPref fields. Single parallel query per page-load alongside fetchAttributesByEntityIds — no N+1. UI: extend the Project type with optional dirPath/agentPref. Render them as small mono chips on truly bare tiles (no description, no status, no maturity, no health signals, no next_step, no extra attrs) — the same gap aec0ef8 left visually empty. dirPath is truncated to the last two path segments (e.g. ".local/share/foo") with the full path in title-tooltip. agentPref renders as a micro- badge. Drops out cleanly when both fields are null. No behavior change on tiles that already render status/maturity/etc. --- src/components/projects/ProjectGrid.tsx | 30 ++++++++++-- src/db/queries/projects.ts | 62 ++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/src/components/projects/ProjectGrid.tsx b/src/components/projects/ProjectGrid.tsx index 50b8800ce..d16447177 100644 --- a/src/components/projects/ProjectGrid.tsx +++ b/src/components/projects/ProjectGrid.tsx @@ -40,6 +40,11 @@ type Project = { description: string | null; attrs: Record; readonly?: boolean; + // Surfaced from user_projects via getProjects join so bare-attr tiles can + // show concrete project context (dir path + preferred agent) instead of + // just a clickable title. + dirPath?: string | null; + agentPref?: string | null; }; function ProjectCard({ @@ -151,11 +156,26 @@ function ProjectCard({ ))} )} - {/* No empty-state placeholder: a card with only a title is less ugly - than a card with a dashed-bordered "Add context →" prompt that - dominates the visual when the user is scanning 20+ tiles. The whole - card is already clickable (onClick on the wrapper) so the affordance - to open the project is preserved. */} + {/* Bare-attr tiles (no description/status/maturity/health/next_step/ + custom attrs) get the dirPath + agentPref from the user_projects + join. Same affordance as the dropped "Add context →" placeholder — + the whole card is clickable — but the user can now see WHERE the + project lives and WHICH agent runs it at a glance. Drops out when + neither field is set (truly unconfigured project). */} + {!description && !status && !maturity && !hasIssues && !nextStep && extraAttrs.length === 0 && (project.dirPath || project.agentPref) && ( +
+ {project.dirPath && ( + + {project.dirPath.replace(/^.*\/([^/]+\/[^/]+)$/, "$1")} + + )} + {project.agentPref && ( + + {project.agentPref} + + )} +
+ )} ); } diff --git a/src/db/queries/projects.ts b/src/db/queries/projects.ts index a041e3784..1cd4b623d 100644 --- a/src/db/queries/projects.ts +++ b/src/db/queries/projects.ts @@ -57,6 +57,32 @@ export async function deleteProject(userId: string, id: string) { return deleted ?? null; } +// Fetch the user_projects runtime metadata (dirPath + agentPref) for a list +// of entity ids. Returned map is keyed by entityProjectId — entities without +// a linked user_projects row are absent (caller treats as null). +// +// user_projects is the SSOT for where the project lives on disk and which +// agent it prefers; the Projects page card needs both so bare-attr tiles show +// concrete context instead of just a clickable title. +async function fetchRuntimeMetaByEntityIds( + entityIds: string[], +): Promise> { + const out = new Map(); + if (entityIds.length === 0) return out; + const rows = await db + .select({ + entityProjectId: userProjects.entityProjectId, + dirPath: userProjects.dirPath, + agentPref: userProjects.agentPref, + }) + .from(userProjects) + .where(inArray(userProjects.entityProjectId, entityIds)); + for (const r of rows) { + if (r.entityProjectId) out.set(r.entityProjectId, { dirPath: r.dirPath, agentPref: r.agentPref }); + } + return out; +} + export async function getProjects(userId: string) { const projects = await db .select() @@ -69,12 +95,21 @@ export async function getProjects(userId: string) { ) .orderBy(entities.name); - const attrsByEntity = await fetchAttributesByEntityIds(projects.map((p) => p.id)); + const ids = projects.map((p) => p.id); + const [attrsByEntity, runtimeByEntity] = await Promise.all([ + fetchAttributesByEntityIds(ids), + fetchRuntimeMetaByEntityIds(ids), + ]); - return projects.map((p) => ({ - ...p, - attrs: attrsByEntity.get(p.id) ?? {}, - })); + return projects.map((p) => { + const runtime = runtimeByEntity.get(p.id) ?? { dirPath: null, agentPref: null }; + return { + ...p, + attrs: attrsByEntity.get(p.id) ?? {}, + dirPath: runtime.dirPath, + agentPref: runtime.agentPref, + }; + }); } export type ProjectRow = Awaited>[number]; @@ -88,8 +123,21 @@ export async function getOrgEntityProjects(userId: string): Promise<(ProjectRow .from(entities) .where(and(inArray(entities.userId, peerIds), eq(entities.type, ENTITY_TYPE.PROJECT))) .orderBy(entities.name); - const attrsByEntity = await fetchAttributesByEntityIds(projects.map((p) => p.id)); - return projects.map((p) => ({ ...p, attrs: attrsByEntity.get(p.id) ?? {}, readonly: true as const })); + const ids = projects.map((p) => p.id); + const [attrsByEntity, runtimeByEntity] = await Promise.all([ + fetchAttributesByEntityIds(ids), + fetchRuntimeMetaByEntityIds(ids), + ]); + return projects.map((p) => { + const runtime = runtimeByEntity.get(p.id) ?? { dirPath: null, agentPref: null }; + return { + ...p, + attrs: attrsByEntity.get(p.id) ?? {}, + dirPath: runtime.dirPath, + agentPref: runtime.agentPref, + readonly: true as const, + }; + }); } /**