Skip to content

Add a private SDK that records and reads the record by code, and hold its three doors to one another - #692

Merged
felipesauer merged 9 commits into
main-v1from
a-library-door-to-the-record
Oct 4, 2026
Merged

felipesauer merged 9 commits into
main-v1from
a-library-door-to-the-record

Conversation

@felipesauer

Copy link
Copy Markdown
Owner

What

A new private package, @mnema/sdk, that lets a program which builds its own agent read and write the record by code, and a test that holds the command line, the MCP server and the library to one another.

  • openRecord({ cwd, agent }) has recordDecision, acceptDecision, rejectDecision, addNote, brief, recall, rulesFor(path) and verify. Each calls the function the matching command calls; a refusal comes back as a value with the command line's code.
  • mnemaHooks({ cwd, agent? }) returns what the Claude Agent SDK's query() takes as options.hooks: SessionStart hands over the document mnema brief --hook prints, as additionalContext; PreToolUse on Write, Edit and NotebookEdit asks what mnema before-a-write asks (deny citing the rule, ask for a person, {} otherwise) and records the same facts. The hook shapes follow the Agent SDK hooks page; no test calls a model.
  • private: true; it joins the licence, NOTICE, version and sentence guards. Its README says what it proves and what it does not.

Reuse, not reimplementation

  • @mnema/code gains a library subpath (src/library.ts) that only re-exports the commands' functions and the presentation they print through. A test asserts each name on it is the very function the command line imports. This is the one change to the published manifest of @mnema/code.
  • runBeforeAWrite is split in two: the payload reading stays, and the part that asks the record and appends the facts becomes runBeforeAPath, which the command and the SDK hook both call. Behaviour of the command is unchanged.
  • HookEvent in the hook reply helper gains SessionStart, which carries additionalContext only.

The three doors

packages/code/tests/the-three-doors-are-one.test.ts runs each scenario through the built binary, an in-memory MCP connection and the SDK, each in a project of its own. It compares the events left in the record (kind, tree, attribution, payload; time, signature, MCP run pins and ids taken out, ids replaced by order of appearance) and what each step answered (ok or the refusal code). Scenarios: record, accept, accept again; reject without a note; a move on an unknown decision; an agent's accept with the switch off; notes by default and by scope; a rule that refuses a write, through the vscode host command, the MCP tool and the SDK hook; reads against the command's own output, and NO_PROJECT from outside a project.

It also enumerates the SDK's methods, the MCP tools declared as writing and the verbs declared as writing; each must be a row of the table or carry a written reason for not being in the SDK, and a reason whose tool or verb is gone is red.

Mutation: removing addNote from the SDK turns the note scenario and the method-row case red.

Known limits

  • The PreToolUse hook is the gate alone, like the command door: it does not carry the rules that only govern a path, which the plugin's Claude Code door hands beside a write.
  • brief, recall and verify have no MCP tool of the same shape, so they are compared against the command line only; the table says why.
  • The README has no code block: a ```ts example would have to be run verbatim by the example guards and would found an identity in this repository.

@felipesauer
felipesauer merged commit c482148 into main-v1 Oct 4, 2026
6 checks passed
@felipesauer
felipesauer deleted the a-library-door-to-the-record branch October 4, 2026 04:19
felipesauer added a commit that referenced this pull request Oct 5, 2026
… its three doors to one another (#692)

## What

A new private package, `@mnema/sdk`, that lets a program which builds
its own agent read and write the record by code, and a test that holds
the command line, the MCP server and the library to one another.

- `openRecord({ cwd, agent })` has `recordDecision`, `acceptDecision`,
`rejectDecision`, `addNote`, `brief`, `recall`, `rulesFor(path)` and
`verify`. Each calls the function the matching command calls; a refusal
comes back as a value with the command line's code.
- `mnemaHooks({ cwd, agent? })` returns what the Claude Agent SDK's
`query()` takes as `options.hooks`: `SessionStart` hands over the
document `mnema brief --hook` prints, as `additionalContext`;
`PreToolUse` on `Write`, `Edit` and `NotebookEdit` asks what `mnema
before-a-write` asks (`deny` citing the rule, `ask` for a person, `{}`
otherwise) and records the same facts. The hook shapes follow the Agent
SDK hooks page; no test calls a model.
- `private: true`; it joins the licence, NOTICE, version and sentence
guards. Its README says what it proves and what it does not.

## Reuse, not reimplementation

- `@mnema/code` gains a `library` subpath (`src/library.ts`) that only
re-exports the commands' functions and the presentation they print
through. A test asserts each name on it is the very function the command
line imports. This is the one change to the published manifest of
`@mnema/code`.
- `runBeforeAWrite` is split in two: the payload reading stays, and the
part that asks the record and appends the facts becomes
`runBeforeAPath`, which the command and the SDK hook both call.
Behaviour of the command is unchanged.
- `HookEvent` in the hook reply helper gains `SessionStart`, which
carries `additionalContext` only.

## The three doors

`packages/code/tests/the-three-doors-are-one.test.ts` runs each scenario
through the built binary, an in-memory MCP connection and the SDK, each
in a project of its own. It compares the events left in the record
(kind, tree, attribution, payload; time, signature, MCP run pins and ids
taken out, ids replaced by order of appearance) and what each step
answered (`ok` or the refusal code). Scenarios: record, accept, accept
again; reject without a note; a move on an unknown decision; an agent's
accept with the switch off; notes by default and by scope; a rule that
refuses a write, through the vscode host command, the MCP tool and the
SDK hook; reads against the command's own output, and `NO_PROJECT` from
outside a project.

It also enumerates the SDK's methods, the MCP tools declared as writing
and the verbs declared as writing; each must be a row of the table or
carry a written reason for not being in the SDK, and a reason whose tool
or verb is gone is red.

Mutation: removing `addNote` from the SDK turns the note scenario and
the method-row case red.

## Known limits

- The `PreToolUse` hook is the gate alone, like the command door: it
does not carry the rules that only govern a path, which the plugin's
Claude Code door hands beside a write.
- `brief`, `recall` and `verify` have no MCP tool of the same shape, so
they are compared against the command line only; the table says why.
- The README has no code block: a ```ts example would have to be run
verbatim by the example guards and would found an identity in this
repository.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant