Repository navigation
feat(mocactl): a TUI client for the moca (serverless-harness) control plane - #347
Conversation
Terminal client for MU1's /v1 API: device-flow login, session list/create/resume/delete, streaming turns over SSE, and named inference-credential management. No backend changes -- pure HTTP client, zero @sh/* runtime deps. UX modeled on OpenCode's TUI (persistent chat view + overlays, leader-key/slash-command/palette, /details and /thinking toggles, a theme-token seam). Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Records the pivotal decision behind the sh-tui spec: a standalone terminal client with no workspace dependency on any @sh/* package, substrate-agnostic toward Knative vs P6, built on Ink/React with an OpenCode-modeled interaction model. Indexed in docs/adrs/README.md. Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Resume would have shown an empty screen -- no route returns a session's
messages -- so add a local per-subject transcript store and make
GET /v1/sessions/{id}/messages the top owed backend item. Correct the
claim that a harness without MU1 auth is undetectable: a rejected fresh
token is now diagnosed rather than looping through re-login. Enforce
one in-flight turn per session client-side, since the server does not
serialize them.
Also add onboarding, a doctor command, session titles, per-tool
rendering with an edit diff, markdown, latency and usage display, a
native default theme, <Static> rendering, a data-driven command
registry, renderer registries with fallbacks, schema-driven session
options, a contract-drift test, and a headless run mode. ADR-0036
updated to match.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
26 TDD tasks, headless core first: API clients and SSE parser, then transcripts, session options, login, the session manager, doctor and the run/login/doctor commands, then theme, command registry, block model, rendering, overlays, the chat view, and the app. Pins five review-focus inputs (truncated streams, clock skew, torn transcripts, prefixed URLs, malformed config) to named tests. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…f-by-one Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
- Adds ActiveSession for managing per-session turn queue, token lifecycle, and retry logic - Implements SessionManager for creating, resuming, and removing sessions - Handles token remint with 30s margin before expiry - Retries on token errors (invalid, expired) and 503 with Retry-After - Never retries once frames have flowed (stream_truncated error continues queue) - Reports turn-start, frame, retrying, and turn-end events - Integrates with TranscriptStore for persistent turn history - Review Focus #1 (truncated stream ends as error, queue continues) and rossoctl#2 (token_expired remints once and succeeds) both tested and passing Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…, turn-end guarantee Fix Round 1 (coordinator review): 1. Transcript store now best-effort via private transcriptSafe helper; catches and ignores all I/O errors. Added .catch(() => undefined) to drain() call in submit() to prevent unhandled rejection from stranding the queue. 2. Listener throws now caught per-listener in emit() so one bad listener does not crash the session or break event delivery to other listeners. 3. Added safety: check controller.signal.aborted at top of outer catch to report 'cancelled' (cancel during mint now reads as cancel, not error). Stream ends without terminal frame now emit turn-end error with message 'the harness ended the turn without a result' (every turn-start now paired with turn-end). 4. Added 6 tests covering: control-plane mint failure during remint, session_mismatch twice (ApiError not HarnessUntrustedError), 503 with Retry-After after frame (no retry), truncated stream with real TranscriptStore (pending delta flushed), throwing listener (turns complete in order, one turn-end per turn-start visible to good listener, idle() resolves), and appendPrompt throw (turn still runs, idle() resolves). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Adds the runtime wiring (buildRuntime/setAuth/setEndpoints), the three headless command handlers (login, doctor, run), the CLI arg parser and entrypoint, and the tsx-registering bin shim for @sh/tui (Task 11 of the sh-tui staged plan). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
cmdLogin returned 1 with a "login failed" line on a Ctrl+C during the device-flow poll (deviceLogin throws LoginCancelledError); now returns 130 quietly, matching the rest of the exit-code contract. cmdRun attached its abort listener only after session setup (resolveSessionOptions / create / resume); a cancel landing during setup signalled an already-aborted signal that the listener, added later, never fires for, so the turn ran anyway. Now checks opts.signal?.aborted right after setup (after printing the session line, so the session can still be resumed) and returns 130 without submitting a turn. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…uced motion - theme/tokens.ts: ThemeTokens interface and system/dark theme definitions - theme/context.tsx: ThemeProvider and useTheme hook - views/Spinner.tsx: Braille spinner with reduced-motion support - test/helpers/ink.ts: Test helper with tick() and withTheme() - test/theme.test.tsx: Tests for theme resolution, toChalk, and Spinner animation Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…keys Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ummaries Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… circular args Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…n-tool args Review round 1 on Task 17's BlockView found three issues in ToolBlock: - Diff hunk/add/remove/context lines rendered raw and could overflow the render width; truncate each (including its 2-char prefix) to Math.max(20, width - 4), same as the preview. - An errored edit with details on showed the attempted diff but never the error text, because the diff set `body` and skipped the preview fallback. An errored tool now always shows its error preview; for an expanded errored edit the preview renders first, then the diff. - Per spec Sec 5.5, an unknown tool (absent from TOOL_RENDERERS) expanded now shows its args as pretty-printed JSON, capped at 12 lines with the same "N more lines" note, ahead of the preview. Known tools are unchanged. Factored the capped-lines-plus-note rendering (preview and args JSON) into a small CappedLines helper to keep ToolBlock readable. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…trand it Repeated presses of down-arrow on an empty input walked historyIndex past -1 (-2, -3, ...) with no lower bound, so the next up-arrow press appeared stuck instead of showing the newest history entry. Clamp the down-arrow branch with Math.max(-1, historyIndex - 1). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ogin tests - bin/sh-tui.mjs names the package tsconfig for tsx. tsx otherwise reads the CWD's, so launching from the repo root lost `jsx: react-jsx` and crashed with "React is not defined". - The interactive UI now exits 2 with a pointer to `sh-tui run` when stdin is not a terminal, instead of Ink's raw-mode stack trace. - Two app tests waited on the last frame for a Login screen that the fake approves on its first poll, so it could come and go between samples. They now check every rendered frame. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
MOCA is the new name of serverless-harness, so the terminal client becomes `mocactl`: package @sh/mocactl in packages/mocactl, binary `mocactl`, config and state under ~/.config/mocactl and ~/.local/state/mocactl, live-smoke gate MOCACTL_LIVE_SMOKE. The spec file, ADR-0036, CLAUDE.md and every user-facing string follow. The SH_CONTROL_PLANE_URL / SH_HARNESS_URL variables keep the repo-wide SH_ prefix they share with the harness and the control plane. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
A client that knows only the control plane's URL can now find the
harness. GET /v1/discovery is public (a client reads it before login)
and answers {"harnessUrl": string | null}, from SH_PUBLIC_HARNESS_URL:
the harness base URL as a CLIENT reaches it.
- Unset answers null, not 404, so a client can tell "advertises no
harness" from "predates discovery" and name the right fix.
- A malformed value fails startup rather than breaking every user's
first turn.
- The route table's "api token on every /v1 route" rule gains one
named, GET-only exception, and the OpenAPI contract documents it.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
mocactl now needs only the server (control-plane) URL: - The harness client asks GET /v1/discovery on first use, caches a success and retries after a failure, so fixing the deployment needs no restart. - Onboarding asks for one "Server URL" and never saves a discovered harness URL, so a harness the operator moves is followed. - --harness-url / SH_HARNESS_URL remain as a local override and skip discovery. - Doctor gains check 5 "harness located", printing where the harness was found and how. Its failures name the right knob: SH_PUBLIC_HARNESS_URL on the control plane, an upgrade for a control plane that predates discovery, or the override. - The advertised value is used only as the URL parser serialises it, since doctor prints it. Spec v1.2, ADR-0036 and the README record the change. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ontext runAsNonRoot: true without an explicit runAsUser makes kubelet fall back to the image's default user. The shared image has no USER directive, so kubelet finds root and refuses to start the container (CreateContainerConfigError: container has runAsNonRoot and image will run as root). service.yaml already pins runAsUser: 65532 and fsGroup: 65532 for the same reason; control-plane.yaml was missing both. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ot /dev/stdin libuv backs a Node child's stdin pipe with a UNIX-domain socket on Linux, and kubectl reads --patch-file=/dev/stdin by reopening it BY PATH -- which the kernel refuses for a socket (ENXIO, "no such device or address"). Verified directly against the deployed image: `stat -L /proc/self/fd/0` on the child reports `socket:[...]`, and the real kubectl binary fails with exactly that error. Every credential write hit this. defaultRunKubectl now writes the patch body to a briefly-lived 0600 temp file and substitutes it for /dev/stdin in argv before spawning, preserving the original property that the patch content never appears in argv/cmdline. Adds a regression test (never hands the child the literal /dev/stdin path) and an end-to-end test against a fake kubectl that reopens --patch-file by name, mirroring the real binary's behavior. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…setup-k8s.sh
Neither script ever applied the base harness egress NetworkPolicy, despite
control-plane.yaml's additive policy and setup-kind.sh's own AB1 comment both
assuming it already exists on the cluster ("Applied AFTER any base egress
policy"). It's listed in kustomization.yaml's resources, but neither script
runs `kubectl apply -k` -- they apply individual files.
Net effect: once control-plane.yaml's additive policy (TCP:8080 to the
control plane only) was applied to a Kind/vanilla-k8s cluster, the harness
pod became egress-restricted with no DNS allowance at all, so EVERY DNS
lookup from that pod failed (EAI_AGAIN) -- not just the control-plane one.
Every /turn credential exchange then failed with "the harness is
unavailable". Verified directly: raw IP:8080 to the control-plane pod
succeeded while DNS to kube-system's CoreDNS timed out; applying the base
policy fixed both.
setup-ocp.sh is unaffected -- it renders its overlay via `kubectl kustomize`,
which already resolves harness-egress-policy.yaml.
Adds a regression test asserting both scripts actually apply the file,
alongside the existing kustomization-wiring test that wasn't sufficient on
its own.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
The router's generic "POST/PUT needs a body" guard only exempted
startDeviceAuth by operationId. mintSessionToken (POST
/v1/sessions/{id}/token) is equally bodyless -- its handler takes
everything from the path param and the caller's principal, never touches
ctx.body -- but wasn't exempted, so every call 400ed with body is
required before the handler ran. mocactl calls this right after creating
a session and again on every token refresh, so this broke every turn.
Existing coverage called HANDLERS.mintSessionToken directly, bypassing
the router, which is why it went unnoticed.
Adds a bodyRequired?: boolean field to RouteSpec (defaults true) instead
of hardcoding a second operationId string, matching this file's existing
convention of declaring route behavior as data rather than per-handler
logic. server.ts now checks that field.
Adds an HTTP-level regression test: create a session, then mint a token
with no body at all (matching what mocactl actually sends) -- 400
before this fix, 200 after.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
ink's own useInput doc: "if the user pastes text and it's more than one
character, the callback will be called only once, and the whole string
will be passed as input" -- with every key.* flag false, since the
combined chunk matches no single named key. Fast typing (not just an
explicit paste) triggers the same delivery whenever the OS/tty/
multiplexer buffers a character together with the next one, most
dangerously the following Enter.
Reproduced directly: writing "litellm\r" as one stdin chunk landed as
input="litellm\r", key.return=false -- Form appended the raw '\r' as a
literal (invisible) character and never submitted. A \r renders as
nothing, so the field LOOKS unchanged and pressing Enter appears to do
nothing; a confused Backspace removes the invisible \r first (still no
visible change), and only the second Backspace removes the character
the user actually meant to delete. This is almost certainly how a fast
"litellm<Enter>" ended up stored as the credential name "litell" in
today's session, and raises the same risk for a masked token field,
where a dropped/altered character is invisible by design.
Fix: when a multi-char input carries no key.* flag and contains an
embedded single-byte control character (return, tab, backspace/delete,
escape), replay it byte-by-byte through the same per-key handler instead
of treating the whole chunk as literal text. Deliberately narrow: only
the single-byte controls this form already reacts to are decoded;
multi-byte sequences (arrow keys) landing mid-burst are not attempted.
Adds a regression test: a single stdin.write of "litellm\r" (no tick
between the text and the Enter) now submits {name: "litellm"} instead of
silently doing nothing.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…data
delete() patched stringData: { [name]: null } to remove a credential's
encrypted value. stringData is a write-only, admission-time convenience
the apiserver base64-encodes INTO data for a non-null value and
otherwise ignores entirely -- nulling a stringData entry does not delete
the corresponding data key. The annotation-clearing half of the same
patch DID work (annotations are a plain map field, not a write-only
alias), so a deleted credential correctly disappeared from list()/get()
(both require the annotations describe() needs) while its ciphertext
stayed in the Secret object forever, unbounded, under the deleted name.
Found live: a credential re-added under a corrected name after a
previous delete left a stray, annotation-less `data` key behind.
The existing test suite never caught this because its own fake cluster
modeled stringData nulling as deleting data too -- the same wrong
assumption as the bug, baked into the test double. Fixed the fake to
model the real asymmetry (stringData writes merge into data; only a
data patch can remove a key) and extended the existing delete test to
assert the underlying data key is actually gone, not just annotation-less.
Fix: delete() now patches `data: { [name]: null }` instead of
`stringData`.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
The endpoint becomes the turn's ANTHROPIC_BASE_URL, and the model client appends the API path itself, so the `https://litellm.internal/v1` example invited a doubled version segment. The hint now says to enter the value as for ANTHROPIC_BASE_URL, with no /v1. A test keeps a /v1 example from returning. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
packages/mocactl/QUICKSTART.md takes a new user from a fresh checkout to a streamed reply: building the image, registering the GitHub OAuth app, what goes in each credential field, and doctor's fixes. The cluster wiring is deploy/knative/mocactl-quickstart.sh (also make mocactl-quickstart). It is safe to re-run: - Secrets: an existing signing key is reused, never replaced. Secret values go through files, never argv. - Control plane: deployed with SH_PUBLIC_HARNESS_URL set to the forwarded harness, so discovery gives mocactl its one URL. - Harness: gets the key's public half (without it the harness refuses every mocactl turn, in either auth mode), with min-scale 1 and a build-ts stamp so a re-loaded same-tag image is actually served. - Port-forwards: go to the latest revision's pod and are checked end to end through discovery. A 404 is named as an image that predates /v1/discovery. - SH_REQUIRE_AUTH is left alone, so the other smokes keep working. --teardown undoes all of it. tests/mocactl-quickstart.test.sh asserts the call log under mocked kubectl/openssl/curl. The key-ID derivation was also checked with real OpenSSL 3 against the control plane's makeSigner/parseKeyset. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
The harness egress policy that setup-kind.sh now applies (0592b06) lets the harness out only on TCP 443, so a gateway on another port (e.g. LiteLLM's default :4000) fails every model call. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
295ed93 to
a241ecb
Compare
- js/indirect-command-line-injection (mocactl os.ts): $VISUAL/$EDITOR is now split into words (editorArgv: quotes and backslashes as a shell would, no expansion) and spawned directly, with the file as one more argument. No shell ever interprets the editor string or the path. A test proves a `$(touch ...)` in $EDITOR runs nothing. On Windows the editor must name an executable; the README says so. - js/polynomial-redos (control-plane main.ts, and the same /\/+$/ at four mocactl sites on user-, env- and server-supplied URLs): trailing slashes are trimmed by a linear loop, tested on a 100k-slash run. - js/file-system-race (mocactl config.test.ts): the auth.json mode check and the read go through one file descriptor. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
esnible
left a comment
There was a problem hiding this comment.
Summary
Approving. Unusually disciplined work: 74 signed commits, five live-walkthrough bugs each fixed with a verified-red test before the fix, and comments that explain why rather than restating the code. One non-blocking suggestion inline.
Areas reviewed: TypeScript/Node, Helm/K8s manifests, Shell, YAML/OpenAPI, Docs, Tests, Security
Agent/IDE config (.claude/.vscode): none
Commits: 74, all signed-off (74/74)
CI status: passing — all 13 checks green, including the CodeQL failure noted in the description, since fixed in d01cb39
What I verified rather than took on faith
- Supply-chain gate: clean — no
.claude/or.vscode/paths added, modified, or renamed; no workflow files touched; no hardcoded secrets in added lines. - The
runAsUser: 65532claim: matchesservice.yaml:21-22exactly, as the description states. - OpenAPI/route parity:
/v1/discoveryis declared withsecurity: [], matchingauth: 'none'inroutes.ts, and theharnessUrl: [string, 'null']schema matches the?? nullhandler. - The
bodyRequiredrefactor: replaces a hardcodedoperationIdcheck with a data-driven flag — the right fix, correctly applied to both bodyless routes. - Credential hygiene in the new package:
0600files,0700dirs, write-then-rename for atomicity, no secret logged or persisted to config. - Test hygiene: no stray
.only/xit; the single.skipis the documented env-gated live smoke. - The
.gitignorenegation: scoped to one exact path rather than broadening the pattern. - Discovery and SSRF: the advertised URL is validated as absolute http(s) at startup, used only as a harness base URL, and never persisted — no new trust surface beyond the user's own choice of control-plane URL.
Worth calling out
The stringData → data fix in k8s-secret-store.ts is a genuine latent data-retention bug — nulling a stringData entry never removed the persisted data key, so deleted credentials stayed in the Secret indefinitely, invisible to list()/get() but never actually erased. Good catch, and the comment explains the apiserver semantics that make it non-obvious.
The root-cause comments on the ENXIO-on-a-UNIX-socket /dev/stdin failure and the quadratic-regex avoidance in urlEnv are the kind that save the next reader an afternoon.
Assisted-By: Claude Code
| * keep out of /proc/<pid>/cmdline. | ||
| */ | ||
| const path = join(tmpdir(), `sh-cp-patch-${randomBytes(16).toString('hex')}.json`); | ||
| await writeFile(path, stdin, { mode: 0o600 }); |
There was a problem hiding this comment.
suggestion — mode: 0o600 here is masked by the process umask, so it is a request rather than a guarantee.
This package's sibling code in mocactl gets this exactly right:
writeFileSync(tmp, data, { mode: 0o600 });
chmodSync(tmp, 0o600);...with the comment "chmod because the create mode is masked by the umask." That reasoning applies verbatim here, and this path is the more sensitive of the two: the patch body carries plaintext credentials through stringData (k8s-secret-store.ts:168), so under a permissive umask a user's inference API key is briefly world-readable in tmpdir().
Real-world exposure is small — the 128-bit random filename is unguessable, the window is milliseconds, and the container is single-tenant — which is why this is a suggestion and not a blocker. But the fix is one line and makes the hardening hold regardless of ambient umask:
await writeFile(path, stdin, { mode: 0o600 });
await chmod(path, 0o600);There was a problem hiding this comment.
Thanks, good catch on hardening this path. It's fixed in 7f30cfb, though with a different change than the chmod.
The umask can't widen this file. A umask only clears bits. On a file the call creates, mode: 0o600 is an upper bound: under umask 000 it's still 0600. So chmod after a fresh create is a no-op. The mocactl comment you quoted ("chmod because the create mode is masked by the umask") gave the wrong reason, which I've corrected. Its chmods are needed, but because mkdir -p keeps an existing directory's mode, and its predictable <path>.<pid>.tmp can be a leftover that writeFileSync reopens without applying mode.
The real gap was next to it. writeFile opened without O_EXCL. If anything already existed at the path (a file, or a symlink planted in a shared /tmp), mode would be ignored and the plaintext written into or through it. The random name makes that impractical, but it's now flag: 'wx': the file is created fresh or the write fails.
Two new tests in test/kubectl.test.ts:
- the patch file kubectl reads is
0600under umask000, which is your scenario pinned; - a file planted at the temp path, with the name forced via a mocked
randomBytes, makes the write fail withEEXISTand leaves the planted file untouched. It fails withoutwx.
…tl#347 review) The temp file that carries a credential's plaintext to `kubectl patch` is now opened with `wx` (O_CREAT|O_EXCL). It is created fresh or the write fails, so it never writes into, or through a symlink at, a path someone else put there, and its `mode: 0o600` always applies. A chmod, as the review suggested, would not add anything: on a newly created file a umask can only clear bits, so 0o600 is already an upper bound. A new test pins this under umask 000. A second test pins the exclusive create by planting a file at the path; it fails without `wx`. The mocactl comment the review cited ("chmod because the create mode is masked by the umask") gave the wrong reason. Its chmods are needed because `mkdir -p` keeps an existing directory's mode, and a leftover `<path>.<pid>.tmp` is opened without applying `mode`. The comment now says so. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
CodeQL (js/insecure-temporary-file) flagged the exclusive-create test: it wrote a predictably named file straight into the shared temp dir, which is the pattern the fix defends against. The planted file now goes in a private mkdtemp directory that os.tmpdir() is pointed at through TMPDIR (read on each call), with an assertion that the redirect took effect. The test still fails without `wx`. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Sixteen ADRs still said Proposed although their decisions are in code on main. Each status line now names the merged PRs that implemented it and the date the core landed (format of ADR-0042), and notes what is still owed where only part is built: - 0028 (rossoctl#170, rossoctl#201, rossoctl#340; its KEDA transport removed by ADR-0041) - 0029 (rossoctl#171), 0030 (rossoctl#214), 0031 (rossoctl#214, rossoctl#225) - 0032 (rossoctl#249, rossoctl#350, as amended by MI1) - 0035 (rossoctl#251; ADR-0048 adds lease mode beside it) - 0036 (rossoctl#347), 0038 (rossoctl#458), 0039 (rossoctl#467), 0040 (rossoctl#481) - 0043 (rossoctl#560, rossoctl#588, rossoctl#600, rossoctl#615), 0044 (rossoctl#563), 0045 (rossoctl#620) - 0046 (phase 1: rossoctl#630, rossoctl#641, rossoctl#646; phase 2 owed) - 0047 (M1 and M3: rossoctl#704, rossoctl#713, rossoctl#717, rossoctl#765; M2 owed) - 0048 (rossoctl#706, rossoctl#763, rossoctl#802, rossoctl#808, rossoctl#814; off by default until the security review's lease sections are signed off) The README index follows, and its 0033 row, which still said Proposed after rossoctl#249 accepted the ADR, is corrected. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
packages/mocactl(@sh/mocactl, binarymocactl; MOCA is the new name of serverless-harness): an OpenCode-style terminal client. It logs in with the GitHub device flow, manages owned sessions and write-only inference credentials over the control plane's/v1API, and streams turns from the harness over SSE. It talks only HTTP and depends on no other@sh/*package, so it works the same against a Knative or a P6/VM harness.GET /v1/discovery→{"harnessUrl": string | null}, set by the operator withSH_PUBLIC_HARNESS_URL.--harness-url/SH_HARNESS_URLremain as a local override.ctrl+xleader keys, slash commands and a fuzzy palette, all driven by one command tableeditdiff; Markdown with syntax highlightingNO_COLORand reduced motionmocactl loginmocactl doctor [--json]: seven checks in dependency order. They include where the harness was found and whether it trusts this control plane's tokens, without running a model turn.mocactl run "prompt" [--session ID | --new] [--option k=v] [--json]docs/specs/2026-09-25-mocactl-control-plane-client-design.md(v1.2) and ADR-0036.packages/mocactl/QUICKSTART.mdgoes from a fresh checkout to a streamed reply on kind.deploy/knative/mocactl-quickstart.sh(make mocactl-quickstart/-teardown) does the cluster wiring and is safe to re-run.build-tsstamp.SH_REQUIRE_AUTHalone, so the other smokes keep working.The one backend change:
GET /v1/discovery(packages/control-plane)/v1route" rule gains this as its single named exception.SH_PUBLIC_HARNESS_URLanswersnull, not 404. The client can then tell "advertises no harness" from "predates discovery" and name the right fix for each.docs/api/openapi.yaml;deploy/knative/control-plane.yamlcarries the variable with guidance (it takes the client-facing address, not the in-cluster one).Notable behaviour:
Also in this PR:
.gitignoreexception (credentials.*matchedCredentials.tsxon case-insensitive filesystems)CLAUDE.mdmocactl runUpdate 2026-09-27: live walkthrough on Kind found and fixed 5 real bugs
The original test plan below flagged the live walk and live-smoke run as not yet done. Doing that walk end-to-end (real GitHub device login, real credential, real turn) surfaced five distinct, previously-undetected bugs blocking it — each fixed with a failing test verified red before the fix, then green after:
deploy/knative/control-plane.yaml: podsecurityContextsetrunAsNonRoot: truewith norunAsUser. The shared image has noUSERdirective (defaults to root), so kubelet refused to start the container (CreateContainerConfigError). AddedrunAsUser: 65532+fsGroup: 65532, matchingservice.yaml's existing convention.packages/control-plane/src/kubectl.ts: every credential write usedkubectl patch --patch-file=/dev/stdinfed through a Node child's stdin pipe. On Linux, libuv backs that pipe with a UNIX-domain socket, and kubectl's path-based reopen of/dev/stdingetsENXIOfor a socket (confirmed withstat -L /proc/self/fd/0on the deployed image). Fixed by writing the patch body to a briefly-lived 0600 temp file instead.deploy/knative/setup-kind.sh/setup-k8s.sh: neither script ever applied the baseharness-egress-policy.yaml, despitecontrol-plane.yaml's additive NetworkPolicy assuming it already exists. Net effect: once the additive policy landed, the harness pod had no DNS egress at all, soSH_CONTROL_PLANE_URL's hostname couldn't resolve and every/turncredential exchange failed. Both scripts now apply it (verified live: DNS resolution and the exchange call both fixed).packages/control-plane/src/routes.ts/server.ts:mintSessionToken(POST /v1/sessions/{id}/token) is legitimately bodyless — its handler never readsctx.body— but the router's generic "POST/PUT needs a body" guard only exemptedstartDeviceAuthby name, so every call 400'd withbody is requiredbefore the handler ran. mocactl calls this right after creating a session and on every token refresh, so this broke every turn. Added a data-drivenbodyRequired?: booleanonRouteSpecinstead of another hardcoded operationId.packages/mocactl/src/views/Form.tsx: per ink's ownuseInputdoc, a multi-character stdin chunk (fast typing, paste, tty/multiplexer buffering) is delivered as one raw string with everykey.*flag false. Form.tsx appended that whole string as literal text, so a\rglued onto the end of a field (fast typing + Enter) got embedded invisibly, the field silently failed to advance, and a confused Backspace removed the invisible\rbefore the intended character — reproduced directly:"litellm\r"written as one chunk ended up stored as the credential namelitell. Fixed by decomposing a flagless multi-char input into its constituent control bytes and replaying them through the same per-key handler.All five are unit/integration-tested (RED verified before each fix) and pushed to this branch's head. CI is green except a pre-existing, unrelated
CodeQLfailure (same failure on the prior head commit, before any of these changes).Test plan
pnpm --filter @sh/mocactl test: 463 passed, 2 skipped (the env-gated live smoke) — was 461: +1 for the Form fix above, +1 pinning the gateway-endpoint hint to no/v1examplepackages/control-plane: 318 passed — was 315, +3 across the kubectl.ts and mintSessionToken fixesmake lintpassesdocs/api/openapi.yaml(including/v1/discovery) and to the harnessTurnStreamFrameunion. A layering test keepssrc/apiandsrc/corefree of UI imports.deploy/knative/tests/mocactl-quickstart.test.sh(inmake test-deploy) asserts the quickstart's call log under mocked kubectl/openssl/curl. Mutants were caught: regenerating an existing key, skipping the key publish, flippingSH_REQUIRE_AUTH. The key-ID derivation was checked with real OpenSSL 3 against the control plane'smakeSigner/parseKeyset.mocactl-quickstart.shitself not yet run end to end on a live kind clustermocactl login(real GitHub device flow) and adding a credential now both work end-to-end.MOCACTL_LIVE_SMOKE=1 pnpm --filter @sh/mocactl exec vitest run test/live.smoke.test.tsagainst the live clusterSH_PUBLIC_HARNESS_URLsetctrl+x dedit diff, Esc mid-turn, a queued promptNO_COLOR=1and a narrow terminalSH_SESSION_TOKEN_PUBLIC_KEYS(the P6/VMsupervisor.env.exampledoes not ship the MU1 auth settings yet)🤖 Generated with Claude Code