Managed Mailbox Compatibility Scripts¶
This page documents the optional compatibility helper surface under rules/scripts/ when a filesystem mailbox publishes it.
Ordinary mailbox work should use pixi run houmao-mgr agents mail resolve-live, gateway /v1/mail/* when available, and pixi run houmao-mgr agents mail ... when it is not. The scripts documented here matter for repair, debugging, and intentionally direct filesystem workflows, not for the default attached-session path.
Mental Model¶
The managed scripts are a compatibility mutation boundary.
- The runtime may materialize them into the mailbox-local
rules/tree. - Operators and sessions can inspect them, but should not replace them with improvisational equivalents.
- Each wrapper validates one JSON payload through strict shared models before calling the underlying handler.
- Each wrapper prints exactly one JSON object to stdout for both success and failure.
That contract keeps direct compatibility workflows predictable even when different sessions are sharing one mailbox root.
Published Asset Set When Present¶
Current managed script filenames:
register_mailbox.pyderegister_mailbox.pydeliver_message.pyinsert_standard_headers.pyupdate_mailbox_state.pyrepair_index.py
Shared dependency manifest:
rules/scripts/requirements.txt- Current third-party requirements:
pydantic>=2.12andPyYAML>=6.0 - The invoking environment must also have the
houmaopackage available
Stable CLI Shape When Present¶
All managed Python wrappers use:
--mailbox-root <path>--payload-file <path>for payload-driven scripts
Current exception:
repair_index.pyallows--payload-fileto be omitted and defaults to{}.
The wrappers emit newline-terminated JSON to stdout and return process exit code 0 on success or 1 on handled failure.
sequenceDiagram
participant Inv as Invoker
participant Scr as Script
participant Val as Shared request<br/>validation
participant Hdl as Handler
Inv->>Scr: --mailbox-root<br/>--payload-file
Scr->>Val: load JSON payload<br/>and validate
alt payload valid
Val->>Hdl: typed request
Hdl-->>Scr: result dict
Scr-->>Inv: one JSON object<br/>exit 0
else payload invalid or safe error
Val-->>Scr: validation error
Scr-->>Inv: {\"ok\": false, ...}<br/>exit 1
end
Validation Expectations¶
The shared request models are strict:
- extra fields are forbidden,
- models are frozen and strict,
- blank required strings are rejected,
- addresses and message ids are validated against the same mailbox rules used elsewhere,
- validation errors are normalized into a field-path-oriented message such as
$.to[0].address: ....
The wrapper reports up to five validation issues in one error string. Validation failure happens before any mailbox mutation.
Representative failure:
{
"ok": false,
"error": "delivery payload: $.to[0].address: mailbox addresses must be full-form email-like values such as `research@houmao.localhost`"
}
Script-Specific Contracts¶
register_mailbox.py¶
Payload fields:
mode:safe,force, orstashaddressowner_principal_idmailbox_kind:in_rootorsymlinkmailbox_path- optional
display_name,manifest_path_hint,role
deregister_mailbox.py¶
Payload fields:
mode:deactivateorpurgeaddress
deliver_message.py¶
Payload fields include:
staged_message_pathmessage_id,thread_id,in_reply_to,references,created_at_utcsender,to,cc,reply_tosubject,attachments,headers
update_mailbox_state.py¶
Payload fields:
addressmessage_id- at least one of
read,starred,archived,deleted
repair_index.py¶
Payload fields:
- optional
cleanup_stagingdefaulttrue - optional
quarantine_stagingdefaulttrue
insert_standard_headers.py¶
This script is materialized as part of the compatibility asset set, but the current build reserves it rather than implementing header normalization. It emits a structured failure result instead of silently doing nothing.
Source References¶
src/houmao/mailbox/managed.pysrc/houmao/mailbox/assets/rules/README.mdsrc/houmao/mailbox/assets/rules/scripts/requirements.txtsrc/houmao/mailbox/assets/rules/scripts/register_mailbox.pysrc/houmao/mailbox/assets/rules/scripts/deregister_mailbox.pysrc/houmao/mailbox/assets/rules/scripts/deliver_message.pysrc/houmao/mailbox/assets/rules/scripts/update_mailbox_state.pysrc/houmao/mailbox/assets/rules/scripts/repair_index.pysrc/houmao/mailbox/assets/rules/scripts/insert_standard_headers.py