From 91d157cae44a676812181a39c5b5dcae575bf4e9 Mon Sep 17 00:00:00 2001 From: Codeman maintainer Date: Wed, 4 Nov 2026 16:59:16 +0100 Subject: [PATCH] fix: name the pane directory field paneCwd and apply the review items for #740 `cwd` beside the fixed `workingDir` reads ambiguously on a public API surface, and `paneCwd` says where the value comes from, like `paneExit`. Also pin the field on the payload the browser really receives (getSessionStateWithRespawn), and give the pane-directory text its own architecture-invariants paragraph. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- docs/api-reference.md | 4 +- docs/architecture-invariants.md | 4 +- src/session.ts | 16 ++--- src/tmux-manager.ts | 4 +- src/types/session.ts | 2 +- src/web/public/constants.js | 12 ++-- src/web/server.ts | 4 +- test/pane-cwd-tracking.test.ts | 105 ++++++++++++++++++-------------- 9 files changed, 83 insertions(+), 70 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 50b0286b..f6858000 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -226,7 +226,7 @@ Codeman is a Claude Code session manager with web interface and autonomous Ralph **Prompt uploads** (`POST /api/sessions/:id/paste-image`: clipboard paste, drop, the Compose Attach key and the phone toolbar's Attach button; client wiring in `image-input.js` and `keyboard-accessory.js`): a pick is written to `/.codeman-uploads/` and its path lands on the prompt as unsent text. The folder is IN the workspace because that is the only path identical for a local and a container agent, FLAT because `/.codeman/` would BE the data dir when the workspace is the home directory, and self-ignoring through a `.gitignore` of `*` written ONCE with `wx` (a file already there is the user's and is never overwritten; the user's own ignore file is never touched). ⚠️ The directory names live ONLY in `paste-image-gc.ts` (`UPLOAD_DIR_NAMES`): the pre-move `.claude-images/` receives nothing but stays readable for one release, so the GC sweep and the delete cleanup (through `uploadDirs()`) and the image watcher's ignore filter (reading the names) cover BOTH; retire the legacy entry there, never by hand elsewhere. ⚠️ `uploadDirs()` is async and probes the workspace BOUNDED first (`probePathKind()`, the #516 rule: an `unknown` path is skipped, never touched; the sweep keeps the stall cap and the delete passes `pastCap`), then returns only REAL directories (lstat, so a planted symlink is never one), none that is or contains `getDataDir()` (one strictly inside it only holds uploads and is listed), and none for a remote session, since both consumers delete; the check is made at list time, and the same-user race after it is accepted. Images are buffered in memory under `MAX_PASTE_IMAGE_BYTES` (50MB) after a client-side canvas re-encode; a DOCUMENT (pdf, docx, pptx, xlsx, zip and the text family txt/md/csv/tsv/json/log/yaml/yml/xml; the curated `ALLOWED_DOCUMENT_EXTS`, never `SUPPORTED_ATTACHMENT_EXTENSIONS` or `EDITABLE_EXTENSIONS`, which carry sh/py/js/html) is admitted by its name's extension alone, buffered like an image, judged on its bytes by the same fail-closed `imageMagicMatchesExt` (`%PDF-`, `PK\x03\x04` for the OOXML trio and zip, UTF-8 without a NUL byte for text: a SIGNATURE or ENCODING check, never a structure or content check, so generic zip bytes pass as `.docx` and a script renamed `.txt` is text; the sh/py/js/html exclusion is a SCOPE choice by extension, keeping the server from storing what it would serve or run, not a content filter: the agent can already write any of those) and saved as `paste---` with a sanitized stem (`[A-Za-z0-9._-]`, 40 chars, a wholly non-ASCII name leaves no stem; the `paste-` prefix is what the GC matches). A VIDEO is never buffered: `?kind=video` streams it to disk under `MAX_PASTE_VIDEO_BYTES` (1GB, env `CODEMAN_MAX_PASTE_VIDEO_BYTES`), judges the container on the first 12 bytes as they arrive (ISO BMFF / QuickTime atom, EBML for webm, Ogg for ogv; a mislabeled body is drained unwritten from there, never parked on disk first) and unlinks on any failure, a dead transfer included. ⚠️ The flag is the ONLY way onto that path and admits video types alone (the registry's `VIDEO_ATTACHMENT_EXTENSIONS`, single-sourced: mp4/webm/mov/m4v/ogv, so an uploaded video is one the file viewer can also play; 3gp/mkv are out, since a phone's camera roll produces neither and neither previews), so an image can never ride the larger cap through memory; without it the route is byte-identical to the image-only version. Busboy takes its size limit before the part is seen, which is why the choice rides the URL and not the file. ⚠️ A video draws on its OWN per-(IP, session) rate bucket (`consumeVideoToken`, 3/min) beside the image bucket (`consumePasteToken`, 30/min): at 1GB each, 30/min would be 30GB of disk a minute, so the lower rate bounds it to 3GB; the image path keeps the 30/min bucket and is unchanged without the flag. A remote (SSH) session is refused (400) before any disk touch: its `workingDir` is the remote path, so the file would land on THIS host where the agent cannot read it (Docker is fine, the workspace is bind-mounted at the same absolute path). ⚠️ A live session's workspace can still sit on a network mount that stopped answering, so the route probes it BOUNDED (`probePathKind(session.workingDir, { pastCap: true })`, the #516 rule) before the first disk touch and refuses an `unknown` mount through `describeUnknownPath()` (OPERATION_FAILED), the way session create does, so a mount already unreachable cannot freeze a libuv worker on every upload (a mount that dies after the probe is the same residual race create accepts). ⚠️ Dispatch mirrors the client: an `image/*` MIME takes the IMAGE path whatever the name says (a GIF named `animation.txt` stays a GIF), a document extension takes the document branch, and anything else takes the image path exactly as before, where the HEIC sniff still recovers a HEIC under a generic name; a foreign extension with no image MIME gets its `Unsupported file type` 400 only AFTER that sniff fails, never before, so nothing the image path ever accepted by its bytes is refused. A text mismatch is refused as not UTF-8 text (UTF-16 when the file opens with a UTF-16 BOM, as Excel's "Unicode Text" and Notepad's "Unicode" do), telling the user to save it as UTF-8, and its log line names the failure (`utf16-bom`/`nul-byte`/`not-utf8`) and never prints the bytes, since the head of a text file is user content. ⚠️ The client classifies a pick through ONE helper, `_promptAttachKind()` (MIME type first, then the name's extension, because some Android file managers hand over a File with none; returns `image`, `video` or `document`); every pick and paste filter (Attach, drop, the tile grid's drop in `tile-grid.js`, the Compose and paste-dialog pickers, the clipboard handlers), the flag and the re-encode gate read it, never `file.type` directly. Those surfaces ADMIT through `_admitPromptAttachments()` (image-input.js), which calls it and toasts what a pick skipped (how many files of a mixed pick, `Unsupported file type` when none pass, nothing for a text paste); a new surface admits through that helper too, never by filtering on `_promptAttachKind()` itself, or it loses the toasts. ⚠️ A pick that lands while the tile grid owns the terminal goes to the PTY, never the main terminal's overlay: that terminal is parked and hidden then, and a tile's Enter cannot flush it (`_tilesOwnTerminal()` in the `_attachFromToolbar` guard). Tests: `test/toolbar-attach.test.ts`, `test/mobile-prompt-composer.test.ts`, `test/paste-image-gc.test.ts`, `test/paste-image-dir-shared.test.ts`, `test/upload-document-list-parity.test.ts` (the browser's copies of `ALLOWED_DOCUMENT_EXTS`: `_promptAttachKind()`, the three pickers' `accept=` and the two file-path link patterns), the paste-image block of `test/routes/session-routes.test.ts`. → [architecture-invariants#buffers-uploads-and-terminal-history](docs/architecture-invariants.md#buffers-uploads-and-terminal-history) -**File-path links (terminal + chat)**: a path an agent prints is clickable on BOTH surfaces and opens the file-preview overlay. ⚠️ ONE pattern (`FILE_PATH_LINK_PATTERN` / `absoluteFilePathPattern()` in constants.js) feeds the xterm link provider AND `_linkifyFilePaths()`, a fresh instance per call (`lastIndex`). Both call `findFilePathLinks()`, which reserves spaced-path spans first (an unlinkable one only while its last word holds a `/`; any label, before an absolute or relative path, must be an explicit path label, prose after that label stays out, and an earlier connective or verb such as `and` or `has` (`SPACED_PATH_PROSE_WORD`) makes any candidate prose; rules and trade-offs in the architecture-invariants paragraph linked below), then adds rooted, `~/`, relative and folder paths without overlapping a reservation, earlier match or URL; a relative path resolves against the pane's live directory `SessionState.cwd` when known, else `workingDir` (`relativeResolutionBase()` + `resolveLinkedFilePath`; `cwd` is only a BASE, never a confinement root: routing and the file routes still judge against `workingDir`, and remote/docker/direct-PTY/rediscovered sessions never get one, scoped by `paneExitApplies`), `~/` only server-side on the session's host (attachment route), and `terminalPathLine()` joins a path a program hard-wrapped short of the edge. ⚠️ A folder link opens the **folder grid**: `POST /api/sessions/:id/folders` guards + GRANTS the folder (`folder-listing.ts`, own registry, never the 200-capped attachment registry), files come by bare name via `…/folders/:folderId/files/:name/*` through `resolveServableAttachmentPath` plus the same extension/regular-file gate on the symlink's resolved target, so no browser request carries a path; `~/` is refused in a Docker case (the container's home is not this host's). The chat linkifier walks TEXT NODES with DOM APIs, never rebuilds sanitized markup as a string. ⚠️ An out-of-workspace path goes through the ATTACHMENT routes (`POST /api/sessions/:id/attachments` with `notify: false`), never by widening `file-content`/`file-raw` or `file-stream-manager`'s `tail -f` allowlist. An ambiguous parenthesised hard wrap is checked only on activation, original first: only a 404 permits a spaced-path lookup, and only a registered alternative is opened; every other original result uses the normal opener, never an attachment-policy gate on workspace files, and hover performs no lookup. ⚠️ `TEXT_ATTACHMENT_EXTENSIONS` IS `EDITABLE_EXTENSIONS` (never a second list), and widening READ must never widen RUN: `html`/`htm`/`svg` stay download-only, other text is inert `text/plain`+`nosniff`. ⚠️ The ONE place HTML renders is `/html-view//...` (`html-view-routes.ts`, `html-view-capabilities.ts`): `POST /api/sessions/:id/html-view` mints a capability for the file's own directory, every response carries `Content-Security-Policy: sandbox` WITHOUT `allow-same-origin` (opaque origin even as a top-level tab, so the page can never read Codeman or drive its API) and with NO fetch directive (open network, owner decision 2026-10-13: never restrict it or add `allow-same-origin` without the owner), and only non-dot, asset-allowlisted files under that directory are served (GET/HEAD only; capabilities revoked with the web-tab ones on logout). That tree is served recursively, so minting is refused for a hidden directory or a broad root (`isBroadHtmlViewRoot`); the preview renders by default and the **Page** pill (or a refused mint) falls through to the source view and its Edit button. Never serve HTML same-origin anywhere else. Tests: `test/routes/html-view-routes.test.ts`. Media extensions are single-sourced in `attachment-registry.ts`. ⚠️ **XLSX previews parse in the BROWSER**, never on the server; the admission limits that keep a hostile workbook from freezing the worker live in `src/web/CLAUDE.md` (Spreadsheet preview). → [architecture-invariants#file-path-links-terminal--response-viewer](docs/architecture-invariants.md#file-path-links-terminal--response-viewer) +**File-path links (terminal + chat)**: a path an agent prints is clickable on BOTH surfaces and opens the file-preview overlay. ⚠️ ONE pattern (`FILE_PATH_LINK_PATTERN` / `absoluteFilePathPattern()` in constants.js) feeds the xterm link provider AND `_linkifyFilePaths()`, a fresh instance per call (`lastIndex`). Both call `findFilePathLinks()`, which reserves spaced-path spans first (an unlinkable one only while its last word holds a `/`; any label, before an absolute or relative path, must be an explicit path label, prose after that label stays out, and an earlier connective or verb such as `and` or `has` (`SPACED_PATH_PROSE_WORD`) makes any candidate prose; rules and trade-offs in the architecture-invariants paragraph linked below), then adds rooted, `~/`, relative and folder paths without overlapping a reservation, earlier match or URL; a relative path resolves against the pane's live directory `SessionState.paneCwd` when known, else `workingDir` (`relativeResolutionBase()` + `resolveLinkedFilePath`; `paneCwd` is only a BASE, never a confinement root: routing and the file routes still judge against `workingDir`, and remote/docker/direct-PTY/rediscovered sessions never get one, scoped by `paneExitApplies`), `~/` only server-side on the session's host (attachment route), and `terminalPathLine()` joins a path a program hard-wrapped short of the edge. ⚠️ A folder link opens the **folder grid**: `POST /api/sessions/:id/folders` guards + GRANTS the folder (`folder-listing.ts`, own registry, never the 200-capped attachment registry), files come by bare name via `…/folders/:folderId/files/:name/*` through `resolveServableAttachmentPath` plus the same extension/regular-file gate on the symlink's resolved target, so no browser request carries a path; `~/` is refused in a Docker case (the container's home is not this host's). The chat linkifier walks TEXT NODES with DOM APIs, never rebuilds sanitized markup as a string. ⚠️ An out-of-workspace path goes through the ATTACHMENT routes (`POST /api/sessions/:id/attachments` with `notify: false`), never by widening `file-content`/`file-raw` or `file-stream-manager`'s `tail -f` allowlist. An ambiguous parenthesised hard wrap is checked only on activation, original first: only a 404 permits a spaced-path lookup, and only a registered alternative is opened; every other original result uses the normal opener, never an attachment-policy gate on workspace files, and hover performs no lookup. ⚠️ `TEXT_ATTACHMENT_EXTENSIONS` IS `EDITABLE_EXTENSIONS` (never a second list), and widening READ must never widen RUN: `html`/`htm`/`svg` stay download-only, other text is inert `text/plain`+`nosniff`. ⚠️ The ONE place HTML renders is `/html-view//...` (`html-view-routes.ts`, `html-view-capabilities.ts`): `POST /api/sessions/:id/html-view` mints a capability for the file's own directory, every response carries `Content-Security-Policy: sandbox` WITHOUT `allow-same-origin` (opaque origin even as a top-level tab, so the page can never read Codeman or drive its API) and with NO fetch directive (open network, owner decision 2026-10-13: never restrict it or add `allow-same-origin` without the owner), and only non-dot, asset-allowlisted files under that directory are served (GET/HEAD only; capabilities revoked with the web-tab ones on logout). That tree is served recursively, so minting is refused for a hidden directory or a broad root (`isBroadHtmlViewRoot`); the preview renders by default and the **Page** pill (or a refused mint) falls through to the source view and its Edit button. Never serve HTML same-origin anywhere else. Tests: `test/routes/html-view-routes.test.ts`. Media extensions are single-sourced in `attachment-registry.ts`. ⚠️ **XLSX previews parse in the BROWSER**, never on the server; the admission limits that keep a hostile workbook from freezing the worker live in `src/web/CLAUDE.md` (Spreadsheet preview). → [architecture-invariants#file-path-links-terminal--response-viewer](docs/architecture-invariants.md#file-path-links-terminal--response-viewer) The terminal provider scans `terminalLinkLine()`, which extends `terminalPathLine()` for URL continuations in indented paragraphs and table cells. List markers, bare numbers, version tokens, whole email addresses, labels ending in `:`, measurements and clock times (`45%`, `12.3ms`, `10:00:00`) and a `name=value` field under a URL ending in `/` never continue a URL; a token with only `-`, `_` or `.` is also refused when it carries a call paren (`client.get()`) or ends a sentence (`Done.`). A URL in the last column of a space-aligned table never takes the next row's first cell: a continuation row must start inside the URL's own cell, so a gap of two or more spaces between its indent and where the URL starts on the row above means it is the next record. `terminalCellWrappedPaths()` follows each table cell independently: a fragment carries on into the next row only when it ends its cell on `/` or `-` (where a wrapper breaks a path; codex's cell wrap never breaks at `_`), the continuation row is blank to the left of the cell (a wrapper wraps every column of a table row together, so a label there such as `Entry` or `│ Log │` is the next record, unless a left column's path continued on that row too; a left column of wrapped prose, as in a `Description | Path` table, fills that row as well, so the path beside it keeps its per-row fragment links, the safe direction), the next row's token passes `pathContinuation()`, and the cell is no wider than the one above. So a directory that is a whole cell value (`/home/u/proj` over `config.yaml`, or `/home/u/proj/app/` over a labelled `main.py`) keeps its folder link and the next row keeps its own file link. With no label to tell them apart, a directory written with its trailing slash over a relative path in the same column (`/home/u/proj/src/` over `lib/util.ts`) still joins, a known trade-off: it reads exactly like a wrap at `/`. Accepted paths displace other links on their cells. Full-width divider rows stop `terminalLogicalLine()` stitching for both links and touch selection. OSC 8 links confirm the real target URI before the shared opener runs. diff --git a/docs/api-reference.md b/docs/api-reference.md index ffb3f536..f7870264 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -969,9 +969,9 @@ also pure decoration: it confers no permission, and a child is unaffected by its parent exiting. It appears on session state as `parentSessionId` (absent when unresolved) and survives a server restart. -## Pane directory (`cwd`) +## Pane directory (`paneCwd`) -Session state (`GET /api/v1/sessions`, the `session:updated` event) may carry `cwd`, +Session state (`GET /api/v1/sessions`, the `session:updated` event) may carry `paneCwd`, the directory the session's local tmux pane is in now (`#{pane_current_path}`), which the web UI uses as the base for a relative path printed in the terminal. It is never restored after a restart (it is written to `state.json` with the rest of the diff --git a/docs/architecture-invariants.md b/docs/architecture-invariants.md index edf17186..18d01c85 100644 --- a/docs/architecture-invariants.md +++ b/docs/architecture-invariants.md @@ -409,7 +409,9 @@ A file path an agent prints is a link on both surfaces it can appear on, and cli ⚠️ **The terminal routes an out-of-workspace path to the preview, not the log viewer.** The log viewer spawns `tail -f` and allows only the workspace, `/var/log` and `~/logs`, so an external `.log`/`.json`/code path answered `Path must be within working directory or allowed log directories` while the SAME path clicked in the response viewer previewed fine. `activate()` now checks `_isExternalPreviewPath` alongside `previewsInFileViewer`. In-workspace text keeps the tail viewer, which is the point of it (live follow), except markdown (`.md`/`.markdown`, in `FILE_PREVIEW_EXTENSIONS` since the owner's 2026-10-13 decision, rendered as a document) and `.html`/`.htm` (`rendersAsPage()`, rendered as a page, see below), which always go to the preview; nothing widened `file-stream-manager`'s allowlist, so no `tail -f` is spawned on an arbitrary host path. -**Path forms beyond the rooted one.** `findFilePathLinks(text)` (constants.js) is the single entry point both consumers call; it reserves spaced candidates first (including unlinkable spans), then detects rooted matches, then `~/` and relative paths (`RELATIVE_FILE_PATH_LINK_PATTERN`, same extension list, pinned equal by `test/link-provider-regex.test.ts`), then folder paths, each only where it overlaps neither an earlier match nor an `http(s)` URL. A relative match must start at a boundary (line start, whitespace, quote, bracket, `=`, `,`, `>`), so it can never begin inside a word, an absolute path or a URL; brackets, `=` and `,` end it (`(shot.png)`, `OUT=shots/a.png`). `resolveLinkedFilePath()` resolves a relative path against a base (`.`/`..` collapsed, so `../x.png` lands outside and routes like any external path) and passes absolute and `~/` paths through. The base is `relativeResolutionBase(session)`: the pane's live directory `SessionState.cwd` when known, else `workingDir`, which is fixed at create time and never follows a `cd`. `cwd` is `#{pane_current_path}` from the pane-exit watcher's existing batched `list-panes -a` read (`derivePaneCurrentPaths()`, single-pane sessions and absolute paths only; no new tmux call and no new SSE event: the server applies it on the `paneExitsUpdated` tick and broadcasts `session:updated` only on a change). tmux reports the cwd of the pane's FOREGROUND process-group leader, so a shell's `cd` moves it, while an agent CLI's tool subprocesses (Claude's Bash tool, codex's exec) do not: for those sessions it stays the CLI's own directory. ⚠️ `cwd` is a resolution BASE only, never a confinement root: `_isExternalPreviewPath`, `file-content`/`file-raw` and the log viewer's `tail -f` allowlist all still judge against `workingDir`, so a pane that `cd`s outside the workspace sends its relative links through the attachment routes like any other external path, and what can be opened is unchanged (an absolute path to the same file already opened). ⚠️ `Session.setCwd()` uses the `paneExitApplies` scoping rule and fails closed the same way: a remote session's local pane runs the ssh client and a docker case's runs `docker exec`, so their pane directory is a host directory the agent was never in; direct-PTY and rediscovered sessions get none either, and the browser re-checks `remote`/`docker`. ⚠️ tmux reads the directory from `/proc//cwd`, always the RESOLVED path, while `workingDir` keeps the spelling the case was created with (a symlinked `~/codeman-cases`, a case linked through a symlink, macOS `/tmp`), and `_isExternalPreviewPath` compares lexically, so `setCwd()` writes a reading at or under the workspace's resolved path back in `workingDir`'s spelling. The resolution runs once per session in the background, bounded (`probePathKind()` first, then a `realpath()` raced against the same timeout, never on the watcher tick and never `realpathSync`); an `unknown` probe or a failed or slow `realpath()` leaves the reading untranslated and retries after `WORKSPACE_REALPATH_RETRY_MS`. Until it settles, only a reading lexically inside `workingDir` is taken, so the first tick cannot mis-route links. ⚠️ Never restored after a restart: written to `state.json` by `toState()` like the rest of the session state but never read back, and a directory change alone never persists. A failed or empty read keeps every last directory, and a blank `#{pane_current_path}` on a single-pane session keeps that session's (`derivePaneCurrentPaths()` carries it forward); an authoritative read that lists the session as split into several panes, or not at all, clears it, so a hand-split session falls back to `workingDir`. The server applies the manager's answer as given, `undefined` included, and `setCwd()` reports a clear once. Trade-off: the base is the pane's directory at CLICK time, so a relative path printed before a `cd` resolves against the new directory. Tests: `test/pane-cwd-tracking.test.ts`. ⚠️ `~` is the home of the SESSION'S host, which only the server knows: `~/` paths always take the attachment route, where `registerExternalAttachment` expands them (`homedir()` locally, `$HOME` inside the remote probe script), and the guard runs on the expanded, realpath-resolved path as before. ⚠️ Programs hard-wrap their own output short of the terminal edge (Claude Code breaks tool output at 59-118 columns), so xterm's `isWrapped` never fires. `terminalPathLine()` (link provider only; touch selection keeps `terminalLogicalLine`) joins the next row when the previous row ends in a path token with a `/` and no extension and the join reaches an extension; a row that starts a new path is never joined: rooted or `~/`, `./`/`../`, or a relative one that opens on the same top directory the broken token did (the next entry of `git ls-files`/`find`/`ls -R`: `src/components` + `src/index.ts` are two paths, not `src/componentssrc/index.ts`), while a wrapped path continues INSIDE a name, so `…/captures/2` + `026-10-10/…` still joins; a 3+ row chain is kept only if a later row completes the path, and the broken row must be at least as long as the continuing one (keeps `cd /mnt/foo` + a longer next line apart). Tests: `test/file-path-link-forms.test.ts`. +**Path forms beyond the rooted one.** `findFilePathLinks(text)` (constants.js) is the single entry point both consumers call; it reserves spaced candidates first (including unlinkable spans), then detects rooted matches, then `~/` and relative paths (`RELATIVE_FILE_PATH_LINK_PATTERN`, same extension list, pinned equal by `test/link-provider-regex.test.ts`), then folder paths, each only where it overlaps neither an earlier match nor an `http(s)` URL. A relative match must start at a boundary (line start, whitespace, quote, bracket, `=`, `,`, `>`), so it can never begin inside a word, an absolute path or a URL; brackets, `=` and `,` end it (`(shot.png)`, `OUT=shots/a.png`). `resolveLinkedFilePath()` resolves a relative path against a base (`.`/`..` collapsed, so `../x.png` lands outside and routes like any external path) and passes absolute and `~/` paths through. ⚠️ `~` is the home of the SESSION'S host, which only the server knows: `~/` paths always take the attachment route, where `registerExternalAttachment` expands them (`homedir()` locally, `$HOME` inside the remote probe script), and the guard runs on the expanded, realpath-resolved path as before. ⚠️ Programs hard-wrap their own output short of the terminal edge (Claude Code breaks tool output at 59-118 columns), so xterm's `isWrapped` never fires. `terminalPathLine()` (link provider only; touch selection keeps `terminalLogicalLine`) joins the next row when the previous row ends in a path token with a `/` and no extension and the join reaches an extension; a row that starts a new path is never joined: rooted or `~/`, `./`/`../`, or a relative one that opens on the same top directory the broken token did (the next entry of `git ls-files`/`find`/`ls -R`: `src/components` + `src/index.ts` are two paths, not `src/componentssrc/index.ts`), while a wrapped path continues INSIDE a name, so `…/captures/2` + `026-10-10/…` still joins; a 3+ row chain is kept only if a later row completes the path, and the broken row must be at least as long as the continuing one (keeps `cd /mnt/foo` + a longer next line apart). Tests: `test/file-path-link-forms.test.ts`. + +**The relative base is the pane's directory.** The base is `relativeResolutionBase(session)`: the pane's live directory `SessionState.paneCwd` when known, else `workingDir`, which is fixed at create time and never follows a `cd`. `paneCwd` is `#{pane_current_path}` from the pane-exit watcher's existing batched `list-panes -a` read (`derivePaneCurrentPaths()`, single-pane sessions and absolute paths only; no new tmux call and no new SSE event: the server applies it on the `paneExitsUpdated` tick and broadcasts `session:updated` only on a change). tmux reports the cwd of the pane's FOREGROUND process-group leader, so a shell's `cd` moves it, while an agent CLI's tool subprocesses (Claude's Bash tool, codex's exec) do not: for those sessions it stays the CLI's own directory. ⚠️ `paneCwd` is a resolution BASE only, never a confinement root: `_isExternalPreviewPath`, `file-content`/`file-raw` and the log viewer's `tail -f` allowlist all still judge against `workingDir`, so a pane that `cd`s outside the workspace sends its relative links through the attachment routes like any other external path, and what can be opened is unchanged (an absolute path to the same file already opened). ⚠️ `Session.setPaneCwd()` uses the `paneExitApplies` scoping rule and fails closed the same way: a remote session's local pane runs the ssh client and a docker case's runs `docker exec`, so their pane directory is a host directory the agent was never in; direct-PTY and rediscovered sessions get none either, and the browser re-checks `remote`/`docker`. ⚠️ tmux reads the directory from `/proc//cwd`, always the RESOLVED path, while `workingDir` keeps the spelling the case was created with (a symlinked `~/codeman-cases`, a case linked through a symlink, macOS `/tmp`), and `_isExternalPreviewPath` compares lexically, so `setPaneCwd()` writes a reading at or under the workspace's resolved path back in `workingDir`'s spelling. The resolution runs once per session in the background, bounded (`probePathKind()` first, then a `realpath()` raced against the same timeout, never on the watcher tick and never `realpathSync`); an `unknown` probe or a failed or slow `realpath()` leaves the reading untranslated and retries after `WORKSPACE_REALPATH_RETRY_MS`. Until it settles, only a reading lexically inside `workingDir` is taken, so the first tick cannot mis-route links. ⚠️ Never restored after a restart: written to `state.json` by `toState()` like the rest of the session state but never read back, and a directory change alone never persists. A failed or empty read keeps every last directory, and a blank `#{pane_current_path}` on a single-pane session keeps that session's (`derivePaneCurrentPaths()` carries it forward); an authoritative read that lists the session as split into several panes, or not at all, clears it, so a hand-split session falls back to `workingDir`. The server applies the manager's answer as given, `undefined` included, and `setPaneCwd()` reports a clear once. Trade-off: the base is the pane's directory at CLICK time, so a relative path printed before a `cd` resolves against the new directory. Tests: `test/pane-cwd-tracking.test.ts`. Spaced paths are considered first by `findFilePathLinks()`: accepted candidates reserve their entire span even when unlinkable, so later detectors cannot link fragments. Relative and `~/` spaced paths require an explicit path label (`Path:`, `File:`, `Files:`, `Saved to:`, `Saved as:`, `Wrote:`, `Written to:`, `Output:`, `Created:`, `Location:`, `Attachment:`), optionally preceded by a marker. Generic labels and bare bullets defer to ordinary detection, including slash-containing prose such as `CI/CD` or `45/45`. A later `/`, `~/`, `./` or `../` word starts a separate path; an earlier word ending in `/` is a separate folder. Absolute paths keep the own-line and marker forms plus the same path labels; any other label (`Error:`, `Note:`, `Saved the report to:`) defers an absolute path too. A rooted candidate needs a directory before its first space, so `/review the changes in src/a.ts` is prose. An earlier word holding a known extension anywhere (`a.ts#L12 foo.ts`) ends the path at that word, a `:` followed by a digit inside an earlier word is a line suffix (`a.ts:42:See b.md`, grep and compiler output) and ends the path there, a run of spaces is a column gap rather than a name, and a leading run of `./` or `../` is not a segment (`Saved to: ../My Docs/plan.md` links whole; an interior `..` is still refused). An unlinkable candidate reserves its span only while its last word holds a `/`, so `/usr/bin/env node build.js` keeps its ordinary links while `/etc/secret files/passwords.txt` links nothing. A path label vouches that a path follows, not for the words before it: a relative candidate whose only `/` word is its last is prose after the label (`Wrote: 120 lines to src/foo.ts`, `Path: see src/foo.ts`) and defers to the ordinary detectors. The cost is a labelled relative path whose only space is in its top directory, `Saved to: My Docs/plan.md` (and `Saved to: 03 Attachments/plan.pptx`), which splits as on master; `03 Attachments/Build SIPOC Design/Build-SIPOC.pptx`, `notes/a b/c.md`, `~/`, `./` and `../` forms and absolute paths still link whole. An earlier word that is a lowercase connective or verb (`SPACED_PATH_PROSE_WORD`: `and`, `or`, `to`, `in`, `the`, `is`, `has`, `contains`, `then`, `as` and a few more) or a bare `=` makes the candidate a sentence, in every shape: `/home/me/proj contains a.md`, `- /tmp/out has the logs in run.log`, `Path: /home/me/proj/out contains a.md`, `Files: src/components and utils/x.ts`, `Wrote: 3 files to docs/design notes/overview.md`. The cost is a name that uses one of those words (`Pros and Cons.md`, `How to deploy.md`, `Documents and Settings`), which splits as on master; `at` (`Screenshot 2026-10-24 at 10.00.00.png`) and `of` (`Copy of report.docx`) are left out of the list on purpose. What remains ambiguous is an own-line absolute path followed by words that hold none of them (`/home/me/proj/out report.pdf` reads like `/home/me/docs/Read Me.txt`), which links as one path. A command line is refused too: a first word that is an executable under `bin/`, `.bin/`, `scripts/` or `tools/` (`/opt/homebrew/bin/node server.js`, `/home/me/proj/scripts/deploy prod.yml`) or any `-x`/`--x` flag word (`/home/me/proj/node_modules/.bin/tsc -p tsconfig.json`); a bare `-` (`Docs - Copy`, `OneDrive - Contoso`) is not a flag. So is a shell prompt that prints an absolute working directory (WSL's `/mnt/c/...` is outside `$HOME`, so every earlier command in a shell's scrollback has one): a first word ending in `$` (`/home/me/proj$ cat notes.md`) and any earlier word with no letter or digit other than a bare `-` (`/mnt/c/proj ❯ code notes.md`, `/home/me/proj $ cat notes.md`, `/home/me/proj/out ✓ report.pdf`) refuse the candidate, while `Program Files (x86)` and `Docs - Copy` still link whole. The response viewer carries any leading `` label in a paragraph or list item, or one starting a later line of a paragraph (after a `
`, since chat renders with `breaks: true`), into detection without changing the label or displayed text, and `spacedFilePathOnLine()` judges it as it judges the same line in the terminal (`**Note:** /home/me/proj/out report.pdf` splits). A text node that follows any other inline element starts mid-line, so a placeholder word stands in for what precedes it (``Use `--config` /home/me/proj/cfg data.json`` splits as in the terminal), while a path inside inline code still links whole; paths split across inline elements remain detected per text node. Tests feed vendored marked output into the jsdom linkifier, so consumed bullets and bold labels are covered. Trailing whitespace uses linear `trimEnd()` before the length cap. diff --git a/src/session.ts b/src/session.ts index 63093747..8291dddb 100644 --- a/src/session.ts +++ b/src/session.ts @@ -765,7 +765,7 @@ export class Session extends EventEmitter { * The pane's live directory, from the pane-exit watcher's read. Runtime-only: * serialized by toState() but never restored by the constructor. */ - private _cwd: string | undefined; + private _paneCwd: string | undefined; /** * `workingDir` with symlinks resolved, so a pane reading (tmux reads the * process cwd, always the resolved path) can be put back into `workingDir`'s @@ -1530,8 +1530,8 @@ export class Session extends EventEmitter { } /** The pane's live working directory, when the pane read has reported one. */ - get cwd(): string | undefined { - return this._cwd; + get paneCwd(): string | undefined { + return this._paneCwd; } /** @@ -1553,7 +1553,7 @@ export class Session extends EventEmitter { * `workingDir`'s spelling. Until that resolution has settled, only a reading * lexically inside `workingDir` is accepted. */ - setCwd(next: string | undefined): boolean { + setPaneCwd(next: string | undefined): boolean { let resolved = this.paneExitApplies && next?.startsWith('/') ? next : undefined; if (resolved !== undefined) { if ( @@ -1571,8 +1571,8 @@ export class Session extends EventEmitter { resolved = rebasePath(resolved, this._workspaceRealPath, this._workspaceSpelling()); } } - if (resolved === this._cwd) return false; - this._cwd = resolved; + if (resolved === this._paneCwd) return false; + this._paneCwd = resolved; return true; } @@ -1582,7 +1582,7 @@ export class Session extends EventEmitter { } /** - * Resolve `workingDir`'s symlinks in the background for {@link setCwd}. + * Resolve `workingDir`'s symlinks in the background for {@link setPaneCwd}. * * Bounded: the folder can sit on a network mount that stopped answering, so it * is probed with `probePathKind()` first and the `realpath()` is raced against @@ -2299,7 +2299,7 @@ export class Session extends EventEmitter { pid: this.pid, status: this._status, workingDir: this.workingDir, - cwd: this._cwd, + paneCwd: this._paneCwd, remote: this._remote, docker: this._docker, owner: this._owner, diff --git a/src/tmux-manager.ts b/src/tmux-manager.ts index 8df06aa4..fc944d14 100644 --- a/src/tmux-manager.ts +++ b/src/tmux-manager.ts @@ -441,7 +441,7 @@ export function derivePaneExits(rows: PaneRow[], now: number): Map `#{pane_current_path}` from the last authoritative pane read * ({@link derivePaneCurrentPaths}). Replaced wholesale by each non-empty read, * so it is bounded by the panes on the socket. Like {@link paneExits} it holds - * the raw reading; `Session.setCwd()` decides which sessions may use it. + * the raw reading; `Session.setPaneCwd()` decides which sessions may use it. */ private paneCurrentPaths: Map = new Map(); /** The pane-exit watcher's own interval. Runs whether or not stats are on. */ diff --git a/src/types/session.ts b/src/types/session.ts index a55f4044..e4a0e93a 100644 --- a/src/types/session.ts +++ b/src/types/session.ts @@ -846,7 +846,7 @@ export interface SessionState { * to `workingDir`, and a path resolved outside it goes through the attachment * routes like any other out-of-workspace path. */ - cwd?: string; + paneCwd?: string; /** Remote execution metadata, present when this session runs over SSH through local tmux */ remote?: SessionRemote; /** Docker execution metadata, present when this session runs inside a container via local tmux + docker exec */ diff --git a/src/web/public/constants.js b/src/web/public/constants.js index d7b7a566..8d7446b8 100644 --- a/src/web/public/constants.js +++ b/src/web/public/constants.js @@ -2431,23 +2431,23 @@ function resolveLinkedFilePath(filePath, workingDir) { * * `workingDir` is recorded once at create time and never follows a `cd`, so it * stops describing where a shell (or an agent that changed directory) really - * is. `session.cwd` is the pane's live `#{pane_current_path}`, published by the + * is. `session.paneCwd` is the pane's live `#{pane_current_path}`, published by the * server from its pane read. It only changes which BASE a relative path joins; * the result is then routed like any other path, so a target outside the * workspace still goes through the attachment routes. * - * Remote and Docker sessions are excluded (the server never sends them a cwd, + * Remote and Docker sessions are excluded (the server never sends them a paneCwd, * and this checks again): their local pane runs the ssh / docker-exec CLIENT, - * so its directory says nothing about the agent. An unknown cwd falls back to + * so its directory says nothing about the agent. An unknown paneCwd falls back to * `workingDir`. * - * @param {{workingDir?: string, cwd?: string, remote?: unknown, docker?: unknown}} [session] + * @param {{workingDir?: string, paneCwd?: string, remote?: unknown, docker?: unknown}} [session] * @returns {string|undefined} */ function relativeResolutionBase(session) { if (!session) return undefined; - const cwd = session.cwd; - if (!session.remote && !session.docker && typeof cwd === 'string' && cwd.startsWith('/')) return cwd; + const paneCwd = session.paneCwd; + if (!session.remote && !session.docker && typeof paneCwd === 'string' && paneCwd.startsWith('/')) return paneCwd; return session.workingDir; } diff --git a/src/web/server.ts b/src/web/server.ts index 61193cde..5edfb5a3 100644 --- a/src/web/server.ts +++ b/src/web/server.ts @@ -2866,10 +2866,10 @@ export class WebServer extends EventEmitter { // or empty read and carries a blank `#{pane_current_path}` forward, so an // `undefined` here means an authoritative read listed no single directory // for the session (split into several panes, or gone from the socket). - const cwdChanged = getPaneCurrentPath ? session.setCwd(getPaneCurrentPath(muxName)) : false; + const paneCwdChanged = getPaneCurrentPath ? session.setPaneCwd(getPaneCurrentPath(muxName)) : false; if (session.setPaneExit(getPaneExit(muxName))) { this.persistSessionState(session); - } else if (!cwdChanged) { + } else if (!paneCwdChanged) { continue; } this.broadcastSessionStateDebounced(session.id); diff --git a/test/pane-cwd-tracking.test.ts b/test/pane-cwd-tracking.test.ts index 734e6031..51c32794 100644 --- a/test/pane-cwd-tracking.test.ts +++ b/test/pane-cwd-tracking.test.ts @@ -202,45 +202,45 @@ function localMuxSession(extra: Record = {}) { }); } -describe('Session.setCwd scoping', () => { +describe('Session.setPaneCwd scoping', () => { it('records an absolute directory for a local pane and reports the change once', () => { const session = localMuxSession(); - expect(session.setCwd('/work/proj/sub')).toBe(true); - expect(session.cwd).toBe('/work/proj/sub'); - expect(session.setCwd('/work/proj/sub')).toBe(false); - expect(session.toState().cwd).toBe('/work/proj/sub'); + expect(session.setPaneCwd('/work/proj/sub')).toBe(true); + expect(session.paneCwd).toBe('/work/proj/sub'); + expect(session.setPaneCwd('/work/proj/sub')).toBe(false); + expect(session.toState().paneCwd).toBe('/work/proj/sub'); }); it('clears the directory when the reading goes away', () => { const session = localMuxSession(); - session.setCwd('/work/proj/sub'); - expect(session.setCwd(undefined)).toBe(true); - expect(session.cwd).toBeUndefined(); + session.setPaneCwd('/work/proj/sub'); + expect(session.setPaneCwd(undefined)).toBe(true); + expect(session.paneCwd).toBeUndefined(); }); it('refuses a relative directory', () => { const session = localMuxSession(); - expect(session.setCwd('rel/ative')).toBe(false); - expect(session.cwd).toBeUndefined(); + expect(session.setPaneCwd('rel/ative')).toBe(false); + expect(session.paneCwd).toBeUndefined(); }); it('refuses a directory for a remote session, whose local pane runs the ssh client', () => { const session = localMuxSession({ remote }); - expect(session.setCwd('/home/dev')).toBe(false); - expect(session.toState().cwd).toBeUndefined(); + expect(session.setPaneCwd('/home/dev')).toBe(false); + expect(session.toState().paneCwd).toBeUndefined(); }); it('refuses a directory for a docker case, whose local pane runs docker exec', () => { const session = localMuxSession({ docker }); - expect(session.setCwd('/work/proj')).toBe(false); - expect(session.toState().cwd).toBeUndefined(); + expect(session.setPaneCwd('/work/proj')).toBe(false); + expect(session.toState().paneCwd).toBeUndefined(); }); it('refuses a directory for a direct-PTY session and a rediscovered one', () => { const direct = new Session({ workingDir: '/work/proj', mode: 'shell', useMux: false }); - expect(direct.setCwd('/work/proj/sub')).toBe(false); + expect(direct.setPaneCwd('/work/proj/sub')).toBe(false); const discovered = localMuxSession({ discoveredMuxSession: true }); - expect(discovered.setCwd('/work/proj/sub')).toBe(false); + expect(discovered.setPaneCwd('/work/proj/sub')).toBe(false); }); }); @@ -257,18 +257,23 @@ describe('a pane read reaching the session record', () => { server = web; const mux = (web as unknown as { mux: Record & { emit: (e: string) => void } }).mux; const sessions = (web as unknown as { sessions: Map }).sessions; - return { mux, sessions }; + return { mux, sessions, web }; }; it("publishes the pane's directory on the existing paneExitsUpdated tick", () => { - const { mux, sessions } = build(); + const { mux, sessions, web } = build(); const session = localMuxSession(); sessions.set(session.id, session); mux.getPaneExit = () => undefined; mux.getPaneCurrentPath = (muxName: string) => (muxName === 'codeman-aaaa' ? '/work/proj/sub' : undefined); mux.emit('paneExitsUpdated'); - expect(session.toState().cwd).toBe('/work/proj/sub'); + expect(session.toState().paneCwd).toBe('/work/proj/sub'); + // What the browser actually receives: a future explicit field list must not drop it. + const state = ( + web as unknown as { getSessionStateWithRespawn: (s: Session) => { paneCwd?: string } } + ).getSessionStateWithRespawn(session); + expect(state.paneCwd).toBe('/work/proj/sub'); // A resolution base only: the confinement root is untouched. expect(session.toState().workingDir).toBe('/work/proj'); }); @@ -294,7 +299,7 @@ describe('a pane read reaching the session record', () => { dir = '/work/proj/other'; mux.emit('paneExitsUpdated'); expect(broadcast).toHaveBeenCalledTimes(2); - expect(session.toState().cwd).toBe('/work/proj/other'); + expect(session.toState().paneCwd).toBe('/work/proj/other'); // Runtime-only: a directory change alone is never written to state.json. expect(persist).not.toHaveBeenCalled(); }); @@ -335,12 +340,12 @@ describe('a pane read reaching the session record', () => { it('clears the directory once the session is split into several panes', async () => { const { session, broadcast, tick } = buildWithRealManager(); await tick('codeman-aaaa|100|0|||/work/proj/sub'); - expect(session.toState().cwd).toBe('/work/proj/sub'); + expect(session.toState().paneCwd).toBe('/work/proj/sub'); expect(broadcast).toHaveBeenCalledTimes(1); await tick(['codeman-aaaa|100|0|||/work/proj/sub', 'codeman-aaaa|101|0|||/work/proj'].join('\n')); // An absent cwd is what makes the browser fall back to workingDir. - expect(session.toState().cwd).toBeUndefined(); + expect(session.toState().paneCwd).toBeUndefined(); expect(broadcast).toHaveBeenCalledTimes(2); // The clear is announced once, not on every later tick that agrees. @@ -351,10 +356,10 @@ describe('a pane read reaching the session record', () => { it('clears the directory once a read no longer lists the session', async () => { const { session, broadcast, tick } = buildWithRealManager(); await tick('codeman-aaaa|100|0|||/work/proj/sub'); - expect(session.toState().cwd).toBe('/work/proj/sub'); + expect(session.toState().paneCwd).toBe('/work/proj/sub'); await tick('codeman-other|300|0|||/elsewhere'); - expect(session.toState().cwd).toBeUndefined(); + expect(session.toState().paneCwd).toBeUndefined(); expect(broadcast).toHaveBeenCalledTimes(2); await tick('codeman-other|300|0|||/elsewhere'); expect(broadcast).toHaveBeenCalledTimes(2); @@ -365,10 +370,10 @@ describe('a pane read reaching the session record', () => { await tick('codeman-aaaa|100|0|||/work/proj/sub'); // tmux could not read the process cwd for one tick. await tick('codeman-aaaa|100|0|||'); - expect(session.toState().cwd).toBe('/work/proj/sub'); + expect(session.toState().paneCwd).toBe('/work/proj/sub'); // A failed read arrives as no rows at all. await tick(''); - expect(session.toState().cwd).toBe('/work/proj/sub'); + expect(session.toState().paneCwd).toBe('/work/proj/sub'); expect(broadcast).toHaveBeenCalledTimes(1); }); @@ -380,7 +385,7 @@ describe('a pane read reaching the session record', () => { mux.getPaneCurrentPath = () => '/work/proj'; mux.emit('paneExitsUpdated'); - expect(session.toState().cwd).toBeUndefined(); + expect(session.toState().paneCwd).toBeUndefined(); }); it('publishes nothing for a remote session', () => { @@ -391,7 +396,7 @@ describe('a pane read reaching the session record', () => { mux.getPaneCurrentPath = () => '/home/dev'; mux.emit('paneExitsUpdated'); - expect(session.toState().cwd).toBeUndefined(); + expect(session.toState().paneCwd).toBeUndefined(); }); }); @@ -418,13 +423,15 @@ describe('browser resolution order: live cwd, then workingDir', () => { }; it("resolves against the pane's live directory after a cd into a subdirectory", () => { - expect(resolveFor({ workingDir: '/work/proj', cwd: '/work/proj/sub' }, 'note.md')).toBe('/work/proj/sub/note.md'); + expect(resolveFor({ workingDir: '/work/proj', paneCwd: '/work/proj/sub' }, 'note.md')).toBe( + '/work/proj/sub/note.md' + ); }); it('resolves outside the workspace when the pane cd-ed to a sibling repo', () => { // Routing is unchanged: an absolute target outside the workspace is what // `_isExternalPreviewPath` already sends through the attachment routes. - expect(resolveFor({ workingDir: '/work/proj', cwd: '/work/other' }, 'src/a.js')).toBe('/work/other/src/a.js'); + expect(resolveFor({ workingDir: '/work/proj', paneCwd: '/work/other' }, 'src/a.js')).toBe('/work/other/src/a.js'); }); it('falls back to workingDir when no live directory is known', () => { @@ -432,16 +439,20 @@ describe('browser resolution order: live cwd, then workingDir', () => { }); it('ignores a live directory on a remote or docker session', () => { - expect(resolveFor({ workingDir: '/work/proj', cwd: '/tmp/x', remote: {} }, 'note.md')).toBe('/work/proj/note.md'); - expect(resolveFor({ workingDir: '/work/proj', cwd: '/tmp/x', docker: {} }, 'note.md')).toBe('/work/proj/note.md'); + expect(resolveFor({ workingDir: '/work/proj', paneCwd: '/tmp/x', remote: {} }, 'note.md')).toBe( + '/work/proj/note.md' + ); + expect(resolveFor({ workingDir: '/work/proj', paneCwd: '/tmp/x', docker: {} }, 'note.md')).toBe( + '/work/proj/note.md' + ); }); it('ignores a relative live directory', () => { - expect(resolveFor({ workingDir: '/work/proj', cwd: 'sub' }, 'note.md')).toBe('/work/proj/note.md'); + expect(resolveFor({ workingDir: '/work/proj', paneCwd: 'sub' }, 'note.md')).toBe('/work/proj/note.md'); }); it('leaves absolute and home paths alone', () => { - const session = { workingDir: '/work/proj', cwd: '/work/proj/sub' }; + const session = { workingDir: '/work/proj', paneCwd: '/work/proj/sub' }; expect(resolveFor(session, '/etc/hosts.md')).toBe('/etc/hosts.md'); expect(resolveFor(session, '~/x.md')).toBe('~/x.md'); }); @@ -481,12 +492,12 @@ describe('confinement is unchanged by the live cwd', () => { }; it('keeps a target inside the workspace on the workspace route', () => { - const app = loadApp({ workingDir: '/work/proj', cwd: '/work/proj/sub' }); + const app = loadApp({ workingDir: '/work/proj', paneCwd: '/work/proj/sub' }); expect(app.external(app.target('note.md'))).toBe(false); }); it('sends a target outside the workspace through the attachment route', () => { - const app = loadApp({ workingDir: '/work/proj', cwd: '/work/other' }); + const app = loadApp({ workingDir: '/work/proj', paneCwd: '/work/other' }); expect(app.target('src/a.js')).toBe('/work/other/src/a.js'); expect(app.external(app.target('src/a.js'))).toBe(true); }); @@ -528,8 +539,8 @@ describe('a workspace reached through a symlink', () => { /** Feed a reading until the background resolution has settled and it is taken. */ const settle = async (session: Session, reading: string) => { await vi.waitFor(() => { - session.setCwd(reading); - expect(session.cwd).toBeDefined(); + session.setPaneCwd(reading); + expect(session.paneCwd).toBeDefined(); }); }; @@ -548,9 +559,9 @@ describe('a workspace reached through a symlink', () => { setup(); const session = localMuxSession({ workingDir: link }); await settle(session, physical); - expect(session.cwd).toBe(link); - expect(session.setCwd(join(physical, 'src'))).toBe(true); - expect(session.cwd).toBe(join(link, 'src')); + expect(session.paneCwd).toBe(link); + expect(session.setPaneCwd(join(physical, 'src'))).toBe(true); + expect(session.paneCwd).toBe(join(link, 'src')); }); it('keeps an in-workspace relative link on the workspace route from the first reading', async () => { @@ -565,7 +576,7 @@ describe('a workspace reached through a symlink', () => { setup(); const session = localMuxSession({ workingDir: link }); await settle(session, join(root, 'other')); - expect(session.cwd).toBe(join(root, 'other')); + expect(session.paneCwd).toBe(join(root, 'other')); const external = routingFor(session.toState() as unknown as Record); expect(external('notes.md')).toBe(true); }); @@ -575,24 +586,24 @@ describe('a workspace reached through a symlink', () => { const session = localMuxSession({ workingDir: link }); // The first call starts the resolution; a physical reading cannot be told // apart from a real cd yet, so it is not stored this tick. - expect(session.setCwd(physical)).toBe(false); - expect(session.cwd).toBeUndefined(); + expect(session.setPaneCwd(physical)).toBe(false); + expect(session.paneCwd).toBeUndefined(); // A reading lexically inside workingDir needs no translation and is taken. - expect(session.setCwd(join(link, 'src'))).toBe(true); + expect(session.setPaneCwd(join(link, 'src'))).toBe(true); }); it('leaves the reading alone when workingDir has no symlink in it', async () => { setup(); const session = localMuxSession({ workingDir: physical }); await settle(session, join(physical, 'src')); - expect(session.cwd).toBe(join(physical, 'src')); + expect(session.paneCwd).toBe(join(physical, 'src')); }); it('takes readings untranslated once a missing workingDir has settled', async () => { setup(); const session = localMuxSession({ workingDir: join(root, 'gone') }); await settle(session, join(root, 'other')); - expect(session.cwd).toBe(join(root, 'other')); + expect(session.paneCwd).toBe(join(root, 'other')); }); });