Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ claim to cover them; `git log` and the PR history are the record for those.

| change | anchor | what you may have to do | why it was taken |
|---|---|---|---|
| **Versioned JSON output: `cairn recall --json`, `cairn routes --json`, and new verbs `cairn associate --scope S --paths-from F` (`--json`, `--min-paths N`), `cairn refs` (ref collisions, by the reader's resolver; `--all-scopes` exits 11 on a cached scope with no route and prints a PARTIAL answer at 3 when an instance's cache is unreadable), `cairn parse --file F --json` (the reader's parse of an entry or a bullet body) and `cairn fold --file F --json` (the reader's ref fold of a JSON array of strings); `cairn validate --file F [--ref R]` checks one draft offline with the body predicate `create`/`put` apply and the store's 1 MiB body cap (with `--ref`, under the filename `create --ref R` would use).** Shapes carry `schema: 1` and are documented in `README.md` → *Machine-readable output*. | PR → `<UNFILLED>` | Nothing; every existing invocation prints what it did. A consumer parsing the new documents should refuse a `schema` it does not know. | The Python client's last consumers parsed its in-process report objects; these give the Go client the same answers as a stable contract, so the Python client can be retired (v1 plan Phase 5). |
| **`cairn log list\|search` cover the CURRENT REPO's records by default, PER RECORD** — a search keeps the hits whose own record ran in a worktree of the repo `--repo` names (default: the working directory); a list, the sessions with any record there (showing that directory and its first prompt). New **`--all-repos`** widens to every record; `--cwd PREFIX` replaces the default and is now per record too; the two together, or neither outside a git repo, are exit 2. stderr names what was covered (`cairn: sessions=…`). The scoped request is a NEW `POST /client/v1/log/{list,search}` with a `cwd_under` form. **Index migration 5** adds `transcript_units.cwd` and `transcript_session_cwds` and zeroes every index cursor. `log query` is unchanged and unscoped | [#329](https://github.com/ZacxDev/cairn/pull/329) → `<UNFILLED>` | ⚠ **Deploy `cairn-ui` first**: migration 5 runs on start and the backfill re-reads every stream in place (rate-limited; scoped results grow as it goes, `--all-repos` is unaffected); then pin the client. An older listener answers the scoped POST 405, which exits 3 with nothing printed. ⚠ **A script that searched every repo** must add `--all-repos`; one run outside a git repo must add `--all-repos` or `--cwd`; one using `--cwd` now gets per-record hits. [`README.md`](README.md) § *`cairn log` covers the current repo* | `--repo` only picked the instance, and the index kept ONE cwd per session (its first), so a search printed other repos' (and clients') records into the caller's own captured transcript: [`internal/client/log.go`](internal/client/log.go)'s header |
| **`cairn-capture` no longer HOLDS a session for a scope the routing table does not name** (on a host with more than one instance): it ships to the DEFAULT instance OWNER-ONLY (`*` declared), as a `*` session does. A session already bound to the DEFAULT instance is no longer withdrawn for it; one bound to ANOTHER instance is withdrawn from there and re-shipped whole to the default, owner-only — the `*` path (before, it was withdrawn and HELD). A scope the table EXPLICITLY routes to an instance this host does not configure is still held — the only routing hold left — and its `held_reason` now says so (`scope X is routed by the table to instance Y, which this host does not configure`). New mode **`--reevaluate-held [-apply]`** recovers the holds the old rule made | [#330](https://github.com/ZacxDev/cairn/pull/330) → `<UNFILLED>` | ⚠ **Sessions previously held stay held** until you run `--reevaluate-held` (read-only listing), then, with `-host`/`-worker`/`-capture-token-file`, `-apply`: it clears only holds whose destination answered the position probe; a 410 is listed `needs-server-restore` and left held — restore it by the server journal. The `routed back to …, which deleted this session's transcript` holds are never touched. ⚠ **If you match `held_reason` text**, the unconfigured-alias hold's wording changed. [`internal/capture/README.md`](internal/capture/README.md) step 3 and § *`--reevaluate-held`* | `scopeuse` reads header-shaped text anywhere in a transcript (test output, a source read, assistant prose) as a scope read, so a fixture name in a grep result held — and withdrew — whole sessions: measured on a two-instance host, 15 held this way, 14 on fixture names. An unnamed scope is a claim about no instance, so there is no leak to stop: [`internal/capture/route.go`](internal/capture/route.go)'s `Decide` |
| **`cairn-capture --clear-held` no longer clears a hold whose session was ever bound or WITHDRAWN, nor any empty-`instance` hold in a state written by an earlier agent.** The state keeps a per-session shipping history (`bound_ever`, `withdrawn_from`, `history_kept`); `--list-held` prints a sixth field, why a `permanent` hold is kept, and `--clear-held` prints it per kept hold. EVERY first binding is now position-probed (one request per new session; a 410 there holds the session), a withdrawal is recorded before it is sent, and a 410 on an instance the session was withdrawn from HOLDS it instead of marking it `deleted`. The hold reason is neutral (`410: withdrawn or deleted there`): restore by the server journal's reason. | [#324](https://github.com/ZacxDev/cairn/pull/324) → `<UNFILLED>` | ⚠ **Existing empty-`instance` holds become `permanent`** (a legacy state cannot prove they never shipped). List them: `cairn-capture --list-held \| awk -F'\t' '$3 == "permanent"'`. ⚠ **If you parse `--list-held`**, one trailing field is added; the first five keep their positions. [`internal/capture/README.md`](internal/capture/README.md) § *`held=` is not the backlog* | DATA LOSS: an empty `instance` was read as "never shipped", but a withdrawal empties it too. `--clear-held` cleared withdrawn sessions, the next pass re-sent them unprobed, the instance answered 410 (a withdrawal is final for its uploader), and each was marked `deleted` for good — measured: 49 sessions on one host |
Expand Down
116 changes: 113 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ the Go client.
| verb | what it does | |
|---|---|---|
| `sync` | refresh the local cache from the pod | |
| `recall --scope X` | the scope's digest (`--ref R`, `--list`, `--limit N`, `--page N`, `--tag`, `--ref-to`) | |
| `recall --scope X` | the scope's digest (`--ref R`, `--list`, `--limit N`, `--page N`, `--tag`, `--ref-to`; `--json` — [*Machine-readable output*](#machine-readable-output)) | |
| `search 'query'` | find a hunk by text (`--all-scopes`, `--tag`, `--ref-to`) | |
| `validate` | the post-write check: parse, dropped lines, marker reachability | |
| `validate` | the post-write check: parse, dropped lines, marker reachability; `--file F [--ref R]` checks one draft offline with the body predicate `create`/`put` apply and the store's 1 MiB body cap — with `--ref`, under the filename `create --ref R` would use (without it, under the draft's own name, which can differ) | |
| `ls-entries` | what the cache actually holds — the ENTRY files, never a scope's `README.md` | |
| `doctor` | one call of diagnostics (`--json`, `--no-sync`) | |
| `routes` | the scope→instance table, graded (`--check`) | |
| `routes` | the scope→instance table, graded (`--check`); `--json` adds each instance's cache root | |
| `append --scope S --ref R --text '…' --session ID` | append one dated, attributed bullet | writes |
| `put --scope S --ref R --file F` | replace a whole entry behind `If-Match` | writes |
| `create --scope S --ref R --file F` | create a new entry (refuses to overwrite) | writes |
Expand All @@ -235,6 +235,10 @@ the Go client.
| `audit-refs --scope X` | check entries' paths, symbols, commits and PRs against the declared sources | *Go* |
| `memo-send`, `memo-check`, `memo-read`, `memo-retract` | scope memos — § [*Scope memos*](#scope-memos--messages-between-agent-sessions) | *Go* |
| `transcript skeleton\|records\|tool` | read a stored session transcript; takes `--timeout` after the verb too, and a smaller positive value is raised to 90 s (a very large session's skeleton takes tens of seconds) | *Go* |
| `refs --scope X` / `refs --all-scopes` | every ref the cached entries make addressable, and every one the resolver finds AMBIGUOUS (`--json`); `--all-scopes` counts each scope once, in its routed instance | *Go* |
| `parse --file F --json` | the reader's parse of one entry (front matter, headings, sections, journal bullets) or, with `--bullets`, of any text using the bullet grammar; offline | *Go* |
| `fold --file F --json` | the reader's ref fold (`NormalizeRef`, `PathRefs`) of each string in a JSON array (`-` reads stdin) — for a string that is not an entry's; offline | *Go* |
| `associate --scope X --paths-from F` | which entries of the scope a list of repo-relative paths names (`-` reads stdin; `--min-paths N`, `--json`) | *Go* |
| `log list\|search QUERY\|read SESSION` | search stored transcripts: your sessions, full-text hits (one per block), or verbatim records around a hit (`--since`, `--until`, `--cwd`, `--all-repos`, `--session`, `--limit`; `read --from/--to` or `--around/--context`); `list`/`search` cover **the current repo's records by default** (per record) — § [*`cairn log` covers the current repo*](#cairn-log-covers-the-current-repo); single-user instances only | *Go* |
| `log query SQL` | ONE read-only SELECT over `log_sessions` and `log_units` (your sessions only; `cairn log --help` lists the columns): a table, or the answer's JSON (`schema: 1`) with `--json`; `--limit` rows (default 100, max 1000), 1 MiB, 5 s. Single-user instances with a query role only — the guarantee and its escape battery: [`internal/transcript/README.md`](internal/transcript/README.md#the-l2-sql-route-v1-phase-2) | *Go* |

Expand Down Expand Up @@ -347,6 +351,112 @@ clean bill of health. `arcs --check` and `audit-refs` reuse it. The `{0, 9}` ove
stale write, so an unreachable store is a refused write at `7`, never a queued or
local one.

### Machine-readable output

`recall --json`, `associate --json`, `routes --json`, `refs --json`, `parse --json` and `fold --json` print one JSON document on stdout. **The
shapes are a stable contract**, versioned by the integer field `schema` (today `1`):

- **adding** a field is compatible and does not change `schema`; **removing, renaming or
re-typing** one does. Ignore fields you do not know; refuse a `schema` you do not know.
- every list is a JSON array, never `null` (`routes` is the one deliberate `null`, below);
- **the exit code is the verb's usual one** — `--json` changes stdout, nothing else. A run that
refuses before answering (usage, an unrouted scope, an unreadable cache) prints **no document**,
so an empty stdout means "no answer", never "an empty answer". Warnings still go to stderr. The
one exception is `refs --all-scopes`, which walks several instances: it prints what it could
walk and names what it could not, at a non-zero exit (below).

`recall --json` — the reader's answer for one scope:

| field | |
|---|---|
| `schema`, `verb` | `1`, `"recall"` |
| `status` | the reader's verdict: `recalled`, `ref-absent`, `ref-ambiguous`, `scope-absent`, `scope-empty`, `scope-unreadable`, `tag-absent`, `ref-to-absent` |
| `exit`, `warning` | the code the command exits with, and the stderr warning (`""` when none) |
| `scope`, `instance`, `cache_root` | which scope, which configured instance, and the cache directory read |
| `state`, `state_detail` | the cache's state (`live`, `stale`, …) and the banner's detail sentence |
| `mode`, `ref` | the digest mode; the `--ref` asked for, or `null` |
| `candidates` | for `ref-ambiguous`, the refs the ask could mean |
| `known_scopes` | for `scope-absent`, the scopes the cache does hold |
| `total_in_scope` | entries in the scope |
| `entries` | the entries the digest shows in full (see below) |
| `listing`, `listing_total`, `listing_page`, `listing_pages` | the index page, for `--list` |
| `malformed`, `malformed_elsewhere` | rejected files, `{scope, filename, reason}` |

Each entry: `ref`, `filename`, `sensitivity` (effective), `declared_sensitivity` (an unknown
marker the fail-safe overrode, else `""`), `sections` (an object keyed by the heading line as
written — `"## What it is"`, `"## Pointers"`, `"## Nuance / work-history"` — holding only the
headings the entry has), `missing_sections`, `bullet_count`, `open_count`, `near_miss_count`,
`unverifiable_count`, `tags`, `refs`, `mtime` (seconds since the epoch).

`associate --json` — `schema`, `verb` (`"associate"`), `status` (`associated`, or `scope-absent` — `recall`'s spelling, exit 0, the same answer for a scope that never existed and one this credential cannot see), `scope`, `instance`, `cache_root`,
`state`, `state_detail`, `min_paths`; `matched` and `below_threshold` (each
`{ref, filename, paths, evidence: [{path, component, ref, tier, matched_alias}]}`, where `tier`
is `filename` or `alias`); `ambiguous` (`{ref, tier, candidates, paths}`); `unmatched_paths`;
`considered_paths` (every non-blank input line, deduplicated, in input order); `malformed`. A
scope the cache does not hold answers `status: scope-absent` (never an empty `matched` that reads
as "these paths touch nothing"); a scope holding a malformed entry answers for the rest and exits 5.

`routes --json` — `schema`, `verb` (`"routes"`), `multi_instance`, `instances`
(`[{alias, default, cache_root}]`, where `cache_root` is the directory every read verb uses for
that instance), `routes_source` (the table's path, or `""`) and `routes` (`{scope: alias}`, or
**`null` when no table is configured**, which is a different fact from an empty table). It reads
no cache and contacts no pod; `--json --check` is refused (2) — run `--check` on its own.

`refs --json` — `schema`, `verb` (`"refs"`), `status` (`answered`, or `scope-absent` for a
`--scope` the cache does not hold — `recall`'s spelling, exit 0, with an instance whose `scopes`
is empty), `instances` (`[{instance, cache_root, state, state_detail, scopes, not_routed_here,
unrouted}]`) and `unread_instances`. Each scope: `scope`, `refs_tried` (the denominator — every
slug, kind-qualified ref and normalized alias fed to the resolver), `entries`
(`[{ref, filename, slug, kind, aliases}]`), `collisions` (`[{ref, tier, candidates}]`, exactly the
refs `recall --ref` would refuse as ambiguous; `tier` is `filename` or `alias`, `candidates` are
filenames) and `malformed`. With `--all-scopes` a scope is counted only under the instance the
routing table sends it to:

| a cached scope that… | is listed in | exit |
|---|---|---|
| the table routes to THIS instance | `scopes` | 0 (5 if it holds a malformed entry) |
| the table routes to ANOTHER configured instance | `not_routed_here` (not counted: its copy is not the one any read uses) | 0 |
| has no route (`recall --scope` refuses it) | `unrouted`, and named on stderr — **not counted** | **11** |

and an instance whose cache cannot be read is `search --all-scopes`'s PARTIAL: it is listed in
`unread_instances`, a `🔴 cairn: PARTIAL` line names it on stderr, the instances that answered are
still in the document, and the exit is the unread state's (**3**, or 4). The exit is the HIGHEST
that applies (11 > 5 > 4 > 3); `unrouted`, `malformed` and `unread_instances` say which. **A
consumer that reads only `scopes` must treat any non-zero exit as an incomplete census.**
With `--scope`: an unrouted scope is refused at 11 and an unreadable cache at 3, printing no
document, as `recall` does.

`parse --json` — `schema`, `verb` (`"parse"`), `mode` (`entry` or `bullets`), `source`,
`front_matter` (strings and lists of strings, as the reader parses them), `headings` (every `#`
heading line in order), `sections` (heading line → body, a repeated heading's bodies joined) and
`bullets`: the `## Nuance / work-history` journal (or, with `--bullets`, the whole input) as
`[{start_line, lines, date, openness, resolved_by, population, citation_id}]`, where `population`
is exactly one of `open`, `resolved`, `unverifiable` (RESOLVED with no sha), `near-miss`,
`unmarked`, `none`. It is NOT a well-formedness verdict — that is `validate --file`. Input over the
store's body cap (`write.MaxEntryBytes`, 1 MiB) is refused (2).

`fold --json` — the reader's ref fold, for a string that is not an entry's (a service name typed on
a command line, a repo basename, a path no entry matched). Input: `--file PATH` or `--file -`
(stdin), ONE JSON array of strings, so any string — empty, `--`, surrounding whitespace — is
carried exactly. Output: `schema`, `verb` (`"fold"`), `results`, one per input in input order:
`{input, ref, path_refs}`, where `ref` is `NormalizeRef(input)` — the fold `recall --ref` and
`create --ref` apply; `""` means "not a ref", never a wildcard — and `path_refs` is
`[{component, ref}]`, `PathRefs(input)`: every `/`-separated component's fold plus the final
component's stem with ONE extension stripped (`foo.tar.gz` offers `foo.tar`), duplicates collapsed,
order kept, empty folds dropped. Exit 0 on any array (`[]` included); 2 when the input is
unreadable or not an array of strings (a `null` element included).

```console
$ printf '%s' '["Widget_API", "apps/values.yaml"]' | cairn fold --json --file -
{"schema": 1, "verb": "fold", "results": [
{"input": "Widget_API", "ref": "widget-api", "path_refs": [{"component": "Widget_API", "ref": "widget-api"}]},
{"input": "apps/values.yaml", "ref": "apps-values.yaml", "path_refs": [{"component": "apps", "ref": "apps"},
{"component": "values.yaml", "ref": "values.yaml"}, {"component": "values", "ref": "values"}]}]}
```
(reflowed; the real output is indented JSON)

`doctor --json` predates this contract and carries no `schema` field.

### A sync that is already current does not re-download

`GET /api/v1/snapshot` carries an **`ETag`** — `"sha256:<64 hex>"` over the
Expand Down
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2000,9 +2000,11 @@
# first, `sessions`, is the arcs/sessions S2 slice; the arc registry is S3; the four
# `memo-*` verbs are scope mail's S3 (decision 8 of the scope-mail plan); `sources`
# is the scope-refs plan's S3 and `audit-refs` its S5; `transcript` is the transcripts
# plan's S8 (its decision 17); `log` is Phase 1 of the v1 event-log plan.
# plan's S8 (its decision 17); `log` is Phase 1 of the v1 event-log plan; `associate`, `refs`, `parse`
# and `fold` are its Phase 5 (the Python client's last consumers move to the Go one).
cat > want-go-only-verbs.txt <<'EOF'
arc-register writes
associate reads
arc-show reads
arcs reads
audit-refs reads
Expand All @@ -2011,6 +2013,9 @@
memo-read reads
memo-retract writes
memo-send writes
fold reads
parse reads
refs reads
sessions reads
sources reads
transcript reads
Expand Down
5 changes: 3 additions & 2 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ const (

// How much of a request body this server will read. The oracle's cap, kept: it
// bounds what an authenticated caller can make the process hold in memory per
// in-flight request.
maxBodyBytes = 1 << 20
// in-flight request. Defined from `write.MaxEntryBytes` so the client's offline
// `validate --file` refuses an oversize draft at the same bound.
maxBodyBytes = write.MaxEntryBytes

// auditTimeLayout is the audit record's `ts=` spelling, and it is NOT `time.RFC3339`.
//
Expand Down
Loading
Loading