Skip to content

fix(cli): POSIX-normalize docsPaths for cross-platform portability#103

Merged
amondnet merged 1 commit intomainfrom
amondnet/cubic-agent-memory
Apr 17, 2026
Merged

fix(cli): POSIX-normalize docsPaths for cross-platform portability#103
amondnet merged 1 commit intomainfrom
amondnet/cubic-agent-memory

Conversation

@amondnet
Copy link
Copy Markdown
Contributor

@amondnet amondnet commented Apr 17, 2026

Summary

  • Re-applies the cubic P2 fix that was pushed to feat(cli): prompt to select docs paths on ask add #101 after it had already been merged, so the change never reached main.
  • sanitizeDocsPath in packages/cli/src/commands/add.ts now uses path.posix.normalize(trimmed.replaceAll('\\', '/')) so values persisted in ask.json always use forward slashes. Windows-authored docs\api and POSIX-authored docs/api produce the same stored token docs/api.
  • Traversal guard simplified to startsWith('../') — the normalized form is guaranteed POSIX after the fix.
  • Captures the pattern in .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, so df95077 landed on main without the POSIX fix. ec15af2 was pushed to the merged branch but never made it to main. This PR brings that fix plus the agent-memory onto main in one commit.

Test plan

  • bun run --cwd packages/cli build — clean
  • bun run --cwd packages/cli lint — clean
  • bun run --cwd packages/cli test505 pass, 0 fail (2 new tests: backslash normalization in stored output, ..\escape rejection on POSIX)
  • CI green (Cloudflare Pages, Test CLI, codecov, cubic AI reviewer)

Summary by cubic

Normalize docsPaths to POSIX forward slashes in the CLI so values in ask.json are consistent across platforms. Also tightens traversal checks and adds tests.

  • Bug Fixes
    • In packages/cli/src/commands/add.ts, use path.posix.normalize(trimmed.replaceAll('\\', '/')) to store paths like docs\api and docs/api as docs/api.
    • Simplify traversal guard to normalized === '..' || normalized.startsWith('../') now that output is POSIX.
    • Add tests for backslash→slash normalization and rejecting ..\escape.
    • Capture the normalization pattern in .claude/agent-memory/review-review-cubic-reviewer/ for future reviews.

Written for commit 60ee4cc. Summary will update on new commits.

…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.
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. type:bug Something isn't working labels Apr 17, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying ask-registry with  Cloudflare Pages  Cloudflare Pages

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

View logs

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

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
Loading

@amondnet amondnet merged commit 2608bab into main Apr 17, 2026
5 checks passed
@amondnet amondnet deleted the amondnet/cubic-agent-memory branch April 17, 2026 07:24
@github-actions github-actions bot mentioned this pull request Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files. type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant