Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

feat(domains): merge managed-app persistent subdomains (PR #123)

Abdurrahman Fakhrul716de90010dc
diff --cc docs/PROGRESS.md
index 92c500f4,48d57785..bd0b82cd
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@@ -1,90 -1,37 +1,124 @@@
+## 2026-10-18c: A service-owned listener no longer dead-ends an update; Alfa lint restored
+
+Two follow-ups after the agent-surface batch.
+
+**Service-active updates.** An interrupted update could leave a gateway restore inventory naming an origin
+that this checkout's own `mso.service` now serves; the quiesce step then failed closed ("a loopback MSO
+runtime is active but is not gateway-owned") and every retry failed identically. The service-active quiesce
+path now reports `runtime: service-owned` when `gateway_service_owns_local_listener` *proves* the healthy
+listener belongs to this checkout's own active unit — that listener is not a fallback runtime, the service
+lifecycle keeps it, and `scripts/self-update.sh` replaces it by signalling its same-UID MainPID, so there is
+nothing to quiesce. The offline preflight (`runtime-assert-update-safe`) keeps the strict form, and any
+listener not proven to be this checkout's unit still fails closed. Regressions:
+`scripts/mso-gateway-service-owned.test.ts` plus a service-owned case in `scripts/mso-service-update.test.ts`.
+
+**Lint.** The batch above shipped two `bun run lint` failures that neither a `--no-verify` push nor the
+build-only verify stage catches: a `react-hooks/set-state-in-effect` error in the saved-chat drawer and a
+`max-lines` breach in `chat-panel.tsx` (239 counted lines). The drawer now resets with a render-time state
+adjustment (its History button opens the sheet without routing through `onOpenChange`), and the token-usage
+state moved into a new `useTurnUsage` hook, returning `chat-panel.tsx` to 217 counted lines.
+`docs/CHANGELOG.md` was regenerated.
+
+## 2026-10-18b: `fs_stat` returns, paid for by a tighter ChatGPT description cap
+
+The read-scope `fs_stat` tool (true size/mtime without `exec_run` or reading binary content) was reverted
+earlier today because its descriptor pushed the complete ChatGPT profile to 94,584 bytes, past the in-repo
+**92 KiB** gate asserted in `lib/mcp/chatgpt-profile.test.ts`. The established way to admit a tool is to
+compact the profile rather than raise the gate (see 2026-10-09), so `lib/mcp/tool-contract.ts` now caps the
+compact one-line descriptions at **24 characters** (was 30) and keeps an explicit `COMPACT_DESCRIPTIONS`
+override for `workflow_start` ("First call: multi-step") so the first-call rule survives the tighter cut;
+`skills_search`'s compact description was shortened so `mso-agent-bootstrap` stays intact. The complete
+profile is now **93,877 bytes with the new tool** (331 bytes of headroom under 92 KiB), the toolset moves to
+`2026.10.18.1` (119 model tools) with a regenerated catalog, and `fs_stat`'s guarded `statReadableMeta` host
+facade plus its parity `MCP_ONLY` entry are restored. The documented scanner budget is 96 KiB
+(`docs/CHATGPT-PLUGIN.md`); the in-repo gate stays deliberately stricter at 92 KiB, and only the character cap
+changed — names, schemas, scopes and safety semantics are unchanged.
+
+## 2026-10-18: Four agent-surface improvements, a CLI verb, and one benchmark that said "no change"
+
+A parallel agent run (one coordinator, disposable worktrees under `~/.cache/mso-worktrees/mso-*`, each worker
+owning a disjoint file set) landed four independent improvements to the agent surface plus one CLI verb, plus
+one benchmark run that correctly produced no code. Everything below was reviewed as a diff, merged to `main`,
+and gated.
+
+**`/api/skills` is cached now.** `lib/skills/catalog-ttl.ts` is a value-level memo (`createCatalogTtl`, 15 s
+default, injected clock, single-flight) wired into the list branch of `app/api/skills/route.ts`. The Cockpit and
+`skills.list` tool calls stop re-walking every skill root per turn. The `?name=` branch stays uncached (a stale
+name lookup would be a trust bug), `?refresh=1` forces a re-walk, and the `scan`/`continuation` report passes
+through byte-identical so `scan.truncated` still means incomplete-not-absent. This closes the one gap the
+assistant contract named.
+
+**A read-scope `fs_stat` tool was prototyped and then reverted.** External MCP clients had no way to learn a
+file's true size or mtime without `exec_run` or reading binary content (`fs_list` reports size `0` by design),
+so a guarded `statReadableMeta` host facade and an `fs_stat` declaration were added — but the added descriptor
+pushed the complete ChatGPT profile to 94,584 bytes, past the in-repo **92 KiB** budget gate asserted in
+`lib/mcp/chatgpt-profile.test.ts`. That gate is deliberately stricter than the documented 96 KiB scanner budget
+(`docs/CHATGPT-PLUGIN.md`), and MSO's established way to admit a tool is to compact the profile, not to raise
+the gate. No compaction left the asserted compact descriptions intact at the required saving, so the change was
+reverted rather than weakening the budget; the toolset returns to `2026.10.10.1` (118 model tools). Re-adding
+`fs_stat` needs a profile-budget plan first (reclaim ~400 bytes, or an owner decision on the 92→94 KiB gate).
+
+**Alfa's saved-chat drawer is searchable and safe.** It rendered `updatedAt` but never showed it, had no
+search, could not rename, and deleted a chat with no confirmation. `lib/ai/threads.ts` gained `renameThread`
+(atomic temp-file save), `app/api/threads/route.ts` gained an owner-gated `PATCH { id, title }` with the same
+id validation the delete path uses, and the drawer filters, sorts, shows relative time, and gates delete
+behind a confirm. Title persistence survives later turns instead of being re-derived from the first message.
+
+**Proactive agent turns are bindable to a durable session.** This is the seam OpenDots-style "always-on"
+agents needed. A graph `agent` node may now set `sessionRef`; `lib/agent/session-turn.ts`
+(`runDurableSessionTurn`) resolves the same-owner session, runs the bounded turn through the existing local
+session seam, serializes with an at-most-one execution lease so two turns cannot interleave history writes,
+and persists the turn (history append + `agent_turn` audit event). Combined with the existing in-process
+schedule trigger this needs no systemd timer, cron entry, or second scheduler, and `lib/workflow/graph-authority.ts`
+is untouched — unattended authority is still `web:*`-only with a live device recheck.
+
+**Per-turn token usage is visible.** Every provider stream already emitted `usage` on its `done` event and the
+client threw it away. `AgentTurn`/`AgentLoopResult` now carry an optional `ProviderUsage` (additive only, so the
+image editor that also calls `runToolAgent` is unaffected), accumulated across tool rounds with `addProviderUsage`,
+and rendered per turn plus as a running thread total.
+
+**The new rename route needs a reachable CLI verb.** `bin/mso.test.ts` requires every `app/api` `(method, path)`
+to map to a named verb, so `PATCH /api/threads` added a `jpatch` transport helper and a `threads rename <json>`
+verb, and `docs/CLI.md` was regenerated from the help text (the same change keeps `docs/CLI.md` fresh).
+
+**The cognitive-routing task produced no code, on purpose.** The worker ran `bun run bench:cognitive`; all 17
+gates passed (100% routing recall, 97.3% schema reduction, deterministic selection). Per the P7 #5 / P8 #6
+closed-loop rule, a passing corpus is not evidence of a defect, so it reported the observed gate values instead
+of inventing a speculative change.
+ ## 2026-10-17: Handoff the managed-domain CLI candidate for a new session
+
+ The owner explicitly requested a committed, pushed draft PR checkpoint and progress record before continuing in a new session. Implementation is preserved on `agent/mso-103047d38625`; the code commit is `da3ce4f69dfcdcb44a26f4522ced653194ec6172`, based on `89d61bb0d73b47047c67e51df9a6ee30351c8c3a`. The task worktree is `/home/rahman/.cache/mso-worktrees/mso-103047d38625`; canonical remains `/home/rahman/mso`. Keep the draft separate from release integration until the remaining checks pass.
+
+ The implementation and operating guide are in `docs/MANAGED-DOMAINS.md`, `scripts/mso-domain.ts`, `scripts/cli/managed-apps.sh`, `lib/managed-apps/domain-*`, `lib/infra/managed-domain*` and the named-gateway helpers in `scripts/lib/gateway-app-route*.sh` / `gateway-named-config.mjs`. The earlier entry below records the design reasons. Setup persists a versioned private configuration, and enable/install/update/start/restart use its shared ingress-before-DNS lifecycle. The replacement connector must have its own registration evidence before the prior connector is retired; interrupted swaps use bounded identity-checked recovery.
+
+ Verification of the code commit:
+
+ - Typecheck and zero-warning ESLint passed. `bun run check`, the strict high/critical dependency audit and generated-changelog check passed.
+ - The targeted gateway run passed all 38 cases before the full run. Core configuration/store/probe/env, provider DNS/route, CLI and managed-app lifecycle regression groups also passed their targeted runs.
+ - Full `bun run verify` completed its coverage run with **749 passing / 3 failing files; 4,604 passing / 5 failing tests (4,609 total)**. The overall verify gate failed and coverage completion is not a release pass.
+ - Three failures in `lib/forge/forge.test.ts` require a real accessible Docker daemon and the existing `mso-forge-sandbox:node22-v1` fixture image. No Docker executable, daemon socket or remote Docker host was available. After Docker is available, use `bash scripts/provision-forge-sandbox.sh`; do not replace these tests with mocks or skips.
+ - Two candidate test issues remain: `scripts/mso-gateway-app-route-recovery.test.ts` expects the immediate-start failure text, while a loaded full run reaches the connection-registration failure instead; preserve the actual recovery/identity assertions when making that fixture deterministic. `scripts/mso-heartbeat.test.ts` copies a fixture checkout that lacks the new `scripts/lib/gateway-named-config.mjs`; update its fixture dependency inventory.
+ - The isolated production build, zero-build-warning check, eager shell bundle budget and **all mandatory browser journeys passed** (build/E2E job exit 0). This includes release, native Integrations, native Google Integrations, server status, Assistant UX, deferred shell performance, macOS chrome and iOS lock checks on the code commit.
+
+ The MSO exec environment inherits `NODE_ENV=production`; unit/coverage verification must explicitly use `NODE_ENV=test` so production process-ownership guards correctly distinguish test fixtures. The successful baseline ZIP tests used real Info-ZIP 3.0 extracted to `/tmp/mso-domain-toolchain.rZ3neG/root/usr/bin` on this host; ensure a real `zip` executable is available when reproducing. Keep production build verification in `scripts/verify-build.sh`, which archives committed HEAD and never builds over the live checkout.
+
+ Operational state at handoff: the existing gateway-owned fallback runtime served the cockpit on loopback port 4005 and the public MSO hostname. This task did not deploy code, enable 9Router, write public DNS or apply tunnel routes. The selected Integrations user `rahman` and direct Cloudflare connection `mso-domains` now exist; their private setup form was opened, but the latest redacted connection query still reported the API token missing. Supply credentials through that private form, with Zone Read, DNS Edit and Cloudflare Tunnel Edit for the intended zone/account. The desired nested 9Router hostname also needs a certificate covering it; a CNAME alone does not establish working HTTPS.
+
+ Next session should first read this entry and the draft PR, resume the existing branch/worktree, fix the two fixture issues, provide Docker/Forge prerequisites and rerun the required gates. Then verify the saved Cloudflare connection, run domain setup preview and apply as documented, rebuild through the supported lifecycle, and run `mso mapp enable 9router` or `mso domain ensure 9router --apply`. This installation has no active `mso.service`; its supported runtime rebuild is `mso update --rebuild`. The previous entry below explains why the current ship finalizer cannot complete on this topology.
+
+ Evidence retained on the host: workflow `dc617f85-a3c5-4d80-925b-37f1eeb36f95`; full verify job `8eb2c590-0c0d-4775-ba25-f39d01f19b3d`, log `/tmp/mso-domain-verify-final.QG0zye`; isolated build/E2E job `254d79b0-1475-42ab-9baf-bc85092f9450`, log `/tmp/mso-domain-build-final.WiH3Vo`; check/strict-audit job `5706b638-f060-41a4-9b32-c7d6b5259e6c`. Logs and job access are host/session evidence; the committed summary is the durable handoff record.
+
+ ## 2026-10-17: Persist managed-app domains and provision them through the existing MSO gateway
+
+ The earlier app-host RFC described the hostname and login boundary, but enabling an application did not own a complete DNS lifecycle or leave durable evidence when setup stopped halfway through. `mso domain setup` now discovers the existing Cloudflare zone, account and named tunnel through a selected MSO Integration. Its public routing configuration, ownership ID, per-app progress, resource receipts and last error live in a private versioned store outside the checkout. Writes are atomic, retain the previous valid snapshot and serialize operations across processes; malformed or unsafe state fails visibly instead of becoming an empty configuration. The environment editor preserves unrelated values, validates the file before saving setup, and supports explicit repair after an interrupted write.
+
+ `mso mapp enable <id>` installs an absent managed app, waits for its existing job and starts it through the shared API. Successful install/update jobs and start/restart actions then use the same domain provisioner. Local runtime success remains visible if domain setup needs attention, while CLI exit 2 and persistent diagnostics identify that incomplete outcome. Status, doctor and preview commands do not create infrastructure; `ensure --apply` resumes the saved plan. Stopping or uninstalling an app does not silently delete its hostname.
+
+ Provisioning first checks the deployed MSO app-host authorization gate, the selected provider identity and exact-name DNS conflicts. It establishes the authenticated MSO ingress before publishing a CNAME. Remote tunnel updates preserve unrelated configuration; locally configured tunnels use only the existing MSO-owned named-gateway lifecycle. Conflicting foreign records/routes and unsafe Host overrides are refused. A matching record can be reused without taking ownership, and a lost DNS write response is resolved by rereading before retrying. App health and public HTTPS/authentication are checked separately before recording `ready`. The cockpit and app retain their existing separate, host-only authorization cookies.
+
+ Nested application names require a certificate covering those exact hosts. DNS creation is not presented as TLS success, and no paid certificate is purchased automatically. Current setup, repair and migration boundaries are documented in `docs/MANAGED-DOMAINS.md`; the old RFC is retained as historical context rather than an active setup recipe.
+
+ Verification on the inspected fallback-runtime host found no Docker executable, daemon socket or configured remote Docker host. The existing mandatory Tool Forge sandbox tests therefore remain an environment prerequisite for release; no live DNS, application installation or deployment is claimed from candidate-only checks.
## 2026-10-17: Deploying on a host with no `mso.service`, and why `bun run ship` cannot finalize there