Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@
)}
<SessionModal
sessionId={openSessionId}
repoDir={branches.find((b) => b.worktreePath)?.worktreePath ?? null}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Shorten project-session paths from the project root

For project notes opened from ProjectSection, the backend creates the session with working_dir = project_worktree_root_for(project.id) (apps/staged/src-tauri/src/session_commands.rs:457-479), so tool-call paths should be made relative to that project root. Passing the first branch's worktreePath here makes one arbitrary repo look like the root: paths in that repo collapse to src/..., while paths in sibling repos still render as other-repo--branch/.... In multi-repo projects this produces a misleading transcript, because reviewers can no longer tell which repo the coordinator session actually accessed.

Useful? React with 👍 / 👎.

projectId={project.id}
noteInfo={noteForSession
? { id: noteForSession.id, title: noteForSession.title, content: noteForSession.content }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@

<!-- Open SessionModals — one per open session, stacked -->
{#each [...openModals] as modalSessionId (modalSessionId)}
<SessionModal sessionId={modalSessionId} onClose={() => closeModal(modalSessionId)} />
<SessionModal
sessionId={modalSessionId}
repoDir={null}
onClose={() => closeModal(modalSessionId)}
/>
{/each}

<style>
Expand Down
20 changes: 18 additions & 2 deletions apps/staged/src/lib/features/sessions/sessionModalHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,27 @@ export function parseToolCall(content: string): ParsedToolCall | null {
/**
* Replace absolute paths that fall within `repoDir` with relative paths.
* If repoDir is empty/null, returns the text unchanged.
*
* When the exact `repoDir` prefix isn't found in the text, ancestor directories
* are tried (up to 3 levels). This handles the common case where the session's
* working directory includes a repo subpath (e.g. `worktree_root/apps/staged`)
* but tool call paths reference the worktree root directly.
*/
export function makePathsRelative(text: string, repoDir: string | null | undefined): string {
if (!repoDir) return text;
const prefix = repoDir.endsWith('/') ? repoDir : repoDir + '/';
return text.replaceAll(prefix, '');

let dir = repoDir;
for (let i = 0; i < 4; i++) {
const prefix = dir.endsWith('/') ? dir : dir + '/';
if (text.includes(prefix)) {
return text.replaceAll(prefix, '');
}
const parentEnd = dir.lastIndexOf('/');
if (parentEnd <= 0) break;
dir = dir.slice(0, parentEnd);
}

return text;
}

const TOOL_VERBS: Record<string, [past: string, present: string]> = {
Expand Down