All jobs

Persist Pinia State in a Vue App from a Linear Issue

An agent keeps a Vue app's user name and language in localStorage, restores them after hydration, adds a clear button, and pnpm test passes.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads src/stores/user.ts, src/modules/i18n.ts, src/modules/pinia.ts, TheFooter.vue, main.ts, the hi/ and index.vue pages and the existing tests before writing. The store held savedName and a previousNames set in memory only, and the footer's language toggle called loadLanguageAsync itself.

It adds src/composables/preferences.ts, which stores {name, locale} under one key, vitesse:preferences, and guards every access with typeof window and try/catch so the SSG build never touches storage. setNewName saves the name, a new setPreferredLanguage in i18n.ts saves the language and the footer calls it, so i18n stays the one locale owner. App.vue restores both in onMounted, and a trash-can button in the footer clears them.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "A Linear issue labeled agent asks us to persist the Vue app's user name and preferred language across reloads using localStorage, with a way to clear them. Read the actual Pinia store, i18n loader, footer locale control and SSG initialization first. Extend their existing paths; do not introduce a second locale owner or persist unrelated state. Define restoration order, preserve an explicit route name, validate stored preferences and keep browser storage access out of server rendering. Add a visible clear action and tests for reloading, changing language and clearing preferences. Use the package manager declared by the repository. In Vitesse, run pnpm test --run and pnpm build. Open a pull request linking the Linear issue URL supplied in the task, with actual command results and any unresolved behavior.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

Tried on antfu-collective/vitesse at a878526: 9 files changed, 305 insertions(+), 4 deletions(-), with 131 lines in a new test/preferences.test.ts and 15 in src/auto-imports.d.ts, which the build regenerated. pnpm test --run and pnpm build both exited 0 before and after; the final run ended Tests 15 passed (15) and the build [vite-ssg] Build finished. The first test run failed the 2 footer tests of the 12 new ones with Need to install with app.use, and after the agent rewrote the test setup, one more failed on a locale saved after an async load until it waited with vi.waitFor.

For the reviewer: visiting /hi/<name> overwrites the stored name, and clearing also resets the language to en and drops previousNames; either may be wrong for you. The tests run in jsdom only: no real browser reload, no Cypress, and the new label is in en.yml alone, and the change adds fallbackLocale: 'en' so the other 17 locales show the English label. No Linear URL was given, so the link is a placeholder.

Run it on every Linear issue labeled agent

An automation with a linear trigger on linear.issue.labeled and the label agent runs the linear-label-to-pr recipe's prompt when someone in your Rush org labels an issue. If the issue lists which settings should survive a reload, those reach the agent instead of the name and language.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

Restoring from localStorage during setup would make the pre-rendered HTML and the first client render disagree. The run restores in onMounted, after hydration, and said plainly that this part is reasoned rather than tested in a browser.

Frequently asked questions

Why not pinia-plugin-persistedstate?

The issue asked for two values, and the language belongs to vue-i18n, not to Pinia. One small module keeps both under one key, so clearing is one removeItem, and nothing else in the store is persisted.

What happens to a bad stored value?

readPreferences drops a name that is blank or over 100 characters and ignores invalid JSON; a stored locale not in availableLocales falls back to en.

More Vue jobs

More jobs like this: Turn a Linear label into a PR

Keep reading