driverkit 0.0.1 → 0.1.0
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/package.json +10 -1
- package/REACT.md +0 -477
package/package.json
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "driverkit",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Make a web app drivable by an agent. No pixels, no selectors, no model.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Nideesh1/driver.git",
|
|
9
|
+
"directory": "packages/driverkit"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Nideesh1/driver#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Nideesh1/driver/issues"
|
|
14
|
+
},
|
|
6
15
|
"type": "module",
|
|
7
16
|
"//exports": [
|
|
8
17
|
"One install, one version, one changelog. The five areas are subpaths rather",
|
package/REACT.md
DELETED
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
# `driverkit/react`
|
|
2
|
-
|
|
3
|
-
A second, optional panel, for a team that already has React.
|
|
4
|
-
|
|
5
|
-
`mountWidget` — `driverkit/widget` — is hand-written DOM in a shadow root with
|
|
6
|
-
zero dependencies, and that is the right shape for a drop-in: it goes into a
|
|
7
|
-
Thymeleaf template, a Rails view or a static page, and the host ends up owning
|
|
8
|
-
no version of anything it did not pick. It is the wrong shape for a team that
|
|
9
|
-
has React, a design system and an opinion about what their product looks like.
|
|
10
|
-
For them the shadow root is a wall around the panel and the hand-written markup
|
|
11
|
-
is something to fight.
|
|
12
|
-
|
|
13
|
-
So there are two panels. **This one changes nothing about the other one: the
|
|
14
|
-
vanilla widget's dependency count is still zero and its behaviour is
|
|
15
|
-
untouched.** An app that imports neither pays for neither.
|
|
16
|
-
|
|
17
|
-
Pre-release, like the rest of the library: nothing is published.
|
|
18
|
-
|
|
19
|
-
This entry point **has** now been rendered by a real React — `react` and
|
|
20
|
-
`react-dom` are dev dependencies of the workspace and
|
|
21
|
-
`test/react-dom.test.ts` renders the panel into jsdom, clicks its buttons and
|
|
22
|
-
watches where focus goes. That is new, and it mattered: the first render under
|
|
23
|
-
`StrictMode` found a panel that rendered correctly and then ignored every
|
|
24
|
-
instruction typed into it, and the first real `ref` found the receipt stealing
|
|
25
|
-
focus on every phase change rather than once. Both are fixed and both are
|
|
26
|
-
pinned. What is still unproven is written down in *What has not been rendered*
|
|
27
|
-
at the bottom.
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Install
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
npm install driverkit
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
React is an **optional peer dependency**. If you do not import
|
|
38
|
-
`driverkit/react`, React is not installed, is not in your lockfile, and is not
|
|
39
|
-
referenced by any declaration file the package publishes. See *How the optional
|
|
40
|
-
peer is enforced* below, which is a shorter section than you might expect
|
|
41
|
-
because the mechanism is mostly subtraction.
|
|
42
|
-
|
|
43
|
-
## Bind it to your React, once
|
|
44
|
-
|
|
45
|
-
```tsx
|
|
46
|
-
// src/driver-panel.tsx — one file you own
|
|
47
|
-
import * as React from "react";
|
|
48
|
-
import { createDriverPanel } from "driverkit/react";
|
|
49
|
-
|
|
50
|
-
export const { DriverPanel, useDriver, components } = createDriverPanel(React);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Everything after that line is ordinary React.
|
|
54
|
-
|
|
55
|
-
**Why that line exists**, since it is the first thing anybody will object to.
|
|
56
|
-
React's hook dispatcher is module-level mutable state, so a component built
|
|
57
|
-
against a different copy of `react` than the one rendering it throws "Invalid
|
|
58
|
-
hook call" — or, with a bundler that hoisted two versions, silently reads the
|
|
59
|
-
wrong dispatcher. A library that imports its own `react` can get that second
|
|
60
|
-
copy through a version mismatch, a nested `node_modules`, a monorepo hoist, or
|
|
61
|
-
an app that loads React from a CDN while the bundle resolves it from disk.
|
|
62
|
-
Taking the runtime as an argument makes it impossible: the only React that can
|
|
63
|
-
be passed is the one the host already has. It is the same argument
|
|
64
|
-
`driverkit/otel` makes about taking a `Tracer` instead of importing
|
|
65
|
-
`@opentelemetry/api`, and it is stronger here, because this failure is one the
|
|
66
|
-
adopter cannot debug from inside their own app.
|
|
67
|
-
|
|
68
|
-
The cost is real and it is one line. What is lost is `import { DriverPanel }
|
|
69
|
-
from "driverkit/react"` in forty files instead of re-exporting it from one.
|
|
70
|
-
|
|
71
|
-
That line also has to *typecheck*, which is a separate claim from compiling:
|
|
72
|
-
the React API is described structurally in `src/react/runtime.ts`, and a
|
|
73
|
-
structural description written against types nobody in this repository could
|
|
74
|
-
resolve is a description that can simply be wrong. It was. `ReactRuntime`
|
|
75
|
-
required a `useCallback` this area never calls, typed loosely enough that
|
|
76
|
-
React's own `<T extends Function>` signature did not satisfy it — so
|
|
77
|
-
`createDriverPanel(React)` was a type error in the adopter's own file, on the
|
|
78
|
-
first line of this document. `test/react-dom.test.ts` now assigns React's
|
|
79
|
-
module namespace to `ReactRuntime`, so `tsc` answers that question instead of
|
|
80
|
-
this paragraph.
|
|
81
|
-
|
|
82
|
-
## Use it
|
|
83
|
-
|
|
84
|
-
### The hook is the library
|
|
85
|
-
|
|
86
|
-
```tsx
|
|
87
|
-
function Assistant({ driver }: { driver: Driver }) {
|
|
88
|
-
const d = useDriver(driver, { think: backendThink("/api/chat") });
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<YourPanel>
|
|
92
|
-
{d.entries.map((e) => <YourRow key={e.id} entry={e} />)}
|
|
93
|
-
{d.pending && <YourApprovalCard entry={d.pending} onDecide={d.decide} />}
|
|
94
|
-
<YourComposer onSubmit={d.ask} busy={d.busy} />
|
|
95
|
-
</YourPanel>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
`useDriver` is the whole thing: the conversation, the approval gate, the run
|
|
101
|
-
controls, the budget and the receipts, as plain data and plain functions. A host
|
|
102
|
-
that renders none of our components still gets all of the behaviour. This is
|
|
103
|
-
deliberately what the documentation leads with — a team adopting this has a
|
|
104
|
-
design system, and headless-with-defaults is the only shape that respects one.
|
|
105
|
-
|
|
106
|
-
### The panel is one assembly of it
|
|
107
|
-
|
|
108
|
-
```tsx
|
|
109
|
-
<DriverPanel
|
|
110
|
-
driver={driver}
|
|
111
|
-
options={{ think: backendThink("/api/chat") }}
|
|
112
|
-
placeholder="Ask about your contacts"
|
|
113
|
-
/>
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Every part is replaceable, one at a time:
|
|
117
|
-
|
|
118
|
-
```tsx
|
|
119
|
-
<DriverPanel
|
|
120
|
-
driver={driver}
|
|
121
|
-
options={{ think }}
|
|
122
|
-
components={{ ApprovalCard: OurApprovalCard }}
|
|
123
|
-
Prose={OurMarkdown}
|
|
124
|
-
/>
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Both surfaces, rather than one, because the two audiences are real: a single
|
|
128
|
-
`<DriverPanel />` would make the design-system team reimplement the gate, which
|
|
129
|
-
is the one thing in here nobody should be reimplementing.
|
|
130
|
-
|
|
131
|
-
### The gate, for a commit that did not come from this panel
|
|
132
|
-
|
|
133
|
-
An agent over the relay or MCP can call a `commit` too, and that call never
|
|
134
|
-
touches `drive`'s `onBeforeCommit`. Wire this panel's card up as the core's
|
|
135
|
-
approver and one question covers every path:
|
|
136
|
-
|
|
137
|
-
```tsx
|
|
138
|
-
let panel: PanelStore;
|
|
139
|
-
const driver = mount({ …, approve: (req) => panel.approve(req) });
|
|
140
|
-
// and from the component, once it has rendered:
|
|
141
|
-
const d = useDriver(driver, { think });
|
|
142
|
-
panel = d.store;
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
When the core is already asking — the app's own `approve` hook, or a dialog
|
|
146
|
-
adopted by something else on the page — the panel installs no gate of its own.
|
|
147
|
-
Two questions about one commit is how people learn to click Yes without reading,
|
|
148
|
-
and the next one they skip is the bulk accept.
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## The approval receipt
|
|
153
|
-
|
|
154
|
-
This is the feature the area was built for, and it is the one place the panel
|
|
155
|
-
is better than the vanilla one.
|
|
156
|
-
|
|
157
|
-
**The card does not disappear when you decide. It becomes a receipt in place:
|
|
158
|
-
same element, same id, same position in scrollback, the question's own words
|
|
159
|
-
intact, and the button row replaced by a `role="status"` line.** The gate is the
|
|
160
|
-
only auditable feature in the library, and auditability happens in scrollback —
|
|
161
|
-
a card that unmounted on decision and left a loose outcome line somewhere below
|
|
162
|
-
would break the link between the question and its answer, which is exactly the
|
|
163
|
-
link somebody scrolling back for "what did I agree to" is following.
|
|
164
|
-
|
|
165
|
-
The phases, which are what a reader of that receipt needs distinguished:
|
|
166
|
-
|
|
167
|
-
| phase | what it says |
|
|
168
|
-
| --- | --- |
|
|
169
|
-
| `asking` | the buttons are live and nothing has happened |
|
|
170
|
-
| `allowed` | a person said yes and the verb is now running |
|
|
171
|
-
| `allowed-ok` | the verb ran and the app said ok |
|
|
172
|
-
| `allowed-refused` | the verb ran and **the app refused it anyway** |
|
|
173
|
-
| `denied` | a person said no |
|
|
174
|
-
| `stopped` | the run was stopped before the verb ran; nobody refused it |
|
|
175
|
-
| `lapsed` | the panel closed with the question open; nobody answered |
|
|
176
|
-
|
|
177
|
-
`allowed-refused` is the one worth pointing at. "You approved this" and "this
|
|
178
|
-
happened" are different facts, and a receipt recording only the first would be
|
|
179
|
-
recording the more flattering of the two. A stale rev, a spent budget or a plan
|
|
180
|
-
token that no longer matches all land there. `receiptLine(entry)` is exported so
|
|
181
|
-
a replacement card keeps the wording without re-deriving it from the phase.
|
|
182
|
-
|
|
183
|
-
`stopped` and `lapsed` are kept apart from `denied` for the reason the core
|
|
184
|
-
keeps `timed-out` apart from `declined`: a record that cannot tell "a person
|
|
185
|
-
refused" from "nobody was there" is the record this whole mechanism exists to
|
|
186
|
-
stop writing. The two are a question of ordering as well as of vocabulary, and
|
|
187
|
-
the store decides it deliberately: closing a panel with a question open lapses
|
|
188
|
-
the question *before* it aborts the run, because the abort would otherwise
|
|
189
|
-
answer it `stopped` and record the less true of the two available facts.
|
|
190
|
-
|
|
191
|
-
**Where focus goes, and once.** The status line is also a focus target —
|
|
192
|
-
`tabIndex={-1}`, so it can be focused programmatically and is not a tab stop —
|
|
193
|
-
and focus moves to it the first time the phase leaves `asking`, so somebody who
|
|
194
|
-
pressed a button lands on the answer rather than on whatever followed the
|
|
195
|
-
buttons that have just gone. It moves **once**: a receipt that took focus again
|
|
196
|
-
when the app's verdict arrived a moment later would pull somebody out of the
|
|
197
|
-
message they had started typing. The region itself is therefore mounted once
|
|
198
|
-
and stays, and only the line inside it is keyed on the phase. A replacement
|
|
199
|
-
card that remounts the region per phase gets both halves wrong — the focus
|
|
200
|
-
moves again, and the node holding focus leaves the document — which is not a
|
|
201
|
-
guess: it is what this one did until it was rendered with React.
|
|
202
|
-
|
|
203
|
-
### Standing rules — off by default
|
|
204
|
-
|
|
205
|
-
With `grants: true` the card also offers "Always allow" / "Always refuse". Two
|
|
206
|
-
rules hold, and both are load-bearing:
|
|
207
|
-
|
|
208
|
-
- **The rule is shown in full before the click**, in the same string that is
|
|
209
|
-
then stored, so nobody installs a rule whose text they have not read.
|
|
210
|
-
- **Grants live for this panel and this page load.** Nothing is written to
|
|
211
|
-
storage, deliberately: a standing approval that came back after a reload, in a
|
|
212
|
-
session nobody remembers granting it in, is worse than asking again.
|
|
213
|
-
`PanelSnapshot.grants` is on the snapshot so a host can render the list, and
|
|
214
|
-
`revoke(verb)` takes one away — a grant nobody can see is a grant nobody can
|
|
215
|
-
revoke.
|
|
216
|
-
|
|
217
|
-
A commit answered by a rule is still posted as a receipt, naming the rule that
|
|
218
|
-
answered. A rule that silenced the question must not also silence the record.
|
|
219
|
-
|
|
220
|
-
On the core's `approve` path such a commit answers `{ asked: false }` rather
|
|
221
|
-
than `true`, because nobody *was* asked this time, and that is the answer the
|
|
222
|
-
core added for exactly this case. **An app that needs every allowed commit to
|
|
223
|
-
carry a person's yes in the audit record should leave `grants` off.** (On
|
|
224
|
-
`drive`'s `onBeforeCommit` path there is no `{ asked: false }` to return — it is
|
|
225
|
-
a `CommitDecision`, not an `Approval` — so a grant there can only say `true`,
|
|
226
|
-
and the richer record lives only in the panel. That asymmetry is the core's, not
|
|
227
|
-
ours.)
|
|
228
|
-
|
|
229
|
-
### Notes — off by default
|
|
230
|
-
|
|
231
|
-
With `notes: true` the card offers a free-text field. On a *denial* the note
|
|
232
|
-
becomes the hint the model is told, which is a real feature of the gate rather
|
|
233
|
-
than decoration: `CommitDecision` takes a string, and "not until finance signs
|
|
234
|
-
off" is something a model can act on where "declined" is not.
|
|
235
|
-
|
|
236
|
-
**Typing in it never approves anything.** The note is read only when a decision
|
|
237
|
-
button is pressed, Enter in the field does not submit, and there is deliberately
|
|
238
|
-
no API that takes a note on its own. On a decision the approval itself is the
|
|
239
|
-
authorization; a gate that inferred consent from a typed explanation would let
|
|
240
|
-
the explanation authorize the call.
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
## The markdown seam
|
|
245
|
-
|
|
246
|
-
**Markdown rendering is not built here and must not be.** It is being built for
|
|
247
|
-
the vanilla widget. When it lands, this is where it plugs in:
|
|
248
|
-
|
|
249
|
-
```tsx
|
|
250
|
-
const Prose: ProseRenderer = ({ text }) => /* nodes */;
|
|
251
|
-
<DriverPanel … Prose={Prose} />
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
What the seam guarantees to whatever fills it:
|
|
255
|
-
|
|
256
|
-
- **`text` is the model's complete text for one turn.** `onSay` delivers a whole
|
|
257
|
-
turn at once — driverkit does not stream tokens — so a renderer never sees a
|
|
258
|
-
half-written fence, never has to parse incrementally, and needs none of the
|
|
259
|
-
streaming-markdown machinery the rest of the world needs.
|
|
260
|
-
- It is called during render, so it must be pure. Memoize an expensive parse in
|
|
261
|
-
the host.
|
|
262
|
-
- **It returns nodes, never HTML.** The prop is a component precisely so that
|
|
263
|
-
the escape hatch cannot be `dangerouslySetInnerHTML` over a model's output,
|
|
264
|
-
which is the least trusted thing on the screen. Nothing in this area injects
|
|
265
|
-
HTML and a test pins that.
|
|
266
|
-
|
|
267
|
-
The default renderer is the identity: the model's text, as text. Plugging
|
|
268
|
-
markdown in is replacing something rather than filling a hole.
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
## How the optional peer is enforced
|
|
273
|
-
|
|
274
|
-
Four things have to hold, and three of them are subtraction.
|
|
275
|
-
|
|
276
|
-
1. **`peerDependencies: { react: ">=18" }` with
|
|
277
|
-
`peerDependenciesMeta: { react: { optional: true } }`.** This is what stops
|
|
278
|
-
npm installing React for somebody who does not want it, and stops it warning
|
|
279
|
-
about a peer they correctly do not have. `>=18` because
|
|
280
|
-
`useSyncExternalStore` is an 18 API and it is the one that makes this area
|
|
281
|
-
small.
|
|
282
|
-
2. **React is in no `dependencies`.** The package's only dependency is
|
|
283
|
-
`@types/node`, which the relay's own declarations need.
|
|
284
|
-
3. **No file in the package imports `react`, in any form, including
|
|
285
|
-
`import type`.** This is the one that peer-optional alone does not buy: an
|
|
286
|
-
`import type { ReactNode } from "react"` in a published `.d.ts` is a dangling
|
|
287
|
-
module reference for every consumer who did not install React. There is
|
|
288
|
-
nothing to dangle because the React API is typed structurally in
|
|
289
|
-
`src/react/runtime.ts` and passed in.
|
|
290
|
-
4. **`./react` is reachable only by naming it.** Nothing in `core`, `agent`,
|
|
291
|
-
`widget`, `controls`, `browser`, `check`, `otel` or `relay` imports this
|
|
292
|
-
area, so the module graph of somebody importing only `driverkit` does not
|
|
293
|
-
contain it.
|
|
294
|
-
|
|
295
|
-
Proved in `test/packaging.test.ts`, in the style of the entry-point tests
|
|
296
|
-
already there:
|
|
297
|
-
|
|
298
|
-
- `./react` resolves under browser conditions like every other non-relay entry,
|
|
299
|
-
with `types` before `default`.
|
|
300
|
-
- the peer is declared, optional, and absent from `dependencies`.
|
|
301
|
-
- the emitted JavaScript for `dist/react` names **no** bare specifier — not even
|
|
302
|
-
`react` — so a page can load it from a plain URL with no import map.
|
|
303
|
-
- walking the emitted imports from `dist/core/index.js` transitively never
|
|
304
|
-
reaches `dist/react/`.
|
|
305
|
-
|
|
306
|
-
**A test-time renderer is not a shipped dependency.** `react`, `react-dom` and
|
|
307
|
-
`jsdom` are dev dependencies of the *workspace* — the repository root, not the
|
|
308
|
-
package — so they are in this repository's lockfile and in nobody's install.
|
|
309
|
-
All four assertions above are about `packages/driverkit/package.json` and the
|
|
310
|
-
files under `dist/`, and all four still hold with React on disk; the one that
|
|
311
|
-
would have noticed a slip is the probe that loads `dist/react/index.js` in a
|
|
312
|
-
child `node` and checks it names no bare specifier at all.
|
|
313
|
-
|
|
314
|
-
## What is feature-equivalent, and what is deliberately not
|
|
315
|
-
|
|
316
|
-
Equivalent, and tested:
|
|
317
|
-
|
|
318
|
-
- the conversation: sending instructions, the model's replies, the stop notes
|
|
319
|
-
- **the approval gate**, under the same three options (`confirmCommits`,
|
|
320
|
-
`commitAskAbove`, `confirmEveryCommit`), the same `reversible` reading, the
|
|
321
|
-
same size check, the same `{ asked: false }` for a commit nobody was asked
|
|
322
|
-
about, and the same no-other-calls lock held while a question is open
|
|
323
|
-
- the run controls: pause, resume, single-step, and a visible, changeable pace
|
|
324
|
-
that reaches the run already in flight
|
|
325
|
-
- the session budget, where a ceiling is declared
|
|
326
|
-
- stop, and a clear that takes a dying run's events with it
|
|
327
|
-
|
|
328
|
-
Deliberately not:
|
|
329
|
-
|
|
330
|
-
- **No launcher, no drag, no snapping, no corner.** Those exist because the
|
|
331
|
-
vanilla widget has to place itself in a page nobody told it about. Here the
|
|
332
|
-
host renders the panel in its own layout.
|
|
333
|
-
- **No shadow root.** The vanilla panel needs one because it renders into an app
|
|
334
|
-
whose CSS it has never seen. A React app has a CSS isolation story of its own,
|
|
335
|
-
and a shadow root would break it — the host's own class names would not reach
|
|
336
|
-
inside, which is the opposite of the point.
|
|
337
|
-
- **No stylesheet at all.** Class names (`dk-step`, `dk-ask`, …) and
|
|
338
|
-
`data-dk` / `data-phase` / `data-status` attributes are emitted for you to
|
|
339
|
-
style. The one exception is the inline clip on the screen-reader-only status
|
|
340
|
-
regions, which is not a look: a `role="status"` that is `display: none` is not
|
|
341
|
-
announced.
|
|
342
|
-
- **No `localStorage`.** The vanilla panel remembers a viewer's pace and
|
|
343
|
-
position because it has nowhere else to put them. A React app has a user
|
|
344
|
-
object and a server, and a library writing to `localStorage` behind its back
|
|
345
|
-
is a surprise. Pace, step mode and confirmations are state with setters; the
|
|
346
|
-
host persists them if it wants to.
|
|
347
|
-
- **No element highlighting.** `at` is on every step entry and `onAim` fires
|
|
348
|
-
with it, which is the seam. The outline itself is DOM drawn outside React's
|
|
349
|
-
tree into a page whose stacking and transforms belong to the host, and a React
|
|
350
|
-
app that wants it can draw it with the tools it already has.
|
|
351
|
-
- **No settings view.** Four preferences and a budget row is a design-system
|
|
352
|
-
decision, and the state is all on the snapshot.
|
|
353
|
-
|
|
354
|
-
## The vanilla design decisions, kept and dropped
|
|
355
|
-
|
|
356
|
-
| vanilla decision | here | why |
|
|
357
|
-
| --- | --- | --- |
|
|
358
|
-
| shadow root | **dropped** | a React app's CSS isolation is its own, and a shadow root breaks it |
|
|
359
|
-
| fixed-size launcher ("Ask", never the app's name) | **dropped** | there is no launcher; the host places the panel |
|
|
360
|
-
| `textContent` over `innerHTML` | **kept, restated** | React escapes by default; the rule becomes "nothing here calls `dangerouslySetInnerHTML`", including at the markdown seam |
|
|
361
|
-
| the `era` counter on Clear | **kept** | React does not help: a `setState` from an async callback that outlived a Clear is exactly as wrong as the `appendChild` it replaced |
|
|
362
|
-
| the commit gate's three options and the `reversible` reading | **kept, identically** | one of the two panels being laxer than the other would make "which panel is this app using" a security question |
|
|
363
|
-
| row text that reads the same pending or finished (state as a class, never as words) | **kept** | a step row is a record |
|
|
364
|
-
| "No" focused / reached first, "Yes" one key further | **kept** | a person pressing Enter on a card that appeared while they were typing must not thereby accept a thousand rows |
|
|
365
|
-
| the step row appearing on `onBeforeCall`, before the pace wait | **kept** | the only way "you can see it coming and stop it" is true rather than aspirational |
|
|
366
|
-
| named speeds rather than a free slider | **kept** | milliseconds are not a thing anybody has an opinion about, and four labelled radios are keyboard-reachable without anybody being careful forever |
|
|
367
|
-
| `aria-live="polite"` on the whole transcript | **dropped as a bug** | at a 600ms pace the region is re-read as each step row lands, so the person hears a growing conversation from the top instead of what just changed. State is announced instead, in one-sentence `role="status"` regions that stay in the document, each with a keyed line inside it so a change replaces a node rather than editing one |
|
|
368
|
-
| the approval row keeping its outcome line | **kept and extended** | the vanilla row survives and records that *you* answered; this also records what the *app* then did, which is the half that turns a decision into a record of a change |
|
|
369
|
-
|
|
370
|
-
## What a React adopter can get wrong that the vanilla widget made impossible
|
|
371
|
-
|
|
372
|
-
Worth reading once; each of these is a shape the DOM version had no way to
|
|
373
|
-
express.
|
|
374
|
-
|
|
375
|
-
- **Rendering the transcript inside a live region.** The vanilla panel owns its
|
|
376
|
-
markup, so its (wrong) `aria-live` was at least one wrong thing in one place.
|
|
377
|
-
A host that wraps `<DriverPanel />` in its own `aria-live="polite"` container,
|
|
378
|
-
or in a design-system `<Toast>` that is one, reproduces the bug from outside
|
|
379
|
-
and nothing in here can stop it.
|
|
380
|
-
- **Replacing `ApprovalCard` with one that unmounts on decision.** The receipt
|
|
381
|
-
is the product. A card that returns `null` once `phase !== "asking"`, or that
|
|
382
|
-
renders decided approvals into a separate "history" list, throws away the
|
|
383
|
-
question/answer link in scrollback. If you replace the card, keep the entry
|
|
384
|
-
rendered in place.
|
|
385
|
-
- **Treating `pending` as a modal.** `d.pending` is convenient and it is also
|
|
386
|
-
the entry that is already in `entries`. Rendering it a second time in a dialog
|
|
387
|
-
gives two live "Yes" buttons for one commit.
|
|
388
|
-
- **Keying transcript entries by index.** Entries are appended and patched in
|
|
389
|
-
place; `entry.id` is stable and an index is not, so an index key will make a
|
|
390
|
-
receipt inherit another entry's state mid-run.
|
|
391
|
-
- **Calling `useDriver` twice for one driver.** Two stores means two gates, and
|
|
392
|
-
the second one's `onBeforeCommit` is a second question about one commit. One
|
|
393
|
-
store per driver; lift it if two components need it. (One hook rendered
|
|
394
|
-
twice under `StrictMode` is *not* this: that builds one store, and a test
|
|
395
|
-
pins it.)
|
|
396
|
-
- **Expecting an options change to take effect.** The store is built once per
|
|
397
|
-
`driver` and the options are read then. The things a person changes while
|
|
398
|
-
watching a run — pace, step mode, confirmations — are state with setters for
|
|
399
|
-
exactly that reason. Re-key the component if you genuinely need new options.
|
|
400
|
-
- **Persisting grants.** If you add storage for `PanelSnapshot.grants`, you have
|
|
401
|
-
changed what a standing approval means. See above.
|
|
402
|
-
|
|
403
|
-
## StrictMode, and what the hook does about it
|
|
404
|
-
|
|
405
|
-
Worth one section because it is the configuration every React app runs in
|
|
406
|
-
development, and because this area got it wrong.
|
|
407
|
-
|
|
408
|
-
`StrictMode` double-invokes a component's body and, since React 18, also runs
|
|
409
|
-
each mount effect's **cleanup and then the effect again**. The second half is
|
|
410
|
-
the one that bites a library holding a resource: the obvious
|
|
411
|
-
`useEffect(() => () => store.destroy(), [store])` therefore destroys the store
|
|
412
|
-
during mount, and `destroy` is final — it clears the listeners and latches the
|
|
413
|
-
store closed, so `ask` returns immediately and the panel renders perfectly
|
|
414
|
-
while doing nothing at all. That is what this hook did in `70ca8aa`, and no
|
|
415
|
-
framework-free test could see it, because nothing in one runs an effect twice.
|
|
416
|
-
|
|
417
|
-
What it does now:
|
|
418
|
-
|
|
419
|
-
- **The store is built lazily in render and kept in a ref**, so the
|
|
420
|
-
double-invoked render finds the one it already made. `useMemo` would not do:
|
|
421
|
-
React may double-invoke a memo factory, and two stores for one driver means
|
|
422
|
-
two gates.
|
|
423
|
-
- **Render tears nothing down.** A `driver` change no longer destroys the
|
|
424
|
-
outgoing store from inside render — a render may be discarded, and destroying
|
|
425
|
-
a live store speculatively would abort a run that is still on screen. The
|
|
426
|
-
effect owns every teardown.
|
|
427
|
-
- **The teardown is a hold count, decided one microtask late.** The cleanup
|
|
428
|
-
gives up its hold; only a hold count still at zero on the next microtask is a
|
|
429
|
-
real unmount. StrictMode's remount re-takes the hold first, so the store
|
|
430
|
-
survives with its conversation intact.
|
|
431
|
-
- **A mount onto a store somebody already destroyed builds a new one**, through
|
|
432
|
-
`PanelStore.destroyed`. That is the hidden-then-re-shown case — `<Activity>`
|
|
433
|
-
far enough apart that the microtask already ran — where nothing can revive
|
|
434
|
-
the store. The conversation is gone in that case; the panel is not.
|
|
435
|
-
|
|
436
|
-
## What has not been rendered
|
|
437
|
-
|
|
438
|
-
Honest list, since the top of this file now claims rather a lot more than it
|
|
439
|
-
used to.
|
|
440
|
-
|
|
441
|
-
- **jsdom is not a browser.** It lays nothing out and has no screen reader, so
|
|
442
|
-
"the status region is announced" is not asserted anywhere and cannot be. What
|
|
443
|
-
is asserted is the structure that makes it possible. The vanilla widget's
|
|
444
|
-
equivalent claims meet a real Chrome in `e2e/`; this panel's do not, because
|
|
445
|
-
the demo in `examples/` is the vanilla one.
|
|
446
|
-
- **No concurrent-rendering stress.** `useSyncExternalStore` is what makes the
|
|
447
|
-
panel tear-free under a transition, and that is React's guarantee rather than
|
|
448
|
-
a tested one here. What was removed was the thing that would break it: render
|
|
449
|
-
no longer has side effects.
|
|
450
|
-
- **One React.** The tests run against React 19. The peer range is `>=18`
|
|
451
|
-
because `useSyncExternalStore` is an 18 API; nothing here has been rendered by
|
|
452
|
-
an 18.
|
|
453
|
-
- **No React Server Components.** `useDriver` is a client hook over a live
|
|
454
|
-
driver and a browser event stream; the panel has never been near an RSC
|
|
455
|
-
boundary, and `"use client"` is the host's to write.
|
|
456
|
-
|
|
457
|
-
## Reference
|
|
458
|
-
|
|
459
|
-
```ts
|
|
460
|
-
createDriverPanel(react): { useDriver, DriverPanel, components }
|
|
461
|
-
|
|
462
|
-
useDriver(driver, options): Driving
|
|
463
|
-
// entries, busy, runState, paceMs, permits, stepMode, confirmCommits,
|
|
464
|
-
// budget?, grants, pending?, era
|
|
465
|
-
// ask, stop, clear, pause, resume, step, setPace, setStepMode,
|
|
466
|
-
// setConfirmCommits, decide, revoke, approve, store
|
|
467
|
-
|
|
468
|
-
createPanelStore(driver, options): PanelStore // the same thing, without React
|
|
469
|
-
receiptLine(entry): string // what a receipt says
|
|
470
|
-
stepOutcome(ok, refused?, count?): string // what a step row says
|
|
471
|
-
COMMIT_ASK_ABOVE // 25, as in the vanilla widget
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
`PanelOptions`: `think`, `instructions`, `maxSteps`, `refusalLimit`, `greeting`,
|
|
475
|
-
`confirmCommits`, `commitAskAbove`, `confirmEveryCommit`, `onBeforeCommit`,
|
|
476
|
-
`grants`, `notes`, `pace`, `stepMode`, `controls`, `clock`, `onAim`, `onError`,
|
|
477
|
-
`AbortController`.
|