driverkit 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTROLS.md +578 -0
- package/REACT.md +477 -0
- package/README.md +104 -2
- package/dist/agent/backend.d.ts +69 -0
- package/dist/agent/backend.d.ts.map +1 -0
- package/dist/agent/backend.js +130 -0
- package/dist/agent/backend.js.map +1 -0
- package/dist/agent/control.d.ts +148 -0
- package/dist/agent/control.d.ts.map +1 -0
- package/dist/agent/control.js +342 -0
- package/dist/agent/control.js.map +1 -0
- package/dist/agent/index.d.ts +9 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +6 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/loop.d.ts +136 -0
- package/dist/agent/loop.d.ts.map +1 -0
- package/dist/agent/loop.js +824 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/render.d.ts +173 -0
- package/dist/agent/render.d.ts.map +1 -0
- package/dist/agent/render.js +425 -0
- package/dist/agent/render.js.map +1 -0
- package/dist/agent/tools.d.ts +138 -0
- package/dist/agent/tools.d.ts.map +1 -0
- package/dist/agent/tools.js +622 -0
- package/dist/agent/tools.js.map +1 -0
- package/dist/agent/types.d.ts +566 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +32 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/browser/budget.d.ts +92 -0
- package/dist/browser/budget.d.ts.map +1 -0
- package/dist/browser/budget.js +151 -0
- package/dist/browser/budget.js.map +1 -0
- package/dist/browser/connect.d.ts +368 -0
- package/dist/browser/connect.d.ts.map +1 -0
- package/dist/browser/connect.js +1038 -0
- package/dist/browser/connect.js.map +1 -0
- package/dist/browser/elsewhere.d.ts +89 -0
- package/dist/browser/elsewhere.d.ts.map +1 -0
- package/dist/browser/elsewhere.js +91 -0
- package/dist/browser/elsewhere.js.map +1 -0
- package/dist/browser/frames.d.ts +85 -0
- package/dist/browser/frames.d.ts.map +1 -0
- package/dist/browser/frames.js +11 -0
- package/dist/browser/frames.js.map +1 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +9 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/check/check.d.ts +171 -0
- package/dist/check/check.d.ts.map +1 -0
- package/dist/check/check.js +666 -0
- package/dist/check/check.js.map +1 -0
- package/dist/check/index.d.ts +3 -0
- package/dist/check/index.d.ts.map +1 -0
- package/dist/check/index.js +2 -0
- package/dist/check/index.js.map +1 -0
- package/dist/check/types.d.ts +149 -0
- package/dist/check/types.d.ts.map +1 -0
- package/dist/check/types.js +29 -0
- package/dist/check/types.js.map +1 -0
- package/dist/controls/controls.d.ts +198 -0
- package/dist/controls/controls.d.ts.map +1 -0
- package/dist/controls/controls.js +742 -0
- package/dist/controls/controls.js.map +1 -0
- package/dist/controls/dom.d.ts +108 -0
- package/dist/controls/dom.d.ts.map +1 -0
- package/dist/controls/dom.js +56 -0
- package/dist/controls/dom.js.map +1 -0
- package/dist/controls/index.d.ts +26 -0
- package/dist/controls/index.d.ts.map +1 -0
- package/dist/controls/index.js +23 -0
- package/dist/controls/index.js.map +1 -0
- package/dist/controls/rows.d.ts +66 -0
- package/dist/controls/rows.d.ts.map +1 -0
- package/dist/controls/rows.js +127 -0
- package/dist/controls/rows.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/registry.d.ts +192 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +2799 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/types.d.ts +2468 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +19 -0
- package/dist/core/types.js.map +1 -0
- package/dist/otel/index.d.ts +122 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +157 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/react/index.d.ts +191 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +547 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/runtime.d.ts +95 -0
- package/dist/react/runtime.d.ts.map +1 -0
- package/dist/react/runtime.js +54 -0
- package/dist/react/runtime.js.map +1 -0
- package/dist/react/store.d.ts +333 -0
- package/dist/react/store.d.ts.map +1 -0
- package/dist/react/store.js +695 -0
- package/dist/react/store.js.map +1 -0
- package/dist/relay/auth.d.ts +244 -0
- package/dist/relay/auth.d.ts.map +1 -0
- package/dist/relay/auth.js +391 -0
- package/dist/relay/auth.js.map +1 -0
- package/dist/relay/frames.d.ts +141 -0
- package/dist/relay/frames.d.ts.map +1 -0
- package/dist/relay/frames.js +20 -0
- package/dist/relay/frames.js.map +1 -0
- package/dist/relay/index.d.ts +8 -0
- package/dist/relay/index.d.ts.map +1 -0
- package/dist/relay/index.js +4 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/relay/relay.d.ts +277 -0
- package/dist/relay/relay.d.ts.map +1 -0
- package/dist/relay/relay.js +1026 -0
- package/dist/relay/relay.js.map +1 -0
- package/dist/relay/serve.d.ts +33 -0
- package/dist/relay/serve.d.ts.map +1 -0
- package/dist/relay/serve.js +86 -0
- package/dist/relay/serve.js.map +1 -0
- package/dist/widget/chat.d.ts +290 -0
- package/dist/widget/chat.d.ts.map +1 -0
- package/dist/widget/chat.js +486 -0
- package/dist/widget/chat.js.map +1 -0
- package/dist/widget/css.d.ts +49 -0
- package/dist/widget/css.d.ts.map +1 -0
- package/dist/widget/css.js +532 -0
- package/dist/widget/css.js.map +1 -0
- package/dist/widget/dom.d.ts +143 -0
- package/dist/widget/dom.d.ts.map +1 -0
- package/dist/widget/dom.js +27 -0
- package/dist/widget/dom.js.map +1 -0
- package/dist/widget/highlight.d.ts +64 -0
- package/dist/widget/highlight.d.ts.map +1 -0
- package/dist/widget/highlight.js +136 -0
- package/dist/widget/highlight.js.map +1 -0
- package/dist/widget/index.d.ts +9 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +20 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget/position.d.ts +166 -0
- package/dist/widget/position.d.ts.map +1 -0
- package/dist/widget/position.js +497 -0
- package/dist/widget/position.js.map +1 -0
- package/dist/widget/settings.d.ts +116 -0
- package/dist/widget/settings.d.ts.map +1 -0
- package/dist/widget/settings.js +117 -0
- package/dist/widget/settings.js.map +1 -0
- package/dist/widget/widget.d.ts +442 -0
- package/dist/widget/widget.d.ts.map +1 -0
- package/dist/widget/widget.js +2005 -0
- package/dist/widget/widget.js.map +1 -0
- package/package.json +144 -4
package/CONTROLS.md
ADDED
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
# Controls
|
|
2
|
+
|
|
3
|
+
driverkit has one layer today, and it is a good one: somebody writes a verb
|
|
4
|
+
list, an agent calls the verbs by name, and a thousand rows move in one call
|
|
5
|
+
with a count in front of them. This document is about the thing that layer
|
|
6
|
+
cannot do, and the second layer that fixes it.
|
|
7
|
+
|
|
8
|
+
## The failure
|
|
9
|
+
|
|
10
|
+
A contacts demo. The verb list had `select-where(company, status?)` and nothing
|
|
11
|
+
else that selected anything. Asked to select one named contact, the model
|
|
12
|
+
refused.
|
|
13
|
+
|
|
14
|
+
It was right to refuse. Its only selection tool would have selected all four
|
|
15
|
+
hundred and ten contacts at that company in order to get one of them, and
|
|
16
|
+
`select-where` is a `describe` verb whose whole purpose is to be the thing that
|
|
17
|
+
happens *before* a commit. The model did the correct thing with the wrong
|
|
18
|
+
vocabulary.
|
|
19
|
+
|
|
20
|
+
The obvious fix is to write a `select-one(id)` verb. Do that and the next
|
|
21
|
+
request is "unsubscribe him from the newsletter", and the next is "switch to
|
|
22
|
+
the compact view", and the next is "dismiss that banner". You cannot enumerate
|
|
23
|
+
your way out of this, because the set of things a person will ask for is not a
|
|
24
|
+
set anybody has. The requirement is plainer than any verb list can satisfy:
|
|
25
|
+
**driverkit needs to be able to do whatever I ask it on the UI** — a button
|
|
26
|
+
click at the small end, multi-step work at the large one.
|
|
27
|
+
|
|
28
|
+
So the gap is structural, not an omission. A curated list is incomplete by
|
|
29
|
+
construction, and no amount of curation fixes a construction.
|
|
30
|
+
|
|
31
|
+
## The two layers
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
controls one action, total coverage press a button, tick a row, type in a field
|
|
35
|
+
shortcuts one call, many rows select-where(company) -- 410 rows, one call, one count
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Neither replaces the other, and the reason is worth being precise about,
|
|
39
|
+
because "add controls and delete the verb list" is the wrong lesson.
|
|
40
|
+
|
|
41
|
+
A shortcut is how bulk work is *safe*. `select-where` resolves a predicate
|
|
42
|
+
inside the app, where the rows already are, reports how many it matched, and a
|
|
43
|
+
`commit` verb then acts on that selection with a number in front of the human.
|
|
44
|
+
Four hundred and ten rows, two calls, one question. The controls layer cannot
|
|
45
|
+
do that at any price: a control is one action on one thing, so four hundred and
|
|
46
|
+
ten rows is four hundred and ten presses, four hundred and ten round trips, and
|
|
47
|
+
an agent that loses its place in the middle. If the answer to a request is a
|
|
48
|
+
predicate, the answer is a shortcut, and writing one is still the single most
|
|
49
|
+
valuable thing an app author can do.
|
|
50
|
+
|
|
51
|
+
A control is how the request nobody anticipated gets done *at all*. It is
|
|
52
|
+
complete by construction rather than by curation: whatever the person at the
|
|
53
|
+
keyboard could press, tick or type into, an agent can too, and the app author
|
|
54
|
+
did not have to foresee it.
|
|
55
|
+
|
|
56
|
+
They compose in one `mount()`. An agent cannot tell which layer a verb came
|
|
57
|
+
from — it sees verb names and a snapshot — which is the same property a verb
|
|
58
|
+
that calls a store action shares with a verb that clicks a marked button.
|
|
59
|
+
|
|
60
|
+
## Where each half lives
|
|
61
|
+
|
|
62
|
+
This is the decision everything else follows from, and getting it backwards
|
|
63
|
+
would quietly destroy the library's cost argument.
|
|
64
|
+
|
|
65
|
+
| | | |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| **static**, cached in the prompt prefix, in the **manifest** | *that* the app can press a control | three verbs, three argument lists |
|
|
68
|
+
| **dynamic**, never cached, in the **snapshot** | *which* controls are on this screen right now | `Snapshot.controls` |
|
|
69
|
+
|
|
70
|
+
A verb is static because its name, arguments and refusals are the same for
|
|
71
|
+
every user on every day. Which buttons exist is not: it changes when you page,
|
|
72
|
+
filter, open a detail panel or switch tab, and it differs between two users
|
|
73
|
+
looking at the same app with different permissions. That is exactly the
|
|
74
|
+
definition of the dynamic half, which is where the rows already live. So the
|
|
75
|
+
controls ride beside the rows, in the uncached tail, and they are small by the
|
|
76
|
+
same discipline: never more than the person at the keyboard can see.
|
|
77
|
+
|
|
78
|
+
### The mistake this split exists to prevent
|
|
79
|
+
|
|
80
|
+
It has an obvious and attractive shape:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// WRONG. Do not do this.
|
|
84
|
+
args: { control: { type: "string", describe: "which control",
|
|
85
|
+
oneOf: ["next-page", "accept-all", "open", "delete"] } }
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
It reads as a kindness. The model cannot then name a control that does not
|
|
89
|
+
exist, it gets an `enum` in its tool schema, and a wrong value comes back from
|
|
90
|
+
the core listing the accepted set. Every one of those is true, and it is still
|
|
91
|
+
the single most expensive line anybody could add to this library.
|
|
92
|
+
|
|
93
|
+
`oneOf` lives in `ArgSpec`, which lives in `Verb`, which lives in the
|
|
94
|
+
**manifest**. Putting a per-screen list there means the cached half changes on
|
|
95
|
+
every navigation, so the prefix is busted once per screen, per user, forever —
|
|
96
|
+
and no two users share a prefix at all, because no two users are looking at the
|
|
97
|
+
same screen. The manifest stops being cacheable, which is the entire reason the
|
|
98
|
+
manifest exists.
|
|
99
|
+
|
|
100
|
+
So `control` is a plain `string`, and it is validated against the page at call
|
|
101
|
+
time instead. The cost is one refusal when a model names a control that is not
|
|
102
|
+
there; the refusal lists the ones that are, so the model fixes it on the next
|
|
103
|
+
turn without another read. There is a test that walks the manifest and asserts
|
|
104
|
+
no argument enumerates anything, because this is the kind of thing somebody
|
|
105
|
+
improves in six months with the best intentions.
|
|
106
|
+
|
|
107
|
+
## The three verbs
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
press describe press a button, tick a checkbox, switch tabs
|
|
111
|
+
type-into describe put text in a field
|
|
112
|
+
commit-control commit use a control that changes data -- or one the app never declared
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
A control's name and an optional `row` are the arguments. `type-into` takes
|
|
116
|
+
`text`; `commit-control` takes it optionally, for a field that commits.
|
|
117
|
+
|
|
118
|
+
### Why three, and why the split is by *kind*
|
|
119
|
+
|
|
120
|
+
`kind` is how an agent knows what is irreversible before it calls, and the
|
|
121
|
+
confirmation gate in `driverkit/agent` fires on `kind === "commit"` and on
|
|
122
|
+
nothing else. `kind` is a property of a **verb**, which is static. The effect
|
|
123
|
+
of pressing a control is a property of the **control**, which is dynamic. One
|
|
124
|
+
generic `press` verb would have to carry one `kind` for every control it could
|
|
125
|
+
ever reach, and both available answers are bad:
|
|
126
|
+
|
|
127
|
+
- `kind: "read"` tells an agent that an unmarked Delete button is free to try.
|
|
128
|
+
- `kind: "commit"` asks the human about paging, sorting and switching tabs. A
|
|
129
|
+
gate that asks about everything is a gate nobody reads, which is the same as
|
|
130
|
+
having no gate while looking like you have one.
|
|
131
|
+
|
|
132
|
+
So the verbs are split along the only line that has to be static: the safe
|
|
133
|
+
door and the gated door. `read` and `describe` controls share the safe door;
|
|
134
|
+
`commit` controls use the gated one. `press` and `type-into` are then two
|
|
135
|
+
mechanisms behind the safe door, because their argument shapes genuinely
|
|
136
|
+
differ — a field takes text and a button has nowhere to put it, and "an
|
|
137
|
+
optional `text` that is required for some values of another argument" is the
|
|
138
|
+
shape the authoring guide tells app authors not to write.
|
|
139
|
+
|
|
140
|
+
The gated door is deliberately **one** verb rather than two. Everything
|
|
141
|
+
irreversible goes through one name, so a host auditing commits has one name to
|
|
142
|
+
watch, and a person being asked has one question shape to recognise.
|
|
143
|
+
|
|
144
|
+
`press` is declared `describe` and not `read`. It presses `read` controls as
|
|
145
|
+
well, so `read` would be the stronger claim — and it would be false the moment
|
|
146
|
+
somebody marks a select-all checkbox `describe`. `describe` is the weakest
|
|
147
|
+
claim that covers both, and `read` and `describe` are treated identically by
|
|
148
|
+
everything downstream (both are "safe to call"), so the collapse costs nothing
|
|
149
|
+
real. Its description says it reports no count, because the generic
|
|
150
|
+
`describe` briefing promises one.
|
|
151
|
+
|
|
152
|
+
### Routing is enforced, in both directions
|
|
153
|
+
|
|
154
|
+
Calling `press` on a control the author declared `commit` is refused
|
|
155
|
+
`wrong-verb`, with a hint naming `commit-control`. That is the direction people
|
|
156
|
+
expect.
|
|
157
|
+
|
|
158
|
+
Calling `commit-control` on a control declared `read` is **also** refused. This
|
|
159
|
+
direction matters more than it looks: without it, a model can route every press
|
|
160
|
+
through the gated verb — plausibly, even helpfully — and the person is asked to
|
|
161
|
+
confirm paging. One control, one verb; the gate stays worth reading.
|
|
162
|
+
|
|
163
|
+
## How `kind` is declared, and what happens when it is not
|
|
164
|
+
|
|
165
|
+
The author declares it in the markup, next to the control:
|
|
166
|
+
|
|
167
|
+
```html
|
|
168
|
+
<button data-dk-control="next-page" data-dk-kind="read">Next</button>
|
|
169
|
+
<input data-dk-control="search" data-dk-kind="describe" placeholder="Search" />
|
|
170
|
+
<button data-dk-control="accept-all" data-dk-kind="commit">Accept all</button>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
In the markup rather than in a config map in the mount file, because the person
|
|
174
|
+
who knows what the handler does is the person editing that line, and a map
|
|
175
|
+
keyed by control name in another file rots the first time somebody renames a
|
|
176
|
+
button. A `kind(name, el)` hook exists for generated or third-party markup you
|
|
177
|
+
cannot annotate; it is consulted first and falling through to the attribute.
|
|
178
|
+
|
|
179
|
+
Nothing can infer this. The library cannot tell a "Next page" button from a
|
|
180
|
+
"Delete account" button, and no amount of looking at the DOM changes that — the
|
|
181
|
+
two differ only in what the handler does, which is code this library cannot
|
|
182
|
+
see. It is the same cost any verb that clicks a button has always carried —
|
|
183
|
+
including the four-line `data-dk` click helper the README shows an app writing
|
|
184
|
+
by hand — and it is why the attribute exists.
|
|
185
|
+
|
|
186
|
+
### An undeclared control is reachable only through the gate
|
|
187
|
+
|
|
188
|
+
This is the load-bearing default, so here is the argument rather than the rule.
|
|
189
|
+
|
|
190
|
+
Three options were available for a control whose author never declared a kind:
|
|
191
|
+
|
|
192
|
+
1. **Default to `read`.** Unacceptable. An unmarked Delete button is then
|
|
193
|
+
described to an agent as free to try, and the agent finds out it was not by
|
|
194
|
+
doing it. The library would be manufacturing a safety claim about code it
|
|
195
|
+
has never seen.
|
|
196
|
+
2. **Default to `commit`.** Every press is a question, including in an app that
|
|
197
|
+
declared nothing because it declared nothing yet. The person clicks through
|
|
198
|
+
the fifth confirmation without reading it and the gate is now decoration.
|
|
199
|
+
3. **Refuse undeclared controls entirely.** Honest, and it throws away the one
|
|
200
|
+
property the layer exists for. An app that marked its buttons and declared
|
|
201
|
+
nothing else would have complete coverage of nothing.
|
|
202
|
+
|
|
203
|
+
What ships is none of those and is closest to (2) with the sting removed:
|
|
204
|
+
**an undeclared control is reported with no `kind` at all, and is reachable
|
|
205
|
+
only through `commit-control`.** So:
|
|
206
|
+
|
|
207
|
+
- The agent is never told an unreviewed button is safe. `ScreenControl.kind` is
|
|
208
|
+
absent, which `Snapshot`'s own doctrine already defines as "no claim", and
|
|
209
|
+
the control is rendered to the model as `(undeclared)` — never as `read`.
|
|
210
|
+
- It is still reachable. Coverage holds. What the missing declaration costs is
|
|
211
|
+
a question to the human, not the action.
|
|
212
|
+
- **The cost decays.** Declare the control and the question goes away. Unlike
|
|
213
|
+
defaulting everything to `commit`, this leaves a well-marked app with a gate
|
|
214
|
+
that fires on the things that actually commit — so the gate goes on meaning
|
|
215
|
+
something, and the incentive points at declaring rather than at ignoring.
|
|
216
|
+
The incentive also points somewhere bad, which is worth saying out loud:
|
|
217
|
+
`data-dk-kind="read"` on everything silences every question in one pass.
|
|
218
|
+
**Declaring a kind is a claim, and nothing here can check it.** The console
|
|
219
|
+
line is therefore worded as a decision the author owes rather than a nuisance
|
|
220
|
+
they can clear: an undeclared control is the safe state and the right place
|
|
221
|
+
to leave one until somebody has read its handler.
|
|
222
|
+
- The author hears about it once, on the console, listing the undeclared
|
|
223
|
+
names. The agent is never told; a diagnostic about the app's markup is not
|
|
224
|
+
information an agent can act on.
|
|
225
|
+
|
|
226
|
+
The treatment is the same one `Snapshot.page.total` gets: take the weakest
|
|
227
|
+
honest claim, and let the cost fall on the cheap side. A redundant
|
|
228
|
+
confirmation costs a round trip and a moment of a person's attention. The
|
|
229
|
+
reverse mistake costs something that cannot be undone.
|
|
230
|
+
|
|
231
|
+
## Keeping the snapshot small
|
|
232
|
+
|
|
233
|
+
A screen with twenty rows and six controls on each row has a hundred and twenty
|
|
234
|
+
marked elements. It must not have a hundred and twenty snapshot entries, and it
|
|
235
|
+
does not have eight.
|
|
236
|
+
|
|
237
|
+
A control found inside one of the rows the snapshot is showing is listed
|
|
238
|
+
**once**, marked `per: "row"`, and addressed by row id:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
controls: search “Search contacts” (text, describe), next-page “Next”, accept-all “Accept all” (commit);
|
|
242
|
+
each row: pick (describe), open, delete (commit)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
await driver.call("press", { control: "open", row: "c-0184" });
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
This works because the twenty copies came out of one template. They are the
|
|
250
|
+
same control rendered twenty times and differ in nothing an agent needs — the
|
|
251
|
+
thing that differs between them is the row, and the row is already in `rows`.
|
|
252
|
+
Row ids are resolved by `rows.ts`, which exists only for this: `data-dk-id` on
|
|
253
|
+
the row, then on any cell, then an `idFrom(row, index)` hook, then the first
|
|
254
|
+
cell's text, then `row<n>` positionally and loudly. An id an agent reads out of
|
|
255
|
+
`rows` has to be an id a control accepts, so put the ids your snapshot reports
|
|
256
|
+
in `data-dk-id` and nothing below the first step ever runs. That file is NOT a
|
|
257
|
+
reader — it produces no `Row`, no cell values and no `page`; the readers that
|
|
258
|
+
used to guess all of that out of markup are gone, and what a control needed
|
|
259
|
+
from them was never the data, only the name.
|
|
260
|
+
|
|
261
|
+
Every field but `name` is omitted when it would state the common case, which is
|
|
262
|
+
why `field` and `disabled` are `true` rather than `boolean`. Eight controls cost
|
|
263
|
+
about one line.
|
|
264
|
+
|
|
265
|
+
There is a `limit`, default 40. Over it the list is cut, says how much it is
|
|
266
|
+
hiding, and warns the author to narrow `root`. A truncated list that admits it
|
|
267
|
+
is truncated costs an agent a step; a two-hundred-entry list costs every turn of
|
|
268
|
+
every session, in the half that is never cached.
|
|
269
|
+
|
|
270
|
+
## Never a selector the library guessed
|
|
271
|
+
|
|
272
|
+
The agent sees `accept`, and `accept` is a word somebody typed next to their own
|
|
273
|
+
button:
|
|
274
|
+
|
|
275
|
+
```html
|
|
276
|
+
<button data-dk-control="accept" onclick={/* whatever lives here */}>Accept</button>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
That is the same claim a hand-written `data-dk` click verb makes and it holds
|
|
280
|
+
for the same reasons: the attribute exists only for this, so restyling, renaming the component,
|
|
281
|
+
swapping CSS framework or translating the label does not touch it; and the agent
|
|
282
|
+
never sees a selector, so it cannot ask for a different element, be prompted
|
|
283
|
+
onto one, or drift onto one when the DOM changes shape.
|
|
284
|
+
|
|
285
|
+
What this layer adds is **enumeration**, and enumeration is not inference. The
|
|
286
|
+
library lists the marks the author made. It does not search by label text, by
|
|
287
|
+
ARIA role, by position, by heuristic or by similarity, and there is no
|
|
288
|
+
"did you mean". A name the screen does not offer is a refusal listing the names
|
|
289
|
+
it does offer — never a near miss, because a near miss is how an agent presses
|
|
290
|
+
Delete when it meant Dismiss. There is a test that fires `Next`, `next`,
|
|
291
|
+
`nextpage`, `next-pag`, `Accept all` and `accept` at a screen offering
|
|
292
|
+
`next-page` and `accept-all`, and asserts that nothing was clicked.
|
|
293
|
+
|
|
294
|
+
`data-dk-control` is deliberately **not** `data-dk`. The two marks say different
|
|
295
|
+
things. `data-dk` says "a verb I wrote, named and described clicks this".
|
|
296
|
+
`data-dk-control` says "publish this to an agent as a control it may use at
|
|
297
|
+
will". Folding them together would silently publish every button an app marked
|
|
298
|
+
so that one of its own verbs could click it, including the ones whose author
|
|
299
|
+
deliberately wrapped them in a narrower verb — and publishing is consent. `{ attribute: "data-dk" }` opts into
|
|
300
|
+
exactly that, once you have looked at the list.
|
|
301
|
+
|
|
302
|
+
### How this differs from `Verb.at`
|
|
303
|
+
|
|
304
|
+
`Verb.at` is a CSS selector and is purely presentational: it exists so a UI can
|
|
305
|
+
outline the part of the screen a verb is about while a human watches, and the
|
|
306
|
+
library never queries it, never resolves it, and never shows it to the model. A
|
|
307
|
+
wrong `at` costs an outline drawn in the wrong place and nothing else.
|
|
308
|
+
|
|
309
|
+
A control is the opposite in every respect: it is a name and not a selector, the
|
|
310
|
+
agent *does* see it, and resolving it is the point. The two must not be
|
|
311
|
+
conflated in either direction. An `at` that the library clicked would be a back
|
|
312
|
+
door straight back to selector automation. A control that the library found by
|
|
313
|
+
guessing would be the same door with a different sign on it.
|
|
314
|
+
|
|
315
|
+
## Refusals
|
|
316
|
+
|
|
317
|
+
All three verbs declare the same six, in the cached half, so a briefed agent
|
|
318
|
+
avoids the call rather than discovering the answer by making it.
|
|
319
|
+
|
|
320
|
+
| slug | means |
|
|
321
|
+
|---|---|
|
|
322
|
+
| `no-such-control` | this screen offers no control by that name. Lists the ones it does. |
|
|
323
|
+
| `no-such-row` | no row with that id is on screen. Lists some that are. |
|
|
324
|
+
| `needs-row` | a per-row control was named with no row. |
|
|
325
|
+
| `not-a-row-control` | a screen control was named with a row. |
|
|
326
|
+
| `wrong-verb` | the right control, the wrong verb. The hint names the right one. |
|
|
327
|
+
| `disabled` | on screen, not actionable right now. |
|
|
328
|
+
|
|
329
|
+
Two of these are the ones that earn the list.
|
|
330
|
+
|
|
331
|
+
**A control that has vanished refuses cleanly.** The element is resolved on
|
|
332
|
+
every call and never captured, for the reason `click.ts` gives at length: any
|
|
333
|
+
app worth adapting re-renders, and a captured node is a node that has since been
|
|
334
|
+
detached — pressing it does precisely nothing, with no error, and the verb
|
|
335
|
+
reports success. Worse, the person at the keyboard has been clicking the whole
|
|
336
|
+
time the model was thinking, so a control disappearing between the snapshot and
|
|
337
|
+
the call is the ordinary case and not an exception. It is therefore a refusal
|
|
338
|
+
carrying the screen as it is *now*, so the agent's next turn sees the shorter
|
|
339
|
+
list without another read. Quoting `rev` turns the same situation into a `stale`
|
|
340
|
+
refusal one layer up, which is better still, and the hint says so.
|
|
341
|
+
|
|
342
|
+
**A disabled control refuses instead of being pressed.** A rendered-but-disabled
|
|
343
|
+
button accepts a click, does nothing, and the call reports `ok`. A verb that
|
|
344
|
+
silently does nothing is the worst outcome in this library. The check is
|
|
345
|
+
`disabled` and `aria-disabled="true"`, read off the author's own markup, and
|
|
346
|
+
`refuseWhen` replaces it for an app that disables its controls some other way —
|
|
347
|
+
return `disabled` from it unless you mean to add a slug, because `disabled` is
|
|
348
|
+
the only availability refusal the verbs declare and the core warns once about
|
|
349
|
+
any refusal that is not on a verb's declared list.
|
|
350
|
+
Deliberately not a visibility or pointer-events check: those need layout, layout
|
|
351
|
+
needs a real browser, and a heuristic that is right in Chrome and wrong in a
|
|
352
|
+
test is worse than a rule an author can read off their own markup.
|
|
353
|
+
|
|
354
|
+
## Typing is not assigning `value`
|
|
355
|
+
|
|
356
|
+
```ts
|
|
357
|
+
await driver.call("type-into", { control: "search", text: "Ada" });
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Assigning `value` and stopping is the failure this part is built around. A
|
|
361
|
+
framework learns about a keystroke from an event; a field whose `value` was
|
|
362
|
+
assigned and nothing else looks right on screen, has told the app nothing, and
|
|
363
|
+
is wiped by the next render — while the verb reports `ok`. So the default path
|
|
364
|
+
focuses the element, assigns `value`, and fires `input` and `change`. When it
|
|
365
|
+
cannot fire anything (no `Event`, no `dispatchEvent`) it **throws** rather than
|
|
366
|
+
doing the half of the job that looks like all of it.
|
|
367
|
+
|
|
368
|
+
`setValue` is the hook for a framework the default cannot reach; see the limits
|
|
369
|
+
below for why React is one of them.
|
|
370
|
+
|
|
371
|
+
A checkbox is an `<input>` and is a control you press, not a field you type
|
|
372
|
+
into. The rule: `textarea` and `input` are fields, except the `input` types that
|
|
373
|
+
plainly are not text (`checkbox`, `radio`, `button`, `submit`, `reset`, `file`,
|
|
374
|
+
`image`, `color`, `range`). `data-dk-field="true|false"` overrides it for a
|
|
375
|
+
`contenteditable` div or a custom element.
|
|
376
|
+
|
|
377
|
+
## Using it
|
|
378
|
+
|
|
379
|
+
The whole integration for an app that already has a verb list:
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
import { controlsFromDom } from "driverkit/controls";
|
|
383
|
+
|
|
384
|
+
const dk = controlsFromDom({ root: "#app", rows: "#contacts" });
|
|
385
|
+
|
|
386
|
+
mount({
|
|
387
|
+
app: "Contacts",
|
|
388
|
+
verbs: [...myShortcuts, ...dk.verbs],
|
|
389
|
+
visible: () => dk.withControls(myVisible()),
|
|
390
|
+
});
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
`withControls` is non-destructive: a note the app already wrote is kept and the
|
|
394
|
+
control line is appended to it.
|
|
395
|
+
|
|
396
|
+
`rows` is the option worth not forgetting. Pointing the row scan at the
|
|
397
|
+
container your rows live in is what makes the per-row collapsing work: without
|
|
398
|
+
it, a screen of twenty rows with six controls each reports a hundred and twenty
|
|
399
|
+
entries under twenty names, a duplicate-name warning for each, and a snapshot
|
|
400
|
+
that grows with the table. With it, six entries marked `per: "row"` and
|
|
401
|
+
addressed by row id.
|
|
402
|
+
|
|
403
|
+
It is a separate entry point, `driverkit/controls`, and that is deliberate.
|
|
404
|
+
Importing it is how an app says "publish my marked controls to an agent", and
|
|
405
|
+
publishing is consent; an app that only wants the verbs it wrote never resolves
|
|
406
|
+
this module at all.
|
|
407
|
+
|
|
408
|
+
### Why the control list is also in `note`
|
|
409
|
+
|
|
410
|
+
`Snapshot.controls` is structured and new, and nothing that renders a snapshot
|
|
411
|
+
for a model reads it yet — the TypeScript renderer and the Python one both print
|
|
412
|
+
`note`, `rows`, `page` and `selected`. So the enumeration also writes a compact
|
|
413
|
+
one-line rendering into `note`, which is how the controls actually reach a
|
|
414
|
+
model today.
|
|
415
|
+
|
|
416
|
+
That is duplication in the uncached half and it is transitional. The grammar is
|
|
417
|
+
terse on purpose and the legend that makes it readable lives in the verbs'
|
|
418
|
+
descriptions, which are cached — the same static/dynamic reasoning applied to
|
|
419
|
+
the rendering itself. `inNote: false` turns it off; set it once your renderer
|
|
420
|
+
prints `controls`.
|
|
421
|
+
|
|
422
|
+
## What this deliberately does not do
|
|
423
|
+
|
|
424
|
+
- **No `kind` inference.** Declared by the author, checked by nothing. The
|
|
425
|
+
same cost any verb that clicks a button has always had.
|
|
426
|
+
- **No predicates, so no bulk work.** A control acts on one thing. Four hundred
|
|
427
|
+
rows is four hundred presses, and the answer to that is a shortcut, not a
|
|
428
|
+
better control layer.
|
|
429
|
+
- **No `count`.** A control cannot report how many rows a predicate matched,
|
|
430
|
+
because it never had a predicate. The `describe` → count → `commit` pairing
|
|
431
|
+
belongs to verbs the app wrote.
|
|
432
|
+
- **No selector, path, role, label or coordinate matching.** Only the names the
|
|
433
|
+
author marked.
|
|
434
|
+
- **No multi-step macros.** Three verbs, one action each. Sequencing is the
|
|
435
|
+
agent's job, which is the one thing an agent is unambiguously good at.
|
|
436
|
+
- **No reading of `Verb.at`.** See above.
|
|
437
|
+
|
|
438
|
+
## The honest limits
|
|
439
|
+
|
|
440
|
+
Named, because a design that reports itself complete is the one not to trust.
|
|
441
|
+
|
|
442
|
+
**Coverage is complete over what the author marked, not over the UI.** This is
|
|
443
|
+
the big one, and it is a real retreat from "whatever I ask it on the UI". An
|
|
444
|
+
unmarked button does not exist to an agent, so the completeness is structural
|
|
445
|
+
only once the marking is. A screen with thirty controls and three marks is three
|
|
446
|
+
controls, and the agent will answer "I cannot do that" about a button a person
|
|
447
|
+
can see. The unmarked alternative — enumerate every `<button>` — would be
|
|
448
|
+
inference, would publish controls nobody reviewed, and would have no `kind` for
|
|
449
|
+
any of them; that trade was refused on purpose. The practical mitigation is a
|
|
450
|
+
loud list of what *is* marked and a codemod-shaped job: `data-dk-control` on
|
|
451
|
+
every interactive element in a view is a mechanical edit, and `data-dk-kind` on
|
|
452
|
+
each is the hour of judgement that cannot be mechanised.
|
|
453
|
+
|
|
454
|
+
**Per-row `disabled` is collapsed and therefore imprecise.** Twenty Delete
|
|
455
|
+
buttons, three of them greyed out, are one entry. It claims `disabled` only when
|
|
456
|
+
every copy is disabled, so an agent can be told a control is available and then
|
|
457
|
+
refused for the specific row. The call-time check is correct; the snapshot is a
|
|
458
|
+
summary. The alternative is one entry per row per control, which is the cost
|
|
459
|
+
argument gone.
|
|
460
|
+
|
|
461
|
+
**React controlled inputs may defeat the default typing path.** React tracks an
|
|
462
|
+
input's value on the DOM node and a plain assignment bypasses the tracker, so
|
|
463
|
+
the `input` event may be dispatched with React still believing the old value,
|
|
464
|
+
and the next render reverts the field. The fix is the native-setter trick, which
|
|
465
|
+
this package does not do for you because it is a React-specific hack that has
|
|
466
|
+
changed shape across versions. `setValue` is the hook, and an app that is
|
|
467
|
+
driving a controlled input should use it — or better, expose a verb of its own
|
|
468
|
+
that calls the state setter.
|
|
469
|
+
|
|
470
|
+
**No keystroke granularity, no composition, no blur.** Typing replaces the whole
|
|
471
|
+
value in one shot. An autocomplete that only searches on the third character, a
|
|
472
|
+
field with an input mask, an IME composition, a form that validates on blur, a
|
|
473
|
+
control that commits on Enter — none of those are reachable. There is no
|
|
474
|
+
`press-key` verb; a screen that genuinely needs one needs a verb of its own
|
|
475
|
+
more.
|
|
476
|
+
|
|
477
|
+
**The human-only walk stops at a shadow boundary, and at an element that has
|
|
478
|
+
no parent.** `parentElement` is null on the top node of a shadow tree, so
|
|
479
|
+
marking the HOST of a component does not withhold the controls inside it — mark
|
|
480
|
+
something inside. And an `ElementLike` written by hand for a non-DOM renderer
|
|
481
|
+
need not implement `parentElement`; one that does not gets the element-only
|
|
482
|
+
reading, which is what this package did before the walk existed. Compatible
|
|
483
|
+
rather than safe, deliberately: withholding every control from an adapter that
|
|
484
|
+
simply did not implement an optional field would be a silent outage.
|
|
485
|
+
|
|
486
|
+
**Nothing outside the main document.** Canvas-rendered grids, a table in an
|
|
487
|
+
`<iframe>`, closed shadow roots, native `<select>` dropdowns, and anything
|
|
488
|
+
drawn by a non-DOM renderer are invisible here, exactly as they are to the rest
|
|
489
|
+
of this package. An open shadow root works if you pass the element as `root`.
|
|
490
|
+
|
|
491
|
+
**No ordering, grouping or spatial sense.** The control list is in document
|
|
492
|
+
order with no notion of toolbars, menus, dialogs or what is behind a modal. An
|
|
493
|
+
agent cannot tell that a control is inside a dialog it must dismiss first, or
|
|
494
|
+
that two controls are mutually exclusive. It will discover that by being refused
|
|
495
|
+
or, worse, by pressing something that was technically available. `root` is the
|
|
496
|
+
only tool for this, and narrowing it to the open dialog is a thing the app has
|
|
497
|
+
to do.
|
|
498
|
+
|
|
499
|
+
**Two controls with one name is an authoring bug this can only report.** Like
|
|
500
|
+
two rows with one id, the verb acts on whichever the page yields first. Warned
|
|
501
|
+
about, never renamed — a suffixed name would be a name no screen shows.
|
|
502
|
+
|
|
503
|
+
**The gate is no longer only as good as the host, and this paragraph used to
|
|
504
|
+
say it was.** `commit-control` is declared `commit`, which routes it to the
|
|
505
|
+
gated door; what fires at that door now lives in the core rather than in a
|
|
506
|
+
consumer. `mount({ approve })` is asked before any `commit` verb runs, on every
|
|
507
|
+
path — the in-page loop, a relay frame, a test with no transport — and a denial
|
|
508
|
+
is the reserved `declined-by-user`. So an undeclared control pressed by an agent
|
|
509
|
+
in another process is asked about, where before it was pressed with no question
|
|
510
|
+
at all because the only gate in the library was the in-page one. Connecting a
|
|
511
|
+
driver that publishes ungated commits with no policy declared is refused
|
|
512
|
+
outright; see `MountOptions.approve`. The routing here is still what makes it
|
|
513
|
+
work — the core can only ask about a verb that says it changes data — but the
|
|
514
|
+
human in front of it is no longer optional wiring.
|
|
515
|
+
|
|
516
|
+
**A MIS-DECLARED CONTROL IS NOT GATED, AND THIS LAYER CANNOT CLOSE THAT.** The
|
|
517
|
+
sharpest limit here, so it gets its own paragraph. `commit-control` is declared
|
|
518
|
+
`commit` and routes through the core's gate. `press` and `type-into` are
|
|
519
|
+
declared `describe` and do not — they cannot be anything else, because `press`
|
|
520
|
+
also presses controls the author declared `describe` (a select-all checkbox),
|
|
521
|
+
and declaring the verb `read` or `commit` would be a false claim about every
|
|
522
|
+
other call it serves. The core asks about the **verb's** kind, not the
|
|
523
|
+
control's. So a genuinely destructive button marked `data-dk-kind="read"` is
|
|
524
|
+
pressed with no question asked.
|
|
525
|
+
|
|
526
|
+
Three true things about that, in order of how much they help:
|
|
527
|
+
|
|
528
|
+
- **The undeclared case is already covered.** An unmarked kind routes to
|
|
529
|
+
`commit-control`, which is gated — and because `commit-control` is a `commit`
|
|
530
|
+
with no `reversible`, `connect()` will not publish a driver carrying this
|
|
531
|
+
layer until the app has declared who approves. Forgetting is handled; this
|
|
532
|
+
limit is about asserting something false, not about omitting it.
|
|
533
|
+
- **A central override exists for markup you do not trust.** The
|
|
534
|
+
`kind(name, el)` hook is consulted before the attribute, so an app embedding
|
|
535
|
+
third-party or generated markup can force the controls it knows are dangerous
|
|
536
|
+
to `commit` in one place, in code, without editing anybody's template. That
|
|
537
|
+
is the mitigation to reach for when the markup's claims are not yours.
|
|
538
|
+
- **Closing it properly needs a change in the core, not here.** The gate would
|
|
539
|
+
have to be askable per call rather than only per verb — a verb declaring that
|
|
540
|
+
it gates itself and an approval the verb body raises, under the same
|
|
541
|
+
no-other-calls lock. With that, `press` could ask about a particular control
|
|
542
|
+
while staying honestly `describe`. Without it, the only way to route one
|
|
543
|
+
control through the gate is to declare it `commit`, which is the author's job
|
|
544
|
+
and is the mechanism this layer already offers.
|
|
545
|
+
|
|
546
|
+
**An agent can press its own confirm button, and three things stop it.** This is
|
|
547
|
+
the failure the gate above has on its own, and it is observed rather than
|
|
548
|
+
theoretical: in webmachinelearning/webmcp#288 a proposal-only tool correctly
|
|
549
|
+
declined to execute itself, so the agent clicked the page's own Approve button
|
|
550
|
+
and the receipt recorded "approved by you". This layer is exactly that bypass —
|
|
551
|
+
one action, total coverage, and total coverage includes the button that exists
|
|
552
|
+
to stop the action, which an agent cannot tell is inside a dialog (see the
|
|
553
|
+
ordering limit above).
|
|
554
|
+
|
|
555
|
+
1. **The core refuses every call while an approval is open**, as
|
|
556
|
+
`approval-pending`. The strongest of the three, because it needs nobody to
|
|
557
|
+
remember anything and it covers any approval UI rather than a known one. It
|
|
558
|
+
also stops a second call racing the dialog.
|
|
559
|
+
2. **A confirmation in a shadow root is invisible here.** Closed shadow roots
|
|
560
|
+
are not walked, which this document already lists as a limit; for an
|
|
561
|
+
approval UI it is the feature. `driverkit/widget`'s dialog is in its own
|
|
562
|
+
shadow tree for this reason among others.
|
|
563
|
+
3. **`data-dk-human-only`** takes a marked control back out: not enumerated,
|
|
564
|
+
and refused as `no-such-control` — the same answer an unmarked button gets,
|
|
565
|
+
so the refusal is not an oracle over which buttons are the interesting ones.
|
|
566
|
+
Put it on the Yes, the signature field, the "I agree" tick, the 2FA box.
|
|
567
|
+
`data-dk-human-only="false"` is a real no, for markup that cannot omit an
|
|
568
|
+
attribute. **The mark is inherited**: one attribute on the `<dialog>` takes
|
|
569
|
+
every control inside it out together, which is the way an author would
|
|
570
|
+
write it and, until the walk existed, the way that did nothing at all. It is
|
|
571
|
+
still the weakest layer, because it is the one an author can forget — so it
|
|
572
|
+
is a second line and never the only one.
|
|
573
|
+
|
|
574
|
+
**The uncached cost is real and grows with the screen.** Rows plus controls plus
|
|
575
|
+
the duplicated note line is paid for on every turn. Forty controls is a lot more
|
|
576
|
+
than eight, and nothing here makes a busy admin screen cheap. `limit`, `root`
|
|
577
|
+
and `inNote: false` are the three levers, and all three are the author's to
|
|
578
|
+
pull.
|