plan: named-unit declarations from an operator parameter
Eight tasks: the strict gate, installer split, SSM adapter, the root fetch step, SyncUnits outcomes, heartbeat field, operator put/show, copy review + census. Spec updated from the code survey: per-host console guard, a public rootstate status store, hold only while a rollback attempt is in flight, show reads /api/cli/system/status.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+403
−10
docs/superpowers/plans/2026-11-19-named-units-from-parameters.md+385 −0docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md+18 −10
CI passed — run details
diff --git a/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md b/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md| new file mode 100644 |
| index 000000000..761a14ce0 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md |
| @@ -0,0 +1,385 @@ |
| +# Named-unit declarations from a parameter: Implementation Plan |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** Root installs `/etc/carlos/named-units.json` from the |
| +operator-written parameter `/carlos/host/named-units/<instance-id>` |
| +during its adopt pass, and reports each outcome through the heartbeat, |
| +so declaring a unit needs no SSM session. |
| + |
| +**Architecture:** |
| +- A new leaf package holds the one strict gate that both the release |
| + path and the installer use. |
| +- An AWS adapter in `internal/hostenv` reads and writes the parameter. |
| +- A new step in `runAdoptUnderRootRelease` fetches the parameter, gates |
| + it and installs it under the config-sync flock, then writes a public |
| + status record. |
| +- `SyncUnits` reports per-unit outcomes through a hook. |
| +- The agent folds the record into `BoxMetrics`, and the console's system |
| + status rows carry it to `carlos system named-units show`. |
| + |
| +**Tech Stack:** Go; AWS SDK v2 SSM (method values, not `*ssm.Client`, |
| +per `awsssm.go:21-25`); `rootstate` public stores; systemd root units. |
| + |
| +**Spec:** `docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md` |
| +(approved by Paul 2026-11-19). Read it before any task. |
| + |
| +## Global Constraints |
| + |
| +- Parameter name: `/carlos/host/named-units/<instance-id>`. Type |
| + `String`. The box's own AWS region. Value = the whole file, byte for |
| + byte. |
| +- Instance ID and region come only from root's own IMDSv2 read |
| + (`readIdentity(haIMDSClient, imdsBase)`, `internal/host/haself.go:83`). |
| + Never from env, host.env or the bucket. |
| +- Value cap: 4096 bytes (`namedunits.MaxBytes`). |
| +- Absent parameter: never touch the file. Read error: never touch the |
| + file. Equal bytes: never rewrite the file. |
| +- The file changes only under `lockConfigSync(appconfig.DefaultEnvDir + "/.sync")`. |
| +- The step runs in the full and `--config-only` passes, not in |
| + `-restart-only`, and does not depend on `CARLOS_SECRETS_KEY`. |
| +- The step skips, with no network call, on group boxes |
| + (`os.Lstat(hostenv.GroupConfigPath)` succeeds) and fleet boxes |
| + (`resolveFleetIdentity(os.Getenv)` returns no error). |
| +- Bound the step: IMDS 2 s (existing `haIdentityRead`), SSM read 10 s. |
| +- Outcome strings, exactly: `installed`, `unchanged`, `not-found`, |
| + `unreadable`, `invalid`, `held`, `skipped`. |
| +- Status store: `/var/lib/carlos-named-units`, record `status.json`, |
| + public (0644). |
| +- Every user-facing string (log lines, CLI output, docs) goes through |
| + the copy-review skill before merge. Paul's bans: no em dashes; use |
| + curly quotes in prose. |
| +- Testing: targeted `go test ./<pkg> -run <Test>` only. No full suites |
| + locally (CI runs on amadan). Before handing off: |
| + `GOOS=darwin go build ./...` and `GOOS=windows go build ./...`. |
| +- Commit subjects under 80 characters, with the body after a blank |
| + line. |
| + |
| +## Review Focus |
| + |
| +1. **A box replaced under the same declaration.** The new instance ID |
| + has no parameter, so the result is `not-found` with the parameter |
| + path and region in the record, and the existing file stays. |
| + (Task 4 test `TestNamedUnitsFetchNotFoundKeepsFile`.) |
| +2. **A value with a trailing newline, or CRLF line endings.** It is |
| + accepted (JSON whitespace), and installed once. The next pass is |
| + `unchanged`. (Task 1 test `TestValidateStrictAcceptsTrailingWhitespace`, |
| + Task 4 test `TestNamedUnitsFetchEqualBytesNoRewrite`.) |
| +3. **The operator puts in the wrong region.** The box reports |
| + `not-found` with its own region in the record, and `show` prints |
| + both regions. (Task 7 test `TestNamedUnitsShowNamesBothRegions`.) |
| +4. **A slow or throttled SSM read.** It is bounded at 10 s and recorded |
| + as `unreadable`. The pass carries on to `SyncUnits`. (Task 4 test |
| + `TestNamedUnitsFetchReadErrorKeepsFileAndContinues`.) |
| +5. **Clearing with `{"schema":1,"units":[]}`.** It installs, and the |
| + next `SyncUnits` reaps the drop-ins, as for a hand install. (Task 4 |
| + test `TestNamedUnitsFetchInstallsClearingValue`.) |
| + |
| +--- |
| + |
| +### Task 1: The strict gate (`internal/namedunits`) |
| + |
| +**Files:** |
| +- Create: `internal/namedunits/namedunits.go`, `internal/namedunits/namedunits_test.go` |
| +- Modify: `internal/host/proofnamed.go:24-31,101-122` (use the shared decoder) |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + const MaxBytes = 4096 |
| + type Entry struct { |
| + Host string `json:"host"` |
| + Account string `json:"account,omitempty"` |
| + App string `json:"app"` |
| + Unit string `json:"unit"` |
| + Addr string `json:"addr"` |
| + Health *provision.Health `json:"health"` |
| + } |
| + // Decode is the release path's reading: DisallowUnknownFields, one JSON |
| + // document then EOF, schema 1, every entry's host/app/account valid. |
| + func Decode(raw []byte) ([]Entry, error) |
| + // ValidateStrict is Decode plus, for EVERY entry: len(raw) <= MaxBytes, |
| + // Unit non-empty and registry.ValidUnitName and not "carlos-app@"-prefixed, |
| + // Addr non-empty, Health != nil && Health.Path != "", no host twice, |
| + // no unit twice. |
| + func ValidateStrict(raw []byte) error |
| + // Hosts returns the hosts a decoded file names (for the rollback hold). |
| + func Hosts(entries []Entry) []string |
| + ``` |
| +- `proofnamed.go`: `namedUnit` becomes `= namedunits.Entry` (a type |
| + alias), and the decode at `:101-114` calls `namedunits.Decode`, with |
| + any error mapped to `os.ErrPermission`. The per-selected-host |
| + duplicate check and the rule at `:150` stay where they are. |
| + |
| +- [ ] **Step 1: Write failing tests** in `namedunits_test.go`: |
| + - `TestDecodeRefusesUnknownField`: `{"schema":1,"units":[{"host":"a.example.com","app":"shop","unit":"shop.service","addr":"127.0.0.1:1","health":{"path":"/"},"extra":1}]}` → error. |
| + - `TestDecodeRefusesTrailingDocument` (`{...}{}`) → error. `TestDecodeRefusesSchema2` → error. |
| + - `TestValidateStrictRequiresAddrAndHealthOnEveryEntry`: two entries, the second without `addr` → error naming that host. The same without `health.path` → error. |
| + - `TestValidateStrictRefusesEmptyUnit`, `TestValidateStrictRefusesCarlosAppUnit` (`carlos-app@x.service`), `TestValidateStrictRefusesUnitTwice`, `TestValidateStrictRefusesHostTwice`. |
| + - `TestValidateStrictRefusesOverCap`: a valid file padded with spaces to 4097 bytes → error. |
| + - `TestValidateStrictAcceptsTrailingWhitespace`: a valid file + `"\r\n"` → nil. |
| + - `TestValidateStrictAcceptsEmptyUnits`: `{"schema":1,"units":[]}` → nil. |
| +- [ ] **Step 2:** Run `go test ./internal/namedunits -run 'TestDecode|TestValidateStrict'`. Expect FAIL (no package). |
| +- [ ] **Step 3:** Implement the package. Error text names the host or |
| + unit and the rule. Copy goes through copy review in Task 8. |
| +- [ ] **Step 4:** Run step 2 again: PASS. Switch `proofnamed.go` to the |
| + shared decoder, then run |
| + `go test ./internal/host -run 'TestPlan14NamedUnits|TestProductionUnitOpsDeclarationIsTheReleasePathsFile'`: PASS, unchanged. |
| +- [ ] **Step 5:** Commit: `namedunits: one strict gate for the declaration file`. |
| + |
| +### Task 2: Installer split and strict gate |
| + |
| +**Files:** |
| +- Modify: `internal/host/unitops.go:49-90` (InstallNamedUnits) |
| +- Test: `internal/host/unitops_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: `namedunits.ValidateStrict`, `appconfig.ValidateDeclarations`. |
| +- Produces: |
| + ```go |
| + // validateForInstall: both readers must accept raw. |
| + func validateForInstall(raw []byte) error // ValidateDeclarations(raw) then namedunits.ValidateStrict(raw) |
| + // installNamedUnitsLocked writes raw to dst atomically (today's body: |
| + // tmp O_EXCL 0644, fsync, rename, dir fsync). Caller holds the lock and |
| + // has validated. |
| + func installNamedUnitsLocked(dst string, raw []byte) error |
| + ``` |
| + `InstallNamedUnits(envDir, dst, raw)` keeps its signature: |
| + `validateForInstall`, then the lock, then `installNamedUnitsLocked`. |
| + |
| +- [ ] **Step 1: Failing test** `TestInstallNamedUnitsRefusesWhatTheReleasePathRefuses`: a file with an unknown field, or an entry without `addr`, returns an error, and `dst` is not created. |
| +- [ ] **Step 2:** `go test ./internal/host -run 'TestInstallNamedUnits'`. Expect the new test to FAIL and `TestInstallNamedUnitsWaitsForTheConfigSyncLock` to PASS. That test must keep passing; if its fixture lacks addr/health, give it both. |
| +- [ ] **Step 3:** Implement the split. |
| +- [ ] **Step 4:** Run step 2 again: PASS. |
| +- [ ] **Step 5:** Commit: `host: named-units install takes the strict gate; split the locked write`. |
| + |
| +### Task 3: The parameter adapter (`internal/hostenv`) |
| + |
| +**Files:** |
| +- Create: `internal/hostenv/namedunits.go`, `internal/hostenv/namedunits_test.go` |
| +- Modify: `internal/hostenv/awsssm.go` (add a GetParameter method value and an opener) |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + const NamedUnitsPrefix = "/carlos/host/named-units/" |
| + var ErrNoParameter = errors.New("hostenv: parameter not found") |
| + // NamedUnitsParameter validates iid against ^i-[0-9a-f]{8}([0-9a-f]{9})?$ (bindingIID). |
| + func NamedUnitsParameter(iid string) (string, error) |
| + type NamedUnitsStore interface { |
| + // Get returns ErrNoParameter for ParameterNotFound, and an error for |
| + // a parameter whose Type is not String. |
| + Get(ctx context.Context, iid string) (raw []byte, version int64, err error) |
| + // Put writes Type=String, Overwrite=true; returns the new version. |
| + Put(ctx context.Context, iid string, raw []byte) (version int64, err error) |
| + } |
| + func OpenNamedUnitsStore(ctx context.Context, awsRegion string) (NamedUnitsStore, error) |
| + ``` |
| + The opener uses `rootaws.LoadDefaultConfig` with |
| + `config.WithRegion(awsRegion)`, as `openSSMParamsMode` does, so root |
| + gets the IMDS chain and an operator gets their profile. |
| + `WithDecryption` is false. |
| + |
| +- [ ] **Step 1: Failing tests**, using fake `get` and `put` funcs on the |
| + unexported struct: |
| + - `TestNamedUnitsGetMapsParameterNotFound`: `&types.ParameterNotFound{}` → `errors.Is(err, ErrNoParameter)`. |
| + - `TestNamedUnitsGetRefusesSecureString`: Type `SecureString` → an error that isn't ErrNoParameter. |
| + - `TestNamedUnitsPutSendsStringOverwrite`: the input has Name `/carlos/host/named-units/i-0123456789abcdef0`, `Type == types.ParameterTypeString`, `Overwrite == true`, and the value equal to the raw bytes. |
| + - `TestNamedUnitsParameterRefusesBadInstanceID`: `"i-xyz"`, `"../x"` → error. |
| +- [ ] **Step 2:** `go test ./internal/hostenv -run TestNamedUnits`. Expect FAIL. |
| +- [ ] **Step 3:** Implement. |
| +- [ ] **Step 4:** Run step 2 again: PASS. Then run `GOOS=windows go build ./internal/hostenv`. |
| +- [ ] **Step 5:** Commit: `hostenv: a box's named-units parameter, read and put`. |
| + |
| +### Task 4: The root fetch step and status record |
| + |
| +**Files:** |
| +- Create: `internal/host/namedunitsfetch.go`, `internal/host/namedunitsfetch_test.go` |
| +- Modify: `internal/status/snapshot.go` (the record types only; Task 6 wires them into the heartbeat), `internal/host/rootrollback.go` (one helper), `internal/host/agent.go` (`runAdoptUnderRootRelease`, after the `-restart-only` return at `:6157`, before `ParsePublicKey` at `:6165`) |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 1-3; `readIdentity`, `haIMDSClient`, `imdsBase`; `lockConfigSync`; `rootstate.Open`, `rootstate.OpenTrustedFile`; `readRollbackAttempt`, `rollbackMargin`, `rootRestartState`. |
| +- Produces: |
| + ```go |
| + // internal/status |
| + type NamedUnitsStatus struct { |
| + Parameter string `json:"parameter,omitempty"` |
| + InstanceID string `json:"instance_id,omitempty"` |
| + Region string `json:"region,omitempty"` |
| + Version int64 `json:"version,omitempty"` |
| + Outcome string `json:"outcome"` |
| + Reason string `json:"reason,omitempty"` |
| + Digest string `json:"digest,omitempty"` // sha256 hex of the installed file |
| + At time.Time `json:"at"` |
| + Units []NamedUnitDelivery `json:"units,omitempty"` |
| + } |
| + type NamedUnitDelivery struct { |
| + Host string `json:"host"` |
| + Unit string `json:"unit"` |
| + State string `json:"state"` // "delivered" | "refused" |
| + Reason string `json:"reason,omitempty"` |
| + } |
| + |
| + // internal/host |
| + const namedUnitsStatusDir = "/var/lib/carlos-named-units" |
| + // rollbackInFlight: an attempt exists, !Settled, and now is before |
| + // Deadline+rollbackMargin. No side effects (unlike loadRollback). |
| + func rollbackInFlight(s rootstate.Store, host string, now time.Time) (bool, error) |
| + type namedUnitsFetch struct { |
| + skip func() string // non-empty = skip reason |
| + identity func(ctx context.Context) (iid, region string, err error) |
| + open func(ctx context.Context, region string) (hostenv.NamedUnitsStore, error) |
| + lock func() (func(), error) |
| + dst string |
| + inFlight func(host string) (bool, error) |
| + guardHost func() (host string, ok bool) // console guard's host, if armed |
| + now func() time.Time |
| + } |
| + func (f namedUnitsFetch) run(ctx context.Context) status.NamedUnitsStatus |
| + func productionNamedUnitsFetch() namedUnitsFetch |
| + func writeNamedUnitsStatus(st status.NamedUnitsStatus) error // rootstate.Open(namedUnitsStatusDir, true, true).Write("status.json", ...) |
| + ``` |
| +- `run` follows the spec's table. |
| + 1. Run `skip`, then `identity` (any error → `skipped`). |
| + 2. Open and Get, under a 10 s context: |
| + - `ErrNoParameter` → `not-found` |
| + - any other error → `unreadable` |
| + 3. Gate the value with `validateForInstall`, plus the guard rule (if |
| + `guardHost` returns a host, that host's entry must be |
| + `console.service`, app `console`, empty account). Failure → |
| + `invalid`. |
| + 4. Then, under `lock`: |
| + - Read `dst` with `OpenTrustedFile`. Equal bytes → `unchanged`. |
| + - Any host in the *current* file with `inFlight` true (or an error) |
| + → `held`, with the host named. |
| + - Otherwise `installNamedUnitsLocked` → `installed`. |
| + 5. `Digest` is the sha256 of the file as it stands after the step. |
| +- Wiring: a package var `adoptNamedUnitsStep = func(ctx context.Context) status.NamedUnitsStatus { return productionNamedUnitsFetch().run(ctx) }`. |
| + `runAdoptUnderRootRelease` calls it, logs one line for the outcome, |
| + and keeps the result for Task 5 to complete and write. |
| + `guardHost` reads `<opt>/system/guard/console-ready.json` with the |
| + same trusted read and the same `release.LiveLink` match as |
| + `proofnamed.go:126-133`. Extract that match into one helper both |
| + files call. |
| + |
| +- [ ] **Step 1: Failing tests**, with fakes for every field and `t.TempDir()` for `dst`: |
| + - `TestNamedUnitsFetchNotFoundKeepsFile`: the file exists, Get returns ErrNoParameter → `not-found`, the file bytes and inode unchanged, and `Parameter`, `InstanceID` and `Region` set. |
| + - `TestNamedUnitsFetchReadErrorKeepsFileAndContinues`: Get returns `context.DeadlineExceeded` → `unreadable`, the file unchanged. |
| + - `TestNamedUnitsFetchInvalidKeepsFile`: a value missing `addr` → `invalid`, a reason naming the host, the file unchanged. |
| + - `TestNamedUnitsFetchEqualBytesNoRewrite`: same bytes → `unchanged`, and the inode is the same before and after. |
| + - `TestNamedUnitsFetchInstallsNewValue`: → `installed`, the file equals the value, mode 0644, `Version` and `Digest` set. |
| + - `TestNamedUnitsFetchInstallsClearingValue`: `{"schema":1,"units":[]}` → `installed`. |
| + - `TestNamedUnitsFetchHeldWhileRollbackInFlight`: `inFlight` is true for a host in the current file → `held`, the reason names the host, the file unchanged. Flip it to false and run again → `installed`. |
| + - `TestNamedUnitsFetchSkipsGroupAndFleetWithoutNetwork`: `skip` returns a reason → `skipped`, and the `identity` and `open` fakes are never called. |
| + - `TestNamedUnitsFetchGuardHostMustBeConsole`: the guard names `a.example.com`, and the value maps it to `shop.service` → `invalid`. |
| + - `TestNamedUnitsFetchWaitsForConfigSyncLock`: the shape of `TestInstallNamedUnitsWaitsForTheConfigSyncLock`, using the real `lockConfigSync`. |
| + - `TestRollbackInFlight` (in `rootrollback_test.go` or alongside it): no attempt → false; settled → false; past the deadline plus margin → false; open → true. Nothing is written to the store. |
| + - `TestAdoptRunsNamedUnitsStepBeforeConfigSync`: a source-order check over `runAdoptUnderRootRelease`, in the style of `TestRunAdoptOpensTheRegistryThroughTheHelper` (`registryowner_test.go:301`). `adoptNamedUnitsStep(` appears after the `if *restartOnly` block and before `appconfig.SyncUnits(`, and outside the `CARLOS_SECRETS_KEY` branch. |
| + - `TestProductionNamedUnitsFetchIsWired`: every field of `productionNamedUnitsFetch()` is non-nil, and `dst == appconfig.DefaultNamedUnitsPath`. |
| +- [ ] **Step 2:** `go test ./internal/host -run 'TestNamedUnitsFetch|TestRollbackInFlight|TestAdoptRunsNamedUnitsStep|TestProductionNamedUnitsFetch'`. Expect FAIL. |
| +- [ ] **Step 3:** Implement and wire. |
| +- [ ] **Step 4:** Run step 2 again: PASS. Then run `GOOS=darwin go build ./...` and `GOOS=windows go build ./...`. |
| +- [ ] **Step 5:** Commit: `host: root installs named-units from the box's parameter`. |
| + |
| +### Task 5: Per-unit outcomes from SyncUnits |
| + |
| +**Files:** |
| +- Modify: `internal/appconfig/unitsync.go` (`UnitOps` gets a hook; refusal sites at :264-303, :447, :456, :484; success at :326, :329, :467), `internal/appconfig/sync.go:256,362`, `internal/host/agent.go` (collect, then write the record) |
| +- Test: `internal/appconfig/unitsync_test.go`, `internal/host/namedunitsfetch_test.go` |
| + |
| +**Interfaces:** |
| +- Produces, on `appconfig.UnitOps`: |
| + ```go |
| + // Outcome, when set, is called exactly once per declared host per pass |
| + // that reaches planning: state "delivered" (config current, restarted |
| + // or not) or "refused" with the same reason the pass prints. |
| + Outcome func(host, unit, state, reason string) |
| + ``` |
| +- In `runAdoptUnderRootRelease`, `productionUnitOps` gets an `Outcome` |
| + that appends to `st.Units`. After `SyncUnits` returns (or is skipped |
| + for want of a key), call `writeNamedUnitsStatus(st)` once. On a |
| + `-restart-only` pass, write nothing. |
| + |
| +- [ ] **Step 1: Failing tests:** |
| + - `TestSyncUnitsReportsOneOutcomePerDeclaredHost`. Use `newFakeUnits` with two declared hosts: one delivers, and one has an unmanaged `EnvironmentFile`. That gives exactly two calls: `delivered`, and `refused` with the same reason text the pass prints. |
| + - `TestSyncUnitsOutcomeNilIsSafe`: the existing behaviour with no hook. |
| + - `TestAdoptWritesNamedUnitsStatusOnce` (host, with fakes for the step and the writer): one write per full or config-only pass, none on restart-only. |
| +- [ ] **Step 2:** `go test ./internal/appconfig -run 'TestSyncUnitsReportsOneOutcome|TestSyncUnitsOutcomeNil'` and `go test ./internal/host -run TestAdoptWritesNamedUnitsStatus`. Expect FAIL. |
| +- [ ] **Step 3:** Implement. Call the hook next to the existing |
| + `fmt.Printf` at each site; don't change any printed text. |
| +- [ ] **Step 4:** Run step 2 again, then the existing declaration tests (`go test ./internal/appconfig -run 'TestSyncUnits.*Declar'`): PASS. |
| +- [ ] **Step 5:** Commit: `appconfig: SyncUnits reports each declared unit's outcome`. |
| + |
| +### Task 6: The heartbeat carries the record |
| + |
| +**Files:** |
| +- Modify: `internal/status/snapshot.go` (`Probes`, `BoxMetrics`, `CollectBox` presence check `:1261-1268` and literal `:1276-1328`), `internal/host/agent.go` (`statusLoop` probes `:5172-5300`) |
| +- Create: `internal/host/namedunitsprobe.go`, with its test |
| + |
| +**Interfaces:** |
| +- Produces: |
| + - `Probes.NamedUnits *status.NamedUnitsStatus` |
| + - `BoxMetrics.NamedUnits *status.NamedUnitsStatus` with tag `json:"named_units,omitempty"` |
| + - `func namedUnitsStatusProbe() *status.NamedUnitsStatus`. It reads `status.json` with `rootstate.Open(namedUnitsStatusDir, false, true)`, caps it at 64 KiB, and returns nil on any error. |
| + |
| +- [ ] **Step 1: Failing tests:** |
| + - `TestCollectBoxCarriesNamedUnits`: Probes with a record → `Metrics.NamedUnits` equal to it. Without one → nil, and the presence check is unchanged. |
| + - `TestNamedUnitsStatusProbeNilOnMissingOrOversize`. |
| +- [ ] **Step 2:** `go test ./internal/status -run TestCollectBoxCarriesNamedUnits` and `go test ./internal/host -run TestNamedUnitsStatusProbe`. Expect FAIL. |
| +- [ ] **Step 3:** Implement. |
| +- [ ] **Step 4:** Run step 2 again: PASS. |
| +- [ ] **Step 5:** Commit: `status: the heartbeat carries the named-units record`. |
| + |
| +### Task 7: Operator CLI `put` / `show`, and the console status rows |
| + |
| +**Files:** |
| +- Modify: `internal/host/unitops.go` (`RunSystemNamedUnits` dispatch), `internal/console/apisystemupdate.go` (`handleAPISystemStatus` rows, `:1057`), `system.go` (`systemBoxRow` `:326`; usage line `:220`), `docs/site/cli.md` (the `carlos system named-units` section, ~`:3343`) |
| +- Create: `internal/host/namedunitscli.go`, with its test |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + // put: no root needed. Read FILE, validateForInstall, OpenNamedUnitsStore(region), Put. |
| + // show: Get and print value + version; then the console row whose |
| + // instance_id matches, printing its named_units record. |
| + func runNamedUnitsPut(ctx context.Context, args []string, out io.Writer, open func(ctx context.Context, region string) (hostenv.NamedUnitsStore, error)) error |
| + func runNamedUnitsShow(ctx context.Context, args []string, out io.Writer, open func(ctx context.Context, region string) (hostenv.NamedUnitsStore, error), boxes func(ctx context.Context) ([]systemBoxRow, error)) error |
| + ``` |
| + Flags: `--instance` (required), `--aws-region` (optional, falls back |
| + to the SDK default). `install` is unchanged and stays root-only. |
| +- Console rows gain `"instance_id"` (from `Metrics.InstanceID`) and |
| + `"named_units"` (from `Metrics.NamedUnits`). `systemBoxRow` gains |
| + `InstanceID string` and `NamedUnits *status.NamedUnitsStatus`. |
| + `boxes` in production is the same `sess.getJSON(ctx, "/api/cli/system/status")` that `runSystemStatus` uses (`system.go:585`). |
| + Extract it if `RunSystemNamedUnits` can't reach it from |
| + `internal/host`. If that crosses packages awkwardly, the dispatch for |
| + `put`/`show` may live in `system.go` and call into `internal/host`. |
| + Builder's call. |
| + |
| +- [ ] **Step 1: Failing tests:** |
| + - `TestNamedUnitsPutRefusesInvalidBeforeAWS`: the `open` fake records whether it was called. With an invalid file it is never called. |
| + - `TestNamedUnitsPutPrintsPathVersionAndPickup`. |
| + - `TestNamedUnitsShowNamesBothRegions`: the parameter was read in `eu-west-1`, and the box record says region `eu-west-2` with `not-found`. Both regions are printed. |
| + - `TestNamedUnitsShowBoxNotReported`: no row matches → the output says the box hasn't reported for that instance. |
| + - `TestAPISystemStatusRowsCarryInstanceAndNamedUnits` (console). |
| +- [ ] **Step 2:** Run the new tests with targeted `-run` in `./internal/host`, `.` and `./internal/console`. Expect FAIL. |
| +- [ ] **Step 3:** Implement. Write the CLI copy (the pickup line from the |
| + spec, outcomes, the no-report line) and the docs/site/cli.md |
| + paragraph. Collect them for Task 8's copy review. |
| +- [ ] **Step 4:** Run step 2 again: PASS. |
| +- [ ] **Step 5:** Commit: `cli: carlos system named-units put and show`. |
| + |
| +### Task 8: Copy review, census, and branch review |
| + |
| +**Files:** |
| +- Modify: the strings from Tasks 1, 4, 5 and 7 as Paul edits them; |
| + `docs/superpowers/notes/census-proposal-named-units-param-114.md` and |
| + the census chain files (generated) |
| + |
| +- [ ] **Step 1:** Run the copy-review skill over every new user-facing string (CLI output, log lines an operator reads, errors from the gate, docs). Apply Paul's edits verbatim. |
| +- [ ] **Step 2:** Run `make census-card`. Write CLAIMS for each changed root-read unit (the new fetch step's reads: IMDS, SSM, `named-units.json` via the trusted read, the rollback store, the guard marker). Then run `make census-propose NAME=named-units-param-114 CLAIMS=<file>`, and commit the overlay and the card. |
| +- [ ] **Step 3:** Run the targeted tests from Tasks 1-7, the census test (`go test ./internal/provision -run TestPlan14RootReadCensus`), and both cross-builds: all PASS. |
| +- [ ] **Step 4:** Push, and let CI on amadan run the full suite. Then get Astra's branch review and census verdict: at most three rounds (record them on #280 and #114). |
| +- [ ] **Step 5:** Commit any fixes. |
| + - Merge subject: `Named-unit declarations from an operator parameter (#114)`. |
| + - The body carries the reviews and "Not released". |
diff --git a/docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md b/docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md| index eb9894faf..ef4e1c317 100644 |
| --- a/docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md |
| +++ b/docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md |
| @@ -150,10 +150,10 @@ silently skip boxes without the key.) |
| | Any other error (denied, throttled, network) | Nothing to the file. Log once per pass: `named-units: parameter <path> unreadable: <err>; the installed declarations stand`. | |
| | A value | Validate it (next section). If it is invalid, log the reason and leave the file. If it is valid and its bytes equal the installed file, do nothing. Otherwise install it. | |
| -4. **Hold the install while a rollback is recorded.** If the release |
| - path has a recorded restart or rollback binding for any host the |
| - current file names (`/var/lib/carlos-release/private/restarts`), |
| - don't install. Report `held: a recorded rollback of <host> needs the |
| +4. **Hold the install while a rollback is in flight.** If the release |
| + path has an unsettled rollback attempt, within its deadline, for any |
| + host the current file names (`readRollbackAttempt` in |
| + `/var/lib/carlos-release/private/restarts`), don't install. Report `held: a recorded rollback of <host> needs the |
| current declarations` and try again next pass. A new file identity |
| would otherwise strand that rollback, with nobody on the box to |
| notice. (My call, from the builder check.) |
| @@ -192,7 +192,10 @@ A value is installed only if both readers of the file accept it: |
| is what keeps "both readers accept it" true.) |
| Root also applies, at install time only, the one rule that depends on |
| -the box: on a box with the console guard, entries must be the console's. |
| +the box: if the console guard names a host (`proofnamed.go:126-146`), |
| +that host's entry must be the console's (`console.service`, app |
| +`console`, ops account). The guard is per host, as the release path |
| +reads it; other entries on a guarded box are unaffected. |
| The builder extracts the release decoder and per-entry rules into one |
| function that both `proofnamed.go` and the installer call. The local |
| @@ -233,15 +236,19 @@ took what they wrote and why not if it didn't. The journal alone would |
| need a shell on the box, which is what this change removes. |
| - **Root writes a status record** each time the step runs: |
| - `/var/lib/carlos/named-units-status.json`, root-owned, mode 0644, |
| - replaced atomically. It holds: |
| + `status.json` in the public root store `/var/lib/carlos-named-units` |
| + (`rootstate.Open(dir, true, true)`, the same convention as |
| + `/var/lib/carlos-swap-status`), root-owned, mode 0644, replaced |
| + atomically. It holds: |
| - the parameter path and the version last read (or none), |
| - the outcome: `installed`, `unchanged`, `not-found`, `unreadable`, |
| `invalid`, `held` or `skipped`, with the reason, |
| - the sha256 of the installed file, and when the step ran, |
| + - the box's instance ID and AWS region as root read them, |
| - each declared unit's delivery state from the last `SyncUnits` pass: |
| - delivered, or refused with the rail's reason. `SyncUnits` adds this |
| - part after it runs, still under its lock. |
| + delivered, or refused with the rail's reason. `SyncUnits` reports |
| + these through a new hook on `UnitOps`, and root adds them to the |
| + record after `SyncUnits` returns. |
| - **The agent adds it to the heartbeat** it already sends. It reads the |
| file, size-capped, and includes it as one new snapshot field next to |
| the box's other root-side facts. The field is optional, and an old |
| @@ -249,7 +256,8 @@ need a shell on the box, which is what this change removes. |
| - **`carlos system named-units show --instance <id>`** prints the stored |
| parameter and, beside it, what the box last reported: version taken, |
| outcome, and each unit's delivery state. It reads the heartbeat |
| - through the console API the operator CLI already uses for box status. |
| + through `GET /api/cli/system/status` (what `carlos system status` |
| + uses), whose rows gain the instance ID and this record. |
| If the box hasn't reported since the put, it says so with the |
| heartbeat's age. |
| - Each outcome is also logged in the journal, once per pass. |