Skip to content

Adds XDG Base Directory support (backward compatible)#612

Open
Joao-O-Santos wants to merge 9 commits intobacknotprop:mainfrom
Joao-O-Santos:main
Open

Adds XDG Base Directory support (backward compatible)#612
Joao-O-Santos wants to merge 9 commits intobacknotprop:mainfrom
Joao-O-Santos:main

Conversation

@Joao-O-Santos
Copy link
Copy Markdown

Add XDG Base Directory support (backward compatible)

First off, let me thank you for building this plugin and open sourcing it. I'm still just trying out the plugin, but I'm already seeing the benefits!

PR Rationale

I like to keep my $HOME directory as clean as possible, and have configured XDG_ env vars to help keep it that way. It is just a personal nit pick, but I wanted to get plannotator to respect XDG spec.

What this PR does

This PR adds support for the XDG Base Directory Specification while keeping ~/.plannotator as the default for full backward compatibility.

Before this PR

All plannotator data lived in a single ~/.plannotator/ directory:

  • Config (config.json)
  • Data (plans/, history/, hooks/)
  • Cache/transient files (drafts/, sessions/, pastes/, debug logs,
    schemas)

After this PR

Path resolution now follows this priority (highest wins):

  1. PLANNOTATOR_*_DIR env var (explicit override)
  2. XDG_*_HOME env var (spec compliance)
  3. ~/.plannotator (original default — unchanged)

| Category | Contents | Env override | XDG fallback | Default |
|----------|----------|--------------|--------------|---------| Config |
|config.json | PLANNOTATOR_CONFIG_DIR | XDG_CONFIG_HOME |
|~/.plannotator | Data | plans/, history/, hooks/ |
|PLANNOTATOR_DATA_DIR | XDG_DATA_HOME | ~/.plannotator | Cache |
|drafts/, sessions/, pastes/, logs, schemas | PLANNOTATOR_CACHE_DIR |
|XDG_CACHE_HOME | ~/.plannotator |

Migration strategy

  • Reads: new resolved path first, then fallback to ~/.plannotator/
  • Writes: always go to the resolved path
  • No forced migration: old data is never moved or deleted
  • Indefinite legacy support: existing users see zero change unless they set
    XDG vars

Files changed

  • packages/shared/paths.ts — new path resolution module
  • packages/shared/config.ts, storage.ts, draft.ts, improvement-hooks.ts
    — use new paths
  • packages/server/sessions.ts, browser.ts, codex-review.ts, tour/tour-review.ts — use new paths
  • apps/vscode-extension/src/extension.ts — match server's IPC path
  • apps/paste-service/targets/bun.ts — paste store uses cache dir
  • packages/ui/components/Settings.tsx, utils/planSave.ts,
    utils/quickLabels.ts — UI strings updated
  • scripts/install.sh, install.ps1, install.cmd — dynamic config path resolution
  • packages/shared/improvement-hooks.test.ts, tests/manual/local/test-sessions.sh — tests updated
  • Documentation (AGENTS.md, marketing docs, env var reference)
  • XDG_DESIGN.md — design decision record

Testing

  • Compiled and tested locally on Arch Linux
  • plannotator --help
  • plannotator annotate md_file.md
  • Hook mode (plan review) creates data in resolved path ✓
  • ~/.plannotator is not created when XDG vars are set ✓
  • Install scripts seem to dynamically resolve config path ✓

About this PR

The key design constraint was: no breaking changes. Users who don't set XDG_*_HOME should see absolutely zero difference in behavior. XDG support is
purely opt-in.

I am not a Node.js/TypeScript developer by trade, nor an AI tooling specialist. I reviewed the generated changes, tested them on my machine, and validated that the behavior is correct. The implementation was done with the help of an AI coding assistant (namely, OpenCode with the plannotator plugin). I reviewed the decisions, and overall approach. Still, this is not my wheel house.

Please review carefully, and do let me know what I need to fix.

Thank you for reading and considering the PR. Please keep up the good work!

Add packages/shared/paths.ts as the single source of truth for
config/data/cache directories.  Respects PLANNOTATOR_*_DIR overrides
and XDG_*_HOME variables, falling back to ~/.config/plannotator,
~/.config/plannotator/data, and ~/.cache/plannotator.

Updates config.ts, storage.ts, draft.ts, and improvement-hooks.ts
to use the new paths with transparent legacy fallback for reads.
Archive listing merges results from new and legacy paths so existing
plans remain visible.
Update server-side paths to use getCacheDir() for transient state:
- sessions.ts: ~/.cache/plannotator/sessions/
- browser.ts: ~/.cache/plannotator/vscode-ipc.json
- codex-review.ts: ~/.cache/plannotator/ (debug log + schema)
- tour/tour-review.ts: ~/.cache/plannotator/ (tour schema)
- vscode-extension/src/extension.ts: resolve vscode-ipc.json via
  getCacheDir() (PLANNOTATOR_CACHE_DIR / XDG_CACHE_HOME / ~/.cache)
- paste-service/targets/bun.ts: default paste dir under cache,
  keeping PASTE_DATA_DIR override for backward compat
Update user-facing labels, placeholders, and tooltip text to reflect
the new default data directory: ~/.config/plannotator/data/plans/
install.sh, install.ps1, and install.cmd now resolve config.json
through PLANNOTATOR_CONFIG_DIR > XDG_CONFIG_HOME > default
(~/.config/plannotator/config.json) instead of hardcoding
~/.plannotator/config.json.  Updates install.test.ts assertions
to match the new resolution functions.
- improvement-hooks.test.ts: create new-path fixtures under
  .config/plannotator/data/hooks/ and update assertions
- test-sessions.sh: use XDG_CACHE_HOME or ~/.cache for sessions dir
Update AGENTS.md and marketing docs to reflect the new directory
layout:
- Config: ~/.config/plannotator/
- Data: ~/.config/plannotator/data/
- Cache: ~/.cache/plannotator/

Add new env vars (PLANNOTATOR_CONFIG_DIR, PLANNOTATOR_DATA_DIR,
PLANNOTATOR_CACHE_DIR) to the environment variables reference.
Previously, all plannotator data lived in ~/.plannotator. This change
adds support for the XDG Base Directory Specification while keeping
~/.plannotator as the default for backward compatibility.

New behavior:
- No XDG_*_HOME set → uses ~/.plannotator (original behavior)
- XDG_CONFIG_HOME set → config goes to /home/random_user/.config/plannotator/
- XDG_DATA_HOME set → data goes to /home/random_user/.config/plannotator/
- XDG_CACHE_HOME set → cache goes to /home/random_user/.cache/plannotator/
- PLANNOTATOR_*_DIR → overrides everything (highest priority)

Data categories:
- Config: config.json
- Data: plans/, history/, hooks/
- Cache: drafts/, sessions/, pastes/, logs/, schemas/

Reads fall back transparently to ~/.plannotator so existing data
remains accessible. Writes always go to the resolved path.

New env vars documented:
- PLANNOTATOR_CONFIG_DIR
- PLANNOTATOR_DATA_DIR
- PLANNOTATOR_CACHE_DIR

Fixes #XXX (replace with actual issue number if applicable)
@Joao-O-Santos
Copy link
Copy Markdown
Author

Just saw @cwrau 's #568 which must be a better implementation than this. Feel free to close this one.

@backnotprop
Copy link
Copy Markdown
Owner

I will evaluate both approaches this weekend

Thanks for thoughtful approach!

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.

2 participants