@igorjpimenta/brayer 2026.10.28-beta.1 → 2026.10.29-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/README.md CHANGED
@@ -209,9 +209,25 @@ on turn end, resumes from the latest checkpoint, and receives claim webhooks at
209
209
  }
210
210
  ```
211
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.
212
+ **OpenCode** — `@igorjpimenta/brayer-opencode` stamps agent/session identity on
213
+ Brayer MCP tool calls. It needs the Brayer MCP server configured and
214
+ `BRAYER_AGENT` when the session agent cannot be captured.
215
+
216
+ ```json
217
+ {
218
+ "mcp": {
219
+ "brayer": {
220
+ "type": "remote",
221
+ "url": "http://127.0.0.1:38293/mcp",
222
+ "headers": { "Authorization": "Bearer secret" }
223
+ }
224
+ },
225
+ "plugin": ["@igorjpimenta/brayer-opencode"]
226
+ }
227
+ ```
228
+
229
+ Automatic checkpoint/resume is not part of this release; the agent uses the
230
+ Brayer MCP tools directly.
215
231
 
216
232
  **Wake bridge** — OpenCode has no plugin HTTP route, so `@igorjpimenta/brayer-wake`
217
233
  receives the claim webhook and prompts the claiming session through the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igorjpimenta/brayer",
3
- "version": "2026.10.28-beta.1",
3
+ "version": "2026.10.29-beta.1",
4
4
  "description": "Vendor-neutral command layer for agent work",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,6 +29,7 @@
29
29
  "start": "node bin/brayer.js",
30
30
  "test": "node --test \"test/unit/**/*.js\"",
31
31
  "test:e2e": "node --test \"test/e2e/*.test.js\"",
32
+ "proof:opencode": "node scripts/proof-opencode.mjs",
32
33
  "db:generate": "drizzle-kit generate",
33
34
  "db:migrate": "drizzle-kit migrate"
34
35
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igorjpimenta/brayer-openclaw",
3
- "version": "2026.10.28-beta.1",
3
+ "version": "2026.10.29-beta.1",
4
4
  "description": "OpenClaw companion for Brayer: stamps caller identity on Brayer MCP tool calls.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,6 +32,6 @@
32
32
  "openclaw": ">=2026.5.18"
33
33
  },
34
34
  "dependencies": {
35
- "@igorjpimenta/brayer": "2026.10.28-beta.1"
35
+ "@igorjpimenta/brayer": "2026.10.29-beta.1"
36
36
  }
37
37
  }
@@ -0,0 +1,17 @@
1
+ import { stampBrayerIdentity } from "./identity.js";
2
+
3
+ export function createBrayerHooks() {
4
+ const agents = new Map();
5
+
6
+ return {
7
+ "chat.message": async (input) => {
8
+ if (input?.sessionID && input?.agent) agents.set(input.sessionID, input.agent);
9
+ },
10
+ "chat.params": async (input) => {
11
+ if (input?.sessionID && input?.agent) agents.set(input.sessionID, input.agent);
12
+ },
13
+ "tool.execute.before": async (input, output) => {
14
+ stampBrayerIdentity(input, output, { agent: agents.get(input?.sessionID) ?? process.env.BRAYER_AGENT });
15
+ },
16
+ };
17
+ }
@@ -1,92 +1,5 @@
1
- import { createStore } from "@igorjpimenta/brayer/src/store.js";
2
- import {
3
- attachSession,
4
- checkpointSession,
5
- resumeSession,
6
- } from "@igorjpimenta/brayer/plugins/shared/contract.js";
7
- import { stampBrayerIdentity } from "./identity.js";
8
- import { checkpointPayload, eventSessionID, resumeContext } from "./session.js";
1
+ import { createBrayerHooks } from "./hooks.js";
9
2
 
10
- export { isBrayerTool, stampBrayerIdentity } from "./identity.js";
11
-
12
- const TRIGGERS = {
13
- "session.idle": "idle",
14
- "session.compacted": "compaction",
15
- "session.error": "error",
16
- };
17
-
18
- export function createBrayerHooks({ store, orderId, worktree } = {}) {
19
- const agents = new Map();
20
- const resumed = new Set();
21
-
22
- const sessionFor = (sessionID) => {
23
- const agent = agents.get(sessionID);
24
- if (!agent || !sessionID) return null;
25
- return { harness: "opencode", agent, session: sessionID };
26
- };
27
-
28
- const hooks = {
29
- "chat.message": async (input) => {
30
- if (input?.sessionID && input?.agent) agents.set(input.sessionID, input.agent);
31
- },
32
- "tool.execute.before": async (input, output) => {
33
- stampBrayerIdentity(input, output, { agent: agents.get(input?.sessionID) });
34
- },
35
- dispose: async () => {
36
- store?.close();
37
- },
38
- };
39
-
40
- if (!store || !orderId) return hooks;
41
-
42
- hooks.event = async ({ event } = {}) => {
43
- const trigger = TRIGGERS[event?.type];
44
- if (!trigger) return;
45
- const sessionID = eventSessionID(event);
46
- const session = sessionFor(sessionID);
47
- if (!session) return;
48
- try {
49
- const attached = attachSession({ store, session, orderId });
50
- const payload = checkpointPayload({ trigger, event });
51
- checkpointSession({
52
- store,
53
- session,
54
- orderId,
55
- attemptId: attached.attempt.id,
56
- ...payload,
57
- treeHash: worktree ?? "unknown",
58
- });
59
- } catch {}
60
- };
61
-
62
- hooks["experimental.chat.system.transform"] = async (input, output) => {
63
- if (!input?.sessionID || resumed.has(input.sessionID)) return;
64
- const session = sessionFor(input.sessionID);
65
- if (!session) return;
66
- try {
67
- const resumed = resumeSession({ store, session, orderId });
68
- const context = resumeContext(resumed.checkpoint);
69
- if (context) {
70
- output.system.push(context);
71
- resumed.add(input.sessionID);
72
- }
73
- } catch {}
74
- };
75
-
76
- return hooks;
3
+ export default async function BrayerPlugin() {
4
+ return createBrayerHooks();
77
5
  }
78
-
79
- export default {
80
- id: "brayer",
81
- server: async (input, options = {}) => {
82
- const orderId = options.orderId ?? process.env.BRAYER_ORDER_ID ?? null;
83
- const store = orderId
84
- ? createStore({ dbPath: options.dbPath ?? process.env.BRAYER_DB ?? undefined })
85
- : null;
86
- return createBrayerHooks({
87
- store,
88
- orderId,
89
- worktree: options.worktree ?? input?.worktree ?? input?.directory,
90
- });
91
- },
92
- };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igorjpimenta/brayer-opencode",
3
- "version": "2026.10.28-beta.1",
3
+ "version": "2026.10.28-beta.3",
4
4
  "description": "OpenCode companion for Brayer: stamps agent and session identity on Brayer tool calls.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,10 +18,8 @@
18
18
  },
19
19
  "files": [
20
20
  "index.js",
21
- "identity.js",
22
- "session.js"
21
+ "hooks.js",
22
+ "identity.js"
23
23
  ],
24
- "dependencies": {
25
- "@igorjpimenta/brayer": "2026.10.28-beta.1"
26
- }
24
+ "main": "index.js"
27
25
  }
@@ -70,12 +70,13 @@ export function createAttemptApi({ db, insertEvent, orderApi }) {
70
70
  if (!attempt) { db.exec("ROLLBACK"); return { attempt: null, order: null, reason: "not_found" }; }
71
71
  if (attempt.status !== "running") { db.exec("ROLLBACK"); return { attempt, order: orderApi.get(attempt.workOrderId), reason: "not_running" }; }
72
72
 
73
+ const nextCheckpointId = checkpointId ?? attempt.checkpointId;
73
74
  db.prepare(`
74
75
  UPDATE attempts
75
76
  SET status=?, ended_at=?, tokens_in=?, tokens_out=?, cache_read=?, cost_usd=?,
76
77
  tool_calls=?, error=?, checkpoint_id=?
77
78
  WHERE id=? AND status='running'
78
- `).run(status, t, tokensIn, tokensOut, cacheRead, costUsd, toolCalls, error, checkpointId, attemptId);
79
+ `).run(status, t, tokensIn, tokensOut, cacheRead, costUsd, toolCalls, error, nextCheckpointId, attemptId);
79
80
 
80
81
  const order = orderApi.get(attempt.workOrderId);
81
82
  const nextStatus = status === "finished" ? "review" : "ready";
@@ -33,6 +33,9 @@ export function createVerdictApi({ db, insertEvent, orderApi, evidenceApi }) {
33
33
  if (decision === "approve" && evidenceApi.list({ workOrderId }).length === 0) {
34
34
  throw new Error("approve requires at least one evidence row");
35
35
  }
36
+ const resolvedAttemptId = attemptId ?? db.prepare(
37
+ "SELECT id FROM attempts WHERE work_order_id=? ORDER BY started_at DESC LIMIT 1"
38
+ ).get(workOrderId)?.id ?? null;
36
39
 
37
40
  const nextStatus = decision === "approve" ? "approved"
38
41
  : decision === "reject" ? "rejected"
@@ -42,10 +45,10 @@ export function createVerdictApi({ db, insertEvent, orderApi, evidenceApi }) {
42
45
  db.prepare(`
43
46
  INSERT INTO verdicts(id, work_order_id, attempt_id, decision, reason, actor, policy, evidence_ids, created_at)
44
47
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
45
- `).run(id, workOrderId, attemptId, decision, reason, actor, policy, jsonOut(evidenceIds), t);
48
+ `).run(id, workOrderId, resolvedAttemptId, decision, reason, actor, policy, jsonOut(evidenceIds), t);
46
49
  db.prepare("UPDATE work_orders SET status=?, updated_at=? WHERE id=?").run(nextStatus, t, workOrderId);
47
50
  insertEvent({
48
- workOrderId, attemptId, fromStatus: order.status, toStatus: nextStatus, kind: "verdict.issued",
51
+ workOrderId, attemptId: resolvedAttemptId, fromStatus: order.status, toStatus: nextStatus, kind: "verdict.issued",
49
52
  actor, note: reason ?? decision, at: t,
50
53
  });
51
54
  db.exec("COMMIT");
@@ -1,25 +0,0 @@
1
- export function eventSessionID(event) {
2
- return event?.properties?.sessionID ?? event?.properties?.info?.id ?? null;
3
- }
4
-
5
- export function checkpointPayload({ trigger, event }) {
6
- return {
7
- trigger,
8
- state: {
9
- trigger,
10
- eventType: event?.type ?? null,
11
- error: event?.properties?.error?.message ?? null,
12
- },
13
- };
14
- }
15
-
16
- export function resumeContext(checkpoint) {
17
- if (!checkpoint) return null;
18
- return [
19
- `Brayer checkpoint ${checkpoint.id} for this order.`,
20
- `Summary: ${checkpoint.summary ?? "(none)"}`,
21
- `Tree: ${checkpoint.treeHash ?? "(none)"}`,
22
- `Resume: ${checkpoint.resumeRecipe ?? "(none)"}`,
23
- `State: ${JSON.stringify(checkpoint.state ?? {})}`,
24
- ].join("\n");
25
- }