mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-17 03:39:33 +01:00
feat(files): follow the agent into a worktree outside the session folder
#772 made the Files panel follow an agent into a worktree inside the session's folder. A worktree beside the repository (git worktree add ../feature, or an EnterWorktree into one that already exists there) stayed unfollowed, since serving it needs a second confinement root. findOutsideWorktree() answers that case without running git. The nearest .git above the pane must name <common dir>/worktrees/<id> of the session's own repository, and that registry entry must name the candidate back (or the .git folder must be the common dir itself). It refuses /, the home folder and above, any folder holding workingDir and Docker case workspaces, and multi-user mode applies the owner's folderAllowedForUser rule. The answer is liveWorktree with outside: true and the folder's real path. The file routes serve an absolute path inside that worktree, and only while the folder still resolves to the recorded path. A relative path still resolves against workingDir alone. The browser routes such paths to the editable preview, and root-relative markdown refs resolve from the top of the worktree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e9b2ecd552
commit
c9b79097b0
18 files changed
+1030
-56
No files matched your search
@@ -4264,7 +4264,24 @@ Object.assign(CodemanApp.prototype, {
|
||||
const workingDir = this.sessions.get(sessionId)?.workingDir;
|
||||
if (!workingDir) return false;
|
||||
const root = workingDir.endsWith('/') ? workingDir : `${workingDir}/`;
|
||||
return filePath !== workingDir && !filePath.startsWith(root);
|
||||
if (filePath === workingDir || filePath.startsWith(root)) return false;
|
||||
// A worktree outside `workingDir` that the agent is in (#765) is a second root the file
|
||||
// routes serve, so a path inside it previews (and edits) like a workspace path.
|
||||
return this._isOutsideWorktreePath?.(filePath, sessionId) !== true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether an absolute path lies inside the worktree OUTSIDE `workingDir` that the session's agent
|
||||
* is in (`liveWorktree.outside`, #765). The file routes serve it as a second root, while the log
|
||||
* viewer's `tail-file` stays confined to `workingDir`, so the terminal opens such a path in the
|
||||
* file preview.
|
||||
*/
|
||||
_isOutsideWorktreePath(filePath, sessionId) {
|
||||
if (typeof filePath !== 'string' || !filePath.startsWith('/')) return false;
|
||||
const worktree = this.sessions?.get?.(sessionId)?.liveWorktree;
|
||||
if (worktree?.outside !== true || typeof worktree.path !== 'string' || !worktree.path) return false;
|
||||
const root = worktree.path.endsWith('/') ? worktree.path : `${worktree.path}/`;
|
||||
return filePath === worktree.path || filePath.startsWith(root);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -5197,6 +5214,13 @@ Object.assign(CodemanApp.prototype, {
|
||||
_rebaseFilePreviewMarkdownRefs(root, { sessionId, filePath, attachmentId }) {
|
||||
const dir = filePath.includes('/') ? filePath.slice(0, filePath.lastIndexOf('/') + 1) : '';
|
||||
const unresolvable = !!attachmentId && !filePath.startsWith('/');
|
||||
// A root-relative ref (`/docs/x.png`) resolves from the top of the checkout the file is in, as
|
||||
// on GitHub: the workspace, or the worktree outside it that the agent is in (#765).
|
||||
const worktree = this.sessions?.get?.(sessionId)?.liveWorktree;
|
||||
const rootPrefix =
|
||||
worktree?.outside === true && this._isOutsideWorktreePath?.(filePath, sessionId)
|
||||
? `${worktree.path.replace(/\/+$/, '')}/`
|
||||
: '';
|
||||
// Workspace ref = no scheme, not protocol-relative (//host), not a fragment.
|
||||
const isWorkspaceRef = (ref) =>
|
||||
!!ref && !/^[a-z][a-z0-9+.-]*:/i.test(ref) && !ref.startsWith('//') && !ref.startsWith('#');
|
||||
@@ -5216,7 +5240,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
/* malformed escape: keep the ref as written */
|
||||
}
|
||||
const parts = [];
|
||||
for (const seg of (rel.startsWith('/') ? rel.slice(1) : dir + rel).split('/')) {
|
||||
for (const seg of (rel.startsWith('/') ? rootPrefix + rel.slice(1) : dir + rel).split('/')) {
|
||||
if (seg === '.' || (seg === '' && parts.length)) continue;
|
||||
if (seg === '..' && parts.length && parts[parts.length - 1] !== '..' && parts[parts.length - 1] !== '') parts.pop();
|
||||
else parts.push(seg);
|
||||
|
||||
@@ -2367,7 +2367,13 @@ Object.assign(CodemanApp.prototype, {
|
||||
}
|
||||
// An HTML file renders as a page in the preview, never as source
|
||||
// in the log viewer (markdown is in FILE_PREVIEW_EXTENSIONS).
|
||||
if (previewsInFileViewer(target) || rendersAsPage(target) || self._isExternalPreviewPath(target, sessionId)) {
|
||||
// The log viewer's tail-file stays confined to workingDir, so a path in a worktree outside it previews.
|
||||
if (
|
||||
previewsInFileViewer(target) ||
|
||||
rendersAsPage(target) ||
|
||||
self._isExternalPreviewPath(target, sessionId) ||
|
||||
self._isOutsideWorktreePath?.(target, sessionId)
|
||||
) {
|
||||
self.openFilePreview(target, sessionId);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user