fix(cli): POSIX-normalize docsPaths for cross-platform portability#103
Merged
fix(cli): POSIX-normalize docsPaths for cross-platform portability#103
Conversation
…portability Cubic P2 flagged on the now-merged PR #101 but the fix was pushed after the merge landed, so it never made it to main. This reintroduces the change on top of the merged state, plus the agent-memory entry that captures the reusable pattern. - add.ts: replace `path.normalize(trimmed)` with `path.posix.normalize(trimmed.replaceAll('\\', '/'))` in `sanitizeDocsPath` so the value persisted in `ask.json` always uses forward slashes. A Windows user writing `docs\api` and a POSIX user writing `docs/api` now produce the same stored token `docs/api`. Traversal guard simplified to `startsWith('../')` — the normalized form is guaranteed POSIX after the fix. - Read side unchanged — `path.resolve` accepts both separator styles on Windows and forward slashes on POSIX, so the containment guard in `docs.ts` still works. - Tests: backslash→forward-slash normalization in stored output, and `..\escape` rejection on POSIX. - Agent memory: record the `path.normalize` → `path.posix.normalize` pattern so the cubic-reviewer subagent can recognize it next time.
Deploying ask-registry with
|
| Latest commit: |
60ee4cc
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6190c7c2.ask-registry.pages.dev |
| Branch Preview URL: | https://amondnet-cubic-agent-memory.ask-registry.pages.dev |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
No issues found across 4 files
Auto-approved: Safe, isolated fix for cross-platform path normalization. Includes tests and documentation updates to ensure consistency in configuration files across OSs.
Architecture diagram
sequenceDiagram
participant User as User / CLI Input
participant CLI as Add Command (packages/cli)
participant Sanitizer as sanitizeDocsPath()
participant Config as ask.json (Disk)
participant Consumer as Read Side (ask docs)
Note over User,Config: Path Configuration Flow (Write)
User->>CLI: runAdd(docsPathsArg)
CLI->>Sanitizer: Validate raw input (e.g., "docs\\api")
Sanitizer->>Sanitizer: Check path.isAbsolute()
rect rgb(240, 245, 255)
Note right of Sanitizer: NEW: Cross-platform Normalization
Sanitizer->>Sanitizer: CHANGED: replaceAll('\\', '/')
Sanitizer->>Sanitizer: CHANGED: path.posix.normalize()
end
alt Unsafe Path (Traversal)
Sanitizer->>Sanitizer: CHANGED: Check startsWith('../')
Sanitizer-->>CLI: return null
else Safe Path
Sanitizer-->>CLI: return "docs/api"
end
CLI->>Config: Persist normalized POSIX paths
Note right of Config: ask.json now contains:<br/>"docsPaths": ["docs/api"]
Note over Config,Consumer: Path Resolution Flow (Read)
Consumer->>Config: Load library configuration
Config-->>Consumer: ["docs/api"]
rect rgb(240, 245, 255)
Note right of Consumer: Portability Strategy
Consumer->>Consumer: path.resolve(projectRoot, "docs/api")
Note over Consumer: path.resolve handles POSIX separators<br/>on both Windows and Linux
end
Consumer-->>User: Resolved absolute path for docs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
main.sanitizeDocsPathinpackages/cli/src/commands/add.tsnow usespath.posix.normalize(trimmed.replaceAll('\\', '/'))so values persisted inask.jsonalways use forward slashes. Windows-authoreddocs\apiand POSIX-authoreddocs/apiproduce the same stored tokendocs/api.startsWith('../')— the normalized form is guaranteed POSIX after the fix..claude/agent-memory/review-review-cubic-reviewer/so the cubic-reviewer subagent can recognize it next time. Per CLAUDE.md, agent-memory changes ship with the code change that produced them.Why this is a separate PR
#101 was merged at 2026-04-17T06:58:55Z but cubic's second-pass review (P2 on
path.normalize) completed after the merge, sodf95077landed onmainwithout the POSIX fix.ec15af2was pushed to the merged branch but never made it tomain. This PR brings that fix plus the agent-memory ontomainin one commit.Test plan
bun run --cwd packages/cli build— cleanbun run --cwd packages/cli lint— cleanbun run --cwd packages/cli test— 505 pass, 0 fail (2 new tests: backslash normalization in stored output,..\escaperejection on POSIX)Summary by cubic
Normalize
docsPathsto POSIX forward slashes in the CLI so values inask.jsonare consistent across platforms. Also tightens traversal checks and adds tests.packages/cli/src/commands/add.ts, usepath.posix.normalize(trimmed.replaceAll('\\', '/'))to store paths likedocs\apianddocs/apiasdocs/api.normalized === '..' || normalized.startsWith('../')now that output is POSIX...\escape..claude/agent-memory/review-review-cubic-reviewer/for future reviews.Written for commit 60ee4cc. Summary will update on new commits.