Skip to content

Use the loaded supermemory config file in install and status - #92

Open
Chebaleomkar wants to merge 2 commits into
supermemoryai:mainfrom
Chebaleomkar:fix/cli-respect-jsonc-config
Open

Chebaleomkar wants to merge 2 commits into
supermemoryai:mainfrom
Chebaleomkar:fix/cli-respect-jsonc-config

Conversation

@Chebaleomkar

Copy link
Copy Markdown
Contributor

Fixes #91

Problem

The plugin loads supermemory.jsonc before supermemory.json, but the CLI only knew about supermemory.json. With a .jsonc config (the file the README tells users to create), status reported the working key as not configured, and install treated the setup as fresh and wrote a stray supermemory.json containing a copy of the API key and settings that never take effect.

Fix

  • src/config.ts: remember which file was actually loaded and export it as CONFIG_FILE. It falls back to supermemory.json only when neither file exists, so fresh installs behave exactly as before.
  • install: apply its defaults to that file with jsonc-parser (via the existing applyModification helper in opencode-config.ts), so user comments, formatting, and settings are preserved instead of the file being rewritten with JSON.stringify. This lives on the CLI side, so jsonc-parser does not enter the plugin runtime bundles (v2 index.js stays at ~141.7 KB).
  • status: parse the config as JSONC when reporting the key source.
  • Behaviour change: if the existing config can't be parsed, install now prints ⚠ Could not parse <file>; left it unchanged. instead of overwriting the user's file with defaults.

No effect on the plugin inside OpenCode sessions: CONFIG_FILE is only used by the CLI. Users who authenticate via login or SUPERMEMORY_API_KEY, or who keep their config in supermemory.json, see no difference. Stray supermemory.json files created by earlier versions are left alone; #91 tells affected users they can delete them.

Before / after

Same repro as #91 (sandboxed HOME, fake key, only supermemory.jsonc present):

# main
API key: sm_fak...1234 (not configured)
$ install --no-tui && ls ~/.config/opencode | grep supermemory
supermemory.json          <- new file with a copy of the key
supermemory.jsonc

# this branch
API key: sm_fak...1234 (~/.config/opencode/supermemory.jsonc)
$ install --no-tui && ls ~/.config/opencode | grep supermemory
supermemory.jsonc         <- untouched, comment preserved

Testing

  • New unit tests in src/services/opencode-config.test.ts for applyInstallDefaults: keeps comments and user settings, leaves an existing captureEveryNTurns untouched, writes fresh-install defaults, returns null for unparseable input.
  • bun run typecheck clean, bun test 37 pass.
  • Ran the built CLI end to end with a sandboxed HOME on Windows 11:
Config on disk install result status key source
only supermemory.jsonc no stray .json; file and comments unchanged …/supermemory.jsonc
none (fresh) creates supermemory.json with recallMode: "direct", captureEveryNTurns: 0 (unchanged from main) not configured
only supermemory.json (legacy) adds captureEveryNTurns: 3 (unchanged from main) …/supermemory.json
unparseable supermemory.jsonc warns, file left as is not configured

The plugin loads supermemory.jsonc before supermemory.json, but the CLI
always used supermemory.json. With only a .jsonc (as the README
suggests), install treated the setup as fresh and wrote a stray
supermemory.json with a copy of the API key and different settings that
never took effect, and status reported the key source as not configured.

Point CONFIG_FILE at the file that was actually loaded, apply install
defaults with jsonc-parser so comments are preserved (and leave
unparseable files alone), and parse the file as JSONC in status.
Keeps jsonc-parser out of the plugin runtime bundles, since only
install needs it, and warns instead of silently skipping when the
existing config cannot be parsed.
ishaanxgupta added a commit that referenced this pull request Sep 27, 2026
Fixes #97.

- Describe what the plugin does today: profile-only first-message context,
  direct recall by default, the real `[SUPERMEMORY]` and
  `<supermemory-context>` blocks, `search` scope and `limit` semantics,
  container tag precedence, `filterPrompt`, capture defaults, and
  `SUPERMEMORY_DEBUG`.
- Document the installer steps once, including the config-directory and
  in-place config handling from #92 and #94.
- The generated /supermemory-login command no longer claims a fixed port, and
  the tool's help lists `limit` for search.
- Add a CI workflow running typecheck, tests, and build on pull requests and
  pushes to main.
- Bump to 2.0.16 so the CLI fixes in #92, #94, and #96 publish together.
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.

CLI ignores supermemory.jsonc: status says the API key is "not configured" and install writes a stray copy of the key to supermemory.json

1 participant