Skip to content

Canonical Operations

Every mutating or policy-relevant action in Moneypenny flows through the canonical operation layer. This is the single execution path — CLI, HTTP, sidecar, and MCP all compile down to the same operations.

Why Canonical Operations

Without a canonical layer, each transport adapter (CLI, HTTP, sidecar, MCP) would implement its own business logic, leading to divergent behavior and security gaps. The canonical operation layer guarantees:

  • Consistent policy enforcement across all entry points
  • Uniform audit trail regardless of how an action was triggered
  • Single place to add hooks (pre/post processing, transformation)
  • No adapter-specific business logic — adapters only translate wire formats

Operation Envelope

Every request follows this structure:

{
"op": "namespace.action",
"args": { ... }
}

Every response uses a standard envelope:

{
"ok": true,
"code": "success",
"message": "Operation completed",
"data": { ... },
"policy": {
"effect": "allow",
"policy_id": "pol_abc123"
},
"audit": {
"recorded": true
}
}

Execution Pipeline

Every operation follows these steps in order:

1. Parse operation envelope
2. Resolve context (actor, session, tenant)
3. Pre-policy evaluation
4. Pre-hooks (DB-backed hook registry + baseline guardrails)
5. Handler execution
6. Post-hooks (DB-backed hook registry + baseline redaction)
7. Secret redaction + audit write
8. Standard result envelope

Steps in Detail

Parse — validate the operation name and argument schema.

Resolve context — determine who is making the request (actor), which session it belongs to, and any tenant scoping.

Pre-policy — evaluate the action against the policy engine before executing anything. If denied, return immediately with the denial reason.

Pre-hooks — run registered pre-hooks from the DB hook registry. Hooks can transform arguments or abort the operation. Baseline guardrails (e.g. argument validation) run here.

Handler — execute the actual operation logic (insert a fact, run a search, create a job, etc.).

Post-hooks — run registered post-hooks. These can transform output before it’s returned.

Redaction + audit — scrub sensitive content from the result using the 18-pattern secret redaction engine, then write the audit record.

Envelope — wrap the result in the standard response envelope with policy and audit metadata.

Operation Catalog

Memory Operations

OperationArgumentsDescription
memory.searchquery, limitHybrid search across all stores
memory.fact.addcontent, summary, pointer, confidence, keywordsStore a fact
memory.fact.updateid, content, summary, pointerUpdate a fact
memory.fact.getidRetrieve a fact
memory.fact.compaction.resetidReset compaction state
fact.deleteidSoft-delete a fact

Knowledge Operations

OperationArgumentsDescription
knowledge.ingestpath or urlIngest a document

Policy Operations

OperationArgumentsDescription
policy.addname, effect, action, resource, …Add a rule
policy.evaluateactor, action, resourceEvaluate an action
policy.explainactor, action, resourceExplain a decision

Skill Operations

OperationArgumentsDescription
skill.addname, description, contentAdd a skill
skill.promoteidPromote retrieval weight

Job Operations

OperationArgumentsDescription
job.createname, schedule, job_type, payloadCreate a job
job.listList all jobs
job.runidTrigger immediately
job.pauseidPause scheduling
job.historyid (optional)View run history
job.spec.plandescriptionPlan a job (agent flow)
job.spec.confirmspec_idConfirm a planned job
job.spec.applyspec_idApply a confirmed job

JS Tool Operations

OperationArgumentsDescription
js.tool.addname, description, source, parameters_schemaRegister a tool
js.tool.listList JS tools
js.tool.deletenameRemove a tool

Session Operations

OperationArgumentsDescription
session.resolvesession_id (optional)Resolve or create a session
session.listlimitList recent sessions

Agent Operations

OperationArgumentsDescription
agent.createnameCreate a new agent
agent.configname, key, valueUpdate configuration
agent.deletenameDelete an agent

Audit Operations

OperationArgumentsDescription
audit.queryquery, limitSearch audit records
audit.appendaction, resource, messageWrite an entry

Ingest Operations (External Events)

OperationArgumentsDescription
ingest.eventssource, fileIngest external events
ingest.statussource, limitCheck run status
ingest.replayrun_id, dry_runReplay a prior run

Transport Mapping

Each transport adapter maps to canonical operations:

TransportHow It Works
CLIclap commands map to operations; mp facts listmemory.fact.list
HTTPPOST /v1/ops accepts the JSON envelope directly
SidecarJSONL over stdin/stdout, one operation per line
MCPMCP tool calls are translated to canonical operations

The agent loop itself uses canonical operations for internal mutations (fact extraction, audit writes, session management). There are no hidden “agent-only” mutation paths.