Skip to content

fix(file-api): let a drive-root project contain the paths below it - #24742

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
leonlaiyc:claude/file-api-drive-root-project
Nov 7, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
leonlaiyc:claude/file-api-drive-root-project

Conversation

@leonlaiyc

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The dashboard's file viewer and path completion work under a project opened at a drive root (H:\, or /), as they already do under any other project directory.

Two dashboard file-API checks decide "is this inside the project?" with x.startswith(root + os.sep), where root is realpath(project). realpath keeps the trailing separator of a root (H:\, /), so root + os.sep becomes H:\\ (or //) and prefixes nothing real:

  • file_api/pinned_io.py::_resolve_project_relative (the resolve=1 path of file read / stream / download / office preview): every relative path under a drive-root KIROCREW_PROJECT_DIR is refused as outside_project.
  • file_api/path_complete.py::_complete_path_listing: the witness check on the opened directory refuses every subdirectory of a drive-root project as outside, so @-path completion offers nothing below the project's top level.

Measured on Windows 11 / Python 3.13 at origin/main: with KIROCREW_PROJECT_DIR=C:\, _resolve_project_relative("Users/…/clip.mp4") returns ("", "outside_project"), and completing ./Users/…/ under a known project C:\ returns outside: true with no rows.

Why it matters

An operator who keeps work on a dedicated drive and opens it at its root (the layout #24475 reports, H:\) finds that relative file links in chat do not open and path completion lists nothing below the top level. Nothing says why: the refusal is the same outside_project / outside answer a real escape gets. Both checks fail closed, so this is a broken feature, not a leak.

Not a goal

What changed (motivation → approach → change)

  • Symptom → cause: root + os.sep assumes root does not already end in a separator; a drive root or / always does.
  • Change: both checks ask sandbox_plan.path_within(path, root), which compares against normpath(root).rstrip(os.sep) + os.sep and keeps the equality case. It is the helper fix(subagent): let a drive-root cwd allow-list entry admit its subtree #24504 and fix(terminal): count paths under a drive-root project as agent-writable #24694 route their sites through, so the file API does not carry a third hand-rolled prefix test. Equality, the sibling-name guard (…/proj-other vs …/proj) and every refusal branch are unchanged.
  • sandbox_plan imports only the standard library. The file_api owners run on dashboard/handlers/files.py's globals (_facade_compose), so the facade binds sandbox_plan and each owner names it under TYPE_CHECKING, the same way they reach pinned_fs and platform_compat.

Backwards compatibility

Compatible: for every project root that does not end in a separator, path_within gives the same answer as the old test. For a drive root or / it now admits the paths below the root, which every later gate (the validator's sensitive-path fence, the per-entry fence in completion) still screens.

Removes nothing: no key, route, response field or function is removed; the change only stops refusing paths that are inside the project.

Tests

Proof: PROVEN test/test_file_stream.py::test_resolve_admits_a_path_below_a_drive_root_project test/test_path_complete.py::TestPathComplete::test_a_drive_root_project_completes_below_itself (head 10c3bec99459)

  • test_file_stream.py::test_resolve_admits_a_path_below_a_drive_root_project (new): with KIROCREW_PROJECT_DIR set to the drive root of tmp_path (C:\ on Windows, / on POSIX), a relative path to a real file resolves to that file. Fails on main (outside_project).
  • test_path_complete.py::TestPathComplete::test_a_drive_root_project_completes_below_itself (new): through the real /api/path-complete route, a known project at the drive root completes a directory below it and lists its entries. Fails on main (outside: true, no rows).
  • Existing guards still pass: test_a_witness_outside_the_root_is_refused, the ../outside/ and ../<project>/src/ cases, the UNC / drive-absolute pass-through, and the outside_project refusals in test_file_download.py / test_file_office_preview.py.
  • Windows 11, Python 3.13: test_path_complete.py, test_file_stream.py, test_dashboard_files_composition_contract.py, test_dashboard_files_onloop_fs.py, test_file_office_preview.py, test_file_download.py, test_validation.py, test_pathres_loop_starvation.py: 499 passed; the 7 failures (symlink creation needs a privilege this host lacks, CRLF and content-type differences) fail identically on main on this host, which passes 497.
  • black gate, isort, flake8, mypy (touched modules), comment-history, brand, file-line cap, flake-pattern ratchet.

Manual verification

N/A — unit coverage sufficient: the defect is a string-prefix test, and both new tests drive it with the real drive root of the host they run on, one of them through the HTTP route.

Related Issues

Related to #24475 (same root + os.sep drive-root defect; that issue's validate_cwd site is #24504, the terminal sites are #24694)

Sibling sweep

Swept: git grep -nE "startswith\(.{0,60}(\+ ?os\.sep|\+ ?os\.path\.sep)" -- src/kiro_crew (wider than #24694's sweep, which only matched a bare identifier before + os.sep)
Sibling: src/kiro_crew/dashboard/file_api/pinned_io.py:430 -- changed here -- resolve=1 project-relative paths
Sibling: src/kiro_crew/dashboard/file_api/path_complete.py:266 -- changed here -- the completion witness check
Sibling: src/kiro_crew/subagent_parts/agent_policy.py:941 -- tracked in #24504 -- validate_cwd allow-list
Sibling: src/kiro_crew/dashboard/terminal_commands.py:472 -- tracked in #24694 -- agent-writable PATH filter
Sibling: src/kiro_crew/name_grant.py:534 -- tracked in #24694 -- name-grant agent-tree refusal
Sibling: src/kiro_crew/folder_steering.py:339 -- not affected -- by this PR; the memory-silo fence is fixed in its own PR
Sibling: src/kiro_crew/folder_steering.py:176 -- not affected -- skip roots are .kiro/steering dirs, never a drive root
Sibling: src/kiro_crew/dashboard/handlers/worktree.py:835 -- not affected -- already strips the separator before appending one
Sibling: src/kiro_crew/artifact_source.py:199 -- not affected -- already strips the separator before appending one

Pattern harvest

Rule candidate: semgrep
Pattern: x.startswith(root + os.sep) where root came from realpath/abspath of a configured directory; use sandbox_plan.path_within, since a drive root or / already ends in a separator

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

🤖 Generated with Claude Code

@leonlaiyc
leonlaiyc requested review from a team and KiroCrewCaptain as code owners October 27, 2026 05:42
@leonlaiyc
leonlaiyc requested a review from iamwhatever October 27, 2026 05:42
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 354c1c8e1a00d8983703805e52b38bb37c0348d3 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 354c1c8e1a00d8983703805e52b38bb37c0348d3 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Both containment checks now call the existing sandbox_plan.path_within (sandbox_plan.py:630) instead of a third hand-written prefix test. The fix addresses the mechanism, its two tests fail on base, and it changes no default.

What this change ships

Inventory (4 items) — 4 justified

Intent: let the dashboard file viewer and @-path completion work under a project opened at a drive root (H:\, /). This is a FIX.

  1. Relative file links (read, stream, download, office preview) under a drive-root project open instead of returning outside_project — justified
  2. Path completion lists subdirectories below a drive-root project instead of returning outside — justified
  3. The files facade now binds sandbox_plan for its file_api owners — justified
  4. Two regression tests pin the drive-root case on the host's real root — justified

[FIRST-PRINCIPLES-REVIEWED] 354c1c8

Description read

[DESCRIPTION-READ] 91c29603d98ca47c6e7ca5f1400a320b738a24c3efe7ce15ebedf6c38f94f1df

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 354c1c8e1a00d8983703805e52b38bb37c0348d3 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Narrow fix at the actual cause. Both checks now use the containment helper the codebase already has, and the new tests drive the real root of whatever host they run on, so POSIX CI covers the / case.

[DESIGN-REVIEWED] 354c1c8

Description read

[DESCRIPTION-READ] fff7a8fdc186b43c797caaddc1b846a771818c65532fdccf4405ab4337bb0a2d

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 354c1c8e1a00d8983703805e52b38bb37c0348d3 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 354c1c8

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 354c1c8e1a00d8983703805e52b38bb37c0348d3 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 354c1c8

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 27, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 27, 2026
@leonlaiyc
leonlaiyc force-pushed the claude/file-api-drive-root-project branch from 10c3bec to 5e0b7c3 Compare October 31, 2026 14:53
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 31, 2026
_resolve_project_relative and the path-completion witness check tested
containment with startswith(root + os.sep). realpath keeps the
separator of a root, so for a project at H:\ or / the prefix became a
doubled separator and every relative path or subdirectory under the
project was refused as outside it. Both now ask
sandbox_plan.path_within, the helper the validate_cwd and terminal
sites use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamwhatever
iamwhatever force-pushed the claude/file-api-drive-root-project branch from 5e0b7c3 to 354c1c8 Compare November 6, 2026 11:22
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@iamwhatever iamwhatever self-assigned this Nov 6, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving at 354c1c8. All checks pass and there are no change requests.

What I checked:

  • sandbox_plan.path_within gives the same answer as the old root + os.sep test for every project except one at a drive root. It strips the trailing separator before adding one, so H:\ and / no longer double it. Equal paths still count as inside.
  • Both callers keep their other checks. _complete_path_listing still runs is_sensitive_resolved_path on the witness. _resolve_project_relative still uses realpath on both sides.
  • files.py only adds sandbox_plan to the module names the file API reads through.
  • Each call site has a test for a drive-root project.
  • No new regex, and no new refusal.

@bolichen97
bolichen97 merged commit eaf92fc into kirodotdev:main Nov 7, 2026
102 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
buluoray pushed a commit that referenced this pull request Nov 7, 2026
…24742)

_resolve_project_relative and the path-completion witness check tested
containment with startswith(root + os.sep). realpath keeps the
separator of a root, so for a project at H:\ or / the prefix became a
doubled separator and every relative path or subdirectory under the
project was refused as outside it. Both now ask
sandbox_plan.path_within, the helper the validate_cwd and terminal
sites use.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit eaf92fc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants