Skip to content

Accept Windows drive-letter paths for projects and workspaces - #4659

Merged
SawyerHood merged 2 commits into
mainfrom
bb/windows-host-paths-thr_jensq3v9th
Oct 2, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/windows-host-paths-thr_jensq3v9th

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb's path model was POSIX-only, so a native Windows host could not add a project or run a thread. packages/domain/src/project-path.ts rejected every drive-letter path ("Native Windows paths are not supported"), several server checks required startsWith("/"), and the worktree and personal-workspace plugins built managed paths with path.posix.join, which on Windows produced mixed separators (C:\…\host-data/worktrees/…). Paths were also compared as raw strings, so C:\repo, c:/repo/, and C:\REPO would have become separate projects, environments, and path claims. The server joined host paths with its own node:path, which is wrong whenever the server and the host run different operating systems. Part of #1206.

What changed

  • Domain. New packages/domain/src/host-path.ts: pure string helpers that infer POSIX or Windows from the path's shape and normalize, join, take the directory or base name, compare, and test containment for either. project-path.ts now accepts drive-letter paths and stores them in one spelling (upper-case drive letter, backslashes, no trailing separator). UNC paths are refused with a message that says to map a drive. POSIX normalization is unchanged.
  • Server. update_environment_directory, the environment provider existingPath and claimPath results, and path admission accept any absolute host path and canonicalize it. Thread storage, the thread-storage orphan sweep, the host's threadStorageRootPath, the diff-file route, workspace skills, and workspace AGENTS.md are joined with the host path's own separator through services/lib/host-path.ts. isBbManagedWorkspacePath uses the same helpers. Project create, source create, and source update refuse a Windows path for a machine that reported darwin, linux, or wsl, so that input still fails clearly on existing hosts.
  • Contract. The unmanaged workspace path in thread requests is canonicalized at the boundary.
  • Database. packages/db/src/data/host-path-sql.ts registers two SQL functions on every connection, backed by the domain helpers: bb_host_path_key (the case-folded comparison key) and bb_host_path_contains. A Windows-shaped path is compared by key, so letters outside ASCII fold too (C:\src\Équipe equals C:\src\équipe; SQLite's NOCASE folds only ASCII). Containment no longer builds a LIKE pattern from the stored path, so _ and % in a directory name are literal, for POSIX paths as well. POSIX equality is still an exact, case-sensitive =. Used for project sources, environments, and path claims. No schema change or migration.
  • Plugins. environment-git-worktree and environment-personal-workspace build managed paths with the host's native path.join, and compare git worktree list output (which uses / on Windows) through path.relative.
  • App. apps/app/src/lib/absolute-file-path.ts and thread-local-file-links.ts use the domain helpers, so a file link under a Windows workspace root resolves to its workspace-relative path.
  • CLI. bb thread spawn --environment recognizes C:\… and c:/… as a path, not an ID.
  • docs/platform-support.md documents the drive-letter rules.

No wire change: the daemon protocol and HostPlatform are untouched, so a Windows daemon still reports unknown. Not included: Windows paths in Markdown file links that agents print, drive switching in the remote path browser, and the dialog placeholder text.

How you verified

  • Linux: turbo run lint typecheck test for @bb/domain, @bb/db, @bb/server-contract, @bb/server, @bb/cli, @bb/app, and the two environment plugins. 25 of 26 tasks passed in the combined run; the server task had 4 failures of 3,226 tests (machine-environment.test.ts timeout and three plugin-native-server-loading.test.ts cases) while two other Turbo runs shared the machine. Both files pass when rerun alone on this branch (5 of 5), and the second file is untouched by this change.
  • New tests, all runnable on Linux because the helpers do not use the ambient node:path: host-path.test.ts (flavor, normalization, comparison, containment, join), updated project-path.test.ts and contract test, case-insensitive Windows lookups (including a non-ASCII folder name), literal _ and % in owned paths, and case-sensitive POSIX lookups in environments.test.ts, managed-root detection for a Windows data directory, two route tests (three spellings of one Windows folder yield one project; a Windows folder is refused for a POSIX machine), app path helper and file-link tests, and the CLI path detection test.
  • Windows 11 Enterprise VM (build 26300), on a branch with this change on top of Start bb and run the bb CLI on native Windows #4657 (which is needed to build on Windows at all): bb project create --root with C:\src\testrepo, c:/src/TestRepo/, and C:\SRC\testrepo\. returned the same project with source path C:\src\testrepo; a UNC root returned HTTP 400 with the network-path message; a worktree thread got the environment path C:\bb-data\plugins\environment-git-worktree\host-data\worktrees\thr_…-1\PlainRepo (all backslashes); two checkout threads started with --environment C:\src\plainrepo and --environment c:/SRC/plainrepo/ shared one project-checkout environment; all three threads completed a turn. environments.test.ts also passes on the VM (16 of 16).

🤖 Generated with Claude Code

AGENT GENERATED

Project and workspace paths had to start with `/`, so a native Windows host
could not add `C:\src\repo`, and paths were compared as raw strings.

- Add `@bb/domain` host-path helpers that infer POSIX or Windows from the
  path's shape and normalize, join, compare, and contain paths for either.
- Store a Windows path in one spelling and compare Windows paths without
  regard to case in the database; POSIX paths keep exact comparison.
- Join host paths on the server with the host's separator instead of the
  server's own `node:path`.
- Build managed worktree and personal workspace paths with native separators.
- Refuse a Windows path for a machine that reported macOS, Linux, or WSL, and
  refuse UNC paths.

Co-Authored-By: Claude Code <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T01:45:23.937867Z dd5661d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SawyerHood
SawyerHood marked this pull request as draft October 1, 2026 23:37
@SawyerHood
SawyerHood added this pull request to stack #4666 October 2, 2026 00:17
@SawyerHood
SawyerHood marked this pull request as ready for review October 2, 2026 01:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd5661dec0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/db/src/data/host-path-sql.ts Outdated

export function hostPathEquals(column: SQLiteColumn, path: string): SQL {
return isWindowsHostPath(path)
? sql`${column} = ${path} COLLATE NOCASE`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Compare non-ASCII Windows paths case-insensitively

SQLite's built-in NOCASE collation only folds ASCII characters, so paths such as C:\src\Équipe and C:\src\équipe still compare as different even though they normally identify the same directory on Windows. This affects project deduplication and environment path claims, potentially allowing two environments to operate concurrently on the same checkout; use a normalized comparison key whose segments are case-folded before storage or lookup rather than relying on NOCASE.

Useful? React with 👍 / 👎.

Comment thread packages/db/src/data/host-path-sql.ts Outdated

export function hostPathContains(column: SQLiteColumn, path: string): SQL {
const descendant = isWindowsHostPath(path)
? sql`${path} LIKE ${column} || '\\%'`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Escape LIKE metacharacters in Windows containment checks

When a managed Windows path contains the legal filename characters _ or %, concatenating the stored column directly into a LIKE pattern treats those characters as wildcards. For example, an owned root C:\repos\foo_bar incorrectly contains C:\repos\fooXbar\child, which can cause unrelated workspaces to be rejected as provider-owned; escape metacharacters and add an explicit ESCAPE clause before performing this prefix match.

Useful? React with 👍 / 👎.

SQLite's NOCASE collation folds only ASCII letters, and the containment
check built a LIKE pattern from the stored path, so '_' and '%' in a
directory name matched any character. Path equality and containment now
run through connection-registered SQL functions backed by the shared host
path helpers.

Co-Authored-By: Claude Code <[email protected]>
@SawyerHood
SawyerHood merged commit 4b06794 into main Oct 2, 2026
21 checks passed
@SawyerHood
SawyerHood deleted the bb/windows-host-paths-thr_jensq3v9th branch October 2, 2026 03:22
SawyerHood added a commit that referenced this pull request Oct 2, 2026
## Human comments

## What was wrong

File links that an agent prints with a Windows path did not work in
rendered Markdown:

- `[readme](C:\src\repo\README.md)` and
`[readme](C:/src/repo/README.md:12)` rendered as plain text. The link
parser tested the href against a URI-scheme pattern first, so `C:` was
read as a scheme, the href was not recognised as a local file, and the
default URL transform dropped it.
- Markdown treats a backslash before punctuation as an escape, so a
destination such as `C:\src\repo\.config\app.json` lost its `\.` before
the parser saw it.
- `file:///C:/src/repo/README.md` parsed to the POSIX-looking path
`/C:/src/repo/README.md` and rendered as an external link.

Part of #1206. Stacked on #4659, which adds the Windows-aware path
helpers this uses for containment.

## What changed

- `apps/app/src/components/ui/markdown-local-file-link.ts`: a
drive-letter path (`C:\…` or `C:/…`) is a local file path, not a URL.
`file:` and editor URLs whose pathname is `/C:/…` yield `C:/…`.
Validation rejects drive roots and directory paths the same way it
rejects `/` and trailing-slash POSIX paths. `buildLocalFileAnchorHref`
renders a Windows link as `file:///C:/…` with each segment
percent-encoded.
- `markdown-local-file-link-normalize.ts`: before Markdown parsing, an
inline link destination that is a Windows drive path is rewritten to
forward slashes inside angle brackets, so no backslash is consumed as an
escape and spaces survive. While finding where such a destination ends,
a backslash is read as a path separator, not an escape, so
`[draft](C:\docs\(draft).md)` keeps its parentheses and becomes
`<C:/docs/(draft).md>`.

POSIX link handling is unchanged; the existing tests pass unmodified.

## How you verified

- Windows 11 Enterprise VM (build 26300), installed desktop build
containing this change and the other open Windows changes, driven
through its web UI: a message containing
`[readme](C:\src\testrepo\README.md)`,
`[fwd](C:/src/testrepo/README.md:1)`, and
`[uri](file:///C:/src/testrepo/README.md)` rendered three anchors with
hrefs `file:///C:/src/testrepo/README.md`, `…README.md#L1`, and
`…README.md`. Clicking `fwd` opened the file preview panel titled
`C:\src\testrepo\README.md` showing the file's contents. Before the
change the first two were plain text and the third was an external link.
- Linux: `turbo run lint typecheck test --filter=@bb/app` passes (6 of 6
tasks). New tests cover drive paths with line suffixes, `file:///C:/…`
URLs, rejected roots and directories, case-insensitive containment in a
Windows workspace root, the rendered anchor href, relative links under a
Windows root, and the normalization of backslash and space-containing
destinations and of a file name in parentheses after a separator. The
two link test files also pass on the VM (41 of 41).

Not verified: bare Windows paths that are not Markdown links are still
plain text (the same is true of bare POSIX paths); editor-scheme URLs
(`vscode://file/C:/…`) are covered only by the shared parsing path, not
by a click on Windows.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

---------

Co-authored-by: Claude Code <[email protected]>
ymichael added a commit that referenced this pull request Nov 2, 2026
## Human comments

## What was wrong

After #4659 added the shared host-path parser
(`packages/domain/src/host-path.ts`), the server files route, the skills
listing and the daemon skill-tree check kept their own path code. The
copies disagreed. Skill dirname/basename/join used a drive-letter regex,
so UNC paths were treated as POSIX and resolved to the wrong folder.
File preview `rootPath` accepted a rootless `\foo`. Relative paths
starting with a drive letter (`C:/x`) passed the files route, thread
open and skill reads, but the daemon rejected them. Skill reads returned
404 for malformed paths that every other route rejects with 400.

## What changed

- `@bb/domain`: new `getRelativeHostPathSegments` next to the
absolute-path parser.
- `apps/server/src/routes/files.ts`: uses the shared normalize/join and
the shared relative check. Windows separators in URL paths are still
turned into `/` before the check.
- `routes/relative-route-path.ts` deleted; thread open calls the shared
check.
- Skills listing and shared skills use the shared dirname/basename/join
(wrapped in `services/lib/host-path.ts`) and the shared relative check.
Hidden files still return 404; malformed paths now return 400.
- `apps/host-daemon/src/injected-skills.ts`: `isSafeTreePath` uses the
shared check plus its depth limit. No wire change.

Net: 119 added, 137 removed.

## How you verified

- One test table in `packages/domain/test/host-path.test.ts` runs every
removed check's cases (and the newly rejected ones) against
`getRelativeHostPathSegments`; added UNC dirname/basename cases.
- Updated `public-project-skills.test.ts`: `references/../../secrets.md`
now expects 400.
- `pnpm exec turbo run test lint --filter=@bb/server
--filter=@bb/host-daemon --filter=@bb/domain` and `turbo run typecheck`
for server and daemon pass.

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 3, 2026
## Human comments

## What was wrong

The Automations CLI copies core's thread-spawn helpers, and the copies
drifted. Its path check missed Windows paths (#4659), so `--environment
C:\repo` was saved as an environment id. `--new-environment` and
workspace paths picked the first host matching a `connected` field that
doesn't exist, then any connected host, then `hosts[0]` even when
offline. Core uses the CLI's own machine. `--at 2026-12-01` was read as
UTC midnight, but core rejects a date with no time as ambiguous.

## What changed

`plugins/automations/src/cli.ts` only:

- The path check uses core's rules: a backslash or a leading drive
letter makes the value a path.
- New environments and workspace paths run on the calling thread's
machine, falling back to `primaryHostId`. This reuses the thread-host
lookup that `--script-file` already had. The old host-list scan is
deleted.
- A date-only `--at` is rejected. Other `--at` values parse as before.
- The `--environment` help text now says where a path runs.

No plugin SDK, host-daemon protocol, or RPC contract changes. Open #6056
makes the same default-machine change as part of a larger feature;
whichever lands second will need a small conflict fix in `cli.ts`.

## How you verified

New tests in `server-harness.test.ts` failed before the fix and pass
after:

- `--environment C:\repo` and `--new-environment worktree` from a thread
land on that thread's machine. Before, the path was saved as `reuse` and
the worktree went to the first connected host.
- A date-only `--at` is rejected. Before, it was accepted.

Three existing expectations moved from the first connected host to the
primary host, so they now cover the no-thread fallback. `pnpm exec turbo
run test typecheck lint --filter=bb-plugin-automations` passes: 166
tests; lint has 0 errors and 4 warnings, all pre-existing in other
files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant