Repository navigation
Add a private SDK that records and reads the record by code, and hold its three doors to one another - #692
Merged
Conversation
…e events and refusals
The notice about a record that does not chain goes under the opening document and counts against the room the host leaves, as it does in the command line and the plugin.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 })hasrecordDecision,acceptDecision,rejectDecision,addNote,brief,recall,rulesFor(path)andverify. 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'squery()takes asoptions.hooks:SessionStarthands over the documentmnema brief --hookprints, asadditionalContext;PreToolUseonWrite,EditandNotebookEditasks whatmnema before-a-writeasks (denyciting the rule,askfor 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/codegains alibrarysubpath (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.runBeforeAWriteis split in two: the payload reading stays, and the part that asks the record and appends the facts becomesrunBeforeAPath, which the command and the SDK hook both call. Behaviour of the command is unchanged.HookEventin the hook reply helper gainsSessionStart, which carriesadditionalContextonly.The three doors
packages/code/tests/the-three-doors-are-one.test.tsruns 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 (okor 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, andNO_PROJECTfrom 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
addNotefrom the SDK turns the note scenario and the method-row case red.Known limits
PreToolUsehook 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,recallandverifyhave no MCP tool of the same shape, so they are compared against the command line only; the table says why.