Expand ~ and $HOME in the configured outputDirectory before writing - #129
Merged
Conversation
Collaborator
Author
Independent code review trailRan the independent Opus reviewer over Round 1 — 4 findings
Round 2 — 6 findings
Round 3 — 5 findings
Verification: |
5 tasks
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.
What & why
outputDirectorywas persisted and read as a raw string, so a value like~/notesor$HOME/notes(from a quotedconfig set, the interactive prompt, or a.envfile — none of which a shell expands) was handed straight toexistsSync/mkdirSync/resolve. The result was a literal~directory created under the cwd, silently scattering synced notes. This expands a leading~/$HOME/${HOME}at read time so files land in the home directory.Closes #125
Changes
src/libs/paths.ts(new):expandHomeDirectory(inputPath, resolveHomeDirectory)— a pure string transform that expands a leading~,~/…,$HOME, or${HOME}and returns everything else (absolute, relative, or a mid-string tilde) untouched.src/libs/markdown.ts:getOutputDirectory()now runs the configured value through the expander. This is the single read seam bothensureOutputDirectory(sync) andrequireOutputDirectory(dry-run preview) go through, so both paths are covered.src/libs/config.ts: the interactive prompt now trims its answer, matchingconfig set— a pasted" ~/notes"would otherwise never match the leading-token check.paths.ts(all required cases:~,~/sub,$HOME,${HOME}, absolute, relative-with-mid-tilde, plus~user/$HOMEworknon-matches, no-prefix skips env access, empty-home throws), the write + dry-run seams inmarkdown.ts, and the prompt-trim inconfig.ts.Key decisions
/separator. Only a home reference at the very start of the string expands; a directory legitimately named~mid-path (notes/~drafts) stays literal.~user(another user's home) is not resolvable, so it's left alone.os.homedir()runs only when a prefix actually matched, so a fully absoluteOUTPUT_DIRECTORYnever depends on the environment. An empty home fails loud rather than lettingjoin('', 'notes')degrade the path into a cwd-relative write.~/notesvisible in the config file and re-resolves per machine, matching the issue's recommendation.Viewable
Not a UI change. Behaviour is exercised by
markpost sync/markpost sync --dry-runwithoutputDirectoryset to~/notes.Follow-up suggestions
Expand ~/$HOME in push input paths—markpost push '~/vault/**'globs a literal~and matches nothing; run the same expander over push args in resolveMarkdownInputs. (suggested: P3, effort: S, evidence: src/commands/push.ts, src/libs/files.ts)Show expanded target in config get—config get outputDirectoryprints the raw~/noteswhile files land elsewhere; display the resolved path alongside it for debuggability. (suggested: P4, effort: S, evidence: src/commands/config.ts formatValue)Optional Windows separator support in home expansion— expansion only recognises the POSIX/; a Windows~\notesstays literal. Gate asep-based check on platform if Windows becomes a target. (suggested: P4, effort: S, evidence: src/libs/paths.ts)