@igorjpimenta/brayer 0.0.0-stage → 2026.10.28-beta.1
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.
- package/.migrations/0000_initial.sql +133 -0
- package/.migrations/0001_awesome_ben_parker.sql +8 -0
- package/.migrations/meta/0000_snapshot.json +931 -0
- package/.migrations/meta/0001_snapshot.json +983 -0
- package/.migrations/meta/_journal.json +20 -0
- package/LICENSE +21 -0
- package/README.md +245 -2
- package/bin/brayer.js +7 -0
- package/package.json +42 -4
- package/plugins/openclaw/brayer/index.js +119 -0
- package/plugins/openclaw/brayer/meta.js +23 -0
- package/plugins/openclaw/brayer/openclaw.plugin.json +14 -0
- package/plugins/openclaw/brayer/package.json +37 -0
- package/plugins/openclaw/brayer/session.js +30 -0
- package/plugins/openclaw/brayer/webhook.js +125 -0
- package/plugins/opencode/brayer/identity.js +11 -0
- package/plugins/opencode/brayer/index.js +92 -0
- package/plugins/opencode/brayer/package.json +27 -0
- package/plugins/opencode/brayer/session.js +25 -0
- package/plugins/shared/contract.js +193 -0
- package/plugins/wake/brayer/bin/brayer-wake.js +7 -0
- package/plugins/wake/brayer/index.js +125 -0
- package/plugins/wake/brayer/package.json +29 -0
- package/src/claim-webhook.js +66 -0
- package/src/cli.js +164 -0
- package/src/config.js +63 -0
- package/src/db.js +24 -0
- package/src/events-ws.js +121 -0
- package/src/evidence.js +42 -0
- package/src/identity.js +32 -0
- package/src/ids.js +17 -0
- package/src/mcp.js +114 -0
- package/src/schema.js +168 -0
- package/src/store/attempts.js +103 -0
- package/src/store/checkpoints.js +76 -0
- package/src/store/claims.js +139 -0
- package/src/store/events.js +24 -0
- package/src/store/evidence.js +67 -0
- package/src/store/orders.js +70 -0
- package/src/store/resume.js +38 -0
- package/src/store/rows.js +118 -0
- package/src/store/util.js +3 -0
- package/src/store/verdicts.js +61 -0
- package/src/store/webhooks.js +56 -0
- package/src/store.js +53 -0
- package/src/tools/attempts.js +75 -0
- package/src/tools/handoff.js +120 -0
- package/src/tools/index.js +28 -0
- package/src/tools/orders.js +146 -0
- package/src/tools/shared.js +7 -0
- package/src/tools/verdicts.js +46 -0
- package/src/version.js +5 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "7",
|
|
3
|
+
"dialect": "sqlite",
|
|
4
|
+
"entries": [
|
|
5
|
+
{
|
|
6
|
+
"idx": 0,
|
|
7
|
+
"version": "6",
|
|
8
|
+
"when": 1793122951186,
|
|
9
|
+
"tag": "0000_initial",
|
|
10
|
+
"breakpoints": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"idx": 1,
|
|
14
|
+
"version": "6",
|
|
15
|
+
"when": 1793201380906,
|
|
16
|
+
"tag": "0001_awesome_ben_parker",
|
|
17
|
+
"breakpoints": true
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Igor Pimenta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,246 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Brayer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Ink the work, not the transcript.**
|
|
4
|
+
|
|
5
|
+
Brayer is a vendor-neutral command layer for agent work. It records a work order,
|
|
6
|
+
the attempts made against it, the handoff checkpoint, the evidence returned, and
|
|
7
|
+
the verdict — so a fleet of coding agents can be supervised by exception instead
|
|
8
|
+
of by transcript.
|
|
9
|
+
|
|
10
|
+
## Why Brayer
|
|
11
|
+
|
|
12
|
+
A brayer is the printer's small hand roller that applies ink evenly to type. It
|
|
13
|
+
does not rewrite the page, and it does not keep the manuscript. It puts the ink
|
|
14
|
+
exactly where the work needs it.
|
|
15
|
+
|
|
16
|
+
Brayer does the same for agents. It applies context to the work — the order, the
|
|
17
|
+
checkpoint, the proof, the decision — instead of piling another transcript into
|
|
18
|
+
the context window.
|
|
19
|
+
|
|
20
|
+
The product is a command layer, not another agent:
|
|
21
|
+
|
|
22
|
+
- **Work order in** — goal, acceptance, workspace, budget, approval mode.
|
|
23
|
+
- **Handoff out** — a structured checkpoint with a tree hash, not a transcript.
|
|
24
|
+
- **Evidence attached** — diff, tests, screenshots, artifacts, all content-addressed.
|
|
25
|
+
- **Verdict recorded** — approve, reject, escalate or rollback, with an audit event.
|
|
26
|
+
- **Resume exact** — a leased attempt can die and continue in any harness without a re-brief.
|
|
27
|
+
|
|
28
|
+
## Who it is for
|
|
29
|
+
|
|
30
|
+
Technical operators who run several coding agents across repos and harnesses and
|
|
31
|
+
need to supervise by exception, not by reading every trace. It is local-first and
|
|
32
|
+
vendor-neutral: OpenCode, OpenClaw and future harnesses are adapters, not the
|
|
33
|
+
product. It is also planning-system agnostic: a work order is
|
|
34
|
+
self-contained, and no external planner task id is required.
|
|
35
|
+
|
|
36
|
+
## Status
|
|
37
|
+
|
|
38
|
+
Brayer is in active development. The MCP server, SQLite store, claim lease,
|
|
39
|
+
attempts, checkpoints, evidence, verdicts, resume, event stream, HTTP MCP,
|
|
40
|
+
claim webhooks and the OpenCode/OpenClaw identity plugins are implemented.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
Brayer is published to public npm:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
npm install -g @igorjpimenta/brayer@beta
|
|
48
|
+
brayer --version
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What works
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
# MCP over stdio for one harness
|
|
55
|
+
BRAYER_HARNESS=opencode brayer serve --mcp stdio
|
|
56
|
+
|
|
57
|
+
# MCP over HTTP with bearer auth
|
|
58
|
+
BRAYER_HARNESS=openclaw BRAYER_MCP_BEARER=secret \
|
|
59
|
+
brayer serve --mcp http --port 38293
|
|
60
|
+
|
|
61
|
+
# Event stream for dashboards and inboxes
|
|
62
|
+
brayer serve --ws --port 38294
|
|
63
|
+
|
|
64
|
+
# Read the queue
|
|
65
|
+
brayer status
|
|
66
|
+
brayer status --json
|
|
67
|
+
|
|
68
|
+
# Register a claim wake target
|
|
69
|
+
brayer webhook set --harness opencode \
|
|
70
|
+
--url http://127.0.0.1:38295/api/brayer/claimed --bearer secret
|
|
71
|
+
brayer webhook test --harness opencode
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The MCP tools are:
|
|
75
|
+
|
|
76
|
+
| Area | Tools |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| Orders | `brayer_order_create`, `brayer_order_get`, `brayer_order_next`, `brayer_order_claim`, `brayer_order_heartbeat`, `brayer_order_resume` |
|
|
79
|
+
| Attempts | `brayer_attempt_start`, `brayer_attempt_finish`, `brayer_attempt_get` |
|
|
80
|
+
| Handoff | `brayer_checkpoint_write`, `brayer_checkpoint_get` |
|
|
81
|
+
| Evidence | `brayer_evidence_attach`, `brayer_evidence_list` |
|
|
82
|
+
| Verdict | `brayer_verdict_issue`, `brayer_verdict_list` |
|
|
83
|
+
|
|
84
|
+
## Flows
|
|
85
|
+
|
|
86
|
+
### Order lifecycle
|
|
87
|
+
|
|
88
|
+
An order moves from ready through a claim and a running attempt to review. The
|
|
89
|
+
verdict decides where it lands, and resume returns rejected or blocked work to
|
|
90
|
+
ready.
|
|
91
|
+
|
|
92
|
+
```mermaid
|
|
93
|
+
flowchart LR
|
|
94
|
+
A[Order created] -->|status ready| B[Ready]
|
|
95
|
+
B -->|claim| C[Claimed]
|
|
96
|
+
C -->|attempt start| D[Running]
|
|
97
|
+
D -->|checkpoint / evidence| D
|
|
98
|
+
D -->|attempt finished| E[Review]
|
|
99
|
+
D -->|attempt failed| B
|
|
100
|
+
E -->|approve| F[Approved]
|
|
101
|
+
E -->|reject| G[Rejected]
|
|
102
|
+
E -->|escalate| H[Blocked]
|
|
103
|
+
G -->|resume| B
|
|
104
|
+
H -->|resume| B
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Claim and lease
|
|
108
|
+
|
|
109
|
+
An agent claims a ready order, then keeps the lease alive with heartbeats. An
|
|
110
|
+
expired lease returns to the queue or blocks at the attempt cap.
|
|
111
|
+
|
|
112
|
+
```mermaid
|
|
113
|
+
flowchart LR
|
|
114
|
+
Q[Ready order] -->|claimNext / claimById| L{Lease won?}
|
|
115
|
+
L -->|no| Q
|
|
116
|
+
L -->|yes| H[Claimed with lease]
|
|
117
|
+
H -->|heartbeat| H
|
|
118
|
+
H -->|lease expired| E{Attempt cap?}
|
|
119
|
+
E -->|no| Q
|
|
120
|
+
E -->|yes| X[Blocked]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Checkpoint and evidence
|
|
124
|
+
|
|
125
|
+
The store validates the attempt and the handoff or proof before it records the
|
|
126
|
+
row and emits the event.
|
|
127
|
+
|
|
128
|
+
```mermaid
|
|
129
|
+
flowchart LR
|
|
130
|
+
A[Running attempt] --> B{Belongs to order?}
|
|
131
|
+
B -->|no| R[Refuse]
|
|
132
|
+
B -->|yes| C{Valid state / tree hash / sha256?}
|
|
133
|
+
C -->|no| R
|
|
134
|
+
C -->|yes| D[Insert checkpoint or evidence]
|
|
135
|
+
D --> E[Emit event]
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Verdict and resume
|
|
139
|
+
|
|
140
|
+
A verdict closes review or blocked work. Reject and escalate remain resumable;
|
|
141
|
+
rollback returns the order to ready directly.
|
|
142
|
+
|
|
143
|
+
```mermaid
|
|
144
|
+
flowchart LR
|
|
145
|
+
A[Review or blocked] --> B{Decision}
|
|
146
|
+
B -->|approve| C[Approved]
|
|
147
|
+
B -->|reject| D[Rejected]
|
|
148
|
+
B -->|escalate| E[Blocked]
|
|
149
|
+
B -->|rollback| F[Ready]
|
|
150
|
+
D -->|resume| F
|
|
151
|
+
E -->|resume| F
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Storage
|
|
155
|
+
|
|
156
|
+
- SQLite at `BRAYER_DB` or `~/.brayer/store.sqlite`
|
|
157
|
+
- Content-addressed evidence at `BRAYER_BLOBS` or `~/.brayer/blobs/<sha256>`
|
|
158
|
+
- Drizzle migrations in `.migrations/`, applied on open
|
|
159
|
+
- WAL, foreign keys and a 5s busy timeout
|
|
160
|
+
|
|
161
|
+
## Configuration
|
|
162
|
+
|
|
163
|
+
Explicit config beats `BRAYER_*` env beats defaults. Integer knobs refuse
|
|
164
|
+
malformed values; unknown explicit keys refuse as typos.
|
|
165
|
+
|
|
166
|
+
| Knob | Env | Default |
|
|
167
|
+
| --- | --- | --- |
|
|
168
|
+
| Store | `BRAYER_DB` | `~/.brayer/store.sqlite` |
|
|
169
|
+
| Blobs | `BRAYER_BLOBS` | `~/.brayer/blobs` |
|
|
170
|
+
| Lease | `BRAYER_LEASE_SECONDS` | `1800` |
|
|
171
|
+
| Attempt cap | `BRAYER_MAX_ATTEMPTS` | `3` |
|
|
172
|
+
| HTTP port | `BRAYER_HTTP_PORT` | `38293` |
|
|
173
|
+
| WS port | `BRAYER_WS_PORT` | `38294` |
|
|
174
|
+
| HTTP MCP bearer | `BRAYER_MCP_BEARER` | required for HTTP |
|
|
175
|
+
| Claim webhook URL | `BRAYER_CLAIM_WEBHOOK_URL` | unset |
|
|
176
|
+
| Claim webhook bearer | `BRAYER_CLAIM_WEBHOOK_BEARER` | unset |
|
|
177
|
+
| Claim webhook timeout | `BRAYER_CLAIM_WEBHOOK_TIMEOUT_MS` | `3000` |
|
|
178
|
+
| Per-harness webhooks | `BRAYER_CLAIM_WEBHOOKS` | `{}` |
|
|
179
|
+
| Wake bridge port | `BRAYER_WAKE_PORT` | `38295` |
|
|
180
|
+
| Wake bridge bearer | `BRAYER_WAKE_BEARER` | unset |
|
|
181
|
+
| OpenCode server URL | `BRAYER_OPENCODE_URL` | `http://127.0.0.1:4096` |
|
|
182
|
+
|
|
183
|
+
## Identity
|
|
184
|
+
|
|
185
|
+
Every call is keyed `harness:agent:session`. The harness is declared at
|
|
186
|
+
construction (`BRAYER_HARNESS`); the agent and session are stamped per call via
|
|
187
|
+
`_meta.brayer` with `brayer_agent` / `brayer_session` as the fallback. Missing or
|
|
188
|
+
mismatched identity refuses the call.
|
|
189
|
+
|
|
190
|
+
## Harnesses
|
|
191
|
+
|
|
192
|
+
An adapter attaches an existing order; it never creates work.
|
|
193
|
+
|
|
194
|
+
**OpenClaw** — `@igorjpimenta/brayer-openclaw` stamps `_meta.brayer`, checkpoints
|
|
195
|
+
on turn end, resumes from the latest checkpoint, and receives claim webhooks at
|
|
196
|
+
`POST /api/brayer/claimed`.
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
{
|
|
200
|
+
"mcp": {
|
|
201
|
+
"servers": {
|
|
202
|
+
"brayer": {
|
|
203
|
+
"command": "brayer",
|
|
204
|
+
"args": ["serve", "--mcp", "stdio"],
|
|
205
|
+
"env": { "BRAYER_HARNESS": "openclaw" }
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**OpenCode** — `@igorjpimenta/brayer-opencode` stamps agent/session identity and
|
|
213
|
+
checkpoints on idle, compaction and error. It loads through the OpenCode plugin
|
|
214
|
+
config or a local `file://` entry.
|
|
215
|
+
|
|
216
|
+
**Wake bridge** — OpenCode has no plugin HTTP route, so `@igorjpimenta/brayer-wake`
|
|
217
|
+
receives the claim webhook and prompts the claiming session through the
|
|
218
|
+
OpenCode SDK.
|
|
219
|
+
|
|
220
|
+
## Docker
|
|
221
|
+
|
|
222
|
+
```sh
|
|
223
|
+
BRAYER_MCP_BEARER=secret docker compose up --build
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The image stores SQLite and blobs on the `brayer-data` volume at `/data`;
|
|
227
|
+
HTTP MCP is exposed on 38293 and the event stream on 38294.
|
|
228
|
+
|
|
229
|
+
## Release
|
|
230
|
+
|
|
231
|
+
Versions are CalVer (`YYYY.MM.DD-beta.N`). Tags are bare for core and prefixed
|
|
232
|
+
for adapters: `brayer-openclaw-<calver>`, `brayer-opencode-<calver>`,
|
|
233
|
+
`brayer-wake-<calver>`. Prereleases publish to `beta`; stable tags publish to
|
|
234
|
+
`latest`.
|
|
235
|
+
|
|
236
|
+
## Development
|
|
237
|
+
|
|
238
|
+
```sh
|
|
239
|
+
npm install
|
|
240
|
+
npm test
|
|
241
|
+
node bin/brayer.js --help
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
MIT
|
package/bin/brayer.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@igorjpimenta/brayer",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2026.10.28-beta.1",
|
|
4
|
+
"description": "Vendor-neutral command layer for agent work",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/igorjpimenta/brayer.git"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"registry": "https://registry.npmjs.org",
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/",
|
|
20
|
+
"src/",
|
|
21
|
+
"plugins/",
|
|
22
|
+
".migrations/",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"bin": {
|
|
26
|
+
"brayer": "bin/brayer.js"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"start": "node bin/brayer.js",
|
|
30
|
+
"test": "node --test \"test/unit/**/*.js\"",
|
|
31
|
+
"test:e2e": "node --test \"test/e2e/*.test.js\"",
|
|
32
|
+
"db:generate": "drizzle-kit generate",
|
|
33
|
+
"db:migrate": "drizzle-kit migrate"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
37
|
+
"better-sqlite3": "^13.0.3",
|
|
38
|
+
"drizzle-orm": "^0.45.4",
|
|
39
|
+
"zod": "^3.25 || ^4.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"drizzle-kit": "^0.31.11"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
2
|
+
import { createStore } from "@igorjpimenta/brayer/src/store.js";
|
|
3
|
+
import {
|
|
4
|
+
attachSession,
|
|
5
|
+
checkpointSession,
|
|
6
|
+
resumeSession,
|
|
7
|
+
} from "@igorjpimenta/brayer/plugins/shared/contract.js";
|
|
8
|
+
import { buildBrayerMeta } from "./meta.js";
|
|
9
|
+
import { checkpointPayload, resumeContext, sessionFromContext } from "./session.js";
|
|
10
|
+
import { registerClaimWebhook } from "./webhook.js";
|
|
11
|
+
|
|
12
|
+
export default definePluginEntry({
|
|
13
|
+
id: "brayer",
|
|
14
|
+
name: "Brayer",
|
|
15
|
+
description:
|
|
16
|
+
"Stamps _meta.brayer on Brayer MCP calls, checkpoints a configured order on turn end, and resumes its latest checkpoint.",
|
|
17
|
+
configSchema: () => ({
|
|
18
|
+
type: "object",
|
|
19
|
+
additionalProperties: true,
|
|
20
|
+
properties: {
|
|
21
|
+
orderId: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Existing Brayer order for this gateway. Required for automatic checkpoint/resume.",
|
|
24
|
+
},
|
|
25
|
+
dbPath: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Brayer SQLite path. Defaults to BRAYER_DB or ~/.brayer/store.sqlite.",
|
|
28
|
+
},
|
|
29
|
+
workspaceDir: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Workspace path used as the checkpoint tree pin.",
|
|
32
|
+
},
|
|
33
|
+
autoCheckpoint: {
|
|
34
|
+
type: "boolean",
|
|
35
|
+
description: "Checkpoint on turn end and session end. Default true when orderId is set.",
|
|
36
|
+
},
|
|
37
|
+
webhookBearer: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "Shared secret for POST /api/brayer/claimed. Route stays disarmed until set.",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
register: (api) => {
|
|
44
|
+
if (typeof api.on !== "function") {
|
|
45
|
+
api.logger.warn("brayer: api.on unavailable; hooks not registered");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
api.on("before_tool_call", (event, ctx) => buildBrayerMeta(event, ctx));
|
|
50
|
+
registerClaimWebhook({ api, logger: api.logger });
|
|
51
|
+
|
|
52
|
+
const cfg = api.pluginConfig ?? {};
|
|
53
|
+
const orderId = cfg.orderId ?? process.env.BRAYER_ORDER_ID ?? null;
|
|
54
|
+
if (!orderId || cfg.autoCheckpoint === false) return;
|
|
55
|
+
|
|
56
|
+
let store = null;
|
|
57
|
+
const getStore = () => {
|
|
58
|
+
if (!store) {
|
|
59
|
+
store = createStore({ dbPath: cfg.dbPath ?? process.env.BRAYER_DB ?? undefined });
|
|
60
|
+
}
|
|
61
|
+
return store;
|
|
62
|
+
};
|
|
63
|
+
const attach = (session) => attachSession({ store: getStore(), session, orderId });
|
|
64
|
+
|
|
65
|
+
api.on("agent_end", (event, ctx) => {
|
|
66
|
+
const session = sessionFromContext(event, ctx);
|
|
67
|
+
if (!session) return;
|
|
68
|
+
try {
|
|
69
|
+
const attached = attach(session);
|
|
70
|
+
const trigger = event?.success === false ? "error" : "idle";
|
|
71
|
+
const payload = checkpointPayload({ trigger, event, workspaceDir: ctx?.workspaceDir ?? cfg.workspaceDir });
|
|
72
|
+
checkpointSession({
|
|
73
|
+
store: getStore(),
|
|
74
|
+
session,
|
|
75
|
+
orderId,
|
|
76
|
+
attemptId: attached.attempt.id,
|
|
77
|
+
...payload,
|
|
78
|
+
});
|
|
79
|
+
} catch (err) {
|
|
80
|
+
api.logger.warn(`brayer: checkpoint failed: ${err?.message ?? err}`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
api.on("session_end", (event, ctx) => {
|
|
85
|
+
const session = sessionFromContext(event, ctx);
|
|
86
|
+
if (!session) return;
|
|
87
|
+
try {
|
|
88
|
+
const attached = attach(session);
|
|
89
|
+
const payload = checkpointPayload({ trigger: "stop", event, workspaceDir: ctx?.workspaceDir ?? cfg.workspaceDir });
|
|
90
|
+
checkpointSession({
|
|
91
|
+
store: getStore(),
|
|
92
|
+
session,
|
|
93
|
+
orderId,
|
|
94
|
+
attemptId: attached.attempt.id,
|
|
95
|
+
...payload,
|
|
96
|
+
});
|
|
97
|
+
} catch (err) {
|
|
98
|
+
api.logger.warn(`brayer: session checkpoint failed: ${err?.message ?? err}`);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
api.on("before_prompt_build", (event, ctx) => {
|
|
103
|
+
const session = sessionFromContext(event, ctx);
|
|
104
|
+
if (!session) return;
|
|
105
|
+
try {
|
|
106
|
+
const resumed = resumeSession({ store: getStore(), session, orderId });
|
|
107
|
+
const context = resumeContext(resumed.checkpoint);
|
|
108
|
+
if (context) return { prependContext: context };
|
|
109
|
+
} catch (err) {
|
|
110
|
+
api.logger.warn(`brayer: resume failed: ${err?.message ?? err}`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
api.on("gateway_stop", () => {
|
|
115
|
+
store?.close();
|
|
116
|
+
store = null;
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function isBrayerTool(name) {
|
|
2
|
+
return typeof name === "string" && name.includes("brayer");
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function buildBrayerMeta(event, ctx) {
|
|
6
|
+
const toolName = event?.toolName ?? ctx?.toolName;
|
|
7
|
+
if (!isBrayerTool(toolName)) return undefined;
|
|
8
|
+
|
|
9
|
+
const agent = ctx?.agentId ?? event?.agentId ?? null;
|
|
10
|
+
const session = ctx?.sessionKey ?? ctx?.sessionId ?? ctx?.runId ?? event?.sessionId ?? event?.runId ?? null;
|
|
11
|
+
if (agent === null && session === null) return undefined;
|
|
12
|
+
|
|
13
|
+
const params = event?.params ?? {};
|
|
14
|
+
return {
|
|
15
|
+
params: {
|
|
16
|
+
...params,
|
|
17
|
+
_meta: {
|
|
18
|
+
...(params._meta ?? {}),
|
|
19
|
+
brayer: { harness: "openclaw", agent, session },
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "brayer",
|
|
3
|
+
"name": "Brayer",
|
|
4
|
+
"description": "Stamps _meta.brayer (harness/agent/session) onto Brayer MCP tool calls.",
|
|
5
|
+
"enabledByDefault": true,
|
|
6
|
+
"activation": {
|
|
7
|
+
"onStartup": true
|
|
8
|
+
},
|
|
9
|
+
"configSchema": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"additionalProperties": true,
|
|
12
|
+
"properties": {}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@igorjpimenta/brayer-openclaw",
|
|
3
|
+
"version": "2026.10.28-beta.1",
|
|
4
|
+
"description": "OpenClaw companion for Brayer: stamps caller identity on Brayer MCP tool calls.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/igorjpimenta/brayer.git",
|
|
10
|
+
"directory": "plugins/openclaw/brayer"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org",
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"meta.js",
|
|
19
|
+
"session.js",
|
|
20
|
+
"webhook.js",
|
|
21
|
+
"openclaw.plugin.json"
|
|
22
|
+
],
|
|
23
|
+
"openclaw": {
|
|
24
|
+
"extensions": [
|
|
25
|
+
"./index.js"
|
|
26
|
+
],
|
|
27
|
+
"install": {
|
|
28
|
+
"minHostVersion": ">=2026.5.18"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"openclaw": ">=2026.5.18"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@igorjpimenta/brayer": "2026.10.28-beta.1"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function sessionFromContext(event, ctx) {
|
|
2
|
+
const agent = ctx?.agentId ?? event?.agentId ?? null;
|
|
3
|
+
const session = ctx?.sessionKey ?? ctx?.sessionId ?? ctx?.runId ?? event?.sessionId ?? event?.runId ?? null;
|
|
4
|
+
if (!agent || !session) return null;
|
|
5
|
+
return { harness: "openclaw", agent, session };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function checkpointPayload({ trigger, event, workspaceDir }) {
|
|
9
|
+
return {
|
|
10
|
+
trigger,
|
|
11
|
+
state: {
|
|
12
|
+
trigger,
|
|
13
|
+
success: event?.success ?? null,
|
|
14
|
+
messageCount: Array.isArray(event?.messages) ? event.messages.length : null,
|
|
15
|
+
durationMs: event?.durationMs ?? null,
|
|
16
|
+
},
|
|
17
|
+
treeHash: workspaceDir ?? "unknown",
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resumeContext(checkpoint) {
|
|
22
|
+
if (!checkpoint) return null;
|
|
23
|
+
return [
|
|
24
|
+
`Brayer checkpoint ${checkpoint.id} for this order.`,
|
|
25
|
+
`Summary: ${checkpoint.summary ?? "(none)"}`,
|
|
26
|
+
`Tree: ${checkpoint.treeHash ?? "(none)"}`,
|
|
27
|
+
`Resume: ${checkpoint.resumeRecipe ?? "(none)"}`,
|
|
28
|
+
`State: ${JSON.stringify(checkpoint.state ?? {})}`,
|
|
29
|
+
].join("\n");
|
|
30
|
+
}
|