Skip to content

fix: store persistent state under XDG state directory - #920

Open
mikemikimike wants to merge 6 commits into
modem-dev:mainfrom
mikemikimike:fix/issue-821-xdg-state
Open

mikemikimike wants to merge 6 commits into
modem-dev:mainfrom
mikemikimike:fix/issue-821-xdg-state

Conversation

@mikemikimike

@mikemikimike mikemikimike commented Aug 30, 2026 •

Copy link
Copy Markdown

Problem

Hunk stores persistent state at $XDG_CONFIG_HOME/hunk/state.json, next to the user-editable configuration file $XDG_CONFIG_HOME/hunk/config.toml. The XDG Base Directory Specification reserves XDG_CONFIG_HOME for configuration and XDG_STATE_HOME for persistent, non-portable application state. The same misplaced location is also used for the user-scoped global extensions directory.

This addresses issue #821, where state.json was expected under the state directory.

Root cause

Path resolution treated the configuration directory as the base for both editable configuration and persistent extension state. It also accepted a relative XDG_STATE_HOME, which could resolve state relative to the process working directory instead of an absolute user state location.

Solution

  • Resolve state.json and the global extensions directory under an absolute $XDG_STATE_HOME/hunk.
  • Fall back to ~/.local/state/hunk when XDG_STATE_HOME is unset or relative.
  • Keep config.toml under $XDG_CONFIG_HOME/hunk, with the existing ~/.config/hunk fallback.
  • Update the PTY environment, extension documentation, examples, and site sample to use the new global extension location.
  • Add regression coverage for explicit XDG directories, home-directory fallbacks, and a relative XDG_STATE_HOME.

Validation

  • bun test src/core/run/paths.test.ts src/extensions/discovery.test.ts src/extensions/startup.test.ts src/extensions/manage/install.test.ts (66 passed)
  • bun run test:integration (193 passed, 1 skipped)
  • bun run typecheck
  • bun run lint
  • bun run deps:check
  • bun run check:docs
  • Formatting checks for the changed files and git diff --check

The repository-wide bun run test failures are reproducible on clean upstream main; the affected tests are unchanged by this PR.

Compatibility

This changes the default location of persistent state and globally managed extensions on XDG-compatible systems. User-editable configuration remains at its existing location. Existing state or extensions under the old configuration directory are not migrated automatically.

Fixes #821

@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

@mikemikimike is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

@benvinegar

Copy link
Copy Markdown
Member

Can you fix the PR description? It's poorly formatted. What problem are you solving, etc? (I can guess, but ...)

@mikemikimike

Copy link
Copy Markdown
Author

I rechecked this PR for issue #821. The PR description covers the reported persistent-state behavior, and I do not see a human changes-requested review or a failing check for the current head. Could a maintainer please review whether this fully resolves the issue and approve it, or advise on any remaining work?

@mikemikimike

Copy link
Copy Markdown
Author

The PR description now documents the problem, the XDG state/config split, the compatibility limitation, and the focused validation. Issue #821 is still open. Please review the current head when available; Vercel authorization is intentionally ignored.

This branch has not been deployed

No deployments
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.

state.json (and extensions dir) hardcoded under $XDG_CONFIG_HOME instead of $XDG_STATE_HOME

2 participants