Commit graph hyperhive/hive-c0re
Author SHA1 Message Date
atlas
994f53d06f fix(#978): stage roles.json in sync_agents alongside topology.json
topology::reconcile_roles writes roles.json to the meta dir, but
sync_agents never staged it. After #978 merged, roles.json showed up
as an untracked file in the meta repo (visible in `git status`) because
it followed the same pattern as topology.json and tool-groups.json but
was missed in the git add list.

Add the same conditional stage for roles.json: git add is a no-op when
the file is unchanged or absent, matching the existing pattern.
2026-06-01 19:45:20 +02:00
atlas
f56b5c5a7b fix(#991): start nginx when unit is in failed state, not just reload
nginx -s reload signals a running master process. When nginx enters
failed state (start-limit-hit from repeated nginx -t failures on a
bad agents.conf), there is no master and the reload is a silent no-op.
c0re kept re-firing the same no-op reload forever via RELOAD_PENDING.

Fix: probe the nginx unit's ActiveState before sending the reload:
- active    → nginx -s reload (existing zero-downtime path)
- failed    → systemctl reset-failed nginx + systemctl start nginx
- other     → systemctl start nginx

This makes c0re self-healing: once a corrected agents.conf is published,
the next reload_gateway_nginx call clears the start-limit and restarts
nginx automatically without operator intervention.

New helpers: nginx_active_state() (systemctl show --property=ActiveState
--value) and gateway_systemctl() (host-side systemctl --machine=hive-gateway).
2026-06-01 19:31:30 +02:00
atlas
e3b4d38565 fix(#922): fall back to m.login.password when matrix user already exists
When the token file is deleted but the homeserver account still exists,
register_user returns M_USER_IN_USE (HTTP 400) and the provisioning
sweep hard-fails, leaving the agent without a working matrix token.

Fix: persist the random password to matrix-password alongside the
access token on first registration. On subsequent attempts where
M_USER_IN_USE is returned, fall back to login_user (m.login.password)
using the stored password. If both files are gone, the error message
guides the operator to `hivectl matrix create-user <name> --password`.
2026-06-01 19:28:50 +02:00
iris
0b15cad93f feat(#986): dedicated logs page with build/agent/system sub-tabs
Add /logs.html as a standalone page (same back-link pattern as flow.html):
- BUILD tab: all-agents build log history via new GET /api/build-logs endpoint
- AGENT tab: per-container journald viewer with agent selector + unit filter
- SYSTEM tab: host-side hive-c0re.service logs via new GET /api/journal-host endpoint

Remove inline log drill-ins from SW4RM container rows (buildJournalTrigger
and buildBuildLogsTrigger) — log viewing now lives on the dedicated page.

flow.html: strip the full dashboard tabbar, replace with a simple back link
matching the new logs page chrome.

index.html: add L0GS tab link to /logs.html in the tab strip.

Backend additions:
- build_logs::list_recent_all — cross-agent query (newest first, cap 100)
- GET /api/build-logs — all-agents variant backed by list_recent_all
- GET /api/journal-host — host journald (no -M container flag), restricted
  to allow-listed units (hive-c0re.service)
2026-06-01 19:20:54 +02:00
atlas
fd87cf9924 fix(#962): top_level_agents = parentless agents, not children of manager
Per mara's design: the role grants access to every agent with no parent
in the topology (parent=None), derived purely from structure. No agent
name is hardcoded. In normal operation this is just the manager; any
additional parentless agents the operator creates are also covered.

Update ROLE docstring, lifecycle.rs comment, and unit tests accordingly.
Add a multi-root test to document the behaviour with multiple parentless
agents.
2026-06-01 19:19:24 +02:00
atlas
aae4be19bd fix(#962): remove hardcoded "root" string from docstrings and tests
Replace literal "root" with MANAGER_NAME constant in role tests;
update ROLE_CAN_MANAGE_TOP_LEVEL_AGENTS docstring to say "manager"
not "root/manager agent".
2026-06-01 19:19:24 +02:00
atlas
a4e0628ba1 fix(#962): top_level_agents_in delegates to children_of(MANAGER_NAME)
The previous parent=None heuristic was wrong — the manager is not
required to be the structural topology root (it can have a parent).
Delegate to children_of_in(MANAGER_NAME) directly; topology.rs is the
right place for this knowledge. Update comment in lifecycle.rs to say
"direct child of the manager" instead of "direct child of root".
2026-06-01 19:19:24 +02:00
atlas
828be8e2c8 refactor(#962): replace children_of(MANAGER_NAME) with top_level_agents()
Add topology::top_level_agents_in(topo) and top_level_agents() which
find the topology root by structure (parent=None) rather than by name,
then return its children. Lifecycle.rs role logic now uses this instead
of children_of(MANAGER_NAME), removing the hardcoded manager-name
reference from the bind-mount logic.

Also adds two unit tests for top_level_agents_in.
2026-06-01 19:19:24 +02:00
atlas
d79df752d6 fix(#962): keep empty role entries as tombstone; add role unit tests
set_role previously removed empty entries after revoke, causing
reconcile_roles to re-seed the role on the next tick (absent key =
never seen = seed). Fix: never remove empty entries; an empty list
is a tombstone meaning "explicitly revoked".

Also adds unit tests for has_role_in, set_role revoke semantics, and
the reconcile_roles seed/no-seed distinction (pure in-memory, no disk).
2026-06-01 19:19:24 +02:00
atlas
6d2d0ed847 feat(#962): topology-driven child bind mounts + can_manage_top_level_agents role
Removes the MANAGER_NAME special-case from set_nspawn_flags in favour of
two general mechanisms:

1. Topology-driven child mounts: every agent now gets its direct children's
   state, harness, and config dirs bind-mounted (RW). Root's children are
   the top-level agents, so root gets the same access it did before via the
   old /agents blob bind — but derived from topology, not a hardcoded name
   check.

2. can_manage_top_level_agents role: agents holding this role additionally
   get every top-level agent treated as a virtual child (same RW mounts)
   plus /applied and /meta as RO. Designed for recovery: a role holder can
   update a top-level agent's config even when that agent is down.
   Root receives this role by default on first reconcile_roles call.
   Operator can revoke it with set_role.

Every agent (including root) now gets its own state/harness/config dirs via
the standard path. Roles are stored in meta/roles.json (same dir as
topology.json); reconcile_roles is called from reconcile so both files stay
in sync.
2026-06-01 19:19:24 +02:00
iris
ab278affc7 rename(#162): scrub remaining hm1nd references from comments and MCP instructions
All functional renames (MANAGER_NAME, MANAGER_AGENT → "root") were done in
earlier commits. This cleans up the stale `hm1nd` strings that remained in
doc comments, test fixture labels, and the manager MCP server instructions
(which told the manager its config lived at /agents/hm1nd/config/agent.nix).
2026-06-01 19:18:02 +02:00
müde
f9de183f4e fix: strip /agent/<name>/ via rewrite in named location
nginx forbids a URI part on proxy_pass inside named locations, so the
split-mode `@<name>_dynamic` fallback (introduced when the gateway
started serving static dist directly) failed config-test with:

  "proxy_pass" cannot have URI part in location given by regular
  expression, or inside named location

Render two upstream forms: prefix locations keep the trailing slash so
nginx auto-strips the location prefix; the named-location path strips
`/agent/<name>/` via `rewrite ... break` and uses a bare upstream.
2026-06-01 19:10:38 +02:00
damocles
4d934748f7 fix(#977): abort phase 5 if stop fails; clean up old root.conf after rename 2026-06-01 18:32:19 +02:00
damocles
68cc433ac9 fix(#977): add MANAGER_CONTAINER=h-root, migrate root container name 2026-06-01 18:32:19 +02:00
atlas
286a7c8fd3 fix(#975): use hyperhive.local email domain to pass Forgejo validation
`@hyperhive` (no dot) is rejected by Forgejo's PATCH /admin/users API
with 422 Unprocessable Entity. Switch to `@hyperhive.local` across all
four files that construct hive-c0re/agent git emails and Forgejo account
emails, so both stay in sync and pass RFC-valid domain validation.
2026-06-01 18:28:22 +02:00
damocles
b83edc40c6 fix(#970,#973): retry gateway reload on failure; always enable HIVE_WEB_SOCKET 2026-06-01 18:18:45 +02:00
atlas
5cf18ad7c7 fix(#971): remove duplicate BindMount re-export in priv_client
BindMount was imported at line 10 via the priv_proto glob-style import,
then re-exported again with `pub use` at line 69. E0252: two definitions
of BindMount in the same type namespace. Remove the redundant pub use —
callers that need BindMount should import from hive_sh4re::priv_proto.
2026-06-01 18:05:43 +02:00
damocles
68fd7e08a5 fix(#948): pre-enqueue topology-sorted cascades on meta-update approval 2026-06-01 17:55:01 +02:00
damocles
11d74e1e17 fix(#947): include manager in gateway agents.conf routing 2026-06-01 17:46:10 +02:00
damocles
aa96d76e73 build-logs: extract compute_runtime_secs helper; clamp runtime in js 2026-06-01 17:42:35 +02:00
damocles
26c9c13cf5 build-logs: surface runtime_secs in header; show duration in dashboard row 2026-06-01 17:36:29 +02:00
iris
e162c1a1fa feat(#955): split agent page serving — statics from nix store, API proxied
gateway_nginx.rs reads HIVE_AGENT_FRONTEND_DIR (injected by hive-c0re.nix
as ${cfg.frontend}/agent). When set, agents.conf emits per-agent split
blocks instead of the old single proxy_pass:

  # Compiled assets — immutable nix store path, cache 1y
  location ^~ /agent/<name>/static/ {
      alias <frontend>/static/;
      expires 1y; add_header Cache-Control "public, immutable, ...";
  }
  # Static dist + proxy fallback
  location /agent/<name>/ {
      alias <frontend>/;
      try_files $uri $uri.html $uri/index.html @<name>_dynamic;
  }
  location @<name>_dynamic {
      proxy_pass <upstream>;   # api, events, icon, login, …
      …proxy headers unchanged…
  }

try_files path resolution (nginx applies alias mapping first):
  $uri           — exact file (/static/app.js → static/app.js)
  $uri.html      — bare-path fallback (/stats → stats.html)
  $uri/index.html — directory index (/ → index.html)
  @<name>_dynamic — proxy catchall for anything not in the dist

Adding pages to the frontend dist works automatically — no generator
change needed. Per-agent extraFiles (in mergedDist, not in the base
nix-store path) continue to proxy to the agent daemon.

frontend is a nix store path injected at build time — only [a-z0-9/._-],
no shell metacharacters — safe to interpolate without sanitization;
comment added documenting this assumption.

Without HIVE_AGENT_FRONTEND_DIR the existing single-proxy block is
emitted unchanged — backward-compatible for deployments without the env.

render() takes frontend_dir as a parameter so tests exercise both code
paths safely in parallel. 13 tests: 7 legacy, 6 split-mode. No clippy
warnings in changed files.

nix/modules/hive-c0re.nix: inject HIVE_AGENT_FRONTEND_DIR = "${cfg.frontend}/agent".
2026-06-01 17:35:28 +02:00
damocles
e7e0675d22 rename: role badge stays 'manager'; unify harness unit name to hive-ag3nt 2026-06-01 17:33:09 +02:00
damocles
1b4e9d0e2b rename(162): nixosConfigurations.manager -> root, hive-m1nd -> hive-root 2026-06-01 17:33:09 +02:00
damocles
9654315a20 rename(162): update manager test to use root 2026-06-01 17:33:09 +02:00
damocles
935f2011a0 rename(162): update hm1nd comment in ensure_manager 2026-06-01 17:33:09 +02:00
damocles
4c2398a38e rename(162): role badge manager -> root, update hm1nd comment 2026-06-01 17:33:09 +02:00
damocles
37b5335c27 rename(162): MANAGER_NAME hm1nd -> root 2026-06-01 17:33:09 +02:00
damocles
c9eb520e7c priv: WriteNspawnFlags takes Vec<BindMount> instead of raw flag strings 2026-06-01 17:27:14 +02:00
damocles
aa7f8e5553 priv: move shared consts to hive-sh4re; WriteNspawnFlags uses Vec<String> + per-flag validation 2026-06-01 17:27:14 +02:00
damocles
89d0937473 priv: derive flake ref from agent name; WriteNspawnFlags takes flags only 2026-06-01 17:27:14 +02:00
damocles
8d5e97ce9f fix(702): update priv_client to match narrowed PrivRequest variants 2026-06-01 17:27:14 +02:00
damocles
29926031ae fix(702): replace systemd_run_machine with reload_gateway_nginx in priv_client 2026-06-01 17:27:14 +02:00
damocles
c5cab732a2 feat(#702): priv_client - async client for hive-priv 2026-06-01 17:27:14 +02:00
damocles
138d9fdabe feat(#702): add priv_client module to hive-c0re 2026-06-01 17:27:14 +02:00
damocles
e8b24e7021 fix(948): topo-sort cascade agents in meta_update_cascade_agents 2026-06-01 16:50:41 +02:00
damocles
5dc31c1e13 fix(948): make topology_sort pub 2026-06-01 16:50:40 +02:00
damocles
eb108f9dd8 fix(947): trim prose in lifecycle.rs socket-dir block 2026-06-01 16:49:41 +02:00
damocles
e7a5718e83 fix(947): strip prose/issue-tags from agent_sockets.rs 2026-06-01 16:49:41 +02:00
damocles
7af29b3249 fix(#947): extend socket-dir bind to manager container 2026-06-01 16:49:41 +02:00
damocles
4435666c00 fix(#947): include manager in agent-sockets.json 2026-06-01 16:49:41 +02:00
damocles
8b946a67c6 fix(#947): extend socket-dir bind to manager container 2026-06-01 16:49:41 +02:00
atlas
f8c0f64fd4 feat: socket-activate the hive-c0re admin socket
Add a systemd.sockets.hive-c0re unit that holds /run/hyperhive/host.sock
before hive-c0re starts. hive-c0re serve() detects LISTEN_FDS via the
listenfd crate and accepts the systemd-handed fd instead of calling bind().
Falls back to the existing bind path when LISTEN_FDS is absent so direct
invocation and CI are unaffected.

Benefits: hivectl can connect the moment the socket unit activates (no
racy window), and a hive-c0re restart never drops the socket inode.
2026-06-01 16:29:41 +02:00
damocles
0f62eca356 fix(#942): wire bash_tasks_vacuum spawn into main.rs 2026-06-01 16:11:08 +02:00
damocles
5880328831 fix(#942): wire bash_tasks_vacuum into lib.rs + main.rs 2026-06-01 16:11:08 +02:00
damocles
38a5299183 fix(#942): host-side bash-tasks vacuum, 48h retention 2026-06-01 16:11:08 +02:00
damocles
8d2ae047b1 fix(#937): drop dead has_pending_from — superseded by has_pending_with_body 2026-06-01 15:39:26 +02:00
damocles
3283362b36 fix(#937): use has_pending_with_body in worker — mirrors broker change 2026-06-01 15:39:26 +02:00
damocles
ce27ef8b9e fix(#937): narrow skip to same-body pending — different schedules can still enqueue 2026-06-01 15:39:26 +02:00
damocles
bf4937d116 fix(#937): skip scheduled delivery if target already has pending scheduled message 2026-06-01 15:39:26 +02:00