Skip to content

fix: preserve selected public subfolder when opening terminal#2003

Merged
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/public-terminal-path-resolution
Apr 1, 2026
Merged

fix: preserve selected public subfolder when opening terminal#2003
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/public-terminal-path-resolution

Conversation

@bajrangCoder
Copy link
Copy Markdown
Member

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR fixes a regression where opening a terminal from a subfolder within the Acode-documents public SAF provider always navigated to /public instead of the selected subfolder. The fix parses the SAF URI via Uri.parse to extract the docId, then maps it to the correct proot path through a series of prefix-matching branches, falling back to /public on any error.

Key changes:

  • Imports Uri utility for SAF URI parsing.
  • Replaces the hard-coded return \"/public\" with a try/catch block that extracts the docId from the URI and maps it to a proot-relative path.
  • Handles four distinct docId formats: full filesystem path, /public-prefixed string, public:-prefixed Android document ID, and a bare/relative segment.
  • Degrades gracefully to /public on parse failure.

Issues found:

  • Uri.parse returns an already-decoded docId in the no-:: URI branch, so the subsequent decodeURIComponent(docId || \"\") call double-decodes it. For paths with literal % characters this throws a URIError (silently caught), losing the subfolder path.
  • The final fallback branch (lines 67–68) strips only leading slashes before joining onto /public, so a docId shaped like public/subfolder would produce /public/public/subfolder.

Confidence Score: 4/5

Safe to merge; both findings are edge-case P2s that degrade to the old '/public' behaviour rather than causing crashes or data loss.

The primary fix is correct and an unambiguous improvement over the previous hard-coded return. The two issues are edge cases (percent characters in folder names, slash-separated docId format) that fall back to pre-existing '/public' behaviour via try/catch, introducing no regressions. Score is 4 rather than 5 because there is a concrete (if uncommon) path where the subfolder is silently dropped.

src/lib/openFolder.js – specifically the convertToProotPath function around lines 55 and 67–68.

Important Files Changed

Filename Overview
src/lib/openFolder.js Replaces the hard-coded "/public" return with logic that parses the SAF URI via Uri.parse to extract a subfolder docId and map it to the correct proot path; error handling degrades gracefully to "/public", but a latent double-decode issue exists.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["convertToProotPath(url)"] --> B{isAcodeTerminalPublicSafUri?}
    B -- No --> C[Strip file:// and map alpineRoot / publicDir]
    B -- Yes --> D["Uri.parse(url) → docId"]
    D --> E["cleanDocId = decodeURIComponent(docId || '')"]
    E --> F{cleanDocId empty?}
    F -- Yes --> G[return '/public']
    F -- No --> H{startsWith publicDir?}
    H -- Yes --> I["replace(publicDir, '/public')"]
    H -- No --> J{startsWith '/public'?}
    J -- Yes --> K["return cleanDocId as-is"]
    J -- No --> L{startsWith 'public:'?}
    L -- Yes --> M["Path.join('/public', relativePath)"]
    L -- No --> N["strip leading '/', Path.join('/public', ...)"]
    D -- throws --> O["console.warn + return '/public'"]
Loading

Reviews (1): Last reviewed commit: "fix: preserve selected public subfolder ..." | Re-trigger Greptile

@bajrangCoder bajrangCoder merged commit c522580 into Acode-Foundation:main Apr 1, 2026
6 checks passed
@bajrangCoder bajrangCoder deleted the fix/public-terminal-path-resolution branch April 1, 2026 03:32
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