Repository navigation
feat: mocactl startup banner with component versions - #484
Conversation
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Adds a startup banner to the mocactl TUI showing the mocactl, control-plane and harness versions plus the cwd. To get those versions the PR adds version to GET /v1/discovery, changes knative-server GET /health from bare ok to JSON {status, version}, gives each of the three packages a resolveVersion() (MOCA_VERSION env, else ../package.json), and bumps all three package.json files from 0.0.0 to 0.5.2.
The banner code itself is clean and well tested. The problem is the base: the branch sits on 73f1bf4 (2026-09-29), 372 commits behind main. mergeable_state is dirty with conflicts in 10 files, so GitHub ran no CI on this head (only DCO reported). Main has also moved underneath the design:
- mocactl already has a build-time version on main (
src/version.tsexportsVERSIONfrom esbuild'sMOCACTL_VERSIONdefine, used by--version). The PR's add/addversion.tsconflicts with it, and its../package.jsonlookup breaks in the bundled release asset. - main's
docs/api/harness-openapi.yamldeclares/healthastext/plainenum[ok], and main's server test now assertsContent-Type: text/plain. The JSON switch contradicts both. - main's discovery now carries
sandboxTiers(spec-required), and theversionfield is undocumented.
Remote version strings are also printed to the terminal without sanitizeRemote.
Areas reviewed: TypeScript (mocactl, control-plane, knative-server), tests, API contract (openapi specs), security
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes (DCO pass)
CI status: NOT RUN. The PR conflicts with main (mergeable_state: dirty), so no pull_request workflows ran. The author's "make test exit 0" was on the 2026-09-29 base and can't be checked against main.
Prompt-injection check: none found in title, body, or diff.
Conflicting files (local git merge --no-commit origin/main): control-plane handlers.ts, main.ts, test/discovery.test.ts, test/main.test.ts, test/server.test.ts; knative-server src/server.ts, test/server.test.ts; mocactl src/api/types.ts, src/app.tsx, src/version.ts (add/add).
Other nits
- The PR body uses
## Whatrather than## Summary(advisory). - The three
version.tsfiles are byte-identical. After addressing #1 only two remain (control-plane, knative-server), so this is minor, but a shared helper would keep them from drifting.
Drafted by an AI reviewer, approved by a human before posting.
| export function resolveVersion(env: NodeJS.ProcessEnv): string { | ||
| if (env.MOCA_VERSION) return env.MOCA_VERSION; | ||
| try { | ||
| const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { |
There was a problem hiding this comment.
must-fix: Conflicts (add/add) with main's version.ts, which exports VERSION baked in by build.mjs via esbuild define: { MOCACTL_VERSION } (release tag / edge-<sha> / dev, installer spec §4) and feeds mocactl --version. In the bundled release asset, new URL('../package.json', import.meta.url) resolves next to the installed mocactl.mjs. It will either miss (→ unknown) or pick up an unrelated package.json. Even when it works, the banner would disagree with --version. On rebase, use main's VERSION for the banner and drop this file, the MOCA_VERSION client override, and the mocactl package.json bump.
There was a problem hiding this comment.
Rebased onto main: this file is gone. The banner imports main's build-time VERSION (esbuild define: { MOCACTL_VERSION }, release tag / edge- / dev), so it always agrees with --version, and there is no new URL(../package.json) read in the bundled asset. The MOCA_VERSION client override and the mocactl package.json bump (0.5.2) are dropped — back to the 0.0.0 placeholder as on main.
| if (req.method === 'GET' && url === '/health') { | ||
| res.writeHead(200).end('ok'); | ||
| // JSON (not bare 'ok') so clients can read the version; probes only check the status code. | ||
| res.writeHead(200, JSON_HEADERS).end(JSON.stringify({ status: 'ok', version: VERSION })); |
There was a problem hiding this comment.
must-fix: docs/api/harness-openapi.yaml declares /health 200 as text/plain, enum: [ok], and main's test/server.test.ts now asserts res.body === 'ok' and contentType === 'text/plain' (added specifically to make wire and spec agree). This change contradicts both and doesn't update the spec. Either update the spec (and the "Liveness — answers ok" summary) in this PR, or leave /health as-is and expose the version some other way (e.g. an X-Moca-Version response header, which old clients ignore and which keeps the probe body unchanged).
There was a problem hiding this comment.
Reworked per the header suggestion: /health answers text/plain ok again — main's wire/spec test passes unchanged — and the version rides an X-Moca-Version response header, which old clients ignore. docs/api/harness-openapi.yaml documents the header (absent on an old harness, body unchanged either way); mocactl reads it in HarnessClient.health() and treats a missing header as an old harness with nothing to say.
| const { tokens: t } = useTheme(); | ||
| const lines = [ | ||
| `mocactl ${info.mocactlVersion}`, | ||
| `control plane ${info.cpVersion ?? '?'}`, |
There was a problem hiding this comment.
must-fix: cpVersion and harnessVersion are strings from the network (the control plane, and a harness at whatever URL discovery advertises), and they're written straight to the terminal. Elsewhere mocactl runs every remote string through sanitizeRemote (session-options.ts, headless.ts, messages.ts), so a hostile or MITM'd endpoint can't inject ANSI/OSC sequences (clipboard writes, hyperlinks, screen clears). Sanitize both in collectBannerInfo, and cap the length (e.g. 64 chars) so a huge value can't wreck the layout. A test with '\u001b]52;c;…\u0007' as the version would pin it.
There was a problem hiding this comment.
Done in collectBannerInfo: both cpVersion and harnessVersion go through sanitizeRemote and are capped at 64 characters; a value that sanitizes to nothing reads as unknown (a ?), not blank. banner.test.ts pins it with an OSC 52 clipboard-write payload (0.5.2\x1b]52;c;aGVsbG8=\x07), a 100-character version, and an all-controls version.
| * The deployment's version, advertised through /v1/discovery so clients can show it. MOCA_VERSION | ||
| * wins — deploys bake in the git tag they were built from — else this package's own version. | ||
| */ | ||
| export function resolveVersion(env: NodeJS.ProcessEnv): string { |
There was a problem hiding this comment.
must-fix: Nothing in the diff sets MOCA_VERSION: no Dockerfile ARG/ENV, no workflow, no deploy manifest. So every deployment reports the package.json value, and the 0.0.0→0.5.2 bump is a hand-maintained number that is wrong from the next release on (a v0.5.3 build still says 0.5.2). That's misleading in a banner whose job is to diagnose version skew. Either wire the tag in (root Dockerfile ARG MOCA_VERSION → ENV, set by the image build), or follow mocactl's convention and report dev when nothing was baked in, instead of bumping package.json by hand. The same applies to packages/knative-server/src/version.ts.
There was a problem hiding this comment.
Both version.ts files now resolve MOCA_VERSION || 'dev' — no package.json read (a bundled release asset ships none) and no hand-maintained number; the three 0.5.2 bumps are reverted to 0.0.0. The root Dockerfile wires it: ARG MOCA_VERSION=dev → ENV MOCA_VERSION, so an image build bakes the tag in with --build-arg MOCA_VERSION=<tag> and both the control plane and the harness advertise it.
| body: { harnessUrl: deps.config.publicHarnessUrl ?? null }, | ||
| body: { | ||
| harnessUrl: deps.config.publicHarnessUrl ?? null, | ||
| version: deps.config.version ?? null, |
There was a problem hiding this comment.
suggestion: version is a new response field on /v1/discovery, but docs/api/openapi.yaml's getDiscovery schema doesn't list it (on main that schema has required: [harnessUrl, sandboxTiers]). When rebasing, document it as type: [string, 'null'], and add 'version' to the reads for /v1/discovery in packages/mocactl/test/contract.test.ts, so the client/spec contract test covers it.
There was a problem hiding this comment.
Documented in docs/api/openapi.yaml: getDiscovery now lists version as type: [string, 'null'] and adds it to required alongside harnessUrl/sandboxTiers, matching the handler (it always answers the field, null when nothing was baked in). packages/mocactl/test/contract.test.ts lists 'version' in the /v1/discovery reads, so the contract test fails if either side drifts.
|
|
||
| /** A version that did not arrive within `ms` is an unknown version, not a wait. */ | ||
| async function withTimeout<T>(p: Promise<T>, ms: number): Promise<T | undefined> { | ||
| return Promise.race([p, sleep(ms).then(() => undefined)]); |
There was a problem hiding this comment.
nit: withTimeout stops waiting, but the underlying discovery()/health() fetch keeps running. Neither the request nor the 750 ms timer is cancelled. mocactl exits via process.exitCode, not process.exit(), so if a harness hangs, an in-flight socket can keep the process alive after the user quits. Consider passing an AbortSignal (aborted on timeout and on effect cleanup) through to the fetch.
There was a problem hiding this comment.
Done: discovery() and health() now accept { signal? }, threaded through ControlPlaneClient.request and HarnessClient.health into the fetch init. collectBannerInfo runs both calls on one AbortController that follows a caller-supplied signal and is aborted when the timeout gives up; the app effect aborts it on unmount. banner.test.ts asserts the fetch signals are aborted on both timeout and caller abandon, and app.test.tsx pins the unmount case.
baeaed2 to
c98a006
Compare
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Thanks for the rebase. It's clean: range-diff vs baeaed2 shows only the import-list conflict resolutions against #481, and CI is green.
Re-checked the replies to the earlier threads at this head: the version.ts, /health → X-Moca-Version, sanitizeRemote + length cap, openapi/contract, and AbortSignal items are all fixed. 👍
One blocker remains, on the MOCA_VERSION thread: the Dockerfile now declares the ARG, but .github/workflows/build.yaml never passes it, so every published image will report dev (inline below). Two small doc/abort nits are also inline.
nit: the PR body uses ## What rather than ## Summary.
| FROM node:24-alpine | ||
| # The git tag (or sha) this image was built from; advertised by the control plane's /v1/discovery | ||
| # and the harness's /health so clients can show it. Build with --build-arg MOCA_VERSION=<tag>. | ||
| ARG MOCA_VERSION=dev |
There was a problem hiding this comment.
must-fix: Follow-up to the earlier MOCA_VERSION thread. The ARG is here, but nothing sets it: .github/workflows/build.yaml's docker/build-push-action step passes no build-args, so every published ghcr.io/rossoctl/moca image (latest, main-<sha>, vX.Y.Z) advertises dev, and the banner never shows a real control-plane/harness version. Add build-args: MOCA_VERSION=${{ steps.meta.outputs.version }} to that step (the metadata-action already computes the semver / main-<sha>). The other matrix Dockerfiles ignore an unused build-arg.
Separately, declaring the ARG before RUN apk add / COPY --from=builder makes those layers' cache keys depend on its value (ARGs are implicitly in the env of every following RUN), so each new version re-runs the apk install. Move ARG MOCA_VERSION=dev down next to ENV MOCA_VERSION=${MOCA_VERSION}.
There was a problem hiding this comment.
Both done. build.yaml's build-push step now passes build-args: MOCA_VERSION=${{ steps.meta.outputs.version }} (metadata-action's semver / main-<sha>; the other matrix images ignore the unused arg). And the ARG MOCA_VERSION=dev moved down to sit next to ENV MOCA_VERSION, after the apk/COPY layers, with a comment naming the cache-key reason.
| async health(): Promise<void> { | ||
| return (await this.resolve()).health(); | ||
| async health(opts: { signal?: AbortSignal } = {}): Promise<HealthReport> { | ||
| return (await this.resolve()).health(opts); |
There was a problem hiding this comment.
nit: opts.signal reaches HarnessClient.health, but not the discover() call inside resolve(). On first use against a hung control plane, that GET /v1/discovery isn't cancelled by the banner's abort, so the dangling-socket case from the earlier thread is still possible on this path. The resolve promise is cached and shared, so aborting it is awkward. A simpler fix would be for collectBannerInfo to reuse the discovery it already fetched, or for discover() to carry its own timeout.
There was a problem hiding this comment.
Fixed without aborting the shared promise: an uncached health() called with a signal now runs its own one-off, abortable discovery (discoverHarnessUrl(cp, { signal })) instead of going through resolve() — so an abandoned banner probe aborts exactly its fetch and cannot kill a discovery a turn is waiting on. A successful one-off seeds the cache, which also means the banner warms the harness client for later callers. banner.test.ts pins the full chain against a hung control plane (both discovery fetches aborted), and discovery.test.ts pins the signal hand-off and the cache seeding.
| type: [string, 'null'] | ||
| description: | | ||
| the deployment's version (MOCA_VERSION, baked in at image build), so a client | ||
| can show it; null when nothing was baked in (a from-source run reports dev) |
There was a problem hiding this comment.
nit: "null when nothing was baked in (a from-source run reports dev)" contradicts itself: resolveVersion always returns a string (MOCA_VERSION || 'dev'), so this control plane never answers null. Suggest: dev when nothing was baked in, with null permitted for compatibility.
There was a problem hiding this comment.
Reworded: dev when nothing was baked in, and null permitted for compatibility with a control plane that reports none — matching what the code can actually answer.
c98a006 to
ba2a306
Compare
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround. I re-checked all three threads at ba2a306:
- MOCA_VERSION wiring: fixed. build.yaml now passes the build-arg, and the ARG sits below the apk/COPY layers.
- discovery abort: fixed. The one-off abortable discovery for a signalled, uncached
health()keeps the sharedresolve()promise intact and seeds the cache. The new banner/discovery tests pin it nicely. - openapi wording: fixed.
CI is green, so approving. One non-blocking follow-up, which is my mistake from the last round: steps.meta.outputs.version is latest on main pushes, not main-<sha> (inline). Plus one comment nit.
| labels: ${{ steps.meta.outputs.labels }} | ||
| # The version the harness/control plane advertise (MOCA_VERSION; the root Dockerfile is | ||
| # the only one that consumes it — the other matrix images ignore the unused build-arg). | ||
| build-args: MOCA_VERSION=${{ steps.meta.outputs.version }} |
There was a problem hiding this comment.
suggestion: My earlier suggestion here was wrong, sorry. metadata-action takes version from the highest-priority tag, and type=raw (default priority 200) outranks type=sha (100). So on main pushes this resolves to latest, not main-<sha>, and main images will advertise latest. Tag pushes get the semver, which is correct.
Either bump the sha tag above raw:
type=sha,prefix=main-,enable={{is_default_branch}},priority=300or choose the value explicitly:
build-args: MOCA_VERSION=${{ github.ref_type == 'tag' && steps.meta.outputs.version || format('main-{0}', github.sha) }}(note that the sha form is the full SHA, not the 7-char short one the tag uses).
There was a problem hiding this comment.
Took the priority route: the sha tag is now type=sha,prefix=main-,enable={{is_default_branch}},priority=300, with a comment naming the reason, so the version output is main-<sha> on main pushes (raw latest at 200 no longer outranks it). Tag pushes are unaffected — the sha tag is disabled there (enable={{is_default_branch}}), so semver still wins. This also keeps the 7-char sha consistent with the image tag, which the explicit-format alternative would not have.
| # and the harness's /health so clients can show it. Build with --build-arg MOCA_VERSION=<tag>. | ||
| # Declared last: an ARG's value keys the cache of every RUN below it, so declaring it above the | ||
| # apk layer would rebuild that layer on every version change. | ||
| ARG MOCA_VERSION=dev |
There was a problem hiding this comment.
nit: "Declared last" isn't quite accurate: RUN mkdir … /var/lib/moca/credentials still follows, so a version change re-runs that layer. It's cheap, so either move the ARG/ENV below that RUN or reword the comment.
There was a problem hiding this comment.
Moved rather than reworded: ARG/ENV MOCA_VERSION now sit below the RUN mkdir credentials layer, so nothing but EXPOSE/WORKDIR/CMD follows and a version change re-runs no layer at all. The comment now says "declaring it earlier would rebuild those layers".
Print a red logo banner once at the top of the TUI transcript: this client's build version, the control plane's (GET /v1/discovery, additive version field), the harness's (X-Moca-Version header on /health, whose body stays text/plain ok), and the launch directory with ~ folding. It scrolls away with the transcript like any <Static> output and reappears at the top after a redraw. Remote halves are collected in the background (750ms cap each, failures leave a ?), so the TUI paints immediately; both fetches are aborted on timeout or unmount, since mocactl exits via process.exitCode and a lingering socket would hold it alive. Remote versions are sanitized (sanitizeRemote) and capped at 64 characters before they can reach the terminal. Versions are build-time, not hand-bumped: mocactl reads the esbuild MOCACTL_VERSION (the same constant --version prints); control-plane and knative-server read MOCA_VERSION (wired through the image build: the Dockerfile's ARG/ENV and build.yaml's --build-arg from metadata-action) and report dev when nothing was baked in. /v1/discovery's version is documented in docs/api/openapi.yaml and pinned by mocactl's contract test. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ba2a306 to
e5e0dfa
Compare
Summary
mocactl prints a logo banner (pure TrueColor red, via a new
logotheme token soNO_COLORstill applies) once at the top of the transcript. It rides in<Static>as the first item, so it scrolls away with the transcript like any other settled output, and reappears at the top after a redraw (theme toggle,/details, editor round-trip). Headlessmocactl runis unchanged.Where the versions come from
All build-time, no hand-maintained numbers:
VERSION(MOCACTL_VERSION), the same constant--versionprints —devfrom a checkoutGET /v1/discoverygains an additiveversionfield (always answered,nullwhen nothing was baked in); documented indocs/api/openapi.yamland pinned by mocactl's contract testGET /healthkeeps its declaredtext/plainokbody and carries the version in anX-Moca-Versionresponse header (old clients ignore it); documented indocs/api/harness-openapi.yamlMOCA_VERSION || 'dev'— nopackage.jsonread (a bundled release asset ships none); the rootDockerfilewiresARG MOCA_VERSION→ENV MOCA_VERSIONso image builds bake the tag inBehavior details
?— the banner always renders.process.exitCode, so a lingering socket would hold the process alive):discovery()/health()take{ signal? }, threaded through to the fetch.sanitizeRemoteand are capped at 64 characters, so a hostile endpoint cannot inject ANSI/OSC sequences or wreck the layout.<Static>is append-only, so a late-arriving banner after history has printed goes through the existingredraw()re-key rather than a prepend.Verification
version,X-Moca-Versionon/health, client header parsing incl. header-less old harnesses, banner collection with timeout/failure/sanitize/abort cases, banner rendering, banner-above-history ordering, unmount abort)main;make testexit 0 (3,216+ passed, 0 failures),make typecheckexit 0,make lintexit 0🤖 Assisted-By: Claude Code