oficina / sheets Public

Mail through rastrillo's FromCarlos, ready for CARLOS platform mail submission (SMTP unchanged until switched)

Re-pinned to the rastrillo patch tag, which adds only mail/. Boots with CARLOS_MAIL=submit and a socket, or on SMTP as before; refuses with neither. Fable APPROVED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from mail/from-carlos-patch into main.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 60a0f3df0a8e1b07b5797429add2e7955c7ca082 parent ef9c313
7 files changed, +174 −6
  • AGENTS.md +14 −0
  • Makefile +3 −0
  • go.mod +1 −1
  • go.sum +2 −2
  • internal/sheets/auth.go +26 −3
  • internal/sheets/auth_test.go +3 −0
  • internal/sheets/mail_submission_test.go +125 −0

CI passed — run details

diff --git a/AGENTS.md b/AGENTS.md
index 50b8e60..a476ef8 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -275,6 +275,20 @@ relying on remembering one, make it a test instead.
channel points at it, and nothing serves it. `deploy` ships, promotes
and waits for the URL — one command, and it is the one that tells you
when it is actually live. (Paul, 2026-08-31.)
+ **Until `carlos deploy` takes `--mail`, the exception is mail
+ submission:** every build must be shipped with `--mail submit`, which
+ declares that it sends through CARLOS mail submission
+ (`mail.FromCarlos`, `LoadAuthEnv` in `internal/sheets/auth.go`, From
+ `$CARLOS_MAIL_FROM`). Until `carlos email submission on --app sheets`
+ runs, Sheets keeps sending over `CARLOS_SMTP_*`; after it the agent
+ sets `CARLOS_MAIL=submit`, Sheets holds no mail credential, and every
+ instance must run a build shipped with the flag. `carlos deploy` has
+ no `--mail` flag yet (carlos main 9eec0236), so ship and promote, then
+ poll `/api/version` as below: `carlos ship --app sheets --account
+ oficina --mail submit --version <v> --target linux-arm64
+ releases/sheets-linux-arm64`, then `carlos promote --app sheets
+ --account oficina <v>`. Once it ships, `carlos deploy --mail submit`
+ replaces both.
- **Build shipping binaries with `make release`, never a bare `go build`.**
It stamps `rastrillo.BuildVersion` via `-ldflags -X` and refuses a dirty
tree. An unstamped binary reports `dev` from `/api/version` forever.
diff --git a/Makefile b/Makefile
index 60f5dcc..795be70 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,9 @@ release:
@echo "built $(RELEASE_BIN) reporting version $(VERSION)"
@echo "publish it with:"
@echo " amadan release create -repo oficina/$(APP) -notes-file NOTES.md $(VERSION) $(RELEASE_BIN)"
+ @echo "ship it declaring CARLOS mail submission, then promote it (AGENTS.md, Deploys):"
+ @echo " carlos ship -app $(APP) -mail submit -version $(VERSION) -target $(RELEASE_GOOS)-$(RELEASE_GOARCH) $(RELEASE_BIN)"
+ @echo " carlos promote -app $(APP) $(VERSION)"
# The gate, split into named targets so CI can report them individually
# (.amadan/ci.d calls these one at a time, each its own step). `make
diff --git a/go.mod b/go.mod
index 46a2d88..1f5eaab 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,7 @@ require (
amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d
amadan.net/oficina/home/roster v0.0.0-20261028171508-67c12e39a9d2
amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2
- amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060
+ amadan.net/rastrillo/rastrillo v0.27.1
github.com/carlosframework/rastrillo v0.23.0
github.com/chromedp/cdproto v0.0.0-20250724212937-08a3db8b4327
github.com/chromedp/chromedp v0.14.2
diff --git a/go.sum b/go.sum
index 73cee00..621ec9b 100644
--- a/go.sum
+++ b/go.sum
@@ -14,8 +14,8 @@ amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2 h1:0PQiRUkC+
amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2/go.mod h1:dXBZeB2ic33SIZiGUCzafmviUT8TYWgzSYZvo2rM6zA=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 h1:5EFx7BLJj/+G/rt8bTmeyMWVfF5s5Sns7ajTvX4w/I8=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3/go.mod h1:ZaaxeE278dJltdrLwmwpxUjQ5wuKzqDAVSNRet+WupY=
-amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 h1:K2PXcCKfm+AYrqgH1ea6cNsFs4sN7MKLvq+uBY11NZE=
-amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060/go.mod h1:WmC8TAIfqjAkSwmD+FCTqr7VuqAO5FaX03HlV49K608=
+amadan.net/rastrillo/rastrillo v0.27.1 h1:cVG2ll1BZxlyyuNINRKblKO/6hvk/ucCFXz6HNoCo58=
+amadan.net/rastrillo/rastrillo v0.27.1/go.mod h1:WmC8TAIfqjAkSwmD+FCTqr7VuqAO5FaX03HlV49K608=
amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM=
amadan.net/rastrillo/rastrillo/money v0.1.0/go.mod h1:cmgkjBEIQh1pFSYvQk0UU6oPYS8kSDypdT9+t4Flx0U=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
diff --git a/internal/sheets/auth.go b/internal/sheets/auth.go
index 41fbef2..a72cbd2 100644
--- a/internal/sheets/auth.go
+++ b/internal/sheets/auth.go
@@ -108,14 +108,23 @@ func LoadAuthEnv(logger *slog.Logger) (AuthEnv, error) {
strings.Join(missing, ", "))
}
+ // Mail is either channel rastrillo's mail.FromCarlos takes:
+ // CARLOS mail submission, which the agent turns on with
+ // CARLOS_MAIL=submit beside its control socket (the From is
+ // CARLOS_MAIL_FROM, the stem of Sheets' declared CARLOS_SMTP
+ // prefix), or CARLOS_SMTP_*.
+ //
// mail.FromEnv falls back to a logging sender with a warning when
// SMTP is absent. A warning is not enough: the emailed link is a
// live credential and the log is platform-held storage we cannot
// grep or redact. Detect the fallback ourselves and refuse.
- if os.Getenv("CARLOS_SMTP_HOST") == "" || os.Getenv("CARLOS_SMTP_FROM") == "" {
+ submit := os.Getenv("CARLOS_MAIL") == "submit"
+ smtp := os.Getenv("CARLOS_SMTP_HOST") != "" && os.Getenv("CARLOS_SMTP_FROM") != ""
+ if !submit && !smtp {
if !loopback(env.Origin) {
return AuthEnv{}, errors.New(
- "sign-in is not configured: CARLOS_SMTP_HOST and CARLOS_SMTP_FROM not set, " +
+ "sign-in is not configured: neither CARLOS_MAIL=submit nor " +
+ "CARLOS_SMTP_HOST and CARLOS_SMTP_FROM are set, " +
"so magic links would be written to the log instead of emailed. " +
"Run `carlos email enable --app sheets`")
}
@@ -128,7 +137,21 @@ func LoadAuthEnv(logger *slog.Logger) (AuthEnv, error) {
if err := validateAgentConfig(env.AgentIssuer, env.AgentTeam, env.Origin, env.Home); err != nil {
return AuthEnv{}, err
}
- env.Mailer = mail.FromEnv("CARLOS", logger)
+ // Built here, on the serving path only (cmd/sheets main; the
+ // sheets-contract command never loads sign-in): a CARLOS seed or
+ // one-shot has no control socket and the agent strips CARLOS_MAIL
+ // from it, so FromCarlos there would refuse a switched app.
+ // FromCarlos never falls back to logged mail; that is only the
+ // loopback case above, with neither channel.
+ if submit || smtp {
+ mailer, err := mail.FromCarlos("CARLOS", logger)
+ if err != nil {
+ return AuthEnv{}, err
+ }
+ env.Mailer = mailer
+ } else {
+ env.Mailer = mail.FromEnv("CARLOS", logger)
+ }
return env, nil
}
diff --git a/internal/sheets/auth_test.go b/internal/sheets/auth_test.go
index b71d189..b064e2b 100644
--- a/internal/sheets/auth_test.go
+++ b/internal/sheets/auth_test.go
@@ -22,6 +22,9 @@ func setEnv(t *testing.T, kv map[string]string) {
"SHEETS_AGENT_ISSUER", "SHEETS_AGENT_TEAM",
"SHEETS_HOME_ISSUER", "SHEETS_HOME_CONSUMER_ID", "SHEETS_HOME_KEYS_BASE64", "SHEETS_HOME_DEK_BASE64",
"CARLOS_SMTP_HOST", "CARLOS_SMTP_FROM",
+ "CARLOS_SMTP_PORT", "CARLOS_SMTP_USER", "CARLOS_SMTP_PASS",
+ "CARLOS_MAIL", "CARLOS_CONTROL_SOCKET", "CARLOS_ADMIN_TOKEN",
+ "CARLOS_MAIL_FROM",
} {
t.Setenv(k, "")
}
diff --git a/internal/sheets/mail_submission_test.go b/internal/sheets/mail_submission_test.go
new file mode 100644
index 0000000..b0a18aa
--- /dev/null
+++ b/internal/sheets/mail_submission_test.go
@@ -0,0 +1,125 @@
+package sheets
+
+import (
+ "context"
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/mail"
+)
+
+// The boots CARLOS platform mail submission needs (carlos plan Task 9):
+// on submission with the agent's socket, on SMTP alone, and with
+// neither, which refuses on a public origin.
+
+// switchedEnv is a switched instance: the five CARLOS_SMTP_* have left
+// the bundle, and the agent has set CARLOS_MAIL=submit beside its
+// socket, with the platform's CARLOS_MAIL_FROM.
+func switchedEnv(socket string) map[string]string {
+ env := goodEnv()
+ delete(env, "CARLOS_SMTP_HOST")
+ delete(env, "CARLOS_SMTP_FROM")
+ env["CARLOS_MAIL"] = "submit"
+ env["CARLOS_CONTROL_SOCKET"] = socket
+ env["CARLOS_ADMIN_TOKEN"] = "token"
+ env["CARLOS_MAIL_FROM"] = "noreply@sheets.example.com"
+ return env
+}
+
+// mailVerb stands in for the agent's control socket, answering POST
+// /v1/mail and reporting each request's method and path.
+func mailVerb(t *testing.T) (string, chan string) {
+ t.Helper()
+ // A short directory: a unix socket path has a 104-byte limit.
+ dir, err := os.MkdirTemp("/tmp", "sheets-mail")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { os.RemoveAll(dir) })
+ socket := filepath.Join(dir, "control.sock")
+ listener, err := net.Listen("unix", socket)
+ if err != nil {
+ t.Fatal(err)
+ }
+ paths := make(chan string, 1)
+ server := &http.Server{Handler: http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ paths <- r.Method + " " + r.URL.Path
+ w.Write([]byte(`{"message_id":"m-1"}`))
+ })}
+ go server.Serve(listener)
+ t.Cleanup(func() { server.Close() })
+ return socket, paths
+}
+
+func TestLoadAuthEnvBootsOnMailSubmission(t *testing.T) {
+ socket, paths := mailVerb(t)
+ setEnv(t, switchedEnv(socket))
+ env, err := LoadAuthEnv(quietLogger())
+ if err != nil {
+ t.Fatalf("a switched Sheets refused to boot: %v", err)
+ }
+ if err := env.Mailer.Send(context.Background(), "ana@example.com",
+ "Sign in", "link"); err != nil {
+ t.Fatal(err)
+ }
+ if got := <-paths; got != "POST /v1/mail" {
+ t.Fatalf("the sign-in went to %s, not the mail verb", got)
+ }
+}
+
+func TestLoadAuthEnvBootsOnSMTPAlone(t *testing.T) {
+ setEnv(t, goodEnv())
+ env, err := LoadAuthEnv(quietLogger())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !mail.IsConfigured(env.Mailer) {
+ t.Fatal("SMTP is configured but the sender only logs")
+ }
+}
+
+func TestLoadAuthEnvRefusesWithNeitherChannel(t *testing.T) {
+ env := goodEnv()
+ delete(env, "CARLOS_SMTP_HOST")
+ delete(env, "CARLOS_SMTP_FROM")
+ setEnv(t, env)
+ _, err := LoadAuthEnv(quietLogger())
+ if err == nil {
+ t.Fatal("booted on a public origin with no mail channel")
+ }
+ for _, want := range []string{"CARLOS_MAIL=submit", "CARLOS_SMTP_HOST"} {
+ if !strings.Contains(err.Error(), want) {
+ t.Errorf("refusal %q does not name %s", err, want)
+ }
+ }
+}
+
+// A submission missing anything the agent delivers refuses at boot,
+// even on loopback: it is never logged mail in its place.
+func TestLoadAuthEnvRefusesHalfASubmission(t *testing.T) {
+ socket, _ := mailVerb(t)
+ for _, missing := range []string{"CARLOS_CONTROL_SOCKET",
+ "CARLOS_ADMIN_TOKEN", "CARLOS_MAIL_FROM"} {
+ for _, origin := range []string{"https://sheets.example.com",
+ "http://localhost:8080"} {
+ t.Run(missing+" "+origin, func(t *testing.T) {
+ env := switchedEnv(socket)
+ env["SHEETS_ORIGIN"] = origin
+ delete(env, missing)
+ setEnv(t, env)
+ _, err := LoadAuthEnv(quietLogger())
+ if err == nil {
+ t.Fatalf("booted on submission with no %s", missing)
+ }
+ if !strings.Contains(err.Error(), missing) {
+ t.Errorf("refusal %q does not name %s", err, missing)
+ }
+ })
+ }
+ }
+}