carlos / platform Public

region labels: the CLI reads the console's labels and prints only clean ones (plan 2 task 1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 8a22fc306542d9a68347e0126eeed78030e3bdab parent 4f81d51
5 files changed, +172 −17
  • apimode.go +39 −3
  • move.go +25 −14
  • region_labels.go +38 −0
  • region_labels_test.go +62 −0
  • status_instances.go +8 −0
diff --git a/apimode.go b/apimode.go
index 46d6a20ae..3bf8e47e5 100644
--- a/apimode.go
+++ b/apimode.go
@@ -1036,6 +1036,9 @@ type apiCreateAppResult struct {
RegionName string `json:"region_name"`
RegionSource string `json:"region_source"`
RegionsAvailable int `json:"regions_available"`
+ // RegionLabel is the stored region's label, "London (uk)" (region
+ // labels spec §4); "" from an older console.
+ RegionLabel string `json:"region_label"`
}
// createApp claims one app name through the console — the API door onto the
@@ -1100,6 +1103,7 @@ func (s *apiSession) createApp(ctx context.Context, a apiAcct, app, place string
type apiAppDefault struct {
Region string `json:"region"`
Name string `json:"name"`
+ Label string `json:"label"` // region labels spec §4; "" from an older console
Source string `json:"source"`
Effective string `json:"effective"`
Reason string `json:"reason"`
@@ -1110,8 +1114,9 @@ type apiAppDefault struct {
}
type apiRegionEntry struct {
- Code string `json:"code"`
- Name string `json:"name"`
+ Code string `json:"code"`
+ Name string `json:"name"`
+ Label string `json:"label"` // region labels spec §4; "" from an older console
}
type apiRegionsResult struct {
@@ -1130,6 +1135,19 @@ func (r apiRegionsResult) nameOf(code string) string {
return code
}
+// labelOf is the console's label for code (region labels §4), else nameOf's
+// answer: the full place an older console sent, or the code.
+func (r apiRegionsResult) labelOf(code string) string {
+ for _, e := range r.Regions {
+ if e.Code == code {
+ if p := cleanPlace(e.Label); p != "" {
+ return p
+ }
+ }
+ }
+ return r.nameOf(code)
+}
+
// appRegions reads GET …/regions for app: the regions the console knows and,
// from a console that has it, the app's own default.
func (s *apiSession) appRegions(ctx context.Context, a apiAcct, app string) (apiRegionsResult, error) {
@@ -1866,6 +1884,12 @@ type apiAppLife struct {
DeletedAt *time.Time `json:"deleted_at"`
ExpiresAt *time.Time `json:"expires_at"`
PurgeAfter *time.Time `json:"purge_after"`
+ // Region and RegionName are the app's stored region (or fleet) and its
+ // label (region labels spec §4). RegionName is nil from an older
+ // console, which sends neither; "" means the console could not read
+ // the placement.
+ Region string `json:"region"`
+ RegionName *string `json:"region_name"`
}
var (
@@ -3340,9 +3364,15 @@ type apiInstanceRecord struct {
Seed *apiSeed `json:"seed,omitempty"`
// RegionName and RegionFrom say where the create put the record and how
// that was chosen (nearest-region §9). Empty from a console that predates
- // them, and then the CLI prints today's line.
+ // them, and then the CLI prints today's line. RegionName is the label on
+ // list and get (region labels spec §4), the full C23 place on create.
RegionName string `json:"region_name,omitempty"`
RegionFrom string `json:"region_from,omitempty"`
+ // RegionLabel is a create's region label and MovePhrase a listed
+ // record's move phrase (region labels spec §3.3, §4); "" from an older
+ // console.
+ RegionLabel string `json:"region_label,omitempty"`
+ MovePhrase string `json:"move_phrase,omitempty"`
// Rollout is the instance's rollout state from its box (zero-downtime
// spec §9.1; the console's rollout join). nil from an older console, and
// for a host whose box reports none (CARLOS_SWAP off, or a dark box):
@@ -3818,6 +3848,10 @@ type apiRouteRow struct {
// PlatformCanary is a route the domains reconciler owns whole; a console
// that predates the field sends nothing and this reads false.
PlatformCanary bool `json:"platform_canary,omitempty"`
+ // Region and RegionName are the row's placement code and label (region
+ // labels spec §4); "" from an older console.
+ Region string `json:"region"`
+ RegionName string `json:"region_name"`
}
// apiRoutePathRow is one path route of the same answer: a leading URL
@@ -4198,6 +4232,8 @@ type apiSidecarRecord struct {
// RunningVersion is the console's best-effort join from the fleet's own
// box snapshots (sidecarListRecord.RunningVersion) — see the doc above.
RunningVersion string `json:"running_version"`
+ // RegionName is the sidecar's region label (region labels spec §4).
+ RegionName string `json:"region_name"`
}
// sidecarCreate asks the console to create one sidecar record — the
diff --git a/move.go b/move.go
index 579078a79..b05b02388 100644
--- a/move.go
+++ b/move.go
@@ -293,13 +293,16 @@ func moveMain(ctx context.Context, args []string, out io.Writer, d moveDeps) int
// The console's answers, as this CLI reads them (Task 2's shapes, copied
// here as the CLI convention is).
type moveFlat struct {
- State string `json:"state"`
- Phase string `json:"phase"`
- Target string `json:"target"`
- UpdatedAt int64 `json:"updated_at"`
- ID string `json:"id"`
- Last *moveOutcome `json:"last"`
- Protocol string `json:"protocol"`
+ State string `json:"state"`
+ Phase string `json:"phase"`
+ Target string `json:"target"`
+ // TargetName is Target's label (region labels spec §4); "" from an
+ // older console. Commands keep Target.
+ TargetName string `json:"target_name"`
+ UpdatedAt int64 `json:"updated_at"`
+ ID string `json:"id"`
+ Last *moveOutcome `json:"last"`
+ Protocol string `json:"protocol"`
}
// moveOutcome is the record's last close (D11). Reason is read when the
@@ -328,8 +331,12 @@ type moveAnswer struct {
}
type moveDetailView struct {
- From string `json:"from"`
- Region string `json:"region"`
+ From string `json:"from"`
+ Region string `json:"region"`
+ // FromName and ToName are the move's endpoints as labels (region labels
+ // spec §4); "" from an older console.
+ FromName string `json:"from_name"`
+ ToName string `json:"to_name"`
Move *moveJournal `json:"move"`
Claim *moveClaim `json:"claim"`
TargetReport *moveReport `json:"target_report"`
@@ -998,11 +1005,15 @@ var offlineVerbs = []string{"stage", "start", "seal", "flip", "open", "finish",
// offlineView is the offline status view (GET) and the 202 every mutating
// door answers with.
type offlineView struct {
- Host string `json:"host"`
- State string `json:"state"`
- ID string `json:"id"`
- From string `json:"from"`
- To string `json:"to"`
+ Host string `json:"host"`
+ State string `json:"state"`
+ ID string `json:"id"`
+ From string `json:"from"`
+ To string `json:"to"`
+ // FromName and ToName are From and To as labels (region labels spec
+ // §4); "" from an older console. Commands keep the codes.
+ FromName string `json:"from_name"`
+ ToName string `json:"to_name"`
Sealer string `json:"sealer"`
Boxes []string `json:"boxes"`
Next string `json:"next"`
diff --git a/region_labels.go b/region_labels.go
new file mode 100644
index 000000000..48e685f4c
--- /dev/null
+++ b/region_labels.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "unicode"
+ "unicode/utf8"
+)
+
+// The region labels (spec docs/superpowers/specs/2026-10-25-region-labels-design.md,
+// §5 surfaces 15 to 30): the CLI prints the label the console sends,
+// "London (uk)", and what it printed before when the console sends none.
+
+// placeMaxBytes bounds a label the CLI will print: a city, a code and a
+// move phrase fit many times over.
+const placeMaxBytes = 128
+
+// cleanPlace is a label the console sent, fit to print: valid UTF-8, at most
+// placeMaxBytes, every rune printable (no control characters, escapes or
+// bidi overrides). Anything else is "", and the caller prints its fallback.
+func cleanPlace(s string) string {
+ if s == "" || len(s) > placeMaxBytes || !utf8.ValidString(s) {
+ return ""
+ }
+ for _, r := range s {
+ if !unicode.IsPrint(r) {
+ return ""
+ }
+ }
+ return s
+}
+
+// placeOr is the one rule every surface follows: the console's label when
+// it sent one fit to print, else exactly what the surface printed before.
+func placeOr(label, fallback string) string {
+ if p := cleanPlace(label); p != "" {
+ return p
+ }
+ return fallback
+}
diff --git a/region_labels_test.go b/region_labels_test.go
new file mode 100644
index 000000000..a078b9e6e
--- /dev/null
+++ b/region_labels_test.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+ "encoding/json"
+ "strings"
+ "testing"
+)
+
+func TestCleanPlaceRefusesWhatATerminalWouldObey(t *testing.T) {
+ t.Parallel()
+ for in, want := range map[string]string{
+ "London (uk)": "London (uk)",
+ "Montréal (ca)": "Montréal (ca)",
+ "fleet private": "fleet private",
+ "moving to Sydney (au)": "moving to Sydney (au)",
+ "": "",
+ "London\x1b[31m (uk)": "",
+ "London (uk)\n": "",
+ "London\u202e(ku)": "",
+ "\xff\xfe": "",
+ strings.Repeat("a", 129): "",
+ } {
+ if got := cleanPlace(in); got != want {
+ t.Errorf("cleanPlace(%q) = %q, want %q", in, got, want)
+ }
+ }
+ if placeOr("London\x1b]0;x\x07", "uk") != "uk" || placeOr("London (uk)", "uk") != "London (uk)" || placeOr("", "uk") != "uk" {
+ t.Fatal("placeOr must fall back on anything cleanPlace drops")
+ }
+}
+
+// TestAPITypesReadLabels decodes a labels console's answers and an older
+// console's: the old ones leave every new field zero (and apps list's
+// region_name nil).
+func TestAPITypesReadLabels(t *testing.T) {
+ var rec apiInstanceRecord
+ json.Unmarshal([]byte(`{"host":"a.shop.example.com","region":"uk","region_name":"London (uk)","move_phrase":"moving to Sydney (au)","region_label":"London (uk)"}`), &rec)
+ if rec.RegionName != "London (uk)" || rec.MovePhrase != "moving to Sydney (au)" || rec.RegionLabel != "London (uk)" {
+ t.Fatalf("instance record = %+v", rec)
+ }
+ var life, old apiAppLife
+ json.Unmarshal([]byte(`{"app":"shop","region":"ie","region_name":"Dublin (ie)"}`), &life)
+ json.Unmarshal([]byte(`{"app":"shop"}`), &old)
+ if life.RegionName == nil || *life.RegionName != "Dublin (ie)" || life.Region != "ie" || old.RegionName != nil {
+ t.Fatalf("apps list rows = %+v / %+v", life, old)
+ }
+ var regions apiRegionsResult
+ json.Unmarshal([]byte(`{"regions":[{"code":"uk","name":"UK · London","label":"London (uk)"},{"code":"au","name":"Australia · Sydney"}],"app_default":{"region":"ie","label":"Dublin (ie)"}}`), &regions)
+ if regions.labelOf("uk") != "London (uk)" || regions.labelOf("au") != "Australia · Sydney" || regions.labelOf("nz") != "nz" || regions.AppDefault.Label != "Dublin (ie)" {
+ t.Fatalf("regions = %+v", regions)
+ }
+ var off offlineView
+ json.Unmarshal([]byte(`{"from":"ie","to":"uk","from_name":"Dublin (ie)","to_name":"London (uk)"}`), &off)
+ if off.FromName != "Dublin (ie)" || off.ToName != "London (uk)" {
+ t.Fatalf("offline view = %+v", off)
+ }
+ var ans moveAnswer
+ json.Unmarshal([]byte(`{"target":"uk","target_name":"London (uk)","detail":{"from":"ie","from_name":"Dublin (ie)","to_name":"London (uk)"}}`), &ans)
+ if ans.TargetName != "London (uk)" || ans.Detail.FromName != "Dublin (ie)" || ans.Detail.ToName != "London (uk)" {
+ t.Fatalf("move answer = %+v", ans)
+ }
+}
diff --git a/status_instances.go b/status_instances.go
index 2eb8b11bc..aebd33df6 100644
--- a/status_instances.go
+++ b/status_instances.go
@@ -42,6 +42,10 @@ type statusInstanceRow struct {
CPU *float64 `json:"cpu"`
Mem *int64 `json:"mem_bytes"`
Platform bool `json:"platform"`
+ // Region and RegionName are the box's placement code and label (region
+ // labels spec §4); "" from an older console or for a box it cannot name.
+ Region string `json:"region"`
+ RegionName string `json:"region_name"`
}
func (s *apiSession) statusInstanceList(ctx context.Context, account string) ([]statusInstanceRow, error) {
@@ -157,6 +161,10 @@ type statusLayoutBox struct {
// DefaultBlocked: why the default is not in force on this box.
Default bool `json:"default"`
DefaultBlocked string `json:"default_blocked"`
+ // Region and RegionName are the box's placement code and label (region
+ // labels spec §4); "" from an older console or for a box it cannot name.
+ Region string `json:"region"`
+ RegionName string `json:"region_name"`
}
func (s *apiSession) statusLayoutList(ctx context.Context) ([]statusLayoutBox, error) {