Metadata-Version: 2.5
Name: cortexdb-cli
Version: 0.8.0
Summary: Command-line interface for CortexDB — the long-term memory layer for AI.
Project-URL: Homepage, https://cortexdb.ai
Project-URL: Documentation, https://cortexdb.ai/docs
Project-URL: Repository, https://github.com/cortexdb/cortexdb
Project-URL: Issues, https://github.com/cortexdb/cortexdb/issues
Author-email: CortexDB Team <team@cortexdb.ai>
License-Expression: Apache-2.0
Keywords: agents,ai,cli,cortexdb,llm,memory
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: click>=8.1
Requires-Dist: httpx>=0.27
Requires-Dist: prompt-toolkit>=3.0
Requires-Dist: rich-click>=1.7
Requires-Dist: rich>=13.0
Requires-Dist: tomli-w>=1.0
Requires-Dist: tomli>=2.0; python_version < '3.11'
Description-Content-Type: text/markdown

# cortexdb-cli

Command-line interface for [CortexDB](https://cortexdb.ai) — the long-term memory layer for AI systems.

Wraps the v1 HTTP API in a small, fast Click + Rich CLI. Anonymous signup
in one command, no email or card; works against the public SaaS or any
self-hosted CortexDB deployment. Version 0.8.0 covers CortexDB 0.15.0,
governed memory formation included: derivation policies, corrections, review
and re-derivation; and CortexDB 0.14.x, shared memory included: the access
API, change sets, the directory, applications, rollups, publishing and the
new erasures.

## Install

```bash
pip install cortexdb-cli
```

Requires Python 3.10+.

## Quickstart

```bash
# 1. One-time setup — anonymous signup, writes ~/.cortexdb/state.json
cortexdb init

# 2. Store a memory
cortexdb experience "Q3 revenue: $2.4M. We're on track for $10M ARR by year-end."

# 3. Recall it
cortexdb recall "Q3 revenue?"

# 4. Or just type — drops into a REPL
cortexdb
```

The signup token has a 7-day TTL on the free tier.

**Re-running `cortexdb init` does not refresh it.** `init` reuses an existing
identity and changes nothing; against an expired one it refuses and exits 3.
That is deliberate: a new identity is a new *brain*, and memories written
under the old actor stay where they are, unreachable from the new config.

When a token expires you have two safe options:

- `cortexdb init --api-key <token> --actor <actor>` — keep the same brain
  with a token you already hold (e.g. from your IdP).
- `cortexdb init --force` — deliberately start a NEW brain. The previous
  identity is backed up to `state.json.replaced` first.

For a second brain alongside the first, isolate instead of replacing:
`cortexdb --config-dir <dir> init`, or set `CORTEXDB_HOME`.

## What's new for CortexDB 0.15.0 (cortexdb-cli 0.8.0)

CortexDB 0.15.0 adds governed memory formation: control over what its
background enrichment learns, and corrections that stay corrected. Each
command below needs a server that serves its capability: a server before
0.15.0 answers it 404, which reads like a missing record, and the hint says
the server predates the command.

- **`cortexdb derivation`**: `status` and `decisions` (what was learned from
  an event, and why not), `policy`, `templates`, `taxonomy`, `test` (a draft
  tried on real events, writing nothing), `stage` (stage, preview and
  activate a policy), `settings`, `texts`, `feed` and `consumers`, and the
  re-derivation jobs: `rederive` (a dry run unless `--apply`, of the unsynced
  rows unless `--events`), `job`, `cancel` and `report`.
- **`cortexdb corrections`** (`add`, `list`, `show`, `undo`) and **`cortexdb
  memory about`** (`--corrections`): fix a wrong memory so it stays fixed,
  rather than forget it.
- **`cortexdb review`** (`list`, `approve`, `reject`): decide what a
  derivation policy held back.
- **`cortexdb episodes declare`** and **`episodes delete`**: a worker's own
  episodes.
- **New options**: `--derived-by NAME@VERSION` on `experience write`, `beliefs
  create` and `episodes declare`; `--include derivation` on `facts list`,
  `facts timeline`, `beliefs list` and `beliefs why`; `--session ID` on
  `recall`, `search`, `answer` and `compose`.
- **Warnings**: a write that names a directive nothing reads prints
  "accepted, not enforced: NAME", and a change set that keeps a scope's
  `enrich` says so.

## What's new for CortexDB 0.14.1 (cortexdb-cli 0.7.1)

- **Change sets that take long.** A staging, a preview or an activation whose
  evaluation runs past the server's wait answers 202 and goes on. `changes
  stage`, `parts`, `preview` and `activate` send the request again until it
  answers, with a progress line, for `--wait` seconds (120 by default); past
  it they exit 75 and say how to collect the answer. A 202 is never an error.
- **The tenant-binding dry run** shows how the operator plane will decide the
  real run, and says when `--apply` needs `--break-glass`.
- **A write that would make a version-2 record version 1** is refused; the
  hint names the fields it drops and `--convert`.
- **Token lifetimes** are the server's settings: by default 90 days for a
  person, 7 for an agent, 30 for a service, 24 hours with a chain claim.

## What's new for CortexDB 0.14.0 (cortexdb-cli 0.7.0)

CortexDB 0.14.0 is the breaking release of shared memory. What changes for a
CLI user:

- **Break-glass.** On `cloud_shared_saas` the operator key's data reads are
  denied by default (`CORTEX_OPERATOR_DATA_READS=deny`): they answer 403
  `BREAK_GLASS_REQUIRED` without `X-Cortex-Break-Glass`. Every command that
  calls the server takes `--break-glass REASON --break-glass-ticket TICKET
  [--break-glass-note TEXT]` (`--ticket` for short; also before the
  subcommand, or as `CORTEXDB_BREAK_GLASS`, `CORTEXDB_BREAK_GLASS_TICKET`,
  `CORTEXDB_BREAK_GLASS_NOTE`). The reason is one of `incident`, `legal`,
  `support`, `security`, `migration`, `restore` or `other`.
- **Typed errors.** Every refusal prints its code, its `details`, a one-line
  hint and whether it is retriable; `--json` prints `{"error": {...}}` on
  stderr. `BREAK_GLASS_REQUIRED`, a confinement denial, `ACCESS_RESTORE_PENDING`,
  `NOTICE_UNAVAILABLE`, the `CHANGESET_*` codes, `ACCESS_LIMIT_REACHED`,
  `SUBJECT_UNMAPPED`, `PUBLISH_PERSON_REQUIRED`, `FRESH_AUTH_REQUIRED`,
  `CONSISTENCY_TOKEN_INVALID`, `WAIT_TIMEOUT`, `SCOPE_MOVING` and
  `FORMAT_UPGRADE_PENDING` each say what to do.
- **Strict forget selectors.** The server refuses a selector field it does not
  know (422 `unknown_selector_field`). The REPL's `/forget QUERY` sent one: it
  now lists the events a recall of QUERY returns and forgets the ones you
  pick, by id. `cortexdb forget --query` does the same (a script passes
  `--yes` or `--preview`). `--cascade none` is gone: the cascades are
  `derived_only` and `redact_events`.
- **Views at org-tree scopes.** `recall`, `answer` and `compose` send a view
  only when you choose one, so a read at a team, an org, a group or a
  compartment gets the server's default (granular there) instead of 422
  `VIEW_NOT_ALLOWED_AT_SCOPE`.
- **Tokens.** A token that carries `scopes` holds only the families its
  entries name, lifetimes are capped (the server's settings since 0.14.1: by
  default 90 days for a person, 7 for an agent, 30 for a service, 24 hours
  with chain claims), and `act` must name a delegable agent. Every mint names its tenant root (`--scope`, `--tenant` or its
  `--confine` entries); only the operator mints deployment-wide, for a
  service. A minted token holds no more than its minter. `cortexdb tokens
  mint` mints with every field: `--confine`, `--exact` (the `CAP:PATH!`
  form), `--cap`, `--tenant` and the chain claims.
- **Names live in the directory.** A scope record's `tree.display_name` is
  refused; use `cortexdb directory put`.
- **A read's purpose, a record's texts, legal holds.** `--purpose ID` declares
  what a read is for (`recall`, `search`, `answer`, `compose`, `access check`,
  `access explain`, `access authzen evaluate`); `cortexdb access texts erase
  PATH` erases the free text a registry record names on every replica; `forget`
  and its preview show what a legal hold kept. `beliefs create` takes
  `--idempotency-key`, `beliefs why` and `conflicts show` take `--scope`,
  `facts timeline --as-of` is applied, `scopes list` pages (`--cursor`,
  `--all`), and `publish` and `access records` return consistency tokens.
- **Fixed against 0.14.0** (`COVERAGE.md` has the whole audit): `experience
  "text" --wait ...` and `experience bulk FILE` (the group swallowed both),
  `search` (sent a budget key the server refuses), `facts timeline`
  (`--predicate` is required), `verify` and `apply` (wrote to a scope type no
  preset registers), the forget receipt, and `code import-scip` /
  `import-index`. `scopes register --owner` sends the Owner as a roster
  entry, which every server honours (servers before the final 0.14.0 dropped
  the `owner` field 0.6.0 sent).

## Commands

```
cortexdb init                                 anonymous signup; persist token + actor
cortexdb preflight | plan | apply | resume | status | doctor | verify | cleanup
cortexdb experience "..."                     store a memory (POST /v1/experience)
cortexdb experience bulk file.jsonl           bulk ingest (POST /v1/experience/bulk)
cortexdb recall   "..."                       recall a stratified context pack
cortexdb search   "..."                       granular event-level search
cortexdb answer   "..."                       recall + LLM answer
cortexdb compose  "..."                       a markdown document from memory
cortexdb forget   --memory-id | --idempotency-key | --capture-key ...
cortexdb episodes {list,get,declare,delete}
cortexdb entities {list,get,link}
cortexdb facts    {list,timeline}
cortexdb beliefs  {list,why,build,create}
cortexdb derivation {status,decisions,policy,templates,taxonomy,stage,test,settings,feed,consumers,texts}
cortexdb corrections {add,list,show,undo}
cortexdb memory   {about}
cortexdb review   {list,approve,reject}
cortexdb conflicts {list,show,resolve}
cortexdb claims   {history}
cortexdb concepts {list,coverage,synthesize}
cortexdb scopes   {list,register,members}
cortexdb access   {check,explain,lookup,limits,enrich,records,restore-ack,rehome,watermarks,accounts,authzen}
cortexdb changes  {stage,parts,preview,activate,get,discard}
cortexdb watch    [ROOT] [--follow]
cortexdb notices  {list,ack}
cortexdb apps     {put,get}
cortexdb directory {put,get,delete,search}
cortexdb rollups  {list,get,totals}
cortexdb publish  --target ... --event | --rollup ...
cortexdb erase    {person,tenant,party,status,receipt,verify}
cortexdb tokens   {mint}
cortexdb auth     {whoami,signup,tokens,revoke}
cortexdb policy   {effective,deployment}
cortexdb admin    {health,usage,layers,retention,wal,access,auth,rollups}
cortexdb audit    {chain,verify}
cortexdb import   data.json | backup.jsonl --server
cortexdb export   -o backup.json
cortexdb code     {add,remove,status,import-scip,import-coverage,export-index,import-index,pin,gc,matrix,watch}
cortexdb config   {show,set}
cortexdb wire     --harness ...
cortexdb                                      interactive REPL
```

Every command that calls the server takes `--json` and the break-glass
options. A command whose scope is optional uses your default scope; one that
takes a tenant root uses the first segment of it.

### Reads: consistency, read sets, coverage

`recall`, `search`, `answer` and `compose` take `--extra-scope SCOPE` (up to
40), `--coverage` (what was searched, authorized, and the gaps),
`--beliefs merged` (beliefs rebuilt across the read set for you), `--mounts`
(your application's admitted mounts), `--consistency`, `--at-least TOKEN` and
`--purpose ID` (the purpose the read is for: a grant whose `when` names a
purpose holds only for that one; `access check`, `access explain` and
`access authzen evaluate` decide a chain for one too) and `--session ID` (the
conversation session the read is made in, CortexDB 0.15.0: where a read-time
use rule is in force, memory from other sessions, or older than its window, is
withheld, and `warnings` says how many events). A write returns a consistency token with `--consistency`; a read that passes it
to `--at-least` sees that write:

```bash
TOKEN=$(cortexdb experience "ship on Friday" --consistency --json | jq -r .consistency_token)
cortexdb recall "ship" --at-least "$TOKEN"
```

`experience write` also takes `--provenance EVENT_ID` (erasing the source
erases the write), `--intent` and `--idempotency-key`.

### derivation: what CortexDB learned, and how (CortexDB 0.15.0)

```bash
cortexdb derivation status org:acme/user:alice                 # layers and extraction caught up?
cortexdb derivation decisions org:acme/user:alice evt_0196...  # what became of one event
cortexdb facts list --include derivation                       # how each fact was made
cortexdb facts timeline --subject Alice --predicate lives_in --include derivation
cortexdb beliefs list --include derivation
cortexdb beliefs why belief_01... --include derivation
```

On a server that serves `derivation_provenance_v1`, `derivation status`
adds the extraction line to the layer builds: how many of the scope's
events the background enrichment has not derived yet, learned from, derived
with nothing admitted, held for review or failed on, with its own caught-up.
`derivation decisions` says what became of one event: learned, nothing
admitted, held, pending, skipped (and why: enrichment off, a reference
root, a `directives.extract` naming no model stage, a typed triple, no
text) or failed (retrying or not), with the models, the prompt version and
the policy; a rejected candidate is counted by its rule id, never shown.
`--include derivation` adds each fact's or belief's derivation (verdict,
models, prompt version, gate, policy; `no stamp` for a row made before
0.15.0) as a column. An older server has no extraction line, answers
`derivation decisions` with a 404 (the hint says so) and ignores
`--include`.

### derivation policies, settings, texts and the feed (CortexDB 0.15.0)

```bash
cortexdb derivation policy org:acme/app:companion/user:bob     # what derives here, under which rules
cortexdb derivation templates                                  # consumer, minimal, enterprise, ...
cortexdb derivation templates consumer > policy.json           # one template's body, to edit
cortexdb derivation test org:acme/app:companion --file policy.json --recent 20   # try it first, writes nothing
cortexdb derivation stage org:acme/app:companion --file policy.json   # stage, preview, activate
cortexdb derivation stage org:acme/app:companion --template consumer
cortexdb derivation settings org:acme/app:companion/user:bob --deny-predicate diet
cortexdb derivation settings org:acme/app:companion/user:bob --consent "health:health coaching"
cortexdb derivation texts org:acme --all                       # the policy texts, without their content
cortexdb derivation feed org:acme/app:tutor --consumer acme-level --cursor-file level.cursor --follow
cortexdb experience write --triple Alice level advanced --derived-by acme-level@1.1.0
```

A derivation policy is a registry record of kind `derive` at
`<scope>/attrs:derive`: `derivation stage` stages it at the scope's root,
prints the preview's derivation section (the record's hash before and after,
the effective policy's before and after with the rules that move, the texts it
names) and activates it with the preview's hash after asking (`--yes` skips
the question). `derivation test` tries a draft first (the same `--file`, or
`--changeset ID` for one you staged): extraction and the gate over the newest
events (`--recent N`, 50 by default) or named ones (`--events FILE`), each
candidate's verdict and rule beside the policy in force, the diff and the
cost. It writes nothing, but its model calls are real: `--max-cost` (1 US
dollar by default) caps them, and a larger estimate is refused before any
call. `changes stage --file` also takes a `{"scope": SCOPE, "derive":
{...}}` entry. `derivation policy` says whether anything derives at a scope and
why not (the server's ceiling, which no policy widens), the mode, each
restriction and where it was set, and the steering in force. `derivation
settings` changes one scope's own restrictions and consents with no change set:
it reads the record, changes what its flags name and writes the whole record
back. `derivation feed` prints a scope's events and the erasures that touch
them, one JSON object a line, for a worker outside CortexDB; `--cursor-file`
resumes where the last run's printed items end. A write-back is a typed triple
stamped `--derived-by NAME@VERSION` (`beliefs create` takes the stamp too).
`stage`, `settings` and `texts` need a shard armed for apply format 11; the
hint of a 503 `FORMAT_UPGRADE_PENDING` says what holds it. A server before
CortexDB 0.15.0 answers `policy`, `templates`, `taxonomy`, `test`,
`settings`, `texts` and `feed` with a 404, which reads like a missing record:
the hint says the server predates the command's capability, and
`GET /v1/admin/version` lists the capabilities a server serves.

### corrections and memory about (CortexDB 0.15.0)

```bash
cortexdb memory about org:acme/app:companion/user:bob          # what is known, with sources and fact ids
cortexdb corrections add org:acme/app:companion/user:bob --reject fact_0196... --reason "I never lived in Boston"
cortexdb corrections add org:acme/app:companion/user:bob --replace fact_0196... --value Denver --valid-from 2026-03-01
cortexdb corrections add org:acme/app:companion/user:bob --pin fact_0196...
cortexdb corrections list org:acme/app:companion/user:bob
cortexdb corrections undo org:acme/app:companion/user:bob cor_0196...
```

To fix a wrong memory, correct it rather than forget it: a forget of what was
derived can be learned again from the events, a correction is not. A
correction names the fact's claim, and changes every live fact of it in the
scope and below: a reject deletes them and keeps the claim from being learned
again (`--bind subject_predicate` or `subject` widen it to every value, or
everything about the subject, for good), a replace writes the new value as
your own fact and closes the old ones, a pin keeps any extracted value from
superseding it, a confirm raises its authority. A reject and an undo ask first
on a terminal, saying what they delete or bring back (`--yes` from a script).
The same `corrections add` sent again replays its first attempt: its default
idempotency key is a hash of the request. `memory about` lists every fact and
belief about the scope's subject with the memories it came from, which is also
the subject's export; `--corrections` adds the scope's corrections. A server
before CortexDB 0.15.0 answers `corrections` and `memory about` with a 404,
which reads like a missing fact or correction: the hint says the server
predates `corrections_v1`.

### review: what a derivation policy held back (CortexDB 0.15.0)

```bash
cortexdb review list org:acme/clinic:north                     # oldest first: what each states, why it was held
cortexdb review list org:acme/clinic:north --topic health --descend --all --json
cortexdb review approve org:acme/clinic:north hld_0196... --reason "confirmed with patient"
cortexdb review reject org:acme/clinic:north hld_0196... --bind subject_predicate --yes
```

A derivation policy's review rules (a topic or predicate held for review, the
`review` mode, a refused writer, a low confidence) hold a candidate memory
CortexDB extracted before it is stored: a held candidate is in no store,
recall or answer until a reviewer decides it. `review list` prints the open
candidates held at a scope, oldest first: what each states, its topic, the
rule that held it, when it was held and when it lapses, and the text around
its quote while its memory is there to quote. `--topic`, `--rule` and `--descend`
(the scopes under it you may read, with `scope.read.descend`) filter it;
`--limit`, `--cursor` and `--all` page it. `review approve` makes each held
candidate a fact of its memory and prints the fact's id. `review reject`
erases each and keeps its claim suppressed by a correction of origin `review`
(`cortexdb corrections list SCOPE --origin review`, which `corrections undo`
reverses): this claim, from its memory and every memory captured before the
decision (`--bind claim`, the default), or every value of its subject and
predicate, past and future (`--bind subject_predicate`). A reject asks first on
a terminal (`--yes` from a script). Each decision is its own: one that is
refused (decided before, its memory erased meanwhile) leaves the others made,
and the command exits 1 after printing every result; more than 100 go in
requests of 100. A candidate nobody decides lapses after the policy's
`review.lapse_days` (30 by default). A Writer of the scope, or a reviewer the
policy names, decides; the routes need a shard armed for apply format 11. A
server before CortexDB 0.15.0 answers `review` with a 404, which reads like a
missing scope or candidate: the hint says the server predates
`derivation_review_v1`.

### outside workers: declared episodes and the feed's consumers (CortexDB 0.15.0)

```bash
cortexdb episodes declare org:acme/team:support --file outage-call.json --derived-by acme-sessionizer@2.1.0
cortexdb episodes list --scope org:acme/team:support           # the declared ones are marked
cortexdb episodes delete org:acme/team:support ep_0196...       # a declared episode
cortexdb episodes delete evt_0196... --reason "posted by mistake"   # one event: the forget it always was
cortexdb derivation consumers org:acme/app:tutor               # who reads the feed here
```

A worker outside CortexDB that groups events into an episode (a call, a
session, a case) declares it: `outage-call.json` holds `events` (1 to 1,024
`evt_` ids) and, as it needs them, `name`, `summary`, `started_at`,
`ended_at`, `actors_involved`, `derived_by` and `idempotency_key`; the CLI
checks its shape as the server does before sending. The episode is served
beside the built ones with `declared: true` and is erased with any event it
names. The same declaration sent again answers its first episode: the default
idempotency key is a hash of the request. Only a declared episode can be
deleted (a built one answers 404). `derivation consumers` lists the workers
whose reads of `derivation feed` reach a scope, which an erasure's receipt
names: their principal, what they read, the last event delivered, when they
last read, whether they are idle and when their mark is purged. Declaring and
deleting need a shard armed for apply format 11; below it `derivation
consumers` says no consumer is recorded. A server before CortexDB 0.15.0 has
none of these routes: `episodes declare` answers 405 there (the server lists
episodes at that path), and `episodes delete` of a declared episode and
`derivation consumers` answer 404; the hint says the server predates the
capability.

Writes say which of their directives nothing reads: `consolidate_into`,
`confidence_floor`, `ttl_for_belief_layer`, `embed` and `async` are
accepted and validated, but nothing reads them, and `experience`, each item
of `experience bulk` and `import --server` print "accepted, not enforced:
NAME" for each one they named. `changes stage`, `parts` and `preview` print "kept enrich: on at
PATH" for a companion put that keeps the stored `enrich` (a put that does
not name `enrich` keeps it; only `"enrich": "inherit"` clears it).

### access

```bash
cortexdb access check org:acme/team:eng --role writer
cortexdb access check org:acme/team:eng --for user:bob         # another chain: Owners and the operator
cortexdb access explain org:acme/team:eng --memory evt_01...
cortexdb access lookup scopes org:acme --include-private --all
cortexdb access lookup principals org:acme/team:eng
cortexdb access limits org:acme
cortexdb access enrich org:acme/team:eng
cortexdb access records org:acme --all                         # a restore's registry listing
cortexdb access restore-ack org:acme                           # acknowledge a restored root
cortexdb access rehome org:acme/source:slack/container:launch evt_01...
cortexdb access watermarks put org:acme/source:slack --at 2026-10-26T00:00:00Z
cortexdb access accounts org:acme --account slack:T1=U123
cortexdb access texts erase org:acme/team:eng --yes             # a record's reasons, matter and notes, everywhere
cortexdb access authzen evaluate --subject user:alice --action read --resource org:acme/team:eng
```

A chain is given with `--for SUB` and `--act`, `--app`, `--client`, `--run`,
`--auth-time`, `--cap`, `--confine`, or whole with `--chain JSON`.

### changes

Change sets write registry records all at once. Stage them, preview the access
diff, activate with the preview's hash:

```bash
cortexdb changes stage org-compile --file records.json --reason "first compile"
cortexdb changes preview org-compile --people
cortexdb changes activate org-compile          # previews, shows the diff, asks, activates
cortexdb changes get org-compile
cortexdb changes discard org-compile
```

`--file` holds a list of records (each a put), operations
(`{"path", "op": "put" | "delete", "record"}`), `{"records": [...]}` or
`{"parts": [...]}`; `--delete PATH` adds deletes; `changes parts` stages more.
A staging, a preview or an activation whose evaluation runs long answers 202
(0.14.1): the command sends it again until it answers, for `--wait` seconds
(120 by default), then exits 75 saying how to collect the answer.

### watch and notices

```bash
cortexdb watch org:acme                         # the current position
cortexdb watch org:acme --after wp1.... --follow
cortexdb notices list org:acme                  # who read what of yours
cortexdb notices ack org:acme --seq 3           # or --through POSITION, or --all
```

`--follow` long-polls from each page's position (one JSON line per page with
`--json`) and prints the last position when stopped.

### apps

```bash
cortexdb apps put notes --kind note --kind decision --mount-prefix org:acme/source:slack
cortexdb apps get notes
```

### directory

```bash
cortexdb directory put user:alice --display-name "Alice Moreau" --email alice@acme.example \
    --account slack:T1=UALICE
cortexdb directory put user:alice --merge --title "Staff engineer"   # read, change, write on its version
cortexdb directory put org:acme/team:eng --display-name "Engineering"  # a scope's name entry
cortexdb directory get user:alice
cortexdb directory search ali
cortexdb directory delete user:temp
```

### rollups and publish

```bash
cortexdb rollups list --scope org:acme/team:eng/aud:roll
cortexdb rollups get roll_01... --scope org:acme/team:eng/aud:roll
cortexdb rollups totals --scope org:acme/team:eng/aud:roll --from 2026-09 --to 2026-10
cortexdb publish --target org:acme/team:eng --from org:acme/user:alice --event evt_01...
```

Only a person publishes: a `user:` token with no `act` or `run`, your own or
one through an admitted application whose client says `client: person`. An
agent, a run, a service, an application token with no `client` and the
operator key get 403 `PUBLISH_PERSON_REQUIRED`.

### forget and erase

```bash
cortexdb forget --memory-id evt_01... --reason "user request"
cortexdb forget --idempotency-key note-42 --key-caller user:alice --reason "deleted"   # reads nothing
cortexdb forget --capture-key cap:upload-7 --reason "withdrawn"
cortexdb erase person user:dev --scope org:acme --yes          # no server dry run: asks, or --yes
cortexdb erase tenant --scope org:acme                         # a dry run
cortexdb erase tenant --scope org:acme --apply --yes
cortexdb erase party pat@example.com --scope org:acme          # a preview
cortexdb erase party pat@example.com --scope org:acme --apply --yes
cortexdb erase status erasure_01... --wait 120
cortexdb erase receipt erasure_01...
cortexdb erase verify erasure_01...
```

A forget needs Owner at its scope. The erasures are the trusted operator's.

### tokens

```bash
cortexdb tokens mint --subject user:bob --confine scope.read.local:org:acme/team:eng
cortexdb tokens mint --subject user:bob --exact scope.read.local:org:acme/team:eng   # sent as ...eng!
cortexdb tokens mint --subject user:alice --act agent:helper --run run-7 --client agent \
    --confine scope.write:org:acme/user:alice
cortexdb tokens mint --subject user:carol --scope org:acme --cap scope.read
```

Every mint names its tenant root: `--scope` (a scope of it, where your
`auth.mint` is checked; it never confines the token), `--tenant` (hosted; it
takes no `--scope`) or its `--confine` / `--exact` entries, all in one root.
A mint naming none is the operator's, for a `service:` or `system:` subject
(403 `deployment_mint_requires_operator` otherwise). `auth tokens` takes the
same flags and prints the raw JSON.

### admin

```bash
cortexdb admin access report org:acme
cortexdb admin access tenant-settings org:acme --operator-data-reads deny
cortexdb admin access tenant-settings org:acme --operator-data-reads allow \
    --break-glass support --break-glass-ticket SUP-1            # lowering from deny
cortexdb admin access tenant-binding org:acme --from default   # a dry run; --apply rebinds
cortexdb admin access restore --scope org:acme --reason "nothing changed since the backup"
cortexdb admin auth reload
cortexdb admin rollups status org:acme
```

## Configuration

Three layers, in precedence order:

1. **CLI flags** — `--api-key`, `--endpoint`, `--actor`, `--scope`, `--profile`
2. **Environment** — `CORTEXDB_API_KEY`, `CORTEXDB_URL`, `CORTEXDB_ACTOR`, `CORTEXDB_SCOPE`
3. **Persisted state**:
   - `~/.cortexdb/config.toml` — endpoint, profile names (human-editable)
   - `~/.cortexdb/state.json` — token, actor, scope, expiry (managed by `init`, 0600 on POSIX)

The state.json format matches the cortexdb-mcp 0.3.0 server's, so you can
copy state across to use both tools from the same anonymous identity.

## Pipe-friendly

Auto-detects when stdout isn't a TTY and emits JSON:

```bash
cortexdb recall "Q3 revenue" | jq .context_block
cortexdb entities list      | jq '.[].subject'
echo "remember this"        | cortexdb experience -
```

Force JSON mode any time with `--json`, before or after the subcommand.

## Auth notes

- The v1 API requires both `Authorization: Bearer <PASETO>` and `X-Cortex-Actor`.
  The CLI stamps both on every request — you never need to pass them by hand.
- 401s show the specific error code (`EXPIRED_TOKEN`, `ACTOR_MISMATCH`, …)
  and the remediation. Note that an expired token is **not** fixed by re-running
  `cortexdb init` — see the identity note above; that would mint a different
  brain rather than restore access to yours.
- 403s cite the missing capability and the policy tier that denied, or the
  `--confine` entry a confined token lacks. If a recall returns
  `diagnostics.read denied`, pass `--diagnostics none` — free-tier tokens don't
  carry the `diagnostics.read` capability.

## License

Apache-2.0
