oficina / memoria 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 17be7e27e5df7ad17a88fdc42339e00ac7b557ca parent c9f041c
10 files changed, +224 −15
  • AGENTS.md +4 −0
  • Makefile +3 −2
  • README.md +15 −2
  • cmd/memoria/main.go +8 −3
  • go.mod +1 −1
  • go.sum +2 −2
  • internal/memoria/config.go +12 −4
  • internal/memoria/credits/notices.json +1 −1
  • internal/memoria/mailer.go +24 −0
  • internal/memoria/mailer_test.go +154 −0

CI passed — run details

CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/memoriatest/
=== fmt ===
=== test ===
go test ./...
?   	amadan.net/oficina/memoria/cmd/memoria	[no test files]
?   	amadan.net/oficina/memoria/cmd/memoria-contract	[no test files]
ok  	amadan.net/oficina/memoria/internal/memoria	11.146s
ok  	amadan.net/oficina/memoria/internal/memoria/chunk	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/fact	(cached)
?   	amadan.net/oficina/memoria/internal/memoria/icons	[no test files]
ok  	amadan.net/oficina/memoria/internal/memoria/index	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/notion	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/provider	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/query	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/seal	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/sibling	(cached)
?   	amadan.net/oficina/memoria/internal/memoria/teamstate	[no test files]
ok  	amadan.net/oficina/memoria/internal/memoriatest	5.015s
?   	amadan.net/oficina/memoria/scripts/writeestilo	[no test files]
?   	amadan.net/oficina/memoria/tools/bench	[no test files]
?   	amadan.net/oficina/memoria/tools/drive	[no test files]
?   	amadan.net/oficina/memoria/tools/seed	[no test files]
?   	amadan.net/oficina/memoria/tools/vendorassets	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
diff --git a/AGENTS.md b/AGENTS.md
index 066a8bc..a235bca 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -230,6 +230,10 @@ so; it never renders as a confident zero.
**Deploys**
- One binary, `CGO_ENABLED=0`, cgo-free SQLite.
- `carlos deploy`, never `carlos ship`. Flags before the binary path.
+ Until `carlos deploy` takes `--mail`, the exception is mail
+ submission: `carlos ship --mail submit`, then `carlos promote`
+ (README, Deploying), because every instance of a switched app must
+ run a build shipped with the flag.
- `make release`, never a bare `go build`, or `/api/version` reports `dev`
forever. Poll the process, not `X-Carlos-Version`.
diff --git a/Makefile b/Makefile
index 69cc221..389c887 100644
--- a/Makefile
+++ b/Makefile
@@ -53,8 +53,9 @@ release:
-ldflags "-s -w -X amadan.net/rastrillo/rastrillo.BuildVersion=$(VERSION)" \
-o $(RELEASE_BIN) ./cmd/$(APP)
@echo "built $(RELEASE_BIN) reporting version $(VERSION)"
- @echo "deploy it with:"
- @echo " carlos deploy --app $(APP) --account bds --channel edge --timeout 5m $(RELEASE_BIN)"
+ @echo "ship it declaring CARLOS mail submission, then promote it (carlos deploy has no --mail flag yet; see README):"
+ @echo " carlos ship --app $(APP) --account bds --mail submit --version $(VERSION) $(RELEASE_BIN)"
+ @echo " carlos promote --app $(APP) --account bds $(VERSION) edge"
@echo "publish it with:"
@echo " amadan release create -repo oficina/$(APP) -notes-file NOTES.md $(VERSION) $(RELEASE_BIN)"
diff --git a/README.md b/README.md
index 9eb4dd6..d0c86a9 100644
--- a/README.md
+++ b/README.md
@@ -172,9 +172,21 @@ of refusing loudly.
```
make release
-carlos deploy --app memoria --account bds --channel edge --timeout 5m releases/memoria-linux-arm64
+carlos ship --app memoria --account bds --mail submit --version <sha> releases/memoria-linux-arm64
+carlos promote --app memoria --account bds <sha> edge
```
+**Mail submission.** Ship every build with `--mail submit`: it declares
+that the build sends through CARLOS mail submission (`mail.FromCarlos`,
+`internal/memoria/mailer.go`, From `$CARLOS_MAIL_FROM`). Until `carlos
+email submission on --app memoria` runs, memoria keeps sending over
+`CARLOS_SMTP_*`; after it the agent sets `CARLOS_MAIL=submit`, memoria
+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 as above; once it has, `carlos deploy
+--app memoria --account bds --channel edge --mail submit --timeout 5m
+releases/memoria-linux-arm64` does both.
+
Trust the command `make release` prints over the one written here: it
names the path it actually built. This section used to say
`./releases/memoria-arm64`, which no build has ever produced — the binary
@@ -189,7 +201,8 @@ committing noise to get past it.
Flags go **before** the binary path; Go's flag package stops parsing at
the first non-flag argument, so a path first makes `--account` invisible.
-`carlos deploy`, never `carlos ship` on its own. Then poll
+`carlos deploy`, never `carlos ship` on its own, except for mail
+submission's ship-then-promote above until `deploy` takes `--mail`. Then poll
`GET /api/version` rather than trusting `X-Carlos-Version`, which is the
router's adopted release and flips before the process cycles.
diff --git a/cmd/memoria/main.go b/cmd/memoria/main.go
index dcbaaed..ccab2b5 100644
--- a/cmd/memoria/main.go
+++ b/cmd/memoria/main.go
@@ -8,7 +8,6 @@ import (
"amadan.net/rastrillo/rastrillo"
"amadan.net/rastrillo/rastrillo/db"
- "amadan.net/rastrillo/rastrillo/mail"
memoria "amadan.net/oficina/memoria/internal/memoria"
)
@@ -61,7 +60,8 @@ func main() {
// explicitly, but refusing was only half the fix: nothing was
// building a real sender either.
//
- // "CARLOS" is the prefix the suite uses, matching Sheets.
+ // memoria.Mailer: CARLOS mail submission or SMTP under the suite's
+ // CARLOS prefix, through mail.FromCarlos.
//
// The owners list is set FIRST, because app.Admit reads it: it is the
// one admission predicate, used by rastrillo at verification, by the
@@ -76,11 +76,16 @@ func main() {
// yet have.
app.SetOwners(cfg.Owners)
+ mailer, err := memoria.Mailer(cfg, logger)
+ if err != nil {
+ logger.Error("configure mail", "err", err)
+ os.Exit(1)
+ }
a, err := memoria.NewAuth(d.Writer(), memoria.AuthEnv{
Origin: cfg.Origin,
InstanceKey: cfg.InstanceKey,
Owners: cfg.Owners,
- Mailer: mail.FromEnv("CARLOS", logger),
+ Mailer: mailer,
HomeEnabled: cfg.Home != nil,
}, logger, app)
if err != nil {
diff --git a/go.mod b/go.mod
index efd4b25..807fe9d 100644
--- a/go.mod
+++ b/go.mod
@@ -27,7 +27,7 @@ require (
)
require (
- amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060
+ amadan.net/rastrillo/rastrillo v0.27.1
github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2
)
diff --git a/go.sum b/go.sum
index 5399669..ee0ad3f 100644
--- a/go.sum
+++ b/go.sum
@@ -14,8 +14,8 @@ amadan.net/oficina/suite v0.0.0-20261102002704-91affa14eae4 h1:BP+KHZTSgL7HDCz9I
amadan.net/oficina/suite v0.0.0-20261102002704-91affa14eae4/go.mod h1:Xgw0N+DBiDzkhQHm/nIhgumfaiMElDg/KIFD1OxTm5w=
amadan.net/rastrillo/native/server v0.0.0-20261114133130-c989034602fd h1:bZOyKxnshpVjbtWzNhZwnMnj/YjRaLWTg5XdNaVWWOA=
amadan.net/rastrillo/native/server v0.0.0-20261114133130-c989034602fd/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/memoria/config.go b/internal/memoria/config.go
index 9e7b0a0..7e2a02a 100644
--- a/internal/memoria/config.go
+++ b/internal/memoria/config.go
@@ -36,6 +36,9 @@ type Config struct {
// `carlos logs` is platform-held storage we cannot grep, so that is
// a credential we cannot retract. Opt in explicitly for local dev.
AllowLoggedMail bool
+ // MailConfigured is true when the platform gave memoria a way to
+ // send: CARLOS mail submission or SMTP. Mailer builds the sender.
+ MailConfigured bool
// AI is the team owner's opt-in to the model layer (decision 4). With
// it off, nothing is ever sent to a provider and §8.9 does nothing.
@@ -115,11 +118,16 @@ func LoadConfig(getenv func(string) string) (Config, error) {
// sender unless it has both. Checking only HOST would let a
// half-configured instance log links while this function reported
// everything fine.
+ //
+ // Mail is either channel rastrillo's mail.FromCarlos takes (Mailer,
+ // mailer.go): CARLOS mail submission, which the agent turns on with
+ // CARLOS_MAIL=submit beside its control socket, or CARLOS_SMTP_*.
c.AllowLoggedMail = getenv("MEMORIA_ALLOW_LOGGED_MAIL") == "1"
- if !c.AllowLoggedMail {
- if getenv("CARLOS_SMTP_HOST") == "" || getenv("CARLOS_SMTP_FROM") == "" {
- return c, fmt.Errorf("%w: CARLOS_SMTP_HOST and CARLOS_SMTP_FROM (or MEMORIA_ALLOW_LOGGED_MAIL=1 to log sign-in links instead, which puts a live credential in a log nobody can delete)", ErrMissing)
- }
+ submit := getenv("CARLOS_MAIL") == "submit"
+ smtp := getenv("CARLOS_SMTP_HOST") != "" && getenv("CARLOS_SMTP_FROM") != ""
+ c.MailConfigured = submit || smtp
+ if !c.MailConfigured && !c.AllowLoggedMail {
+ return c, fmt.Errorf("%w: CARLOS_MAIL=submit, or CARLOS_SMTP_HOST and CARLOS_SMTP_FROM (or MEMORIA_ALLOW_LOGGED_MAIL=1 to log sign-in links instead, which puts a live credential in a log nobody can delete)", ErrMissing)
}
// The model layer: off unless the owner says "on", in exactly those
diff --git a/internal/memoria/credits/notices.json b/internal/memoria/credits/notices.json
index b237262..5a8d191 100644
--- a/internal/memoria/credits/notices.json
+++ b/internal/memoria/credits/notices.json
@@ -35,7 +35,7 @@
},
{
"Name": "amadan.net/rastrillo/rastrillo",
- "Version": "v0.27.1-0.20261006204347-fb806a287060",
+ "Version": "v0.27.1",
"SourceURL": "https://amadan.net/rastrillo/rastrillo",
"Notices": [
{
diff --git a/internal/memoria/mailer.go b/internal/memoria/mailer.go
new file mode 100644
index 0000000..e74bdf4
--- /dev/null
+++ b/internal/memoria/mailer.go
@@ -0,0 +1,24 @@
+package memoria
+
+import (
+ "log/slog"
+
+ "amadan.net/rastrillo/rastrillo/mail"
+)
+
+// Mailer builds the sign-in sender. Call it only where memoria serves:
+// a CARLOS seed or one-shot runs with no control socket, and the agent
+// strips CARLOS_MAIL from it, so mail.FromCarlos there would refuse
+// once the app is switched to submission.
+//
+// mail.FromCarlos picks submission when CARLOS_MAIL=submit (From
+// CARLOS_MAIL_FROM, the stem of memoria's declared CARLOS_SMTP prefix),
+// else SMTP, and refuses with neither, or with submission half set up.
+// Logged mail is only what LoadConfig admitted:
+// MEMORIA_ALLOW_LOGGED_MAIL with no channel at all.
+func Mailer(config Config, logger *slog.Logger) (mail.Sender, error) {
+ if !config.MailConfigured {
+ return mail.FromEnv("CARLOS", logger), nil
+ }
+ return mail.FromCarlos("CARLOS", logger)
+}
diff --git a/internal/memoria/mailer_test.go b/internal/memoria/mailer_test.go
new file mode 100644
index 0000000..a87b9a5
--- /dev/null
+++ b/internal/memoria/mailer_test.go
@@ -0,0 +1,154 @@
+package memoria
+
+import (
+ "context"
+ "errors"
+ "log/slog"
+ "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.
+
+// mailEnv is every variable the boot's mail choice reads, so each case
+// starts from none of them whatever the test process inherited.
+var mailEnv = []string{"CARLOS_MAIL", "CARLOS_CONTROL_SOCKET",
+ "CARLOS_ADMIN_TOKEN", "CARLOS_MAIL_FROM", "CARLOS_SMTP_HOST",
+ "CARLOS_SMTP_PORT", "CARLOS_SMTP_FROM", "CARLOS_SMTP_USER",
+ "CARLOS_SMTP_PASS"}
+
+// boot is main's mail path: LoadConfig, then Mailer. LoadConfig reads
+// the map; mail.FromCarlos reads the process environment, so the map
+// is set there too.
+func boot(t *testing.T, env map[string]string) (mail.Sender, error) {
+ t.Helper()
+ for _, key := range mailEnv {
+ t.Setenv(key, "")
+ }
+ for key, value := range env {
+ t.Setenv(key, value)
+ }
+ config, err := LoadConfig(func(key string) string { return env[key] })
+ if err != nil {
+ return nil, err
+ }
+ return Mailer(config, slog.New(slog.DiscardHandler))
+}
+
+// public is a deployed instance: no logged mail, a public origin.
+func public(env map[string]string) map[string]string {
+ full := baseEnv()
+ delete(full, "MEMORIA_ALLOW_LOGGED_MAIL")
+ full["MEMORIA_ORIGIN"] = "https://memoria.oficina.works"
+ for key, value := range env {
+ full[key] = value
+ }
+ return full
+}
+
+// mailVerb is the agent's control socket, answering POST /v1/mail.
+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", "memoria-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(writer http.ResponseWriter, request *http.Request) {
+ paths <- request.Method + " " + request.URL.Path
+ writer.Write([]byte(`{"message_id":"m-1"}`))
+ })}
+ go server.Serve(listener)
+ t.Cleanup(func() { server.Close() })
+ return socket, paths
+}
+
+func TestBootsOnMailSubmission(t *testing.T) {
+ socket, paths := mailVerb(t)
+ sender, err := boot(t, public(map[string]string{
+ "CARLOS_MAIL": "submit", "CARLOS_CONTROL_SOCKET": socket,
+ "CARLOS_ADMIN_TOKEN": "token",
+ "CARLOS_MAIL_FROM": "noreply@memoria.oficina.works"}))
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = sender.Send(context.Background(), "ana@example.com",
+ "Sign in", "link")
+ if 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 TestBootsOnSMTPAlone(t *testing.T) {
+ sender, err := boot(t, public(map[string]string{
+ "CARLOS_SMTP_HOST": "email-smtp.eu-west-1.amazonaws.com",
+ "CARLOS_SMTP_FROM": "noreply@memoria.oficina.works"}))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !mail.IsConfigured(sender) {
+ t.Fatal("SMTP is configured but the sender only logs")
+ }
+}
+
+func TestRefusesWithNeitherChannel(t *testing.T) {
+ _, err := boot(t, public(nil))
+ if !errors.Is(err, ErrMissing) {
+ t.Fatalf("booted with no mail: %v", err)
+ }
+ if !strings.Contains(err.Error(), "CARLOS_MAIL=submit") {
+ t.Errorf("refusal %q does not name submission", err)
+ }
+}
+
+// A submission missing anything the agent or platform delivers is a
+// boot refusal, never SMTP or logged mail in its place: not even with
+// MEMORIA_ALLOW_LOGGED_MAIL set.
+func TestRefusesHalfASubmission(t *testing.T) {
+ socket, _ := mailVerb(t)
+ for _, missing := range []string{"CARLOS_CONTROL_SOCKET",
+ "CARLOS_ADMIN_TOKEN", "CARLOS_MAIL_FROM"} {
+ t.Run(missing, func(t *testing.T) {
+ env := public(map[string]string{"CARLOS_MAIL": "submit",
+ "CARLOS_CONTROL_SOCKET": socket, "CARLOS_ADMIN_TOKEN": "token",
+ "CARLOS_MAIL_FROM": "noreply@memoria.oficina.works",
+ "MEMORIA_ALLOW_LOGGED_MAIL": "1"})
+ delete(env, missing)
+ _, err := boot(t, env)
+ if err == nil || !strings.Contains(err.Error(), missing) {
+ t.Fatalf("booted on submission with no %s: %v", missing, err)
+ }
+ })
+ }
+}
+
+// Logged mail stays what it was: only with MEMORIA_ALLOW_LOGGED_MAIL
+// and no channel at all.
+func TestLoggedMailOnlyWhenAskedAndNoChannel(t *testing.T) {
+ sender, err := boot(t, baseEnv())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if mail.IsConfigured(sender) {
+ t.Fatal("logged mail with no channel built a real sender")
+ }
+}