Card 20261122140510-06e82712. Plan memory 20261122140443-09c5c225. Phase 1 (HTTP/JSON) is built: hive-compose.api (pure request/response layer), hive-compose.adapter.http (JDK com.sun.net.httpserver, no new runtime dependency), served by the addon when :compose/api {:enabled? true}. Phase 2 (hive_call) is designed below, not built.
| path | what |
|---|---|
resources/hive_compose/openapi.yaml | the spec (OpenAPI 3.1.0, 30 paths, 98 schemas), served at GET /v1/openapi.yaml. Generated by doc/api/gen/assemble.py. Do not hand-edit it; edit the script and rerun it. |
doc/api/gen/gen.clj | dev tooling. A Clojure generator that loads a hive-compose checkout read-only and writes *.components.generated.json (malli.json-schema of hive-compose.schema), *.tool.generated.json (the live addon/tool :inputSchema, commands, command-help) and *.datajson-probe.json |
doc/api/gen/assemble.py | dev tooling. Merges the generated JSON with the hand-written response shapes into the spec |
test/hive_compose/openapi_contract_test.clj | contract: one path per tool command and the reverse (planned paths and the two GETs excepted), x-hive-call-op, every mapped category in ErrorCategory, the Req_* params are tool params, and sample params validate (networknt json-schema-validator, test alias only) |
Regenerate (needs python3 + PyYAML):
cd doc/api/gen
clojure -Sdeps '{:paths ["."] :deps {io.github.hive-agi/hive-compose {:local/root "../../.."}}}' -M -m gen staging.
python3 assemble.py # writes ../../../resources/hive_compose/openapi.yaml
(The guard refuses a deps.edn with :local/root, so the dependency is passed with -Sdeps. hc2.* inputs come from the hc-2 worktree and are kept until hc-2 merges.) The draft's client-ts/ and client-elm/ smoke tests stayed in the scratch dir; they are not part of this PR.
;; config.edn :addons {"hive.compose" {...}}
:compose/api {:enabled? true :port 0 :host "127.0.0.1"} ; additive; off by default
:port 0 binds an ephemeral port. compose status answers api {host port url}, and so does the initialize! metadata. A bind failure, or a non-loopback :host (refused), leaves the addon running and puts api {error detail} in its state.initialize! after the reaper and stops in shutdown!, 4 daemon threads, request bodies are capped at 1 MiB (413).curl -s -XPOST -H 'Content-Type: application/json' 127.0.0.1:$PORT/v1/status -d '{}' (a POST without that header is 415), curl 127.0.0.1:$PORT/v1/openapi.yaml, curl 127.0.0.1:$PORT/v1/health.hive-compose.addon/dispatch (was private) is the ONE dispatch: the MCP tool handler and the API both call (dispatch addon command params). The MCP behaviour did not change: same params, same text-result, bare categories.hive-compose.api/route maps (method, path, body) to {status headers body}. POST /v1/{command}, with the body a JSON object (blank = {}, a command key is ignored; the path names it). A planned path answers 501 compose/not-implemented, and an unknown command 404 compose/unknown-command. Both are checked before dispatch, so they do not depend on the lifecycle. A thrown dispatch answers 500 compose/dispatch-threw.{ok:true,value} | {ok:false,error,...}. Every :error keyword at any depth is written qualified (api/qualify-errors), and every other key or value goes through the same data.json encoder as MCP (namespaced keys bare).api/browser-guard, before anything else): binding loopback does not stop a web page, which can POST text/plain with no preflight and use DNS rebinding to read answers. So the guard refuses with 403 compose/forbidden-origin when Host is not 127.0.0.1, localhost or [::1], or when an Origin header is present and not loopback. A POST without Content-Type: application/json gets 415 compose/unsupported-media-type; that header forces a CORS preflight, and the server never grants one.api/check-params): a declared tool param of the wrong JSON type (tail "many", env "x") gets 400 compose/invalid-param before dispatch. Booleans also accept "true"/"false", as on MCP.compose/dispatch-threw or compose/internal) with only the class and message, never ex-data, which could carry env values.:compose/api values never fail the addon. That covers a non-loopback host, a port outside 0..65535, threads below 1, and a bind error. status then answers api {error detail}. A changed :compose/api is listed under reload's :not-reloaded, because it is rebound at the next initialize!.agent/agent_id are taken as sent, so any local caller can claim or release for any agent. That is the same as MCP today, where the host stamps agent_id. A token file is the next step if a non-operator process ever shares the host.status-by-category maps every category the source answers: 400 invalid, unknown-reference, clash and collision; 404 a named run, stack, test or proxy not there; 409 conflict or exists; 502 a backend (docker, toxiproxy, the trace store) failed or is unreachable; 503 not ready or not configured; 500 a fault of the addon. NB: unknown-command moved from the draft's 400 to 404 (card decision).~/PP/hive/hive-compose is detached at d1d884b, 13 commits behind origin/staging (db09adc). Staging adds the allow_orphans and allow_shared params and two refusal errors (compose/orphans-hold-resources, compose/held-by-another-section) to up, switch and restart, plus :cpu activity. The draft is derived from staging.
Sources were read through carto (carto ns, read-form, read-file mode=raw, structural-grep (r/err ?cat ?&rest)). Those sources are addon.clj, schema.clj, pipeline/{ops,swarm,restart,orphans,ownership}.clj, promote/{plan,swarm,ownership,orphan,config,target,profile,env}.clj and port.clj. Two git diff calls compared d1d884b with staging.
Every schema carries x-source: generated|hand.
Generated:
hive-compose.schema @ staging, via malli.json-schema/transform: ProfileId, IdleAction, SecretRef, EnvValue, Env, Program, Running, Activity, Profile, Claim, Usage, Active, ActiveMap, Project, Settings, Release. Each carries x-malli.hive-compose.schema @ staging (hc-2 has merged): CapabilityId, Version, VersionRange, RunId, ConsumerId, Resources, Provide, Need, Provides, Needs, Stack, Instance, Resolution, Wiring, ReportFormat, Suite.ComposeRequest and every Req_<command>, from the tool's live :inputSchema. Which params a command reads is hive-compose.addon/command-params (the [up|switch|..] prefixes of the param descriptions, plus target/profile for the section commands and agent_id for claim/release), emitted by gen.clj. The API enforces the same table: a key outside it is 400 compose/invalid-param naming the param and the known ones, so a typo such as runn on stack-down is refused instead of dropped. The command check runs first, so /v1/bogus is 404 whatever its body. openapi_contract_test checks Req_ properties == command-params. env is typed as $ref Env because addon/checked-options validates the call against schema/Env. The tool itself declares only {type: object}.summary/description, from addon/command-help.Hand-written from the pipeline code:
released), DownResult/StepReport, RestartResult, TouchResult, PsResult, LogsResult, ClaimResult, ReleaseResult, WhoResult, NreplResult/Route, ProjectsResult, ReloadResult, ReaperPass/ObserveReport, ProgramReport/ProgramRow, TargetsResult, ProgramsResult, HelpResult, AdoptResult. These are functions building maps with cond->, not malli schemas, so nothing could be generated.Ok, ErrorEnvelope) and the HTTP status mapping (api/status-by-category).ErrorCategory is generated from hive-compose.api/source-categories: every category under src/ written as the first arg of r/err, r/try-effect* or r/try-effect-throwable*, the category arg of read-edn or parsed, or a keyword under :error. gen.clj emits it, openapi_contract_test checks the enum equals the same scan, and api_test checks that status-by-category maps every category in it, so neither can drift from the code. A category built some other way (from a variable) is not seen; keep categories literal.Report schema.POST /v1/{command} with body = the MCP params minus command. x-hive-call-op on each operation is the op for hive_call(op, json), and the body is the same JSON, so both transports share one request schema.hive-spi.native.schema/Envelope): {ok:true, value} | {ok:false, error:"<category>", ...rest of the r/err map}. hive-spi's Envelope is an open map, so the extra keys (param, profile, known, hint, stderr, holders, orphans) conform. error/type is reserved for host transport failures (native/*).x-mutates flags commands with side effects (all are POST, including the reads, so the op name stays the whole route).The draft uses bare names (namespace dropped), because that is what both sides already do:
clojure.data.json/write-str writes :profile/id as "id" and the keyword value :compose/unknown-profile as "unknown-profile". Measured with gen/staging.datajson-probe.json.malli.json-schema likewise emits "id" for :profile/id.hc-lane-edge suggested "without the ns or with a/b style". I chose without the ns for the value objects, because it matches today's wire. Exceptions:
compose/unknown-profile) on the API wire, while the MCP text keeps "unknown-profile". DECIDED by coordinator:45a1f993 (open question 1 closed), implemented with no MCP change.Report.cases[].case/id keeps hc-8's a/b style as relayed by hc-lane-core.Risk of dropping the ns: collisions. The probe map {:profile/id "x" :program/id "p"} serialised to two "id" keys in one object. No current response puts two */id keys in one map (checked by reading ops/swarm), but hc-6 Instance/Wiring rows will be next to profile/id. The fix is to serialise with :key-fn keeping ns/name in the HTTP adapter. That changes the MCP wire too unless it is done only in the new transport.
npx @redocly/cli@2.11.0 lint openapi.yaml: valid, 0 errors, 21 warnings, all no-unused-components. The unused ones are the value objects not yet referenced by any response, kept as the generated catalog: Profile, Settings, Active, the hc-2 stack types and so on.npx openapi-typescript@7.13.0 produced schema.d.ts (about 2.7k lines). tsc --strict --noEmit check.ts passes, apart from the error planted on purpose: env: {TOKEN: {pass: 1}} is rejected with "number is not assignable to string", which shows the SecretRef typing reaches clients. {pass: "dev/token"} and plain strings type-check, as does r.value.services: string[].npx elm-open-api (latest) generated 7 modules, and elm make (0.19.3) compiles them with Success! Compiled 7 modules. The generator printed 87 warnings, mostly the same three.anyOf [{required:[target]},{required:[profile]}]: each required-only branch became unknown, collapsing the whole body type to unknown. I dropped it for x-requires-one-of: [target, profile], so the target-or-profile rule is not machine-checked (the server answers missing-param).$ref into another schema's properties (#/components/schemas/ComposeRequest/properties/x). Param schemas are now inlined per command.Error generated decodeError, which collides with a local name in generated code, and Elm 0.19.3 rejects shadowing. Renamed to ErrorEnvelope.anyOf string | object and const. Env becomes Dict String Json.Encode.Value, ok becomes Value, error becomes Value, and holds becomes {}. It works, but Elm callers build the SecretRef by hand. Not fixed. A oneOf with a discriminator is impossible here because the string branch has no property. Possible fix: a dedicated {literal: s} | {pass: p} form for the HTTP API only (open question 3).:re patterns as java.util.regex.Pattern, so gen.clj renders them with str. [:fn ...] parts (the Suite image-or-command rule) are dropped, and [:and number? [:>= 0]] (cpu-busy-percent) becomes a bare {}/number without the bound. Check after hc-2 merges."true" strings (addon/flag), while the draft types them as boolean. An HTTP adapter should accept both or reject strings; I left it as a note in the ComposeRequest description.| path | op | plan step | params |
|---|---|---|---|
/v1/test | test | hc-8 | {suites, projects, run?}, a matrix of Report |
/v1/stack-up, /v1/stack-down, /v1/stack-status, /v1/plan, /v1/why, /v1/faults and /v1/flaky were placeholders here. They are live since staging merged hc-4/6/10/12/13. Their Req_ schemas are generated from the tool's params like every other command (faults: run, op, proxy, toxic). Their results are typed open (FaultsResult, StackUpResult, ...) until those maps get malli schemas.
The stack params are hc-lane-core's provisional hc-6 params (hivemind, via hc-lane-edge). The response shapes of the planned paths are my guesses from the plan text, apart from Report (from hc-8, relayed). hc-10, hc-12 and hc-13 shapes are unverified against their branches (hc10-trace, hc-13-flaky worktrees have uncommitted or empty work).
schema/api.clj, m/=> the dispatch results in tests, and generate everything.logs.out is one string (compose output, clipped by cli/max-output-chars), not per-service lines.status.config[].error and StepReport.error inner shapes are loose (select-keys res [:error :exit :stderr]).who.agents[] comes from ISwarm {agent/id agent/status agent/cwd} plus sections. It is typed open.reap returns the tick! pass with {skipped} and {error} variants under ok:true. A thrown pass is still ok:true with error inside, which a client could mistake for success.help works before init, and everything else answers not-initialized (503). The HTTP server only runs while the addon is active, so over HTTP a 503 appears only between a failed reload and the next init.agent_id, but an HTTP server needs an identity for claim/release (agent defaults to agent_id).hive_call is designed below, not built (phase 2).ns/name before stacks add colliding */id keys?{literal} | {pass}) in the HTTP API to get clean sum types in Elm and TS, while keeping the MCP form as is?stack.up (dotted, the native-op style that hive-spi ToolName projects to stack_up) vs nested paths /v1/stack/up. The draft uses both: path nested, op dotted.hive_call(op, json) (hive-cabi/v1) is a second transport over the SAME function the HTTP adapter calls:
hive_call(op, json) == (api/encode (api/envelope (api/call deps op (json/read-str json))))
POST /v1/{op} == the same, plus api/http-status for the code
op is the operation's x-hive-call-op: the command name for today's paths, dotted for the planned ones (stack.up maps to /v1/stack/up; api/planned holds the table). json is the request body unchanged, so both transports share one request schema. The answer is the envelope with no status code. Host-side failures use error/type native/* (unavailable, timeout, malformed, failed) and never a compose/* category.ops catalog: generated from the spec, with name = x-hive-call-op, doc = summary, pure = (not x-mutates).api/call with (partial addon/dispatch a) is the in-process hive_call. A JVM hive_call shim over FFM is only needed for a foreign .so.hive_call/hive_free. The hc-15(b) spike (knowledge 20261122142916-4a4b1c4b) built one with jolt: a 16.5 KB C shim (real dynamic symbols, dlopen of the 15 MB jolt .so, jolt_library_init once, :collect-safe exports, malloc'd strings freed by hive_free). Its output was byte-identical to the JVM's. Only the PURE layer can go there (resolver/plan: hc-3/hc-4). Docker-driving commands stay in the JVM and are reached over HTTP. Keep hc-3/hc-4 portable .cljc so this stays open.LD_PRELOAD=$JAVA_HOME/lib/libjsig.so. hive-cabi's JVM loader must set or require that for jolt libraries (see the hive-cabi README). Inside hive-mcp, prefer the HTTP API or a subprocess.up --wait can take :compose/up-timeout-ms (10 min), so a native caller runs it on its own thread. A deadline param (timeout_ms in the body) is a later addition for both transports at once.agent_id. Over HTTP and hive_call, claim/release need agent in the body (otherwise compose/missing-param). There is no auth: the API binds loopback only.(str t) of an ExceptionInfo still prints its ex-data in addon/tick! last-pass (status, reap), ops release-threw, orphans/ownership check-failed. This predates hc-14 but now reaches HTTP: switch to class + ex-message.up --wait calls starve /v1/health. Bound the queue (503) and set sun.net.httpserver.maxReqTime.:compose/api is only reported by reload, not rebound, and the comparison is against the last reload's cfg, not the config the server started with.check-params runs before the unknown/planned check, so a badly typed param on /v1/bogus answers 400, not 404.gen/hc2.*.json came from the uncommitted hc-2 worktree. Regenerate it from origin/feat/hc-2-stack-schema b55bf75 (or staging, once hc-2 merges) and pin the commit in assemble.py.stack-up, stack-down, stack-status and plan become real paths, and the contract test picks them up from the command enum.Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |