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
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering a Snapshot and a Result for a model to read.
|
|
3
|
+
*
|
|
4
|
+
* This is the TypeScript twin of `python/src/driverkit/render.py`, and the
|
|
5
|
+
* duplication is on purpose: the Python half renders for an MCP client driving
|
|
6
|
+
* the app from outside, this half renders for a chatbot sitting inside the
|
|
7
|
+
* page, and **a model must read the same sentences about the same screen
|
|
8
|
+
* either way.** Two halves of one library that describe one app differently is
|
|
9
|
+
* not a cosmetic problem — a prompt that worked through MCP and misbehaves in
|
|
10
|
+
* the widget is a bug with no stack trace. When you change wording here,
|
|
11
|
+
* change it there.
|
|
12
|
+
*
|
|
13
|
+
* Why render text at all rather than `JSON.stringify` at the boundary: a tool
|
|
14
|
+
* result is prompt. The snapshot that comes back from every call is the
|
|
15
|
+
* uncached half, so its bytes are paid for on every turn, and JSON spends a
|
|
16
|
+
* large share of them on punctuation and on repeating each column name once
|
|
17
|
+
* per row. The thing a model re-reads most often is the thing we made
|
|
18
|
+
* smallest.
|
|
19
|
+
*
|
|
20
|
+
* The second rule is that the post-call snapshot is never dropped. `Result`
|
|
21
|
+
* carries it so acting and observing are one round trip; a renderer that
|
|
22
|
+
* returned "ok" and nothing else would hand that saving straight back, because
|
|
23
|
+
* the model's next move would be to read the screen it was just given.
|
|
24
|
+
*
|
|
25
|
+
* **One difference from the Python half, and it is a simplification.** There
|
|
26
|
+
* are no relay refusals here. `no-such-tab`, `tab-went-away` and `timeout`
|
|
27
|
+
* describe a call that never reached a tab, and in-page there is no tab to
|
|
28
|
+
* miss and no deadline to blow: `driver.call()` is a function call that always
|
|
29
|
+
* returns a `Result` with a `snapshot`. So the unknown-outcome branch, which
|
|
30
|
+
* is most of the Python file, has nothing to render and is absent rather than
|
|
31
|
+
* ported as dead code.
|
|
32
|
+
*/
|
|
33
|
+
/** Verbatim from the Python half. Both describe the same `Result` field. */
|
|
34
|
+
const COUNT_NOTE = "This is what a commit verb acting on the current selection would affect. " +
|
|
35
|
+
"Check it is the number you expect before committing.";
|
|
36
|
+
/**
|
|
37
|
+
* The line that carries a plan token to the model.
|
|
38
|
+
*
|
|
39
|
+
* Rendered directly under the count, because it is the count's receipt and
|
|
40
|
+
* means nothing apart from it. Without this line the token exists in the
|
|
41
|
+
* `Result` and the model never sees it, so every commit that requires one is
|
|
42
|
+
* refused — the field would be plumbing that reaches everywhere except the one
|
|
43
|
+
* reader that has to use it.
|
|
44
|
+
*
|
|
45
|
+
* Verbatim with `render.py`. The two renderers say the same words to the same
|
|
46
|
+
* model and a difference between them is a difference in what an agent is told
|
|
47
|
+
* depending on how it connected.
|
|
48
|
+
*/
|
|
49
|
+
const PLAN_NOTE = "Pass this `plan` back to the commit verb that acts on this selection. It is the receipt " +
|
|
50
|
+
"for the count above: if anything moves the selection first the commit is refused as " +
|
|
51
|
+
"`stale-plan` rather than acting on rows nobody counted. One commit per plan. Reading and " +
|
|
52
|
+
"navigating do not move the selection and do not spend this plan, so go and check whatever " +
|
|
53
|
+
"you need to before you commit.";
|
|
54
|
+
/**
|
|
55
|
+
* The screen as a short text block.
|
|
56
|
+
*
|
|
57
|
+
* ```
|
|
58
|
+
* screen: contacts
|
|
59
|
+
* where: contacts, filtered to Acme (rev 8)
|
|
60
|
+
* selected: c-8821
|
|
61
|
+
* rows 1-2 of 5
|
|
62
|
+
* id company status
|
|
63
|
+
* c-8820 Acme new
|
|
64
|
+
* c-8821 Acme accepted
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Field order is fixed so the same screen renders identically every time: a
|
|
68
|
+
* model comparing two reads should see a diff only where the screen changed.
|
|
69
|
+
*
|
|
70
|
+
* `screen` goes FIRST, above the prose, and is omitted by an app that does not
|
|
71
|
+
* declare one. It is the one line on this block a model can compare for
|
|
72
|
+
* equality: `where` carries the filter, the sort and a drill-down's record
|
|
73
|
+
* description, so it moves for reasons that are not navigation, and two reads
|
|
74
|
+
* either side of a `go` differ in a dozen ways. One short word that changes if
|
|
75
|
+
* and only if the screen changed is worth a line of the uncached half.
|
|
76
|
+
*/
|
|
77
|
+
export function renderSnapshot(snapshot) {
|
|
78
|
+
const lines = snapshot.screen
|
|
79
|
+
? [`screen: ${snapshot.screen}`, `where: ${snapshot.where} (rev ${snapshot.rev})`]
|
|
80
|
+
: [`where: ${snapshot.where} (rev ${snapshot.rev})`];
|
|
81
|
+
const selected = snapshot.selected ?? [];
|
|
82
|
+
if (selected.length > 0) {
|
|
83
|
+
// Before the rows, because "this one" is usually the subject of the next
|
|
84
|
+
// verb and the model should not have to scan the table to find it.
|
|
85
|
+
lines.push("selected: " + selected.join(", "));
|
|
86
|
+
}
|
|
87
|
+
if (snapshot.selectedCount !== undefined && snapshot.selectedCount !== selected.length) {
|
|
88
|
+
// The ids and the size of a selection are different facts, and the size is
|
|
89
|
+
// the one a commit decision turns on. `selected` carries only what is on
|
|
90
|
+
// screen — ten thousand ids in the uncached half is the token budget
|
|
91
|
+
// gone — so a model holding three ids and about to commit has to be told in
|
|
92
|
+
// words that the list is a window onto the selection and not the selection.
|
|
93
|
+
lines.push(`selected ${commas(snapshot.selectedCount)} rows in all; ` +
|
|
94
|
+
(selected.length
|
|
95
|
+
? `the ${selected.length} ids above are only the ones on screen`
|
|
96
|
+
: "none of them are on screen"));
|
|
97
|
+
}
|
|
98
|
+
else if (selected.length === 0) {
|
|
99
|
+
// An absent value reads as a claim — the same defect already fixed on
|
|
100
|
+
// `page` and on `rows`, in the one remaining place it was still live.
|
|
101
|
+
//
|
|
102
|
+
// This block used to be nothing at all: the selection was described only
|
|
103
|
+
// when it was non-empty, so a screen with nothing selected said NOTHING
|
|
104
|
+
// about selections, and silence cannot be told from "this screen does not
|
|
105
|
+
// report selections". The library's own rule is that a commit is never
|
|
106
|
+
// made on a count nobody read, so a model asked to accept the selection
|
|
107
|
+
// here obeyed the rule against a screen that told it nothing — and went
|
|
108
|
+
// navigating other screens hunting for the number. Observed in an eval
|
|
109
|
+
// run, not imagined.
|
|
110
|
+
//
|
|
111
|
+
// selectedCount: 0 the app counts, and the answer is none
|
|
112
|
+
// count absent, selected [] the app says which ids on screen are
|
|
113
|
+
// selected and none are, but does not count,
|
|
114
|
+
// so a row off screen may still be selected
|
|
115
|
+
// both absent the app does not report selections at all
|
|
116
|
+
//
|
|
117
|
+
// Three sentences because they are three different facts, and the whole
|
|
118
|
+
// bug was one of them being rendered as another. The middle one is the
|
|
119
|
+
// weakest claim and the one nobody thinks about; conflating it with the
|
|
120
|
+
// first would say "nothing is selected" on the strength of a window.
|
|
121
|
+
if (snapshot.selectedCount === 0) {
|
|
122
|
+
lines.push("selected: none (0 rows; this screen counts the selection)");
|
|
123
|
+
}
|
|
124
|
+
else if (snapshot.selected === undefined) {
|
|
125
|
+
lines.push("(this screen reports no selection)");
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
lines.push("selected: none on screen; this screen does not count the selection, so rows off " +
|
|
129
|
+
"screen may be selected");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (snapshot.note)
|
|
133
|
+
lines.push(`note: ${snapshot.note}`);
|
|
134
|
+
const rows = snapshot.rows;
|
|
135
|
+
if (rows === undefined) {
|
|
136
|
+
// Absent rows and zero rows are different claims. An app with no table on
|
|
137
|
+
// screen reports no rows; a filter that matched nothing reports an empty
|
|
138
|
+
// list, and an agent told "no rows" in the first case would conclude the
|
|
139
|
+
// records do not exist.
|
|
140
|
+
lines.push("(this screen reports no rows)");
|
|
141
|
+
return lines.join("\n");
|
|
142
|
+
}
|
|
143
|
+
const page = snapshot.page;
|
|
144
|
+
if (page !== undefined) {
|
|
145
|
+
const first = rows.length ? page.index * page.size + 1 : 0;
|
|
146
|
+
const seen = page.index * page.size + rows.length;
|
|
147
|
+
if (page.total === undefined) {
|
|
148
|
+
// `page.total` is optional, and total-absent is the NORMAL case for
|
|
149
|
+
// anything reading a rendered DOM: an adapter cannot tell a virtualised
|
|
150
|
+
// grid from a short list, so it is the only honest thing it can say. The
|
|
151
|
+
// unguarded interpolation this replaces printed `of undefined` into the
|
|
152
|
+
// prompt on every turn of every DOM-adapted app.
|
|
153
|
+
//
|
|
154
|
+
// Rendered as a claim rather than as a gap. "of at least 20" is true,
|
|
155
|
+
// which "of undefined" and "of 20" are not — the first is noise a model
|
|
156
|
+
// ignores or hallucinates around, the second tells it the table ends
|
|
157
|
+
// where the window ends and invites it to report that a record does not
|
|
158
|
+
// exist. The count a nobody-knows total would need is simply not said.
|
|
159
|
+
lines.push(rows.length
|
|
160
|
+
? `rows ${first}-${first + rows.length - 1} of at least ${seen} (total unknown)`
|
|
161
|
+
: `rows 0 of at least ${seen} (total unknown)`);
|
|
162
|
+
lines.push("the total is not known, so more rows may exist off screen; use the app's own paging " +
|
|
163
|
+
"verb to look further, and do not report that something is absent on the strength " +
|
|
164
|
+
"of this window");
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
lines.push(rows.length
|
|
168
|
+
? `rows ${first}-${first + rows.length - 1} of ${page.total}`
|
|
169
|
+
: `rows 0 of ${page.total}`);
|
|
170
|
+
if (seen < page.total) {
|
|
171
|
+
// Said in words, because `of 5` alone has repeatedly been read by
|
|
172
|
+
// models as "I have all five".
|
|
173
|
+
lines.push("more rows exist off screen; use the app's own paging verb to reach them");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// No `page` is a claim that this is everything. Worth stating, since the
|
|
179
|
+
// alternative reading — "the driver forgot to tell me" — leads an agent to
|
|
180
|
+
// hunt for a paging verb that does not exist.
|
|
181
|
+
lines.push(`rows ${rows.length} (all of them)`);
|
|
182
|
+
}
|
|
183
|
+
if (rows.length === 0) {
|
|
184
|
+
lines.push("(no rows on screen)");
|
|
185
|
+
return lines.join("\n");
|
|
186
|
+
}
|
|
187
|
+
for (const line of table(rows))
|
|
188
|
+
lines.push(line);
|
|
189
|
+
return lines.join("\n");
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* A Result as text: the outcome, then the screen it left behind.
|
|
193
|
+
*
|
|
194
|
+
* A refusal renders as an ordinary outcome and not as an error banner. The
|
|
195
|
+
* slug is the one the manifest already declared under `refuses`, so an agent
|
|
196
|
+
* that read the tool description recognises the word and generally knows the
|
|
197
|
+
* fix; wrapping it in alarm language mostly teaches a model to retry the same
|
|
198
|
+
* call unchanged.
|
|
199
|
+
*
|
|
200
|
+
* Byte-identical to what `render_result` produces in the Python half, which is
|
|
201
|
+
* why the join lives here and not only where the loop needs the halves apart.
|
|
202
|
+
* `drive` composes the same two pieces with a seam of its own between them —
|
|
203
|
+
* see `renderOutcome` — but this exported renderer, the one an MCP client's
|
|
204
|
+
* agent reads, goes on saying exactly what the Python one says.
|
|
205
|
+
*/
|
|
206
|
+
export function renderResult(result) {
|
|
207
|
+
return renderOutcome(result) + "\n\n" + renderSnapshot(result.snapshot);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The outcome half of a `Result`: `ok`, the count, or the refusal and its hint.
|
|
211
|
+
*
|
|
212
|
+
* Split out because the two halves of a tool result age at different rates, and
|
|
213
|
+
* only something that can hold them apart can act on that. The screen below is
|
|
214
|
+
* current for exactly one turn. THIS half stays true forever: it is the answer
|
|
215
|
+
* to "what did my third call actually do", and it is a line or two rather than
|
|
216
|
+
* a table. The loop keeps it and drops the screen from older tool turns — see
|
|
217
|
+
* `pruneScreens`.
|
|
218
|
+
*/
|
|
219
|
+
export function renderOutcome(result) {
|
|
220
|
+
let head;
|
|
221
|
+
if (result.ok) {
|
|
222
|
+
head = "ok" + (result.note ? ` — ${result.note}` : "");
|
|
223
|
+
if (result.count !== undefined) {
|
|
224
|
+
// On its own line, high up, with thousands separators. This is the
|
|
225
|
+
// number a person would have to see before pressing a bulk button, and
|
|
226
|
+
// the reason `describe` and `commit` are separate verbs; a renderer that
|
|
227
|
+
// folds it into prose further down has given back the safety the split
|
|
228
|
+
// was bought with. 1000 and 10000 also look alike at a glance, which is
|
|
229
|
+
// the mistake that costs the most.
|
|
230
|
+
head += `\ncount: ${commas(result.count)} matched\n${COUNT_NOTE}`;
|
|
231
|
+
}
|
|
232
|
+
if (result.plan !== undefined) {
|
|
233
|
+
head += `\nplan: ${result.plan}\n${PLAN_NOTE}`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
head = `refused: ${result.refused}`;
|
|
238
|
+
if (result.hint)
|
|
239
|
+
head += `\nhint: ${result.hint}`;
|
|
240
|
+
}
|
|
241
|
+
return head;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The shortest honest wait worth a line in a prompt.
|
|
245
|
+
*
|
|
246
|
+
* One second, and the number is the whole token argument. A duration on every
|
|
247
|
+
* call is a line in every turn forever, for a capability most runs never use,
|
|
248
|
+
* and `pruneScreens` cut a ten-step run from 5,775 to 1,397 characters by
|
|
249
|
+
* refusing to pay exactly that kind of per-step rent. So the default is that a
|
|
250
|
+
* call which took no time says nothing: a snappy app renders not one byte more
|
|
251
|
+
* than it did before this existed, and the bytes get spent only on the calls
|
|
252
|
+
* where elapsed time is a fact about the app rather than noise.
|
|
253
|
+
*
|
|
254
|
+
* A second is also roughly where a wait stops being invisible to the person
|
|
255
|
+
* watching the panel. Below it, the model learning the number changes no
|
|
256
|
+
* decision it could make; above it, "this verb is slow" is a real property of
|
|
257
|
+
* the app that explains why the next step should not be another one of these.
|
|
258
|
+
*/
|
|
259
|
+
export const SLOW_MS = 1000;
|
|
260
|
+
/**
|
|
261
|
+
* How long a call took, as one line for the outcome half of a tool turn.
|
|
262
|
+
*
|
|
263
|
+
* ```
|
|
264
|
+
* ok — 3,412 contacts accepted
|
|
265
|
+
* took: ~2s
|
|
266
|
+
*
|
|
267
|
+
* On screen now:
|
|
268
|
+
* screen: contacts
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* **Why this is a function and not a field on `Result`.** A `Result` is what
|
|
272
|
+
* the APP returned; a duration is a fact about the call that wrapped it, which
|
|
273
|
+
* the app never measured and cannot be asked to. Putting it on the wire would
|
|
274
|
+
* invite an app to fill it in, and then the number a model reads would be an
|
|
275
|
+
* app's claim about its own speed rather than an observation. The caller
|
|
276
|
+
* measures, the caller renders, and this is the one place either half of the
|
|
277
|
+
* library says it in words.
|
|
278
|
+
*
|
|
279
|
+
* **Why it is bucketed rather than exact.** Every other byte of a rendered
|
|
280
|
+
* turn is a function of app state, so two identical runs produce identical
|
|
281
|
+
* transcripts — which is what eval caching, snapshot tests and anything that
|
|
282
|
+
* diffs transcripts are built on. A wall-clock millisecond count breaks that
|
|
283
|
+
* for every reader at once. Rounding to a coarse bucket gives it back for the
|
|
284
|
+
* ordinary case: a verb that takes 2.1s one run and 2.3s the next renders
|
|
285
|
+
* `~2s` both times, so the transcript is stable wherever the app's own
|
|
286
|
+
* behaviour is. It does not make the output a pure function of state — a
|
|
287
|
+
* bucket boundary is still a boundary, and a call that straddles one renders
|
|
288
|
+
* two ways — and that is why `Clock.now` is injectable through `DriveOptions
|
|
289
|
+
* .clock`: a suite or an eval that needs a byte-exact transcript pins the
|
|
290
|
+
* clock and gets one. Buckets are for production, the injected clock is for
|
|
291
|
+
* determinism, and neither is asked to do the other's job.
|
|
292
|
+
*
|
|
293
|
+
* `~` is on the number on purpose. A model shown `took: 2.13s` will compare
|
|
294
|
+
* two of them to three figures and report a difference that is scheduler
|
|
295
|
+
* noise; `~2s` cannot be over-read, and reads naturally in an answer a person
|
|
296
|
+
* gets back.
|
|
297
|
+
*
|
|
298
|
+
* **What this must never include.** The time a person spent deciding. `ms` in
|
|
299
|
+
* an `AuditEvent` is approval-inclusive by design — a reader of the record
|
|
300
|
+
* wants that gap back — but telling a MODEL that a call "took 40 seconds" when
|
|
301
|
+
* 38 of them were somebody reading a confirmation dialog is a false claim
|
|
302
|
+
* about the app's speed, and a model that believes it will go looking for a
|
|
303
|
+
* faster route around a verb that is not slow. The caller is responsible for
|
|
304
|
+
* handing in work time only; see `DriveOptions.waited`, which is how a host
|
|
305
|
+
* that gates commits INSIDE `driver.call()` subtracts its own dialog.
|
|
306
|
+
*
|
|
307
|
+
* `floorMs` below is the "not interesting" threshold, and `0` renders every
|
|
308
|
+
* call. Returns the EMPTY STRING rather than a sentinel when there is nothing
|
|
309
|
+
* worth saying, so a caller appends it unconditionally and the fast path adds
|
|
310
|
+
* no line at all.
|
|
311
|
+
*
|
|
312
|
+
* Verbatim with `render.py`. Both halves say the same words about the same
|
|
313
|
+
* number, which is the rule for everything in this file: a prompt that worked
|
|
314
|
+
* through MCP and misbehaves in the widget is a bug with no stack trace.
|
|
315
|
+
*/
|
|
316
|
+
export function renderDuration(ms, floorMs = SLOW_MS) {
|
|
317
|
+
const whole = Math.floor(ms);
|
|
318
|
+
// A negative or non-finite figure is a broken clock, not a fast call, and
|
|
319
|
+
// the honest rendering of a measurement that did not happen is silence. A
|
|
320
|
+
// monotonic clock cannot go backwards; an injected one can, and a test
|
|
321
|
+
// clock that does should not put `took: ~-1s` in a prompt.
|
|
322
|
+
if (!Number.isFinite(whole) || whole < 0)
|
|
323
|
+
return "";
|
|
324
|
+
if (whole < floorMs)
|
|
325
|
+
return "";
|
|
326
|
+
return `took: ${bucket(whole)}`;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Whole milliseconds as a coarse, stable label.
|
|
330
|
+
*
|
|
331
|
+
* Integer arithmetic only, and no locale and no float formatting anywhere:
|
|
332
|
+
* `toFixed` and `%.1f` are the two things most likely to disagree between the
|
|
333
|
+
* two implementations, and this function's entire job is to agree. Each band
|
|
334
|
+
* floors rather than rounds, so the label never claims more time than elapsed.
|
|
335
|
+
*
|
|
336
|
+
* under 100ms `under 0.1s` said in words, because `~0.0s` reads as zero
|
|
337
|
+
* and `~0.1s` would overstate it
|
|
338
|
+
* under 1s `~0.4s` tenths: the resolution a `floorMs: 0` caller
|
|
339
|
+
* asked for, and the one at which two fetches
|
|
340
|
+
* are actually worth comparing
|
|
341
|
+
* under 10s `~2s` whole seconds
|
|
342
|
+
* under 1m `~15s` five-second steps. Tens were the first try and
|
|
343
|
+
* understated badly at the top of the band —
|
|
344
|
+
* 19 seconds rendering `~10s` is a 47% lie, and
|
|
345
|
+
* "it took ten seconds" is the sentence a model
|
|
346
|
+
* will repeat to somebody. Five is still far
|
|
347
|
+
* coarser than any scheduler noise, so the
|
|
348
|
+
* label is stable where the app is
|
|
349
|
+
* 1m and over `~3m` whole minutes
|
|
350
|
+
*/
|
|
351
|
+
function bucket(ms) {
|
|
352
|
+
if (ms < 100)
|
|
353
|
+
return "under 0.1s";
|
|
354
|
+
if (ms < 1000)
|
|
355
|
+
return `~0.${Math.floor(ms / 100)}s`;
|
|
356
|
+
if (ms < 10_000)
|
|
357
|
+
return `~${Math.floor(ms / 1000)}s`;
|
|
358
|
+
if (ms < 60_000)
|
|
359
|
+
return `~${Math.floor(ms / 5_000) * 5}s`;
|
|
360
|
+
return `~${Math.floor(ms / 60_000)}m`;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Rows as a padded text table.
|
|
364
|
+
*
|
|
365
|
+
* Columns are `id` first, then every other key in the order it was first
|
|
366
|
+
* seen — the union over all rows, not the first row's keys. Rows are not
|
|
367
|
+
* required to agree, and silently dropping a column that only some rows carry
|
|
368
|
+
* would hide exactly the outlier a person is usually asking about.
|
|
369
|
+
*/
|
|
370
|
+
function table(rows) {
|
|
371
|
+
const columns = ["id"];
|
|
372
|
+
for (const row of rows) {
|
|
373
|
+
for (const key of Object.keys(row)) {
|
|
374
|
+
if (!columns.includes(key))
|
|
375
|
+
columns.push(key);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const cells = rows.map((row) => columns.map((c) => cell(row[c])));
|
|
379
|
+
const widths = columns.map((c) => c.length);
|
|
380
|
+
for (const rowCells of cells) {
|
|
381
|
+
for (let i = 0; i < rowCells.length; i++) {
|
|
382
|
+
widths[i] = Math.max(widths[i], rowCells[i].length);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const line = (values) => values
|
|
386
|
+
// The last column is not padded: trailing spaces are tokens that carry
|
|
387
|
+
// nothing.
|
|
388
|
+
.map((v, i) => (i < values.length - 1 ? v.padEnd(widths[i]) : v))
|
|
389
|
+
.join(" ")
|
|
390
|
+
.replace(/\s+$/, "");
|
|
391
|
+
return [line(columns), ...cells.map(line)];
|
|
392
|
+
}
|
|
393
|
+
function cell(value) {
|
|
394
|
+
if (value === undefined || value === null)
|
|
395
|
+
return "-";
|
|
396
|
+
if (value === true)
|
|
397
|
+
return "true";
|
|
398
|
+
if (value === false)
|
|
399
|
+
return "false";
|
|
400
|
+
return String(value);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Thousands separators, hand-rolled.
|
|
404
|
+
*
|
|
405
|
+
* Not `toLocaleString()`. That reads the host's locale, so the same count
|
|
406
|
+
* renders `1,000` for one person and `1.000` for another and `1 000` for a
|
|
407
|
+
* third — a per-user difference in the uncached half, and in the one number
|
|
408
|
+
* the commit decision turns on. The Python half writes `1,000`; so does this.
|
|
409
|
+
*
|
|
410
|
+
* Exported because the widget asks the person "accept 1,000 contacts?" about
|
|
411
|
+
* the same number the model was told about. One implementation, so the figure
|
|
412
|
+
* in the prompt and the figure on the button cannot come to disagree about
|
|
413
|
+
* where the comma goes.
|
|
414
|
+
*/
|
|
415
|
+
export function commas(n) {
|
|
416
|
+
const digits = Math.trunc(Math.abs(n)).toString();
|
|
417
|
+
let out = "";
|
|
418
|
+
for (let i = 0; i < digits.length; i++) {
|
|
419
|
+
if (i > 0 && (digits.length - i) % 3 === 0)
|
|
420
|
+
out += ",";
|
|
421
|
+
out += digits[i];
|
|
422
|
+
}
|
|
423
|
+
return (n < 0 ? "-" : "") + out;
|
|
424
|
+
}
|
|
425
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/agent/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAIH,4EAA4E;AAC5E,MAAM,UAAU,GACd,2EAA2E;IAC3E,sDAAsD,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,MAAM,SAAS,GACb,0FAA0F;IAC1F,sFAAsF;IACtF,2FAA2F;IAC3F,4FAA4F;IAC5F,gCAAgC,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,cAAc,CAAC,QAAkB;IAC/C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM;QAC3B,CAAC,CAAC,CAAC,WAAW,QAAQ,CAAC,MAAM,EAAE,EAAE,UAAU,QAAQ,CAAC,KAAK,SAAS,QAAQ,CAAC,GAAG,GAAG,CAAC;QAClF,CAAC,CAAC,CAAC,UAAU,QAAQ,CAAC,KAAK,SAAS,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC;IAEvD,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC;IACzC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,yEAAyE;QACzE,mEAAmE;QACnE,KAAK,CAAC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,QAAQ,CAAC,aAAa,KAAK,SAAS,IA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CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,GAAG,IAAI,GAAG,CAAC;QACvD,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;AAClC,CAAC","sourcesContent":["/**\n * Rendering a Snapshot and a Result for a model to read.\n *\n * This is the TypeScript twin of `python/src/driverkit/render.py`, and the\n * duplication is on purpose: the Python half renders for an MCP client driving\n * the app from outside, this half renders for a chatbot sitting inside the\n * page, and **a model must read the same sentences about the same screen\n * either way.** Two halves of one library that describe one app differently is\n * not a cosmetic problem — a prompt that worked through MCP and misbehaves in\n * the widget is a bug with no stack trace. When you change wording here,\n * change it there.\n *\n * Why render text at all rather than `JSON.stringify` at the boundary: a tool\n * result is prompt. The snapshot that comes back from every call is the\n * uncached half, so its bytes are paid for on every turn, and JSON spends a\n * large share of them on punctuation and on repeating each column name once\n * per row. The thing a model re-reads most often is the thing we made\n * smallest.\n *\n * The second rule is that the post-call snapshot is never dropped. `Result`\n * carries it so acting and observing are one round trip; a renderer that\n * returned \"ok\" and nothing else would hand that saving straight back, because\n * the model's next move would be to read the screen it was just given.\n *\n * **One difference from the Python half, and it is a simplification.** There\n * are no relay refusals here. `no-such-tab`, `tab-went-away` and `timeout`\n * describe a call that never reached a tab, and in-page there is no tab to\n * miss and no deadline to blow: `driver.call()` is a function call that always\n * returns a `Result` with a `snapshot`. So the unknown-outcome branch, which\n * is most of the Python file, has nothing to render and is absent rather than\n * ported as dead code.\n */\n\nimport type { Result, Row, Scalar, Snapshot } from \"../core/index.ts\";\n\n/** Verbatim from the Python half. Both describe the same `Result` field. */\nconst COUNT_NOTE =\n \"This is what a commit verb acting on the current selection would affect. \" +\n \"Check it is the number you expect before committing.\";\n\n/**\n * The line that carries a plan token to the model.\n *\n * Rendered directly under the count, because it is the count's receipt and\n * means nothing apart from it. Without this line the token exists in the\n * `Result` and the model never sees it, so every commit that requires one is\n * refused — the field would be plumbing that reaches everywhere except the one\n * reader that has to use it.\n *\n * Verbatim with `render.py`. The two renderers say the same words to the same\n * model and a difference between them is a difference in what an agent is told\n * depending on how it connected.\n */\nconst PLAN_NOTE =\n \"Pass this `plan` back to the commit verb that acts on this selection. It is the receipt \" +\n \"for the count above: if anything moves the selection first the commit is refused as \" +\n \"`stale-plan` rather than acting on rows nobody counted. One commit per plan. Reading and \" +\n \"navigating do not move the selection and do not spend this plan, so go and check whatever \" +\n \"you need to before you commit.\";\n\n/**\n * The screen as a short text block.\n *\n * ```\n * screen: contacts\n * where: contacts, filtered to Acme (rev 8)\n * selected: c-8821\n * rows 1-2 of 5\n * id company status\n * c-8820 Acme new\n * c-8821 Acme accepted\n * ```\n *\n * Field order is fixed so the same screen renders identically every time: a\n * model comparing two reads should see a diff only where the screen changed.\n *\n * `screen` goes FIRST, above the prose, and is omitted by an app that does not\n * declare one. It is the one line on this block a model can compare for\n * equality: `where` carries the filter, the sort and a drill-down's record\n * description, so it moves for reasons that are not navigation, and two reads\n * either side of a `go` differ in a dozen ways. One short word that changes if\n * and only if the screen changed is worth a line of the uncached half.\n */\nexport function renderSnapshot(snapshot: Snapshot): string {\n const lines = snapshot.screen\n ? [`screen: ${snapshot.screen}`, `where: ${snapshot.where} (rev ${snapshot.rev})`]\n : [`where: ${snapshot.where} (rev ${snapshot.rev})`];\n\n const selected = snapshot.selected ?? [];\n if (selected.length > 0) {\n // Before the rows, because \"this one\" is usually the subject of the next\n // verb and the model should not have to scan the table to find it.\n lines.push(\"selected: \" + selected.join(\", \"));\n }\n\n if (snapshot.selectedCount !== undefined && snapshot.selectedCount !== selected.length) {\n // The ids and the size of a selection are different facts, and the size is\n // the one a commit decision turns on. `selected` carries only what is on\n // screen — ten thousand ids in the uncached half is the token budget\n // gone — so a model holding three ids and about to commit has to be told in\n // words that the list is a window onto the selection and not the selection.\n lines.push(\n `selected ${commas(snapshot.selectedCount)} rows in all; ` +\n (selected.length\n ? `the ${selected.length} ids above are only the ones on screen`\n : \"none of them are on screen\"),\n );\n } else if (selected.length === 0) {\n // An absent value reads as a claim — the same defect already fixed on\n // `page` and on `rows`, in the one remaining place it was still live.\n //\n // This block used to be nothing at all: the selection was described only\n // when it was non-empty, so a screen with nothing selected said NOTHING\n // about selections, and silence cannot be told from \"this screen does not\n // report selections\". The library's own rule is that a commit is never\n // made on a count nobody read, so a model asked to accept the selection\n // here obeyed the rule against a screen that told it nothing — and went\n // navigating other screens hunting for the number. Observed in an eval\n // run, not imagined.\n //\n // selectedCount: 0 the app counts, and the answer is none\n // count absent, selected [] the app says which ids on screen are\n // selected and none are, but does not count,\n // so a row off screen may still be selected\n // both absent the app does not report selections at all\n //\n // Three sentences because they are three different facts, and the whole\n // bug was one of them being rendered as another. The middle one is the\n // weakest claim and the one nobody thinks about; conflating it with the\n // first would say \"nothing is selected\" on the strength of a window.\n if (snapshot.selectedCount === 0) {\n lines.push(\"selected: none (0 rows; this screen counts the selection)\");\n } else if (snapshot.selected === undefined) {\n lines.push(\"(this screen reports no selection)\");\n } else {\n lines.push(\n \"selected: none on screen; this screen does not count the selection, so rows off \" +\n \"screen may be selected\",\n );\n }\n }\n\n if (snapshot.note) lines.push(`note: ${snapshot.note}`);\n\n const rows = snapshot.rows;\n if (rows === undefined) {\n // Absent rows and zero rows are different claims. An app with no table on\n // screen reports no rows; a filter that matched nothing reports an empty\n // list, and an agent told \"no rows\" in the first case would conclude the\n // records do not exist.\n lines.push(\"(this screen reports no rows)\");\n return lines.join(\"\\n\");\n }\n\n const page = snapshot.page;\n if (page !== undefined) {\n const first = rows.length ? page.index * page.size + 1 : 0;\n const seen = page.index * page.size + rows.length;\n\n if (page.total === undefined) {\n // `page.total` is optional, and total-absent is the NORMAL case for\n // anything reading a rendered DOM: an adapter cannot tell a virtualised\n // grid from a short list, so it is the only honest thing it can say. The\n // unguarded interpolation this replaces printed `of undefined` into the\n // prompt on every turn of every DOM-adapted app.\n //\n // Rendered as a claim rather than as a gap. \"of at least 20\" is true,\n // which \"of undefined\" and \"of 20\" are not — the first is noise a model\n // ignores or hallucinates around, the second tells it the table ends\n // where the window ends and invites it to report that a record does not\n // exist. The count a nobody-knows total would need is simply not said.\n lines.push(\n rows.length\n ? `rows ${first}-${first + rows.length - 1} of at least ${seen} (total unknown)`\n : `rows 0 of at least ${seen} (total unknown)`,\n );\n lines.push(\n \"the total is not known, so more rows may exist off screen; use the app's own paging \" +\n \"verb to look further, and do not report that something is absent on the strength \" +\n \"of this window\",\n );\n } else {\n lines.push(\n rows.length\n ? `rows ${first}-${first + rows.length - 1} of ${page.total}`\n : `rows 0 of ${page.total}`,\n );\n if (seen < page.total) {\n // Said in words, because `of 5` alone has repeatedly been read by\n // models as \"I have all five\".\n lines.push(\"more rows exist off screen; use the app's own paging verb to reach them\");\n }\n }\n } else {\n // No `page` is a claim that this is everything. Worth stating, since the\n // alternative reading — \"the driver forgot to tell me\" — leads an agent to\n // hunt for a paging verb that does not exist.\n lines.push(`rows ${rows.length} (all of them)`);\n }\n\n if (rows.length === 0) {\n lines.push(\"(no rows on screen)\");\n return lines.join(\"\\n\");\n }\n\n for (const line of table(rows)) lines.push(line);\n return lines.join(\"\\n\");\n}\n\n/**\n * A Result as text: the outcome, then the screen it left behind.\n *\n * A refusal renders as an ordinary outcome and not as an error banner. The\n * slug is the one the manifest already declared under `refuses`, so an agent\n * that read the tool description recognises the word and generally knows the\n * fix; wrapping it in alarm language mostly teaches a model to retry the same\n * call unchanged.\n *\n * Byte-identical to what `render_result` produces in the Python half, which is\n * why the join lives here and not only where the loop needs the halves apart.\n * `drive` composes the same two pieces with a seam of its own between them —\n * see `renderOutcome` — but this exported renderer, the one an MCP client's\n * agent reads, goes on saying exactly what the Python one says.\n */\nexport function renderResult(result: Result): string {\n return renderOutcome(result) + \"\\n\\n\" + renderSnapshot(result.snapshot);\n}\n\n/**\n * The outcome half of a `Result`: `ok`, the count, or the refusal and its hint.\n *\n * Split out because the two halves of a tool result age at different rates, and\n * only something that can hold them apart can act on that. The screen below is\n * current for exactly one turn. THIS half stays true forever: it is the answer\n * to \"what did my third call actually do\", and it is a line or two rather than\n * a table. The loop keeps it and drops the screen from older tool turns — see\n * `pruneScreens`.\n */\nexport function renderOutcome(result: Result): string {\n let head: string;\n\n if (result.ok) {\n head = \"ok\" + (result.note ? ` — ${result.note}` : \"\");\n if (result.count !== undefined) {\n // On its own line, high up, with thousands separators. This is the\n // number a person would have to see before pressing a bulk button, and\n // the reason `describe` and `commit` are separate verbs; a renderer that\n // folds it into prose further down has given back the safety the split\n // was bought with. 1000 and 10000 also look alike at a glance, which is\n // the mistake that costs the most.\n head += `\\ncount: ${commas(result.count)} matched\\n${COUNT_NOTE}`;\n }\n if (result.plan !== undefined) {\n head += `\\nplan: ${result.plan}\\n${PLAN_NOTE}`;\n }\n } else {\n head = `refused: ${result.refused}`;\n if (result.hint) head += `\\nhint: ${result.hint}`;\n }\n\n return head;\n}\n\n/**\n * The shortest honest wait worth a line in a prompt.\n *\n * One second, and the number is the whole token argument. A duration on every\n * call is a line in every turn forever, for a capability most runs never use,\n * and `pruneScreens` cut a ten-step run from 5,775 to 1,397 characters by\n * refusing to pay exactly that kind of per-step rent. So the default is that a\n * call which took no time says nothing: a snappy app renders not one byte more\n * than it did before this existed, and the bytes get spent only on the calls\n * where elapsed time is a fact about the app rather than noise.\n *\n * A second is also roughly where a wait stops being invisible to the person\n * watching the panel. Below it, the model learning the number changes no\n * decision it could make; above it, \"this verb is slow\" is a real property of\n * the app that explains why the next step should not be another one of these.\n */\nexport const SLOW_MS = 1000;\n\n/**\n * How long a call took, as one line for the outcome half of a tool turn.\n *\n * ```\n * ok — 3,412 contacts accepted\n * took: ~2s\n *\n * On screen now:\n * screen: contacts\n * ```\n *\n * **Why this is a function and not a field on `Result`.** A `Result` is what\n * the APP returned; a duration is a fact about the call that wrapped it, which\n * the app never measured and cannot be asked to. Putting it on the wire would\n * invite an app to fill it in, and then the number a model reads would be an\n * app's claim about its own speed rather than an observation. The caller\n * measures, the caller renders, and this is the one place either half of the\n * library says it in words.\n *\n * **Why it is bucketed rather than exact.** Every other byte of a rendered\n * turn is a function of app state, so two identical runs produce identical\n * transcripts — which is what eval caching, snapshot tests and anything that\n * diffs transcripts are built on. A wall-clock millisecond count breaks that\n * for every reader at once. Rounding to a coarse bucket gives it back for the\n * ordinary case: a verb that takes 2.1s one run and 2.3s the next renders\n * `~2s` both times, so the transcript is stable wherever the app's own\n * behaviour is. It does not make the output a pure function of state — a\n * bucket boundary is still a boundary, and a call that straddles one renders\n * two ways — and that is why `Clock.now` is injectable through `DriveOptions\n * .clock`: a suite or an eval that needs a byte-exact transcript pins the\n * clock and gets one. Buckets are for production, the injected clock is for\n * determinism, and neither is asked to do the other's job.\n *\n * `~` is on the number on purpose. A model shown `took: 2.13s` will compare\n * two of them to three figures and report a difference that is scheduler\n * noise; `~2s` cannot be over-read, and reads naturally in an answer a person\n * gets back.\n *\n * **What this must never include.** The time a person spent deciding. `ms` in\n * an `AuditEvent` is approval-inclusive by design — a reader of the record\n * wants that gap back — but telling a MODEL that a call \"took 40 seconds\" when\n * 38 of them were somebody reading a confirmation dialog is a false claim\n * about the app's speed, and a model that believes it will go looking for a\n * faster route around a verb that is not slow. The caller is responsible for\n * handing in work time only; see `DriveOptions.waited`, which is how a host\n * that gates commits INSIDE `driver.call()` subtracts its own dialog.\n *\n * `floorMs` below is the \"not interesting\" threshold, and `0` renders every\n * call. Returns the EMPTY STRING rather than a sentinel when there is nothing\n * worth saying, so a caller appends it unconditionally and the fast path adds\n * no line at all.\n *\n * Verbatim with `render.py`. Both halves say the same words about the same\n * number, which is the rule for everything in this file: a prompt that worked\n * through MCP and misbehaves in the widget is a bug with no stack trace.\n */\nexport function renderDuration(ms: number, floorMs: number = SLOW_MS): string {\n const whole = Math.floor(ms);\n // A negative or non-finite figure is a broken clock, not a fast call, and\n // the honest rendering of a measurement that did not happen is silence. A\n // monotonic clock cannot go backwards; an injected one can, and a test\n // clock that does should not put `took: ~-1s` in a prompt.\n if (!Number.isFinite(whole) || whole < 0) return \"\";\n if (whole < floorMs) return \"\";\n return `took: ${bucket(whole)}`;\n}\n\n/**\n * Whole milliseconds as a coarse, stable label.\n *\n * Integer arithmetic only, and no locale and no float formatting anywhere:\n * `toFixed` and `%.1f` are the two things most likely to disagree between the\n * two implementations, and this function's entire job is to agree. Each band\n * floors rather than rounds, so the label never claims more time than elapsed.\n *\n * under 100ms `under 0.1s` said in words, because `~0.0s` reads as zero\n * and `~0.1s` would overstate it\n * under 1s `~0.4s` tenths: the resolution a `floorMs: 0` caller\n * asked for, and the one at which two fetches\n * are actually worth comparing\n * under 10s `~2s` whole seconds\n * under 1m `~15s` five-second steps. Tens were the first try and\n * understated badly at the top of the band —\n * 19 seconds rendering `~10s` is a 47% lie, and\n * \"it took ten seconds\" is the sentence a model\n * will repeat to somebody. Five is still far\n * coarser than any scheduler noise, so the\n * label is stable where the app is\n * 1m and over `~3m` whole minutes\n */\nfunction bucket(ms: number): string {\n if (ms < 100) return \"under 0.1s\";\n if (ms < 1000) return `~0.${Math.floor(ms / 100)}s`;\n if (ms < 10_000) return `~${Math.floor(ms / 1000)}s`;\n if (ms < 60_000) return `~${Math.floor(ms / 5_000) * 5}s`;\n return `~${Math.floor(ms / 60_000)}m`;\n}\n\n/**\n * Rows as a padded text table.\n *\n * Columns are `id` first, then every other key in the order it was first\n * seen — the union over all rows, not the first row's keys. Rows are not\n * required to agree, and silently dropping a column that only some rows carry\n * would hide exactly the outlier a person is usually asking about.\n */\nfunction table(rows: Row[]): string[] {\n const columns = [\"id\"];\n for (const row of rows) {\n for (const key of Object.keys(row)) {\n if (!columns.includes(key)) columns.push(key);\n }\n }\n\n const cells = rows.map((row) => columns.map((c) => cell(row[c])));\n const widths = columns.map((c) => c.length);\n for (const rowCells of cells) {\n for (let i = 0; i < rowCells.length; i++) {\n widths[i] = Math.max(widths[i]!, rowCells[i]!.length);\n }\n }\n\n const line = (values: string[]): string =>\n values\n // The last column is not padded: trailing spaces are tokens that carry\n // nothing.\n .map((v, i) => (i < values.length - 1 ? v.padEnd(widths[i]!) : v))\n .join(\" \")\n .replace(/\\s+$/, \"\");\n\n return [line(columns), ...cells.map(line)];\n}\n\nfunction cell(value: Scalar | undefined): string {\n if (value === undefined || value === null) return \"-\";\n if (value === true) return \"true\";\n if (value === false) return \"false\";\n return String(value);\n}\n\n/**\n * Thousands separators, hand-rolled.\n *\n * Not `toLocaleString()`. That reads the host's locale, so the same count\n * renders `1,000` for one person and `1.000` for another and `1 000` for a\n * third — a per-user difference in the uncached half, and in the one number\n * the commit decision turns on. The Python half writes `1,000`; so does this.\n *\n * Exported because the widget asks the person \"accept 1,000 contacts?\" about\n * the same number the model was told about. One implementation, so the figure\n * in the prompt and the figure on the button cannot come to disagree about\n * where the comma goes.\n */\nexport function commas(n: number): string {\n const digits = Math.trunc(Math.abs(n)).toString();\n let out = \"\";\n for (let i = 0; i < digits.length; i++) {\n if (i > 0 && (digits.length - i) % 3 === 0) out += \",\";\n out += digits[i];\n }\n return (n < 0 ? \"-\" : \"\") + out;\n}\n"]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The manifest, rendered as a tool list and a system prompt.
|
|
3
|
+
*
|
|
4
|
+
* **Nothing in this file knows the name of a single verb.** Each verb in the
|
|
5
|
+
* manifest becomes one tool, its `args` become the tool's `inputSchema`, and
|
|
6
|
+
* its `refuses` go into the description so a model can decline to make a call
|
|
7
|
+
* that was always going to be declined. The app's verb table is the only
|
|
8
|
+
* description of the app that exists, and it lives next to the code that
|
|
9
|
+
* implements it.
|
|
10
|
+
*
|
|
11
|
+
* This is the twin of `tools_for`/`verb_tool` in
|
|
12
|
+
* `python/src/driverkit/mcp_server.py`, and the notes below are the same
|
|
13
|
+
* strings. The Python half renders for an MCP client driving the app from
|
|
14
|
+
* outside; this half renders for a chatbot inside the page. A verb that is
|
|
15
|
+
* described one way through MCP and another way in the widget is a bug: the
|
|
16
|
+
* whole promise is that the app declares its capabilities once.
|
|
17
|
+
*
|
|
18
|
+
* Everything here is the STATIC half. It is a pure function of the manifest,
|
|
19
|
+
* which the core guarantees does not vary between two users or two minutes, so
|
|
20
|
+
* the output is byte-identical across every turn of every session of every
|
|
21
|
+
* person using the app — which is what makes it worth caching in the prompt
|
|
22
|
+
* prefix. Reaching into `driver.snapshot()` from this file would quietly undo
|
|
23
|
+
* that for everybody; it is not imported here, which is the cheapest way to
|
|
24
|
+
* make that impossible rather than merely discouraged.
|
|
25
|
+
*/
|
|
26
|
+
import type { ArgSpec, Manifest } from "../core/index.ts";
|
|
27
|
+
import type { JsonSchema, ToolSpec } from "./types.ts";
|
|
28
|
+
/**
|
|
29
|
+
* The one tool that is not a verb.
|
|
30
|
+
*
|
|
31
|
+
* It is the protocol's own read, not an app feature, and no app should have to
|
|
32
|
+
* declare it. Verb names are kebab-case by the core's contract and this is
|
|
33
|
+
* snake_case so they cannot collide; `toolsFor` checks anyway rather than
|
|
34
|
+
* silently shadowing a verb.
|
|
35
|
+
*
|
|
36
|
+
* MCP's other hand-written tool, `list_tabs`, is deliberately absent. In-page
|
|
37
|
+
* there is one app and it is the one the person is looking at; a tool that
|
|
38
|
+
* lists tabs would invite a model to ask which tab it is driving, and the
|
|
39
|
+
* honest answer is "this one, there is no other".
|
|
40
|
+
*/
|
|
41
|
+
export declare const READ_SCREEN = "read_screen";
|
|
42
|
+
/**
|
|
43
|
+
* One `ArgSpec` as one JSON Schema property.
|
|
44
|
+
*
|
|
45
|
+
* `oneOf` becomes `enum`. See the note on `JsonSchema`: the two names look
|
|
46
|
+
* alike and the meanings diverge, and emitting JSON Schema's `oneOf` would
|
|
47
|
+
* produce a schema that validates anything.
|
|
48
|
+
*/
|
|
49
|
+
export declare function argSchema(spec: ArgSpec): JsonSchema;
|
|
50
|
+
/**
|
|
51
|
+
* One manifest verb as one tool.
|
|
52
|
+
*
|
|
53
|
+
* `optional` is expressed by omission from `required`, which is how JSON
|
|
54
|
+
* Schema says it; an `"optional": true` key would be ignored by every
|
|
55
|
+
* validator and the argument would silently become mandatory.
|
|
56
|
+
*
|
|
57
|
+
* `rev` is added as an extra optional property on every verb. It is not an app
|
|
58
|
+
* argument — it is `CallOptions.rev`, the staleness claim, hoisted into the
|
|
59
|
+
* schema because a model has nowhere else to put it. Passing the `rev` it last
|
|
60
|
+
* read is what turns "act on a row somebody already moved" into a clean
|
|
61
|
+
* `stale` refusal, and in-page that is not a rare case: the person is sitting
|
|
62
|
+
* right there, clicking, while the model thinks. A verb that declares its own
|
|
63
|
+
* `rev` argument keeps it and does not get the hoisted one, because the app's
|
|
64
|
+
* meaning wins over ours.
|
|
65
|
+
*/
|
|
66
|
+
export declare function verbTool(verb: Manifest["verbs"][number]): ToolSpec;
|
|
67
|
+
/** The whole tool list: every verb, then the one fixed read. */
|
|
68
|
+
export declare function toolsFor(manifest: Manifest): ToolSpec[];
|
|
69
|
+
/**
|
|
70
|
+
* The app's map, rendered for the model.
|
|
71
|
+
*
|
|
72
|
+
* `Manifest.screens` is the static list of every screen the app has, so this
|
|
73
|
+
* belongs in the cached prefix beside the tool list rather than in any turn's
|
|
74
|
+
* tail. What an agent could not do before this existed is learn that a screen
|
|
75
|
+
* EXISTS without standing on it: `Snapshot.screen` says where it is and
|
|
76
|
+
* `Verb.screen` says where a verb works, and between them there was still no
|
|
77
|
+
* way to find out that a companies list is in there somewhere. The worked
|
|
78
|
+
* example closed that gap by pasting a prose screen-map into `instructions`,
|
|
79
|
+
* which is the same map the app's own route table already had, written a
|
|
80
|
+
* second time in English with nothing checking that the two agree.
|
|
81
|
+
*
|
|
82
|
+
* The sentence about it being the same for every user is not padding. It is
|
|
83
|
+
* the one thing a model cannot tell by looking: a list that might have been
|
|
84
|
+
* filtered for this person is a list whose absences mean nothing, and an agent
|
|
85
|
+
* that cannot trust the absences has to probe for screens anyway. See
|
|
86
|
+
* `ScreenSpec`, which forbids filtering it, and which puts "you may not open
|
|
87
|
+
* that" in the refusal where it can be read.
|
|
88
|
+
*
|
|
89
|
+
* Verbatim from the Python half.
|
|
90
|
+
*/
|
|
91
|
+
export declare function screensNote(screens: NonNullable<Manifest["screens"]>): string;
|
|
92
|
+
/**
|
|
93
|
+
* The app's flows, rendered for the model.
|
|
94
|
+
*
|
|
95
|
+
* THE SENTENCE THAT MATTERS is the one saying there is no tool that runs a
|
|
96
|
+
* flow. A model handed a list of numbered steps will look for the button, and
|
|
97
|
+
* not finding one it may well decide the flow is unavailable; being told that
|
|
98
|
+
* following the steps IS the mechanism, and why, is what turns a list into an
|
|
99
|
+
* instruction. The why is honest and is the design: a flow that executed
|
|
100
|
+
* internally could not adapt when step three found the record already
|
|
101
|
+
* accepted, and the agent would get back an `ok` that told it nothing. Apple's
|
|
102
|
+
* app skills say the same thing about themselves — "Skills don't enforce
|
|
103
|
+
* deterministic behavior, and Siri doesn't run the listed intents in sequence."
|
|
104
|
+
*
|
|
105
|
+
* Static, so it rides in the prefix that was already being cached and costs
|
|
106
|
+
* nothing per turn. Verbatim from the Python half.
|
|
107
|
+
*/
|
|
108
|
+
export declare function flowsNote(flows: NonNullable<Manifest["flows"]>, verbs?: Manifest["verbs"]): string;
|
|
109
|
+
/**
|
|
110
|
+
* The system prompt. A pure function of the manifest — including the app's own
|
|
111
|
+
* `Manifest.instructions` — and the host's static `instructions`, and of
|
|
112
|
+
* nothing else.
|
|
113
|
+
*
|
|
114
|
+
* Mirrors the MCP server's `initialize` instructions, with the differences
|
|
115
|
+
* that are actually true in-page: there is no relay, no tab to pick, and the
|
|
116
|
+
* person whose screen this is can see every word of what happens next.
|
|
117
|
+
*
|
|
118
|
+
* The screen is NOT in here, and that is the rule this function exists to
|
|
119
|
+
* enforce. It is the uncached half; putting it in the system prompt would mean
|
|
120
|
+
* re-sending and re-paying for the entire prefix on every single turn, which
|
|
121
|
+
* is the exact cost the static/dynamic split was designed to avoid. It goes in
|
|
122
|
+
* the newest message instead — see `loop.ts`.
|
|
123
|
+
*/
|
|
124
|
+
export declare function systemPrompt(manifest: Manifest, instructions?: string,
|
|
125
|
+
/**
|
|
126
|
+
* `DriveOptions.timing`, so the note about what a `took:` line means is paid
|
|
127
|
+
* for ONCE, in the half a provider caches, instead of once per call.
|
|
128
|
+
*
|
|
129
|
+
* Absent and `"off"` are the same thing and add nothing: a caller from before
|
|
130
|
+
* timing existed gets the byte-identical prompt it got before, which is what
|
|
131
|
+
* keeps every existing eval's cached prefix valid on upgrade.
|
|
132
|
+
*
|
|
133
|
+
* Still a pure function of its arguments, which is the property that matters
|
|
134
|
+
* here more than any wording: `drive` computes this once, before the loop,
|
|
135
|
+
* and `test/tools.test.ts` asserts it is byte-identical across turns.
|
|
136
|
+
*/
|
|
137
|
+
timing?: "off" | "slow" | "always"): string;
|
|
138
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/agent/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAkIzC;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAYnD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,QAAQ,CAqHlE;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAoBvD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC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