Skip to content

fix(terminal): count paths under a drive-root project as agent-writable - #24694

Merged
iamwhatever merged 2 commits into
kirodotdev:mainfrom
leonlaiyc:claude/terminal-within-drive-root
Oct 28, 2026
Merged

iamwhatever merged 2 commits into
kirodotdev:mainfrom
leonlaiyc:claude/terminal-within-drive-root

Conversation

@leonlaiyc

@leonlaiyc leonlaiyc commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Terminal command completion treats a PATH entry under a drive-root project directory (H:\, or /) as agent-writable, as it already does under any other project directory.

#24475 reports that validate_cwd cannot admit anything below a drive-root allow-list entry, because realpath("H:\\") keeps its trailing separator and root + os.sep becomes H:\\. #24504 fixes validate_cwd by routing it through sandbox_plan.path_within. The same test, real.startswith(root + os.sep), is in dashboard/terminal_commands.py::_within, which decides which PATH entries the command-completion probe must drop because the agent can write them. With KIROCREW_PROJECT_DIR or the workspace root at a drive root, no entry below it counts as inside, so _sanitized_path stops dropping them for that reason.

Why it matters

_within is the check that keeps an agent-writable directory out of the PATH the completion probe resolves commands from. Measured on a Windows 11 host on origin/main: _within("C:\\...\\repo\\bin", ("C:\\",)) is False. An operator who opens a project at a drive root (a common Windows layout for a dedicated work drive) silently loses that filter for every PATH entry on the drive.

Not a goal

What changed (motivation → approach → change)

  • Symptom → cause: root + os.sep assumes root does not already end in a separator. realpath strips a trailing separator from every path except a root, where it is part of the name (H:\, /).
  • Change: _within now asks sandbox_plan.path_within(real, root), which compares normpath(root).rstrip(os.sep) + os.sep, the helper fix(subagent): let a drive-root cwd allow-list entry admit its subtree #24504 uses for validate_cwd. One containment rule for both sites instead of a second hand-rolled prefix test. Equality, the sibling-name guard (…/workspace-other vs …/workspace) and the fail-closed None / OSError branches are unchanged.
  • sandbox_plan imports only the standard library, so the new import adds no dependency to the dashboard module.
  • Second commit, same defect: name_grant._within ran the identical real.startswith(root + os.sep) over the same agent_writable_roots() (KIROCREW_PROJECT_DIR plus workspace_root()). Under a drive-root project a program planted below the root was not counted as agent-tree, so a name grant honoured it instead of refusing it with AGENT_TREE. It now asks sandbox_plan.path_within too, so one containment rule serves both readers of those roots. The First Principles review on 29e1177377 named this site; the original sweep regex matched it and the list below left it out.

Backwards compatibility

Compatible: for every 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 reports the paths below the root as inside, which only removes entries from the probe's PATH, and makes a name grant refuse a program resolved below that root.

Removes nothing: no key, route or function is removed; the change can only make _sanitized_path drop more agent-writable entries and a name grant refuse more agent-tree programs, never fewer.

Tests

Proof: PROVEN test/test_terminal_commands.py::TestSanitizedPath::test_a_drive_root_contains_every_path_below_it (head 29e1177)
Proof: PROVEN test/test_name_grant_windows.py::TestAgentWritableRootContainment::test_a_drive_root_contains_every_path_below_it (head ac29c23)

  • test_terminal_commands.py::TestSanitizedPath::test_a_drive_root_contains_every_path_below_it (new): a directory below the drive root of tmp_path (C:\ on Windows, / on POSIX) is inside that root. Fails on main (False).
  • Existing guards still pass: test_a_sibling_of_a_root_is_not_inside_it (sibling-name, root itself, path inside) and test_an_undetermined_root_set_refuses_every_entry (fail closed).
  • Windows 11, Python 3.13: test_terminal_commands.py, test_terminal_facade.py, test_terminal_handler.py, test_api_health.py, test_facade_mirror_guards.py: 327 passed; the 19 failures (POSIX shell resolution in test_terminal_handler.py) fail identically on main on this host, which passes 326.
  • test_name_grant_windows.py::TestAgentWritableRootContainment (new, runs on every host; test_name_grant.py is skipped on Windows): the drive-root case fails on main (False); the sibling-name / root-itself / inside case passes before and after.
  • Windows 11, Python 3.13, at ac29c23189: test_name_grant.py, test_name_grant_windows.py, test_name_grant_facade.py, test_name_grant_surfaces.py, test_terminal_commands.py, test_facade_mirror_guards.py: all pass (POSIX-only modules skip here).
  • black gate, isort, flake8, comment-history, brand, file-line cap, flake-pattern ratchet; Semgrep (--baseline-commit) on the first commit only.

Manual verification

N/A — unit coverage sufficient: the defect is a string-prefix test, and the new test drives it with the real drive root of the host it runs on.

Related Issues

Part of #24475 (the validate_cwd half is #24504)

Sibling sweep

Swept: git grep -nE "startswith\([a-z_]+ ?\+ ?(os\.sep|\"/\"|os\.path\.sep)\)" -- src/kiro_crew
Sibling: src/kiro_crew/subagent_parts/agent_policy.py -- tracked in #24504 -- validate_cwd, the reported site
Sibling: src/kiro_crew/name_grant.py:534 -- fixed in this PR -- _within, same roots as the terminal site (second commit)
Sibling: src/kiro_crew/dashboard/file_api/pinned_io.py:430 -- tracked in #24742 -- project-relative resolve under a drive-root project
Sibling: src/kiro_crew/dashboard/file_api/path_complete.py:266 -- tracked in #24742 -- path-completion witness check
Sibling: src/kiro_crew/folder_steering.py:339 -- tracked in #24743 -- memory-silo fence, both directions
Sibling: src/kiro_crew/apps/module_loader.py:199 -- not affected -- roots are app source directories, never a drive root
Sibling: src/kiro_crew/dashboard/token_auth.py:110 -- not affected -- URL paths, no trailing-separator root
Sibling: src/kiro_crew/acp/kas_agents.py:299 -- not affected -- the roots are the fixed /proc, /sys and /dev, none of them /
Sibling: src/kiro_crew/apps/agent_launch.py:221 -- not affected -- roots are an app agent's launch directory (launch_cwd_roots), which sits under the data home, never at a drive root

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

The completion probe's _within tested `real.startswith(root + os.sep)`.
realpath keeps the separator a drive root already ends in (H:\, or /),
so with the project directory or workspace root at a drive root the
prefix became H:\\ and no PATH entry below it counted as agent-writable,
and _sanitized_path no longer dropped them for being agent-writable.

Route the test through sandbox_plan.path_within, which already treats
a root ending in a separator as its own prefix: the helper kirodotdev#24504
routes validate_cwd through for the same defect.

Part of kirodotdev#24475

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leonlaiyc
leonlaiyc requested review from a team and KiroCrewCaptain as code owners October 27, 2026 02:39
@leonlaiyc
leonlaiyc requested a review from buluoray October 27, 2026 02:39
@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 ac29c23189d3602d75909a47ea253b926eba554a 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

Design Review (Opus 5.5, fork) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: both _within copies now use the shared sandbox_plan.path_within, which fixes the root cause. The change can only make the checks refuse more paths, never fewer.

[DESIGN-REVIEWED] ac29c23

Description read

[DESCRIPTION-READ] ed921eb063c1ea7a77ebadc6c6214c8b39e304dd9e1c8d1823b69e7f9cf52fe6

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

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

Premise-level review of ac29c23189d3602d75909a47ea253b926eba554a 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

The fix calls the existing containment helper at both readers of the agent-writable roots, so nothing blocks. One note: the sibling sweep leaves out two sites that its own regex matches.

Notes

  • Item 3 — symptom-level: the sweep regex startswith\([a-z_]+ ?\+ ?(os\.sep|"/"|os\.path\.sep)\) matches 50 sites under src/kiro_crew. Two of them build the same root + os.sep over a project-dir root, and the "Sibling sweep" list leaves both out:

    • dashboard/file_api/pinned_io.py:430 (resolved_proj = realpath(KIROCREW_PROJECT_DIR))
    • dashboard/file_api/path_complete.py:266

    Under a drive-root project, both refuse every path below the root. That fails closed, so it is out of this Goal and not a blocker. Subtraction: replace those two hand-rolled tests with sandbox_plan.path_within, here or in a follow-up.

What this change ships

Inventory (3 items) — 2 justified

Intent: under a drive-root project, keep agent-writable PATH entries out of command completion and refuse name grants for programs planted there. FIX.

  1. Command completion now drops agent-writable PATH entries below a drive-root project (H:\, /) — justified
  2. A name grant now refuses (AGENT_TREE) a program resolved below a drive-root project — justified
  3. Two hand-rolled prefix tests now go through the existing sandbox_plan.path_within; two same-cause siblings are left — symptom-level (2 unlisted siblings)

[FIRST-PRINCIPLES-REVIEWED] ac29c23

Description read

[DESCRIPTION-READ] 3afe8df1f7daa69ef7162e7bb5a34d322f5f23d2db6e7b8ebfb09a9b8918417b

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

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ac29c23

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] ac29c23

…able

name_grant._within compared against root + os.sep, the same test the
previous commit replaced in terminal_commands._within, over the same
agent_writable_roots(). A drive root (H:\ or /) already ends in a
separator, so no path below it counted as inside, and a program planted
under a drive-root project was honoured by a name grant instead of being
refused as agent-tree. Route it through sandbox_plan.path_within so one
containment rule serves both sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 27, 2026
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

ac29c23189 addresses the First Principles note on 29e1177377 (name_grant.py:534, the identical sibling the sweep left out).

name_grant._within ran the same real.startswith(root + os.sep) over the same agent_writable_roots(), so under a drive-root project a program planted below the root was honoured by a name grant instead of refused as AGENT_TREE. It now asks sandbox_plan.path_within too, the subtraction the review proposed: one containment rule, two readers. This is the second and last commit; the Goal is unchanged, and the body's What changed / Tests / Sibling sweep now include the second site.

The new test lives in test_name_grant_windows.py::TestAgentWritableRootContainment because test_name_grant.py is skipped on Windows. It fails on main and passes here; the name_grant and terminal suites pass on Windows 11 / Python 3.13.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 27, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 27, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Hold at ac29c23 for human review.

Both _within checks now call sandbox_plan.path_within (name_grant.py#L535, terminal_commands.py#L474). One decides which name grants are refused as agent-tree. The other decides which PATH entries the completion probe drops as agent-writable. Both are trust filters, so this is reserved for a human reviewer.

I found no defect. For any root that does not end in a separator, path_within (sandbox_plan.py#L543) gives the old answer. For a drive root or / it contains the paths below, so both checks can only refuse more. The remaining siblings are in open PRs #24742, #24743 and #24504. All AI lanes pass and checks are green.

— crew-pr-reviewer (r129)

@iamwhatever iamwhatever 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.

APPROVE (security-sensitive scope, maintainer-accepted)

This PR touches a security-sensitive area, so it was held for a human decision. A maintainer reviewed the deep-check notes for this exact head (ac29c23189d3) and accepted it. This approval supersedes any earlier HOLD from crew-pr-reviewer.

Why it is safe: fixes two path-containment checks for projects at a drive root; the change only makes the writable-path check stricter. CI is green on this head, the base is main, and there is no conflict.

— crew-pr-reviewer (r132)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 28, 2026 16:10
@iamwhatever
iamwhatever merged commit 8105665 into kirodotdev:main Oct 28, 2026
124 of 132 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 28, 2026
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.

2 participants