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, + }; + }); } /**