@igorjpimenta/brayer-opencode 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/identity.js ADDED
@@ -0,0 +1,11 @@
1
+ export function isBrayerTool(name) {
2
+ return typeof name === "string" && name.includes("brayer");
3
+ }
4
+
5
+ export function stampBrayerIdentity(input, output, { agent = null } = {}) {
6
+ if (!isBrayerTool(input?.tool)) return false;
7
+ output.args = output.args ?? {};
8
+ if (!output.args.brayer_agent && agent) output.args.brayer_agent = agent;
9
+ if (!output.args.brayer_session) output.args.brayer_session = input.sessionID;
10
+ return true;
11
+ }
package/index.js ADDED
@@ -0,0 +1,92 @@
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";
9
+
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;
77
+ }
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,27 @@
1
1
  {
2
2
  "name": "@igorjpimenta/brayer-opencode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2026.10.28-beta.1",
4
+ "description": "OpenCode companion for Brayer: stamps agent and session identity on Brayer 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/opencode/brayer"
11
+ },
12
+ "publishConfig": {
13
+ "registry": "https://registry.npmjs.org",
14
+ "access": "public"
15
+ },
16
+ "exports": {
17
+ ".": "./index.js"
18
+ },
19
+ "files": [
20
+ "index.js",
21
+ "identity.js",
22
+ "session.js"
23
+ ],
24
+ "dependencies": {
25
+ "@igorjpimenta/brayer": "2026.10.28-beta.1"
26
+ }
27
+ }
package/session.js ADDED
@@ -0,0 +1,25 @@
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
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.