kagura-memory 0.9.0 → 0.10.1
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 +170 -8
- package/dist/cli.js +1707 -317
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +217 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +129 -12
- package/dist/index.d.ts +129 -12
- package/dist/index.js +216 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,12 +108,14 @@ npx kagura-memory --help
|
|
|
108
108
|
| `files` | `upload` `list` `delete` `download-url` |
|
|
109
109
|
| `resource` | `tokens {list,create,update,revoke}` `list` `setup` `schema` `stats` `indexer-status` `events` `ingest` `ingest-batch` `import` |
|
|
110
110
|
| `secret` | `keygen` `list` `put` `get` `grant` `revoke` `rotate` `delete` `pubkeys` `approve` `audit-verify` `exec` |
|
|
111
|
-
|
|
|
111
|
+
| `setup` | `claude` `codex` `hermes` `openclaw` |
|
|
112
|
+
| other | `config show` `doctor` |
|
|
112
113
|
|
|
113
114
|
```bash
|
|
114
115
|
npx kagura-memory auth login --profile work --read-only
|
|
115
116
|
npx kagura-memory recall "OAuth setup" -c dev -k 10
|
|
116
117
|
npx kagura-memory remember -s "FastAPI DI" --content "Use Depends()" --tags "python,fastapi"
|
|
118
|
+
npx kagura-memory setup codex --dry-run # key from .kagura.json or KAGURA_API_KEY
|
|
117
119
|
npx kagura-memory doctor
|
|
118
120
|
```
|
|
119
121
|
|
|
@@ -122,6 +124,72 @@ The context id comes from `-c/--context-id`, or from `context_id` in
|
|
|
122
124
|
shared with the Python CLI, so either tool can create a profile the other
|
|
123
125
|
then uses.
|
|
124
126
|
|
|
127
|
+
**Connecting a harness.** Each `setup` subcommand writes `.kagura.json`
|
|
128
|
+
(0600, gitignored) and an MCP entry named `kagura-memory`: the URL plus a
|
|
129
|
+
Bearer header. The key comes from `--api-key`, else the `api_key` in
|
|
130
|
+
`.kagura.json`, else `KAGURA_API_KEY`. `.kagura.json` gets the URL as
|
|
131
|
+
given; the parameters that `--guardrails` and `--tool-profile` set go on
|
|
132
|
+
the entry's URL only. The key is never printed, and outside
|
|
133
|
+
Claude Code it never goes into the harness's config file. `setup codex`
|
|
134
|
+
also leaves a key it found in `KAGURA_API_KEY` out of `.kagura.json`.
|
|
135
|
+
|
|
136
|
+
| Subcommand | How the entry is applied | Where the key lives |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `setup claude` | `.mcp.json` (`--scope project`, the default), or `claude mcp add-json --scope user …` | in the entry |
|
|
139
|
+
| `setup codex` | `codex mcp add … --bearer-token-env-var KAGURA_API_KEY` | `KAGURA_API_KEY`, exported in the shell that starts Codex |
|
|
140
|
+
| `setup hermes` | the `config.yaml` block is printed; `hermes mcp add` always prompts | `$HERMES_HOME/.env`, as `MCP_KAGURA_MEMORY_API_KEY` (`MCP_<NAME>_API_KEY` with `--name`) |
|
|
141
|
+
| `setup openclaw` | `openclaw mcp add … --transport streamable-http --no-probe` | `$OPENCLAW_STATE_DIR/.env` (default `~/.openclaw/.env`), as `KAGURA_API_KEY` |
|
|
142
|
+
|
|
143
|
+
This package has no TOML, YAML or JSON5 parser, so it never rewrites those
|
|
144
|
+
files. When the harness's CLI is not on `PATH`, the block is printed on
|
|
145
|
+
stderr with the file it belongs in (`$CODEX_HOME/config.toml`,
|
|
146
|
+
`$HERMES_HOME/config.yaml`, or `$OPENCLAW_CONFIG_PATH`, by default
|
|
147
|
+
`openclaw.json` in the OpenClaw state directory), and stdout stays one
|
|
148
|
+
JSON document. When Hermes's `config.yaml` already has an `mcp_servers:`
|
|
149
|
+
key, only the `kagura-memory` entry is printed, to go under it: a second
|
|
150
|
+
top-level `mcp_servers:` would replace the first, and every server in it.
|
|
151
|
+
On Windows, a CLI installed only as an npm `.cmd` shim counts as not
|
|
152
|
+
found: Node runs one only through a shell, which would re-parse the
|
|
153
|
+
arguments.
|
|
154
|
+
|
|
155
|
+
`--guardrails <context-id|off>` sets the URL's `guardrails` parameter on
|
|
156
|
+
`setup claude` and `setup codex`. Hermes and OpenClaw do not pass the
|
|
157
|
+
server's instructions to the model, so there `off` is refused and a
|
|
158
|
+
context id is dropped, whether it comes from the flag or from the URL.
|
|
159
|
+
`--tool-profile` (claude, codex) sets `profile` and refuses an empty name;
|
|
160
|
+
the server applies a `?tools=` allowlist already on the URL instead, so
|
|
161
|
+
that case gets a warning. Both go at the end of the query, `guardrails`
|
|
162
|
+
first, replacing any value already there, as the Python CLI writes them.
|
|
163
|
+
A `setup claude` run that leaves out a `guardrails` or `profile` value
|
|
164
|
+
the entry it replaces had says so in a note. `--name`, `--force` and
|
|
165
|
+
`--dry-run` (codex, hermes, openclaw) name the entry, replace an existing
|
|
166
|
+
one, and show what would be configured without changing anything. A name
|
|
167
|
+
starts with a letter or digit: it is a bare argument to `codex` and
|
|
168
|
+
`openclaw`, which would read `--help` as an option.
|
|
169
|
+
|
|
170
|
+
Claude Code uses the `kagura-memory` entry from the strongest scope
|
|
171
|
+
(local > project > user). It keys local scope by the git repository root
|
|
172
|
+
(a linked worktree's main working tree), and takes project scope from the
|
|
173
|
+
closest `.mcp.json` that defines the entry, in the directory it runs in or
|
|
174
|
+
any parent; `setup claude` and `doctor` read them the same way.
|
|
175
|
+
`setup claude` writes nothing when a stronger scope already defines one,
|
|
176
|
+
and prints the `claude mcp remove --scope …` command for it, after a `cd`
|
|
177
|
+
into the directory that command must run in when that is not the current
|
|
178
|
+
one. An entry the new one hides, in a weaker scope or in a parent's
|
|
179
|
+
`.mcp.json`, is noted.
|
|
180
|
+
With `--scope user`, an identical user-scope entry is left as it is and a
|
|
181
|
+
different one is replaced: `claude mcp remove` runs before `claude mcp
|
|
182
|
+
add-json`, and if the add then fails, the old entry is put back (if that
|
|
183
|
+
fails too, the error prints the command to add the new one by hand).
|
|
184
|
+
Without `claude` on `PATH`, `--scope user` prints the commands to run and
|
|
185
|
+
writes nothing, unless the user-scope entry is already identical. When
|
|
186
|
+
`claude plugin list --json` shows the Kagura Memory plugin enabled, the
|
|
187
|
+
notes list the plugin settings to enter. `doctor` reports the entry
|
|
188
|
+
Claude Code uses in the current directory, with its scope and file, and
|
|
189
|
+
warns about each entry that one hides. For a `type: "url"` entry, which
|
|
190
|
+
earlier releases wrote and Claude Code skips, it names the fix for the
|
|
191
|
+
entry's scope.
|
|
192
|
+
|
|
125
193
|
**Not ported.** `kagura ingest` needs the text-extraction pipeline (PDF,
|
|
126
194
|
Office, EPUB, audio) and `kagura process` needs the litellm-backed agent;
|
|
127
195
|
neither exists in this package and both would cost the zero-dependency
|
|
@@ -136,10 +204,10 @@ promise. Use the Python CLI for those.
|
|
|
136
204
|
from `KAGURA_AGE_IDENTITY` or `KAGURA_AGE_IDENTITY_FILE` and fails
|
|
137
205
|
closed when neither is set. **A key custodied by the Python CLI is not
|
|
138
206
|
readable here, and vice versa.**
|
|
139
|
-
- `setup
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
would fail at launch. The `--api-key` path works here.
|
|
207
|
+
- `setup … --profile` (the OAuth path) writes an entry that launches
|
|
208
|
+
Python's `kagura-mcp` stdio proxy, which this package does not install;
|
|
209
|
+
every `setup` subcommand reports the fact instead of writing a config
|
|
210
|
+
that would fail at launch. The `--api-key` path works here.
|
|
143
211
|
- `config show` does not reproduce Python's key mask
|
|
144
212
|
(`key[:8] + "..." + key[-4:]`), whose halves overlap below 12 characters
|
|
145
213
|
and print the whole secret twice.
|
|
@@ -150,6 +218,71 @@ An empty profile name would create a nameless profile and an empty scope
|
|
|
150
218
|
would go to the server verbatim. Every other option treats `--flag=` as
|
|
151
219
|
Python does.
|
|
152
220
|
|
|
221
|
+
**Sign-in rate limit.** memory-cloud v0.76.0 and later limit device sign-in
|
|
222
|
+
requests per client address. When the server refuses one with HTTP 429,
|
|
223
|
+
`auth login` says so and how many seconds to wait (from the `Retry-After`
|
|
224
|
+
header, 60 when it is missing or not a number of seconds), with the
|
|
225
|
+
server's reason, when it gives one, on the next line.
|
|
226
|
+
`login()` and `authorizeDevice` throw the same message as a
|
|
227
|
+
`KaguraAuthError`.
|
|
228
|
+
|
|
229
|
+
#### Signing up with an invite
|
|
230
|
+
|
|
231
|
+
On a deployment that admits new accounts only by beta invite, pass the
|
|
232
|
+
invite to `auth login`, either as the bare token or as the
|
|
233
|
+
`https://…/join/<token>` link it arrived in:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
npx kagura-memory auth login --invite <link-or-token>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Without it, a new user who starts from `auth login` is refused at sign-up:
|
|
240
|
+
the approval page sends a signed-out visitor to the login page, which does
|
|
241
|
+
not carry an invite. With it, once the device code is issued, the CLI asks
|
|
242
|
+
the server how to present the invite (`GET /api/v1/system/info`, which
|
|
243
|
+
takes no credentials, allowed 5 seconds):
|
|
244
|
+
|
|
245
|
+
- **The server supports the hand-off** (memory-cloud 0.76.0 or later,
|
|
246
|
+
`v0.76.0` and build suffixes included): one link,
|
|
247
|
+
`<frontend>/join/<token>?return_to=%2Fdevice%3Fuser_code%3D<code>`, that
|
|
248
|
+
signs up with the invite and lands on the approval page with the code
|
|
249
|
+
filled in. The browser opens that link. Below it, "If you land on the
|
|
250
|
+
dashboard instead, approve here:" and the approval URL cover a user who
|
|
251
|
+
is already signed in.
|
|
252
|
+
- **An older or unrecognised version, or the check failed**: two steps, in
|
|
253
|
+
order. The plain `/join/<token>` link, which the browser opens, then the
|
|
254
|
+
approval URL, and how long the code stays valid.
|
|
255
|
+
- **The server does not take invites** (a `features` object without
|
|
256
|
+
`beta_invites: true`): a one-line note, then the ordinary prompt. A body
|
|
257
|
+
with no `features` object says nothing about invites, so the version
|
|
258
|
+
decides.
|
|
259
|
+
|
|
260
|
+
`<frontend>` is the device response's approval URL with its final
|
|
261
|
+
`/device` removed, so a frontend under a base path gets its `/join` beside
|
|
262
|
+
its `/device`. When that URL does not end in `/device`, the CLI does not
|
|
263
|
+
guess where `/join` lives: it takes the two steps, with your own link as
|
|
264
|
+
step 1, or tells you to open the invite you were sent when you gave a bare
|
|
265
|
+
token. It takes the two steps too when memory-cloud's `/join` would drop
|
|
266
|
+
the `return_to` (a path starting with `//`, as a frontend URL configured
|
|
267
|
+
with a trailing slash produces, or one holding a backslash or a control
|
|
268
|
+
character), which would otherwise leave the new user on the dashboard.
|
|
269
|
+
|
|
270
|
+
The invite is checked before any request. A malformed one exits 2 with
|
|
271
|
+
`Error: Invalid value for '--invite': <reason>`, the Python CLI's reason,
|
|
272
|
+
which never quotes the value. A pasted link must be written out in full,
|
|
273
|
+
`https://<host>/…/join/<token>` (a browser would repair `https:/host/…`;
|
|
274
|
+
the CLI does not), and must be HTTPS, as `--server` must (plain HTTP only
|
|
275
|
+
on localhost). A `/join` link is never built on a plain-HTTP frontend: the
|
|
276
|
+
token would travel in the clear. A link for a different server than the one
|
|
277
|
+
being logged into aborts before the server is asked about invites and
|
|
278
|
+
before the device code is polled, so no profile is written; the error
|
|
279
|
+
suggests logging in with `--server` instead. The token is never saved, in
|
|
280
|
+
`credentials.json` or anywhere else, and never appears in an error message:
|
|
281
|
+
it is printed only inside a link. Every other `auth` subcommand rejects
|
|
282
|
+
`--invite` with exit 2 rather than ignoring it. `--no-browser` works as it
|
|
283
|
+
does without an invite, and when the browser cannot be opened the CLI says
|
|
284
|
+
which link above to open by hand.
|
|
285
|
+
|
|
153
286
|
#### Logging in from TypeScript
|
|
154
287
|
|
|
155
288
|
`login()` runs the OAuth 2.0 Device Authorization Grant (RFC 8628) and
|
|
@@ -202,6 +335,34 @@ primitives are exported too: `authorizeDevice`, `pollForToken`,
|
|
|
202
335
|
(`loadCredentialsFile`, `updateProfile`, `setDefaultProfile`,
|
|
203
336
|
`deleteProfile`, …).
|
|
204
337
|
|
|
338
|
+
For a new user holding a beta invite, `buildInviteLink` builds the same
|
|
339
|
+
sign-up-and-approve link the CLI's `--invite` prints. It takes the Python
|
|
340
|
+
SDK's `build_invite_link` arguments in the same order: the two approval
|
|
341
|
+
URLs from the device response, then the invite token. `onUserCode` is the
|
|
342
|
+
first point where both are known, so call it there. It is a pure function
|
|
343
|
+
and does not check the server version; that check is the CLI's own.
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
import { buildInviteLink, login } from "kagura-memory";
|
|
347
|
+
|
|
348
|
+
const token = "<token>"; // the last path segment of https://…/join/<token>
|
|
349
|
+
|
|
350
|
+
await login({
|
|
351
|
+
onUserCode: ({ verificationUri, verificationUriComplete }) => {
|
|
352
|
+
// null when /join cannot be placed: the approval URL does not end in
|
|
353
|
+
// /device, is plain HTTP off localhost, or is not a return_to that
|
|
354
|
+
// memory-cloud's /join keeps.
|
|
355
|
+
const link = buildInviteLink(verificationUri, verificationUriComplete, token);
|
|
356
|
+
if (link !== null) console.log(`Sign up and approve: ${link}`);
|
|
357
|
+
// A signed-in user, or a server older than memory-cloud 0.76.0, ends
|
|
358
|
+
// up on the dashboard instead; the pending code is approved here.
|
|
359
|
+
console.log(`Or approve at: ${verificationUriComplete}`);
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
A malformed token throws `KaguraAuthError`, whose message never quotes it.
|
|
365
|
+
|
|
205
366
|
#### Refreshing
|
|
206
367
|
|
|
207
368
|
Clients auto-refresh as tokens near expiry, so most code never calls this.
|
|
@@ -299,6 +460,7 @@ per-minute limit. `SecretClient` renders a 429 as `KaguraConnectionError`.
|
|
|
299
460
|
import { KaguraFeatureNotAvailableError, KaguraQuotaError } from "kagura-memory";
|
|
300
461
|
|
|
301
462
|
try {
|
|
463
|
+
// The context is named after the resource unless you pass `name`.
|
|
302
464
|
await client.setupResource({ resourceId: "crm" });
|
|
303
465
|
} catch (e) {
|
|
304
466
|
if (e instanceof KaguraFeatureNotAvailableError) {
|
|
@@ -348,7 +510,7 @@ the counterpart to `recall`'s probabilistic search.
|
|
|
348
510
|
|
|
349
511
|
| Method | What it does |
|
|
350
512
|
|--------|--------------|
|
|
351
|
-
| `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. |
|
|
513
|
+
| `listTags` | Tag vocabulary with counts and recency. `prefix` narrows by spelling; `withTags` is a multi-tag AND drill-down that also excludes those tags from the result — the two compose into server-side faceted browsing with no local index. A drill-down calls the REST tags endpoint, because the MCP tool ignores `withTags` (through server v0.76.0); the result has the same shape. Its values are trimmed and blank ones dropped, and at most 50 of up to 200 characters each are accepted. |
|
|
352
514
|
| `explore` | Graph traversal from a seed memory (`depth` 1–5, `minWeight`). |
|
|
353
515
|
| `listEdges` | Edges touching a memory, incoming and outgoing, deduplicated. |
|
|
354
516
|
| `createEdge` / `updateEdge` / `deleteEdge` | Manual edge curation. `(sourceId, targetId)` is the identity; self-loops are rejected. |
|
|
@@ -360,13 +522,13 @@ the counterpart to `recall`'s probabilistic search.
|
|
|
360
522
|
| Method | What it does |
|
|
361
523
|
|--------|--------------|
|
|
362
524
|
| `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. |
|
|
363
|
-
| `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+). |
|
|
525
|
+
| `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`. |
|
|
364
526
|
| `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. |
|
|
365
527
|
| `updateContext` | Change display name, summary, usage guide, visibility, lock. `isPublic: true` is plan-gated and throws `KaguraFeatureNotAvailableError` on a plan without public contexts. |
|
|
366
528
|
| `deleteContext` | Delete by id. Locked contexts are refused. |
|
|
367
529
|
| `mergeContexts` | Move memories between contexts. Both must share an embedding model and workspace. |
|
|
368
530
|
| `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. |
|
|
369
|
-
| `setupResource` | Context + resource entity + ingestion token in one transaction. The returned token is plaintext and shown once. Plan-gated: throws `KaguraFeatureNotAvailableError` on a plan without resources. |
|
|
531
|
+
| `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. |
|
|
370
532
|
|
|
371
533
|
### Agent run-state
|
|
372
534
|
|