@shobyde/boaz 0.0.0-stage → 0.8.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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +402 -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,403 @@
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
+ Releases are staged by CI and approved by hand (`npm stage approve`), so a version is installable
24
+ only after a human with an authenticator has looked at it. Every version is also attached to its
25
+ GitHub release, which npm installs directly and which ships a prebuilt `dist/`:
26
+
27
+ ```bash
28
+ npm install https://github.com/shobyde/boaz/releases/download/v0.7.0/boaz-0.7.0.tgz
29
+ ```
30
+
31
+ ## The pieces
32
+
33
+ | Subpath | What it is |
34
+ | --- | --- |
35
+ | `@shobyde/boaz/core` | Registry, JSON Schema validator, BM25 retrieval, prompt assembly, tool-call parser, the execution loop, and a deterministic keyword engine |
36
+ | `@shobyde/boaz/rules` | `KnowledgeBase` (facts + Datalog rules), `createRulesEngine()`, and the answer-rule contract that turns solutions into replies |
37
+ | `@shobyde/boaz/vite` | AST scanner for `defineCapability()` / `defineKnowledge()` that emits `agent-manifest.json` and serves it as a virtual module |
38
+ | `@shobyde/boaz/react` | `<AgentProvider>`, `useAgentChat()`, `useRegisterCapability()` |
39
+ | `@shobyde/boaz/dom` | `createDomContextReader()`: labelled, budgeted page text, for a custom engine that wants grounding |
40
+ | `@shobyde/boaz/cli` | `verify`, `manifest`, `codes`, `audit`, `bench`, `init --skill`, and a self-check corpus runner |
41
+
42
+ 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.
43
+
44
+ ## Declaring a capability
45
+
46
+ Capabilities live next to the feature that owns the behaviour, not in a central file that rots.
47
+
48
+ ```ts
49
+ import { defineCapability } from '@shobyde/boaz/core';
50
+
51
+ export const filterInvoices = defineCapability({
52
+ id: 'billing.filter_invoices',
53
+ kind: 'action',
54
+ title: 'Filter invoices by status',
55
+ description:
56
+ 'Filters the invoice table down to paid, open, or overdue invoices, so the visitor can see just the ones that still need paying.',
57
+ keywords: ['filter', 'show only', 'unpaid', 'overdue'],
58
+ route: '/settings/billing',
59
+ paramsSchema: {
60
+ type: 'object',
61
+ properties: { status: { type: 'string', enum: ['paid', 'open', 'overdue'] } },
62
+ required: ['status'],
63
+ additionalProperties: false,
64
+ },
65
+ handler: async ({ status }, ctx) => {
66
+ if (ctx.currentRoute !== '/settings/billing') await ctx.navigate('/settings/billing');
67
+ ctx.dispatch('invoices:filter', { status });
68
+ return { appliedFilter: status };
69
+ },
70
+ });
71
+ ```
72
+
73
+ `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.
74
+
75
+ ## Facts and rules
76
+
77
+ Prose answers "what is this page about". Rows and rules answer "which ones".
78
+
79
+ ```ts
80
+ import { KnowledgeBase, createRulesEngine, fact } from '@shobyde/boaz/rules';
81
+
82
+ const knowledge = new KnowledgeBase({
83
+ facts: [
84
+ ...invoices.map((invoice) =>
85
+ fact('invoice', invoice.id, invoice.customer, invoice.status, String(invoice.amount))),
86
+ ],
87
+ // The library injects `asked(<term>)` for every declared constant the visitor
88
+ // names, so a rule can talk about the question without seeing raw text.
89
+ rules: ['invoices_with(?I, ?C, ?S, ?A) :- invoice(?I, ?C, ?S, ?A), asked(?S).'],
90
+ });
91
+
92
+ const engine = createRulesEngine({
93
+ knowledge,
94
+ answers: [
95
+ {
96
+ id: 'invoices.by_status',
97
+ title: 'Which invoices have a status',
98
+ keywords: ['overdue invoices', 'unpaid', 'paid invoices', 'open invoices'],
99
+ goal: 'invoices_with(?I, ?C, ?S, ?A)',
100
+ compose: ({ solutions }) => {
101
+ if (solutions.length === 0) return '';
102
+ const rows = solutions.map(
103
+ (s) => `${s.bindings['?I']} (${s.bindings['?C']}, $${Number(s.bindings['?A']).toLocaleString('en-US')})`,
104
+ );
105
+ return `${solutions.length} invoice${solutions.length === 1 ? '' : 's'}: ${rows.join(', ')}.`;
106
+ },
107
+ },
108
+ ],
109
+ });
110
+ ```
111
+
112
+ The engine picks an answer rule with BM25 over its title and keywords, runs the goal against the
113
+ knowledge base (with the question's terms as assumptions), and calls `compose` with the solutions.
114
+ When no rule matches, or `compose` returns an empty string, it hands the turn to the keyword engine,
115
+ which navigates and calls actions from the manifest.
116
+
117
+ Answers come back with the reasoning attached:
118
+
119
+ ```ts
120
+ const { text, steps } = await runtime.send('which invoices are overdue?');
121
+ // text: "3 invoices: INV-2039 (Meridian Health, $9,600), INV-2037 (Ardent Freight, $3,120), INV-2032 (Vesper Audio, $560)."
122
+ // steps: [{ type: 'inference', goal: 'invoices_with(?I, ?C, ?S, ?A)', terms: ['overdue'],
123
+ // solutions: [...], rule: 'invoices_with(?I, ?C, ?S, ?A) :- invoice(?I, ?C, ?S, ?A), asked(?S)' }]
124
+ ```
125
+
126
+ That step is what makes the reply auditable: the sentence came from those rows, and you can show
127
+ which ones. A model cannot make that claim.
128
+
129
+ ## Wiring it up
130
+
131
+ ```ts
132
+ // vite.config.ts
133
+ import { defineConfig } from 'vite';
134
+ import react from '@vitejs/plugin-react';
135
+ import { boaz } from '@shobyde/boaz/vite';
136
+
137
+ export default defineConfig({
138
+ plugins: [react(), boaz({ include: ['src/**/*.{ts,tsx}'] })],
139
+ });
140
+ ```
141
+
142
+ ```tsx
143
+ // app.tsx
144
+ import manifest from 'boaz:manifest';
145
+ import { AgentProvider } from '@shobyde/boaz/react';
146
+ import { createRulesEngine } from '@shobyde/boaz/rules';
147
+
148
+ <AgentProvider
149
+ engine={createRulesEngine({ knowledge, answers, capabilities: manifest.capabilities })}
150
+ capabilities={manifest.capabilities}
151
+ getSnapshot={() => ({ currentRoute: location.pathname, state: { openInvoices: 3 } })}
152
+ navigate={(route) => router.navigate(route)}
153
+ dispatch={(event, payload) => store.handle(event, payload)}
154
+ streaming={{ chunkChars: 16, paceMs: 18 }}
155
+ >
156
+ <App />
157
+ </AgentProvider>
158
+ ```
159
+
160
+ 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.
161
+
162
+ ## Streaming
163
+
164
+ `streaming` reveals the reply as `delta` events instead of one block. The text is already known when
165
+ the first delta fires, so this is pacing, not inference: a host that wants instant text leaves it off,
166
+ and a host that shows a transcript gets the same event shape it uses for tool steps.
167
+
168
+ ```
169
+ step inference overdue(?I, ?C, ?A) terms: [overdue] 0ms
170
+ delta "3 overdue: "
171
+ delta "INV-2039 (Meridian Health), "
172
+ ...
173
+ turn text = "3 overdue: INV-2039 (...)."
174
+ ```
175
+
176
+ For a deterministic engine the honest thing to stream is the reasoning, not a fake progress bar:
177
+ the trace is real and it arrives in about a millisecond.
178
+
179
+ ## Grounding (only when you bring your own engine)
180
+
181
+ Capability metadata says what the app can do. It does not say what the page says. If you plug in a
182
+ hosted model, pass `readContext` and the runtime carries page text into the prompt under its own budget:
183
+
184
+ ```js
185
+ import { createDomContextReader } from '@shobyde/boaz/dom';
186
+
187
+ const readContext = createDomContextReader({
188
+ sections: [
189
+ { selector: '#about', label: 'About' },
190
+ { selector: '#projects', label: 'Projects' },
191
+ { selector: '#experience', label: 'Experience' },
192
+ ],
193
+ maxChars: 2600,
194
+ });
195
+
196
+ new AgentRuntime({ engine, capabilities, registry, getSnapshot, readContext /* ... */ });
197
+ ```
198
+
199
+ Sections are ranked by the visitor's words, so a question about experience keeps that text and drops the
200
+ blog when the budget is tight. The default engines ignore `readContext` entirely.
201
+
202
+ ## Answers that are UI
203
+
204
+ A handler can return a declarative surface instead of a sentence. The loop does not interpret it: it
205
+ emits a `surface` step and the host renders it with its own components.
206
+
207
+ ```ts
208
+ handler: async ({ project }) => ({ surface: projectCard(project) })
209
+ ```
210
+
211
+ A2UI 1.0 streams (`createSurface` / `updateComponents` / `updateDataModel`) are one shape that fits; a
212
+ host can use its own. shobyde.com renders A2UI components with native elements, so the agent names
213
+ components and the page keeps its design system, and `groundglass` checks every surface the assistant
214
+ can emit in CI.
215
+
216
+ ## No React? The core is framework-free
217
+
218
+ `@shobyde/boaz/react` is a convenience, not the contract. shobyde.com runs the same package in a
219
+ Vite page with no framework at all: it imports the generated manifest, registers the handlers, and
220
+ renders its own panel.
221
+
222
+ ```js
223
+ import manifest from 'boaz:manifest';
224
+ import { AgentRuntime, registry } from '@shobyde/boaz/core';
225
+ import { createRulesEngine } from '@shobyde/boaz/rules';
226
+ import { siteCapabilities } from './capabilities.js';
227
+
228
+ for (const capability of siteCapabilities) registry.register(capability);
229
+
230
+ const runtime = new AgentRuntime({
231
+ engine: createRulesEngine({ knowledge, answers, capabilities: manifest.capabilities }),
232
+ capabilities: manifest.capabilities, // what the assistant may choose from
233
+ registry, // what can actually run
234
+ getSnapshot: () => ({ currentRoute: location.hash || '#hero' }),
235
+ navigate: (route) => document.querySelector(route)?.scrollIntoView(),
236
+ dispatch: (event, payload) => handle(event, payload),
237
+ });
238
+
239
+ const { text, steps } = await runtime.send('open the printable resume');
240
+ ```
241
+
242
+ Hash routes are supported for anchor navigation (`route: '#projects'`).
243
+
244
+ ## Proving the assistant answers (audit and bench)
245
+
246
+ `verify` checks the declarations. These two check the conversation, against the
247
+ engine your app actually runs:
248
+
249
+ ```bash
250
+ npx boaz audit --probes agent-probes.json --module agent-setup.mjs
251
+ npx boaz bench --probes agent-probes.json --module agent-setup.mjs --samples
252
+ ```
253
+
254
+ `agent-probes.json` is one question per line, with what a correct answer looks
255
+ like:
256
+
257
+ ```json
258
+ {
259
+ "questions": [
260
+ { "question": "which invoices are overdue?", "expect": "invoices.overdue",
261
+ "intent": "invoices.overdue", "must": ["Northwind", "Fabrikam"] },
262
+ { "question": "filter to overdue", "expect": "invoices.filter", "args": { "status": "overdue" } }
263
+ ]
264
+ }
265
+ ```
266
+
267
+ `audit` reports the engine's own decision — the rule that planned a tool call, the
268
+ capability that ran, or the knowledge paragraph that was quoted — and exits 1 on
269
+ any miss. `bench` groups the probes by `intent` and scores the copy: fidelity
270
+ (required facts present), paraphrase similarity with the facts masked, opener
271
+ variety, length spread, and stability. Only intents with a `must` list are scored.
272
+
273
+ `agent-setup.mjs` is the bridge: it exports `createEngine()` (and optionally
274
+ `runCapability`, `answers`, `capabilities`) so the harness asks your app instead
275
+ of reimplementing it. The skill written by `init --skill` documents the whole
276
+ loop.
277
+
278
+ No probe file yet? Generate one from the manifest:
279
+
280
+ ```bash
281
+ npx boaz probes --generate --manifest dist/agent-manifest.json
282
+ ```
283
+
284
+ Every capability title and keyword becomes a question that expects the
285
+ capability it came from. It reports the two things it cannot decide for you:
286
+ phrases that two capabilities in the same query class both claim, and
287
+ capabilities that need arguments (a phrase names what to open, not which one).
288
+ Edit the wording, then run `audit`.
289
+
290
+ ## What `verify` actually prints
291
+
292
+ Real output, from the demo app in `apps/demo`:
293
+
294
+ ```console
295
+ $ boaz verify apps/demo
296
+ 12 capabilities · 5 routes · 17 files scanned
297
+ clean
298
+ ```
299
+
300
+ And on a fixture where an action sounds destructive but has no confirmation gate:
301
+
302
+ ```console
303
+ $ boaz verify fixtures/selfcheck/unsafe-action
304
+ src/capabilities.ts:3 warning CAP007 action sounds like it mutates state; set requiresConfirmation: true unless it is reversible and cheap
305
+
306
+ 1 capability · 0 routes · 1 file scanned
307
+ 1 warning
308
+ ```
309
+
310
+ Every code is stable and documented, so CI output is citable:
311
+
312
+ | Code | Severity | Meaning |
313
+ | --- | --- | --- |
314
+ | `CAP001` | error | Duplicate capability id |
315
+ | `CAP002` | error | Title/description missing or too short to retrieve on |
316
+ | `CAP003` | error | Route capability without a usable `/` path |
317
+ | `CAP004` | error | Malformed `paramsSchema` structure |
318
+ | `CAP005` | warning | Schema keyword the runtime cannot enforce (`$ref`, `format`) |
319
+ | `CAP006` | error | Declaration is not statically evaluable, so no manifest entry |
320
+ | `CAP007` | warning | Mutating action without `requiresConfirmation` (id or title names the mutation, and the title does not open with a read-only verb) |
321
+ | `CAP008` | warning | Router path with no route capability (heuristic) |
322
+ | `CAP009` | error | Invalid id or kind |
323
+ | `CAP010` | warning | Two capabilities claim the same route |
324
+
325
+ `npx boaz codes` prints the table; `boaz verify --strict` fails on warnings too.
326
+
327
+ ## The safety model
328
+
329
+ Letting a program act in a live app is the risky part, so the boundaries are structural rather than prompted:
330
+
331
+ 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.
332
+ 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.
333
+ 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."
334
+ 4. **Step cap.** At most 3 sequential tool calls per message (`maxToolCalls`), so a confused engine cannot loop.
335
+ 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.
336
+
337
+ ## Engines
338
+
339
+ - **`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.
340
+ - **`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.
341
+ - **`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.
342
+
343
+ ### Why there is no bundled model
344
+
345
+ Earlier versions shipped WebLLM and Chrome's Prompt API adapters. They are gone in 0.4.0: a
346
+ multi-hundred-megabyte download, a GPU requirement and a browser-specific API are three good reasons
347
+ for a visitor not to get an answer, and none of them buy a reply that is verifiable. The rules engine
348
+ answers the questions an app can actually answer from its own data, and says so plainly when it cannot.
349
+
350
+ ## The demo
351
+
352
+ ```bash
353
+ pnpm install
354
+ pnpm build
355
+ pnpm --filter demo dev # http://localhost:5173
356
+ ```
357
+
358
+ 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.
359
+
360
+ ![The assistant, docked, after filtering the invoice table](docs/media/dashboard.png)
361
+
362
+ ![The confirmation gate before a destructive action](docs/media/confirm-gate.png)
363
+
364
+ ## What is verified, and what is not
365
+
366
+ Verified on this machine:
367
+
368
+ - `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.
369
+ - `boaz verify --self-check fixtures/selfcheck` — 9/9 fixtures produce exactly the diagnostic codes they declare, including the clean fixture producing none.
370
+ - 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.
371
+
372
+ Not verified here:
373
+
374
+ - 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.
375
+ - Token counts are `chars / 4` estimates; the budget is approximate by design.
376
+ - `CAP008` route detection is a heuristic over React Router JSX and `path:` literals. File-based routers (Next `app/`, Remix) are not scanned yet.
377
+
378
+ ## Repo layout
379
+
380
+ ```
381
+ packages/boaz/src/
382
+ core/ types, define, registry, schema, retriever, prompt, tools, loop, keyword engine
383
+ rules/ knowledge base (facts, rules, unification), rules engine, answer contract
384
+ build/ AST extractor, glob matcher, diagnostic codes, terminal report
385
+ vite/ plugin: scan, emit manifest, virtual module, dev watcher
386
+ cli/ verify / manifest / codes / init / self-check + the shipped skill
387
+ react/ provider, useAgentChat, useRegisterCapability
388
+ apps/demo/ the Ledger app used in the screenshots
389
+ fixtures/selfcheck/ nine fixtures, each declaring the codes it must provoke
390
+ docs/media/ stills captured from the running demo
391
+ ```
392
+
393
+ ## Status
394
+
395
+ `0.7.0`. The package is renamed from `client-agent` to `boaz`; the code is the same 0.6.10 behaviour
396
+ under a new name, `bin`, virtual module (`boaz:manifest`), dev artifact directory (`.boaz/`) and
397
+ consumer skill (`boaz-capabilities.md`). 0.4.0 was the last breaking change before that: the `webllm`
398
+ and `chrome-ai` entry points, their peer dependency and the demo's worker are gone. Releasing is
399
+ wired in `.github/workflows/release.yml`: a version tag packs the tarball, attaches it to the GitHub
400
+ release, and stages the package on npm for approval, so no CI-held credential can publish on its own.
401
+ It is running in production on shobyde.com.
402
+
403
+ 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;QACd,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,yCAAyC;QAChD,MAAM,EAAE,sDAAsD;KAC/D;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,gCAAgC;QACvC,MAAM,EAAE,sFAAsF;KAC/F;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,6CAA6C;QACpD,MAAM,EAAE,iFAAiF;KAC1F;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,yCAAyC;QAChD,MAAM,EAAE,oFAAoF;KAC7F;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,4CAA4C;QACnD,MAAM,EAAE,uFAAuF;KAChG;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,2CAA2C;QAClD,MAAM,EAAE,+FAA+F;KACxG;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,oBAAoB;QAC3B,MAAM,EAAE,8EAA8E;KACvF;IACD;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,uCAAuC;QAC9C,MAAM,EAAE,qDAAqD;KAC9D;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAmC,MAAM,CAAC,WAAW,CAC1E,gBAAgB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CACrD,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,IAAI,OAAO,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { AgentManifest, ManifestCapability } from '../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,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,gBAAgB,EAAE,CAAC;IACjC,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AA2QD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG;IAC1D,YAAY,EAAE,gBAAgB,EAAE,CAAC;IACjC,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CA0FA;AAoCD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAiFzF;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,aAAa,CAS7E;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,CAE5D"}