carlos / platform Public

feat: show fleet boxes through the console API

Add the BYO fleet view with member access, observed versions and API-only CLI selectors. Include focused coverage and a root envelope census proposal for independent review.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 67db5e657d58bd5f7592c99ba4deef4f14a88c71 parent 7855250
11 files changed, +358 −1
  • apimode_managedfleets.go +56 −0
  • docs/site/cli.md +11 −0
  • docs/superpowers/notes/census-proposal-managed-fleets-2a-task-1.md +11 −0
  • fleets.go +6 −1
  • fleets_managed.go +53 −0
  • fleets_managed_test.go +71 −0
  • internal/console/authcli.go +1 −0
  • internal/console/managedview.go +65 −0
  • internal/console/managedview_test.go +80 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-managed-fleets-2a-task-1.tsv +3 −0
diff --git a/apimode_managedfleets.go b/apimode_managedfleets.go
new file mode 100644
index 000000000..c8e331707
--- /dev/null
+++ b/apimode_managedfleets.go
@@ -0,0 +1,56 @@
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/url"
+)
+
+type apiManagedCheck struct {
+ State string `json:"state"`
+ Reason string `json:"reason"`
+}
+
+type apiFleetShowBox struct {
+ Label string `json:"label"`
+ State string `json:"state"`
+ Version string `json:"version"`
+ LastError string `json:"last_error"`
+ Checks map[string]apiManagedCheck `json:"checks"`
+}
+
+type apiFleetShowOperation struct {
+ ID string `json:"id"`
+ Kind string `json:"kind"`
+ State string `json:"state"`
+ Outcome string `json:"outcome"`
+ Error string `json:"error"`
+ Requested int `json:"requested"`
+}
+
+type apiFleetShowReply struct {
+ Name string `json:"name"`
+ Managed bool `json:"managed"`
+ Boxes []apiFleetShowBox `json:"boxes"`
+ Operation *apiFleetShowOperation `json:"operation,omitempty"`
+}
+
+func (s *apiSession) showFleet(ctx context.Context, a apiAcct, name string) (apiFleetShowReply, error) {
+ code, body, err := s.getJSON(ctx, fleetPath(a, "/"+url.PathEscape(name)))
+ if err != nil {
+ return apiFleetShowReply{}, err
+ }
+ if code != http.StatusOK {
+ return apiFleetShowReply{}, apiErrorFromBody(code, body)
+ }
+ var out apiFleetShowReply
+ if err := json.Unmarshal(body, &out); err != nil {
+ return out, fmt.Errorf("fleets show: unreadable response: %w", err)
+ } // COPY
+ if out.Name != name || out.Boxes == nil {
+ return apiFleetShowReply{}, fmt.Errorf("fleets show: incomplete response")
+ } // COPY
+ return out, nil
+}
diff --git a/docs/site/cli.md b/docs/site/cli.md
index 6cf69e8e0..12d9f5691 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -2256,6 +2256,17 @@ To check that a box holds the registered key, run `carlos secrets fingerprint` o
You can replace a fleet's key only while none of its apps holds a sealed value. Unset those apps' secrets, register the new key, set the secrets again and rotate the credentials the console minted. If a key may have leaked, take the box off the fleet first. A box that has never run an instance can be detached at once with `carlos fleets detach-box <fleet> <label>`. Otherwise drain it with `carlos fleets drain <fleet> <label>`, terminate its machine once its instances have moved, then detach it with `carlos fleets detach-box --terminated <fleet> <label>`. Rotate the credentials after detaching. The drain needs the box's current token: rotating first would cut the box off before it sees its instances leave. A detached box stops reading the platform's store.
+### carlos fleets show
+
+Show each box's active or detached status and its last observed version:
+
+```sh
+carlos fleets show --account ops production
+```
+
+A box with no available version report shows `unknown`. Bring-your-own fleets
+have no managed readiness checks. Use `--account-id` to select an exact account sqid.
+
### carlos services
Credentials a server holds rather than a person: a CI job that ships, a
diff --git a/docs/superpowers/notes/census-proposal-managed-fleets-2a-task-1.md b/docs/superpowers/notes/census-proposal-managed-fleets-2a-task-1.md
new file mode 100644
index 000000000..a90b43c0d
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-managed-fleets-2a-task-1.md
@@ -0,0 +1,11 @@
+# Census approval: managed-fleets-2a-task-1
+
+Ruling `census-ruling-managed-fleets-2a-task-1`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `.`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Seal: `5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc` → `5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-managed-fleets-2a-task-1.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/fleets.go b/fleets.go
index 76d74a733..2477370fc 100644
--- a/fleets.go
+++ b/fleets.go
@@ -31,7 +31,7 @@ import (
"github.com/carlosframework/platform/internal/registry"
)
-const fleetsUsage = `usage: carlos fleets <create|add-box|rotate-token|tag-box|drain|detach-box|secrets-key|ls> [flags]
+const fleetsUsage = `usage: carlos fleets <create|add-box|rotate-token|tag-box|drain|detach-box|secrets-key|show|ls> [flags]
create --bucket <bucket> [--account <sqid|name>] <name>
mint an account-owned fleet: a named group of remote boxes
@@ -103,6 +103,9 @@ const fleetsUsage = `usage: carlos fleets <create|add-box|rotate-token|tag-box|d
for the console to move instances between boxes, unknown when the
console could not read every box's report, and - otherwise.
+ show [--account <sqid|name>] <fleet>
+ show each box's status and observed version.
+
--account <sqid|name> account the fleet belongs to (default: your only
account, or the configured/chosen one) —
resolved by the console against your own
@@ -137,6 +140,8 @@ func RunFleets(args []string) {
runFleetsDetachBox(args[1:])
case "secrets-key":
runFleetsSecretsKey(args[1:])
+ case "show":
+ runFleetsShow(args[1:])
case "ls":
runFleetsList(args[1:])
default:
diff --git a/fleets_managed.go b/fleets_managed.go
new file mode 100644
index 000000000..32d64f309
--- /dev/null
+++ b/fleets_managed.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "io"
+ "log"
+ "text/tabwriter"
+)
+
+func runFleetsShow(args []string) {
+ fs := flag.NewFlagSet("fleets show", flag.ExitOnError)
+ // COPY: flag descriptions and usage.
+ acctRaw := fs.String("account", "", "account name or sqid")
+ acctIDRaw := fs.String("account-id", "", "exact account sqid; overrides --account")
+ consoleFlag := consoleOption(fs, "console to read the fleet from")
+ fs.Usage = flagUsage(fs, "<fleet>")
+ fs.Parse(args)
+ if fs.NArg() != 1 {
+ fs.Usage()
+ log.Fatal("fleets show: name one fleet")
+ } // COPY
+ name := fs.Arg(0)
+ if err := validFleetName(name); err != nil {
+ log.Fatal(err)
+ }
+ sess := fleetsSignedInSession(*consoleFlag)
+ acct := resolvedAccount(sess, acctRaw, acctIDRaw)
+ out, err := sess.showFleet(context.Background(), acct, name)
+ if err != nil {
+ log.Fatal(err)
+ }
+ printFleetShow(stdout, out)
+}
+
+func printFleetShow(w io.Writer, out apiFleetShowReply) {
+ fmt.Fprintln(w, out.Name)
+ if len(out.Boxes) == 0 {
+ fmt.Fprintln(w, "no boxes")
+ return
+ } // COPY
+ tw := tabwriter.NewWriter(w, 0, 4, 2, ' ', 0)
+ fmt.Fprintln(tw, "BOX\tSTATE\tVERSION\tLAST ERROR") // COPY
+ for _, b := range out.Boxes {
+ version := b.Version
+ if version == "" {
+ version = "unknown"
+ } // COPY
+ fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", b.Label, b.State, version, b.LastError)
+ }
+ tw.Flush()
+}
diff --git a/fleets_managed_test.go b/fleets_managed_test.go
new file mode 100644
index 000000000..a2eb0f73f
--- /dev/null
+++ b/fleets_managed_test.go
@@ -0,0 +1,71 @@
+package main
+
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os/exec"
+ "strings"
+ "testing"
+)
+
+func TestFleetsShowCLI(t *testing.T) {
+ for _, exact := range []bool{false, true} {
+ t.Run(fmt.Sprint(exact), func(t *testing.T) {
+ malformed := false
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != "GET" || r.URL.Path != "/api/cli/fleets/chosen/production" || (r.URL.Query().Get("exact") == "sqid") != exact {
+ t.Errorf("request: %s %s", r.Method, r.URL)
+ }
+ if malformed {
+ fmt.Fprint(w, `{"boxes":`)
+ return
+ }
+ fmt.Fprint(w, `{"name":"production","managed":false,"boxes":[{"label":"box-1","state":"active","version":"v1.2.3","last_error":"","checks":{}}]}`)
+ }))
+ defer ts.Close()
+ s := newTestSession(ts.URL)
+ out, err := s.showFleet(context.Background(), apiAcct{Seg: "chosen", Exact: exact}, "production")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var buf bytes.Buffer
+ printFleetShow(&buf, out)
+ for _, text := range []string{"production", "box-1", "active", "v1.2.3"} {
+ if !strings.Contains(buf.String(), text) {
+ t.Fatalf("missing %s: %s", text, buf.String())
+ }
+ }
+ malformed = true
+ if _, err = s.showFleet(context.Background(), apiAcct{Seg: "chosen", Exact: exact}, "production"); err == nil {
+ t.Fatal("malformed reply accepted")
+ }
+ })
+ }
+}
+
+func TestFleetsShowCLICommand(t *testing.T) {
+ fx := fskCLIFixture(t)
+ buf := captureStdout(t)
+ for _, args := range [][]string{{"show", "--account", "ops", "home"}, {"show", "--account", "wrong", "--account-id", fx.account, "home"}} {
+ buf.Reset()
+ RunFleets(args)
+ if !strings.Contains(buf.String(), "home\nno boxes") {
+ t.Fatalf("show: %s", buf.String())
+ }
+ }
+}
+
+func TestFleetsShowCLIRefusesDirectMode(t *testing.T) {
+ bin := buildCarlos(t)
+ dir := t.TempDir()
+ cmd := exec.Command(bin, "fleets", "show", "production")
+ cmd.Dir = dir
+ cmd.Env = carlosTestEnv(t, "CARLOS_DEPLOYMENT_DIR="+dir)
+ out, err := cmd.CombinedOutput()
+ if err == nil || !strings.Contains(string(out), "no bucket-direct fallback") {
+ t.Fatalf("direct show: %v %s", err, out)
+ }
+}
diff --git a/internal/console/authcli.go b/internal/console/authcli.go
index dd33d676d..c9b50defd 100644
--- a/internal/console/authcli.go
+++ b/internal/console/authcli.go
@@ -981,6 +981,7 @@ func (s *Server) registerCLIRoutes() {
// mint door above. Pinned by TestNoRoleReachesAMintFleetOrPolicyDoor.
s.cliRoute("POST /api/cli/fleets/{account}/new", svcrole.Set{}, s.handleAPIFleetNew)
s.cliRoute("GET /api/cli/fleets/{account}", svcrole.Set{}, s.handleAPIFleetList)
+ s.cliRoute("GET /api/cli/fleets/{account}/{fleet}", svcrole.Set{}, s.handleAPIFleetShow)
s.cliRoute("POST /api/cli/fleets/{account}/{fleet}/boxes", svcrole.Set{}, s.handleAPIFleetAddBox)
s.cliRoute("POST /api/cli/fleets/{account}/{fleet}/boxes/{label}/rotate", svcrole.Set{}, s.handleAPIFleetRotateBox)
s.cliRoute("POST /api/cli/fleets/{account}/{fleet}/boxes/{label}/detach", svcrole.Set{}, s.handleAPIFleetDetachBox)
diff --git a/internal/console/managedview.go b/internal/console/managedview.go
new file mode 100644
index 000000000..a838ea6f3
--- /dev/null
+++ b/internal/console/managedview.go
@@ -0,0 +1,65 @@
+package console
+
+import (
+ "log"
+ "net/http"
+)
+
+type managedCheck struct {
+ State string `json:"state"`
+ Reason string `json:"reason"`
+}
+
+type fleetShowBox struct {
+ Label string `json:"label"`
+ State string `json:"state"`
+ Version string `json:"version"`
+ LastError string `json:"last_error"`
+ Checks map[string]managedCheck `json:"checks"`
+}
+
+type fleetShowOperation struct {
+ ID string `json:"id"`
+ Kind string `json:"kind"`
+ State string `json:"state"`
+ Outcome string `json:"outcome"`
+ Error string `json:"error"`
+ Requested int `json:"requested"`
+}
+
+type fleetShowReply struct {
+ Name string `json:"name"`
+ Managed bool `json:"managed"`
+ Boxes []fleetShowBox `json:"boxes"`
+ Operation *fleetShowOperation `json:"operation,omitempty"`
+}
+
+func (s *Server) handleAPIFleetShow(w http.ResponseWriter, r *http.Request) {
+ _, _, fleet, reg, ok := s.apiFleet(w, r)
+ if !ok {
+ return
+ }
+ boxes, err := reg.ListFleetBoxes(fleet.Name)
+ if err != nil {
+ log.Printf("console: fleet show %s: %v", fleet.Name, err)
+ jsonError(w, http.StatusInternalServerError, "could not read fleet boxes") // COPY
+ return
+ }
+ out := fleetShowReply{Name: fleet.Name, Boxes: make([]fleetShowBox, 0, len(boxes))}
+ versions := make(map[string]string)
+ if len(boxes) > 0 && s.cfg.Releases != nil {
+ beats, _, err := s.loadBoxes(r.Context(), s.cfg.Releases, "fleets/"+fleet.Name+"/")
+ if err != nil {
+ log.Printf("console: fleet show %s: heartbeat: %v", fleet.Name, err)
+ }
+ for _, b := range beats {
+ if b.Metrics != nil {
+ versions[b.Label] = b.Metrics.Release
+ }
+ }
+ }
+ for _, b := range boxes {
+ out.Boxes = append(out.Boxes, fleetShowBox{Label: b.Label, State: b.Status, Version: versions[b.Label], Checks: map[string]managedCheck{}})
+ }
+ writeJSON(w, http.StatusOK, out)
+}
diff --git a/internal/console/managedview_test.go b/internal/console/managedview_test.go
new file mode 100644
index 000000000..852bfe10b
--- /dev/null
+++ b/internal/console/managedview_test.go
@@ -0,0 +1,80 @@
+package console
+
+import (
+ "encoding/json"
+ "net/http"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+func seedShowFleet(t *testing.T, fx *consoleFixture) {
+ t.Helper()
+ reg := openTestReg(t, fx)
+ defer reg.Close()
+ if err := reg.UpsertFleet(registry.Fleet{Name: "production", Account: fx.sqid, Bucket: "private-bucket"}); err != nil {
+ t.Fatal(err)
+ }
+ for _, b := range []registry.FleetBox{{Fleet: "production", Label: "box-1", Status: "active", TokenHash: strings.Repeat("a", 64)}, {Fleet: "production", Label: "box-2", Status: "detached", TokenHash: strings.Repeat("a", 64)}} {
+ if err := reg.AddFleetBox(b); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+func TestFleetShowBYO(t *testing.T) {
+ fx, token := fleetFixture(t, "show-byo")
+ seedShowFleet(t, fx)
+ writeFleetHeartbeat(t, fx, "production", status.Box{Label: "box-1", GeneratedAt: time.Now(), Metrics: &status.BoxMetrics{Release: "v1.2.3"}})
+ code, _, body := rawReq(t, http.MethodGet, fleetsURL(fx, fx.sqid)+"/production", token, "")
+ if code != 200 {
+ t.Fatalf("show = %d %s", code, body)
+ }
+ for _, secret := range []string{"token_hash", "secret-hash", "private-bucket", "operation"} {
+ if strings.Contains(body, secret) {
+ t.Fatalf("leaked %q: %s", secret, body)
+ }
+ }
+ var out fleetShowReply
+ if err := json.Unmarshal([]byte(body), &out); err != nil {
+ t.Fatal(err)
+ }
+ if out.Managed || out.Name != "production" || len(out.Boxes) != 2 {
+ t.Fatalf("show: %+v", out)
+ }
+ if out.Boxes[0].Label != "box-1" || out.Boxes[0].State != "active" || out.Boxes[0].Version != "v1.2.3" || out.Boxes[1].State != "detached" {
+ t.Fatalf("boxes: %+v", out.Boxes)
+ }
+ for _, b := range out.Boxes {
+ if b.Checks == nil || len(b.Checks) != 0 {
+ t.Fatalf("invented checks: %+v", b)
+ }
+ }
+}
+
+func TestFleetShowMembership(t *testing.T) {
+ fx, owner := fleetFixture(t, "show-owner")
+ seedShowFleet(t, fx)
+ if err := fx.st.AddMember(OpsAccountID, "member@example.com", RoleMember, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ member := cliToken(t, fx, "member@example.com", "show-member")
+ for _, token := range []string{owner, member} {
+ code, _, body := rawReq(t, http.MethodGet, fleetsURL(fx, fx.sqid)+"/production", token, "")
+ if code != 200 {
+ t.Fatalf("member show = %d %s", code, body)
+ }
+ }
+ if err := fx.st.CreateAccount(42, "cdef", "other", "other@example.com", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ other := cliToken(t, fx, "other@example.com", "show-other")
+ want := canonicalNotFound(t)
+ for _, path := range []string{fx.sqid + "/production", "cdef/production", "cdef/absent"} {
+ code, h, body := rawReq(t, http.MethodGet, fleetsURL(fx, path), other, "")
+ assertNotFound(t, path, want, code, h, body)
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index b14a7a4e3..d39f66d70 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -56,3 +56,4 @@ plan14-root-reads-fix-set-aside-exdev.tsv f9d3016cc6803338f9db19311f3f598e20c37c
plan14-root-reads-durability-3a-escrow.tsv 03a92257beb9b8aac421559e247d191bd69f28a0b26243397a1344a90d59fc2a
plan14-root-reads-rootfs-default-home.tsv 7a0a3da3d6fe7e3c77abb22676db000af2a276c3d13ccae0f038190f51287ed5
plan14-root-reads-probe-burst-limit.tsv 5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc
+plan14-root-reads-managed-fleets-2a-task-1.tsv 5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc
diff --git a/internal/provision/testdata/plan14-root-reads-managed-fleets-2a-task-1.tsv b/internal/provision/testdata/plan14-root-reads-managed-fleets-2a-task-1.tsv
new file mode 100644
index 000000000..79d7b978c
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-managed-fleets-2a-task-1.tsv
@@ -0,0 +1,3 @@
+# Census overlay managed-fleets-2a-task-1, written by census-propose (#369). census-ruling-managed-fleets-2a-task-1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-managed-fleets-2a-task-1.md.
+# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . 5d1f5d5dce8ef20deb6447bca13d86c6dce4d12c84909de9dd3c8b824179e201