Repository navigation
Every slm command answers in JSON for agents - #349
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Any agent, bot or framework that can run a shell command can now drive SuperLocalMemory without MCP.
--json;slm --json <command>andSLM_JSON=1mean 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_codekeeps a specific code) / 2 could not run / 130 interrupted.confirmation_requiredorinput_requirednames the flag.slm help --jsonreturns the whole command tree.slm mcp,slm session,slm session-contextandslm hookignoreSLM_JSON, so MCP servers and hooks are byte-identical when a harness sets it everywhere.gdpr exportstreams.slm toolfailures now carryerror: {code, message}in every form (the top-levelcodeis kept). Scripts that readerroras a string need a small change.hooks install/remove --dry-runno longer writes settings.--json.Ships together with the skills/agents PR, which documents this behaviour.
🤖 Generated with Claude Code