fix(context): fold submodule cwd sessions into the parent repo memory (closes #2842)#2856
fix(context): fold submodule cwd sessions into the parent repo memory (closes #2842)#2856rodboev wants to merge 9 commits into
Conversation
Greptile SummaryThis PR fixes context injection for sessions launched inside a git submodule by teaching
Confidence Score: 5/5Safe to merge — the change is tightly scoped to the .git-file parsing path and does not touch worktree naming, context rendering, or search semantics. The submodule regex correctly extracts the outermost parent repo path via non-greedy capture, the validContextRoot guard prevents ancestor-worktree overshoot for both worktree and submodule shapes, and the new test suite covers the root-dir case, the nested-subdirectory case, and the ancestor-worktree isolation case. Existing worktree tests are green. No data is mutated; the change only affects which project name is returned. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["getProjectContext(cwd)"] --> B["findNearestGitContextRoot(cwd)"]
B --> C{".git file at current dir?"}
C -- No --> D["Walk up to parent dir"]
D --> C
C -- Yes --> E["detectWorktree(dir)"]
E --> F{gitdir pattern}
F -- ".git/worktrees/*" --> G["kind: worktree"]
F -- ".git/modules/* NEW" --> H["kind: submodule"]
F -- other --> I["NOT_A_WORKTREE"]
G --> J["contextRoot = dir"]
H --> J
J --> K["validContextRoot check: contextRoot inside repoRoot?"]
K -- No ancestor overshoot --> L["validContextRoot = null"]
K -- Yes --> M["validContextRoot = contextRoot"]
L --> N["detectWorktree(repoRoot ?? cwd)"]
M --> N
N --> P{isWorktree?}
P -- Yes --> Q["primary = parent/worktree\nallProjects = parent + composite"]
P -- No --> R{isSubmodule NEW}
R -- Yes --> S["primary = parentProjectName\nallProjects = parentProjectName only"]
R -- No --> T["primary = cwdProjectName"]
Reviews (5): Last reviewed commit: "fix(context): reject unrelated ancestor ..." | Re-trigger Greptile |
|
Reworked |
|
Addressed the ancestor-worktree false positive Greptile flagged.
Focused checks after the patch:
|
|
Review finding that blocks this one: relative |
Summary
Sessions launched inside a git submodule were resolving to the submodule leaf directory as a brand-new project, so context injection hit the empty-state path even when the parent repo already had substantial memory. This change teaches the
.gitindirection parser to recognize.git/modules/*layouts and updatesgetProjectContext()to include the parent repo project for submodule cwd sessions.Why
detectWorktree()insrc/utils/worktree.ts:20-55only recognized.git/worktrees/*, so a submodule.gitfile pointing at.git/modules/*always fell through toNOT_A_WORKTREE.getProjectContext()insrc/utils/project-name.ts:83-96then returnedallProjects: [cwdProjectName], andgenerateContext()insrc/services/context/ContextBuilder.ts:107-125queried only that empty leaf project. Recognizing the submodule parent in the same parsing path fixes the lookup without adding route-specific fallback logic.Scope
This PR is limited to project-context resolution for submodule cwd sessions. It does not add a configurable submodule namespacing mode, and it does not change current worktree naming, context rendering, or search-query semantics outside the project list produced by
getProjectContext().Risk
The behavior change is confined to cwds whose
.gitfile points at.git/modules/*. Ordinary repos and current worktree handling should remain unchanged, but the project-context tests need to keep both branches covered because the parent-project merge logic now has two valid.gitindirection shapes instead of one.Verification / Test plan
bun test tests/utils/project-name.test.ts --test-name-pattern "submodule|worktree isolation"— 4 passed; new submodule and existing worktree context coverage are green.bun test tests/utils/project-name.test.ts— 20 passed, 2 failed on pre-existing Windows~expectations that currently expectC:\Users\Rodinstead of the actual basenameRod; unchanged by this branch.bun test tests/hooks/file-context.test.ts tests/worker/http/routes/search-routes-welcome-hint.test.ts— 13 passed; multi-project context injection still queries both projects for worktrees.npm run build— passed after wiring the worktree to the existing reponode_modules; regeneratedplugin/scripts/context-generator.cjsfrom the project-context source change.npm run lint:hook-io && npm run lint:spawn-env— passed.npm run strip-comments:check— fails on the existing repo-wide baseline (Changed: 301in check mode), unrelated to this branch.Closes #2842