@shobyde/boaz 0.0.0-stage → 0.8.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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +422 -2
  3. package/dist/build/codes.d.ts +16 -0
  4. package/dist/build/codes.d.ts.map +1 -0
  5. package/dist/build/codes.js +72 -0
  6. package/dist/build/codes.js.map +1 -0
  7. package/dist/build/extract.d.ts +45 -0
  8. package/dist/build/extract.d.ts.map +1 -0
  9. package/dist/build/extract.js +484 -0
  10. package/dist/build/extract.js.map +1 -0
  11. package/dist/build/glob.d.ts +11 -0
  12. package/dist/build/glob.d.ts.map +1 -0
  13. package/dist/build/glob.js +88 -0
  14. package/dist/build/glob.js.map +1 -0
  15. package/dist/build/index.d.ts +7 -0
  16. package/dist/build/index.d.ts.map +1 -0
  17. package/dist/build/index.js +4 -0
  18. package/dist/build/index.js.map +1 -0
  19. package/dist/build/probes.d.ts +41 -0
  20. package/dist/build/probes.d.ts.map +1 -0
  21. package/dist/build/probes.js +134 -0
  22. package/dist/build/probes.js.map +1 -0
  23. package/dist/build/report.d.ts +11 -0
  24. package/dist/build/report.d.ts.map +1 -0
  25. package/dist/build/report.js +39 -0
  26. package/dist/build/report.js.map +1 -0
  27. package/dist/cli/audit.d.ts +15 -0
  28. package/dist/cli/audit.d.ts.map +1 -0
  29. package/dist/cli/audit.js +68 -0
  30. package/dist/cli/audit.js.map +1 -0
  31. package/dist/cli/bench.d.ts +7 -0
  32. package/dist/cli/bench.d.ts.map +1 -0
  33. package/dist/cli/bench.js +147 -0
  34. package/dist/cli/bench.js.map +1 -0
  35. package/dist/cli/harness.d.ts +45 -0
  36. package/dist/cli/harness.d.ts.map +1 -0
  37. package/dist/cli/harness.js +90 -0
  38. package/dist/cli/harness.js.map +1 -0
  39. package/dist/cli/index.d.ts +3 -0
  40. package/dist/cli/index.d.ts.map +1 -0
  41. package/dist/cli/index.js +404 -0
  42. package/dist/cli/index.js.map +1 -0
  43. package/dist/cli/probes.d.ts +20 -0
  44. package/dist/cli/probes.d.ts.map +1 -0
  45. package/dist/cli/probes.js +27 -0
  46. package/dist/cli/probes.js.map +1 -0
  47. package/dist/cli/skill-template.d.ts +2 -0
  48. package/dist/cli/skill-template.d.ts.map +1 -0
  49. package/dist/cli/skill-template.js +254 -0
  50. package/dist/cli/skill-template.js.map +1 -0
  51. package/dist/core/actions.d.ts +67 -0
  52. package/dist/core/actions.d.ts.map +1 -0
  53. package/dist/core/actions.js +357 -0
  54. package/dist/core/actions.js.map +1 -0
  55. package/dist/core/define.d.ts +25 -0
  56. package/dist/core/define.d.ts.map +1 -0
  57. package/dist/core/define.js +76 -0
  58. package/dist/core/define.js.map +1 -0
  59. package/dist/core/execute.d.ts +75 -0
  60. package/dist/core/execute.d.ts.map +1 -0
  61. package/dist/core/execute.js +145 -0
  62. package/dist/core/execute.js.map +1 -0
  63. package/dist/core/index.d.ts +35 -0
  64. package/dist/core/index.d.ts.map +1 -0
  65. package/dist/core/index.js +20 -0
  66. package/dist/core/index.js.map +1 -0
  67. package/dist/core/lemmas.d.ts +32 -0
  68. package/dist/core/lemmas.d.ts.map +1 -0
  69. package/dist/core/lemmas.js +80 -0
  70. package/dist/core/lemmas.js.map +1 -0
  71. package/dist/core/lexical-engine.d.ts +18 -0
  72. package/dist/core/lexical-engine.d.ts.map +1 -0
  73. package/dist/core/lexical-engine.js +296 -0
  74. package/dist/core/lexical-engine.js.map +1 -0
  75. package/dist/core/loop.d.ts +51 -0
  76. package/dist/core/loop.d.ts.map +1 -0
  77. package/dist/core/loop.js +432 -0
  78. package/dist/core/loop.js.map +1 -0
  79. package/dist/core/mcp.d.ts +119 -0
  80. package/dist/core/mcp.d.ts.map +1 -0
  81. package/dist/core/mcp.js +253 -0
  82. package/dist/core/mcp.js.map +1 -0
  83. package/dist/core/memory.d.ts +106 -0
  84. package/dist/core/memory.d.ts.map +1 -0
  85. package/dist/core/memory.js +185 -0
  86. package/dist/core/memory.js.map +1 -0
  87. package/dist/core/plan.d.ts +83 -0
  88. package/dist/core/plan.d.ts.map +1 -0
  89. package/dist/core/plan.js +258 -0
  90. package/dist/core/plan.js.map +1 -0
  91. package/dist/core/preferences.d.ts +54 -0
  92. package/dist/core/preferences.d.ts.map +1 -0
  93. package/dist/core/preferences.js +83 -0
  94. package/dist/core/preferences.js.map +1 -0
  95. package/dist/core/prompt.d.ts +23 -0
  96. package/dist/core/prompt.d.ts.map +1 -0
  97. package/dist/core/prompt.js +76 -0
  98. package/dist/core/prompt.js.map +1 -0
  99. package/dist/core/question.d.ts +96 -0
  100. package/dist/core/question.d.ts.map +1 -0
  101. package/dist/core/question.js +501 -0
  102. package/dist/core/question.js.map +1 -0
  103. package/dist/core/registry.d.ts +33 -0
  104. package/dist/core/registry.d.ts.map +1 -0
  105. package/dist/core/registry.js +72 -0
  106. package/dist/core/registry.js.map +1 -0
  107. package/dist/core/retriever.d.ts +48 -0
  108. package/dist/core/retriever.d.ts.map +1 -0
  109. package/dist/core/retriever.js +123 -0
  110. package/dist/core/retriever.js.map +1 -0
  111. package/dist/core/schema.d.ts +27 -0
  112. package/dist/core/schema.d.ts.map +1 -0
  113. package/dist/core/schema.js +231 -0
  114. package/dist/core/schema.js.map +1 -0
  115. package/dist/core/skill.d.ts +105 -0
  116. package/dist/core/skill.d.ts.map +1 -0
  117. package/dist/core/skill.js +205 -0
  118. package/dist/core/skill.js.map +1 -0
  119. package/dist/core/summarise.d.ts +52 -0
  120. package/dist/core/summarise.d.ts.map +1 -0
  121. package/dist/core/summarise.js +146 -0
  122. package/dist/core/summarise.js.map +1 -0
  123. package/dist/core/tools.d.ts +21 -0
  124. package/dist/core/tools.d.ts.map +1 -0
  125. package/dist/core/tools.js +120 -0
  126. package/dist/core/tools.js.map +1 -0
  127. package/dist/core/types.d.ts +199 -0
  128. package/dist/core/types.d.ts.map +1 -0
  129. package/dist/core/types.js +5 -0
  130. package/dist/core/types.js.map +1 -0
  131. package/dist/dom/index.d.ts +22 -0
  132. package/dist/dom/index.d.ts.map +1 -0
  133. package/dist/dom/index.js +94 -0
  134. package/dist/dom/index.js.map +1 -0
  135. package/dist/extract/index.d.ts +36 -0
  136. package/dist/extract/index.d.ts.map +1 -0
  137. package/dist/extract/index.js +86 -0
  138. package/dist/extract/index.js.map +1 -0
  139. package/dist/react/index.d.ts +52 -0
  140. package/dist/react/index.d.ts.map +1 -0
  141. package/dist/react/index.js +131 -0
  142. package/dist/react/index.js.map +1 -0
  143. package/dist/rules/engine.d.ts +152 -0
  144. package/dist/rules/engine.d.ts.map +1 -0
  145. package/dist/rules/engine.js +364 -0
  146. package/dist/rules/engine.js.map +1 -0
  147. package/dist/rules/facts.d.ts +63 -0
  148. package/dist/rules/facts.d.ts.map +1 -0
  149. package/dist/rules/facts.js +115 -0
  150. package/dist/rules/facts.js.map +1 -0
  151. package/dist/rules/index.d.ts +10 -0
  152. package/dist/rules/index.d.ts.map +1 -0
  153. package/dist/rules/index.js +5 -0
  154. package/dist/rules/index.js.map +1 -0
  155. package/dist/rules/knowledge.d.ts +78 -0
  156. package/dist/rules/knowledge.d.ts.map +1 -0
  157. package/dist/rules/knowledge.js +254 -0
  158. package/dist/rules/knowledge.js.map +1 -0
  159. package/dist/vite/index.d.ts +26 -0
  160. package/dist/vite/index.d.ts.map +1 -0
  161. package/dist/vite/index.js +112 -0
  162. package/dist/vite/index.js.map +1 -0
  163. package/package.json +108 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sho byde
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,423 @@
1
- # Temporary Holding Version
1
+ # boaz
2
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.
3
+ **Ground a browser assistant in your app's real routes, actions and data — with no model to download, no API key, and every sentence traceable to a fact.**
4
+
5
+ **Why the name.** In Ruth 4, Boaz settles a transaction at the city gate, in front of the elders, where the record is kept: "you are witnesses this day." In Ruth 2:11 he answers a question from what he had been told, not from what he could guess. That is the contract this package keeps, so the name is a reminder rather than a metaphor: answers come from the record, and changes happen where they can be seen.
6
+
7
+ ![The Ledger demo: an invoice table filtered by the assistant, with the transcript showing the call it made](docs/media/billing-filter.png)
8
+
9
+ Most "AI in your app" implementations stream the DOM to a server, pay per token, and hand a language model a bag of selectors. This package takes the opposite position:
10
+
11
+ - **The app publishes a contract, not a DOM dump.** Co-located `defineCapability()` declarations are extracted at build time into a small JSON manifest. The assistant knows exactly which screens and operations exist because the build said so.
12
+ - **The app declares facts, the library does the reasoning.** `KnowledgeBase` holds rows plus Datalog-style rules; `createRulesEngine()` joins them against the question, then composes a sentence from the result. No weights, no GPU, no network.
13
+ - **Every call is checked before it runs.** Ids must exist in the manifest, arguments must satisfy the JSON Schema, mutating actions pass a confirmation gate, and a turn is capped at three sequential calls.
14
+ - **Replies can stream, with provenance.** `streaming: { chunkChars, paceMs }` emits `delta` events on the same channel as tool steps, and a rule answer carries the goal, the terms it matched and the rule it applied.
15
+
16
+ ```bash
17
+ npm install @shobyde/boaz
18
+ npx boaz init --skill # writes the skill that keeps capabilities in sync
19
+ npx boaz audit --probes agent-probes.json --module agent-setup.mjs
20
+ npx boaz bench --probes agent-probes.json --module agent-setup.mjs --samples
21
+ ```
22
+
23
+ Every version is also attached to its GitHub release, which npm installs directly and which ships a
24
+ prebuilt `dist/`:
25
+
26
+ ```bash
27
+ npm install https://github.com/shobyde/boaz/releases/download/v0.7.0/boaz-0.7.0.tgz
28
+ ```
29
+
30
+ ## The pieces
31
+
32
+ | Subpath | What it is |
33
+ | --- | --- |
34
+ | `@shobyde/boaz/core` | Registry, JSON Schema validator, BM25 retrieval, prompt assembly, tool-call parser, the execution loop, and a deterministic keyword engine |
35
+ | `@shobyde/boaz/rules` | `KnowledgeBase` (facts + Datalog rules), `createRulesEngine()`, and the answer-rule contract that turns solutions into replies |
36
+ | `@shobyde/boaz/vite` | AST scanner for `defineCapability()` / `defineKnowledge()` that emits `agent-manifest.json` and serves it as a virtual module |
37
+ | `@shobyde/boaz/react` | `<AgentProvider>`, `useAgentChat()`, `useRegisterCapability()` |
38
+ | `@shobyde/boaz/dom` | `createDomContextReader()`: labelled, budgeted page text, for a custom engine that wants grounding |
39
+ | `@shobyde/boaz/cli` | `verify`, `manifest`, `codes`, `audit`, `bench`, `init --skill`, and a self-check corpus runner |
40
+
41
+ One package, six entry points. `react` and `vite` are optional peers, so install the ones your app uses. `typescript` is a regular dependency because the manifest crawler and the Vite plugin parse with its AST.
42
+
43
+ ## Declaring a capability
44
+
45
+ Capabilities live next to the feature that owns the behaviour, not in a central file that rots.
46
+
47
+ ```ts
48
+ import { defineCapability } from '@shobyde/boaz/core';
49
+
50
+ export const filterInvoices = defineCapability({
51
+ id: 'billing.filter_invoices',
52
+ kind: 'action',
53
+ title: 'Filter invoices by status',
54
+ description:
55
+ 'Filters the invoice table down to paid, open, or overdue invoices, so the visitor can see just the ones that still need paying.',
56
+ keywords: ['filter', 'show only', 'unpaid', 'overdue'],
57
+ route: '/settings/billing',
58
+ paramsSchema: {
59
+ type: 'object',
60
+ properties: { status: { type: 'string', enum: ['paid', 'open', 'overdue'] } },
61
+ required: ['status'],
62
+ additionalProperties: false,
63
+ },
64
+ handler: async ({ status }, ctx) => {
65
+ if (ctx.currentRoute !== '/settings/billing') await ctx.navigate('/settings/billing');
66
+ ctx.dispatch('invoices:filter', { status });
67
+ return { appliedFilter: status };
68
+ },
69
+ });
70
+ ```
71
+
72
+ `kind: 'route'` is a destination the assistant can explain and navigate to. `kind: 'action'` is a state change with a handler. `kind: 'query'` is read-only state, and can return `{ answer }` to phrase its own reply. `kind: 'knowledge'` (see `defineKnowledge()`) is prose the assistant may quote verbatim.
73
+
74
+ ## Facts and rules
75
+
76
+ Prose answers "what is this page about". Rows and rules answer "which ones".
77
+
78
+ ```ts
79
+ import { KnowledgeBase, createRulesEngine, fact } from '@shobyde/boaz/rules';
80
+
81
+ const knowledge = new KnowledgeBase({
82
+ facts: [
83
+ ...invoices.map((invoice) =>
84
+ fact('invoice', invoice.id, invoice.customer, invoice.status, String(invoice.amount))),
85
+ ],
86
+ // The library injects `asked(<term>)` for every declared constant the visitor
87
+ // names, so a rule can talk about the question without seeing raw text.
88
+ rules: ['invoices_with(?I, ?C, ?S, ?A) :- invoice(?I, ?C, ?S, ?A), asked(?S).'],
89
+ });
90
+
91
+ const engine = createRulesEngine({
92
+ knowledge,
93
+ answers: [
94
+ {
95
+ id: 'invoices.by_status',
96
+ title: 'Which invoices have a status',
97
+ keywords: ['overdue invoices', 'unpaid', 'paid invoices', 'open invoices'],
98
+ goal: 'invoices_with(?I, ?C, ?S, ?A)',
99
+ compose: ({ solutions }) => {
100
+ if (solutions.length === 0) return '';
101
+ const rows = solutions.map(
102
+ (s) => `${s.bindings['?I']} (${s.bindings['?C']}, $${Number(s.bindings['?A']).toLocaleString('en-US')})`,
103
+ );
104
+ return `${solutions.length} invoice${solutions.length === 1 ? '' : 's'}: ${rows.join(', ')}.`;
105
+ },
106
+ },
107
+ ],
108
+ });
109
+ ```
110
+
111
+ The engine picks an answer rule with BM25 over its title and keywords, runs the goal against the
112
+ knowledge base (with the question's terms as assumptions), and calls `compose` with the solutions.
113
+ When no rule matches, or `compose` returns an empty string, it hands the turn to the keyword engine,
114
+ which navigates and calls actions from the manifest.
115
+
116
+ Answers come back with the reasoning attached:
117
+
118
+ ```ts
119
+ const { text, steps } = await runtime.send('which invoices are overdue?');
120
+ // text: "3 invoices: INV-2039 (Meridian Health, $9,600), INV-2037 (Ardent Freight, $3,120), INV-2032 (Vesper Audio, $560)."
121
+ // steps: [{ type: 'inference', goal: 'invoices_with(?I, ?C, ?S, ?A)', terms: ['overdue'],
122
+ // solutions: [...], rule: 'invoices_with(?I, ?C, ?S, ?A) :- invoice(?I, ?C, ?S, ?A), asked(?S)' }]
123
+ ```
124
+
125
+ That step is what makes the reply auditable: the sentence came from those rows, and you can show
126
+ which ones. A model cannot make that claim.
127
+
128
+ ## Wiring it up
129
+
130
+ ```ts
131
+ // vite.config.ts
132
+ import { defineConfig } from 'vite';
133
+ import react from '@vitejs/plugin-react';
134
+ import { boaz } from '@shobyde/boaz/vite';
135
+
136
+ export default defineConfig({
137
+ plugins: [react(), boaz({ include: ['src/**/*.{ts,tsx}'] })],
138
+ });
139
+ ```
140
+
141
+ ```tsx
142
+ // app.tsx
143
+ import manifest from 'boaz:manifest';
144
+ import { AgentProvider } from '@shobyde/boaz/react';
145
+ import { createRulesEngine } from '@shobyde/boaz/rules';
146
+
147
+ <AgentProvider
148
+ engine={createRulesEngine({ knowledge, answers, capabilities: manifest.capabilities })}
149
+ capabilities={manifest.capabilities}
150
+ getSnapshot={() => ({ currentRoute: location.pathname, state: { openInvoices: 3 } })}
151
+ navigate={(route) => router.navigate(route)}
152
+ dispatch={(event, payload) => store.handle(event, payload)}
153
+ streaming={{ chunkChars: 16, paceMs: 18 }}
154
+ >
155
+ <App />
156
+ </AgentProvider>
157
+ ```
158
+
159
+ Handlers register on mount, so an action declared for another screen is not callable until that screen exists. The runtime handles that: it navigates to `capability.route`, waits up to 2s for the handler, then runs it. `useRegisterCapability(capability)` inside a page component is the whole integration.
160
+
161
+ ## Streaming
162
+
163
+ `streaming` reveals the reply as `delta` events instead of one block. The text is already known when
164
+ the first delta fires, so this is pacing, not inference: a host that wants instant text leaves it off,
165
+ and a host that shows a transcript gets the same event shape it uses for tool steps.
166
+
167
+ ```
168
+ step inference overdue(?I, ?C, ?A) terms: [overdue] 0ms
169
+ delta "3 overdue: "
170
+ delta "INV-2039 (Meridian Health), "
171
+ ...
172
+ turn text = "3 overdue: INV-2039 (...)."
173
+ ```
174
+
175
+ For a deterministic engine the honest thing to stream is the reasoning, not a fake progress bar:
176
+ the trace is real and it arrives in about a millisecond.
177
+
178
+ ## Grounding (only when you bring your own engine)
179
+
180
+ Capability metadata says what the app can do. It does not say what the page says. If you plug in a
181
+ hosted model, pass `readContext` and the runtime carries page text into the prompt under its own budget:
182
+
183
+ ```js
184
+ import { createDomContextReader } from '@shobyde/boaz/dom';
185
+
186
+ const readContext = createDomContextReader({
187
+ sections: [
188
+ { selector: '#about', label: 'About' },
189
+ { selector: '#projects', label: 'Projects' },
190
+ { selector: '#experience', label: 'Experience' },
191
+ ],
192
+ maxChars: 2600,
193
+ });
194
+
195
+ new AgentRuntime({ engine, capabilities, registry, getSnapshot, readContext /* ... */ });
196
+ ```
197
+
198
+ Sections are ranked by the visitor's words, so a question about experience keeps that text and drops the
199
+ blog when the budget is tight. The default engines ignore `readContext` entirely.
200
+
201
+ ## Answers that are UI
202
+
203
+ A handler can return a declarative surface instead of a sentence. The loop does not interpret it: it
204
+ emits a `surface` step and the host renders it with its own components.
205
+
206
+ ```ts
207
+ handler: async ({ project }) => ({ surface: projectCard(project) })
208
+ ```
209
+
210
+ A2UI 1.0 streams (`createSurface` / `updateComponents` / `updateDataModel`) are one shape that fits; a
211
+ host can use its own. shobyde.com renders A2UI components with native elements, so the agent names
212
+ components and the page keeps its design system, and `groundglass` checks every surface the assistant
213
+ can emit in CI.
214
+
215
+ ## No React? The core is framework-free
216
+
217
+ `@shobyde/boaz/react` is a convenience, not the contract. shobyde.com runs the same package in a
218
+ Vite page with no framework at all: it imports the generated manifest, registers the handlers, and
219
+ renders its own panel.
220
+
221
+ ```js
222
+ import manifest from 'boaz:manifest';
223
+ import { AgentRuntime, registry } from '@shobyde/boaz/core';
224
+ import { createRulesEngine } from '@shobyde/boaz/rules';
225
+ import { siteCapabilities } from './capabilities.js';
226
+
227
+ for (const capability of siteCapabilities) registry.register(capability);
228
+
229
+ const runtime = new AgentRuntime({
230
+ engine: createRulesEngine({ knowledge, answers, capabilities: manifest.capabilities }),
231
+ capabilities: manifest.capabilities, // what the assistant may choose from
232
+ registry, // what can actually run
233
+ getSnapshot: () => ({ currentRoute: location.hash || '#hero' }),
234
+ navigate: (route) => document.querySelector(route)?.scrollIntoView(),
235
+ dispatch: (event, payload) => handle(event, payload),
236
+ });
237
+
238
+ const { text, steps } = await runtime.send('open the printable resume');
239
+ ```
240
+
241
+ Hash routes are supported for anchor navigation (`route: '#projects'`).
242
+
243
+ ## Proving the assistant answers (audit and bench)
244
+
245
+ `verify` checks the declarations. These two check the conversation, against the
246
+ engine your app actually runs:
247
+
248
+ ```bash
249
+ npx boaz audit --probes agent-probes.json --module agent-setup.mjs
250
+ npx boaz bench --probes agent-probes.json --module agent-setup.mjs --samples
251
+ ```
252
+
253
+ `agent-probes.json` is one question per line, with what a correct answer looks
254
+ like:
255
+
256
+ ```json
257
+ {
258
+ "questions": [
259
+ { "question": "which invoices are overdue?", "expect": "invoices.overdue",
260
+ "intent": "invoices.overdue", "must": ["Northwind", "Fabrikam"] },
261
+ { "question": "filter to overdue", "expect": "invoices.filter", "args": { "status": "overdue" } }
262
+ ]
263
+ }
264
+ ```
265
+
266
+ `audit` reports the engine's own decision — the rule that planned a tool call, the
267
+ capability that ran, or the knowledge paragraph that was quoted — and exits 1 on
268
+ any miss. `bench` groups the probes by `intent` and scores the copy: fidelity
269
+ (required facts present), paraphrase similarity with the facts masked, opener
270
+ variety, length spread, and stability. Only intents with a `must` list are scored.
271
+
272
+ `agent-setup.mjs` is the bridge: it exports `createEngine()` (and optionally
273
+ `runCapability`, `answers`, `capabilities`) so the harness asks your app instead
274
+ of reimplementing it. The skill written by `init --skill` documents the whole
275
+ loop.
276
+
277
+ No probe file yet? Generate one from the manifest:
278
+
279
+ ```bash
280
+ npx boaz probes --generate --manifest dist/agent-manifest.json
281
+ ```
282
+
283
+ Every capability title and keyword becomes a question that expects the
284
+ capability it came from. It reports the two things it cannot decide for you:
285
+ phrases that two capabilities in the same query class both claim, and
286
+ capabilities that need arguments (a phrase names what to open, not which one).
287
+ Edit the wording, then run `audit`.
288
+
289
+ ## What `verify` actually prints
290
+
291
+ Real output, from the demo app in `apps/demo`:
292
+
293
+ ```console
294
+ $ boaz verify apps/demo
295
+ 12 capabilities · 5 routes · 17 files scanned
296
+ clean
297
+ ```
298
+
299
+ And on a fixture where an action sounds destructive but has no confirmation gate:
300
+
301
+ ```console
302
+ $ boaz verify fixtures/selfcheck/unsafe-action
303
+ src/capabilities.ts:3 warning CAP007 action sounds like it mutates state; set requiresConfirmation: true unless it is reversible and cheap
304
+
305
+ 1 capability · 0 routes · 1 file scanned
306
+ 1 warning
307
+ ```
308
+
309
+ Every code is stable and documented, so CI output is citable:
310
+
311
+ | Code | Severity | Meaning |
312
+ | --- | --- | --- |
313
+ | `CAP001` | error | Duplicate capability id |
314
+ | `CAP002` | error | Title/description missing or too short to retrieve on |
315
+ | `CAP003` | error | Route capability without a usable `/` path |
316
+ | `CAP004` | error | Malformed `paramsSchema` structure |
317
+ | `CAP005` | warning | Schema keyword the runtime cannot enforce (`$ref`, `format`) |
318
+ | `CAP006` | error | Declaration is not statically evaluable, so no manifest entry |
319
+ | `CAP007` | warning | Mutating action without `requiresConfirmation` (id or title names the mutation, and the title does not open with a read-only verb) |
320
+ | `CAP008` | warning | Router path with no route capability (heuristic) |
321
+ | `CAP009` | error | Invalid id or kind |
322
+ | `CAP010` | warning | Two capabilities claim the same route |
323
+
324
+ `npx boaz codes` prints the table; `boaz verify --strict` fails on warnings too.
325
+
326
+ ## The safety model
327
+
328
+ Letting a program act in a live app is the risky part, so the boundaries are structural rather than prompted:
329
+
330
+ 1. **Allowlisted registry.** No `eval`, no selector clicking, no generated code. The loop matches a parsed id against the manifest and calls the handler registered for it, or nothing.
331
+ 2. **Schema validation with one retry.** Arguments are validated against `paramsSchema`. A failure is replayed verbatim (`arguments.status must be one of "paid", "open", "overdue" (enum)`) with one chance to correct.
332
+ 3. **Confirmation gate.** `requiresConfirmation: true` pauses the turn, emits the request to the UI, and only calls the handler on an explicit approve. Cancel ends the turn with "Cancelled. Nothing was changed."
333
+ 4. **Step cap.** At most 3 sequential tool calls per message (`maxToolCalls`), so a confused engine cannot loop.
334
+ 5. **Bounded inference.** Rules are evaluated to a depth limit with deduped solutions, and a rule can only derive facts from rows the app declared.
335
+
336
+ ## Engines
337
+
338
+ - **`createRulesEngine()`** — BM25 over your answer rules, Datalog over your facts, `compose` for the sentence. Handles `asked()` assumptions, returns an `inference` step, and falls through to keyword matching when nothing matches.
339
+ - **`createLexicalEngine()`** — deterministic BM25 over the manifest. It navigates, calls actions when every required argument is unambiguous from the visitor's words (enum value present, email present), and asks otherwise.
340
+ - **`AgentEngine`** — a six-line interface (`id` + `complete(messages, tools)`). Wrap your own endpoint, a hosted model, or a test double; nothing in the loop assumes where the text came from.
341
+
342
+ ### Why there is no bundled model
343
+
344
+ Earlier versions shipped WebLLM and Chrome's Prompt API adapters. They are gone in 0.4.0: a
345
+ multi-hundred-megabyte download, a GPU requirement and a browser-specific API are three good reasons
346
+ for a visitor not to get an answer, and none of them buy a reply that is verifiable. The rules engine
347
+ answers the questions an app can actually answer from its own data, and says so plainly when it cannot.
348
+
349
+ ## The demo
350
+
351
+ ```bash
352
+ pnpm install
353
+ pnpm build
354
+ pnpm --filter demo dev # http://localhost:5173
355
+ ```
356
+
357
+ It is a small invoices app ("Ledger") with five routes and twelve capabilities. Nothing about the assistant is hard-coded to those pages: the manifest is generated from the declarations beside the pages, and the same handlers back the buttons. The demo's knowledge base is its invoice rows plus one rule, so "which invoices are overdue" is answered from data.
358
+
359
+ ![The assistant, docked, after filtering the invoice table](docs/media/dashboard.png)
360
+
361
+ ![The confirmation gate before a destructive action](docs/media/confirm-gate.png)
362
+
363
+ ## What is verified, and what is not
364
+
365
+ Verified on this machine:
366
+
367
+ - `pnpm test` — 86 tests across schema validation, BM25 ranking, prompt budgeting, output parsing, the tool loop (navigation, late handler registration, schema retry, confirmation approve/cancel, step cap), the AST extractor, the keyword engine, the knowledge base (joins, recursive rules, scoped assumptions, dedupe) and streamed deltas.
368
+ - `boaz verify --self-check fixtures/selfcheck` — 9/9 fixtures produce exactly the diagnostic codes they declare, including the clean fixture producing none.
369
+ - The demo in headless Chromium: "show only the overdue invoices" navigates from `/` to `/settings/billing` and filters the table to three overdue rows; "delete this workspace" raises the confirmation card; Cancel leaves state untouched.
370
+
371
+ Not verified here:
372
+
373
+ - Rule quality beyond the demo: the tests cover the engine, not whether your rules are the right ones. `inference` steps are the tool for that review.
374
+ - Token counts are `chars / 4` estimates; the budget is approximate by design.
375
+ - `CAP008` route detection is a heuristic over React Router JSX and `path:` literals. File-based routers (Next `app/`, Remix) are not scanned yet.
376
+
377
+ ## Repo layout
378
+
379
+ ```
380
+ packages/boaz/src/
381
+ core/ types, define, registry, schema, retriever, prompt, tools, loop, keyword engine
382
+ rules/ knowledge base (facts, rules, unification), rules engine, answer contract
383
+ build/ AST extractor, glob matcher, diagnostic codes, terminal report
384
+ vite/ plugin: scan, emit manifest, virtual module, dev watcher
385
+ cli/ verify / manifest / codes / init / self-check + the shipped skill
386
+ react/ provider, useAgentChat, useRegisterCapability
387
+ apps/demo/ the Ledger app used in the screenshots
388
+ fixtures/selfcheck/ nine fixtures, each declaring the codes it must provoke
389
+ docs/media/ stills captured from the running demo
390
+ ```
391
+
392
+ ## Releasing
393
+
394
+ Pushing a version tag does the whole release.
395
+
396
+ ```bash
397
+ cd packages/boaz && npm version minor --no-git-tag-version && cd ../..
398
+ # add the entry at the top of CHANGELOG.md, then
399
+ git commit -am "0.8.3: what changed" && git tag v0.8.3 && git push origin main --tags
400
+ ```
401
+
402
+ The tag runs `.github/workflows/release.yml`: install, build, test, check that the tag matches
403
+ `packages/boaz/package.json`, `npm pack`, attach the tarball to the GitHub release, then publish to
404
+ npm with provenance. A tag whose version is already on the registry is a no-op, so re-running a
405
+ release is safe. Auth is trusted publishing over OIDC when the `NPM_TRUSTED_PUBLISHER` repo variable
406
+ is `true`, otherwise the `NPM_TOKEN` secret.
407
+
408
+ If you would rather see a release before it ships, set the repo variable `NPM_STAGE=true`. The same
409
+ step then runs `npm stage publish` instead: nothing is installable until someone runs
410
+ `npm stage approve <stage-id>`, and the run summary prints that command. Staging needs no 2FA; the
411
+ approval is where the human comes in.
412
+
413
+ ## Status
414
+
415
+ `0.7.0`. The package is renamed from `client-agent` to `boaz`; the code is the same 0.6.10 behaviour
416
+ under a new name, `bin`, virtual module (`boaz:manifest`), dev artifact directory (`.boaz/`) and
417
+ consumer skill (`boaz-capabilities.md`). 0.4.0 was the last breaking change before that: the `webllm`
418
+ and `chrome-ai` entry points, their peer dependency and the demo's worker are gone. Releasing is
419
+ wired in `.github/workflows/release.yml`: a version tag builds and tests, packs the tarball, attaches
420
+ it to the GitHub release and publishes to npm with provenance. It is running in production on
421
+ shobyde.com.
422
+
423
+ MIT.
@@ -0,0 +1,16 @@
1
+ export type Severity = 'error' | 'warning';
2
+ export interface DiagnosticCode {
3
+ code: string;
4
+ severity: Severity;
5
+ title: string;
6
+ detail: string;
7
+ }
8
+ /**
9
+ * The diagnostic contract. Codes are stable: they appear in CI output, in
10
+ * `boaz verify --json`, and in the self-check corpus, so a rule can be
11
+ * referenced without pasting prose.
12
+ */
13
+ export declare const DIAGNOSTIC_CODES: DiagnosticCode[];
14
+ export declare const CODE_INDEX: Record<string, DiagnosticCode>;
15
+ export declare function codeSeverity(code: string): Severity;
16
+ //# sourceMappingURL=codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/build/codes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,cAAc,EA6D5C,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAErD,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAEnD"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The diagnostic contract. Codes are stable: they appear in CI output, in
3
+ * `boaz verify --json`, and in the self-check corpus, so a rule can be
4
+ * referenced without pasting prose.
5
+ */
6
+ export const DIAGNOSTIC_CODES = [
7
+ {
8
+ code: 'CAP001',
9
+ severity: 'error',
10
+ title: 'Duplicate capability id',
11
+ detail: 'Two declarations share an id; only one handler can win at runtime.',
12
+ },
13
+ {
14
+ code: 'CAP002',
15
+ severity: 'error',
16
+ title: 'Missing or unusable title/description',
17
+ detail: 'Both are required. The description is the retrieval text, so a placeholder makes the capability unfindable.',
18
+ },
19
+ {
20
+ code: 'CAP003',
21
+ severity: 'error',
22
+ title: 'Route capability without a usable route',
23
+ detail: 'kind "route" needs a route string starting with "/".',
24
+ },
25
+ {
26
+ code: 'CAP004',
27
+ severity: 'error',
28
+ title: 'Invalid paramsSchema structure',
29
+ detail: 'paramsSchema must be an object with object properties and a string[] required array.',
30
+ },
31
+ {
32
+ code: 'CAP005',
33
+ severity: 'warning',
34
+ title: 'Schema keyword the runtime does not enforce',
35
+ detail: 'The model is told the constraint but the validator will not reject a violation.',
36
+ },
37
+ {
38
+ code: 'CAP006',
39
+ severity: 'error',
40
+ title: 'Declaration is not statically evaluable',
41
+ detail: 'Manifest metadata must be a literal: no function calls, imports, or computed keys.',
42
+ },
43
+ {
44
+ code: 'CAP007',
45
+ severity: 'warning',
46
+ title: 'Side-effecting action without confirmation',
47
+ detail: 'A mutating verb appears in the id or description but requiresConfirmation is not set.',
48
+ },
49
+ {
50
+ code: 'CAP008',
51
+ severity: 'warning',
52
+ title: 'Route in the app with no route capability',
53
+ detail: 'Heuristic: a static path string was found in a router file and no route capability covers it.',
54
+ },
55
+ {
56
+ code: 'CAP009',
57
+ severity: 'error',
58
+ title: 'Invalid id or kind',
59
+ detail: 'Ids are lowercase (a-z, 0-9, ".", "_", "-"); kind is route, action or query.',
60
+ },
61
+ {
62
+ code: 'CAP010',
63
+ severity: 'warning',
64
+ title: 'Two capabilities claim the same route',
65
+ detail: 'The assistant cannot tell which one to navigate to.',
66
+ },
67
+ ];
68
+ export const CODE_INDEX = Object.fromEntries(DIAGNOSTIC_CODES.map((entry) => [entry.code, entry]));
69
+ export function codeSeverity(code) {
70
+ return CODE_INDEX[code]?.severity ?? 'error';
71
+ }
72
+ //# sourceMappingURL=codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/build/codes.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAqB;IAChD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,yBAAyB;QAChC,MAAM,EAAE,oEAAoE;KAC7E;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,uCAAuC;QAC9C,MAAM,EAAE,6GAA6G;KACtH;IACD;QACE,IAAI,EAAE,QAAQ;Q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core/types.js';
2
+ import { type Severity } from './codes.js';
3
+ export interface SourcePosition {
4
+ file: string;
5
+ line: number;
6
+ column: number;
7
+ }
8
+ export interface StaticCapability extends ManifestCapability {
9
+ hasHandler: boolean;
10
+ source: SourcePosition;
11
+ }
12
+ export interface Diagnostic {
13
+ code: string;
14
+ severity: Severity;
15
+ message: string;
16
+ file?: string;
17
+ line?: number;
18
+ capabilityId?: string;
19
+ }
20
+ export interface DiscoveredRoute {
21
+ path: string;
22
+ source: SourcePosition;
23
+ }
24
+ export interface ExtractOptions {
25
+ /** Directory scanned for source files. */
26
+ root: string;
27
+ /** Glob patterns relative to root. */
28
+ include: string[];
29
+ exclude?: string[];
30
+ }
31
+ export interface ExtractResult {
32
+ capabilities: StaticCapability[];
33
+ routes: DiscoveredRoute[];
34
+ diagnostics: Diagnostic[];
35
+ files: string[];
36
+ }
37
+ export declare function scanSource(text: string, fileName: string): {
38
+ capabilities: StaticCapability[];
39
+ routes: DiscoveredRoute[];
40
+ diagnostics: Diagnostic[];
41
+ };
42
+ export declare function extractCapabilities(options: ExtractOptions): Promise<ExtractResult>;
43
+ export declare function buildManifest(capabilities: StaticCapability[]): AgentManifest;
44
+ export declare function hasErrors(diagnostics: Diagnostic[]): boolean;
45
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/build/extract.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAoC,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE5G,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGzD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC1D,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,cAAc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