@igorjpimenta/brayer-opencode 2026.10.28-beta.1 → 2026.10.28-beta.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 (4) hide show
  1. package/hooks.js +17 -0
  2. package/index.js +3 -90
  3. package/package.json +4 -7
  4. package/session.js +0 -25
package/hooks.js ADDED
@@ -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
+ }
package/index.js CHANGED
@@ -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
- };
package/package.json CHANGED
@@ -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.2",
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,7 @@
18
18
  },
19
19
  "files": [
20
20
  "index.js",
21
- "identity.js",
22
- "session.js"
23
- ],
24
- "dependencies": {
25
- "@igorjpimenta/brayer": "2026.10.28-beta.1"
26
- }
21
+ "hooks.js",
22
+ "identity.js"
23
+ ]
27
24
  }
package/session.js DELETED
@@ -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
- }