@igorjpimenta/brayer 0.0.0-stage → 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.
Files changed (52) hide show
  1. package/.migrations/0000_initial.sql +133 -0
  2. package/.migrations/0001_awesome_ben_parker.sql +8 -0
  3. package/.migrations/meta/0000_snapshot.json +931 -0
  4. package/.migrations/meta/0001_snapshot.json +983 -0
  5. package/.migrations/meta/_journal.json +20 -0
  6. package/LICENSE +21 -0
  7. package/README.md +261 -2
  8. package/bin/brayer.js +7 -0
  9. package/package.json +43 -4
  10. package/plugins/openclaw/brayer/index.js +119 -0
  11. package/plugins/openclaw/brayer/meta.js +23 -0
  12. package/plugins/openclaw/brayer/openclaw.plugin.json +14 -0
  13. package/plugins/openclaw/brayer/package.json +37 -0
  14. package/plugins/openclaw/brayer/session.js +30 -0
  15. package/plugins/openclaw/brayer/webhook.js +125 -0
  16. package/plugins/opencode/brayer/hooks.js +17 -0
  17. package/plugins/opencode/brayer/identity.js +11 -0
  18. package/plugins/opencode/brayer/index.js +5 -0
  19. package/plugins/opencode/brayer/package.json +25 -0
  20. package/plugins/shared/contract.js +193 -0
  21. package/plugins/wake/brayer/bin/brayer-wake.js +7 -0
  22. package/plugins/wake/brayer/index.js +125 -0
  23. package/plugins/wake/brayer/package.json +29 -0
  24. package/src/claim-webhook.js +66 -0
  25. package/src/cli.js +164 -0
  26. package/src/config.js +63 -0
  27. package/src/db.js +24 -0
  28. package/src/events-ws.js +121 -0
  29. package/src/evidence.js +42 -0
  30. package/src/identity.js +32 -0
  31. package/src/ids.js +17 -0
  32. package/src/mcp.js +114 -0
  33. package/src/schema.js +168 -0
  34. package/src/store/attempts.js +104 -0
  35. package/src/store/checkpoints.js +76 -0
  36. package/src/store/claims.js +139 -0
  37. package/src/store/events.js +24 -0
  38. package/src/store/evidence.js +67 -0
  39. package/src/store/orders.js +70 -0
  40. package/src/store/resume.js +38 -0
  41. package/src/store/rows.js +118 -0
  42. package/src/store/util.js +3 -0
  43. package/src/store/verdicts.js +64 -0
  44. package/src/store/webhooks.js +56 -0
  45. package/src/store.js +53 -0
  46. package/src/tools/attempts.js +75 -0
  47. package/src/tools/handoff.js +120 -0
  48. package/src/tools/index.js +28 -0
  49. package/src/tools/orders.js +146 -0
  50. package/src/tools/shared.js +7 -0
  51. package/src/tools/verdicts.js +46 -0
  52. package/src/version.js +5 -0
@@ -0,0 +1,146 @@
1
+ import * as z from "zod/v4-mini";
2
+ import { identityKey } from "../identity.js";
3
+ import { identityShape } from "./shared.js";
4
+
5
+ export const orderDefs = [
6
+ {
7
+ name: "brayer_order_create",
8
+ description:
9
+ "Create a work order. The acceptance criteria are required: a worker must be able to verify completion without reading the planner's transcript.",
10
+ shape: {
11
+ ...identityShape,
12
+ title: z.string(),
13
+ goal: z.string(),
14
+ acceptance: z.string(),
15
+ constraints: z.optional(z.string()),
16
+ workspace: z.optional(z.string()),
17
+ repo: z.optional(z.string()),
18
+ branch: z.optional(z.string()),
19
+ priority: z.optional(z.int()),
20
+ status: z.optional(z.enum(["draft", "ready"])),
21
+ budgetTokens: z.optional(z.int()),
22
+ budgetUsd: z.optional(z.number()),
23
+ modelPolicy: z.optional(z.unknown()),
24
+ approvalMode: z.optional(z.enum(["auto", "evidence", "human"])),
25
+ parentId: z.optional(z.string()),
26
+ },
27
+ },
28
+ {
29
+ name: "brayer_order_next",
30
+ description:
31
+ "Atomically claim the highest-priority ready order for this agent. A race loser gets an empty result, never a partial claim.",
32
+ shape: {
33
+ ...identityShape,
34
+ leaseSeconds: z.optional(z.int()),
35
+ },
36
+ },
37
+ {
38
+ name: "brayer_order_claim",
39
+ description:
40
+ "Atomically claim one ready order by id. The order must be ready and unassigned, or assigned to this agent.",
41
+ shape: {
42
+ ...identityShape,
43
+ orderId: z.string(),
44
+ leaseSeconds: z.optional(z.int()),
45
+ },
46
+ },
47
+ {
48
+ name: "brayer_order_heartbeat",
49
+ description:
50
+ "Renew the lease on an order this agent holds. Returns null when the lease is no longer held.",
51
+ shape: {
52
+ ...identityShape,
53
+ orderId: z.string(),
54
+ leaseSeconds: z.optional(z.int()),
55
+ },
56
+ },
57
+ {
58
+ name: "brayer_order_resume",
59
+ description:
60
+ "Resume a rejected or blocked order. Returns the order and its latest checkpoint so the next attempt can continue without a re-brief.",
61
+ shape: {
62
+ ...identityShape,
63
+ orderId: z.string(),
64
+ reason: z.optional(z.string()),
65
+ },
66
+ },
67
+ {
68
+ name: "brayer_order_get",
69
+ description:
70
+ "Read a work order and its event trail. Read-only: it never claims, starts an attempt or changes state.",
71
+ shape: {
72
+ ...identityShape,
73
+ orderId: z.string(),
74
+ },
75
+ },
76
+ ];
77
+
78
+ export const orderHandlers = {
79
+ brayer_order_create({ store, args, identity }) {
80
+ const order = store.order.create({
81
+ title: args.title,
82
+ goal: args.goal,
83
+ acceptance: args.acceptance,
84
+ constraints: args.constraints ?? null,
85
+ workspace: args.workspace ?? null,
86
+ repo: args.repo ?? null,
87
+ branch: args.branch ?? null,
88
+ priority: args.priority ?? 50,
89
+ status: args.status ?? "draft",
90
+ budgetTokens: args.budgetTokens ?? null,
91
+ budgetUsd: args.budgetUsd ?? null,
92
+ modelPolicy: args.modelPolicy ?? null,
93
+ approvalMode: args.approvalMode ?? "human",
94
+ parentId: args.parentId ?? null,
95
+ actor: identityKey(identity),
96
+ });
97
+ return { order };
98
+ },
99
+
100
+ brayer_order_next({ store, args, identity }) {
101
+ return store.claim.claimNext({
102
+ agentId: identityKey(identity),
103
+ sessionRef: identity.session,
104
+ leaseSeconds: args.leaseSeconds,
105
+ });
106
+ },
107
+
108
+ brayer_order_claim({ store, args, identity }) {
109
+ return store.claim.claimById({
110
+ id: args.orderId,
111
+ agentId: identityKey(identity),
112
+ sessionRef: identity.session,
113
+ leaseSeconds: args.leaseSeconds,
114
+ });
115
+ },
116
+
117
+ brayer_order_heartbeat({ store, args, identity }) {
118
+ const order = store.claim.heartbeat({
119
+ id: args.orderId,
120
+ agentId: identityKey(identity),
121
+ sessionRef: identity.session,
122
+ leaseSeconds: args.leaseSeconds,
123
+ });
124
+ return { order };
125
+ },
126
+
127
+ brayer_order_resume({ store, args, identity }) {
128
+ return store.resume.resume({
129
+ workOrderId: args.orderId,
130
+ reason: args.reason ?? "resumed",
131
+ actor: identityKey(identity),
132
+ });
133
+ },
134
+
135
+ brayer_order_get({ store, args }) {
136
+ const order = store.order.get(args.orderId);
137
+ if (!order) throw new Error(`order not found: ${args.orderId}`);
138
+ return {
139
+ order,
140
+ events: store.event.list({ workOrderId: order.id }),
141
+ checkpoint: store.checkpoint.latest({ workOrderId: order.id }),
142
+ evidence: store.evidence.list({ workOrderId: order.id }),
143
+ verdicts: store.verdict.list({ workOrderId: order.id }),
144
+ };
145
+ },
146
+ };
@@ -0,0 +1,7 @@
1
+ import * as z from "zod/v4-mini";
2
+
3
+ export const identityShape = {
4
+ brayer_agent: z.optional(z.string()),
5
+ brayer_session: z.optional(z.string()),
6
+ _meta: z.optional(z.unknown()),
7
+ };
@@ -0,0 +1,46 @@
1
+ import * as z from "zod/v4-mini";
2
+ import { identityKey } from "../identity.js";
3
+ import { identityShape } from "./shared.js";
4
+
5
+ export const verdictDefs = [
6
+ {
7
+ name: "brayer_verdict_issue",
8
+ description:
9
+ "Record a verdict on an order in review or blocked. Approve requires at least one evidence row; escalate blocks the order; rollback returns it to the queue.",
10
+ shape: {
11
+ ...identityShape,
12
+ orderId: z.string(),
13
+ attemptId: z.optional(z.string()),
14
+ decision: z.enum(["approve", "reject", "escalate", "rollback"]),
15
+ reason: z.optional(z.string()),
16
+ policy: z.optional(z.string()),
17
+ evidenceIds: z.optional(z.array(z.string())),
18
+ },
19
+ },
20
+ {
21
+ name: "brayer_verdict_list",
22
+ description: "List verdicts for an order. Read-only.",
23
+ shape: {
24
+ ...identityShape,
25
+ orderId: z.string(),
26
+ },
27
+ },
28
+ ];
29
+
30
+ export const verdictHandlers = {
31
+ brayer_verdict_issue({ store, args, identity }) {
32
+ return store.verdict.issue({
33
+ workOrderId: args.orderId,
34
+ attemptId: args.attemptId ?? null,
35
+ decision: args.decision,
36
+ reason: args.reason ?? null,
37
+ policy: args.policy ?? null,
38
+ evidenceIds: args.evidenceIds ?? null,
39
+ actor: identityKey(identity),
40
+ });
41
+ },
42
+
43
+ brayer_verdict_list({ store, args }) {
44
+ return { verdicts: store.verdict.list({ workOrderId: args.orderId }) };
45
+ },
46
+ };
package/src/version.js ADDED
@@ -0,0 +1,5 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
4
+
5
+ export const VERSION = pkg.version;