Skip to content

Commit 3899682

Browse files
committed
docs(generate-user-docs): add hub-and-spokes deployment structure and ops-pattern import
Restructure skill to produce guides/deploying/ as a hub plus six spokes (local-development, single-server, public-access, upgrading, backup-and-restore, monitoring) instead of one flat deploy guide. Add an "operational guide" template (When to Run → Pre-flight → Procedure → Verify → Rollback) for procedural docs that don't fit the feature-shaped dual-audience template, plus verbatim-reuse snippets for the load-bearing rules: never down/up, rebuild platform services only, six-probe verification, resource-thresholds table, alpine cp backup. Add Step 2h to draw operational patterns from the private ops runbook under ../trinity-ops/, with explicit safe/forbidden import lists and a sshpass→localhost rewrite rule. Strengthen Step 2e to cross-check .env.example keys against each compose's environment block — docs must not promise behavior the chosen compose can't deliver. Add public-safety greps in Step 7 (sshpass, trinity-ops, tailnet, real IPs, instance-dir refs) so leaked private detail blocks completion. Tracks issue #504.
1 parent 7bc481a commit 3899682

1 file changed

Lines changed: 198 additions & 7 deletions

File tree

  • .claude/skills/generate-user-docs

‎.claude/skills/generate-user-docs/SKILL.md‎

Lines changed: 198 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ Read backend routers, frontend views, feature flows, and recent changes to produ
3030
| Feature flow index | `docs/memory/feature-flows.md` | Yes | No |
3131
| Requirements | `docs/memory/requirements.md` | Yes | No |
3232
| Architecture | `docs/memory/architecture.md` | Yes | No |
33-
| Deployment config | `.env.example`, `scripts/deploy/*.sh`, `docker-compose.yml` | Yes | No |
33+
| Deployment config | `.env.example`, `scripts/deploy/*.sh`, `docker-compose.yml`, `docker-compose.prod.yml`, `deploy.config.example` | Yes | No |
3434
| Trinity Docs site | `../trinity-docs/app/getting-started/*.tsx` | Yes | No |
3535
| Abilities repo | `github.com/abilityai/abilities` (README) | Yes | No |
36+
| Ops runbook (private, pattern source for ops content) | `../trinity-ops/playbooks/*.md`, `../trinity-ops/instances/_template/scripts/*.sh`, `../trinity-ops/instances/_template/CLAUDE.md` | Yes | No |
3637
| Git history | `git log --since` | Yes | No |
3738
| Existing user docs | `docs/user-docs/**/*.md` | Yes | Yes |
3839

@@ -47,19 +48,34 @@ These tutorial-style guides walk users through end-to-end tasks. Keep them in sy
4748

4849
| Guide | Source | Purpose |
4950
|-------|--------|---------|
50-
| `guides/deploying-trinity.md` | `trinity-docs/app/getting-started/deploying-trinity/page.tsx` | Cloud vs self-hosted setup |
51+
| `guides/deploying-trinity.md` | `trinity-docs/app/getting-started/deploying-trinity/page.tsx` + this skill's deploy hub rules | Hub: cloud vs self-hosted decision, prerequisites, links into spokes |
52+
| `guides/deploying/local-development.md` | `docker-compose.yml`, `scripts/deploy/start.sh`, `.env.example` | Docker Desktop, dev compose, hot reload, base image build |
53+
| `guides/deploying/single-server.md` | `docker-compose.prod.yml`, `deploy.config.example`, `.env.example` | VPS/bare-metal: prod compose, env, base image, email, Redis password, host paths |
54+
| `guides/deploying/public-access.md` | `docker-compose.prod.yml` (cloudflared profile), `.env.example` (TUNNEL_TOKEN, PUBLIC_CHAT_URL) | Cloudflare Tunnel, public webhook surface, DNS |
55+
| `guides/deploying/upgrading.md` | This skill's operational template + ops runbook patterns | Pre-flight → backup → pull → rebuild platform services → restart → verify → rollback |
56+
| `guides/deploying/backup-and-restore.md` | This skill's operational template + ops runbook patterns | Volume-mounted alpine `cp` pattern, retention, daily cron template |
57+
| `guides/deploying/monitoring.md` | This skill's operational template + ops runbook patterns + `/api/ops/fleet/health` router | Six health probes, fleet-health API, resource thresholds table, common-recovery patterns |
5158
| `guides/using-trinity.md` | `trinity-docs/app/getting-started/using-trinity/page.tsx` | UI tour: dashboard, agents, monitoring |
5259
| `guides/building-agents.md` | `trinity-docs/app/getting-started/building-agents/page.tsx` | Create, develop, deploy with abilities |
5360

5461
**Sync rule**: When the trinity-docs source changes, update the corresponding guide to match. Convert TSX to markdown, preserving structure and content. **Code wins on conflict** — if trinity-docs disagrees with `.env.example`, `scripts/deploy/*.sh`, or `docker-compose.yml`, fix the local guide to match observed repo behavior and note the divergence for upstream.
5562

63+
**Ops-runbook rule**: Pages under `guides/deploying/` (especially `upgrading.md`, `backup-and-restore.md`, `monitoring.md`) draw their *patterns* from the private ops runbook at `../trinity-ops/`. Treat that as a pattern library, not a paste source. See Step 2h for what's safe to import vs. what must stay private.
64+
5665
## Target Structure
5766

5867
```
5968
docs/user-docs/
6069
├── README.md # Index + navigation
6170
├── guides/ # Tutorial-style walkthroughs
62-
│ ├── deploying-trinity.md # Cloud vs self-hosted setup
71+
│ ├── deploying-trinity.md # Hub: cloud vs self-hosted decision, links into spokes
72+
│ ├── deploying/ # Self-hosted deployment spokes (per-scenario + ops)
73+
│ │ ├── local-development.md # Docker Desktop, dev compose, hot reload, base image
74+
│ │ ├── single-server.md # VPS/bare-metal: prod compose, env, email, backups
75+
│ │ ├── public-access.md # Cloudflare Tunnel, PUBLIC_CHAT_URL, webhook surface
76+
│ │ ├── upgrading.md # Pre-flight → backup → rebuild → restart → verify → rollback
77+
│ │ ├── backup-and-restore.md # Volume-mounted alpine cp, retention, daily cron
78+
│ │ └── monitoring.md # Six health probes, /api/ops/fleet/health, thresholds
6379
│ ├── using-trinity.md # UI tour: dashboard, agents, monitoring
6480
│ └── building-agents.md # Create, develop, deploy with abilities
6581
├── getting-started/
@@ -140,7 +156,7 @@ git log --oneline --since="2 weeks ago" | head -30
140156
```
141157
This identifies what has changed recently and which docs may need updating.
142158

143-
**2e. Deployment config (for deploying/setup guides)** — Read `.env.example`, `scripts/deploy/start.sh`, `scripts/deploy/stop.sh`, and `docker-compose.yml`. Extract: required env vars, auto-generated vs user-set secrets, default ports and override vars (e.g., `FRONTEND_PORT`), first-boot behavior, and what the start/stop scripts actually print and do. This is the authoritative source for deploy/setup docs.
159+
**2e. Deployment config (for deploying/setup guides)** — Read `.env.example`, `scripts/deploy/start.sh`, `scripts/deploy/stop.sh`, `scripts/deploy/build-base-image.sh`, `docker-compose.yml`, `docker-compose.prod.yml`, `docker-compose.gitea.yml`, and `deploy.config.example`. Extract: required env vars, auto-generated vs user-set secrets, default ports and override vars (e.g., `FRONTEND_PORT`), first-boot behavior, and what the start/stop scripts actually print and do. **Cross-check `.env.example` keys against the `environment:` blocks in each compose file** — flag any key present in `.env.example` but not forwarded by a given compose as "prod-only / overlay-only / requires compose edit," because docs should not promise behavior the chosen compose can't deliver. This is the authoritative source for deploy/setup docs.
144160

145161
**2f. Backend routers** — Glob `src/backend/routers/*.py` and read router files relevant to the section being written. Extract:
146162
- Endpoint paths and HTTP methods
@@ -152,6 +168,29 @@ This identifies what has changed recently and which docs may need updating.
152168
- User-facing labels and actions
153169
- State management patterns
154170

171+
**2h. Ops-runbook patterns (for `guides/deploying/upgrading.md`, `backup-and-restore.md`, `monitoring.md`)** — Read `../trinity-ops/playbooks/upgrade-instance.md`, `../trinity-ops/playbooks/monitoring-instance.md`, `../trinity-ops/instances/_template/CLAUDE.md`, and the helper scripts in `../trinity-ops/instances/_template/scripts/` (`update.sh`, `health-check.sh`, `restart.sh`, `status.sh`). Treat as a **pattern library**, not a paste source.
172+
173+
**Safe to import (the rules and shapes that make production work):**
174+
- The "use `docker compose restart`, never `down/up`" rule and *why* (preserves agent containers and `trinity-agent-network`).
175+
- The "rebuild only platform services, not the base image" rule (`docker compose build --no-cache backend frontend mcp-server scheduler`).
176+
- The pre-flight → backup → pull → rebuild → restart → verify → rollback sequence shape.
177+
- The six-probe verification list (backend `/health`, scheduler `:8001/health`, frontend HTTP 200, redis PONG, MCP `/health`, Vector `:8686/health`).
178+
- The fleet-status API surface (`/api/ops/fleet/health`, `/api/ops/fleet/status`).
179+
- The resource-thresholds table (warning/critical bands for context %, CPU, memory, disk, error rate, container restarts, DB size, log size).
180+
- The volume-mounted alpine `cp` pattern for SQLite backup/restore.
181+
- Common-recovery patterns (agent network not found, agent context >90%, database locked).
182+
- The daily-DB-backup + 14-day-retention cron template.
183+
184+
**Forbidden to import (private detail; would leak in a public repo):**
185+
- Any host name, IP address, Tailscale identity, or tailnet name.
186+
- Any `sshpass`, `ssh -i`, or `ssh user@host`-prefixed command — local-host examples only.
187+
- Any reference to specific instance directories (`instances/dgx/` etc.) or instance-specific scripts.
188+
- Any password, token, or API-key value (even masked) from ops `.env` files.
189+
- The phrase "trinity-ops" itself, or any path that reveals the private repo's structure.
190+
- Multi-instance management workflows (`source .env && ./scripts/run.sh ...`) — that's an operator-fleet pattern, not a single-instance user pattern.
191+
192+
When in doubt, rewrite the *idea* in localhost form. A production-ops `sshpass -p $PW ssh user@host "sudo docker logs trinity-backend"` becomes the public `docker logs trinity-backend`. The rule survives; the access pattern stays private.
193+
155194
### Step 3: Generate/Update Documentation
156195

157196
For each section in the target structure, produce or update the markdown file following these rules:
@@ -208,6 +247,137 @@ Only include if meaningful.]
208247

209248
Use judgment: if the same content keeps needing to sit awkwardly inside "How It Works" or "Limitations," promote it to its own `##` section.
210249

250+
#### Operational guide template (use for `guides/deploying/upgrading.md`, `backup-and-restore.md`, `monitoring.md`)
251+
252+
The dual-audience template above is for *features*. Operational guides are *procedures with checkpoints* — different shape. Use this instead:
253+
254+
```markdown
255+
# [Procedure Name]
256+
257+
[1-2 sentence summary: what this procedure achieves and when an operator runs it.]
258+
259+
## When to Run This
260+
261+
[Trigger conditions. E.g. "Before every Trinity update," "Daily as a cron job,"
262+
"When the dashboard sync-health dot goes red." Concrete, not aspirational.]
263+
264+
## Pre-flight
265+
266+
- [ ] [Check 1 — e.g., backup target has space]
267+
- [ ] [Check 2 — e.g., no scheduled tasks running in the next N minutes]
268+
- [ ] [Check 3 — e.g., on the right branch / version]
269+
270+
## Procedure
271+
272+
### Step 1: [name]
273+
274+
[What and why. Then the command in a code block. Then "expected output: ..."]
275+
276+
### Step 2: [name]
277+
...
278+
279+
## Verify
280+
281+
After the procedure, confirm each of these returns the expected result. If any
282+
fails, do NOT proceed — go to **Rollback** or **Recovery** below.
283+
284+
| Check | Command | Expected |
285+
|-------|---------|----------|
286+
| Backend | `curl -s http://localhost:8000/health` | `{"status":"healthy",...}` |
287+
| ... | ... | ... |
288+
289+
## Rollback / Recovery
290+
291+
[For procedures with destructive or risky steps, include the inverse procedure.
292+
For monitoring guides, include common-issue resolution table instead.]
293+
294+
## Automation
295+
296+
[Optional: cron template, CI hook, or scheduling guidance if the procedure is
297+
intended to run regularly.]
298+
299+
## See Also
300+
```
301+
302+
**Why this shape:** operators care about (1) when to run, (2) safety pre-checks, (3) numbered steps, (4) explicit verification, (5) rollback. The feature template's "How It Works / For Agents / Limitations" doesn't map to any of those.
303+
304+
#### Reusable snippets for operational guides
305+
306+
The following are canonical snippets. Use verbatim across the deploy spokes so the same rule reads identically in every place. Do **not** paraphrase; consistency is the point.
307+
308+
**The "use restart, never down/up" rule:**
309+
310+
> **Use `docker compose restart`, not `down/up`.** `docker compose down` removes the `trinity-agent-network`, which orphans every running agent container — they keep running but lose their network and have to be removed and recreated. `restart` preserves both the agents and the network. The only times to use `down` are: (1) intentional full teardown, (2) recovering from a corrupted compose state.
311+
312+
**The "rebuild platform services only" rule:**
313+
314+
> When updating Trinity code, rebuild the platform images only:
315+
> ```bash
316+
> docker compose build --no-cache backend frontend mcp-server scheduler
317+
> ```
318+
> The `trinity-agent-base` image is **not** rebuilt by this command. It changes much less often, and rebuilding it forces every agent to be re-deployed. Rebuild it only when `docker/base-image/Dockerfile` itself changes, via `./scripts/deploy/build-base-image.sh`.
319+
320+
**The six-probe verification list:**
321+
322+
```bash
323+
# 1. Backend
324+
curl -s http://localhost:8000/health
325+
# Expected: {"status":"healthy",...}
326+
327+
# 2. Scheduler
328+
curl -s http://localhost:8001/health
329+
# Expected: {"status":"healthy","active_schedules":N}
330+
331+
# 3. Frontend (HTTP 200)
332+
curl -s -o /dev/null -w '%{http_code}' http://localhost
333+
# Expected: 200
334+
335+
# 4. Redis
336+
docker exec trinity-redis redis-cli ping
337+
# Expected: PONG
338+
339+
# 5. MCP Server
340+
curl -s http://localhost:8080/health
341+
# Expected: 200 OK
342+
343+
# 6. Vector (log aggregation)
344+
docker exec trinity-vector wget -q -O - http://localhost:8686/health
345+
# Expected: non-empty response
346+
```
347+
348+
**Resource thresholds table:**
349+
350+
| Metric | Warning | Critical | Action |
351+
|---|---|---|---|
352+
| Backend `/health` | — | not 200 | Restart `trinity-backend` |
353+
| Scheduler `/health` | — | not 200 | Restart `trinity-scheduler` |
354+
| Agent context usage | >75% | >90% | Reset agent context or restart agent container |
355+
| Host CPU | >80% | >95% | Investigate runaway processes |
356+
| Host memory | >85% | >95% | Check container memory limits |
357+
| Disk free | <20% | <5% | Prune Docker, archive logs |
358+
| Error rate (per hour) | >10 | >50 | Inspect platform.json log |
359+
| Container restarts | any | repeated | `docker logs <container>` |
360+
| `trinity.db` size | >1 GB | >5 GB | Archive old data |
361+
| Vector log size | >5 GB | >10 GB | Trigger archival rotation |
362+
363+
**SQLite backup pattern (volume-mounted alpine):**
364+
365+
```bash
366+
# Backup (run on the host, with services running)
367+
docker run --rm \
368+
-v trinity_trinity-data:/data \
369+
-v ~/backups:/backup \
370+
alpine cp /data/trinity.db /backup/trinity-$(date +%Y%m%d-%H%M%S).db
371+
372+
# Restore (services stopped first)
373+
docker compose stop backend scheduler
374+
docker run --rm \
375+
-v trinity_trinity-data:/data \
376+
-v ~/backups:/backup \
377+
alpine cp /backup/trinity-YYYYMMDD-HHMMSS.db /data/trinity.db
378+
docker compose start backend scheduler
379+
```
380+
211381
3. **No redundancy** — Do not repeat information from other docs. Cross-reference instead. The `Concepts` section in `getting-started/overview.md` is the canonical glossary; other docs reference it rather than re-defining terms.
212382

213383
4. **Code-derived accuracy** — Every claim must trace to code or a feature flow. Do not invent features. If a feature flow says "planned" or a router has TODO comments, note it as upcoming rather than documenting it as available.
@@ -263,25 +433,46 @@ Create directories and write all approved files:
263433

264434
```bash
265435
mkdir -p docs/user-docs/{getting-started,agents,credentials,collaboration,automation,operations,sharing-and-access,integrations,advanced,api-reference}
436+
mkdir -p docs/user-docs/guides/deploying
266437
```
267438

268439
Write each markdown file using the Write or Edit tool.
269440

270441
### Step 7: Verify
271442

443+
**Count files written:**
444+
272445
```bash
273446
find docs/user-docs -name "*.md" -type f | wc -l
274447
```
275448

449+
**Public-safety scan** — every page generated under `guides/deploying/` must pass these greps with zero hits. If any hit, the page is leaking ops-internal detail and must be rewritten:
450+
451+
```bash
452+
# Tokens that indicate private-repo or operator-fleet patterns
453+
grep -rE 'sshpass|trinity-ops|tailnet|ts\.net|ssh -i [^ ]+ [^ ]+@' docs/user-docs/guides/deploying/
454+
455+
# Real IPs (allow only loopback and the documented agent subnet 172.28.0.0/16)
456+
grep -rE '\b(10|192\.168|172\.(1[6-9]|2[0-9]|3[01]))\.[0-9]+\.[0-9]+' docs/user-docs/guides/deploying/ \
457+
| grep -vE '172\.28\.0\.[0-9]+/16'
458+
459+
# Instance directory references that hint at private-repo structure
460+
grep -rE 'instances/[a-z0-9_-]+/' docs/user-docs/guides/deploying/
461+
```
462+
276463
Confirm the expected number of files were created/updated. Report the final count.
277464

278465
## Completion Checklist
279466

280-
- [ ] All sections in target structure have corresponding files
281-
- [ ] Every doc follows the dual-audience template (How It Works + For Agents)
467+
- [ ] All sections in target structure have corresponding files (including `guides/deploying/` spokes)
468+
- [ ] Every feature doc follows the dual-audience template (How It Works + For Agents)
469+
- [ ] Every operational doc under `guides/deploying/` follows the operational template (When to Run → Pre-flight → Procedure → Verify → Rollback)
282470
- [ ] No redundant explanations across docs (MECE verified)
283471
- [ ] All API references link to Swagger (`/docs`) rather than duplicating schemas
284-
- [ ] No real credentials, internal URLs, or PII in any doc
472+
- [ ] Every key in `.env.example` is annotated in the relevant deploy spoke as: dev-compose / prod-compose-only / overlay-only / requires-compose-edit (no key promised to work in a compose that doesn't forward it)
473+
- [ ] Reusable snippets (the "use restart" rule, "rebuild platform services only" rule, six-probe verification, thresholds table, alpine `cp` backup pattern) are used verbatim, not paraphrased, across deploy spokes
474+
- [ ] No real credentials, internal URLs, host IPs, or PII in any doc
475+
- [ ] Public-safety greps from Step 7 return zero hits across `guides/deploying/`
285476
- [ ] README.md index is complete and links are valid
286477
- [ ] Changes reviewed by user before writing
287478

0 commit comments

Comments
 (0)