fix(context): derive project from explicit projects array, not cwd

When a caller (e.g. worker context-inject route) passes a `projects`
array without a matching cwd, the cwd-derived `context.primary` drifted
from the projects being queried — producing an empty-state header for
one project while querying another. Use the last entry of `projects` so
header and query target stay in sync.
This commit is contained in:
Alex Newman
2026-04-16 17:16:51 -07:00
parent 148e1892df
commit 3869b083d0
3 changed files with 7 additions and 4 deletions
+5 -2
View File
@@ -130,11 +130,14 @@ export async function generateContext(
const config = loadContextConfig();
const cwd = input?.cwd ?? process.cwd();
const context = getProjectContext(cwd);
const project = context.primary;
const platformSource = input?.platform_source;
// Use provided projects array (for worktree support) or fall back to all known projects
// Single source of truth: explicit projects override cwd-derived context.
// `project` (used for header + single-project query) is always the last entry
// of `projects` so the empty-state header and the query target stay in sync
// when a caller passes `projects` without a matching cwd (e.g. worker route).
const projects = input?.projects ?? context.allProjects;
const project = projects[projects.length - 1];
// Full mode: fetch all observations but keep normal rendering (level 1 summaries)
if (input?.full) {