# Notes and history tool results

Notes, dream and history tools return the same rendered results across Pi, Claude Code, Codex, Antigravity and Cordis. Only `notes_read` also returns structured data where supported.

Stored notes and raw session entries are not rewritten by this protocol change. In Pi, `get_context_remaining` independently declares `{ remaining_tokens }` as its output schema; `empty_brain` remains outside this protocol.

## Results

In Pi codemode and DSH, all shared tools except `notes_read` return strings. Pi and MCP also provide `notes_read` as structured data; in Claude Code it is text only.

```js
const note = await tools.notes_read({ address: "plan.md" });
return note.text;
```

A refusal displays `error: <code>: <message>`. Pi and MCP mark the call as failed (`isError: true`); Pi codemode throws an `Error`, and DSH throws a `HarnessError` with the refusal code. On Pi and MCP, `notes_read` additionally returns `{ error, code }` on refusal.

When an edit fails, the message identifies the failing edit and, for ambiguous text, the matching lines.

## Per-call project selection

All four notes tools accept optional `cwd`. Omitted means the host session's current project. A relative value resolves against the host session/binding cwd, and an existing directory is required; invalid explicit paths produce `invalid_cwd`. The override lasts one call and consistently drives `@project`, default/current-project globs, mutation endpoints, receipts, and new session-note ownership. It does not change the notes root or the physical session notebook.

## Read windows

`notes_read` returns these fields at the structured result root, alongside identity and metadata:

```ts
{
  text: string;
  total_chars: number;
  next_offset_chars: number | null;
}
```

Positions count Unicode code points, not UTF-16 units or UTF-8 bytes. The returned text is a contiguous unmodified prefix of the requested range, without ellipsis markers. `next_offset_chars` names the first undelivered character, or is null at the true end. A negative input offset selects a tail; the delivered window does not echo the offset it resolved.

- `notes_read`: `address`, optional `project_key`, and `metadata` accompany the text fields. Positions address only the note **body**. Access counts and last-access times remain stored; only `dream_begin` rows report last access.
- `history_read`: the rendered header identifies the seq, role and any tool summary. Explicit session targeting also displays the canonical session. Positions address one deterministic document derived from the event's facts. Query matches address that same document, not its decorated presentation.

Repeated note reads observe the current file; this is not a retained snapshot service. A concurrent body edit can change positions. History reflects the active branch and recorded facts, including a result that may arrive after a pending call was first observed.

Text rendering puts identity and relevant metadata above the payload. Only an incomplete read receives a continuation suffix, which states how much of the document was delivered and where to resume:

```text
[truncated at 12000/45000 chars; continue at offset_chars=12000]
```

The suffix and presentation header are never part of `text`, search offsets or total character counts. At the end there is no completion footer.

## History identity and execution evidence

The native adapter allocates seqs from session append order, selects the active branch and decodes facts. Shared history pairs calls and results without allocating a second transcript. A paired execution is addressed by its call seq. Its result's raw slot is not a public event address; list/search provide the canonical seq. Unpaired results remain independently addressable. Inactive-branch addresses are not readable.

Seqs address events across the whole session, including earlier windows. With `session` omitted, headers use `seq <seq> | <role>` plus the event's local ISO timestamp when recorded (`seq <seq> | <role> | <timestamp>`); the boot window tree supplies seq ranges for narrowing `history_list` with `after` and `before`. With an explicit selector, `history_list` and `history_search` print `=== session <harness>:<id> ===` once above that session's rows, `history_read` uses `session <harness>:<id> | seq <seq> | <role> | <timestamp>`, and all paging/expand/neighborhood recipes carry that same identity. Untimed events omit the timestamp segment. Wildcard selectors in `history_list` and `history_search` accept `since` / `until` time bounds and report whether more results may exist beyond the page. See [cross-session history](history-sessions.md) for discovery, representative selection and refusal rules.

Tool event headers expose the tool name, status and, when recorded, truncation and full output path; a truncated run is named even when the host recorded no path, and the full text path is named only when it exists. `history_read` also reports nested-call counts and completeness; a page row does not. Full arguments and nested-call records live only in the searchable/readable document, without duplicating the document.

Pi's nested records contain child ID, name, optional arguments, status, timing and error, plus completeness. They contain **no child result bodies**. Absent records do not establish that no nested work occurred. Host-omitted arguments and unfinished calls remain visible as incomplete evidence. Child records belong to their parent event and do not consume seqs.

`history_read` reports the count and completeness of nested calls exactly as recorded: the count is every record the host stored, even if the current text slice contains none of them. Continue at the displayed `offset_chars` to recover the entire recorded document. Both a call's result and an unpaired result carry their recorded evidence; neither invents the call the other one is missing. Query results contain event rows only; folded rows exist only in the browse view.

## Bounds and continuation

### Notes

`notes_list` with a non-empty `query` returns only matching notes and displays hit lines with their line numbers and `offset_chars`, plus a count when lines are omitted. `max_matches_per_note` requires a query. `notes_list` shows the newest page and, when more match, ends with `→ older: {…}`: pass that object back to keep reading older notes; it carries `cursor` as `<updated_at> <address>`. Paging continues from the last shown note, so an edited note cannot repeat. Omit `glob` for current notebooks or supply a non-empty glob to narrow or widen the selection.

`notes_write` and `notes_update` accept optional `pinned`, `readonly`, and `description` fields (`budget` is a frontmatter-only override, not a model tool parameter). Their receipts and list/search rows display only policy that differs from the note's path defaults (`pinned`, `pinned false` on an unpinned root `CHEATSHEET.md`, `budget <N>`, `readonly`), while read metadata keeps the full effective policy (with `description` included on read metadata and list/search rows when present). Warnings render inside `<notesoup:warning>...</notesoup:warning>` when a body exceeds its UTF-8 byte budget (4096 bytes for root `CHEATSHEET.md`, 8192 bytes for ordinary notes) or when `description` exceeds the boot-index display cap. Both save whole; boot truncates over-budget pinned bodies at the budget boundary (`[truncated at X/Y; offset_chars=X]`) and places warnings outside the note frame. Pi's write/update/read cards display policy and warnings even when collapsed. Pi shows the update diff in the expanded card; the tool response stays a short receipt.

A readonly note refuses mutations with `readonly` until explicitly unlocked with `readonly:false`; this is a soft lock, not security. Pin admission refuses a sixth live pin per notebook with `pin_limit`, including restore/move/rename. Invalid policy fields refuse with `invalid_policy`.

A note read reports unrecognized frontmatter under `metadata.extra`; a value too large to carry, or past the verbatim budget, is named in place as `[omitted: too large]` under its key, and the value itself stays in the note file. A rename receipt displays both source and destination.

`notes_update` takes `replace_all` for the whole call and `edits[].replace_all` for one edit; a per-edit value overrides the call default for that edit, so one atomic update can mix unique-match edits with multi-occurrence ones.

### Shared bounds

A result fits within 32 KiB of UTF-8, including the headers, notices and continuation footers
you see. For `notes_read`, the structured result must also fit within 32 KiB when encoded as
JSON.

Queries are literal and case-insensitive; a list matches any entry, ignoring empty entries. In `notes_list`, an empty or omitted query browses; in `history_search`, `query` is required and an empty query returns no matches.

A read that cannot deliver a single advancing character refuses with `output_too_large` rather
than returning an empty window. A concurrent change to the source can invalidate a previously
observed offset.

A shortened note search match ends with ` [truncated]`; a shortened history preview appends the same ` [truncated]` and names its starting character position as ` | offset_chars <N>` on the header line. The markers are not part of either source document.

Narrowing helps only when a parameter actually reduces the selection. A read whose own metadata
or header overflows cannot be repaired by narrowing a list or search.

If a result omits entries or cuts a preview short, it tells you. Text and structured note reads
refer to the same slice.

### History

- `history_list` browses a single timeline in ascending seq order, or lists one representative event per session when given a wildcard `session` (e.g. `*` or `pi:*`). For a single timeline, `after` and `before` are exclusive integer seqs (with `after: 0` starting at the beginning), optional `since` / `until` filter by ISO 8601 time, and without `roles`, tool/context runs fold and don't count against `limit` (use `→ expand` to see them). Follow `→ older` or `→ newer` to keep paging with the same options. For wildcard sessions, `after` / `before` are refused; use `since` / `until` and `roles`.
- `history_search` finds literal, case-insensitive text (`query` required; a list means any match, and an empty query returns no matches), including tool arguments and output. Search one session or a wildcard such as `*`. Use exclusive ISO 8601 `since` / `until` bounds (local time without an offset); without `since` take the newest matches. `context: N` adds visible neighbors on either side of a hit, even outside its filters, without consuming `limit`. If more results exist, narrow the time range, query, roles or session pattern.
- `history_read` opens one event using `seq`, the session shown above it if any, and the header's `offset_chars` if shown. Follow `offset_chars` to continue a long read. Concatenate text slices without headers or footers before parsing any recorded arguments.

Both list and search default to 20 events or hits/sessions, with a 32 KiB UTF-8 text limit including session headings, notices and footers. Limit previews with `max_chars_per_item`; if a page cannot fit, narrow your request or read a single event.

## Ownership

- The notes store owns addressing, file contents, metadata and mutations.
- The history wire decoders own native seq allocation and persisted branch evidence; adapters supply live branch/head identity. The shared corpus resolves sessions without a second transcript.
- Shared operations own per-call cwd resolution, the typed result, filtering, paging, character windows and refusal messages.
- Shared renderers derive text from that result.
- Host adapters supply base cwd, default identity, projections, optional pure text decoration and transport packaging only; they do not implement separate cwd override algorithms.

There is no second query implementation for codemode, no copy of session storage and no migration of user records.
