"fix(store): create the task directory lazily, on first write - #38
Merged
Conversation
The TaskStore constructor eagerly created `.pi/tasks/` even for sessions that never persist a task. Defer it: acquireLock() and save() already mkdir the directory on every write, so a session with no tasks now leaves no `.pi/tasks/` behind. Extracted from #32 — takes the lazy-creation half only. The auto-cleanup half (rmdir on session end) is intentionally not included. Co-authored-by: jalaxy33 <41473863+jalaxy33@users.noreply.github.com>
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
TaskStorecreated its backing directory (.pi/tasks/) eagerly in the constructor — even for sessions that never persist a task. This defers creation to the first write, so a session with no tasks leaves no empty.pi/tasks/behind.The directory still gets created exactly when needed:
acquireLock()andsave()alreadymkdir(..., { recursive: true })on every mutation (from #27), so nothing else had to change. The constructor'smkdirSyncwas redundant.Why it's safe
new TaskStore(...)and the first mutation.load()/list()/get()areexistsSync-guarded (a missing dir just yields an empty list); every mutation routes throughwithLock→acquireLock/save, which create the dir.create()→ dir + file appear; reload → task persists.Existing users
Purely subtractive. Task creation, listing, persistence, locking, and resume are unchanged, and existing
.pi/tasks/data is untouched. The only observable difference: a session that never creates a task no longer leaves an empty directory.Relationship to #32
Extracted from #32 (thanks @jalaxy33) — this takes the lazy-creation half only. The auto-cleanup half (
rmdirof.pi/tasks/and.pi/on session end) is intentionally not included. Closes #32.Test plan
npx tsc --noEmit— cleannpx vitest run— all pass, including a new test asserting the dir is not created on construction but is created on first writenpx biome check src/ test/— clean