kagura-memory 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,10 +14,15 @@ This SDK connects your TypeScript/JavaScript code to [Kagura Memory Cloud](https
14
14
  | **`WorkspaceClient`** | REST API | Workspace member, invitation, and API key management |
15
15
  | **`SecretClient`** | REST API | [Zero-knowledge secrets](#zero-knowledge-secrets) — age-encrypted on your machine, opaque to the server |
16
16
  | **`AgentsClient`** | REST API | Agent bootstrap for API-key-only callers (no MCP session) |
17
+ | **`MemoryClient`** | REST API | [Tool guardrails](#tool-guardrails-over-rest-memory-cloud-v0740) for API-key-only callers — the `AGENTS.md` export digest and the guardrail set |
17
18
 
18
19
  A `kagura-memory` command-line tool ships alongside it, mirroring the Python
19
20
  CLI's `kagura` command — see [Command line](#command-line).
20
21
 
22
+ For Claude Desktop, the [MCPB extension](docs/mcpb.md) provides browser sign-in
23
+ and a refresh-aware connection without Python or a global CLI install. The npm
24
+ package also includes `kagura-memory-mcp`, a transparent stdio/HTTP proxy.
25
+
21
26
  ## Installation
22
27
 
23
28
  ```bash
@@ -32,8 +37,10 @@ unless you ask for it.
32
37
  Targets memory-cloud **v0.75.0** (`MIN_SERVER_VERSION`).
33
38
  `checkServerVersion()` warns, and never throws, on an older server, which
34
39
  still answers: it ignores options it predates, leaves out fields it
35
- predates, and reports a tool it predates as not found. The method notes
36
- below say which server version a feature needs.
40
+ predates, and reports a tool it predates as not found. A pre-release of
41
+ the minimum (`0.75.0-rc1`) counts as older, and a version it cannot read
42
+ (`0.75`, `main-abc123`) gets no warning, as in the Python SDK. The method
43
+ notes below say which server version a feature needs.
37
44
 
38
45
  ## Quick Start
39
46
 
@@ -88,6 +95,16 @@ Four ways to authenticate, in resolution order:
88
95
  }
89
96
  ```
90
97
 
98
+ Credentials travel over HTTPS only. Every client, `login()`, `auth login
99
+ --server` and the URL every `setup` subcommand puts in a harness entry
100
+ (`setup claude`, `setup codex`, `setup hermes` and `setup openclaw`)
101
+ refuse a plain-HTTP URL unless its host is `localhost`, `127.0.0.1` or
102
+ `[::1]`, and `doctor` fails a configured `mcp_url` like that. The URL is
103
+ read as `fetch` reads it, so the scheme in any case (`HTTP://`), without
104
+ its slashes (`http:host`), or with whitespace or control characters
105
+ around it or a tab or newline inside it is refused all the same, as in
106
+ the Python SDK.
107
+
91
108
  ### Command line
92
109
 
93
110
  `kagura-memory` mirrors the Python CLI's `kagura` command: its subcommands
@@ -96,26 +113,53 @@ stdout and exits with the same codes (2 for a usage error, 1 for a runtime
96
113
  failure). An option a command, a group or the root does not take is
97
114
  refused in the words of click 8.3, the version the Python CLI's lockfile
98
115
  pins: `Error: No such option: --x`, naming the option without any value
99
- given in it (click 8.4 and later write `No such option '--x'.`, and may
100
- add a `Did you mean …?` this bin does not). The commands and options not
101
- ported yet, the few options only this bin has, and the deliberate
116
+ given in it, and for a long option close to one the command takes,
117
+ click's suggestion after it (`Did you mean --json?`, or `(Possible
118
+ options: --end, --period)` for more than one); click 8.4 and later write
119
+ `No such option '--x'.`. An option given no value is `Error: Option '-w'
120
+ requires an argument.`. Either error wins over `--help`, as click reads
121
+ the whole command line first, and only the first one is reported,
122
+ followed by the command's help (where click prints its usage line and a
123
+ `Try '… --help'` hint first). An unknown option does not win over
124
+ `--help` where the Python CLI passes such options on
125
+ (`ignore_unknown_options`: `secret exec`, and `measure record` for a
126
+ negative VALUE), so `secret exec --help --bogus` prints the help; without
127
+ `--help`, `secret exec` still refuses an unknown option before the child
128
+ command rather than running it as that command. The one command not
129
+ ported, the few options only this bin has, and the deliberate
102
130
  differences are listed below.
103
131
 
132
+ Values are read as click reads them. A choice matches exactly, as click's
133
+ `Choice` does, except where the Python CLI declares one case-insensitive
134
+ (`--source-type`, `--progress`), casefolded as click folds it; a number
135
+ is read as Python's `int()` and `float()` read it, `1_000`, any decimal
136
+ digit (`١٢`, `12`) and the whitespace they skip included (a BOM is no
137
+ whitespace to them); an integer id argument (`TOKEN_ID`,
138
+ `INVITATION_ID`, `KEY_ID`) is sent exactly, however large; and an
139
+ out-of-range value is echoed as click converted it (`files upload
140
+ --importance 2` is refused as `2.0 is not in the range 0.0<=x<=1.0.`).
141
+ A failure prints `Error: <message>` on stderr, and a quota or plan
142
+ refusal adds the lines the Python CLI adds: ` Resets at: <time>`, in
143
+ Python's `isoformat()` form, and ` Required plan: <label> (<key>)`.
144
+
104
145
  ```bash
105
146
  npx kagura-memory --help
106
147
  ```
107
148
 
108
149
  | Group | Commands |
109
150
  |---|---|
110
- | `auth` | `login` `logout` `refresh` `status` `use` `list` `token` |
151
+ | `auth` | `login` `logout` `refresh` `status` `use` `list` `token` `create-key` `list-keys` `revoke-key` |
111
152
  | `context` | `list` `create` `update` `delete` `search-config` (plus the `contexts` alias) |
112
153
  | memory | `remember` `recall` `reference` `forget` `update-memory` `explore` |
113
154
  | `edge` | `list` `create` `update` `delete` |
114
155
  | `sleep` | `history` `report` `rollback` |
156
+ | `measure` | `record` `series` |
115
157
  | `files` | `upload` `list` `delete` `download-url` |
158
+ | `guardrails` | `load` `digest` |
116
159
  | `resource` | `tokens {list,create,update,revoke}` `list` `setup` `schema` `stats` `indexer-status` `events` `ingest` `ingest-batch` `import` |
117
160
  | `secret` | `keygen` `list` `put` `get` `grant` `revoke` `rotate` `delete` `pubkeys` `approve` `audit-verify` `exec` |
118
161
  | `setup` | `claude` `codex` `hermes` `openclaw` |
162
+ | `workspace` | `member {list,add,set-role,remove}` `invite {create,list,revoke}` |
119
163
  | other | `config show` `doctor` |
120
164
 
121
165
  ```bash
@@ -123,6 +167,7 @@ npx kagura-memory auth login --profile work --read-only
123
167
  npx kagura-memory recall "OAuth setup" -c dev -k 10
124
168
  npx kagura-memory recall "dependency injection" --no-rerank # skip reranking; no flag follows the context config (v0.69.0+)
125
169
  npx kagura-memory remember -s "FastAPI DI" --content "Use Depends()" --tags "python,fastapi"
170
+ npx kagura-memory measure record <context-id> weight_kg 71.5 --unit kg
126
171
  npx kagura-memory setup codex --dry-run # show the command and the entry; change nothing
127
172
  npx kagura-memory doctor
128
173
  ```
@@ -132,6 +177,57 @@ The context id comes from `-c/--context-id`, or from `context_id` in
132
177
  shared with the Python CLI, so either tool can create a profile the other
133
178
  then uses.
134
179
 
180
+ **`resource setup`** names the new context after the resource, or `-n/--name`
181
+ (lowercase letters, digits, `-` and `_`, at most 100), which a workspace
182
+ that already has a context of that name needs. It prints Python's six
183
+ fields, `context_id`, `context_name`, `resource_id`, `token`, `token_id`
184
+ and `warning` (null when the server sends none); the token is shown this
185
+ once. `--summary` is accepted and ignored, with a note on stderr, since
186
+ the server's `setup_resource` has no summary: the context's owner sets it
187
+ afterwards with `kagura-memory context update <context_id> --summary …`.
188
+ As in Python, `resource tokens revoke` prints `Token revoked.`, and
189
+ `resource schema` prints `No schema registered for this resource.` when
190
+ there is none.
191
+
192
+ **Files and imports.** The `files` commands take their workspace from the
193
+ credential's own source, as the Python CLI does (its #115): `-c` when
194
+ given, else the OAuth profile's workspace, else the `context_id` of the
195
+ `.kagura.json` that holds the key; a `KAGURA_API_KEY` key needs `-c`.
196
+ `files delete` prints `Deleted <file_id>` and `files download-url` the bare
197
+ URL. `files upload --remember` writes the memory the Python CLI writes
198
+ (`source_uri` the file's `file://` URI, `details` the file's id, sha256,
199
+ size and type). `resource import` detects the format by the file's
200
+ extension, so stdin needs `--format`, and reads CSV and JSON the way
201
+ Python's `csv` and `json` modules read them, with their error messages
202
+ (exit 1). A row keeps its keys in the order read, and a doc_id taken from
203
+ a number is Python's `str()` of it as written (`1234567890123456789`,
204
+ `10.0`, `1e+20`). A `NaN` or `Infinity` in the input fails the batch
205
+ holding it, as the Python CLI's request encoding does (`Out of range float
206
+ values are not JSON compliant: nan`), rather than being sent as `null`. A
207
+ doc_id outside 1-255 characters and a CSV row with more cells than the
208
+ header are refused before anything is sent, where the Python CLI stops
209
+ with a traceback. Two limits of JavaScript numbers remain: a number in the
210
+ payload is sent as JavaScript reads it, so an integer past 2^53 loses its
211
+ last digits and `10.0` is sent as `10`, where Python sends them as
212
+ written; and `-V` above 2^53 is refused as too large (exit 2), where
213
+ Python sends it.
214
+
215
+ **Progress.** `files upload` and `resource import` take `-v/--verbose`
216
+ (repeatable) and `--progress rich|json|none`. Progress goes to stderr, one
217
+ line per event, so stdout carries the same result either way.
218
+ `--progress json` writes the Python CLI's NDJSON,
219
+ `{"v": 1, "ts": …, "stage": …, "kind": …, "msg": …, "detail": …}`, whose
220
+ last event is the operation's single `success` or `error`; `-v`, or
221
+ `--progress rich`, writes the lines the Python CLI shows
222
+ (`→ Reserving upload report.pdf (1234 bytes)`, `✓ Upload complete`,
223
+ `✗ Upload failed: …`); `--progress none` is silent even with `-v`. Two
224
+ streams end more reliably than Python's: `files upload --remember`
225
+ reports success only once the linked memory is written (a failed write
226
+ ends the stream with that error), and `resource import` ends with an
227
+ error when the credential fails after its start event. A stderr closed
228
+ early (`2>&1 | head -1`) does not stop the upload or the import. Ctrl-C
229
+ ends the process without a final event.
230
+
135
231
  **Connecting a harness.** Each `setup` subcommand sets up an MCP entry
136
232
  named `kagura-memory`: the URL plus a Bearer header. The key is never
137
233
  printed, and no harness CLI gets it on its command line.
@@ -140,18 +236,25 @@ printed, and no harness CLI gets it on its command line.
140
236
  comes from `--api-key`, else the `api_key` in the project's own
141
237
  `.kagura.json` (the one in `--project-dir`), else `KAGURA_API_KEY`; the
142
238
  URL likewise from `--mcp-url`, else that file's `mcp_url`, else
143
- `KAGURA_MCP_URL`. It never takes them from `~/.kagura.json`, nor, with
239
+ `KAGURA_MCP_URL`, an empty `--mcp-url` counting as none, as Python's `or`
240
+ reads it. It never takes them from `~/.kagura.json`, nor, with
144
241
  `--project-dir`, from the current directory's `.kagura.json`: those are
145
242
  another project's credentials. `.kagura.json` gets the URL as given; the
146
243
  parameters that `--guardrails` and `--tool-profile` set go on the entry's
147
- URL only.
148
-
149
- `setup codex`, `setup hermes` and `setup openclaw` never see, write, print
150
- or pass the key, as in the Python CLI. The entry names the environment
151
- variable the harness reads the key from, and the notes say where to put
152
- it; a missing key is no error. These three write no file themselves:
153
- no `.kagura.json`, no `.gitignore` line, no harness `.env`. The harness's
154
- own CLI writes the entry, or you add the printed block.
244
+ URL only. A plain-HTTP URL to a host other than localhost is refused,
245
+ whichever of the three it came from, before anything is written or run
246
+ (exit 1, `Connection failed: MCP URL must use HTTPS for security …`, the
247
+ Python CLI's words, whose connection test refuses it).
248
+
249
+ Without `--agents-md`, `setup codex`, `setup hermes` and `setup openclaw`
250
+ never see, write, print or pass the key, as in the Python CLI. The entry
251
+ names the environment variable the harness reads the key from, and the
252
+ notes say where to put it; a missing key is no error. These three write
253
+ no config file themselves: no `.kagura.json`, no `.gitignore` line, no
254
+ harness `.env`. The harness's own CLI writes the entry, or you add the
255
+ printed block. The one file they may write is the AGENTS.md export
256
+ (`--agents-md`, below), which is fetched with the usual credential: with
257
+ it, a missing credential stops setup (exit 1).
155
258
 
156
259
  | Subcommand | How the entry is applied | Where the key goes |
157
260
  |---|---|---|
@@ -171,10 +274,18 @@ OpenClaw's `$OPENCLAW_CONFIG_PATH` (default `openclaw.json` in the state
171
274
  directory). The closing notes name the command that checks it:
172
275
  `codex mcp get kagura-memory`, `hermes mcp test kagura-memory` or
173
276
  `openclaw mcp doctor kagura-memory --probe`. `--mcp-url` defaults to the
174
- configured `mcp_url`, then `https://memory.kagura-ai.com/mcp`. A plain
175
- `http://` `--mcp-url` other than localhost is a usage error (exit 2),
176
- since the entry sends the key there with every request; a configured
177
- `mcp_url` like that exits 1 and says to pass `--mcp-url`.
277
+ configured `mcp_url`, then `https://memory.kagura-ai.com/mcp`. It is read
278
+ as a URL parser reads it, as in Python (python-sdk#279): whitespace and
279
+ control characters around it, and any tab or newline inside it, are
280
+ dropped before the checks, and the entry gets that URL. A plain `http://`
281
+ `--mcp-url` other than localhost, in any spelling, is a usage error
282
+ (exit 2), since the entry sends the key there with every request; so is
283
+ anything but an http(s) URL with a host (`--mcp-url=--help`,
284
+ `memory.kagura-ai.com/mcp`, `https://[::1/mcp`), which would go on the
285
+ harness's command line after `--url`. A configured `mcp_url` gets the same
286
+ checks, and exits 1 saying to pass `--mcp-url`. `$OPENCLAW_STATE_DIR`,
287
+ `$OPENCLAW_CONFIG_PATH` and `$OPENCLAW_WORKSPACE_DIR` are read as OpenClaw
288
+ reads them: stripped, with a leading `~` expanded.
178
289
 
179
290
  This package has no TOML, YAML or JSON5 parser, so it never rewrites those
180
291
  files. When the harness's CLI is not on `PATH`, the block is printed on
@@ -188,8 +299,11 @@ always; for Hermes and OpenClaw only with their CLI on `PATH`, since the
188
299
  Python CLI finds their entries only through it. Without the CLI, setup
189
300
  prints the block to go in place of the old entry and exits 0. A
190
301
  `config.toml` that cannot be read stops `setup codex` (exit 1), as in
191
- Python; a Hermes or OpenClaw file that cannot be read stops nothing, since
192
- Python never reads those, and a note says setup could not look there.
302
+ Python. A Hermes `config.yaml` that cannot be read, or is not UTF-8,
303
+ stops nothing: setup prints the whole block with Python's note to put
304
+ only the entry under an `mcp_servers:` key the file may have. An OpenClaw
305
+ file that cannot be read stops nothing either, since Python never reads
306
+ it, and a note says setup could not look there.
193
307
  On Windows, a CLI installed only as an npm `.cmd` shim counts as not
194
308
  found: Node runs one only through a shell, which would re-parse the
195
309
  arguments.
@@ -217,14 +331,17 @@ codex`, when neither the flag nor the MCP URL (`--mcp-url` or the
217
331
  configured `mcp_url`) sets one, it defaults to `off` while the Kagura
218
332
  plugin's Codex hooks are on for the entry (their `config.json` names its
219
333
  table in `mcp_server`, `kagura-memory` by default), and otherwise to
220
- `-c` when that is a UUID. With a context there, the notes give the Python
221
- CLI's `kagura guardrails digest … --target instructions` command, which
222
- previews what Codex receives. Hermes and OpenClaw do not read the
223
- server's instructions. There `--guardrails off` is refused (exit 2), and
224
- a context id is not written, whether it comes from the flag or from the
225
- URL. A `?guardrails=off` already in the URL is kept, with a warning, as
226
- in Python. `--tool-profile` (claude, codex; memory-cloud
227
- v0.73.0+) sets `profile` and refuses an empty name. The server knows
334
+ `-c`. With a context there, the notes give the `kagura-memory guardrails
335
+ digest … --target instructions` command, which previews what Codex
336
+ receives. Hermes and OpenClaw do not read the server's instructions.
337
+ There `--guardrails off` is refused (exit 2), and a context id is not
338
+ written, whether it comes from the flag or from the URL: one warning
339
+ names what was dropped. A first `?guardrails=off` in the URL, the value
340
+ the server reads, is kept, alone and with a warning of its own. Names
341
+ compare decoded, as the server reads them (`guard%72ails` is
342
+ `guardrails`). All of this is as in Python. `--tool-profile` (claude,
343
+ codex; memory-cloud v0.73.0+) sets `profile` and refuses an empty name.
344
+ The server knows
228
345
  `full` and `core` (case-sensitive) and fails `tools/list` for any other
229
346
  name, which leaves the harness with no Kagura tools. It applies a
230
347
  `?tools=` allowlist already on the URL instead, so that case gets a
@@ -234,9 +351,44 @@ A `setup claude` run that leaves out a `guardrails` or `profile` value
234
351
  the entry it replaces had says so in a note. `--name`, `--force` and
235
352
  `--dry-run` (codex, hermes, openclaw) name the entry, replace an existing
236
353
  one, and show the command or block without changing anything. A name is
237
- 1-64 letters, digits, `-` or `_`, as in Python, and here it also starts
238
- with a letter or digit: it is a bare argument to `codex` and `openclaw`,
239
- which would read `--help` as an option.
354
+ 1-64 letters, digits, `-` or `_`, starting with a letter or digit, as in
355
+ Python: it is a bare argument to `codex` and `openclaw`, which would read
356
+ `--help` as an option. Their `--context-id` must be a context UUID
357
+ (exit 2 otherwise, a padded or empty one included), as in Python without
358
+ `--profile`: this port lists no contexts.
359
+
360
+ **The AGENTS.md export.** `--agents-md [PATH]` on `setup codex`, `setup
361
+ hermes` and `setup openclaw` (memory-cloud v0.74.0+) fetches the
362
+ context's tool guardrail export block (`MemoryClient.getGuardrailDigest`)
363
+ and splices it into a file the harness loads every session, between its
364
+ `kagura-memory:guardrails` marker lines: an earlier block is replaced in
365
+ place, an unchanged set rewrites nothing, and the rest of the file is
366
+ kept, line endings and a symlink included. Without PATH the file is the
367
+ harness's own: `$CODEX_HOME/AGENTS.md` (`AGENTS.override.md` when that
368
+ exists); for Hermes the first of `.hermes.md`, `HERMES.md`,
369
+ `AGENTS.override.md`, `AGENTS.md` and `CLAUDE.md` in the current
370
+ directory, else `AGENTS.md`; for OpenClaw `AGENTS.md` in its workspace,
371
+ `$OPENCLAW_WORKSPACE_DIR`, else `workspace/` in the state directory. A
372
+ leading `~` or `~/` in PATH is expanded to your home directory (a
373
+ `~user` is left as written; see below), and missing directories are
374
+ created. The context is `--context-id`, else a `--guardrails` context
375
+ UUID, never the
376
+ URL's `?guardrails=` or `.kagura.json`; without one, `--agents-md` is a
377
+ usage error (exit 2). The block is fetched on the usual credential chain
378
+ (`KAGURA_API_KEY`, the OAuth profile, `.kagura.json`), which setup
379
+ settles before it runs anything, a dry run included: no credential, or
380
+ one for another server than the entry's, stops setup (exit 1) with
381
+ nothing run. The export comes after the entry is applied or printed.
382
+ `wrote` lists the file, and the notes carry Python's lines: the refresh
383
+ command (`kagura-memory guardrails digest <ctx> --out <file>`), a warning
384
+ past the 32 KiB Codex reads or the 20,000 characters OpenClaw reads, and
385
+ Hermes's prompt-injection note. An empty digest writes nothing and says
386
+ so; setup never removes a block, which `guardrails digest --out` does. A
387
+ failed export prints the report, then the error (exit 1). `--dry-run`
388
+ names what the export would do to the file (create it, append the block,
389
+ replace the block, or update a file it cannot read). On Hermes and
390
+ OpenClaw a run without the export ends with Python's "Re-run with
391
+ --agents-md --context-id <id> …" hint.
240
392
 
241
393
  Claude Code uses the `kagura-memory` entry from the strongest scope
242
394
  (local > project > user). It keys local scope by the git repository root
@@ -279,21 +431,14 @@ scope.
279
431
 
280
432
  **Not ported.** `kagura ingest` needs the text-extraction pipeline (PDF,
281
433
  Office, EPUB, audio), which does not exist in this package and would cost
282
- the zero-dependency promise. Not ported yet: `auth create-key`,
283
- `auth list-keys` and `auth revoke-key`; the `workspace` group
284
- (`member list|add|set-role|remove`, `invite create|list|revoke`);
285
- `guardrails load` and `guardrails digest`; `measure record` and
286
- `measure series`; the `-v/--verbose` and `--progress` options of
287
- `files upload` and `resource import`; and the `--agents-md` option of
288
- `setup codex`, `setup hermes` and `setup openclaw`, the guardrail export,
289
- which needs `guardrails digest` first
290
- ([#57](https://github.com/kagura-ai/kagura-memory-typescript-sdk/issues/57))
291
- and which this CLI rejects as an unknown option. Use the Python CLI for
292
- all of these. The Claude Code extras of
293
- `kagura setup claude` are not ported either: its SessionStart and
294
- PostToolUse hooks and its `/kagura-recall` and `/kagura-remember`
434
+ the zero-dependency promise; use the Python CLI for it. The Claude Code
435
+ extras of `kagura setup claude` are not ported either: its SessionStart
436
+ and PostToolUse hooks and its `/kagura-recall` and `/kagura-remember`
295
437
  commands. `setup claude` here writes `.kagura.json` and the MCP entry
296
- only, and takes their flags as inert (see above).
438
+ only, and takes their flags as inert (see above). Every other command of
439
+ the Python CLI is here as of 0.12.0
440
+ ([#57](https://github.com/kagura-ai/kagura-memory-typescript-sdk/issues/57)),
441
+ with the differences in options and output this section lists.
297
442
 
298
443
  **Only in this bin.** `secret keygen --reveal`: keygen prints the private
299
444
  key (see key custody below) and refuses to print it to a terminal without
@@ -310,7 +455,7 @@ older scripts still run. Neither does anything now, and a note says so.
310
455
  `--api-key` beside `--profile` is still the usage error (exit 2) it was,
311
456
  with `--url-form` too.
312
457
 
313
- **Three deliberate divergences.**
458
+ **Five deliberate divergences.**
314
459
 
315
460
  - `secret` needs the optional `age-encryption` peer (`npm install
316
461
  age-encryption`), exactly as Python's `[secret]` extra works. Key
@@ -327,10 +472,24 @@ with `--url-form` too.
327
472
  here, and so does the URL form of the other three. With `--url-form`,
328
473
  those three ignore `--profile`, with a note: the Python CLI uses it
329
474
  there to check the login, list contexts and fetch the `AGENTS.md`
330
- export, and this port never contacts the server.
475
+ export with that profile alone. This port lists nothing and checks no
476
+ login, and fetches the export on the usual credential chain, where
477
+ `KAGURA_PROFILE` picks a profile.
331
478
  - `config show` does not reproduce Python's key mask
332
479
  (`key[:8] + "..." + key[-4:]`), whose halves overlap below 12 characters
333
480
  and print the whole secret twice.
481
+ - `--progress rich`, and `-v` without `--progress`, print the Python CLI's
482
+ `→` / `✓` / `✗` lines as plain text, the text Rich writes when stderr is
483
+ not a terminal: no colours even on a terminal, no wrapping at its width,
484
+ and no Rich markup, so `report[bold].pdf` prints as written (Rich drops
485
+ the `[bold]`, and a `[/…]` in an error message makes it fail). `-vv` and
486
+ `-vvv` show one line per detail or debug event, where Rich draws a panel;
487
+ neither command emits one. `--progress json` is the same NDJSON.
488
+ - With no `.kagura.json`, the MCP-backed commands (`recall`, `guardrails
489
+ load`, `measure`, …) and `doctor` reach an OAuth profile's own server.
490
+ The Python CLI takes the default URL its config loader fills in for the
491
+ server, and sends the profile's token there. A `KAGURA_API_KEY` goes to
492
+ `KAGURA_MCP_URL`, else the default, in both.
334
493
 
335
494
  **`setup codex`, `setup hermes` and `setup openclaw`** also differ from
336
495
  the Python CLI in these ways, each on purpose:
@@ -340,20 +499,33 @@ the Python CLI in these ways, each on purpose:
340
499
  Python requires it. Only that fallback needs the configuration: without
341
500
  `--mcp-url`, a `.kagura.json` that cannot be loaded stops setup (exit 1);
342
501
  with it, setup goes on with a note, as Python never reads that file.
343
- - A `-c` that is not a UUID is not used for guardrails, and a note says
344
- so. Python looks a name up through `--profile`, and without one exits 2.
345
- - `setup codex --force` runs one `codex mcp add`, which overwrites the
346
- entry. Python runs `codex mcp remove` first.
502
+ - `-c` must be a context UUID with `--url-form --profile` too (exit 2),
503
+ where Python looks a name up through the profile.
347
504
  - `setup hermes` never runs `hermes mcp add`, which prompts; it prints the
348
505
  block, as Python does under `-y`.
349
506
  - An existing entry is found by scanning the file, and not described by
350
507
  kind. A readable but malformed `config.toml` does not stop
351
508
  `setup codex`.
352
- - On Hermes and OpenClaw, a context id in `--mcp-url`'s `?guardrails=` is
353
- dropped, where Python keeps it. On Codex, a `?guardrails=` already in
354
- the MCP URL (`--mcp-url` or the configured `mcp_url`) beats the hooks
355
- and `-c` defaults.
356
- - OpenClaw's `.env` is in `$OPENCLAW_STATE_DIR` when that is set.
509
+ - On Codex, a `?guardrails=` already in the MCP URL (`--mcp-url` or the
510
+ configured `mcp_url`) beats the hooks and `-c` defaults.
511
+ - Nothing prompts, so `--agents-md` always needs a context, and the
512
+ export is never offered: a dry run of Hermes or OpenClaw says "not
513
+ offered: this port never prompts" (or "not offered with -y").
514
+ - When the entry was only printed (always for Hermes), a failed export
515
+ says "The MCP entry is printed for you to add", where Python says it is
516
+ set up. When the export credential is for another server, the message
517
+ says what moves it here, where Python's points at `--profile`: for
518
+ `KAGURA_API_KEY`, which outranks every profile, `KAGURA_MCP_URL` or
519
+ unsetting the key; otherwise `KAGURA_PROFILE`.
520
+ - `--agents-md=VALUE` takes VALUE literally even when it begins with a
521
+ dash, where click reads `--agents-md=-y` as the default file plus `-y`.
522
+ - The Codex size warning counts the bytes on disk, CRLFs included, where
523
+ Python counts the text with its line endings folded.
524
+ - A `~user` in an `OPENCLAW_*` variable or in `--agents-md PATH` is left
525
+ as written (`--agents-md '~root/x.md'` names `~root/x.md` in the
526
+ current directory), where Python looks the user up (`/root/x.md`) and
527
+ fails the whole setup for an unknown one. File errors of the export are
528
+ Node's words, not Python's `[Errno …]`.
357
529
  - Output is one JSON document on stdout, with Python's sentences in
358
530
  `notes` and the block on stderr. A non-ASCII URL is written as UTF-8
359
531
  where Python writes `\uXXXX` escapes; both are valid.
@@ -367,6 +539,8 @@ would accept.
367
539
  apart from `--external-id=` in the `update-memory` case below.
368
540
  - `context update --lock --unlock` is a usage error (exit 2, "mutually
369
541
  exclusive; pick one"), where click takes whichever flag comes last.
542
+ - `setup … --agents-md=' '` (a path of only whitespace) is a usage error
543
+ (exit 2), where Python writes a file named `" "`.
370
544
  - `--rerank --no-rerank` is the same usage error, on `recall` and on
371
545
  `context search-config`.
372
546
  - `auth logout --all --profile NAME` is the same usage error, where click
@@ -377,11 +551,48 @@ would accept.
377
551
  CLI refuses that too, as `updateMemory` does.
378
552
  - `-k=5` (a short option, `=`, a value) reads `5`, where click reads `=5`
379
553
  as the value and then refuses it.
554
+ - A float range such as `files upload --importance` refuses `nan`, which
555
+ click's `FloatRange` lets through (every comparison with NaN is false).
380
556
  - An option that takes a value does not take a following argument that
381
557
  begins with a dash and is not a number (a lone `-` is still a value):
382
- `--name-contains -auth` is a missing value here, where click takes
383
- `-auth`. Write `--name-contains=-auth`. `auth login --invite` is the
384
- exception, since an invite token may begin with a dash.
558
+ `--name-contains -auth` is a missing value here (`Error: Option
559
+ '--name-contains' requires an argument.`), where click takes `-auth`.
560
+ Write `--name-contains=-auth`. A number is anything `float()` reads,
561
+ so `-١` is one. `auth login --invite` is the exception, since an invite
562
+ token may begin with a dash.
563
+ - `guardrails digest --out ''` is a usage error (exit 2). Click takes the
564
+ empty path as the current directory, and the Python CLI then fails to
565
+ write to it (exit 1).
566
+
567
+ **`guardrails load` and `guardrails digest`** (memory-cloud v0.74.0+)
568
+ take the context as an optional argument, else `context_id` from
569
+ `.kagura.json`. `load` calls the MCP `load_guardrails` tool and prints the
570
+ set as the Python CLI prints it: the model's fifteen keys in its order,
571
+ without the `context_display_name`, `context_is_private` and
572
+ `context_is_locked` the tool adds, each item's eleven keys, and `null` for
573
+ a `tool_trigger` the Python SDK cannot read (`match: null` is filled in
574
+ when a trigger has none). A set missing a required field, a truncation
575
+ flag above all, is refused with the Python SDK's `KaguraResponseError`
576
+ text (exit 1) rather than printed as complete. `--cap` takes 1-1000.
577
+ `digest` reads the REST digest route with the credential chain (an API
578
+ key or an OAuth profile) and prints the text: the `AGENTS.md` export
579
+ block, or with `--target instructions` the MCP server instructions this
580
+ credential would receive, where `--profile` and `--tools` repeat an MCP
581
+ URL's `?profile=` and `?tools=`. A context with no tool guardrails prints
582
+ nothing, and says so on stderr. With `--out FILE`, it splices the block
583
+ into FILE between its marker lines: an earlier block is replaced in place,
584
+ an unchanged set rewrites nothing, and an empty set removes an earlier
585
+ block. It then prints one JSON line, `{"path": …, "status":
586
+ "written"|"unchanged"|"removed", "tool_triggered_version": …}`, with the
587
+ path as Python's `pathlib` writes it (`./x/../X.md` reads `x/../X.md`).
588
+ As in Python, `--out` does not expand `~`, never creates a missing parent
589
+ directory, and keeps a symlink, the file's mode and its line endings.
590
+ Beside JSON's `1` for Python's `1.0` (an `importance`), two differences
591
+ remain: an item's `created_at` / `updated_at` is printed as
592
+ the server sent it, where Python reformats it and refuses one it cannot
593
+ parse; and a failed read or write of the `--out` file reads in Node's
594
+ words (`ENOENT: no such file or directory, open '…'`) rather than
595
+ Python's (`[Errno 2] No such file or directory: '…'`).
385
596
 
386
597
  **Sign-in rate limit.** memory-cloud v0.76.0 and later limit device sign-in
387
598
  requests per client address. When the server refuses one with HTTP 429,
@@ -393,10 +604,14 @@ server's reason, when it gives one, on the next line.
393
604
 
394
605
  **`auth` subcommands.** Each takes only the options it reads, as in the
395
606
  Python CLI: any other is refused with click's `Error: No such option: --x`
396
- (exit 2), and `--help` lists only its own. `auth status` ends with the
397
- `kagura-memory` entry Claude Code uses in the current directory and each
398
- entry it hides, in the Python CLI's words (nothing when no scope defines
399
- one). `auth list --json` emits Python's fields per profile (`profile`,
607
+ (exit 2), except `--invite`, which every subcommand but `login` refuses
608
+ with `--invite applies only to 'auth login'.` (exit 2, where click says
609
+ `No such option: --invite`), with a value or without and before
610
+ `--help`, as click's error would be, so that a token beginning with a
611
+ dash is not read as options. `--help` lists only a subcommand's own
612
+ options. `auth status` ends with the `kagura-memory` entry Claude Code uses in the
613
+ current directory and each entry it hides, in the Python CLI's words
614
+ (nothing when no scope defines one). `auth list --json` emits Python's fields per profile (`profile`,
400
615
  `default`, `user_email`, `workspace_name`, `workspace_id`, `server`,
401
616
  `scope`, `expired`, `refreshable`, `expires_at`), never a token, and `[]`
402
617
  when there is none, with non-ASCII escaped as `\uXXXX`, as Python's
@@ -412,7 +627,61 @@ logout that names no profile succeeds when nothing is stored, so
412
627
  `logout --yes` stays idempotent in setup scripts; and `--all` with
413
628
  `--profile` is a usage error (exit 2), where Python ignores `--profile`
414
629
  and removes every profile. `auth login` with both `--read-only` and
415
- `--scope` exits 1, as Python does.
630
+ `--scope` exits 1, as Python does. `auth use NAME` prints Python's line,
631
+ `Default profile set to '<name>' (workspace '<workspace>').`, and a note
632
+ when `KAGURA_PROFILE` is set and still overrides the new default; an
633
+ unknown name exits 1 and lists the stored profiles, and a missing or
634
+ extra argument is a usage error (exit 2).
635
+
636
+ **`workspace` and the `auth` key commands** (memory-cloud v0.42.0+)
637
+ manage a workspace's members, invitations and member API keys:
638
+ `workspace member list|add|set-role|remove`, `workspace invite
639
+ create|list|revoke`, and `auth create-key|list-keys|revoke-key`, which
640
+ mint, list and revoke a key for another member. The server takes only
641
+ the workspace owner's static API key here; an OAuth profile gets an
642
+ access-denied error that says so. As in the Python CLI, the workspace
643
+ comes from the same source as the key
644
+ ([#115](https://github.com/kagura-ai/kagura-memory-python-sdk/issues/115)):
645
+ `-w/--workspace` when given, else the OAuth profile's workspace, else
646
+ `context_id` in the `.kagura.json` that holds the key. A `KAGURA_API_KEY`
647
+ key needs `-w`, since nothing binds it to a workspace:
648
+ `KAGURA_API_KEY=<owner key> kagura-memory workspace member list -w
649
+ <workspace-uuid>`. An empty or `auto` `-w` is refused (exit 1) rather
650
+ than falling back to the source's workspace. `member remove` and `auth
651
+ revoke-key` ask first, naming the workspace, unless `--yes` (`-y`).
652
+ `create-key` prints the key, and `invite create` the invitation URL,
653
+ once on stdout, after a warning on stderr. `list-keys` and `invite list`
654
+ never show either; their `--json`, like `member list --json`, prints
655
+ the Python model's fields in its order, `null` or `false` for what the
656
+ server left out, and drops any other. A record the model refuses (a
657
+ required field missing, a scalar, list or mapping of the wrong type)
658
+ exits 1 with its `KaguraResponseError` text; timestamps are printed as
659
+ the server wrote them. `--role` matches exactly, as
660
+ click's `Choice` does (`Admin` is refused). Four things differ from the
661
+ Python CLI, each on purpose: a workspace that is not a UUID is refused
662
+ before `member remove` or `revoke-key` asks, where Python asks first;
663
+ each `invite create -c` must be a context UUID (exit 1, `context_id must
664
+ be a UUID, got '…'`), where Python sends it as typed and the server
665
+ answers `HTTP 500`; a user id of `.` or `..` (`USER_ID` or `--user`) is
666
+ refused (exit 2) before anything is asked or sent, where Python sends it
667
+ and URL resolution turns `member remove ..` into a `DELETE` of the
668
+ workspace's own URL; and an invitation with no email prints `-`, as
669
+ `invite list` does, where Python prints `None`.
670
+
671
+ **`measure record` and `measure series`** take the context as their
672
+ first argument, never from `.kagura.json`: an observation recorded in the
673
+ wrong context cannot be deleted. As in the Python CLI, a negative VALUE
674
+ needs no `--` (`measure record <context-id> pnl_usd -120`). The price is
675
+ that `record` reads any option it does not declare as an argument: after
676
+ VALUE it is an extra argument, and in the CONTEXT_ID or METRIC slot it is
677
+ refused as `No such option: <token>`, even after `--`, as the Python CLI
678
+ refuses it. These errors name a `--name=value` token `--name`, as every
679
+ other command does, where click prints the whole token: the value may be
680
+ a key. `--period` and `--agg` match exactly (`Week` is refused).
681
+ When both are bad, the error names `--period`, where click names
682
+ whichever comes first. The result prints as the Python CLI prints the
683
+ model: its keys in its order, and `unit` `null` when there is none. A
684
+ whole-number float prints without its `.0` (`72` for `72.0`).
416
685
 
417
686
  #### Signing up with an invite
418
687
 
@@ -431,7 +700,8 @@ the server how to present the invite (`GET /api/v1/system/info`, which
431
700
  takes no credentials, allowed 5 seconds):
432
701
 
433
702
  - **The server supports the hand-off** (memory-cloud 0.76.0 or later,
434
- `v0.76.0` and build suffixes included): one link,
703
+ `v0.76.0` and build suffixes included; a pre-release of 0.76.0 such as
704
+ `0.76.0-rc1` comes before it, as in the Python CLI): one link,
435
705
  `<frontend>/join/<token>?return_to=%2Fdevice%3Fuser_code%3D<code>`, that
436
706
  signs up with the invite and lands on the approval page with the code
437
707
  filled in. The browser opens that link. Below it, "If you land on the
@@ -610,8 +880,9 @@ keyed on the error code and the envelope's fields, never on the message:
610
880
  |-------|------------|---------|
611
881
  | `KaguraNotFoundError` | missing contexts/memories/reports/agents/bindings (on `updateSearchConfig`, a missing context is a `KaguraPermissionError` instead) | — |
612
882
  | `KaguraFeatureNotAvailableError` | MCP `plan_required` / `feature_not_available`; REST 403 `FEAT-001` — the plan lacks a feature, or it is switched off | `feature`, `requiredPlan`, `requiredPlanDisplay`, `currentPlan`, `gate` |
613
- | `KaguraQuotaError` | MCP `quota_exceeded` / `CONNECTOR-001`; REST `QUOTA-001`, `QUOTA-002` and `CONNECTOR-001` (the resource-token and connector seat caps answer **403**); any other 429 from a REST client but `SecretClient` | `quotaType`, `current`, `limit`, `usedToday`, `resetsAt`, `retryAfter`, and the plan fields above |
883
+ | `KaguraQuotaError` | MCP `quota_exceeded` / `CONNECTOR-001`, and `rate_limit_exceeded`, the daily MCP call cap every non-read-only tool checks (`quotaType` `api_mcp_daily`, `resetsAt` the next UTC midnight); REST `QUOTA-001`, `QUOTA-002` and `CONNECTOR-001` (the resource-token and connector seat caps answer **403**); any other 429 from a REST client but `SecretClient` | `quotaType`, `current`, `limit`, `usedToday`, `resetsAt`, `retryAfter`, and the plan fields above |
614
884
  | `KaguraPartialRollbackError` | `rollbackSleepRun` reversed some actions but not all | `reportId`, `summary` |
885
+ | `KaguraResponseError` | a successful response the SDK cannot read, usually because the server is newer than this SDK. The message reads as the Python SDK's: the call, then the failing fields, never their values (`<operation>: unexpected server response for <Model> (<field>: Field required). …`), then a suggestion to upgrade. It is not a `KaguraConnectionError`: a retry fails the same way | `operation` |
615
886
  | `KaguraPermissionError` | MCP `permission_denied` — usually the caller's role is too low. `updateSearchConfig` also sends it for a context that does not exist or that the caller cannot see. Only some tools send a role — `updateSearchConfig`, `updateContext`, `deleteContext`, the file tools and the analysis tools do not — so `requiredRole` is often `null`, and on `updateSearchConfig` it cannot tell a missing context from a role denial | `requiredRole` |
616
887
  | `KaguraError` | any other code | — |
617
888
 
@@ -644,7 +915,9 @@ An HTTP 429 keeps the class it always had on two surfaces.
644
915
  per-minute rate limit and the daily call quota alike; from v0.75.0 the
645
916
  quota also sets the `KaguraQuotaError` fields on it (`quotaType` is
646
917
  `api_mcp_daily` or `api_rest_daily`), and they stay `null` on a
647
- per-minute limit. `SecretClient` renders a 429 as `KaguraConnectionError`.
918
+ per-minute limit. A tool that refuses the daily MCP cap itself, in its
919
+ reply rather than with a 429, raises the `KaguraQuotaError` above.
920
+ `SecretClient` renders a 429 as `KaguraConnectionError`.
648
921
 
649
922
  ```ts
650
923
  import { KaguraFeatureNotAvailableError, KaguraQuotaError } from "kagura-memory";
@@ -682,7 +955,7 @@ when `undefined`.
682
955
  | `reference` | Full detail for one memory, under `result.memory`. |
683
956
  | `updateMemory` | Update in place by `memoryId`, or upsert by `externalId`. `details` **replaces** the stored object wholesale — round-trip keys you want to keep; dropping `tool_trigger` turns a guardrail off. `dismissSupersedeCandidate: true` rejects the server's `supersede_candidate` suggestion; it needs `memoryId` and throws locally with `externalId`. |
684
957
  | `forget` | Soft-delete by `memoryId` or by `query`. The rows are kept, but not restorable through the API, until the deployment's cleanup window passes (`CLEANUP_DELETED_MEMORIES_RETENTION_DAYS`, default 30 days). For a caller who may write to the workspace, a target it may not delete, or one already gone, is skipped silently — including every guardrail for a caller below context editor or on an agent credential — so `deleted_count` can be 0. A workspace viewer may not delete at all and is refused with `KaguraPermissionError` (`requiredRole: "member"`). |
685
- | `listMemories` | Browse with substring, facet, and time-window filters. Omit `contextId` for the caller's cross-context view. |
958
+ | `listMemories` | Browse with substring, facet, time-window and bounding-box filters. Omit `contextId` for the caller's cross-context view. `latMin` / `latMax` / `lonMin` / `lonMax` (server v0.54.0+) keep only memories with a location, each then carrying `location: { lat, lon }`; see [the WHERE axis](#the-where-axis--geospatial-memories). |
686
959
 
687
960
  ### Deterministic lanes
688
961
 
@@ -695,12 +968,14 @@ the counterpart to `recall`'s probabilistic search.
695
968
  | `loadGuardrails` | The set a client-side tool hook matches against (server v0.74.0+): the pinned set plus every memory carrying `details.tool_trigger`, in two separately capped lanes — `cap` bounds only the tool-triggered one, so pins never crowd guardrails out. Check `tool_triggered_truncated` / `pinned_truncated`. |
696
969
  | `recallUpcoming` | WHEN — `type: "time"` memories whose window overlaps `from`/`until`, soonest first. Items carry `trigger`, not `details` (server v0.73.0+); `includeDetails: true` returns the full `details` object instead. |
697
970
  | `recallNearby` | WHERE — memories near a point, nearest first with `distance_m`. See [the WHERE axis](#the-where-axis--geospatial-memories). |
971
+ | `recordMeasurement` | HOW-MUCH — append one number to a metric's series (server v0.54.0+). Not a memory: never embedded, recalled or consolidated. Append-only, with no delete. See [the HOW-MUCH axis](#the-how-much-axis--measurement-series). |
972
+ | `recallSeries` | HOW-MUCH — one metric's series, bucketed by `period` (`day`, `week`, `month`) and aggregated by `agg` (`avg`, `min`, `max`, `sum`, `count`, `last`), UTC-aligned, empty buckets omitted. `count` is buckets, not observations. |
698
973
 
699
974
  ### Tags and the neural graph
700
975
 
701
976
  | Method | What it does |
702
977
  |--------|--------------|
703
- | `listTags` | Tag vocabulary with counts and recency. `prefix` narrows by spelling; `withTags` is a multi-tag AND drill-down that also excludes those tags from the result — the two compose into server-side faceted browsing with no local index. A drill-down calls the REST tags endpoint, because the MCP tool ignores `withTags` (through server v0.76.0); the result has the same shape. Its values are trimmed and blank ones dropped, and at most 50 of up to 200 characters each are accepted. |
978
+ | `listTags` | Tag vocabulary with counts and recency. `prefix` narrows by spelling; `withTags` is a multi-tag AND drill-down that also excludes those tags from the result — the two compose into server-side faceted browsing with no local index. A drill-down calls the REST tags endpoint, because the MCP tool ignores `withTags` (through server v0.76.0); the result has the same shape. Its `context_name` is the one the endpoint sends (server v0.77.0+), else one MCP `list_tags` call names the context, once per client. Its values are trimmed and blank ones dropped, and at most 50 of up to 200 characters each are accepted. |
704
979
  | `explore` | Graph traversal from a seed memory (`depth` 1–5, `minWeight`). |
705
980
  | `listEdges` | Edges touching a memory, incoming and outgoing, deduplicated. |
706
981
  | `createEdge` / `updateEdge` / `deleteEdge` | Manual edge curation. `(sourceId, targetId)` is the identity; self-loops are rejected. |
@@ -741,7 +1016,7 @@ Ephemeral, TTL-bounded, and excluded from recall — deliberately not memories.
741
1016
  | Method | What it does |
742
1017
  |--------|--------------|
743
1018
  | `getServerInfo` | Version, deployment feature flags, and (v0.69.0+) the reranker defaults new contexts start with, under `search_defaults`. |
744
- | `checkServerVersion` | Compare against `MIN_SERVER_VERSION` (0.75.0). Advisory: logs, never throws. |
1019
+ | `checkServerVersion` | Compare against `MIN_SERVER_VERSION` (0.75.0). Advisory: logs, never throws. Reads the version as the Python SDK does: `v0.75.0`, `0.75.0+build` and `0.75.0.post1` meet it, a pre-release of it (`0.75.0-rc1`, `0.75.0rc1`, `0.75.0.dev1`) does not, and a version it cannot read (`0.75`, or not a string) is not compared. |
745
1020
  | `getUsage` | Workspace quota and usage: `used` / `limit` for memories, contexts, members and today's MCP calls. |
746
1021
  | `getMemoryStats` | Per-memory usage stats, sortable and paged. |
747
1022
  | `getEmbeddingStatus` / `listEmbeddingModels` | Embedding backend state and the models available for `createContext`. |
@@ -797,6 +1072,38 @@ Requires memory-cloud **v0.49.0+** — older servers return MCP "tool not
797
1072
  found" / REST 404 on this surface. The SDK as a whole targets v0.75.0
798
1073
  (see [Installation](#installation)).
799
1074
 
1075
+ ## Tool guardrails over REST (memory-cloud v0.74.0+)
1076
+
1077
+ `MemoryClient` serves a context's tool guardrails to a caller holding only
1078
+ an API key, an agent-bound key included, with no MCP session:
1079
+
1080
+ | Method | What it does |
1081
+ |--------|--------------|
1082
+ | `getGuardrailDigest` | The rendered tool-triggered set for clients without tool hooks (`GET /api/v1/memory/guardrails/digest`). `target: "export"` (the default) returns the `AGENTS.md` block, between its marker lines, or `""` when the context has none; `"instructions"` returns the exact MCP server instructions this credential would receive, and `profile` / `tools` repeat the MCP URL's `?profile=` / `?tools=`. `tool_triggered_version` is the response header, `null` when absent. The text is returned as is. |
1083
+ | `loadGuardrails` | The REST twin of `KaguraClient.loadGuardrails` (`POST /api/v1/memory/guardrails`): the same two lanes and truncation flags, without the context block (`context_id` and `context_name` are `null`). The set is read as the Python SDK's `GuardrailSet` model reads it, by the same reader `guardrails load` prints with: the model's fields only, in its order, `null` for an optional one left out (so `GuardrailItem`'s optional fields and `ToolTrigger.match` are typed nullable), and a `tool_trigger` that is no trigger `null`. A set missing a required field, a truncation flag included, or holding one of the wrong type (`pinned.0.type: Input should be a valid string`) raises `KaguraResponseError` (`operation` `MemoryClient.load_guardrails`) rather than read as complete. |
1084
+
1085
+ Both refuse a `contextId` that is not a UUID before any request, in the
1086
+ Python SDK's words (`context_id must be a UUID, got '…'`), and send its
1087
+ canonical form. The 404 (`KaguraNotFoundError`) is uniform: an unknown
1088
+ context, one in another workspace, and one the credential may not read
1089
+ all look the same, and so does a server older than v0.74.0 answering
1090
+ `getGuardrailDigest`. That older server answers `loadGuardrails` with
1091
+ `HTTP 405` instead, a `KaguraConnectionError`, so a caller that detects
1092
+ an older server by catching `KaguraNotFoundError` must also expect the
1093
+ 405. An OAuth token's scope follows the HTTP method, so
1094
+ `loadGuardrails`, a `POST`, needs `memory:write`: a `--read-only` login
1095
+ loads the set over MCP instead.
1096
+
1097
+ ```ts
1098
+ import { MemoryClient } from "kagura-memory";
1099
+
1100
+ const memory = MemoryClient.fromMcpUrl();
1101
+ const digest = await memory.getGuardrailDigest("ctx-uuid");
1102
+ if (digest.text) {
1103
+ // The block between the kagura-memory:guardrails marker lines for AGENTS.md.
1104
+ }
1105
+ ```
1106
+
800
1107
  ## The WHERE axis — geospatial memories
801
1108
 
802
1109
  Any memory can carry a location under `details.location`, which makes it
@@ -820,10 +1127,83 @@ into `details`, so `"35.68"` is rejected server-side with HTTP 422.
820
1127
  (`results[].distance_m`); `MemoryLocation` and `NearbyMemory` are exported
821
1128
  too. Out-of-range coordinates throw locally rather than round-tripping.
822
1129
 
1130
+ `listMemories()` filters by a bounding box instead (server v0.54.0+):
1131
+ `latMin`, `latMax`, `lonMin` and `lonMax`, in any combination, keep only
1132
+ memories with a location, and each item carries `location: { lat, lon }`
1133
+ (`null` without one). `lonMin > lonMax` is the box across the
1134
+ antimeridian. A server older than v0.54.0 ignores the bounds and returns
1135
+ an unfiltered page.
1136
+
1137
+ ```ts
1138
+ const pacific = await client.listMemories({ contextId, lonMin: 170, lonMax: -170 });
1139
+ ```
1140
+
823
1141
  > **Gotcha:** `updateMemory()` replaces `details` **wholesale** — the
824
1142
  > server does not deep-merge. Round-trip `location` when updating details
825
1143
  > or the memory silently drops off the spatial axis.
826
1144
 
1145
+ ## The HOW-MUCH axis — measurement series
1146
+
1147
+ Numbers such as a weight, a daily revenue or a rep count go to a lane of
1148
+ their own (server v0.54.0+): never embedded, never returned by `recall()`,
1149
+ never merged or rewritten by Sleep. Keep prose ("hit goal weight") in
1150
+ `remember()`.
1151
+
1152
+ ```ts
1153
+ await client.recordMeasurement({ contextId, metric: "weight_kg", value: 71.5, unit: "kg" });
1154
+
1155
+ const weekly = await client.recallSeries({ contextId, metric: "weight_kg", period: "week", agg: "avg" });
1156
+ // weekly.series: [{ bucket: "2026-08-24T00:00:00Z", value: 72, count: 3 }, ...]
1157
+ ```
1158
+
1159
+ The lane is append-only: recording the same point twice stores two rows,
1160
+ and nothing deletes one, except the retention window an operator can set
1161
+ on the server (v0.55.0+, `SLEEP_MEASUREMENT_RETENTION_DAYS`), which Sleep
1162
+ rollback cannot undo. `measuredAt`, `start` and `end` take an ISO 8601
1163
+ string, sent as given (naive means UTC), or a `Date`. A series window
1164
+ defaults to the last 30 days and spans at most 365; the server refuses a
1165
+ wider one. The metric (1-64 characters), the value (a finite number) and
1166
+ the unit (1-32 characters) are checked before any request, with the Python
1167
+ SDK's messages. Both methods return the Python SDK's model, and a result
1168
+ that does not read as one throws `KaguraResponseError`. On the command
1169
+ line: `measure record` and `measure series`.
1170
+
1171
+ ## Upload and ingest progress
1172
+
1173
+ `FilesClient.upload` and `ResourceClient.ingestEvents` take an
1174
+ `onProgress` callback, the Python SDK's `logger=` hook. Each event is the
1175
+ Python CLI's NDJSON line without its `v` and `ts`: `stage`, `kind`
1176
+ (`action`, then one `success` or `error`, the last event, even when the
1177
+ call throws), and `msg` and `detail` when they are not empty. Without a
1178
+ callback nothing is emitted, and a callback that throws, or an `async` one
1179
+ that rejects, is ignored; its promise is not awaited.
1180
+
1181
+ ```ts
1182
+ import { FilesClient, type ProgressEvent } from "kagura-memory";
1183
+
1184
+ const files = FilesClient.fromMcpUrl();
1185
+ await files.upload({
1186
+ contextId: "workspace-uuid",
1187
+ source: "./report.pdf",
1188
+ onProgress: (e: ProgressEvent) => console.error(e.stage, e.kind, e.msg),
1189
+ });
1190
+ ```
1191
+
1192
+ An upload reports `reserve`, `upload` and `confirm`, then `complete`: a
1193
+ `success` with `{ file_id, size_bytes }` (`{ file_id, deduped: true }` for
1194
+ a 409 dedup hit), or an `error` with how far it got,
1195
+ `{ reserved_file_id, uploaded, confirm_started, confirmed }`;
1196
+ `confirm_started` without `confirmed` means the file may be finalized
1197
+ after all, so check before uploading again. A batch reports
1198
+ `ingest_events`, then `{ created, failed }` or
1199
+ `{ events_attempted, resource_id }`. A 2xx answer neither call can read (a
1200
+ batch answered with `null`, a confirm with no file `id`) ends the stream
1201
+ with that `error` and throws a `KaguraResponseError` in the Python SDK's
1202
+ words; such a confirm is not `confirmed`. Every `FilesClient` method
1203
+ refuses a `contextId` that is not a UUID in the Python SDK's words
1204
+ (`context_id must be a UUID; got '…'`), and sends a `{braced}`,
1205
+ `urn:uuid:` or dashless one in its canonical form.
1206
+
827
1207
  ## Zero-knowledge secrets
828
1208
 
829
1209
  `SecretClient` is the fourth REST client, alongside Files, Resource and
@@ -926,10 +1306,9 @@ Python uses, so a shared backend interoperates.
926
1306
 
927
1307
  This package ports the Python SDK's core (client, auth, REST clients,
928
1308
  models, the zero-knowledge secret client) and, since 0.8.0, its `kagura`
929
- CLI as `kagura-memory`: 17 of the 21 top-level commands, counting the
930
- `contexts` alias. [Command line](#command-line) lists the commands and
931
- options not ported yet (`guardrails`, `measure`, `workspace`, and the
932
- `auth` key commands among them).
1309
+ CLI as `kagura-memory`: 20 of the 21 top-level commands, counting the
1310
+ `contexts` alias. Only `kagura ingest` is not ported (below);
1311
+ [Command line](#command-line) lists where the two CLIs still differ.
933
1312
 
934
1313
  One thing is deliberately not ported, because it would cost the
935
1314
  zero-dependency promise: