@versdotsh/reef 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.github/workflows/test.yml +47 -0
  2. package/README.md +257 -0
  3. package/bun.lock +587 -0
  4. package/examples/services/board/board.test.ts +215 -0
  5. package/examples/services/board/index.ts +155 -0
  6. package/examples/services/board/routes.ts +335 -0
  7. package/examples/services/board/store.ts +329 -0
  8. package/examples/services/board/tools.ts +214 -0
  9. package/examples/services/commits/commits.test.ts +74 -0
  10. package/examples/services/commits/index.ts +14 -0
  11. package/examples/services/commits/routes.ts +43 -0
  12. package/examples/services/commits/store.ts +114 -0
  13. package/examples/services/feed/behaviors.ts +23 -0
  14. package/examples/services/feed/feed.test.ts +101 -0
  15. package/examples/services/feed/index.ts +117 -0
  16. package/examples/services/feed/routes.ts +224 -0
  17. package/examples/services/feed/store.ts +194 -0
  18. package/examples/services/feed/tools.ts +83 -0
  19. package/examples/services/journal/index.ts +15 -0
  20. package/examples/services/journal/journal.test.ts +57 -0
  21. package/examples/services/journal/routes.ts +45 -0
  22. package/examples/services/journal/store.ts +119 -0
  23. package/examples/services/journal/tools.ts +32 -0
  24. package/examples/services/log/index.ts +15 -0
  25. package/examples/services/log/log.test.ts +70 -0
  26. package/examples/services/log/routes.ts +44 -0
  27. package/examples/services/log/store.ts +105 -0
  28. package/examples/services/log/tools.ts +57 -0
  29. package/examples/services/registry/behaviors.ts +128 -0
  30. package/examples/services/registry/index.ts +37 -0
  31. package/examples/services/registry/registry.test.ts +135 -0
  32. package/examples/services/registry/routes.ts +76 -0
  33. package/examples/services/registry/store.ts +224 -0
  34. package/examples/services/registry/tools.ts +116 -0
  35. package/examples/services/reports/index.ts +14 -0
  36. package/examples/services/reports/reports.test.ts +75 -0
  37. package/examples/services/reports/routes.ts +42 -0
  38. package/examples/services/reports/store.ts +110 -0
  39. package/examples/services/ui/auth.ts +61 -0
  40. package/examples/services/ui/index.ts +16 -0
  41. package/examples/services/ui/routes.ts +160 -0
  42. package/examples/services/ui/static/app.js +369 -0
  43. package/examples/services/ui/static/index.html +42 -0
  44. package/examples/services/ui/static/style.css +157 -0
  45. package/examples/services/usage/behaviors.ts +166 -0
  46. package/examples/services/usage/index.ts +19 -0
  47. package/examples/services/usage/routes.ts +53 -0
  48. package/examples/services/usage/store.ts +341 -0
  49. package/examples/services/usage/tools.ts +75 -0
  50. package/examples/services/usage/usage.test.ts +91 -0
  51. package/package.json +29 -0
  52. package/services/agent/index.ts +465 -0
  53. package/services/board/index.ts +155 -0
  54. package/services/board/routes.ts +335 -0
  55. package/services/board/store.ts +329 -0
  56. package/services/board/tools.ts +214 -0
  57. package/services/docs/index.ts +391 -0
  58. package/services/feed/behaviors.ts +23 -0
  59. package/services/feed/index.ts +117 -0
  60. package/services/feed/routes.ts +224 -0
  61. package/services/feed/store.ts +194 -0
  62. package/services/feed/tools.ts +83 -0
  63. package/services/installer/index.ts +574 -0
  64. package/services/services/index.ts +165 -0
  65. package/services/ui/auth.ts +61 -0
  66. package/services/ui/index.ts +16 -0
  67. package/services/ui/routes.ts +160 -0
  68. package/services/ui/static/app.js +369 -0
  69. package/services/ui/static/index.html +42 -0
  70. package/services/ui/static/style.css +157 -0
  71. package/skills/create-service/SKILL.md +698 -0
  72. package/src/core/auth.ts +28 -0
  73. package/src/core/client.ts +99 -0
  74. package/src/core/discover.ts +152 -0
  75. package/src/core/events.ts +44 -0
  76. package/src/core/extension.ts +66 -0
  77. package/src/core/server.ts +262 -0
  78. package/src/core/testing.ts +155 -0
  79. package/src/core/types.ts +194 -0
  80. package/src/extension.ts +16 -0
  81. package/src/main.ts +11 -0
  82. package/tests/server.test.ts +1338 -0
  83. package/tsconfig.json +29 -0
@@ -0,0 +1,47 @@
1
+ name: test & publish
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ id-token: write
11
+ contents: read
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - uses: oven-sh/setup-bun@v2
21
+ with:
22
+ bun-version: latest
23
+
24
+ - run: bun install
25
+
26
+ - run: bun test
27
+
28
+ publish:
29
+ needs: test
30
+ runs-on: ubuntu-latest
31
+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
32
+
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+
36
+ - uses: actions/setup-node@v4
37
+ with:
38
+ node-version: "24"
39
+ registry-url: "https://registry.npmjs.org"
40
+
41
+ - uses: oven-sh/setup-bun@v2
42
+ with:
43
+ bun-version: latest
44
+
45
+ - run: bun install
46
+
47
+ - run: npm publish --access public
package/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # reef
2
+
3
+ Self-improving fleet infrastructure. The minimum kernel agents need to build their own tools.
4
+
5
+ Reef is a plugin-based server where every capability is a service module — a folder with an `index.ts`. Modules are discovered at startup, dispatched dynamically, and can be added, updated, or removed at runtime without restarting. Even the module manager and installer are service modules. Nothing is required. Everything is replaceable.
6
+
7
+ ## Quickstart
8
+
9
+ ```bash
10
+ bun install
11
+
12
+ export VERS_AUTH_TOKEN=your-secret-token
13
+
14
+ bun run start
15
+ ```
16
+
17
+ Out of the box, reef starts with four service modules:
18
+
19
+ ```
20
+ services:
21
+ /agent — Run tasks using pi as the coding agent
22
+ /docs — Auto-generated API documentation
23
+ /installer — Install, update, and remove service modules
24
+ /services — Service module manager
25
+
26
+ reef running on :3000
27
+ ```
28
+
29
+ These give you an agent loop, runtime management, installation, and API docs. They're not special — they're regular service modules that happen to ship in `services/`. You can remove them and replace them with whatever you want.
30
+
31
+ ### Agent setup
32
+
33
+ The agent service spawns [pi](https://github.com/badlogic/pi-mono) to execute tasks. Install pi and the Vers extension so agents get fleet tools:
34
+
35
+ ```bash
36
+ npm install -g @mariozechner/pi-coding-agent
37
+ pi install hdresearch/pi-vers
38
+ ```
39
+
40
+ The agent service provides two modes:
41
+ - **Fire-and-forget tasks** — `POST /agent/tasks` for automation
42
+ - **Interactive chat** — `GET /agent/ui?token=YOUR_TOKEN` for a web-based chat interface
43
+
44
+ The chat UI connects to pi via RPC mode with full streaming — you see text, tool calls, and results in real-time.
45
+
46
+ ### Adding the example services
47
+
48
+ Reef ships with a set of fleet coordination services in `examples/services/`. To use them, copy the ones you want:
49
+
50
+ ```bash
51
+ # Copy everything
52
+ cp -r examples/services/* services/
53
+
54
+ # Or pick what you need
55
+ cp -r examples/services/board services/
56
+ cp -r examples/services/feed services/
57
+ cp -r examples/services/log services/
58
+ ```
59
+
60
+ Then reload:
61
+
62
+ ```bash
63
+ curl -X POST localhost:3000/services/reload \
64
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN"
65
+ ```
66
+
67
+ No restart needed.
68
+
69
+ | Example service | Description |
70
+ |-----------------|-------------|
71
+ | **board** | Shared task tracking with status workflow |
72
+ | **feed** | Activity event stream across the fleet |
73
+ | **log** | Append-only structured work log |
74
+ | **journal** | Personal narrative log per agent |
75
+ | **registry** | VM service discovery and heartbeats |
76
+ | **usage** | Cost and token tracking |
77
+ | **commits** | VM snapshot ledger |
78
+ | **reports** | Markdown report storage |
79
+ | **ui** | Web dashboard |
80
+
81
+ These are one fleet's solution to one fleet's problem. Use them as-is, modify them, or throw them away and build your own.
82
+
83
+ ## How it works
84
+
85
+ The server's only job is discovery, dispatch, and lifecycle. Everything else is a plugin.
86
+
87
+ ```
88
+ services/
89
+ your-service/
90
+ index.ts → /your-service/*
91
+ ```
92
+
93
+ Each module exports a `ServiceModule` with routes, an optional store, and optional metadata:
94
+
95
+ ```ts
96
+ import { Hono } from "hono";
97
+ import type { ServiceModule } from "../src/core/types.js";
98
+
99
+ const routes = new Hono();
100
+ routes.get("/", (c) => c.json({ hello: "world" }));
101
+ routes.post("/", async (c) => {
102
+ const body = await c.req.json();
103
+ return c.json({ created: body }, 201);
104
+ });
105
+
106
+ const myService: ServiceModule = {
107
+ name: "my-service",
108
+ description: "Does something useful",
109
+ routes,
110
+ };
111
+
112
+ export default myService;
113
+ ```
114
+
115
+ Drop that in `services/my-service/index.ts`, reload, and it's live at `/my-service`.
116
+
117
+ ## Runtime management
118
+
119
+ The services manager module provides an API for managing modules without restarting.
120
+
121
+ ```bash
122
+ # Re-scan — picks up new, changed, and deleted modules
123
+ curl -X POST localhost:3000/services/reload \
124
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN"
125
+
126
+ # Reload a specific module
127
+ curl -X POST localhost:3000/services/reload/my-service \
128
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN"
129
+
130
+ # Unload a module
131
+ curl -X DELETE localhost:3000/services/my-service \
132
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN"
133
+
134
+ # Export a module as a tarball
135
+ curl localhost:3000/services/export/my-service \
136
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN" > my-service.tar.gz
137
+ ```
138
+
139
+ ## Installing services
140
+
141
+ The installer module handles git repos, local paths, and other reef instances.
142
+
143
+ ```bash
144
+ # From GitHub (shorthand, HTTPS, or SSH)
145
+ curl -X POST localhost:3000/installer/install \
146
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN" \
147
+ -H "Content-Type: application/json" \
148
+ -d '{"source": "user/repo"}'
149
+
150
+ # From a local path (creates a symlink)
151
+ curl -X POST localhost:3000/installer/install \
152
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN" \
153
+ -H "Content-Type: application/json" \
154
+ -d '{"source": "/path/to/my-service"}'
155
+
156
+ # From another reef instance
157
+ curl -X POST localhost:3000/installer/install \
158
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN" \
159
+ -H "Content-Type: application/json" \
160
+ -d '{"from": "http://other-reef:3000", "name": "their-service", "token": "their-token"}'
161
+ ```
162
+
163
+ Git source formats:
164
+
165
+ | Format | Example |
166
+ |--------|---------|
167
+ | GitHub shorthand | `user/repo` |
168
+ | With ref | `user/repo@v1.0` |
169
+ | HTTPS | `https://github.com/user/repo` |
170
+ | SSH | `git@github.com:user/repo` |
171
+ | Bare host | `gitlab.com/team/repo` |
172
+
173
+ ```bash
174
+ # Update (git pull or re-pull from remote)
175
+ curl -X POST localhost:3000/installer/update \
176
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN" \
177
+ -H "Content-Type: application/json" \
178
+ -d '{"name": "repo-name"}'
179
+
180
+ # Remove (unload + delete)
181
+ curl -X POST localhost:3000/installer/remove \
182
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN" \
183
+ -H "Content-Type: application/json" \
184
+ -d '{"name": "repo-name"}'
185
+
186
+ # List externally installed packages
187
+ curl localhost:3000/installer/installed \
188
+ -H "Authorization: Bearer $VERS_AUTH_TOKEN"
189
+ ```
190
+
191
+ ## Auto-generated docs
192
+
193
+ The docs module documents every loaded service automatically. Modules can add rich descriptions via `routeDocs`.
194
+
195
+ ```bash
196
+ # All services
197
+ curl localhost:3000/docs
198
+
199
+ # Specific service
200
+ curl localhost:3000/docs/board
201
+
202
+ # HTML UI (no auth required)
203
+ open http://localhost:3000/docs/ui
204
+ ```
205
+
206
+ ## Error handling
207
+
208
+ One bad module can't take down the server.
209
+
210
+ | Failure | What happens |
211
+ |---------|--------------|
212
+ | Import fails | Module skipped, others load normally |
213
+ | `init()` throws | Module removed from registry, others keep running |
214
+ | Route handler throws | Returns `500 { error: "internal service error" }` |
215
+ | Runtime `loadModule()` fails | Rolled back — no half-initialized state |
216
+
217
+ ## pi extension
218
+
219
+ Reef is also a [pi](https://github.com/badlogic/pi-mono) package. Install it and agents get LLM tools for every service that defines them:
220
+
221
+ ```bash
222
+ pi install /path/to/reef
223
+ ```
224
+
225
+ Modules can contribute:
226
+ - **Tools** — LLM-callable functions (`registerTools`)
227
+ - **Behaviors** — automatic event handlers (`registerBehaviors`)
228
+ - **Widget lines** — status bar contributions (`widget`)
229
+
230
+ Modules without client-side code are automatically excluded from the extension.
231
+
232
+ ## Creating a service
233
+
234
+ Reef ships with a `create-service` skill at `skills/create-service/SKILL.md` that covers the full pattern — stores, routes, tools, behaviors, route documentation, and testing. If you have reef installed as a pi package, the skill is available to agents automatically.
235
+
236
+ The short version:
237
+
238
+ ```
239
+ services/your-service/
240
+ index.ts — Module definition (required, default-exports ServiceModule)
241
+ store.ts — Data layer (JSON file, JSONL, or SQLite)
242
+ routes.ts — HTTP routes (Hono)
243
+ tools.ts — LLM tools (pi extension)
244
+ behaviors.ts — Event handlers and timers (pi extension)
245
+ ```
246
+
247
+ ## Tests
248
+
249
+ ```bash
250
+ bun test
251
+ ```
252
+
253
+ 60 tests covering discovery, dispatch, auth, error handling, service context, runtime management, installation (local, git, fleet-to-fleet), and source parsing.
254
+
255
+ ## Requirements
256
+
257
+ - [Bun](https://bun.sh)