Macula Mesh Use Build Macula for… Docs Contact

Macula · Martha · docs from Martha v0.4.1

The host contract and the ledger

This exists so that a member refreshed in the middle of a package can see which of its predecessor's pushes, handoffs, room messages and tags were sent and never confirmed, and check them instead of sending them twice; and so that the same code does this on every coding tool Martha runs in.

Both are the first step of the port map, as designed on issue #1.

The host contract

src/host_contract/host_contract.ts is everything the crew core may ask of a coding tool. It has five parts, and a test fails by name if a sixth appears:

Part What a host gives
clock the time
stores rows: streams that are only ever appended to; documents: files read as text; launches: the launcher's records, one row per key, which slices only read; the writable store is the launcher's own seam, outside the contract (#42)
processes running a command and getting its exit status and output; identityOf(pid): which process holds a pid, boot included (#42)
delivery handing a turn to the model, and the turns that arrive, with where each came from as far as the tool can say
tools registering a tool the model can call

Nothing in it decides anything, and settings are not in it: they come from the crew's declaration. An append can name the length it expects the stream to have, so two writers that read the same stream cannot both act on what they read. A stream name is an opaque key: an adapter encodes it before it touches a path, a table or a URL.

The contract also holds the words a host uses to say where a turn came from (Arrival, TurnSource, TurnOrigin). The publish gate's slices read them from here. The contract file imports nothing, and a test holds it to that.

It also holds the words a host's adapter hands the core what its host reported in, so that one entry answers every host (src/answer_what_a_host_reports,

541):

Word What it carries Answered with
AStartingSession the session, the outcome its host's own table gives the start event (SessionStartOutcome: fresh, same_id or inherits; none for an event the table does not declare, which has lost its record), and the predecessor the host names TheAnswerToAStart: refused and why, or taken with what the session is handed as it starts
ArrivingTurn a turn's text, and its Arrival TheAnswerToATurn: kept, or refused and why; a refused turn is never raised
AReviewTheHostSawFail the session, the turn's text, and the origin kind the engine stamped on it nothing: a review the host reports failed is named on the owner's row and to the member, only for a session the entry holds
ACalledTool the session, the tool by the name the host called it, its input, the host's id for the call when it gives one, and the agent that made the call when an agent of the session made it TheAnswerToACall: allowed, or denied and why; only the adapter writes its host's own yes
AResultOfACall the called tool as above, after it ran: the host's answer passed through untouched, whether the called name is a tool server's, what the answer holds where it names an agent, and the model a spawned agent resolved to TheAnswerToAResult: taken, with the end of the turn it carries when it was the last call in flight under a held end, or the member stops and why
AnAgentOfASession the session, and the agent the host says started or stopped under it TheAnswerToAnAgent: taken, or refused and why; an agent that stops unvouched for has its answer recorded as a subagent's text
ACrewToolAsked the session, the crew tool's own name, and its arguments the crew's own answer, or refused and why; a session the crew refreshed is taken in first

The entry never reads a host's own table. The adapter turns the host's event into its outcome and its prompt origin into an Arrival, and it hands the envelope its host writes for a failed agent to the launch as a value. For a result it reads the three facts the core needs out of its own host's answer, and hands its table of result rows and its decisions over its own files to the launch as values and closures (WhereAResultIsRecorded).

The core imports nothing but its own slices and Node's standard library. A test reads every script file under src/ (TypeScript and JavaScript, every extension) and names any other import, including a dynamic import whose name is computed, so a coding tool's API cannot creep in past the contract.

Every slice is tested against host_for_tests.ts, a host that lives in memory and keeps the same promises.

On Claude Code

src/claude_code_host/ implements the contract on Claude Code (#41). It is a host adapter, declared in package.json martha.hostAdapters with the relay mod (src/claude_code_relay/) and the launcher (src/launch_a_claude_code_member/). None of the three is a slice, and an adapter may import the contract, node:*, host glue and slices, never a test or a program. It decides nothing: it composes the engine's clock, prompt submission and tool registration with two pieces of glue any POSIX host can use, src/row_streams_directory/ for the rows and src/linux_process_identity/ for the launcher's records and which process holds a pid.

One file inside an adapter is a decision rather than the adapter's own machinery: martha.decisionFiles names it, and the slice rule's Node modules apply to it wherever it sits, so it reads the machine through the contract and imports no Node module but pure computation (node:path, node:crypto). Declaring a file this way says which other rules it is still outside of; today that is one file, the one that reads a member's own write back (src/launch_a_claude_code_member/remember_own_write_of_a_call.ts, martha#158).

A program a script runs, such as the launch probe (npm run probe:launch), is not a slice either, and it may be cut into several directories to stay under the slice cap. martha.programParts names each such directory and the program it belongs to. The core's rules treat a part like its program, and the part is still held to the slice cap. In exchange, only its program and that program's other parts may import it. prove_the_core/what_the_core_may_reach/a_program_part_is_loaded_by_its_program_alone.ts names any other file that does (martha#443).

The launcher's wiring (who writes the records) waits for #16's launch gate.

The ledger

src/log_ledger/log_ledger.ts keeps one append-only stream per work package:

Failure What happened May the caller send it again?
ACT_NOT_SENT the row was not kept, so the act never ran yes, unless row_may_stand_at is set: a row on that stream was linked and could not be made durable (ROW_NOT_DURABLE), this act's or another act's whose append failed earlier, so it may stand as an act left awaiting, and the store takes no more rows on that stream in this process
the act's own error the act failed, and that is its kept outcome as for any failed act
OUTCOME_NOT_KEPT the act ran, and its outcome is not in the ledger never: check it first

Every act sent through sendOutwardAct has its row first. Room messages go through it in send_a_crew_message, handoffs in read_a_crew_line, and the deletion of a worktree's branch on origin in open_and_finish_a_worktree. No other slice sends one: a member pushes with git in its own shell and a tag goes out from CI, so a push or a tag of Martha's own gets a row the day Martha has a sender of one. - What is unresolved: actsAwaitingOutcome returns every act with no outcome. A successor checks each one (is the push on the remote? did the handoff arrive?) and records what it found with concludeAct. An outcome for an act never announced, or a second outcome for the same act, is refused.

A package is an issue, owner/repo#n; any other name is refused before it names a stream. A row the ledger cannot read is refused rather than skipped, because skipping it could hide an act that was sent, and so is a row filed under another package's stream.

A handover as a ledger row, naming the last row it covers, comes with the hand_over_at_limit slice.

Martha's docs, from release v0.4.1: Getting started: a crew of two on your own project · @macula-io/martha · Martha · The agent control loop · claw-code: what it is, where it comes from, what Martha can learn · The host contract and the ledger · How a release is made · Nothing private gets in · The port map, in summary · The publish gate · The crew's declaration