Skip to content

Every slm command answers in JSON for agents - #349

Merged
varun369 merged 3 commits into
mainfrom
feat/cli-json-everywhere
Nov 21, 2026
Merged

varun369 merged 3 commits into
mainfrom
feat/cli-json-everywhere

Conversation

@varun369

Copy link
Copy Markdown
Member

Any agent, bot or framework that can run a shell command can now drive SuperLocalMemory without MCP.

  • All 210 command paths take --json; slm --json <command> and SLM_JSON=1 mean the same. One JSON document on stdout, everything else on stderr. Envelope {success, command, version, data | error{code, message}}, exit 0 success / 1 failed (error.exit_code keeps a specific code) / 2 could not run / 130 interrupted.
  • Under JSON a command never prompts: confirmation_required or input_required names the flag.
  • slm help --json returns the whole command tree.
  • slm mcp, slm session, slm session-context and slm hook ignore SLM_JSON, so MCP servers and hooks are byte-identical when a harness sets it everywhere. gdpr export streams.
  • slm tool failures now carry error: {code, message} in every form (the top-level code is kept). Scripts that read error as a string need a small change.
  • hooks install/remove --dry-run no longer writes settings.
  • A ratchet test fails if any command ships without --json.

Ships together with the skills/agents PR, which documents this behaviour.

🤖 Generated with Claude Code

varun369 and others added 3 commits November 21, 2026 13:52
Any harness without MCP can now drive SuperLocalMemory from a shell.
Before this change 165 of the 210 command paths (209 leaves plus the
`search` alias) took --json; now all of them do, and a ratchet test
walks the real parser so a new command cannot ship without it.

The contract:

- `slm --json <command>`, `SLM_JSON=1 slm <command>` and
  `slm <command> --json` are the same request. SLM_JSON never applies
  to `slm mcp`, so an MCP server launched from an environment that has
  it set still starts; `slm mcp --json` is the explicit form.
- stdout carries exactly one JSON object on one line, with success,
  command and version. Banners, notices, progress and logs go to
  stderr. Output a command printed before this change is kept as it
  was: an existing object only gains success/command/version when they
  are missing (no key is renamed or removed), and text is wrapped in
  the standard envelope.
- Errors carry {"code", "message"}. Exit 0 success, 1 the command ran
  and failed, 2 bad usage or could not run; usage errors are JSON too.
- Nothing prompts. A question becomes confirmation_required (naming
  the flag that confirms, e.g. --yes) or input_required (listing the
  flags that answer). First-use setup never runs the wizard under JSON.
- `slm help --json` (and `slm --json`, `slm --json X --help`) returns
  the command tree from the parser: every path, its summary, and its
  options with type, required, default and choices.

Commands whose plain form is a server, a launcher or a wizard have a
one-shot JSON form, documented in their --help:

- mcp: how to connect (stdio command, HTTP URL, daemon state); the
  server is not started.
- dashboard: URL, port and daemon state; starts nothing, no browser.
- serve: status reports; start/stop/install/uninstall act (the daemon
  runs in the background) and report the state afterwards.
- warmup: one object with ready after the same wait; exit 1 if not.
- wrap: --list lists agents; otherwise the planned action is reported
  and the agent is never launched.
- setup/init need --auto; reconfigure needs --profile=NAME passed
  through; migrate needs --yes (new flag); team reset-password needs
  --password-stdin; signing resign needs --yes.
- token show carries the key under data.install_token; rotate-token
  only the last four characters; remote keys add carries the new key
  once under data.key_secret, as its text form shows it once.

The parser is now built by an importable build_parser(); main() keeps
its behaviour, with the pre-dispatch steps split into _prepare() and
_before_dispatch().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes from an independent review of the JSON-everywhere change.

- gdpr export streams its own envelope as bytes to stdout's buffer.
  Capturing stdout into text made it crash (and held the export in
  memory several times over). Commands that print their own single
  envelope and stream it are now run with stdout untouched
  (STREAMS_OWN_JSON: gdpr export); prompts are still refused. No
  other command writes to stdout's buffer or streams to stdout.
- Hooks: `slm hook` drops SLM_JSON before running, so the commands it
  starts print what they print today. `session` and `session-context`
  ignore SLM_JSON too: the Stop hook runs `slm session close` on the
  hook's control channel. An explicit --json still works on them.
- The envelope escapes non-ASCII (ensure_ascii), as json_print does, so
  an ASCII or code-page stdout never fails.
- slm tool: a successful call prints the tool's result exactly as MCP
  returns it. A failure carries error {"code", "message"} and keeps the
  top-level code. The JSON wrapper turns any string error into that
  object, keeping an existing code. A backup failure under --json is
  an error object too.
- A bare trailing --json on a tool call (nothing after it, or another
  --flag) means JSON on; --json '{...}' still passes arguments.
- hooks install/remove --dry-run (with or without --json) now writes
  nothing and reports what would change; before, the Claude Code
  settings file was written.
- slm evidence with no subcommand exits 2 (usage).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…code contract

A failed `slm tool NAME` now carries error {code, message} in every
invocation form (after the tool name, global --json, SLM_JSON), keeping
existing top-level keys. Under JSON mode any exit code other than 0, 1, 2
or 130 becomes 1 with the original in error.exit_code (slm media status
with the daemon down: daemon_down, exit_code 3); text mode is unchanged.
The hooks dry run now tells a settings read failure from a merge failure.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@varun369
varun369 merged commit 4b0c823 into main Nov 21, 2026
9 checks passed
@varun369
varun369 deleted the feat/cli-json-everywhere branch November 21, 2026 10:33
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.

1 participant