@graview/tools 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/LICENSE +96 -0
  2. package/README.md +47 -0
  3. package/dist/agent/adapters.d.ts +43 -0
  4. package/dist/agent/adapters.d.ts.map +1 -0
  5. package/dist/agent/adapters.js +52 -0
  6. package/dist/agent/adapters.js.map +1 -0
  7. package/dist/agent/tools.d.ts +105 -0
  8. package/dist/agent/tools.d.ts.map +1 -0
  9. package/dist/agent/tools.js +311 -0
  10. package/dist/agent/tools.js.map +1 -0
  11. package/dist/cli.d.ts +37 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +306 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/conversation.d.ts +108 -0
  16. package/dist/conversation.d.ts.map +1 -0
  17. package/dist/conversation.js +698 -0
  18. package/dist/conversation.js.map +1 -0
  19. package/dist/decide.d.ts +43 -0
  20. package/dist/decide.d.ts.map +1 -0
  21. package/dist/decide.js +125 -0
  22. package/dist/decide.js.map +1 -0
  23. package/dist/derive.d.ts +84 -0
  24. package/dist/derive.d.ts.map +1 -0
  25. package/dist/derive.js +302 -0
  26. package/dist/derive.js.map +1 -0
  27. package/dist/edit.d.ts +70 -0
  28. package/dist/edit.d.ts.map +1 -0
  29. package/dist/edit.js +97 -0
  30. package/dist/edit.js.map +1 -0
  31. package/dist/figure.d.ts +53 -0
  32. package/dist/figure.d.ts.map +1 -0
  33. package/dist/figure.js +86 -0
  34. package/dist/figure.js.map +1 -0
  35. package/dist/index.d.ts +44 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +31 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/intelligence.d.ts +132 -0
  40. package/dist/intelligence.d.ts.map +1 -0
  41. package/dist/intelligence.js +463 -0
  42. package/dist/intelligence.js.map +1 -0
  43. package/dist/local.d.ts +192 -0
  44. package/dist/local.d.ts.map +1 -0
  45. package/dist/local.js +365 -0
  46. package/dist/local.js.map +1 -0
  47. package/dist/loop.d.ts +84 -0
  48. package/dist/loop.d.ts.map +1 -0
  49. package/dist/loop.js +173 -0
  50. package/dist/loop.js.map +1 -0
  51. package/dist/mcp-stdio.d.ts +38 -0
  52. package/dist/mcp-stdio.d.ts.map +1 -0
  53. package/dist/mcp-stdio.js +83 -0
  54. package/dist/mcp-stdio.js.map +1 -0
  55. package/dist/pins.d.ts +29 -0
  56. package/dist/pins.d.ts.map +1 -0
  57. package/dist/pins.js +60 -0
  58. package/dist/pins.js.map +1 -0
  59. package/dist/plan.d.ts +150 -0
  60. package/dist/plan.d.ts.map +1 -0
  61. package/dist/plan.js +303 -0
  62. package/dist/plan.js.map +1 -0
  63. package/dist/providers/insight.d.ts +14 -0
  64. package/dist/providers/insight.d.ts.map +1 -0
  65. package/dist/providers/insight.js +81 -0
  66. package/dist/providers/insight.js.map +1 -0
  67. package/dist/providers/invariant.d.ts +14 -0
  68. package/dist/providers/invariant.d.ts.map +1 -0
  69. package/dist/providers/invariant.js +123 -0
  70. package/dist/providers/invariant.js.map +1 -0
  71. package/dist/providers/jev.d.ts +115 -0
  72. package/dist/providers/jev.d.ts.map +1 -0
  73. package/dist/providers/jev.js +148 -0
  74. package/dist/providers/jev.js.map +1 -0
  75. package/dist/providers/lens.d.ts +24 -0
  76. package/dist/providers/lens.d.ts.map +1 -0
  77. package/dist/providers/lens.js +36 -0
  78. package/dist/providers/lens.js.map +1 -0
  79. package/dist/providers/llm.d.ts +25 -0
  80. package/dist/providers/llm.d.ts.map +1 -0
  81. package/dist/providers/llm.js +44 -0
  82. package/dist/providers/llm.js.map +1 -0
  83. package/dist/providers/schema.d.ts +12 -0
  84. package/dist/providers/schema.d.ts.map +1 -0
  85. package/dist/providers/schema.js +508 -0
  86. package/dist/providers/schema.js.map +1 -0
  87. package/dist/providers/structure.d.ts +14 -0
  88. package/dist/providers/structure.d.ts.map +1 -0
  89. package/dist/providers/structure.js +211 -0
  90. package/dist/providers/structure.js.map +1 -0
  91. package/dist/questions.d.ts +162 -0
  92. package/dist/questions.d.ts.map +1 -0
  93. package/dist/questions.js +316 -0
  94. package/dist/questions.js.map +1 -0
  95. package/dist/run.d.ts +202 -0
  96. package/dist/run.d.ts.map +1 -0
  97. package/dist/run.js +453 -0
  98. package/dist/run.js.map +1 -0
  99. package/dist/space.d.ts +50 -0
  100. package/dist/space.d.ts.map +1 -0
  101. package/dist/space.js +55 -0
  102. package/dist/space.js.map +1 -0
  103. package/dist/types.d.ts +122 -0
  104. package/dist/types.d.ts.map +1 -0
  105. package/dist/types.js +2 -0
  106. package/dist/types.js.map +1 -0
  107. package/dist/usage.d.ts +10 -0
  108. package/dist/usage.d.ts.map +1 -0
  109. package/dist/usage.js +59 -0
  110. package/dist/usage.js.map +1 -0
  111. package/package.json +61 -0
@@ -0,0 +1,316 @@
1
+ import { fieldWriters, formFields, humaniseField, nounOf, labelOf, readableFields, withArticle, } from "@graview/core";
2
+ /** Node-typed values a decision provider answers with, as declared. */
3
+ const MAX_SCORE_LEVELS = 10;
4
+ /** The description a zod field carries, through optional/default wrappers. */
5
+ function describedAs(schema) {
6
+ let at = schema;
7
+ while (at) {
8
+ if (typeof at.description === "string" && at.description.length > 0)
9
+ return at.description;
10
+ at = at._def?.innerType;
11
+ }
12
+ return undefined;
13
+ }
14
+ const say = (field, description, of) => description ?? `${humaniseField(field.name)} of ${of}.`;
15
+ /**
16
+ * One scalar control as one question, or nothing when the control has no
17
+ * typed answer (text, a date, a list). `describe` is the field's own
18
+ * description, which is the instruction when there is one — the
19
+ * declaration's words, not a paraphrase.
20
+ */
21
+ function questionFor(store, field, description, of) {
22
+ switch (field.control) {
23
+ case "choice": {
24
+ if (!field.options?.length)
25
+ return undefined;
26
+ const criteria = {};
27
+ for (const option of field.options)
28
+ criteria[option] = null;
29
+ return { type: "choice", instructions: `Which ${humaniseField(field.name).toLowerCase()}? ${say(field, description, of)}`, criteria };
30
+ }
31
+ case "node": {
32
+ /*
33
+ * THE LIVE NODES OF THAT KIND, labelled by labelOf: the same word a
34
+ * card shows, a chat names and a tool describes. The option name is
35
+ * the id, because the answer has to be a call's argument; the
36
+ * meaning beside it is what the model reads.
37
+ */
38
+ const criteria = {};
39
+ for (const node of store.graph.allNodes()) {
40
+ if (!field.kinds.includes("*") && !field.kinds.includes(node.kind))
41
+ continue;
42
+ if (store.modules.disabledKinds.has(node.kind))
43
+ continue;
44
+ criteria[node.id] = `${withArticle(nounOf(store.schema.tryDefinition(node.kind), node.kind))}: ${labelOf(store.schema.tryDefinition(node.kind), node)}`;
45
+ }
46
+ if (Object.keys(criteria).length === 0)
47
+ return undefined;
48
+ return { type: "choice", instructions: `Which ${humaniseField(field.name).toLowerCase()}? ${say(field, description, of)}`, criteria };
49
+ }
50
+ case "boolean":
51
+ return {
52
+ type: "noul",
53
+ instructions: `${humaniseField(field.name)}: ${description ?? `is this true of ${of}?`}`,
54
+ criteria: { true: `${humaniseField(field.name)} holds.`, false: `${humaniseField(field.name)} does not hold.` },
55
+ };
56
+ case "number": {
57
+ if (field.min === undefined || field.max === undefined)
58
+ return undefined;
59
+ const span = field.max - field.min;
60
+ if (span < 1 || span + 1 > MAX_SCORE_LEVELS)
61
+ return undefined;
62
+ const levels = [];
63
+ for (let level = field.min; level <= field.max; level++) {
64
+ levels.push(level === field.min
65
+ ? `${humaniseField(field.name)} ${level} of ${field.max}: the least.`
66
+ : level === field.max
67
+ ? `${humaniseField(field.name)} ${level} of ${field.max}: the most.`
68
+ : `${humaniseField(field.name)} ${level} of ${field.max}.`);
69
+ }
70
+ return { type: "score", instructions: `How much ${humaniseField(field.name).toLowerCase()}? ${say(field, description, of)}`, criteria: levels };
71
+ }
72
+ default:
73
+ return undefined;
74
+ }
75
+ }
76
+ /** The number a Score answer means, on the field's own scale. */
77
+ export function scoreToValue(field, level) {
78
+ return field.min + Math.round(level);
79
+ }
80
+ /**
81
+ * The questions a KIND asks of one of its members: one per settable field
82
+ * with a typed answer, each naming the act that writes it. A kind whose
83
+ * every field is prose asks nothing, and says so by an empty list.
84
+ */
85
+ export function questionsForKind(store, kind) {
86
+ const definition = store.schema.tryDefinition(kind);
87
+ if (!definition)
88
+ return [];
89
+ const shape = definition.fields.shape ?? {};
90
+ const writers = fieldWriters(store.schema, store.allMutations()).get(kind);
91
+ const of = withArticle(nounOf(definition, kind));
92
+ const out = [];
93
+ for (const field of formFields(definition.fields)) {
94
+ if (field.name in (definition.fixed ?? {}))
95
+ continue;
96
+ const question = questionFor(store, field, describedAs(shape[field.name]), of);
97
+ if (!question)
98
+ continue;
99
+ const scale = field.control === "number" && field.min !== undefined && field.max !== undefined
100
+ ? { scale: { min: field.min, max: field.max } }
101
+ : {};
102
+ const writer = (writers?.get(field.name) ?? [])
103
+ .map((name) => store.allMutations().find((mutation) => mutation.name === name))
104
+ .find((mutation) => mutation?.subject && formFields(mutation.input).some((arg) => arg.name === field.name));
105
+ out.push({
106
+ id: `field:${kind}.${field.name}`,
107
+ about: "field",
108
+ kind,
109
+ field: field.name,
110
+ ...(writer?.subject ? { writes: { mutation: writer.name, arg: field.name, subjectArg: writer.subject.arg } } : {}),
111
+ ...scale,
112
+ question,
113
+ });
114
+ }
115
+ return out;
116
+ }
117
+ /**
118
+ * The questions an ACT asks before it can be called: one per argument with
119
+ * a typed answer that `given` has not already settled. The subject is
120
+ * usually given — a run fans out over nodes and asks each one's questions
121
+ * — and an argument with no typed answer is simply not asked, which is
122
+ * what the checker already guaranteed a decision provider would never
123
+ * meet on its allowlist.
124
+ */
125
+ export function questionsForMutation(store, name, given = {}) {
126
+ const mutation = store.mutation(name);
127
+ const shape = mutation.input.shape ?? {};
128
+ const of = mutation.title ?? name;
129
+ const out = [];
130
+ for (const field of formFields(mutation.input)) {
131
+ if (field.name in given)
132
+ continue;
133
+ const question = questionFor(store, field, describedAs(shape[field.name]), `the act "${of}"`);
134
+ if (!question)
135
+ continue;
136
+ const scale = field.control === "number" && field.min !== undefined && field.max !== undefined
137
+ ? { scale: { min: field.min, max: field.max } }
138
+ : {};
139
+ out.push({ id: `arg:${name}.${field.name}`, about: "argument", mutation: name, arg: field.name, ...scale, question });
140
+ }
141
+ return out;
142
+ }
143
+ /**
144
+ * A RULE IS A TRUTH, and its repairs are the closed set that follows.
145
+ *
146
+ * The invariant's own words are what "yes" means; a violation the store
147
+ * already raised narrows the follow-on Choice to the repairs it named, each
148
+ * with its arguments settled, so the answer is a call and not a guess.
149
+ * Asked without a violation, the follow-on is over the repairs the
150
+ * invariant declares it may name, which is what a loop asks before the
151
+ * store has judged.
152
+ */
153
+ export function questionsForInvariant(store, name, violation) {
154
+ const invariant = store.allInvariants().find((candidate) => candidate.name === name);
155
+ if (!invariant)
156
+ return [];
157
+ const rule = invariant.description ?? invariant.label ?? humaniseField(invariant.name);
158
+ const subject = violation?.subjectId;
159
+ const suffix = subject ? `:${subject}` : "";
160
+ const out = [
161
+ {
162
+ id: `rule:${name}${suffix}`,
163
+ about: "rule",
164
+ invariant: name,
165
+ ...(subject ? { subjectId: subject } : {}),
166
+ question: {
167
+ type: "noul",
168
+ instructions: violation ? `${rule} Is this so of the state given?` : `${rule} Does this hold in the state given?`,
169
+ criteria: { true: rule, false: violation?.message ?? `${rule} — but it does not hold.` },
170
+ },
171
+ },
172
+ ];
173
+ const criteria = {};
174
+ const options = {};
175
+ /*
176
+ * Two repairs of one violation are often the same act with different
177
+ * arguments — "call it turf", "call it a bed" — so the option name is
178
+ * the act's name only while that is unique, and `options` says which
179
+ * call each name means.
180
+ */
181
+ const nameFor = (mutation) => {
182
+ if (!(mutation in options))
183
+ return mutation;
184
+ let n = 2;
185
+ while (`${mutation}:${n}` in options)
186
+ n += 1;
187
+ return `${mutation}:${n}`;
188
+ };
189
+ if (violation) {
190
+ for (const repair of violation.repairs) {
191
+ if (repair.missing?.length)
192
+ continue;
193
+ const key = nameFor(repair.mutation);
194
+ criteria[key] = repair.label;
195
+ options[key] = { mutation: repair.mutation, args: { ...(repair.args ?? {}) } };
196
+ }
197
+ }
198
+ else {
199
+ for (const repairName of invariant.repairs ?? []) {
200
+ const mutation = store.allMutations().find((candidate) => candidate.name === repairName);
201
+ criteria[repairName] = mutation?.description ?? mutation?.title ?? null;
202
+ options[repairName] = { mutation: repairName, args: {} };
203
+ }
204
+ }
205
+ /*
206
+ * A Choice with one option is not a question, and a violation with one
207
+ * ready repair has already answered: a caller finding no repair question
208
+ * takes the one the violation named.
209
+ */
210
+ if (Object.keys(criteria).length >= 2) {
211
+ out.push({
212
+ id: `repair:${name}${suffix}`,
213
+ about: "repair",
214
+ invariant: name,
215
+ ...(subject ? { subjectId: subject } : {}),
216
+ options,
217
+ question: {
218
+ type: "choice",
219
+ instructions: `Which repair should be taken so that: ${rule}`,
220
+ criteria,
221
+ },
222
+ });
223
+ }
224
+ return out;
225
+ }
226
+ /**
227
+ * A PAIR IS A TRUTH. An act that joins a subject to one other node —
228
+ * "says it helps": a practice and a concern — asked of one particular pair
229
+ * is a yes-or-no question, and the act's own title and description are
230
+ * its words. Fan this out over every pair and you have a matrix nobody
231
+ * ever had to author.
232
+ */
233
+ export function pairQuestion(store, name, subjectId, otherId) {
234
+ const mutation = store.mutation(name);
235
+ const subject = mutation.subject;
236
+ if (!subject)
237
+ return undefined;
238
+ const a = store.graph.getNode(subjectId);
239
+ const b = store.graph.getNode(otherId);
240
+ if (!a || !b)
241
+ return undefined;
242
+ const other = formFields(mutation.input).find((field) => field.control === "node" && field.name !== subject.arg && (field.kinds.includes("*") || field.kinds.includes(b.kind)));
243
+ if (!other)
244
+ return undefined;
245
+ const labelA = labelOf(store.schema.tryDefinition(a.kind), a);
246
+ const labelB = labelOf(store.schema.tryDefinition(b.kind), b);
247
+ const title = mutation.title ?? name;
248
+ return {
249
+ id: `pair:${name}:${subjectId}:${otherId}`,
250
+ about: "argument",
251
+ mutation: name,
252
+ arg: other.name,
253
+ other: otherId,
254
+ question: {
255
+ type: "noul",
256
+ instructions: `${title}: ${labelA} — ${labelB}? ${mutation.description ?? ""}`.trim(),
257
+ criteria: {
258
+ true: `"${title}" holds for ${labelA} and ${labelB}.`,
259
+ false: `"${title}" does not hold for ${labelA} and ${labelB}.`,
260
+ },
261
+ },
262
+ };
263
+ }
264
+ /**
265
+ * THE STATE A QUESTION IS ASKED OVER: one node as the model should see it
266
+ * — its kind and what the kind is for, its label, its readable fields in
267
+ * the declaration's own words, and what it is joined to, by label. Nothing
268
+ * a card would not show. Ids are kept beside labels so an answer that is
269
+ * an id can be checked against what was shown.
270
+ */
271
+ export function nodeState(store, id) {
272
+ const node = store.graph.getNode(id);
273
+ if (!node)
274
+ return undefined;
275
+ const definition = store.schema.tryDefinition(node.kind);
276
+ const fields = {};
277
+ for (const field of readableFields(node, definition))
278
+ fields[field.label] = field.value;
279
+ const joined = {};
280
+ for (const edge of store.graph.outEdges(id)) {
281
+ const other = store.graph.getNode(edge.to);
282
+ if (!other)
283
+ continue;
284
+ (joined[edge.kind] ??= []).push(labelOf(store.schema.tryDefinition(other.kind), other));
285
+ }
286
+ for (const edge of store.graph.inEdges(id)) {
287
+ const other = store.graph.getNode(edge.from);
288
+ if (!other)
289
+ continue;
290
+ const inverse = `${edge.kind} (from)`;
291
+ (joined[inverse] ??= []).push(labelOf(store.schema.tryDefinition(other.kind), other));
292
+ }
293
+ return {
294
+ id,
295
+ kind: node.kind,
296
+ ...(definition?.description ? { "what the kind is": definition.description } : {}),
297
+ label: labelOf(definition, node),
298
+ fields,
299
+ ...(Object.keys(joined).length > 0 ? { joined } : {}),
300
+ };
301
+ }
302
+ /** Every derived question in the app, for a reader — or a test — that wants the whole surface. */
303
+ export function allQuestions(store) {
304
+ const out = [];
305
+ for (const kind of store.schema.kinds) {
306
+ if (store.modules.disabledKinds.has(kind))
307
+ continue;
308
+ out.push(...questionsForKind(store, kind));
309
+ }
310
+ for (const mutation of store.allMutations())
311
+ out.push(...questionsForMutation(store, mutation.name));
312
+ for (const invariant of store.allInvariants())
313
+ out.push(...questionsForInvariant(store, invariant.name));
314
+ return out;
315
+ }
316
+ //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AAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtD,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,YAAY,CAAsB,KAAe;IAC/D,MAAM,GAAG,GAAsB,EAAE,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,KAA0B,EAAE,CAAC;QAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAS;QACpD,GAAG,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,YAAY,EAAE;QAAE,GAAG,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACrG,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,aAAa,EAAE;QAAE,GAAG,CAAC,IAAI,CAAC,GAAG,qBAAqB,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACzG,OAAO,GAAG,CAAC;AACb,CAAC"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,202 @@
1
+ import { type AnySchema, type Principal, type Store } from "@graview/core";
2
+ import type { ToolCall } from "./agent/tools.js";
3
+ import { type AppliedPlan, type Plan, type PlanOptions, type PlannedCall } from "./plan.js";
4
+ import type { Answer, Decide } from "./providers/jev.js";
5
+ import type { ChatReply } from "./conversation.js";
6
+ import { type DerivedQuestion, type OfferedQuestion } from "./questions.js";
7
+ /**
8
+ * A RUN IS A SEQUENCE OF TYPED ASKS OVER THE GRAPH, DECLARED NOT SCRIPTED.
9
+ *
10
+ * This is the thing a context graph buys that a chat box cannot. A run is
11
+ * steps: select nodes by a rule, ask each the questions the declaration
12
+ * already types, turn the answers into calls, land them as one batch,
13
+ * re-evaluate. Fan-out is the ordinary case — output is unmetered, so
14
+ * "fill every unset field of every zone" is one step and not a loop
15
+ * somebody writes — and because every step's output is typed, a step can
16
+ * be judged before the next one runs.
17
+ *
18
+ * A run READS before it runs: how many nodes, how many questions, roughly
19
+ * what it will cost — and refuses to begin one its budget cannot afford,
20
+ * because a fan-out over four hundred questions is a fraction of a cent
21
+ * and a run that does not stop is not.
22
+ *
23
+ * A run holds the Decide it started with for its whole length. Switching
24
+ * the rung underneath it does not move it: a run half done on one rung
25
+ * does not silently finish on another.
26
+ */
27
+ export type RunStep = {
28
+ /** Fill the typed fields of every node of this kind. */
29
+ readonly fill: string;
30
+ /** Only these fields; every typed one otherwise. */
31
+ readonly fields?: readonly string[];
32
+ /** Which nodes. Every current one otherwise. */
33
+ readonly where?: (node: {
34
+ readonly id: string;
35
+ readonly kind: string;
36
+ } & Record<string, unknown>) => boolean;
37
+ /** Ask about fields already set, too. Unset ones only otherwise. */
38
+ readonly including?: "unset" | "all";
39
+ } | {
40
+ /** Ask the remaining arguments of this act, once per node of `over` as its subject. */
41
+ readonly ask: string;
42
+ readonly over: string;
43
+ readonly where?: (node: {
44
+ readonly id: string;
45
+ readonly kind: string;
46
+ } & Record<string, unknown>) => boolean;
47
+ /** Arguments already settled for a node; the rest are asked. */
48
+ readonly given?: (node: {
49
+ readonly id: string;
50
+ readonly kind: string;
51
+ } & Record<string, unknown>) => Readonly<Record<string, unknown>>;
52
+ } | {
53
+ /** For every current violation of this rule, choose a repair from the closed set it names. */
54
+ readonly judge: string;
55
+ } | {
56
+ /** Ask, for every (subject, other) pair, whether this joining act holds — a matrix. */
57
+ readonly pair: string;
58
+ readonly over: string;
59
+ readonly against: string;
60
+ readonly where?: (a: {
61
+ readonly id: string;
62
+ } & Record<string, unknown>, b: {
63
+ readonly id: string;
64
+ } & Record<string, unknown>) => boolean;
65
+ /** The truth above which the pair is a call. 0.5 otherwise. */
66
+ readonly threshold?: number;
67
+ };
68
+ export interface RunDeclaration {
69
+ readonly name: string;
70
+ readonly steps: readonly RunStep[];
71
+ /** What this run may spend. A run over budget does not begin. */
72
+ readonly budget?: {
73
+ readonly questions?: number;
74
+ readonly usd?: number;
75
+ };
76
+ }
77
+ /** One answer, where it came from, and the call it became (if any). */
78
+ export interface Answered {
79
+ readonly step: number;
80
+ readonly nodeId?: string;
81
+ readonly question: DerivedQuestion;
82
+ readonly answer: Answer;
83
+ /** 0–1: how sure. A truth's is its distance from even. */
84
+ readonly confidence: number;
85
+ readonly call?: PlannedCall;
86
+ /** Set when the answer was offered to a person rather than planned. */
87
+ readonly offered?: OfferedQuestion;
88
+ }
89
+ export interface StepOutcome {
90
+ readonly step: number;
91
+ readonly what: string;
92
+ /** The nodes visited, in order. */
93
+ readonly nodes: readonly string[];
94
+ readonly asked: number;
95
+ readonly answered: readonly Answered[];
96
+ readonly proposals: readonly PlannedCall[];
97
+ /** What was not sure enough to propose: questions for a person, at their nodes. */
98
+ readonly questions: readonly OfferedQuestion[];
99
+ /** The step's calls, ordered and judged — what a person reviews. */
100
+ readonly plan: Plan;
101
+ /** Set when the step landed (each-step mode): what it made, under which batch. */
102
+ readonly applied?: Pick<AppliedPlan<AnySchema>, "batch" | "applied" | "made" | "stoppedAt">;
103
+ }
104
+ export interface RunReading {
105
+ readonly name: string;
106
+ readonly steps: readonly {
107
+ readonly step: number;
108
+ readonly what: string;
109
+ readonly nodes: number;
110
+ readonly questions: number;
111
+ readonly calls: number;
112
+ }[];
113
+ readonly questions: number;
114
+ readonly calls: number;
115
+ /** A rough figure: the JSON that would be sent, at four characters a token. */
116
+ readonly approxInputTokens: number;
117
+ readonly approxUsd: number;
118
+ /** Why the run would not begin, if it would not. */
119
+ readonly refused?: string;
120
+ }
121
+ export interface RunOptions<S extends AnySchema> extends PlanOptions<S> {
122
+ readonly decide: Decide;
123
+ /** Who the run writes as. `agent:<run name>:run-<time>` otherwise. */
124
+ readonly author?: Principal;
125
+ /**
126
+ * "review": every step's calls are planned and returned, nothing is
127
+ * applied — a person reviews the plan and lands it as one batch.
128
+ * "each-step": each step lands under the run's one batch before the next
129
+ * step is asked, so a later step sees an earlier one's answers. Both are
130
+ * one batch and one undo.
131
+ */
132
+ readonly land?: "review" | "each-step";
133
+ /** Judge a step's typed outcome before the next runs. A string stops the run and is the reason. */
134
+ readonly judge?: (outcome: StepOutcome) => true | string;
135
+ /** The seat's own announcement path: every visit to a node is a read here. */
136
+ readonly onCall?: (call: ToolCall) => void;
137
+ readonly batch?: string;
138
+ readonly today?: string;
139
+ /** Below this confidence an answer is offered rather than planned. 0.5 otherwise. */
140
+ readonly floor?: number;
141
+ /** Two options this close in probability are a split — a question, not an answer. 0.15 otherwise. */
142
+ readonly splitWithin?: number;
143
+ }
144
+ export interface RunResult<S extends AnySchema> {
145
+ readonly name: string;
146
+ readonly author: Principal;
147
+ readonly batch: string;
148
+ readonly reading: RunReading;
149
+ readonly steps: readonly StepOutcome[];
150
+ /** Every step's calls as one plan, for review — or what was applied. */
151
+ readonly plan: Plan;
152
+ /** Every question offered to a person, across the steps. */
153
+ readonly questions: readonly OfferedQuestion[];
154
+ readonly applied?: AppliedPlan<S>;
155
+ readonly usage: {
156
+ readonly questions: number;
157
+ readonly calls: number;
158
+ readonly inputTokens: number;
159
+ readonly usd: number;
160
+ };
161
+ /** Why the run stopped early, if it did. */
162
+ readonly stopped?: {
163
+ readonly at: number;
164
+ readonly why: string;
165
+ };
166
+ readonly refused?: string;
167
+ }
168
+ /**
169
+ * WHY AN ANSWER IS A QUESTION. A split — the top two options within
170
+ * `within` of each other — is a question for a person, not an answer with
171
+ * a low number beside it; and an answer below the floor is a shrug. Either
172
+ * is offered. Undefined means it is an answer.
173
+ */
174
+ export declare function offerOf(answer: Answer, options?: {
175
+ readonly floor?: number;
176
+ readonly splitWithin?: number;
177
+ }): "split" | "unsure" | undefined;
178
+ /** The answer as the value the argument wants. */
179
+ export declare function valueOf(question: DerivedQuestion, answer: Answer): unknown;
180
+ /** What a run would do, counted, before it does any of it. */
181
+ export declare function readRun<S extends AnySchema>(store: Store<S>, run: RunDeclaration, options?: {
182
+ readonly today?: string;
183
+ }): RunReading;
184
+ /** A run's reading, in words a person can weigh before pressing. */
185
+ export declare function describeRun(reading: RunReading): string;
186
+ /**
187
+ * Runs the run. Every visit to a node is announced through `onCall` as a
188
+ * read of that node — the same shape a seat's tool calls take, so the
189
+ * Activity rail marks where the run is without a second reporting path.
190
+ */
191
+ export declare function runFrom<S extends AnySchema>(store: Store<S>, run: RunDeclaration, options: RunOptions<S>): Promise<RunResult<S>>;
192
+ /**
193
+ * A RUN, SPOKEN BY THE SEAT. What it asked, what it proposes, what it is
194
+ * asking the person — as one ChatReply, so the outcome travels the seat's
195
+ * own surfaces: the thread, the rail, a figure's bubble. The confident
196
+ * calls are proposals; the split or unsure ones are questions standing at
197
+ * their nodes; a refusal or a stop is said, not logged.
198
+ */
199
+ export declare function replyFromRun<S extends AnySchema>(result: RunResult<S>): ChatReply;
200
+ /** Lands a reviewed run as one batch, attributed to the run's own seat. One undo. */
201
+ export declare function landRun<S extends AnySchema>(store: Store<S>, result: RunResult<S>, plan?: Plan): AppliedPlan<S>;
202
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EAAkB,MAAM,eAAe,CAAC;AAC/G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAuB,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACjH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAW,MAAM,oBAAoB,CAAC;AAElE,OAAO,KAAK,E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