Skip to content

feat: identify the host in /state and default EMBER_SOURCE to the hostname - #213

Merged
tarakanof merged 7 commits into
mainfrom
feat/208-host-in-state
Oct 3, 2026
Merged

tarakanof merged 7 commits into
mainfrom
feat/208-host-in-state

Conversation

@tarakanof

Copy link
Copy Markdown
Owner

Closes #208

  • /state render carries source and tool of the winning session (empty when none); goldens regenerated.
  • internal/producer/source.go: placeholder or empty EMBER_SOURCE resolves to the short host name (scutil LocalHostName, fallback os.Hostname; lowercased, [a-z0-9_-], 24 chars). Both producers use it; installer template seeds it.
  • Docs: ARCHITECTURE, RUNBOOK, producers/claude-code README.

Tests: gofmt, go vet, go test ./... -race green. Swift untouched (Models.swift does not decode render).

Thin clients (cinder knob, ESP32) had to re-run PickWinning over sessions[] to learn which host needs attention. Part of #208.
A fresh install on a second Mac got the template placeholder and needed hand-editing. Empty or placeholder values now resolve to the lowercased LocalHostName, and the installer seeds that value. Part of #208.

@tarakanof tarakanof left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review (read-only; go vet + go test ./... -race green in the worktree). Mergeable, based on current main 5d17c3f. Auth unaffected (/state stays open). Swift Models.swift does not decode render, as the PR says.

Medium: the default host name makes every Mac look the same on the clock. normalizeHostName keeps the macOS default LocalHostName (Dmitrys-MacBook-Pro), but sourceCardText (internal/render/render.go:414) fits about 4 glyphs. I checked: dmitrys-macbook-pro, dmitrys-macbook-air and dmitrys-mac-mini all render as DMIT. On a fresh second Mac, the clock card and attention label show the same text for both machines, which is the problem #208 is meant to solve. Fix options:

  • strip the default <owner>s- possessive prefix (^[a-z0-9]+s-(?=mac)) so it reads macbook-pro / mac-mini;
  • or have install/doctor print the resolved value with a hint to set a short id (m4). Also mention the 4-glyph card in RUNBOOK.

Low: render.source names one host when the text is an aggregate. In the aggregate.json golden, text AI R2 D1 with source:"a" also covers host b's running session. A thin client showing "on a" next to the aggregate is wrong. Either blank Source when v.Count(win.State) >= 2 and the sources differ (sessions.go:87), or document that source is the tie-break winner only.

Low: scutil is forked on every hook for old installs. loadConfig runs on every Claude hook (hook.go:40) and tick. With the old placeholder or an empty value, ResolveSource execs scutil each time (installs keep their existing producer.env, so every pre-#208 machine hits this). Suggestion: have install/doctor rewrite a placeholder or empty EMBER_SOURCE in place once (producer.ReadEnvFile + set), so the hot path sees an explicit value.

Nits

  • producers/claude-code/config/producer.env.example still says # Required: above EMBER_SOURCE=, which is now empty and optional. The README sentence "defaults to the short host name when empty. Set EMBER_SOURCE…" contradicts itself.
  • The macOS Connection pane (ConnectionSettings(reading:)) shows the raw value (blank or placeholder), not the name the producers actually send.
  • TestLoadConfig_SourceDefaultsFromHostOnPlaceholder passes trivially when DefaultSource()=="". The codex producer has no equivalent test.

Checked and fine: unicode or empty host names strip to "" and fall through. A missing scutil falls back to os.Hostname. The server (Docker) never calls DefaultSource. 24-char truncation re-trims -/_.

An aggregate text like 'AI R2' covers several sessions; naming one host beside it misled thin clients.
… once

macOS default names (Dmitrys-MacBook-Pro/-Air/Mac-mini) all collapsed to DMIT on the 4-glyph clock card; map to mbp/mba/mini. install/configure/doctor now rewrite an empty or placeholder EMBER_SOURCE once (0600 kept) so hooks stop forking scutil, and print the resolved value with a hint.
@tarakanof

Copy link
Copy Markdown
Owner Author

Review fixes pushed (3 commits):

  • Medium: default host id now short (Dmitrys-MacBook-Pro/-Air/Mac-mini -> mbp/mba/mini, '-2' suffix kept; test checks all three differ on SourceCardText). install/configure/doctor print the resolved source + hint to set EMBER_SOURCE.
  • Low: render.source/tool blank when winning-state sessions differ in host/tool; aggregate golden updated, new aggregate-same-host golden; documented.
  • Low: install/configure/doctor rewrite empty/placeholder EMBER_SOURCE in producer.env once (EnsureSourceInEnv, 0600, temp HOME in tests) so hooks don't fork scutil.
  • Nits: env example/README/RUNBOOK wording; host-name injected in placeholder tests; codex producer test added.
    gofmt, go vet, go test ./... -race green.

@tarakanof

Copy link
Copy Markdown
Owner Author

Re-review of ba55051: fixes verified. Every finding is fixed in code, and the tests fail without the fixes (I mutated the aggregate blanking, shortHostID and claude configure's EnsureSourceInEnv, and each one fails). Mergeable; gofmt/vet/go test ./... -race green.

Minor, non-blocking:

  • codex configureAt's EnsureSourceInEnv call has no test (the mutation passes). Doctor now writes producer.env, which is fine but untested.
  • possessiveRe also strips non-Mac names: ops-1 -> 1, nas-server -> server.

Cross-PR: after this merges, #215's T3 producer still reads EMBER_SOURCE raw (cmd/ember-t3-producer/config.go:80, daemon.go:53). It needs producer.ResolveSource in loadConfig plus EnsureSourceInEnv in its configure. Otherwise an empty value exits with 'nothing to do' and the old placeholder gets posted literally as the source. Fresh installs are fine because EnvExample seeds the host id.

The possessive-prefix strip turned names like ops-1 into 1. Now the owner prefix goes only when followed by a known model word (macbook, imac, mac-mini, mbp...), and a bare number is never returned. Akitaka-mbp-14 -> mbp-14. Adds codex configure test.
@tarakanof

Copy link
Copy Markdown
Owner Author

Follow-up: owner prefix now stripped only before a known Mac model word (incl. mbp/mba); ops-1, build-box, dmitrys-laptop unchanged; never bare digits. This Mac's Akitaka-mbp-14 -> mbp-14. Added codex configureAt EnsureSourceInEnv test. Tests green.

@tarakanof
tarakanof merged commit 967fd96 into main Oct 3, 2026
3 checks passed
@tarakanof
tarakanof deleted the feat/208-host-in-state branch October 3, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: identify the host in /state and default EMBER_SOURCE to the hostname

1 participant