diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0390651..8f850e8 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -5,6 +5,9 @@ on:
branches: [main, master]
pull_request:
+permissions:
+ contents: read
+
jobs:
lint-and-test:
runs-on: ubuntu-latest
@@ -19,13 +22,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- pip install ruff pytest
+ python -m pip install -r requirements-dev.txt
- name: Lint
- run: ruff check server.py || true
+ run: python -m ruff check server.py tests
- name: Test
- run: pytest || true
+ run: python -m pytest -q
- name: Smoke import
run: python -c "import server; print('import ok')"
diff --git a/AGENTS.md b/AGENTS.md
index 1c66e99..d0762e9 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -4,10 +4,10 @@ Instructions for AI coding agents (OpenCode, Freebuff/Codebuff, Hermes workers,
## Project
-- **What it is:** replace with one sentence.
-- **Stack:** replace (language, framework, runtime).
-- **Run locally:** `cp .env.example .env && docker compose up -d --build`, then open `http://127.0.0.1:8080`.
-- **Health check:** `GET /healthz` must return 200.
+- **What it is:** 3D virtual office dashboard for agent status.
+- **Stack:** Python standard-library HTTP server and static Three.js UI.
+- **Run locally:** `cp .env.example .env && docker compose up -d --build`, then open `http://127.0.0.1:9502`.
+- **Health check:** `GET /api/config` must return 200.
## Commands
diff --git a/README.md b/README.md
index 1458c20..4947ff2 100644
--- a/README.md
+++ b/README.md
@@ -1,77 +1,127 @@
-
-

# Offivo
-*Formerly VirtOffice (hermes-3d-office).*
-
-Virtual office platform — shared workspaces, video rooms, team chat, and collaborative document editing with Docker deployment.
+A 3D virtual office dashboard for agent status, served by Python with a static Three.js interface.
-[](https://github.com/OneByJorah/offivo/releases)
-[](https://www.npmjs.com/package/offivo)
-[](https://www.docker.com/)
-[](https://opensource.org/licenses/MIT)
+[](https://github.com/OneByJorah/offivo/actions/workflows/ci.yml)
+[](LICENSE)
-
-
-

-## What This Is
+## Why this exists
+
+Offivo displays agents, their tasks, and their activity in an animated office.
+It can read a JSON file or poll a Hermes status API, and sends updates to the browser through Server-Sent Events (SSE).
+The Python server uses only the standard library; no Node build or npm installation is required.
-Virtual office platform — shared workspaces, video rooms, team chat, and collaborative document editing with Docker deployment.
+## Features
-## Quick Start
+- 3D office view at `/office.html`, with agent status and task details.
+- JSON state endpoint at `/api/agents` and configuration at `/api/config`.
+- Hermes API polling, JSON file input, and demo fallback when neither source supplies data.
+- Webhook updates at `POST /webhook/agents`, broadcast through `/events`.
+- A single-service Docker Compose setup.
-### npm
+## Quick start
-```bash
-npm install offivo
-```
+### From source
-### Docker
+Use Python 3.11 or later. On Windows, use `py -3` if `python` is not on PATH.
```bash
git clone https://github.com/OneByJorah/offivo.git
cd offivo
-docker compose up -d
+python server.py
```
-### From Source
+Open for the landing page or
+ for the dashboard. Stop the server with Ctrl+C.
+The server reads the repository's `agents.json` by default. Use a separate file for your own agents.
+The browser loads Three.js from cdnjs and fonts from Google Fonts, so full rendering needs internet access.
+
+### Docker Compose
+
+From the repository directory, with Docker and Compose installed:
```bash
-git clone https://github.com/OneByJorah/offivo.git
-cd offivo
-npm install
-npm run dev
+cp .env.example .env
+docker compose up -d --build
```
-## Features
+In PowerShell, use `Copy-Item .env.example .env` for the copy step.
+The same URLs above apply. Compose publishes only on `127.0.0.1`; `HOST=0.0.0.0`
+in the example configuration is the bind address **inside the container**.
+Compose mounts `./agents.json` read-only at `/app/agents.json`.
+
+Stop the service with `docker compose down`.
+
+## Configuration
+
+The source command reads environment variables; it does **not** load `.env`.
+Compose loads `.env` through `env_file`. Set variables in your shell when running Python directly.
-- **Self-hosted** — run on your own hardware
-- **Docker Compose** — full stack with one command
-- **npm package** — install via npm
-- **Dark theme** — operational UI
+| Variable | Source default | Purpose |
+| --- | --- | --- |
+| `HOST` | `127.0.0.1` | Server bind address; Compose defaults to `0.0.0.0` inside the container. |
+| `PORT` | `9502` | HTTP port. |
+| `AGENTS_JSON_PATH` | `agents.json` beside `server.py` | JSON file; prefer an absolute path for a custom file. |
+| `HERMES_AGENT_API` | Empty | Optional HTTP endpoint returning an agent array or an object containing `agents` or `results`. |
+| `POLL_INTERVAL_SECONDS` | `5` | Source refresh interval in seconds. |
+| `ENABLE_SSE` | `true` | Broadcast live events; `1`, `true`, and `yes` enable broadcasting. |
-- **Shared workspaces** — virtual office spaces for teams
-- **Video rooms** — WebRTC-based video conferencing
-- **Team chat** — real-time messaging and channels
-- **Document collaboration** — shared editing and comments
-- **Docker Compose deployment** — multi-service stack
-- **Dark theme** — modern, collaborative UI
+An agent file can contain an array or an object with an `agents` array:
-## Package Badges
+```json
+{"agents": [{"id": "demo-worker", "name": "Demo Worker", "status": "working", "task": "Example task"}]}
+```
+
+The server normalizes omitted display fields. An empty array means no agents.
+Each refresh tries the configured Hermes API, then the file, then built-in demo agents.
+`/api/config` reports the configured source, not whether the last fetch succeeded.
+
+`POST /webhook/agents` accepts an array or `{"agents": [...]}` and updates the in-memory
+state immediately. The next polling refresh replaces that state from the configured source;
+use file or API input for persistent updates. The server has no authentication, so keep it on loopback.
+See [Hermes integration](docs/HERMES_INTEGRATION.md) for bridge details.
+
+## Architecture
-[](https://github.com/OneByJorah/offivo/releases)
-[](https://www.npmjs.com/package/offivo)
-[](https://www.docker.com/)
-[](https://opensource.org/licenses/MIT)
+```mermaid
+flowchart LR
+ API[Hermes status API] --> Server[Python server]
+ File[Agent JSON file] --> Server
+ Hook[Webhook sender] --> Server
+ Server -->|Static HTML, JSON, SSE| Browser[Three.js dashboard]
+```
+
+## Development checks
+
+Create and activate a virtual environment, then run:
+
+```bash
+python -m pip install -r requirements-dev.txt
+python -m ruff check server.py tests
+python -m pytest -q
+```
+
+Tests start loopback servers with temporary synthetic data and exercise static pages,
+configuration, agent state, webhook updates, SSE, and the Python entry point.
+CI runs the same lint and test commands and fails if either fails.
+The npm scripts are convenience wrappers for Python commands, not a JavaScript runtime package.
+
+## Roadmap
+
+Propose improvements through [issues](https://github.com/OneByJorah/offivo/issues).
## Contributing
-[Open an issue](https://github.com/OneByJorah/offivo/issues) to report a bug or request a feature.
+See [CONTRIBUTING.md](CONTRIBUTING.md) and [AGENTS.md](AGENTS.md).
+
+## Security
+
+See [SECURITY.md](SECURITY.md) for reporting instructions.
## License
-MIT — see [LICENSE](LICENSE).
+MIT; see [LICENSE](LICENSE).
diff --git a/docker-compose.yml b/docker-compose.yml
index 2c2bdd4..6592bc4 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,7 +16,7 @@ services:
image: ghcr.io/onebyjorah/offivo:latest
container_name: offivo
ports:
- - "${PORT:-9502}:${PORT:-9502}"
+ - "127.0.0.1:${PORT:-9502}:${PORT:-9502}"
env_file:
- .env
environment:
diff --git a/package.json b/package.json
index d55d863..49ea932 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,10 @@
{
"name": "offivo",
"version": "1.0.0",
- "description": "Virtual office platform \u2014 shared workspaces, video rooms, team chat, and collaborative document editing with Docker deployment.",
- "main": "index.js",
+ "description": "3D agent dashboard with a Python server, JSON state API, and Server-Sent Events.",
"scripts": {
- "test": "echo 'ok' && exit 0"
+ "start": "python server.py",
+ "test": "python -m pytest -q"
},
"keywords": [
"offivo",
@@ -22,12 +22,13 @@
"url": "https://github.com/OneByJorah/offivo/issues"
},
"homepage": "https://github.com/OneByJorah/offivo#readme",
+ "publishConfig": {
+ "access": "public"
+ },
"files": [
- "dist/",
+ "server.py",
+ "public/",
"README.md",
"LICENSE"
- ],
- "publishConfig": {
- "access": "public"
- }
-}
\ No newline at end of file
+ ]
+}
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..2d25083
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,8 @@
+[tool.pytest.ini_options]
+testpaths = ["tests"]
+
+[tool.ruff]
+target-version = "py311"
+
+[tool.ruff.lint]
+select = ["E4", "E7", "E9", "F"]
diff --git a/requirements-dev.txt b/requirements-dev.txt
new file mode 100644
index 0000000..ec89bca
--- /dev/null
+++ b/requirements-dev.txt
@@ -0,0 +1,2 @@
+pytest==9.2.0
+ruff==0.17.3
diff --git a/server.py b/server.py
index 7fb39b5..52c47aa 100644
--- a/server.py
+++ b/server.py
@@ -3,7 +3,7 @@
Hermes 3D Office Dashboard Server
Serves the static 3D office dashboard and provides a live agent-state API.
-Three wiring modes are supported out of the box:
+Four wiring modes are supported out of the box:
1. Demo mode - Auto-generated sample agents (default).
2. Hermes status API - Poll HERMES_AGENT_API for live agents.
@@ -12,7 +12,7 @@
Environment variables (see .env.example):
PORT Server port (default 9502)
- HOST Bind address (default 0.0.0.0)
+ HOST Bind address (default 127.0.0.1)
HERMES_AGENT_API URL to Hermes GET /api/agents/status endpoint
AGENTS_JSON_PATH Path to agents.json file drop
POLL_INTERVAL_SECONDS Polling interval for HERMES_AGENT_API
@@ -38,7 +38,7 @@
AGENTS_JSON_PATH = os.environ.get("AGENTS_JSON_PATH", "").strip() or str(Path(__file__).parent / "agents.json")
POLL_INTERVAL = int(os.environ.get("POLL_INTERVAL_SECONDS", "5"))
ENABLE_SSE = os.environ.get("ENABLE_SSE", "true").lower() in ("1", "true", "yes")
-DEMO_MODE = not (HERMES_AGENT_API or AGENTS_JSON_PATH)
+DEMO_MODE = not (HERMES_AGENT_API or Path(AGENTS_JSON_PATH).exists())
DIRECTORY = Path(__file__).parent / "public"
ROOT = Path(__file__).parent
@@ -136,7 +136,7 @@ def _read_agents_json():
if path.exists():
with path.open("r", encoding="utf-8") as f:
data = json.load(f)
- if isinstance(data, list) and data:
+ if isinstance(data, list):
return data
if isinstance(data, dict) and "agents" in data:
return data["agents"]
@@ -286,11 +286,12 @@ def do_GET(self):
return
def do_POST(self):
+ global latest_agents
parsed = urlparse(self.path)
if parsed.path == "/webhook/agents":
try:
body = self._read_json_body()
- agents = body.get("agents", body if isinstance(body, list) else [])
+ agents = body if isinstance(body, list) else body.get("agents", [])
normalized = [_normalize_agent(a) for a in agents]
with state_lock:
latest_agents = normalized
@@ -356,12 +357,13 @@ def main():
socketserver.ThreadingTCPServer.allow_reuse_address = True
socketserver.ThreadingTCPServer.daemon_threads = True
with socketserver.ThreadingTCPServer((HOST, PORT), Handler) as httpd:
+ port = httpd.server_address[1]
mode = "DEMO" if DEMO_MODE else ("Hermes API" if HERMES_AGENT_API else "agents.json file")
- print(f"Hermes 3D Office running at http://{HOST}:{PORT}", flush=True)
+ print(f"Hermes 3D Office running at http://{HOST}:{port}", flush=True)
print(f"Mode: {mode}", flush=True)
- print(f"Agent API: http://{HOST}:{PORT}/api/agents", flush=True)
- print(f"Webhook: POST http://{HOST}:{PORT}/webhook/agents", flush=True)
- print(f"Config: http://{HOST}:{PORT}/api/config", flush=True)
+ print(f"Agent API: http://{HOST}:{port}/api/agents", flush=True)
+ print(f"Webhook: POST http://{HOST}:{port}/webhook/agents", flush=True)
+ print(f"Config: http://{HOST}:{port}/api/config", flush=True)
httpd.serve_forever()
diff --git a/tests/test_server.py b/tests/test_server.py
new file mode 100644
index 0000000..b29af16
--- /dev/null
+++ b/tests/test_server.py
@@ -0,0 +1,139 @@
+"""HTTP smoke tests using only temporary, synthetic agent state (MIT license)."""
+
+import http.client
+import importlib.util
+import json
+import os
+from pathlib import Path
+import socketserver
+import subprocess
+import sys
+import threading
+
+import pytest
+
+ROOT = Path(__file__).resolve().parents[1]
+
+
+@pytest.fixture
+def office(tmp_path, monkeypatch):
+ state = tmp_path / "agents.json"
+ state.write_text('[{"id": "demo-test", "name": "Demo Test"}]', encoding="utf-8")
+ monkeypatch.setenv("AGENTS_JSON_PATH", str(state))
+ monkeypatch.setenv("HERMES_AGENT_API", "")
+ monkeypatch.setenv("ENABLE_SSE", "true")
+ monkeypatch.setenv("POLL_INTERVAL_SECONDS", "5")
+ spec = importlib.util.spec_from_file_location("isolated_server", ROOT / "server.py")
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ module.refresh_agents()
+ with socketserver.ThreadingTCPServer(("127.0.0.1", 0), module.Handler) as httpd:
+ httpd.daemon_threads = True
+ worker = threading.Thread(target=httpd.serve_forever, daemon=True)
+ worker.start()
+ yield module, httpd.server_address[1], state
+ httpd.shutdown()
+ worker.join(timeout=5)
+
+
+def request(port, path, method="GET", body=None):
+ connection = http.client.HTTPConnection("127.0.0.1", port, timeout=5)
+ try:
+ connection.request(method, path, body, {"Content-Type": "application/json"})
+ response = connection.getresponse()
+ return response.status, response.getheader("Content-Type"), response.read()
+ finally:
+ connection.close()
+
+
+@pytest.mark.parametrize("path,title", [
+ ("/", "Offivo — 3D Virtual Agent Office"),
+ ("/office.html", "Offivo — Living Office Floor Plan"),
+])
+def test_static_pages(office, path, title):
+ status, content_type, body = request(office[1], path)
+ assert status == 200
+ assert content_type.startswith("text/html")
+ assert f"{title}".encode() in body
+
+
+def test_config_and_normalized_agents(office):
+ status, content_type, body = request(office[1], "/api/config")
+ assert status == 200
+ assert content_type == "application/json"
+ assert json.loads(body) == {
+ "mode": "json_file", "poll_interval_seconds": 5,
+ "enable_sse": True, "hermes_agent_api": None,
+ }
+ agents = json.loads(request(office[1], "/api/agents")[2])
+ assert len(agents) == 1
+ assert agents[0]["id"] == "demo-test"
+ assert agents[0]["status"] == "idle"
+
+
+@pytest.mark.parametrize("wrapped", [False, True])
+def test_webhook_updates_get_and_sse(office, wrapped):
+ connection = http.client.HTTPConnection("127.0.0.1", office[1], timeout=5)
+ try:
+ connection.request("GET", "/events")
+ stream = connection.getresponse()
+ assert stream.status == 200
+ assert stream.getheader("Content-Type") == "text/event-stream"
+ assert json.loads(stream.readline()[6:])["agents"][0]["id"] == "demo-test"
+ assert stream.readline() == b"\n"
+ agents = [{"id": "pushed-demo", "status": "working"}]
+ payload = {"agents": agents} if wrapped else agents
+ status, _, body = request(office[1], "/webhook/agents", "POST", json.dumps(payload))
+ assert status == 200
+ assert json.loads(body) == {"ok": True, "count": 1}
+ current = json.loads(request(office[1], "/api/agents")[2])
+ assert current[0]["id"] == "pushed-demo"
+ assert json.loads(stream.readline()[6:])["agents"] == current
+ finally:
+ connection.close()
+
+
+def test_bad_json_and_missing_route(office):
+ status, _, body = request(office[1], "/webhook/agents", "POST", "{")
+ assert status == 400
+ assert json.loads(body)["ok"] is False
+ assert json.loads(request(office[1], "/api/agents")[2])[0]["id"] == "demo-test"
+ assert request(office[1], "/missing")[0] == 404
+
+
+def test_empty_file_is_empty_state(office):
+ office[2].write_text("[]", encoding="utf-8")
+ office[0].refresh_agents()
+ assert json.loads(request(office[1], "/api/agents")[2]) == []
+
+
+def test_missing_file_uses_demo(office):
+ office[2].unlink()
+ office[0].refresh_agents()
+ assert json.loads(request(office[1], "/api/config")[2])["mode"] == "demo"
+ assert len(json.loads(request(office[1], "/api/agents")[2])) == 5
+
+
+def test_readme_startup(tmp_path):
+ # Run the real entry point with a clean environment and no host agent data.
+ env = {key: value for key, value in os.environ.items() if not key.startswith(
+ ("HERMES_", "AGENTS_", "POLL_", "ENABLE_SSE", "HOST", "PORT")
+ )}
+ env.update(HOST="127.0.0.1", PORT="0", AGENTS_JSON_PATH=str(tmp_path / "missing.json"))
+ process = subprocess.Popen(
+ [sys.executable, "-u", str(ROOT / "server.py")], cwd=tmp_path,
+ env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
+ )
+ try:
+ # Bound the startup wait even if the child never prints a URL.
+ import queue
+ lines = queue.Queue()
+ threading.Thread(target=lambda: lines.put(process.stdout.readline()), daemon=True).start()
+ line = lines.get(timeout=10)
+ port = int(line.strip().rsplit(":", 1)[1])
+ assert port > 0
+ assert request(port, "/api/config")[0] == 200
+ assert request(port, "/office.html")[0] == 200
+ finally:
+ process.terminate()
+ process.communicate(timeout=10)