Skip to content

refactor: unify path normalization with pathe#84

Merged
kermanx merged 7 commits into
mainfrom
feat/unify-pathe-path-normalization
May 27, 2026
Merged

refactor: unify path normalization with pathe#84
kermanx merged 7 commits into
mainfrom
feat/unify-pathe-path-normalization

Conversation

@kermanx
Copy link
Copy Markdown
Collaborator

@kermanx kermanx commented May 26, 2026

Related Issue

N/A – internal cleanup.

Problem

The codebase contained four separate copies of a toForwardSlashes helper scattered across kaos and agent-core. In addition, several files in agent-core unnecessarily imported node:path/win32 and maintained a pathMod factory just to switch between POSIX and win32 implementations, even though pathe already handles both platforms uniformly. This duplication and platform-branching added noise, caused minor TypeScript type mismatches, and made path handling harder to reason about.

What changed

  • packages/kaos/src/local.ts

    • Replaced node:path with pathe.
    • Removed the local toForwardSlashes helper; pathe.normalize / pathe.join now produce forward-slash paths on Windows automatically.
  • packages/agent-core

    • tools/builtin/file/grep.ts, tools/builtin/file/glob.ts, tools/policies/path-access.ts:
      • Removed toForwardSlashes and the node:path/win32 dependency.
      • relativizeIfUnder, parsedFilePath, canonicalizePath, and isWithinDirectory now rely on pathe.normalize.
    • agent/permission/path-glob-match.ts, tools/builtin/file/write.ts, tools/support/git-worktree.ts, tools/support/list-directory.ts:
      • Removed the pathMod(pathClass) factory and always call pathe directly.
    • profile/context.ts, profile/load.ts, tools/policies/sensitive.ts, agent/permission/policies/default-git-cwd-write.ts:
      • Replaced import * as posixPath from 'pathe' with named imports (dirname, join, basename, etc.).
      • Inlined the unused joinPath wrapper.
  • packages/kaos/src/path.ts

    • splitPathLexically now splits on '/' instead of pathMod.sep.
    • KaosPath normalizes internal win32 paths to forward slashes on construction.
  • Tests

    • Updated path-guard.test.ts win32 expectations to match the new forward-slash output.
    • Updated path.test.ts to assert forward-slash paths for win32 KaosPath instances.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 26, 2026

🦋 Changeset detected

Latest commit: 41c0679

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kaos Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

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

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: 926f33eaa6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/tools/policies/path-access.ts
Comment thread packages/agent-core/src/tools/policies/path-access.ts
kermanx added 3 commits May 26, 2026 20:35
…shes

- KaosPath now normalizes backslashes to forward slashes internally
  regardless of pathClass (posix or win32).
- KaosPath.toLocalPath() returns backslashes on win32 for OS interop.
- LocalKaos and SSHKaos both accept backslashes in input paths
  (pathe normalizes them automatically).
- SSHKaos switched from node:path/posix to pathe, removing manual
  backslash normalization.
- Update tests to reflect the new cross-slash behavior.
…rmalization

The fakeKaos mock now accepts both backslash and forward slash
arguments, matching the behavior of pathe-based path resolution.
@kermanx kermanx force-pushed the feat/unify-pathe-path-normalization branch from b559040 to ab79fb2 Compare May 26, 2026 12:41
Copy link
Copy Markdown

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

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: 50356521f9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/agent/permission/path-glob-match.ts
Comment thread packages/kaos/src/ssh.ts
Copy link
Copy Markdown

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

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: 41c0679bf7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kaos/src/path.ts
Comment thread packages/kaos/src/path.ts
Comment thread packages/agent-core/src/tools/policies/sensitive.ts
@kermanx kermanx changed the title refactor: unify path normalization with pathe and remove toForwardSlashes refactor: unify path normalization with pathe May 27, 2026
@kermanx kermanx merged commit e5717b7 into main May 27, 2026
5 checks passed
@kermanx kermanx deleted the feat/unify-pathe-path-normalization branch May 27, 2026 03:53
@github-actions github-actions Bot mentioned this pull request May 27, 2026
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