mo commited on
Commit
1d3594f
·
1 Parent(s): a9876bc

docs: examples and integrations — boot units, health check, automation recipes

Browse files
README.md CHANGED
@@ -134,8 +134,11 @@ More answers: **[docs/FAQ.md](docs/FAQ.md)**
134
  | [docs/GETTING-STARTED.md](docs/GETTING-STARTED.md) | Install, login, first steps, troubleshooting |
135
  | [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Daemon internals, control channel, metrics pipeline |
136
  | [docs/TOOLS.md](docs/TOOLS.md) | Tool-by-tool reference with examples |
 
 
137
  | [docs/FAQ.md](docs/FAQ.md) | Frequently asked questions |
138
  | [docs/CHANGELOG.md](docs/CHANGELOG.md) | Release history |
 
139
  | [SECURITY.md](SECURITY.md) | Security model & vulnerability reporting |
140
  | [CONTRIBUTING.md](CONTRIBUTING.md) | Development setup, tests, conventions |
141
 
 
134
  | [docs/GETTING-STARTED.md](docs/GETTING-STARTED.md) | Install, login, first steps, troubleshooting |
135
  | [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Daemon internals, control channel, metrics pipeline |
136
  | [docs/TOOLS.md](docs/TOOLS.md) | Tool-by-tool reference with examples |
137
+ | [docs/EXAMPLES.md](docs/EXAMPLES.md) | Automation recipes — cron, watchdogs, backups |
138
+ | [docs/INTEGRATIONS.md](docs/INTEGRATIONS.md) | Cloud API, scheduling, boot persistence |
139
  | [docs/FAQ.md](docs/FAQ.md) | Frequently asked questions |
140
  | [docs/CHANGELOG.md](docs/CHANGELOG.md) | Release history |
141
+ | [examples/](examples) | launchd & systemd units, health check script |
142
  | [SECURITY.md](SECURITY.md) | Security model & vulnerability reporting |
143
  | [CONTRIBUTING.md](CONTRIBUTING.md) | Development setup, tests, conventions |
144
 
docs/EXAMPLES.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Examples & Recipes
2
+
3
+ Real things people do with mona-agent. Copy, adapt, enjoy.
4
+
5
+ ## Check on your machine from your phone
6
+
7
+ 1. `mona-agent start` on the machine (or install the launchd/systemd unit
8
+ from [examples/](../examples)).
9
+ 2. Open <https://agent.mona.expert/dashboard> on your phone.
10
+ 3. Chat: *"How's the disk looking?"* — the agent reads `df -h`, and the
11
+ dashboard shows live CPU/memory sparklines.
12
+
13
+ ## Morning briefing with cron
14
+
15
+ Get a daily summary of your home server in your dashboard before coffee:
16
+
17
+ ```cron
18
+ # ~/.config/cron.d/mona (or: crontab -e)
19
+ 30 7 * * * $HOME/.local/bin/mona-agent chat "Summarize disk usage, uptime and any failed systemd units."
20
+ ```
21
+
22
+ The reply lands in the dashboard chat history, timestamped.
23
+
24
+ ## Watchdog — alert when a service dies
25
+
26
+ Ask the agent every 10 minutes; it pings the service and only reports
27
+ problems (the cloud keeps the conversation context):
28
+
29
+ ```cron
30
+ */10 * * * * $HOME/.local/bin/mona-agent chat "Check nginx is answering on :80. Only reply if something is wrong."
31
+ ```
32
+
33
+ ## Nightly log cleanup
34
+
35
+ ```cron
36
+ 10 3 * * * $HOME/.local/bin/mona-agent exec "find ~/logs -name '*.log' -mtime +14 -delete && echo cleaned"
37
+ ```
38
+
39
+ ## Health check from any shell
40
+
41
+ ```bash
42
+ mona-agent connect # force a connection test: health, auth, agents
43
+ ```
44
+
45
+ `connect` reports cloud reachability, key validity and the agent list —
46
+ ideal for install verification and support tickets.
47
+
48
+ ## Drive a script from the dashboard
49
+
50
+ Anything you can put in a script, the agent can run it for you:
51
+
52
+ ```bash
53
+ #!/usr/bin/env bash
54
+ # backup.sh — daily offsite backup, called from the dashboard chat
55
+ tar czf - ~/projects | gpg -c --batch --passphrase-file ~/.backup-pass -o /mnt/backup/projects.tgz.gpg
56
+ ```
57
+
58
+ Say *"run backup.sh"* in the chat; the guarded shell executes it and
59
+ streams the result back to your browser.
60
+
61
+ ## Headless Raspberry Pi companion
62
+
63
+ The agent runs on any Node.js 20+ box:
64
+
65
+ ```bash
66
+ curl -fsSL https://agent.mona.expert/install.sh | bash
67
+ mona-agent login
68
+ mona-agent start # survives reboots via the systemd unit in examples/
69
+ ```
70
+
71
+ Then manage the Pi from the dashboard: temperature, storage, running
72
+ services — with live metrics and chat.
73
+
74
+ ## More
75
+
76
+ - [INTEGRATIONS.md](INTEGRATIONS.md) — the cloud REST API and scheduling
77
+ - [TOOLS.md](TOOLS.md) — the built-in tool sandbox
78
+ - [examples/](../examples) — launchd & systemd units, health check script
docs/INTEGRATIONS.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Integrations
2
+
3
+ mona-agent is designed to be glued into whatever you already run.
4
+
5
+ ## Cloud REST API (client view)
6
+
7
+ The daemon talks to the control plane at `https://agent.mona.expert` over
8
+ HTTPS with Bearer auth. From a client perspective the endpoints are:
9
+
10
+ | Method | Path | Purpose |
11
+ |---|---|---|
12
+ | GET | `/api/v1/agent/health` | Cloud health / uptime check |
13
+ | GET | `/api/v1/agent/verify` | Validate the device token |
14
+ | POST | `/api/v1/agent/chat/:agentId` | Send a chat message, get a reply |
15
+ | POST | `/api/v1/agent/tool/:agentId` | Execute a tool directly |
16
+ | GET | `/api/v1/agent/agents` | List your agents |
17
+ | POST | `/api/v1/agent/think` | Streaming reasoning (SSE) |
18
+ | POST | `/api/v1/agent/stats` | Device metrics snapshot (every 10 s) |
19
+
20
+ The client picks the right base URL and paths automatically
21
+ (`MONA_CLOUD` overrides the default).
22
+
23
+ ## Boot persistence
24
+
25
+ Keep the daemon alive across reboots:
26
+
27
+ - **macOS** — install [examples/macos/com.monaexpert.agent.plist](../examples/macos/com.monaexpert.agent.plist)
28
+ into `~/Library/LaunchAgents/` and `launchctl load` it.
29
+ - **Linux (systemd)** — drop [examples/linux/mona-agent.service](../examples/linux/mona-agent.service)
30
+ into `~/.config/systemd/user/` and `systemctl --user enable --now mona-agent`.
31
+ - **cron fallback** — `@reboot $HOME/.local/bin/mona-agent start`
32
+
33
+ ## Scheduling
34
+
35
+ The agent plays nicely with cron (see [EXAMPLES.md](EXAMPLES.md) for
36
+ recipes). One-liners:
37
+
38
+ ```bash
39
+ mona-agent chat "…" # ask the cloud brain, answer in dashboard history
40
+ mona-agent exec "…" # run a guarded command, stream the output
41
+ ```
42
+
43
+ ## Health checks
44
+
45
+ - **Interactive** — `mona-agent connect` runs the full connectivity test
46
+ (health, auth, agent list) and prints the result.
47
+ - **Scripted** — parse `mona-agent connect` exit code in your monitoring:
48
+
49
+ ```bash
50
+ if mona-agent connect; then echo "agent ok"; else echo "agent degraded"; fi
51
+ ```
52
+
53
+ ## Webhooks & outbound calls
54
+
55
+ The `net` tool lets the agent call your webhooks, health endpoints or
56
+ notification services (outbound HTTPS only):
57
+
58
+ ```bash
59
+ mona-agent exec "curl -fsS https://hc-ping.com/<your-uuid>"
60
+ ```
61
+
62
+ ## Building on the client
63
+
64
+ - `packages/engine` — the cloud-brain client (self-contained)
65
+ - `packages/protocol` — typed message schemas shared with the cloud
66
+
67
+ Both are MIT licensed; reuse them freely.
docs/index.md CHANGED
@@ -5,10 +5,13 @@ Open-source cloud-brained AI agent for your device — macOS, Linux, WSL2.
5
  - [Getting started](GETTING-STARTED.md) — install in 60 seconds
6
  - [Architecture](ARCHITECTURE.md) — how the daemon works
7
  - [Tools reference](TOOLS.md) — files, shell, net, sysinfo
 
 
8
  - [FAQ](FAQ.md) — common questions
9
  - [Changelog](CHANGELOG.md) — release history
10
  - [Security](../SECURITY.md) — security model & disclosure
11
  - [Contributing](../CONTRIBUTING.md) — development setup
 
12
 
13
  **Cloud:** [agent.mona.expert](https://agent.mona.expert) ·
14
  **Repo:** [MONAEXPERT/agent](https://github.com/MONAEXPERT/agent)
 
5
  - [Getting started](GETTING-STARTED.md) — install in 60 seconds
6
  - [Architecture](ARCHITECTURE.md) — how the daemon works
7
  - [Tools reference](TOOLS.md) — files, shell, net, sysinfo
8
+ - [Examples & recipes](EXAMPLES.md) — cron jobs, watchdogs, backups
9
+ - [Integrations](INTEGRATIONS.md) — cloud API, scheduling, boot persistence
10
  - [FAQ](FAQ.md) — common questions
11
  - [Changelog](CHANGELOG.md) — release history
12
  - [Security](../SECURITY.md) — security model & disclosure
13
  - [Contributing](../CONTRIBUTING.md) — development setup
14
+ - [examples/](../examples) — launchd & systemd units, health check script
15
 
16
  **Cloud:** [agent.mona.expert](https://agent.mona.expert) ·
17
  **Repo:** [MONAEXPERT/agent](https://github.com/MONAEXPERT/agent)
examples/README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Examples
2
+
3
+ Copy-paste helpers for running mona-agent in production.
4
+
5
+ | Directory | Contents |
6
+ |---|---|
7
+ | [macos/](macos) | LaunchAgent plist — auto-start on login, keep-alive |
8
+ | [linux/](linux) | systemd user unit — boot persistence with auto-restart |
9
+ | [scripts/](scripts) | `healthcheck.sh` — end-to-end install verification |
10
+
11
+ More recipes: [../docs/EXAMPLES.md](../docs/EXAMPLES.md)
examples/linux/README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Run mona-agent as a systemd user service on Linux
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ mkdir -p ~/.config/systemd/user
7
+ cp mona-agent.service ~/.config/systemd/user/
8
+ systemctl --user daemon-reload
9
+ systemctl --user enable --now mona-agent
10
+ ```
11
+
12
+ ## Useful commands
13
+
14
+ ```bash
15
+ systemctl --user status mona-agent # running? recent log lines
16
+ journalctl --user -u mona-agent -f # follow the log
17
+ systemctl --user restart mona-agent # restart after updates
18
+ ```
19
+
20
+ ## Uninstall
21
+
22
+ ```bash
23
+ systemctl --user disable --now mona-agent
24
+ rm ~/.config/systemd/user/mona-agent.service
25
+ ```
26
+
27
+ Requires `mona-agent` on your PATH (`~/.local/bin`, set by the installer)
28
+ and a systemd user session (standard on desktop distros).
examples/linux/mona-agent.service ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [Unit]
2
+ Description=mona-agent — cloud-brained AI agent for this device
3
+ After=network-online.target
4
+ Wants=network-online.target
5
+
6
+ [Service]
7
+ Type=simple
8
+ ExecStart=%h/.local/bin/mona-agent start
9
+ Restart=on-failure
10
+ RestartSec=10
11
+
12
+ [Install]
13
+ WantedBy=default.target
examples/macos/README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Run mona-agent automatically on macOS
2
+
3
+ Install this LaunchAgent to start mona-agent when you log in and keep it
4
+ running (auto-restart on crash).
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ mkdir -p ~/Library/LaunchAgents
10
+ cp com.monaexpert.agent.plist ~/Library/LaunchAgents/
11
+ launchctl load ~/Library/LaunchAgents/com.monaexpert.agent.plist
12
+ ```
13
+
14
+ ## Verify
15
+
16
+ ```bash
17
+ launchctl list | grep monaexpert
18
+ mona-agent connect # should report cloud reachable, key valid
19
+ ```
20
+
21
+ ## Uninstall
22
+
23
+ ```bash
24
+ launchctl unload ~/Library/LaunchAgents/com.monaexpert.agent.plist
25
+ rm ~/Library/LaunchAgents/com.monaexpert.agent.plist
26
+ ```
27
+
28
+ Requires `mona-agent` on your PATH (`~/.local/bin`, set by the installer).
examples/macos/com.monaexpert.agent.plist ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <!-- mona-agent LaunchAgent — keeps the device agent running on login -->
4
+ <plist version="1.0">
5
+ <dict>
6
+ <key>Label</key>
7
+ <string>com.monaexpert.agent</string>
8
+
9
+ <key>ProgramArguments</key>
10
+ <array>
11
+ <string>/bin/zsh</string>
12
+ <string>-c</string>
13
+ <string>exec $HOME/.local/bin/mona-agent start</string>
14
+ </array>
15
+
16
+ <key>RunAtLoad</key>
17
+ <true/>
18
+
19
+ <key>KeepAlive</key>
20
+ <true/>
21
+
22
+ <!-- Logs: ~/Library/Logs/mona-agent.log -->
23
+ <key>StandardOutPath</key>
24
+ <string>/tmp/mona-agent.log</string>
25
+ <key>StandardErrorPath</key>
26
+ <string>/tmp/mona-agent.log</string>
27
+ </dict>
28
+ </plist>
examples/scripts/healthcheck.sh ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # healthcheck.sh — verify a mona-agent installation end to end.
3
+ # Usage: bash healthcheck.sh (exit 0 = ok, 1 = problem found)
4
+ set -u
5
+
6
+ RED='\033[31m'; GREEN='\033[32m'; RESET='\033[0m'
7
+ fail=0
8
+
9
+ say() { printf '%s\n' "$*"; }
10
+ ok() { printf " ${GREEN}ok${RESET} %s\n" "$*"; }
11
+ bad() { printf " ${RED}bad${RESET} %s\n" "$*"; fail=1; }
12
+
13
+ say "mona-agent health check"
14
+
15
+ # 1. Binary on PATH
16
+ if command -v mona-agent >/dev/null 2>&1; then
17
+ ok "mona-agent on PATH ($(command -v mona-agent))"
18
+ else
19
+ bad "mona-agent not on PATH — run the installer: curl -fsSL https://agent.mona.expert/install.sh | bash"
20
+ exit 1
21
+ fi
22
+
23
+ # 2. Node.js version
24
+ if node -v 2>/dev/null | grep -qE '^v(2[0-9]|[3-9][0-9])\.'; then
25
+ ok "Node.js $(node -v)"
26
+ else
27
+ bad "Node.js 20+ required (found: $(node -v 2>/dev/null || echo none))"
28
+ fi
29
+
30
+ # 3. Credentials present
31
+ if [ -f "$HOME/.mona-agent/credentials.json" ]; then
32
+ ok "credentials.json present"
33
+ else
34
+ bad "not logged in — run: mona-agent login"
35
+ fi
36
+
37
+ # 4. Process running
38
+ if pgrep -f "mona-agent.*(start|gui)" >/dev/null 2>&1; then
39
+ ok "daemon process running (pid $(pgrep -f "mona-agent.*(start|gui)" | head -1))"
40
+ else
41
+ bad "daemon not running — start with: mona-agent start"
42
+ fi
43
+
44
+ # 5. Cloud connectivity + key validity
45
+ if mona-agent connect >/tmp/mona-health.$$.log 2>&1; then
46
+ ok "cloud connection ok (health, auth, agents)"
47
+ else
48
+ bad "cloud connection failed:"
49
+ sed 's/^/ /' /tmp/mona-health.$$.log | tail -8
50
+ fi
51
+ rm -f /tmp/mona-health.$$.log
52
+
53
+ say ""
54
+ if [ "$fail" -eq 0 ]; then
55
+ say "${GREEN}All checks passed.${RESET}"
56
+ else
57
+ say "${RED}Some checks failed — see above.${RESET}"
58
+ fi
59
+ exit "$fail"