Documentation
¶
Overview ¶
Package host isolates what is specific to the agent host a mash session runs in (Claude Code today), so other hosts (Hermes, Pi) can plug in later. An Adapter says how a host's hook invocation is read, who owns a session's spool, how spooled mail is presented, and how serve's wake is delivered.
The wake is today the MCP channel notification serve already passes to the endpoint as its Deliverer; Waker is the seam through which an adapter shapes it. A future durable adapter (issue #43: explicit receive/ack MCP tools, a startup-declared durable mode) will extend this interface; it is deliberately not built here.
Index ¶
- Constants
- Variables
- func IsOtherLaunch(why string) bool
- func Known() []string
- func Notice(event, text string) []byte
- func OwnerPID(owner string) int
- func Utf16Len(s string) int
- func WaiterAncestor(ownerPID int, waiters []int) int
- type Adapter
- type Claude
- func (Claude) Match(owner string, h HookIdentity) (bool, string)
- func (Claude) Name() string
- func (Claude) OwnerToken(env func(string) string) string
- func (c Claude) Owns(owner string, h HookIdentity) bool
- func (Claude) Present(p Presentation, waiting []spool.Entry) ([]byte, []spool.Entry)
- func (Claude) SpoolsFromStart() bool
- func (Claude) Trigger(stdin []byte, env func(string) string) (Trigger, bool)
- func (Claude) Waker(notify func(text string, meta map[string]string) error) func(text string, meta map[string]string) error
- type HookIdentity
- type Presentation
- type Trigger
Constants ¶
const MinClaudeCode = "2.1.312"
MinClaudeCode is the oldest Claude Code a live receipt passed on; raise it with each receipt, never lower it. mash does not refuse older versions; `status` warns below it.
Variables ¶
var Ancestors iter.Seq[int] = func(yield func(int) bool) { pid := os.Getppid() for i := 0; i < maxAncestors && pid > 1; i++ { if !yield(pid) { return } next, err := parentOf(pid) if err != nil { return } pid = next } }
Ancestors yields the process ids above this one, nearest first, lazily (at most 10 levels, stopping at pid 1 or on an error): each level is a lookup (a /proc read, a sysctl, or a forked ps), so a caller that finds what it wants stops early. A var so tests can stub it. The hook is a descendant of the Claude process whose serve child owns the spool, normally its parent or grandparent.
Functions ¶
func IsOtherLaunch ¶ added in v0.3.1
IsOtherLaunch reports whether a Match refusal reason is the other-launch case.
func Notice ¶ added in v0.3.1
Notice renders text as Claude Code hook additionalContext for event, in the shape Present uses.
func OwnerPID ¶ added in v0.3.1
OwnerPID is the Claude process pid an owner record (JSON or legacy "pid:N") names, 0 if none.
func Utf16Len ¶
Utf16Len exposes utf16Len to tests of other packages that assert the Claude Code cap.
func WaiterAncestor ¶ added in v0.3.1
WaiterAncestor is the first of waiters that is among the hook's ancestors, provided the owner (ownerPID) is not itself a waiter and not among the ancestors; 0 otherwise.
Types ¶
type Adapter ¶
type Adapter interface {
Name() string
// Trigger reads a host hook invocation; ok=false means it is not a delivery point for us (do nothing).
Trigger(stdin []byte, env func(string) string) (t Trigger, ok bool)
// OwnerToken is what the lease-holding serve records as the spool's owner. env reads serve's environment.
OwnerToken(env func(string) string) string
// Owns reports whether this hook process may drain a spool recorded with owner.
Owns(owner string, hook HookIdentity) bool
// Match is Owns with the reason: which rule matched, or why every rule failed.
Match(owner string, hook HookIdentity) (ok bool, why string)
// Present renders entries for the host; shown are the entries actually rendered (only they are drained).
Present(p Presentation, entries []spool.Entry) (out []byte, shown []spool.Entry)
// SpoolsFromStart is true when the host takes no channel delivery (Pi never sees the channel notification): serve
// then spools mail from its first message and acks only what a hook drained, never on a channel write.
SpoolsFromStart() bool
// Waker returns the delivery serve uses to wake the session, given the MCP channel notification.
Waker(notify func(text string, meta map[string]string) error) func(text string, meta map[string]string) error
}
Adapter is how mash talks to the agent host a session runs in (Claude Code today).
type Claude ¶
type Claude struct{}
Claude is the adapter for Claude Code: PostToolUse and UserPromptSubmit hooks, additionalContext output.
func (Claude) Match ¶
func (Claude) Match(owner string, h HookIdentity) (bool, string)
Match decides whether the hook belongs to the session whose serve holds the lease. Any one of three rules, cheapest first, is enough; a hook that matches none is refused, and no rule adopts an unknown session:
- session: the hook's session id equals serve's (both non-empty), unless both launch tokens are non-empty and differ (another launch of the same session, ADR 0043);
- launch: both launch tokens are non-empty and equal (stable across /clear);
- process: serve's parent pid is among the hook's ancestors (covers /clear on the plain CLI).
Before them: a hook that descends from a serve recorded as waiting for the lease, and not from the owner, is refused as another launch (ADR 0043), tokens or not.
A legacy owner ("pid:N" text) is checked by rule 3 alone; an empty or other older owner is accepted.
func (Claude) OwnerToken ¶
OwnerToken is the JSON owner record of the serve that holds the lease: its parent pid, its CLAUDE_CODE_SESSION_ID and its MASH_LAUNCH_TOKEN.
func (Claude) Owns ¶
func (c Claude) Owns(owner string, h HookIdentity) bool
Owns reports whether the hook may drain a spool recorded with owner; see Match.
func (Claude) SpoolsFromStart ¶
SpoolsFromStart: Claude Code takes channel events, so mail is the channel's until a hook first runs.
type HookIdentity ¶
HookIdentity is what a hook process knows about the session it runs in: its session id (from its environment, else the hook's stdin), the launch token (MASH_LAUNCH_TOKEN) it inherited, and the pids of the serves recorded as waiting for the lease (spool.Waiters, ADR 0043).
type Presentation ¶
type Presentation struct {
Name, Owner string
Event string // the Trigger's event, for hosts that echo it
BatchMsgs, BatchBytes int
}
Presentation is what Present needs to render a batch.