Local-first π§ memory for Hermes Agent that lives in your Obsidian vault and remembers project context. Nightly π΄ dream passes turn repeat corrections into confirmed preferences with measurable confidence. Adapters ship for Claude Code, Codex, and OpenClaw, with an MCP server for anything else.
Recon β the MCP instruction surface, and whether agent can select on it
Task under verification: kanban t_f2ede668 (priority 2), "Per-agent extraction
instruction set selectable by agent scope, with split-by-attribution".
Every claim below carries a file:line anchor that was read. Anchors are from
the working tree on feat/a-label-is-not-a-boundary.
What exists
1. The instruction surface, end to end
src/mcp/instructions.ts is the whole surface. It exports one function and
holds three bodies of text.
| Piece | Anchor | Varies by |
|---|---|---|
BuildInstructionsOpts |
src/mcp/instructions.ts:13 |
β |
WRITER_INSTRUCTIONS (constant) |
src/mcp/instructions.ts:32 |
nothing |
CATALOG_INSTRUCTIONS (constant) |
src/mcp/instructions.ts:61 |
nothing |
identityLine(agent) |
src/mcp/instructions.ts:89 |
agent only |
buildInstructions full branch |
src/mcp/instructions.ts:116-138 |
agent (one sentence) |
Assembly is a three-way branch in buildInstructions
(src/mcp/instructions.ts:105):
scope === "writer"β returnWRITER_INSTRUCTIONSverbatim (src/mcp/instructions.ts:110).scope === "catalog"β returnCATALOG_INSTRUCTIONSverbatim (src/mcp/instructions.ts:111).- otherwise β
identityLine(agent)concatenated with four fixed paragraphs (memory contract, consolidated read views, preview budget) (src/mcp/instructions.ts:116-138).
What varies today: exactly one sentence, and only on one of three scopes.
identityLine renders either You are @<agent> on this Open Second Brain vault. (src/mcp/instructions.ts:91-94) or a refusal naming the unreadable
config (src/mcp/instructions.ts:96-102). Everything else is a literal.
agent is discarded on two of three scopes. The writer and catalog
branches return before agent is ever read (src/mcp/instructions.ts:110-111).
The writer scope is the always-loaded surface an agent carries in every
session β so on the surface where agent identity matters most, the current
code does not use agent at all.
vault is declared and never read. BuildInstructionsOpts.vault
(src/mcp/instructions.ts:26-27) is documented as "reserved for future
per-vault customisation" and does not appear anywhere in the function body
(src/mcp/instructions.ts:105-139). A test passes it anyway
(tests/mcp/mcp.test.ts:793).
Callers of buildInstructions, complete:
src/mcp/server.ts:313β the only production caller.src/mcp/index.ts:25β re-export.scripts/measure-token-surface.ts:62-63β token-budget report.tests/mcp/mcp.test.ts:792β writer-branch assertion.
2. How the block reaches a client
initialize is the only carrier. MCPServer.handleInitialize
(src/mcp/server.ts:295) returns instructions: buildInstructions({ agent, scope }) at src/mcp/server.ts:313. No other JSON-RPC method emits it; the
tools/list, resources/list, and tools/call handlers
(src/mcp/server.ts:320, :335, :352) never touch it.
It is re-computed on every initialize request β resolveIdentityOrReason
(src/mcp/server.ts:305, defined src/mcp/server.ts:433) reads the config
each time rather than caching at construction. But every input is
process-global:
resolveAgentNameorder isVAULT_AGENT_NAMEenv βagent_name/agentNamein the plugin config β the literal"agent"(src/core/config.ts:373-380).this.scopeis fixed at construction (src/mcp/server.ts:122).
handleInitialize reads only params["protocolVersion"]
(src/mcp/server.ts:296). clientInfo is never read anywhere under src/
(grep for clientInfo: zero hits). So the request carries no identity the
server consults.
Transport confirms the same:
- stdio β one process per client (
src/mcp/stdio.ts:46); the process's env/config is the agent. - HTTP β a single
MCPServerinstance is shared by every request (src/mcp/http.ts:52). Anmcp-session-idis minted oninitialize(src/mcp/http.ts:166) and never read back β grep shows exactly one occurrence. There is no per-session or per-client state of any kind.
Consequence: a client cannot receive a different block per agent over either transport. "One block per agent" is already expressible today, and only today, as "one server process per agent" β which is precisely how identity is configured now.
3. Where a per-agent block would be declared β nowhere, today
Two config files exist; neither can hold the value.
Plugin config (~/.config/open-second-brain/config.yaml, located by
resolveDefaultConfigPath, src/core/config.ts:120) is parsed by
parseSimpleYaml (src/core/config.ts:~148), which is a flat key: value
reader: "Lines that aren't key: value (comments, blanks, complex YAML) are
skipped." No nesting, therefore no map of agent β block.
Vault config (<vault>/Brain/_brain.yaml, src/core/brain/policy/load.ts)
is parsed by parseBrainYaml (src/core/brain/yaml-parse.ts:39). Its grammar
is stated at src/core/brain/yaml-parse.ts:9-24: top-level scalars, one
indented block level, and lists inside a block β "This intentionally rejects
nested mappings deeper than two levels". Scalars have no escape sequences and
there is no block-scalar (|) form, so a multi-line instruction body is not
expressible. Every block is additionally validated against a closed
KNOWN_KEYS list (pattern at src/core/brain/policy/blocks/discipline-report.ts:19),
so an arbitrary agent-name key would be rejected as unknown.
The only agent-keyed configuration that exists:
primary_agentβ a single scalar (src/core/brain/policy/primary-agent.ts:15,45).discipline_report.known_agentsβ a list of strings (src/core/brain/policy/blocks/discipline-report.ts:19,52).
Neither is a map from agent to anything.
Operator text already has two homes, both global:
Brain/standing-rules.mdβsrc/core/brain/standing-rules.ts:1-2, path constantsrc/core/brain/path-constants.ts:173, capped at 4000 chars (src/core/brain/standing-rules.ts:67), injected first and exempt from the adaptive budget (src/core/brain/standing-rules.ts:5-11).<vault>/VAULT.md, name configurable vialink_graph.vault_instruction_fileβsrc/core/brain/vault-instruction-file.ts:31-33, resolved atsrc/core/brain/vault-instruction-file.ts:100-108, line ceiling fromguardrails.instruction_file_max_lines(src/core/brain/config-template.ts:339, checkedsrc/core/brain/doctor.ts:305-308).
Both are delivered by brain_context, a tools/call surface
(src/mcp/brain/context-tools.ts:338 reads standing rules, :408 prepends
them; the vault instruction file is read in the enrichment just below), not by
initialize. Neither has a per-agent axis.
4. scope β what it selects, and orthogonality
The task's anchor is wrong. src/mcp/server.ts:79 is inside the
sendNotification doc comment. The real anchors are:
ToolScope = "full" | "writer" | "catalog"βsrc/mcp/tool-contract.ts:19.MCPServerRuntimeOptions.scopeβsrc/mcp/server.ts:59.- Stored per server β
src/mcp/server.ts:104, defaultedsrc/mcp/server.ts:122.
scope selects two things: which tools buildToolTable emits
(src/mcp/tools.ts:438, catalog branch src/mcp/tools.ts:540), and which
instruction constant is returned (src/mcp/instructions.ts:110-111). It is a
process-level flag, set by --scope / --writer-only / --tool-profile
(src/cli/main.ts:602,614-634,667) through resolveToolSurface
(src/mcp/profiles.ts:121-145).
Orthogonal in principle, entangled in fact. scope and agent identity are
independent inputs, but scope currently decides whether the agent axis is
consulted at all: writer and catalog discard agent
(src/mcp/instructions.ts:110-111). A per-agent block would therefore have to
be defined over (agent Γ scope), or the two constant branches would need an
identity line they deliberately do not have today.
5. The intake path, and every reader of source_agent
Types and stamp:
ExtractionIntakeβsrc/core/brain/intake/extract-intake.ts:61.IntakeOptionsβsrc/core/brain/intake/extract-intake.ts:66;agentat:68, documented as "Agent identity stamped as the entitysource_agent". There is no instruction field on it.intakeExtractionβsrc/core/brain/intake/extract-intake.ts:194; passesagent: opts.agentintoupsertEntityat:219.
Writes:
src/core/brain/entities/registry.ts:504β update arm,source_agent: input.agent.src/core/brain/entities/registry.ts:542β create arm,source_agent: input.agent.src/core/brain/entities/registry.ts:319β the field's slot inENTITY_FIELD_ORDER.src/core/brain/entities/registry.ts:620β carried forward unchanged on relate.src/core/brain/entities/registry.ts:705β carried forward unchanged on status change.
Readers, complete (grep source_agent|sourceAgent over src/):
src/core/brain/entities/types.ts:57βreadonly source_agent?: stringon the index entry.src/core/brain/entities/index-builder.ts:112,120β parsed off frontmatter into that index entry.src/cli/brain/verbs/entity.ts:39β rendered in CLI output.src/mcp/brain/entity-tools.ts:36β rendered in the MCP response.src/core/brain/frontmatter-tiers.ts:119β classified as tier"system"underbrain-entity.
Nothing filters, gates, routes, or selects on source_agent. It is written,
indexed, displayed, and tier-classified. The validator hint is correct.
Where the intake agent comes from at the MCP boundary:
src/mcp/brain/ner-tools.ts:34-36β optional per-callagentargument, elseresolveAgentName(ctx.configPath).src/mcp/brain/ingest-tools.ts:54-56β the same pattern.- Parsed at
src/mcp/brain/intake-args.ts:164.
So intake's agent is a per-call value. The instruction surface's agent
is not. Same word, two axes.
6. The four-piece closed-vocabulary idiom
Enforced by tests/core/architecture/verdict-vocabulary-census.test.ts. The
four pieces, all four required and all four in one module
(doc block :40-48):
const NAME = Object.freeze({ β¦ })whose every entry iskey: "string literal";- a derived union β
(typeof NAME)[keyof typeof NAME]; - a membership list built from it β
Object.values(NAME)or an array ofNAME.member; - a guard: a function or arrow whose parameter is typed
unknownand which reads the membership list or the object.
auditVocabulary (:374-404) enforces seven checks:
- the values object is frozen (
:378); - no duplicate value in the object (
:382); - no duplicate in the membership list (
:387); - every declared value is a member (
:392); - the guard accepts every declared value (
:393); - every member is declared (
:396); - the guard rejects every
NON_MEMBERSoutsider (:398-401) β the outsiders are""," ","unknown-vocabulary-member",null,undefined,42,{}(:363-371).
Registration is not optional: scanVocabularies walks src/
(:1285, invoked :1327) and CENSUS (:411) must account for every
vocabulary found; an entry in CENSUS that the scan cannot find is reported as
orphaned (:1423). There is no exemption list β the doc block states why
(:59-63).
Known blind spots the doc names (:66-97): a vocabulary split across modules,
a two-piece vocabulary, non-literal values, a guard typed string, trees other
than src/, and code inside a template interpolation.
ToolScope is not in this population. src/mcp/tool-contract.ts:19 is a
bare union β no frozen object, no members array, no guard. So the existing
scope axis does not follow the idiom, and a new selector built to the idiom
would sit beside a sibling that is not.
KNOWN_RUNTIME_TARGETS (src/core/identity-reminder.ts:41) is also out of
population: array plus derived type plus guard, but no frozen object, and
isRuntimeTarget takes string | undefined (src/core/identity-reminder.ts:45)
rather than unknown. It is the nearest existing "selector" and it must not be
copied as a template.
7. Existing "operator supplies text the server returns" mechanisms
Three exist. All three select on runtime or host β none on agent.
Per-runtime template files.
templates/identity-reminder.txtplustemplates/identity-reminder.<target>.txtforhermesandopenclaw(src/core/identity-reminder.ts:41). Read atsrc/core/identity-reminder.ts:57(common) and:92(per-target);{agent}is substituted at:138,:140; target comes from an explicit parameter orO2B_TARGET(:108-119); a missing per-target file silently falls back (:136-140). These files ship in the repo β they are install artifacts, not operator-authored vault content, and the module states that adding a target "is a PR-change β¦ not a runtime decision" (src/core/identity-reminder.ts:34-39).Per-runtime hook reminder.
postWriteReminder(hooks/lib/messages.ts:57) withpostWriteCadenceLine(hooks/lib/messages.ts:30-55) branching overHookRuntime(claudecode | codex | grok | unknown).Operator-authored vault text.
Brain/standing-rules.md(src/core/brain/standing-rules.ts) and<vault>/VAULT.md(src/core/brain/vault-instruction-file.ts), both delivered throughbrain_context(src/mcp/brain/context-tools.ts:338,408).
Mechanism 3 is the one that already answers "an operator writes text and the
server returns it". Building a per-agent instruction block on the initialize
path would be a fourth mechanism with a fifth text home.
What does not exist
- No per-agent configuration store, in the vault or in the device config.
Neither YAML grammar can represent a map from agent name to a text block
(Β§3). Nothing under
src/core/brain/policy/blocks/is keyed by agent. - No per-agent selection anywhere in the instruction path.
BuildInstructionsOpts(src/mcp/instructions.ts:13) exposesagent/vault?/scope?; onlyagentandscopeare read, andagentreaches one sentence on one branch. - No per-request or per-session identity.
clientInfois unread; the HTTP session id is minted and discarded (src/mcp/http.ts:166). - No instruction field on
IntakeOptions(src/core/brain/intake/extract-intake.ts:66-80). - No behavioural reader of
source_agentβ it is a display/index field only (Β§5). - No server-side extraction prompt to instruct. Extraction is agent-side;
the module header states the boundary explicitly:
"the model that produced the extraction lives on the agent side of the
MCP/CLI boundary. This primitive never calls a model"
(
src/core/brain/intake/extract-intake.ts:10-12), echoed atsrc/mcp/brain/ner-tools.ts:5.
Corrections to the premise
src/mcp/server.ts:79does not definescope. That line is inside thesendNotificationdoc comment.ToolScopeissrc/mcp/tool-contract.ts:19; the runtime option issrc/mcp/server.ts:59; the stored field issrc/mcp/server.ts:104.recall-tools.ts:720has nothing to do withagentstamping. That line is insidebrain_context_pack_outcome'spostbranch (src/mcp/brain/recall-tools.ts:700-735), returningevidenceon a context-pack outcome. Noagent, nosource_agent."
agentis only a LABEL" is right for intake and wrong for instructions. InIntakeOptionsit is a pure stamp (Β§5). InBuildInstructionsOptsit is not a label at all β it is rendered into a directive sentence (src/mcp/instructions.ts:91-94) or replaced by a refusal (src/mcp/instructions.ts:96-102). And on the writer and catalog scopes it is dropped entirely (src/mcp/instructions.ts:110-111), which is a sharper finding than "it is only a label": the always-loaded surface has no identity line whatsoever.These are two different
agentaxes, not one. Intake'sagentis a per-call tool argument with a server-resolved default (src/mcp/brain/ner-tools.ts:34-36,src/mcp/brain/ingest-tools.ts:54-56). The instruction surface'sagentis a process-level config value read at handshake (src/core/config.ts:373-380,src/mcp/server.ts:305). Turning the first into a selector says nothing about the second, and vice versa. The task treats them as the same field."Selectable by agent" is not reachable over the transport as designed. Both transports resolve identity from process env/config, never from the request (Β§2). Per-agent selection today collapses to per-process selection, which the install already provides by giving each agent its own
VAULT_AGENT_NAMEor config file. There is no new capability in "select by agent" unless a new identity channel is introduced β and introducing one (trusting a client-declared name) would put the identity an agent writes under into the agent's own hands, whichsrc/mcp/instructions.ts:17-23argues against by name."Give the block a home" is the real precondition, and it is not free. The task's own hedge is correct but understated: no operator can write a per-agent block anywhere today, and neither YAML grammar can be extended to hold one without either a third-level map (
src/core/brain/yaml-parse.ts:23rejects it by design) or a new file-per-agent convention that would be a fourth operator-text mechanism alongsidestanding-rules.md,VAULT.md, and thetemplates/identity-reminder.*.txtset (Β§7).
Smallest native unit that is true against this codebase
None of the shapes in the task body is a native unit as stated. The honest finding is that "select a per-agent instruction block" has no supplier, no home, and no transport channel. Stating that is the correct output.
Ranked by how native they are:
A. The true zero-invention unit β the writer scope has no identity line.
src/mcp/instructions.ts:110 returns WRITER_INSTRUCTIONS before agent is
read, so the always-loaded surface β the one an agent carries into every
session β never says which name to log under, while the full surface insists on
it (src/mcp/instructions.ts:91-94). The writer tools are exactly the
identity-bearing writers. This is a real gap in the existing design, needs no
new config, no new vocabulary, and no new file: prepend identityLine(agent)
to the writer (and catalog) branches. It also removes the entanglement noted in
Β§4. This is the smallest thing that is both true and worth doing here.
B. If a per-agent block is genuinely wanted, the home comes first and it is
the whole unit. The only native home is the one that already exists: an
operator-authored file delivered through brain_context, alongside
standing-rules.md and VAULT.md (Β§7, src/mcp/brain/context-tools.ts:338,408).
Not initialize.instructions β that path is process-global, capped by a token
budget the repo actively measures (scripts/measure-token-surface.ts:83-84),
and has no per-agent axis to hang anything on. Framing it as "extend the
existing operator-text lane with an agent-scoped variant" keeps one mechanism;
framing it as "per-agent block in initialize" invents a parallel one, which
this repo forbids.
C. What must NOT be built. A ToolScope-style selector union for
instruction sets, with no operator able to supply a second set, is a
do-nothing fallback with a type attached. Under the census rules (Β§6) it would
also have to ship the full four pieces plus a CENSUS registration for a
vocabulary whose only member is "default".
Recommendation: ship A, and reframe the kanban task from "select a block" to "the writer surface states no identity" plus a separate, later question about whether operator text needs an agent-scoped variant at all.
Defects noticed
Dead option field.
BuildInstructionsOpts.vault(src/mcp/instructions.ts:26-27) is declared, documented as reserved, and never read inbuildInstructions(src/mcp/instructions.ts:105-139). A test supplies it (tests/mcp/mcp.test.ts:793), which makes it look load- bearing. Delete it, or the next unit will "extend" it.Dead legacy-compat branch.
buildInstructionsacceptsBuildInstructionsOpts | stringwith a documented legacy string path (src/mcp/instructions.ts:105-108). All three call sites pass an object (src/mcp/server.ts:313,scripts/measure-token-surface.ts:62-63,tests/mcp/mcp.test.ts:792); grep finds no string-argument call anywhere outside.claude/worktrees/. The union widens the signature for nothing and forces twotypeof opts === "string"reads per call.ToolScopemembers are copied by hand into four places, with nothing asserting they agree. The type atsrc/mcp/tool-contract.ts:19; a literalenum: ["full", "writer", "catalog"]in the capabilities output schema atsrc/mcp/tools.ts:378; a re-declared inline union atsrc/cli/main.ts:762; and a hand-written list in the CLI error message atsrc/cli/main.ts:629. This is verbatim the drift class the census doc calls out β "a status list copied as a literal into a tool schema with nothing asserting the two agree" (tests/core/architecture/verdict-vocabulary-census.test.ts:16-18) β andToolScopeis out of the census population because it has neither a frozen object nor a guard. PromotingToolScopeto the four-piece idiom and registering it inCENSUSis a small, self-contained fix that any work on this axis would benefit from.HTTP mints a session id it never reads.
src/mcp/http.ts:166setsmcp-session-idon theinitializeresponse; grep finds exactly one occurrence in the file. The header advertises per-session state that does not exist β which is also why per-agent instructions cannot ride the HTTP transport without real work.isRuntimeTargetguard takesstring | undefined, notunknown(src/core/identity-reminder.ts:45). It is out of the census population (no frozen object), so nothing fails β but it is the nearest thing to an existing selector and it diverges from the idiom the repo enforces elsewhere.
Not a defect, corrected for the record: codegraph reports buildInstructions
as having "no covering tests". That is a false negative β the catalog branch is
covered at tests/mcp/catalog-scope.test.ts:104-113 and the unresolved-identity
branch at tests/mcp/config-read-failure-server.test.ts:134-143, both through
handleInitialize rather than by calling the function directly.