Skip to content

examples: send-first, sign and submit a thread's first message - #15

Merged
ZacxDev merged 5 commits into
mainfrom
feat/example-send-first-message
Nov 3, 2026
Merged

ZacxDev merged 5 commits into
mainfrom
feat/example-send-first-message

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Adds go/examples/send-first, a small tested program that signs one direct msg and submits it, so a client that only sends replies can have its first message sent from the other side. Spec sections touched: none (it uses §3, §4, §7.2 and §8 POST /v1/submit as written).

What it does

  • Reads the signing key from --key FILE: one line, base64url (no padding) of a 32-byte Ed25519 seed, decoded canonically, at most 128 bytes read (a longer file is refused without repeating its contents). Never from argv or the environment; a stray positional argument is refused, and only its length is reported, never its value.
  • Builds a msg with v, t, from, ts (Unix ms), to, body, optional subject, and no re. An empty subject is omitted. Before signing it checks only that subject and body are valid UTF-8, because Go's json encoder would silently replace invalid bytes. --max-body N is an optional stricter body limit, in bytes, for a recipient whose client accepts less (for example 16384).
  • Signs with clankmail.Sign and runs clankmail.Verify on the result. That gate is where the §7.2 field rules are enforced (recipient shape, count and uniqueness; body 1-32768 bytes; subject 1-200 bytes) along with the §4 98304-byte token limit. The program does not keep its own copy of these rules. A message Verify refuses exits 2 with Verify's error, and nothing is sent. Otherwise the token is posted as text/plain.
  • Exit 0 and the m_ id on stdout only when the hub answers 2xx with this message's id. Exit 1 on any non-2xx (error code and detail printed quoted to stderr), a redirect (not followed), a 2xx without the right id, or a network error. Exit 2 on input errors, which send nothing.

README: a "Send a first message" section and a Layout row. The section is outside "Try it in 30 seconds", so make readme-snippets extracts the same blocks as before. The README and the package doc tell people to use @main because the v0.3.0 tag does not contain the example. They will pin a tagged release once one that includes it is cut.

Tests

  • go/examples/send-first/main_test.go (root module, runs under make conformance-go):
    • exact payload fields; the signature verifies and the id matches; an empty subject is omitted
    • inputs at each §7.2 limit build and verify
    • invalid UTF-8 in the body or subject is refused
    • key-file parsing; a key file over 128 bytes (129 bytes and 1 MiB) exits 2 with the key file is longer than 128 bytes, nothing sent and nothing of the file on stderr
    • schema-invalid input exits 2 with Verify's E_SCHEMA error and makes zero requests to the fake hub: 33 keys, a duplicate key, a channel plus a key, a handle, an empty body, 32769-byte and 32770-byte (multibyte) bodies, a 201-byte subject
    • --max-body is counted in bytes
    • hub refusals exit 1 with empty stdout: 400/403/429/500, a 2xx with a wrong id or no id, 400/404/500 carrying the real id, and an unreachable hub
    • redirects are not followed: 307, 308 and 302 with a Location naming a second fake hub that would accept the message exit 1, and that hub receives zero submissions
    • the 64 KiB response cap: a 200 whose real id comes after the cap exits 1 (200 OK without an m_ id); the same answer with the id under the cap exits 0
    • usage errors exit 2 and send nothing; a stray positional argument (SECRETSEED) is absent from stderr
  • go/hub/example_send_first_test.go (runs under make hub-test): builds the program from this checkout and runs it against an in-process hub. It checks only the seam: the message is accepted, and the printed id fetches the stored signed message (same id, sender, body and subject). Queue placement and refusal paths are covered elsewhere.

Mutation battery, last commit (one at a time, restored from a copy; the main.go checksum matched afterwards): 4/4 killed, each by its own assertion.

  • CheckRedirect deleted: 307 to an accepting hub: exit 0 stdout "m_…\n" stderr ""; want exit 1, empty stdout, stderr containing "307 Temporary Redirect" and origin received 1 submissions, target 1; want 1 and 0 (the same for 308; the 302 case fails only on its stderr, since a followed 302 becomes a GET)
  • the argument echoed again: key as argv: stderr "send-first: unexpected argument \"SECRETSEED\" (…)"; want "unexpected positional argument (10 bytes); the key is read from --key FILE, never from argv" and no trace of the argument
  • LimitReader replaced by the raw body: 200 with 65536 bytes of padding before the id: exit 0 … want 1
  • the key-file length check removed: 129-byte key file: exit 2 … stderr "send-first: not a ClankMail key file (…)"; want … stderr containing "the key file is longer than 128 bytes" (and the same for 1 MiB)

Mutation battery, earlier commits (not re-run at this head): 8/8 killed.

  • Verify gate disabled. Every schema case fails with hub received 1 requests, want 0 and exit 1 ... want exit 2 ... stderr containing "the signed message does not verify: E_SCHEMA: ...". The token too large usage case fails too.
  • UTF-8 check removed for the body: invalid UTF-8 body: want error containing "valid UTF-8", got <nil>, and at the program level invalid UTF-8 body: exit 0 ... / usage errors sent 1 submissions
  • UTF-8 check removed for the subject: invalid UTF-8 subject: want error containing "valid UTF-8", got <nil>
  • UTF-8 check removed entirely: both of the above
  • --max-body ignored: body over a 16384 limit: exit 0 stderr "", want 2 and "body is 16386 bytes; --max-body is 16384"
  • --max-body counted in characters: the same assertion
  • printing a different id, killed in the hub seam test: GET the printed id "m_aaaa…": status 404
  • skipping the submit while still printing the real id, killed in the hub seam test: status 404

Gates run locally (Go 1.26.8)

  • make conformance-go: clankmail 166 and send-first 14 tests passed, 0 failed
  • make hub-test (-race): 83 passed, 0 failed
  • make hub-consumer-check: ok
  • make readme-snippets: go, python, ts, read, read-sig and read-swap all ok
  • go vet and gofmt -l on go/examples/send-first: clean
  • At the last commit only the gates above were re-run; the ones below are from the previous head
  • make conformance-python: 165/165
  • make conformance-ts: 165 passed
  • make smoke-local: 10/10
  • genvectors output is byte-identical to vectors/vectors.json

🤖 Generated with Claude Code

go/examples/send-first signs one direct msg (SPEC.md §7.2, no re) with a
key read from a file (one line, base64url of a 32-byte seed; never argv or
env), runs the signed token through the §4 pipeline, submits it to
<hub>/v1/submit and prints the m_ id. Client-side checks: to is one c_ id
or 1-32 unique k_ ids, body 1-32768 bytes (lowerable with --max-body),
subject 1-200 bytes when present, valid UTF-8. Exit 0 only on a 2xx that
carries this message's id; 1 on any refusal, redirect or network error;
2 on input errors, which send nothing.

Tests: unit tests in the root module (payload fields, signature verifies,
limits at and past each boundary, refusals) and an end-to-end test in
go/hub that builds the program and runs it against an in-process hub
(accepted into the recipient's requests queue; E_STALE from a skewed hub
exits 1). A 17-mutant battery (sign with the wrong key, no domain
separator with the program's own Verify gate off, status check off,
limits off by one, bytes vs runes, ts truncated) was killed 17/17.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ZacxDev added a commit to ZacxDev/muster that referenced this pull request Nov 3, 2026
Replace the embedded hand-signed Go program in section 3 step 5 with a
link to the tested go/examples/send-first program in the ClankMail repo
(ZacxDev/clankmail#15) and its go run command. The side that starts the
conversation sends the first message with it; the other side replies
through its plugin. --max-body 16384 covers muster's 16 KiB chief-body
limit, so the separate limit sentence is dropped.

Drop the stale "v0.134.0 and earlier do not contain it" release sentence
and keep only the `version` probe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev

ZacxDev commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Audit round 0 (requirements & deletion pass) at 48b0e4e. Verdict: deletion candidates D1, D2; proceed to the checklist. No open premises.

D1 — delete send-first's hand-copied §7.2 checks (checkTo, isID/b32, MaxBody/MaxSubject/MaxKeyRecip length checks, dead ts<0) — the post-sign clankmail.Verify gate already enforces schema.go's msg/isTo rules with exit 2; keep only the UTF-8 check and --max-body
D2 — trim go/hub/example_send_first_test.go to the program↔real-hub seam (accepted + id matches); its requests-vs-inbox and E_STALE assertions re-test hub behaviour that hub_test.go and the fake-hub unit tests already cover

Ledger: round 0 · requirements: 11 (unattributed: 0, UNATTRIBUTED-UNKNOWN: 8) · deletion candidates: 2

The program copied the msg rules from go/clankmail/schema.go (recipient
shape and count, body and subject lengths, ts sign). The post-sign
clankmail.Verify already enforces them, exits 2 and sends nothing, so the
copies go. Kept: the UTF-8 check (Go's json encoder would silently
replace invalid UTF-8) and --max-body, now a caller-chosen stricter limit
(0, the default, applies only the spec's).

Tests: schema-invalid input (33 keys, duplicate key, channel plus key,
a handle, empty, 32769-byte and 32770-byte bodies, 201-byte subject) is
refused with exit 2, Verify's error on stderr, and zero requests to the
fake hub. The hub test is trimmed to the seam: the message is accepted
and the printed id names the stored signed message.

The doc comment says @main, as the README does; @latest is v0.3.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev

ZacxDev commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Round 0 dispositions: D1=applied (ccaff32: hand-copied §7.2 checks removed; Verify gate refuses schema-invalid input with exit 2 and zero requests, UTF-8 check and --max-body kept), D2=applied (ccaff32: hub test trimmed to the program/real-hub seam).

@ZacxDev

ZacxDev commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Audit round 1 (full checklist) at ccaff32: no 🔴, so the ladder ends. Gates re-run independently (conformance-go 166 + 11, hub-test 83, hub-consumer-check ok, Go 1.22.0 minimum ok; go run …/send-first@ccaff32 builds from the proxy). Two 🟡 and two 🟢, fixed in a final commit without another round:

1. redirect test now uses a real Location to an accepting hub and asserts exit 1 with zero submissions at the target (kills a CheckRedirect deletion)
2. a stray positional argument is no longer echoed to stderr; the SECRETSEED test asserts it is absent from stderr
3. a test pins the 64 KiB response cap
4. key file read is bounded, and the README states the 0600 expectation

ZacxDev and others added 3 commits November 3, 2026 11:54
…y file

- The redirect case now redirects (307, 308, 302) with a Location naming
  a second hub that would accept the message, and asserts exit 1 and
  zero submissions at the target. Without CheckRedirect the 307 and 308
  cases deliver the message and exit 0, so the test now fails.
- A stray positional argument is no longer echoed: only its length is
  reported, since a key pasted on the command line most likely ends up
  there. The argv test asserts the value is absent from stderr.
- A test pins the 64 KiB response cap: a 200 whose id comes after the
  cap exits 1.
- The key file read is bounded to 128 bytes; a longer file is refused
  (exit 2) without repeating its contents. README: keep it mode 0600.
- Package doc: exit 0 only when the hub answers 2xx with that message's id.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The flag package quotes the offending argument ("flag provided but not
defined: -<arg>", "invalid value \"<arg>\" for flag ..."), and a base64url
key pasted on the command line can start with '-'. Its output is now
discarded and only the kind of error is printed; -h still prints usage.
Tests cover a key pasted as an unknown flag and as a flag value; restoring
the echo fails both with the leaked value in stderr.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
v0.3.1 will be cut from this PR's merge commit, the first tag that
includes the example, so the README and the doc comment pin it instead of
following @main for a program that reads a private key.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev
ZacxDev marked this pull request as ready for review November 3, 2026 18:16
@ZacxDev
ZacxDev merged commit 980e0eb into main Nov 3, 2026
6 checks passed
ZacxDev added a commit to ZacxDev/muster that referenced this pull request Nov 3, 2026
ZacxDev/clankmail#15 merged and v0.3.1 is the first tag carrying the
example: the link now points at tree/v0.3.1 and the go run is pinned to
@v0.3.1 (verified to resolve through the module proxy and to parse the
documented flags).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ZacxDev added a commit to ZacxDev/muster that referenced this pull request Nov 3, 2026
* docs: onboarding a ClankMail peer (docs/clankmail.md)

A step-by-step guide for pairing two operators' muster chiefs over
ClankMail with the muster-clankmail plugin: the trust model, keys and the
handle ceremony, the plugin token, running it beside muster (container,
compose, Kubernetes notes), pinning peers, the first message, day-to-day
approvals and key changes, and the error strings the plugin emits.

There is no outbound-first path yet (the plugin only replies; compose
drafts are not shipped), so the guide gives a small program that signs a
first message with the chief key using the public ClankMail library.

docs/plugins.md said a thread is bound by muster-clankmail's
`send --bind <session>`; that command does not exist. It now says the
plugin has no send command and the first sender binds the thread by hand.

Verified locally against a throwaway hub (clankmail main 85b8d43) and the
image built from this branch: keygen, identity claim/grant, show,
/health, peer verify, requests, a stranger listed and not delivered, the
hand-signed first message delivered as sender_verified on its own root,
an approved reply reaching the other side on the same root, and the
config/disabled-peer/E_AUTH strings in the troubleshooting table (muster
was a stub answering the plugin routes, not a real server).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(clankmail): first message via ClankMail's send-first example

Replace the embedded hand-signed Go program in section 3 step 5 with a
link to the tested go/examples/send-first program in the ClankMail repo
(ZacxDev/clankmail#15) and its go run command. The side that starts the
conversation sends the first message with it; the other side replies
through its plugin. --max-body 16384 covers muster's 16 KiB chief-body
limit, so the separate limit sentence is dropped.

Drop the stale "v0.134.0 and earlier do not contain it" release sentence
and keep only the `version` probe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(clankmail): placeholder hub, build-from-main, re-create on env change, RBAC caveat

Round-1 audit fixes for docs/clankmail.md:

- R1: replace the private hub domain (9 sites) with the placeholder
  hub.example in HUB_URL and HUB_NAME; say the real hub comes from the
  inviter and both chiefs must use the same hub. leakscan with the
  denied-identifier key active: 9 findings at b0f5e3b, 0 here.
- Y2: no release (latest v0.135.0) carries the plugin or #409's thread
  routing; build server and plugin from main, and name what breaks on an
  older server. Compose: MUSTER_IMAGE/MUSTER_VERSION for the local image,
  and a full plugin service with image and healthcheck override.
- Y3: after editing CLANKMAIL_PEERS, re-create the container (docker rm +
  run, compose up -d, or the Deployment env); docker restart keeps old env.
- Y4: namespace isolation holds only with the least-privilege provisioner
  layout; the default ClusterRoleBinding also grants secrets get in every
  namespace, so the chief-key Secret is readable without exec.
- Nit: "unmarked (verified)" -> "marked sender_verified: true".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(clankmail): round-2 audit fixes — RBAC isolation, verified mark, compose exec

- R-A: a namespace of its own does not keep the chief key from muster in
  either provisioner layout. Default: muster's SA holds secrets and
  pods/exec everywhere. Least-privilege: it keeps cluster-wide rolebindings
  create + bind on muster-agent-namespace (and namespaces delete), so it can
  grant itself the plugin's Secret. Name what isolates it (another cluster,
  or the provisioner.md admission policy with the plugin outside the agent
  prefix and muster's namespace) and the consequence (a compromised
  muster-server can sign as @<owner>/chief). Same correction in
  configuration.md's admin-socket note.
- Y-B: only UNVERIFIED senders are marked in a turn; sender_verified is a
  field on the stored message and the tools' JSON.
- Y-C: compose exec form for the admin commands; publish 127.0.0.1:8080 on
  the compose service; kubectl exec form in pairing step 4.
- Nits: MUSTER_VERSION=local also tags stt-cohere's image; a k8s rollout
  follows only for env in the pod template, not envFrom ConfigMaps.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs: round-3 audit nits — muster's own namespace, ConfigMap valueFrom

configuration.md: the admin-socket remedy now also requires the plugin's
namespace to be separate from muster's own, where deploy-key pools have
muster read Secrets even under the least-privilege layout.

clankmail.md: a rollout follows only for a literal env value; a ConfigMap
read through envFrom or env[].valueFrom.configMapKeyRef needs a manual
rollout restart.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(clankmail): point send-first at ClankMail v0.3.1

ZacxDev/clankmail#15 merged and v0.3.1 is the first tag carrying the
example: the link now points at tree/v0.3.1 and the go run is pinned to
@v0.3.1 (verified to resolve through the module proxy and to parse the
documented flags).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev
ZacxDev deleted the feat/example-send-first-message branch November 3, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant