Skip to content

Commit 16e4e71

Browse files
feat: expose read-only Ulysses topology
1 parent 63fa32a commit 16e4e71

13 files changed

Lines changed: 455 additions & 2 deletions

‎app.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ async def _stop_background():
779779
from routes.cookbook_routes import setup_cookbook_routes
780780
app.include_router(setup_cookbook_routes())
781781

782+
from routes.ulysses_routes import setup_ulysses_routes
783+
app.include_router(setup_ulysses_routes())
784+
782785
from routes.workspace_routes import setup_workspace_routes
783786
app.include_router(setup_workspace_routes())
784787

‎config/ulysses/runtime-catalog.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"label": "Hermes gateway",
3434
"adapter": "systemd_user",
3535
"ownership": "external",
36+
"scope": "hermes_agent",
3637
"source_root": "${HOME}/.hermes/hermes-agent",
3738
"dependencies": ["sandwich.runtime"],
3839
"capabilities": ["agent-runtime", "gateway", "mcp-host"]
@@ -90,6 +91,7 @@
9091
"label": "Context Mode MCP",
9192
"adapter": "mcp_stdio",
9293
"ownership": "external",
94+
"scope": "hermes_agent",
9395
"source_root": "${ULYSSES_MICROSERVICES_ROOT}/context-mode",
9496
"dependencies": ["hermes.gateway", "sandwich.runtime"],
9597
"capabilities": ["mcp", "context-archive"]
@@ -99,6 +101,7 @@
99101
"label": "Camofox MCP",
100102
"adapter": "mcp_stdio",
101103
"ownership": "external",
104+
"scope": "hermes_agent",
102105
"source_root": "${ULYSSES_MICROSERVICES_ROOT}/camofox-mcp",
103106
"dependencies": ["camofox.browser", "hermes.gateway", "sandwich.runtime"],
104107
"capabilities": ["mcp", "browser"]

‎docs/SANDWICH_BUN_COMPATIBILITY.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Captured on 2026-07-25 without installing Node.
66

77
- Installed Bun: `1.3.14` (`0d9b296a`)
88
- Sandwich compatibility suite: 35 passed
9-
- Ulysses Sandwich/catalog/discovery contract suite: 27 passed
9+
- Ulysses Sandwich/catalog/discovery/topology contract suite: 32 passed
1010
- Detected installation: `/home/alienl/Hermes/sandwich`
1111
- Ulysses full isolated test suite using the upstream Bun fix build:
1212
4,761 passed, 3 skipped

‎docs/ULYSSES_CONTROL_PLANE_DESIGN.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ Arcane-inspired in workflow, but manages more than Docker:
1616
It is intentionally not a scheduler, Kubernetes replacement, or arbitrary
1717
browser shell.
1818

19+
## Agent and MCP boundaries
20+
21+
Odysseus and Hermes remain separate agents:
22+
23+
- the existing Odysseus MCP configuration UI controls only MCPs registered to
24+
the Odysseus agent;
25+
- Hermes profiles and watchdogs control only MCPs registered to Hermes;
26+
- the Ulysses Services UI may observe and operate either registry, but it
27+
never copies, merges, or implicitly registers configuration between them;
28+
- shared host services such as Camofox, Firecrawl, SearXNG, Chroma, and model
29+
endpoints remain host-scoped dependencies that either agent may reference
30+
explicitly.
31+
32+
Every runtime definition therefore carries a scope: `host`,
33+
`odysseus_agent`, or `hermes_agent`. A future context-mode archival bridge may
34+
use a narrow Chroma storage/retrieval contract, but that does not connect the
35+
Odysseus and Hermes agent loops.
36+
1937
## The service contract
2038

2139
Every service definition records:

‎docs/ULYSSES_ROADMAP.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ corresponding rollback has been tested.
502502
3. [x] Implement control-plane data contracts and a read-only registry.
503503
4. Add discovery-only adapters for Docker, systemd, processes/ports, Git,
504504
NVIDIA, and Chroma.
505-
5. Render the first read-only topology/status API.
505+
5. [x] Render the first read-only topology/status API.
506506
6. [x] Integrate Sandwich as the first optional runtime.
507507
7. Adopt and validate the existing microservices, persistence, configuration,
508508
Camofox browser capability, and lifecycle views.

‎routes/ulysses_routes.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Admin-only, read-only Ulysses control-plane routes."""
2+
3+
from __future__ import annotations
4+
5+
from collections.abc import Callable
6+
7+
from fastapi import APIRouter, Request
8+
from starlette.concurrency import run_in_threadpool
9+
10+
from core.middleware import require_admin
11+
from src.sandwich_runtime import observe_sandwich_installation
12+
from src.ulysses_catalog import default_runtime_registry
13+
from src.ulysses_discovery import HostDiscoverySnapshot, collect_host_discovery
14+
from src.ulysses_topology import build_topology_report
15+
16+
17+
def setup_ulysses_routes(
18+
*,
19+
collector: Callable[[], HostDiscoverySnapshot] = collect_host_discovery,
20+
) -> APIRouter:
21+
router = APIRouter(prefix="/api/ulysses", tags=["ulysses"])
22+
23+
@router.get("/topology")
24+
async def get_topology(request: Request) -> dict:
25+
require_admin(request)
26+
snapshot = await run_in_threadpool(collector)
27+
registry = default_runtime_registry()
28+
sandwich = observe_sandwich_installation()
29+
return build_topology_report(registry, snapshot, sandwich)
30+
31+
return router

‎src/ulysses_catalog.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
RuntimeAdapter,
1515
RuntimeDefinition,
1616
RuntimeRegistry,
17+
RuntimeScope,
1718
)
1819

1920

@@ -86,6 +87,7 @@ def load_runtime_catalog(
8687
try:
8788
adapter = RuntimeAdapter(raw["adapter"])
8889
ownership = OwnershipState(raw.get("ownership", "external"))
90+
scope = RuntimeScope(raw.get("scope", "host"))
8991
except (KeyError, ValueError) as exc:
9092
raise RuntimeCatalogError("runtime adapter or ownership is invalid") from exc
9193
source_root = (
@@ -121,6 +123,7 @@ def load_runtime_catalog(
121123
label=raw["label"],
122124
adapter=adapter,
123125
ownership=ownership,
126+
scope=scope,
124127
source_root=source_root,
125128
ports=ports,
126129
dependencies=tuple(dependencies),

‎src/ulysses_runtime.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class OwnershipState(str, Enum):
2828
MANAGED = "managed"
2929

3030

31+
class RuntimeScope(str, Enum):
32+
HOST = "host"
33+
ODYSSEUS_AGENT = "odysseus_agent"
34+
HERMES_AGENT = "hermes_agent"
35+
36+
3137
class RuntimeStatus(str, Enum):
3238
UNKNOWN = "unknown"
3339
STOPPED = "stopped"
@@ -79,6 +85,7 @@ class RuntimeDefinition:
7985
adapter: RuntimeAdapter
8086
execution: ExecutionSpec | None = None
8187
ownership: OwnershipState = OwnershipState.EXTERNAL
88+
scope: RuntimeScope = RuntimeScope.HOST
8289
source_root: Path | None = None
8390
data_roots: tuple[Path, ...] = ()
8491
ports: tuple[PortBinding, ...] = ()

‎src/ulysses_topology.py‎

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
"""Pure topology projection for Ulysses discovery observations."""
2+
3+
from __future__ import annotations
4+
5+
from pathlib import Path
6+
7+
from src.sandwich_runtime import SandwichInstallation
8+
from src.ulysses_discovery import HostDiscoverySnapshot
9+
from src.ulysses_runtime import (
10+
RuntimeAdapter,
11+
RuntimeDefinition,
12+
RuntimeRegistry,
13+
RuntimeStatus,
14+
)
15+
16+
17+
def _path_matches(left: Path | None, right: Path | None) -> bool:
18+
if left is None or right is None:
19+
return False
20+
return left.resolve() == right.resolve()
21+
22+
23+
def _runtime_status(
24+
definition: RuntimeDefinition,
25+
snapshot: HostDiscoverySnapshot,
26+
sandwich: SandwichInstallation,
27+
) -> tuple[RuntimeStatus, tuple[int, ...]]:
28+
active_ports = tuple(
29+
sorted(
30+
{
31+
socket.port
32+
for socket in snapshot.listening_sockets
33+
if any(binding.port == socket.port for binding in definition.ports)
34+
}
35+
)
36+
)
37+
if definition.runtime_id == "sandwich.runtime":
38+
return (
39+
RuntimeStatus.RUNNING if sandwich.installed else RuntimeStatus.STOPPED,
40+
(),
41+
)
42+
if active_ports:
43+
return RuntimeStatus.RUNNING, active_ports
44+
45+
if definition.adapter is RuntimeAdapter.SYSTEMD_USER:
46+
expected = f"{definition.runtime_id.replace('.', '-')}.service"
47+
unit = next(
48+
(item for item in snapshot.systemd_user_units if item.unit == expected),
49+
None,
50+
)
51+
if unit is not None:
52+
if unit.active == "active":
53+
return RuntimeStatus.RUNNING, ()
54+
if unit.active == "failed" or unit.sub == "failed":
55+
return RuntimeStatus.FAILED, ()
56+
return RuntimeStatus.STOPPED, ()
57+
58+
if definition.adapter is RuntimeAdapter.DOCKER_COMPOSE:
59+
containers = tuple(
60+
item
61+
for item in snapshot.compose_containers
62+
if _path_matches(item.working_dir, definition.source_root)
63+
)
64+
if containers:
65+
statuses = tuple(item.status.lower() for item in containers)
66+
if any("unhealthy" in status for status in statuses):
67+
return RuntimeStatus.DEGRADED, ()
68+
if any(status.startswith("up") for status in statuses):
69+
return RuntimeStatus.RUNNING, ()
70+
if all(
71+
status.startswith(("exited", "created", "dead"))
72+
for status in statuses
73+
):
74+
return RuntimeStatus.STOPPED, ()
75+
76+
if definition.ports and not any(
77+
issue.source == "sockets" for issue in snapshot.issues
78+
):
79+
return RuntimeStatus.STOPPED, ()
80+
return RuntimeStatus.UNKNOWN, ()
81+
82+
83+
def _runtime_payload(
84+
definition: RuntimeDefinition,
85+
snapshot: HostDiscoverySnapshot,
86+
sandwich: SandwichInstallation,
87+
) -> dict:
88+
status, active_ports = _runtime_status(definition, snapshot, sandwich)
89+
return {
90+
"runtime_id": definition.runtime_id,
91+
"label": definition.label,
92+
"adapter": definition.adapter.value,
93+
"ownership": definition.ownership.value,
94+
"scope": definition.scope.value,
95+
"status": status.value,
96+
"source_root": (
97+
str(definition.source_root) if definition.source_root is not None else None
98+
),
99+
"source_exists": (
100+
definition.source_root.exists()
101+
if definition.source_root is not None
102+
else None
103+
),
104+
"ports": [
105+
{
106+
"port": binding.port,
107+
"protocol": binding.protocol,
108+
"host": binding.host,
109+
"active": binding.port in active_ports,
110+
}
111+
for binding in definition.ports
112+
],
113+
"dependencies": list(definition.dependencies),
114+
"capabilities": list(definition.capabilities),
115+
}
116+
117+
118+
def build_topology_report(
119+
registry: RuntimeRegistry,
120+
snapshot: HostDiscoverySnapshot,
121+
sandwich: SandwichInstallation,
122+
) -> dict:
123+
"""Create the stable, secret-free response consumed by the Services UI."""
124+
125+
runtimes = [
126+
_runtime_payload(definition, snapshot, sandwich)
127+
for definition in registry.definitions()
128+
]
129+
counts = {
130+
status.value: sum(item["status"] == status.value for item in runtimes)
131+
for status in RuntimeStatus
132+
}
133+
return {
134+
"schema_version": "ulysses.topology.v1",
135+
"observed_at": snapshot.observed_at,
136+
"counts": counts,
137+
"runtimes": runtimes,
138+
"javascript_runtime": {
139+
"id": "sandwich",
140+
"installed": sandwich.installed,
141+
"source_root": (
142+
str(sandwich.source_root)
143+
if sandwich.source_root is not None
144+
else None
145+
),
146+
"commands": {
147+
name: str(path)
148+
for name, path in sorted(sandwich.command_paths.items())
149+
},
150+
"missing_commands": list(sandwich.missing_commands),
151+
},
152+
"compose": [
153+
{
154+
"container_id": item.container_id,
155+
"name": item.name,
156+
"status": item.status,
157+
"project": item.project,
158+
"working_dir": (
159+
str(item.working_dir) if item.working_dir is not None else None
160+
),
161+
"ports": item.ports,
162+
}
163+
for item in snapshot.compose_containers
164+
],
165+
"tmux": [
166+
{
167+
"name": item.name,
168+
"attached": item.attached,
169+
"windows": item.windows,
170+
"created_at": item.created_at,
171+
}
172+
for item in snapshot.tmux_sessions
173+
],
174+
"systemd_user": [
175+
{
176+
"unit": item.unit,
177+
"load": item.load,
178+
"active": item.active,
179+
"sub": item.sub,
180+
"description": item.description,
181+
}
182+
for item in snapshot.systemd_user_units
183+
],
184+
"issues": [
185+
{"source": issue.source, "detail": issue.detail}
186+
for issue in snapshot.issues
187+
],
188+
}

‎tests/test_ulysses_catalog.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def test_default_catalog_resolves_portable_roots_and_sandwich(tmp_path):
3636
"hermes.gateway",
3737
"sandwich.runtime",
3838
)
39+
assert registry.get("camofox.mcp").scope.value == "hermes_agent"
40+
assert registry.get("context.mode.mcp").scope.value == "hermes_agent"
41+
assert registry.get("firecrawl.api").scope.value == "host"
3942

4043

4144
def test_catalog_rejects_relative_microservices_root(tmp_path):

0 commit comments

Comments
 (0)