feat: default sessions list to cwd project + fix sqlite timestamps#7
Open
buihongduc132 wants to merge 9 commits intoshuv1337:masterfrom
Open
feat: default sessions list to cwd project + fix sqlite timestamps#7buihongduc132 wants to merge 9 commits intoshuv1337:masterfrom
buihongduc132 wants to merge 9 commits intoshuv1337:masterfrom
Conversation
added 3 commits
February 21, 2026 02:56
- Add --global flag to list all sessions (default: cwd project only) - Add inferProjectFromCwd() with nested project support - Validate --global and --project mutual exclusion - Fix SQLite timestamp display by adding time_created/time_updated to column fallbacks - Add 10 tests covering cwd filtering, nested projects, ambiguous matches, symlinks
- Update tests to use --global flag for listing all sessions - Preserves original test behavior after default changed to cwd filtering - All cwd filtering tests still pass
| for (const project of projects) { | ||
| const worktree = project.worktree | ||
| // Check if cwd is inside or equal to worktree | ||
| if (cwd === worktree || cwd.startsWith(worktree + "/")) { |
There was a problem hiding this comment.
hardcoded / separator won't work on Windows - use path.sep instead
Suggested change
| if (cwd === worktree || cwd.startsWith(worktree + "/")) { | |
| if (cwd === worktree || cwd.startsWith(worktree + path.sep)) { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/commands/sessions.ts
Line: 253
Comment:
hardcoded `/` separator won't work on Windows - use `path.sep` instead
```suggestion
if (cwd === worktree || cwd.startsWith(worktree + path.sep)) {
```
How can I resolve this? If you propose a fix, please make it concise.| // Check if cwd is inside or equal to worktree | ||
| if (cwd === worktree || cwd.startsWith(worktree + "/")) { | ||
| // Depth is the number of path segments in worktree | ||
| const depth = worktree.split("/").length |
There was a problem hiding this comment.
hardcoded / separator won't work on Windows - use path.sep instead
Suggested change
| const depth = worktree.split("/").length | |
| const depth = worktree.split(path.sep).length |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/commands/sessions.ts
Line: 255
Comment:
hardcoded `/` separator won't work on Windows - use `path.sep` instead
```suggestion
const depth = worktree.split(path.sep).length
```
How can I resolve this? If you propose a fix, please make it concise.
Comment on lines
+208
to
+235
| it("resolves symlinks when matching cwd to projects", async () => { | ||
| const { tempDir, storeRoot, cleanup } = await createTempStore(); | ||
| try { | ||
| const realDir = join(tempDir, "worktrees", "real"); | ||
| const linkDir = join(tempDir, "worktrees", "link"); | ||
| await fs.mkdir(realDir, { recursive: true }); | ||
| await fs.symlink(realDir, linkDir); | ||
|
|
||
| await writeProject(storeRoot, "proj_real", realDir); | ||
| await writeSession(storeRoot, "proj_real", "session_real", realDir, "Realpath match"); | ||
|
|
||
| const shellPromise = $`bun ${CLI_PATH} sessions list --root ${storeRoot} --format json`.cwd(linkDir).quiet(); | ||
| const result = await Promise.race([ | ||
| shellPromise, | ||
| new Promise<never>((_, reject) => | ||
| setTimeout(() => reject(new Error("CLI command timed out after 30s")), 30000) | ||
| ), | ||
| ]); | ||
| const output = result.stdout.toString(); | ||
| const parsed = JSON.parse(output); | ||
|
|
||
| expect(parsed.ok).toBe(true); | ||
| expect(parsed.data.length).toBe(1); | ||
| expect(parsed.data[0].sessionId).toBe("session_real"); | ||
| } finally { | ||
| await cleanup(); | ||
| } | ||
| }); |
There was a problem hiding this comment.
test description is misleading - the code doesn't explicitly resolve symlinks. It works because process.cwd() automatically returns the canonical path (POSIX behavior).
Also missing reverse scenario: what if a project is registered with a symlink path but user cds into it? That would fail because stored paths aren't canonicalized.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/cli/commands/sessions-cwd-filter.test.ts
Line: 208-235
Comment:
test description is misleading - the code doesn't explicitly resolve symlinks. It works because `process.cwd()` automatically returns the canonical path (POSIX behavior).
Also missing reverse scenario: what if a project is registered with a symlink path but user `cd`s into it? That would fail because stored paths aren't canonicalized.
How can I resolve this? If you propose a fix, please make it concise.
added 6 commits
February 21, 2026 05:45
- Add tests for project registered via symlink path - process.cwd() resolves symlinks, but worktree paths don't - Bug: project registered via symlink won't match when running from real path - Also add tests for path prefix collision and trailing slashes
- Use fs.realpath() to resolve worktree paths before comparison - process.cwd() already resolves symlinks, so worktree must too - Handle case where realpath fails (non-existent path) - Normalize trailing slashes for consistent comparison - Fixes: project registered via symlink wouldn't match when running from real path
- Compare latest session timestamps between SQLite and JSONL stores - Prefer SQLite when it has fresher data than JSONL - Fall back to JSONL when SQLite unavailable or older - Add helper functions to scan both stores for latest timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements cwd-based filtering for
sessions listand fixes a critical bug where SQLite timestamps weren't displaying.Changes
Feature: CWD-based session filtering
sessions listnow defaults to showing sessions for the current working directory's project--globalflag to list all sessions (previous default behavior)inferProjectFromCwd()helper with support for:Bug fix: SQLite timestamp display
time_createdandtime_updatedto column name fallback listTests
--globalflag functionality--search+ cwd intersection semantics--global+--project)--globalflag where neededVerification
Example usage
Commits
62c69ed- test: expand CLI coverage for sqlite rename/copy and root/TUI behavior3cecb34- feat: default sessions list to cwd project, fix sqlite timestampsc7a55a1- fix: add --global flag to tests after cwd filtering implementationGreptile Summary
This PR implements cwd-based filtering for
sessions listand fixes SQLite timestamp display. Thesessions listcommand now defaults to showing sessions for the current directory's project, with a--globalflag to list all sessions.Key changes:
inferProjectFromCwd()helper that finds projects matching the current working directory (deepest match wins)time_createdandtime_updatedto column fallback list--globalflag to list all sessions (previous default behavior)Issues found:
/separator instead ofpath.sep(lines 253, 255 in sessions.ts)getcwd()behaviorConfidence Score: 3/5
src/cli/commands/sessions.ts- fix Windows path separator issues before mergingImportant Files Changed
inferProjectFromCwd()helper, but has symlink handling bug and Windows path compatibility issuetime_createdandtime_updatedto column fallback listFlowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD Start[sessions list command] --> CheckFlags{Flags provided?} CheckFlags -->|--global| Global[List all sessions] CheckFlags -->|--project <id>| Project[Filter by project ID] CheckFlags -->|neither| InferCwd[inferProjectFromCwd] InferCwd --> LoadProjects[Load all projects] LoadProjects --> GetCwd[Get process.cwd] GetCwd --> FindCandidates{Find matching projects} FindCandidates -->|No matches| ErrorNoProject[Error: No project found] FindCandidates -->|One match| UseDeepest[Use deepest match] FindCandidates -->|Multiple at same depth| ErrorAmbiguous[Error: Ambiguous match] UseDeepest --> FilterSessions[Filter sessions by project] Project --> FilterSessions Global --> LoadAllSessions[Load all sessions] FilterSessions --> ApplySearch{--search provided?} LoadAllSessions --> ApplySearch ApplySearch -->|Yes| FuzzySearch[Apply fuzzy search] ApplySearch -->|No| Output[Output sessions] FuzzySearch --> OutputLast reviewed commit: c7a55a1
(2/5) Greptile learns from your feedback when you react with thumbs up/down!