kagura-memory 0.14.0 → 0.15.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
@@ -29,20 +29,24 @@ package also includes `kagura-memory-mcp`, a transparent stdio/HTTP proxy.
29
29
  npm install kagura-memory
30
30
  ```
31
31
 
32
- Requires Node.js >= 18 (native `fetch`). Zero runtime dependencies —
33
- the one optional peer dependency, for
32
+ Requires Node.js >= 20.19.0 (Node 18 support ended with 0.14.x). Zero
33
+ runtime dependencies — the one optional peer dependency, for
34
34
  [zero-knowledge secrets](#the-crypto-package-is-opt-in), is never installed
35
35
  unless you ask for it.
36
36
 
37
37
  Targets memory-cloud **v0.75.0** (`MIN_SERVER_VERSION`) and is checked
38
- against memory-cloud up to **v0.77.0**, as the Python SDK 0.42.0 is (whose
39
- own `MIN_SERVER_VERSION` stays at an advisory 0.17.1).
40
- `checkServerVersion()` warns, and never throws, on an older server, which
41
- still answers: it ignores options it predates, leaves out fields it
42
- predates, and reports a tool it predates as not found. A pre-release of
43
- the minimum (`0.75.0-rc1`) counts as older, and a version it cannot read
44
- (`0.75`, `main-abc123`) gets no warning, as in the Python SDK. The method
45
- notes below say which server version a feature needs.
38
+ against memory-cloud up to **v0.143.0**; the Python SDK 0.44.0, its
39
+ parity target, is checked up to v0.142.0 (v0.143.0 changes nothing a
40
+ client sees), and its own `MIN_SERVER_VERSION` stays at an advisory
41
+ 0.17.1. `checkServerVersion()` warns, and never throws, on an older
42
+ server, which still answers: it reports a tool it predates as not found
43
+ and leaves out fields it predates, and an option it predates is ignored
44
+ before v0.82.0 and refused (`invalid_argument`) from v0.82.0. A
45
+ pre-release of the minimum (`0.75.0-rc1`) counts as older, and a version
46
+ it cannot read (`0.75`, `main-abc123`) gets no warning, as in the Python
47
+ SDK. The method notes below say which server version a feature needs, and
48
+ [`docs/compatibility.md`](docs/compatibility.md) lists every floor by
49
+ release.
46
50
 
47
51
  ## Quick Start
48
52
 
@@ -87,7 +91,11 @@ Four ways to authenticate, in resolution order:
87
91
  (below) or the Python CLI's `kagura auth login`. Profiles
88
92
  (`KAGURA_PROFILE` env or `{ profile: "name" }`) and auto-refresh work
89
93
  exactly like the Python SDK; the credentials file is shared between both
90
- SDKs.
94
+ SDKs. Every refresh (a client's, `kagura-memory-mcp`'s, `refresh()`'s,
95
+ `auth refresh`'s and `auth token`'s) takes one lock on the file and
96
+ re-reads it first, so processes sharing a profile refresh it once, and a
97
+ `credentials.json` that exists but cannot be read is never rewritten (see
98
+ [Refreshing](#refreshing)).
91
99
  4. **Config file** — `.kagura.json` in the working directory or home:
92
100
 
93
101
  ```json
@@ -132,15 +140,16 @@ negative VALUE), so `secret exec --help --bogus` prints the help; without
132
140
  command rather than running it as that command. The one command not
133
141
  ported, the few options only this bin has, and the deliberate
134
142
  differences are listed below. The parity target is the Python CLI
135
- **0.42.0**.
143
+ **0.44.0**.
136
144
 
137
145
  Values are read as click reads them. A choice matches exactly, as click's
138
146
  `Choice` does, except where the Python CLI declares one case-insensitive
139
147
  (`--source-type`, `--progress`), casefolded as click folds it; a number
140
148
  is read as Python's `int()` and `float()` read it, `1_000`, any decimal
141
149
  digit (`١٢`, `12`) and the whitespace they skip included (a BOM is no
142
- whitespace to them); an integer id argument (`TOKEN_ID`,
143
- `INVITATION_ID`, `KEY_ID`) is sent exactly, however large; and an
150
+ whitespace to them); an id argument (`TOKEN_ID`, `INVITATION_ID`,
151
+ `KEY_ID`) is sent exactly, an integer however large, or a string id
152
+ (`rtok_…`, `winv_…`, `akey_…`, memory-cloud v0.89.0+) as typed; and an
144
153
  out-of-range value is echoed as click converted it (`files upload
145
154
  --importance 2` is refused as `2.0 is not in the range 0.0<=x<=1.0.`).
146
155
  A failure prints `Error: <message>` on stderr, and a quota or plan
@@ -155,7 +164,7 @@ npx kagura-memory --help
155
164
  |---|---|
156
165
  | `auth` | `login` `logout` `refresh` `status` `use` `list` `token` `create-key` `list-keys` `revoke-key` |
157
166
  | `context` | `list` `create` `update` `delete` `search-config` (plus the `contexts` alias) |
158
- | memory | `remember` `recall` `reference` `forget` `update-memory` `explore` |
167
+ | memory | `remember` `recall` `reference` `forget` `update-memory` `explore` `bootstrap` `changes` `list` |
159
168
  | `edge` | `list` `create` `update` `delete` |
160
169
  | `sleep` | `history` `report` `rollback` |
161
170
  | `measure` | `record` `series` |
@@ -171,10 +180,26 @@ npx kagura-memory --help
171
180
  npx kagura-memory auth login --profile work --read-only
172
181
  npx kagura-memory recall "OAuth setup" -c dev -k 10
173
182
  npx kagura-memory recall "dependency injection" --no-rerank # skip reranking; no flag follows the context config (v0.69.0+)
183
+ npx kagura-memory recall "project context" --verbosity full # uncut summaries + tags; compact is the server default (v0.108.0+)
184
+ npx kagura-memory recall "deploy runbook" --full 1 --max-chars 40000 # content on the top hit only (v0.114.0+); reply budget (v0.82.0+)
185
+ # A server that refuses one of --verbosity/--full/--max-chars (invalid_argument) gets one
186
+ # retry without the ones it names (every one it sent when it names none), with a note on stderr.
174
187
  npx kagura-memory remember -s "FastAPI DI" --content "Use Depends()" --tags "python,fastapi"
188
+ npx kagura-memory remember -s "Release 2.0 shipped" --content "..." --observed-at 2026-11-01 # when the fact held (v0.127.0+)
189
+ npx kagura-memory remember -s "Deploy key rotated" --content "..." --dedupe check # a duplicate_candidate prints with exit 0 (v0.93.0+)
190
+ npx kagura-memory update-memory -m MEM_UUID --add-tag status:done --remove-tag status:open \
191
+ --details-patch '{"status": "done"}' --expected-version 3 # partial edits (v0.140.0+), guarded (v0.113.0+)
192
+ npx kagura-memory update-memory -m MEM_UUID --accept-supersede-candidate # shadow the suggested older memory (v0.126.0+)
193
+ npx kagura-memory context search-config CTX_UUID --content-chunks --no-llm-selector # owner only (v0.110.0+ / v0.115.0+)
194
+ npx kagura-memory bootstrap --since 7d --format index --max-chars 5000 # open a session (v0.93.0+; index/--max-chars < 10000 v0.115.0+)
195
+ npx kagura-memory changes 2026-11-04T09:00:00Z --by-me # what you wrote since then (v0.93.0+; --by-me v0.114.0+)
196
+ npx kagura-memory list --filters '{"type": "task", "details.status": "open"}' --order-by created_at # exact filters, a total, no ranking
197
+ npx kagura-memory forget --ids "$ID1,$ID2" # one row per id: deleted / skipped / error (v0.117.0+)
175
198
  npx kagura-memory measure record <context-id> weight_kg 71.5 --unit kg
176
199
  npx kagura-memory setup codex --dry-run # show the command and the entry; change nothing
177
- npx kagura-memory doctor
200
+ npx kagura-memory setup claude --add-tools explore --context <context-id> # ?add_tools= (v0.129.0+), ?context= (v0.114.0+)
201
+ npx kagura-memory guardrails digest <context-id> --target instructions --add-tools explore # …for ?add_tools=explore
202
+ npx kagura-memory doctor # ends with the tools/list view of the CLI's MCP URL
178
203
  ```
179
204
 
180
205
  The context id comes from `-c/--context-id`, or from `context_id` in
@@ -182,6 +207,64 @@ The context id comes from `-c/--context-id`, or from `context_id` in
182
207
  shared with the Python CLI, so either tool can create a profile the other
183
208
  then uses.
184
209
 
210
+ **`bootstrap`, `changes`, `list` and `forget --ids`** (memory-cloud
211
+ v0.93.0+; `forget --ids` v0.117.0+) are the Python CLI 0.44.0's session
212
+ commands. Each prints the Python SDK model's dump of the reply: a field
213
+ the server left out prints with its default, a timestamp in pydantic's
214
+ form. `list` is the MCP `list` tool (`listMatching`) and takes
215
+ `--filters` as a JSON object; it is no longer a spelling of `auth list`,
216
+ the one bare `auth` alias that gave way. `forget --ids` takes 1-50
217
+ comma-separated memory UUIDs and refuses `-k` (exit 1, as Python); when
218
+ every id failed it prints one `<id> <status> [<error>]` row per id on
219
+ stderr before the error, so the `not_attempted` ones can be resent.
220
+
221
+ **`context list`** prints the `list_contexts` reply as JSON on stdout.
222
+ From memory-cloud v0.82.0 that is one page: 100 contexts by default, or
223
+ `--limit N` (1-200), and a page also stops at 20,000 characters. When a
224
+ page was cut, a line on stderr says so, as the Python CLI's does:
225
+ `has_more: true; next_cursor: "100". For the next page, run the command
226
+ again with the same options and --cursor "100".` The cursor is printed
227
+ there only when it is ASCII digits, the only form the server takes back;
228
+ any other `next_cursor` is left to the JSON (`--cursor set to next_cursor
229
+ from the JSON`), so nothing a shell would expand or a terminal would
230
+ interpret reaches stderr. A blank `--cursor` is unset, so a script can feed
231
+ back `jq -r '.next_cursor // empty'`. `--details` with a `--limit` above 20
232
+ and no non-blank `--name-contains` is a usage error (exit 2) before any
233
+ request, since the server refuses that page. Servers before v0.82.0 return
234
+ every context and ignore `--limit` and `--cursor`. **`contexts`**, the
235
+ short form, takes no options and prints one page, the 100 most recently
236
+ used contexts; when more follow, its stderr line names the
237
+ `kagura-memory context list --cursor "100"` call for the next page.
238
+
239
+ ```bash
240
+ npx kagura-memory context list --limit 50
241
+ npx kagura-memory context list --limit 50 --cursor 50 # the next_cursor of the page before
242
+ ```
243
+
244
+ **`update-memory --merge-details`** (and `--details-patch`, a patch you
245
+ write yourself) sends `--details` / `--location` as one `details_patch`
246
+ call, as the Python CLI 0.44.0 does: the server merges their top-level keys
247
+ over the stored details, keeps the rest, and deletes a key given as `null`.
248
+ Before memory-cloud 0.140.0 there is no `details_patch`, so the command
249
+ falls back to reading the memory with `reference()` and writing the merged
250
+ object — two calls, not one atomic update — and says so on stderr:
251
+
252
+ | Server | First call | Then | Exit |
253
+ |---|---|---|---|
254
+ | 0.140.0+ | `update_memory` with `details_patch` and every other flag | nothing | 0 |
255
+ | 0.82.0–0.139.x | refused: `invalid_argument` listing exactly `details_patch` in `unknown_arguments`, nothing written | `reference()`, then the merged object as `details` with every other flag (`--expected-version` still guards it on 0.113.0+) | 0 |
256
+ | 0.82.0+, refused for any other reason (or naming another argument too) | the error | nothing | 1 |
257
+ | before 0.82.0 | ignored: success without `version`, the other flags applied (or ignored) | `GET /api/v1/system/info`; below 0.82.0, `reference()` and the merged details alone | 0, or 1 naming each of `--add-tag` / `--remove-tag` / `--expected-version` / `--accept-supersede-candidate` / `--observed-at` it sent, after printing the reply |
258
+ | a reply without `version` from 0.82.0+, an unparseable version or a failed probe | — | nothing more written | 1 |
259
+
260
+ The fallback merge follows the server's rule (`null` deletes) and folds
261
+ `--observed-at` into the merged details. A bounded `reference()` reply
262
+ (`details_omitted`, a `details_json` page) is refused, never merged.
263
+ `--details-patch` cannot be combined with `--details` / `--location` /
264
+ `--merge-details`, `--tags` replaces the whole list where `--add-tag` /
265
+ `--remove-tag` edit it, and a refused `--expected-version` prints the
266
+ server's message with ` Current version: N` (and ` Help:`).
267
+
185
268
  **`resource setup`** names the new context after the resource, or `-n/--name`
186
269
  (lowercase letters, digits, `-` and `_`, at most 100), which a workspace
187
270
  that already has a context of that name needs. It prints Python's six
@@ -194,6 +277,11 @@ As in Python, `resource tokens revoke` prints `Token revoked.`, and
194
277
  `resource schema` prints `No schema registered for this resource.` when
195
278
  there is none (the route's 404).
196
279
 
280
+ **`resource list`** (`ResourceClient.listResources()`) also lists a resource
281
+ whose contexts were all deleted while it still holds active tokens, with
282
+ `context_id` and `context_name` null (memory-cloud v0.94.0+), so those
283
+ tokens stay reachable; revoking its last token removes the row.
284
+
197
285
  **Records print as the Python CLI prints them.** `resource tokens
198
286
  list|create|update`, `resource list|stats|indexer-status|events|schema`,
199
287
  `resource ingest|ingest-batch|setup`, `files list` and `files upload`
@@ -311,12 +399,36 @@ URL likewise from `--mcp-url`, else that file's `mcp_url`, else
311
399
  reads it. It never takes them from `~/.kagura.json`, nor, with
312
400
  `--project-dir`, from the current directory's `.kagura.json`: those are
313
401
  another project's credentials. `.kagura.json` gets the URL as given; the
314
- parameters that `--guardrails` and `--tool-profile` set go on the entry's
315
- URL only. A plain-HTTP URL to a host other than localhost is refused,
402
+ parameters that `--guardrails`, `--tool-profile`, `--add-tools` and
403
+ `--context` set go on the entry's URL only. A plain-HTTP URL to a host other than localhost is refused,
316
404
  whichever of the three it came from, before anything is written or run
317
405
  (exit 1, `Connection failed: MCP URL must use HTTPS for security …`, the
318
406
  Python CLI's words, whose connection test refuses it).
319
407
 
408
+ `setup claude` makes no connection unless the context (`--context-id`,
409
+ else that file's `context_id`, else `KAGURA_CONTEXT_ID`) is a name, which
410
+ it resolves through `list_contexts` on that key and URL, as the Python
411
+ CLI 0.44.0 does (python-sdk#309): any value but a UUID in the dashed form
412
+ (a dashless 32-hex one included) up to 100 characters is trimmed and
413
+ matched by id or exact name on the first page, then by exact name on
414
+ every page, with `name_contains` and the cursor when the first page says
415
+ `has_more` (memory-cloud 0.73.0 / 0.82.0; an older server's one reply is
416
+ the whole list), at most 50 pages, and the context's id is written. A
417
+ value no page matches, or a longer one, is still written, trimmed, after
418
+ `Warning: no context named 'NAME' is visible to this credential; using it
419
+ as a raw context id.` on stderr when it is not a UUID, although the
420
+ server takes only a UUID there, so later commands refuse it. Pages that
421
+ do not add up (`Setup failed: …`) and a failed request (`Authentication
422
+ failed: …` or `Cannot connect to …` with Python's hints, else
423
+ `Connection failed: …` on the first page) stop setup (exit 1) before
424
+ anything is written or run, as does a blank key, which the lookup never
425
+ replaces with another credential, and a context that is only whitespace
426
+ (`Invalid context_id: '' — must be alphanumeric, hyphens, or underscores
427
+ only`, Python's words); an empty `--context-id` counts as none, as in
428
+ Python. A dashed UUID is never looked up, even
429
+ one that is a context's name, which Python 0.44.0 would resolve when that
430
+ context is on its first page.
431
+
320
432
  Without `--agents-md`, `setup codex`, `setup hermes` and `setup openclaw`
321
433
  never see, write, print or pass the key, as in the Python CLI. The entry
322
434
  names the environment variable the harness reads the key from, and the
@@ -453,23 +565,51 @@ written, whether it comes from the flag or from the URL: one warning
453
565
  names what was dropped. A first `?guardrails=off` in the URL, the value
454
566
  the server reads, is kept, alone and with a warning of its own. Names
455
567
  compare decoded, as the server reads them (`guard%72ails` is
456
- `guardrails`). All of this is as in Python. `--tool-profile` (claude,
457
- codex; memory-cloud v0.73.0+) sets `profile` and refuses an empty name.
458
- The server knows
459
- `full` and `core` (case-sensitive) and fails `tools/list` for any other
460
- name, which leaves the harness with no Kagura tools. It applies a
461
- `?tools=` allowlist already on the URL instead, so that case gets a
462
- warning. Both go at the end of the query, `guardrails`
463
- first, replacing any value already there, as the Python CLI writes them.
464
- A `setup claude` run that leaves out a `guardrails` or `profile` value
465
- the entry it replaces had says so in a note. `--name`, `--force` and
568
+ `guardrails`). All of this is as in Python.
569
+
570
+ **What `tools/list` shows** (the entry's tool view). Since memory-cloud
571
+ 0.93.0 a bare MCP URL lists the `core` profile, the memory loop (21 tools
572
+ on 0.141.0), and `?profile=full` every tool (72). `tools/call` is
573
+ unaffected: a profile is a view, not an authorization boundary, so an
574
+ unlisted tool stays callable and every `KaguraClient` method works on any
575
+ URL. `--tool-profile NAME` (every harness; memory-cloud v0.73.0+) sets
576
+ `profile`; the server knows only `core` and `full` (case-sensitive) and
577
+ fails `tools/list` for any other name, which leaves the harness with no
578
+ Kagura tools. Setup leaves that check to the server and refuses only a
579
+ blank name or one starting with `-` (exit 2), as Python does.
580
+ `--add-tools NAME[,NAME…]` (every harness; v0.129.0+; may
581
+ repeat) lists more tools on top of the profile: trimmed, de-duplicated,
582
+ at most 100, unknown names ignored by the server. `recall`'s
583
+ `explore_hints` need `explore` listed (v0.135.0 took it out of `core`),
584
+ so add `--add-tools explore` or use `--tool-profile full`. A `?tools=`
585
+ allowlist already on the URL wins over both, which gets a warning.
586
+ `--context CONTEXT_ID` (`setup claude`; v0.114.0+) names the connection's
587
+ default context: context-scoped tools called without `context_id` run in
588
+ it, an explicit `context_id` wins, and the default is checked like one,
589
+ so it never widens access; unlike `--context-id`, it must be a UUID. On
590
+ codex, hermes and openclaw a `?profile=` or `?add_tools=` already in
591
+ `--mcp-url` is kept when the flag is absent, and Codex's `--guardrails`
592
+ preview repeats the entry's view (`--profile` / `--tools` /
593
+ `--add-tools`), so its truncation note names a tool the entry lists. The
594
+ keys go at the end of the query in Python's order (`guardrails`,
595
+ `profile`, `add_tools`, `context`), replacing any value already there,
596
+ with commas left literal, as the Python CLI writes them. A `setup claude`
597
+ run that leaves out a `guardrails`, `profile`, `add_tools` or `context`
598
+ value the entry it replaces had, or its `?tools=` allowlist (which goes
599
+ back on `--mcp-url`), says so in a note, reading the old URL as the
600
+ server does: the first value of each key, trimmed; a blank one, or a
601
+ `?tools=` naming no tool, is left out, as the Python CLI 0.44.0 does.
602
+ Servers older than a
603
+ parameter ignore it. `--name`, `--force` and
466
604
  `--dry-run` (codex, hermes, openclaw) name the entry, replace an existing
467
605
  one, and show the command or block without changing anything. A name is
468
606
  1-64 letters, digits, `-` or `_`, starting with a letter or digit, as in
469
607
  Python: it is a bare argument to `codex` and `openclaw`, which would read
470
608
  `--help` as an option. Their `--context-id` must be a context UUID
471
609
  (exit 2 otherwise, a padded or empty one included), as in Python without
472
- `--profile`: this port lists no contexts.
610
+ `--profile`: this port lists no contexts. `--dry-run` shows one not in
611
+ the dashed form (dashless, `{braced}`, `urn:uuid:`) as `<UUID of context
612
+ VALUE>`, as Python 0.44.0 does.
473
613
 
474
614
  **The AGENTS.md export.** `--agents-md [PATH]` on `setup codex`, `setup
475
615
  hermes` and `setup openclaw` (memory-cloud v0.74.0+) fetches the
@@ -565,15 +705,17 @@ Nor are the skills of the Python CLI's Claude Code plugin, such as the
565
705
  `remember`, `recall`, `reference`, `update-memory` and `forget` and their
566
706
  `--details`/`--location` rules: this package ships no Claude Code plugin.
567
707
 
568
- Every other command of the Python CLI is here as of 0.12.0
708
+ Every other command of the Python CLI 0.44.0 is here, with the
709
+ differences in options and output this section lists: all but
710
+ `bootstrap`, `changes` and `list` as of 0.12.0
569
711
  ([#57](https://github.com/kagura-ai/kagura-memory-typescript-sdk/issues/57)),
570
- with the differences in options and output this section lists.
712
+ and those three, which the Python CLI added in 0.44.0, as of 0.15.0
713
+ ([#86](https://github.com/kagura-ai/kagura-memory-typescript-sdk/issues/86)).
571
714
 
572
715
  **Only in this bin.** `secret keygen --reveal`: keygen prints the private
573
716
  key (see key custody below) and refuses to print it to a terminal without
574
717
  `--reveal`. `-c` is short for `--context-id` on every `setup` subcommand.
575
- `setup codex` also takes `--tool-profile`, which the Python CLI has only on
576
- `setup claude`. `auth refresh --no-browser`: a refresh that widens
718
+ `auth refresh --no-browser`: a refresh that widens
577
719
  `--scope` re-runs the device flow here too, and this skips opening the
578
720
  browser, as on `auth login`; Python's `auth refresh` takes only
579
721
  `--profile` and `--scope`. `-h` is short for `--help` everywhere, where
@@ -679,13 +821,17 @@ would accept.
679
821
  - `context update --lock --unlock` is a usage error (exit 2, "mutually
680
822
  exclusive; pick one"), where click takes whichever flag comes last.
681
823
  - `--rerank --no-rerank` is the same usage error, on `recall` and on
682
- `context search-config`.
824
+ `context search-config`, and so are `--content-chunks
825
+ --no-content-chunks` and `--llm-selector --no-llm-selector`.
683
826
  - `auth logout --all --profile NAME` is the same usage error, where click
684
827
  ignores `--profile` and logs out every profile.
685
- - `update-memory --dismiss-supersede-candidate` exits 1 beside any
686
- `--external-id`, before anything is sent. The Python CLI refuses only a
687
- non-empty one, and sends an empty `--external-id=` to the server; this
688
- CLI refuses that too, as `updateMemory` does.
828
+ - `update-memory --dismiss-supersede-candidate`, and the other flags
829
+ that need `--memory-id` (`--accept-supersede-candidate`,
830
+ `--merge-details`, `--details-patch`, `--add-tag`, `--remove-tag`,
831
+ `--expected-version`), exit 1 beside any `--external-id`, before
832
+ anything is sent. The Python CLI refuses only a non-empty one, and sends
833
+ an empty `--external-id=` to the server beside `-m`, which refuses both
834
+ ids; this CLI refuses that too, as `updateMemory` does.
689
835
  - `-k=5` (a short option, `=`, a value) reads `5`, where click reads `=5`
690
836
  as the value and then refuses it.
691
837
  - An option that takes a value does not take a following argument that
@@ -708,23 +854,31 @@ would accept.
708
854
  id rather than reaching another route or replacing the query
709
855
  (`files delete 'x?workspace_id=…'`).
710
856
 
711
- **Differences from the Python CLI 0.42.0 in what it added**, each on
712
- purpose or out of reach:
713
-
714
- - `update-memory --details` and `remember --details` refuse text that is
715
- not JSON with JavaScript's parser message after `Invalid JSON for
716
- --details:`, where Python prints its `json` module's.
857
+ **Differences from the Python CLI 0.42.0–0.44.0 in what those releases
858
+ added**, each on purpose or out of reach:
859
+
860
+ - `update-memory --details` and `remember --details` refuse a `NaN` or
861
+ an infinity in the object (`Out of range float values are not JSON
862
+ compliant: nan`, exit 1, Python's line) before the context is looked
863
+ up; the Python CLI reads the object as JSON and fails only when it
864
+ sends it, so without a context it reports that first. (`--details-patch`
865
+ refuses it where Python does, never sending a `null` that would delete
866
+ the key.) Text that is not JSON at all gets Python's `json` module's
867
+ message, as `list --filters` does.
717
868
  - `update-memory --merge-details` prints the size of a bounded
718
869
  `reference` reply when `details_total_chars` is a whole number sent as a
719
870
  float (`24000.0`), which Python leaves out: JSON.parse cannot tell it
720
871
  from `24000`.
872
+ - A message of `update-memory` (0.44.0) that names a command says
873
+ `kagura-memory reference`, where the Python CLI's says `kagura
874
+ reference`.
721
875
  - `getServerInfo`, `checkServerVersion`, `getEmbeddingStatus`,
722
876
  `getMemoryStats`, `findDuplicates` and `listEmbeddingModels` check the
723
877
  body against the Python model and return it as the server sent it:
724
878
  keys the model does not have stay, and a lax value such as `"3"` for an
725
879
  int is not converted, where Python returns the model.
726
880
  - `getMemoryStats` accepts rows without `use_count`, which memory-cloud
727
- v0.34.0 and later never send. The Python SDK 0.42.0's model still
881
+ v0.34.0 and later never send. The Python SDK's model (0.44.0 too) still
728
882
  requires it, so it refuses every non-empty page
729
883
  (`memories.0.use_count: Field required`).
730
884
  - `listMemories` returns its body unchecked. The Python SDK has read it
@@ -740,7 +894,8 @@ purpose or out of reach:
740
894
  **`guardrails load` and `guardrails digest`** (memory-cloud v0.74.0+)
741
895
  take the context as an optional argument, else `context_id` from
742
896
  `.kagura.json`. `load` calls the MCP `load_guardrails` tool and prints the
743
- set as the Python CLI prints it: the model's fifteen keys in its order,
897
+ set as the Python CLI prints it: the model's sixteen keys in its order
898
+ (`context_summary_omitted` last, `false` when the tool sends none),
744
899
  without the `context_display_name`, `context_is_private` and
745
900
  `context_is_locked` the tool adds, each item's eleven keys, and `null` for
746
901
  a `tool_trigger` the Python SDK cannot read (`match: null` is filled in
@@ -750,8 +905,10 @@ text (exit 1) rather than printed as complete. `--cap` takes 1-1000.
750
905
  `digest` reads the REST digest route with the credential chain (an API
751
906
  key or an OAuth profile) and prints the text: the `AGENTS.md` export
752
907
  block, or with `--target instructions` the MCP server instructions this
753
- credential would receive, where `--profile` and `--tools` repeat an MCP
754
- URL's `?profile=` and `?tools=`. A context with no tool guardrails prints
908
+ credential would receive, where `--profile`, `--tools` and `--add-tools`
909
+ (memory-cloud v0.129.0+; comma-separated, may repeat) repeat an MCP URL's
910
+ `?profile=`, `?tools=` and `?add_tools=`; without them, memory-cloud 0.93.0+
911
+ previews the `core` view a bare URL lists. A context with no tool guardrails prints
755
912
  nothing, and says so on stderr. With `--out FILE`, it splices the block
756
913
  into FILE between its marker lines: an earlier block is replaced in place,
757
914
  an unchanged set rewrites nothing, and an empty set removes an earlier
@@ -767,6 +924,26 @@ parse; and a failed read or write of the `--out` file reads in Node's
767
924
  words (`ENOENT: no such file or directory, open '…'`) rather than
768
925
  Python's (`[Errno 2] No such file or directory: '…'`).
769
926
 
927
+ **`sleep history` and `sleep report`** print what the Python CLI prints:
928
+ `{"reports": […]}` and the report, each read through the Python SDK's
929
+ model (`SleepReport`, `SleepReportDetail`) — its keys in its order, its
930
+ default for a key an older server leaves out (`source: null`,
931
+ `actions_has_more: false`, an action's `details_omitted: false`), a
932
+ timestamp in pydantic's form — and a report the model refuses exits 1
933
+ with its `KaguraResponseError` text. `history --source
934
+ sleep|analysis|all` (memory-cloud v0.138.0+) lists Sleep runs (the
935
+ server's default), the rows Memory Analysis writes for its LLM spend, or
936
+ both. `report --actions-limit N` (1-200; the server's default is 50) and
937
+ `--actions-cursor C` (memory-cloud v0.82.0+) page the audit log: while
938
+ `actions_has_more` is true, pass `actions_next_cursor` as
939
+ `--actions-cursor`. `report`'s `CONTEXT_ID` is kept for compatibility
940
+ and not sent: the server finds the run by `REPORT_ID`.
941
+
942
+ ```bash
943
+ npx kagura-memory sleep history <context-id> --limit 5 --source all
944
+ npx kagura-memory sleep report <context-id> <report-id> --actions-limit 100 --actions-cursor <cursor>
945
+ ```
946
+
770
947
  **`doctor`** checks the credentials, the `kagura-memory` entry Claude Code
771
948
  uses, the optional `age-encryption` peer and the age identity, then the
772
949
  server, whose checks are the Python CLI's: `Server reachable`, then
@@ -796,7 +973,15 @@ resolves it, as in Python: `KAGURA_API_KEY`, then the OAuth profile
796
973
  is the default), then `.kagura.json`. A selected profile that does not
797
974
  exist fails the auth section once, with the resolution's message, and
798
975
  with `KAGURA_API_KEY` set an expired or missing profile is no failure, as
799
- in Python, whose warning is that the key shadows the profile. A resolved
976
+ in Python, whose warning is that the key shadows the profile. A static
977
+ key that does not start with `kagura_` gets Python's auth warning
978
+ (`Unusual API key shape: <first 8>...<last 4>. This value does not look
979
+ like a Kagura API key (kagura_…); the server routes bearer tokens by
980
+ shape, so an OAuth token passed as an API key is a 401.`): from
981
+ memory-cloud v0.119.0 the server looks a `kagura_` bearer up only among
982
+ API keys and any other one only among OAuth tokens, so an OAuth token
983
+ configured as the API key is refused. It is a warning, so the exit code is
984
+ unchanged, and only the redacted preview is printed. A resolved
800
985
  MCP URL that is not HTTPS is a warning and the server is not contacted
801
986
  (`Server connectivity check skipped because the MCP URL is insecure`),
802
987
  whichever source it came from:
@@ -806,9 +991,29 @@ remaining difference: a plain-HTTP `.kagura.json` `mcp_url` that the
806
991
  credential does not use, because `KAGURA_API_KEY` or an OAuth profile
807
992
  brings its own URL, still fails the `mcp` section here (`mcp_url is not
808
993
  HTTPS: …`, exit 1), since `setup claude` would refuse that URL; the
809
- Python CLI's `doctor` never reads the file's `mcp_url`. `--json`
810
- prints Python's shape, with `details` on every check (`{}` when there are
811
- none). Any failed check exits 1.
994
+ Python CLI's `doctor` never reads the file's `mcp_url`.
995
+
996
+ The last section, `tools` (Python 0.43.0's, python-sdk#300), is the
997
+ `tools/list` view of the CLI's MCP URL, asked on the server check's own
998
+ client: `tools/list on the CLI's MCP URL: 21 tools (profile core
999
+ (default))`. The URL's query is read as the server reads it (the first
1000
+ value of a key wins): `profile full`, `+ add_tools explore, list_edges`
1001
+ for an `?add_tools=`, `tools allowlist recall,remember` for a `?tools=`
1002
+ (which beats the other two), and `profile core (default)` without
1003
+ `?profile=` on memory-cloud 0.93.0+ (`no ?profile=` on an older server,
1004
+ or when the version is unknown, as after the OAuth `info` line). A
1005
+ `tools/list` that fails fails the check, never doctor, with the view in
1006
+ the message (`tools allowlist (empty)` for a `?tools=` naming no tool, and
1007
+ `profile (empty)` for a blank `?profile=`, both of which the server
1008
+ refuses), and so does a reply that is no `tools/list` result, with
1009
+ `getToolDefinitions`' `KaguraResponseError` message; a 401 for a static key without the `kagura_` prefix carries the
1010
+ bearer-routing hint above. It is skipped when the server check fails or
1011
+ finds the server below the minimum. A Claude Code entry's own tool view
1012
+ (its URL's query) is not this one. `--json` details carry `mcp_url`, the
1013
+ view and `tool_count`.
1014
+
1015
+ `--json` prints Python's shape, with `details` on every check (`{}` when
1016
+ there are none). Any failed check exits 1.
812
1017
 
813
1018
  **Sign-in rate limit.** memory-cloud v0.76.0 and later limit device sign-in
814
1019
  requests per client address. When the server refuses one with HTTP 429,
@@ -833,11 +1038,22 @@ current directory and each entry it hides, in the Python CLI's words
833
1038
  when there is none, with non-ASCII escaped as `\uXXXX`, as Python's
834
1039
  `json.dumps` default writes it. `auth list` and `auth status` without
835
1040
  profiles exit 1. `auth logout`
836
- revokes the access
837
- token on the server before it deletes the profile, best effort: the
838
- profile is deleted even when that fails, with Python's warning (with
839
- `--all`, silently, as in Python). It notes when `KAGURA_API_KEY` is still
840
- set. Unlike the Python CLI, it asks before removing anything unless
1041
+ revokes the profile's refresh token on the server, as Python 0.43.0+
1042
+ does, and then its access token, before it deletes the profile; on
1043
+ memory-cloud v0.82.0+ revoking the refresh token revokes the access token
1044
+ issued with it too
1045
+ ([memory-cloud#1741](https://github.com/kagura-ai/memory-cloud/issues/1741)),
1046
+ while an older server revokes only the token sent. Up to 0.14.1 it
1047
+ revoked only the access token, which left the refresh token valid. The
1048
+ revoke is best effort: the profile is deleted even when it fails, with
1049
+ Python's warning (with `--all`, silently, as in Python). It notes when
1050
+ `KAGURA_API_KEY` is still set. Its lines read `Profile 'NAME' removed.`
1051
+ and `All profiles removed.`, where Python prints `✓ Profile 'NAME'
1052
+ removed.` and `✓ All profiles removed; ~/.kagura/credentials.json
1053
+ deleted.`, and that note says `kagura-memory commands` where Python's
1054
+ says `kagura commands`. Unlike the Python CLI, it also revokes the
1055
+ access token, which Python leaves valid until it expires on a server
1056
+ before v0.82.0; it asks before removing anything unless
841
1057
  `--yes` (`-y`) is given, rather than refusing `--all` without it; a
842
1058
  logout that names no profile succeeds when nothing is stored, so
843
1059
  `logout --yes` stays idempotent in setup scripts; and `--all` with
@@ -869,7 +1085,12 @@ revoke-key` ask first, naming the workspace, unless `--yes` (`-y`).
869
1085
  once on stdout, after a warning on stderr. `list-keys` and `invite list`
870
1086
  never show either; their `--json`, like `member list --json`, prints
871
1087
  the Python model's fields in its order, `null` or `false` for what the
872
- server left out, and drops any other. A record the model refuses (a
1088
+ server left out, and drops any other. A key's or invitation's `id` is
1089
+ read as the model's `int | str`, as in `WorkspaceClient.mintMemberKey`:
1090
+ the opaque `akey_…` / `winv_…` id of a memory-cloud v0.89.0+ server is
1091
+ printed as the string (a numeric string such as `"7"` stays a string),
1092
+ an older server's integer as the integer, and the tables widen the ID
1093
+ column to the longest id. A record the model refuses (a
873
1094
  required field missing, a scalar, list or mapping of the wrong type)
874
1095
  exits 1 with its `KaguraResponseError` text; timestamps are printed as
875
1096
  the server wrote them. `--role` matches exactly, as
@@ -1073,6 +1294,54 @@ Callers holding their own provider can use `KaguraOAuth` directly — its
1073
1294
  `forceRefresh()` is what `refresh()` builds on, including the
1074
1295
  cross-process lock and the "another process already rotated" dedup.
1075
1296
 
1297
+ **One refresh path.** A refresh token works once (memory-cloud v0.79.0+,
1298
+ kagura-ai/memory-cloud#1686): of two processes presenting the same one, the
1299
+ second gets `invalid_grant`. So every refresh — `KaguraOAuth` in a client or
1300
+ in `kagura-memory-mcp`, `refresh()`, and the CLI's `auth refresh` and
1301
+ `auth token` — takes the lock on `credentials.json` (a sibling
1302
+ `credentials.json.lock`), re-reads the profile, and when another process
1303
+ already rotated it to a token that has not expired, uses that profile and
1304
+ sends nothing; otherwise it refreshes from the refresh token on file and
1305
+ saves the result before it releases the lock. (Python 0.44.0 also adopts a
1306
+ different token that has expired; this SDK refreshes it instead.) The
1307
+ device flow a widening `--scope` falls back to runs after the lock is
1308
+ released, since it waits on the user. The Python SDK
1309
+ locks the same `credentials.json.lock` with an OS lock, which Node does not
1310
+ have, so the two SDKs' locks do not exclude each other: between them only
1311
+ the re-read applies. This is client-side and works against every server. As
1312
+ in Python SDK 0.44.0 (kagura-ai/kagura-memory-python-sdk#313):
1313
+
1314
+ - `auth refresh` says `✓ Profile 'NAME' was already refreshed by another
1315
+ process.` when it found the profile rotated under the lock, and `✓
1316
+ Refreshed profile 'NAME'.` after a refresh of its own, each followed by
1317
+ the `Scope:` and `Expires:` lines; both exit 0. `auth token` prints the
1318
+ token another process refreshed.
1319
+ - A `credentials.json` that exists but cannot be read or parsed is refused
1320
+ before any refresh request or write, and left as it is: `KaguraAuthError`
1321
+ `Cannot update <path>: it is not valid JSON.` (or why else it cannot be
1322
+ read), with `Fix the file, or move it aside and run: kagura-memory auth
1323
+ login`. This holds for a refresh (checked under the lock), the save at
1324
+ the end of `login()`, `updateProfile`, `setDefaultProfile` and
1325
+ `deleteProfile`; `kagura-memory-mcp` refuses it at startup and before any
1326
+ login. "Exists" includes a dangling symlink, and a file in a directory
1327
+ this process cannot search. A missing file is still "no profile".
1328
+ `loadCredentialsFile()`, client construction, `refresh()` and the CLI's
1329
+ `auth refresh` / `auth token` read such a file as holding no profile first,
1330
+ as Python's do (`No profile named 'default'.`); the refusal comes when it
1331
+ became unreadable by the time the lock is held.
1332
+ - When the server refreshed but the profile cannot be saved (a full disk, a
1333
+ read-only directory), the refresh throws `KaguraAuthError` `Refreshed
1334
+ profile 'NAME', but could not save it to <path>: <reason>`, saying the
1335
+ refresh used up the refresh token on file and to run `kagura-memory auth
1336
+ login` after fixing the cause. The process that refreshed keeps the
1337
+ rotated token in memory (its next refresh sends the new refresh token,
1338
+ until another process saves the profile), so a client stays usable until
1339
+ it expires; `kagura-memory-mcp` goes on serving the request with it and
1340
+ logs the message once. A widening `--scope` whose device-flow grant
1341
+ cannot be saved gives the same kind of error (`Got consent for scope
1342
+ …`), and the grant is kept the same way. `auth refresh` and `auth token`
1343
+ exit 1, and `auth token` prints no token.
1344
+
1076
1345
  ### Error handling
1077
1346
 
1078
1347
  All errors extend `KaguraError`:
@@ -1091,19 +1360,113 @@ try {
1091
1360
  }
1092
1361
  ```
1093
1362
 
1363
+ Every error the server reported keeps what it sent. `code` is its error
1364
+ code: the MCP envelope's `error` (`payload_too_large`, `capacity_locked`
1365
+ …), the REST body's `error` (`FEAT-001`, `CAPACITY-001`, `DB-002` …), the
1366
+ OAuth `error` (`invalid_client`, `insufficient_scope` …) or a JSON-RPC
1367
+ error's `data.error`; it is `undefined` when the SDK raised the error
1368
+ itself or the server named no code (an MCP envelope without `error`,
1369
+ whose message still reads `failed (unknown)`). `details` holds the other
1370
+ fields as sent (the MCP envelope without `status` / `error` / `message`,
1371
+ the REST `details` whole, the JSON-RPC `data` without its `error`, an
1372
+ OAuth body without its `error`), `{}` when there are none. A JSON-RPC
1373
+ error that `/mcp` answers with HTTP 200 (a `tools/call` whose plumbing
1374
+ failed) stays a `KaguraConnectionError` (`MCP error: …`), as in Python,
1375
+ and keeps its `data` the same way. **Branch on `code` and the class,
1376
+ never on the message**: memory-cloud words its messages for people and
1377
+ changes them.
1378
+
1379
+ Since memory-cloud v0.78.0 an MCP tool refusal carries `help`, the next
1380
+ step, and a tool's server failure `help`, `cause`, `correlation_id`,
1381
+ `retryable` and, for a write, `outcome: "unknown"`; since v0.82.0 the
1382
+ `/mcp` transport's own JSON-RPC errors (a 503, a failed session) carry
1383
+ them too. `KaguraError` reads
1384
+ them from `details` as getters, `null` when absent:
1385
+
1386
+ | Getter | Envelope field | Meaning |
1387
+ |--------|----------------|---------|
1388
+ | `help` | `help` | what to do next |
1389
+ | `serverCause` | `cause` | why a server failure happened: `timeout`, `service_unavailable` or `internal_error`; `null` on a refusal, which is the caller's to fix |
1390
+ | `correlationId` | `correlation_id` | the id the server logged the failure under — quote it in a report |
1391
+ | `retryable` | `retryable` | whether repeating the call is safe; `false` for a write whose outcome is unknown |
1392
+ | `outcome` | `outcome` | `"unknown"` when a failed write may or may not have been applied: check with the read `help` names before calling it again |
1393
+
1394
+ `serverCause` is the Python SDK's `cause` property, renamed because
1395
+ JavaScript's `Error.cause` already holds the chained error (the `fetch`
1396
+ failure, a parse error); `details.cause` holds the server's value too.
1397
+
1398
+ ```ts
1399
+ import { KaguraCapacityLockedError, KaguraError, KaguraServiceUnavailableError } from "kagura-memory";
1400
+
1401
+ try {
1402
+ await client.remember({ contextId, summary: "s", content: "..." });
1403
+ } catch (e) {
1404
+ if (e instanceof KaguraCapacityLockedError) {
1405
+ console.log(`over by ${e.overMemories} memories; clean up at ${e.cleanupUrl}`);
1406
+ } else if (e instanceof KaguraServiceUnavailableError) {
1407
+ console.log(`retry in ${e.retryAfter ?? "a few"} s (${e.reason})`);
1408
+ } else if (e instanceof KaguraError && e.code === "payload_too_large") {
1409
+ console.log(`split it: ${e.details.actual} > ${e.details.limit}`);
1410
+ } else if (e instanceof KaguraError && e.outcome === "unknown") {
1411
+ console.log(`may have been saved; ${e.help} (correlation id ${e.correlationId})`);
1412
+ }
1413
+ }
1414
+ ```
1415
+
1094
1416
  Server-side domain errors (`{"status": "error", ...}`) are translated into
1095
1417
  exceptions, so you never need to inspect `result.status`. The class is
1096
1418
  keyed on the error code and the envelope's fields, never on the message:
1097
1419
 
1098
1420
  | Class | Raised for | Carries |
1099
1421
  |-------|------------|---------|
1100
- | `KaguraNotFoundError` | missing contexts/memories/reports/agents/bindings (on `updateSearchConfig`, a missing context is a `KaguraPermissionError` instead) | — |
1101
- | `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` |
1422
+ | `KaguraNotFoundError` | missing contexts/memories/reports/agents/bindings, and `rollbackSession`'s `session_not_found` (on `updateSearchConfig`, a missing context is a `KaguraPermissionError` instead) | — |
1423
+ | `KaguraFeatureNotAvailableError` | MCP `plan_required` / `feature_not_available`; REST 403 `FEAT-001` — the plan lacks a feature, or it is switched off. From memory-cloud v0.100.0 also a plan that dropped below what the workspace holds: `feature` `"members"` on every workspace route for a member without a seat, `"contexts"` on a content write into a context without a writable slot (`limit` / `current` in `details`) | `feature`, `requiredPlan`, `requiredPlanDisplay`, `currentPlan`, `gate` |
1102
1424
  | `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 |
1425
+ | `KaguraCapacityLockedError` | memory-cloud v0.99.0+: a Free workspace over its capacity — MCP `capacity_locked`, REST 403 `CAPACITY-001` (`details.gate` `"capacity"`). Search and saving are refused until it is cleaned up or re-subscribed; listing, deleting, export and `getUsage` keep working. Neither a quota nor a plan gate, so it extends neither class. A caller outside the locked workspace (a public context) gets every figure `null` | `cleanupUrl`, `memoryCount`, `memoryLimit`, `overMemories`, `usedBytes`, `storageLimitBytes`, `overBytes`, `gate` (`"capacity"`) |
1426
+ | `KaguraAuthError` | HTTP 401; and from memory-cloud v0.79.0 an OAuth token that lacks the scope a call needs (HTTP 403 `insufficient_scope`): `memory:read` for the read-only tools, `recall` and `getAgentBootstrap`, `memory:write` for every other tool, so a `kagura-memory auth login --read-only` profile gets it on every write. The message names the scope and the re-login | `code` `"insufficient_scope"`, `details.required_scope` |
1427
+ | `KaguraServiceUnavailableError` | any HTTP 503 from `/mcp` or a REST route (the OAuth endpoints keep their own errors): `/mcp`'s `temporarily_unavailable` (the credential could not be verified, v0.82.0+) and its JSON-RPC transport failures (a dependency down or timed out), REST `DB-002` (the database unavailable). A `KaguraConnectionError`, so existing handlers keep catching it | `retryAfter` (the `Retry-After` header, else `data.retry_after_seconds`; `null` on a write whose outcome is unknown), `reason` (REST `details.reason`, else the MCP `cause`, else the code) |
1103
1428
  | `KaguraPartialRollbackError` | `rollbackSleepRun` reversed some actions but not all. A `rollback_summary` the SDK cannot read adds ` (rollback_summary could not be read)` to the message, as Python's does, with `summary` `{}` (Python: `None`) and the `KaguraResponseError` as `cause` | `reportId`, `summary` |
1429
+ | `KaguraPartialSessionRollbackError` | `rollbackSession` (memory-cloud v0.113.0+) failed some items of a real run (`partial_rollback`); every other item was handled and saved, and a call with the same arguments retries the failed ones. A field the SDK cannot read is `null` rather than a second error | `sessionSummary` (with `errors`), `totals`, `rollbackId`, `remaining` |
1104
1430
  | `KaguraResponseError` | a successful response the SDK cannot read, usually because the server is newer than this SDK. That includes `getServerInfo`, `checkServerVersion` (as `KaguraClient.get_server_info`), `getEmbeddingStatus`, `getMemoryStats`, `findDuplicates` and `listEmbeddingModels`, which check the body against the Python model and return it as sent. 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` |
1431
+ | `KaguraVersionConflictError` | memory-cloud v0.113.0+: an `updateMemory({ expectedVersion })` that found the memory at another version, so nothing was written — MCP `version_conflict`, REST 409 `RES-002` with `details.reason` `"version_conflict"` (the files API's dedup 409 shares `RES-002` without that reason and stays a `KaguraConnectionError`). Read the memory again and resend with its version, or drop `expectedVersion` to overwrite | `currentVersion`, `expectedVersion`, `memoryId` (MCP only), all read from `details` |
1105
1432
  | `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` |
1106
- | `KaguraError` | any other code | — |
1433
+ | `KaguraError` | any other code — `payload_too_large` among them, a memory over 1 MB on MCP (memory-cloud v0.108.0+; it replaced `quota_exceeded` there, and REST keeps `429 QUOTA-001`): no plan lifts it, so it is no quota. Also `edge_exists` (v0.126.0+), an `acceptSupersedeCandidate` that met a different declared edge between the pair (nothing written), and `dedupe_unavailable` (v0.93.0+), a `dedupe: "check"` that could not run | `code`, `details` (`limit` / `actual` for `payload_too_large`, `existing_edge` for `edge_exists`) |
1434
+
1435
+ The codes the SDK types, by surface:
1436
+
1437
+ | Code | Surface | Class | Server |
1438
+ |------|---------|-------|--------|
1439
+ | `capacity_locked` | MCP | `KaguraCapacityLockedError` | v0.99.0+ |
1440
+ | `CAPACITY-001` (`details.gate` `"capacity"`) | REST 403 | `KaguraCapacityLockedError` | v0.99.0+ |
1441
+ | `plan_required`, `feature_not_available` | MCP | `KaguraFeatureNotAvailableError` | |
1442
+ | `FEAT-001` (`details.feature`; `members` / `contexts` from v0.100.0) | REST 403 | `KaguraFeatureNotAvailableError` | |
1443
+ | `quota_exceeded`, `CONNECTOR-001`, `rate_limit_exceeded` | MCP | `KaguraQuotaError` | |
1444
+ | `QUOTA-001`, `QUOTA-002`, `CONNECTOR-001` | REST | `KaguraQuotaError` | |
1445
+ | `insufficient_scope` | MCP / REST 403 | `KaguraAuthError` | v0.79.0+ |
1446
+ | `temporarily_unavailable` | MCP 503 | `KaguraServiceUnavailableError` | v0.82.0+ |
1447
+ | `timeout`, `service_unavailable` (JSON-RPC `data.error`) | MCP 503 | `KaguraServiceUnavailableError` | v0.82.0+ |
1448
+ | `DB-002` (`details.reason`: `pool_exhausted`, `connection_refused`, `database_error`, `deadlock`) | REST 503 | `KaguraServiceUnavailableError` | v0.104.0+ (`deadlock` v0.105.0) |
1449
+ | `payload_too_large` (`limit`, `actual`) | MCP | `KaguraError` | v0.108.0+ |
1450
+ | `invalid_request`, `invalid_client`, `invalid_scope` (`device/authorize`) | OAuth | `KaguraAuthError`, `error_description` in the message and `details` | v0.78.0+ |
1451
+
1452
+ A gate is read before the code, so a v0.75.0+ server's `gate` decides the
1453
+ class whatever the code. `kagura-memory` commands print, under the error
1454
+ message, the reset time, the required plan, the capacity lock's cleanup
1455
+ page (unless `help` already names it), a 503's retry window and the
1456
+ server's `help` and correlation id, as the Python CLI does.
1457
+
1458
+ `authorizeDevice` turns an RFC 6749 refusal from `device/authorize`
1459
+ (memory-cloud v0.78.0+) into a `KaguraAuthError` whose `code` is the OAuth
1460
+ `error` and whose message carries the `error_description`. Only an RFC
1461
+ 6749 code or a body with an `error_description` reads so: any other error
1462
+ body — memory-cloud's REST `HTTP-404` from a server URL with the wrong
1463
+ path — keeps the generic `Device authorization failed (HTTP 404): …`
1464
+ message and its "Verify the server URL" hint, with the body's code as
1465
+ `code` (Python 0.44.0 drops that hint). `pollForToken` keeps the OAuth
1466
+ `error` of a refusal it does not know as `code` too. `pollForToken` treats `temporarily_unavailable` (v0.84.0+) as transient:
1467
+ it keeps polling until the device code expires, after the `Retry-After`
1468
+ wait when the server sent one (never less than the interval, never past
1469
+ the expiry), else the interval.
1107
1470
 
1108
1471
  `ResourceClient`'s readers check each 2xx body against the Python SDK's
1109
1472
  model, as Python's `_parse` does, and throw `KaguraResponseError` for one
@@ -1128,8 +1491,9 @@ when no plan lifts the refusal, which is what an `allowlist` or
1128
1491
  including one no tier raises, so an upgrade helps only when `requiredPlan`
1129
1492
  is non-null. With no `gate`, a `null` `requiredPlan` means the plan is
1130
1493
  unknown, not that no plan lifts it. That covers an older server, and
1131
- `createContext`'s own context-limit check, which reads `listContexts()`
1132
- and so fills in only `quotaType`, `current` and `limit`.
1494
+ `createContext`'s own context-limit check, which reads a one-row
1495
+ `listContexts({ limit: 1 })` page and so fills in only `quotaType`,
1496
+ `current` and `limit`.
1133
1497
 
1134
1498
  `retryAfter` is the `Retry-After` header, else the retry hint in the body
1135
1499
  (REST `details.retry_after`, MCP `retry_after_seconds`, which is all the
@@ -1177,12 +1541,259 @@ when `undefined`.
1177
1541
 
1178
1542
  | Method | What it does |
1179
1543
  |--------|--------------|
1180
- | `remember` | Store a memory. `details` accepts arbitrary JSON, including `location` (see below) and the reserved `tool_trigger`, which marks a tool guardrail and needs context editor or above on a user (not agent) credential; `supersedes` declares this the newer version of an existing memory, shadowing the old one from default recall without destroying it; `deliveryMode: "always"` pins it. |
1181
- | `recall` | Hybrid semantic + keyword search. Takes `filters` (`type`, `scope`, `tags` with `tags_match` and `tags_normalize`, `importance` bounds, created/updated date bounds, `source_uri_prefix`, `source_type`, `trust_tier`, and the `near` / `within` geo filters), `searchMode`, `useRerank`, `includeExploreHints`, `includeSuperseded` (read back what `supersedes` shadowed, annotated with `superseded_by`), and `contextIds` for 2–20-context search. `useRerank` is tri-state (memory-cloud v0.69.0+): omit it to follow the context's search config (the first context's, with `contextIds`), `true` requests reranking where the context allows it, `false` skips it for the call. A tag filter that matches nothing can return `tag_suggestions`. When the semantic half is unavailable, the result is keyword-only and carries `degraded: true` and `degraded_reason` (v0.66.0+) — an empty one then means "search impaired", not "nothing stored". |
1182
- | `reference` | Full detail for one memory, under `result.memory`. |
1183
- | `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`. |
1184
- | `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"`). |
1185
- | `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). |
1544
+ | `remember` | Store a memory. `details` accepts arbitrary JSON, including `location` (see below) and the reserved `tool_trigger`, which marks a tool guardrail and needs context editor or above on a user (not agent) credential; `supersedes` declares this the newer version of an existing memory, shadowing the old one from default recall without destroying it; `deliveryMode: "always"` pins it. `tags` takes at most 50 tags of at most 100 characters each, the caps memory-cloud v0.82.0+ enforces: more throws before any request, on every server. `toolTrigger` marks the guardrail without writing the key yourself. `observedAt` (v0.127.0+) says when the fact held — a `YYYY-MM-DD` date or an extended ISO 8601 datetime, or a `Date` (sent as its UTC instant), stored as `details.observed_at`; a basic form (`20240307`), a time without seconds, an impossible day or a disagreeing `details.observed_at` throws before any request. `dedupe` (v0.93.0+): `"check"` writes nothing when a near-duplicate exists and returns `{ status: "duplicate_candidate", candidate }` instead of throwing, `"off"` opts the memory out of supersede suggestions for good; `tagsNormalize: true` stores each tag under the context's established spelling; `verbose: true` keeps `persistence.detail`. The reply (`RememberResult`, returned unchecked as Python's dict, so every key is optional) carries `version` (v0.113.0+), `session_id` (v0.113.0+), when a summary over 500 characters was cut, `summary_truncated` / `summary_original_length` (v0.108.0+), and `plan_headroom` (v0.142.0+, read fail-open; see [Plan headroom](#plan-headroom-memory-cloud-v01420)). |
1545
+ | `recall` | Hybrid semantic + keyword search. Takes `filters` (`type`, `scope`, `tags` with `tags_match` and `tags_normalize`, `importance` bounds, created/updated date bounds, `source_uri_prefix`, `source_type`, `trust_tier`, and the `near` / `within` geo filters), `searchMode`, `useRerank`, `includeExploreHints`, `includeSuperseded` (read back what `supersedes` shadowed, annotated with `superseded_by`), and `contextIds` for 2–20-context search. `useRerank` is tri-state (memory-cloud v0.69.0+): omit it to follow the context's search config (the first context's, with `contextIds`), `true` requests reranking where the context allows it, `false` skips it for the call. A tag filter that matches nothing can return `tag_suggestions`. When the semantic half is unavailable, the result is keyword-only and carries `degraded: true` and `degraded_reason` (v0.66.0+) — an empty one then means "search impaired", not "nothing stored". `observedAfter` (inclusive) / `observedBefore` (exclusive) keep the memories whose fact held in that range (`filters.observed_after` / `observed_before`, v0.127.0+; a date is the start of its UTC day, and a memory without `observed_at` never matches); one beside the same key in `filters` throws. Returns a typed `RecallResponse` (`confidence` first: read `confidence.level` before the hits); see [Recall result shape](#recall-result-shape). |
1546
+ | `reference` | Full detail for one memory, under `result.memory` (`ReferenceResponse`), with its `version` (v0.113.0+) — the `expectedVersion` for `updateMemory` — and `observed_at` (v0.127.0+). Since v0.78.0 the reply is bounded (`maxChars`, 10,000–100,000, default 20,000): cut `content` comes with `content_truncated` / `content_next_offset`, and a `details` / `context` / links field that does not fit is left out with `<field>_omitted` / `<field>_total_chars`. Page the rest with `contentOffset`, `detailsOffset` (`details_json` slices) or `contextOffset` — one per call — and pick fields with `fields` (`content`, `details`, `context`, `links`). `version` (v0.113.0+) reads an earlier version (`historical: true`, `current_version`). A live `supersede_candidate` carries `acceptance` (v0.137.0+; see [Supersede suggestions](#supersede-suggestions)). Every one is checked locally (an integer in range, more than one offset refused first, a known field, an offset's own field listed) before any request. The reply comes back as sent once its `status` (a string) and `memory` (an object) are checked: otherwise `KaguraResponseError` (the CLI's `reference` prints the raw reply, as Python's does). |
1547
+ | `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 — and `detailsPatch` (v0.140.0+) merges into it instead: each key replaces the stored one, `null` deletes it, the rest are kept. `tags` replaces the list, with `remember`'s caps; `addTags` / `removeTags` (v0.140.0+) edit it (removals first, each new tag once; `addTags` takes the caps, `removeTags` none). `expectedVersion` (v0.113.0+) applies the edit only while the memory is at that version, else throws `KaguraVersionConflictError` with `currentVersion` and writes nothing. `dismissSupersedeCandidate: true` rejects the server's `supersede_candidate` suggestion; `acceptSupersedeCandidate: true` (v0.126.0+) accepts it — the candidate is shadowed by a `supersedes` edge, named in the reply's `superseded_memory_id`, and a different edge already linking the pair throws `KaguraError` `code` `"edge_exists"`; check the candidate's `acceptance` first ([Supersede suggestions](#supersede-suggestions)). `observedAt`, `toolTrigger` and `verbose` work as on `remember`. The reply (`UpdateMemoryResult`, returned unchecked as Python's dict, so every key is optional) carries `version`, and `plan_headroom` read fail-open as `remember`'s is (v0.142.0+). See [the local rules](#updatememorys-local-rules) below. |
1548
+ | `forget` | Soft-delete by `memoryId`, by `memoryIds` (1-50 ids in one call, memory-cloud v0.117.0+; returns a `ForgetBatchResult`, see [Session tools](#session-tools-memory-cloud-v0930)) 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"`). |
1549
+ | `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). A row carries `observed_at` (v0.127.0+), when the fact held, as the text the server stores: a date `YYYY-MM-DD` or a UTC datetime `YYYY-MM-DDTHH:MM:SSZ`, never parsed (a date sorts and filters as the start of its UTC day). |
1550
+
1551
+ #### `updateMemory`'s local rules
1552
+
1553
+ `updateMemory` refuses before any request what memory-cloud's
1554
+ `UpdateMemoryRequest` refuses (`validation_error`), with the Python SDK
1555
+ 0.44.0's checks: exactly one of `memoryId` / `externalId`; with
1556
+ `externalId` (an upsert replaces the memory under a new id) none of
1557
+ `dismissSupersedeCandidate`, `acceptSupersedeCandidate`,
1558
+ `expectedVersion`, `addTags`, `removeTags`, `detailsPatch` — an empty
1559
+ `externalId: ""` counts as given, as on the server; not both supersede
1560
+ flags; not `tags` beside `addTags` / `removeTags`, nor `details` beside
1561
+ `detailsPatch`; `expectedVersion` an integer ≥ 1 (a boolean is none); the
1562
+ tag caps on `tags` and `addTags`; `toolTrigger` beside a `tool_trigger` key
1563
+ in the object it is merged into (`detailsPatch` when given, else
1564
+ `details`); `observedAt` in a form the server refuses, or disagreeing with
1565
+ `details.observed_at` / `detailsPatch.observed_at` (a patch's
1566
+ `observed_at: null` disagrees too); and `acceptSupersedeCandidate` beside
1567
+ any field edit (`toolTrigger` and `observedAt` included) — it is a graph
1568
+ action, so send the edit in a separate call. Each throws a plain `Error`.
1569
+
1570
+ Every new argument is sent only when set. From memory-cloud v0.82.0 a
1571
+ server refuses an argument it does not declare (`KaguraError`, `code`
1572
+ `"invalid_argument"`, the names in `details.unknown_arguments`); one before
1573
+ v0.82.0 ignores it — an `addTags` / `detailsPatch` edit then changes
1574
+ nothing, and `expectedVersion` guards nothing, which the reply's missing
1575
+ `version` gives away.
1576
+
1577
+ #### Recall result shape
1578
+
1579
+ Since memory-cloud v0.108.0 a `recall` hit is **compact** unless you pass
1580
+ `verbosity: "full"`: `memory_id`, a 160-character `summary` head
1581
+ (`summary_cut: true` when it was cut), `type`, `importance`, `score`,
1582
+ `created_at` and `updated_at`. **`tags`, `context_summary`,
1583
+ `scope`, `version` and the uncut `summary` need `verbosity: "full"`**;
1584
+ code that reads them from a compact hit gets `undefined`. Both shapes
1585
+ carry `observed_at`, `superseded_by`, `contradicts`, `supersede_candidate`
1586
+ (with `verified: true` when the server's judge confirmed it, v0.109.0+,
1587
+ and `acceptance` from v0.142.0 — see
1588
+ [Supersede suggestions](#supersede-suggestions)) and `folded` (older
1589
+ versions of the same fact folded under the newest row, v0.114.0+) when
1590
+ they apply. A key that does not apply is left out:
1591
+ `context_summary` and the annotations since v0.73.0, an empty `tags`
1592
+ since v0.93.0. Older servers send `null` / `[]` for them, so test these
1593
+ keys for truthiness, not for `undefined`. `updated_at` is `null` on a
1594
+ memory never edited.
1595
+
1596
+ Since v0.114.0 the top `full` hits also carry `content` (up to 1,500
1597
+ characters; `content_truncated` / `content_next_offset` when cut, and
1598
+ `reference()` has the rest). The MCP default is 3 (the deployment's
1599
+ `MCP_RECALL_DEFAULT_FULL`), on trusted, non-connector rows only; an
1600
+ explicit `full` makes every row eligible, and `full: 0` returns summaries
1601
+ only. `maxChars` (10,000–100,000, server default 20,000; v0.82.0+) bounds
1602
+ the whole reply: content goes first (`full_applied` counts the rows that
1603
+ kept it), then `context_summary` (`context_summary_omitted: true`), then
1604
+ the lowest-ranked rows (`truncated: true`). A context with the LLM
1605
+ selector on adds `selector` and per-row `spans` (v0.115.0+).
1606
+
1607
+ ```ts
1608
+ const detailed = await client.recall({ contextId, query: "OAuth2", verbosity: "full", full: 0 });
1609
+ for (const hit of detailed.results) {
1610
+ console.log(hit.summary, hit.tags ?? []); // an empty tag list is omitted, not []
1611
+ }
1612
+ const top = await client.recall({ contextId, query: "deploy runbook", full: 1, maxChars: 40_000 });
1613
+ // top.results[0]?.content; with content_truncated, reference() has the whole memory
1614
+ ```
1615
+
1616
+ `verbosity`, `full` and `maxChars` are sent only when set, and checked
1617
+ locally first (`full` 0–100, `maxChars` 10,000–100,000, integers). From
1618
+ v0.82.0 a server refuses an argument it does not declare (`KaguraError`,
1619
+ code `invalid_argument`), so `verbosity` needs v0.108.0+ and `full`
1620
+ v0.114.0+ there; older servers ignore all three. `recall()` never retries
1621
+ without them; the `recall` command of the bin does, once.
1622
+
1623
+ `includeExploreHints` asks for `explore_hints`, seeds for `explore()`.
1624
+ Since v0.135.0 the server makes them only when the MCP URL lists the
1625
+ `explore` tool, which the bare URL (the core tool profile) does not: add
1626
+ `?add_tools=explore` or `?profile=full` to `mcpUrl` (or `explore` to a
1627
+ `tools=` / `add_tools=` list it already has). On any other URL the call
1628
+ still succeeds and carries `explore_hints_omitted`, a sentence naming that
1629
+ opt-in, in place of `explore_hints`. `explore()` itself is unaffected.
1630
+ `kagura-memory setup … --add-tools explore` writes that URL into a
1631
+ harness entry, and `kagura-memory-mcp --add-tools explore` sets it on the
1632
+ proxy's upstream.
1633
+
1634
+ #### Supersede suggestions
1635
+
1636
+ A `supersede_candidate` on a `recall` row or a `reference` memory is a
1637
+ suggestion, never an edge: a near-duplicate this memory may replace.
1638
+ Since memory-cloud v0.137.0 an older memory never takes a newer one as
1639
+ its candidate. Accept it with `updateMemory({ memoryId,
1640
+ acceptSupersedeCandidate: true })` or reject it with
1641
+ `dismissSupersedeCandidate: true`.
1642
+
1643
+ The candidate carries `acceptance: { allowed, reason? }` — whether the
1644
+ accept would go through — on `reference` since v0.137.0 and on every
1645
+ `recall` row that has a candidate since v0.142.0. `reason` is set only
1646
+ when `allowed` is `false`, the first of these that applies:
1647
+
1648
+ - `not_writable`: no write access to the context (an agent binding that
1649
+ does not grant the write included). From v0.142.0 also a memory
1650
+ carrying `details.tool_trigger` when the caller is below context editor
1651
+ or not on a user credential: the guardrail gate the accept runs first.
1652
+ - `not_owner`: one or both memories are not the caller's own (in a
1653
+ private context a linked account's count).
1654
+ - `newer_candidate`: the candidate was written after the memory carrying
1655
+ it; dismiss it instead.
1656
+ - `edge_exists` (v0.138.0+): a different declared edge already links the
1657
+ pair, so the accept would throw `KaguraError` `code` `"edge_exists"`;
1658
+ from v0.142.0 only the edge kept by the carrier's author, the account
1659
+ the accept writes under, counts.
1660
+
1661
+ `acceptance` is absent on an older server, on a share-key read and where
1662
+ the server could not evaluate it; the accept call still decides then. It
1663
+ is typed `SupersedeAcceptance`, `reason` a plain `string` so a reason a
1664
+ newer server adds still reads.
1665
+
1666
+ Only the accept checks the direction: `acceptSupersedeCandidate` refuses
1667
+ a candidate written after the memory carrying it, since accepting it
1668
+ would hide the newer fact behind the older one. `createEdge` and
1669
+ `updateEdge` apply no direction check — for a `supersedes` edge the
1670
+ caller owns it, source newer and target older.
1671
+
1672
+ ```ts
1673
+ const { results } = await client.recall({ contextId, query: "deploy target" });
1674
+ const hit = results.find((r) => r.supersede_candidate?.acceptance?.allowed);
1675
+ if (hit) await client.updateMemory({ contextId, memoryId: hit.memory_id, acceptSupersedeCandidate: true });
1676
+ ```
1677
+
1678
+ ### Session tools (memory-cloud v0.93.0+)
1679
+
1680
+ The tools an agent session starts and ends with. Each sends only the
1681
+ options set, under the server's names, checks the reply against the Python
1682
+ SDK's model (a reply it refuses is `KaguraResponseError` naming the tool)
1683
+ and returns it as sent.
1684
+
1685
+ | Method | What it does |
1686
+ |--------|--------------|
1687
+ | `bootstrap` | Open a session on one context in one deterministic call (no recall): the `context` block, its tool `guardrails`, and the `pinned` / `upcoming` / `changes` lanes under `components`, each fail-soft (`degraded: true` when one failed). `since` (`"0d"`–`"999d"`, ISO 8601 or a `Date`; server default `"7d"`), `include`, `maxChars` (2,000–100,000) and `format`. Not `getAgentBootstrap`, which rehydrates a registered agent. |
1688
+ | `changesSince` | The change log of a context in `[since, until)`, oldest first: `created`, `updated`, `superseded` (with `superseded_by`) and `forgotten` events, keyset-paged (`cursor: next_cursor` while `has_more`). `kinds`, `limit` (1-100), `sessionId` (v0.113.0+), `byMe` (v0.114.0+), `maxChars`. |
1689
+ | `listMatching` | Every live memory matching exact `filters` (recall's vocabulary plus `details.<key>`, JSON-type strict), a stable order (`orderBy` `updated_at` / `created_at` / `importance` / `observed_at` (v0.127.0+), `direction`) and a `total`; offset-paged. The MCP `list` tool — not `listMemories`, which is REST. |
1690
+ | `rememberBatch` | Store 1-50 memories in one call; `items` are `remember` arguments by their wire names (`summary`, `content`, `type` required). `atomic`, `dedupe`, `tagsNormalize`, `verbose`. |
1691
+ | `describeTools` | The tools this MCP URL's `tools/list` leaves out (`query` narrows them), or with `names` (≤ 20) their full definitions, and which URL query lists more. |
1692
+ | `guide` | Sections of the server's tool manual: `guide(["recall", "remember.dedupe"])` (≤ 20 topics; omit for the index). Unknown names come back in `unknown`. |
1693
+ | `listRevisions` | One memory's revision log, newest first (v0.113.0+): `created` / `updated` (with `changed_fields`) / `forgotten` / `restored`, each with the version after it; `writer` is `api`, `rollback` or `erasure`. |
1694
+ | `rollbackSession` | Plan (`dryRun`, **default `true`, always sent**) or undo what one `sessionId` wrote, or what you wrote in a `since` / `until` window of at most 7 days (v0.114.0+). A memory someone else changed since, Sleep merged or you may not write is skipped with a `cause`, never half-reverted. `status: "in_progress"` with `remaining > 0` means call again with the same arguments. |
1695
+
1696
+ **`bootstrap`'s two formats.** `format: "index"` (v0.115.0+) gives pointer
1697
+ rows: pinned keeps its text, but guardrail, upcoming and change rows carry
1698
+ an 80-character `summary` head with `summary_cut`, and there are no
1699
+ `instructions`. `"full"` is the whole shape. Omitted, the server picks
1700
+ `index` below `maxChars` 10,000 and `full` otherwise; `format: "full"`
1701
+ under 10,000 throws locally, and a `maxChars` below 10,000 needs v0.115.0+
1702
+ (an older server refuses it). Over budget a lane keeps the prefix that
1703
+ fits (`truncated`), and a full reply leaves `context_summary` out of the
1704
+ pinned rows first (`context_summary_omitted`). `guardrails` is absent
1705
+ with `?guardrails=off` and `null` when the server's read failed or the
1706
+ block cannot be read; `plan_headroom` (v0.142.0+) lists the plan
1707
+ dimensions at 80 % or more of their limit, on every call — see
1708
+ [Plan headroom](#plan-headroom-memory-cloud-v01420). The session-start
1709
+ skill calls
1710
+ `bootstrap({ contextId, since: "7d", format: "index", maxChars: 5000 })`.
1711
+
1712
+ **`changesSince` kinds.** Without `sessionId` / `byMe` the kinds are
1713
+ `created`, `updated`, `superseded`, `forgotten`; with either (the
1714
+ revision lane) `created`, `updated`, `forgotten`, `restored`. Every
1715
+ event of a memory that is forgotten now has no `summary` (v0.96.0+), and a
1716
+ soft delete logs `forgotten` only. `byMe: true` previews what
1717
+ `rollbackSession({ since })` would undo.
1718
+
1719
+ **`rememberBatch` accounting.** Without `atomic` each item is written and
1720
+ reported on its own; with `atomic: true` the batch is one transaction,
1721
+ and a failing item or a `dedupe: "check"` candidate rolls it back, the
1722
+ other items `skipped`. `results` has one row per item (`success`,
1723
+ `duplicate_candidate`, `skipped` or `error`), and `failed` excludes
1724
+ `skipped` and `candidates` (v0.96.0+). `committed_after_timeout: true`
1725
+ means every item is stored though the call passed its time limit: do not
1726
+ resend. A batch that wrote nothing throws: `KaguraError` with `code`
1727
+ `batch_failed` (every item failed) or `batch_refused` (an atomic batch
1728
+ with an invalid item), the rows in `details.results`, or `timeout` (an
1729
+ atomic batch rolled back, no rows); an atomic batch over the daily quota
1730
+ is `KaguraQuotaError`. Items are checked first: 1-50 objects, no
1731
+ `dedupe` / `tags_normalize` / `verbose` on an item, no other context's
1732
+ `context_id`, `remember`'s tag caps. A batch near a plan limit carries
1733
+ `plan_headroom` (v0.142.0+; see [Plan headroom](#plan-headroom-memory-cloud-v01420)).
1734
+
1735
+ **`forget` by ids.** `forget({ contextId, memoryIds })` (v0.117.0+)
1736
+ forgets each id exactly as `memoryId` would, committed on its own, and
1737
+ returns a `ForgetBatchResult` with one row per id: `deleted`, `skipped`
1738
+ (not found, not yours, or already gone) or `error`; an id the call's time
1739
+ budget did not reach is `error: "not_attempted"` (v0.118.0+) — resend
1740
+ those. `k` is not sent; `memoryIds` with `memoryId`, `query` or `k`, an id
1741
+ that is no UUID or a repeated one throws before any request. Every id
1742
+ failing throws `KaguraError` `batch_failed` with the rows in
1743
+ `details.results`.
1744
+
1745
+ ```ts
1746
+ const session = await client.bootstrap({ contextId, since: "7d", format: "index", maxChars: 5000 });
1747
+ const lane = session.components.changes;
1748
+ if (lane?.has_more) {
1749
+ const next = await client.changesSince({ contextId, since: session.since!, cursor: lane.next_cursor! });
1750
+ }
1751
+ const batch = await client.rememberBatch({
1752
+ contextId,
1753
+ items: [{ summary: "Adopt FastAPI DI", content: "Use Depends()", type: "decision" }],
1754
+ });
1755
+ const plan = await client.rollbackSession({ contextId, sessionId: batch.session_id! }); // dry run
1756
+ ```
1757
+
1758
+ #### Plan headroom (memory-cloud v0.142.0)
1759
+
1760
+ The success reply of `bootstrap`, `rememberBatch`, `remember` and
1761
+ `updateMemory` carries `plan_headroom` when a plan dimension is at 80 %
1762
+ (`level: "warning"`) or 95 % (`"critical"`) of its effective limit
1763
+ (add-on and referral bonuses included): one `PlanHeadroomNotice` per
1764
+ dimension — `memories` (live memories), `memories_per_day` or
1765
+ `mcp_calls_per_day` — with `used`, `limit`, `percentage` (rounded down to
1766
+ one decimal), `plan` (absent when the server could not resolve it),
1767
+ `remedies` (`cleanup` for the total cap or `wait` for a daily one, then
1768
+ `upgrade` when a higher tier raises that cap, or `admin` on a deployment
1769
+ without billing), `help` (what to do and what fails at 100 %) and, on the
1770
+ daily dimensions, `resets_at` (the next UTC midnight). Below 80 % the key
1771
+ is absent. `bootstrap` carries it on every call (no hourly throttle)
1772
+ within a quarter of its `maxChars`: past that, `help` stays on the most
1773
+ severe entry only, and past it still that entry alone stays. A write
1774
+ shows an entry at most once an hour per workspace, dimension and level,
1775
+ so a missing key does not mean the plan has room.
1776
+
1777
+ All four read it fail-open, as the Python SDK's `PlanHeadroom` field
1778
+ does: the notice is advisory, so an entry the model cannot read is
1779
+ dropped (the call still succeeds), and a value that is not a list, or
1780
+ keeps no entry, is left out (where Python's model reads `None`). The
1781
+ entries that read come back as sent; `dimension`, `level` and the
1782
+ `remedies` are plain strings, so a value a newer server adds still
1783
+ reads. The Python SDK's `remember` / `update_memory` return their reply
1784
+ as an unchecked dict, so for a malformed notice only Python keeps what
1785
+ `remember` / `updateMemory` drop here; the CLI's `remember`,
1786
+ `update-memory` and `files upload --remember` print the reply as sent, as
1787
+ the Python CLI does. The CLI's `bootstrap` prints each notice as Python's
1788
+ model dumps it, defaults filled, and `"plan_headroom": null` when none
1789
+ reads.
1790
+
1791
+ ```ts
1792
+ const session = await client.bootstrap({ contextId });
1793
+ for (const notice of session.plan_headroom ?? []) {
1794
+ console.warn(`${notice.dimension}: ${notice.percentage} % (${notice.level}) — ${notice.help ?? ""}`);
1795
+ }
1796
+ ```
1186
1797
 
1187
1798
  ### Deterministic lanes
1188
1799
 
@@ -1191,10 +1802,10 @@ the counterpart to `recall`'s probabilistic search.
1191
1802
 
1192
1803
  | Method | Axis |
1193
1804
  |--------|------|
1194
- | `loadPinned` | The complete, unranked `deliveryMode: "always"` set. Bounded: check `truncated` / `total_available` rather than assuming you got everything. |
1195
- | `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`. |
1805
+ | `loadPinned` | The complete, unranked `deliveryMode: "always"` set. Bounded: check `truncated` / `total_available` rather than assuming you got everything. `maxChars` (10,000–100,000, server default 20,000; v0.82.0+) bounds the reply: `context_summary` goes first (`context_summary_omitted: true`), then items from the end. |
1806
+ | `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`; `context_summary_omitted` (v0.82.0+) says the reply passed its budget and the pinned items lost their `context_summary`. `maxChars` as for `loadPinned` (MCP only; the REST twin takes none). |
1196
1807
  | `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. |
1197
- | `recallNearby` | WHERE — memories near a point, nearest first with `distance_m`. See [the WHERE axis](#the-where-axis--geospatial-memories). |
1808
+ | `recallNearby` | WHERE — memories near a point, nearest first with `distance_m`. Items carry `location`, not `details` (server v0.82.0+); `includeDetails: true` returns the full `details` object instead. See [the WHERE axis](#the-where-axis--geospatial-memories). |
1198
1809
  | `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). |
1199
1810
  | `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. |
1200
1811
 
@@ -1202,10 +1813,10 @@ the counterpart to `recall`'s probabilistic search.
1202
1813
 
1203
1814
  | Method | What it does |
1204
1815
  |--------|--------------|
1205
- | `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 on every server, because the MCP tool has `with_tags` only from server v0.77.0 and an older one ignores it; 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. |
1816
+ | `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 on every server, because the MCP tool has `with_tags` only from server v0.77.0 and an older one ignores it; 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. Over MCP a reply holds at most 200 tags whatever the `limit` (v0.82.0+), with `has_more: true` when more matched; there is no cursor, so narrow with `prefix` or `minCount`. |
1206
1817
  | `explore` | Graph traversal from a seed memory (`depth` 1–5, `minWeight`). |
1207
- | `listEdges` | Edges touching a memory, incoming and outgoing, deduplicated. |
1208
- | `createEdge` / `updateEdge` / `deleteEdge` | Manual edge curation. `(sourceId, targetId)` is the identity; self-loops are rejected. |
1818
+ | `listEdges` | Edges touching a memory, incoming and outgoing, deduplicated, heaviest first. Each direction is cut at `limit` (the server's default is 50 from v0.82.0, its maximum 200), and the tool has no cursor: when the server's default or its clamp cut a direction (`outgoing_has_more` / `incoming_has_more`), the client logs a warning (to `console.warn` unless the client's `warn` option routes it); raise `limit` or `minWeight`, or narrow `edgeTypes`. `minWeight` is always sent, `0.0` unless set, so every edge comes back: the server's own default is 0.05 since v0.117.0, which hides weak automatic edges. |
1819
+ | `createEdge` / `updateEdge` / `deleteEdge` | Manual edge curation. `(sourceId, targetId)` is the identity; self-loops are rejected. No direction check: for a `supersedes` edge the caller owns the direction, source newer and target older (see [Supersede suggestions](#supersede-suggestions)). |
1209
1820
  | `findDuplicates` | Near-duplicate pairs above `threshold` (0.5–1.0, default 0.90). |
1210
1821
  | `feedback` | Record whether a recalled memory was useful — an append-only signal in its own lane, not a memory edit. |
1211
1822
 
@@ -1213,13 +1824,13 @@ the counterpart to `recall`'s probabilistic search.
1213
1824
 
1214
1825
  | Method | What it does |
1215
1826
  |--------|--------------|
1216
- | `listContexts` | The contexts you can see, most recently used first, as a slim name→id directory (`id`, `name`, `is_private`, `is_locked`, `last_used_at`; server v0.73.0+). `nameContains` filters (server v0.73.0+; older servers ignore it and return every context); `includeSummary` (capped at 300 chars), `includeDetails` (full `summary` + `embedding_model`) and `includeStats` (`memory_count`) add fields. `count` is quota usage and `total` the number returned; `can_create` is the quota flag, and `hint` appears when you can see no context. |
1217
- | `createContext` | New context. Throws `KaguraQuotaError` when the workspace limit is reached: the SDK checks `listContexts()` first, so that error carries `quotaType`, `current` and `limit` but no `gate` or plan fields (`requiredPlan` `null` means unknown). Also throws `KaguraFeatureNotAvailableError` for a shared one (`isPrivate: false`) on a plan without shared contexts (server v0.75.0+). `embeddingModel` cannot be changed through the API afterwards (an operator can migrate it server-side, v0.66.0+). `resourceId` is deprecated and no longer sent, since the server ignores it: set it with `updateContext`, or use `setupResource`. |
1218
- | `getContextInfo` | Metadata plus, by default, a memory-count breakdown. On server v0.74.0+ also a trimmed `guardrails` block: absent when the MCP URL carries `?guardrails=off`, `null` when the server's read failed. |
1827
+ | `listContexts` | The contexts you can see, most recently used first, as a slim name→id directory (`id`, `name`, `is_private`, `is_locked`, `last_used_at`; server v0.73.0+). `nameContains` filters (server v0.73.0+; older servers ignore it and return every context); `includeSummary` (capped at 300 chars), `includeDetails` (full `summary` + `embedding_model`) and `includeStats` (`memory_count`) add fields. `count` is quota usage and `total` the number returned; `can_create` is the quota flag, and `hint` appears when you can see no context. From v0.82.0 the directory is paged — 100 contexts a page, 20 with `includeDetails` and no `nameContains` — with `has_more` / `next_cursor`: pass `next_cursor` back as `cursor` for the next page, with the same `nameContains`. `limit` sets the page size, 1-200; more than 20 with `includeDetails` and no non-blank `nameContains` throws before any request, as the server would refuse it. Servers before v0.82.0 ignore `limit` and `cursor` and return every context. `nameContains` is sent trimmed, and not at all when blank. There is no `maxChars`: the page's 20,000-character budget is fixed, and a v0.82.0+ server refuses an argument `list_contexts` does not declare. The envelope's `limit` is the plan's context maximum, not the page size. |
1828
+ | `createContext` | New context. Throws `KaguraQuotaError` when the workspace limit is reached: the SDK checks a one-row `listContexts({ limit: 1 })` page first, so that error carries `quotaType`, `current` and `limit` but no `gate` or plan fields (`requiredPlan` `null` means unknown). Also throws `KaguraFeatureNotAvailableError` for a shared one (`isPrivate: false`) on a plan without shared contexts (server v0.75.0+). `embeddingModel` cannot be changed through the API afterwards (an operator can migrate it server-side, v0.66.0+). `resourceId` is deprecated and no longer sent, since the server ignores it: set it with `updateContext`, or use `setupResource`. |
1829
+ | `getContextInfo` | Metadata plus, by default, a memory-count breakdown. On server v0.74.0+ also a trimmed `guardrails` block: absent when the MCP URL carries `?guardrails=off`, `null` when the server's read failed; its `provenance` (v0.79.0+) labels the items as notes context editors stored, not operator instructions. `search_config` carries `llm_selector_enabled` / `llm_selector_effective` (v0.115.0+). |
1219
1830
  | `updateContext` | Change display name, summary, usage guide, visibility, lock. `isPublic: true` is plan-gated and throws `KaguraFeatureNotAvailableError` on a plan without public contexts. |
1220
1831
  | `deleteContext` | Delete by id. Locked contexts are refused. |
1221
1832
  | `mergeContexts` | Move memories between contexts. Both must share an embedding model and workspace. |
1222
- | `updateSearchConfig` | Hybrid-search weights (must sum to 1.0 ±0.01), reranking (`useRerank`, which a `recall` that omits it follows) and the reranker (`voyage`, `cohere` or `self_hosted`), reinforce re-rank (`reinforceEnabled`, `reinforceMaxBoost`, `reinforceRequireHostArbitration`) and query routing (`routingMode`). Owner/editor only; a context that does not exist, or that the caller cannot see, also throws `KaguraPermissionError`. Returns the whole updated `config`, the only place the reinforce and routing fields come back. |
1833
+ | `updateSearchConfig` | Hybrid-search weights (must sum to 1.0 ±0.01), reranking (`useRerank`, which a `recall` that omits it follows) and the reranker (`voyage`, `cohere` or `self_hosted`), reinforce re-rank (`reinforceEnabled`, `reinforceMaxBoost`, `reinforceRequireHostArbitration`) and query routing (`routingMode`). The weights and reranker settings need context editor or above; a context that does not exist, or that the caller cannot see, also throws `KaguraPermissionError`. Returns the whole updated `config`, the only place the reinforce and routing fields come back; it also carries the content-chunk state (`content_chunks_enabled`, `_effective`, `_supported`, `_can_change`, `_disabled_reason`, `_in_use`, `_limit`, `_backfill_pending`, and `embedding_provider`; v0.110.0–v0.113.0) and the recall LLM selector's (`llm_selector_*`, v0.115.0+). `contentChunksEnabled` (v0.110.0+; on, memory content — not only summaries — goes to the embedding and rerank providers) and `llmSelectorEnabled` (v0.115.0+) turn them on or off; both need the context owner or a workspace owner/admin, and where the deployment gates them by plan, the plan's feature and a free slot (`KaguraFeatureNotAvailableError` / `KaguraQuotaError`). Write back the stored `*_enabled` flag, never `*_effective`. |
1223
1834
  | `setupResource` | Context + resource entity + ingestion token in one transaction. The returned token is plaintext and shown once. The context is named `name`, or `resourceId` when that is omitted. `summary` is deprecated and no longer sent, since the server ignores it: set it afterwards with `updateContext`. Plan-gated: throws `KaguraFeatureNotAvailableError` on a plan without resources. |
1224
1835
 
1225
1836
  ### Agent run-state
@@ -1228,32 +1839,80 @@ Ephemeral, TTL-bounded, and excluded from recall — deliberately not memories.
1228
1839
 
1229
1840
  | Method | What it does |
1230
1841
  |--------|--------------|
1231
- | `setState` / `getState` | Key/value at `(contextId, key)`. Omit `key` on read to list all live keys. |
1842
+ | `setState` / `getState` | Key/value at `(contextId, key)`. A value takes at most 16,384 characters as compact JSON, measured as the server measures it; a longer one throws before any request, on every server. Omit `key` on read to list the live entries: from v0.82.0 a page at a time in key order, with `has_more` / `next_cursor` (pass it back as `cursor`) and `omitted_keys` for values too large for the page. `limit` (1-200, default 50) and `maxChars` (10,000-100,000 characters, default 20,000) size the page, each checked before any request; servers before v0.82.0 ignore all three and return every entry. `cursor`, `limit` or `maxChars` with `key` throws. |
1232
1843
 
1233
1844
  ### Sleep maintenance
1234
1845
 
1235
1846
  | Method | What it does |
1236
1847
  |--------|--------------|
1237
- | `getSleepHistory` | Recent runs, newest first. |
1238
- | `getSleepReport` | One run in detail, including the per-action audit log. |
1239
- | `rollbackSleepRun` | Reverse a completed or degraded run. The server commits per step, so a partial rollback is possible: it throws `KaguraPartialRollbackError` instead of returning, and the steps it did reverse stay reversed. There is no retry: the report is now `failed`, and the server will not roll back a `failed` report again. `err.summary` has the same counts a clean run returns, and the actions in `err.summary.errors` were not reversed and need handling some other way. |
1848
+ | `getSleepHistory` | Recent runs, newest first. Since v0.138.0 the server lists Sleep runs only unless `source` says otherwise (`"analysis"` for the rows Memory Analysis writes for its LLM spend, `"all"` for both), and each row carries `source`; older servers have no filter. |
1849
+ | `getSleepReport` | One run in detail, including the per-action audit log. `contextId` is not sent: the server finds the run by `reportId`. From v0.82.0 the log comes a page at a time (`actionsLimit`, default 50, at most 200; `maxChars` 10,000–100,000): while `actions_has_more` is true, pass `actions_next_cursor` as `actionsCursor`. An action too large for its page has `details_omitted` and `details_total_chars` instead of `details`; an analysis report carries a `note` (v0.140.0+). |
1850
+ | `rollbackSleepRun` | Reverse a completed or degraded run. The server commits per step, so a partial rollback is possible: it throws `KaguraPartialRollbackError` instead of returning, and the steps it did reverse stay reversed. There is no retry: the report is now `failed`, and the server will not roll back a `failed` report again. `err.summary` has the same counts a clean run returns, and the actions in `err.summary.errors` were not reversed and need handling some other way. `chunks_requeued` / `points_requeued` (v0.112.0+) count restored memories queued for the embedding sweep to rebuild — not errors. |
1851
+
1852
+ `getSleepReport` and `rollbackSleepRun`, and `kagura-memory sleep
1853
+ report|rollback`, send `report_id` only. Their `contextId` is ignored and
1854
+ now optional, so calls that pass it keep compiling; the CLI's
1855
+ `CONTEXT_ID` is ignored too and stays a required positional, as in the
1856
+ Python CLI, so scripts keep working. No memory-cloud release declares or
1857
+ reads a `context_id` on `get_sleep_report` or `rollback_sleep_run`, and from
1858
+ v0.82.0 the server refuses an argument a tool does not declare
1859
+ ([memory-cloud#1742](https://github.com/kagura-ai/memory-cloud/issues/1742)),
1860
+ so up to 0.14.1 both methods and both commands failed every call there
1861
+ with `invalid_argument`
1862
+ ([#79](https://github.com/kagura-ai/kagura-memory-typescript-sdk/issues/79)).
1863
+ The server finds the run by `report_id` and, from v0.126.0
1864
+ ([memory-cloud#2315](https://github.com/kagura-ai/memory-cloud/pull/2315)),
1865
+ authorizes against the report's own context: read access for a report,
1866
+ the editor or owner role for a rollback (`KaguraPermissionError` without
1867
+ it; a workspace viewer cannot roll back). A report in a context the
1868
+ caller cannot read throws `KaguraNotFoundError`, like a missing one. From
1869
+ v0.140.0 `rollbackSleepRun` refuses a Memory Analysis report (`source:
1870
+ "analysis"`), which records LLM spend and has no Sleep actions, with
1871
+ `analysis_report`, a plain `KaguraError`
1872
+ ([memory-cloud#2547](https://github.com/kagura-ai/memory-cloud/issues/2547)).
1240
1873
 
1241
1874
  ### Workspace and server
1242
1875
 
1243
1876
  | Method | What it does |
1244
1877
  |--------|--------------|
1245
- | `getServerInfo` | Version, deployment feature flags, and (v0.69.0+) the reranker defaults new contexts start with, under `search_defaults`. |
1878
+ | `getServerInfo` | Version, deployment feature flags, and (v0.69.0+) the reranker defaults new contexts start with, under `search_defaults` (from v0.112.0 also `content_chunks_enabled`, a new context's chunk setting). `content_chunks_require_plan` (v0.113.0+) and `llm_selector_require_plan` (v0.115.0+) say the deployment gates those features by plan. |
1246
1879
  | `checkServerVersion` | Compare against `MIN_SERVER_VERSION` (0.75.0). Advisory: logs, and never throws on an old version; a body that is not a `ServerInfo` throws `KaguraResponseError`, as in `getServerInfo`. 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`, `main-abc123`) is not compared. |
1247
- | `getUsage` | Workspace quota and usage: `used` / `limit` for memories, contexts, members and today's MCP calls. |
1880
+ | `getUsage` | Workspace quota and usage: `used` / `limit` for memories, contexts, members and today's MCP calls. `capacity_lock` is `null` unless the workspace is over its Free capacity (memory-cloud v0.99.0+; absent before): then the same figures `KaguraCapacityLockedError` carries, with `cleanup_url` and `help`. A `capacity_lock` the Python SDK's `CapacityLock` model refuses throws `KaguraResponseError`. |
1248
1881
  | `getMemoryStats` | Per-memory usage stats, sortable and paged. |
1249
- | `getEmbeddingStatus` / `listEmbeddingModels` | Embedding backend state and the models available for `createContext`. |
1250
- | `getToolDefinitions` | Raw MCP `tools/list` output — every tool the server exposes, including any this SDK does not wrap yet. |
1882
+ | `getEmbeddingStatus` / `listEmbeddingModels` | Embedding backend state and the models available for `createContext`. A failed row's `embedding_attempted_at` (v0.95.0+) is when its embedding last failed. |
1883
+ | `getToolDefinitions` | Raw MCP `tools/list` output, including tools this SDK does not wrap yet: the view `mcpUrl`'s query selects, not every tool. A bare URL lists the `core` profile on memory-cloud 0.93.0+ (21 tools on 0.141.0), `?profile=full` all of them (72), `?add_tools=a,b` (v0.129.0+) adds names to the profile, and `?tools=a,b` is an allowlist. `tools/call` never reads the view, so every method of this client works on any URL; only `recall`'s `explore_hints` need `explore` listed. The result is read as the Python SDK's `ToolListResponse`: each definition passes through unread, a result without `tools` lists none, and one that is not an object or whose `tools` is not a list of objects throws `KaguraResponseError` (`operation` `KaguraClient.get_tool_definitions`) rather than reading as an empty list. |
1251
1884
  | `callRawTool` | Call any MCP tool by name — the escape hatch for tools with no typed wrapper. Args pass through verbatim (wire form: `context_id`, not `contextId`) and the result is untyped. Prefer a wrapper where one exists; use this so a missing one is a detour, not a dead end. |
1252
1885
  | `close` | Drop the MCP session. The next call re-initializes automatically. |
1253
1886
 
1887
+ The advisory warnings `checkServerVersion` and `listEdges` log go to
1888
+ `console.warn` unless the client is built with a `warn` option:
1889
+ `new KaguraClient({ warn: (message) => logger.warn(message) })` routes
1890
+ them, and `warn: () => {}` silences them.
1891
+
1254
1892
  Agent Registry and binding methods are covered in
1255
1893
  [Agent control plane](#agent-control-plane-memory-cloud-v0490) below.
1256
1894
 
1895
+ ### Permission model (memory-cloud v0.126.0+)
1896
+
1897
+ The server decides who reaches which context, the same way on every MCP
1898
+ tool and REST route. A workspace owner or admin reaches every shared
1899
+ context. A member or viewer reaches the contexts its
1900
+ `allowed_context_ids` names; with no list, a viewer reaches every shared
1901
+ context and a member none. A context outside the list answers as one
1902
+ that does not exist, `KaguraNotFoundError`; `KaguraPermissionError` is
1903
+ for a context the caller reaches with too low a role. A workspace viewer
1904
+ is read-only, even in a private context it created. Resource tokens are
1905
+ workspace-scoped (v0.94.0): an owner lists and revokes every token of
1906
+ the workspace, whoever minted it, and another workspace's token answers
1907
+ 404 (v0.97.0). `deleteContext` soft-deletes the context's files with it,
1908
+ and `mergeContexts({ deleteSource: true })` moves the source's files to
1909
+ the target (v0.101.0). A `supersedes` edge from `createEdge` /
1910
+ `updateEdge` needs both memories to be the caller's (v0.132.0), else
1911
+ `KaguraPermissionError`. On a memory carrying `details.tool_trigger` an
1912
+ accepted supersede suggestion is a guardrail edit (context editor or
1913
+ above, a user credential), which its `acceptance` reports as
1914
+ `not_writable` (v0.142.0).
1915
+
1257
1916
  ## Agent control plane (memory-cloud v0.49.0+)
1258
1917
 
1259
1918
  `KaguraClient` wraps the RFC-0002 agent platform: the **Agent Registry**
@@ -1264,6 +1923,11 @@ the session-start `getAgentBootstrap` call. Registry and binding methods are
1264
1923
  **owner/admin-gated** server-side; `deleteAgent` is permanent and
1265
1924
  cascades every API key bound to the agent (prefer
1266
1925
  `updateAgent({ status: "retired" })` for operational retirement).
1926
+ `listAgents` follows the server's cursor (memory-cloud v0.82.0+, 50
1927
+ agents a page) and returns every agent, at most 50 pages; each row's
1928
+ `description` is a 200-character preview there, with
1929
+ `description_truncated` set when it was cut (`getAgent` returns it
1930
+ whole).
1267
1931
 
1268
1932
  ```ts
1269
1933
  // One-time provisioning (owner/admin): register the agent, bind its context
@@ -1275,7 +1939,10 @@ const bootstrap = await client.getAgentBootstrap({
1275
1939
  agentId: agent.id, // contextId omitted → default binding
1276
1940
  sessionId: "run-42", // echoed in the correlation block
1277
1941
  query: "session summary", // enables the trusted-only recall component
1942
+ maxChars: 40_000, // whole-envelope budget (server v0.82.0+; default 20,000)
1278
1943
  });
1944
+ // Server v0.82.0+ loads 20 pinned memories by default here (pinnedCap raises it);
1945
+ // bootstrap.context_summary_omitted / a component's truncated say what the budget took.
1279
1946
  if (bootstrap.degraded) {
1280
1947
  // some component failed fail-soft; inspect bootstrap.components
1281
1948
  }
@@ -1306,7 +1973,7 @@ an API key, an agent-bound key included, with no MCP session:
1306
1973
 
1307
1974
  | Method | What it does |
1308
1975
  |--------|--------------|
1309
- | `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. |
1976
+ | `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` / `addTools` repeat the MCP URL's `?profile=` / `?tools=` / `?add_tools=` (`addTools`, memory-cloud v0.129.0+, is validated and joined as the server reads the names, sent only when it names a tool, and refused before any request for more than 100 names or one starting with `-`). `tool_triggered_version` is the response header, `null` when absent. The text is returned as is. |
1310
1977
  | `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. |
1311
1978
 
1312
1979
  Both refuse a `contextId` that is not a UUID before any request, in the
@@ -1353,6 +2020,12 @@ into `details`, so `"35.68"` is rejected server-side with HTTP 422.
1353
2020
  `recallNearby()` returns a typed `RecallNearbyResponse`
1354
2021
  (`results[].distance_m`); `MemoryLocation` and `NearbyMemory` are exported
1355
2022
  too. Out-of-range coordinates throw locally rather than round-tripping.
2023
+ Since server v0.82.0 each item carries `location` (its
2024
+ `details.location`) instead of the whole `details`; `includeDetails: true`
2025
+ returns `details` again, held to a reply budget of about 20,000
2026
+ characters: from the last item backwards, one that does not fit carries
2027
+ `details_omitted: true` and `details_total_chars` instead (read it with
2028
+ `reference()`). Older servers always send `details`.
1356
2029
 
1357
2030
  `listMemories()` filters by a bounding box instead (server v0.54.0+):
1358
2031
  `latMin`, `latMax`, `lonMin` and `lonMax`, in any combination, keep only
@@ -1367,7 +2040,9 @@ const pacific = await client.listMemories({ contextId, lonMin: 170, lonMax: -170
1367
2040
 
1368
2041
  > **Gotcha:** `updateMemory()` replaces `details` **wholesale** — the
1369
2042
  > server does not deep-merge. Round-trip `location` when updating details
1370
- > or the memory silently drops off the spatial axis.
2043
+ > or the memory silently drops off the spatial axis — or change only the
2044
+ > keys you name with `detailsPatch` (memory-cloud v0.140.0+), which keeps
2045
+ > `location`.
1371
2046
 
1372
2047
  ## The HOW-MUCH axis — measurement series
1373
2048
 
@@ -1516,14 +2191,13 @@ including the whole REST surface, `fingerprint()`, and the armor codec. Call
1516
2191
  one of those without the package and you get a `KaguraCryptoError` naming
1517
2192
  the install command, not a module-resolution stack trace.
1518
2193
 
1519
- > **On Node 18.** This SDK supports Node 18 and CI exercises the crypto
1520
- > round-trip there on every push. But `age-encryption`'s `@noble/*`
1521
- > dependencies declare `engines.node: ">= 20.19.0"`, so `npm install
1522
- > age-encryption` on Node 18 prints `EBADENGINE` warnings, and an
1523
- > `engine-strict=true` npmrc will refuse the install outright. It works —
1524
- > WebCrypto is not a global before Node 19, so the SDK installs
1525
- > `node:crypto`'s `webcrypto` itself — but if you want the warnings gone,
1526
- > use Node 20.19+.
2194
+ > **Node version.** `age-encryption`'s `@noble/*` dependencies declare
2195
+ > `engines.node: ">= 20.19.0"`, the same floor as this SDK, so the install
2196
+ > is clean on every supported Node, `engine-strict=true` included.
2197
+ > Encryption and keygen take their randomness from the `globalThis.crypto`
2198
+ > WebCrypto global, which Node has provided since 19; the SDK no longer
2199
+ > installs `node:crypto`'s `webcrypto` there itself, as 0.14.x did for
2200
+ > Node 18.
1527
2201
 
1528
2202
  Recipients are X25519-only. `age1pq1…` (post-quantum) and plugin
1529
2203
  recipients are rejected even though `age-encryption` would accept them,
@@ -1557,12 +2231,24 @@ Python uses, so a shared backend interoperates.
1557
2231
 
1558
2232
  This package ports the Python SDK's core (client, auth, REST clients,
1559
2233
  models, the zero-knowledge secret client) and, since 0.8.0, its `kagura`
1560
- CLI as `kagura-memory`: 20 of the 21 top-level commands, counting the
1561
- `contexts` alias. Only `kagura ingest` is not ported (below);
1562
- [Command line](#command-line) lists where the two CLIs still differ.
1563
-
1564
- The parity target is the Python SDK and CLI **0.42.0**, checked against
1565
- memory-cloud up to **v0.77.0**.
2234
+ CLI as `kagura-memory`: 23 of the 24 top-level commands of the Python CLI
2235
+ 0.44.0, counting the `contexts` alias. Only `kagura ingest` is not ported
2236
+ (below); [Command line](#command-line) lists where the two CLIs still
2237
+ differ.
2238
+
2239
+ The parity target is the Python SDK and CLI **0.44.0**, checked against
2240
+ memory-cloud up to **v0.143.0**.
2241
+
2242
+ **SDK ↔ memory-cloud compatibility.**
2243
+ [`docs/compatibility.md`](docs/compatibility.md) records, for each release
2244
+ of this package, the memory-cloud release it needs and the newest one it
2245
+ was checked against, with the floor of every method, option and flag
2246
+ newer than `MIN_SERVER_VERSION` (0.75.0, advisory). A newer option sent to
2247
+ an older server is ignored there before v0.82.0 and refused with
2248
+ `invalid_argument` from v0.82.0, so the floor is where to look when an
2249
+ option seems to do nothing or is refused. The Python SDK keeps the same
2250
+ record in its own
2251
+ [`docs/compatibility.md`](https://github.com/kagura-ai/kagura-memory-python-sdk/blob/main/docs/compatibility.md).
1566
2252
 
1567
2253
  One thing is deliberately not ported, because it would cost the
1568
2254
  zero-dependency promise:
@@ -1592,8 +2278,10 @@ an int field takes `"0-1"` (-1) and `"0__7"` and refuses a digit run past
1592
2278
  than Python's `float()`, and a string holding a lone surrogate is refused
1593
2279
  in any field but a `str`. Three limits of JavaScript numbers remain. An
1594
2280
  int field of a typed result (`recallSeries`' `count`, the guardrail caps,
1595
- a member key's or invitation's `id`) holds a `number`, so a value past
1596
- 2^53 is the nearest double and one of 2^1024 or more (309 digits) is
2281
+ a member key's or invitation's `id` when it is an integer — memory-cloud
2282
+ v0.89.0+ sends an `akey_…` / `winv_…` string, which stays the string, as
2283
+ does a numeric string such as `"7"`) holds a `number`, so a value
2284
+ past 2^53 is the nearest double and one of 2^1024 or more (309 digits) is
1597
2285
  `Infinity`, where Python keeps the exact int; widening those types would
1598
2286
  break callers. The other two hold only where a body is read with
1599
2287
  `JSON.parse`, which cannot tell `1e20` from `100000000000000000000` or
@@ -1657,15 +2345,12 @@ the header is `Bearer None` in both.
1657
2345
 
1658
2346
  ```bash
1659
2347
  npm install
1660
- npm test # vitest
1661
- npm run test:no-webcrypto # the same suite with globalThis.crypto deleted
1662
- npm run typecheck # tsc --noEmit
1663
- npm run build # tsup → dist/ (ESM + CJS + d.ts)
2348
+ npm test # vitest
2349
+ npm run typecheck # tsc --noEmit
2350
+ npm run build # tsup → dist/ (ESM + CJS + d.ts)
1664
2351
  ```
1665
2352
 
1666
- `test:no-webcrypto` reproduces Node 18, which has no WebCrypto global —
1667
- the crypto path installs `node:crypto`'s `webcrypto` itself, and that used
1668
- to break in CI only. `prepublishOnly` runs all four.
2353
+ `prepublishOnly` runs all three.
1669
2354
 
1670
2355
  ## License
1671
2356